the second problem:
moving ONE Image from folder1 to folder2 has the result: the path of every other image in folder1 will be changed to folder2 in the staticpage-sourcecode (but of course, these other images are not moved into folder2).
problem: the hook-call only gives the path(=folder-name) of origin and destination, not the image-name. So the regex finds and changes all staticpages with an image of folder1 - with the one, right image, but even with all the other images!
problem 3:
As I see in functions_images all the regex-code works only with mysql(i)
Code: Select all
// Only MySQL supported, since I don't know how to use REGEXPs differently.
The code you add into the staticpage-php is similar to the code in functions_images, so I think, these code needs mysql(i), too. Right?
Solution to all problems:
in the moment, in functions_images the hook is called in every of the three if-clauses - but it is allways the same code!
We can delete the new code in all theses if-clauses!
and then add after:
Code: Select all
// Only MySQL supported, since I don't know how to use REGEXPs differently.
if ($serendipity['dbType'] != 'mysql' && $serendipity['dbType'] != 'mysqli') {
echo MEDIA_DIRECTORY_MOVE_ENTRY . '<br />';
return true;
}
$q = "SELECT id, body, extended
FROM {$serendipity['dbPrefix']}entries
WHERE body REGEXP '(src=|href=|window.open.)(\'|\")(" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $oldDir) . "|" . serendipity_db_escape_string($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $oldDir) . ")'
OR extended REGEXP '(src=|href=|window.open.)(\'|\")(" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $oldDir) . "|" . serendipity_db_escape_string($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $oldDir) . ")'
";
$dirs = serendipity_db_query($q);
if (is_array($dirs)) {
foreach($dirs AS $dir) {
$dir['body'] = preg_replace('@(src=|href=|window.open.)(\'|")(' . preg_quote($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $oldDir) . '|' . preg_quote($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $oldDir) . ')@', '\1\2' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $newDir, $dir['body']);
$dir['extended'] = preg_replace('@(src=|href=|window.open.)(\'|")(' . preg_quote($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $oldDir) . '|' . preg_quote($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $oldDir) . ')@', '\1\2' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $newDir, $dir['extended']);
$uq = "UPDATE {$serendipity['dbPrefix']}entries
SET body = '" . serendipity_db_escape_string($dir['body']) . "' ,
extended = '" . serendipity_db_escape_string($dir['extended']) . "'
WHERE id = " . serendipity_db_escape_string($dir['id']);
serendipity_db_query($uq);
}
printf(MEDIA_DIRECTORY_MOVE_ENTRIES . '<br />', count($dirs));
}
this:
Code: Select all
$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
));
serendipity_plugin_api::hook_event('backend_media_rename', $renameValues);
return true;
}
advantage:
$oldDir and $newDir are allways with the right and needed content - because the sql-statement for the entries gets the same values! It has the folder when moving an entire folder. It has the folder+filename if only a file is moved or renamed.
and all these code - which works only with mysql(i) - is behind the mysql-test. Or, if you think, that the hook should be called even if there is not mysql(i), - perhaps some further plugin would use it for something independant from mysql(i) - we can move the new code directly before the
Code: Select all
// Only MySQL supported, since I don't know how to use REGEXPs differently.
But in this case we have to add these mysql(i)-test in the staticpage-php, because this special code needs mysql(i).
btw, so we are able to make the structure of the if-clauses more clean with elseif:
Code: Select all
if ($type == 'dir') {do something
} elseif ($type == 'file') {do something
} elseif ($type == 'filedir') {do something }