From 3030b80c2be5292a0d50922ffa04deacbf65fb39 Mon Sep 17 00:00:00 2001 From: Ian Date: Sat, 17 Oct 2015 15:03:15 +0200 Subject: [PATCH] fix rename media file reload issue References #370 and allow better umlaut conversion This is a plain javascript event, therefore the message and reload stuff had to move into the JS caller. --- docs/NEWS | 5 ++ include/admin/images.inc.php | 23 +++++--- templates/2k11/admin/images.inc.tpl | 13 +---- .../2k11/admin/serendipity_editor.js.tpl | 56 ++++++++++++++++++- templates/2k11/admin/style.css | 19 +++++++ 5 files changed, 96 insertions(+), 20 deletions(-) diff --git a/docs/NEWS b/docs/NEWS index 5995e118..0ddbf749 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -1,6 +1,11 @@ Version 2.1 () ------------------------------------------------------------------------ + * Fixed media item rename handler (#370) + + * Fixed and enhanced multiple media redirects and path / name + related issues, as well as some better umlaut conversions + * Allow strict media directory selection by toggle filter * Allow a better auto char conversion to media upload item names diff --git a/include/admin/images.inc.php b/include/admin/images.inc.php index 7986d7cc..553b0870 100644 --- a/include/admin/images.inc.php +++ b/include/admin/images.inc.php @@ -173,18 +173,22 @@ switch ($serendipity['GET']['adminAction']) { break; case 'rename': - $data['case_rename'] = true; $serendipity['GET']['fid'] = (int)$serendipity['GET']['fid']; $file = serendipity_fetchImageFromDatabase($serendipity['GET']['fid']); - $serendipity['GET']['newname'] = serendipity_uploadSecure($serendipity['GET']['newname'], true); + + if (LANG_CHARSET == 'UTF-8') { + // yeah, turn on content to be a real utf-8 string, which it isn't at this point! Else serendipity_makeFilename() can not work! + $serendipity['GET']['newname'] = utf8_encode($serendipity['GET']['newname']); + } + $serendipity['GET']['newname'] = str_replace(' ', '_', $serendipity['GET']['newname']); // keep serendipity_uploadSecure(URL) whitespace convert behaviour, when using serendipity_makeFilename() + $serendipity['GET']['newname'] = serendipity_uploadSecure(serendipity_makeFilename($serendipity['GET']['newname']), true); if (!is_array($file) || !serendipity_checkFormToken() || !serendipity_checkPermission('adminImagesDelete') || (!serendipity_checkPermission('adminImagesMaintainOthers') && $file['authorid'] != '0' && $file['authorid'] != $serendipity['authorid'])) { return; } - if (!serendipity_moveMediaDirectory(null, $serendipity['GET']['newname'], 'file', $serendipity['GET']['fid'], $file)) { - $data['go_back'] = true; - } + // since this is a javascript action only, all event success/error action messages have moved into js + serendipity_moveMediaDirectory(null, $serendipity['GET']['newname'], 'file', $serendipity['GET']['fid'], $file); break; case 'properties': @@ -218,7 +222,7 @@ switch ($serendipity['GET']['adminAction']) { $serendipity['POST']['imageurl'] = serendipity_specialchars($serendipity['POST']['imageurl']); - // First find out whether to fetch a file or accept an upload + // First find out whether to fetch a hotlink file or accept an upload if ($serendipity['POST']['imageurl'] != '' && $serendipity['POST']['imageurl'] != 'http://') { if (!empty($serendipity['POST']['target_filename'][2])) { // Faked hidden form 2 when submitting with JavaScript @@ -233,7 +237,7 @@ switch ($serendipity['GET']['adminAction']) { $tindex = 1; } - $tfile = str_replace(' ', '_', basename($tfile)); // keep serendipity_uploadSecure(URL) whitespace convert behaviour + $tfile = str_replace(' ', '_', basename($tfile)); // keep serendipity_uploadSecure(URL) whitespace convert behaviour, when using serendipity_makeFilename() $tfile = serendipity_uploadSecure(serendipity_makeFilename($tfile)); if (serendipity_isActiveFile($tfile)) { @@ -336,7 +340,7 @@ switch ($serendipity['GET']['adminAction']) { continue; } - $tfile = str_replace(' ', '_', basename($tfile)); // keep serendipity_uploadSecure(URL) whitespace convert behaviour + $tfile = str_replace(' ', '_', basename($tfile)); // keep serendipity_uploadSecure(URL) whitespace convert behaviour, when using serendipity_makeFilename() $tfile = serendipity_uploadSecure(serendipity_makeFilename($tfile)); if (serendipity_isActiveFile($tfile)) { @@ -689,7 +693,7 @@ switch ($serendipity['GET']['adminAction']) { return; } - $data['extraParems'] = serendipity_generateImageSelectorParems("form"); + $data['extraParems'] = serendipity_generateImageSelectorParems('form'); $data['case_scaleSelect'] = true; $s = getimagesize($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['path'] . $file['name'] . ($file['extension'] ? '.'. $file['extension'] : "")); $data['img_width'] = $s[0]; @@ -731,6 +735,7 @@ switch ($serendipity['GET']['adminAction']) { $data['case_default'] = true; $data['showML'] = showMediaLibrary(); break; + } if (! isset($data['showML'])) { diff --git a/templates/2k11/admin/images.inc.tpl b/templates/2k11/admin/images.inc.tpl index ca6bd07a..71e61073 100644 --- a/templates/2k11/admin/images.inc.tpl +++ b/templates/2k11/admin/images.inc.tpl @@ -40,18 +40,11 @@ {/if} {if $case_do_multidelete || $case_do_delete} - {if $showML}{$showML}{/if} -{/if} -{if $case_rename} - {if $go_back} - - {else} - - - {/if} + {if isset($showML)}{$showML}{/if} {/if} +{* A $case_rename can not respond to reload page while in JS - serendipity.rename() ajax will reload and set message events by script *} {if $case_add} - {$showML} + {if isset($showML)}{$showML}{/if} {/if} {if $case_directoryDoDelete} {if $print_DIRECTORY_WRITE_ERROR} {$print_DIRECTORY_WRITE_ERROR}{/if} diff --git a/templates/2k11/admin/serendipity_editor.js.tpl b/templates/2k11/admin/serendipity_editor.js.tpl index 479a71f8..6b072c3c 100644 --- a/templates/2k11/admin/serendipity_editor.js.tpl +++ b/templates/2k11/admin/serendipity_editor.js.tpl @@ -497,7 +497,61 @@ var media_rename = '{$CONST.ENTER_NEW_NAME}'; if (newname = prompt(media_rename + fname, fname)) { var media_token_url = $('input[name*="serendipity[token]"]').val(); - $.post('?serendipity[adminModule]=images&serendipity[adminAction]=rename&serendipity[fid]='+ escape(id) +'&serendipity[newname]='+ escape(newname) +'&serendipity[token]='+ media_token_url); + $.ajax({ + type: 'POST', + url: '?serendipity[adminModule]=images&serendipity[adminAction]=rename&serendipity[fid]='+ escape(id) +'&serendipity[newname]='+ escape(newname) +'&serendipity[token]='+ media_token_url, + async: true, + cache: false, + success: function(response) { + $response = (response.trim() == '') + ? '

