diff --git a/inc/functions.php b/inc/functions.php index 105449ab..05b10cd6 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -3154,6 +3154,17 @@ function shell_exec_error($command, $suppress_stdout = false) { return $return === 'TB_SUCCESS' ? false : $return; } +// Clone all the files and thumbnails on a post's file array, performing sanity checks. +// Used for moving and merging posts. Assumes source and destination boards are different. +// Checks that files exist and aren't special thumbnails. +function clone_files($clone_function, &$file, $dest_uri) { + global $config; + if ($file['file'] !== 'deleted' && file_exists($file['file_path'])) + $clone_function($file['file_path'], sprintf($config['board_path'], $dest_uri) . $config['dir']['img'] . $file['file']); + if (isset($file['thumb']) && !in_array($file['thumb'], array('spoiler', 'deleted', 'file')) && file_exists($file['thumb_path'])) + $clone_function($file['thumb_path'], sprintf($config['board_path'], $dest_uri) . $config['dir']['thumb'] . $file['thumb']); +} + /* Die rolling: * If "dice XdY+/-Z" is in the email field (where X or +/-Z may be * missing), X Y-sided dice are rolled and summed, with the modifier Z diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 140ec48c..63ed5516 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1344,12 +1344,8 @@ function mod_move_reply($originBoard, $postID) { if ($post['has_file'] && $board_move) { foreach ($post['files'] as $i => &$file) { - // move the image - if (isset($file['thumb'])) - if ($file['thumb'] != 'spoiler' || $file['thumb'] != 'deleted') { //trying to move/copy the spoiler thumb raises an error - rename($file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']); - rename($file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']); - } + // move images + clone_files(rename, $file, $board['uri']); } } @@ -1466,12 +1462,9 @@ function mod_move($originBoard, $postID) { $op['id'] = $newID; if ($post['has_file']) { - // copy image + // copy images foreach ($post['files'] as $i => &$file) { - if ($file['file'] !== 'deleted') - $clone($file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']); - if (isset($file['thumb']) && !in_array($file['thumb'], array('spoiler', 'deleted', 'file'))) - $clone($file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']); + clone_files($clone, $file, $board['uri']); } } @@ -1532,13 +1525,9 @@ function mod_move($originBoard, $postID) { $post['tracked_cites'] = markup($post['body'], true); if ($post['has_file']) { - // copy image + // copy images foreach ($post['files'] as $i => &$file) { - if (isset($file['thumb'])) - if ($file['thumb'] != 'spoiler' || $file['thumb'] != 'deleted') { //trying to move/copy the spoiler thumb raises an error - $clone($file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']); - $clone($file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']); - } + clone_files($clone, $file, $board['uri']); } } @@ -1736,12 +1725,9 @@ function mod_merge($originBoard, $postID) { $op['id'] = $newID; if ($post['has_file']) { - // copy image + // copy images foreach ($post['files'] as $i => &$file) { - if ($file['file'] !== 'deleted') - $clone($file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']); - if (isset($file['thumb']) && !in_array($file['thumb'], array('spoiler', 'deleted', 'file'))) - $clone($file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']); + clone_files($clone, $file, $board['uri']); } } @@ -1800,10 +1786,9 @@ function mod_merge($originBoard, $postID) { $post['tracked_cites'] = markup($post['body'], true); if ($post['has_file']) { - // copy image + // copy images foreach ($post['files'] as $i => &$file) { - $clone($file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']); - $clone($file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']); + clone_files($clone, $file, $board['uri']); } } // insert reply