Commit ce3f945e by pupi1985

Extract closed question check into own function

parent 9f1907d8
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
require_once QA_INCLUDE_DIR . 'app/posts.php';
require_once QA_INCLUDE_DIR . 'app/users.php'; require_once QA_INCLUDE_DIR . 'app/users.php';
require_once QA_INCLUDE_DIR . 'app/limits.php'; require_once QA_INCLUDE_DIR . 'app/limits.php';
require_once QA_INCLUDE_DIR . 'db/selects.php'; require_once QA_INCLUDE_DIR . 'db/selects.php';
...@@ -37,7 +38,7 @@ list($question, $childposts) = qa_db_select_with_pending( ...@@ -37,7 +38,7 @@ list($question, $childposts) = qa_db_select_with_pending(
// Check if the question exists, is not closed, and whether the user has permission to do this // Check if the question exists, is not closed, and whether the user has permission to do this
if (@$question['basetype'] == 'Q' && !isset($question['closedbyid']) && (!qa_opt('do_close_on_select') || !isset($question['selchildid'])) && !qa_user_post_permit_error('permit_post_a', $question, QA_LIMIT_ANSWERS)) { if (@$question['basetype'] == 'Q' && !qa_post_is_closed($question) && !qa_user_post_permit_error('permit_post_a', $question, QA_LIMIT_ANSWERS)) {
require_once QA_INCLUDE_DIR . 'app/captcha.php'; require_once QA_INCLUDE_DIR . 'app/captcha.php';
require_once QA_INCLUDE_DIR . 'app/format.php'; require_once QA_INCLUDE_DIR . 'app/format.php';
require_once QA_INCLUDE_DIR . 'app/post-create.php'; require_once QA_INCLUDE_DIR . 'app/post-create.php';
......
...@@ -293,6 +293,7 @@ function qa_post_html_fields($post, $userid, $cookieid, $usershtml, $dummy, $opt ...@@ -293,6 +293,7 @@ function qa_post_html_fields($post, $userid, $cookieid, $usershtml, $dummy, $opt
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
require_once QA_INCLUDE_DIR . 'app/updates.php'; require_once QA_INCLUDE_DIR . 'app/updates.php';
require_once QA_INCLUDE_DIR . 'app/posts.php';
if (isset($options['blockwordspreg'])) if (isset($options['blockwordspreg']))
require_once QA_INCLUDE_DIR . 'util/string.php'; require_once QA_INCLUDE_DIR . 'util/string.php';
...@@ -320,8 +321,9 @@ function qa_post_html_fields($post, $userid, $cookieid, $usershtml, $dummy, $opt ...@@ -320,8 +321,9 @@ function qa_post_html_fields($post, $userid, $cookieid, $usershtml, $dummy, $opt
$fields['tags'] = 'id="' . qa_html($elementid) . '"'; $fields['tags'] = 'id="' . qa_html($elementid) . '"';
$fields['classes'] = ($isquestion && $favoritedview && @$post['userfavoriteq']) ? 'qa-q-favorited' : ''; $fields['classes'] = ($isquestion && $favoritedview && @$post['userfavoriteq']) ? 'qa-q-favorited' : '';
if ($isquestion && (isset($post['closedbyid']) || (qa_opt('do_close_on_select') && isset($post['selchildid'])))) if ($isquestion && qa_post_is_closed($post)) {
$fields['classes'] = ltrim($fields['classes'] . ' qa-q-closed'); $fields['classes'] = ltrim($fields['classes'] . ' qa-q-closed');
}
if ($microdata) { if ($microdata) {
if ($isanswer) { if ($isanswer) {
...@@ -621,7 +623,7 @@ function qa_post_html_fields($post, $userid, $cookieid, $usershtml, $dummy, $opt ...@@ -621,7 +623,7 @@ function qa_post_html_fields($post, $userid, $cookieid, $usershtml, $dummy, $opt
( // otherwise check if one of these conditions is fulfilled... ( // otherwise check if one of these conditions is fulfilled...
(!isset($post['created'])) || // ... we didn't show the created time (should never happen in practice) (!isset($post['created'])) || // ... we didn't show the created time (should never happen in practice)
($post['hidden'] && ($post['updatetype'] == QA_UPDATE_VISIBLE)) || // ... the post was hidden as the last action ($post['hidden'] && ($post['updatetype'] == QA_UPDATE_VISIBLE)) || // ... the post was hidden as the last action
((isset($post['closedbyid']) || (qa_opt('do_close_on_select') && isset($post['selchildid']))) && $post['updatetype'] == QA_UPDATE_CLOSED) || // ... the post was closed as the last action (qa_post_is_closed($post) && $post['updatetype'] == QA_UPDATE_CLOSED) || // ... the post was closed as the last action
(abs($post['updated'] - $post['created']) > 300) || // ... or over 5 minutes passed between create and update times (abs($post['updated'] - $post['created']) > 300) || // ... or over 5 minutes passed between create and update times
($post['lastuserid'] != $post['userid']) // ... or it was updated by a different user ($post['lastuserid'] != $post['userid']) // ... or it was updated by a different user
) )
...@@ -641,7 +643,7 @@ function qa_post_html_fields($post, $userid, $cookieid, $usershtml, $dummy, $opt ...@@ -641,7 +643,7 @@ function qa_post_html_fields($post, $userid, $cookieid, $usershtml, $dummy, $opt
break; break;
case QA_UPDATE_CLOSED: case QA_UPDATE_CLOSED:
$langstring = isset($post['closedbyid']) || (qa_opt('do_close_on_select') && isset($post['selchildid'])) ? 'main/closed' : 'main/reopened'; $langstring = qa_post_is_closed($post) ? 'main/closed' : 'main/reopened';
break; break;
case QA_UPDATE_TAGS: case QA_UPDATE_TAGS:
...@@ -842,7 +844,7 @@ function qa_other_to_q_html_fields($question, $userid, $cookieid, $usershtml, $d ...@@ -842,7 +844,7 @@ function qa_other_to_q_html_fields($question, $userid, $cookieid, $usershtml, $d
break; break;
case 'Q-' . QA_UPDATE_CLOSED: case 'Q-' . QA_UPDATE_CLOSED:
$isClosed = isset($question['closedbyid']) || (qa_opt('do_close_on_select') && isset($question['selchildid'])); $isClosed = qa_post_is_closed($question);
if (@$question['opersonal']) if (@$question['opersonal'])
$langstring = $isClosed ? 'misc/your_q_closed' : 'misc/your_q_reopened'; $langstring = $isClosed ? 'misc/your_q_closed' : 'misc/your_q_reopened';
else else
......
...@@ -207,8 +207,8 @@ function qa_post_set_selchildid($questionid, $answerid, $byuserid = null) ...@@ -207,8 +207,8 @@ function qa_post_set_selchildid($questionid, $answerid, $byuserid = null)
/** /**
* Closed $questionid if $closed is true, otherwise reopen it. If $closed is true, pass either the $originalpostid of * Close $questionid if $closed is true, otherwise reopen it. If $closed is true, pass either the $originalpostid of
* the question that it is a duplicate of, or a $note to explain why it's closed. Pass the identify of the user in * the question that it is a duplicate of, or a $note to explain why it's closed. Pass the identifier of the user in
* $byuserid (or null for an anonymous change). * $byuserid (or null for an anonymous change).
* @param $questionid * @param $questionid
* @param bool $closed * @param bool $closed
...@@ -234,6 +234,17 @@ function qa_post_set_closed($questionid, $closed = true, $originalpostid = null, ...@@ -234,6 +234,17 @@ function qa_post_set_closed($questionid, $closed = true, $originalpostid = null,
qa_question_close_clear($oldquestion, $oldclosepost, $byuserid, $byhandle, null); qa_question_close_clear($oldquestion, $oldclosepost, $byuserid, $byhandle, null);
} }
/**
* Return whether the given question is closed. This check takes into account the do_close_on_select option which
* considers questions with a selected answer as closed.
* @param array $question
* @return bool
*/
function qa_post_is_closed(array $question)
{
return isset($question['closedbyid']) || (isset($question['selchildid']) && qa_opt('do_close_on_select'));
}
/** /**
* Hide $postid if $hidden is true, otherwise show the post. Pass the identify of the user making this change in * Hide $postid if $hidden is true, otherwise show the post. Pass the identify of the user making this change in
......
...@@ -62,6 +62,7 @@ function qa_q_list_page_content($questions, $pagesize, $start, $count, $sometitl ...@@ -62,6 +62,7 @@ function qa_q_list_page_content($questions, $pagesize, $start, $count, $sometitl
require_once QA_INCLUDE_DIR . 'app/format.php'; require_once QA_INCLUDE_DIR . 'app/format.php';
require_once QA_INCLUDE_DIR . 'app/updates.php'; require_once QA_INCLUDE_DIR . 'app/updates.php';
require_once QA_INCLUDE_DIR . 'app/posts.php';
$userid = qa_get_logged_in_userid(); $userid = qa_get_logged_in_userid();
...@@ -97,11 +98,10 @@ function qa_q_list_page_content($questions, $pagesize, $start, $count, $sometitl ...@@ -97,11 +98,10 @@ function qa_q_list_page_content($questions, $pagesize, $start, $count, $sometitl
$defaults['categorypathprefix'] = $categorypathprefix; $defaults['categorypathprefix'] = $categorypathprefix;
} }
$closeOnSelect = qa_opt('do_close_on_select');
foreach ($questions as $question) { foreach ($questions as $question) {
$fields = qa_any_to_q_html_fields($question, $userid, qa_cookie_get(), $usershtml, null, qa_post_html_options($question, $defaults)); $fields = qa_any_to_q_html_fields($question, $userid, qa_cookie_get(), $usershtml, null, qa_post_html_options($question, $defaults));
if (!empty($fields['raw']['closedbyid']) || (!empty($fields['raw']['selchildid']) && $closeOnSelect)) { if (qa_post_is_closed($question)) {
$fields['closed'] = array( $fields['closed'] = array(
'state' => qa_lang_html('main/closed'), 'state' => qa_lang_html('main/closed'),
); );
......
...@@ -261,6 +261,8 @@ function qa_page_q_post_rules($post, $parentpost = null, $siblingposts = null, $ ...@@ -261,6 +261,8 @@ function qa_page_q_post_rules($post, $parentpost = null, $siblingposts = null, $
*/ */
function qa_page_q_question_view($question, $parentquestion, $closepost, $usershtml, $formrequested) function qa_page_q_question_view($question, $parentquestion, $closepost, $usershtml, $formrequested)
{ {
require_once QA_INCLUDE_DIR . 'app/posts.php';
$questionid = $question['postid']; $questionid = $question['postid'];
$userid = qa_get_logged_in_userid(); $userid = qa_get_logged_in_userid();
$cookieid = qa_cookie_get(); $cookieid = qa_cookie_get();
...@@ -428,7 +430,7 @@ function qa_page_q_question_view($question, $parentquestion, $closepost, $usersh ...@@ -428,7 +430,7 @@ function qa_page_q_question_view($question, $parentquestion, $closepost, $usersh
// Information about the question that this question is a duplicate of (if appropriate) // Information about the question that this question is a duplicate of (if appropriate)
if (isset($closepost) || (!empty($q_view['raw']['selchildid']) && qa_opt('do_close_on_select'))) { if (isset($closepost) || qa_post_is_closed($question)) {
if ($closepost['basetype'] == 'Q') { if ($closepost['basetype'] == 'Q') {
if ($closepost['hidden']) { if ($closepost['hidden']) {
// don't show link for hidden questions // don't show link for hidden questions
......
...@@ -280,6 +280,7 @@ switch ($feedtype) { ...@@ -280,6 +280,7 @@ switch ($feedtype) {
require_once QA_INCLUDE_DIR . 'app/format.php'; require_once QA_INCLUDE_DIR . 'app/format.php';
require_once QA_INCLUDE_DIR . 'app/updates.php'; require_once QA_INCLUDE_DIR . 'app/updates.php';
require_once QA_INCLUDE_DIR . 'app/posts.php';
require_once QA_INCLUDE_DIR . 'util/string.php'; require_once QA_INCLUDE_DIR . 'util/string.php';
if ($feedtype != 'search' && $feedtype != 'hot') // leave search results and hot questions sorted by relevance if ($feedtype != 'search' && $feedtype != 'hot') // leave search results and hot questions sorted by relevance
...@@ -337,7 +338,7 @@ foreach ($questions as $question) { ...@@ -337,7 +338,7 @@ foreach ($questions as $question) {
break; break;
case 'Q-' . QA_UPDATE_CLOSED: case 'Q-' . QA_UPDATE_CLOSED:
$langstring = isset($question['closedbyid']) || ($question['selchildid'] && qa_opt('do_close_on_select')) ? 'misc/feed_closed_prefix' : 'misc/feed_reopened_prefix'; $langstring = qa_post_is_closed($question) ? 'misc/feed_closed_prefix' : 'misc/feed_reopened_prefix';
break; break;
case 'Q-' . QA_UPDATE_TAGS: case 'Q-' . QA_UPDATE_TAGS:
......
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