Commit 4fb68aa6 by Scott

Coding style (misc)

parent 54ada742
......@@ -68,6 +68,7 @@ class Q2A_Util_Usage
/**
* Mark the beginning of a new stage of script execution and store usages accordingly.
* @param $stage
*/
public function mark($stage)
{
......@@ -78,6 +79,10 @@ class Q2A_Util_Usage
/**
* Logs query and updates database usage stats.
* @param $query
* @param $usedtime
* @param $gotrows
* @param $gotcolumns
*/
public function logDatabaseQuery($query, $usedtime, $gotrows, $gotcolumns)
{
......@@ -197,6 +202,9 @@ class Q2A_Util_Usage
/**
* Return the difference between two resource usage arrays, as an array.
* @param $oldusage
* @param $newusage
* @return array
*/
private function delta($oldusage, $newusage)
{
......
......@@ -29,24 +29,26 @@ if (!defined('QA_VERSION')) { // don't allow this page to be requested directly
/**
* Return true if user is logged in with admin privileges. If not, return false
* and set up $qa_content with the appropriate title and error message
* @param $qa_content
* @return bool
*/
function qa_admin_check_privileges(&$qa_content)
{
if (!qa_is_logged_in()) {
require_once QA_INCLUDE_DIR.'app/format.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
$qa_content=qa_content_prepare();
$qa_content = qa_content_prepare();
$qa_content['title']=qa_lang_html('admin/admin_title');
$qa_content['error']=qa_insert_login_links(qa_lang_html('admin/not_logged_in'), qa_request());
$qa_content['title'] = qa_lang_html('admin/admin_title');
$qa_content['error'] = qa_insert_login_links(qa_lang_html('admin/not_logged_in'), qa_request());
return false;
} elseif (qa_get_logged_in_level()<QA_USER_LEVEL_ADMIN) {
$qa_content=qa_content_prepare();
} elseif (qa_get_logged_in_level() < QA_USER_LEVEL_ADMIN) {
$qa_content = qa_content_prepare();
$qa_content['title']=qa_lang_html('admin/admin_title');
$qa_content['error']=qa_lang_html('admin/no_privileges');
$qa_content['title'] = qa_lang_html('admin/admin_title');
$qa_content['error'] = qa_lang_html('admin/no_privileges');
return false;
}
......@@ -124,11 +126,12 @@ function qa_admin_language_options()
foreach (glob(QA_LANG_DIR . '*', GLOB_ONLYDIR) as $directory) {
$code = basename($directory);
$metadata = $metadataUtil->fetchFromAddonPath($directory);
if (isset($metadata['name']))
if (isset($metadata['name'])) {
$options[$code] = $metadata['name'];
// otherwise use an entry from above
elseif (isset($codetolanguage[$code]))
} elseif (isset($codetolanguage[$code])) {
// otherwise use an entry from above
$options[$code] = $codetolanguage[$code];
}
}
asort($options, SORT_STRING);
......@@ -184,17 +187,19 @@ function qa_admin_place_options()
/**
* Return an array of page size options up to $maximum, [page size] => [page size]
* @param $maximum
* @return array
*/
function qa_admin_page_size_options($maximum)
{
$rawoptions=array(5, 10, 15, 20, 25, 30, 40, 50, 60, 80, 100, 120, 150, 200, 250, 300, 400, 500, 600, 800, 1000);
$rawoptions = array(5, 10, 15, 20, 25, 30, 40, 50, 60, 80, 100, 120, 150, 200, 250, 300, 400, 500, 600, 800, 1000);
$options=array();
$options = array();
foreach ($rawoptions as $rawoption) {
if ($rawoption>$maximum)
if ($rawoption > $maximum)
break;
$options[$rawoption]=$rawoption;
$options[$rawoption] = $rawoption;
}
return $options;
......@@ -219,12 +224,17 @@ function qa_admin_match_options()
/**
* Return an array of options representing permission restrictions, [value] => [label]
* ranging from $widest to $narrowest. Set $doconfirms to whether email confirmations are on
* @param $widest
* @param $narrowest
* @param bool $doconfirms
* @param bool $dopoints
* @return array
*/
function qa_admin_permit_options($widest, $narrowest, $doconfirms=true, $dopoints=true)
function qa_admin_permit_options($widest, $narrowest, $doconfirms = true, $dopoints = true)
{
require_once QA_INCLUDE_DIR.'app/options.php';
require_once QA_INCLUDE_DIR . 'app/options.php';
$options=array(
$options = array(
QA_PERMIT_ALL => qa_lang_html('options/permit_all'),
QA_PERMIT_USERS => qa_lang_html('options/permit_users'),
QA_PERMIT_CONFIRMED => qa_lang_html('options/permit_confirmed'),
......@@ -239,9 +249,10 @@ function qa_admin_permit_options($widest, $narrowest, $doconfirms=true, $dopoint
QA_PERMIT_SUPERS => qa_lang_html('options/permit_supers'),
);
foreach ($options as $key => $label)
if (($key<$narrowest) || ($key>$widest))
foreach ($options as $key => $label) {
if ($key < $narrowest || $key > $widest)
unset($options[$key]);
}
if (!$doconfirms) {
unset($options[QA_PERMIT_CONFIRMED]);
......@@ -270,130 +281,131 @@ function qa_admin_sub_navigation()
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
$navigation=array();
$level=qa_get_logged_in_level();
$navigation = array();
$level = qa_get_logged_in_level();
if ($level>=QA_USER_LEVEL_ADMIN) {
$navigation['admin/general']=array(
if ($level >= QA_USER_LEVEL_ADMIN) {
$navigation['admin/general'] = array(
'label' => qa_lang_html('admin/general_title'),
'url' => qa_path_html('admin/general'),
);
$navigation['admin/emails']=array(
$navigation['admin/emails'] = array(
'label' => qa_lang_html('admin/emails_title'),
'url' => qa_path_html('admin/emails'),
);
$navigation['admin/users']=array(
$navigation['admin/users'] = array(
'label' => qa_lang_html('admin/users_title'),
'url' => qa_path_html('admin/users'),
'selected_on' => array('admin/users$', 'admin/userfields$', 'admin/usertitles$'),
);
$navigation['admin/layout']=array(
$navigation['admin/layout'] = array(
'label' => qa_lang_html('admin/layout_title'),
'url' => qa_path_html('admin/layout'),
);
$navigation['admin/posting']=array(
$navigation['admin/posting'] = array(
'label' => qa_lang_html('admin/posting_title'),
'url' => qa_path_html('admin/posting'),
);
$navigation['admin/viewing']=array(
$navigation['admin/viewing'] = array(
'label' => qa_lang_html('admin/viewing_title'),
'url' => qa_path_html('admin/viewing'),
);
$navigation['admin/lists']=array(
$navigation['admin/lists'] = array(
'label' => qa_lang_html('admin/lists_title'),
'url' => qa_path_html('admin/lists'),
);
if (qa_using_categories())
$navigation['admin/categories']=array(
$navigation['admin/categories'] = array(
'label' => qa_lang_html('admin/categories_title'),
'url' => qa_path_html('admin/categories'),
);
$navigation['admin/permissions']=array(
$navigation['admin/permissions'] = array(
'label' => qa_lang_html('admin/permissions_title'),
'url' => qa_path_html('admin/permissions'),
);
$navigation['admin/pages']=array(
$navigation['admin/pages'] = array(
'label' => qa_lang_html('admin/pages_title'),
'url' => qa_path_html('admin/pages'),
);
$navigation['admin/feeds']=array(
$navigation['admin/feeds'] = array(
'label' => qa_lang_html('admin/feeds_title'),
'url' => qa_path_html('admin/feeds'),
);
$navigation['admin/points']=array(
$navigation['admin/points'] = array(
'label' => qa_lang_html('admin/points_title'),
'url' => qa_path_html('admin/points'),
);
$navigation['admin/spam']=array(
$navigation['admin/spam'] = array(
'label' => qa_lang_html('admin/spam_title'),
'url' => qa_path_html('admin/spam'),
);
if (defined('QA_CACHE_DIRECTORY')) {
$navigation['admin/caching']=array(
$navigation['admin/caching'] = array(
'label' => qa_lang_html('admin/caching_title'),
'url' => qa_path_html('admin/caching'),
);
}
$navigation['admin/stats']=array(
$navigation['admin/stats'] = array(
'label' => qa_lang_html('admin/stats_title'),
'url' => qa_path_html('admin/stats'),
);
if (!QA_FINAL_EXTERNAL_USERS)
$navigation['admin/mailing']=array(
$navigation['admin/mailing'] = array(
'label' => qa_lang_html('admin/mailing_title'),
'url' => qa_path_html('admin/mailing'),
);
$navigation['admin/plugins']=array(
$navigation['admin/plugins'] = array(
'label' => qa_lang_html('admin/plugins_title'),
'url' => qa_path_html('admin/plugins'),
);
}
if (!qa_user_maximum_permit_error('permit_moderate')) {
$count=qa_user_permit_error('permit_moderate') ? null : qa_opt('cache_queuedcount'); // if only in some categories don't show cached count
$count = qa_user_permit_error('permit_moderate') ? null : qa_opt('cache_queuedcount'); // if only in some categories don't show cached count
$navigation['admin/moderate']=array(
'label' => qa_lang_html('admin/moderate_title').($count ? (' ('.$count.')') : ''),
$navigation['admin/moderate'] = array(
'label' => qa_lang_html('admin/moderate_title') . ($count ? (' (' . $count . ')') : ''),
'url' => qa_path_html('admin/moderate'),
);
}
if (qa_opt('flagging_of_posts') && !qa_user_maximum_permit_error('permit_hide_show')) {
$count=qa_user_permit_error('permit_hide_show') ? null : qa_opt('cache_flaggedcount'); // if only in some categories don't show cached count
$count = qa_user_permit_error('permit_hide_show') ? null : qa_opt('cache_flaggedcount'); // if only in some categories don't show cached count
$navigation['admin/flagged']=array(
'label' => qa_lang_html('admin/flagged_title').($count ? (' ('.$count.')') : ''),
$navigation['admin/flagged'] = array(
'label' => qa_lang_html('admin/flagged_title') . ($count ? (' (' . $count . ')') : ''),
'url' => qa_path_html('admin/flagged'),
);
}
if ( (!qa_user_maximum_permit_error('permit_hide_show')) || (!qa_user_maximum_permit_error('permit_delete_hidden')) )
$navigation['admin/hidden']=array(
if (!qa_user_maximum_permit_error('permit_hide_show') || !qa_user_maximum_permit_error('permit_delete_hidden')) {
$navigation['admin/hidden'] = array(
'label' => qa_lang_html('admin/hidden_title'),
'url' => qa_path_html('admin/hidden'),
);
}
if ( (!QA_FINAL_EXTERNAL_USERS) && qa_opt('moderate_users') && ($level>=QA_USER_LEVEL_MODERATOR)) {
$count=qa_opt('cache_uapprovecount');
if (!QA_FINAL_EXTERNAL_USERS && qa_opt('moderate_users') && $level >= QA_USER_LEVEL_MODERATOR) {
$count = qa_opt('cache_uapprovecount');
$navigation['admin/approve']=array(
'label' => qa_lang_html('admin/approve_users_title').($count ? (' ('.$count.')') : ''),
$navigation['admin/approve'] = array(
'label' => qa_lang_html('admin/approve_users_title') . ($count ? (' (' . $count . ')') : ''),
'url' => qa_path_html('admin/approve'),
);
}
......@@ -407,24 +419,24 @@ function qa_admin_sub_navigation()
*/
function qa_admin_page_error()
{
if (file_exists(QA_INCLUDE_DIR.'db/install.php')) // file can be removed for extra security
include_once QA_INCLUDE_DIR.'db/install.php';
if (file_exists(QA_INCLUDE_DIR . 'db/install.php')) // file can be removed for extra security
include_once QA_INCLUDE_DIR . 'db/install.php';
if (defined('QA_DB_VERSION_CURRENT') && (qa_opt('db_version')<QA_DB_VERSION_CURRENT) && (qa_get_logged_in_level()>=QA_USER_LEVEL_ADMIN))
if (defined('QA_DB_VERSION_CURRENT') && qa_opt('db_version') < QA_DB_VERSION_CURRENT && qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
return strtr(
qa_lang_html('admin/upgrade_db'),
array(
'^1' => '<a href="'.qa_path_html('install').'">',
'^1' => '<a href="' . qa_path_html('install') . '">',
'^2' => '</a>',
)
);
elseif (defined('QA_BLOBS_DIRECTORY') && !is_writable(QA_BLOBS_DIRECTORY))
} elseif (defined('QA_BLOBS_DIRECTORY') && !is_writable(QA_BLOBS_DIRECTORY)) {
return qa_lang_html_sub('admin/blobs_directory_error', qa_html(QA_BLOBS_DIRECTORY));
}
else
return null;
return null;
}
......@@ -439,20 +451,23 @@ function qa_admin_url_test_html()
/**
* Returns whether a URL path beginning with $requestpart is reserved by the engine or a plugin page module
* @param $requestpart
* @return bool
*/
function qa_admin_is_slug_reserved($requestpart)
{
$requestpart=trim(strtolower($requestpart));
$routing=qa_page_routing();
$requestpart = trim(strtolower($requestpart));
$routing = qa_page_routing();
if (isset($routing[$requestpart]) || isset($routing[$requestpart.'/']) || is_numeric($requestpart))
if (isset($routing[$requestpart]) || isset($routing[$requestpart . '/']) || is_numeric($requestpart))
return true;
$pathmap=qa_get_request_map();
$pathmap = qa_get_request_map();
foreach ($pathmap as $mappedrequest)
foreach ($pathmap as $mappedrequest) {
if (trim(strtolower($mappedrequest)) == $requestpart)
return true;
}
switch ($requestpart) {
case '':
......@@ -465,10 +480,11 @@ function qa_admin_is_slug_reserved($requestpart)
return true;
}
$pagemodules=qa_load_modules_with('page', 'match_request');
foreach ($pagemodules as $pagemodule)
$pagemodules = qa_load_modules_with('page', 'match_request');
foreach ($pagemodules as $pagemodule) {
if ($pagemodule->match_request($requestpart))
return true;
}
return false;
}
......@@ -477,40 +493,44 @@ function qa_admin_is_slug_reserved($requestpart)
/**
* Returns true if admin (hidden/flagged/approve/moderate) page $action performed on $entityid is permitted by the
* logged in user and was processed successfully
* @param $entityid
* @param $action
* @return bool
*/
function qa_admin_single_click($entityid, $action)
{
$userid=qa_get_logged_in_userid();
$userid = qa_get_logged_in_userid();
if ( (!QA_FINAL_EXTERNAL_USERS) && (($action=='userapprove') || ($action=='userblock')) ) { // approve/block moderated users
require_once QA_INCLUDE_DIR.'db/selects.php';
if (!QA_FINAL_EXTERNAL_USERS && ($action == 'userapprove' || $action == 'userblock')) { // approve/block moderated users
require_once QA_INCLUDE_DIR . 'db/selects.php';
$useraccount=qa_db_select_with_pending(qa_db_user_account_selectspec($entityid, true));
$useraccount = qa_db_select_with_pending(qa_db_user_account_selectspec($entityid, true));
if ( isset($useraccount) && (qa_get_logged_in_level()>=QA_USER_LEVEL_MODERATOR) )
if (isset($useraccount) && qa_get_logged_in_level() >= QA_USER_LEVEL_MODERATOR) {
switch ($action) {
case 'userapprove':
if ($useraccount['level']<=QA_USER_LEVEL_APPROVED) { // don't demote higher level users
require_once QA_INCLUDE_DIR.'app/users-edit.php';
if ($useraccount['level'] <= QA_USER_LEVEL_APPROVED) { // don't demote higher level users
require_once QA_INCLUDE_DIR . 'app/users-edit.php';
qa_set_user_level($useraccount['userid'], $useraccount['handle'], QA_USER_LEVEL_APPROVED, $useraccount['level']);
return true;
}
break;
case 'userblock':
require_once QA_INCLUDE_DIR.'app/users-edit.php';
require_once QA_INCLUDE_DIR . 'app/users-edit.php';
qa_set_user_blocked($useraccount['userid'], $useraccount['handle'], true);
return true;
break;
}
}
} else { // something to do with a post
require_once QA_INCLUDE_DIR.'app/posts.php';
require_once QA_INCLUDE_DIR . 'app/posts.php';
$post=qa_post_get_full($entityid);
$post = qa_post_get_full($entityid);
if (isset($post)) {
$queued=(substr($post['type'], 1)=='_QUEUED');
$queued = (substr($post['type'], 1) == '_QUEUED');
switch ($action) {
case 'approve':
......@@ -528,7 +548,7 @@ function qa_admin_single_click($entityid, $action)
break;
case 'hide':
if ((!$queued) && !qa_user_post_permit_error('permit_hide_show', $post)) {
if (!$queued && !qa_user_post_permit_error('permit_hide_show', $post)) {
qa_post_set_hidden($entityid, true, $userid);
return true;
}
......@@ -549,7 +569,7 @@ function qa_admin_single_click($entityid, $action)
break;
case 'clearflags':
require_once QA_INCLUDE_DIR.'app/votes.php';
require_once QA_INCLUDE_DIR . 'app/votes.php';
if (!qa_user_post_permit_error('permit_hide_show', $post)) {
qa_flags_clear_all($post, $userid, qa_get_logged_in_handle(), null);
......@@ -569,18 +589,24 @@ function qa_admin_single_click($entityid, $action)
*/
function qa_admin_check_clicks()
{
if (qa_is_http_post())
foreach ($_POST as $field => $value)
if (strpos($field, 'admin_')===0) {
@list($dummy, $entityid, $action)=explode('_', $field);
if (strlen($entityid) && strlen($action)) {
if (!qa_check_form_security_code('admin/click', qa_post_text('code')))
return qa_lang_html('misc/form_security_again');
elseif (qa_admin_single_click($entityid, $action))
qa_redirect(qa_request());
}
}
if (!qa_is_http_post()) {
return null;
}
foreach ($_POST as $field => $value) {
if (strpos($field, 'admin_') !== 0) {
continue;
}
@list($dummy, $entityid, $action) = explode('_', $field);
if (strlen($entityid) && strlen($action)) {
if (!qa_check_form_security_code('admin/click', qa_post_text('code')))
return qa_lang_html('misc/form_security_again');
elseif (qa_admin_single_click($entityid, $action))
qa_redirect(qa_request());
}
}
return null;
}
......@@ -590,14 +616,18 @@ function qa_admin_check_clicks()
* Retrieve metadata information from the $contents of a qa-theme.php or qa-plugin.php file, mapping via $fields.
*
* @deprecated Deprecated from 1.7; use `qa_addon_metadata($contents, $type)` instead.
* @param $contents
* @param $fields
* @return array
*/
function qa_admin_addon_metadata($contents, $fields)
{
$metadata=array();
$metadata = array();
foreach ($fields as $key => $field)
if (preg_match('/'.str_replace(' ', '[ \t]*', preg_quote($field, '/')).':[ \t]*([^\n\f]*)[\n\f]/i', $contents, $matches))
$metadata[$key]=trim($matches[1]);
foreach ($fields as $key => $field) {
if (preg_match('/' . str_replace(' ', '[ \t]*', preg_quote($field, '/')) . ':[ \t]*([^\n\f]*)[\n\f]/i', $contents, $matches))
$metadata[$key] = trim($matches[1]);
}
return $metadata;
}
......@@ -605,6 +635,8 @@ function qa_admin_addon_metadata($contents, $fields)
/**
* Return the hash code for the plugin in $directory (without trailing slash), used for in-page navigation on admin/plugins page
* @param $directory
* @return mixed
*/
function qa_admin_plugin_directory_hash($directory)
{
......@@ -617,6 +649,8 @@ function qa_admin_plugin_directory_hash($directory)
/**
* Return the URL (relative to the current page) to navigate to the options panel for the plugin in $directory (without trailing slash)
* @param $directory
* @return mixed|string
*/
function qa_admin_plugin_options_path($directory)
{
......@@ -627,6 +661,9 @@ function qa_admin_plugin_options_path($directory)
/**
* Return the URL (relative to the current page) to navigate to the options panel for plugin module $name of $type
* @param $type
* @param $name
* @return mixed|string
*/
function qa_admin_module_options_path($type, $name)
{
......
......@@ -903,7 +903,7 @@ function qa_other_to_q_html_fields($question, $userid, $cookieid, $usershtml, $d
if (@$question['opersonal'])
$fields['what_your'] = true;
if (($question['obasetype'] != 'Q') || (@$question['oupdatetype'] == QA_UPDATE_FOLLOWS))
if ($question['obasetype'] != 'Q' || @$question['oupdatetype'] == QA_UPDATE_FOLLOWS)
$fields['what_url'] = qa_q_path_html($question['postid'], $question['title'], false, $question['obasetype'], $question['opostid']);
if (@$options['contentview'] && !empty($question['ocontent'])) {
......@@ -1210,7 +1210,7 @@ function qa_html_page_links($request, $start, $pagesize, $count, $prevnext, $par
$thispage = 1 + floor($start / $pagesize);
$lastpage = ceil(min($count, 1 + QA_MAX_LIMIT_START) / $pagesize);
if (($thispage > 1) || ($lastpage > $thispage)) {
if ($thispage > 1 || $lastpage > $thispage) {
$links = array('label' => qa_lang_html('main/page_label'), 'items' => array());
$keypages[1] = true;
......
......@@ -404,7 +404,7 @@ function qa_default_option($name)
case 'from_email': // heuristic to remove short prefix (e.g. www. or qa.)
$parts = explode('.', @$_SERVER['HTTP_HOST']);
if ((count($parts) > 2) && (strlen($parts[0]) < 5) && !is_numeric($parts[0]))
if (count($parts) > 2 && strlen($parts[0]) < 5 && !is_numeric($parts[0]))
unset($parts[0]);
$value = 'no-reply@' . ((count($parts) > 1) ? implode('.', $parts) : 'example.com');
......
......@@ -802,9 +802,10 @@ function qa_content_prepare($voting = false, $categoryids = null)
} else {
setcookie('qa_noticed', 1, time() + 86400 * 3650, '/', QA_COOKIE_DOMAIN, (bool)ini_get('session.cookie_secure'), true); // don't show first-time notice if a user has logged in
if (qa_opt('show_notice_welcome') && (qa_get_logged_in_flags() & QA_USER_FLAGS_WELCOME_NOTICE))
if (($requestlower != 'confirm') && ($requestlower != 'account')) // let people finish registering in peace
if (qa_opt('show_notice_welcome') && (qa_get_logged_in_flags() & QA_USER_FLAGS_WELCOME_NOTICE)) {
if ($requestlower != 'confirm' && $requestlower != 'account') // let people finish registering in peace
$qa_content['notices'][] = qa_notice_form('welcome', qa_opt('notice_welcome'));
}
}
$qa_content['script_rel'] = array('qa-content/jquery-1.11.3.min.js');
......
......@@ -298,8 +298,9 @@ function qa_comment_create($userid, $handle, $cookieid, $content, $format, $text
qa_db_queuedcount_update();
} else {
if (($question['type'] == 'Q') && (($parent['type'] == 'Q') || ($parent['type'] == 'A'))) // only index if antecedents fully visible
if ($question['type'] == 'Q' && ($parent['type'] == 'Q' || $parent['type'] == 'A')) { // only index if antecedents fully visible
qa_post_index($postid, 'C', $question['postid'], $parent['postid'], null, $content, $format, $text, null, $question['categoryid']);
}
qa_db_points_update_ifuser($userid, 'cposts');
qa_db_ccount_update();
......@@ -308,7 +309,7 @@ function qa_comment_create($userid, $handle, $cookieid, $content, $format, $text
$thread = array();
foreach ($commentsfollows as $comment) {
if (($comment['type'] == 'C') && ($comment['parentid'] == $parent['postid'])) // find just those for this parent, fully visible
if ($comment['type'] == 'C' && $comment['parentid'] == $parent['postid']) // find just those for this parent, fully visible
$thread[] = $comment;
}
......
......@@ -390,7 +390,7 @@ function qa_question_set_status($oldquestion, $status, $userid, $handle, $cookie
if ($comment['type'] == 'C') {
$answer = @$answers[$comment['parentid']];
if ((!isset($answer)) || ($answer['type'] == 'A')) { // don't index comment if it or its parent is hidden
if (!isset($answer) || $answer['type'] == 'A') { // don't index comment if it or its parent is hidden
qa_post_index($comment['postid'], $comment['type'], $oldquestion['postid'], $comment['parentid'], null,
$comment['content'], $comment['format'], qa_viewer_text($comment['content'], $comment['format']), null, $comment['categoryid']);
}
......@@ -630,7 +630,7 @@ function qa_answer_set_content($oldanswer, $content, $format, $text, $notify, $u
$commentsfollows = qa_post_get_answer_commentsfollows($oldanswer['postid']);
foreach ($commentsfollows as $comment) {
if (($comment['basetype'] == 'C') && ($comment['parentid'] == $oldanswer['postid']))
if ($comment['basetype'] == 'C' && $comment['parentid'] == $oldanswer['postid'])
qa_post_unindex($comment['postid']);
}
......@@ -642,7 +642,7 @@ function qa_answer_set_content($oldanswer, $content, $format, $text, $notify, $u
if ($oldanswer['flagcount'])
qa_db_flaggedcount_update();
} elseif (($oldanswer['type'] == 'A') && ($question['type'] == 'Q')) { // don't index if question or answer are hidden/queued
} elseif ($oldanswer['type'] == 'A' && $question['type'] == 'Q') { // don't index if question or answer are hidden/queued
qa_post_index($oldanswer['postid'], 'A', $question['postid'], $oldanswer['parentid'], null, $content, $format, $text, null, $oldanswer['categoryid']);
}
......@@ -711,7 +711,7 @@ function qa_answer_set_status($oldanswer, $status, $userid, $handle, $cookieid,
qa_post_unindex($oldanswer['postid']);
foreach ($commentsfollows as $comment) {
if (($comment['basetype'] == 'C') && ($comment['parentid'] == $oldanswer['postid']))
if ($comment['basetype'] == 'C' && $comment['parentid'] == $oldanswer['postid'])
qa_post_unindex($comment['postid']);
}
......@@ -765,12 +765,12 @@ function qa_answer_set_status($oldanswer, $status, $userid, $handle, $cookieid,
if ($oldanswer['flagcount'])
qa_db_flaggedcount_update();
if (($question['type'] == 'Q') && ($status == QA_POST_STATUS_NORMAL)) { // even if answer visible, don't index if question is hidden or queued
if ($question['type'] == 'Q' && $status == QA_POST_STATUS_NORMAL) { // even if answer visible, don't index if question is hidden or queued
qa_post_index($oldanswer['postid'], 'A', $question['postid'], $oldanswer['parentid'], null, $oldanswer['content'],
$oldanswer['format'], qa_viewer_text($oldanswer['content'], $oldanswer['format']), null, $oldanswer['categoryid']);
foreach ($commentsfollows as $comment) {
if (($comment['type'] == 'C') && ($comment['parentid'] == $oldanswer['postid'])) { // and don't index hidden/queued comments
if ($comment['type'] == 'C' && $comment['parentid'] == $oldanswer['postid']) { // and don't index hidden/queued comments
qa_post_index($comment['postid'], $comment['type'], $question['postid'], $comment['parentid'], null, $comment['content'],
$comment['format'], qa_viewer_text($comment['content'], $comment['format']), null, $comment['categoryid']);
}
......@@ -1028,7 +1028,7 @@ function qa_answer_to_comment($oldanswer, $parentid, $content, $format, $text, $
if ($oldanswer['flagcount'])
qa_db_flaggedcount_update();
} elseif (($oldanswer['type'] == 'A') && ($question['type'] == 'Q') && (($parent['type'] == 'Q') || ($parent['type'] == 'A'))) // only if all fully visible
} elseif ($oldanswer['type'] == 'A' && $question['type'] == 'Q' && ($parent['type'] == 'Q' || $parent['type'] == 'A')) // only if all fully visible
qa_post_index($oldanswer['postid'], 'C', $question['postid'], $parentid, null, $content, $format, $text, null, $oldanswer['categoryid']);
if ($question['selchildid'] == $oldanswer['postid']) { // remove selected answer
......
......@@ -455,7 +455,7 @@ function qa_post_get_question_commentsfollows($questionid)
}
foreach ($achildposts as $postid => $post) {
if (($post['basetype'] == 'Q') || ($post['basetype'] == 'C'))
if ($post['basetype'] == 'Q' || $post['basetype'] == 'C')
$commentsfollows[$postid] = $post;
}
......@@ -486,7 +486,7 @@ function qa_post_get_answer_commentsfollows($answerid)
$childposts = qa_db_single_select(qa_db_full_child_posts_selectspec(null, $answerid));
foreach ($childposts as $postid => $post) {
if (($post['basetype'] == 'Q') || ($post['basetype'] == 'C'))
if ($post['basetype'] == 'Q' || $post['basetype'] == 'C')
$commentsfollows[$postid] = $post;
}
......
......@@ -303,9 +303,9 @@ function qa_recalc_perform_step(&$state)
if ($followonq)
$updatetype = QA_UPDATE_FOLLOWS;
elseif (($post['basetype'] == 'C') && (@$posts[$post['parentid']]['basetype'] == 'Q'))
elseif ($post['basetype'] == 'C' && @$posts[$post['parentid']]['basetype'] == 'Q')
$updatetype = QA_UPDATE_C_FOR_Q;
elseif (($post['basetype'] == 'C') && (@$posts[$post['parentid']]['basetype'] == 'A'))
elseif ($post['basetype'] == 'C' && @$posts[$post['parentid']]['basetype'] == 'A')
$updatetype = QA_UPDATE_C_FOR_A;
else
$updatetype = null;
......@@ -337,9 +337,11 @@ function qa_recalc_perform_step(&$state)
qa_sort_by($comments, 'created');
foreach ($comments as $comment) {
foreach ($keyuserids as $keyuserid => $dummy)
if (($keyuserid != $comment['userid']) && ($keyuserid != @$posts[$parentid]['userid']))
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;
......
......@@ -97,7 +97,7 @@ function qa_upload_file($localfilename, $sourcefilename, $maxfilesize = null, $o
else
$maxfilesize = qa_get_max_upload_size();
if (($filesize <= 0) || ($filesize > $maxfilesize)) { // if file was too big for PHP, $filesize will be zero
if ($filesize <= 0 || $filesize > $maxfilesize) { // if file was too big for PHP, $filesize will be zero
$result['error'] = qa_lang_sub('main/max_upload_size_x', qa_format_number($maxfilesize / 1048576, 1) . 'MB');
return $result;
}
......@@ -134,7 +134,7 @@ function qa_upload_file($localfilename, $sourcefilename, $maxfilesize = null, $o
$result['format'] = $format;
if ($onlyimage) {
if ((!$isimage) || !is_array($imagesize)) {
if (!$isimage || !is_array($imagesize)) {
$result['error'] = qa_lang_sub('main/image_not_read', 'GIF, JPG, PNG');
return $result;
}
......
......@@ -405,7 +405,7 @@ if (QA_FINAL_EXTERNAL_USERS) {
$sessioncode = trim($sessioncode); // trim to prevent passing in blank values to match uninitiated DB rows
// Try to recover session from the database if PHP session has timed out
if ((!isset($_SESSION['qa_session_userid_' . $suffix])) && (!empty($handle)) && (!empty($sessioncode))) {
if (!isset($_SESSION['qa_session_userid_' . $suffix]) && !empty($handle) && !empty($sessioncode)) {
require_once QA_INCLUDE_DIR . 'db/selects.php';
$userinfo = qa_db_single_select(qa_db_user_account_selectspec($handle, false)); // don't get any pending
......@@ -1282,7 +1282,7 @@ function qa_set_form_security_key()
global $qa_form_key_cookie_set;
if ((!qa_is_logged_in()) && !@$qa_form_key_cookie_set) {
if (!qa_is_logged_in() && !@$qa_form_key_cookie_set) {
$qa_form_key_cookie_set = true;
if (strlen(@$_COOKIE['qa_key']) != QA_FORM_KEY_LENGTH) {
......
......@@ -20,460 +20,501 @@
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
header('Location: ../');
exit;
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../');
exit;
}
require_once QA_INCLUDE_DIR . 'app/post-create.php';
require_once QA_INCLUDE_DIR . 'app/post-update.php';
/**
* Checks for a POSTed click on $question by the current user and returns true if it was permitted and processed. Pass
* in the question's $answers, all $commentsfollows from it or its answers, and its closing $closepost (or null if
* none). If there is an error to display, it will be passed out in $error.
* @param $question
* @param $answers
* @param $commentsfollows
* @param $closepost
* @param $error
* @return bool
*/
function qa_page_q_single_click_q($question, $answers, $commentsfollows, $closepost, &$error)
{
require_once QA_INCLUDE_DIR . 'app/post-update.php';
require_once QA_INCLUDE_DIR . 'app/limits.php';
$userid = qa_get_logged_in_userid();
$handle = qa_get_logged_in_handle();
$cookieid = qa_cookie_get();
if (qa_clicked('q_doreopen') && $question['reopenable'] && qa_page_q_click_check_form_code($question, $error)) {
qa_question_close_clear($question, $closepost, $userid, $handle, $cookieid);
return true;
}
require_once QA_INCLUDE_DIR.'app/post-create.php';
require_once QA_INCLUDE_DIR.'app/post-update.php';
function qa_page_q_single_click_q($question, $answers, $commentsfollows, $closepost, &$error)
/*
Checks for a POSTed click on $question by the current user and returns true if it was permitted and processed. Pass
in the question's $answers, all $commentsfollows from it or its answers, and its closing $closepost (or null if
none). If there is an error to display, it will be passed out in $error.
*/
{
require_once QA_INCLUDE_DIR.'app/post-update.php';
require_once QA_INCLUDE_DIR.'app/limits.php';
$userid=qa_get_logged_in_userid();
$handle=qa_get_logged_in_handle();
$cookieid=qa_cookie_get();
if (qa_clicked('q_doreopen') && $question['reopenable'] && qa_page_q_click_check_form_code($question, $error) ) {
qa_question_close_clear($question, $closepost, $userid, $handle, $cookieid);
if ((qa_clicked('q_dohide') && $question['hideable']) || (qa_clicked('q_doreject') && $question['moderatable'])) {
if (qa_page_q_click_check_form_code($question, $error)) {
qa_question_set_hidden($question, true, $userid, $handle, $cookieid, $answers, $commentsfollows, $closepost);
return true;
}
}
if ( (qa_clicked('q_dohide') && $question['hideable']) || (qa_clicked('q_doreject') && $question['moderatable']) )
if (qa_page_q_click_check_form_code($question, $error)) {
qa_question_set_hidden($question, true, $userid, $handle, $cookieid, $answers, $commentsfollows, $closepost);
return true;
}
if ( (qa_clicked('q_doreshow') && $question['reshowable']) || (qa_clicked('q_doapprove') && $question['moderatable']) )
if (qa_page_q_click_check_form_code($question, $error)) {
if ($question['moderatable'] || $question['reshowimmed']) {
$status=QA_POST_STATUS_NORMAL;
if ((qa_clicked('q_doreshow') && $question['reshowable']) || (qa_clicked('q_doapprove') && $question['moderatable'])) {
if (qa_page_q_click_check_form_code($question, $error)) {
if ($question['moderatable'] || $question['reshowimmed']) {
$status = QA_POST_STATUS_NORMAL;
} else {
$in=qa_page_q_prepare_post_for_filters($question);
$filtermodules=qa_load_modules_with('filter', 'filter_question'); // run through filters but only for queued status
} else {
$in = qa_page_q_prepare_post_for_filters($question);
$filtermodules = qa_load_modules_with('filter', 'filter_question'); // run through filters but only for queued status
foreach ($filtermodules as $filtermodule) {
$tempin=$in; // always pass original question in because we aren't modifying anything else
$filtermodule->filter_question($tempin, $temperrors, $question);
$in['queued']=$tempin['queued']; // only preserve queued status in loop
}
$status=$in['queued'] ? QA_POST_STATUS_QUEUED : QA_POST_STATUS_NORMAL;
foreach ($filtermodules as $filtermodule) {
$tempin = $in; // always pass original question in because we aren't modifying anything else
$filtermodule->filter_question($tempin, $temperrors, $question);
$in['queued'] = $tempin['queued']; // only preserve queued status in loop
}
qa_question_set_status($question, $status, $userid, $handle, $cookieid, $answers, $commentsfollows, $closepost);
return true;
$status = $in['queued'] ? QA_POST_STATUS_QUEUED : QA_POST_STATUS_NORMAL;
}
if (qa_clicked('q_doclaim') && $question['claimable'] && qa_page_q_click_check_form_code($question, $error) ) {
if (qa_user_limits_remaining(QA_LIMIT_QUESTIONS)) { // already checked 'permit_post_q'
qa_question_set_userid($question, $userid, $handle, $cookieid);
return true;
} else
$error=qa_lang_html('question/ask_limit');
qa_question_set_status($question, $status, $userid, $handle, $cookieid, $answers, $commentsfollows, $closepost);
return true;
}
}
if (qa_clicked('q_doflag') && $question['flagbutton'] && qa_page_q_click_check_form_code($question, $error)) {
require_once QA_INCLUDE_DIR.'app/votes.php';
if (qa_clicked('q_doclaim') && $question['claimable'] && qa_page_q_click_check_form_code($question, $error)) {
if (qa_user_limits_remaining(QA_LIMIT_QUESTIONS)) { // already checked 'permit_post_q'
qa_question_set_userid($question, $userid, $handle, $cookieid);
return true;
$error=qa_flag_error_html($question, $userid, qa_request());
if (!$error) {
if (qa_flag_set_tohide($question, $userid, $handle, $cookieid, $question))
qa_question_set_hidden($question, true, null, null, null, $answers, $commentsfollows, $closepost); // hiding not really by this user so pass nulls
return true;
}
}
} else
$error = qa_lang_html('question/ask_limit');
}
if (qa_clicked('q_dounflag') && $question['unflaggable'] && qa_page_q_click_check_form_code($question, $error)) {
require_once QA_INCLUDE_DIR.'app/votes.php';
if (qa_clicked('q_doflag') && $question['flagbutton'] && qa_page_q_click_check_form_code($question, $error)) {
require_once QA_INCLUDE_DIR . 'app/votes.php';
qa_flag_clear($question, $userid, $handle, $cookieid);
$error = qa_flag_error_html($question, $userid, qa_request());
if (!$error) {
if (qa_flag_set_tohide($question, $userid, $handle, $cookieid, $question))
qa_question_set_hidden($question, true, null, null, null, $answers, $commentsfollows, $closepost); // hiding not really by this user so pass nulls
return true;
}
}
if (qa_clicked('q_doclearflags') && $question['clearflaggable'] && qa_page_q_click_check_form_code($question, $error)) {
require_once QA_INCLUDE_DIR.'app/votes.php';
qa_flags_clear_all($question, $userid, $handle, $cookieid);
return true;
}
if (qa_clicked('q_dounflag') && $question['unflaggable'] && qa_page_q_click_check_form_code($question, $error)) {
require_once QA_INCLUDE_DIR . 'app/votes.php';
return false;
qa_flag_clear($question, $userid, $handle, $cookieid);
return true;
}
if (qa_clicked('q_doclearflags') && $question['clearflaggable'] && qa_page_q_click_check_form_code($question, $error)) {
require_once QA_INCLUDE_DIR . 'app/votes.php';
function qa_page_q_single_click_a($answer, $question, $answers, $commentsfollows, $allowselectmove, &$error)
/*
Checks for a POSTed click on $answer by the current user and returns true if it was permitted and processed. Pass in
the $question, all of its $answers, and all $commentsfollows from it or its answers. Set $allowselectmove to whether
it is legitimate to change the selected answer for the question from one to another (this can't be done via Ajax).
If there is an error to display, it will be passed out in $error.
*/
{
$userid=qa_get_logged_in_userid();
$handle=qa_get_logged_in_handle();
$cookieid=qa_cookie_get();
qa_flags_clear_all($question, $userid, $handle, $cookieid);
return true;
}
$prefix='a'.$answer['postid'].'_';
return false;
}
/**
* Checks for a POSTed click on $answer by the current user and returns true if it was permitted and processed. Pass in
* the $question, all of its $answers, and all $commentsfollows from it or its answers. Set $allowselectmove to whether
* it is legitimate to change the selected answer for the question from one to another (this can't be done via Ajax).
* If there is an error to display, it will be passed out in $error.
* @param $answer
* @param $question
* @param $answers
* @param $commentsfollows
* @param $allowselectmove
* @param $error
* @return bool
*/
function qa_page_q_single_click_a($answer, $question, $answers, $commentsfollows, $allowselectmove, &$error)
{
$userid = qa_get_logged_in_userid();
$handle = qa_get_logged_in_handle();
$cookieid = qa_cookie_get();
$prefix = 'a' . $answer['postid'] . '_';
if (qa_clicked($prefix . 'doselect') && $question['aselectable'] && ($allowselectmove || ((!isset($question['selchildid'])) && !qa_opt('do_close_on_select'))) && qa_page_q_click_check_form_code($answer, $error)) {
qa_question_set_selchildid($userid, $handle, $cookieid, $question, $answer['postid'], $answers);
return true;
}
if (qa_clicked($prefix.'doselect') && $question['aselectable'] && ($allowselectmove || ( (!isset($question['selchildid'])) && !qa_opt('do_close_on_select'))) && qa_page_q_click_check_form_code($answer, $error) ) {
qa_question_set_selchildid($userid, $handle, $cookieid, $question, $answer['postid'], $answers);
return true;
}
if (qa_clicked($prefix . 'dounselect') && $question['aselectable'] && ($question['selchildid'] == $answer['postid']) && ($allowselectmove || !qa_opt('do_close_on_select')) && qa_page_q_click_check_form_code($answer, $error)) {
qa_question_set_selchildid($userid, $handle, $cookieid, $question, null, $answers);
return true;
}
if (qa_clicked($prefix.'dounselect') && $question['aselectable'] && ($question['selchildid']==$answer['postid']) && ($allowselectmove || !qa_opt('do_close_on_select')) && qa_page_q_click_check_form_code($answer, $error)) {
qa_question_set_selchildid($userid, $handle, $cookieid, $question, null, $answers);
if ((qa_clicked($prefix . 'dohide') && $answer['hideable']) || (qa_clicked($prefix . 'doreject') && $answer['moderatable'])) {
if (qa_page_q_click_check_form_code($answer, $error)) {
qa_answer_set_hidden($answer, true, $userid, $handle, $cookieid, $question, $commentsfollows);
return true;
}
}
if ( (qa_clicked($prefix.'dohide') && $answer['hideable']) || (qa_clicked($prefix.'doreject') && $answer['moderatable']) )
if (qa_page_q_click_check_form_code($answer, $error)) {
qa_answer_set_hidden($answer, true, $userid, $handle, $cookieid, $question, $commentsfollows);
return true;
}
if ( (qa_clicked($prefix.'doreshow') && $answer['reshowable']) || (qa_clicked($prefix.'doapprove') && $answer['moderatable']) )
if (qa_page_q_click_check_form_code($answer, $error)) {
if ($answer['moderatable'] || $answer['reshowimmed']) {
$status=QA_POST_STATUS_NORMAL;
} else {
$in=qa_page_q_prepare_post_for_filters($answer);
$filtermodules=qa_load_modules_with('filter', 'filter_answer'); // run through filters but only for queued status
if ((qa_clicked($prefix . 'doreshow') && $answer['reshowable']) || (qa_clicked($prefix . 'doapprove') && $answer['moderatable'])) {
if (qa_page_q_click_check_form_code($answer, $error)) {
if ($answer['moderatable'] || $answer['reshowimmed']) {
$status = QA_POST_STATUS_NORMAL;
foreach ($filtermodules as $filtermodule) {
$tempin=$in; // always pass original answer in because we aren't modifying anything else
$filtermodule->filter_answer($tempin, $temperrors, $question, $answer);
$in['queued']=$tempin['queued']; // only preserve queued status in loop
}
} else {
$in = qa_page_q_prepare_post_for_filters($answer);
$filtermodules = qa_load_modules_with('filter', 'filter_answer'); // run through filters but only for queued status
$status=$in['queued'] ? QA_POST_STATUS_QUEUED : QA_POST_STATUS_NORMAL;
foreach ($filtermodules as $filtermodule) {
$tempin = $in; // always pass original answer in because we aren't modifying anything else
$filtermodule->filter_answer($tempin, $temperrors, $question, $answer);
$in['queued'] = $tempin['queued']; // only preserve queued status in loop
}
qa_answer_set_status($answer, $status, $userid, $handle, $cookieid, $question, $commentsfollows);
return true;
$status = $in['queued'] ? QA_POST_STATUS_QUEUED : QA_POST_STATUS_NORMAL;
}
if (qa_clicked($prefix.'dodelete') && $answer['deleteable'] && qa_page_q_click_check_form_code($answer, $error)) {
qa_answer_delete($answer, $question, $userid, $handle, $cookieid);
qa_answer_set_status($answer, $status, $userid, $handle, $cookieid, $question, $commentsfollows);
return true;
}
}
if (qa_clicked($prefix.'doclaim') && $answer['claimable'] && qa_page_q_click_check_form_code($answer, $error)) {
if (qa_user_limits_remaining(QA_LIMIT_ANSWERS)) { // already checked 'permit_post_a'
qa_answer_set_userid($answer, $userid, $handle, $cookieid);
return true;
} else
$error=qa_lang_html('question/answer_limit');
}
if (qa_clicked($prefix . 'dodelete') && $answer['deleteable'] && qa_page_q_click_check_form_code($answer, $error)) {
qa_answer_delete($answer, $question, $userid, $handle, $cookieid);
return true;
}
if (qa_clicked($prefix.'doflag') && $answer['flagbutton'] && qa_page_q_click_check_form_code($answer, $error)) {
require_once QA_INCLUDE_DIR.'app/votes.php';
if (qa_clicked($prefix . 'doclaim') && $answer['claimable'] && qa_page_q_click_check_form_code($answer, $error)) {
if (qa_user_limits_remaining(QA_LIMIT_ANSWERS)) { // already checked 'permit_post_a'
qa_answer_set_userid($answer, $userid, $handle, $cookieid);
return true;
$error=qa_flag_error_html($answer, $userid, qa_request());
if (!$error) {
if (qa_flag_set_tohide($answer, $userid, $handle, $cookieid, $question))
qa_answer_set_hidden($answer, true, null, null, null, $question, $commentsfollows); // hiding not really by this user so pass nulls
} else
$error = qa_lang_html('question/answer_limit');
}
return true;
}
}
if (qa_clicked($prefix . 'doflag') && $answer['flagbutton'] && qa_page_q_click_check_form_code($answer, $error)) {
require_once QA_INCLUDE_DIR . 'app/votes.php';
if (qa_clicked($prefix.'dounflag') && $answer['unflaggable'] && qa_page_q_click_check_form_code($answer, $error)) {
require_once QA_INCLUDE_DIR.'app/votes.php';
$error = qa_flag_error_html($answer, $userid, qa_request());
if (!$error) {
if (qa_flag_set_tohide($answer, $userid, $handle, $cookieid, $question))
qa_answer_set_hidden($answer, true, null, null, null, $question, $commentsfollows); // hiding not really by this user so pass nulls
qa_flag_clear($answer, $userid, $handle, $cookieid);
return true;
}
}
if (qa_clicked($prefix.'doclearflags') && $answer['clearflaggable'] && qa_page_q_click_check_form_code($answer, $error)) {
require_once QA_INCLUDE_DIR.'app/votes.php';
if (qa_clicked($prefix . 'dounflag') && $answer['unflaggable'] && qa_page_q_click_check_form_code($answer, $error)) {
require_once QA_INCLUDE_DIR . 'app/votes.php';
qa_flags_clear_all($answer, $userid, $handle, $cookieid);
return true;
}
return false;
qa_flag_clear($answer, $userid, $handle, $cookieid);
return true;
}
if (qa_clicked($prefix . 'doclearflags') && $answer['clearflaggable'] && qa_page_q_click_check_form_code($answer, $error)) {
require_once QA_INCLUDE_DIR . 'app/votes.php';
function qa_page_q_single_click_c($comment, $question, $parent, &$error)
/*
Checks for a POSTed click on $comment by the current user and returns true if it was permitted and processed. Pass
in the antecedent $question and the comment's $parent post. If there is an error to display, it will be passed out
in $error.
*/
{
$userid=qa_get_logged_in_userid();
$handle=qa_get_logged_in_handle();
$cookieid=qa_cookie_get();
$prefix='c'.$comment['postid'].'_';
qa_flags_clear_all($answer, $userid, $handle, $cookieid);
return true;
}
if ( (qa_clicked($prefix.'dohide') && $comment['hideable']) || (qa_clicked($prefix.'doreject') && $comment['moderatable']) )
if (qa_page_q_click_check_form_code($parent, $error)) {
qa_comment_set_hidden($comment, true, $userid, $handle, $cookieid, $question, $parent);
return true;
}
return false;
}
/**
* Checks for a POSTed click on $comment by the current user and returns true if it was permitted and processed. Pass
* in the antecedent $question and the comment's $parent post. If there is an error to display, it will be passed out
* in $error.
* @param $comment
* @param $question
* @param $parent
* @param $error
* @return bool
*/
function qa_page_q_single_click_c($comment, $question, $parent, &$error)
{
$userid = qa_get_logged_in_userid();
$handle = qa_get_logged_in_handle();
$cookieid = qa_cookie_get();
$prefix = 'c' . $comment['postid'] . '_';
if ((qa_clicked($prefix . 'dohide') && $comment['hideable']) || (qa_clicked($prefix . 'doreject') && $comment['moderatable'])) {
if (qa_page_q_click_check_form_code($parent, $error)) {
qa_comment_set_hidden($comment, true, $userid, $handle, $cookieid, $question, $parent);
return true;
}
}
if ( (qa_clicked($prefix.'doreshow') && $comment['reshowable']) || (qa_clicked($prefix.'doapprove') && $comment['moderatable']) )
if (qa_page_q_click_check_form_code($parent, $error)) {
if ($comment['moderatable'] || $comment['reshowimmed']) {
$status=QA_POST_STATUS_NORMAL;
if ((qa_clicked($prefix . 'doreshow') && $comment['reshowable']) || (qa_clicked($prefix . 'doapprove') && $comment['moderatable'])) {
if (qa_page_q_click_check_form_code($parent, $error)) {
if ($comment['moderatable'] || $comment['reshowimmed']) {
$status = QA_POST_STATUS_NORMAL;
} else {
$in=qa_page_q_prepare_post_for_filters($comment);
$filtermodules=qa_load_modules_with('filter', 'filter_comment'); // run through filters but only for queued status
} else {
$in = qa_page_q_prepare_post_for_filters($comment);
$filtermodules = qa_load_modules_with('filter', 'filter_comment'); // run through filters but only for queued status
foreach ($filtermodules as $filtermodule) {
$tempin=$in; // always pass original comment in because we aren't modifying anything else
$filtermodule->filter_comment($tempin, $temperrors, $question, $parent, $comment);
$in['queued']=$tempin['queued']; // only preserve queued status in loop
}
$status=$in['queued'] ? QA_POST_STATUS_QUEUED : QA_POST_STATUS_NORMAL;
foreach ($filtermodules as $filtermodule) {
$tempin = $in; // always pass original comment in because we aren't modifying anything else
$filtermodule->filter_comment($tempin, $temperrors, $question, $parent, $comment);
$in['queued'] = $tempin['queued']; // only preserve queued status in loop
}
qa_comment_set_status($comment, $status, $userid, $handle, $cookieid, $question, $parent);
return true;
$status = $in['queued'] ? QA_POST_STATUS_QUEUED : QA_POST_STATUS_NORMAL;
}
if (qa_clicked($prefix.'dodelete') && $comment['deleteable'] && qa_page_q_click_check_form_code($parent, $error)) {
qa_comment_delete($comment, $question, $parent, $userid, $handle, $cookieid);
qa_comment_set_status($comment, $status, $userid, $handle, $cookieid, $question, $parent);
return true;
}
}
if (qa_clicked($prefix.'doclaim') && $comment['claimable'] && qa_page_q_click_check_form_code($parent, $error)) {
if (qa_user_limits_remaining(QA_LIMIT_COMMENTS)) {
qa_comment_set_userid($comment, $userid, $handle, $cookieid);
return true;
} else
$error=qa_lang_html('question/comment_limit');
}
if (qa_clicked($prefix.'doflag') && $comment['flagbutton'] && qa_page_q_click_check_form_code($parent, $error)) {
require_once QA_INCLUDE_DIR.'app/votes.php';
$error=qa_flag_error_html($comment, $userid, qa_request());
if (!$error) {
if (qa_flag_set_tohide($comment, $userid, $handle, $cookieid, $question))
qa_comment_set_hidden($comment, true, null, null, null, $question, $parent); // hiding not really by this user so pass nulls
if (qa_clicked($prefix . 'dodelete') && $comment['deleteable'] && qa_page_q_click_check_form_code($parent, $error)) {
qa_comment_delete($comment, $question, $parent, $userid, $handle, $cookieid);
return true;
}
return true;
}
}
if (qa_clicked($prefix . 'doclaim') && $comment['claimable'] && qa_page_q_click_check_form_code($parent, $error)) {
if (qa_user_limits_remaining(QA_LIMIT_COMMENTS)) {
qa_comment_set_userid($comment, $userid, $handle, $cookieid);
return true;
if (qa_clicked($prefix.'dounflag') && $comment['unflaggable'] && qa_page_q_click_check_form_code($parent, $error)) {
require_once QA_INCLUDE_DIR.'app/votes.php';
} else
$error = qa_lang_html('question/comment_limit');
}
qa_flag_clear($comment, $userid, $handle, $cookieid);
return true;
}
if (qa_clicked($prefix . 'doflag') && $comment['flagbutton'] && qa_page_q_click_check_form_code($parent, $error)) {
require_once QA_INCLUDE_DIR . 'app/votes.php';
if (qa_clicked($prefix.'doclearflags') && $comment['clearflaggable'] && qa_page_q_click_check_form_code($parent, $error)) {
require_once QA_INCLUDE_DIR.'app/votes.php';
$error = qa_flag_error_html($comment, $userid, qa_request());
if (!$error) {
if (qa_flag_set_tohide($comment, $userid, $handle, $cookieid, $question))
qa_comment_set_hidden($comment, true, null, null, null, $question, $parent); // hiding not really by this user so pass nulls
qa_flags_clear_all($comment, $userid, $handle, $cookieid);
return true;
}
return false;
}
if (qa_clicked($prefix . 'dounflag') && $comment['unflaggable'] && qa_page_q_click_check_form_code($parent, $error)) {
require_once QA_INCLUDE_DIR . 'app/votes.php';
function qa_page_q_click_check_form_code($post, &$error)
/*
Check the form security (anti-CSRF protection) for one of the buttons shown for post $post. Return true if the
security passed, otherwise return false and set an error message in $error
*/
{
$result=qa_check_form_security_code('buttons-'.$post['postid'], qa_post_text('code'));
if (!$result)
$error=qa_lang_html('misc/form_security_again');
return $result;
qa_flag_clear($comment, $userid, $handle, $cookieid);
return true;
}
if (qa_clicked($prefix . 'doclearflags') && $comment['clearflaggable'] && qa_page_q_click_check_form_code($parent, $error)) {
require_once QA_INCLUDE_DIR . 'app/votes.php';
function qa_page_q_add_a_submit($question, $answers, $usecaptcha, &$in, &$errors)
/*
Processes a POSTed form to add an answer to $question, returning the postid if successful, otherwise null. Pass in
other $answers to the question and whether a $usecaptcha is required. The form fields submitted will be passed out
as an array in $in, as well as any $errors on those fields.
*/
{
$in=array(
'name' => qa_post_text('a_name'),
'notify' => qa_post_text('a_notify') !== null,
'email' => qa_post_text('a_email'),
'queued' => qa_user_moderation_reason(qa_user_level_for_post($question)) !== false,
);
qa_get_post_content('a_editor', 'a_content', $in['editor'], $in['content'], $in['format'], $in['text']);
$errors=array();
if (!qa_check_form_security_code('answer-'.$question['postid'], qa_post_text('code')))
$errors['content']=qa_lang_html('misc/form_security_again');
else {
// call any filter plugins
$filtermodules=qa_load_modules_with('filter', 'filter_answer');
foreach ($filtermodules as $filtermodule) {
$oldin=$in;
$filtermodule->filter_answer($in, $errors, $question, null);
qa_update_post_text($in, $oldin);
}
// check CAPTCHA
if ($usecaptcha)
qa_captcha_validate_post($errors);
qa_flags_clear_all($comment, $userid, $handle, $cookieid);
return true;
}
// check for duplicate posts
if (empty($errors)) {
$testwords=implode(' ', qa_string_to_words($in['content']));
return false;
}
/**
* Check the form security (anti-CSRF protection) for one of the buttons shown for post $post. Return true if the
* security passed, otherwise return false and set an error message in $error
* @param $post
* @param $error
* @return bool
*/
function qa_page_q_click_check_form_code($post, &$error)
{
$result = qa_check_form_security_code('buttons-' . $post['postid'], qa_post_text('code'));
if (!$result)
$error = qa_lang_html('misc/form_security_again');
return $result;
}
/**
* Processes a POSTed form to add an answer to $question, returning the postid if successful, otherwise null. Pass in
* other $answers to the question and whether a $usecaptcha is required. The form fields submitted will be passed out
* as an array in $in, as well as any $errors on those fields.
* @param $question
* @param $answers
* @param $usecaptcha
* @param $in
* @param $errors
* @return mixed|null
*/
function qa_page_q_add_a_submit($question, $answers, $usecaptcha, &$in, &$errors)
{
$in = array(
'name' => qa_post_text('a_name'),
'notify' => qa_post_text('a_notify') !== null,
'email' => qa_post_text('a_email'),
'queued' => qa_user_moderation_reason(qa_user_level_for_post($question)) !== false,
);
qa_get_post_content('a_editor', 'a_content', $in['editor'], $in['content'], $in['format'], $in['text']);
$errors = array();
if (!qa_check_form_security_code('answer-' . $question['postid'], qa_post_text('code')))
$errors['content'] = qa_lang_html('misc/form_security_again');
else {
// call any filter plugins
$filtermodules = qa_load_modules_with('filter', 'filter_answer');
foreach ($filtermodules as $filtermodule) {
$oldin = $in;
$filtermodule->filter_answer($in, $errors, $question, null);
qa_update_post_text($in, $oldin);
}
foreach ($answers as $answer)
if (!$answer['hidden'])
if (implode(' ', qa_string_to_words($answer['content'])) == $testwords) {
$errors['content']=qa_lang_html('question/duplicate_content');
break;
}
}
// check CAPTCHA
if ($usecaptcha)
qa_captcha_validate_post($errors);
$userid = qa_get_logged_in_userid();
// check for duplicate posts
if (empty($errors)) {
$testwords = implode(' ', qa_string_to_words($in['content']));
// if this is an additional answer, check we can add it
if (empty($errors) && !qa_opt('allow_multi_answers')) {
foreach ($answers as $answer) {
if (qa_post_is_by_user($answer, $userid, qa_cookie_get())) {
$errors[] = '';
foreach ($answers as $answer) {
if (!$answer['hidden']) {
if (implode(' ', qa_string_to_words($answer['content'])) == $testwords) {
$errors['content'] = qa_lang_html('question/duplicate_content');
break;
}
}
}
}
// create the answer
if (empty($errors)) {
$handle = qa_get_logged_in_handle();
$cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create(); // create a new cookie if necessary
$answerid = qa_answer_create($userid, $handle, $cookieid, $in['content'], $in['format'], $in['text'], $in['notify'], $in['email'],
$question, $in['queued'], $in['name']);
$userid = qa_get_logged_in_userid();
return $answerid;
// if this is an additional answer, check we can add it
if (empty($errors) && !qa_opt('allow_multi_answers')) {
foreach ($answers as $answer) {
if (qa_post_is_by_user($answer, $userid, qa_cookie_get())) {
$errors[] = '';
break;
}
}
}
return null;
}
function qa_page_q_add_c_submit($question, $parent, $commentsfollows, $usecaptcha, &$in, &$errors)
/*
Processes a POSTed form to add a comment, returning the postid if successful, otherwise null. Pass in the antecedent
$question and the comment's $parent post. Set $usecaptcha to whether a captcha is required. Pass an array which
includes the other comments with the same parent in $commentsfollows (it can contain other posts which are ignored).
The form fields submitted will be passed out as an array in $in, as well as any $errors on those fields.
*/
{
$parentid=$parent['postid'];
$prefix='c'.$parentid.'_';
// create the answer
if (empty($errors)) {
$handle = qa_get_logged_in_handle();
$cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create(); // create a new cookie if necessary
$in=array(
'name' => qa_post_text($prefix.'name'),
'notify' => qa_post_text($prefix.'notify') !== null,
'email' => qa_post_text($prefix.'email'),
'queued' => qa_user_moderation_reason(qa_user_level_for_post($parent)) !== false,
);
$answerid = qa_answer_create($userid, $handle, $cookieid, $in['content'], $in['format'], $in['text'], $in['notify'], $in['email'],
$question, $in['queued'], $in['name']);
qa_get_post_content($prefix.'editor', $prefix.'content', $in['editor'], $in['content'], $in['format'], $in['text']);
$errors=array();
if (!qa_check_form_security_code('comment-'.$parent['postid'], qa_post_text($prefix.'code')))
$errors['content']=qa_lang_html('misc/form_security_again');
else {
$filtermodules=qa_load_modules_with('filter', 'filter_comment');
foreach ($filtermodules as $filtermodule) {
$oldin=$in;
$filtermodule->filter_comment($in, $errors, $question, $parent, null);
qa_update_post_text($in, $oldin);
}
if ($usecaptcha)
qa_captcha_validate_post($errors);
if (empty($errors)) {
$testwords=implode(' ', qa_string_to_words($in['content']));
return $answerid;
}
}
foreach ($commentsfollows as $comment)
if (($comment['basetype']=='C') && ($comment['parentid']==$parentid) && !$comment['hidden'])
if (implode(' ', qa_string_to_words($comment['content'])) == $testwords) {
$errors['content']=qa_lang_html('question/duplicate_content');
break;
}
}
return null;
}
/**
* Processes a POSTed form to add a comment, returning the postid if successful, otherwise null. Pass in the antecedent
* $question and the comment's $parent post. Set $usecaptcha to whether a captcha is required. Pass an array which
* includes the other comments with the same parent in $commentsfollows (it can contain other posts which are ignored).
* The form fields submitted will be passed out as an array in $in, as well as any $errors on those fields.
* @param $question
* @param $parent
* @param $commentsfollows
* @param $usecaptcha
* @param $in
* @param $errors
* @return mixed|null
*/
function qa_page_q_add_c_submit($question, $parent, $commentsfollows, $usecaptcha, &$in, &$errors)
{
$parentid = $parent['postid'];
$prefix = 'c' . $parentid . '_';
$in = array(
'name' => qa_post_text($prefix . 'name'),
'notify' => qa_post_text($prefix . 'notify') !== null,
'email' => qa_post_text($prefix . 'email'),
'queued' => qa_user_moderation_reason(qa_user_level_for_post($parent)) !== false,
);
qa_get_post_content($prefix . 'editor', $prefix . 'content', $in['editor'], $in['content'], $in['format'], $in['text']);
$errors = array();
if (!qa_check_form_security_code('comment-' . $parent['postid'], qa_post_text($prefix . 'code')))
$errors['content'] = qa_lang_html('misc/form_security_again');
else {
$filtermodules = qa_load_modules_with('filter', 'filter_comment');
foreach ($filtermodules as $filtermodule) {
$oldin = $in;
$filtermodule->filter_comment($in, $errors, $question, $parent, null);
qa_update_post_text($in, $oldin);
}
if (empty($errors)) {
$userid=qa_get_logged_in_userid();
$handle=qa_get_logged_in_handle();
$cookieid=isset($userid) ? qa_cookie_get() : qa_cookie_get_create(); // create a new cookie if necessary
if ($usecaptcha)
qa_captcha_validate_post($errors);
$commentid=qa_comment_create($userid, $handle, $cookieid, $in['content'], $in['format'], $in['text'], $in['notify'], $in['email'],
$question, $parent, $commentsfollows, $in['queued'], $in['name']);
if (empty($errors)) {
$testwords = implode(' ', qa_string_to_words($in['content']));
return $commentid;
foreach ($commentsfollows as $comment) {
if (($comment['basetype'] == 'C') && ($comment['parentid'] == $parentid) && !$comment['hidden']) {
if (implode(' ', qa_string_to_words($comment['content'])) == $testwords) {
$errors['content'] = qa_lang_html('question/duplicate_content');
break;
}
}
}
}
return null;
}
if (empty($errors)) {
$userid = qa_get_logged_in_userid();
$handle = qa_get_logged_in_handle();
$cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create(); // create a new cookie if necessary
$commentid = qa_comment_create($userid, $handle, $cookieid, $in['content'], $in['format'], $in['text'], $in['notify'], $in['email'],
$question, $parent, $commentsfollows, $in['queued'], $in['name']);
function qa_page_q_prepare_post_for_filters($post)
/*
Return the array of information to be passed to filter modules for the post in $post (from the database)
*/
{
$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 $commentid;
}
return $in;
}
return null;
}
/**
* Return the array of information to be passed to filter modules for the post in $post (from the database)
* @param $post
* @return array
*/
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'];
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
return $in;
}
......@@ -20,1037 +20,1121 @@
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
header('Location: ../');
exit;
}
function qa_page_q_load_as($question, $childposts)
/*
Given a $question and its $childposts from the database, return a list of that question's answers
*/
{
$answers=array();
foreach ($childposts as $postid => $post)
switch ($post['type']) {
case 'A':
case 'A_HIDDEN':
case 'A_QUEUED':
$answers[$postid]=$post;
break;
}
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../');
exit;
}
/**
* Given a $question and its $childposts from the database, return a list of that question's answers
* @param $question
* @param $childposts
* @return array
*/
function qa_page_q_load_as($question, $childposts)
{
$answers = array();
foreach ($childposts as $postid => $post)
switch ($post['type']) {
case 'A':
case 'A_HIDDEN':
case 'A_QUEUED':
$answers[$postid] = $post;
break;
}
return $answers;
return $answers;
}
/**
* Given a $question, its $childposts and its answers $achildposts from the database,
* return a list of comments or follow-on questions for that question or its answers.
* Follow-on and duplicate questions are now returned, with their visibility determined in qa_page_q_comment_follow_list()
* @param $question
* @param $childposts
* @param $achildposts
* @param array $duplicateposts
* @return array
*/
function qa_page_q_load_c_follows($question, $childposts, $achildposts, $duplicateposts = array())
{
$commentsfollows = array();
foreach ($childposts as $postid => $post) {
switch ($post['basetype']) {
case 'Q':
case 'C':
$commentsfollows[$postid] = $post;
break;
}
}
function qa_page_q_load_c_follows($question, $childposts, $achildposts, $duplicateposts=array())
/*
Given a $question, its $childposts and its answers $achildposts from the database,
return a list of comments or follow-on questions for that question or its answers.
Follow-on and duplicate questions are now returned, with their visibility determined in qa_page_q_comment_follow_list()
*/
{
$commentsfollows=array();
foreach ($childposts as $postid => $post)
switch ($post['basetype']) {
case 'Q':
case 'C':
$commentsfollows[$postid]=$post;
break;
}
foreach ($achildposts as $postid => $post)
switch ($post['basetype']) {
case 'Q':
case 'C':
$commentsfollows[$postid]=$post;
break;
}
foreach ($duplicateposts as $postid => $post) {
$commentsfollows[$postid] = $post;
foreach ($achildposts as $postid => $post) {
switch ($post['basetype']) {
case 'Q':
case 'C':
$commentsfollows[$postid] = $post;
break;
}
}
return $commentsfollows;
foreach ($duplicateposts as $postid => $post) {
$commentsfollows[$postid] = $post;
}
return $commentsfollows;
}
/**
* Calculates which operations the current user may perform on a post. This function is a key part of Q2A's logic
* and is ripe for overriding by plugins. The latter two arrays can contain additional posts retrieved from the
* database, and these will be ignored.
*
* @param array $post The question/answer/comment to check.
* @param array $parentpost The post's parent if there is one.
* @param array $siblingposts The post's siblings (i.e. those with the same type and parent as the post).
* @param array $childposts The post's children (e.g. comments on answers).
* @return array List of elements that can be added to the post.
*/
function qa_page_q_post_rules($post, $parentpost = null, $siblingposts = null, $childposts = null)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
$userid = qa_get_logged_in_userid();
$cookieid = qa_cookie_get();
$userlevel = qa_user_level_for_post($post);
$userfields = qa_get_logged_in_user_cache();
if (!isset($userfields)) {
$userfields = array(
'userid' => null,
'level' => null,
'flags' => null,
);
}
/**
* Calculates which operations the current user may perform on a post. This function is a key part of Q2A's logic
* and is ripe for overriding by plugins. The latter two arrays can contain additional posts retrieved from the
* database, and these will be ignored.
*
* @param array $post The question/answer/comment to check.
* @param array $parentpost The post's parent if there is one.
* @param array $siblingposts The post's siblings (i.e. those with the same type and parent as the post).
* @param null $childposts The post's children (e.g. comments on answers).
* @return array List of elements that can be added to the post.
*/
function qa_page_q_post_rules($post, $parentpost=null, $siblingposts=null, $childposts=null)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
$userid = qa_get_logged_in_userid();
$cookieid = qa_cookie_get();
$userlevel = qa_user_level_for_post($post);
$userfields = qa_get_logged_in_user_cache();
if (!isset($userfields)) {
$userfields = array(
'userid' => null,
'level' => null,
'flags' => null,
);
}
$rules['isbyuser'] = qa_post_is_by_user($post, $userid, $cookieid);
$rules['queued'] = substr($post['type'], 1) == '_QUEUED';
$rules['closed'] = $post['basetype'] == 'Q' && (isset($post['closedbyid']) || (isset($post['selchildid']) && qa_opt('do_close_on_select')));
$rules['isbyuser'] = qa_post_is_by_user($post, $userid, $cookieid);
$rules['queued'] = substr($post['type'], 1) == '_QUEUED';
$rules['closed'] = $post['basetype'] == 'Q' && (isset($post['closedbyid']) || (isset($post['selchildid']) && qa_opt('do_close_on_select')));
// Cache some responses to the user permission checks
// Cache some responses to the user permission checks
$permiterror_post_q = qa_user_permit_error('permit_post_q', null, $userlevel, true, $userfields); // don't check limits here, so we can show error message
$permiterror_post_a = qa_user_permit_error('permit_post_a', null, $userlevel, true, $userfields);
$permiterror_post_c = qa_user_permit_error('permit_post_c', null, $userlevel, true, $userfields);
$permiterror_post_q = qa_user_permit_error('permit_post_q', null, $userlevel, true, $userfields); // don't check limits here, so we can show error message
$permiterror_post_a = qa_user_permit_error('permit_post_a', null, $userlevel, true, $userfields);
$permiterror_post_c = qa_user_permit_error('permit_post_c', null, $userlevel, true, $userfields);
$edit_option = $post['basetype'] == 'Q' ? 'permit_edit_q' : ($post['basetype'] == 'A' ? 'permit_edit_a' : 'permit_edit_c');
$permiterror_edit = qa_user_permit_error($edit_option, null, $userlevel, true, $userfields);
$permiterror_retagcat = qa_user_permit_error('permit_retag_cat', null, $userlevel, true, $userfields);
$permiterror_flag = qa_user_permit_error('permit_flag', null, $userlevel, true, $userfields);
$permiterror_hide_show = qa_user_permit_error('permit_hide_show', null, $userlevel, true, $userfields);
$permiterror_hide_show_self = $rules['isbyuser'] ? qa_user_permit_error(null, null, $userlevel, true, $userfields) : $permiterror_hide_show;
$permiterror_close_open = qa_user_permit_error($rules['isbyuser'] ? null : 'permit_close_q', null, $userlevel, true, $userfields);
$permiterror_moderate = qa_user_permit_error('permit_moderate', null, $userlevel, true, $userfields);
$edit_option = $post['basetype'] == 'Q' ? 'permit_edit_q' : ($post['basetype'] == 'A' ? 'permit_edit_a' : 'permit_edit_c');
$permiterror_edit = qa_user_permit_error($edit_option, null, $userlevel, true, $userfields);
$permiterror_retagcat = qa_user_permit_error('permit_retag_cat', null, $userlevel, true, $userfields);
$permiterror_flag = qa_user_permit_error('permit_flag', null, $userlevel, true, $userfields);
$permiterror_hide_show = qa_user_permit_error('permit_hide_show', null, $userlevel, true, $userfields);
$permiterror_hide_show_self = $rules['isbyuser'] ? qa_user_permit_error(null, null, $userlevel, true, $userfields) : $permiterror_hide_show;
$permiterror_close_open = qa_user_permit_error($rules['isbyuser'] ? null : 'permit_close_q', null, $userlevel, true, $userfields);
$permiterror_moderate = qa_user_permit_error('permit_moderate', null, $userlevel, true, $userfields);
// General permissions
// General permissions
$rules['authorlast'] = !isset($post['lastuserid']) || $post['lastuserid'] === $post['userid'];
$rules['viewable'] = $post['hidden'] ? !$permiterror_hide_show_self : ($rules['queued'] ? ($rules['isbyuser'] || !$permiterror_moderate) : true);
$rules['authorlast'] = !isset($post['lastuserid']) || $post['lastuserid'] === $post['userid'];
$rules['viewable'] = $post['hidden'] ? !$permiterror_hide_show_self : ($rules['queued'] ? ($rules['isbyuser'] || !$permiterror_moderate) : true);
// Answer, comment and edit might show the button even if the user still needs to do something (e.g. log in)
// Answer, comment and edit might show the button even if the user still needs to do something (e.g. log in)
$rules['answerbutton'] = $post['type'] == 'Q' && $permiterror_post_a != 'level' && !$rules['closed']
&& (qa_opt('allow_self_answer') || !$rules['isbyuser']);
$rules['answerbutton'] = $post['type'] == 'Q' && $permiterror_post_a != 'level' && !$rules['closed']
&& (qa_opt('allow_self_answer') || !$rules['isbyuser']);
$rules['commentbutton'] = ($post['type'] == 'Q' || $post['type'] == 'A') && $permiterror_post_c != 'level'
&& qa_opt($post['type'] == 'Q' ? 'comment_on_qs' : 'comment_on_as');
$rules['commentable'] = $rules['commentbutton'] && !$permiterror_post_c;
$rules['commentbutton'] = ($post['type'] == 'Q' || $post['type'] == 'A') && $permiterror_post_c != 'level'
&& qa_opt($post['type'] == 'Q' ? 'comment_on_qs' : 'comment_on_as');
$rules['commentable'] = $rules['commentbutton'] && !$permiterror_post_c;
$button_errors = array('login', 'level', 'approve');
$button_errors = array('login', 'level', 'approve');
$rules['editbutton'] = !$post['hidden'] && !$rules['closed']
&& ($rules['isbyuser'] || (!in_array($permiterror_edit, $button_errors) && (!$rules['queued'])));
$rules['editable'] = $rules['editbutton'] && ($rules['isbyuser'] || !$permiterror_edit);
$rules['editbutton'] = !$post['hidden'] && !$rules['closed']
&& ($rules['isbyuser'] || (!in_array($permiterror_edit, $button_errors) && (!$rules['queued'])));
$rules['editable'] = $rules['editbutton'] && ($rules['isbyuser'] || !$permiterror_edit);
$rules['retagcatbutton'] = $post['basetype'] == 'Q' && (qa_using_tags() || qa_using_categories())
&& !$post['hidden'] && ($rules['isbyuser'] || !in_array($permiterror_retagcat, $button_errors));
$rules['retagcatable'] = $rules['retagcatbutton'] && ($rules['isbyuser'] || !$permiterror_retagcat);
$rules['retagcatbutton'] = $post['basetype'] == 'Q' && (qa_using_tags() || qa_using_categories())
&& !$post['hidden'] && ($rules['isbyuser'] || !in_array($permiterror_retagcat, $button_errors));
$rules['retagcatable'] = $rules['retagcatbutton'] && ($rules['isbyuser'] || !$permiterror_retagcat);
if ($rules['editbutton'] && $rules['retagcatbutton']) {
// only show one button since they lead to the same form
if ($rules['retagcatable'] && !$rules['editable'])
$rules['editbutton'] = false; // if we can do this without getting an error, show that as the title
else
$rules['retagcatbutton'] = false;
}
if ($rules['editbutton'] && $rules['retagcatbutton']) {
// only show one button since they lead to the same form
if ($rules['retagcatable'] && !$rules['editable'])
$rules['editbutton'] = false; // if we can do this without getting an error, show that as the title
else
$rules['retagcatbutton'] = false;
$rules['aselectable'] = $post['type'] == 'Q' && !qa_user_permit_error($rules['isbyuser'] ? null : 'permit_select_a', null, $userlevel, true, $userfields);
$rules['flagbutton'] = qa_opt('flagging_of_posts') && !$rules['isbyuser'] && !$post['hidden'] && !$rules['queued']
&& !@$post['userflag'] && !in_array($permiterror_flag, $button_errors);
$rules['flagtohide'] = $rules['flagbutton'] && !$permiterror_flag && ($post['flagcount'] + 1) >= qa_opt('flagging_hide_after');
$rules['unflaggable'] = @$post['userflag'] && !$post['hidden'];
$rules['clearflaggable'] = $post['flagcount'] >= (@$post['userflag'] ? 2 : 1) && !$permiterror_hide_show;
// Other actions only show the button if it's immediately possible
$notclosedbyother = !($rules['closed'] && isset($post['closedbyid']) && !$rules['authorlast']);
$nothiddenbyother = !($post['hidden'] && !$rules['authorlast']);
$rules['closeable'] = qa_opt('allow_close_questions') && $post['type'] == 'Q' && !$rules['closed'] && !$permiterror_close_open;
// cannot reopen a question if it's been hidden, or if it was closed by someone else and you don't have global closing permissions
$rules['reopenable'] = $rules['closed'] && isset($post['closedbyid']) && !$permiterror_close_open && !$post['hidden']
&& ($notclosedbyother || !qa_user_permit_error('permit_close_q', null, $userlevel, true, $userfields));
$rules['moderatable'] = $rules['queued'] && !$permiterror_moderate;
// cannot hide a question if it was closed by someone else and you don't have global hiding permissions
$rules['hideable'] = !$post['hidden'] && ($rules['isbyuser'] || !$rules['queued']) && !$permiterror_hide_show_self
&& ($notclosedbyother || !$permiterror_hide_show);
// means post can be reshown immediately without checking whether it needs moderation
$rules['reshowimmed'] = $post['hidden'] && !$permiterror_hide_show;
// cannot reshow a question if it was hidden by someone else, or if it has flags - unless you have global hide/show permissions
$rules['reshowable'] = $post['hidden'] && (!$permiterror_hide_show_self) &&
($rules['reshowimmed'] || ($nothiddenbyother && !$post['flagcount']));
$rules['deleteable'] = $post['hidden'] && !qa_user_permit_error('permit_delete_hidden', null, $userlevel, true, $userfields);
$rules['claimable'] = !isset($post['userid']) && isset($userid) && strlen(@$post['cookieid']) && (strcmp(@$post['cookieid'], $cookieid) == 0)
&& !($post['basetype'] == 'Q' ? $permiterror_post_q : ($post['basetype'] == 'A' ? $permiterror_post_a : $permiterror_post_c));
$rules['followable'] = $post['type'] == 'A' ? qa_opt('follow_on_as') : false;
// Check for claims that could break rules about self answering and multiple answers
if ($rules['claimable'] && $post['basetype'] == 'A') {
if (!qa_opt('allow_self_answer') && isset($parentpost) && qa_post_is_by_user($parentpost, $userid, $cookieid))
$rules['claimable'] = false;
if (isset($siblingposts) && !qa_opt('allow_multi_answers')) {
foreach ($siblingposts as $siblingpost) {
if ($siblingpost['parentid'] == $post['parentid'] && $siblingpost['basetype'] == 'A' && qa_post_is_by_user($siblingpost, $userid, $cookieid))
$rules['claimable'] = false;
}
}
}
$rules['aselectable'] = $post['type'] == 'Q' && !qa_user_permit_error($rules['isbyuser'] ? null : 'permit_select_a', null, $userlevel, true, $userfields);
$rules['flagbutton'] = qa_opt('flagging_of_posts') && !$rules['isbyuser'] && !$post['hidden'] && !$rules['queued']
&& !@$post['userflag'] && !in_array($permiterror_flag, $button_errors);
$rules['flagtohide'] = $rules['flagbutton'] && !$permiterror_flag && ($post['flagcount'] + 1) >= qa_opt('flagging_hide_after');
$rules['unflaggable'] = @$post['userflag'] && !$post['hidden'];
$rules['clearflaggable'] = $post['flagcount'] >= (@$post['userflag'] ? 2 : 1) && !$permiterror_hide_show;
// Other actions only show the button if it's immediately possible
$notclosedbyother = !($rules['closed'] && isset($post['closedbyid']) && !$rules['authorlast']);
$nothiddenbyother = !($post['hidden'] && !$rules['authorlast']);
$rules['closeable'] = qa_opt('allow_close_questions') && $post['type'] == 'Q' && !$rules['closed'] && !$permiterror_close_open;
// cannot reopen a question if it's been hidden, or if it was closed by someone else and you don't have global closing permissions
$rules['reopenable'] = $rules['closed'] && isset($post['closedbyid']) && !$permiterror_close_open && !$post['hidden']
&& ($notclosedbyother || !qa_user_permit_error('permit_close_q', null, $userlevel, true, $userfields));
$rules['moderatable'] = $rules['queued'] && !$permiterror_moderate;
// cannot hide a question if it was closed by someone else and you don't have global hiding permissions
$rules['hideable'] = !$post['hidden'] && ($rules['isbyuser'] || !$rules['queued']) && !$permiterror_hide_show_self
&& ($notclosedbyother || !$permiterror_hide_show);
// means post can be reshown immediately without checking whether it needs moderation
$rules['reshowimmed'] = $post['hidden'] && !$permiterror_hide_show;
// cannot reshow a question if it was hidden by someone else, or if it has flags - unless you have global hide/show permissions
$rules['reshowable'] = $post['hidden'] && (!$permiterror_hide_show_self) &&
($rules['reshowimmed'] || ($nothiddenbyother && !$post['flagcount']));
$rules['deleteable'] = $post['hidden'] && !qa_user_permit_error('permit_delete_hidden', null, $userlevel, true, $userfields);
$rules['claimable'] = !isset($post['userid']) && isset($userid) && strlen(@$post['cookieid']) && (strcmp(@$post['cookieid'], $cookieid) == 0)
&& !($post['basetype'] == 'Q' ? $permiterror_post_q : ($post['basetype'] == 'A' ? $permiterror_post_a : $permiterror_post_c));
$rules['followable'] = $post['type'] == 'A' ? qa_opt('follow_on_as') : false;
// Now make any changes based on the child posts
// Check for claims that could break rules about self answering and multiple answers
if (isset($childposts)) {
foreach ($childposts as $childpost) {
if ($childpost['parentid'] == $post['postid']) {
// this post has comments
$rules['deleteable'] = false;
if ($rules['claimable'] && $post['basetype'] == 'A') {
if ( (!qa_opt('allow_self_answer')) && isset($parentpost) && qa_post_is_by_user($parentpost, $userid, $cookieid) )
$rules['claimable'] = false;
if ($childpost['basetype'] == 'A' && qa_post_is_by_user($childpost, $userid, $cookieid)) {
if (!qa_opt('allow_multi_answers'))
$rules['answerbutton'] = false;
if (isset($siblingposts) && !qa_opt('allow_multi_answers')) {
foreach ($siblingposts as $siblingpost) {
if ($siblingpost['parentid'] == $post['parentid'] && $siblingpost['basetype'] == 'A' && qa_post_is_by_user($siblingpost, $userid, $cookieid))
if (!qa_opt('allow_self_answer'))
$rules['claimable'] = false;
}
}
}
// Now make any changes based on the child posts
if (isset($childposts)) {
foreach ($childposts as $childpost) {
if ($childpost['parentid'] == $post['postid']) {
// this post has comments
$rules['deleteable'] = false;
if ($childpost['basetype'] == 'A' && qa_post_is_by_user($childpost, $userid, $cookieid)) {
if (!qa_opt('allow_multi_answers'))
$rules['answerbutton'] = false;
if (!qa_opt('allow_self_answer'))
$rules['claimable'] = false;
}
}
if ($childpost['closedbyid'] == $post['postid']) {
// other questions are closed as duplicates of this one
$rules['deleteable'] = false;
}
if ($childpost['closedbyid'] == $post['postid']) {
// other questions are closed as duplicates of this one
$rules['deleteable'] = false;
}
}
// Return the resulting rules
return $rules;
}
// Return the resulting rules
return $rules;
}
/**
* Return the $qa_content['q_view'] element for $question as viewed by the current user. If this question is a
* follow-on, pass the question for this question's parent answer in $parentquestion, otherwise null. If the question
* is closed, pass the post used to close this question in $closepost, otherwise null. $usershtml should be an array
* which maps userids to HTML user representations, including the question's author and (if present) last editor. If a
* form has been explicitly requested for the page, set $formrequested to true - this will hide the buttons.
* @param $question
* @param $parentquestion
* @param $closepost
* @param $usershtml
* @param $formrequested
* @return array
*/
function qa_page_q_question_view($question, $parentquestion, $closepost, $usershtml, $formrequested)
{
$questionid = $question['postid'];
$userid = qa_get_logged_in_userid();
$cookieid = qa_cookie_get();
$htmloptions = qa_post_html_options($question, null, true);
$htmloptions['answersview'] = false; // answer count is displayed separately so don't show it here
$htmloptions['avatarsize'] = qa_opt('avatar_q_page_q_size');
$htmloptions['q_request'] = qa_q_request($question['postid'], $question['title']);
$q_view = qa_post_html_fields($question, $userid, $cookieid, $usershtml, null, $htmloptions);
$q_view['main_form_tags'] = 'method="post" action="' . qa_self_html() . '"';
$q_view['voting_form_hidden'] = array('code' => qa_get_form_security_code('vote'));
$q_view['buttons_form_hidden'] = array('code' => qa_get_form_security_code('buttons-' . $questionid), 'qa_click' => '');
// Buttons for operating on the question
if (!$formrequested) { // don't show if another form is currently being shown on page
$clicksuffix = ' onclick="qa_show_waiting_after(this, false);"'; // add to operations that write to database
$buttons = array();
if ($question['editbutton']) {
$buttons['edit'] = array(
'tags' => 'name="q_doedit"',
'label' => qa_lang_html('question/edit_button'),
'popup' => qa_lang_html('question/edit_q_popup'),
);
}
function qa_page_q_question_view($question, $parentquestion, $closepost, $usershtml, $formrequested)
/*
Return the $qa_content['q_view'] element for $question as viewed by the current user. If this question is a
follow-on, pass the question for this question's parent answer in $parentquestion, otherwise null. If the question
is closed, pass the post used to close this question in $closepost, otherwise null. $usershtml should be an array
which maps userids to HTML user representations, including the question's author and (if present) last editor. If a
form has been explicitly requested for the page, set $formrequested to true - this will hide the buttons.
*/
{
$questionid=$question['postid'];
$userid=qa_get_logged_in_userid();
$cookieid=qa_cookie_get();
$htmloptions=qa_post_html_options($question, null, true);
$htmloptions['answersview']=false; // answer count is displayed separately so don't show it here
$htmloptions['avatarsize']=qa_opt('avatar_q_page_q_size');
$htmloptions['q_request']=qa_q_request($question['postid'], $question['title']);
$q_view=qa_post_html_fields($question, $userid, $cookieid, $usershtml, null, $htmloptions);
$q_view['main_form_tags']='method="post" action="'.qa_self_html().'"';
$q_view['voting_form_hidden']=array('code' => qa_get_form_security_code('vote'));
$q_view['buttons_form_hidden']=array('code' => qa_get_form_security_code('buttons-'.$questionid), 'qa_click' => '');
// Buttons for operating on the question
if (!$formrequested) { // don't show if another form is currently being shown on page
$clicksuffix=' onclick="qa_show_waiting_after(this, false);"'; // add to operations that write to database
$buttons=array();
if ($question['editbutton'])
$buttons['edit']=array(
'tags' => 'name="q_doedit"',
'label' => qa_lang_html('question/edit_button'),
'popup' => qa_lang_html('question/edit_q_popup'),
);
$hascategories=qa_using_categories();
if ($question['retagcatbutton'])
$buttons['retagcat']=array(
'tags' => 'name="q_doedit"',
'label' => qa_lang_html($hascategories ? 'question/recat_button' : 'question/retag_button'),
'popup' => qa_lang_html($hascategories
? (qa_using_tags() ? 'question/retag_cat_popup' : 'question/recat_popup')
: 'question/retag_popup'
),
);
if ($question['flagbutton'])
$buttons['flag']=array(
'tags' => 'name="q_doflag"'.$clicksuffix,
'label' => qa_lang_html($question['flagtohide'] ? 'question/flag_hide_button' : 'question/flag_button'),
'popup' => qa_lang_html('question/flag_q_popup'),
);
$hascategories = qa_using_categories();
if ($question['unflaggable'])
$buttons['unflag']=array(
'tags' => 'name="q_dounflag"'.$clicksuffix,
'label' => qa_lang_html('question/unflag_button'),
'popup' => qa_lang_html('question/unflag_popup'),
);
if ($question['retagcatbutton']) {
$buttons['retagcat'] = array(
'tags' => 'name="q_doedit"',
'label' => qa_lang_html($hascategories ? 'question/recat_button' : 'question/retag_button'),
'popup' => qa_lang_html($hascategories
? (qa_using_tags() ? 'question/retag_cat_popup' : 'question/recat_popup')
: 'question/retag_popup'
),
);
}
if ($question['clearflaggable'])
$buttons['clearflags']=array(
'tags' => 'name="q_doclearflags"'.$clicksuffix,
'label' => qa_lang_html('question/clear_flags_button'),
'popup' => qa_lang_html('question/clear_flags_popup'),
);
if ($question['flagbutton']) {
$buttons['flag'] = array(
'tags' => 'name="q_doflag"' . $clicksuffix,
'label' => qa_lang_html($question['flagtohide'] ? 'question/flag_hide_button' : 'question/flag_button'),
'popup' => qa_lang_html('question/flag_q_popup'),
);
}
if ($question['closeable'])
$buttons['close']=array(
'tags' => 'name="q_doclose"',
'label' => qa_lang_html('question/close_button'),
'popup' => qa_lang_html('question/close_q_popup'),
);
if ($question['unflaggable']) {
$buttons['unflag'] = array(
'tags' => 'name="q_dounflag"' . $clicksuffix,
'label' => qa_lang_html('question/unflag_button'),
'popup' => qa_lang_html('question/unflag_popup'),
);
}
if ($question['reopenable'])
$buttons['reopen']=array(
'tags' => 'name="q_doreopen"'.$clicksuffix,
'label' => qa_lang_html('question/reopen_button'),
'popup' => qa_lang_html('question/reopen_q_popup'),
);
if ($question['clearflaggable']) {
$buttons['clearflags'] = array(
'tags' => 'name="q_doclearflags"' . $clicksuffix,
'label' => qa_lang_html('question/clear_flags_button'),
'popup' => qa_lang_html('question/clear_flags_popup'),
);
}
if ($question['moderatable']) {
$buttons['approve']=array(
'tags' => 'name="q_doapprove"'.$clicksuffix,
'label' => qa_lang_html('question/approve_button'),
'popup' => qa_lang_html('question/approve_q_popup'),
);
if ($question['closeable']) {
$buttons['close'] = array(
'tags' => 'name="q_doclose"',
'label' => qa_lang_html('question/close_button'),
'popup' => qa_lang_html('question/close_q_popup'),
);
}
$buttons['reject']=array(
'tags' => 'name="q_doreject"'.$clicksuffix,
'label' => qa_lang_html('question/reject_button'),
'popup' => qa_lang_html('question/reject_q_popup'),
);
}
if ($question['reopenable']) {
$buttons['reopen'] = array(
'tags' => 'name="q_doreopen"' . $clicksuffix,
'label' => qa_lang_html('question/reopen_button'),
'popup' => qa_lang_html('question/reopen_q_popup'),
);
}
if ($question['hideable'])
$buttons['hide']=array(
'tags' => 'name="q_dohide"'.$clicksuffix,
'label' => qa_lang_html('question/hide_button'),
'popup' => qa_lang_html('question/hide_q_popup'),
);
if ($question['moderatable']) {
$buttons['approve'] = array(
'tags' => 'name="q_doapprove"' . $clicksuffix,
'label' => qa_lang_html('question/approve_button'),
'popup' => qa_lang_html('question/approve_q_popup'),
);
if ($question['reshowable'])
$buttons['reshow']=array(
'tags' => 'name="q_doreshow"'.$clicksuffix,
'label' => qa_lang_html('question/reshow_button'),
'popup' => qa_lang_html('question/reshow_q_popup'),
);
$buttons['reject'] = array(
'tags' => 'name="q_doreject"' . $clicksuffix,
'label' => qa_lang_html('question/reject_button'),
'popup' => qa_lang_html('question/reject_q_popup'),
);
}
if ($question['deleteable'])
$buttons['delete']=array(
'tags' => 'name="q_dodelete"'.$clicksuffix,
'label' => qa_lang_html('question/delete_button'),
'popup' => qa_lang_html('question/delete_q_popup'),
);
if ($question['hideable']) {
$buttons['hide'] = array(
'tags' => 'name="q_dohide"' . $clicksuffix,
'label' => qa_lang_html('question/hide_button'),
'popup' => qa_lang_html('question/hide_q_popup'),
);
}
if ($question['claimable'])
$buttons['claim']=array(
'tags' => 'name="q_doclaim"'.$clicksuffix,
'label' => qa_lang_html('question/claim_button'),
'popup' => qa_lang_html('question/claim_q_popup'),
);
if ($question['reshowable']) {
$buttons['reshow'] = array(
'tags' => 'name="q_doreshow"' . $clicksuffix,
'label' => qa_lang_html('question/reshow_button'),
'popup' => qa_lang_html('question/reshow_q_popup'),
);
}
if ($question['answerbutton']) // don't show if shown by default
$buttons['answer']=array(
'tags' => 'name="q_doanswer" id="q_doanswer" onclick="return qa_toggle_element(\'anew\')"',
'label' => qa_lang_html('question/answer_button'),
'popup' => qa_lang_html('question/answer_q_popup'),
);
if ($question['deleteable']) {
$buttons['delete'] = array(
'tags' => 'name="q_dodelete"' . $clicksuffix,
'label' => qa_lang_html('question/delete_button'),
'popup' => qa_lang_html('question/delete_q_popup'),
);
}
if ($question['commentbutton'])
$buttons['comment']=array(
'tags' => 'name="q_docomment" onclick="return qa_toggle_element(\'c'.$questionid.'\')"',
'label' => qa_lang_html('question/comment_button'),
'popup' => qa_lang_html('question/comment_q_popup'),
);
if ($question['claimable']) {
$buttons['claim'] = array(
'tags' => 'name="q_doclaim"' . $clicksuffix,
'label' => qa_lang_html('question/claim_button'),
'popup' => qa_lang_html('question/claim_q_popup'),
);
}
$q_view['form']=array(
'style' => 'light',
'buttons' => $buttons,
if ($question['answerbutton']) {
// don't show if shown by default
$buttons['answer'] = array(
'tags' => 'name="q_doanswer" id="q_doanswer" onclick="return qa_toggle_element(\'anew\')"',
'label' => qa_lang_html('question/answer_button'),
'popup' => qa_lang_html('question/answer_q_popup'),
);
}
if ($question['commentbutton']) {
$buttons['comment'] = array(
'tags' => 'name="q_docomment" onclick="return qa_toggle_element(\'c' . $questionid . '\')"',
'label' => qa_lang_html('question/comment_button'),
'popup' => qa_lang_html('question/comment_q_popup'),
);
}
// Information about the question of the answer that this question follows on from (or a question directly)
$q_view['form'] = array(
'style' => 'light',
'buttons' => $buttons,
);
}
if (isset($parentquestion))
$q_view['follows']=array(
'label' => qa_lang_html(($question['parentid']==$parentquestion['postid']) ? 'question/follows_q' : 'question/follows_a'),
'title' => qa_html(qa_block_words_replace($parentquestion['title'], qa_get_block_words_preg())),
'url' => qa_q_path_html($parentquestion['postid'], $parentquestion['title'], false,
($question['parentid']==$parentquestion['postid']) ? 'Q' : 'A', $question['parentid']),
);
// Information about the question of the answer that this question follows on from (or a question directly)
// Information about the question that this question is a duplicate of (if appropriate)
if (isset($parentquestion)) {
$q_view['follows'] = array(
'label' => qa_lang_html(($question['parentid'] == $parentquestion['postid']) ? 'question/follows_q' : 'question/follows_a'),
'title' => qa_html(qa_block_words_replace($parentquestion['title'], qa_get_block_words_preg())),
'url' => qa_q_path_html($parentquestion['postid'], $parentquestion['title'], false,
($question['parentid'] == $parentquestion['postid']) ? 'Q' : 'A', $question['parentid']),
);
}
if (isset($closepost)) {
if ($closepost['basetype']=='Q') {
if ($closepost['hidden']) {
// don't show link for hidden questions
$q_view['closed']=array(
'state' => qa_lang_html('main/closed'),
'label' => qa_lang_html('main/closed'),
'content' => '',
);
}
else {
$q_view['closed']=array(
'state' => qa_lang_html('main/closed'),
'label' => qa_lang_html('question/closed_as_duplicate'),
'content' => qa_html(qa_block_words_replace($closepost['title'], qa_get_block_words_preg())),
'url' => qa_q_path_html($closepost['postid'], $closepost['title']),
);
}
// Information about the question that this question is a duplicate of (if appropriate)
} elseif ($closepost['type']=='NOTE') {
$viewer=qa_load_viewer($closepost['content'], $closepost['format']);
if (isset($closepost)) {
$q_view['closed']=array(
if ($closepost['basetype'] == 'Q') {
if ($closepost['hidden']) {
// don't show link for hidden questions
$q_view['closed'] = array(
'state' => qa_lang_html('main/closed'),
'label' => qa_lang_html('main/closed'),
'content' => '',
);
} else {
$q_view['closed'] = array(
'state' => qa_lang_html('main/closed'),
'label' => qa_lang_html('question/closed_with_note'),
'content' => $viewer->get_html($closepost['content'], $closepost['format'], array(
'blockwordspreg' => qa_get_block_words_preg(),
)),
'label' => qa_lang_html('question/closed_as_duplicate'),
'content' => qa_html(qa_block_words_replace($closepost['title'], qa_get_block_words_preg())),
'url' => qa_q_path_html($closepost['postid'], $closepost['title']),
);
}
}
// Extra value display
} elseif ($closepost['type'] == 'NOTE') {
$viewer = qa_load_viewer($closepost['content'], $closepost['format']);
if (strlen(@$question['extra']) && qa_opt('extra_field_active') && qa_opt('extra_field_display'))
$q_view['extra']=array(
'label' => qa_html(qa_opt('extra_field_label')),
'content' => qa_html(qa_block_words_replace($question['extra'], qa_get_block_words_preg())),
$q_view['closed'] = array(
'state' => qa_lang_html('main/closed'),
'label' => qa_lang_html('question/closed_with_note'),
'content' => $viewer->get_html($closepost['content'], $closepost['format'], array(
'blockwordspreg' => qa_get_block_words_preg(),
)),
);
return $q_view;
}
}
function qa_page_q_answer_view($question, $answer, $isselected, $usershtml, $formrequested)
/*
Returns an element to add to $qa_content['a_list']['as'] for $answer as viewed by $userid and $cookieid. Pass the
answer's $question and whether it $isselected. $usershtml should be an array which maps userids to HTML user
representations, including the answer's author and (if present) last editor. If a form has been explicitly requested
for the page, set $formrequested to true - this will hide the buttons.
*/
{
$answerid=$answer['postid'];
$userid=qa_get_logged_in_userid();
$cookieid=qa_cookie_get();
$htmloptions=qa_post_html_options($answer, null, true);
$htmloptions['isselected']=$isselected;
$htmloptions['avatarsize']=qa_opt('avatar_q_page_a_size');
$htmloptions['q_request']=qa_q_request($question['postid'], $question['title']);
$a_view=qa_post_html_fields($answer, $userid, $cookieid, $usershtml, null, $htmloptions);
if ($answer['queued'])
$a_view['error']=$answer['isbyuser'] ? qa_lang_html('question/a_your_waiting_approval') : qa_lang_html('question/a_waiting_your_approval');
// Extra value display
$a_view['main_form_tags']='method="post" action="'.qa_self_html().'"';
$a_view['voting_form_hidden']=array('code' => qa_get_form_security_code('vote'));
$a_view['buttons_form_hidden']=array('code' => qa_get_form_security_code('buttons-'.$answerid), 'qa_click' => '');
// Selection/unselect buttons and others for operating on the answer
if (!$formrequested) { // don't show if another form is currently being shown on page
$prefix='a'.qa_html($answerid).'_';
$clicksuffix=' onclick="return qa_answer_click('.qa_js($answerid).', '.qa_js($question['postid']).', this);"';
if ($question['aselectable'] && !$answer['hidden'] && !$answer['queued']) {
if ($isselected)
$a_view['unselect_tags']='title="'.qa_lang_html('question/unselect_popup').'" name="'.$prefix.'dounselect"'.$clicksuffix;
else
$a_view['select_tags']='title="'.qa_lang_html('question/select_popup').'" name="'.$prefix.'doselect"'.$clicksuffix;
}
$buttons=array();
if (strlen(@$question['extra']) && qa_opt('extra_field_active') && qa_opt('extra_field_display')) {
$q_view['extra'] = array(
'label' => qa_html(qa_opt('extra_field_label')),
'content' => qa_html(qa_block_words_replace($question['extra'], qa_get_block_words_preg())),
);
}
if ($answer['editbutton'])
$buttons['edit']=array(
'tags' => 'name="'.$prefix.'doedit"',
'label' => qa_lang_html('question/edit_button'),
'popup' => qa_lang_html('question/edit_a_popup'),
);
if ($answer['flagbutton'])
$buttons['flag']=array(
'tags' => 'name="'.$prefix.'doflag"'.$clicksuffix,
'label' => qa_lang_html($answer['flagtohide'] ? 'question/flag_hide_button' : 'question/flag_button'),
'popup' => qa_lang_html('question/flag_a_popup'),
);
return $q_view;
}
if ($answer['unflaggable'])
$buttons['unflag']=array(
'tags' => 'name="'.$prefix.'dounflag"'.$clicksuffix,
'label' => qa_lang_html('question/unflag_button'),
'popup' => qa_lang_html('question/unflag_popup'),
);
if ($answer['clearflaggable'])
$buttons['clearflags']=array(
'tags' => 'name="'.$prefix.'doclearflags"'.$clicksuffix,
'label' => qa_lang_html('question/clear_flags_button'),
'popup' => qa_lang_html('question/clear_flags_popup'),
);
/**
* Returns an element to add to $qa_content['a_list']['as'] for $answer as viewed by $userid and $cookieid. Pass the
* answer's $question and whether it $isselected. $usershtml should be an array which maps userids to HTML user
* representations, including the answer's author and (if present) last editor. If a form has been explicitly requested
* for the page, set $formrequested to true - this will hide the buttons.
* @param $question
* @param $answer
* @param $isselected
* @param $usershtml
* @param $formrequested
* @return array
*/
function qa_page_q_answer_view($question, $answer, $isselected, $usershtml, $formrequested)
{
$answerid = $answer['postid'];
$userid = qa_get_logged_in_userid();
$cookieid = qa_cookie_get();
if ($answer['moderatable']) {
$buttons['approve']=array(
'tags' => 'name="'.$prefix.'doapprove"'.$clicksuffix,
'label' => qa_lang_html('question/approve_button'),
'popup' => qa_lang_html('question/approve_a_popup'),
);
$htmloptions = qa_post_html_options($answer, null, true);
$htmloptions['isselected'] = $isselected;
$htmloptions['avatarsize'] = qa_opt('avatar_q_page_a_size');
$htmloptions['q_request'] = qa_q_request($question['postid'], $question['title']);
$a_view = qa_post_html_fields($answer, $userid, $cookieid, $usershtml, null, $htmloptions);
$buttons['reject']=array(
'tags' => 'name="'.$prefix.'doreject"'.$clicksuffix,
'label' => qa_lang_html('question/reject_button'),
'popup' => qa_lang_html('question/reject_a_popup'),
);
}
if ($answer['queued'])
$a_view['error'] = $answer['isbyuser'] ? qa_lang_html('question/a_your_waiting_approval') : qa_lang_html('question/a_waiting_your_approval');
if ($answer['hideable'])
$buttons['hide']=array(
'tags' => 'name="'.$prefix.'dohide"'.$clicksuffix,
'label' => qa_lang_html('question/hide_button'),
'popup' => qa_lang_html('question/hide_a_popup'),
);
$a_view['main_form_tags'] = 'method="post" action="' . qa_self_html() . '"';
$a_view['voting_form_hidden'] = array('code' => qa_get_form_security_code('vote'));
$a_view['buttons_form_hidden'] = array('code' => qa_get_form_security_code('buttons-' . $answerid), 'qa_click' => '');
if ($answer['reshowable'])
$buttons['reshow']=array(
'tags' => 'name="'.$prefix.'doreshow"'.$clicksuffix,
'label' => qa_lang_html('question/reshow_button'),
'popup' => qa_lang_html('question/reshow_a_popup'),
);
if ($answer['deleteable'])
$buttons['delete']=array(
'tags' => 'name="'.$prefix.'dodelete"'.$clicksuffix,
'label' => qa_lang_html('question/delete_button'),
'popup' => qa_lang_html('question/delete_a_popup'),
);
// Selection/unselect buttons and others for operating on the answer
if ($answer['claimable'])
$buttons['claim']=array(
'tags' => 'name="'.$prefix.'doclaim"'.$clicksuffix,
'label' => qa_lang_html('question/claim_button'),
'popup' => qa_lang_html('question/claim_a_popup'),
);
if (!$formrequested) { // don't show if another form is currently being shown on page
$prefix = 'a' . qa_html($answerid) . '_';
$clicksuffix = ' onclick="return qa_answer_click(' . qa_js($answerid) . ', ' . qa_js($question['postid']) . ', this);"';
if ($answer['followable'])
$buttons['follow']=array(
'tags' => 'name="'.$prefix.'dofollow"',
'label' => qa_lang_html('question/follow_button'),
'popup' => qa_lang_html('question/follow_a_popup'),
);
if ($question['aselectable'] && !$answer['hidden'] && !$answer['queued']) {
if ($isselected)
$a_view['unselect_tags'] = 'title="' . qa_lang_html('question/unselect_popup') . '" name="' . $prefix . 'dounselect"' . $clicksuffix;
else
$a_view['select_tags'] = 'title="' . qa_lang_html('question/select_popup') . '" name="' . $prefix . 'doselect"' . $clicksuffix;
}
if ($answer['commentbutton'])
$buttons['comment']=array(
'tags' => 'name="'.$prefix.'docomment" onclick="return qa_toggle_element(\'c'.$answerid.'\')"',
'label' => qa_lang_html('question/comment_button'),
'popup' => qa_lang_html('question/comment_a_popup'),
);
$buttons = array();
$a_view['form']=array(
'style' => 'light',
'buttons' => $buttons,
if ($answer['editbutton']) {
$buttons['edit'] = array(
'tags' => 'name="' . $prefix . 'doedit"',
'label' => qa_lang_html('question/edit_button'),
'popup' => qa_lang_html('question/edit_a_popup'),
);
}
return $a_view;
}
if ($answer['flagbutton']) {
$buttons['flag'] = array(
'tags' => 'name="' . $prefix . 'doflag"' . $clicksuffix,
'label' => qa_lang_html($answer['flagtohide'] ? 'question/flag_hide_button' : 'question/flag_button'),
'popup' => qa_lang_html('question/flag_a_popup'),
);
}
if ($answer['unflaggable']) {
$buttons['unflag'] = array(
'tags' => 'name="' . $prefix . 'dounflag"' . $clicksuffix,
'label' => qa_lang_html('question/unflag_button'),
'popup' => qa_lang_html('question/unflag_popup'),
);
}
function qa_page_q_comment_view($question, $parent, $comment, $usershtml, $formrequested)
/*
Returns an element to add to the appropriate $qa_content[...]['c_list']['cs'] array for $comment as viewed by the
current user. Pass the comment's $parent post and antecedent $question. $usershtml should be an array which maps
userids to HTML user representations, including the comments's author and (if present) last editor. If a form has
been explicitly requested for the page, set $formrequested to true - this will hide the buttons.
*/
{
$commentid=$comment['postid'];
$questionid=($parent['basetype']=='Q') ? $parent['postid'] : $parent['parentid'];
$answerid=($parent['basetype']=='Q') ? null : $parent['postid'];
$userid=qa_get_logged_in_userid();
$cookieid=qa_cookie_get();
if ($answer['clearflaggable']) {
$buttons['clearflags'] = array(
'tags' => 'name="' . $prefix . 'doclearflags"' . $clicksuffix,
'label' => qa_lang_html('question/clear_flags_button'),
'popup' => qa_lang_html('question/clear_flags_popup'),
);
}
$htmloptions=qa_post_html_options($comment, null, true);
$htmloptions['avatarsize']=qa_opt('avatar_q_page_c_size');
$htmloptions['q_request']=qa_q_request($question['postid'], $question['title']);
$c_view=qa_post_html_fields($comment, $userid, $cookieid, $usershtml, null, $htmloptions);
if ($answer['moderatable']) {
$buttons['approve'] = array(
'tags' => 'name="' . $prefix . 'doapprove"' . $clicksuffix,
'label' => qa_lang_html('question/approve_button'),
'popup' => qa_lang_html('question/approve_a_popup'),
);
if ($comment['queued'])
$c_view['error']=$comment['isbyuser'] ? qa_lang_html('question/c_your_waiting_approval') : qa_lang_html('question/c_waiting_your_approval');
$buttons['reject'] = array(
'tags' => 'name="' . $prefix . 'doreject"' . $clicksuffix,
'label' => qa_lang_html('question/reject_button'),
'popup' => qa_lang_html('question/reject_a_popup'),
);
}
if ($answer['hideable']) {
$buttons['hide'] = array(
'tags' => 'name="' . $prefix . 'dohide"' . $clicksuffix,
'label' => qa_lang_html('question/hide_button'),
'popup' => qa_lang_html('question/hide_a_popup'),
);
}
// Buttons for operating on this comment
if ($answer['reshowable']) {
$buttons['reshow'] = array(
'tags' => 'name="' . $prefix . 'doreshow"' . $clicksuffix,
'label' => qa_lang_html('question/reshow_button'),
'popup' => qa_lang_html('question/reshow_a_popup'),
);
}
if (!$formrequested) { // don't show if another form is currently being shown on page
$prefix='c'.qa_html($commentid).'_';
$clicksuffix=' onclick="return qa_comment_click('.qa_js($commentid).', '.qa_js($questionid).', '.qa_js($parent['postid']).', this);"';
if ($answer['deleteable']) {
$buttons['delete'] = array(
'tags' => 'name="' . $prefix . 'dodelete"' . $clicksuffix,
'label' => qa_lang_html('question/delete_button'),
'popup' => qa_lang_html('question/delete_a_popup'),
);
}
$buttons=array();
if ($answer['claimable']) {
$buttons['claim'] = array(
'tags' => 'name="' . $prefix . 'doclaim"' . $clicksuffix,
'label' => qa_lang_html('question/claim_button'),
'popup' => qa_lang_html('question/claim_a_popup'),
);
}
if ($comment['editbutton'])
$buttons['edit']=array(
'tags' => 'name="'.$prefix.'doedit"',
'label' => qa_lang_html('question/edit_button'),
'popup' => qa_lang_html('question/edit_c_popup'),
);
if ($answer['followable']) {
$buttons['follow'] = array(
'tags' => 'name="' . $prefix . 'dofollow"',
'label' => qa_lang_html('question/follow_button'),
'popup' => qa_lang_html('question/follow_a_popup'),
);
}
if ($comment['flagbutton'])
$buttons['flag']=array(
'tags' => 'name="'.$prefix.'doflag"'.$clicksuffix,
'label' => qa_lang_html($comment['flagtohide'] ? 'question/flag_hide_button' : 'question/flag_button'),
'popup' => qa_lang_html('question/flag_c_popup'),
);
if ($answer['commentbutton']) {
$buttons['comment'] = array(
'tags' => 'name="' . $prefix . 'docomment" onclick="return qa_toggle_element(\'c' . $answerid . '\')"',
'label' => qa_lang_html('question/comment_button'),
'popup' => qa_lang_html('question/comment_a_popup'),
);
}
if ($comment['unflaggable'])
$buttons['unflag']=array(
'tags' => 'name="'.$prefix.'dounflag"'.$clicksuffix,
'label' => qa_lang_html('question/unflag_button'),
'popup' => qa_lang_html('question/unflag_popup'),
);
$a_view['form'] = array(
'style' => 'light',
'buttons' => $buttons,
);
}
if ($comment['clearflaggable'])
$buttons['clearflags']=array(
'tags' => 'name="'.$prefix.'doclearflags"'.$clicksuffix,
'label' => qa_lang_html('question/clear_flags_button'),
'popup' => qa_lang_html('question/clear_flags_popup'),
);
return $a_view;
}
/**
* Returns an element to add to the appropriate $qa_content[...]['c_list']['cs'] array for $comment as viewed by the
* current user. Pass the comment's $parent post and antecedent $question. $usershtml should be an array which maps
* userids to HTML user representations, including the comments's author and (if present) last editor. If a form has
* been explicitly requested for the page, set $formrequested to true - this will hide the buttons.
* @param $question
* @param $parent
* @param $comment
* @param $usershtml
* @param $formrequested
* @return array
*/
function qa_page_q_comment_view($question, $parent, $comment, $usershtml, $formrequested)
{
$commentid = $comment['postid'];
$questionid = ($parent['basetype'] == 'Q') ? $parent['postid'] : $parent['parentid'];
$answerid = ($parent['basetype'] == 'Q') ? null : $parent['postid'];
$userid = qa_get_logged_in_userid();
$cookieid = qa_cookie_get();
$htmloptions = qa_post_html_options($comment, null, true);
$htmloptions['avatarsize'] = qa_opt('avatar_q_page_c_size');
$htmloptions['q_request'] = qa_q_request($question['postid'], $question['title']);
$c_view = qa_post_html_fields($comment, $userid, $cookieid, $usershtml, null, $htmloptions);
if ($comment['queued'])
$c_view['error'] = $comment['isbyuser'] ? qa_lang_html('question/c_your_waiting_approval') : qa_lang_html('question/c_waiting_your_approval');
// Buttons for operating on this comment
if (!$formrequested) { // don't show if another form is currently being shown on page
$prefix = 'c' . qa_html($commentid) . '_';
$clicksuffix = ' onclick="return qa_comment_click(' . qa_js($commentid) . ', ' . qa_js($questionid) . ', ' . qa_js($parent['postid']) . ', this);"';
$buttons = array();
if ($comment['editbutton']) {
$buttons['edit'] = array(
'tags' => 'name="' . $prefix . 'doedit"',
'label' => qa_lang_html('question/edit_button'),
'popup' => qa_lang_html('question/edit_c_popup'),
);
}
if ($comment['moderatable']) {
$buttons['approve']=array(
'tags' => 'name="'.$prefix.'doapprove"'.$clicksuffix,
'label' => qa_lang_html('question/approve_button'),
'popup' => qa_lang_html('question/approve_c_popup'),
);
if ($comment['flagbutton']) {
$buttons['flag'] = array(
'tags' => 'name="' . $prefix . 'doflag"' . $clicksuffix,
'label' => qa_lang_html($comment['flagtohide'] ? 'question/flag_hide_button' : 'question/flag_button'),
'popup' => qa_lang_html('question/flag_c_popup'),
);
}
$buttons['reject']=array(
'tags' => 'name="'.$prefix.'doreject"'.$clicksuffix,
'label' => qa_lang_html('question/reject_button'),
'popup' => qa_lang_html('question/reject_c_popup'),
);
}
if ($comment['unflaggable']) {
$buttons['unflag'] = array(
'tags' => 'name="' . $prefix . 'dounflag"' . $clicksuffix,
'label' => qa_lang_html('question/unflag_button'),
'popup' => qa_lang_html('question/unflag_popup'),
);
}
if ($comment['hideable'])
$buttons['hide']=array(
'tags' => 'name="'.$prefix.'dohide"'.$clicksuffix,
'label' => qa_lang_html('question/hide_button'),
'popup' => qa_lang_html('question/hide_c_popup'),
);
if ($comment['clearflaggable']) {
$buttons['clearflags'] = array(
'tags' => 'name="' . $prefix . 'doclearflags"' . $clicksuffix,
'label' => qa_lang_html('question/clear_flags_button'),
'popup' => qa_lang_html('question/clear_flags_popup'),
);
}
if ($comment['reshowable'])
$buttons['reshow']=array(
'tags' => 'name="'.$prefix.'doreshow"'.$clicksuffix,
'label' => qa_lang_html('question/reshow_button'),
'popup' => qa_lang_html('question/reshow_c_popup'),
);
if ($comment['moderatable']) {
$buttons['approve'] = array(
'tags' => 'name="' . $prefix . 'doapprove"' . $clicksuffix,
'label' => qa_lang_html('question/approve_button'),
'popup' => qa_lang_html('question/approve_c_popup'),
);
if ($comment['deleteable'])
$buttons['delete']=array(
'tags' => 'name="'.$prefix.'dodelete"'.$clicksuffix,
'label' => qa_lang_html('question/delete_button'),
'popup' => qa_lang_html('question/delete_c_popup'),
);
$buttons['reject'] = array(
'tags' => 'name="' . $prefix . 'doreject"' . $clicksuffix,
'label' => qa_lang_html('question/reject_button'),
'popup' => qa_lang_html('question/reject_c_popup'),
);
}
if ($comment['claimable'])
$buttons['claim']=array(
'tags' => 'name="'.$prefix.'doclaim"'.$clicksuffix,
'label' => qa_lang_html('question/claim_button'),
'popup' => qa_lang_html('question/claim_c_popup'),
);
if ($comment['hideable']) {
$buttons['hide'] = array(
'tags' => 'name="' . $prefix . 'dohide"' . $clicksuffix,
'label' => qa_lang_html('question/hide_button'),
'popup' => qa_lang_html('question/hide_c_popup'),
);
}
if ($parent['commentbutton'] && qa_opt('show_c_reply_buttons') && ($comment['type']=='C'))
$buttons['comment']=array(
'tags' => 'name="'.(($parent['basetype']=='Q') ? 'q' : ('a'.qa_html($parent['postid']))).
'_docomment" onclick="return qa_toggle_element(\'c'.qa_html($parent['postid']).'\')"',
'label' => qa_lang_html('question/reply_button'),
'popup' => qa_lang_html('question/reply_c_popup'),
);
if ($comment['reshowable']) {
$buttons['reshow'] = array(
'tags' => 'name="' . $prefix . 'doreshow"' . $clicksuffix,
'label' => qa_lang_html('question/reshow_button'),
'popup' => qa_lang_html('question/reshow_c_popup'),
);
}
$c_view['form']=array(
'style' => 'light',
'buttons' => $buttons,
if ($comment['deleteable']) {
$buttons['delete'] = array(
'tags' => 'name="' . $prefix . 'dodelete"' . $clicksuffix,
'label' => qa_lang_html('question/delete_button'),
'popup' => qa_lang_html('question/delete_c_popup'),
);
}
return $c_view;
}
if ($comment['claimable']) {
$buttons['claim'] = array(
'tags' => 'name="' . $prefix . 'doclaim"' . $clicksuffix,
'label' => qa_lang_html('question/claim_button'),
'popup' => qa_lang_html('question/claim_c_popup'),
);
}
if ($parent['commentbutton'] && qa_opt('show_c_reply_buttons') && $comment['type'] == 'C') {
$buttons['comment'] = array(
'tags' => 'name="' . (($parent['basetype'] == 'Q') ? 'q' : ('a' . qa_html($parent['postid']))) .
'_docomment" onclick="return qa_toggle_element(\'c' . qa_html($parent['postid']) . '\')"',
'label' => qa_lang_html('question/reply_button'),
'popup' => qa_lang_html('question/reply_c_popup'),
);
}
function qa_page_q_comment_follow_list($question, $parent, $commentsfollows, $alwaysfull, $usershtml, $formrequested, $formpostid)
/*
Return an array for $qa_content[...]['c_list'] to display all of the comments and follow-on questions in
$commentsfollows which belong to post $parent with antecedent $question, as viewed by the current user. If
$alwaysfull then all comments will be included, otherwise the list may be shortened with a 'show previous x
comments' link. $usershtml should be an array which maps userids to HTML user representations, including all
comments' and follow on questions' authors and (if present) last editors. If a form has been explicitly requested
for the page, set $formrequested to true and pass the postid of the post for the form in $formpostid - this will
hide the buttons and remove the $formpostid comment from the list.
*/
{
$parentid=$parent['postid'];
$userid=qa_get_logged_in_userid();
$cookieid=qa_cookie_get();
$commentlist=array(
'tags' => 'id="c'.qa_html($parentid).'_list"',
'cs' => array(),
$c_view['form'] = array(
'style' => 'light',
'buttons' => $buttons,
);
}
$showcomments=array();
// $commentsfollows contains ALL comments on the question and all answers, so here we filter the comments viewable for this context
foreach ($commentsfollows as $commentfollowid => $commentfollow) {
$showcomment = $commentfollow['parentid'] == $parentid && $commentfollow['viewable'] && $commentfollowid != $formpostid;
// show hidden follow-on questions only if the parent is hidden
if ($showcomment && $commentfollow['basetype'] == 'Q' && $commentfollow['hidden']) {
$showcomment = $parent['hidden'];
}
// show questions closed as duplicate of this one, only if this question is hidden
$showduplicate = $question['hidden'] && $commentfollow['closedbyid'] == $parentid;
if ($showcomment || $showduplicate) {
$showcomments[$commentfollowid] = $commentfollow;
}
return $c_view;
}
/**
* Return an array for $qa_content[...]['c_list'] to display all of the comments and follow-on questions in
* $commentsfollows which belong to post $parent with antecedent $question, as viewed by the current user. If
* $alwaysfull then all comments will be included, otherwise the list may be shortened with a 'show previous x
* comments' link. $usershtml should be an array which maps userids to HTML user representations, including all
* comments' and follow on questions' authors and (if present) last editors. If a form has been explicitly requested
* for the page, set $formrequested to true and pass the postid of the post for the form in $formpostid - this will
* hide the buttons and remove the $formpostid comment from the list.
* @param $question
* @param $parent
* @param $commentsfollows
* @param $alwaysfull
* @param $usershtml
* @param $formrequested
* @param $formpostid
* @return array
*/
function qa_page_q_comment_follow_list($question, $parent, $commentsfollows, $alwaysfull, $usershtml, $formrequested, $formpostid)
{
$parentid = $parent['postid'];
$userid = qa_get_logged_in_userid();
$cookieid = qa_cookie_get();
$commentlist = array(
'tags' => 'id="c' . qa_html($parentid) . '_list"',
'cs' => array(),
);
$showcomments = array();
// $commentsfollows contains ALL comments on the question and all answers, so here we filter the comments viewable for this context
foreach ($commentsfollows as $commentfollowid => $commentfollow) {
$showcomment = $commentfollow['parentid'] == $parentid && $commentfollow['viewable'] && $commentfollowid != $formpostid;
// show hidden follow-on questions only if the parent is hidden
if ($showcomment && $commentfollow['basetype'] == 'Q' && $commentfollow['hidden']) {
$showcomment = $parent['hidden'];
}
// show questions closed as duplicate of this one, only if this question is hidden
$showduplicate = $question['hidden'] && $commentfollow['closedbyid'] == $parentid;
$countshowcomments=count($showcomments);
if ( (!$alwaysfull) && ($countshowcomments > qa_opt('show_fewer_cs_from')) )
$skipfirst=$countshowcomments-qa_opt('show_fewer_cs_count');
else
$skipfirst=0;
if ($skipfirst==$countshowcomments) { // showing none
if ($skipfirst==1)
$expandtitle=qa_lang_html('question/show_1_comment');
else
$expandtitle=qa_lang_html_sub('question/show_x_comments', $skipfirst);
} else {
if ($skipfirst==1)
$expandtitle=qa_lang_html('question/show_1_previous_comment');
else
$expandtitle=qa_lang_html_sub('question/show_x_previous_comments', $skipfirst);
if ($showcomment || $showduplicate) {
$showcomments[$commentfollowid] = $commentfollow;
}
}
if ($skipfirst>0)
$commentlist['cs'][$parentid]=array(
'url' => qa_html('?state=showcomments-'.$parentid.'&show='.$parentid.'#'.urlencode(qa_anchor($parent['basetype'], $parentid))),
'expand_tags' => 'onclick="return qa_show_comments('.qa_js($question['postid']).', '.qa_js($parentid).', this);"',
'title' => $expandtitle,
);
$countshowcomments = count($showcomments);
foreach ($showcomments as $commentfollowid => $commentfollow)
if ($skipfirst>0)
$skipfirst--;
if (!$alwaysfull && $countshowcomments > qa_opt('show_fewer_cs_from'))
$skipfirst = $countshowcomments - qa_opt('show_fewer_cs_count');
else
$skipfirst = 0;
elseif ($commentfollow['basetype']=='C') {
$commentlist['cs'][$commentfollowid]=qa_page_q_comment_view($question, $parent, $commentfollow, $usershtml, $formrequested);
if ($skipfirst == $countshowcomments) { // showing none
if ($skipfirst == 1)
$expandtitle = qa_lang_html('question/show_1_comment');
else
$expandtitle = qa_lang_html_sub('question/show_x_comments', $skipfirst);
} elseif ($commentfollow['basetype']=='Q') {
$htmloptions=qa_post_html_options($commentfollow);
$htmloptions['avatarsize']=qa_opt('avatar_q_page_c_size');
} else {
if ($skipfirst == 1)
$expandtitle = qa_lang_html('question/show_1_previous_comment');
else
$expandtitle = qa_lang_html_sub('question/show_x_previous_comments', $skipfirst);
}
$commentlist['cs'][$commentfollowid]=qa_post_html_fields($commentfollow, $userid, $cookieid, $usershtml, null, $htmloptions);
}
if ($skipfirst > 0) {
$commentlist['cs'][$parentid] = array(
'url' => qa_html('?state=showcomments-' . $parentid . '&show=' . $parentid . '#' . urlencode(qa_anchor($parent['basetype'], $parentid))),
if (!count($commentlist['cs']))
$commentlist['hidden']=true;
'expand_tags' => 'onclick="return qa_show_comments(' . qa_js($question['postid']) . ', ' . qa_js($parentid) . ', this);"',
return $commentlist;
'title' => $expandtitle,
);
}
foreach ($showcomments as $commentfollowid => $commentfollow) {
if ($skipfirst > 0) {
$skipfirst--;
} elseif ($commentfollow['basetype'] == 'C') {
$commentlist['cs'][$commentfollowid] = qa_page_q_comment_view($question, $parent, $commentfollow, $usershtml, $formrequested);
function qa_page_q_add_a_form(&$qa_content, $formid, $captchareason, $question, $in, $errors, $loadnow, $formrequested)
/*
Return a $qa_content form for adding an answer to $question. Pass an HTML element id to use for the form in $formid
and the result of qa_user_captcha_reason() in $captchareason. Pass previous inputs from a submitted version of this
form in the array $in and resulting errors in $errors. If $loadnow is true, the form will be loaded immediately. Set
$formrequested to true if the user explicitly requested it, as opposed being shown automatically.
*/
{
// 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(...)
switch (qa_user_post_permit_error('permit_post_a', $question, QA_LIMIT_ANSWERS)) {
case 'login':
$form=array(
'title' => qa_insert_login_links(qa_lang_html('question/answer_must_login'), qa_request())
);
break;
} elseif ($commentfollow['basetype'] == 'Q') {
$htmloptions = qa_post_html_options($commentfollow);
$htmloptions['avatarsize'] = qa_opt('avatar_q_page_c_size');
case 'confirm':
$form=array(
'title' => qa_insert_login_links(qa_lang_html('question/answer_must_confirm'), qa_request())
);
break;
$commentlist['cs'][$commentfollowid] = qa_post_html_fields($commentfollow, $userid, $cookieid, $usershtml, null, $htmloptions);
}
}
case 'approve':
$form=array(
'title' => qa_lang_html('question/answer_must_be_approved')
);
break;
if (!count($commentlist['cs']))
$commentlist['hidden'] = true;
return $commentlist;
}
/**
* Return a $qa_content form for adding an answer to $question. Pass an HTML element id to use for the form in $formid
* and the result of qa_user_captcha_reason() in $captchareason. Pass previous inputs from a submitted version of this
* form in the array $in and resulting errors in $errors. If $loadnow is true, the form will be loaded immediately. Set
* $formrequested to true if the user explicitly requested it, as opposed being shown automatically.
* @param $qa_content
* @param $formid
* @param $captchareason
* @param $question
* @param $in
* @param $errors
* @param $loadnow
* @param $formrequested
* @return array
*/
function qa_page_q_add_a_form(&$qa_content, $formid, $captchareason, $question, $in, $errors, $loadnow, $formrequested)
{
// 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(...)
switch (qa_user_post_permit_error('permit_post_a', $question, QA_LIMIT_ANSWERS)) {
case 'login':
$form = array(
'title' => qa_insert_login_links(qa_lang_html('question/answer_must_login'), qa_request()),
);
break;
case 'limit':
$form=array(
'title' => qa_lang_html('question/answer_limit')
);
break;
case 'confirm':
$form = array(
'title' => qa_insert_login_links(qa_lang_html('question/answer_must_confirm'), qa_request()),
);
break;
default:
$form=array(
'title' => qa_lang_html('users/no_permission')
);
break;
case 'approve':
$form = array(
'title' => qa_lang_html('question/answer_must_be_approved'),
);
break;
case false:
$editorname=isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_as');
$editor=qa_load_editor(@$in['content'], @$in['format'], $editorname);
case 'limit':
$form = array(
'title' => qa_lang_html('question/answer_limit'),
);
break;
if (method_exists($editor, 'update_script'))
$updatescript=$editor->update_script('a_content');
else
$updatescript='';
default:
$form = array(
'title' => qa_lang_html('users/no_permission'),
);
break;
$custom=qa_opt('show_custom_answer') ? trim(qa_opt('custom_answer')) : '';
case false:
$editorname = isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_as');
$editor = qa_load_editor(@$in['content'], @$in['format'], $editorname);
$form=array(
'tags' => 'method="post" action="'.qa_self_html().'" name="a_form"',
if (method_exists($editor, 'update_script'))
$updatescript = $editor->update_script('a_content');
else
$updatescript = '';
'title' => qa_lang_html('question/your_answer_title'),
$custom = qa_opt('show_custom_answer') ? trim(qa_opt('custom_answer')) : '';
'fields' => array(
'custom' => array(
'type' => 'custom',
'note' => $custom,
),
$form = array(
'tags' => 'method="post" action="' . qa_self_html() . '" name="a_form"',
'content' => array_merge(
qa_editor_load_field($editor, $qa_content, @$in['content'], @$in['format'], 'a_content', 12, $formrequested, $loadnow),
array(
'error' => qa_html(@$errors['content']),
)
),
),
'title' => qa_lang_html('question/your_answer_title'),
'buttons' => array(
'answer' => array(
'tags' => 'onclick="'.$updatescript.' return qa_submit_answer('.qa_js($question['postid']).', this);"',
'label' => qa_lang_html('question/add_answer_button'),
),
'fields' => array(
'custom' => array(
'type' => 'custom',
'note' => $custom,
),
'hidden' => array(
'a_editor' => qa_html($editorname),
'a_doadd' => '1',
'code' => qa_get_form_security_code('answer-'.$question['postid']),
'content' => array_merge(
qa_editor_load_field($editor, $qa_content, @$in['content'], @$in['format'], 'a_content', 12, $formrequested, $loadnow),
array(
'error' => qa_html(@$errors['content']),
)
),
);
),
if (!strlen($custom))
unset($form['fields']['custom']);
'buttons' => array(
'answer' => array(
'tags' => 'onclick="' . $updatescript . ' return qa_submit_answer(' . qa_js($question['postid']) . ', this);"',
'label' => qa_lang_html('question/add_answer_button'),
),
),
if ($formrequested || !$loadnow)
$form['buttons']['cancel']=array(
'tags' => 'name="docancel"',
'label' => qa_lang_html('main/cancel_button'),
);
'hidden' => array(
'a_editor' => qa_html($editorname),
'a_doadd' => '1',
'code' => qa_get_form_security_code('answer-' . $question['postid']),
),
);
if (!qa_is_logged_in())
qa_set_up_name_field($qa_content, $form['fields'], @$in['name'], 'a_');
if (!strlen($custom))
unset($form['fields']['custom']);
qa_set_up_notify_fields($qa_content, $form['fields'], 'A', qa_get_logged_in_email(),
isset($in['notify']) ? $in['notify'] : qa_opt('notify_users_default'), @$in['email'], @$errors['email'], 'a_');
if ($formrequested || !$loadnow)
$form['buttons']['cancel'] = array(
'tags' => 'name="docancel"',
'label' => qa_lang_html('main/cancel_button'),
);
$onloads=array();
if (!qa_is_logged_in())
qa_set_up_name_field($qa_content, $form['fields'], @$in['name'], 'a_');
if ($captchareason) {
$captchaloadscript=qa_set_up_captcha_field($qa_content, $form['fields'], $errors, qa_captcha_reason_note($captchareason));
qa_set_up_notify_fields($qa_content, $form['fields'], 'A', qa_get_logged_in_email(),
isset($in['notify']) ? $in['notify'] : qa_opt('notify_users_default'), @$in['email'], @$errors['email'], 'a_');
if (strlen($captchaloadscript))
$onloads[]='document.getElementById('.qa_js($formid).').qa_show=function() { '.$captchaloadscript.' };';
}
$onloads = array();
if (!$loadnow) {
if (method_exists($editor, 'load_script'))
$onloads[]='document.getElementById('.qa_js($formid).').qa_load=function() { '.$editor->load_script('a_content').' };';
if ($captchareason) {
$captchaloadscript = qa_set_up_captcha_field($qa_content, $form['fields'], $errors, qa_captcha_reason_note($captchareason));
$form['buttons']['cancel']['tags'].=' onclick="return qa_toggle_element();"';
}
if (strlen($captchaloadscript))
$onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_show=function() { ' . $captchaloadscript . ' };';
}
if (!$formrequested) {
if (method_exists($editor, 'focus_script'))
$onloads[]='document.getElementById('.qa_js($formid).').qa_focus=function() { '.$editor->focus_script('a_content').' };';
}
if (!$loadnow) {
if (method_exists($editor, 'load_script'))
$onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_load=function() { ' . $editor->load_script('a_content') . ' };';
if (count($onloads))
$qa_content['script_onloads'][]=$onloads;
break;
}
$form['buttons']['cancel']['tags'] .= ' onclick="return qa_toggle_element();"';
}
$form['id']=$formid;
$form['collapse']=!$loadnow;
$form['style']='tall';
if (!$formrequested) {
if (method_exists($editor, 'focus_script'))
$onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_focus=function() { ' . $editor->focus_script('a_content') . ' };';
}
return $form;
if (count($onloads))
$qa_content['script_onloads'][] = $onloads;
break;
}
$form['id'] = $formid;
$form['collapse'] = !$loadnow;
$form['style'] = 'tall';
return $form;
}
/**
* Returns a $qa_content form for adding a comment to post $parent which is part of $question. Pass an HTML element id
* to use for the form in $formid and the result of qa_user_captcha_reason() in $captchareason. Pass previous inputs
* from a submitted version of this form in the array $in and resulting errors in $errors. If $loadfocusnow is true,
* the form will be loaded and focused immediately.
* @param $qa_content
* @param $question
* @param $parent
* @param $formid
* @param $captchareason
* @param $in
* @param $errors
* @param $loadfocusnow
* @return array
*/
function qa_page_q_add_c_form(&$qa_content, $question, $parent, $formid, $captchareason, $in, $errors, $loadfocusnow)
{
// 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(...)
switch (qa_user_post_permit_error('permit_post_c', $parent, QA_LIMIT_COMMENTS)) {
case 'login':
$form = array(
'title' => qa_insert_login_links(qa_lang_html('question/comment_must_login'), qa_request()),
);
break;
function qa_page_q_add_c_form(&$qa_content, $question, $parent, $formid, $captchareason, $in, $errors, $loadfocusnow)
/*
Returns a $qa_content form for adding a comment to post $parent which is part of $question. Pass an HTML element id
to use for the form in $formid and the result of qa_user_captcha_reason() in $captchareason. Pass previous inputs
from a submitted version of this form in the array $in and resulting errors in $errors. If $loadfocusnow is true,
the form will be loaded and focused immediately.
*/
{
// 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(...)
switch (qa_user_post_permit_error('permit_post_c', $parent, QA_LIMIT_COMMENTS)) {
case 'login':
$form=array(
'title' => qa_insert_login_links(qa_lang_html('question/comment_must_login'), qa_request())
);
break;
case 'confirm':
$form=array(
'title' => qa_insert_login_links(qa_lang_html('question/comment_must_confirm'), qa_request())
);
break;
case 'approve':
$form=array(
'title' => qa_lang_html('question/comment_must_be_approved')
);
break;
case 'confirm':
$form = array(
'title' => qa_insert_login_links(qa_lang_html('question/comment_must_confirm'), qa_request()),
);
break;
case 'limit':
$form=array(
'title' => qa_lang_html('question/comment_limit')
);
break;
case 'approve':
$form = array(
'title' => qa_lang_html('question/comment_must_be_approved'),
);
break;
default:
$form=array(
'title' => qa_lang_html('users/no_permission')
);
break;
case 'limit':
$form = array(
'title' => qa_lang_html('question/comment_limit'),
);
break;
case false:
$prefix='c'.$parent['postid'].'_';
default:
$form = array(
'title' => qa_lang_html('users/no_permission'),
);
break;
$editorname=isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_cs');
$editor=qa_load_editor(@$in['content'], @$in['format'], $editorname);
case false:
$prefix = 'c' . $parent['postid'] . '_';
if (method_exists($editor, 'update_script'))
$updatescript=$editor->update_script($prefix.'content');
else
$updatescript='';
$editorname = isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_cs');
$editor = qa_load_editor(@$in['content'], @$in['format'], $editorname);
$custom=qa_opt('show_custom_comment') ? trim(qa_opt('custom_comment')) : '';
if (method_exists($editor, 'update_script'))
$updatescript = $editor->update_script($prefix . 'content');
else
$updatescript = '';
$form=array(
'tags' => 'method="post" action="'.qa_self_html().'" name="c_form_'.qa_html($parent['postid']).'"',
$custom = qa_opt('show_custom_comment') ? trim(qa_opt('custom_comment')) : '';
'title' => qa_lang_html(($question['postid']==$parent['postid']) ? 'question/your_comment_q' : 'question/your_comment_a'),
$form = array(
'tags' => 'method="post" action="' . qa_self_html() . '" name="c_form_' . qa_html($parent['postid']) . '"',
'fields' => array(
'custom' => array(
'type' => 'custom',
'note' => $custom,
),
'title' => qa_lang_html(($question['postid'] == $parent['postid']) ? 'question/your_comment_q' : 'question/your_comment_a'),
'content' => array_merge(
qa_editor_load_field($editor, $qa_content, @$in['content'], @$in['format'], $prefix.'content', 4, $loadfocusnow, $loadfocusnow),
array(
'error' => qa_html(@$errors['content']),
)
),
'fields' => array(
'custom' => array(
'type' => 'custom',
'note' => $custom,
),
'buttons' => array(
'comment' => array(
'tags' => 'onclick="'.$updatescript.' return qa_submit_comment('.qa_js($question['postid']).', '.qa_js($parent['postid']).', this);"',
'label' => qa_lang_html('question/add_comment_button'),
),
'cancel' => array(
'tags' => 'name="docancel"',
'label' => qa_lang_html('main/cancel_button'),
),
'content' => array_merge(
qa_editor_load_field($editor, $qa_content, @$in['content'], @$in['format'], $prefix . 'content', 4, $loadfocusnow, $loadfocusnow),
array(
'error' => qa_html(@$errors['content']),
)
),
),
'hidden' => array(
$prefix.'editor' => qa_html($editorname),
$prefix.'doadd' => '1',
$prefix.'code' => qa_get_form_security_code('comment-'.$parent['postid']),
'buttons' => array(
'comment' => array(
'tags' => 'onclick="' . $updatescript . ' return qa_submit_comment(' . qa_js($question['postid']) . ', ' . qa_js($parent['postid']) . ', this);"',
'label' => qa_lang_html('question/add_comment_button'),
),
);
if (!strlen($custom))
unset($form['fields']['custom']);
'cancel' => array(
'tags' => 'name="docancel"',
'label' => qa_lang_html('main/cancel_button'),
),
),
if (!qa_is_logged_in())
qa_set_up_name_field($qa_content, $form['fields'], @$in['name'], $prefix);
'hidden' => array(
$prefix . 'editor' => qa_html($editorname),
$prefix . 'doadd' => '1',
$prefix . 'code' => qa_get_form_security_code('comment-' . $parent['postid']),
),
);
qa_set_up_notify_fields($qa_content, $form['fields'], 'C', qa_get_logged_in_email(),
isset($in['notify']) ? $in['notify'] : qa_opt('notify_users_default'), $in['email'], @$errors['email'], $prefix);
if (!strlen($custom))
unset($form['fields']['custom']);
$onloads=array();
if (!qa_is_logged_in())
qa_set_up_name_field($qa_content, $form['fields'], @$in['name'], $prefix);
if ($captchareason) {
$captchaloadscript=qa_set_up_captcha_field($qa_content, $form['fields'], $errors, qa_captcha_reason_note($captchareason));
qa_set_up_notify_fields($qa_content, $form['fields'], 'C', qa_get_logged_in_email(),
isset($in['notify']) ? $in['notify'] : qa_opt('notify_users_default'), $in['email'], @$errors['email'], $prefix);
if (strlen($captchaloadscript))
$onloads[]='document.getElementById('.qa_js($formid).').qa_show=function() { '.$captchaloadscript.' };';
}
$onloads = array();
if (!$loadfocusnow) {
if (method_exists($editor, 'load_script'))
$onloads[]='document.getElementById('.qa_js($formid).').qa_load=function() { '.$editor->load_script($prefix.'content').' };';
if (method_exists($editor, 'focus_script'))
$onloads[]='document.getElementById('.qa_js($formid).').qa_focus=function() { '.$editor->focus_script($prefix.'content').' };';
if ($captchareason) {
$captchaloadscript = qa_set_up_captcha_field($qa_content, $form['fields'], $errors, qa_captcha_reason_note($captchareason));
$form['buttons']['cancel']['tags'].=' onclick="return qa_toggle_element()"';
}
if (strlen($captchaloadscript))
$onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_show=function() { ' . $captchaloadscript . ' };';
}
if (count($onloads))
$qa_content['script_onloads'][]=$onloads;
}
if (!$loadfocusnow) {
if (method_exists($editor, 'load_script'))
$onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_load=function() { ' . $editor->load_script($prefix . 'content') . ' };';
if (method_exists($editor, 'focus_script'))
$onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_focus=function() { ' . $editor->focus_script($prefix . 'content') . ' };';
$form['id']=$formid;
$form['collapse']=!$loadfocusnow;
$form['style']='tall';
$form['buttons']['cancel']['tags'] .= ' onclick="return qa_toggle_element()"';
}
return $form;
if (count($onloads))
$qa_content['script_onloads'][] = $onloads;
}
$form['id'] = $formid;
$form['collapse'] = !$loadfocusnow;
$form['style'] = 'tall';
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
return $form;
}
......@@ -1001,13 +1001,13 @@ function qa_sanitize_html_hook_tag($element, $attributes = null)
if (!isset($attributes)) // it's a closing tag
return '</' . $element . '>';
if (($element == 'param') && (trim(strtolower(@$attributes['name'])) == 'allowscriptaccess'))
if ($element == 'param' && trim(strtolower(@$attributes['name'])) == 'allowscriptaccess')
$attributes['name'] = 'allowscriptaccess_denied';
if ($element == 'embed')
unset($attributes['allowscriptaccess']);
if (($element == 'a') && isset($attributes['href']) && $qa_sanitize_html_newwindow)
if ($element == 'a' && isset($attributes['href']) && $qa_sanitize_html_newwindow)
$attributes['target'] = '_blank';
$html = '<' . $element;
......@@ -1639,7 +1639,7 @@ function qa_q_path($questionid, $title, $absolute = false, $showtype = null, $sh
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
if ((($showtype == 'Q') || ($showtype == 'A') || ($showtype == 'C')) && isset($showid)) {
if (($showtype == 'Q' || $showtype == 'A' || $showtype == 'C') && isset($showid)) {
$params = array('show' => $showid); // due to pagination
$anchor = qa_anchor($showtype, $showid);
......@@ -1772,7 +1772,7 @@ function qa_retrieve_url($url)
$contents = @file_get_contents($url);
if ((!strlen($contents)) && function_exists('curl_exec')) { // try curl as a backup (if allow_url_fopen not set)
if (!strlen($contents) && function_exists('curl_exec')) { // try curl as a backup (if allow_url_fopen not set)
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
......@@ -1794,7 +1794,7 @@ function qa_opt($name, $value = null)
{
global $qa_options_cache;
if ((!isset($value)) && isset($qa_options_cache[$name]))
if (!isset($value) && isset($qa_options_cache[$name]))
return $qa_options_cache[$name]; // quick shortcut to reduce calls to qa_get_options()
require_once QA_INCLUDE_DIR . 'app/options.php';
......
......@@ -35,6 +35,10 @@ qa_report_process_stage('init_install');
if (!function_exists('qa_install_db_fail_handler')) {
/**
* Handler function for database failures during the installation process
* @param $type
* @param int $errno
* @param string $error
* @param string $query
*/
function qa_install_db_fail_handler($type, $errno=null, $error=null, $query=null)
{
......
......@@ -610,6 +610,8 @@ class qa_html_theme extends qa_html_theme_base
*
* @since Snow 1.4
* @version 1.0
* @param string $addon_class
* @param string $ids
*/
private function qam_search($addon_class = null, $ids = null)
{
......
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