public function q_list($q_list)
 {
     if (!empty($q_list['qs']) && qa_opt('mouseover_content_on')) {
         // first check it is not an empty list and the feature is turned on
         // Collect the question ids of all items in the question list (so we can do this in one DB query)
         $postids = array();
         foreach ($q_list['qs'] as $question) {
             if (isset($question['raw']['postid'])) {
                 $postids[] = $question['raw']['postid'];
             }
         }
         if (!empty($postids)) {
             // Retrieve the content for these questions from the database
             $maxlength = qa_opt('mouseover_content_max_len');
             $result = qa_db_query_sub('SELECT postid, content, format FROM ^posts WHERE postid IN (#)', $postids);
             $postinfo = qa_db_read_all_assoc($result, 'postid');
             // Get the regular expression fragment to use for blocked words and the maximum length of content to show
             $blockwordspreg = qa_get_block_words_preg();
             // Now add the popup to the title for each question
             foreach ($q_list['qs'] as $index => $question) {
                 if (isset($postinfo[$question['raw']['postid']])) {
                     $thispost = $postinfo[$question['raw']['postid']];
                     $text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));
                     $text = preg_replace('/\\s+/', ' ', $text);
                     // Remove duplicated blanks, new line characters, tabs, etc
                     $text = qa_shorten_string_line($text, $maxlength);
                     $title = isset($question['title']) ? $question['title'] : '';
                     $q_list['qs'][$index]['title'] = $this->getHtmlTitle(qa_html($text), $title);
                 }
             }
         }
     }
     parent::q_list($q_list);
     // call back through to the default function
 }
 function q_list($q_list)
 {
     if (count(@$q_list['qs']) && qa_opt('mouseover_content_on')) {
         // first check it is not an empty list and the feature is turned on
         //	Collect the question ids of all items in the question list (so we can do this in one DB query)
         $postids = array();
         foreach ($q_list['qs'] as $question) {
             if (isset($question['raw']['postid'])) {
                 $postids[] = $question['raw']['postid'];
             }
         }
         if (count($postids)) {
             //	Retrieve the content for these questions from the database and put into an array
             $result = qa_db_query_sub('SELECT postid, content, format FROM ^posts WHERE postid IN (#)', $postids);
             $postinfo = qa_db_read_all_assoc($result, 'postid');
             //	Get the regular expression fragment to use for blocked words and the maximum length of content to show
             $blockwordspreg = qa_get_block_words_preg();
             $maxlength = qa_opt('mouseover_content_max_len');
             //	Now add the popup to the title for each question
             foreach ($q_list['qs'] as $index => $question) {
                 $thispost = @$postinfo[$question['raw']['postid']];
                 if (isset($thispost)) {
                     $text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));
                     $text = qa_shorten_string_line($text, $maxlength);
                     $q_list['qs'][$index]['title'] = '<SPAN TITLE="' . qa_html($text) . '">' . @$question['title'] . '</SPAN>';
                 }
             }
         }
     }
     qa_html_theme_base::q_list($q_list);
     // call back through to the default function
 }
Beispiel #3
0
 public function q_list($q_list)
 {
     if (!empty($q_list['qs']) && qa_opt('mouseover_content_on')) {
         // first check it is not an empty list and the feature is turned on
         // Collect the question ids of all items in the question list (so we can do this in one DB query)
         $postids = array();
         foreach ($q_list['qs'] as $question) {
             if (isset($question['raw']['postid'])) {
                 $postids[] = $question['raw']['postid'];
             }
         }
         if (!empty($postids)) {
             // Retrieve the content for these questions from the database and put into an array fetching
             // the minimal amount of characters needed to determine the string should be shortened or not
             $maxlength = qa_opt('mouseover_content_max_len');
             $result = qa_db_query_sub('SELECT postid, LEFT(content, #) content, format FROM ^posts WHERE postid IN (#)', $maxlength + 1, $postids);
             $postinfo = qa_db_read_all_assoc($result, 'postid');
             // Get the regular expression fragment to use for blocked words and the maximum length of content to show
             $blockwordspreg = qa_get_block_words_preg();
             // Now add the popup to the title for each question
             foreach ($q_list['qs'] as $index => $question) {
                 if (isset($postinfo[$question['raw']['postid']])) {
                     $thispost = $postinfo[$question['raw']['postid']];
                     $text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));
                     $text = qa_shorten_string_line($text, $maxlength);
                     $title = isset($question['title']) ? $question['title'] : '';
                     $q_list['qs'][$index]['title'] = sprintf('<span title="%s">%s</span>', qa_html($text), $title);
                 }
             }
         }
     }
     qa_html_theme_base::q_list($q_list);
     // call back through to the default function
 }
function qa_wall_add_post($userid, $handle, $cookieid, $touserid, $tohandle, $content, $format)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    require_once QA_INCLUDE_DIR . 'qa-app-format.php';
    require_once QA_INCLUDE_DIR . 'qa-db-messages.php';
    $messageid = qa_db_message_create($userid, $touserid, $content, $format, true);
    qa_db_user_recount_posts($touserid);
    qa_report_event('u_wall_post', $userid, $handle, $cookieid, array('userid' => $touserid, 'handle' => $tohandle, 'messageid' => $messageid, 'content' => $content, 'format' => $format, 'text' => qa_viewer_text($content, $format)));
    return $messageid;
}
 function send_default_emails($event, $userid, $handle, $cookieid, $params)
 {
     switch ($event) {
         case 'q_queue':
         case 'q_requeue':
             if (qa_opt('moderate_notify_admin')) {
                 qw_send_notification(null, qa_opt('feedback_email'), null, $event == 'q_requeue' ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'), $event == 'q_requeue' ? nl2br(qa_lang('emails/remoderate_body')) : nl2br(qa_lang('emails/moderate_body')), array('^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : (strlen(@$oldquestion['name']) ? $oldquestion['name'] : qa_lang('main/anonymous'))), '^p_context' => trim(@$params['title'] . "\n\n" . $params['text']), '^url' => qa_q_path($params['postid'], $params['title'], true), '^a_url' => qa_path_absolute('admin/moderate')));
             }
             break;
         case 'a_queue':
         case 'a_requeue':
             if (qa_opt('moderate_notify_admin')) {
                 qw_send_notification(null, qa_opt('feedback_email'), null, $event == 'a_requeue' ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'), $event == 'a_requeue' ? nl2br(qa_lang('emails/remoderate_body')) : nl2br(qa_lang('emails/moderate_body')), array('^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : (strlen(@$oldanswer['name']) ? $oldanswer['name'] : qa_lang('main/anonymous'))), '^p_context' => $params['text'], '^url' => qa_q_path($params['parentid'], $params['parent']['title'], true, 'A', $params['postid']), '^a_url' => qa_path_absolute('admin/moderate')));
             }
             break;
         case 'c_queue':
         case 'c_requeue':
             if (qa_opt('moderate_notify_admin')) {
                 qw_send_notification(null, qa_opt('feedback_email'), null, $event == 'c_requeue' ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'), $event == 'c_requeue' ? nl2br(qa_lang('emails/remoderate_body')) : nl2br(qa_lang('emails/moderate_body')), array('^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : (strlen(@$oldcomment['name']) ? $oldcomment['name'] : (strlen(@$oldanswer['name']) ? $oldanswer['name'] : qa_lang('main/anonymous')))), '^p_context' => $params['text'], '^url' => qa_q_path($params['questionid'], $params['question']['title'], true, 'C', $params['postid']), '^a_url' => qa_path_absolute('admin/moderate')));
             }
             break;
         case 'q_flag':
         case 'a_flag':
         case 'c_flag':
             $flagcount = $params['flagcount'];
             $oldpost = $params['oldpost'];
             $notifycount = $flagcount - qa_opt('flagging_notify_first');
             if ($notifycount >= 0 && $notifycount % qa_opt('flagging_notify_every') == 0) {
                 qw_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/flagged_subject'), nl2br(qa_lang('emails/flagged_body')), array('^p_handle' => isset($oldpost['handle']) ? $oldpost['handle'] : (strlen($oldpost['name']) ? $oldpost['name'] : qa_lang('main/anonymous')), '^flags' => $flagcount == 1 ? qa_lang_html_sub('main/1_flag', '1', '1') : qa_lang_html_sub('main/x_flags', $flagcount), '^p_context' => trim(@$oldpost['title'] . "\n\n" . qa_viewer_text($oldpost['content'], $oldpost['format'])), '^url' => qa_q_path($params['questionid'], $params['question']['title'], true, $oldpost['basetype'], $oldpost['postid']), '^a_url' => qa_path_absolute('admin/flagged')));
             }
             break;
         case 'u_register':
             if (qa_opt('register_notify_admin')) {
                 qw_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/u_registered_subject'), qa_opt('moderate_users') ? nl2br(qa_lang('emails/u_to_approve_body')) : nl2br(qa_lang('emails/u_registered_body')), array('^u_handle' => $handle, '^url' => qa_path_absolute('user/' . $handle), '^a_url' => qa_path_absolute('admin/approve')));
             }
             break;
     }
 }
