Commit 4a51a213 by Scott

Coding style (core plugins)

parent 7ebb9fa6
...@@ -20,58 +20,43 @@ ...@@ -20,58 +20,43 @@
More about this license: http://www.question2answer.org/license.php 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 class qa_editor_basic
header('Location: ../'); {
exit; public function load_module($localdir, $htmldir)
{
} }
public function calc_quality($content, $format)
{
if ($format=='')
return 1.0;
class qa_editor_basic { if ($format=='html')
return 0.2;
public function load_module($localdir, $htmldir) return 0;
{ }
}
public function calc_quality($content, $format)
{
if ($format=='')
return 1.0;
if ($format=='html')
return 0.2;
return 0;
}
public function get_field(&$qa_content, $content, $format, $fieldname, $rows /* $autofocus parameter deprecated */)
{
return array(
'type' => 'textarea',
'tags' => 'name="'.$fieldname.'" id="'.$fieldname.'"',
'value' => qa_html($content),
'rows' => $rows,
);
}
public function focus_script($fieldname)
{
return "document.getElementById('".$fieldname."').focus();";
}
public function read_post($fieldname)
{
return array(
'format' => '',
'content' => qa_post_text($fieldname),
);
}
public function get_field(&$qa_content, $content, $format, $fieldname, $rows /* $autofocus parameter deprecated */)
{
return array(
'type' => 'textarea',
'tags' => 'name="'.$fieldname.'" id="'.$fieldname.'"',
'value' => qa_html($content),
'rows' => $rows,
);
} }
public function focus_script($fieldname)
{
return "document.getElementById('".$fieldname."').focus();";
}
/* public function read_post($fieldname)
Omit PHP closing tag to help avoid accidental output {
*/ return array(
\ No newline at end of file 'format' => '',
'content' => qa_post_text($fieldname),
);
}
}
...@@ -20,97 +20,84 @@ ...@@ -20,97 +20,84 @@
More about this license: http://www.question2answer.org/license.php 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 class qa_event_limits
header('Location: ../'); {
exit; public function process_event($event, $userid, $handle, $cookieid, $params)
} {
// Don't increment limits or report user actions for events that were delayed. For example, a 'q_post'
// event sent when a post is approved by the admin, for which a 'q_queue' event was already sent.
class qa_event_limits {
if (isset($params['delayed']))
public function process_event($event, $userid, $handle, $cookieid, $params) return;
{
// Don't increment limits or report user actions for events that were delayed. For example, a 'q_post' require_once QA_INCLUDE_DIR.'app/limits.php';
// event sent when a post is approved by the admin, for which a 'q_queue' event was already sent.
switch ($event) {
if (isset($params['delayed'])) case 'q_queue':
return; case 'q_post':
case 'q_claim':
require_once QA_INCLUDE_DIR.'app/limits.php'; qa_limits_increment($userid, QA_LIMIT_QUESTIONS);
break;
switch ($event) {
case 'q_queue': case 'a_queue':
case 'q_post': case 'a_post':
case 'q_claim': case 'a_claim':
qa_limits_increment($userid, QA_LIMIT_QUESTIONS); qa_limits_increment($userid, QA_LIMIT_ANSWERS);
break; break;
case 'a_queue': case 'c_queue':
case 'a_post': case 'c_post':
case 'a_claim': case 'c_claim':
qa_limits_increment($userid, QA_LIMIT_ANSWERS); case 'a_to_c':
break; qa_limits_increment($userid, QA_LIMIT_COMMENTS);
break;
case 'c_queue':
case 'c_post': case 'q_vote_up':
case 'c_claim': case 'q_vote_down':
case 'a_to_c': case 'q_vote_nil':
qa_limits_increment($userid, QA_LIMIT_COMMENTS); case 'a_vote_up':
break; case 'a_vote_down':
case 'a_vote_nil':
case 'q_vote_up': qa_limits_increment($userid, QA_LIMIT_VOTES);
case 'q_vote_down': break;
case 'q_vote_nil':
case 'a_vote_up': case 'q_flag':
case 'a_vote_down': case 'a_flag':
case 'a_vote_nil': case 'c_flag':
qa_limits_increment($userid, QA_LIMIT_VOTES); qa_limits_increment($userid, QA_LIMIT_FLAGS);
break; break;
case 'q_flag': case 'u_message':
case 'a_flag': qa_limits_increment($userid, QA_LIMIT_MESSAGES);
case 'c_flag': break;
qa_limits_increment($userid, QA_LIMIT_FLAGS);
break; case 'u_wall_post':
qa_limits_increment($userid, QA_LIMIT_WALL_POSTS);
case 'u_message': break;
qa_limits_increment($userid, QA_LIMIT_MESSAGES); }
break;
case 'u_wall_post':
qa_limits_increment($userid, QA_LIMIT_WALL_POSTS);
break;
}
$writeactions=array( $writeactions=array(
'_approve', '_claim', '_clearflags', '_delete', '_edit', '_favorite', '_flag', '_hide', '_approve', '_claim', '_clearflags', '_delete', '_edit', '_favorite', '_flag', '_hide',
'_post', '_queue', '_reject', '_reshow', '_unfavorite', '_unflag', '_vote_down', '_vote_nil', '_vote_up', '_post', '_queue', '_reject', '_reshow', '_unfavorite', '_unflag', '_vote_down', '_vote_nil', '_vote_up',
'a_select', 'a_to_c', 'a_unselect', 'a_select', 'a_to_c', 'a_unselect',
'q_close', 'q_move', 'q_reopen', 'q_close', 'q_move', 'q_reopen',
'u_block', 'u_edit', 'u_level', 'u_message', 'u_password', 'u_save', 'u_unblock', 'u_block', 'u_edit', 'u_level', 'u_message', 'u_password', 'u_save', 'u_unblock',
); );
if ( if (
is_numeric(array_search(strstr($event, '_'), $writeactions)) || is_numeric(array_search(strstr($event, '_'), $writeactions)) ||
is_numeric(array_search($event, $writeactions)) is_numeric(array_search($event, $writeactions))
) { ) {
if (isset($userid)) { 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); qa_user_report_action($userid, $event);
} elseif (isset($cookieid)) { } 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); qa_cookie_report_action($cookieid, $event);
}
} }
} }
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,119 +20,101 @@ ...@@ -20,119 +20,101 @@
More about this license: http://www.question2answer.org/license.php 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 require_once QA_INCLUDE_DIR.'db/maxima.php';
header('Location: ../'); require_once QA_INCLUDE_DIR.'qa-util-string.php';
exit;
}
require_once QA_INCLUDE_DIR.'db/maxima.php';
require_once QA_INCLUDE_DIR.'qa-util-string.php';
class qa_filter_basic {
public function filter_email(&$email, $olduser)
{
if (!strlen($email))
return qa_lang('users/email_required');
if (!qa_email_validate($email))
return qa_lang('users/email_invalid');
if (qa_strlen($email)>QA_DB_MAX_EMAIL_LENGTH)
return qa_lang_sub('main/max_length_x', QA_DB_MAX_EMAIL_LENGTH);
}
public function filter_handle(&$handle, $olduser) class qa_filter_basic
{ {
if (!strlen($handle)) public function filter_email(&$email, $olduser)
return qa_lang('users/handle_empty'); {
if (!strlen($email))
return qa_lang('users/email_required');
if (preg_match('/[\\@\\+\\/]/', $handle)) if (!qa_email_validate($email))
return qa_lang_sub('users/handle_has_bad', '@ + /'); return qa_lang('users/email_invalid');
if (qa_strlen($handle)>QA_DB_MAX_HANDLE_LENGTH)
return qa_lang_sub('main/max_length_x', QA_DB_MAX_HANDLE_LENGTH);
}
if (qa_strlen($email)>QA_DB_MAX_EMAIL_LENGTH)
return qa_lang_sub('main/max_length_x', QA_DB_MAX_EMAIL_LENGTH);
}
public function filter_question(&$question, &$errors, $oldquestion) public function filter_handle(&$handle, $olduser)
{ {
$this->validate_length($errors, 'title', @$question['title'], qa_opt('min_len_q_title'), if (!strlen($handle))
max(qa_opt('min_len_q_title'), min(qa_opt('max_len_q_title'), QA_DB_MAX_TITLE_LENGTH))); return qa_lang('users/handle_empty');
$this->validate_length($errors, 'content', @$question['content'], 0, QA_DB_MAX_CONTENT_LENGTH); // for storage if (preg_match('/[\\@\\+\\/]/', $handle))
return qa_lang_sub('users/handle_has_bad', '@ + /');
$this->validate_length($errors, 'content', @$question['text'], qa_opt('min_len_q_content'), null); // for display if (qa_strlen($handle)>QA_DB_MAX_HANDLE_LENGTH)
return qa_lang_sub('main/max_length_x', QA_DB_MAX_HANDLE_LENGTH);
}
if (isset($question['tags'])) { public function filter_question(&$question, &$errors, $oldquestion)
$counttags=count($question['tags']); {
$mintags=min(qa_opt('min_num_q_tags'), qa_opt('max_num_q_tags')); $this->validate_length($errors, 'title', @$question['title'], qa_opt('min_len_q_title'),
max(qa_opt('min_len_q_title'), min(qa_opt('max_len_q_title'), QA_DB_MAX_TITLE_LENGTH)));
if ($counttags<$mintags) $this->validate_length($errors, 'content', @$question['content'], 0, QA_DB_MAX_CONTENT_LENGTH); // for storage
$errors['tags']=qa_lang_sub('question/min_tags_x', $mintags);
elseif ($counttags>qa_opt('max_num_q_tags'))
$errors['tags']=qa_lang_sub('question/max_tags_x', qa_opt('max_num_q_tags'));
else
$this->validate_length($errors, 'tags', qa_tags_to_tagstring($question['tags']), 0, QA_DB_MAX_TAGS_LENGTH); // for storage
}
$this->validate_post_email($errors, $question); $this->validate_length($errors, 'content', @$question['text'], qa_opt('min_len_q_content'), null); // for display
}
if (isset($question['tags'])) {
$counttags=count($question['tags']);
$mintags=min(qa_opt('min_num_q_tags'), qa_opt('max_num_q_tags'));
public function filter_answer(&$answer, &$errors, $question, $oldanswer) if ($counttags<$mintags)
{ $errors['tags']=qa_lang_sub('question/min_tags_x', $mintags);
$this->validate_length($errors, 'content', @$answer['content'], 0, QA_DB_MAX_CONTENT_LENGTH); // for storage elseif ($counttags>qa_opt('max_num_q_tags'))
$this->validate_length($errors, 'content', @$answer['text'], qa_opt('min_len_a_content'), null); // for display $errors['tags']=qa_lang_sub('question/max_tags_x', qa_opt('max_num_q_tags'));
$this->validate_post_email($errors, $answer); else
$this->validate_length($errors, 'tags', qa_tags_to_tagstring($question['tags']), 0, QA_DB_MAX_TAGS_LENGTH); // for storage
} }
$this->validate_post_email($errors, $question);
}
public function filter_comment(&$comment, &$errors, $question, $parent, $oldcomment) public function filter_answer(&$answer, &$errors, $question, $oldanswer)
{ {
$this->validate_length($errors, 'content', @$comment['content'], 0, QA_DB_MAX_CONTENT_LENGTH); // for storage $this->validate_length($errors, 'content', @$answer['content'], 0, QA_DB_MAX_CONTENT_LENGTH); // for storage
$this->validate_length($errors, 'content', @$comment['text'], qa_opt('min_len_c_content'), null); // for display $this->validate_length($errors, 'content', @$answer['text'], qa_opt('min_len_a_content'), null); // for display
$this->validate_post_email($errors, $comment); $this->validate_post_email($errors, $answer);
} }
public function filter_comment(&$comment, &$errors, $question, $parent, $oldcomment)
{
$this->validate_length($errors, 'content', @$comment['content'], 0, QA_DB_MAX_CONTENT_LENGTH); // for storage
$this->validate_length($errors, 'content', @$comment['text'], qa_opt('min_len_c_content'), null); // for display
$this->validate_post_email($errors, $comment);
}
public function filter_profile(&$profile, &$errors, $user, $oldprofile) public function filter_profile(&$profile, &$errors, $user, $oldprofile)
{ {
foreach ($profile as $field => $value) foreach ($profile as $field => $value)
$this->validate_length($errors, $field, $value, 0, QA_DB_MAX_PROFILE_CONTENT_LENGTH); $this->validate_length($errors, $field, $value, 0, QA_DB_MAX_PROFILE_CONTENT_LENGTH);
} }
// The definitions below are not part of a standard filter module, but just used within this one // The definitions below are not part of a standard filter module, but just used within this one
private function validate_length(&$errors, $field, $input, $minlength, $maxlength) /**
/* * Add textual element $field to $errors if length of $input is not between $minlength and $maxlength
Add textual element $field to $errors if length of $input is not between $minlength and $maxlength */
*/ private function validate_length(&$errors, $field, $input, $minlength, $maxlength)
{ {
$length = isset($input) ? qa_strlen($input) : 0; $length = isset($input) ? qa_strlen($input) : 0;
if ($length < $minlength)
$errors[$field] = ($minlength == 1) ? qa_lang('main/field_required') : qa_lang_sub('main/min_length_x', $minlength);
elseif (isset($maxlength) && ($length > $maxlength))
$errors[$field] = qa_lang_sub('main/max_length_x', $maxlength);
}
if ($length < $minlength)
$errors[$field] = ($minlength == 1) ? qa_lang('main/field_required') : qa_lang_sub('main/min_length_x', $minlength);
elseif (isset($maxlength) && ($length > $maxlength))
$errors[$field] = qa_lang_sub('main/max_length_x', $maxlength);
}
private function validate_post_email(&$errors, $post) private function validate_post_email(&$errors, $post)
{ {
if (@$post['notify'] && strlen(@$post['email'])) { if (@$post['notify'] && strlen(@$post['email'])) {
$error=$this->filter_email($post['email'], null); $error=$this->filter_email($post['email'], null);
if (isset($error)) if (isset($error))
$errors['email']=$error; $errors['email']=$error;
}
} }
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,133 +20,116 @@ ...@@ -20,133 +20,116 @@
More about this license: http://www.question2answer.org/license.php 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 class qa_search_basic
header('Location: ../'); {
exit; public function index_post($postid, $type, $questionid, $parentid, $title, $content, $format, $text, $tagstring, $categoryid)
} {
require_once QA_INCLUDE_DIR.'db/post-create.php';
class qa_search_basic {
public function index_post($postid, $type, $questionid, $parentid, $title, $content, $format, $text, $tagstring, $categoryid)
{
require_once QA_INCLUDE_DIR.'db/post-create.php';
// Get words from each textual element
$titlewords=array_unique(qa_string_to_words($title));
$contentcount=array_count_values(qa_string_to_words($text));
$tagwords=array_unique(qa_string_to_words($tagstring));
$wholetags=array_unique(qa_tagstring_to_tags($tagstring));
// Map all words to their word IDs // Get words from each textual element
$words=array_unique(array_merge($titlewords, array_keys($contentcount), $tagwords, $wholetags)); $titlewords=array_unique(qa_string_to_words($title));
$wordtoid=qa_db_word_mapto_ids_add($words); $contentcount=array_count_values(qa_string_to_words($text));
$tagwords=array_unique(qa_string_to_words($tagstring));
$wholetags=array_unique(qa_tagstring_to_tags($tagstring));
// Add to title words index // Map all words to their word IDs
$titlewordids=qa_array_filter_by_keys($wordtoid, $titlewords); $words=array_unique(array_merge($titlewords, array_keys($contentcount), $tagwords, $wholetags));
qa_db_titlewords_add_post_wordids($postid, $titlewordids); $wordtoid=qa_db_word_mapto_ids_add($words);
// Add to content words index (including word counts) // Add to title words index
$contentwordidcounts=array(); $titlewordids=qa_array_filter_by_keys($wordtoid, $titlewords);
foreach ($contentcount as $word => $count) qa_db_titlewords_add_post_wordids($postid, $titlewordids);
if (isset($wordtoid[$word]))
$contentwordidcounts[$wordtoid[$word]]=$count;
qa_db_contentwords_add_post_wordidcounts($postid, $type, $questionid, $contentwordidcounts); // Add to content words index (including word counts)
// Add to tag words index $contentwordidcounts=array();
foreach ($contentcount as $word => $count)
if (isset($wordtoid[$word]))
$contentwordidcounts[$wordtoid[$word]]=$count;
$tagwordids=qa_array_filter_by_keys($wordtoid, $tagwords); qa_db_contentwords_add_post_wordidcounts($postid, $type, $questionid, $contentwordidcounts);
qa_db_tagwords_add_post_wordids($postid, $tagwordids);
// Add to whole tags index // Add to tag words index
$wholetagids=qa_array_filter_by_keys($wordtoid, $wholetags); $tagwordids=qa_array_filter_by_keys($wordtoid, $tagwords);
qa_db_posttags_add_post_wordids($postid, $wholetagids); qa_db_tagwords_add_post_wordids($postid, $tagwordids);
// Update counts cached in database (will be skipped if qa_suspend_update_counts() was called // Add to whole tags index
qa_db_word_titlecount_update($titlewordids); $wholetagids=qa_array_filter_by_keys($wordtoid, $wholetags);
qa_db_word_contentcount_update(array_keys($contentwordidcounts)); qa_db_posttags_add_post_wordids($postid, $wholetagids);
qa_db_word_tagwordcount_update($tagwordids);
qa_db_word_tagcount_update($wholetagids);
qa_db_tagcount_update();
}
// Update counts cached in database (will be skipped if qa_suspend_update_counts() was called
public function unindex_post($postid) qa_db_word_titlecount_update($titlewordids);
{ qa_db_word_contentcount_update(array_keys($contentwordidcounts));
require_once QA_INCLUDE_DIR.'db/post-update.php'; qa_db_word_tagwordcount_update($tagwordids);
qa_db_word_tagcount_update($wholetagids);
qa_db_tagcount_update();
}
$titlewordids=qa_db_titlewords_get_post_wordids($postid); public function unindex_post($postid)
qa_db_titlewords_delete_post($postid); {
qa_db_word_titlecount_update($titlewordids); require_once QA_INCLUDE_DIR.'db/post-update.php';
$contentwordids=qa_db_contentwords_get_post_wordids($postid); $titlewordids=qa_db_titlewords_get_post_wordids($postid);
qa_db_contentwords_delete_post($postid); qa_db_titlewords_delete_post($postid);
qa_db_word_contentcount_update($contentwordids); qa_db_word_titlecount_update($titlewordids);
$tagwordids=qa_db_tagwords_get_post_wordids($postid); $contentwordids=qa_db_contentwords_get_post_wordids($postid);
qa_db_tagwords_delete_post($postid); qa_db_contentwords_delete_post($postid);
qa_db_word_tagwordcount_update($tagwordids); qa_db_word_contentcount_update($contentwordids);
$wholetagids=qa_db_posttags_get_post_wordids($postid); $tagwordids=qa_db_tagwords_get_post_wordids($postid);
qa_db_posttags_delete_post($postid); qa_db_tagwords_delete_post($postid);
qa_db_word_tagcount_update($wholetagids); qa_db_word_tagwordcount_update($tagwordids);
}
$wholetagids=qa_db_posttags_get_post_wordids($postid);
qa_db_posttags_delete_post($postid);
qa_db_word_tagcount_update($wholetagids);
}
public function move_post($postid, $categoryid) public function move_post($postid, $categoryid)
{ {
// for now, the built-in search engine ignores categories // for now, the built-in search engine ignores categories
} }
public function index_page($pageid, $request, $title, $content, $format, $text)
{
// for now, the built-in search engine ignores custom pages
}
public function index_page($pageid, $request, $title, $content, $format, $text) public function unindex_page($pageid)
{ {
// for now, the built-in search engine ignores custom pages // for now, the built-in search engine ignores custom pages
} }
public function process_search($query, $start, $count, $userid, $absoluteurls, $fullcontent)
{
require_once QA_INCLUDE_DIR.'db/selects.php';
require_once QA_INCLUDE_DIR.'qa-util-string.php';
public function unindex_page($pageid) $words=qa_string_to_words($query);
{
// for now, the built-in search engine ignores custom pages
}
$questions=qa_db_select_with_pending(
qa_db_search_posts_selectspec($userid, $words, $words, $words, $words, trim($query), $start, $fullcontent, $count)
);
public function process_search($query, $start, $count, $userid, $absoluteurls, $fullcontent) $results=array();
{
require_once QA_INCLUDE_DIR.'db/selects.php';
require_once QA_INCLUDE_DIR.'qa-util-string.php';
$words=qa_string_to_words($query); foreach ($questions as $question) {
qa_search_set_max_match($question, $type, $postid); // to link straight to best part
$questions=qa_db_select_with_pending( $results[]=array(
qa_db_search_posts_selectspec($userid, $words, $words, $words, $words, trim($query), $start, $fullcontent, $count) 'question' => $question,
'match_type' => $type,
'match_postid' => $postid,
); );
$results=array();
foreach ($questions as $question) {
qa_search_set_max_match($question, $type, $postid); // to link straight to best part
$results[]=array(
'question' => $question,
'match_type' => $type,
'match_postid' => $postid,
);
}
return $results;
} }
return $results;
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,51 +20,42 @@ ...@@ -20,51 +20,42 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
class qa_activity_count { class qa_activity_count
{
public function allow_template($template) public function allow_template($template)
{ {
return true; return true;
} }
public function allow_region($region)
{
return ($region=='side');
}
public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
{
$themeobject->output('<div class="qa-activity-count">');
$this->output_count($themeobject, qa_opt('cache_qcount'), 'main/1_question', 'main/x_questions'); public function allow_region($region)
$this->output_count($themeobject, qa_opt('cache_acount'), 'main/1_answer', 'main/x_answers'); {
return ($region=='side');
}
if (qa_opt('comment_on_qs') || qa_opt('comment_on_as')) public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
$this->output_count($themeobject, qa_opt('cache_ccount'), 'main/1_comment', 'main/x_comments'); {
$themeobject->output('<div class="qa-activity-count">');
$this->output_count($themeobject, qa_opt('cache_userpointscount'), 'main/1_user', 'main/x_users'); $this->output_count($themeobject, qa_opt('cache_qcount'), 'main/1_question', 'main/x_questions');
$this->output_count($themeobject, qa_opt('cache_acount'), 'main/1_answer', 'main/x_answers');
$themeobject->output('</div>'); if (qa_opt('comment_on_qs') || qa_opt('comment_on_as'))
} $this->output_count($themeobject, qa_opt('cache_ccount'), 'main/1_comment', 'main/x_comments');
$this->output_count($themeobject, qa_opt('cache_userpointscount'), 'main/1_user', 'main/x_users');
public function output_count($themeobject, $value, $langsingular, $langplural) $themeobject->output('</div>');
{ }
$themeobject->output('<p class="qa-activity-count-item">');
if ($value==1) public function output_count($themeobject, $value, $langsingular, $langplural)
$themeobject->output(qa_lang_html_sub($langsingular, '<span class="qa-activity-count-data">1</span>', '1')); {
else $themeobject->output('<p class="qa-activity-count-item">');
$themeobject->output(qa_lang_html_sub($langplural, '<span class="qa-activity-count-data">'.number_format((int)$value).'</span>'));
$themeobject->output('</p>'); if ($value==1)
} $themeobject->output(qa_lang_html_sub($langsingular, '<span class="qa-activity-count-data">1</span>', '1'));
else
$themeobject->output(qa_lang_html_sub($langplural, '<span class="qa-activity-count-data">'.number_format((int)$value).'</span>'));
$themeobject->output('</p>');
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,30 +20,28 @@ ...@@ -20,30 +20,28 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
class qa_ask_box { class qa_ask_box
{
public function allow_template($template) public function allow_template($template)
{ {
$allowed = array( $allowed = array(
'activity', 'categories', 'custom', 'feedback', 'qa', 'questions', 'activity', 'categories', 'custom', 'feedback', 'qa', 'questions',
'hot', 'search', 'tag', 'tags', 'unanswered' 'hot', 'search', 'tag', 'tags', 'unanswered'
); );
return in_array($template, $allowed); return in_array($template, $allowed);
} }
public function allow_region($region)
{
return in_array($region, array('main', 'side', 'full'));
}
public function allow_region($region)
{
return in_array($region, array('main', 'side', 'full'));
}
public function output_widget($region, $place, $themeobject, $template, $request, $qa_content) public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
{ {
if (isset($qa_content['categoryids'])) if (isset($qa_content['categoryids']))
$params=array('cat' => end($qa_content['categoryids'])); $params=array('cat' => end($qa_content['categoryids']));
else else
$params=null; $params=null;
?> ?>
<div class="qa-ask-box"> <div class="qa-ask-box">
<form method="post" action="<?php echo qa_path_html('ask', $params); ?>"> <form method="post" action="<?php echo qa_path_html('ask', $params); ?>">
...@@ -69,11 +67,5 @@ ...@@ -69,11 +67,5 @@
</form> </form>
</div> </div>
<?php <?php
}
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,92 +20,84 @@ ...@@ -20,92 +20,84 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
class qa_related_qs { class qa_related_qs
{
public function allow_template($template) public function allow_template($template)
{ {
return ($template=='question'); return ($template=='question');
} }
public function allow_region($region)
{
return ($region=='side') || ($region=='main') || ($region=='full');
}
public function allow_region($region)
{
return ($region=='side') || ($region=='main') || ($region=='full');
}
public function output_widget($region, $place, $themeobject, $template, $request, $qa_content) public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
{ {
require_once QA_INCLUDE_DIR.'db/selects.php'; require_once QA_INCLUDE_DIR.'db/selects.php';
if (@$qa_content['q_view']['raw']['type']!='Q') // question might not be visible, etc... if (@$qa_content['q_view']['raw']['type']!='Q') // question might not be visible, etc...
return; return;
$questionid=$qa_content['q_view']['raw']['postid']; $questionid=$qa_content['q_view']['raw']['postid'];
$userid=qa_get_logged_in_userid(); $userid=qa_get_logged_in_userid();
$cookieid=qa_cookie_get(); $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) foreach ($questions as $key => $question)
if ($question['score']<$minscore) if ($question['score']<$minscore)
unset($questions[$key]); 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( $themeobject->output(
'<div class="qa-related-qs">', '<div class="qa-related-qs">',
'<h2 style="margin-top:0; padding-top:0;">', '<h2 style="margin-top:0; padding-top:0;">',
$titlehtml, $titlehtml,
'</h2>' '</h2>'
); );
$themeobject->output('<ul class="qa-related-q-list">'); $themeobject->output('<ul class="qa-related-q-list">');
foreach ($questions as $question) 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('<li class="qa-related-q-item"><a href="'.qa_q_path_html($question['postid'], $question['title']).'">'.qa_html($question['title']).'</a></li>');
$themeobject->output( $themeobject->output(
'</ul>', '</ul>',
'</div>' '</div>'
); );
} else { } else {
$themeobject->output( $themeobject->output(
'<h2>', '<h2>',
$titlehtml, $titlehtml,
'</h2>' '</h2>'
); );
$q_list=array( $q_list=array(
'form' => array( 'form' => array(
'tags' => 'method="post" action="'.qa_self_html().'"', 'tags' => 'method="post" action="'.qa_self_html().'"',
'hidden' => array( 'hidden' => array(
'code' => qa_get_form_security_code('vote'), 'code' => qa_get_form_security_code('vote'),
),
), ),
),
'qs' => array(), 'qs' => array(),
); );
$defaults=qa_post_html_defaults('Q'); $defaults=qa_post_html_defaults('Q');
$usershtml=qa_userids_handles_html($questions); $usershtml=qa_userids_handles_html($questions);
foreach ($questions as $question) 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); $themeobject->q_list_and_form($q_list);
}
} }
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
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