there is a bitchy bug in the backend_media_rename part:
Moving a picture into another image-folder, all appearances in articles are changed in the database, so every article has imge-links to the new path.
serendipity_event_staticpage does the some for the appearances in static pages. BUT: Not only the path of the moved picture is changed in the database - ALL pathes for pictures in the same old-dir are changed (of course the pictures themselve are not moved), so in every static page there are wrong urls pointing to the new path of the one picture which should moved!
code problem:
the backend_media_rename part in the plugin does not know the name of the moved picture, only the path, so it changed them all
solution:
staticpage must differ between a renaming of a directory-name (type=dir) and the moving of one single picture (type=filedir)
serendipity_event_staticpage old line 2705:
Code: Select all
case 'backend_media_rename':
// Only MySQL supported, since I don't know how to use REGEXPs differently.
if ($serendipity['dbType'] != 'mysql' && $serendipity['dbType'] != 'mysqli') {
echo STATICPAGE_MEDIA_DIRECTORY_MOVE_ENTRY . '<br />';
break;
}
if (!isset($eventData[0]['oldDir'])) {
return true;
}
$q = "SELECT id, content, pre_content
FROM {$serendipity['dbPrefix']}staticpages
WHERE content REGEXP '(src=|href=|window.open.)(\'|\")(" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . "|" . serendipity_db_escape_string($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ")'
OR pre_content REGEXP '(src=|href=|window.open.)(\'|\")(" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . "|" . serendipity_db_escape_string($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ")'
";
$dirs = serendipity_db_query($q);
if (is_array($dirs)) {
foreach($dirs AS $dir) {
$dir['content'] = preg_replace('@(src=|href=|window.open.)(\'|")(' . preg_quote($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . '|' . preg_quote($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ')@', '\1\2' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['newDir'], $dir['content']);
$dir['pre_content'] = preg_replace('@(src=|href=|window.open.)(\'|")(' . preg_quote($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . '|' . preg_quote($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ')@', '\1\2' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['newDir'], $dir['pre_content']);
$uq = "UPDATE {$serendipity['dbPrefix']}staticpages
SET content = '" . serendipity_db_escape_string($dir['content']) . "' ,
pre_content = '" . serendipity_db_escape_string($dir['pre_content']) . "'
WHERE id = " . serendipity_db_escape_string($dir['id']);
serendipity_db_query($uq);
}
printf(STATICPAGE_MEDIA_DIRECTORY_MOVE_ENTRIES . '<br />', count($dirs));
}
break;
Code: Select all
case 'backend_media_rename':
// Only MySQL supported, since I don't know how to use REGEXPs differently.
if ($serendipity['dbType'] != 'mysql' && $serendipity['dbType'] != 'mysqli') {
echo STATICPAGE_MEDIA_DIRECTORY_MOVE_ENTRY . '<br />';
break;
}
if (!isset($eventData[0]['oldDir'])) {
return true;
}
if ($eventData[0]['type'] == 'dir'){
$q = "SELECT id, content, pre_content
FROM {$serendipity['dbPrefix']}staticpages
WHERE content REGEXP '(src=|href=|window.open.)(\'|\")(" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . "|" . serendipity_db_escape_string($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ")'
OR pre_content REGEXP '(src=|href=|window.open.)(\'|\")(" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . "|" . serendipity_db_escape_string($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ")'
";
$dirs = serendipity_db_query($q);
if (is_array($dirs)) {
foreach($dirs AS $dir) {
$dir['content'] = preg_replace('@(src=|href=|window.open.)(\'|")(' . preg_quote($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . '|' . preg_quote($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ')@', '\1\2' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['newDir'], $dir['content']);
$dir['pre_content'] = preg_replace('@(src=|href=|window.open.)(\'|")(' . preg_quote($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . '|' . preg_quote($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ')@', '\1\2' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['newDir'], $dir['pre_content']);
$uq = "UPDATE {$serendipity['dbPrefix']}staticpages
SET content = '" . serendipity_db_escape_string($dir['content']) . "' ,
pre_content = '" . serendipity_db_escape_string($dir['pre_content']) . "'
WHERE id = " . serendipity_db_escape_string($dir['id']);
serendipity_db_query($uq);
}
printf(STATICPAGE_MEDIA_DIRECTORY_MOVE_ENTRIES . '<br />', count($dirs));
printf($eventData[0]['type']);
}
}
if ($eventData[0]['type'] == 'filedir'){
$eventData[0]['oldDir'] .= $eventData[0]['name'];
$eventData[0]['newDir'] .= $eventData[0]['name'];
$q = "SELECT id, content, pre_content
FROM {$serendipity['dbPrefix']}staticpages
WHERE content REGEXP '(src=|href=|window.open.)(\'|\")(" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . "|" . serendipity_db_escape_string($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ")'
OR pre_content REGEXP '(src=|href=|window.open.)(\'|\")(" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . "|" . serendipity_db_escape_string($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ")'
";
$dirs = serendipity_db_query($q);
if (is_array($dirs)) {
foreach($dirs AS $dir) {
$dir['content'] = preg_replace('@(src=|href=|window.open.)(\'|")(' . preg_quote($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . '|' . preg_quote($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ')@', '\1\2' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['newDir'], $dir['content']);
$dir['pre_content'] = preg_replace('@(src=|href=|window.open.)(\'|")(' . preg_quote($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . '|' . preg_quote($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['oldDir']) . ')@', '\1\2' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $eventData[0]['newDir'], $dir['pre_content']);
$uq = "UPDATE {$serendipity['dbPrefix']}staticpages
SET content = '" . serendipity_db_escape_string($dir['content']) . "' ,
pre_content = '" . serendipity_db_escape_string($dir['pre_content']) . "'
WHERE id = " . serendipity_db_escape_string($dir['id']);
serendipity_db_query($uq);
}
printf(STATICPAGE_MEDIA_DIRECTORY_MOVE_ENTRIES . '<br />', count($dirs));
}
}
line 3378:
Code: Select all
} elseif ($type == 'filedir') {
serendipity_db_query("UPDATE {$serendipity['dbPrefix']}images
SET path = '" . serendipity_db_escape_string($newDir) . "'
WHERE id = " . (int)$item_id);
$pick = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}images
WHERE id = " . (int)$item_id, true, 'assoc');
// Move thumbs
$oldfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $oldDir . $pick['name'] . '.' . $pick['extension'];
$newfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $newDir . $pick['name'] . '.' . $pick['extension'];
$renameValues = array(array(
'from' => $oldfile,
'to' => $newfile,
'thumb' => $serendipity['thumbSuffix'],
'fthumb' => $pick['thumbnail_name'],
'oldDir' => $oldDir,
'newDir' => $newDir,
'type' => $type,
'item_id'=> $item_id,
'file' => $file,
'name' => $pick['name']
));