Commit f3363623 by Scott

Merge pull request #252 from pupi1985/patch-61

Some minor changes in core plugins
parents 4ab2d6e1 349d03ab
......@@ -66,6 +66,7 @@
$a_view=qa_page_q_answer_view($question, $answer, false, $usershtml, false);
$themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-answer', null, null);
$themeclass->initialize();
echo "QA_AJAX_RESPONSE\n1\n";
......
......@@ -95,6 +95,7 @@
}
$themeclass = qa_load_theme_class(qa_get_site_theme(), 'ajax-asktitle', null, null);
$themeclass->initialize();
$themeclass->q_ask_similar($limitedquestions, qa_lang_html('question/ask_same_q'));
}
......
......@@ -93,6 +93,7 @@
$a_view['c_list']=qa_page_q_comment_follow_list($question, $answer, $achildposts, false, $usershtml, false, null);
$themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-answer', null, null);
$themeclass->initialize();
// ... send back the HTML for it
......
......@@ -74,6 +74,7 @@
$c_view=qa_page_q_comment_view($question, $parent, $comment, $usershtml, false);
$themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-comment', null, null);
$themeclass->initialize();
// ... send back the HTML for it
......
......@@ -78,6 +78,7 @@
$c_list=qa_page_q_comment_follow_list($question, $parent, $children, true, $usershtml, false, null);
$themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-comments', null, null);
$themeclass->initialize();
echo "QA_AJAX_RESPONSE\n1\n";
......
......@@ -43,6 +43,7 @@
$favoriteform=qa_favorite_form($entitytype, $entityid, $setfavorite, qa_lang($setfavorite ? 'main/remove_favorites' : 'main/add_favorites'));
$themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-favorite', null, null);
$themeclass->initialize();
echo "QA_AJAX_RESPONSE\n1\n";
......
......@@ -54,6 +54,7 @@
$c_list=qa_page_q_comment_follow_list($question, $parent, $children, true, $usershtml, false, null);
$themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-comments', null, null);
$themeclass->initialize();
echo "QA_AJAX_RESPONSE\n1\n";
......
......@@ -53,6 +53,7 @@
));
$themeclass=qa_load_theme_class(qa_get_site_theme(), 'voting', null, null);
$themeclass->initialize();
echo "QA_AJAX_RESPONSE\n1\n";
$themeclass->voting_inner_html($fields);
......
......@@ -47,6 +47,7 @@
$usermessages=qa_wall_posts_add_rules($usermessages, 0);
$themeclass=qa_load_theme_class(qa_get_site_theme(), 'wall', null, null);
$themeclass->initialize();
echo "QA_AJAX_RESPONSE\n1\n";
......
......@@ -28,10 +28,10 @@ class qa_editor_basic
public function calc_quality($content, $format)
{
if ($format=='')
if ($format == '')
return 1.0;
if ($format=='html')
if ($format == 'html')
return 0.2;
return 0;
......@@ -41,7 +41,7 @@ class qa_editor_basic
{
return array(
'type' => 'textarea',
'tags' => 'name="'.$fieldname.'" id="'.$fieldname.'"',
'tags' => 'name="' . $fieldname . '" id="' . $fieldname . '"',
'value' => qa_html($content),
'rows' => $rows,
);
......@@ -49,7 +49,7 @@ class qa_editor_basic
public function focus_script($fieldname)
{
return "document.getElementById('".$fieldname."').focus();";
return "document.getElementById('" . $fieldname . "').focus();";
}
public function read_post($fieldname)
......
......@@ -89,12 +89,12 @@ class qa_event_limits
is_numeric(array_search($event, $writeactions))
) {
if (isset($userid)) {
require_once QA_INCLUDE_DIR.'app/users.php';
require_once QA_INCLUDE_DIR . 'app/users.php';
qa_user_report_action($userid, $event);
} elseif (isset($cookieid)) {
require_once QA_INCLUDE_DIR.'app/cookies.php';
require_once QA_INCLUDE_DIR . 'app/cookies.php';
qa_cookie_report_action($cookieid, $event);
}
......
......@@ -22,8 +22,8 @@
class qa_html_theme_layer extends qa_html_theme_base
{
private $qa_voters_flaggers_queue=array();
private $qa_voters_flaggers_cache=array();
private $qa_voters_flaggers_queue = array();
private $qa_voters_flaggers_cache = array();
// Collect up all required postids for the entire page to save DB queries - common case where whole page output
......@@ -31,24 +31,27 @@ class qa_html_theme_layer extends qa_html_theme_base
public function main()
{
foreach ($this->content as $key => $part) {
if (strpos($key, 'q_list')===0)
$this->queue_raw_posts_voters_flaggers(@$part['qs']);
if (strpos($key, 'q_list') === 0) {
if (isset($part['qs']))
$this->queue_raw_posts_voters_flaggers($part['qs']);
elseif (strpos($key, 'q_view')===0) {
} elseif (strpos($key, 'q_view') === 0) {
$this->queue_post_voters_flaggers($part['raw']);
$this->queue_raw_posts_voters_flaggers($part['c_list']['cs']);
} elseif (strpos($key, 'a_list')===0) {
} elseif (strpos($key, 'a_list') === 0) {
if (!empty($part)) {
$this->queue_raw_posts_voters_flaggers($part['as']);
foreach ($part['as'] as $a_item)
$this->queue_raw_posts_voters_flaggers(@$a_item['c_list']['cs']);
foreach ($part['as'] as $a_item) {
if (isset($a_item['c_list']['cs']))
$this->queue_raw_posts_voters_flaggers($a_item['c_list']['cs']);
}
}
}
}
qa_html_theme_base::main();
parent::main();
}
......@@ -58,21 +61,21 @@ class qa_html_theme_layer extends qa_html_theme_base
{
$this->queue_raw_posts_voters_flaggers($q_items);
qa_html_theme_base::q_list_items($q_items);
parent::q_list_items($q_items);
}
public function a_list_items($a_items)
{
$this->queue_raw_posts_voters_flaggers($a_items);
qa_html_theme_base::a_list_items($a_items);
parent::a_list_items($a_items);
}
public function c_list_items($c_items)
{
$this->queue_raw_posts_voters_flaggers($c_items);
qa_html_theme_base::c_list_items($c_items);
parent::c_list_items($c_items);
}
......@@ -80,55 +83,60 @@ class qa_html_theme_layer extends qa_html_theme_base
public function vote_count($post)
{
$votersflaggers=$this->get_post_voters_flaggers($post['raw'], @$post['vote_opostid'] ? $post['raw']['opostid'] : $post['raw']['postid']);
$tooltip='';
$postid = isset($post['vote_opostid']) && $post['vote_opostid'] ? $post['raw']['opostid'] : $post['raw']['postid'];
$votersflaggers = $this->get_post_voters_flaggers($post['raw'], $postid);
if (isset($votersflaggers)) {
$uphandles='';
$downhandles='';
$uphandles = array();
$downhandles = array();
foreach ($votersflaggers as $voterflagger) {
if ($voterflagger['vote']>0)
$uphandles.=(strlen($uphandles) ? ', ' : '').qa_html($voterflagger['handle']);
if ($voterflagger['vote'] != 0) {
$newflagger = qa_html($voterflagger['handle']);
if ($voterflagger['vote'] > 0)
$uphandles[] = $newflagger;
else // if ($voterflagger['vote'] < 0)
$downhandles[] = $newflagger;
}
}
if ($voterflagger['vote']<0)
$downhandles.=(strlen($downhandles) ? ', ' : '').qa_html($voterflagger['handle']);
$tooltip = trim(
(empty($uphandles) ? '' : '&uarr; ' . implode(', ', $uphandles)) . "\n\n" .
(empty($downhandles) ? '' : '&darr; ' . implode(', ', $downhandles))
);
$tooltip=trim((strlen($uphandles) ? ('&uarr; '.$uphandles) : '')."\n\n".(strlen($downhandles) ? ('&darr; '.$downhandles) : ''));
}
$post['vote_count_tags'] = sprintf('%s title="%s"', isset($post['vote_count_tags']) ? $post['vote_count_tags'] : '', $tooltip);
}
$post['vote_count_tags']=@$post['vote_count_tags'].' title="'.$tooltip.'"';
qa_html_theme_base::vote_count($post);
parent::vote_count($post);
}
public function post_meta_flags($post, $class)
{
$postid=@$post['raw']['opostid'];
if (!isset($postid))
$postid=@$post['raw']['postid'];
if (isset($post['raw']['opostid']))
$postid = $post['raw']['opostid'];
elseif (isset($post['raw']['postid']))
$postid = $post['raw']['postid'];
$tooltip='';
$flaggers = array();
if (isset($postid)) {
$votersflaggers=$this->get_post_voters_flaggers($post, $postid);
$votersflaggers = $this->get_post_voters_flaggers($post, $postid);
if (isset($votersflaggers)) {
foreach ($votersflaggers as $voterflagger) {
if ($voterflagger['flag']>0)
$tooltip.=(strlen($tooltip) ? ', ' : '').qa_html($voterflagger['handle']);
if ($voterflagger['flag'] > 0)
$flaggers[] = qa_html($voterflagger['handle']);
}
}
}
if (strlen($tooltip))
$this->output('<span title="&#9873; '.$tooltip.'">');
if (!empty($flaggers))
$this->output('<span title="&#9873; ' . implode(', ', $flaggers) . '">');
qa_html_theme_base::post_meta_flags($post, $class);
parent::post_meta_flags($post, $class);
if (strlen($tooltip))
if (!empty($flaggers))
$this->output('</span>');
}
......@@ -142,11 +150,10 @@ class qa_html_theme_layer extends qa_html_theme_base
public function queue_post_voters_flaggers($post)
{
if (!qa_user_post_permit_error('permit_view_voters_flaggers', $post)) {
$postids=array(@$post['postid'], @$post['opostid']); // opostid can be relevant for flags
foreach ($postids as $postid) {
if (isset($postid) && !isset($this->qa_voters_flaggers_cache[$postid]))
$this->qa_voters_flaggers_queue[$postid]=true;
$postkeys = array('postid', 'opostid');
foreach ($postkeys as $key) {
if (isset($post[$key]) && !isset($this->qa_voters_flaggers_cache[$post[$key]]))
$this->qa_voters_flaggers_queue[$post[$key]] = true;
}
}
}
......@@ -172,29 +179,29 @@ class qa_html_theme_layer extends qa_html_theme_base
public function retrieve_queued_voters_flaggers()
{
if (count($this->qa_voters_flaggers_queue)) {
require_once QA_INCLUDE_DIR.'db/votes.php';
require_once QA_INCLUDE_DIR . 'db/votes.php';
$postids=array_keys($this->qa_voters_flaggers_queue);
$postids = array_keys($this->qa_voters_flaggers_queue);
foreach ($postids as $postid)
$this->qa_voters_flaggers_cache[$postid]=array();
$this->qa_voters_flaggers_cache[$postid] = array();
$newvotersflaggers=qa_db_uservoteflag_posts_get($postids);
$newvotersflaggers = qa_db_uservoteflag_posts_get($postids);
if (QA_FINAL_EXTERNAL_USERS) {
$keyuserids=array();
$keyuserids = array();
foreach ($newvotersflaggers as $voterflagger)
$keyuserids[$voterflagger['userid']]=true;
$keyuserids[$voterflagger['userid']] = true;
$useridhandles=qa_get_public_from_userids(array_keys($keyuserids));
$useridhandles = qa_get_public_from_userids(array_keys($keyuserids));
foreach ($newvotersflaggers as $index => $voterflagger)
$newvotersflaggers[$index]['handle']=@$useridhandles[$voterflagger['userid']];
$newvotersflaggers[$index]['handle'] = isset($useridhandles[$voterflagger['userid']]) ? $useridhandles[$voterflagger['userid']] : null;
}
foreach ($newvotersflaggers as $voterflagger)
$this->qa_voters_flaggers_cache[$voterflagger['postid']][]=$voterflagger;
$this->qa_voters_flaggers_cache[$voterflagger['postid']][] = $voterflagger;
$this->qa_voters_flaggers_queue=array();
$this->qa_voters_flaggers_queue = array();
}
}
......@@ -204,14 +211,14 @@ class qa_html_theme_layer extends qa_html_theme_base
*/
public function get_post_voters_flaggers($post, $postid)
{
require_once QA_INCLUDE_DIR.'util/sort.php';
require_once QA_INCLUDE_DIR . 'util/sort.php';
if (!isset($this->qa_voters_flaggers_cache[$postid])) {
$this->queue_post_voters_flaggers($post);
$this->retrieve_queued_voters_flaggers();
}
$votersflaggers=@$this->qa_voters_flaggers_cache[$postid];
$votersflaggers = isset($this->qa_voters_flaggers_cache[$postid]) ? $this->qa_voters_flaggers_cache[$postid] : null;
if (isset($votersflaggers))
qa_sort_by($votersflaggers, 'handle');
......
......@@ -24,37 +24,38 @@ class qa_related_qs
{
public function allow_template($template)
{
return ($template=='question');
return $template == 'question';
}
public function allow_region($region)
{
return ($region=='side') || ($region=='main') || ($region=='full');
return in_array($region, array('side', 'main', 'full'));
}
public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
{
require_once QA_INCLUDE_DIR.'db/selects.php';
if (@$qa_content['q_view']['raw']['type']!='Q') // question might not be visible, etc...
if (!isset($qa_content['q_view']['raw']['type']) || $qa_content['q_view']['raw']['type'] != 'Q') // question might not be visible, etc...
return;
$questionid=$qa_content['q_view']['raw']['postid'];
$questionid = $qa_content['q_view']['raw']['postid'];
$userid=qa_get_logged_in_userid();
$cookieid=qa_cookie_get();
$userid = qa_get_logged_in_userid();
$cookieid = qa_cookie_get();
$questions=qa_db_single_select(qa_db_related_qs_selectspec($userid, $questionid, qa_opt('page_size_related_qs')));
$questions = qa_db_single_select(qa_db_related_qs_selectspec($userid, $questionid, qa_opt('page_size_related_qs')));
$minscore=qa_match_to_min_score(qa_opt('match_related_qs'));
$minscore = qa_match_to_min_score(qa_opt('match_related_qs'));
foreach ($questions as $key => $question)
if ($question['score']<$minscore)
foreach ($questions as $key => $question) {
if ($question['score'] < $minscore)
unset($questions[$key]);
}
$titlehtml=qa_lang_html(count($questions) ? 'main/related_qs_title' : 'main/no_related_qs_title');
$titlehtml = qa_lang_html(count($questions) ? 'main/related_qs_title' : 'main/no_related_qs_title');
if ($region=='side') {
if ($region == 'side') {
$themeobject->output(
'<div class="qa-related-qs">',
'<h2 style="margin-top:0; padding-top:0;">',
......@@ -64,14 +65,20 @@ class qa_related_qs
$themeobject->output('<ul class="qa-related-q-list">');
foreach ($questions as $question)
$themeobject->output('<li class="qa-related-q-item"><a href="'.qa_q_path_html($question['postid'], $question['title']).'">'.qa_html($question['title']).'</a></li>');
foreach ($questions as $question) {
$themeobject->output(
'<li class="qa-related-q-item">' .
'<a href="' . qa_q_path_html($question['postid'], $question['title']) . '">' .
qa_html($question['title']) .
'</a>' .
'</li>'
);
}
$themeobject->output(
'</ul>',
'</div>'
);
} else {
$themeobject->output(
'<h2>',
......@@ -79,23 +86,21 @@ class qa_related_qs
'</h2>'
);
$q_list=array(
$q_list = array(
'form' => array(
'tags' => 'method="post" action="'.qa_self_html().'"',
'tags' => 'method="post" action="' . qa_self_html() . '"',
'hidden' => array(
'code' => qa_get_form_security_code('vote'),
),
),
'qs' => array(),
);
$defaults=qa_post_html_defaults('Q');
$usershtml=qa_userids_handles_html($questions);
$defaults = qa_post_html_defaults('Q');
$usershtml = qa_userids_handles_html($questions);
foreach ($questions as $question)
$q_list['qs'][]=qa_post_html_fields($question, $userid, $cookieid, $usershtml, null, qa_post_html_options($question, $defaults));
$q_list['qs'][] = qa_post_html_fields($question, $userid, $cookieid, $usershtml, null, qa_post_html_options($question, $defaults));
$themeobject->q_list_and_form($q_list);
}
......
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