function qa_comment_set_status($oldcomment, $status, $userid, $handle, $cookieid, $question, $parent)
{
    require_once QA_INCLUDE_DIR . 'qa-app-format.php';
    if (!isset($parent)) {
        $parent = $question;
    }
    // for backwards compatibility with old answer parameter
    $washidden = $oldcomment['type'] == 'C_HIDDEN';
    $wasqueued = $oldcomment['type'] == 'C_QUEUED';
    $wasrequeued = $wasqueued && isset($oldcomment['updated']);
    qa_post_unindex($oldcomment['postid']);
    $setupdated = false;
    $event = null;
    if ($status == QA_POST_STATUS_QUEUED) {
        $newtype = 'C_QUEUED';
        if (!$wasqueued) {
            $event = 'c_requeue';
        }
        // same event whether it was hidden or shown before
    } elseif ($status == QA_POST_STATUS_HIDDEN) {
        $newtype = 'C_HIDDEN';
        if (!$washidden) {
            $event = $wasqueued ? 'c_reject' : 'c_hide';
            if (!$wasqueued) {
                $setupdated = true;
            }
        }
    } elseif ($status == QA_POST_STATUS_NORMAL) {
        $newtype = 'C';
        if ($wasqueued) {
            $event = 'c_approve';
        } elseif ($washidden) {
            $event = 'c_reshow';
            $setupdated = true;
        }
    } else {
        qa_fatal_error('Unknown status in qa_comment_set_status(): ' . $status);
    }
    qa_db_post_set_type($oldcomment['postid'], $newtype, $setupdated ? $userid : null, $setupdated ? qa_remote_ip_address() : null, QA_UPDATE_VISIBLE);
    if ($wasqueued && $status == QA_POST_STATUS_NORMAL && qa_opt('moderate_update_time')) {
        // ... for approval of a post, can set time to now instead
        if ($wasrequeued) {
            qa_db_post_set_updated($oldcomment['postid'], null);
        } else {
            qa_db_post_set_created($oldcomment['postid'], null);
        }
    }
    qa_db_ccount_update();
    qa_db_points_update_ifuser($oldcomment['userid'], array('cposts'));
    if ($wasqueued || $status == QA_POST_STATUS_QUEUED) {
        qa_db_queuedcount_update();
    }
    if ($oldcomment['flagcount']) {
        qa_db_flaggedcount_update();
    }
    if ($question['type'] == 'Q' && ($parent['type'] == 'Q' || $parent['type'] == 'A') && $status == QA_POST_STATUS_NORMAL) {
        // only index if none of the things it depends on are hidden or queued
        qa_post_index($oldcomment['postid'], 'C', $question['postid'], $oldcomment['parentid'], null, $oldcomment['content'], $oldcomment['format'], qa_viewer_text($oldcomment['content'], $oldcomment['format']), null, $oldcomment['categoryid']);
    }
    $eventparams = array('postid' => $oldcomment['postid'], 'parentid' => $oldcomment['parentid'], 'parenttype' => $parent['basetype'], 'parent' => $parent, 'questionid' => $question['postid'], 'question' => $question, 'content' => $oldcomment['content'], 'format' => $oldcomment['format'], 'text' => qa_viewer_text($oldcomment['content'], $oldcomment['format']), 'categoryid' => $oldcomment['categoryid'], 'name' => $oldcomment['name']);
    if (isset($event)) {
        qa_report_event($event, $userid, $handle, $cookieid, $eventparams + array('oldcomment' => $oldcomment));
    }
    if ($wasqueued && $status == QA_POST_STATUS_NORMAL && !$wasrequeued) {
        require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
        require_once QA_INCLUDE_DIR . 'qa-util-string.php';
        $commentsfollows = qa_db_single_select(qa_db_full_child_posts_selectspec(null, $oldcomment['parentid']));
        $thread = array();
        foreach ($commentsfollows as $comment) {
            if ($comment['type'] == 'C' && $comment['parentid'] == $parent['postid']) {
                $thread[] = $comment;
            }
        }
        qa_report_event('c_post', $oldcomment['userid'], $oldcomment['handle'], $oldcomment['cookieid'], $eventparams + array('thread' => $thread, 'notify' => isset($oldcomment['notify']), 'email' => qa_email_validate($oldcomment['notify']) ? $oldcomment['notify'] : null, 'delayed' => $oldcomment['created']));
    }
}
Beispiel #7
0
function qa_update_post_text(&$fields, $oldfields)
{
    if (strcmp($oldfields['content'], $fields['content']) || strcmp($oldfields['format'], $fields['format']) || strcmp($oldfields['text'], $fields['text'])) {
        $fields['text'] = qa_viewer_text($fields['content'], $fields['format']);
    }
}
function qa_comment_set_hidden($oldcomment, $hidden, $userid, $handle, $cookieid, $question, $parent)
{
    require_once QA_INCLUDE_DIR . 'qa-app-format.php';
    if (!isset($parent)) {
        $parent = $question;
    }
    // for backwards compatibility with old answer parameter
    $wasqueued = $oldcomment['type'] == 'C_QUEUED';
    qa_post_unindex($oldcomment['postid']);
    $setupdated = $hidden || !$wasqueued;
    // don't record approval of a post as an update action...
    qa_db_post_set_type($oldcomment['postid'], $hidden ? 'C_HIDDEN' : 'C', $setupdated ? $userid : null, $setupdated ? qa_remote_ip_address() : null, QA_UPDATE_VISIBLE);
    if (!$setupdated) {
        // ... for approval of a post, set created time to now instead
        qa_db_post_set_created($oldcomment['postid'], null);
    }
    qa_db_points_update_ifuser($oldcomment['userid'], array('cposts'));
    qa_db_ccount_update();
    if ($question['type'] == 'Q' && ($parent['type'] == 'Q' || $parent['type'] == 'A') && !$hidden) {
        // only index if none of the things it depends on are hidden or queued
        qa_post_index($oldcomment['postid'], 'C', $question['postid'], $oldcomment['parentid'], null, $oldcomment['content'], $oldcomment['format'], qa_viewer_text($oldcomment['content'], $oldcomment['format']), null, $oldcomment['categoryid']);
    }
    qa_report_event($wasqueued ? $hidden ? 'c_reject' : 'c_approve' : ($hidden ? 'c_hide' : 'c_reshow'), $userid, $handle, $cookieid, array('postid' => $oldcomment['postid'], 'parentid' => $oldcomment['parentid'], 'oldcomment' => $oldcomment, 'parenttype' => $parent['basetype'], 'questionid' => $question['postid']));
    if ($wasqueued && !$hidden) {
        require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
        require_once QA_INCLUDE_DIR . 'qa-util-string.php';
        $commentsfollows = qa_db_single_select(qa_db_full_child_posts_selectspec(null, $oldcomment['parentid']));
        $thread = array();
        foreach ($commentsfollows as $comment) {
            if ($comment['type'] == 'C' && $comment['parentid'] == $parent['postid']) {
                $thread[] = $comment;
            }
        }
        qa_report_event('c_post', $oldcomment['userid'], $oldcomment['handle'], $oldcomment['cookieid'], array('postid' => $oldcomment['postid'], 'parentid' => $oldcomment['parentid'], 'parenttype' => $parent['basetype'], 'parent' => $parent, 'questionid' => $question['postid'], 'question' => $question, 'thread' => $thread, 'content' => $oldcomment['content'], 'format' => $oldcomment['format'], 'text' => qa_viewer_text($oldcomment['content'], $oldcomment['format']), 'categoryid' => $oldcomment['categoryid'], 'notify' => isset($oldcomment['notify']), 'email' => qa_email_validate($oldcomment['notify']) ? $oldcomment['notify'] : null, 'delayed' => $oldcomment['created']));
    }
}
function qa_recalc_perform_step(&$state)
{
    $continue = false;
    @(list($operation, $length, $next, $done) = explode("\t", $state));
    switch ($operation) {
        case 'doreindexcontent':
            qa_recalc_transition($state, 'doreindexcontent_pagereindex');
            break;
        case 'doreindexcontent_pagereindex':
            $pages = qa_db_pages_get_for_reindexing($next, 10);
            if (count($pages)) {
                require_once QA_INCLUDE_DIR . 'app/format.php';
                $lastpageid = max(array_keys($pages));
                foreach ($pages as $pageid => $page) {
                    if (!($page['flags'] & QA_PAGE_FLAGS_EXTERNAL)) {
                        $searchmodules = qa_load_modules_with('search', 'unindex_page');
                        foreach ($searchmodules as $searchmodule) {
                            $searchmodule->unindex_page($pageid);
                        }
                        $searchmodules = qa_load_modules_with('search', 'index_page');
                        if (count($searchmodules)) {
                            $indextext = qa_viewer_text($page['content'], 'html');
                            foreach ($searchmodules as $searchmodule) {
                                $searchmodule->index_page($pageid, $page['tags'], $page['heading'], $page['content'], 'html', $indextext);
                            }
                        }
                    }
                }
                $next = 1 + $lastpageid;
                $done += count($pages);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'doreindexcontent_postcount');
            }
            break;
        case 'doreindexcontent_postcount':
            qa_db_qcount_update();
            qa_db_acount_update();
            qa_db_ccount_update();
            qa_recalc_transition($state, 'doreindexcontent_postreindex');
            break;
        case 'doreindexcontent_postreindex':
            $posts = qa_db_posts_get_for_reindexing($next, 10);
            if (count($posts)) {
                require_once QA_INCLUDE_DIR . 'app/format.php';
                $lastpostid = max(array_keys($posts));
                qa_db_prepare_for_reindexing($next, $lastpostid);
                qa_suspend_update_counts();
                foreach ($posts as $postid => $post) {
                    qa_post_unindex($postid);
                    qa_post_index($postid, $post['type'], $post['questionid'], $post['parentid'], $post['title'], $post['content'], $post['format'], qa_viewer_text($post['content'], $post['format']), $post['tags'], $post['categoryid']);
                }
                $next = 1 + $lastpostid;
                $done += count($posts);
                $continue = true;
            } else {
                qa_db_truncate_indexes($next);
                qa_recalc_transition($state, 'doreindexposts_wordcount');
            }
            break;
        case 'doreindexposts_wordcount':
            $wordids = qa_db_words_prepare_for_recounting($next, 1000);
            if (count($wordids)) {
                $lastwordid = max($wordids);
                qa_db_words_recount($next, $lastwordid);
                $next = 1 + $lastwordid;
                $done += count($wordids);
                $continue = true;
            } else {
                qa_db_tagcount_update();
                // this is quick so just do it here
                qa_recalc_transition($state, 'doreindexposts_complete');
            }
            break;
        case 'dorecountposts':
            qa_recalc_transition($state, 'dorecountposts_postcount');
            break;
        case 'dorecountposts_postcount':
            qa_db_qcount_update();
            qa_db_acount_update();
            qa_db_ccount_update();
            qa_db_unaqcount_update();
            qa_db_unselqcount_update();
            qa_recalc_transition($state, 'dorecountposts_votecount');
            break;
        case 'dorecountposts_votecount':
            $postids = qa_db_posts_get_for_recounting($next, 1000);
            if (count($postids)) {
                $lastpostid = max($postids);
                qa_db_posts_votes_recount($next, $lastpostid);
                $next = 1 + $lastpostid;
                $done += count($postids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorecountposts_acount');
            }
            break;
        case 'dorecountposts_acount':
            $postids = qa_db_posts_get_for_recounting($next, 1000);
            if (count($postids)) {
                $lastpostid = max($postids);
                qa_db_posts_answers_recount($next, $lastpostid);
                $next = 1 + $lastpostid;
                $done += count($postids);
                $continue = true;
            } else {
                qa_db_unupaqcount_update();
                qa_recalc_transition($state, 'dorecountposts_complete');
            }
            break;
        case 'dorecalcpoints':
            qa_recalc_transition($state, 'dorecalcpoints_usercount');
            break;
        case 'dorecalcpoints_usercount':
            qa_db_userpointscount_update();
            // for progress update - not necessarily accurate
            qa_db_uapprovecount_update();
            // needs to be somewhere and this is the most appropriate place
            qa_recalc_transition($state, 'dorecalcpoints_recalc');
            break;
        case 'dorecalcpoints_recalc':
            $recalccount = 10;
            $userids = qa_db_users_get_for_recalc_points($next, $recalccount + 1);
            // get one extra so we know where to start from next
            $gotcount = count($userids);
            $recalccount = min($recalccount, $gotcount);
            // can't recalc more than we got
            if ($recalccount > 0) {
                $lastuserid = $userids[$recalccount - 1];
                qa_db_users_recalc_points($next, $lastuserid);
                $done += $recalccount;
            } else {
                $lastuserid = $next;
            }
            // for truncation
            if ($gotcount > $recalccount) {
                // more left to do
                $next = $userids[$recalccount];
                // start next round at first one not recalculated
                $continue = true;
            } else {
                qa_db_truncate_userpoints($lastuserid);
                qa_db_userpointscount_update();
                // quick so just do it here
                qa_recalc_transition($state, 'dorecalcpoints_complete');
            }
            break;
        case 'dorefillevents':
            qa_recalc_transition($state, 'dorefillevents_qcount');
            break;
        case 'dorefillevents_qcount':
            qa_db_qcount_update();
            qa_recalc_transition($state, 'dorefillevents_refill');
            break;
        case 'dorefillevents_refill':
            $questionids = qa_db_qs_get_for_event_refilling($next, 1);
            if (count($questionids)) {
                require_once QA_INCLUDE_DIR . 'app/events.php';
                require_once QA_INCLUDE_DIR . 'app/updates.php';
                require_once QA_INCLUDE_DIR . 'util/sort.php';
                $lastquestionid = max($questionids);
                foreach ($questionids as $questionid) {
                    //	Retrieve all posts relating to this question
                    list($question, $childposts, $achildposts) = qa_db_select_with_pending(qa_db_full_post_selectspec(null, $questionid), qa_db_full_child_posts_selectspec(null, $questionid), qa_db_full_a_child_posts_selectspec(null, $questionid));
                    //	Merge all posts while preserving keys as postids
                    $posts = array($questionid => $question);
                    foreach ($childposts as $postid => $post) {
                        $posts[$postid] = $post;
                    }
                    foreach ($achildposts as $postid => $post) {
                        $posts[$postid] = $post;
                    }
                    //	Creation and editing of each post
                    foreach ($posts as $postid => $post) {
                        $followonq = $post['basetype'] == 'Q' && $postid != $questionid;
                        if ($followonq) {
                            $updatetype = QA_UPDATE_FOLLOWS;
                        } elseif ($post['basetype'] == 'C' && @$posts[$post['parentid']]['basetype'] == 'Q') {
                            $updatetype = QA_UPDATE_C_FOR_Q;
                        } elseif ($post['basetype'] == 'C' && @$posts[$post['parentid']]['basetype'] == 'A') {
                            $updatetype = QA_UPDATE_C_FOR_A;
                        } else {
                            $updatetype = null;
                        }
                        qa_create_event_for_q_user($questionid, $postid, $updatetype, $post['userid'], @$posts[$post['parentid']]['userid'], $post['created']);
                        if (isset($post['updated']) && !$followonq) {
                            qa_create_event_for_q_user($questionid, $postid, $post['updatetype'], $post['lastuserid'], $post['userid'], $post['updated']);
                        }
                    }
                    //	Tags and categories of question
                    qa_create_event_for_tags($question['tags'], $questionid, null, $question['userid'], $question['created']);
                    qa_create_event_for_category($question['categoryid'], $questionid, null, $question['userid'], $question['created']);
                    //	Collect comment threads
                    $parentidcomments = array();
                    foreach ($posts as $postid => $post) {
                        if ($post['basetype'] == 'C') {
                            $parentidcomments[$post['parentid']][$postid] = $post;
                        }
                    }
                    //	For each comment thread, notify all previous comment authors of each comment in the thread (could get slow)
                    foreach ($parentidcomments as $parentid => $comments) {
                        $keyuserids = array();
                        qa_sort_by($comments, 'created');
                        foreach ($comments as $comment) {
                            foreach ($keyuserids as $keyuserid => $dummy) {
                                if ($keyuserid != $comment['userid'] && $keyuserid != @$posts[$parentid]['userid']) {
                                    qa_db_event_create_not_entity($keyuserid, $questionid, $comment['postid'], QA_UPDATE_FOLLOWS, $comment['userid'], $comment['created']);
                                }
                            }
                            if (isset($comment['userid'])) {
                                $keyuserids[$comment['userid']] = true;
                            }
                        }
                    }
                }
                $next = 1 + $lastquestionid;
                $done += count($questionids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorefillevents_complete');
            }
            break;
        case 'dorecalccategories':
            qa_recalc_transition($state, 'dorecalccategories_postcount');
            break;
        case 'dorecalccategories_postcount':
            qa_db_acount_update();
            qa_db_ccount_update();
            qa_recalc_transition($state, 'dorecalccategories_postupdate');
            break;
        case 'dorecalccategories_postupdate':
            $postids = qa_db_posts_get_for_recategorizing($next, 100);
            if (count($postids)) {
                $lastpostid = max($postids);
                qa_db_posts_recalc_categoryid($next, $lastpostid);
                qa_db_posts_calc_category_path($next, $lastpostid);
                $next = 1 + $lastpostid;
                $done += count($postids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorecalccategories_recount');
            }
            break;
        case 'dorecalccategories_recount':
            $categoryids = qa_db_categories_get_for_recalcs($next, 10);
            if (count($categoryids)) {
                $lastcategoryid = max($categoryids);
                foreach ($categoryids as $categoryid) {
                    qa_db_ifcategory_qcount_update($categoryid);
                }
                $next = 1 + $lastcategoryid;
                $done += count($categoryids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorecalccategories_backpaths');
            }
            break;
        case 'dorecalccategories_backpaths':
            $categoryids = qa_db_categories_get_for_recalcs($next, 10);
            if (count($categoryids)) {
                $lastcategoryid = max($categoryids);
                qa_db_categories_recalc_backpaths($next, $lastcategoryid);
                $next = 1 + $lastcategoryid;
                $done += count($categoryids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorecalccategories_complete');
            }
            break;
        case 'dodeletehidden':
            qa_recalc_transition($state, 'dodeletehidden_comments');
            break;
        case 'dodeletehidden_comments':
            $posts = qa_db_posts_get_for_deleting('C', $next, 1);
            if (count($posts)) {
                require_once QA_INCLUDE_DIR . 'app/posts.php';
                $postid = $posts[0];
                qa_post_delete($postid);
                $next = 1 + $postid;
                $done++;
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dodeletehidden_answers');
            }
            break;
        case 'dodeletehidden_answers':
            $posts = qa_db_posts_get_for_deleting('A', $next, 1);
            if (count($posts)) {
                require_once QA_INCLUDE_DIR . 'app/posts.php';
                $postid = $posts[0];
                qa_post_delete($postid);
                $next = 1 + $postid;
                $done++;
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dodeletehidden_questions');
            }
            break;
        case 'dodeletehidden_questions':
            $posts = qa_db_posts_get_for_deleting('Q', $next, 1);
            if (count($posts)) {
                require_once QA_INCLUDE_DIR . 'app/posts.php';
                $postid = $posts[0];
                qa_post_delete($postid);
                $next = 1 + $postid;
                $done++;
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dodeletehidden_complete');
            }
            break;
        case 'doblobstodisk':
            qa_recalc_transition($state, 'doblobstodisk_move');
            break;
        case 'doblobstodisk_move':
            $blob = qa_db_get_next_blob_in_db($next);
            if (isset($blob)) {
                require_once QA_INCLUDE_DIR . 'app/blobs.php';
                require_once QA_INCLUDE_DIR . 'db/blobs.php';
                if (qa_write_blob_file($blob['blobid'], $blob['content'], $blob['format'])) {
                    qa_db_blob_set_content($blob['blobid'], null);
                }
                $next = 1 + $blob['blobid'];
                $done++;
                $continue = true;
            } else {
                qa_recalc_transition($state, 'doblobstodisk_complete');
            }
            break;
        case 'doblobstodb':
            qa_recalc_transition($state, 'doblobstodb_move');
            break;
        case 'doblobstodb_move':
            $blob = qa_db_get_next_blob_on_disk($next);
            if (isset($blob)) {
                require_once QA_INCLUDE_DIR . 'app/blobs.php';
                require_once QA_INCLUDE_DIR . 'db/blobs.php';
                $content = qa_read_blob_file($blob['blobid'], $blob['format']);
                qa_db_blob_set_content($blob['blobid'], $content);
                qa_delete_blob_file($blob['blobid'], $blob['format']);
                $next = 1 + $blob['blobid'];
                $done++;
                $continue = true;
            } else {
                qa_recalc_transition($state, 'doblobstodb_complete');
            }
            break;
        default:
            $state = '';
            break;
    }
    if ($continue) {
        $state = $operation . "\t" . $length . "\t" . $next . "\t" . $done;
    }
    return $continue && $done < $length;
}
function qa_flag_set_tohide($post, $userid, $handle, $cookieid, $question)
{
    require_once QA_INCLUDE_DIR . 'qa-db-votes.php';
    require_once QA_INCLUDE_DIR . 'qa-app-limits.php';
    qa_db_userflag_set($post['postid'], $userid, true);
    qa_db_post_recount_flags($post['postid']);
    switch ($post['basetype']) {
        case 'Q':
            $action = 'q_flag';
            break;
        case 'A':
            $action = 'a_flag';
            break;
        case 'C':
            $action = 'c_flag';
            break;
    }
    qa_report_write_action($userid, null, $action, $post['basetype'] == 'Q' ? $post['postid'] : null, $post['basetype'] == 'A' ? $post['postid'] : null, $post['basetype'] == 'C' ? $post['postid'] : null);
    qa_report_event($action, $userid, $handle, $cookieid, array('postid' => $post['postid']));
    $post = qa_db_select_with_pending(qa_db_full_post_selectspec(null, $post['postid']));
    $flagcount = $post['flagcount'];
    $notifycount = $flagcount - qa_opt('flagging_notify_first');
    if ($notifycount >= 0 && $notifycount % qa_opt('flagging_notify_every') == 0) {
        require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
        require_once QA_INCLUDE_DIR . 'qa-app-format.php';
        $anchor = $post['basetype'] == 'Q' ? null : qa_anchor($post['basetype'], $post['postid']);
        qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/flagged_subject'), qa_lang('emails/flagged_body'), array('^p_handle' => isset($post['handle']) ? $post['handle'] : qa_lang('main/anonymous'), '^flags' => $flagcount == 1 ? qa_lang_html_sub('main/1_flag', '1', '1') : qa_lang_html_sub('main/x_flags', $flagcount), '^p_context' => trim(@$post['title'] . "\n\n" . qa_viewer_text($post['content'], $post['format'])), '^url' => qa_path(qa_q_request($question['postid'], $question['title']), null, qa_opt('site_url'), null, $anchor)));
    }
    if ($flagcount >= qa_opt('flagging_hide_after') && !$post['hidden']) {
        return true;
    }
    return false;
}
Beispiel #11
0
 function q_list($q_list)
 {
     if (qa_opt('it_layout_lists') == 'qlist') {
         qa_html_theme_base::q_list($q_list);
         return;
     }
     if (count(@$q_list['qs'])) {
         // first check it is not an empty list and the feature is turned on
         //	Collect the question ids of all items in the question list (so we can do this in one DB query)
         $postids = array();
         foreach ($q_list['qs'] as $question) {
             if (isset($question['raw']['postid'])) {
                 $postids[] = $question['raw']['postid'];
             }
         }
         if (count($postids)) {
             //	Retrieve favourite count
             $userid = qa_get_logged_in_userid();
             $result = qa_db_query_sub('SELECT userid,entityid FROM ^userfavorites WHERE entitytype=$ AND entityid IN (#)', 'Q', $postids);
             while ($row = mysqli_fetch_row($result)) {
                 if ($row[0] == $userid) {
                     // loged in user favorited this post
                     $faved_post[$row[1]] = 1;
                 }
                 if (isset($favs[$row[1]])) {
                     $favs[$row[1]] = $favs[$row[1]] + 1;
                 } else {
                     $favs[$row[1]] = 1;
                 }
             }
             //	Retrieve comment count
             $result = qa_db_query_sub('SELECT postid,parentid FROM ^posts WHERE type=$ AND parentid IN (#)', 'C', $postids);
             $comment_list = qa_db_read_all_assoc($result, 'postid');
             foreach ($comment_list as $key => $value) {
                 if (isset($comments[$value['parentid']])) {
                     $comments[$value['parentid']] = $comments[$value['parentid']] + 1;
                 } else {
                     $comments[$value['parentid']] = 1;
                 }
             }
             if (qa_opt('it_excerpt_field_enable') or qa_opt('it_enable_except')) {
                 //	Get the regular expression fragment to use for blocked words and the maximum length of content to show
                 $blockwordspreg = qa_get_block_words_preg();
                 if (qa_opt('it_excerpt_field_enable')) {
                     $maxlength = qa_opt('it_excerpt_field_length');
                     //	Retrieve Excerpt Text for all questions
                     $result = qa_db_query_sub('SELECT postid,content FROM ^postmetas WHERE postid IN (#) AND title=$', $postids, 'et_excerpt_text');
                     $excerpt_text = qa_db_read_all_assoc($result, 'postid');
                     // set excerpt from field info
                     foreach ($q_list['qs'] as $index => $question) {
                         // from field
                         if (!empty($excerpt_text[$question['raw']['postid']]['content'])) {
                             $text = qa_viewer_text($excerpt_text[$question['raw']['postid']]['content'], '', array('blockwordspreg' => $blockwordspreg));
                             $text = qa_shorten_string_line($text, $maxlength);
                             $q_list['qs'][$index]['excerpt'] = qa_html($text);
                             // from post content
                         } elseif (qa_opt('it_enable_except')) {
                             // Retrieve the content for these questions from the database and put into an array
                             $result = qa_db_query_sub('SELECT postid, content, format FROM ^posts WHERE postid IN (#)', $postids);
                             $postinfo = qa_db_read_all_assoc($result, 'postid');
                             $thispost = @$postinfo[$question['raw']['postid']];
                             if (isset($thispost)) {
                                 $text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));
                                 $text = qa_shorten_string_line($text, $maxlength);
                                 $q_list['qs'][$index]['excerpt'] = qa_html($text);
                             }
                         }
                     }
                 } else {
                     // qa_opt('it_enable_except')  ==> excerpt from question content instead of excerpt field
                     $maxlength = qa_opt('it_except_len');
                     $result = qa_db_query_sub('SELECT postid, content, format FROM ^posts WHERE postid IN (#)', $postids);
                     $postinfo = qa_db_read_all_assoc($result, 'postid');
                     foreach ($q_list['qs'] as $index => $question) {
                         $thispost = @$postinfo[$question['raw']['postid']];
                         if (isset($thispost)) {
                             $text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));
                             $text = qa_shorten_string_line($text, $maxlength);
                             $q_list['qs'][$index]['excerpt'] = qa_html($text);
                         }
                     }
                 }
             }
             //	Retrieve featured images for all list questions
             if (qa_opt('it_feature_img_enable')) {
                 $result = qa_db_query_sub('SELECT postid,content FROM ^postmetas WHERE postid IN (#) AND title=$', $postids, 'et_featured_image');
                 $featured_images = qa_db_read_all_assoc($result, 'postid');
             }
             //	Now meta information for each question
             foreach ($q_list['qs'] as $index => $question) {
                 if (qa_opt('it_feature_img_enable')) {
                     $featured_image = @$featured_images[$question['raw']['postid']]['content'];
                     if (isset($featured_image)) {
                         $q_list['qs'][$index]['featured'] = qa_opt('it_featured_url_abs') . 'featured/' . $featured_image;
                     }
                 }
                 if (isset($comments[$question['raw']['postid']])) {
                     $q_list['qs'][$index]['comments'] = $comments[$question['raw']['postid']];
                 } else {
                     $q_list['qs'][$index]['comments'] = 0;
                 }
                 $q_list['qs'][$index]['favourited'] = 0;
                 if (isset($favs[$question['raw']['postid']])) {
                     $q_list['qs'][$index]['favourites'] = $favs[$question['raw']['postid']];
                     if (isset($faved_post[$question['raw']['postid']])) {
                         $q_list['qs'][$index]['favourited'] = 1;
                     }
                 } else {
                     $q_list['qs'][$index]['favourites'] = 0;
                 }
             }
         }
     }
     if (isset($q_list['qs'])) {
         $this->output('<div class="qa-q-list row' . ($this->list_vote_disabled($q_list['qs']) ? ' qa-q-list-vote-disabled' : '') . '">', '');
         $this->q_list_items($q_list['qs']);
         $this->output('</div> <!-- END qa-q-list -->', '');
     }
 }
