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,255 +20,246 @@
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_notify {
public function process_event($event, $userid, $handle, $cookieid, $params)
{
require_once QA_INCLUDE_DIR.'app/emails.php';
require_once QA_INCLUDE_DIR.'app/format.php';
require_once QA_INCLUDE_DIR.'qa-util-string.php';
switch ($event) {
case 'q_post':
$followanswer=@$params['followanswer'];
$sendhandle=isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous'));
if (isset($followanswer['notify']) && !qa_post_is_by_user($followanswer, $userid, $cookieid)) {
$blockwordspreg=qa_get_block_words_preg();
$sendtext=qa_viewer_text($followanswer['content'], $followanswer['format'], array('blockwordspreg' => $blockwordspreg));
qa_send_notification($followanswer['userid'], $followanswer['notify'], @$followanswer['handle'], qa_lang('emails/a_followed_subject'), qa_lang('emails/a_followed_body'), array(
'^q_handle' => $sendhandle,
'^q_title' => qa_block_words_replace($params['title'], $blockwordspreg),
'^a_content' => $sendtext,
'^url' => qa_q_path($params['postid'], $params['title'], true),
));
}
if (qa_opt('notify_admin_q_post'))
qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/q_posted_subject'), qa_lang('emails/q_posted_body'), array(
'^q_handle' => $sendhandle,
'^q_title' => $params['title'], // don't censor title or content here since we want the admin to see bad words
'^q_content' => $params['text'],
'^url' => qa_q_path($params['postid'], $params['title'], true),
));
class qa_event_notify
{
public function process_event($event, $userid, $handle, $cookieid, $params)
{
require_once QA_INCLUDE_DIR.'app/emails.php';
require_once QA_INCLUDE_DIR.'app/format.php';
require_once QA_INCLUDE_DIR.'qa-util-string.php';
break;
switch ($event) {
case 'q_post':
$followanswer=@$params['followanswer'];
$sendhandle=isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous'));
case 'a_post':
$question=$params['parent'];
if (isset($question['notify']) && !qa_post_is_by_user($question, $userid, $cookieid))
qa_send_notification($question['userid'], $question['notify'], @$question['handle'], qa_lang('emails/q_answered_subject'), qa_lang('emails/q_answered_body'), array(
'^a_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous')),
'^q_title' => $question['title'],
'^a_content' => qa_block_words_replace($params['text'], qa_get_block_words_preg()),
'^url' => qa_q_path($question['postid'], $question['title'], true, 'A', $params['postid']),
));
break;
case 'c_post':
$parent=$params['parent'];
$question=$params['question'];
$senttoemail=array(); // to ensure each user or email gets only one notification about an added comment
$senttouserid=array();
switch ($parent['basetype']) {
case 'Q':
$subject=qa_lang('emails/q_commented_subject');
$body=qa_lang('emails/q_commented_body');
$context=$parent['title'];
break;
case 'A':
$subject=qa_lang('emails/a_commented_subject');
$body=qa_lang('emails/a_commented_body');
$context=qa_viewer_text($parent['content'], $parent['format']);
break;
}
if (isset($followanswer['notify']) && !qa_post_is_by_user($followanswer, $userid, $cookieid)) {
$blockwordspreg=qa_get_block_words_preg();
$sendhandle=isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous'));
$sendcontext=qa_block_words_replace($context, $blockwordspreg);
$sendtext=qa_block_words_replace($params['text'], $blockwordspreg);
$sendurl=qa_q_path($question['postid'], $question['title'], true, 'C', $params['postid']);
if (isset($parent['notify']) && !qa_post_is_by_user($parent, $userid, $cookieid)) {
$senduserid=$parent['userid'];
$sendemail=@$parent['notify'];
$sendtext=qa_viewer_text($followanswer['content'], $followanswer['format'], array('blockwordspreg' => $blockwordspreg));
qa_send_notification($followanswer['userid'], $followanswer['notify'], @$followanswer['handle'], qa_lang('emails/a_followed_subject'), qa_lang('emails/a_followed_body'), array(
'^q_handle' => $sendhandle,
'^q_title' => qa_block_words_replace($params['title'], $blockwordspreg),
'^a_content' => $sendtext,
'^url' => qa_q_path($params['postid'], $params['title'], true),
));
}
if (qa_opt('notify_admin_q_post'))
qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/q_posted_subject'), qa_lang('emails/q_posted_body'), array(
'^q_handle' => $sendhandle,
'^q_title' => $params['title'], // don't censor title or content here since we want the admin to see bad words
'^q_content' => $params['text'],
'^url' => qa_q_path($params['postid'], $params['title'], true),
));
break;
case 'a_post':
$question=$params['parent'];
if (isset($question['notify']) && !qa_post_is_by_user($question, $userid, $cookieid))
qa_send_notification($question['userid'], $question['notify'], @$question['handle'], qa_lang('emails/q_answered_subject'), qa_lang('emails/q_answered_body'), array(
'^a_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous')),
'^q_title' => $question['title'],
'^a_content' => qa_block_words_replace($params['text'], qa_get_block_words_preg()),
'^url' => qa_q_path($question['postid'], $question['title'], true, 'A', $params['postid']),
));
break;
case 'c_post':
$parent=$params['parent'];
$question=$params['question'];
$senttoemail=array(); // to ensure each user or email gets only one notification about an added comment
$senttouserid=array();
switch ($parent['basetype']) {
case 'Q':
$subject=qa_lang('emails/q_commented_subject');
$body=qa_lang('emails/q_commented_body');
$context=$parent['title'];
break;
case 'A':
$subject=qa_lang('emails/a_commented_subject');
$body=qa_lang('emails/a_commented_body');
$context=qa_viewer_text($parent['content'], $parent['format']);
break;
}
$blockwordspreg=qa_get_block_words_preg();
$sendhandle=isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous'));
$sendcontext=qa_block_words_replace($context, $blockwordspreg);
$sendtext=qa_block_words_replace($params['text'], $blockwordspreg);
$sendurl=qa_q_path($question['postid'], $question['title'], true, 'C', $params['postid']);
if (isset($parent['notify']) && !qa_post_is_by_user($parent, $userid, $cookieid)) {
$senduserid=$parent['userid'];
$sendemail=@$parent['notify'];
if (qa_email_validate($sendemail))
$senttoemail[$sendemail]=true;
elseif (isset($senduserid))
$senttouserid[$senduserid]=true;
qa_send_notification($senduserid, $sendemail, @$parent['handle'], $subject, $body, array(
'^c_handle' => $sendhandle,
'^c_context' => $sendcontext,
'^c_content' => $sendtext,
'^url' => $sendurl,
));
}
foreach ($params['thread'] as $comment)
if (isset($comment['notify']) && !qa_post_is_by_user($comment, $userid, $cookieid)) {
$senduserid=$comment['userid'];
$sendemail=@$comment['notify'];
if (qa_email_validate($sendemail)) {
if (@$senttoemail[$sendemail])
continue;
if (qa_email_validate($sendemail))
$senttoemail[$sendemail]=true;
elseif (isset($senduserid))
} elseif (isset($senduserid)) {
if (@$senttouserid[$senduserid])
continue;
$senttouserid[$senduserid]=true;
}
qa_send_notification($senduserid, $sendemail, @$parent['handle'], $subject, $body, array(
qa_send_notification($senduserid, $sendemail, @$comment['handle'], qa_lang('emails/c_commented_subject'), qa_lang('emails/c_commented_body'), array(
'^c_handle' => $sendhandle,
'^c_context' => $sendcontext,
'^c_content' => $sendtext,
'^url' => $sendurl,
));
}
foreach ($params['thread'] as $comment)
if (isset($comment['notify']) && !qa_post_is_by_user($comment, $userid, $cookieid)) {
$senduserid=$comment['userid'];
$sendemail=@$comment['notify'];
if (qa_email_validate($sendemail)) {
if (@$senttoemail[$sendemail])
continue;
$senttoemail[$sendemail]=true;
} elseif (isset($senduserid)) {
if (@$senttouserid[$senduserid])
continue;
$senttouserid[$senduserid]=true;
}
qa_send_notification($senduserid, $sendemail, @$comment['handle'], qa_lang('emails/c_commented_subject'), qa_lang('emails/c_commented_body'), array(
'^c_handle' => $sendhandle,
'^c_context' => $sendcontext,
'^c_content' => $sendtext,
'^url' => $sendurl,
));
}
break;
case 'q_queue':
case 'q_requeue':
if (qa_opt('moderate_notify_admin'))
qa_send_notification(null, qa_opt('feedback_email'), null,
($event=='q_requeue') ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'),
($event=='q_requeue') ? qa_lang('emails/remoderate_body') : qa_lang('emails/moderate_body'),
array(
'^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] :
(strlen(@$oldquestion['name']) ? $oldquestion['name'] : qa_lang('main/anonymous'))),
'^p_context' => trim(@$params['title']."\n\n".$params['text']), // don't censor for admin
'^url' => qa_q_path($params['postid'], $params['title'], true),
'^a_url' => qa_path_absolute('admin/moderate'),
)
);
break;
case 'a_queue':
case 'a_requeue':
if (qa_opt('moderate_notify_admin'))
qa_send_notification(null, qa_opt('feedback_email'), null,
($event=='a_requeue') ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'),
($event=='a_requeue') ? qa_lang('emails/remoderate_body') : qa_lang('emails/moderate_body'),
array(
'^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] :
(strlen(@$oldanswer['name']) ? $oldanswer['name'] : qa_lang('main/anonymous'))),
'^p_context' => $params['text'], // don't censor for admin
'^url' => qa_q_path($params['parentid'], $params['parent']['title'], true, 'A', $params['postid']),
'^a_url' => qa_path_absolute('admin/moderate'),
)
);
break;
case 'c_queue':
case 'c_requeue':
if (qa_opt('moderate_notify_admin'))
qa_send_notification(null, qa_opt('feedback_email'), null,
($event=='c_requeue') ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'),
($event=='c_requeue') ? qa_lang('emails/remoderate_body') : qa_lang('emails/moderate_body'),
array(
'^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] :
(strlen(@$oldcomment['name']) ? $oldcomment['name'] : // could also be after answer converted to comment
(strlen(@$oldanswer['name']) ? $oldanswer['name'] : qa_lang('main/anonymous')))),
'^p_context' => $params['text'], // don't censor for admin
'^url' => qa_q_path($params['questionid'], $params['question']['title'], true, 'C', $params['postid']),
'^a_url' => qa_path_absolute('admin/moderate'),
)
);
break;
case 'q_flag':
case 'a_flag':
case 'c_flag':
$flagcount=$params['flagcount'];
$oldpost=$params['oldpost'];
$notifycount=$flagcount-qa_opt('flagging_notify_first');
if ( ($notifycount>=0) && (($notifycount % qa_opt('flagging_notify_every'))==0) )
qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/flagged_subject'), qa_lang('emails/flagged_body'), array(
'^p_handle' => isset($oldpost['handle']) ? $oldpost['handle'] :
(strlen($oldpost['name']) ? $oldpost['name'] : qa_lang('main/anonymous')),
'^flags' => ($flagcount==1) ? qa_lang_html_sub('main/1_flag', '1', '1') : qa_lang_html_sub('main/x_flags', $flagcount),
'^p_context' => trim(@$oldpost['title']."\n\n".qa_viewer_text($oldpost['content'], $oldpost['format'])), // don't censor for admin
'^url' => qa_q_path($params['questionid'], $params['question']['title'], true, $oldpost['basetype'], $oldpost['postid']),
'^a_url' => qa_path_absolute('admin/flagged'),
));
break;
case 'a_select':
$answer=$params['answer'];
if (isset($answer['notify']) && !qa_post_is_by_user($answer, $userid, $cookieid)) {
$blockwordspreg=qa_get_block_words_preg();
$sendcontent=qa_viewer_text($answer['content'], $answer['format'], array('blockwordspreg' => $blockwordspreg));
qa_send_notification($answer['userid'], $answer['notify'], @$answer['handle'], qa_lang('emails/a_selected_subject'), qa_lang('emails/a_selected_body'), array(
'^s_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'),
'^q_title' => qa_block_words_replace($params['parent']['title'], $blockwordspreg),
'^a_content' => $sendcontent,
break;
case 'q_queue':
case 'q_requeue':
if (qa_opt('moderate_notify_admin'))
qa_send_notification(null, qa_opt('feedback_email'), null,
($event=='q_requeue') ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'),
($event=='q_requeue') ? qa_lang('emails/remoderate_body') : qa_lang('emails/moderate_body'),
array(
'^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] :
(strlen(@$oldquestion['name']) ? $oldquestion['name'] : qa_lang('main/anonymous'))),
'^p_context' => trim(@$params['title']."\n\n".$params['text']), // don't censor for admin
'^url' => qa_q_path($params['postid'], $params['title'], true),
'^a_url' => qa_path_absolute('admin/moderate'),
)
);
break;
case 'a_queue':
case 'a_requeue':
if (qa_opt('moderate_notify_admin'))
qa_send_notification(null, qa_opt('feedback_email'), null,
($event=='a_requeue') ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'),
($event=='a_requeue') ? qa_lang('emails/remoderate_body') : qa_lang('emails/moderate_body'),
array(
'^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] :
(strlen(@$oldanswer['name']) ? $oldanswer['name'] : qa_lang('main/anonymous'))),
'^p_context' => $params['text'], // don't censor for admin
'^url' => qa_q_path($params['parentid'], $params['parent']['title'], true, 'A', $params['postid']),
));
}
break;
case 'u_register':
if (qa_opt('register_notify_admin'))
qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/u_registered_subject'),
qa_opt('moderate_users') ? qa_lang('emails/u_to_approve_body') : qa_lang('emails/u_registered_body'), array(
'^u_handle' => $handle,
'^url' => qa_path_absolute('user/'.$handle),
'^a_url' => qa_path_absolute('admin/approve'),
));
break;
case 'u_level':
if ( ($params['level']>=QA_USER_LEVEL_APPROVED) && ($params['oldlevel']<QA_USER_LEVEL_APPROVED) )
qa_send_notification($params['userid'], null, $params['handle'], qa_lang('emails/u_approved_subject'), qa_lang('emails/u_approved_body'), array(
'^url' => qa_path_absolute('user/'.$params['handle']),
));
break;
case 'u_wall_post':
if ($userid!=$params['userid']) {
$blockwordspreg=qa_get_block_words_preg();
'^a_url' => qa_path_absolute('admin/moderate'),
)
);
break;
case 'c_queue':
case 'c_requeue':
if (qa_opt('moderate_notify_admin'))
qa_send_notification(null, qa_opt('feedback_email'), null,
($event=='c_requeue') ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'),
($event=='c_requeue') ? qa_lang('emails/remoderate_body') : qa_lang('emails/moderate_body'),
array(
'^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] :
(strlen(@$oldcomment['name']) ? $oldcomment['name'] : // could also be after answer converted to comment
(strlen(@$oldanswer['name']) ? $oldanswer['name'] : qa_lang('main/anonymous')))),
'^p_context' => $params['text'], // don't censor for admin
'^url' => qa_q_path($params['questionid'], $params['question']['title'], true, 'C', $params['postid']),
'^a_url' => qa_path_absolute('admin/moderate'),
)
);
break;
case 'q_flag':
case 'a_flag':
case 'c_flag':
$flagcount=$params['flagcount'];
$oldpost=$params['oldpost'];
$notifycount=$flagcount-qa_opt('flagging_notify_first');
if ( ($notifycount>=0) && (($notifycount % qa_opt('flagging_notify_every'))==0) )
qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/flagged_subject'), qa_lang('emails/flagged_body'), array(
'^p_handle' => isset($oldpost['handle']) ? $oldpost['handle'] :
(strlen($oldpost['name']) ? $oldpost['name'] : qa_lang('main/anonymous')),
'^flags' => ($flagcount==1) ? qa_lang_html_sub('main/1_flag', '1', '1') : qa_lang_html_sub('main/x_flags', $flagcount),
'^p_context' => trim(@$oldpost['title']."\n\n".qa_viewer_text($oldpost['content'], $oldpost['format'])), // don't censor for admin
'^url' => qa_q_path($params['questionid'], $params['question']['title'], true, $oldpost['basetype'], $oldpost['postid']),
'^a_url' => qa_path_absolute('admin/flagged'),
));
break;
case 'a_select':
$answer=$params['answer'];
if (isset($answer['notify']) && !qa_post_is_by_user($answer, $userid, $cookieid)) {
$blockwordspreg=qa_get_block_words_preg();
$sendcontent=qa_viewer_text($answer['content'], $answer['format'], array('blockwordspreg' => $blockwordspreg));
qa_send_notification($answer['userid'], $answer['notify'], @$answer['handle'], qa_lang('emails/a_selected_subject'), qa_lang('emails/a_selected_body'), array(
'^s_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'),
'^q_title' => qa_block_words_replace($params['parent']['title'], $blockwordspreg),
'^a_content' => $sendcontent,
'^url' => qa_q_path($params['parentid'], $params['parent']['title'], true, 'A', $params['postid']),
));
}
break;
case 'u_register':
if (qa_opt('register_notify_admin'))
qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/u_registered_subject'),
qa_opt('moderate_users') ? qa_lang('emails/u_to_approve_body') : qa_lang('emails/u_registered_body'), array(
'^u_handle' => $handle,
'^url' => qa_path_absolute('user/'.$handle),
'^a_url' => qa_path_absolute('admin/approve'),
));
break;
case 'u_level':
if ( ($params['level']>=QA_USER_LEVEL_APPROVED) && ($params['oldlevel']<QA_USER_LEVEL_APPROVED) )
qa_send_notification($params['userid'], null, $params['handle'], qa_lang('emails/u_approved_subject'), qa_lang('emails/u_approved_body'), array(
'^url' => qa_path_absolute('user/'.$params['handle']),
));
break;
case 'u_wall_post':
if ($userid!=$params['userid']) {
$blockwordspreg=qa_get_block_words_preg();
qa_send_notification($params['userid'], null, $params['handle'], qa_lang('emails/wall_post_subject'), qa_lang('emails/wall_post_body'), array(
'^f_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'),
'^post' => qa_block_words_replace($params['text'], $blockwordspreg),
'^url' => qa_path_absolute('user/'.$params['handle'], null, 'wall'),
));
}
break;
}
qa_send_notification($params['userid'], null, $params['handle'], qa_lang('emails/wall_post_subject'), qa_lang('emails/wall_post_body'), array(
'^f_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'),
'^post' => qa_block_words_replace($params['text'], $blockwordspreg),
'^url' => qa_path_absolute('user/'.$params['handle'], null, 'wall'),
));
}
break;
}
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
}
......@@ -20,161 +20,149 @@
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_updates {
class qa_event_updates
{
public function process_event($event, $userid, $handle, $cookieid, $params)
{
if (@$params['silent']) // don't create updates about silent edits, and possibly other silent events in future
return;
public function process_event($event, $userid, $handle, $cookieid, $params)
{
if (@$params['silent']) // don't create updates about silent edits, and possibly other silent events in future
return;
require_once QA_INCLUDE_DIR.'db/events.php';
require_once QA_INCLUDE_DIR.'app/events.php';
require_once QA_INCLUDE_DIR.'db/events.php';
require_once QA_INCLUDE_DIR.'app/events.php';
switch ($event) {
case 'q_post':
if (isset($params['parent'])) // question is following an answer
qa_create_event_for_q_user($params['parent']['parentid'], $params['postid'], QA_UPDATE_FOLLOWS, $userid, $params['parent']['userid']);
switch ($event) {
case 'q_post':
if (isset($params['parent'])) // question is following an answer
qa_create_event_for_q_user($params['parent']['parentid'], $params['postid'], QA_UPDATE_FOLLOWS, $userid, $params['parent']['userid']);
qa_create_event_for_q_user($params['postid'], $params['postid'], null, $userid);
qa_create_event_for_tags($params['tags'], $params['postid'], null, $userid);
qa_create_event_for_category($params['categoryid'], $params['postid'], null, $userid);
break;
qa_create_event_for_q_user($params['postid'], $params['postid'], null, $userid);
qa_create_event_for_tags($params['tags'], $params['postid'], null, $userid);
qa_create_event_for_category($params['categoryid'], $params['postid'], null, $userid);
break;
case 'a_post':
qa_create_event_for_q_user($params['parentid'], $params['postid'], null, $userid, $params['parent']['userid']);
break;
case 'a_post':
qa_create_event_for_q_user($params['parentid'], $params['postid'], null, $userid, $params['parent']['userid']);
break;
case 'c_post':
$keyuserids=array();
case 'c_post':
$keyuserids=array();
foreach ($params['thread'] as $comment) // previous comments in thread (but not author of parent again)
if (isset($comment['userid']))
$keyuserids[$comment['userid']]=true;
foreach ($params['thread'] as $comment) // previous comments in thread (but not author of parent again)
if (isset($comment['userid']))
$keyuserids[$comment['userid']]=true;
foreach ($keyuserids as $keyuserid => $dummy)
if ($keyuserid != $userid)
qa_db_event_create_not_entity($keyuserid, $params['questionid'], $params['postid'], QA_UPDATE_FOLLOWS, $userid);
foreach ($keyuserids as $keyuserid => $dummy)
if ($keyuserid != $userid)
qa_db_event_create_not_entity($keyuserid, $params['questionid'], $params['postid'], QA_UPDATE_FOLLOWS, $userid);
switch ($params['parent']['basetype'])
{
case 'Q':
$updatetype=QA_UPDATE_C_FOR_Q;
break;
switch ($params['parent']['basetype'])
{
case 'Q':
$updatetype=QA_UPDATE_C_FOR_Q;
break;
case 'A':
$updatetype=QA_UPDATE_C_FOR_A;
break;
case 'A':
$updatetype=QA_UPDATE_C_FOR_A;
break;
default:
$updatetype=null;
break;
}
default:
$updatetype=null;
break;
}
qa_create_event_for_q_user($params['questionid'], $params['postid'], $updatetype, $userid,
@$keyuserids[$params['parent']['userid']] ? null : $params['parent']['userid']);
// give precedence to 'your comment followed' rather than 'your Q/A commented' if both are true
break;
qa_create_event_for_q_user($params['questionid'], $params['postid'], $updatetype, $userid,
@$keyuserids[$params['parent']['userid']] ? null : $params['parent']['userid']);
// give precedence to 'your comment followed' rather than 'your Q/A commented' if both are true
break;
case 'q_edit':
if ($params['titlechanged'] || $params['contentchanged'])
$updatetype=QA_UPDATE_CONTENT;
elseif ($params['tagschanged'])
$updatetype=QA_UPDATE_TAGS;
else
$updatetype=null;
case 'q_edit':
if ($params['titlechanged'] || $params['contentchanged'])
$updatetype=QA_UPDATE_CONTENT;
elseif ($params['tagschanged'])
$updatetype=QA_UPDATE_TAGS;
else
$updatetype=null;
if (isset($updatetype)) {
qa_create_event_for_q_user($params['postid'], $params['postid'], $updatetype, $userid, $params['oldquestion']['userid']);
if (isset($updatetype)) {
qa_create_event_for_q_user($params['postid'], $params['postid'], $updatetype, $userid, $params['oldquestion']['userid']);
if ($params['tagschanged'])
qa_create_event_for_tags($params['tags'], $params['postid'], QA_UPDATE_TAGS, $userid);
}
break;
if ($params['tagschanged'])
qa_create_event_for_tags($params['tags'], $params['postid'], QA_UPDATE_TAGS, $userid);
}
break;
case 'a_select':
qa_create_event_for_q_user($params['parentid'], $params['postid'], QA_UPDATE_SELECTED, $userid, $params['answer']['userid']);
break;
case 'a_select':
qa_create_event_for_q_user($params['parentid'], $params['postid'], QA_UPDATE_SELECTED, $userid, $params['answer']['userid']);
break;
case 'q_reopen':
case 'q_close':
qa_create_event_for_q_user($params['postid'], $params['postid'], QA_UPDATE_CLOSED, $userid, $params['oldquestion']['userid']);
break;
case 'q_reopen':
case 'q_close':
qa_create_event_for_q_user($params['postid'], $params['postid'], QA_UPDATE_CLOSED, $userid, $params['oldquestion']['userid']);
break;
case 'q_hide':
if (isset($params['oldquestion']['userid']))
qa_db_event_create_not_entity($params['oldquestion']['userid'], $params['postid'], $params['postid'], QA_UPDATE_VISIBLE, $userid);
break;
case 'q_hide':
if (isset($params['oldquestion']['userid']))
qa_db_event_create_not_entity($params['oldquestion']['userid'], $params['postid'], $params['postid'], QA_UPDATE_VISIBLE, $userid);
break;
case 'q_reshow':
qa_create_event_for_q_user($params['postid'], $params['postid'], QA_UPDATE_VISIBLE, $userid, $params['oldquestion']['userid']);
break;
case 'q_reshow':
qa_create_event_for_q_user($params['postid'], $params['postid'], QA_UPDATE_VISIBLE, $userid, $params['oldquestion']['userid']);
break;
case 'q_move':
qa_create_event_for_q_user($params['postid'], $params['postid'], QA_UPDATE_CATEGORY, $userid, $params['oldquestion']['userid']);
qa_create_event_for_category($params['categoryid'], $params['postid'], QA_UPDATE_CATEGORY, $userid);
break;
case 'q_move':
qa_create_event_for_q_user($params['postid'], $params['postid'], QA_UPDATE_CATEGORY, $userid, $params['oldquestion']['userid']);
qa_create_event_for_category($params['categoryid'], $params['postid'], QA_UPDATE_CATEGORY, $userid);
break;
case 'a_edit':
if ($params['contentchanged'])
qa_create_event_for_q_user($params['parentid'], $params['postid'], QA_UPDATE_CONTENT, $userid, $params['oldanswer']['userid']);
break;
case 'a_edit':
if ($params['contentchanged'])
qa_create_event_for_q_user($params['parentid'], $params['postid'], QA_UPDATE_CONTENT, $userid, $params['oldanswer']['userid']);
break;
case 'a_hide':
if (isset($params['oldanswer']['userid']))
qa_db_event_create_not_entity($params['oldanswer']['userid'], $params['parentid'], $params['postid'], QA_UPDATE_VISIBLE, $userid);
break;
case 'a_hide':
if (isset($params['oldanswer']['userid']))
qa_db_event_create_not_entity($params['oldanswer']['userid'], $params['parentid'], $params['postid'], QA_UPDATE_VISIBLE, $userid);
break;
case 'a_reshow':
qa_create_event_for_q_user($params['parentid'], $params['postid'], QA_UPDATE_VISIBLE, $userid, $params['oldanswer']['userid']);
break;
case 'a_reshow':
qa_create_event_for_q_user($params['parentid'], $params['postid'], QA_UPDATE_VISIBLE, $userid, $params['oldanswer']['userid']);
break;
case 'c_edit':
if ($params['contentchanged'])
qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_CONTENT, $userid, $params['oldcomment']['userid']);
break;
case 'c_edit':
if ($params['contentchanged'])
qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_CONTENT, $userid, $params['oldcomment']['userid']);
break;
case 'a_to_c':
if ($params['contentchanged'])
qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_CONTENT, $userid, $params['oldanswer']['userid']);
else
qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_TYPE, $userid, $params['oldanswer']['userid']);
break;
case 'a_to_c':
if ($params['contentchanged'])
qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_CONTENT, $userid, $params['oldanswer']['userid']);
else
qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_TYPE, $userid, $params['oldanswer']['userid']);
break;
case 'c_hide':
if (isset($params['oldcomment']['userid']))
qa_db_event_create_not_entity($params['oldcomment']['userid'], $params['questionid'], $params['postid'], QA_UPDATE_VISIBLE, $userid);
break;
case 'c_hide':
if (isset($params['oldcomment']['userid']))
qa_db_event_create_not_entity($params['oldcomment']['userid'], $params['questionid'], $params['postid'], QA_UPDATE_VISIBLE, $userid);
break;
case 'c_reshow':
qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_VISIBLE, $userid, $params['oldcomment']['userid']);
break;
}
case 'c_reshow':
qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_VISIBLE, $userid, $params['oldcomment']['userid']);
break;
}
}
/*
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,188 +20,181 @@
More about this license: http://www.question2answer.org/license.php
*/
class qa_html_theme_layer extends qa_html_theme_base {
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();
// Utility functions for this layer
// Utility functions for this layer
private 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
private 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;
}
foreach ($postids as $postid)
if (isset($postid) && !isset($this->qa_voters_flaggers_cache[$postid]))
$this->qa_voters_flaggers_queue[$postid]=true;
}
}
private function queue_raw_posts_voters_flaggers($posts)
{
if (is_array($posts))
foreach ($posts as $post)
if (isset($post['raw']))
$this->queue_post_voters_flaggers($post['raw']);
}
private function retrieve_queued_voters_flaggers()
{
if (count($this->qa_voters_flaggers_queue)) {
require_once QA_INCLUDE_DIR.'db/votes.php';
$postids=array_keys($this->qa_voters_flaggers_queue);
private function queue_raw_posts_voters_flaggers($posts)
{
if (is_array($posts))
foreach ($posts as $post)
if (isset($post['raw']))
$this->queue_post_voters_flaggers($post['raw']);
}
foreach ($postids as $postid)
$this->qa_voters_flaggers_cache[$postid]=array();
private function retrieve_queued_voters_flaggers()
{
if (count($this->qa_voters_flaggers_queue)) {
require_once QA_INCLUDE_DIR.'db/votes.php';
$newvotersflaggers=qa_db_uservoteflag_posts_get($postids);
$postids=array_keys($this->qa_voters_flaggers_queue);
if (QA_FINAL_EXTERNAL_USERS) {
$keyuserids=array();
foreach ($newvotersflaggers as $voterflagger)
$keyuserids[$voterflagger['userid']]=true;
foreach ($postids as $postid)
$this->qa_voters_flaggers_cache[$postid]=array();
$useridhandles=qa_get_public_from_userids(array_keys($keyuserids));
foreach ($newvotersflaggers as $index => $voterflagger)
$newvotersflaggers[$index]['handle']=@$useridhandles[$voterflagger['userid']];
}
$newvotersflaggers=qa_db_uservoteflag_posts_get($postids);
if (QA_FINAL_EXTERNAL_USERS) {
$keyuserids=array();
foreach ($newvotersflaggers as $voterflagger)
$this->qa_voters_flaggers_cache[$voterflagger['postid']][]=$voterflagger;
$keyuserids[$voterflagger['userid']]=true;
$this->qa_voters_flaggers_queue=array();
$useridhandles=qa_get_public_from_userids(array_keys($keyuserids));
foreach ($newvotersflaggers as $index => $voterflagger)
$newvotersflaggers[$index]['handle']=@$useridhandles[$voterflagger['userid']];
}
foreach ($newvotersflaggers as $voterflagger)
$this->qa_voters_flaggers_cache[$voterflagger['postid']][]=$voterflagger;
$this->qa_voters_flaggers_queue=array();
}
}
private function get_post_voters_flaggers($post, $postid)
{
require_once QA_INCLUDE_DIR.'qa-util-sort.php';
private function get_post_voters_flaggers($post, $postid)
{
require_once QA_INCLUDE_DIR.'qa-util-sort.php';
if (!isset($this->qa_voters_flaggers_cache[$postid])) {
$this->queue_post_voters_flaggers($post);
$this->retrieve_queued_voters_flaggers();
}
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=@$this->qa_voters_flaggers_cache[$postid];
if (isset($votersflaggers))
qa_sort_by($votersflaggers, 'handle');
if (isset($votersflaggers))
qa_sort_by($votersflaggers, 'handle');
return $votersflaggers;
}
return $votersflaggers;
}
// Collect up all required postids for the entire page to save DB queries - common case where whole page output
// Collect up all required postids for the entire page to save DB queries - common case where whole page output
public function main()
{
foreach ($this->content as $key => $part) {
if (strpos($key, 'q_list')===0)
$this->queue_raw_posts_voters_flaggers(@$part['qs']);
public function main()
{
foreach ($this->content as $key => $part) {
if (strpos($key, 'q_list')===0)
$this->queue_raw_posts_voters_flaggers(@$part['qs']);
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, '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) {
if (!empty($part)) {
$this->queue_raw_posts_voters_flaggers($part['as']);
} 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)
$this->queue_raw_posts_voters_flaggers(@$a_item['c_list']['cs']);
}
}
qa_html_theme_base::main();
}
qa_html_theme_base::main();
}
// Other functions which also collect up required postids for lists to save DB queries - helps with widget output and Ajax calls
public function q_list_items($q_items)
{
$this->queue_raw_posts_voters_flaggers($q_items);
qa_html_theme_base::q_list_items($q_items);
}
// Other functions which also collect up required postids for lists to save DB queries - helps with widget output and Ajax calls
public function a_list_items($a_items)
{
$this->queue_raw_posts_voters_flaggers($a_items);
public function q_list_items($q_items)
{
$this->queue_raw_posts_voters_flaggers($q_items);
qa_html_theme_base::a_list_items($a_items);
}
qa_html_theme_base::q_list_items($q_items);
}
public function c_list_items($c_items)
{
$this->queue_raw_posts_voters_flaggers($c_items);
public function a_list_items($a_items)
{
$this->queue_raw_posts_voters_flaggers($a_items);
qa_html_theme_base::c_list_items($c_items);
}
qa_html_theme_base::a_list_items($a_items);
}
public function c_list_items($c_items)
{
$this->queue_raw_posts_voters_flaggers($c_items);
// Actual output of the voters and flaggers
qa_html_theme_base::c_list_items($c_items);
}
public function vote_count($post)
{
$votersflaggers=$this->get_post_voters_flaggers($post['raw'], @$post['vote_opostid'] ? $post['raw']['opostid'] : $post['raw']['postid']);
$tooltip='';
// Actual output of the voters and flaggers
if (isset($votersflaggers)) {
$uphandles='';
$downhandles='';
public function vote_count($post)
{
$votersflaggers=$this->get_post_voters_flaggers($post['raw'], @$post['vote_opostid'] ? $post['raw']['opostid'] : $post['raw']['postid']);
foreach ($votersflaggers as $voterflagger) {
if ($voterflagger['vote']>0)
$uphandles.=(strlen($uphandles) ? ', ' : '').qa_html($voterflagger['handle']);
$tooltip='';
if ($voterflagger['vote']<0)
$downhandles.=(strlen($downhandles) ? ', ' : '').qa_html($voterflagger['handle']);
if (isset($votersflaggers)) {
$uphandles='';
$downhandles='';
$tooltip=trim((strlen($uphandles) ? ('&uarr; '.$uphandles) : '')."\n\n".(strlen($downhandles) ? ('&darr; '.$downhandles) : ''));
}
}
foreach ($votersflaggers as $voterflagger) {
if ($voterflagger['vote']>0)
$uphandles.=(strlen($uphandles) ? ', ' : '').qa_html($voterflagger['handle']);
$post['vote_count_tags']=@$post['vote_count_tags'].' title="'.$tooltip.'"';
if ($voterflagger['vote']<0)
$downhandles.=(strlen($downhandles) ? ', ' : '').qa_html($voterflagger['handle']);
qa_html_theme_base::vote_count($post);
$tooltip=trim((strlen($uphandles) ? ('&uarr; '.$uphandles) : '')."\n\n".(strlen($downhandles) ? ('&darr; '.$downhandles) : ''));
}
}
$post['vote_count_tags']=@$post['vote_count_tags'].' title="'.$tooltip.'"';
public function post_meta_flags($post, $class)
{
$postid=@$post['raw']['opostid'];
if (!isset($postid))
$postid=@$post['raw']['postid'];
$tooltip='';
if (isset($postid)) {
$votersflaggers=$this->get_post_voters_flaggers($post, $postid);
qa_html_theme_base::vote_count($post);
}
if (isset($votersflaggers))
foreach ($votersflaggers as $voterflagger)
if ($voterflagger['flag']>0)
$tooltip.=(strlen($tooltip) ? ', ' : '').qa_html($voterflagger['handle']);
}
public function post_meta_flags($post, $class)
{
$postid=@$post['raw']['opostid'];
if (!isset($postid))
$postid=@$post['raw']['postid'];
if (strlen($tooltip))
$this->output('<span title="&#9873; '.$tooltip.'">');
$tooltip='';
qa_html_theme_base::post_meta_flags($post, $class);
if (isset($postid)) {
$votersflaggers=$this->get_post_voters_flaggers($post, $postid);
if (strlen($tooltip))
$this->output('</span>');
if (isset($votersflaggers))
foreach ($votersflaggers as $voterflagger)
if ($voterflagger['flag']>0)
$tooltip.=(strlen($tooltip) ? ', ' : '').qa_html($voterflagger['handle']);
}
}
if (strlen($tooltip))
$this->output('<span title="&#9873; '.$tooltip.'">');
qa_html_theme_base::post_meta_flags($post, $class);
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
if (strlen($tooltip))
$this->output('</span>');
}
}
......@@ -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,167 +20,152 @@
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_viewer_basic {
class qa_viewer_basic
{
private $htmllineseparators;
private $htmlparagraphseparators;
private $htmllineseparators;
private $htmlparagraphseparators;
public function load_module($localdir, $htmldir)
{
$this->htmllineseparators='br|option';
$this->htmlparagraphseparators='address|applet|blockquote|center|cite|col|div|dd|dl|dt|embed|form|frame|frameset|h1|h2|h3|h4|h5|h6'.
'|hr|iframe|input|li|marquee|ol|p|pre|samp|select|spacer|table|tbody|td|textarea|tfoot|th|thead|tr|ul';
}
public function load_module($localdir, $htmldir)
{
$this->htmllineseparators='br|option';
$this->htmlparagraphseparators='address|applet|blockquote|center|cite|col|div|dd|dl|dt|embed|form|frame|frameset|h1|h2|h3|h4|h5|h6'.
'|hr|iframe|input|li|marquee|ol|p|pre|samp|select|spacer|table|tbody|td|textarea|tfoot|th|thead|tr|ul';
}
public function calc_quality($content, $format)
{
if ( ($format=='') || ($format=='html') )
return 1.0;
return 0.0001; // if there's nothing better this will give an error message for unknown formats
}
public function calc_quality($content, $format)
{
if ( ($format=='') || ($format=='html') )
return 1.0;
return 0.0001; // if there's nothing better this will give an error message for unknown formats
}
public function get_html($content, $format, $options)
{
if ($format=='html') {
$html=qa_sanitize_html($content, @$options['linksnewwindow'], false); // sanitize again for display, for extra safety, and due to new window setting
public function get_html($content, $format, $options)
{
if ($format=='html') {
$html=qa_sanitize_html($content, @$options['linksnewwindow'], false); // sanitize again for display, for extra safety, and due to new window setting
if (isset($options['blockwordspreg'])) { // filtering out blocked words inline within HTML is pretty complex, e.g. p<b>oo</b>p must be caught
require_once QA_INCLUDE_DIR.'qa-util-string.php';
if (isset($options['blockwordspreg'])) { // filtering out blocked words inline within HTML is pretty complex, e.g. p<b>oo</b>p must be caught
require_once QA_INCLUDE_DIR.'qa-util-string.php';
$html=preg_replace('/<\s*('.$this->htmllineseparators.')[^A-Za-z0-9]/i', "\n\\0", $html); // tags to single new line
$html=preg_replace('/<\s*('.$this->htmlparagraphseparators.')[^A-Za-z0-9]/i', "\n\n\\0", $html); // tags to double new line
$html=preg_replace('/<\s*('.$this->htmllineseparators.')[^A-Za-z0-9]/i', "\n\\0", $html); // tags to single new line
$html=preg_replace('/<\s*('.$this->htmlparagraphseparators.')[^A-Za-z0-9]/i', "\n\n\\0", $html); // tags to double new line
preg_match_all('/<[^>]*>/', $html, $pregmatches, PREG_OFFSET_CAPTURE); // find tag positions and lengths
$tagmatches=$pregmatches[0];
$text=preg_replace('/<[^>]*>/', '', $html); // effectively strip_tags() but use same regexp as above to ensure consistency
preg_match_all('/<[^>]*>/', $html, $pregmatches, PREG_OFFSET_CAPTURE); // find tag positions and lengths
$tagmatches=$pregmatches[0];
$text=preg_replace('/<[^>]*>/', '', $html); // effectively strip_tags() but use same regexp as above to ensure consistency
$blockmatches=qa_block_words_match_all($text, $options['blockwordspreg']); // search for blocked words within text
$blockmatches=qa_block_words_match_all($text, $options['blockwordspreg']); // search for blocked words within text
$nexttagmatch=array_shift($tagmatches);
$texttohtml=0;
$htmlshift=0;
$nexttagmatch=array_shift($tagmatches);
$texttohtml=0;
$htmlshift=0;
foreach ($blockmatches as $textoffset => $textlength) {
while ( isset($nexttagmatch) && ($nexttagmatch[1]<=($textoffset+$texttohtml)) ) { // keep text and html in sync
$texttohtml+=strlen($nexttagmatch[0]);
$nexttagmatch=array_shift($tagmatches);
}
foreach ($blockmatches as $textoffset => $textlength) {
while ( isset($nexttagmatch) && ($nexttagmatch[1]<=($textoffset+$texttohtml)) ) { // keep text and html in sync
$texttohtml+=strlen($nexttagmatch[0]);
$nexttagmatch=array_shift($tagmatches);
}
while (1) {
$replacepart=$textlength;
if (isset($nexttagmatch))
$replacepart=min($replacepart, $nexttagmatch[1]-($textoffset+$texttohtml)); // stop replacing early if we hit an HTML tag
while (1) {
$replacepart=$textlength;
if (isset($nexttagmatch))
$replacepart=min($replacepart, $nexttagmatch[1]-($textoffset+$texttohtml)); // stop replacing early if we hit an HTML tag
$replacelength=qa_strlen(substr($text, $textoffset, $replacepart)); // to work with multi-byte characters
$replacelength=qa_strlen(substr($text, $textoffset, $replacepart)); // to work with multi-byte characters
$html=substr_replace($html, str_repeat('*', $replacelength), $textoffset+$texttohtml+$htmlshift, $replacepart);
$htmlshift+=$replacelength-$replacepart; // HTML might have moved around if we replaced multi-byte characters
$html=substr_replace($html, str_repeat('*', $replacelength), $textoffset+$texttohtml+$htmlshift, $replacepart);
$htmlshift+=$replacelength-$replacepart; // HTML might have moved around if we replaced multi-byte characters
if ($replacepart>=$textlength)
break; // we have replaced everything expected, otherwise more left (due to hitting an HTML tag)
if ($replacepart>=$textlength)
break; // we have replaced everything expected, otherwise more left (due to hitting an HTML tag)
$textlength-=$replacepart;
$textoffset+=$replacepart;
$texttohtml+=strlen($nexttagmatch[0]);
$nexttagmatch=array_shift($tagmatches);
}
$textlength-=$replacepart;
$textoffset+=$replacepart;
$texttohtml+=strlen($nexttagmatch[0]);
$nexttagmatch=array_shift($tagmatches);
}
}
}
if (@$options['showurllinks']) { // we need to ensure here that we don't put new links inside existing ones
require_once QA_INCLUDE_DIR.'qa-util-string.php';
if (@$options['showurllinks']) { // we need to ensure here that we don't put new links inside existing ones
require_once QA_INCLUDE_DIR.'qa-util-string.php';
$htmlunlinkeds=array_reverse(preg_split('|<[Aa]\s+[^>]+>.*</[Aa]\s*>|', $html, -1, PREG_SPLIT_OFFSET_CAPTURE)); // start from end so we substitute correctly
$htmlunlinkeds=array_reverse(preg_split('|<[Aa]\s+[^>]+>.*</[Aa]\s*>|', $html, -1, PREG_SPLIT_OFFSET_CAPTURE)); // start from end so we substitute correctly
foreach ($htmlunlinkeds as $htmlunlinked) { // and that we don't detect links inside HTML, e.g. <img src="http://...">
$thishtmluntaggeds=array_reverse(preg_split('/<[^>]*>/', $htmlunlinked[0], -1, PREG_SPLIT_OFFSET_CAPTURE)); // again, start from end
foreach ($htmlunlinkeds as $htmlunlinked) { // and that we don't detect links inside HTML, e.g. <img src="http://...">
$thishtmluntaggeds=array_reverse(preg_split('/<[^>]*>/', $htmlunlinked[0], -1, PREG_SPLIT_OFFSET_CAPTURE)); // again, start from end
foreach ($thishtmluntaggeds as $thishtmluntagged) {
$innerhtml=$thishtmluntagged[0];
foreach ($thishtmluntaggeds as $thishtmluntagged) {
$innerhtml=$thishtmluntagged[0];
if (is_numeric(strpos($innerhtml, '://'))) { // quick test first
$newhtml=qa_html_convert_urls($innerhtml, qa_opt('links_in_new_window'));
if (is_numeric(strpos($innerhtml, '://'))) { // quick test first
$newhtml=qa_html_convert_urls($innerhtml, qa_opt('links_in_new_window'));
$html=substr_replace($html, $newhtml, $htmlunlinked[1]+$thishtmluntagged[1], strlen($innerhtml));
}
$html=substr_replace($html, $newhtml, $htmlunlinked[1]+$thishtmluntagged[1], strlen($innerhtml));
}
}
}
}
elseif ($format=='') {
if (isset($options['blockwordspreg'])) {
require_once QA_INCLUDE_DIR.'qa-util-string.php';
$content=qa_block_words_replace($content, $options['blockwordspreg']);
}
$html=qa_html($content, true);
}
elseif ($format=='') {
if (isset($options['blockwordspreg'])) {
require_once QA_INCLUDE_DIR.'qa-util-string.php';
$content=qa_block_words_replace($content, $options['blockwordspreg']);
}
if (@$options['showurllinks']) {
require_once QA_INCLUDE_DIR.'app/format.php';
$html=qa_html_convert_urls($html, qa_opt('links_in_new_window'));
}
$html=qa_html($content, true);
if (@$options['showurllinks']) {
require_once QA_INCLUDE_DIR.'app/format.php';
$html=qa_html_convert_urls($html, qa_opt('links_in_new_window'));
}
else
$html='[no viewer found for format: '.qa_html($format).']'; // for unknown formats
return $html;
}
else
$html='[no viewer found for format: '.qa_html($format).']'; // for unknown formats
return $html;
}
public function get_text($content, $format, $options)
{
if ($format=='html') {
$text=strtr($content, "\n\r\t", ' '); // convert all white space in HTML to spaces
$text=preg_replace('/<\s*('.$this->htmllineseparators.')[^A-Za-z0-9]/i', "\n\\0", $text); // tags to single new line
$text=preg_replace('/<\s*('.$this->htmlparagraphseparators.')[^A-Za-z0-9]/i', "\n\n\\0", $text); // tags to double new line
$text=strip_tags($text); // all tags removed
$text=preg_replace('/ +/', ' ', $text); // combine multiple spaces into one
$text=preg_replace('/ *\n */', "\n", $text); // remove spaces either side new lines
$text=preg_replace('/\n\n\n+/', "\n\n", $text); // more than two new lines combine into two
$text=strtr($text, array(
'&#34;' => "\x22",
'&#38;' => "\x26",
'&#39;' => "\x27",
'&#60;' => "\x3C",
'&#62;' => "\x3E",
'&nbsp;' => " ",
'&quot;' => "\x22",
'&amp;' => "\x26",
'&lt;' => "\x3C",
'&gt;' => "\x3E",
)); // base HTML entities (others should not be stored in database)
$text=trim($text);
}
elseif ($format=='')
$text=$content;
else
$text='[no viewer found for format: '.$format.']'; // for unknown formats
if (isset($options['blockwordspreg'])) {
require_once QA_INCLUDE_DIR.'qa-util-string.php';
$text=qa_block_words_replace($text, $options['blockwordspreg']);
}
public function get_text($content, $format, $options)
{
if ($format=='html') {
$text=strtr($content, "\n\r\t", ' '); // convert all white space in HTML to spaces
$text=preg_replace('/<\s*('.$this->htmllineseparators.')[^A-Za-z0-9]/i', "\n\\0", $text); // tags to single new line
$text=preg_replace('/<\s*('.$this->htmlparagraphseparators.')[^A-Za-z0-9]/i', "\n\n\\0", $text); // tags to double new line
$text=strip_tags($text); // all tags removed
$text=preg_replace('/ +/', ' ', $text); // combine multiple spaces into one
$text=preg_replace('/ *\n */', "\n", $text); // remove spaces either side new lines
$text=preg_replace('/\n\n\n+/', "\n\n", $text); // more than two new lines combine into two
$text=strtr($text, array(
'&#34;' => "\x22",
'&#38;' => "\x26",
'&#39;' => "\x27",
'&#60;' => "\x3C",
'&#62;' => "\x3E",
'&nbsp;' => " ",
'&quot;' => "\x22",
'&amp;' => "\x26",
'&lt;' => "\x3C",
'&gt;' => "\x3E",
)); // base HTML entities (others should not be stored in database)
$text=trim($text);
return $text;
}
elseif ($format=='')
$text=$content;
else
$text='[no viewer found for format: '.$format.']'; // for unknown formats
if (isset($options['blockwordspreg'])) {
require_once QA_INCLUDE_DIR.'qa-util-string.php';
$text=qa_block_words_replace($text, $options['blockwordspreg']);
}
return $text;
}
/*
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