Commit 79943c03 by Scott

Fix missing smiley links in WYSIWYG plugin options

parent 4d8804c5
......@@ -42,3 +42,5 @@ if (!defined('QA_VERSION')) { // don't allow this page to be requested directly
qa_register_plugin_module('editor', 'qa-wysiwyg-editor.php', 'qa_wysiwyg_editor', 'WYSIWYG Editor');
qa_register_plugin_module('page', 'qa-wysiwyg-upload.php', 'qa_wysiwyg_upload', 'WYSIWYG Upload');
qa_register_plugin_module('page', 'qa-wysiwyg-ajax.php', 'qa_wysiwyg_ajax', 'WYSIWYG Editor AJAX handler');
......@@ -31,16 +31,33 @@ class qa_wysiwyg_ajax
// Fix path to WYSIWYG editor smilies
public function process_request($request)
{
// todo: lock tables?
// echo '<pre>', print_r(qa_db_list_tables(), true), '</pre>';
require_once QA_INCLUDE_DIR.'qa-app-posts.php';
// smiley replacement regexes
$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);
while (($post=qa_db_read_one_assoc($result, true)) !== null) {
$search = '#<(img|a)([^>]+)(src|href)="([^"]+)/wysiwyg-editor/plugins/smiley/images/([^"]+)"#';
$replace = '<$1$2$3="$4/wysiwyg-editor/ckeditor/plugins/smiley/images/$5"';
$newcontent = preg_replace($search, $replace, $post['content']);
// 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));
$numPosts = 0;
while (($post=qa_db_read_one_assoc($result, true)) !== null) {
$newcontent = preg_replace($rxSearch, $rxReplace, $post['content']);
qa_post_set_content($post['postid'], $post['title'], $newcontent);
$numPosts++;
}
qa_db_query_raw('UNLOCK TABLES');
qa_suspend_event_reports(false);
echo $numPosts;
}
}
......@@ -57,6 +57,40 @@ class qa_wysiwyg_editor
'wysiwyg_editor_upload_max_size_display' => 'wysiwyg_editor_upload_images_field',
));
// handle AJAX requests to 'wysiwyg-editor-ajax'
$js = array(
'function wysiwyg_editor_ajax(totalEdited) {',
' $.ajax({',
' url: ' . qa_js(qa_path('wysiwyg-editor-ajax')) . ',',
' success: function(response) {',
' var postsEdited = parseInt(response, 10);',
' var $btn = $("#wysiwyg_editor_ajax");',
' if (isNaN(postsEdited)) {',
' $btn.text("ERROR");',
' }',
' else if (postsEdited < 5) {',
' $btn.text("All posts converted.");',
' }',
' else {',
' totalEdited += postsEdited;',
' $btn.text("Updating posts... " + totalEdited)',
' window.setTimeout(function() {',
' wysiwyg_editor_ajax(totalEdited);',
' }, 1000);',
' }',
' }',
' });',
'}',
'$("#wysiwyg_editor_ajax").click(function() {',
' wysiwyg_editor_ajax(0);',
' return false;',
'});',
);
$ajaxHtml = 'Update broken images from old CKeditor Smilie plugin: ' .
'<button id="wysiwyg_editor_ajax">click here</button> ' .
'<script>' . implode("\n", $js) . '</script>';
return array(
'ok' => $saved ? 'WYSIWYG editor settings saved' : null,
......@@ -84,6 +118,11 @@ class qa_wysiwyg_editor
'value' => $this->bytes_to_mega_html(qa_opt('wysiwyg_editor_upload_max_size')),
'tags' => 'name="wysiwyg_editor_upload_max_size_field"',
),
array(
'type' => 'custom',
'html' => $ajaxHtml,
),
),
'buttons' => array(
......
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