示例#1
0
 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/([^"]+)"';
     $rxReplace = '<$1$2$3="$4/wysiwyg-editor/ckeditor/plugins/smiley/images/$5"';
     qa_suspend_event_reports(true);
     // avoid infinite loop
     // 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']);
         qa_post_set_content($post['postid'], $post['title'], $newcontent);
         $numPosts++;
     }
     qa_db_query_raw('UNLOCK TABLES');
     qa_suspend_event_reports(false);
     echo $numPosts;
 }
 function process_event($event, $userid, $handle, $cookieid, $params)
 {
     // only interested in q_post & q_edit
     if ($event != 'q_post' && $event != 'q_edit') {
         return;
     }
     // get config data
     $config = qa_opt('tag_synonyms');
     if (!$config) {
         return;
     }
     $oldtags = qa_tagstring_to_tags($params['tags']);
     $synonyms = $this->_synonyms_to_array($config);
     $newtags = $this->_convert_tags($oldtags, $synonyms);
     // updating content would trigger another event, so we suspend events to avoid an infinite loop
     qa_suspend_event_reports(true);
     qa_post_set_content($params['postid'], $params['title'], $params['content'], $params['format'], $newtags);
     qa_suspend_event_reports(false);
 }