Commit 4a51a213 by Scott

Coding style (core plugins)

parent 7ebb9fa6
......@@ -20,58 +20,43 @@
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;
class qa_editor_basic
{
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)
{
}
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),
);
}
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();";
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
public function read_post($fieldname)
{
return array(
'format' => '',
'content' => qa_post_text($fieldname),
);
}
}
......@@ -20,97 +20,84 @@
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;
}
class qa_event_limits {
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.
if (isset($params['delayed']))
return;
require_once QA_INCLUDE_DIR.'app/limits.php';
switch ($event) {
case 'q_queue':
case 'q_post':
case 'q_claim':
qa_limits_increment($userid, QA_LIMIT_QUESTIONS);
break;
case 'a_queue':
case 'a_post':
case 'a_claim':
qa_limits_increment($userid, QA_LIMIT_ANSWERS);
break;
case 'c_queue':
case 'c_post':
case 'c_claim':
case 'a_to_c':
qa_limits_increment($userid, QA_LIMIT_COMMENTS);
break;
case 'q_vote_up':
case 'q_vote_down':
case 'q_vote_nil':
case 'a_vote_up':
case 'a_vote_down':
case 'a_vote_nil':
qa_limits_increment($userid, QA_LIMIT_VOTES);
break;
case 'q_flag':
case 'a_flag':
case 'c_flag':
qa_limits_increment($userid, QA_LIMIT_FLAGS);
break;
case 'u_message':
qa_limits_increment($userid, QA_LIMIT_MESSAGES);
break;
case 'u_wall_post':
qa_limits_increment($userid, QA_LIMIT_WALL_POSTS);
break;
}
class qa_event_limits
{
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.
if (isset($params['delayed']))
return;
require_once QA_INCLUDE_DIR.'app/limits.php';
switch ($event) {
case 'q_queue':
case 'q_post':
case 'q_claim':
qa_limits_increment($userid, QA_LIMIT_QUESTIONS);
break;
case 'a_queue':
case 'a_post':
case 'a_claim':
qa_limits_increment($userid, QA_LIMIT_ANSWERS);
break;
case 'c_queue':
case 'c_post':
case 'c_claim':
case 'a_to_c':
qa_limits_increment($userid, QA_LIMIT_COMMENTS);
break;
case 'q_vote_up':
case 'q_vote_down':
case 'q_vote_nil':
case 'a_vote_up':
case 'a_vote_down':
case 'a_vote_nil':
qa_limits_increment($userid, QA_LIMIT_VOTES);
break;
case 'q_flag':
case 'a_flag':
case 'c_flag':
qa_limits_increment($userid, QA_LIMIT_FLAGS);
break;
case 'u_message':
qa_limits_increment($userid, QA_LIMIT_MESSAGES);
break;
case 'u_wall_post':
qa_limits_increment($userid, QA_LIMIT_WALL_POSTS);
break;
}
$writeactions=array(
'_approve', '_claim', '_clearflags', '_delete', '_edit', '_favorite', '_flag', '_hide',
'_post', '_queue', '_reject', '_reshow', '_unfavorite', '_unflag', '_vote_down', '_vote_nil', '_vote_up',
'a_select', 'a_to_c', 'a_unselect',
'q_close', 'q_move', 'q_reopen',
'u_block', 'u_edit', 'u_level', 'u_message', 'u_password', 'u_save', 'u_unblock',
);
$writeactions=array(
'_approve', '_claim', '_clearflags', '_delete', '_edit', '_favorite', '_flag', '_hide',
'_post', '_queue', '_reject', '_reshow', '_unfavorite', '_unflag', '_vote_down', '_vote_nil', '_vote_up',
'a_select', 'a_to_c', 'a_unselect',
'q_close', 'q_move', 'q_reopen',
'u_block', 'u_edit', 'u_level', 'u_message', 'u_password', 'u_save', 'u_unblock',
);
if (
is_numeric(array_search(strstr($event, '_'), $writeactions)) ||
is_numeric(array_search($event, $writeactions))
) {
if (isset($userid)) {
require_once QA_INCLUDE_DIR.'app/users.php';
if (
is_numeric(array_search(strstr($event, '_'), $writeactions)) ||
is_numeric(array_search($event, $writeactions))
) {
if (isset($userid)) {
require_once QA_INCLUDE_DIR.'app/users.php';
qa_user_report_action($userid, $event);
qa_user_report_action($userid, $event);
} elseif (isset($cookieid)) {
require_once QA_INCLUDE_DIR.'app/cookies.php';
} elseif (isset($cookieid)) {
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 @@
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;
}
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);
}
require_once QA_INCLUDE_DIR.'db/maxima.php';
require_once QA_INCLUDE_DIR.'qa-util-string.php';
public function filter_handle(&$handle, $olduser)
{
if (!strlen($handle))
return qa_lang('users/handle_empty');
class qa_filter_basic
{
public function filter_email(&$email, $olduser)
{
if (!strlen($email))
return qa_lang('users/email_required');
if (preg_match('/[\\@\\+\\/]/', $handle))
return qa_lang_sub('users/handle_has_bad', '@ + /');
if (qa_strlen($handle)>QA_DB_MAX_HANDLE_LENGTH)
return qa_lang_sub('main/max_length_x', QA_DB_MAX_HANDLE_LENGTH);
}
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_question(&$question, &$errors, $oldquestion)
{
$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)));
public function filter_handle(&$handle, $olduser)
{
if (!strlen($handle))
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'])) {
$counttags=count($question['tags']);
$mintags=min(qa_opt('min_num_q_tags'), qa_opt('max_num_q_tags'));
public function filter_question(&$question, &$errors, $oldquestion)
{
$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)
$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_length($errors, 'content', @$question['content'], 0, QA_DB_MAX_CONTENT_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)
{
$this->validate_length($errors, 'content', @$answer['content'], 0, QA_DB_MAX_CONTENT_LENGTH); // for storage
$this->validate_length($errors, 'content', @$answer['text'], qa_opt('min_len_a_content'), null); // for display
$this->validate_post_email($errors, $answer);
if ($counttags<$mintags)
$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);
}
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_answer(&$answer, &$errors, $question, $oldanswer)
{
$this->validate_length($errors, 'content', @$answer['content'], 0, QA_DB_MAX_CONTENT_LENGTH); // for storage
$this->validate_length($errors, 'content', @$answer['text'], qa_opt('min_len_a_content'), null); // for display
$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)
{
foreach ($profile as $field => $value)
$this->validate_length($errors, $field, $value, 0, QA_DB_MAX_PROFILE_CONTENT_LENGTH);
}
public function filter_profile(&$profile, &$errors, $user, $oldprofile)
{
foreach ($profile as $field => $value)
$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
*/
{
$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);
}
/**
* 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;
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)
{
if (@$post['notify'] && strlen(@$post['email'])) {
$error=$this->filter_email($post['email'], null);
if (isset($error))
$errors['email']=$error;
}
private function validate_post_email(&$errors, $post)
{
if (@$post['notify'] && strlen(@$post['email'])) {
$error=$this->filter_email($post['email'], null);
if (isset($error))
$errors['email']=$error;
}
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
}
......@@ -20,133 +20,116 @@
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;
}
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));
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';
// Map all words to their word IDs
// Get words from each textual element
$words=array_unique(array_merge($titlewords, array_keys($contentcount), $tagwords, $wholetags));
$wordtoid=qa_db_word_mapto_ids_add($words);
$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));
// Add to title words index
// Map all words to their word IDs
$titlewordids=qa_array_filter_by_keys($wordtoid, $titlewords);
qa_db_titlewords_add_post_wordids($postid, $titlewordids);
$words=array_unique(array_merge($titlewords, array_keys($contentcount), $tagwords, $wholetags));
$wordtoid=qa_db_word_mapto_ids_add($words);
// Add to content words index (including word counts)
// Add to title words index
$contentwordidcounts=array();
foreach ($contentcount as $word => $count)
if (isset($wordtoid[$word]))
$contentwordidcounts[$wordtoid[$word]]=$count;
$titlewordids=qa_array_filter_by_keys($wordtoid, $titlewords);
qa_db_titlewords_add_post_wordids($postid, $titlewordids);
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_tagwords_add_post_wordids($postid, $tagwordids);
qa_db_contentwords_add_post_wordidcounts($postid, $type, $questionid, $contentwordidcounts);
// Add to whole tags index
// Add to tag words index
$wholetagids=qa_array_filter_by_keys($wordtoid, $wholetags);
qa_db_posttags_add_post_wordids($postid, $wholetagids);
$tagwordids=qa_array_filter_by_keys($wordtoid, $tagwords);
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);
qa_db_word_contentcount_update(array_keys($contentwordidcounts));
qa_db_word_tagwordcount_update($tagwordids);
qa_db_word_tagcount_update($wholetagids);
qa_db_tagcount_update();
}
$wholetagids=qa_array_filter_by_keys($wordtoid, $wholetags);
qa_db_posttags_add_post_wordids($postid, $wholetagids);
// Update counts cached in database (will be skipped if qa_suspend_update_counts() was called
public function unindex_post($postid)
{
require_once QA_INCLUDE_DIR.'db/post-update.php';
qa_db_word_titlecount_update($titlewordids);
qa_db_word_contentcount_update(array_keys($contentwordidcounts));
qa_db_word_tagwordcount_update($tagwordids);
qa_db_word_tagcount_update($wholetagids);
qa_db_tagcount_update();
}
$titlewordids=qa_db_titlewords_get_post_wordids($postid);
qa_db_titlewords_delete_post($postid);
qa_db_word_titlecount_update($titlewordids);
public function unindex_post($postid)
{
require_once QA_INCLUDE_DIR.'db/post-update.php';
$contentwordids=qa_db_contentwords_get_post_wordids($postid);
qa_db_contentwords_delete_post($postid);
qa_db_word_contentcount_update($contentwordids);
$titlewordids=qa_db_titlewords_get_post_wordids($postid);
qa_db_titlewords_delete_post($postid);
qa_db_word_titlecount_update($titlewordids);
$tagwordids=qa_db_tagwords_get_post_wordids($postid);
qa_db_tagwords_delete_post($postid);
qa_db_word_tagwordcount_update($tagwordids);
$contentwordids=qa_db_contentwords_get_post_wordids($postid);
qa_db_contentwords_delete_post($postid);
qa_db_word_contentcount_update($contentwordids);
$wholetagids=qa_db_posttags_get_post_wordids($postid);
qa_db_posttags_delete_post($postid);
qa_db_word_tagcount_update($wholetagids);
}
$tagwordids=qa_db_tagwords_get_post_wordids($postid);
qa_db_tagwords_delete_post($postid);
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)
{
// for now, the built-in search engine ignores categories
}
public function move_post($postid, $categoryid)
{
// 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)
{
// for now, the built-in search engine ignores custom pages
}
public function unindex_page($pageid)
{
// 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)
{
// for now, the built-in search engine ignores custom pages
}
$words=qa_string_to_words($query);
$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)
{
require_once QA_INCLUDE_DIR.'db/selects.php';
require_once QA_INCLUDE_DIR.'qa-util-string.php';
$results=array();
$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(
qa_db_search_posts_selectspec($userid, $words, $words, $words, $words, trim($query), $start, $fullcontent, $count)
$results[]=array(
'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 @@
More about this license: http://www.question2answer.org/license.php
*/
class qa_activity_count {
public function allow_template($template)
{
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">');
class qa_activity_count
{
public function allow_template($template)
{
return true;
}
$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');
public function allow_region($region)
{
return ($region=='side');
}
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');
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_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('<p class="qa-activity-count-item">');
$themeobject->output('</div>');
}
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>'));
public function output_count($themeobject, $value, $langsingular, $langplural)
{
$themeobject->output('<p class="qa-activity-count-item">');
$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 @@
More about this license: http://www.question2answer.org/license.php
*/
class qa_ask_box {
public function allow_template($template)
{
$allowed = array(
'activity', 'categories', 'custom', 'feedback', 'qa', 'questions',
'hot', 'search', 'tag', 'tags', 'unanswered'
);
return in_array($template, $allowed);
}
public function allow_region($region)
{
return in_array($region, array('main', 'side', 'full'));
}
class qa_ask_box
{
public function allow_template($template)
{
$allowed = array(
'activity', 'categories', 'custom', 'feedback', 'qa', 'questions',
'hot', 'search', 'tag', 'tags', 'unanswered'
);
return in_array($template, $allowed);
}
public function allow_region($region)
{
return in_array($region, array('main', 'side', 'full'));
}
public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
{
if (isset($qa_content['categoryids']))
$params=array('cat' => end($qa_content['categoryids']));
else
$params=null;
public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
{
if (isset($qa_content['categoryids']))
$params=array('cat' => end($qa_content['categoryids']));
else
$params=null;
?>
<div class="qa-ask-box">
<form method="post" action="<?php echo qa_path_html('ask', $params); ?>">
......@@ -69,11 +67,5 @@
</form>
</div>
<?php
}
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
}
......@@ -20,92 +20,84 @@
More about this license: http://www.question2answer.org/license.php
*/
class qa_related_qs {
public function allow_template($template)
{
return ($template=='question');
}
public function allow_region($region)
{
return ($region=='side') || ($region=='main') || ($region=='full');
}
class qa_related_qs
{
public function allow_template($template)
{
return ($template=='question');
}
public function allow_region($region)
{
return ($region=='side') || ($region=='main') || ($region=='full');
}
public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
{
require_once QA_INCLUDE_DIR.'db/selects.php';
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...
return;
if (@$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)
unset($questions[$key]);
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') {
$themeobject->output(
'<div class="qa-related-qs">',
'<h2 style="margin-top:0; padding-top:0;">',
$titlehtml,
'</h2>'
);
if ($region=='side') {
$themeobject->output(
'<div class="qa-related-qs">',
'<h2 style="margin-top:0; padding-top:0;">',
$titlehtml,
'</h2>'
);
$themeobject->output('<ul class="qa-related-q-list">');
$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>'
);
$themeobject->output(
'</ul>',
'</div>'
);
} else {
$themeobject->output(
'<h2>',
$titlehtml,
'</h2>'
);
} else {
$themeobject->output(
'<h2>',
$titlehtml,
'</h2>'
);
$q_list=array(
'form' => array(
'tags' => 'method="post" action="'.qa_self_html().'"',
$q_list=array(
'form' => array(
'tags' => 'method="post" action="'.qa_self_html().'"',
'hidden' => array(
'code' => qa_get_form_security_code('vote'),
),
'hidden' => array(
'code' => qa_get_form_security_code('vote'),
),
),
'qs' => array(),
);
'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));
foreach ($questions as $question)
$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