function qa_comment_set_hidden($oldcomment, $hidden, $userid, $handle, $cookieid, $question, $answer)
{
    qa_post_unindex($oldcomment['postid']);
    qa_db_post_set_type($oldcomment['postid'], $hidden ? 'C_HIDDEN' : 'C', $userid, qa_remote_ip_address());
    qa_db_points_update_ifuser($oldcomment['userid'], array('cposts'));
    qa_db_ccount_update();
    if (!($hidden || $question['hidden'] || @$answer['hidden'])) {
        // only index if none of the things it depends on are hidden
        require_once QA_INCLUDE_DIR . 'qa-app-format.php';
        qa_post_index($oldcomment['postid'], 'C', $question['postid'], null, qa_viewer_text($oldcomment['content'], $oldcomment['format']), null);
    }
    qa_report_event($hidden ? 'c_hide' : 'c_reshow', $userid, $handle, $cookieid, array('postid' => $oldcomment['postid'], 'parentid' => $oldcomment['parentid'], 'parenttype' => isset($answer) ? $answer['basetype'] : $question['basetype'], 'questionid' => $question['postid']));
}
Beispiel #13
0
    function q_list($q_list)
    {
        if (isset($q_list['qs'])) {
            if (qa_opt('cs_enable_except')) {
                // first check it is not an empty list and the feature is turned on
                //	Collect the question ids of all items in the question list (so we can do this in one DB query)
                $postids = array();
                foreach ($q_list['qs'] as $question) {
                    if (isset($question['raw']['postid'])) {
                        $postids[] = $question['raw']['postid'];
                    }
                }
                if (count($postids)) {
                    //	Retrieve the content for these questions from the database and put into an array
                    //$result         = qa_db_query_sub('SELECT postid, content, format FROM ^posts WHERE postid IN (#)', $postids);
                    //$postinfo       = qa_db_read_all_assoc($result, 'postid');
                    //cache and apply keys to array now that I can't use array key argument in qa_db_read_all_assoc
                    $posts = qa_db_read_all_assoc(qa_db_query_sub('SELECT postid, content, format FROM ^posts WHERE postid IN (#)', $postids));
                    $postinfo = array();
                    foreach ($posts as $qitem) {
                        $postinfo[$qitem['postid']] = $qitem;
                    }
                    //	Get the regular expression fragment to use for blocked words and the maximum length of content to show
                    $blockwordspreg = qa_get_block_words_preg();
                    $maxlength = qa_opt('cs_except_len');
                    //	Now add the popup to the title for each question
                    foreach ($q_list['qs'] as $index => $question) {
                        $thispost = @$postinfo[$question['raw']['postid']];
                        if (isset($thispost)) {
                            $text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));
                            $text = qa_shorten_string_line($text, $maxlength);
                            $q_list['qs'][$index]['content'] = '<SPAN>' . qa_html($text) . '</SPAN>';
                        }
                    }
                }
            }
            $this->output('<div class="qa-q-list' . ($this->list_vote_disabled($q_list['qs']) ? ' qa-q-list-vote-disabled' : '') . ((bool) qa_opt('cs_enable_clean_qlist') ? ' clean' : '') . '">', '');
            $this->q_list_items($q_list['qs']);
            $this->output('</div> <!-- END qa-q-list -->', '');
        } else {
            $this->output('
					<div class="no-items">
						<h3 class="icon-sad">' . qa_lang_html('cleanstrap/no_users') . '</h3>
						<p>' . qa_lang_html('cleanstrap/no_results_detail') . '.</p>
					</div>');
        }
    }