{$CONST.DONE}!

\ + \ + ' + : response + '\ + \ + '; + $.magnificPopup.open({ + items: { + type: 'inline', + src: $('
\ +

{$CONST.MEDIA_RENAME}

\ + '+ $response +'\ +
') + }, + type: 'inline', + midClick: true, + callbacks: { + open: function() { + this.content.on('click', '#rename_ok', function() { + window.parent.parent.location.href= '?serendipity[adminModule]=images&serendipity[adminAction]=default'; + }); + }, + } + }); + }, + error: function(XMLHttpRequest, textStatus, errorThrown) { + $.magnificPopup.open({ + items: { + type: 'inline', + src: $('
\ +

{$CONST.MEDIA_RENAME}

\ +

"Status: " + textStatus

\ + '+ errorThrown +'\ + \ +
') + }, + type: 'inline', + midClick: true, + callbacks: { + open: function() { + this.content.on('click', '#rename_error', function() { + window.parent.parent.location.href= '?serendipity[adminModule]=images&serendipity[adminAction]=default'; + }); + }, + } + }); + } + }); } } diff --git a/templates/2k11/admin/style.css b/templates/2k11/admin/style.css index f0ded630..1d2621a6 100644 --- a/templates/2k11/admin/style.css +++ b/templates/2k11/admin/style.css @@ -1859,6 +1859,25 @@ form > .button_link:first-of-type, padding-bottom: .583335em; } +.mfp-content #rename_msg { + width: 40em; + background-color: #FFF; + text-align: center; + margin: auto; + border: 2px double #00FFDB; + padding: 0.5em; +} +.mfp-content #rename_ok { + margin-bottom: 1em; + color: #FFF; + text-shadow: inherit; +} +.mfp-content #rename_msg button.mfp-close { + display: none; + visibility: hidden; + overflow: hidden; +} + .taxonomy h3:hover, .taxonomy li:hover { cursor: pointer;