Commit 4ab2d6e1 by Scott

More robust query for CKeditor smiley plugin

parent 923dcc08
......@@ -28,29 +28,33 @@ class qa_wysiwyg_ajax
return $request == 'wysiwyg-editor-ajax';
}
// Fix path to WYSIWYG editor smilies
// Fix path to WYSIWYG editor smileys
public function process_request($request)
{
require_once QA_INCLUDE_DIR.'qa-app-posts.php';
// smiley replacement regexes
$rxSearch = '#<(img|a)([^>]+)(src|href)="([^"]+)/wysiwyg-editor/plugins/smiley/images/([^"]+)"#';
$rxSearch = '<(img|a)([^>]+)(src|href)="([^"]+)/wysiwyg-editor/plugins/smiley/images/([^"]+)"';
$rxReplace = '<$1$2$3="$4/wysiwyg-editor/ckeditor/plugins/smiley/images/$5"';
qa_suspend_event_reports(true); // avoid infinite loop
$sql = 'SELECT postid, title, content FROM ^posts WHERE format="html" AND content LIKE "%/wysiwyg-editor/plugins/smiley/images/%" LIMIT 5';
$result = qa_db_query_sub($sql);
// prevent race conditions
$locks = array('posts', 'categories', 'users', 'users AS lastusers', 'userpoints', 'words', 'titlewords', 'contentwords', 'tagwords', 'words AS x', 'posttags', 'options');
foreach ($locks as &$tbl)
$tbl = '^'.$tbl.' WRITE';
qa_db_query_sub('LOCK TABLES ' . implode(',', $locks));
$sql =
'SELECT postid, title, content FROM ^posts WHERE format="html" ' .
'AND content LIKE "%/wysiwyg-editor/plugins/smiley/images/%" ' .
'AND content RLIKE \'' . $rxSearch . '\' ' .
'LIMIT 5';
$result = qa_db_query_sub($sql);
$numPosts = 0;
while (($post=qa_db_read_one_assoc($result, true)) !== null) {
$newcontent = preg_replace($rxSearch, $rxReplace, $post['content']);
$newcontent = preg_replace("#$rxSearch#", $rxReplace, $post['content']);
qa_post_set_content($post['postid'], $post['title'], $newcontent);
$numPosts++;
}
......
......@@ -87,7 +87,7 @@ class qa_wysiwyg_editor
' return false;',
'});',
);
$ajaxHtml = 'Update broken images from old CKeditor Smilie plugin: ' .
$ajaxHtml = 'Update broken images from old CKeditor Smiley plugin: ' .
'<button id="wysiwyg_editor_ajax">click here</button> ' .
'<script>' . implode("\n", $js) . '</script>';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment