Skip to content

Commit

Permalink
fix entry replacements on image MOVE
Browse files Browse the repository at this point in the history
now matches thumbs too and tries to be as strict as possible and necessary fixing any move

Staticpages Dev will be fixed in v.4.51 for SP entries
  • Loading branch information
ophian committed Aug 26, 2015
1 parent 300bdd6 commit c80fc3d
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions include/functions_images.inc.php
Expand Up @@ -3557,11 +3557,30 @@ function serendipity_moveMediaDirectory($oldDir, $newDir, $type = 'dir', $item_i
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) . ")'
";
// prepare the SELECT query for filetypes
if ($type == 'filedir' || $type == 'file') {
$_file = ($type == 'filedir') ? $pick : $file;
// Path patterns to SELECT en detail
$oldDirThumb = $oldDir . $_file['name'] . '.' . $_file['thumbnail_name'] . (($_file['extension']) ? '.'.$_file['extension'] : '');
$newDirThumb = $newDir . $_file['name'] . '.' . $_file['thumbnail_name'] . (($_file['extension']) ? '.'.$_file['extension'] : '');
$oldDirFile = $oldDir . $_file['name'] . (($_file['extension']) ? '.'.$_file['extension'] : '');
$newDirFile = $newDir . $_file['name'] . (($_file['extension']) ? '.'.$_file['extension'] : '');
// REPLACE BY Path and Name only to also match Thumbs
$oldDir .= $_file['name'];
$newDir .= $_file['name'];

$q = "SELECT id, body, extended
FROM {$serendipity['dbPrefix']}entries
WHERE body REGEXP '(src=|href=|window.open.)(\'|\")(" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $oldDirFile) . "|" . serendipity_db_escape_String($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $oldDirFile) . "|" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $oldDirThumb) . "|" . serendipity_db_escape_String($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $oldDirThumb) . ")'
OR extended REGEXP '(src=|href=|window.open.)(\'|\")(" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $oldDirFile) . "|" . serendipity_db_escape_String($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $oldDirFile) . "|" . serendipity_db_escape_String($serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $oldDirThumb) . "|" . serendipity_db_escape_String($serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $oldDirThumb) . ")'
";
} else {
$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)) {
Expand Down

2 comments on commit c80fc3d

@ophian
Copy link
Member Author

@ophian ophian commented on c80fc3d Aug 28, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the body entry I need help with another regular expression matching quickblog db entries.
$quickblogFilePath = $serendipity['serendipityPath'] . $serendipity['uploadHTTPPath'] . $oldDirFile;
Plugin isp quickblogs old entry pattern is <!--quickblog:TheFullPath--> and quickblogs new entry patterns are either <!--quickblog:(|[none|plugin|js|_blank]|)TheFullPath--> merged into this line WHERE body REGEXP '(src=|href=|window.open.)(\'|\")(HERE_ALL_THE_OTHERS" . serendipity_db_escape_String($quickblogFilePath) . ")'
Any ideas? @garvinhicking

@ophian
Copy link
Member Author

@ophian ophian commented on c80fc3d Aug 29, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I got it in 44689de commit.

Please sign in to comment.