1
0

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.
This commit is contained in:
Ian
2015-10-17 15:03:15 +02:00
parent 732d6067c3
commit 3030b80c2b
5 changed files with 96 additions and 20 deletions

View File

@@ -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

View File

@@ -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'])) {

View File

@@ -40,18 +40,11 @@
</form>
{/if}
{if $case_do_multidelete || $case_do_delete}
{if $showML}{$showML}{/if}
{/if}
{if $case_rename}
{if $go_back}
<input class="go_back" type="button" value="{$CONST.BACK}">
{else}
<script>location.href="?serendipity[adminModule]=images&serendipity[adminAction]=default";</script>
<noscript><a class="button_link icon_link standalone" href="?serendipity[adminModule]=images&amp;serendipity[adminAction]=default">{$CONST.DONE}</a></noscript>
{/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}<span class="msg_error"><span class="icon-attention-circled"></span> {$print_DIRECTORY_WRITE_ERROR}</span>{/if}

View File

@@ -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() == '')
? '<p>{$CONST.DONE}!</p>\
<button id="rename_ok" class="button_link state_submit" type="button" >{$CONST.GO}</button>\
'
: response + '\
<input class="go_back" type="button" onClick="$.magnificPopup.close();" value="{$CONST.BACK}">\
';
$.magnificPopup.open({
items: {
type: 'inline',
src: $('<div id="rename_msg">\
<h4>{$CONST.MEDIA_RENAME}</h4>\
'+ $response +'\
</div>')
},
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: $('<div id="rename_msg">\
<h4>{$CONST.MEDIA_RENAME}</h4>\
<p>"Status: " + textStatus</p>\
'+ errorThrown +'\
<button id="rename_error" class="button_link state_submit" type="button" >{$CONST.GO}</button>\
</div>')
},
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';
});
},
}
});
}
});
}
}

View File

@@ -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;