function qa_comment_create($userid, $handle, $cookieid, $content, $format, $text, $notify, $email, $question, $answer, $commentsfollows)
{
    require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
    require_once QA_INCLUDE_DIR . 'qa-app-options.php';
    require_once QA_INCLUDE_DIR . 'qa-app-format.php';
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    $parent = isset($answer) ? $answer : $question;
    $postid = qa_db_post_create('C', $parent['postid'], $userid, isset($userid) ? null : $cookieid, qa_remote_ip_address(), null, $content, $format, null, qa_combine_notify_email($userid, $notify, $email), $question['categoryid']);
    qa_db_posts_calc_category_path($postid);
    if (!($question['hidden'] || @$answer['hidden'])) {
        // don't index comment if parent or parent of parent is hidden
        qa_post_index($postid, 'C', $question['postid'], null, $text, null);
    }
    qa_db_points_update_ifuser($userid, 'cposts');
    qa_db_ccount_update();
    //	$senttoemail and $senttouserid ensure each user or email gets only one notification about an added comment,
    //	even if they have several previous comments in the same thread and asked for notifications for the parent.
    //	Still, if a person posted some comments as a registered user and some others anonymously,
    //	they could get two emails about a subsequent comment. Shouldn't be much of a problem in practice.
    $senttoemail = array();
    $senttouserid = array();
    switch ($parent['basetype']) {
        case 'Q':
            $subject = qa_lang('emails/q_commented_subject');
            $body = qa_lang('emails/q_commented_body');
            $context = $parent['title'];
            break;
        case 'A':
            $subject = qa_lang('emails/a_commented_subject');
            $body = qa_lang('emails/a_commented_body');
            $context = qa_viewer_text($parent['content'], $parent['format']);
            break;
    }
    $blockwordspreg = qa_get_block_words_preg();
    $sendhandle = isset($handle) ? $handle : qa_lang('main/anonymous');
    $sendcontext = qa_block_words_replace($context, $blockwordspreg);
    $sendtext = qa_block_words_replace($text, $blockwordspreg);
    $sendtitle = qa_block_words_replace($question['title'], $blockwordspreg);
    $sendurl = qa_path(qa_q_request($question['postid'], $sendtitle), null, qa_opt('site_url'), null, qa_anchor($parent['basetype'], $parent['postid']));
    if (isset($parent['notify']) && !qa_post_is_by_user($parent, $userid, $cookieid)) {
        $senduserid = $parent['userid'];
        $sendemail = @$parent['notify'];
        if (qa_email_validate($sendemail)) {
            $senttoemail[$sendemail] = true;
        } elseif (isset($senduserid)) {
            $senttouserid[$senduserid] = true;
        }
        qa_send_notification($senduserid, $sendemail, @$parent['handle'], $subject, $body, array('^c_handle' => $sendhandle, '^c_context' => $sendcontext, '^c_content' => $sendtext, '^url' => $sendurl));
    }
    foreach ($commentsfollows as $comment) {
        if ($comment['basetype'] == 'C' && $comment['parentid'] == $parent['postid'] && !$comment['hidden']) {
            // find just those for this parent
            if (isset($comment['notify']) && !qa_post_is_by_user($comment, $userid, $cookieid)) {
                $senduserid = $comment['userid'];
                $sendemail = @$comment['notify'];
                if (qa_email_validate($sendemail)) {
                    if (@$senttoemail[$sendemail]) {
                        continue;
                    }
                    $senttoemail[$sendemail] = true;
                } elseif (isset($senduserid)) {
                    if (@$senttouserid[$senduserid]) {
                        continue;
                    }
                    $senttouserid[$senduserid] = true;
                }
                qa_send_notification($senduserid, $sendemail, @$comment['handle'], qa_lang('emails/c_commented_subject'), qa_lang('emails/c_commented_body'), array('^c_handle' => $sendhandle, '^c_context' => $sendcontext, '^c_content' => $sendtext, '^url' => $sendurl));
            }
        }
    }
    qa_report_event('c_post', $userid, $handle, $cookieid, array('postid' => $postid, 'parentid' => $parent['postid'], 'parenttype' => $parent['basetype'], 'questionid' => $question['postid'], 'content' => $content, 'format' => $format, 'text' => $text, 'categoryid' => $question['categoryid'], 'notify' => $notify, 'email' => $email));
    return $postid;
}
Beispiel #15
0
function qa_recalc_perform_step(&$state)
{
    $continue = false;
    @(list($operation, $length, $next, $done) = explode(',', $state));
    switch ($operation) {
        case 'doreindexcontent':
            qa_recalc_transition($state, 'doreindexcontent_pagereindex');
            break;
        case 'doreindexcontent_pagereindex':
            $pages = qa_db_pages_get_for_reindexing($next, 10);
            if (count($pages)) {
                require_once QA_INCLUDE_DIR . 'qa-app-format.php';
                $lastpageid = max(array_keys($pages));
                foreach ($pages as $pageid => $page) {
                    if (!($page['flags'] & QA_PAGE_FLAGS_EXTERNAL)) {
                        $searchmodules = qa_load_modules_with('search', 'unindex_page');
                        foreach ($searchmodules as $searchmodule) {
                            $searchmodule->unindex_page($pageid);
                        }
                        $searchmodules = qa_load_modules_with('search', 'index_page');
                        if (count($searchmodules)) {
                            $indextext = qa_viewer_text($page['content'], 'html');
                            foreach ($searchmodules as $searchmodule) {
                                $searchmodule->index_page($pageid, $page['tags'], $page['heading'], $page['content'], 'html', $indextext);
                            }
                        }
                    }
                }
                $next = 1 + $lastpageid;
                $done += count($pages);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'doreindexcontent_postcount');
            }
            break;
        case 'doreindexcontent_postcount':
            qa_db_qcount_update();
            qa_db_acount_update();
            qa_db_ccount_update();
            qa_recalc_transition($state, 'doreindexcontent_postreindex');
            break;
        case 'doreindexcontent_postreindex':
            $posts = qa_db_posts_get_for_reindexing($next, 10);
            if (count($posts)) {
                require_once QA_INCLUDE_DIR . 'qa-app-format.php';
                $lastpostid = max(array_keys($posts));
                qa_db_prepare_for_reindexing($next, $lastpostid);
                qa_suspend_update_counts();
                foreach ($posts as $postid => $post) {
                    qa_post_unindex($postid);
                    qa_post_index($postid, $post['type'], $post['questionid'], $post['parentid'], $post['title'], $post['content'], $post['format'], qa_viewer_text($post['content'], $post['format']), $post['tags'], $post['categoryid']);
                }
                $next = 1 + $lastpostid;
                $done += count($posts);
                $continue = true;
            } else {
                qa_db_truncate_indexes($next);
                qa_recalc_transition($state, 'doreindexposts_wordcount');
            }
            break;
        case 'doreindexposts_wordcount':
            $wordids = qa_db_words_prepare_for_recounting($next, 1000);
            if (count($wordids)) {
                $lastwordid = max($wordids);
                qa_db_words_recount($next, $lastwordid);
                $next = 1 + $lastwordid;
                $done += count($wordids);
                $continue = true;
            } else {
                qa_db_tagcount_update();
                // this is quick so just do it here
                qa_recalc_transition($state, 'doreindexposts_complete');
            }
            break;
        case 'dorecountposts':
            qa_recalc_transition($state, 'dorecountposts_postcount');
            break;
        case 'dorecountposts_postcount':
            qa_db_qcount_update();
            qa_db_acount_update();
            qa_db_ccount_update();
            qa_db_unaqcount_update();
            qa_db_unselqcount_update();
            qa_recalc_transition($state, 'dorecountposts_votecount');
            break;
        case 'dorecountposts_votecount':
            $postids = qa_db_posts_get_for_recounting($next, 1000);
            if (count($postids)) {
                $lastpostid = max($postids);
                qa_db_posts_votes_recount($next, $lastpostid);
                $next = 1 + $lastpostid;
                $done += count($postids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorecountposts_acount');
            }
            break;
        case 'dorecountposts_acount':
            $postids = qa_db_posts_get_for_recounting($next, 1000);
            if (count($postids)) {
                $lastpostid = max($postids);
                qa_db_posts_answers_recount($next, $lastpostid);
                $next = 1 + $lastpostid;
                $done += count($postids);
                $continue = true;
            } else {
                qa_db_unupaqcount_update();
                qa_recalc_transition($state, 'dorecountposts_complete');
            }
            break;
        case 'dorecalcpoints':
            qa_recalc_transition($state, 'dorecalcpoints_usercount');
            break;
        case 'dorecalcpoints_usercount':
            qa_db_userpointscount_update();
            // for progress update - not necessarily accurate
            qa_recalc_transition($state, 'dorecalcpoints_recalc');
            break;
        case 'dorecalcpoints_recalc':
            $userids = qa_db_users_get_for_recalc_points($next, 10);
            if (count($userids)) {
                $lastuserid = max($userids);
                qa_db_users_recalc_points($next, $lastuserid);
                $next = 1 + $lastuserid;
                $done += count($userids);
                $continue = true;
            } else {
                qa_db_truncate_userpoints($next);
                qa_db_userpointscount_update();
                // quick so just do it here
                qa_recalc_transition($state, 'dorecalcpoints_complete');
            }
            break;
        case 'dorefillevents':
            qa_recalc_transition($state, 'dorefillevents_qcount');
            break;
        case 'dorefillevents_qcount':
            qa_db_qcount_update();
            qa_recalc_transition($state, 'dorefillevents_refill');
            break;
        case 'dorefillevents_refill':
            $questionids = qa_db_qs_get_for_event_refilling($next, 1);
            if (count($questionids)) {
                require_once QA_INCLUDE_DIR . 'qa-app-events.php';
                require_once QA_INCLUDE_DIR . 'qa-app-updates.php';
                require_once QA_INCLUDE_DIR . 'qa-util-sort.php';
                $lastquestionid = max($questionids);
                foreach ($questionids as $questionid) {
                    //	Retrieve all posts relating to this question
                    list($question, $childposts, $achildposts) = qa_db_select_with_pending(qa_db_full_post_selectspec(null, $questionid), qa_db_full_child_posts_selectspec(null, $questionid), qa_db_full_a_child_posts_selectspec(null, $questionid));
                    //	Merge all posts while preserving keys as postids
                    $posts = array($questionid => $question);
                    foreach ($childposts as $postid => $post) {
                        $posts[$postid] = $post;
                    }
                    foreach ($achildposts as $postid => $post) {
                        $posts[$postid] = $post;
                    }
                    //	Creation and editing of each post
                    foreach ($posts as $postid => $post) {
                        $followonq = $post['basetype'] == 'Q' && $postid != $questionid;
                        qa_create_event_for_q_user($questionid, $postid, $followonq ? QA_UPDATE_FOLLOWS : null, $post['userid'], @$posts[$post['parentid']]['userid'], $post['created']);
                        if (isset($post['updated']) && !$followonq) {
                            qa_create_event_for_q_user($questionid, $postid, $post['updatetype'], $post['lastuserid'], $post['userid'], $post['updated']);
                        }
                    }
                    //	Tags and categories of question
                    qa_create_event_for_tags($question['tags'], $questionid, null, $question['userid'], $question['created']);
                    qa_create_event_for_category($question['categoryid'], $questionid, null, $question['userid'], $question['created']);
                    //	Collect comment threads
                    $parentidcomments = array();
                    foreach ($posts as $postid => $post) {
                        if ($post['basetype'] == 'C') {
                            $parentidcomments[$post['parentid']][$postid] = $post;
                        }
                    }
                    //	For each comment thread, notify all previous comment authors of each comment in the thread (could get slow)
                    foreach ($parentidcomments as $parentid => $comments) {
                        $keyuserids = array();
                        qa_sort_by($comments, 'created');
                        foreach ($comments as $comment) {
                            foreach ($keyuserids as $keyuserid => $dummy) {
                                if ($keyuserid != $comment['userid'] && $keyuserid != @$posts[$parentid]['userid']) {
                                    qa_db_event_create_not_entity($keyuserid, $questionid, $comment['postid'], null, $comment['userid'], $comment['created']);
                                }
                            }
                            if (isset($comment['userid'])) {
                                $keyuserids[$comment['userid']] = true;
                            }
                        }
                    }
                }
                $next = 1 + $lastquestionid;
                $done += count($questionids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorefillevents_complete');
            }
            break;
        case 'dorecalccategories':
            qa_recalc_transition($state, 'dorecalccategories_postcount');
            break;
        case 'dorecalccategories_postcount':
            qa_db_acount_update();
            qa_db_ccount_update();
            qa_recalc_transition($state, 'dorecalccategories_postupdate');
            break;
        case 'dorecalccategories_postupdate':
            $postids = qa_db_posts_get_for_recategorizing($next, 100);
            if (count($postids)) {
                $lastpostid = max($postids);
                qa_db_posts_recalc_categoryid($next, $lastpostid);
                qa_db_posts_calc_category_path($next, $lastpostid);
                $next = 1 + $lastpostid;
                $done += count($postids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorecalccategories_recount');
            }
            break;
        case 'dorecalccategories_recount':
            $categoryids = qa_db_categories_get_for_recalcs($next, 10);
            if (count($categoryids)) {
                $lastcategoryid = max($categoryids);
                foreach ($categoryids as $categoryid) {
                    qa_db_ifcategory_qcount_update($categoryid);
                }
                $next = 1 + $lastcategoryid;
                $done += count($categoryids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorecalccategories_backpaths');
            }
            break;
        case 'dorecalccategories_backpaths':
            $categoryids = qa_db_categories_get_for_recalcs($next, 10);
            if (count($categoryids)) {
                $lastcategoryid = max($categoryids);
                qa_db_categories_recalc_backpaths($next, $lastcategoryid);
                $next = 1 + $lastcategoryid;
                $done += count($categoryids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorecalccategories_complete');
            }
            break;
        case 'dodeletehidden':
            qa_recalc_transition($state, 'dodeletehidden_comments');
            break;
        case 'dodeletehidden_comments':
            $posts = qa_db_posts_get_for_deleting('C', $next, 1);
            if (count($posts)) {
                require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
                $postid = $posts[0];
                qa_post_delete($postid);
                $next = 1 + $postid;
                $done++;
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dodeletehidden_answers');
            }
            break;
        case 'dodeletehidden_answers':
            $posts = qa_db_posts_get_for_deleting('A', $next, 1);
            if (count($posts)) {
                require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
                $postid = $posts[0];
                qa_post_delete($postid);
                $next = 1 + $postid;
                $done++;
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dodeletehidden_questions');
            }
            break;
        case 'dodeletehidden_questions':
            $posts = qa_db_posts_get_for_deleting('Q', $next, 1);
            if (count($posts)) {
                require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
                $postid = $posts[0];
                qa_post_delete($postid);
                $next = 1 + $postid;
                $done++;
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dodeletehidden_complete');
            }
            break;
        default:
            $state = '';
            break;
    }
    if ($continue) {
        $state = $operation . ',' . $length . ',' . $next . ',' . $done;
    }
    return $continue && $done < $length;
}
function qa_recalc_perform_step(&$state)
{
    $continue = false;
    @(list($operation, $length, $next, $done) = explode(',', $state));
    switch ($operation) {
        case 'doreindexposts':
            qa_recalc_transition($state, 'doreindexposts_postcount');
            break;
        case 'doreindexposts_postcount':
            qa_db_qcount_update();
            qa_db_acount_update();
            qa_db_ccount_update();
            qa_recalc_transition($state, 'doreindexposts_reindex');
            break;
        case 'doreindexposts_reindex':
            $posts = qa_db_posts_get_for_reindexing($next, 10);
            if (count($posts)) {
                require_once QA_INCLUDE_DIR . 'qa-app-format.php';
                $lastpostid = max(array_keys($posts));
                qa_db_prepare_for_reindexing($next, $lastpostid);
                foreach ($posts as $postid => $post) {
                    qa_post_index($postid, $post['type'], $post['questionid'], $post['title'], qa_viewer_text($post['content'], $post['format']), $post['tags'], true);
                }
                $next = 1 + $lastpostid;
                $done += count($posts);
                $continue = true;
            } else {
                qa_db_truncate_indexes($next);
                qa_recalc_transition($state, 'doreindexposts_wordcount');
            }
            break;
        case 'doreindexposts_wordcount':
            $wordids = qa_db_words_prepare_for_recounting($next, 1000);
            if (count($wordids)) {
                $lastwordid = max($wordids);
                qa_db_words_recount($next, $lastwordid);
                $next = 1 + $lastwordid;
                $done += count($wordids);
                $continue = true;
            } else {
                qa_db_tagcount_update();
                // this is quick so just do it here
                qa_recalc_transition($state, 'doreindexposts_complete');
            }
            break;
        case 'dorecountposts':
            qa_recalc_transition($state, 'dorecountposts_postcount');
            break;
        case 'dorecountposts_postcount':
            qa_db_qcount_update();
            qa_db_acount_update();
            qa_db_ccount_update();
            qa_db_unaqcount_update();
            qa_recalc_transition($state, 'dorecountposts_recount');
            break;
        case 'dorecountposts_recount':
            $postids = qa_db_posts_get_for_recounting($next, 1000);
            if (count($postids)) {
                $lastpostid = max($postids);
                qa_db_posts_recount($next, $lastpostid);
                $next = 1 + $lastpostid;
                $done += count($postids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorecountposts_complete');
            }
            break;
        case 'dorecalcpoints':
            qa_recalc_transition($state, 'dorecalcpoints_usercount');
            break;
        case 'dorecalcpoints_usercount':
            qa_db_userpointscount_update();
            // for progress update - not necessarily accurate
            qa_recalc_transition($state, 'dorecalcpoints_recalc');
            break;
        case 'dorecalcpoints_recalc':
            $userids = qa_db_users_get_for_recalc_points($next, 10);
            if (count($userids)) {
                $lastuserid = max($userids);
                qa_db_users_recalc_points($next, $lastuserid);
                $next = 1 + $lastuserid;
                $done += count($userids);
                $continue = true;
            } else {
                qa_db_truncate_userpoints($next);
                qa_db_userpointscount_update();
                // quick so just do it here
                qa_recalc_transition($state, 'dorecalcpoints_complete');
            }
            break;
        case 'dorecalccategories':
            qa_recalc_transition($state, 'dorecalccategories_postcount');
            break;
        case 'dorecalccategories_postcount':
            qa_db_acount_update();
            qa_db_ccount_update();
            qa_recalc_transition($state, 'dorecalccategories_postupdate');
            break;
        case 'dorecalccategories_postupdate':
            $postids = qa_db_posts_get_for_recategorizing($next, 100);
            if (count($postids)) {
                $lastpostid = max($postids);
                qa_db_posts_recalc_categoryid($next, $lastpostid);
                qa_db_posts_calc_category_path($next, $lastpostid);
                $next = 1 + $lastpostid;
                $done += count($postids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorecalccategories_recount');
            }
            break;
        case 'dorecalccategories_recount':
            $categoryids = qa_db_categories_get_for_recalcs($next, 10);
            if (count($categoryids)) {
                $lastcategoryid = max($categoryids);
                foreach ($categoryids as $categoryid) {
                    qa_db_ifcategory_qcount_update($categoryid);
                }
                $next = 1 + $lastcategoryid;
                $done += count($categoryids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorecalccategories_backpaths');
            }
            break;
        case 'dorecalccategories_backpaths':
            $categoryids = qa_db_categories_get_for_recalcs($next, 10);
            if (count($categoryids)) {
                $lastcategoryid = max($categoryids);
                qa_db_categories_recalc_backpaths($next, $lastcategoryid);
                $next = 1 + $lastcategoryid;
                $done += count($categoryids);
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dorecalccategories_complete');
            }
            break;
        case 'dodeletehidden':
            qa_recalc_transition($state, 'dodeletehidden_comments');
            break;
        case 'dodeletehidden_comments':
            $posts = qa_db_posts_get_for_deleting('C', $next, 1);
            if (count($posts)) {
                $postid = $posts[0];
                $oldcomment = qa_db_single_select(qa_db_full_post_selectspec(null, $postid));
                $parent = qa_db_single_select(qa_db_full_post_selectspec(null, $oldcomment['parentid']));
                if ($parent['basetype'] == 'Q') {
                    $question = $parent;
                    $answer = null;
                } else {
                    $question = qa_db_single_select(qa_db_full_post_selectspec(null, $parent['parentid']));
                    $answer = $parent;
                }
                qa_comment_delete($oldcomment, $question, $answer, null, null, null);
                $next = 1 + $postid;
                $done++;
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dodeletehidden_answers');
            }
            break;
        case 'dodeletehidden_answers':
            $posts = qa_db_posts_get_for_deleting('A', $next, 1);
            if (count($posts)) {
                $postid = $posts[0];
                $oldanswer = qa_db_single_select(qa_db_full_post_selectspec(null, $postid));
                $question = qa_db_single_select(qa_db_full_post_selectspec(null, $oldanswer['parentid']));
                qa_answer_delete($oldanswer, $question, null, null, null);
                $next = 1 + $postid;
                $done++;
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dodeletehidden_questions');
            }
            break;
        case 'dodeletehidden_questions':
            $posts = qa_db_posts_get_for_deleting('Q', $next, 1);
            if (count($posts)) {
                $postid = $posts[0];
                $oldquestion = qa_db_single_select(qa_db_full_post_selectspec(null, $postid));
                qa_question_delete($oldquestion, null, null, null);
                $next = 1 + $postid;
                $done++;
                $continue = true;
            } else {
                qa_recalc_transition($state, 'dodeletehidden_complete');
            }
            break;
        default:
            $state = '';
            break;
    }
    if ($continue) {
        $state = $operation . ',' . $length . ',' . $next . ',' . $done;
    }
    return $continue && $done < $length;
}
Beispiel #17
0
function qa_page_q_prepare_post_for_filters($post)
{
    $in = array('content' => $post['content'], 'format' => $post['format'], 'text' => qa_viewer_text($post['content'], $post['format']), 'notify' => isset($post['notify']), 'email' => qa_email_validate($post['notify']) ? $post['notify'] : null, 'queued' => qa_user_moderation_reason(qa_user_level_for_post($post)) !== false);
    if ($post['basetype'] == 'Q') {
        $in['title'] = $post['title'];
        $in['tags'] = qa_tagstring_to_tags($post['tags']);
        $in['categoryid'] = $post['categoryid'];
        $in['extra'] = $post['extra'];
    }
    return $in;
}
         }
         qa_db_page_move($editpage['pageid'], substr($inposition, 0, 1), substr($inposition, 1));
         $reloadpages = true;
         if (empty($errors)) {
             $editpage = null;
         } else {
             $editpage = @$pages[$editpage['pageid']];
         }
     } else {
         // creating a new one
         if (empty($errors)) {
             if ($isexternal) {
                 $pageid = qa_db_page_create($inname, QA_PAGE_FLAGS_EXTERNAL | ($innewwindow ? QA_PAGE_FLAGS_NEW_WINDOW : 0), $inurl, null, null, $inpermit);
             } else {
                 $pageid = qa_db_page_create($inname, 0, $inslug, $inheading, $incontent, $inpermit);
                 $indextext = qa_viewer_text($incontent, 'html');
                 $searchmodules = qa_load_modules_with('search', 'index_page');
                 foreach ($searchmodules as $searchmodule) {
                     $searchmodule->index_page($pageid, $inslug, $inheading, $incontent, 'html', $indextext);
                 }
             }
             qa_db_page_move($pageid, substr($inposition, 0, 1), substr($inposition, 1));
             $editpage = null;
             $reloadpages = true;
         }
     }
     if (qa_clicked('dosaveview') && empty($errors) && !$isexternal) {
         qa_redirect($inslug);
     }
 }
 if ($reloadpages) {
function qa_page_q_edit_a_form(&$qa_content, $id, $answer, $question, $answers, $commentsfollows, $in, $errors)
{
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    $answerid = $answer['postid'];
    $prefix = 'a' . $answerid . '_';
    $content = isset($in['content']) ? $in['content'] : $answer['content'];
    $format = isset($in['format']) ? $in['format'] : $answer['format'];
    $editorname = isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_as');
    $editor = qa_load_editor($content, $format, $editorname);
    $hascomments = false;
    foreach ($commentsfollows as $commentfollow) {
        if ($commentfollow['parentid'] == $answerid) {
            $hascomments = true;
        }
    }
    $form = array('tags' => 'method="post" action="' . qa_self_html() . '"', 'id' => $id, 'title' => qa_lang_html('question/edit_a_title'), 'style' => 'tall', 'fields' => array('content' => array_merge(qa_editor_load_field($editor, $qa_content, $content, $format, $prefix . 'content', 12), array('error' => qa_html(@$errors['content'])))), 'buttons' => array('save' => array('tags' => 'onclick="qa_show_waiting_after(this, false); ' . (method_exists($editor, 'update_script') ? $editor->update_script($prefix . 'content') : '') . '"', 'label' => qa_lang_html('main/save_button')), 'cancel' => array('tags' => 'name="docancel"', 'label' => qa_lang_html('main/cancel_button'))), 'hidden' => array($prefix . 'editor' => qa_html($editorname), $prefix . 'dosave' => '1', $prefix . 'code' => qa_get_form_security_code('edit-' . $answerid)));
    //	Show option to convert this answer to a comment, if appropriate
    $commentonoptions = array();
    $lastbeforeid = $question['postid'];
    // used to find last post created before this answer - this is default given
    $lastbeforetime = $question['created'];
    if ($question['commentable']) {
        $commentonoptions[$question['postid']] = qa_lang_html('question/comment_on_q') . qa_html(qa_shorten_string_line($question['title'], 80));
    }
    foreach ($answers as $otheranswer) {
        if ($otheranswer['postid'] != $answerid && $otheranswer['created'] < $answer['created'] && $otheranswer['commentable'] && !$otheranswer['hidden']) {
            $commentonoptions[$otheranswer['postid']] = qa_lang_html('question/comment_on_a') . qa_html(qa_shorten_string_line(qa_viewer_text($otheranswer['content'], $otheranswer['format']), 80));
            if ($otheranswer['created'] > $lastbeforetime) {
                $lastbeforeid = $otheranswer['postid'];
                $lastebeforetime = $otheranswer['created'];
            }
        }
    }
    if (count($commentonoptions)) {
        $form['fields']['tocomment'] = array('tags' => 'name="' . $prefix . 'dotoc" id="' . $prefix . 'dotoc"', 'label' => '<span id="' . $prefix . 'toshown">' . qa_lang_html('question/a_convert_to_c_on') . '</span>' . '<span id="' . $prefix . 'tohidden" style="display:none;">' . qa_lang_html('question/a_convert_to_c') . '</span>', 'type' => 'checkbox', 'tight' => true);
        $form['fields']['commenton'] = array('tags' => 'name="' . $prefix . 'commenton"', 'id' => $prefix . 'commenton', 'type' => 'select', 'note' => qa_lang_html($hascomments ? 'question/a_convert_warn_cs' : 'question/a_convert_warn'), 'options' => $commentonoptions, 'value' => @$commentonoptions[$lastbeforeid]);
        qa_set_display_rules($qa_content, array($prefix . 'commenton' => $prefix . 'dotoc', $prefix . 'toshown' => $prefix . 'dotoc', $prefix . 'tohidden' => '!' . $prefix . 'dotoc'));
    }
    //	Show name and notification field if appropriate
    if ($answer['isbyuser']) {
        if (!qa_is_logged_in()) {
            qa_set_up_name_field($qa_content, $form['fields'], isset($in['name']) ? $in['name'] : @$answer['name'], $prefix);
        }
        qa_set_up_notify_fields($qa_content, $form['fields'], 'A', qa_get_logged_in_email(), isset($in['notify']) ? $in['notify'] : !empty($answer['notify']), isset($in['email']) ? $in['email'] : @$answer['notify'], @$errors['email'], $prefix);
    }
    if (!qa_user_post_permit_error('permit_edit_silent', $answer)) {
        $form['fields']['silent'] = array('type' => 'checkbox', 'label' => qa_lang_html('question/save_silent_label'), 'tags' => 'name="' . $prefix . 'silent"', 'value' => qa_html(@$in['silent']));
    }
    return $form;
}
}
if ($question['hidden']) {
    $qa_content['hidden'] = true;
}
qa_sort_by($commentsfollows, 'created');
//	Prepare content for the question...
if ($formtype == 'q_edit') {
    // ...in edit mode
    $qa_content['title'] = qa_lang_html($question['editable'] ? 'question/edit_q_title' : (qa_using_categories() ? 'question/recat_q_title' : 'question/retag_q_title'));
    $qa_content['form_q_edit'] = qa_page_q_edit_q_form($qa_content, $question, @$qin, @$qerrors, $completetags, $categories);
    $qa_content['q_view']['raw'] = $question;
} else {
    // ...in view mode
    $qa_content['q_view'] = qa_page_q_question_view($question, $parentquestion, $closepost, $usershtml, $formrequested);
    $qa_content['title'] = $qa_content['q_view']['title'];
    $qa_content['description'] = qa_html(qa_shorten_string_line(qa_viewer_text($question['content'], $question['format']), 150));
    $categorykeyword = @$categories[$question['categoryid']]['title'];
    $qa_content['keywords'] = qa_html(implode(',', array_merge(qa_using_categories() && strlen($categorykeyword) ? array($categorykeyword) : array(), qa_tagstring_to_tags($question['tags']))));
    // as far as I know, META keywords have zero effect on search rankings or listings, but many people have asked for this
}
$microdata = qa_opt('use_microdata');
if ($microdata) {
    $qa_content['head_lines'][] = '<meta itemprop="name" content="' . qa_html($qa_content['q_view']['raw']['title']) . '">';
    $qa_content['html_tags'] = ' itemscope itemtype="http://schema.org/QAPage"';
    $qa_content['main_tags'] = ' itemscope itemtype="http://schema.org/Question"';
}
//	Prepare content for an answer being edited (if any) or to be added
if ($formtype == 'a_edit') {
    $qa_content['a_form'] = qa_page_q_edit_a_form($qa_content, 'a' . $formpostid, $answers[$formpostid], $question, $answers, $commentsfollows, @$aeditin[$formpostid], @$aediterrors[$formpostid]);
    $qa_content['a_form']['c_list'] = qa_page_q_comment_follow_list($question, $answers[$formpostid], $commentsfollows, true, $usershtml, $formrequested, $formpostid);
    $jumptoanchor = 'a' . $formpostid;
 function process_event($event, $userid, $handle, $cookieid, $params)
 {
     require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
     require_once QA_INCLUDE_DIR . 'qa-app-format.php';
     require_once QA_INCLUDE_DIR . 'qa-util-string.php';
     switch ($event) {
         case 'q_post':
             $followanswer = @$params['followanswer'];
             $sendhandle = isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous'));
             if (isset($followanswer['notify']) && !qa_post_is_by_user($followanswer, $userid, $cookieid)) {
                 $blockwordspreg = qa_get_block_words_preg();
                 $sendtext = qa_viewer_text($followanswer['content'], $followanswer['format'], array('blockwordspreg' => $blockwordspreg));
                 qa_send_notification($followanswer['userid'], $followanswer['notify'], @$followanswer['handle'], qa_lang('emails/a_followed_subject'), qa_lang('emails/a_followed_body'), array('^q_handle' => $sendhandle, '^q_title' => qa_block_words_replace($params['title'], $blockwordspreg), '^a_content' => $sendtext, '^url' => qa_q_path($params['postid'], $params['title'], true)));
             }
             if (qa_opt('notify_admin_q_post')) {
                 qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/q_posted_subject'), qa_lang('emails/q_posted_body'), array('^q_handle' => $sendhandle, '^q_title' => $params['title'], '^q_content' => $params['text'], '^url' => qa_q_path($params['postid'], $params['title'], true)));
             }
             break;
         case 'a_post':
             $question = $params['parent'];
             if (isset($question['notify']) && !qa_post_is_by_user($question, $userid, $cookieid)) {
                 qa_send_notification($question['userid'], $question['notify'], @$question['handle'], qa_lang('emails/q_answered_subject'), qa_lang('emails/q_answered_body'), array('^a_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous')), '^q_title' => $question['title'], '^a_content' => qa_block_words_replace($params['text'], qa_get_block_words_preg()), '^url' => qa_q_path($question['postid'], $question['title'], true, 'A', $params['postid'])));
             }
             break;
         case 'c_post':
             $parent = $params['parent'];
             $question = $params['question'];
             $senttoemail = array();
             // to ensure each user or email gets only one notification about an added comment
             $senttouserid = array();
             switch ($parent['basetype']) {
                 case 'Q':
                     $subject = qa_lang('emails/q_commented_subject');
                     $body = qa_lang('emails/q_commented_body');
                     $context = $parent['title'];
                     break;
                 case 'A':
                     $subject = qa_lang('emails/a_commented_subject');
                     $body = qa_lang('emails/a_commented_body');
                     $context = qa_viewer_text($parent['content'], $parent['format']);
                     break;
             }
             $blockwordspreg = qa_get_block_words_preg();
             $sendhandle = isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous'));
             $sendcontext = qa_block_words_replace($context, $blockwordspreg);
             $sendtext = qa_block_words_replace($params['text'], $blockwordspreg);
             $sendurl = qa_q_path($question['postid'], $question['title'], true, 'C', $params['postid']);
             if (isset($parent['notify']) && !qa_post_is_by_user($parent, $userid, $cookieid)) {
                 $senduserid = $parent['userid'];
                 $sendemail = @$parent['notify'];
                 if (qa_email_validate($sendemail)) {
                     $senttoemail[$sendemail] = true;
                 } elseif (isset($senduserid)) {
                     $senttouserid[$senduserid] = true;
                 }
                 qa_send_notification($senduserid, $sendemail, @$parent['handle'], $subject, $body, array('^c_handle' => $sendhandle, '^c_context' => $sendcontext, '^c_content' => $sendtext, '^url' => $sendurl));
             }
             foreach ($params['thread'] as $comment) {
                 if (isset($comment['notify']) && !qa_post_is_by_user($comment, $userid, $cookieid)) {
                     $senduserid = $comment['userid'];
                     $sendemail = @$comment['notify'];
                     if (qa_email_validate($sendemail)) {
                         if (@$senttoemail[$sendemail]) {
                             continue;
                         }
                         $senttoemail[$sendemail] = true;
                     } elseif (isset($senduserid)) {
                         if (@$senttouserid[$senduserid]) {
                             continue;
                         }
                         $senttouserid[$senduserid] = true;
                     }
                     qa_send_notification($senduserid, $sendemail, @$comment['handle'], qa_lang('emails/c_commented_subject'), qa_lang('emails/c_commented_body'), array('^c_handle' => $sendhandle, '^c_context' => $sendcontext, '^c_content' => $sendtext, '^url' => $sendurl));
                 }
             }
             break;
         case 'q_queue':
         case 'q_requeue':
             if (qa_opt('moderate_notify_admin')) {
                 qa_send_notification(null, qa_opt('feedback_email'), null, $event == 'q_requeue' ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'), $event == 'q_requeue' ? qa_lang('emails/remoderate_body') : qa_lang('emails/moderate_body'), array('^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : (strlen(@$oldquestion['name']) ? $oldquestion['name'] : qa_lang('main/anonymous'))), '^p_context' => trim(@$params['title'] . "\n\n" . $params['text']), '^url' => qa_q_path($params['postid'], $params['title'], true), '^a_url' => qa_path_absolute('admin/moderate')));
             }
             break;
         case 'a_queue':
         case 'a_requeue':
             if (qa_opt('moderate_notify_admin')) {
                 qa_send_notification(null, qa_opt('feedback_email'), null, $event == 'a_requeue' ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'), $event == 'a_requeue' ? qa_lang('emails/remoderate_body') : qa_lang('emails/moderate_body'), array('^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : (strlen(@$oldanswer['name']) ? $oldanswer['name'] : qa_lang('main/anonymous'))), '^p_context' => $params['text'], '^url' => qa_q_path($params['parentid'], $params['parent']['title'], true, 'A', $params['postid']), '^a_url' => qa_path_absolute('admin/moderate')));
             }
             break;
         case 'c_queue':
         case 'c_requeue':
             if (qa_opt('moderate_notify_admin')) {
                 qa_send_notification(null, qa_opt('feedback_email'), null, $event == 'c_requeue' ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'), $event == 'c_requeue' ? qa_lang('emails/remoderate_body') : qa_lang('emails/moderate_body'), array('^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : (strlen(@$oldcomment['name']) ? $oldcomment['name'] : (strlen(@$oldanswer['name']) ? $oldanswer['name'] : qa_lang('main/anonymous')))), '^p_context' => $params['text'], '^url' => qa_q_path($params['questionid'], $params['question']['title'], true, 'C', $params['postid']), '^a_url' => qa_path_absolute('admin/moderate')));
             }
             break;
         case 'q_flag':
         case 'a_flag':
         case 'c_flag':
             $flagcount = $params['flagcount'];
             $oldpost = $params['oldpost'];
             $notifycount = $flagcount - qa_opt('flagging_notify_first');
             if ($notifycount >= 0 && $notifycount % qa_opt('flagging_notify_every') == 0) {
                 qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/flagged_subject'), qa_lang('emails/flagged_body'), array('^p_handle' => isset($oldpost['handle']) ? $oldpost['handle'] : (strlen($oldpost['name']) ? $oldpost['name'] : qa_lang('main/anonymous')), '^flags' => $flagcount == 1 ? qa_lang_html_sub('main/1_flag', '1', '1') : qa_lang_html_sub('main/x_flags', $flagcount), '^p_context' => trim(@$oldpost['title'] . "\n\n" . qa_viewer_text($oldpost['content'], $oldpost['format'])), '^url' => qa_q_path($params['questionid'], $params['question']['title'], true, $oldpost['basetype'], $oldpost['postid']), '^a_url' => qa_path_absolute('admin/flagged')));
             }
             break;
         case 'a_select':
             $answer = $params['answer'];
             if (isset($answer['notify']) && !qa_post_is_by_user($answer, $userid, $cookieid)) {
                 $blockwordspreg = qa_get_block_words_preg();
                 $sendcontent = qa_viewer_text($answer['content'], $answer['format'], array('blockwordspreg' => $blockwordspreg));
                 qa_send_notification($answer['userid'], $answer['notify'], @$answer['handle'], qa_lang('emails/a_selected_subject'), qa_lang('emails/a_selected_body'), array('^s_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'), '^q_title' => qa_block_words_replace($params['parent']['title'], $blockwordspreg), '^a_content' => $sendcontent, '^url' => qa_q_path($params['parentid'], $params['parent']['title'], true, 'A', $params['postid'])));
             }
             break;
         case 'u_register':
             if (qa_opt('register_notify_admin')) {
                 qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/u_registered_subject'), qa_opt('moderate_users') ? qa_lang('emails/u_to_approve_body') : qa_lang('emails/u_registered_body'), array('^u_handle' => $handle, '^url' => qa_path_absolute('user/' . $handle), '^a_url' => qa_path_absolute('admin/approve')));
             }
             break;
         case 'u_level':
             if ($params['level'] >= QA_USER_LEVEL_APPROVED && $params['oldlevel'] < QA_USER_LEVEL_APPROVED) {
                 qa_send_notification($params['userid'], null, $params['handle'], qa_lang('emails/u_approved_subject'), qa_lang('emails/u_approved_body'), array('^url' => qa_path_absolute('user/' . $params['handle'])));
             }
             break;
         case 'u_wall_post':
             if ($userid != $params['userid']) {
                 $blockwordspreg = qa_get_block_words_preg();
                 qa_send_notification($params['userid'], null, $params['handle'], qa_lang('emails/wall_post_subject'), qa_lang('emails/wall_post_body'), array('^f_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'), '^post' => qa_block_words_replace($params['text'], $blockwordspreg), '^url' => qa_path_absolute('user/' . $params['handle'], null, 'wall')));
             }
             break;
     }
 }
