Allow bulk move ML items to Uploads Root too
Fixes many issues like for renaming files and subdir handling, database placements and other issues. Structures case DIR, FILE and FILE vars for renaming, moving, select and replace. Touches directoryEdit and mediaproperties related boundaries. Adds better event messages, which fixes $ob_serendipity_moveMediaDirectory. Extends and fixes media_items realname issues and changes the length of the item title to be as long as possible. Added new constants to be executed to the lang files in near future, when some follow up commits have been added.
This commit is contained in:
@ -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 '<div class="msg_notice"><span class="icon-attention-circled"></span> ' . sprintf(MULTICHECK_NO_ITEM, $_SERVER['HTTP_REFERER']) . '</div>'."\n";
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ switch ($serendipity['GET']['adminAction']) {
|
||||
$messages = array();
|
||||
$data['case_do_delete'] = true;
|
||||
$messages[] = serendipity_deleteImage($serendipity['GET']['fid']);
|
||||
$messages[] = sprintf('<span class="msg_notice"><span class="icon-info-circled"></span> ' . RIP_ENTRY . '</span>', $serendipity['GET']['fid']);
|
||||
$messages[] = sprintf('<span class="msg_notice"><span class="icon-info-circled"></span> ' . RIP_ENTRY . "</span>\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('<span class="msg_notice"><span class="icon-info-circled"></span> ' . RIP_ENTRY . '</span>', $image['id'] . ' - ' . serendipity_specialchars($image['realname']));
|
||||
$messages[] = sprintf('<span class="msg_notice"><span class="icon-info-circled"></span> ' . RIP_ENTRY . "</span>\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 '<div class="msg_notice"><span class="icon-attention-circled"></span> ' . sprintf(MULTICHECK_NO_ITEM, $_SERVER['HTTP_REFERER']) . '</div>'."\n";
|
||||
break;
|
||||
}
|
||||
if (is_array($serendipity['POST']['multiDelete']) && isset($serendipity['POST']['oldDir']) && empty($serendipity['POST']['newDir'])) {
|
||||
echo '<div class="msg_notice"><span class="icon-attention-circled"></span> ' . sprintf(MULTICHECK_NO_DIR, $_SERVER['HTTP_REFERER']) . '</div>'."\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('<span class="msg_success"><span class="icon-ok-circled"></span> ' . MEDIA_DIRECTORY_MOVED . '</span>', $nDir);
|
||||
$messages[] = sprintf('<span class="msg_success"><span class="icon-ok-circled"></span> ' . MEDIA_DIRECTORY_MOVED . "</span>\n", $nDir);
|
||||
} else {
|
||||
$messages[] = sprintf('<span class="msg_error"><span class="icon-attention-circled"></span> ' . MEDIA_DIRECTORY_MOVE_ERROR . '</span>', $nDir);
|
||||
$messages[] = sprintf('<span class="msg_error"><span class="icon-attention-circled"></span> ' . MEDIA_DIRECTORY_MOVE_ERROR . "</span>\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('<span class="msg_error"><span class="icon-attention-circled"></span> ' . ERROR_FILE_FORBIDDEN . '</span>', $tfile);
|
||||
$messages[] = sprintf('<span class="msg_error"><span class="icon-attention-circled"></span> ' . ERROR_FILE_FORBIDDEN . "</span>\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[] = '<span class="msg_error"><span class="icon-attention-circled"></span> ' . PERM_DENIED . '</span>';
|
||||
$messages[] = '<span class="msg_error"><span class="icon-attention-circled"></span> ' . PERM_DENIED . "</span>\n";
|
||||
return;
|
||||
}
|
||||
|
||||
$realname = $tfile;
|
||||
if (file_exists($target)) {
|
||||
$messages[] = '<span class="msg_error"><span class="icon-attention-circled"></span> ' . $target . ' - ' . ERROR_FILE_EXISTS_ALREADY . '</span>';
|
||||
$messages[] = '<span class="msg_error"><span class="icon-attention-circled"></span> ' . $target . ' - ' . ERROR_FILE_EXISTS_ALREADY . "</span>\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('<span class="msg_error"><span class="icon-attention-circled"></span> ' . REMOTE_FILE_NOT_FOUND . '</span>', $serendipity['POST']['imageurl']);
|
||||
$messages[] = sprintf('<span class="msg_error"><span class="icon-attention-circled"></span> ' . REMOTE_FILE_NOT_FOUND . "</span>\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('<span class="msg_success"><span class="icon-ok-circled"></span> ' . HOTLINK_DONE . '</span>', $serendipity['POST']['imageurl'] , $tfile .'');
|
||||
$messages[] = sprintf('<span class="msg_success"><span class="icon-ok-circled"></span> ' . HOTLINK_DONE . "</span>\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('<span class="msg_success"><span class="icon-ok-circled"></span> ' . FILE_FETCHED . '</span>', $serendipity['POST']['imageurl'] , $tfile . '');
|
||||
$messages[] = sprintf('<span class="msg_success"><span class="icon-ok-circled"></span> ' . FILE_FETCHED . "</span>\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[] = '<span class="msg_success"><span class="icon-ok-circled"></span> ' . THUMB_CREATED_DONE . '</span>';
|
||||
$messages[] = '<span class="msg_success"><span class="icon-ok-circled"></span> ' . THUMB_CREATED_DONE . "</span>\n";
|
||||
}
|
||||
}
|
||||
|
||||
@ -320,14 +327,14 @@ switch ($serendipity['GET']['adminAction']) {
|
||||
$tfile = serendipity_uploadSecure(basename($tfile));
|
||||
|
||||
if (serendipity_isActiveFile($tfile)) {
|
||||
$messages[] = '<span class="msg_error"><span class="icon-attention-circled"></span> ' . ERROR_FILE_FORBIDDEN .' '. $tfile . '</span>';
|
||||
$messages[] = '<span class="msg_error"><span class="icon-attention-circled"></span> ' . ERROR_FILE_FORBIDDEN .' '. $tfile . "</span>\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[] = '<span class="msg_error"><span class="icon-attention-circled"></span> ' . PERM_DENIED . '</span>';
|
||||
$messages[] = '<span class="msg_error"><span class="icon-attention-circled"></span> ' . PERM_DENIED . "</span>\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -335,13 +342,13 @@ switch ($serendipity['GET']['adminAction']) {
|
||||
|
||||
$realname = $tfile;
|
||||
if (file_exists($target)) {
|
||||
$messages[] = '<span class="msg_error"><span class="icon-attention-circled"></span> ' . $target . ' - ' . ERROR_FILE_EXISTS_ALREADY . '</span>';
|
||||
$messages[] = '<span class="msg_error"><span class="icon-attention-circled"></span> ' . $target . ' - ' . ERROR_FILE_EXISTS_ALREADY . "</span>\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('<span class="msg_success"><span class="icon-ok-circled"></span> ' . FILE_UPLOADED . '</span>', $uploadfile , $target);
|
||||
$messages[] = sprintf('<span class="msg_success"><span class="icon-ok-circled"></span> ' . FILE_UPLOADED . "</span>\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[] = '<span class="msg_success"><span class="icon-ok-circled"></span> ' . THUMB_CREATED_DONE . '</span>';
|
||||
$messages[] = '<span class="msg_success"><span class="icon-ok-circled"></span> ' . THUMB_CREATED_DONE . "</span>\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[] = '<span class="msg_error"><span class="icon-attention-circled"></span> ' . ERROR_UNKNOWN_NOUPLOAD . '</span>';
|
||||
$messages[] = '<span class="msg_error"><span class="icon-attention-circled"></span> ' . ERROR_UNKNOWN_NOUPLOAD . "</span>\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);
|
||||
|
||||
|
Reference in New Issue
Block a user