diff --git a/docs/NEWS b/docs/NEWS
index d8dd72c3..83e443d6 100644
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -1,6 +1,11 @@
Version 2.1 ()
------------------------------------------------------------------------
+ * Added new bulk image move ability to MediaLibrary. This fixes
+ several issues with rename AND remove and allows to automatically
+ check and set MediaLibrary item entry paths on MOVE.
+ Staticpages from v.4.52 are modified to support this too.
+
* Fix MediaLibrary objects not pass through into entryproperties
CustomFields
diff --git a/include/admin/entries.inc.php b/include/admin/entries.inc.php
index c997d911..10d40030 100644
--- a/include/admin/entries.inc.php
+++ b/include/admin/entries.inc.php
@@ -396,7 +396,11 @@ switch($serendipity['GET']['adminAction']) {
break;
case 'multidelete':
- if (!serendipity_checkFormToken() || !is_array($serendipity['POST']['multiDelete'])) {
+ if (!serendipity_checkFormToken()) {
+ return; // blank content page, but default token check parameter is presenting a XSRF message when false
+ }
+ if (!is_array($serendipity['POST']['multiDelete'])) {
+ echo '
' . sprintf(MULTICHECK_NO_ITEM, $_SERVER['HTTP_REFERER']) . '
'."\n";
break;
}
diff --git a/include/admin/images.inc.php b/include/admin/images.inc.php
index 97aaf903..fe627c8b 100644
--- a/include/admin/images.inc.php
+++ b/include/admin/images.inc.php
@@ -60,7 +60,7 @@ switch ($serendipity['GET']['adminAction']) {
$messages = array();
$data['case_do_delete'] = true;
$messages[] = serendipity_deleteImage($serendipity['GET']['fid']);
- $messages[] = sprintf(' ' . RIP_ENTRY . '', $serendipity['GET']['fid']);
+ $messages[] = sprintf(' ' . RIP_ENTRY . "\n", $serendipity['GET']['fid']);
$data['showML'] = showMediaLibrary();
$data['messages'] = $messages;
@@ -81,7 +81,7 @@ switch ($serendipity['GET']['adminAction']) {
if ($id > 0) {
$image = serendipity_fetchImageFromDatabase($id);
$messages[] = serendipity_deleteImage((int)$id);
- $messages[] = sprintf(' ' . RIP_ENTRY . '', $image['id'] . ' - ' . serendipity_specialchars($image['realname']));
+ $messages[] = sprintf(' ' . RIP_ENTRY . "\n", $image['id'] . ' - ' . serendipity_specialchars($image['realname']));
}
}
$data['showML'] = showMediaLibrary();
@@ -108,33 +108,41 @@ switch ($serendipity['GET']['adminAction']) {
break;
case 'multidelete':
- if (!serendipity_checkFormToken() || !is_array($serendipity['POST']['multiDelete'])) {
+ if (!serendipity_checkFormToken()) {
+ return; // blank content page, but default token check parameter is presenting a XSRF message when false
+ }
+ if (!is_array($serendipity['POST']['multiDelete'])) {
+ echo ' ' . sprintf(MULTICHECK_NO_ITEM, $_SERVER['HTTP_REFERER']) . '
'."\n";
+ break;
+ }
+ if (is_array($serendipity['POST']['multiDelete']) && isset($serendipity['POST']['oldDir']) && empty($serendipity['POST']['newDir'])) {
+ echo ' ' . sprintf(MULTICHECK_NO_DIR, $_SERVER['HTTP_REFERER']) . '
'."\n";
break;
}
// case bulk multimove (leave the fake oldDir being send as an empty dir)
if (isset($serendipity['POST']['oldDir']) && !empty($serendipity['POST']['newDir'])) {
$messages = array();
- $multiMoveImages = $serendipity['POST']['multiDelete'];
+ $multiMoveImages = $serendipity['POST']['multiDelete']; // The 'multiDelete' key name should better be renamed to 'multiCheck', but this would need to change 2k11/admin/serendipity_editor.js, images.inc.tpl, media_items.tpl, media_pane.tpl and this file
unset($serendipity['POST']['multiDelete']);
- $oDir = ''; // oldDir is relative to Uploads/, since we can not specify a directory of a ML bulk move
- $nDir = serendipity_specialchars((string)$serendipity['POST']['newDir']);
+ $oDir = ''; // oldDir is relative to Uploads/, since we can not specify a directory of a ML bulk move directly
+ $nDir = serendipity_specialchars((string)$serendipity['POST']['newDir']); // relative to Uploads/
if ($oDir != $nDir) {
foreach($multiMoveImages AS $mkey => $move_id) {
$file = serendipity_fetchImageFromDatabase((int)$move_id);
$oDir = $file['path']; // this now is the exact oldDir path of this ID
if (serendipity_moveMediaDirectory($oDir, $nDir, 'file', (int)$move_id, $file)) {
- $messages[] = sprintf(' ' . MEDIA_DIRECTORY_MOVED . '', $nDir);
+ $messages[] = sprintf(' ' . MEDIA_DIRECTORY_MOVED . "\n", $nDir);
} else {
- $messages[] = sprintf(' ' . MEDIA_DIRECTORY_MOVE_ERROR . '', $nDir);
+ $messages[] = sprintf(' ' . MEDIA_DIRECTORY_MOVE_ERROR . "\n", $nDir);
}
}
}
$data['messages'] = $messages;
+ unset($messages);
// fall back
$data['case_default'] = true;
$data['showML'] = showMediaLibrary();
- unset($messages);
break;
}
@@ -168,7 +176,6 @@ switch ($serendipity['GET']['adminAction']) {
}
if (!serendipity_moveMediaDirectory(null, $serendipity['GET']['newname'], 'file', $serendipity['GET']['fid'], $file)) {
$data['go_back'] = true;
- break;
}
break;
@@ -218,7 +225,7 @@ switch ($serendipity['GET']['adminAction']) {
$tfile = serendipity_uploadSecure(basename($tfile));
if (serendipity_isActiveFile($tfile)) {
- $messages[] = sprintf(' ' . ERROR_FILE_FORBIDDEN . '', $tfile);
+ $messages[] = sprintf(' ' . ERROR_FILE_FORBIDDEN . "\n", $tfile);
break;
}
@@ -226,13 +233,13 @@ switch ($serendipity['GET']['adminAction']) {
$target = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $serendipity['POST']['target_directory'][$tindex] . $tfile;
if (!serendipity_checkDirUpload($serendipity['POST']['target_directory'][$tindex])) {
- $messages[] = ' ' . PERM_DENIED . '';
+ $messages[] = ' ' . PERM_DENIED . "\n";
return;
}
$realname = $tfile;
if (file_exists($target)) {
- $messages[] = ' ' . $target . ' - ' . ERROR_FILE_EXISTS_ALREADY . '';
+ $messages[] = ' ' . $target . ' - ' . ERROR_FILE_EXISTS_ALREADY . "\n";
$realname = serendipity_imageAppend($tfile, $target, $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $serendipity['POST']['target_directory'][$tindex]);
}
@@ -244,7 +251,7 @@ switch ($serendipity['GET']['adminAction']) {
// Try to get the URL
if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') {
- $messages[] = sprintf(' ' . REMOTE_FILE_NOT_FOUND . '', $serendipity['POST']['imageurl']);
+ $messages[] = sprintf(' ' . REMOTE_FILE_NOT_FOUND . "\n", $serendipity['POST']['imageurl']);
} else {
// Fetch file
$fContent = $req->getResponseBody();
@@ -256,14 +263,14 @@ switch ($serendipity['GET']['adminAction']) {
fclose($fp);
$image_id = @serendipity_insertHotlinkedImageInDatabase($tfile, $serendipity['POST']['imageurl'], $authorid, null, $tempfile);
- $messages[] = sprintf(' ' . HOTLINK_DONE . '', $serendipity['POST']['imageurl'] , $tfile .'');
+ $messages[] = sprintf(' ' . HOTLINK_DONE . "\n", $serendipity['POST']['imageurl'] , $tfile .'');
serendipity_plugin_api::hook_event('backend_image_addHotlink', $tempfile);
} else {
$fp = fopen($target, 'w');
fwrite($fp, $fContent);
fclose($fp);
- $messages[] = sprintf(' ' . FILE_FETCHED . '', $serendipity['POST']['imageurl'] , $tfile . '');
+ $messages[] = sprintf(' ' . FILE_FETCHED . "\n", $serendipity['POST']['imageurl'] , $tfile . '');
if (serendipity_checkMediaSize($target)) {
$thumbs = array(array(
@@ -275,7 +282,7 @@ switch ($serendipity['GET']['adminAction']) {
foreach($thumbs as $thumb) {
// Create thumbnail
if ( $created_thumbnail = serendipity_makeThumbnail($tfile, $serendipity['POST']['target_directory'][$tindex], $thumb['thumbSize'], $thumb['thumb']) ) {
- $messages[] = ' ' . THUMB_CREATED_DONE . '';
+ $messages[] = ' ' . THUMB_CREATED_DONE . "\n";
}
}
@@ -320,14 +327,14 @@ switch ($serendipity['GET']['adminAction']) {
$tfile = serendipity_uploadSecure(basename($tfile));
if (serendipity_isActiveFile($tfile)) {
- $messages[] = ' ' . ERROR_FILE_FORBIDDEN .' '. $tfile . '';
+ $messages[] = ' ' . ERROR_FILE_FORBIDDEN .' '. $tfile . "\n";
continue;
}
$serendipity['POST']['target_directory'][$idx] = serendipity_uploadSecure($serendipity['POST']['target_directory'][$idx], true, true);
if (!serendipity_checkDirUpload($serendipity['POST']['target_directory'][$idx])) {
- $messages[] = ' ' . PERM_DENIED . '';
+ $messages[] = ' ' . PERM_DENIED . "\n";
continue;
}
@@ -335,13 +342,13 @@ switch ($serendipity['GET']['adminAction']) {
$realname = $tfile;
if (file_exists($target)) {
- $messages[] = ' ' . $target . ' - ' . ERROR_FILE_EXISTS_ALREADY . '';
+ $messages[] = ' ' . $target . ' - ' . ERROR_FILE_EXISTS_ALREADY . "\n";
$realname = serendipity_imageAppend($tfile, $target, $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $serendipity['POST']['target_directory'][$idx]);
}
// Accept file
if (is_uploaded_file($uploadtmp) && serendipity_checkMediaSize($uploadtmp) && move_uploaded_file($uploadtmp, $target)) {
- $messages[] = sprintf(' ' . FILE_UPLOADED . '', $uploadfile , $target);
+ $messages[] = sprintf(' ' . FILE_UPLOADED . "\n", $uploadfile , $target);
@umask(0000);
@chmod($target, 0664);
@@ -354,7 +361,7 @@ switch ($serendipity['GET']['adminAction']) {
foreach($thumbs as $thumb) {
// Create thumbnail
if ( $created_thumbnail = serendipity_makeThumbnail($tfile, $serendipity['POST']['target_directory'][$idx], $thumb['thumbSize'], $thumb['thumb']) ) {
- $messages[] = ' ' . THUMB_CREATED_DONE . '';
+ $messages[] = ' ' . THUMB_CREATED_DONE . "\n";
}
}
@@ -369,7 +376,7 @@ switch ($serendipity['GET']['adminAction']) {
} else {
// necessary for the ajax-uplaoder to show upload errors
header("Internal Server Error", true, 500);
- $messages[] = ' ' . ERROR_UNKNOWN_NOUPLOAD . '';
+ $messages[] = ' ' . ERROR_UNKNOWN_NOUPLOAD . "\n";
}
}
}
@@ -422,6 +429,7 @@ switch ($serendipity['GET']['adminAction']) {
}
$data['case_directoryEdit'] = true;
+
$use_dir = serendipity_uploadSecure($serendipity['GET']['dir']);
$checkpath = array(
array(
@@ -434,17 +442,23 @@ switch ($serendipity['GET']['adminAction']) {
}
if (!empty($serendipity['POST']['save'])) {
- $newDir = serendipity_uploadSecure(serendipity_makeFilename($serendipity['POST']['newDir']));
- $oldDir = serendipity_uploadSecure($serendipity['POST']['oldDir']);
+ // preserve directory slashes, eg for dir/subdir/
+ $_newDir = str_replace('/', '_DS_', $serendipity['POST']['newDir']);
+ $_oldDir = str_replace('/', '_DS_', $serendipity['POST']['oldDir']);
+ $_newDir = serendipity_uploadSecure(serendipity_makeFilename($_newDir));
+ $_oldDir = serendipity_uploadSecure($_oldDir);
+ $newDir = str_replace('_DS_', '/', $_newDir);
+ $oldDir = str_replace('_DS_', '/', $_oldDir);
if ($oldDir != $newDir) {
- //is this possible?
+ //is this possible? Ian: YES! Change an already set directory.
ob_start();
serendipity_moveMediaDirectory($oldDir, $newDir);
- $data['ob_serendipity_moveMediaDirectory'] = ob_get_contents();
+ $data['messages'] = ob_get_contents();
ob_end_clean();
$use_dir = $newDir;
}
+
serendipity_ACLGrant(0, 'directory', 'read', $serendipity['POST']['read_authors'], $use_dir);
serendipity_ACLGrant(0, 'directory', 'write', $serendipity['POST']['write_authors'], $use_dir);
$data['print_SETTINGS_SAVED_AT'] = sprintf(SETTINGS_SAVED_AT, serendipity_strftime('%H:%M:%S'));
@@ -488,6 +502,7 @@ switch ($serendipity['GET']['adminAction']) {
}
$data['case_directoryDoCreate'] = true;
+
$new_dir = serendipity_uploadSecure($serendipity['POST']['parent'] . '/' . serendipity_makeFilename($serendipity['POST']['name']), true);
$new_dir = str_replace(array('..', '//'), array('', '/'), $new_dir);
diff --git a/include/functions_images.inc.php b/include/functions_images.inc.php
index d2475f1a..fc01f800 100644
--- a/include/functions_images.inc.php
+++ b/include/functions_images.inc.php
@@ -322,7 +322,7 @@ function serendipity_deleteImage($id) {
$file = serendipity_fetchImageFromDatabase($id);
if (!is_array($file)) {
- $messages .= sprintf(' ' . FILE_NOT_FOUND . '', $id);
+ $messages .= sprintf(' ' . FILE_NOT_FOUND . "\n", $id);
//return false;
} else {
@@ -344,9 +344,9 @@ function serendipity_deleteImage($id) {
if (!$file['hotlink']) {
if (file_exists($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $dFile)) {
if (@unlink($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $dFile)) {
- $messages .= sprintf(' ' . DELETE_FILE . '', $dFile);
+ $messages .= sprintf(' ' . DELETE_FILE . "\n", $dFile);
} else {
- $messages .= sprintf(' ' . DELETE_FILE_FAIL . '', $dFile);
+ $messages .= sprintf(' ' . DELETE_FILE_FAIL . "\n", $dFile);
}
serendipity_plugin_api::hook_event('backend_media_delete', $dThumb);
@@ -355,14 +355,14 @@ function serendipity_deleteImage($id) {
$dfThumb = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $dfnThumb;
if (@unlink($dfThumb)) {
- $messages .= sprintf(' ' . DELETE_THUMBNAIL . '', $dfnThumb);
+ $messages .= sprintf(' ' . DELETE_THUMBNAIL . "\n", $dfnThumb);
}
}
} else {
- $messages .= sprintf(' ' . FILE_NOT_FOUND . '', $dFile);
+ $messages .= sprintf(' ' . FILE_NOT_FOUND . "\n", $dFile);
}
} else {
- $messages .= sprintf(' ' . DELETE_HOTLINK_FILE . '', $file['name']);
+ $messages .= sprintf(' ' . DELETE_HOTLINK_FILE . "\n", $file['name']);
}
serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}images WHERE id = ". (int)$id);
@@ -494,8 +494,8 @@ function serendipity_insertHotlinkedImageInDatabase($filename, $url, $authorid =
$sql = serendipity_db_query($query);
if (is_string($sql)) {
- echo '' . $query . '';
- echo '' . $sql . '';
+ echo '' . $query . "\n";
+ echo '' . $sql . "\n";
}
$image_id = serendipity_db_insert_id('images', 'id');
@@ -581,8 +581,8 @@ function serendipity_insertImageInDatabase($filename, $directory, $authorid = 0,
$sql = serendipity_db_query($query);
if (is_string($sql)) {
- echo '' . $query . '';
- echo '' . $sql . '';
+ echo '' . $query . "\n";
+ echo '' . $sql . "\n";
}
$image_id = serendipity_db_insert_id('images', 'id');
@@ -675,7 +675,7 @@ function serendipity_makeThumbnail($file, $directory = '', $size = false, $thumb
}
exec($cmd, $output, $result);
if ($result != 0) {
- echo ' ' . sprintf(IMAGICK_EXEC_ERROR, $cmd, $output[0], $result) .'';
+ echo ' ' . sprintf(IMAGICK_EXEC_ERROR, $cmd, $output[0], $result) ."\n";
$r = false; // return failure
} else {
touch($outfile);
@@ -718,7 +718,7 @@ function serendipity_scaleImg($id, $width, $height) {
$cmd = escapeshellcmd($serendipity['convert']) . ' -scale ' . serendipity_escapeshellarg($width . 'x' . $height) . ' ' . serendipity_escapeshellarg($infile) . ' ' . serendipity_escapeshellarg($outfile);
exec($cmd, $output, $result);
if ( $result != 0 ) {
- echo ' ' . sprintf(IMAGICK_EXEC_ERROR, $cmd, $output[0], $result) .'';
+ echo ' ' . sprintf(IMAGICK_EXEC_ERROR, $cmd, $output[0], $result) ."\n";
}
unset($output, $result);
}
@@ -765,7 +765,7 @@ function serendipity_rotateImg($id, $degrees) {
$cmd = escapeshellcmd($serendipity['convert']) . ' -rotate ' . serendipity_escapeshellarg($degrees) . ' ' . serendipity_escapeshellarg($infile) . ' ' . serendipity_escapeshellarg($outfile);
exec($cmd, $output, $result);
if ( $result != 0 ) {
- echo ' ' . sprintf(IMAGICK_EXEC_ERROR, $cmd, $output[0], $result) .'';
+ echo ' ' . sprintf(IMAGICK_EXEC_ERROR, $cmd, $output[0], $result) ."\n";
}
unset($output, $result);
@@ -773,7 +773,7 @@ function serendipity_rotateImg($id, $degrees) {
$cmd = escapeshellcmd($serendipity['convert']) . ' -rotate ' . serendipity_escapeshellarg($degrees) . ' ' . serendipity_escapeshellarg($infileThumb) . ' ' . serendipity_escapeshellarg($outfileThumb);
exec($cmd, $output, $result);
if ( $result != 0 ) {
- echo ' ' . sprintf(IMAGICK_EXEC_ERROR, $cmd, $output[0], $result) .'';
+ echo ' ' . sprintf(IMAGICK_EXEC_ERROR, $cmd, $output[0], $result) ."\n";
}
unset($output, $result);
@@ -826,7 +826,7 @@ function serendipity_generateThumbs() {
if ($returnsize !== false ) {
// Only print the resize message the first time
if (!$msg_printed) {
- printf(' ' . RESIZE_BLAHBLAH, THUMBNAIL_SHORT . '');
+ printf(' ' . RESIZE_BLAHBLAH, THUMBNAIL_SHORT . "\n");
echo "\n" . '' . "\n";
$msg_printed = true;
}
@@ -840,7 +840,7 @@ function serendipity_generateThumbs() {
} elseif (!file_exists($oldThumb) && !file_exists($newThumb) && $fdim[0] <= $serendipity['thumbSize'] && $fdim[1] <= $serendipity['thumbSize']) {
if (!$msg_printed) {
$resizethumb = sprintf(RESIZE_BLAHBLAH, THUMB);
- printf(' ' . $resizethumb . '');
+ printf(' ' . $resizethumb . "\n");
echo "\n" . '' . "\n";
$msg_printed = true;
}
@@ -1101,7 +1101,7 @@ function serendipity_syncThumbs($deleteThumbs = false) {
$f = serendipity_parseFileName($files[$x]);
if (empty($f[1]) || $f[1] == $files[$x]) {
// No extension means bad file most probably. Skip it.
- printf(' ' . SKIPPING_FILE_EXTENSION . '', $files[$x]);
+ printf(' ' . SKIPPING_FILE_EXTENSION . "\n", $files[$x]);
continue;
}
@@ -1115,7 +1115,7 @@ function serendipity_syncThumbs($deleteThumbs = false) {
}
if (!is_readable($ffull) || filesize($ffull) == 0) {
- printf(' ' . SKIPPING_FILE_UNREADABLE . '', $files[$x]);
+ printf(' ' . SKIPPING_FILE_UNREADABLE . "\n", $files[$x]);
continue;
}
@@ -1809,7 +1809,7 @@ function serendipity_killPath($basedir, $directory = '', $forceDelete = false) {
}
echo "
\n";
} else {
- echo ' ' . ERROR_DIRECTORY_NOT_EMPTY . '';
+ echo ' ' . ERROR_DIRECTORY_NOT_EMPTY . "\n";
echo "\n";
foreach($filestack AS $f => $file) {
echo '- ' . $file . "
\n";
@@ -3357,7 +3357,8 @@ function serendipity_checkMediaSize($file) {
/**
* Moves a media directory
*
- * @param string The old directory
+ * @param string The old directory.
+ * This can be NULL or (an empty / a) STRING for re-name/multiCheck move comparison events
* @param string The new directory
* @param string The type of what to remove (dir|file|filedir)
* @param string An item id of a file
@@ -3368,11 +3369,25 @@ function serendipity_checkMediaSize($file) {
function serendipity_moveMediaDirectory($oldDir, $newDir, $type = 'dir', $item_id = null, $file = null) {
global $serendipity;
- $real_oldDir = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $oldDir;
- $real_newDir = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $newDir;
+ // paranoid case for updating an old image id entry - else we have a new entry incrementary
+ if (is_null($item_id) && isset($file['id']) && $file['id'] > 0) $item_id = $file['id'];
+ if ($item_id < 1) {
+ echo ' ' . printf(ERROR_FILE_NOT_EXISTS, $item_id) . "\n";
+ return false;
+ }
+
+ // Prepare data for the database, any hooks and the real file move, by case AREA:
+ // DIR = Media directory form edit,
+ // FILE = File rename or File bulk move,
+ // FILEDIR = Media properties form edit
+
+ // images.inc case 'directoryEdit' via ML case 'directorySelect', which is ML Directories form
if ($type == 'dir') {
+ $real_oldDir = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $oldDir;
+ $real_newDir = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $newDir;
+
if (!is_dir($real_oldDir)) {
echo ' ';
printf(ERROR_FILE_NOT_EXISTS, $oldDir);
@@ -3428,9 +3443,24 @@ function serendipity_moveMediaDirectory($oldDir, $newDir, $type = 'dir', $item_i
AND artifact_index = '" . serendipity_db_escape_string($dir['artifact_index']) . "'");
}
}
- }
+ // hook into staticpage for the renaming regex replacements
+ // first and last two are null - only differ by being set already by their default var for the last two
+ $renameValues = array(array(
+ 'from' => null,
+ 'to' => null,
+ 'thumb' => $serendipity['thumbSuffix'],
+ 'fthumb' => null,
+ 'oldDir' => $oldDir,
+ 'newDir' => $newDir,
+ 'type' => $type,
+ 'item_id' => $item_id,
+ 'file' => $file
+ ));
+ // Changing a ML directory via directoryEdit needs to run through entries too!
+ serendipity_plugin_api::hook_event('backend_media_rename', $renameValues);
- if ($type == 'file') {
+ // case 'rename' OR 'multidelete' (bulk multimove)
+ } else if ($type == 'file') {
// active in mean of eval or executable
if (serendipity_isActiveFile(basename($newDir))) {
@@ -3439,58 +3469,164 @@ function serendipity_moveMediaDirectory($oldDir, $newDir, $type = 'dir', $item_i
echo "\n";
return false;
}
-
- if ($file['hotlink']) {
- serendipity_updateImageInDatabase(array('realname' => $newDir, 'name' => $newDir), $item_id);
+ if (!empty($file['hotlink'])) {
+ $newHotlinkFile = (false === strpos($newDir, $file['extension'])) ? $newDir . (empty($file['extension']) ? '' : '.' . $file['extension']) : $newDir;
+ serendipity_updateImageInDatabase(array('realname' => $newHotlinkFile, 'name' => $newDir), $item_id);
} else {
- $file_new = $newDir . $file['name'] . (empty($file['extension']) ? '' : '.');
- $file_old = $file['path'] . $file['name'] . (empty($file['extension']) ? '' : '.');
+ $parts = pathinfo($newDir);
- $newfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file_new . $file['extension'];
- $oldfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file_old . $file['extension'];
- if ($newDir != '' && file_exists($oldfile) && !file_exists($newfile)) {
- $renameValues = array(array(
- 'from' => $oldfile,
- 'to' => $newfile,
- 'thumb' => $serendipity['thumbSuffix'],
- 'fthumb' => $file['thumbnail_name'],
- 'oldDir' => $oldDir,
- 'newDir' => $newDir,
- 'type' => $type,
- 'item_id'=> $item_id,
- 'file' => $file
- ));
+ // build new, thumb and old file names relative to Serendipity root path
+ if ($oldDir === null && $newDir != 'uploadRoot') {
- serendipity_plugin_api::hook_event('backend_media_rename', $renameValues); // eg. for staticpage entries path regex replacements
+ // case single file re-name event (newDir = newName is passed without path!)
+ $newName = $newDir; // for better readability
+ // do we really need this?
+ if ($parts['extension'] != $file['extension']) {
+ $file_new = $file['path'] . $newName . (empty($file['extension']) ? '' : '.' . $file['extension']);
+ $file_old = $file['path'] . $file['name'] . (empty($file['extension']) ? '' : '.' . $file['extension']);
+ } else {
+ $file_new = $file['path'] . $newName;
+ $file_old = $file['path'] . $file['name'];
+ }
+ // build full thumb file names
+ $file_newthumb = $file['path'] . $newName . (!empty($file['thumbnail_name']) ? '.' . $file['thumbnail_name'] : '') . (empty($file['extension']) ? '' : '.' . $file['extension']);
+ $file_oldthumb = $file['path'] . $file['name'] . (!empty($file['thumbnail_name']) ? '.' . $file['thumbnail_name'] : '') . (empty($file['extension']) ? '' : '.' . $file['extension']);
+ $newThumb = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file_newthumb;
+ $oldThumb = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file_oldthumb;
- // Rename file
- rename($renameValues[0]['from'], $renameValues[0]['to']);
+ } else {
- foreach($renameValues AS $renameData) {
- // Rename thumbnail
- @rename($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['path'] . $file['name'] . (!empty($renameData['fthumb']) ? '.' . $renameData['fthumb'] : '') . (empty($file['extension']) ? '' : '.' . $file['extension']),
- $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $newDir . $file['name'] . (!empty($file['thumbnail_name']) ? '.' . $renameData['thumb'] : '') . (empty($file['extension']) ? '' : '.' . $file['extension']));
+ // case bulkmove event (newDir is passed inclusive path! and normally w/o the filename, but we better check this though)
+ $newDir = ($newDir == 'uploadRoot') ? '' : $newDir; // Take care: remove temporary 'uploadRoot' string, in case of moving a subdir file into upload root by bulkmove
+ $_newDir = str_replace($file['name'] . (empty($file['extension']) ? '' : '.' . $file['extension']), '', $newDir);
+ // do we really need this?
+ if ($parts['extension'] != $file['extension']) {
+ $file_new = $_newDir . $file['name'] . (empty($file['extension']) ? '' : '.' . $file['extension']);
+ $file_old = $file['path'] . $file['name'] . (empty($file['extension']) ? '' : '.' . $file['extension']);
+ } else {
+ $file_new = $_newDir . $file['name'];
+ $file_old = $file['path'] . $file['name'];
}
- serendipity_updateImageInDatabase(array('thumbnail_name' => $renameValues[0]['thumb'], 'realname' => $newDir, 'name' => $newDir), $item_id);
- $oldDir = $file_old;
- $newDir = $file_new;
- $real_oldDir = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $oldDir;
- $real_newDir = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $newDir;
- // Forward user to overview (we don't want the user's back button to rename things again)
+ }
+
+ // build full origin and new file path names
+ $newfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file_new;
+ $oldfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file_old;
+
+ // check files existence
+ if (file_exists($oldfile) && !file_exists($newfile)) {
+
+ // for the paranoid, securely check these build filenames again, since we really need a real file set to continue!
+ $newparts = pathinfo($newfile);
+ if ($newparts['dirname'] == '.' || (!empty($file['extension']) && empty($newparts['extension'])) || empty($newparts['filename'])) {
+ // error new file build mismatch
+ echo ' ' . $newfile . ' ' . ERROR_SOMETHING . "\n";
+ return false;
+ }
+
+ // Case re-name event, keeping a possible moved directory name for a single file
+ if ($oldDir === null) {
+ // Move the origin file
+ @rename($oldfile, $newfile);
+ // do not re-name again, if item has no thumb name (eg zip object file case) and old thumb actually exists (possible missing pdf preview image on WinOS with IM)
+ if (($newThumb != $newfile) && file_exists($oldThumb)) {
+ // the thumb file
+ @rename($oldThumb, $newThumb); // Keep both rename() error disabled, since we have to avoid any output in renaiming cases
+ }
+
+ // hook into staticpage for the renaming regex replacements
+ $renameValues = array(array(
+ 'from' => $oldfile,
+ 'to' => $newfile,
+ 'thumb' => $serendipity['thumbSuffix'],
+ 'fthumb' => $file['thumbnail_name'],
+ 'oldDir' => $oldDir,
+ 'newDir' => $newDir,
+ 'type' => $type,
+ 'item_id' => $item_id,
+ 'file' => $file
+ ));
+ serendipity_plugin_api::hook_event('backend_media_rename', $renameValues);
+
+ // renaming filenames has to update mediaproperties if set
+ $q = "UPDATE {$serendipity['dbPrefix']}mediaproperties
+ SET value = '" . serendipity_db_escape_string($newName . (empty($file['extension']) ? '' : '.' . $file['extension'])) . "'
+ WHERE mediaid = " . (int)$item_id . ' AND property = "realname" AND value = "' . $file['realname'] . '"';
+ serendipity_db_query($q);
+ $q = "UPDATE {$serendipity['dbPrefix']}mediaproperties
+ SET value = '" . serendipity_db_escape_string($newName) . "'
+ WHERE mediaid = " . (int)$item_id . ' AND property = "name" AND value = "' . $file['name'] .'"';
+ serendipity_db_query($q);
+ $q = "UPDATE {$serendipity['dbPrefix']}mediaproperties
+ SET value = '" . serendipity_db_escape_string($newName . (empty($file['extension']) ? '' : '.' . $file['extension'])) . "'
+ WHERE mediaid = " . (int)$item_id . ' AND property = "TITLE" AND value = "' . $file['realname'] .'"';
+ serendipity_db_query($q);
+
+ serendipity_updateImageInDatabase(array('thumbnail_name' => $renameValues[0]['thumb'], 'realname' => $newName . (empty($file['extension']) ? '' : '.' . $file['extension']), 'name' => $newName), $item_id);
+
+ // Forward user to overview (we don't want the user's back button to rename things again) ?? What does this do? Check!!!
+ }
+
+ // Case Move or Bulkmove event
+ // newDir can now be used for the uploads directory root path too
+ // Do not allow an empty string or not set newDir for the build call so we do not conflict with rename calls, which are single files only and is done above
+ // BULKMOVE vars oldfile and newfile are fullpath based see above
+ elseif (!empty($newfile)) {
+
+ if ($newDir == 'uploadRoot') $newDir = ''; // now move back into root of /uploads dir
+
+ // hook into staticpage for the renaming regex replacements
+ $renameValues = array(array(
+ 'from' => $oldfile,
+ 'to' => $newfile,
+ 'thumb' => $serendipity['thumbSuffix'],
+ 'fthumb' => $file['thumbnail_name'],
+ 'oldDir' => $oldDir,
+ 'newDir' => $newDir,
+ 'type' => $type,
+ 'item_id' => $item_id,
+ 'file' => $file
+ ));
+ serendipity_plugin_api::hook_event('backend_media_rename', $renameValues); // eg. for staticpage entries path regex replacements
+
+ // Move the origin file
+ try { rename($oldfile, $newfile); } catch (Exception $e) { echo ' ' . ERROR_SOMETHING . ': '.$e->getMessage() . "\n"; }
+
+ // do still need this? YES, it is definitely false, so we would not need the ternary
+ // Rename newDir + file name in case it is called by the Bulk Move and not by rename
+ $newDirFile = (false === strpos($newDir, $file['name'])) ? $newDir . $file['name'] : $newDir;
+
+ foreach($renameValues AS $renameData) {
+ // build full thumb file names
+ $thisOldThumb = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $renameData['oldDir'] . $file['name'] . (!empty($renameData['fthumb']) ? '.' . $renameData['fthumb'] : '.' . $serendipity['thumbSuffix']) . (empty($file['extension']) ? '' : '.' . $file['extension']);
+ $thisNewThumb = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $newDirFile . (!empty($file['thumbnail_name']) ? '.' . $renameData['thumb'] : '.' . $serendipity['thumbSuffix']) . (empty($file['extension']) ? '' : '.' . $file['extension']);
+ // Check for existent old thumb files first, to not need to disable rename by @rename()
+ if (($thisNewThumb != $newfile) && file_exists($thisOldThumb)) {
+ // the thumb file and catch any wrong renaming
+ try { rename($thisOldThumb, $thisNewThumb); } catch (Exception $e) { echo ' ' . ERROR_SOMETHING . ': '.$e->getMessage() . "\n"; }
+ }
+ }
+
+ serendipity_updateImageInDatabase(array('thumbnail_name' => $renameValues[0]['thumb'], 'path' => $newDir, 'realname' => $file['realname'], 'name' => $file['name']), $item_id);
+ // Forward user to overview (we don't want the user's back button to rename things again)
+ } else {
+ //void
+ }
} else {
if (!file_exists($oldfile)) {
- echo ' ' . ERROR_FILE_NOT_EXISTS . '';
+ echo ' ' . ERROR_FILE_NOT_EXISTS . "\n";
} elseif (file_exists($newfile)) {
- echo ' ' . ERROR_FILE_EXISTS . '';
+ echo ' ' . ERROR_FILE_EXISTS . "\n";
} else {
- echo ' ' . ERROR_SOMETHING . '';
+ echo ' ' . ERROR_SOMETHING . "\n";
}
return false;
}
}
+ // used solely by serendipity_parsePropertyForm base_properties when changing the file selected path within mediaproperties form
} elseif ($type == 'filedir') {
serendipity_db_query("UPDATE {$serendipity['dbPrefix']}images
@@ -3499,10 +3635,11 @@ function serendipity_moveMediaDirectory($oldDir, $newDir, $type = 'dir', $item_i
$pick = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}images
WHERE id = " . (int)$item_id, true, 'assoc');
- // Move thumbs
+ // Move thumbs - Rebuild full origin and new file path names by the new picked file array
$oldfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $oldDir . $pick['name'] . (empty($pick['extension']) ? '' : '.' . $pick['extension']);
$newfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $newDir . $pick['name'] . (empty($pick['extension']) ? '' : '.' . $pick['extension']);
+ // hook into staticpage for the renaming regex replacements
$renameValues = array(array(
'from' => $oldfile,
'to' => $newfile,
@@ -3515,46 +3652,35 @@ function serendipity_moveMediaDirectory($oldDir, $newDir, $type = 'dir', $item_i
'file' => $pick,
'name' => $pick['name']
));
-
serendipity_plugin_api::hook_event('backend_media_rename', $renameValues);
- // Rename file
- rename($renameValues[0]['from'], $renameValues[0]['to']);
+ // Move the origin file
+ try { rename($oldfile, $newfile); } catch (Exception $e) { echo ' ' . ERROR_SOMETHING . ': '.$e->getMessage() . "\n"; }
foreach($renameValues AS $renameData) {
- // Rename thumbnail
- @rename($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $oldDir . $pick['name'] . (!empty($renameData['fthumb']) ? '.' . $renameData['fthumb'] : '') . (empty($pick['extension']) ? '' : '.' . $pick['extension']),
- $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $newDir . $pick['name'] . (!empty($pick['thumbnail_name']) ? '.' . $pick['thumbnail_name'] : '') . (empty($pick['extension']) ? '' : '.' . $pick['extension']));
+ $thisOldThumb = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $oldDir . $pick['name'] . (!empty($renameData['fthumb']) ? '.' . $renameData['fthumb'] : '') . (empty($pick['extension']) ? '' : '.' . $pick['extension']);
+ $thisNewThumb = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $newDir . $pick['name'] . (!empty($pick['thumbnail_name']) ? '.' . $pick['thumbnail_name'] : '') . (empty($pick['extension']) ? '' : '.' . $pick['extension']);
+ // Move the thumb file and catch any wrong renaming
+ try { rename($thisOldThumb, $thisNewThumb); } catch (Exception $e) { echo ' ' . ERROR_SOMETHING . ': '.$e->getMessage() . "\n"; }
}
+ // no need to use serendipity_updateImageInDatabase() here since already done in this case start
+ // ???? Forward user to overview (we don't want the user's back button to rename things again)
- $oldDir .= $pick['name'];
- $newDir .= $pick['name'];
- $hasExt = isset($pick['extension']) ? '.'.$pick['extension'] : '';
+ // prepare for message
+ $thisnew = (empty($newDir) ? $serendipity['uploadPath'] : '') . $newDir . $pick['name'];
+ $thisExt = isset($pick['extension']) ? '.'.$pick['extension'] : '';
if (file_exists($newfile)) {
echo ' ';
- printf(MEDIA_DIRECTORY_MOVED, $newDir . $hasExt);
+ printf(MEDIA_DIRECTORY_MOVED, $thisnew . $thisExt);
echo "\n";
}
- } elseif ($type == 'dir') {
+ } // case dir, file, filedir end
- $renameValues = array(array(
- 'from' => $oldfile,
- 'to' => $newfile,
- 'thumb' => $serendipity['thumbSuffix'],
- 'fthumb' => $file['thumbnail_name'],
- 'oldDir' => $oldDir,
- 'newDir' => $newDir,
- 'type' => $type,
- 'item_id' => $item_id,
- 'file' => $file
- ));
+ // Entry REPLACEMENT AREA
- serendipity_plugin_api::hook_event('backend_media_rename', $renameValues);
- }
-
- // Only MySQL supported, since I don't know how to use REGEXPs differently.
+ // Only MySQL supported, since I don't know how to use REGEXPs differently. // Ian: we should improve this to all!
if ($serendipity['dbType'] != 'mysql' && $serendipity['dbType'] != 'mysqli') {
echo ' ' . MEDIA_DIRECTORY_MOVE_ENTRY . "\n";
return true;
@@ -3562,58 +3688,75 @@ function serendipity_moveMediaDirectory($oldDir, $newDir, $type = 'dir', $item_i
// Prepare the SELECT query for filetypes
if ($type == 'filedir' || $type == 'file') {
+
+ // get the right $file, which is array or null, by type
$_file = ($type == 'filedir') ? $pick : $file;
- $oldDir = ($type == 'file') ? str_replace($_file['name'].'.', '', $oldDir) : $oldDir;
+ // check oldDir in bulkmove case
+ $oldDir = ($type == 'file' && !is_null($oldDir)) ? str_replace($_file['name'].'.'.$_file['extension'], '', $oldDir) : $oldDir;
// Path patterns to SELECT en detail to not pick path parts in a loop
- $oldDirThumb = $oldDir . $_file['name'] . '.' . $_file['thumbnail_name'] . (($_file['extension']) ? '.'.$_file['extension'] : '');
- $oldDirFile = $oldDir . $_file['name'] . (($_file['extension']) ? '.'.$_file['extension'] : '');
- $quickblogFilePath = $serendipity['serendipityPath'] . $serendipity['uploadHTTPPath'] . $oldDirFile;
-
- // REPLACE BY Path and Name only to also match Thumbs
- if (strpos($oldDir, $_file['name']) === FALSE) {
- $oldDir .= $_file['name'];
+ if ($oldDir === null) {// care for file renaming with oldpath
+ $oldDirFile = $_file['path'] . $_file['name'] . (($_file['extension']) ? '.'.$_file['extension'] : '');
+ $oldDirThumb = $_file['path'] . $_file['name'] . '.' . $_file['thumbnail_name'] . (($_file['extension']) ? '.'.$_file['extension'] : '');
+ } else {
+ $oldDirFile = $oldDir . $_file['name'] . (($_file['extension']) ? '.'.$_file['extension'] : '');
+ $oldDirThumb = $oldDir . $_file['name'] . '.' . $_file['thumbnail_name'] . (($_file['extension']) ? '.'.$_file['extension'] : '');
}
- if (strpos($newDir, $_file['name']) === FALSE) {
- $newDir .= $_file['name'];
+ if ($type == 'filedir' && !isset($newDirFile)) {
+ $newDirFile = (strpos($newDir, $_file['name']) === FALSE) ? $newDir . $_file['name'] : $newDir;
}
- // imageselectorplus plugin quickblog is either quickblog:FullPath or quickblog:none|FullPath or quickblog:|(plugin|js|_blankl)|FullPath
- // For a possible future isp regex change, we search for 'none' between pipes too
- $q = "SELECT id, body, extended
- FROM {$serendipity['dbPrefix']}entries
- WHERE body REGEXP '(src=|href=|window.open.|