Commit d057c557 by Scott

Coding style (question page)

parent e6f8efb5
......@@ -20,74 +20,75 @@
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../');
exit;
}
}
require_once QA_INCLUDE_DIR.'app/limits.php';
require_once QA_INCLUDE_DIR.'pages/question-submit.php';
require_once QA_INCLUDE_DIR . 'app/limits.php';
require_once QA_INCLUDE_DIR . 'pages/question-submit.php';
$code=qa_post_text('code');
$code = qa_post_text('code');
// Process general cancel button
if (qa_clicked('docancel'))
if (qa_clicked('docancel'))
qa_page_q_refresh($pagestart);
// Process incoming answer (or button)
if ($question['answerbutton']) {
if ($question['answerbutton']) {
if (qa_clicked('q_doanswer'))
qa_page_q_refresh($pagestart, 'answer');
// The 'approve', 'login', 'confirm', 'limit', 'userblock', 'ipblock' permission errors are reported to the user here
// The other option ('level') prevents the answer button being shown, in qa_page_q_post_rules(...)
if (qa_clicked('a_doadd') || ($pagestate=='answer'))
if (qa_clicked('a_doadd') || $pagestate == 'answer') {
switch (qa_user_post_permit_error('permit_post_a', $question, QA_LIMIT_ANSWERS)) {
case 'login':
$pageerror=qa_insert_login_links(qa_lang_html('question/answer_must_login'), qa_request());
$pageerror = qa_insert_login_links(qa_lang_html('question/answer_must_login'), qa_request());
break;
case 'confirm':
$pageerror=qa_insert_login_links(qa_lang_html('question/answer_must_confirm'), qa_request());
$pageerror = qa_insert_login_links(qa_lang_html('question/answer_must_confirm'), qa_request());
break;
case 'approve':
$pageerror=qa_lang_html('question/answer_must_be_approved');
$pageerror = qa_lang_html('question/answer_must_be_approved');
break;
case 'limit':
$pageerror=qa_lang_html('question/answer_limit');
$pageerror = qa_lang_html('question/answer_limit');
break;
default:
$pageerror=qa_lang_html('users/no_permission');
$pageerror = qa_lang_html('users/no_permission');
break;
case false:
if (qa_clicked('a_doadd')) {
$answerid=qa_page_q_add_a_submit($question, $answers, $usecaptcha, $anewin, $anewerrors);
$answerid = qa_page_q_add_a_submit($question, $answers, $usecaptcha, $anewin, $anewerrors);
if (isset($answerid))
qa_page_q_refresh(0, null, 'A', $answerid);
else
$formtype='a_add'; // show form again
$formtype = 'a_add'; // show form again
} else
$formtype='a_add'; // show form as if first time
$formtype = 'a_add'; // show form as if first time
break;
}
}
}
// Process close buttons for question
if ($question['closeable']) {
if ($question['closeable']) {
if (qa_clicked('q_doclose'))
qa_page_q_refresh($pagestart, 'close');
......@@ -95,196 +96,193 @@
if (qa_page_q_close_q_submit($question, $closepost, $closein, $closeerrors))
qa_page_q_refresh($pagestart);
else
$formtype='q_close'; // keep editing if an error
$formtype = 'q_close'; // keep editing if an error
} elseif (($pagestate=='close') && qa_page_q_permit_edit($question, 'permit_close_q', $pageerror))
$formtype='q_close';
}
} elseif (($pagestate == 'close') && qa_page_q_permit_edit($question, 'permit_close_q', $pageerror))
$formtype = 'q_close';
}
// Process any single click operations or delete button for question
if (qa_page_q_single_click_q($question, $answers, $commentsfollows, $closepost, $pageerror))
if (qa_page_q_single_click_q($question, $answers, $commentsfollows, $closepost, $pageerror))
qa_page_q_refresh($pagestart);
if (qa_clicked('q_dodelete') && $question['deleteable'] && qa_page_q_click_check_form_code($question, $pageerror)) {
if (qa_clicked('q_dodelete') && $question['deleteable'] && qa_page_q_click_check_form_code($question, $pageerror)) {
qa_question_delete($question, $userid, qa_get_logged_in_handle(), $cookieid, $closepost);
qa_redirect(''); // redirect since question has gone
}
}
// Process edit or save button for question
if ($question['editbutton'] || $question['retagcatbutton']) {
if ($question['editbutton'] || $question['retagcatbutton']) {
if (qa_clicked('q_doedit'))
qa_page_q_refresh($pagestart, 'edit-'.$questionid);
qa_page_q_refresh($pagestart, 'edit-' . $questionid);
elseif (qa_clicked('q_dosave') && qa_page_q_permit_edit($question, 'permit_edit_q', $pageerror, 'permit_retag_cat')) {
if (qa_page_q_edit_q_submit($question, $answers, $commentsfollows, $closepost, $qin, $qerrors))
qa_redirect(qa_q_request($questionid, $qin['title'])); // don't use refresh since URL may have changed
else {
$formtype='q_edit'; // keep editing if an error
$pageerror=@$qerrors['page']; // for security code failure
$formtype = 'q_edit'; // keep editing if an error
$pageerror = @$qerrors['page']; // for security code failure
}
} elseif (($pagestate==('edit-'.$questionid)) && qa_page_q_permit_edit($question, 'permit_edit_q', $pageerror, 'permit_retag_cat'))
$formtype='q_edit';
} elseif ($pagestate == ('edit-' . $questionid) && qa_page_q_permit_edit($question, 'permit_edit_q', $pageerror, 'permit_retag_cat'))
$formtype = 'q_edit';
if ($formtype=='q_edit') { // get tags for auto-completion
if ($formtype == 'q_edit') { // get tags for auto-completion
if (qa_opt('do_complete_tags'))
$completetags=array_keys(qa_db_select_with_pending(qa_db_popular_tags_selectspec(0, QA_DB_RETRIEVE_COMPLETE_TAGS)));
$completetags = array_keys(qa_db_select_with_pending(qa_db_popular_tags_selectspec(0, QA_DB_RETRIEVE_COMPLETE_TAGS)));
else
$completetags=array();
}
$completetags = array();
}
}
// Process adding a comment to question (shows form or processes it)
if ($question['commentbutton']) {
if ($question['commentbutton']) {
if (qa_clicked('q_docomment'))
qa_page_q_refresh($pagestart, 'comment-'.$questionid, 'C', $questionid);
qa_page_q_refresh($pagestart, 'comment-' . $questionid, 'C', $questionid);
if (qa_clicked('c'.$questionid.'_doadd') || ($pagestate==('comment-'.$questionid)))
if (qa_clicked('c' . $questionid . '_doadd') || $pagestate == ('comment-' . $questionid))
qa_page_q_do_comment($question, $question, $commentsfollows, $pagestart, $usecaptcha, $cnewin, $cnewerrors, $formtype, $formpostid, $pageerror);
}
}
// Process clicked buttons for answers
foreach ($answers as $answerid => $answer) {
$prefix='a'.$answerid.'_';
foreach ($answers as $answerid => $answer) {
$prefix = 'a' . $answerid . '_';
if (qa_page_q_single_click_a($answer, $question, $answers, $commentsfollows, true, $pageerror))
qa_page_q_refresh($pagestart, null, 'A', $answerid);
if ($answer['editbutton']) {
if (qa_clicked($prefix.'doedit'))
qa_page_q_refresh($pagestart, 'edit-'.$answerid);
if (qa_clicked($prefix . 'doedit'))
qa_page_q_refresh($pagestart, 'edit-' . $answerid);
elseif (qa_clicked($prefix.'dosave') && qa_page_q_permit_edit($answer, 'permit_edit_a', $pageerror)) {
$editedtype=qa_page_q_edit_a_submit($answer, $question, $answers, $commentsfollows, $aeditin[$answerid], $aediterrors[$answerid]);
elseif (qa_clicked($prefix . 'dosave') && qa_page_q_permit_edit($answer, 'permit_edit_a', $pageerror)) {
$editedtype = qa_page_q_edit_a_submit($answer, $question, $answers, $commentsfollows, $aeditin[$answerid], $aediterrors[$answerid]);
if (isset($editedtype))
qa_page_q_refresh($pagestart, null, $editedtype, $answerid);
else {
$formtype='a_edit';
$formpostid=$answerid; // keep editing if an error
$formtype = 'a_edit';
$formpostid = $answerid; // keep editing if an error
}
} elseif (($pagestate==('edit-'.$answerid)) && qa_page_q_permit_edit($answer, 'permit_edit_a', $pageerror)) {
$formtype='a_edit';
$formpostid=$answerid;
} elseif ($pagestate == ('edit-' . $answerid) && qa_page_q_permit_edit($answer, 'permit_edit_a', $pageerror)) {
$formtype = 'a_edit';
$formpostid = $answerid;
}
}
if ($answer['commentbutton']) {
if (qa_clicked($prefix.'docomment'))
qa_page_q_refresh($pagestart, 'comment-'.$answerid, 'C', $answerid);
if (qa_clicked($prefix . 'docomment'))
qa_page_q_refresh($pagestart, 'comment-' . $answerid, 'C', $answerid);
if (qa_clicked('c'.$answerid.'_doadd') || ($pagestate==('comment-'.$answerid)))
if (qa_clicked('c' . $answerid . '_doadd') || $pagestate == ('comment-' . $answerid))
qa_page_q_do_comment($question, $answer, $commentsfollows, $pagestart, $usecaptcha, $cnewin, $cnewerrors, $formtype, $formpostid, $pageerror);
}
if (qa_clicked($prefix.'dofollow')) {
$params=array('follow' => $answerid);
if (qa_clicked($prefix . 'dofollow')) {
$params = array('follow' => $answerid);
if (isset($question['categoryid']))
$params['cat']=$question['categoryid'];
$params['cat'] = $question['categoryid'];
qa_redirect('ask', $params);
}
}
}
// Process hide, show, delete, flag, unflag, edit or save button for comments
foreach ($commentsfollows as $commentid => $comment) {
foreach ($commentsfollows as $commentid => $comment) {
if ($comment['basetype'] == 'C') {
$cparentid = $comment['parentid'];
$commentparent = isset($answers[$cparentid]) ? $answers[$cparentid] : $question;
$prefix = 'c'.$commentid.'_';
$prefix = 'c' . $commentid . '_';
if (qa_page_q_single_click_c($comment, $question, $commentparent, $pageerror))
qa_page_q_refresh($pagestart, 'showcomments-'.$cparentid, $commentparent['basetype'], $cparentid);
qa_page_q_refresh($pagestart, 'showcomments-' . $cparentid, $commentparent['basetype'], $cparentid);
if ($comment['editbutton']) {
if (qa_clicked($prefix.'doedit')) {
if (qa_clicked($prefix . 'doedit')) {
if (qa_page_q_permit_edit($comment, 'permit_edit_c', $pageerror)) // extra check here ensures error message is visible
qa_page_q_refresh($pagestart, 'edit-'.$commentid, 'C', $commentid);
}
elseif (qa_clicked($prefix.'dosave') && qa_page_q_permit_edit($comment, 'permit_edit_c', $pageerror)) {
qa_page_q_refresh($pagestart, 'edit-' . $commentid, 'C', $commentid);
} elseif (qa_clicked($prefix . 'dosave') && qa_page_q_permit_edit($comment, 'permit_edit_c', $pageerror)) {
if (qa_page_q_edit_c_submit($comment, $question, $commentparent, $ceditin[$commentid], $cediterrors[$commentid]))
qa_page_q_refresh($pagestart, null, 'C', $commentid);
else {
$formtype = 'c_edit';
$formpostid = $commentid; // keep editing if an error
}
}
elseif (($pagestate == ('edit-'.$commentid)) && qa_page_q_permit_edit($comment, 'permit_edit_c', $pageerror)) {
} elseif (($pagestate == ('edit-' . $commentid)) && qa_page_q_permit_edit($comment, 'permit_edit_c', $pageerror)) {
$formtype = 'c_edit';
$formpostid = $commentid;
}
}
}
}
}
// Functions used above - also see functions in qa-page-question-submit.php (which are shared with Ajax)
function qa_page_q_refresh($start=0, $state=null, $showtype=null, $showid=null)
/*
Redirects back to the question page, with the specified parameters
*/
{
$params=array();
function qa_page_q_refresh($start = 0, $state = null, $showtype = null, $showid = null)
{
$params = array();
if ($start>0)
$params['start']=$start;
if ($start > 0)
$params['start'] = $start;
if (isset($state))
$params['state']=$state;
$params['state'] = $state;
if (isset($showtype) && isset($showid)) {
$anchor=qa_anchor($showtype, $showid);
$params['show']=$showid;
$anchor = qa_anchor($showtype, $showid);
$params['show'] = $showid;
} else
$anchor=null;
$anchor = null;
qa_redirect(qa_request(), $params, null, null, $anchor);
}
}
function qa_page_q_permit_edit($post, $permitoption, &$error, $permitoption2=null)
/*
Returns whether the editing operation (as specified by $permitoption or $permitoption2) on $post is permitted.
If not, sets the $error variable appropriately
*/
{
function qa_page_q_permit_edit($post, $permitoption, &$error, $permitoption2 = null)
{
// The 'login', 'confirm', 'userblock', 'ipblock' permission errors are reported to the user here
// The other options ('approve', 'level') prevent the edit button being shown, in qa_page_q_post_rules(...)
$permiterror=qa_user_post_permit_error($post['isbyuser'] ? null : $permitoption, $post);
$permiterror = qa_user_post_permit_error($post['isbyuser'] ? null : $permitoption, $post);
// if it's by the user, this will only check whether they are blocked
if ($permiterror && isset($permitoption2)) {
$permiterror2=qa_user_post_permit_error($post['isbyuser'] ? null : $permitoption2, $post);
$permiterror2 = qa_user_post_permit_error($post['isbyuser'] ? null : $permitoption2, $post);
if ( ($permiterror=='level') || ($permiterror=='approve') || (!$permiterror2) ) // if it's a less strict error
$permiterror=$permiterror2;
if ($permiterror == 'level' || $permiterror == 'approve' || !$permiterror2) // if it's a less strict error
$permiterror = $permiterror2;
}
switch ($permiterror) {
case 'login':
$error=qa_insert_login_links(qa_lang_html('question/edit_must_login'), qa_request());
$error = qa_insert_login_links(qa_lang_html('question/edit_must_login'), qa_request());
break;
case 'confirm':
$error=qa_insert_login_links(qa_lang_html('question/edit_must_confirm'), qa_request());
$error = qa_insert_login_links(qa_lang_html('question/edit_must_confirm'), qa_request());
break;
default:
$error=qa_lang_html('users/no_permission');
$error = qa_lang_html('users/no_permission');
break;
case false:
......@@ -292,16 +290,16 @@
}
return !$permiterror;
}
}
function qa_page_q_edit_q_form(&$qa_content, $question, $in, $errors, $completetags, $categories)
/*
Returns a $qa_content form for editing the question and sets up other parts of $qa_content accordingly
*/
{
$form=array(
'tags' => 'method="post" action="'.qa_self_html().'"',
function qa_page_q_edit_q_form(&$qa_content, $question, $in, $errors, $completetags, $categories)
{
$form = array(
'tags' => 'method="post" action="' . qa_self_html() . '"',
'style' => 'tall',
......@@ -351,43 +349,45 @@
'hidden' => array(
'q_dosave' => '1',
'code' => qa_get_form_security_code('edit-'.$question['postid']),
'code' => qa_get_form_security_code('edit-' . $question['postid']),
),
);
if ($question['editable']) {
$content=isset($in['content']) ? $in['content'] : $question['content'];
$format=isset($in['format']) ? $in['format'] : $question['format'];
$content = isset($in['content']) ? $in['content'] : $question['content'];
$format = isset($in['format']) ? $in['format'] : $question['format'];
$editorname=isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_qs');
$editor=qa_load_editor($content, $format, $editorname);
$editorname = isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_qs');
$editor = qa_load_editor($content, $format, $editorname);
$form['fields']['content']=array_merge($form['fields']['content'],
$form['fields']['content'] = array_merge($form['fields']['content'],
qa_editor_load_field($editor, $qa_content, $content, $format, 'q_content', 12, true));
if (method_exists($editor, 'update_script'))
$form['buttons']['save']['tags']='onclick="qa_show_waiting_after(this, false); '.$editor->update_script('q_content').'"';
$form['buttons']['save']['tags'] = 'onclick="qa_show_waiting_after(this, false); ' . $editor->update_script('q_content') . '"';
$form['hidden']['q_editor']=qa_html($editorname);
$form['hidden']['q_editor'] = qa_html($editorname);
} else
unset($form['fields']['content']);
if (qa_using_categories() && count($categories) && $question['retagcatable'])
if (qa_using_categories() && count($categories) && $question['retagcatable']) {
qa_set_up_category_field($qa_content, $form['fields']['category'], 'q_category', $categories,
isset($in['categoryid']) ? $in['categoryid'] : $question['categoryid'],
qa_opt('allow_no_category') || !isset($question['categoryid']), qa_opt('allow_no_sub_category'));
else
} else {
unset($form['fields']['category']);
}
if (!($question['editable'] && qa_opt('extra_field_active')))
unset($form['fields']['extra']);
if (qa_using_tags() && $question['retagcatable'])
if (qa_using_tags() && $question['retagcatable']) {
qa_set_up_tag_field($qa_content, $form['fields']['tags'], 'q_tags', isset($in['tags']) ? $in['tags'] : qa_tagstring_to_tags($question['tags']),
array(), $completetags, qa_opt('page_size_ask_tags'));
else
} else {
unset($form['fields']['tags']);
}
if ($question['isbyuser']) {
if (!qa_is_logged_in())
......@@ -398,128 +398,131 @@
isset($in['email']) ? $in['email'] : @$question['notify'], @$errors['email'], 'q_');
}
if (!qa_user_post_permit_error('permit_edit_silent', $question))
$form['fields']['silent']=array(
if (!qa_user_post_permit_error('permit_edit_silent', $question)) {
$form['fields']['silent'] = array(
'type' => 'checkbox',
'label' => qa_lang_html('question/save_silent_label'),
'tags' => 'name="q_silent"',
'value' => qa_html(@$in['silent']),
);
}
return $form;
}
}
function qa_page_q_edit_q_submit($question, $answers, $commentsfollows, $closepost, &$in, &$errors)
/*
Processes a POSTed form for editing the question and returns true if successful
*/
{
$in=array();
function qa_page_q_edit_q_submit($question, $answers, $commentsfollows, $closepost, &$in, &$errors)
{
$in = array();
if ($question['editable']) {
$in['title']=qa_get_post_title('q_title');
$in['title'] = qa_get_post_title('q_title');
qa_get_post_content('q_editor', 'q_content', $in['editor'], $in['content'], $in['format'], $in['text']);
$in['extra']=qa_opt('extra_field_active') ? qa_post_text('q_extra') : null;
$in['extra'] = qa_opt('extra_field_active') ? qa_post_text('q_extra') : null;
}
if ($question['retagcatable']) {
if (qa_using_tags())
$in['tags']=qa_get_tags_field_value('q_tags');
$in['tags'] = qa_get_tags_field_value('q_tags');
if (qa_using_categories())
$in['categoryid']=qa_get_category_field_value('q_category');
$in['categoryid'] = qa_get_category_field_value('q_category');
}
if (array_key_exists('categoryid', $in)) { // need to check if we can move it to that category, and if we need moderation
$categories=qa_db_select_with_pending(qa_db_category_nav_selectspec($in['categoryid'], true));
$categoryids=array_keys(qa_category_path($categories, $in['categoryid']));
$userlevel=qa_user_level_for_categories($categoryids);
$categories = qa_db_select_with_pending(qa_db_category_nav_selectspec($in['categoryid'], true));
$categoryids = array_keys(qa_category_path($categories, $in['categoryid']));
$userlevel = qa_user_level_for_categories($categoryids);
} else
$userlevel=null;
$userlevel = null;
if ($question['isbyuser']) {
$in['name']=qa_post_text('q_name');
$in['name'] = qa_post_text('q_name');
$in['notify'] = qa_post_text('q_notify') !== null;
$in['email']=qa_post_text('q_email');
$in['email'] = qa_post_text('q_email');
}
if (!qa_user_post_permit_error('permit_edit_silent', $question))
$in['silent']=qa_post_text('q_silent');
$in['silent'] = qa_post_text('q_silent');
// here the $in array only contains values for parts of the form that were displayed, so those are only ones checked by filters
$errors=array();
$errors = array();
if (!qa_check_form_security_code('edit-'.$question['postid'], qa_post_text('code')))
$errors['page']=qa_lang_html('misc/form_security_again');
if (!qa_check_form_security_code('edit-' . $question['postid'], qa_post_text('code')))
$errors['page'] = qa_lang_html('misc/form_security_again');
else {
$in['queued']=qa_opt('moderate_edited_again') && qa_user_moderation_reason($userlevel);
$in['queued'] = qa_opt('moderate_edited_again') && qa_user_moderation_reason($userlevel);
$filtermodules=qa_load_modules_with('filter', 'filter_question');
$filtermodules = qa_load_modules_with('filter', 'filter_question');
foreach ($filtermodules as $filtermodule) {
$oldin=$in;
$oldin = $in;
$filtermodule->filter_question($in, $errors, $question);
if ($question['editable'])
qa_update_post_text($in, $oldin);
}
if (array_key_exists('categoryid', $in) && strcmp($in['categoryid'], $question['categoryid']))
if (array_key_exists('categoryid', $in) && strcmp($in['categoryid'], $question['categoryid'])) {
if (qa_user_permit_error('permit_post_q', null, $userlevel))
$errors['categoryid']=qa_lang_html('question/category_ask_not_allowed');
$errors['categoryid'] = qa_lang_html('question/category_ask_not_allowed');
}
if (empty($errors)) {
$userid=qa_get_logged_in_userid();
$handle=qa_get_logged_in_handle();
$cookieid=qa_cookie_get();
$userid = qa_get_logged_in_userid();
$handle = qa_get_logged_in_handle();
$cookieid = qa_cookie_get();
// now we fill in the missing values in the $in array, so that we have everything we need for qa_question_set_content()
// we do things in this way to avoid any risk of a validation failure on elements the user can't see (e.g. due to admin setting changes)
if (!$question['editable']) {
$in['title']=$question['title'];
$in['content']=$question['content'];
$in['format']=$question['format'];
$in['text']=qa_viewer_text($in['content'], $in['format']);
$in['extra']=$question['extra'];
$in['title'] = $question['title'];
$in['content'] = $question['content'];
$in['format'] = $question['format'];
$in['text'] = qa_viewer_text($in['content'], $in['format']);
$in['extra'] = $question['extra'];
}
if (!isset($in['tags']))
$in['tags']=qa_tagstring_to_tags($question['tags']);
$in['tags'] = qa_tagstring_to_tags($question['tags']);
if (!array_key_exists('categoryid', $in))
$in['categoryid']=$question['categoryid'];
$in['categoryid'] = $question['categoryid'];
if (!isset($in['silent']))
$in['silent']=false;
$in['silent'] = false;
$setnotify=$question['isbyuser'] ? qa_combine_notify_email($question['userid'], $in['notify'], $in['email']) : $question['notify'];
$setnotify = $question['isbyuser'] ? qa_combine_notify_email($question['userid'], $in['notify'], $in['email']) : $question['notify'];
qa_question_set_content($question, $in['title'], $in['content'], $in['format'], $in['text'], qa_tags_to_tagstring($in['tags']),
$setnotify, $userid, $handle, $cookieid, $in['extra'], @$in['name'], $in['queued'], $in['silent']);
if (qa_using_categories() && strcmp($in['categoryid'], $question['categoryid']))
if (qa_using_categories() && strcmp($in['categoryid'], $question['categoryid'])) {
qa_question_set_category($question, $in['categoryid'], $userid, $handle, $cookieid,
$answers, $commentsfollows, $closepost, $in['silent']);
}
return true;
}
}
return false;
}
}
function qa_page_q_close_q_form(&$qa_content, $question, $id, $in, $errors)
/*
Returns a $qa_content form for closing the question and sets up other parts of $qa_content accordingly
*/
{
$form=array(
'tags' => 'method="post" action="'.qa_self_html().'"',
function qa_page_q_close_q_form(&$qa_content, $question, $id, $in, $errors)
{
$form = array(
'tags' => 'method="post" action="' . qa_self_html() . '"',
'id' => $id,
......@@ -531,7 +534,7 @@
'details' => array(
'tags' => 'name="q_close_details" id="q_close_details"',
'label' =>
'<span id="close_label_other">'.qa_lang_html('question/close_reason_title').'</span>',
'<span id="close_label_other">' . qa_lang_html('question/close_reason_title') . '</span>',
'value' => @$in['details'],
'error' => qa_html(@$errors['details']),
),
......@@ -551,92 +554,93 @@
'hidden' => array(
'doclose' => '1',
'code' => qa_get_form_security_code('close-'.$question['postid']),
'code' => qa_get_form_security_code('close-' . $question['postid']),
),
);
$qa_content['focusid']='q_close_details';
$qa_content['focusid'] = 'q_close_details';
return $form;
}
}
function qa_page_q_close_q_submit($question, $closepost, &$in, &$errors)
/*
Processes a POSTed form for closing the question and returns true if successful
*/
{
$in=array(
function qa_page_q_close_q_submit($question, $closepost, &$in, &$errors)
{
$in = array(
'details' => trim(qa_post_text('q_close_details')),
);
$userid=qa_get_logged_in_userid();
$handle=qa_get_logged_in_handle();
$cookieid=qa_cookie_get();
$userid = qa_get_logged_in_userid();
$handle = qa_get_logged_in_handle();
$cookieid = qa_cookie_get();
$isduplicateurl = filter_var($in['details'], FILTER_VALIDATE_URL);
if (!qa_check_form_security_code('close-'.$question['postid'], qa_post_text('code'))) {
$errors['details']=qa_lang_html('misc/form_security_again');
}
elseif ($isduplicateurl) {
if (!qa_check_form_security_code('close-' . $question['postid'], qa_post_text('code'))) {
$errors['details'] = qa_lang_html('misc/form_security_again');
} elseif ($isduplicateurl) {
// be liberal in what we accept, but there are two potential unlikely pitfalls here:
// a) URLs could have a fixed numerical path, e.g. http://qa.mysite.com/1/478/...
// b) There could be a question title which is just a number, e.g. http://qa.mysite.com/478/12345/...
// so we check if more than one question could match, and if so, show an error
$parts=preg_split('|[=/&]|', $in['details'], -1, PREG_SPLIT_NO_EMPTY);
$keypostids=array();
$parts = preg_split('|[=/&]|', $in['details'], -1, PREG_SPLIT_NO_EMPTY);
$keypostids = array();
foreach ($parts as $part)
foreach ($parts as $part) {
if (preg_match('/^[0-9]+$/', $part))
$keypostids[$part]=true;
$keypostids[$part] = true;
}
$questionids=qa_db_posts_filter_q_postids(array_keys($keypostids));
$questionids = qa_db_posts_filter_q_postids(array_keys($keypostids));
if ( (count($questionids)==1) && ($questionids[0]!=$question['postid']) ) {
if (count($questionids) == 1 && $questionids[0] != $question['postid']) {
qa_question_close_duplicate($question, $closepost, $questionids[0], $userid, $handle, $cookieid);
return true;
} else
$errors['details']=qa_lang('question/close_duplicate_error');
$errors['details'] = qa_lang('question/close_duplicate_error');
} else {
if (strlen($in['details'])>0) {
if (strlen($in['details']) > 0) {
qa_question_close_other($question, $closepost, $in['details'], $userid, $handle, $cookieid);
return true;
} else
$errors['details']=qa_lang('main/field_required');
$errors['details'] = qa_lang('main/field_required');
}
return false;
}
}
function qa_page_q_edit_a_form(&$qa_content, $id, $answer, $question, $answers, $commentsfollows, $in, $errors)
/*
Returns a $qa_content form for editing an answer and sets up other parts of $qa_content accordingly
*/
{
require_once QA_INCLUDE_DIR.'util/string.php';
function qa_page_q_edit_a_form(&$qa_content, $id, $answer, $question, $answers, $commentsfollows, $in, $errors)
{
require_once QA_INCLUDE_DIR . 'util/string.php';
$answerid=$answer['postid'];
$prefix='a'.$answerid.'_';
$answerid = $answer['postid'];
$prefix = 'a' . $answerid . '_';
$content=isset($in['content']) ? $in['content'] : $answer['content'];
$format=isset($in['format']) ? $in['format'] : $answer['format'];
$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);
$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;
$hascomments = false;
foreach ($commentsfollows as $commentfollow) {
if ($commentfollow['parentid'] == $answerid)
$hascomments = true;
}
$form=array(
'tags' => 'method="post" action="'.qa_self_html().'"',
$form = array(
'tags' => 'method="post" action="' . qa_self_html() . '"',
'id' => $id,
......@@ -646,7 +650,7 @@
'fields' => array(
'content' => array_merge(
qa_editor_load_field($editor, $qa_content, $content, $format, $prefix.'content', 12),
qa_editor_load_field($editor, $qa_content, $content, $format, $prefix . 'content', 12),
array(
'error' => qa_html(@$errors['content']),
)
......@@ -655,8 +659,8 @@
'buttons' => array(
'save' => array(
'tags' => 'onclick="qa_show_waiting_after(this, false); '.
(method_exists($editor, 'update_script') ? $editor->update_script($prefix.'content') : '').'"',
'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'),
),
......@@ -667,46 +671,48 @@
),
'hidden' => array(
$prefix.'editor' => qa_html($editorname),
$prefix.'dosave' => '1',
$prefix.'code' => qa_get_form_security_code('edit-'.$answerid),
$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();
$commentonoptions = array();
$lastbeforeid=$question['postid']; // used to find last post created before this answer - this is default given
$lastbeforetime=$question['created'];
$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));
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));
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'];
$lastbeforetime=$otheranswer['created'];
if ($otheranswer['created'] > $lastbeforetime) {
$lastbeforeid = $otheranswer['postid'];
$lastbeforetime = $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>',
$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',
$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,
......@@ -714,9 +720,9 @@
);
qa_set_display_rules($qa_content, array(
$prefix.'commenton' => $prefix.'dotoc',
$prefix.'toshown' => $prefix.'dotoc',
$prefix.'tohidden' => '!'.$prefix.'dotoc',
$prefix . 'commenton' => $prefix . 'dotoc',
$prefix . 'toshown' => $prefix . 'dotoc',
$prefix . 'tohidden' => '!' . $prefix . 'dotoc',
));
}
......@@ -731,73 +737,75 @@
isset($in['email']) ? $in['email'] : @$answer['notify'], @$errors['email'], $prefix);
}
if (!qa_user_post_permit_error('permit_edit_silent', $answer))
$form['fields']['silent']=array(
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"',
'tags' => 'name="' . $prefix . 'silent"',
'value' => qa_html(@$in['silent']),
);
}
return $form;
}
}
function qa_page_q_edit_a_submit($answer, $question, $answers, $commentsfollows, &$in, &$errors)
/*
Processes a POSTed form for editing an answer and returns the new type of the post if successful
*/
{
$answerid=$answer['postid'];
$prefix='a'.$answerid.'_';
$in=array(
'dotoc' => qa_post_text($prefix.'dotoc'),
'commenton' => qa_post_text($prefix.'commenton'),
function qa_page_q_edit_a_submit($answer, $question, $answers, $commentsfollows, &$in, &$errors)
{
$answerid = $answer['postid'];
$prefix = 'a' . $answerid . '_';
$in = array(
'dotoc' => qa_post_text($prefix . 'dotoc'),
'commenton' => qa_post_text($prefix . 'commenton'),
);
if ($answer['isbyuser']) {
$in['name']=qa_post_text($prefix.'name');
$in['notify'] = qa_post_text($prefix.'notify') !== null;
$in['email']=qa_post_text($prefix.'email');
$in['name'] = qa_post_text($prefix . 'name');
$in['notify'] = qa_post_text($prefix . 'notify') !== null;
$in['email'] = qa_post_text($prefix . 'email');
}
if (!qa_user_post_permit_error('permit_edit_silent', $answer))
$in['silent']=qa_post_text($prefix.'silent');
$in['silent'] = qa_post_text($prefix . 'silent');
qa_get_post_content($prefix.'editor', $prefix.'content', $in['editor'], $in['content'], $in['format'], $in['text']);
qa_get_post_content($prefix . 'editor', $prefix . 'content', $in['editor'], $in['content'], $in['format'], $in['text']);
// here the $in array only contains values for parts of the form that were displayed, so those are only ones checked by filters
$errors=array();
$errors = array();
if (!qa_check_form_security_code('edit-'.$answerid, qa_post_text($prefix.'code')))
$errors['content']=qa_lang_html('misc/form_security_again');
if (!qa_check_form_security_code('edit-' . $answerid, qa_post_text($prefix . 'code')))
$errors['content'] = qa_lang_html('misc/form_security_again');
else {
$in['queued']=qa_opt('moderate_edited_again') && qa_user_moderation_reason(qa_user_level_for_post($answer));
$in['queued'] = qa_opt('moderate_edited_again') && qa_user_moderation_reason(qa_user_level_for_post($answer));
$filtermodules=qa_load_modules_with('filter', 'filter_answer');
$filtermodules = qa_load_modules_with('filter', 'filter_answer');
foreach ($filtermodules as $filtermodule) {
$oldin=$in;
$oldin = $in;
$filtermodule->filter_answer($in, $errors, $question, $answer);
qa_update_post_text($in, $oldin);
}
if (empty($errors)) {
$userid=qa_get_logged_in_userid();
$handle=qa_get_logged_in_handle();
$cookieid=qa_cookie_get();
$userid = qa_get_logged_in_userid();
$handle = qa_get_logged_in_handle();
$cookieid = qa_cookie_get();
if (!isset($in['silent']))
$in['silent']=false;
$in['silent'] = false;
$setnotify=$answer['isbyuser'] ? qa_combine_notify_email($answer['userid'], $in['notify'], $in['email']) : $answer['notify'];
$setnotify = $answer['isbyuser'] ? qa_combine_notify_email($answer['userid'], $in['notify'], $in['email']) : $answer['notify'];
if ($in['dotoc'] && (
(($in['commenton']==$question['postid']) && $question['commentable']) ||
(($in['commenton']!=$answerid) && @$answers[$in['commenton']]['commentable'])
)) { // convert to a comment
(($in['commenton'] == $question['postid']) && $question['commentable']) ||
(($in['commenton'] != $answerid) && @$answers[$in['commenton']]['commentable'])
)
) { // convert to a comment
if (qa_user_limits_remaining(QA_LIMIT_COMMENTS)) { // already checked 'permit_post_c'
qa_answer_to_comment($answer, $in['commenton'], $in['content'], $in['format'], $in['text'], $setnotify,
......@@ -806,7 +814,7 @@
return 'C'; // to signify that redirect should be to the comment
} else
$errors['content']=qa_lang_html('question/comment_limit'); // not really best place for error, but it will do
$errors['content'] = qa_lang_html('question/comment_limit'); // not really best place for error, but it will do
} else {
qa_answer_set_content($answer, $in['content'], $in['format'], $in['text'], $setnotify,
......@@ -818,14 +826,14 @@
}
return null;
}
}
function qa_page_q_do_comment($question, $parent, $commentsfollows, $pagestart, $usecaptcha, &$cnewin, &$cnewerrors, &$formtype, &$formpostid, &$error)
/*
Processes a request to add a comment to $parent, with antecedent $question, checking for permissions errors
*/
{
function qa_page_q_do_comment($question, $parent, $commentsfollows, $pagestart, $usecaptcha, &$cnewin, &$cnewerrors, &$formtype, &$formpostid, &$error)
{
// The 'approve', 'login', 'confirm', 'userblock', 'ipblock' permission errors are reported to the user here
// The other option ('level') prevents the comment button being shown, in qa_page_q_post_rules(...)
......@@ -834,62 +842,62 @@
switch (qa_user_post_permit_error('permit_post_c', $parent, QA_LIMIT_COMMENTS)) {
case 'login':
$error=qa_insert_login_links(qa_lang_html('question/comment_must_login'), qa_request());
$error = qa_insert_login_links(qa_lang_html('question/comment_must_login'), qa_request());
break;
case 'confirm':
$error=qa_insert_login_links(qa_lang_html('question/comment_must_confirm'), qa_request());
$error = qa_insert_login_links(qa_lang_html('question/comment_must_confirm'), qa_request());
break;
case 'approve':
$error=qa_lang_html('question/comment_must_be_approved');
$error = qa_lang_html('question/comment_must_be_approved');
break;
case 'limit':
$error=qa_lang_html('question/comment_limit');
$error = qa_lang_html('question/comment_limit');
break;
default:
$error=qa_lang_html('users/no_permission');
$error = qa_lang_html('users/no_permission');
break;
case false:
if (qa_clicked('c'.$parentid.'_doadd')) {
$commentid=qa_page_q_add_c_submit($question, $parent, $commentsfollows, $usecaptcha, $cnewin[$parentid], $cnewerrors[$parentid]);
if (qa_clicked('c' . $parentid . '_doadd')) {
$commentid = qa_page_q_add_c_submit($question, $parent, $commentsfollows, $usecaptcha, $cnewin[$parentid], $cnewerrors[$parentid]);
if (isset($commentid))
qa_page_q_refresh($pagestart, null, 'C', $commentid);
else {
$formtype='c_add';
$formpostid=$parentid; // show form again
$formtype = 'c_add';
$formpostid = $parentid; // show form again
}
} else {
$formtype='c_add';
$formpostid=$parentid; // show form first time
$formtype = 'c_add';
$formpostid = $parentid; // show form first time
}
break;
}
}
}
function qa_page_q_edit_c_form(&$qa_content, $id, $comment, $in, $errors)
/*
Returns a $qa_content form for editing a comment and sets up other parts of $qa_content accordingly
*/
{
$commentid=$comment['postid'];
$prefix='c'.$commentid.'_';
function qa_page_q_edit_c_form(&$qa_content, $id, $comment, $in, $errors)
{
$commentid = $comment['postid'];
$prefix = 'c' . $commentid . '_';
$content=isset($in['content']) ? $in['content'] : $comment['content'];
$format=isset($in['format']) ? $in['format'] : $comment['format'];
$content = isset($in['content']) ? $in['content'] : $comment['content'];
$format = isset($in['format']) ? $in['format'] : $comment['format'];
$editorname=isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_cs');
$editor=qa_load_editor($content, $format, $editorname);
$editorname = isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_cs');
$editor = qa_load_editor($content, $format, $editorname);
$form=array(
'tags' => 'method="post" action="'.qa_self_html().'"',
$form = array(
'tags' => 'method="post" action="' . qa_self_html() . '"',
'id' => $id,
......@@ -899,7 +907,7 @@
'fields' => array(
'content' => array_merge(
qa_editor_load_field($editor, $qa_content, $content, $format, $prefix.'content', 4, true),
qa_editor_load_field($editor, $qa_content, $content, $format, $prefix . 'content', 4, true),
array(
'error' => qa_html(@$errors['content']),
)
......@@ -908,8 +916,8 @@
'buttons' => array(
'save' => array(
'tags' => 'onclick="qa_show_waiting_after(this, false); '.
(method_exists($editor, 'update_script') ? $editor->update_script($prefix.'content') : '').'"',
'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'),
),
......@@ -920,9 +928,9 @@
),
'hidden' => array(
$prefix.'editor' => qa_html($editorname),
$prefix.'dosave' => '1',
$prefix.'code' => qa_get_form_security_code('edit-'.$commentid),
$prefix . 'editor' => qa_html($editorname),
$prefix . 'dosave' => '1',
$prefix . 'code' => qa_get_form_security_code('edit-' . $commentid),
),
);
......@@ -935,65 +943,66 @@
isset($in['email']) ? $in['email'] : @$comment['notify'], @$errors['email'], $prefix);
}
if (!qa_user_post_permit_error('permit_edit_silent', $comment))
$form['fields']['silent']=array(
if (!qa_user_post_permit_error('permit_edit_silent', $comment)) {
$form['fields']['silent'] = array(
'type' => 'checkbox',
'label' => qa_lang_html('question/save_silent_label'),
'tags' => 'name="'.$prefix.'silent"',
'tags' => 'name="' . $prefix . 'silent"',
'value' => qa_html(@$in['silent']),
);
}
return $form;
}
}
function qa_page_q_edit_c_submit($comment, $question, $parent, &$in, &$errors)
/*
Processes a POSTed form for editing a comment and returns true if successful
*/
{
$commentid=$comment['postid'];
$prefix='c'.$commentid.'_';
function qa_page_q_edit_c_submit($comment, $question, $parent, &$in, &$errors)
{
$commentid = $comment['postid'];
$prefix = 'c' . $commentid . '_';
$in=array();
$in = array();
if ($comment['isbyuser']) {
$in['name']=qa_post_text($prefix.'name');
$in['notify'] = qa_post_text($prefix.'notify') !== null;
$in['email']=qa_post_text($prefix.'email');
$in['name'] = qa_post_text($prefix . 'name');
$in['notify'] = qa_post_text($prefix . 'notify') !== null;
$in['email'] = qa_post_text($prefix . 'email');
}
if (!qa_user_post_permit_error('permit_edit_silent', $comment))
$in['silent']=qa_post_text($prefix.'silent');
$in['silent'] = qa_post_text($prefix . 'silent');
qa_get_post_content($prefix.'editor', $prefix.'content', $in['editor'], $in['content'], $in['format'], $in['text']);
qa_get_post_content($prefix . 'editor', $prefix . 'content', $in['editor'], $in['content'], $in['format'], $in['text']);
// here the $in array only contains values for parts of the form that were displayed, so those are only ones checked by filters
$errors=array();
$errors = array();
if (!qa_check_form_security_code('edit-'.$commentid, qa_post_text($prefix.'code')))
$errors['content']=qa_lang_html('misc/form_security_again');
if (!qa_check_form_security_code('edit-' . $commentid, qa_post_text($prefix . 'code')))
$errors['content'] = qa_lang_html('misc/form_security_again');
else {
$in['queued']=qa_opt('moderate_edited_again') && qa_user_moderation_reason(qa_user_level_for_post($comment));
$in['queued'] = qa_opt('moderate_edited_again') && qa_user_moderation_reason(qa_user_level_for_post($comment));
$filtermodules=qa_load_modules_with('filter', 'filter_comment');
$filtermodules = qa_load_modules_with('filter', 'filter_comment');
foreach ($filtermodules as $filtermodule) {
$oldin=$in;
$oldin = $in;
$filtermodule->filter_comment($in, $errors, $question, $parent, $comment);
qa_update_post_text($in, $oldin);
}
if (empty($errors)) {
$userid=qa_get_logged_in_userid();
$handle=qa_get_logged_in_handle();
$cookieid=qa_cookie_get();
$userid = qa_get_logged_in_userid();
$handle = qa_get_logged_in_handle();
$cookieid = qa_cookie_get();
if (!isset($in['silent']))
$in['silent']=false;
$in['silent'] = false;
$setnotify=$comment['isbyuser'] ? qa_combine_notify_email($comment['userid'], $in['notify'], $in['email']) : $comment['notify'];
$setnotify = $comment['isbyuser'] ? qa_combine_notify_email($comment['userid'], $in['notify'], $in['email']) : $comment['notify'];
qa_comment_set_content($comment, $in['content'], $in['format'], $in['text'], $setnotify,
$userid, $handle, $cookieid, $question, $parent, @$in['name'], $in['queued'], $in['silent']);
......@@ -1003,9 +1012,4 @@
}
return false;
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
}
......@@ -20,38 +20,38 @@
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../');
exit;
}
}
require_once QA_INCLUDE_DIR.'app/cookies.php';
require_once QA_INCLUDE_DIR.'app/format.php';
require_once QA_INCLUDE_DIR.'db/selects.php';
require_once QA_INCLUDE_DIR.'util/sort.php';
require_once QA_INCLUDE_DIR.'util/string.php';
require_once QA_INCLUDE_DIR.'app/captcha.php';
require_once QA_INCLUDE_DIR.'pages/question-view.php';
require_once QA_INCLUDE_DIR.'app/updates.php';
require_once QA_INCLUDE_DIR . 'app/cookies.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'util/sort.php';
require_once QA_INCLUDE_DIR . 'util/string.php';
require_once QA_INCLUDE_DIR . 'app/captcha.php';
require_once QA_INCLUDE_DIR . 'pages/question-view.php';
require_once QA_INCLUDE_DIR . 'app/updates.php';
$questionid=qa_request_part(0);
$userid=qa_get_logged_in_userid();
$cookieid=qa_cookie_get();
$pagestate=qa_get_state();
$questionid = qa_request_part(0);
$userid = qa_get_logged_in_userid();
$cookieid = qa_cookie_get();
$pagestate = qa_get_state();
// Get information about this question
$cacheHandler = Q2A_Storage_CacheManager::getInstance();
$cacheKey = "page:question:$questionid";
$useCache = $userid === null && $cacheHandler->isEnabled() && !qa_is_http_post() && empty($pagestate);
$saveCache = false;
$cacheHandler = Q2A_Storage_CacheManager::getInstance();
$cacheKey = "page:question:$questionid";
$useCache = $userid === null && $cacheHandler->isEnabled() && !qa_is_http_post() && empty($pagestate);
$saveCache = false;
if ($useCache) {
if ($useCache) {
$questionData = $cacheHandler->get($cacheKey);
}
}
if (!isset($questionData)) {
if (!isset($questionData)) {
$questionData = qa_db_select_with_pending(
qa_db_full_post_selectspec($userid, $questionid),
qa_db_full_child_posts_selectspec($userid, $questionid),
......@@ -66,15 +66,15 @@
// whether to save the cache (actioned below, after basic checks)
$saveCache = $useCache;
}
}
list($question, $childposts, $achildposts, $parentquestion, $closepost, $duplicateposts, $extravalue, $categories, $favorite) = $questionData;
list($question, $childposts, $achildposts, $parentquestion, $closepost, $duplicateposts, $extravalue, $categories, $favorite) = $questionData;
if ($question['basetype']!='Q') // don't allow direct viewing of other types of post
$question=null;
if ($question['basetype'] != 'Q') // don't allow direct viewing of other types of post
$question = null;
if (isset($question)) {
if (isset($question)) {
$q_request = qa_q_request($questionid, $question['title']);
if (trim($q_request, '/') !== trim(qa_request(), '/')) {
......@@ -82,343 +82,347 @@
qa_redirect($q_request);
}
$question['extra']=$extravalue;
$question['extra'] = $extravalue;
$answers=qa_page_q_load_as($question, $childposts);
$commentsfollows=qa_page_q_load_c_follows($question, $childposts, $achildposts, $duplicateposts);
$answers = qa_page_q_load_as($question, $childposts);
$commentsfollows = qa_page_q_load_c_follows($question, $childposts, $achildposts, $duplicateposts);
$question=$question+qa_page_q_post_rules($question, null, null, $childposts+$duplicateposts); // array union
$question = $question + qa_page_q_post_rules($question, null, null, $childposts + $duplicateposts); // array union
if ($question['selchildid'] && (@$answers[$question['selchildid']]['type']!='A'))
$question['selchildid']=null; // if selected answer is hidden or somehow not there, consider it not selected
if ($question['selchildid'] && (@$answers[$question['selchildid']]['type'] != 'A'))
$question['selchildid'] = null; // if selected answer is hidden or somehow not there, consider it not selected
foreach ($answers as $key => $answer) {
$answers[$key]=$answer+qa_page_q_post_rules($answer, $question, $answers, $achildposts);
$answers[$key]['isselected']=($answer['postid']==$question['selchildid']);
$answers[$key] = $answer + qa_page_q_post_rules($answer, $question, $answers, $achildposts);
$answers[$key]['isselected'] = ($answer['postid'] == $question['selchildid']);
}
foreach ($commentsfollows as $key => $commentfollow) {
$parent=($commentfollow['parentid']==$questionid) ? $question : @$answers[$commentfollow['parentid']];
$commentsfollows[$key]=$commentfollow+qa_page_q_post_rules($commentfollow, $parent, $commentsfollows, null);
}
$parent = ($commentfollow['parentid'] == $questionid) ? $question : @$answers[$commentfollow['parentid']];
$commentsfollows[$key] = $commentfollow + qa_page_q_post_rules($commentfollow, $parent, $commentsfollows, null);
}
}
// Deal with question not found or not viewable, otherwise report the view event
if (!isset($question))
return include QA_INCLUDE_DIR.'qa-page-not-found.php';
if (!isset($question))
return include QA_INCLUDE_DIR . 'qa-page-not-found.php';
if (!$question['viewable']) {
$qa_content=qa_content_prepare();
if (!$question['viewable']) {
$qa_content = qa_content_prepare();
if ($question['queued'])
$qa_content['error']=qa_lang_html('question/q_waiting_approval');
$qa_content['error'] = qa_lang_html('question/q_waiting_approval');
elseif ($question['flagcount'] && !isset($question['lastuserid']))
$qa_content['error']=qa_lang_html('question/q_hidden_flagged');
$qa_content['error'] = qa_lang_html('question/q_hidden_flagged');
elseif ($question['authorlast'])
$qa_content['error']=qa_lang_html('question/q_hidden_author');
$qa_content['error'] = qa_lang_html('question/q_hidden_author');
else
$qa_content['error']=qa_lang_html('question/q_hidden_other');
$qa_content['error'] = qa_lang_html('question/q_hidden_other');
$qa_content['suggest_next']=qa_html_suggest_qs_tags(qa_using_tags());
$qa_content['suggest_next'] = qa_html_suggest_qs_tags(qa_using_tags());
return $qa_content;
}
}
$permiterror=qa_user_post_permit_error('permit_view_q_page', $question, null, false);
$permiterror = qa_user_post_permit_error('permit_view_q_page', $question, null, false);
if ( $permiterror && (qa_is_human_probably() || !qa_opt('allow_view_q_bots')) ) {
$qa_content=qa_content_prepare();
$topage=qa_q_request($questionid, $question['title']);
if ($permiterror && (qa_is_human_probably() || !qa_opt('allow_view_q_bots'))) {
$qa_content = qa_content_prepare();
$topage = qa_q_request($questionid, $question['title']);
switch ($permiterror) {
case 'login':
$qa_content['error']=qa_insert_login_links(qa_lang_html('main/view_q_must_login'), $topage);
$qa_content['error'] = qa_insert_login_links(qa_lang_html('main/view_q_must_login'), $topage);
break;
case 'confirm':
$qa_content['error']=qa_insert_login_links(qa_lang_html('main/view_q_must_confirm'), $topage);
$qa_content['error'] = qa_insert_login_links(qa_lang_html('main/view_q_must_confirm'), $topage);
break;
case 'approve':
$qa_content['error']=qa_lang_html('main/view_q_must_be_approved');
$qa_content['error'] = qa_lang_html('main/view_q_must_be_approved');
break;
default:
$qa_content['error']=qa_lang_html('users/no_permission');
$qa_content['error'] = qa_lang_html('users/no_permission');
break;
}
return $qa_content;
}
}
// Save question data to cache (if older than configured limit)
if ($saveCache) {
if ($saveCache) {
$questionAge = qa_opt('db_time') - $question['created'];
if ($questionAge > 86400 * qa_opt('caching_q_start')) {
$cacheHandler->set($cacheKey, $questionData, qa_opt('caching_q_time'));
}
}
}
// Determine if captchas will be required
$captchareason=qa_user_captcha_reason(qa_user_level_for_post($question));
$usecaptcha=($captchareason!=false);
$captchareason = qa_user_captcha_reason(qa_user_level_for_post($question));
$usecaptcha = ($captchareason != false);
// If we're responding to an HTTP POST, include file that handles all posting/editing/etc... logic
// This is in a separate file because it's a *lot* of logic, and will slow down ordinary page views
$pagestart=qa_get_start();
$showid=qa_get('show');
$pageerror=null;
$formtype=null;
$formpostid=null;
$jumptoanchor=null;
$commentsall=null;
if (substr($pagestate, 0, 13)=='showcomments-') {
$commentsall=substr($pagestate, 13);
$pagestate=null;
} elseif (isset($showid)) {
foreach ($commentsfollows as $comment)
if ($comment['postid']==$showid) {
$commentsall=$comment['parentid'];
$pagestart = qa_get_start();
$showid = qa_get('show');
$pageerror = null;
$formtype = null;
$formpostid = null;
$jumptoanchor = null;
$commentsall = null;
if (substr($pagestate, 0, 13) == 'showcomments-') {
$commentsall = substr($pagestate, 13);
$pagestate = null;
} elseif (isset($showid)) {
foreach ($commentsfollows as $comment) {
if ($comment['postid'] == $showid) {
$commentsall = $comment['parentid'];
break;
}
}
}
if (qa_is_http_post() || strlen($pagestate))
require QA_INCLUDE_DIR.'pages/question-post.php';
if (qa_is_http_post() || strlen($pagestate))
require QA_INCLUDE_DIR . 'pages/question-post.php';
$formrequested=isset($formtype);
$formrequested = isset($formtype);
if ((!$formrequested) && $question['answerbutton']) {
$immedoption=qa_opt('show_a_form_immediate');
if ((!$formrequested) && $question['answerbutton']) {
$immedoption = qa_opt('show_a_form_immediate');
if ( ($immedoption=='always') || (($immedoption=='if_no_as') && (!$question['isbyuser']) && (!$question['acount'])) )
$formtype='a_add'; // show answer form by default
}
if (($immedoption == 'always') || (($immedoption == 'if_no_as') && (!$question['isbyuser']) && (!$question['acount'])))
$formtype = 'a_add'; // show answer form by default
}
// Get information on the users referenced
$usershtml=qa_userids_handles_html(array_merge(array($question), $answers, $commentsfollows), true);
$usershtml = qa_userids_handles_html(array_merge(array($question), $answers, $commentsfollows), true);
// Prepare content for theme
$qa_content=qa_content_prepare(true, array_keys(qa_category_path($categories, $question['categoryid'])));
$qa_content = qa_content_prepare(true, array_keys(qa_category_path($categories, $question['categoryid'])));
if (isset($userid) && !$formrequested)
$qa_content['favorite']=qa_favorite_form(QA_ENTITY_QUESTION, $questionid, $favorite,
if (isset($userid) && !$formrequested)
$qa_content['favorite'] = qa_favorite_form(QA_ENTITY_QUESTION, $questionid, $favorite,
qa_lang($favorite ? 'question/remove_q_favorites' : 'question/add_q_favorites'));
$qa_content['script_rel'][]='qa-content/qa-question.js?'.QA_VERSION;
$qa_content['script_rel'][] = 'qa-content/qa-question.js?' . QA_VERSION;
if (isset($pageerror))
$qa_content['error']=$pageerror; // might also show voting error set in qa-index.php
if (isset($pageerror))
$qa_content['error'] = $pageerror; // might also show voting error set in qa-index.php
elseif ($question['queued'])
$qa_content['error']=$question['isbyuser'] ? qa_lang_html('question/q_your_waiting_approval') : qa_lang_html('question/q_waiting_your_approval');
elseif ($question['queued'])
$qa_content['error'] = $question['isbyuser'] ? qa_lang_html('question/q_your_waiting_approval') : qa_lang_html('question/q_waiting_your_approval');
if ($question['hidden'])
$qa_content['hidden']=true;
if ($question['hidden'])
$qa_content['hidden'] = true;
qa_sort_by($commentsfollows, 'created');
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' :
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;
$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);
} 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['title'] = $qa_content['q_view']['title'];
$qa_content['description']=qa_html(qa_shorten_string_line(qa_viewer_text($question['content'], $question['format']), 150));
$qa_content['description'] = qa_html(qa_shorten_string_line(qa_viewer_text($question['content'], $question['format']), 150));
$categorykeyword=@$categories[$question['categoryid']]['title'];
$categorykeyword = @$categories[$question['categoryid']]['title'];
$qa_content['keywords']=qa_html(implode(',', array_merge(
$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) {
$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],
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],
$qa_content['a_form']['c_list'] = qa_page_q_comment_follow_list($question, $answers[$formpostid],
$commentsfollows, true, $usershtml, $formrequested, $formpostid);
$jumptoanchor='a'.$formpostid;
$jumptoanchor = 'a' . $formpostid;
} elseif (($formtype=='a_add') || ($question['answerbutton'] && !$formrequested)) {
$qa_content['a_form']=qa_page_q_add_a_form($qa_content, 'anew', $captchareason, $question, @$anewin, @$anewerrors, $formtype=='a_add', $formrequested);
} elseif (($formtype == 'a_add') || ($question['answerbutton'] && !$formrequested)) {
$qa_content['a_form'] = qa_page_q_add_a_form($qa_content, 'anew', $captchareason, $question, @$anewin, @$anewerrors, $formtype == 'a_add', $formrequested);
if ($formrequested)
$jumptoanchor='anew';
elseif ($formtype=='a_add')
$qa_content['script_onloads'][]=array(
if ($formrequested) {
$jumptoanchor = 'anew';
} elseif ($formtype == 'a_add') {
$qa_content['script_onloads'][] = array(
"qa_element_revealed=document.getElementById('anew');"
);
}
}
// Prepare content for comments on the question, plus add or edit comment forms
if ($formtype=='q_close') {
$qa_content['q_view']['c_form']=qa_page_q_close_q_form($qa_content, $question, 'close', @$closein, @$closeerrors);
$jumptoanchor='close';
if ($formtype == 'q_close') {
$qa_content['q_view']['c_form'] = qa_page_q_close_q_form($qa_content, $question, 'close', @$closein, @$closeerrors);
$jumptoanchor = 'close';
} elseif ((($formtype=='c_add') && ($formpostid==$questionid)) || ($question['commentbutton'] && !$formrequested) ) { // ...to be added
$qa_content['q_view']['c_form']=qa_page_q_add_c_form($qa_content, $question, $question, 'c'.$questionid,
$captchareason, @$cnewin[$questionid], @$cnewerrors[$questionid], $formtype=='c_add');
} elseif ((($formtype == 'c_add') && ($formpostid == $questionid)) || ($question['commentbutton'] && !$formrequested)) { // ...to be added
$qa_content['q_view']['c_form'] = qa_page_q_add_c_form($qa_content, $question, $question, 'c' . $questionid,
$captchareason, @$cnewin[$questionid], @$cnewerrors[$questionid], $formtype == 'c_add');
if (($formtype=='c_add') && ($formpostid==$questionid)) {
$jumptoanchor='c'.$questionid;
$commentsall=$questionid;
if (($formtype == 'c_add') && ($formpostid == $questionid)) {
$jumptoanchor = 'c' . $questionid;
$commentsall = $questionid;
}
} elseif (($formtype=='c_edit') && (@$commentsfollows[$formpostid]['parentid']==$questionid)) { // ...being edited
$qa_content['q_view']['c_form']=qa_page_q_edit_c_form($qa_content, 'c'.$formpostid, $commentsfollows[$formpostid],
} elseif (($formtype == 'c_edit') && (@$commentsfollows[$formpostid]['parentid'] == $questionid)) { // ...being edited
$qa_content['q_view']['c_form'] = qa_page_q_edit_c_form($qa_content, 'c' . $formpostid, $commentsfollows[$formpostid],
@$ceditin[$formpostid], @$cediterrors[$formpostid]);
$jumptoanchor='c'.$formpostid;
$commentsall=$questionid;
}
$jumptoanchor = 'c' . $formpostid;
$commentsall = $questionid;
}
$qa_content['q_view']['c_list']=qa_page_q_comment_follow_list($question, $question, $commentsfollows,
$commentsall==$questionid, $usershtml, $formrequested, $formpostid); // ...for viewing
$qa_content['q_view']['c_list'] = qa_page_q_comment_follow_list($question, $question, $commentsfollows,
$commentsall == $questionid, $usershtml, $formrequested, $formpostid); // ...for viewing
// Prepare content for existing answers (could be added to by Ajax)
$qa_content['a_list']=array(
$qa_content['a_list'] = array(
'tags' => 'id="a_list"',
'as' => array(),
);
);
// sort according to the site preferences
// sort according to the site preferences
if (qa_opt('sort_answers_by')=='votes') {
if (qa_opt('sort_answers_by') == 'votes') {
foreach ($answers as $answerid => $answer)
$answers[$answerid]['sortvotes']=$answer['downvotes']-$answer['upvotes'];
$answers[$answerid]['sortvotes'] = $answer['downvotes'] - $answer['upvotes'];
qa_sort_by($answers, 'sortvotes', 'created');
} else
} else {
qa_sort_by($answers, 'created');
}
// further changes to ordering to deal with queued, hidden and selected answers
// further changes to ordering to deal with queued, hidden and selected answers
$countfortitle=$question['acount'];
$nextposition=10000;
$answerposition=array();
$countfortitle = $question['acount'];
$nextposition = 10000;
$answerposition = array();
foreach ($answers as $answerid => $answer)
foreach ($answers as $answerid => $answer) {
if ($answer['viewable']) {
$position=$nextposition++;
$position = $nextposition++;
if ($answer['hidden'])
$position+=10000;
$position += 10000;
elseif ($answer['queued']) {
$position-=10000;
$position -= 10000;
$countfortitle++; // include these in displayed count
} elseif ($answer['isselected'] && qa_opt('show_selected_first'))
$position-=5000;
$position -= 5000;
$answerposition[$answerid]=$position;
$answerposition[$answerid] = $position;
}
}
asort($answerposition, SORT_NUMERIC);
asort($answerposition, SORT_NUMERIC);
// extract IDs and prepare for pagination
// extract IDs and prepare for pagination
$answerids=array_keys($answerposition);
$countforpages=count($answerids);
$pagesize=qa_opt('page_size_q_as');
$answerids = array_keys($answerposition);
$countforpages = count($answerids);
$pagesize = qa_opt('page_size_q_as');
// see if we need to display a particular answer
// see if we need to display a particular answer
if (isset($showid)) {
if (isset($showid)) {
if (isset($commentsfollows[$showid]))
$showid=$commentsfollows[$showid]['parentid'];
$showid = $commentsfollows[$showid]['parentid'];
$position=array_search($showid, $answerids);
$position = array_search($showid, $answerids);
if (is_numeric($position))
$pagestart=floor($position/$pagesize)*$pagesize;
}
$pagestart = floor($position / $pagesize) * $pagesize;
}
// set the canonical url based on possible pagination
// set the canonical url based on possible pagination
$qa_content['canonical']=qa_path_html(qa_q_request($question['postid'], $question['title']),
($pagestart>0) ? array('start' => $pagestart) : null, qa_opt('site_url'));
$qa_content['canonical'] = qa_path_html(qa_q_request($question['postid'], $question['title']),
($pagestart > 0) ? array('start' => $pagestart) : null, qa_opt('site_url'));
// build the actual answer list
// build the actual answer list
$answerids=array_slice($answerids, $pagestart, $pagesize);
$answerids = array_slice($answerids, $pagestart, $pagesize);
foreach ($answerids as $answerid) {
$answer=$answers[$answerid];
foreach ($answerids as $answerid) {
$answer = $answers[$answerid];
if (!(($formtype=='a_edit') && ($formpostid==$answerid))) {
$a_view=qa_page_q_answer_view($question, $answer, $answer['isselected'], $usershtml, $formrequested);
if (!($formtype == 'a_edit' && $formpostid == $answerid)) {
$a_view = qa_page_q_answer_view($question, $answer, $answer['isselected'], $usershtml, $formrequested);
// Prepare content for comments on this answer, plus add or edit comment forms
if ((($formtype=='c_add') && ($formpostid==$answerid)) || ($answer['commentbutton'] && !$formrequested) ) { // ...to be added
$a_view['c_form']=qa_page_q_add_c_form($qa_content, $question, $answer, 'c'.$answerid,
$captchareason, @$cnewin[$answerid], @$cnewerrors[$answerid], $formtype=='c_add');
if (($formtype == 'c_add' && $formpostid == $answerid) || ($answer['commentbutton'] && !$formrequested)) { // ...to be added
$a_view['c_form'] = qa_page_q_add_c_form($qa_content, $question, $answer, 'c' . $answerid,
$captchareason, @$cnewin[$answerid], @$cnewerrors[$answerid], $formtype == 'c_add');
if (($formtype=='c_add') && ($formpostid==$answerid)) {
$jumptoanchor='c'.$answerid;
$commentsall=$answerid;
if ($formtype == 'c_add' && $formpostid == $answerid) {
$jumptoanchor = 'c' . $answerid;
$commentsall = $answerid;
}
} elseif (($formtype=='c_edit') && (@$commentsfollows[$formpostid]['parentid']==$answerid)) { // ...being edited
$a_view['c_form']=qa_page_q_edit_c_form($qa_content, 'c'.$formpostid, $commentsfollows[$formpostid],
} elseif ($formtype == 'c_edit' && @$commentsfollows[$formpostid]['parentid'] == $answerid) { // ...being edited
$a_view['c_form'] = qa_page_q_edit_c_form($qa_content, 'c' . $formpostid, $commentsfollows[$formpostid],
@$ceditin[$formpostid], @$cediterrors[$formpostid]);
$jumptoanchor='c'.$formpostid;
$commentsall=$answerid;
$jumptoanchor = 'c' . $formpostid;
$commentsall = $answerid;
}
$a_view['c_list']=qa_page_q_comment_follow_list($question, $answer, $commentsfollows,
$commentsall==$answerid, $usershtml, $formrequested, $formpostid); // ...for viewing
$a_view['c_list'] = qa_page_q_comment_follow_list($question, $answer, $commentsfollows,
$commentsall == $answerid, $usershtml, $formrequested, $formpostid); // ...for viewing
// Add the answer to the list
$qa_content['a_list']['as'][]=$a_view;
}
$qa_content['a_list']['as'][] = $a_view;
}
}
if ($question['basetype']=='Q') {
$qa_content['a_list']['title_tags']='id="a_list_title"';
if ($question['basetype'] == 'Q') {
$qa_content['a_list']['title_tags'] = 'id="a_list_title"';
if ($countfortitle > 0) {
$split = $countfortitle == 1
......@@ -429,44 +433,43 @@
$split['data'] = '<span itemprop="answerCount">' . $split['data'] . '</span>';
$qa_content['a_list']['title'] = $split['prefix'] . $split['data'] . $split['suffix'];
}
else
$qa_content['a_list']['title_tags'].=' style="display:none;" ';
}
} else
$qa_content['a_list']['title_tags'] .= ' style="display:none;" ';
}
if (!$formrequested)
$qa_content['page_links']=qa_html_page_links(qa_request(), $pagestart, $pagesize, $countforpages, qa_opt('pages_prev_next'), array(), false, 'a_list_title');
if (!$formrequested)
$qa_content['page_links'] = qa_html_page_links(qa_request(), $pagestart, $pagesize, $countforpages, qa_opt('pages_prev_next'), array(), false, 'a_list_title');
// Some generally useful stuff
if (qa_using_categories() && count($categories))
$qa_content['navigation']['cat']=qa_category_navigation($categories, $question['categoryid']);
if (qa_using_categories() && count($categories))
$qa_content['navigation']['cat'] = qa_category_navigation($categories, $question['categoryid']);
if (isset($jumptoanchor))
$qa_content['script_onloads'][]=array(
'qa_scroll_page_to($("#"+'.qa_js($jumptoanchor).').offset().top);'
if (isset($jumptoanchor))
$qa_content['script_onloads'][] = array(
'qa_scroll_page_to($("#"+' . qa_js($jumptoanchor) . ').offset().top);'
);
// Determine whether this request should be counted for page view statistics.
// The lastviewip check is now in the hotness query in order to bypass caching.
if (
if (
qa_opt('do_count_q_views') &&
(!$formrequested) &&
(!qa_is_http_post()) &&
qa_is_human_probably() &&
( (!$question['views']) || ( // if it has more than zero views
( (@inet_ntop($question['createip'])!=qa_remote_ip_address()) || (!isset($question['createip'])) ) && // and different IP from the creator
( ($question['userid']!=$userid) || (!isset($question['userid'])) ) && // and different user from the creator
( ($question['cookieid']!=$cookieid) || (!isset($question['cookieid'])) ) // and different cookieid from the creator
) )
)
$qa_content['inc_views_postid']=$questionid;
((!$question['views']) || ( // if it has more than zero views
((@inet_ntop($question['createip']) != qa_remote_ip_address()) || (!isset($question['createip']))) && // and different IP from the creator
(($question['userid'] != $userid) || (!isset($question['userid']))) && // and different user from the creator
(($question['cookieid'] != $cookieid) || (!isset($question['cookieid']))) // and different cookieid from the creator
))
)
$qa_content['inc_views_postid'] = $questionid;
return $qa_content;
return $qa_content;
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment