Unverified Commit 952aee97 by Scott Committed by GitHub

Merge pull request #697 from pupi1985/patch-121

 Extract closed question check into own function
parents 44aa9ba8 c35d3af0
......@@ -19,6 +19,7 @@
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/limits.php';
require_once QA_INCLUDE_DIR . 'db/selects.php';
......@@ -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
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/format.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
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/posts.php';
if (isset($options['blockwordspreg']))
require_once QA_INCLUDE_DIR . 'util/string.php';
......@@ -320,8 +321,9 @@ function qa_post_html_fields($post, $userid, $cookieid, $usershtml, $dummy, $opt
$fields['tags'] = 'id="' . qa_html($elementid) . '"';
$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');
}
if ($microdata) {
if ($isanswer) {
......@@ -621,7 +623,7 @@ function qa_post_html_fields($post, $userid, $cookieid, $usershtml, $dummy, $opt
( // otherwise check if one of these conditions is fulfilled...
(!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
((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
($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
break;
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;
case QA_UPDATE_TAGS:
......@@ -842,7 +844,7 @@ function qa_other_to_q_html_fields($question, $userid, $cookieid, $usershtml, $d
break;
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'])
$langstring = $isClosed ? 'misc/your_q_closed' : 'misc/your_q_reopened';
else
......@@ -2359,6 +2361,7 @@ function qa_favorite_form($entitytype, $entityid, $favorite, $title)
* Format a number using the decimal point and thousand separator specified in the language files.
* If the number is compacted it is turned into a string such as 1.3k or 2.5m.
*
* @since 1.8.0
* @param integer $number Number to be formatted
* @param integer $decimals Amount of decimals to use (ignored if number gets shortened)
* @param bool $compact Whether the number can be shown as compact or not
......
......@@ -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
* the question that it is a duplicate of, or a $note to explain why it's closed. Pass the identify of the user in
* 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 identifier of the user in
* $byuserid (or null for an anonymous change).
* @param $questionid
* @param bool $closed
......@@ -234,6 +234,18 @@ function qa_post_set_closed($questionid, $closed = true, $originalpostid = 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.
* @since 1.8.2
* @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
......
......@@ -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/updates.php';
require_once QA_INCLUDE_DIR . 'app/posts.php';
$userid = qa_get_logged_in_userid();
......@@ -97,11 +98,10 @@ function qa_q_list_page_content($questions, $pagesize, $start, $count, $sometitl
$defaults['categorypathprefix'] = $categorypathprefix;
}
$closeOnSelect = qa_opt('do_close_on_select');
foreach ($questions as $question) {
$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(
'state' => qa_lang_html('main/closed'),
);
......
......@@ -520,6 +520,7 @@ if (QA_FINAL_EXTERNAL_USERS) {
* Return the URL to the $blobId with a stored size of $width and $height.
* Constrain the image to $size (width AND height)
*
* @since 1.8.0
* @param string $blobId The blob ID from the image
* @param int|null $size The resulting image's size. If omitted the original image size will be used. If the
* size is present it must be greater than 0
......@@ -584,6 +585,7 @@ if (QA_FINAL_EXTERNAL_USERS) {
* the user's profile, 'local-default' for an avatar fetched locally from the default avatar blob ID, and NULL
* if the avatar could not be fetched from any of these sources
*
* @since 1.8.0
* @param int $flags The user's flags
* @param string|null $email The user's email
* @param string|null $blobId The blob ID for a locally stored avatar.
......@@ -1403,6 +1405,7 @@ function qa_check_form_security_code($action, $value)
/**
* Return the URL for the Gravatar corresponding to $email, constrained to $size
*
* @since 1.8.0
* @param string $email The email of the Gravatar to return
* @param int|null $size The size of the Gravatar to return. If omitted the default size will be used
* @return string The URL to the Gravatar of the user
......
......@@ -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)
{
require_once QA_INCLUDE_DIR . 'app/posts.php';
$questionid = $question['postid'];
$userid = qa_get_logged_in_userid();
$cookieid = qa_cookie_get();
......@@ -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)
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['hidden']) {
// don't show link for hidden questions
......
......@@ -280,6 +280,7 @@ switch ($feedtype) {
require_once QA_INCLUDE_DIR . 'app/format.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';
if ($feedtype != 'search' && $feedtype != 'hot') // leave search results and hot questions sorted by relevance
......@@ -337,7 +338,7 @@ foreach ($questions as $question) {
break;
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;
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