function qa_page_q_edit_a_form($answerid)
{
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    global $questionid, $question, $answers, $inacontent, $inaformat, $inaeditor, $aerrors, $qa_content, $innotify, $inemail, $jumptoanchor, $commentsfollows;
    $answer = $answers[$answerid];
    $content = isset($inacontent) ? $inacontent : $answer['content'];
    $format = isset($inaformat) ? $inaformat : $answer['format'];
    $editorname = isset($inaeditor) ? $inaeditor : qa_opt('editor_for_as');
    $editor = qa_load_editor($content, $format, $editorname);
    $hascomments = false;
    foreach ($commentsfollows as $commentfollow) {
        if ($commentfollow['parentid'] == $answerid) {
            $hascomments = true;
        }
    }
    $form = array('title' => '<A NAME="a_edit">' . qa_lang_html('question/edit_a_title') . '</A>', 'style' => 'tall', 'fields' => array('content' => array_merge($editor->get_field($qa_content, $content, $format, 'acontent', 12, true), array('error' => qa_html(@$aerrors['content'])))), 'buttons' => array('save' => array('label' => qa_lang_html('main/save_button')), 'cancel' => array('tags' => 'NAME="docancel"', 'label' => qa_lang_html('main/cancel_button'))), 'hidden' => array('editor' => qa_html($editorname), 'dosavea_' . qa_html($answerid) => '1'));
    //	Show option to convert this answer to a comment, if appropriate
    $commentonoptions = array();
    $lastbeforeid = $questionid;
    // used to find last post created before this answer - this is default given
    $lastbeforetime = $question['created'];
    if ($question['commentable']) {
        $commentonoptions[$questionid] = qa_lang_html('question/comment_on_q') . qa_html(qa_shorten_string_line($question['title'], 80));
    }
    foreach ($answers as $otheranswer) {
        if ($otheranswer['postid'] != $answerid && $otheranswer['created'] < $answer['created'] && $otheranswer['commentable'] && !$otheranswer['hidden']) {
            $commentonoptions[$otheranswer['postid']] = qa_lang_html('question/comment_on_a') . qa_html(qa_shorten_string_line(qa_viewer_text($otheranswer['content'], $otheranswer['format']), 80));
            if ($otheranswer['created'] > $lastbeforetime) {
                $lastbeforeid = $otheranswer['postid'];
                $lastebeforetime = $otheranswer['created'];
            }
        }
    }
    if (count($commentonoptions)) {
        $form['fields']['tocomment'] = array('tags' => 'NAME="tocomment" ID="tocomment"', 'label' => '<SPAN ID="tocomment_shown">' . qa_lang_html('question/a_convert_to_c_on') . '</SPAN>' . '<SPAN ID="tocomment_hidden" STYLE="display:none;">' . qa_lang_html('question/a_convert_to_c') . '</SPAN>', 'type' => 'checkbox', 'tight' => true);
        $form['fields']['commenton'] = array('tags' => 'NAME="commenton"', 'id' => 'commenton', 'type' => 'select', 'note' => qa_lang_html($hascomments ? 'question/a_convert_warn_cs' : 'question/a_convert_warn'), 'options' => $commentonoptions, 'value' => @$commentonoptions[$lastbeforeid]);
        qa_set_display_rules($qa_content, array('commenton' => 'tocomment', 'tocomment_shown' => 'tocomment', 'tocomment_hidden' => '!tocomment'));
    }
    //	Show notification field if appropriate
    if ($answer['isbyuser']) {
        qa_set_up_notify_fields($qa_content, $form['fields'], 'A', qa_get_logged_in_email(), isset($innotify) ? $innotify : !empty($answer['notify']), isset($inemail) ? $inemail : @$answer['notify'], @$aerrors['email']);
    }
    $form['c_list'] = qa_page_q_comment_follow_list($answer);
    $jumptoanchor = 'a_edit';
    return $form;
}