Commit 4a51a213 by Scott

Coding style (core plugins)

parent 7ebb9fa6
...@@ -20,58 +20,43 @@ ...@@ -20,58 +20,43 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser class qa_editor_basic
header('Location: ../'); {
exit; public function load_module($localdir, $htmldir)
{
} }
public function calc_quality($content, $format)
{
if ($format=='')
return 1.0;
class qa_editor_basic { if ($format=='html')
return 0.2;
public function load_module($localdir, $htmldir) return 0;
{ }
}
public function calc_quality($content, $format)
{
if ($format=='')
return 1.0;
if ($format=='html')
return 0.2;
return 0;
}
public function get_field(&$qa_content, $content, $format, $fieldname, $rows /* $autofocus parameter deprecated */)
{
return array(
'type' => 'textarea',
'tags' => 'name="'.$fieldname.'" id="'.$fieldname.'"',
'value' => qa_html($content),
'rows' => $rows,
);
}
public function focus_script($fieldname)
{
return "document.getElementById('".$fieldname."').focus();";
}
public function read_post($fieldname)
{
return array(
'format' => '',
'content' => qa_post_text($fieldname),
);
}
public function get_field(&$qa_content, $content, $format, $fieldname, $rows /* $autofocus parameter deprecated */)
{
return array(
'type' => 'textarea',
'tags' => 'name="'.$fieldname.'" id="'.$fieldname.'"',
'value' => qa_html($content),
'rows' => $rows,
);
} }
public function focus_script($fieldname)
{
return "document.getElementById('".$fieldname."').focus();";
}
/* public function read_post($fieldname)
Omit PHP closing tag to help avoid accidental output {
*/ return array(
\ No newline at end of file 'format' => '',
'content' => qa_post_text($fieldname),
);
}
}
...@@ -20,97 +20,84 @@ ...@@ -20,97 +20,84 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser class qa_event_limits
header('Location: ../'); {
exit; public function process_event($event, $userid, $handle, $cookieid, $params)
} {
// Don't increment limits or report user actions for events that were delayed. For example, a 'q_post'
// event sent when a post is approved by the admin, for which a 'q_queue' event was already sent.
class qa_event_limits {
if (isset($params['delayed']))
public function process_event($event, $userid, $handle, $cookieid, $params) return;
{
// Don't increment limits or report user actions for events that were delayed. For example, a 'q_post' require_once QA_INCLUDE_DIR.'app/limits.php';
// event sent when a post is approved by the admin, for which a 'q_queue' event was already sent.
switch ($event) {
if (isset($params['delayed'])) case 'q_queue':
return; case 'q_post':
case 'q_claim':
require_once QA_INCLUDE_DIR.'app/limits.php'; qa_limits_increment($userid, QA_LIMIT_QUESTIONS);
break;
switch ($event) {
case 'q_queue': case 'a_queue':
case 'q_post': case 'a_post':
case 'q_claim': case 'a_claim':
qa_limits_increment($userid, QA_LIMIT_QUESTIONS); qa_limits_increment($userid, QA_LIMIT_ANSWERS);
break; break;
case 'a_queue': case 'c_queue':
case 'a_post': case 'c_post':
case 'a_claim': case 'c_claim':
qa_limits_increment($userid, QA_LIMIT_ANSWERS); case 'a_to_c':
break; qa_limits_increment($userid, QA_LIMIT_COMMENTS);
break;
case 'c_queue':
case 'c_post': case 'q_vote_up':
case 'c_claim': case 'q_vote_down':
case 'a_to_c': case 'q_vote_nil':
qa_limits_increment($userid, QA_LIMIT_COMMENTS); case 'a_vote_up':
break; case 'a_vote_down':
case 'a_vote_nil':
case 'q_vote_up': qa_limits_increment($userid, QA_LIMIT_VOTES);
case 'q_vote_down': break;
case 'q_vote_nil':
case 'a_vote_up': case 'q_flag':
case 'a_vote_down': case 'a_flag':
case 'a_vote_nil': case 'c_flag':
qa_limits_increment($userid, QA_LIMIT_VOTES); qa_limits_increment($userid, QA_LIMIT_FLAGS);
break; break;
case 'q_flag': case 'u_message':
case 'a_flag': qa_limits_increment($userid, QA_LIMIT_MESSAGES);
case 'c_flag': break;
qa_limits_increment($userid, QA_LIMIT_FLAGS);
break; case 'u_wall_post':
qa_limits_increment($userid, QA_LIMIT_WALL_POSTS);
case 'u_message': break;
qa_limits_increment($userid, QA_LIMIT_MESSAGES); }
break;
case 'u_wall_post':
qa_limits_increment($userid, QA_LIMIT_WALL_POSTS);
break;
}
$writeactions=array( $writeactions=array(
'_approve', '_claim', '_clearflags', '_delete', '_edit', '_favorite', '_flag', '_hide', '_approve', '_claim', '_clearflags', '_delete', '_edit', '_favorite', '_flag', '_hide',
'_post', '_queue', '_reject', '_reshow', '_unfavorite', '_unflag', '_vote_down', '_vote_nil', '_vote_up', '_post', '_queue', '_reject', '_reshow', '_unfavorite', '_unflag', '_vote_down', '_vote_nil', '_vote_up',
'a_select', 'a_to_c', 'a_unselect', 'a_select', 'a_to_c', 'a_unselect',
'q_close', 'q_move', 'q_reopen', 'q_close', 'q_move', 'q_reopen',
'u_block', 'u_edit', 'u_level', 'u_message', 'u_password', 'u_save', 'u_unblock', 'u_block', 'u_edit', 'u_level', 'u_message', 'u_password', 'u_save', 'u_unblock',
); );
if ( if (
is_numeric(array_search(strstr($event, '_'), $writeactions)) || is_numeric(array_search(strstr($event, '_'), $writeactions)) ||
is_numeric(array_search($event, $writeactions)) is_numeric(array_search($event, $writeactions))
) { ) {
if (isset($userid)) { if (isset($userid)) {
require_once QA_INCLUDE_DIR.'app/users.php'; require_once QA_INCLUDE_DIR.'app/users.php';
qa_user_report_action($userid, $event); qa_user_report_action($userid, $event);
} elseif (isset($cookieid)) { } elseif (isset($cookieid)) {
require_once QA_INCLUDE_DIR.'app/cookies.php'; require_once QA_INCLUDE_DIR.'app/cookies.php';
qa_cookie_report_action($cookieid, $event); qa_cookie_report_action($cookieid, $event);
}
} }
} }
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,255 +20,246 @@ ...@@ -20,255 +20,246 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser class qa_event_notify
header('Location: ../'); {
exit; 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';
class qa_event_notify { require_once QA_INCLUDE_DIR.'qa-util-string.php';
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),
));
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': if (isset($followanswer['notify']) && !qa_post_is_by_user($followanswer, $userid, $cookieid)) {
$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(); $blockwordspreg=qa_get_block_words_preg();
$sendhandle=isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous')); $sendtext=qa_viewer_text($followanswer['content'], $followanswer['format'], array('blockwordspreg' => $blockwordspreg));
$sendcontext=qa_block_words_replace($context, $blockwordspreg);
$sendtext=qa_block_words_replace($params['text'], $blockwordspreg); qa_send_notification($followanswer['userid'], $followanswer['notify'], @$followanswer['handle'], qa_lang('emails/a_followed_subject'), qa_lang('emails/a_followed_body'), array(
$sendurl=qa_q_path($question['postid'], $question['title'], true, 'C', $params['postid']); '^q_handle' => $sendhandle,
'^q_title' => qa_block_words_replace($params['title'], $blockwordspreg),
if (isset($parent['notify']) && !qa_post_is_by_user($parent, $userid, $cookieid)) { '^a_content' => $sendtext,
$senduserid=$parent['userid']; '^url' => qa_q_path($params['postid'], $params['title'], true),
$sendemail=@$parent['notify']; ));
}
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; $senttoemail[$sendemail]=true;
elseif (isset($senduserid))
} elseif (isset($senduserid)) {
if (@$senttouserid[$senduserid])
continue;
$senttouserid[$senduserid]=true; $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_handle' => $sendhandle,
'^c_context' => $sendcontext, '^c_context' => $sendcontext,
'^c_content' => $sendtext, '^c_content' => $sendtext,
'^url' => $sendurl, '^url' => $sendurl,
)); ));
} }
break;
foreach ($params['thread'] as $comment)
if (isset($comment['notify']) && !qa_post_is_by_user($comment, $userid, $cookieid)) {
$senduserid=$comment['userid']; case 'q_queue':
$sendemail=@$comment['notify']; case 'q_requeue':
if (qa_opt('moderate_notify_admin'))
if (qa_email_validate($sendemail)) { qa_send_notification(null, qa_opt('feedback_email'), null,
if (@$senttoemail[$sendemail]) ($event=='q_requeue') ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'),
continue; ($event=='q_requeue') ? qa_lang('emails/remoderate_body') : qa_lang('emails/moderate_body'),
array(
$senttoemail[$sendemail]=true; '^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] :
(strlen(@$oldquestion['name']) ? $oldquestion['name'] : qa_lang('main/anonymous'))),
} elseif (isset($senduserid)) { '^p_context' => trim(@$params['title']."\n\n".$params['text']), // don't censor for admin
if (@$senttouserid[$senduserid]) '^url' => qa_q_path($params['postid'], $params['title'], true),
continue; '^a_url' => qa_path_absolute('admin/moderate'),
)
$senttouserid[$senduserid]=true; );
} break;
qa_send_notification($senduserid, $sendemail, @$comment['handle'], qa_lang('emails/c_commented_subject'), qa_lang('emails/c_commented_body'), array(
'^c_handle' => $sendhandle, case 'a_queue':
'^c_context' => $sendcontext, case 'a_requeue':
'^c_content' => $sendtext, if (qa_opt('moderate_notify_admin'))
'^url' => $sendurl, 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'),
break; array(
'^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] :
(strlen(@$oldanswer['name']) ? $oldanswer['name'] : qa_lang('main/anonymous'))),
case 'q_queue': '^p_context' => $params['text'], // don't censor for admin
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,
'^url' => qa_q_path($params['parentid'], $params['parent']['title'], true, 'A', $params['postid']), '^url' => qa_q_path($params['parentid'], $params['parent']['title'], true, 'A', $params['postid']),
)); '^a_url' => qa_path_absolute('admin/moderate'),
} )
break; );
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'), case 'c_queue':
qa_opt('moderate_users') ? qa_lang('emails/u_to_approve_body') : qa_lang('emails/u_registered_body'), array( case 'c_requeue':
'^u_handle' => $handle, if (qa_opt('moderate_notify_admin'))
'^url' => qa_path_absolute('user/'.$handle), qa_send_notification(null, qa_opt('feedback_email'), null,
'^a_url' => qa_path_absolute('admin/approve'), ($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'),
break; array(
'^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] :
case 'u_level': (strlen(@$oldcomment['name']) ? $oldcomment['name'] : // could also be after answer converted to comment
if ( ($params['level']>=QA_USER_LEVEL_APPROVED) && ($params['oldlevel']<QA_USER_LEVEL_APPROVED) ) (strlen(@$oldanswer['name']) ? $oldanswer['name'] : qa_lang('main/anonymous')))),
qa_send_notification($params['userid'], null, $params['handle'], qa_lang('emails/u_approved_subject'), qa_lang('emails/u_approved_body'), array( '^p_context' => $params['text'], // don't censor for admin
'^url' => qa_path_absolute('user/'.$params['handle']), '^url' => qa_q_path($params['questionid'], $params['question']['title'], true, 'C', $params['postid']),
)); '^a_url' => qa_path_absolute('admin/moderate'),
break; )
);
case 'u_wall_post': break;
if ($userid!=$params['userid']) {
$blockwordspreg=qa_get_block_words_preg();
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( 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'), '^f_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'),
'^post' => qa_block_words_replace($params['text'], $blockwordspreg), '^post' => qa_block_words_replace($params['text'], $blockwordspreg),
'^url' => qa_path_absolute('user/'.$params['handle'], null, 'wall'), '^url' => qa_path_absolute('user/'.$params['handle'], null, 'wall'),
)); ));
} }
break; break;
}
} }
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,161 +20,149 @@ ...@@ -20,161 +20,149 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser class qa_event_updates
header('Location: ../'); {
exit; 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;
class qa_event_updates {
public function process_event($event, $userid, $handle, $cookieid, $params) require_once QA_INCLUDE_DIR.'db/events.php';
{ require_once QA_INCLUDE_DIR.'app/events.php';
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'; switch ($event) {
require_once QA_INCLUDE_DIR.'app/events.php'; 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) { qa_create_event_for_q_user($params['postid'], $params['postid'], null, $userid);
case 'q_post': qa_create_event_for_tags($params['tags'], $params['postid'], null, $userid);
if (isset($params['parent'])) // question is following an answer qa_create_event_for_category($params['categoryid'], $params['postid'], null, $userid);
qa_create_event_for_q_user($params['parent']['parentid'], $params['postid'], QA_UPDATE_FOLLOWS, $userid, $params['parent']['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': foreach ($params['thread'] as $comment) // previous comments in thread (but not author of parent again)
$keyuserids=array(); if (isset($comment['userid']))
$keyuserids[$comment['userid']]=true;
foreach ($params['thread'] as $comment) // previous comments in thread (but not author of parent again) foreach ($keyuserids as $keyuserid => $dummy)
if (isset($comment['userid'])) if ($keyuserid != $userid)
$keyuserids[$comment['userid']]=true; qa_db_event_create_not_entity($keyuserid, $params['questionid'], $params['postid'], QA_UPDATE_FOLLOWS, $userid);
foreach ($keyuserids as $keyuserid => $dummy) switch ($params['parent']['basetype'])
if ($keyuserid != $userid) {
qa_db_event_create_not_entity($keyuserid, $params['questionid'], $params['postid'], QA_UPDATE_FOLLOWS, $userid); case 'Q':
$updatetype=QA_UPDATE_C_FOR_Q;
break;
switch ($params['parent']['basetype']) case 'A':
{ $updatetype=QA_UPDATE_C_FOR_A;
case 'Q': break;
$updatetype=QA_UPDATE_C_FOR_Q;
break;
case 'A': default:
$updatetype=QA_UPDATE_C_FOR_A; $updatetype=null;
break; break;
}
default:
$updatetype=null;
break;
}
qa_create_event_for_q_user($params['questionid'], $params['postid'], $updatetype, $userid, qa_create_event_for_q_user($params['questionid'], $params['postid'], $updatetype, $userid,
@$keyuserids[$params['parent']['userid']] ? null : $params['parent']['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 // give precedence to 'your comment followed' rather than 'your Q/A commented' if both are true
break; break;
case 'q_edit': case 'q_edit':
if ($params['titlechanged'] || $params['contentchanged']) if ($params['titlechanged'] || $params['contentchanged'])
$updatetype=QA_UPDATE_CONTENT; $updatetype=QA_UPDATE_CONTENT;
elseif ($params['tagschanged']) elseif ($params['tagschanged'])
$updatetype=QA_UPDATE_TAGS; $updatetype=QA_UPDATE_TAGS;
else else
$updatetype=null; $updatetype=null;
if (isset($updatetype)) { if (isset($updatetype)) {
qa_create_event_for_q_user($params['postid'], $params['postid'], $updatetype, $userid, $params['oldquestion']['userid']); qa_create_event_for_q_user($params['postid'], $params['postid'], $updatetype, $userid, $params['oldquestion']['userid']);
if ($params['tagschanged']) if ($params['tagschanged'])
qa_create_event_for_tags($params['tags'], $params['postid'], QA_UPDATE_TAGS, $userid); qa_create_event_for_tags($params['tags'], $params['postid'], QA_UPDATE_TAGS, $userid);
} }
break; break;
case 'a_select': case 'a_select':
qa_create_event_for_q_user($params['parentid'], $params['postid'], QA_UPDATE_SELECTED, $userid, $params['answer']['userid']); qa_create_event_for_q_user($params['parentid'], $params['postid'], QA_UPDATE_SELECTED, $userid, $params['answer']['userid']);
break; break;
case 'q_reopen': case 'q_reopen':
case 'q_close': case 'q_close':
qa_create_event_for_q_user($params['postid'], $params['postid'], QA_UPDATE_CLOSED, $userid, $params['oldquestion']['userid']); qa_create_event_for_q_user($params['postid'], $params['postid'], QA_UPDATE_CLOSED, $userid, $params['oldquestion']['userid']);
break; break;
case 'q_hide': case 'q_hide':
if (isset($params['oldquestion']['userid'])) if (isset($params['oldquestion']['userid']))
qa_db_event_create_not_entity($params['oldquestion']['userid'], $params['postid'], $params['postid'], QA_UPDATE_VISIBLE, $userid); qa_db_event_create_not_entity($params['oldquestion']['userid'], $params['postid'], $params['postid'], QA_UPDATE_VISIBLE, $userid);
break; break;
case 'q_reshow': case 'q_reshow':
qa_create_event_for_q_user($params['postid'], $params['postid'], QA_UPDATE_VISIBLE, $userid, $params['oldquestion']['userid']); qa_create_event_for_q_user($params['postid'], $params['postid'], QA_UPDATE_VISIBLE, $userid, $params['oldquestion']['userid']);
break; break;
case 'q_move': case 'q_move':
qa_create_event_for_q_user($params['postid'], $params['postid'], QA_UPDATE_CATEGORY, $userid, $params['oldquestion']['userid']); 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); qa_create_event_for_category($params['categoryid'], $params['postid'], QA_UPDATE_CATEGORY, $userid);
break; break;
case 'a_edit': case 'a_edit':
if ($params['contentchanged']) if ($params['contentchanged'])
qa_create_event_for_q_user($params['parentid'], $params['postid'], QA_UPDATE_CONTENT, $userid, $params['oldanswer']['userid']); qa_create_event_for_q_user($params['parentid'], $params['postid'], QA_UPDATE_CONTENT, $userid, $params['oldanswer']['userid']);
break; break;
case 'a_hide': case 'a_hide':
if (isset($params['oldanswer']['userid'])) if (isset($params['oldanswer']['userid']))
qa_db_event_create_not_entity($params['oldanswer']['userid'], $params['parentid'], $params['postid'], QA_UPDATE_VISIBLE, $userid); qa_db_event_create_not_entity($params['oldanswer']['userid'], $params['parentid'], $params['postid'], QA_UPDATE_VISIBLE, $userid);
break; break;
case 'a_reshow': case 'a_reshow':
qa_create_event_for_q_user($params['parentid'], $params['postid'], QA_UPDATE_VISIBLE, $userid, $params['oldanswer']['userid']); qa_create_event_for_q_user($params['parentid'], $params['postid'], QA_UPDATE_VISIBLE, $userid, $params['oldanswer']['userid']);
break; break;
case 'c_edit': case 'c_edit':
if ($params['contentchanged']) if ($params['contentchanged'])
qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_CONTENT, $userid, $params['oldcomment']['userid']); qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_CONTENT, $userid, $params['oldcomment']['userid']);
break; break;
case 'a_to_c': case 'a_to_c':
if ($params['contentchanged']) if ($params['contentchanged'])
qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_CONTENT, $userid, $params['oldanswer']['userid']); qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_CONTENT, $userid, $params['oldanswer']['userid']);
else else
qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_TYPE, $userid, $params['oldanswer']['userid']); qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_TYPE, $userid, $params['oldanswer']['userid']);
break; break;
case 'c_hide': case 'c_hide':
if (isset($params['oldcomment']['userid'])) if (isset($params['oldcomment']['userid']))
qa_db_event_create_not_entity($params['oldcomment']['userid'], $params['questionid'], $params['postid'], QA_UPDATE_VISIBLE, $userid); qa_db_event_create_not_entity($params['oldcomment']['userid'], $params['questionid'], $params['postid'], QA_UPDATE_VISIBLE, $userid);
break; break;
case 'c_reshow': case 'c_reshow':
qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_VISIBLE, $userid, $params['oldcomment']['userid']); qa_create_event_for_q_user($params['questionid'], $params['postid'], QA_UPDATE_VISIBLE, $userid, $params['oldcomment']['userid']);
break; break;
}
} }
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,119 +20,101 @@ ...@@ -20,119 +20,101 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser require_once QA_INCLUDE_DIR.'db/maxima.php';
header('Location: ../'); require_once QA_INCLUDE_DIR.'qa-util-string.php';
exit;
}
require_once QA_INCLUDE_DIR.'db/maxima.php';
require_once QA_INCLUDE_DIR.'qa-util-string.php';
class qa_filter_basic {
public function filter_email(&$email, $olduser)
{
if (!strlen($email))
return qa_lang('users/email_required');
if (!qa_email_validate($email))
return qa_lang('users/email_invalid');
if (qa_strlen($email)>QA_DB_MAX_EMAIL_LENGTH)
return qa_lang_sub('main/max_length_x', QA_DB_MAX_EMAIL_LENGTH);
}
public function filter_handle(&$handle, $olduser) class qa_filter_basic
{ {
if (!strlen($handle)) public function filter_email(&$email, $olduser)
return qa_lang('users/handle_empty'); {
if (!strlen($email))
return qa_lang('users/email_required');
if (preg_match('/[\\@\\+\\/]/', $handle)) if (!qa_email_validate($email))
return qa_lang_sub('users/handle_has_bad', '@ + /'); return qa_lang('users/email_invalid');
if (qa_strlen($handle)>QA_DB_MAX_HANDLE_LENGTH)
return qa_lang_sub('main/max_length_x', QA_DB_MAX_HANDLE_LENGTH);
}
if (qa_strlen($email)>QA_DB_MAX_EMAIL_LENGTH)
return qa_lang_sub('main/max_length_x', QA_DB_MAX_EMAIL_LENGTH);
}
public function filter_question(&$question, &$errors, $oldquestion) public function filter_handle(&$handle, $olduser)
{ {
$this->validate_length($errors, 'title', @$question['title'], qa_opt('min_len_q_title'), if (!strlen($handle))
max(qa_opt('min_len_q_title'), min(qa_opt('max_len_q_title'), QA_DB_MAX_TITLE_LENGTH))); return qa_lang('users/handle_empty');
$this->validate_length($errors, 'content', @$question['content'], 0, QA_DB_MAX_CONTENT_LENGTH); // for storage if (preg_match('/[\\@\\+\\/]/', $handle))
return qa_lang_sub('users/handle_has_bad', '@ + /');
$this->validate_length($errors, 'content', @$question['text'], qa_opt('min_len_q_content'), null); // for display if (qa_strlen($handle)>QA_DB_MAX_HANDLE_LENGTH)
return qa_lang_sub('main/max_length_x', QA_DB_MAX_HANDLE_LENGTH);
}
if (isset($question['tags'])) { public function filter_question(&$question, &$errors, $oldquestion)
$counttags=count($question['tags']); {
$mintags=min(qa_opt('min_num_q_tags'), qa_opt('max_num_q_tags')); $this->validate_length($errors, 'title', @$question['title'], qa_opt('min_len_q_title'),
max(qa_opt('min_len_q_title'), min(qa_opt('max_len_q_title'), QA_DB_MAX_TITLE_LENGTH)));
if ($counttags<$mintags) $this->validate_length($errors, 'content', @$question['content'], 0, QA_DB_MAX_CONTENT_LENGTH); // for storage
$errors['tags']=qa_lang_sub('question/min_tags_x', $mintags);
elseif ($counttags>qa_opt('max_num_q_tags'))
$errors['tags']=qa_lang_sub('question/max_tags_x', qa_opt('max_num_q_tags'));
else
$this->validate_length($errors, 'tags', qa_tags_to_tagstring($question['tags']), 0, QA_DB_MAX_TAGS_LENGTH); // for storage
}
$this->validate_post_email($errors, $question); $this->validate_length($errors, 'content', @$question['text'], qa_opt('min_len_q_content'), null); // for display
}
if (isset($question['tags'])) {
$counttags=count($question['tags']);
$mintags=min(qa_opt('min_num_q_tags'), qa_opt('max_num_q_tags'));
public function filter_answer(&$answer, &$errors, $question, $oldanswer) if ($counttags<$mintags)
{ $errors['tags']=qa_lang_sub('question/min_tags_x', $mintags);
$this->validate_length($errors, 'content', @$answer['content'], 0, QA_DB_MAX_CONTENT_LENGTH); // for storage elseif ($counttags>qa_opt('max_num_q_tags'))
$this->validate_length($errors, 'content', @$answer['text'], qa_opt('min_len_a_content'), null); // for display $errors['tags']=qa_lang_sub('question/max_tags_x', qa_opt('max_num_q_tags'));
$this->validate_post_email($errors, $answer); else
$this->validate_length($errors, 'tags', qa_tags_to_tagstring($question['tags']), 0, QA_DB_MAX_TAGS_LENGTH); // for storage
} }
$this->validate_post_email($errors, $question);
}
public function filter_comment(&$comment, &$errors, $question, $parent, $oldcomment) public function filter_answer(&$answer, &$errors, $question, $oldanswer)
{ {
$this->validate_length($errors, 'content', @$comment['content'], 0, QA_DB_MAX_CONTENT_LENGTH); // for storage $this->validate_length($errors, 'content', @$answer['content'], 0, QA_DB_MAX_CONTENT_LENGTH); // for storage
$this->validate_length($errors, 'content', @$comment['text'], qa_opt('min_len_c_content'), null); // for display $this->validate_length($errors, 'content', @$answer['text'], qa_opt('min_len_a_content'), null); // for display
$this->validate_post_email($errors, $comment); $this->validate_post_email($errors, $answer);
} }
public function filter_comment(&$comment, &$errors, $question, $parent, $oldcomment)
{
$this->validate_length($errors, 'content', @$comment['content'], 0, QA_DB_MAX_CONTENT_LENGTH); // for storage
$this->validate_length($errors, 'content', @$comment['text'], qa_opt('min_len_c_content'), null); // for display
$this->validate_post_email($errors, $comment);
}
public function filter_profile(&$profile, &$errors, $user, $oldprofile) public function filter_profile(&$profile, &$errors, $user, $oldprofile)
{ {
foreach ($profile as $field => $value) foreach ($profile as $field => $value)
$this->validate_length($errors, $field, $value, 0, QA_DB_MAX_PROFILE_CONTENT_LENGTH); $this->validate_length($errors, $field, $value, 0, QA_DB_MAX_PROFILE_CONTENT_LENGTH);
} }
// The definitions below are not part of a standard filter module, but just used within this one // The definitions below are not part of a standard filter module, but just used within this one
private function validate_length(&$errors, $field, $input, $minlength, $maxlength) /**
/* * Add textual element $field to $errors if length of $input is not between $minlength and $maxlength
Add textual element $field to $errors if length of $input is not between $minlength and $maxlength */
*/ private function validate_length(&$errors, $field, $input, $minlength, $maxlength)
{ {
$length = isset($input) ? qa_strlen($input) : 0; $length = isset($input) ? qa_strlen($input) : 0;
if ($length < $minlength)
$errors[$field] = ($minlength == 1) ? qa_lang('main/field_required') : qa_lang_sub('main/min_length_x', $minlength);
elseif (isset($maxlength) && ($length > $maxlength))
$errors[$field] = qa_lang_sub('main/max_length_x', $maxlength);
}
if ($length < $minlength)
$errors[$field] = ($minlength == 1) ? qa_lang('main/field_required') : qa_lang_sub('main/min_length_x', $minlength);
elseif (isset($maxlength) && ($length > $maxlength))
$errors[$field] = qa_lang_sub('main/max_length_x', $maxlength);
}
private function validate_post_email(&$errors, $post) private function validate_post_email(&$errors, $post)
{ {
if (@$post['notify'] && strlen(@$post['email'])) { if (@$post['notify'] && strlen(@$post['email'])) {
$error=$this->filter_email($post['email'], null); $error=$this->filter_email($post['email'], null);
if (isset($error)) if (isset($error))
$errors['email']=$error; $errors['email']=$error;
}
} }
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,188 +20,181 @@ ...@@ -20,188 +20,181 @@
More about this license: http://www.question2answer.org/license.php 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) foreach ($postids as $postid)
{ if (isset($postid) && !isset($this->qa_voters_flaggers_cache[$postid]))
if (!qa_user_post_permit_error('permit_view_voters_flaggers', $post)) { $this->qa_voters_flaggers_queue[$postid]=true;
$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;
}
} }
}
private function queue_raw_posts_voters_flaggers($posts) private function queue_raw_posts_voters_flaggers($posts)
{ {
if (is_array($posts)) if (is_array($posts))
foreach ($posts as $post) foreach ($posts as $post)
if (isset($post['raw'])) if (isset($post['raw']))
$this->queue_post_voters_flaggers($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);
foreach ($postids as $postid) private function retrieve_queued_voters_flaggers()
$this->qa_voters_flaggers_cache[$postid]=array(); {
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) { foreach ($postids as $postid)
$keyuserids=array(); $this->qa_voters_flaggers_cache[$postid]=array();
foreach ($newvotersflaggers as $voterflagger)
$keyuserids[$voterflagger['userid']]=true;
$useridhandles=qa_get_public_from_userids(array_keys($keyuserids)); $newvotersflaggers=qa_db_uservoteflag_posts_get($postids);
foreach ($newvotersflaggers as $index => $voterflagger)
$newvotersflaggers[$index]['handle']=@$useridhandles[$voterflagger['userid']];
}
if (QA_FINAL_EXTERNAL_USERS) {
$keyuserids=array();
foreach ($newvotersflaggers as $voterflagger) 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) private function get_post_voters_flaggers($post, $postid)
{ {
require_once QA_INCLUDE_DIR.'qa-util-sort.php'; require_once QA_INCLUDE_DIR.'qa-util-sort.php';
if (!isset($this->qa_voters_flaggers_cache[$postid])) { if (!isset($this->qa_voters_flaggers_cache[$postid])) {
$this->queue_post_voters_flaggers($post); $this->queue_post_voters_flaggers($post);
$this->retrieve_queued_voters_flaggers(); $this->retrieve_queued_voters_flaggers();
} }
$votersflaggers=@$this->qa_voters_flaggers_cache[$postid]; $votersflaggers=@$this->qa_voters_flaggers_cache[$postid];
if (isset($votersflaggers)) if (isset($votersflaggers))
qa_sort_by($votersflaggers, 'handle'); 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() public function main()
{ {
foreach ($this->content as $key => $part) { foreach ($this->content as $key => $part) {
if (strpos($key, 'q_list')===0) if (strpos($key, 'q_list')===0)
$this->queue_raw_posts_voters_flaggers(@$part['qs']); $this->queue_raw_posts_voters_flaggers(@$part['qs']);
elseif (strpos($key, 'q_view')===0) { elseif (strpos($key, 'q_view')===0) {
$this->queue_post_voters_flaggers($part['raw']); $this->queue_post_voters_flaggers($part['raw']);
$this->queue_raw_posts_voters_flaggers($part['c_list']['cs']); $this->queue_raw_posts_voters_flaggers($part['c_list']['cs']);
} elseif (strpos($key, 'a_list')===0) { } elseif (strpos($key, 'a_list')===0) {
if (!empty($part)) { if (!empty($part)) {
$this->queue_raw_posts_voters_flaggers($part['as']); $this->queue_raw_posts_voters_flaggers($part['as']);
foreach ($part['as'] as $a_item) foreach ($part['as'] as $a_item)
$this->queue_raw_posts_voters_flaggers(@$a_item['c_list']['cs']); $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) public function q_list_items($q_items)
{ {
$this->queue_raw_posts_voters_flaggers($a_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) public function a_list_items($a_items)
{ {
$this->queue_raw_posts_voters_flaggers($c_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)) { public function vote_count($post)
$uphandles=''; {
$downhandles=''; $votersflaggers=$this->get_post_voters_flaggers($post['raw'], @$post['vote_opostid'] ? $post['raw']['opostid'] : $post['raw']['postid']);
foreach ($votersflaggers as $voterflagger) { $tooltip='';
if ($voterflagger['vote']>0)
$uphandles.=(strlen($uphandles) ? ', ' : '').qa_html($voterflagger['handle']);
if ($voterflagger['vote']<0) if (isset($votersflaggers)) {
$downhandles.=(strlen($downhandles) ? ', ' : '').qa_html($voterflagger['handle']); $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) qa_html_theme_base::vote_count($post);
{ }
$postid=@$post['raw']['opostid'];
if (!isset($postid))
$postid=@$post['raw']['postid'];
$tooltip='';
if (isset($postid)) {
$votersflaggers=$this->get_post_voters_flaggers($post, $postid);
if (isset($votersflaggers)) public function post_meta_flags($post, $class)
foreach ($votersflaggers as $voterflagger) {
if ($voterflagger['flag']>0) $postid=@$post['raw']['opostid'];
$tooltip.=(strlen($tooltip) ? ', ' : '').qa_html($voterflagger['handle']); if (!isset($postid))
} $postid=@$post['raw']['postid'];
if (strlen($tooltip)) $tooltip='';
$this->output('<span title="&#9873; '.$tooltip.'">');
qa_html_theme_base::post_meta_flags($post, $class); if (isset($postid)) {
$votersflaggers=$this->get_post_voters_flaggers($post, $postid);
if (strlen($tooltip)) if (isset($votersflaggers))
$this->output('</span>'); 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);
/* if (strlen($tooltip))
Omit PHP closing tag to help avoid accidental output $this->output('</span>');
*/ }
\ No newline at end of file }
...@@ -20,133 +20,116 @@ ...@@ -20,133 +20,116 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser class qa_search_basic
header('Location: ../'); {
exit; public function index_post($postid, $type, $questionid, $parentid, $title, $content, $format, $text, $tagstring, $categoryid)
} {
require_once QA_INCLUDE_DIR.'db/post-create.php';
class qa_search_basic {
public function index_post($postid, $type, $questionid, $parentid, $title, $content, $format, $text, $tagstring, $categoryid)
{
require_once QA_INCLUDE_DIR.'db/post-create.php';
// Get words from each textual element
$titlewords=array_unique(qa_string_to_words($title));
$contentcount=array_count_values(qa_string_to_words($text));
$tagwords=array_unique(qa_string_to_words($tagstring));
$wholetags=array_unique(qa_tagstring_to_tags($tagstring));
// Map all words to their word IDs // Get words from each textual element
$words=array_unique(array_merge($titlewords, array_keys($contentcount), $tagwords, $wholetags)); $titlewords=array_unique(qa_string_to_words($title));
$wordtoid=qa_db_word_mapto_ids_add($words); $contentcount=array_count_values(qa_string_to_words($text));
$tagwords=array_unique(qa_string_to_words($tagstring));
$wholetags=array_unique(qa_tagstring_to_tags($tagstring));
// Add to title words index // Map all words to their word IDs
$titlewordids=qa_array_filter_by_keys($wordtoid, $titlewords); $words=array_unique(array_merge($titlewords, array_keys($contentcount), $tagwords, $wholetags));
qa_db_titlewords_add_post_wordids($postid, $titlewordids); $wordtoid=qa_db_word_mapto_ids_add($words);
// Add to content words index (including word counts) // Add to title words index
$contentwordidcounts=array(); $titlewordids=qa_array_filter_by_keys($wordtoid, $titlewords);
foreach ($contentcount as $word => $count) qa_db_titlewords_add_post_wordids($postid, $titlewordids);
if (isset($wordtoid[$word]))
$contentwordidcounts[$wordtoid[$word]]=$count;
qa_db_contentwords_add_post_wordidcounts($postid, $type, $questionid, $contentwordidcounts); // Add to content words index (including word counts)
// Add to tag words index $contentwordidcounts=array();
foreach ($contentcount as $word => $count)
if (isset($wordtoid[$word]))
$contentwordidcounts[$wordtoid[$word]]=$count;
$tagwordids=qa_array_filter_by_keys($wordtoid, $tagwords); qa_db_contentwords_add_post_wordidcounts($postid, $type, $questionid, $contentwordidcounts);
qa_db_tagwords_add_post_wordids($postid, $tagwordids);
// Add to whole tags index // Add to tag words index
$wholetagids=qa_array_filter_by_keys($wordtoid, $wholetags); $tagwordids=qa_array_filter_by_keys($wordtoid, $tagwords);
qa_db_posttags_add_post_wordids($postid, $wholetagids); qa_db_tagwords_add_post_wordids($postid, $tagwordids);
// Update counts cached in database (will be skipped if qa_suspend_update_counts() was called // Add to whole tags index
qa_db_word_titlecount_update($titlewordids); $wholetagids=qa_array_filter_by_keys($wordtoid, $wholetags);
qa_db_word_contentcount_update(array_keys($contentwordidcounts)); qa_db_posttags_add_post_wordids($postid, $wholetagids);
qa_db_word_tagwordcount_update($tagwordids);
qa_db_word_tagcount_update($wholetagids);
qa_db_tagcount_update();
}
// Update counts cached in database (will be skipped if qa_suspend_update_counts() was called
public function unindex_post($postid) qa_db_word_titlecount_update($titlewordids);
{ qa_db_word_contentcount_update(array_keys($contentwordidcounts));
require_once QA_INCLUDE_DIR.'db/post-update.php'; qa_db_word_tagwordcount_update($tagwordids);
qa_db_word_tagcount_update($wholetagids);
qa_db_tagcount_update();
}
$titlewordids=qa_db_titlewords_get_post_wordids($postid); public function unindex_post($postid)
qa_db_titlewords_delete_post($postid); {
qa_db_word_titlecount_update($titlewordids); require_once QA_INCLUDE_DIR.'db/post-update.php';
$contentwordids=qa_db_contentwords_get_post_wordids($postid); $titlewordids=qa_db_titlewords_get_post_wordids($postid);
qa_db_contentwords_delete_post($postid); qa_db_titlewords_delete_post($postid);
qa_db_word_contentcount_update($contentwordids); qa_db_word_titlecount_update($titlewordids);
$tagwordids=qa_db_tagwords_get_post_wordids($postid); $contentwordids=qa_db_contentwords_get_post_wordids($postid);
qa_db_tagwords_delete_post($postid); qa_db_contentwords_delete_post($postid);
qa_db_word_tagwordcount_update($tagwordids); qa_db_word_contentcount_update($contentwordids);
$wholetagids=qa_db_posttags_get_post_wordids($postid); $tagwordids=qa_db_tagwords_get_post_wordids($postid);
qa_db_posttags_delete_post($postid); qa_db_tagwords_delete_post($postid);
qa_db_word_tagcount_update($wholetagids); qa_db_word_tagwordcount_update($tagwordids);
}
$wholetagids=qa_db_posttags_get_post_wordids($postid);
qa_db_posttags_delete_post($postid);
qa_db_word_tagcount_update($wholetagids);
}
public function move_post($postid, $categoryid) public function move_post($postid, $categoryid)
{ {
// for now, the built-in search engine ignores categories // for now, the built-in search engine ignores categories
} }
public function index_page($pageid, $request, $title, $content, $format, $text)
{
// for now, the built-in search engine ignores custom pages
}
public function index_page($pageid, $request, $title, $content, $format, $text) public function unindex_page($pageid)
{ {
// for now, the built-in search engine ignores custom pages // for now, the built-in search engine ignores custom pages
} }
public function process_search($query, $start, $count, $userid, $absoluteurls, $fullcontent)
{
require_once QA_INCLUDE_DIR.'db/selects.php';
require_once QA_INCLUDE_DIR.'qa-util-string.php';
public function unindex_page($pageid) $words=qa_string_to_words($query);
{
// for now, the built-in search engine ignores custom pages
}
$questions=qa_db_select_with_pending(
qa_db_search_posts_selectspec($userid, $words, $words, $words, $words, trim($query), $start, $fullcontent, $count)
);
public function process_search($query, $start, $count, $userid, $absoluteurls, $fullcontent) $results=array();
{
require_once QA_INCLUDE_DIR.'db/selects.php';
require_once QA_INCLUDE_DIR.'qa-util-string.php';
$words=qa_string_to_words($query); foreach ($questions as $question) {
qa_search_set_max_match($question, $type, $postid); // to link straight to best part
$questions=qa_db_select_with_pending( $results[]=array(
qa_db_search_posts_selectspec($userid, $words, $words, $words, $words, trim($query), $start, $fullcontent, $count) 'question' => $question,
'match_type' => $type,
'match_postid' => $postid,
); );
$results=array();
foreach ($questions as $question) {
qa_search_set_max_match($question, $type, $postid); // to link straight to best part
$results[]=array(
'question' => $question,
'match_type' => $type,
'match_postid' => $postid,
);
}
return $results;
} }
return $results;
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,167 +20,152 @@ ...@@ -20,167 +20,152 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser class qa_viewer_basic
header('Location: ../'); {
exit; private $htmllineseparators;
} private $htmlparagraphseparators;
class qa_viewer_basic {
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) public function calc_quality($content, $format)
{ {
$this->htmllineseparators='br|option'; if ( ($format=='') || ($format=='html') )
$this->htmlparagraphseparators='address|applet|blockquote|center|cite|col|div|dd|dl|dt|embed|form|frame|frameset|h1|h2|h3|h4|h5|h6'. return 1.0;
'|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
}
return 0.0001; // if there's nothing better this will give an error message for unknown formats
}
public function get_html($content, $format, $options) public function get_html($content, $format, $options)
{ {
if ($format=='html') { if ($format=='html') {
$html=qa_sanitize_html($content, @$options['linksnewwindow'], false); // sanitize again for display, for extra safety, and due to new window setting $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 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'; 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->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->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 preg_match_all('/<[^>]*>/', $html, $pregmatches, PREG_OFFSET_CAPTURE); // find tag positions and lengths
$tagmatches=$pregmatches[0]; $tagmatches=$pregmatches[0];
$text=preg_replace('/<[^>]*>/', '', $html); // effectively strip_tags() but use same regexp as above to ensure consistency $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); $nexttagmatch=array_shift($tagmatches);
$texttohtml=0; $texttohtml=0;
$htmlshift=0; $htmlshift=0;
foreach ($blockmatches as $textoffset => $textlength) { foreach ($blockmatches as $textoffset => $textlength) {
while ( isset($nexttagmatch) && ($nexttagmatch[1]<=($textoffset+$texttohtml)) ) { // keep text and html in sync while ( isset($nexttagmatch) && ($nexttagmatch[1]<=($textoffset+$texttohtml)) ) { // keep text and html in sync
$texttohtml+=strlen($nexttagmatch[0]); $texttohtml+=strlen($nexttagmatch[0]);
$nexttagmatch=array_shift($tagmatches); $nexttagmatch=array_shift($tagmatches);
} }
while (1) { while (1) {
$replacepart=$textlength; $replacepart=$textlength;
if (isset($nexttagmatch)) if (isset($nexttagmatch))
$replacepart=min($replacepart, $nexttagmatch[1]-($textoffset+$texttohtml)); // stop replacing early if we hit an HTML tag $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); $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 $htmlshift+=$replacelength-$replacepart; // HTML might have moved around if we replaced multi-byte characters
if ($replacepart>=$textlength) if ($replacepart>=$textlength)
break; // we have replaced everything expected, otherwise more left (due to hitting an HTML tag) break; // we have replaced everything expected, otherwise more left (due to hitting an HTML tag)
$textlength-=$replacepart; $textlength-=$replacepart;
$textoffset+=$replacepart; $textoffset+=$replacepart;
$texttohtml+=strlen($nexttagmatch[0]); $texttohtml+=strlen($nexttagmatch[0]);
$nexttagmatch=array_shift($tagmatches); $nexttagmatch=array_shift($tagmatches);
}
} }
} }
}
if (@$options['showurllinks']) { // we need to ensure here that we don't put new links inside existing ones 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'; 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://..."> 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 $thishtmluntaggeds=array_reverse(preg_split('/<[^>]*>/', $htmlunlinked[0], -1, PREG_SPLIT_OFFSET_CAPTURE)); // again, start from end
foreach ($thishtmluntaggeds as $thishtmluntagged) { foreach ($thishtmluntaggeds as $thishtmluntagged) {
$innerhtml=$thishtmluntagged[0]; $innerhtml=$thishtmluntagged[0];
if (is_numeric(strpos($innerhtml, '://'))) { // quick test first if (is_numeric(strpos($innerhtml, '://'))) { // quick test first
$newhtml=qa_html_convert_urls($innerhtml, qa_opt('links_in_new_window')); $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']) { $html=qa_html($content, true);
require_once QA_INCLUDE_DIR.'app/format.php';
$html=qa_html_convert_urls($html, qa_opt('links_in_new_window'));
}
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) public function get_text($content, $format, $options)
{ {
if ($format=='html') { if ($format=='html') {
$text=strtr($content, "\n\r\t", ' '); // convert all white space in HTML to spaces $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->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=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=strip_tags($text); // all tags removed
$text=preg_replace('/ +/', ' ', $text); // combine multiple spaces into one $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", $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=preg_replace('/\n\n\n+/', "\n\n", $text); // more than two new lines combine into two
$text=strtr($text, array( $text=strtr($text, array(
'&#34;' => "\x22", '&#34;' => "\x22",
'&#38;' => "\x26", '&#38;' => "\x26",
'&#39;' => "\x27", '&#39;' => "\x27",
'&#60;' => "\x3C", '&#60;' => "\x3C",
'&#62;' => "\x3E", '&#62;' => "\x3E",
'&nbsp;' => " ", '&nbsp;' => " ",
'&quot;' => "\x22", '&quot;' => "\x22",
'&amp;' => "\x26", '&amp;' => "\x26",
'&lt;' => "\x3C", '&lt;' => "\x3C",
'&gt;' => "\x3E", '&gt;' => "\x3E",
)); // base HTML entities (others should not be stored in database) )); // base HTML entities (others should not be stored in database)
$text=trim($text); $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']);
}
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 @@ ...@@ -20,51 +20,42 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
class qa_activity_count { class qa_activity_count
{
public function allow_template($template) public function allow_template($template)
{ {
return true; return true;
} }
public function allow_region($region)
{
return ($region=='side');
}
public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
{
$themeobject->output('<div class="qa-activity-count">');
$this->output_count($themeobject, qa_opt('cache_qcount'), 'main/1_question', 'main/x_questions'); public function allow_region($region)
$this->output_count($themeobject, qa_opt('cache_acount'), 'main/1_answer', 'main/x_answers'); {
return ($region=='side');
}
if (qa_opt('comment_on_qs') || qa_opt('comment_on_as')) public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
$this->output_count($themeobject, qa_opt('cache_ccount'), 'main/1_comment', 'main/x_comments'); {
$themeobject->output('<div class="qa-activity-count">');
$this->output_count($themeobject, qa_opt('cache_userpointscount'), 'main/1_user', 'main/x_users'); $this->output_count($themeobject, qa_opt('cache_qcount'), 'main/1_question', 'main/x_questions');
$this->output_count($themeobject, qa_opt('cache_acount'), 'main/1_answer', 'main/x_answers');
$themeobject->output('</div>'); if (qa_opt('comment_on_qs') || qa_opt('comment_on_as'))
} $this->output_count($themeobject, qa_opt('cache_ccount'), 'main/1_comment', 'main/x_comments');
$this->output_count($themeobject, qa_opt('cache_userpointscount'), 'main/1_user', 'main/x_users');
public function output_count($themeobject, $value, $langsingular, $langplural) $themeobject->output('</div>');
{ }
$themeobject->output('<p class="qa-activity-count-item">');
if ($value==1) public function output_count($themeobject, $value, $langsingular, $langplural)
$themeobject->output(qa_lang_html_sub($langsingular, '<span class="qa-activity-count-data">1</span>', '1')); {
else $themeobject->output('<p class="qa-activity-count-item">');
$themeobject->output(qa_lang_html_sub($langplural, '<span class="qa-activity-count-data">'.number_format((int)$value).'</span>'));
$themeobject->output('</p>'); if ($value==1)
} $themeobject->output(qa_lang_html_sub($langsingular, '<span class="qa-activity-count-data">1</span>', '1'));
else
$themeobject->output(qa_lang_html_sub($langplural, '<span class="qa-activity-count-data">'.number_format((int)$value).'</span>'));
$themeobject->output('</p>');
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,30 +20,28 @@ ...@@ -20,30 +20,28 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
class qa_ask_box { class qa_ask_box
{
public function allow_template($template) public function allow_template($template)
{ {
$allowed = array( $allowed = array(
'activity', 'categories', 'custom', 'feedback', 'qa', 'questions', 'activity', 'categories', 'custom', 'feedback', 'qa', 'questions',
'hot', 'search', 'tag', 'tags', 'unanswered' 'hot', 'search', 'tag', 'tags', 'unanswered'
); );
return in_array($template, $allowed); return in_array($template, $allowed);
} }
public function allow_region($region)
{
return in_array($region, array('main', 'side', 'full'));
}
public function allow_region($region)
{
return in_array($region, array('main', 'side', 'full'));
}
public function output_widget($region, $place, $themeobject, $template, $request, $qa_content) public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
{ {
if (isset($qa_content['categoryids'])) if (isset($qa_content['categoryids']))
$params=array('cat' => end($qa_content['categoryids'])); $params=array('cat' => end($qa_content['categoryids']));
else else
$params=null; $params=null;
?> ?>
<div class="qa-ask-box"> <div class="qa-ask-box">
<form method="post" action="<?php echo qa_path_html('ask', $params); ?>"> <form method="post" action="<?php echo qa_path_html('ask', $params); ?>">
...@@ -69,11 +67,5 @@ ...@@ -69,11 +67,5 @@
</form> </form>
</div> </div>
<?php <?php
}
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,92 +20,84 @@ ...@@ -20,92 +20,84 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
class qa_related_qs { class qa_related_qs
{
public function allow_template($template) public function allow_template($template)
{ {
return ($template=='question'); return ($template=='question');
} }
public function allow_region($region)
{
return ($region=='side') || ($region=='main') || ($region=='full');
}
public function allow_region($region)
{
return ($region=='side') || ($region=='main') || ($region=='full');
}
public function output_widget($region, $place, $themeobject, $template, $request, $qa_content) public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
{ {
require_once QA_INCLUDE_DIR.'db/selects.php'; require_once QA_INCLUDE_DIR.'db/selects.php';
if (@$qa_content['q_view']['raw']['type']!='Q') // question might not be visible, etc... if (@$qa_content['q_view']['raw']['type']!='Q') // question might not be visible, etc...
return; return;
$questionid=$qa_content['q_view']['raw']['postid']; $questionid=$qa_content['q_view']['raw']['postid'];
$userid=qa_get_logged_in_userid(); $userid=qa_get_logged_in_userid();
$cookieid=qa_cookie_get(); $cookieid=qa_cookie_get();
$questions=qa_db_single_select(qa_db_related_qs_selectspec($userid, $questionid, qa_opt('page_size_related_qs'))); $questions=qa_db_single_select(qa_db_related_qs_selectspec($userid, $questionid, qa_opt('page_size_related_qs')));
$minscore=qa_match_to_min_score(qa_opt('match_related_qs')); $minscore=qa_match_to_min_score(qa_opt('match_related_qs'));
foreach ($questions as $key => $question) foreach ($questions as $key => $question)
if ($question['score']<$minscore) if ($question['score']<$minscore)
unset($questions[$key]); unset($questions[$key]);
$titlehtml=qa_lang_html(count($questions) ? 'main/related_qs_title' : 'main/no_related_qs_title'); $titlehtml=qa_lang_html(count($questions) ? 'main/related_qs_title' : 'main/no_related_qs_title');
if ($region=='side') { if ($region=='side') {
$themeobject->output( $themeobject->output(
'<div class="qa-related-qs">', '<div class="qa-related-qs">',
'<h2 style="margin-top:0; padding-top:0;">', '<h2 style="margin-top:0; padding-top:0;">',
$titlehtml, $titlehtml,
'</h2>' '</h2>'
); );
$themeobject->output('<ul class="qa-related-q-list">'); $themeobject->output('<ul class="qa-related-q-list">');
foreach ($questions as $question) foreach ($questions as $question)
$themeobject->output('<li class="qa-related-q-item"><a href="'.qa_q_path_html($question['postid'], $question['title']).'">'.qa_html($question['title']).'</a></li>'); $themeobject->output('<li class="qa-related-q-item"><a href="'.qa_q_path_html($question['postid'], $question['title']).'">'.qa_html($question['title']).'</a></li>');
$themeobject->output( $themeobject->output(
'</ul>', '</ul>',
'</div>' '</div>'
); );
} else { } else {
$themeobject->output( $themeobject->output(
'<h2>', '<h2>',
$titlehtml, $titlehtml,
'</h2>' '</h2>'
); );
$q_list=array( $q_list=array(
'form' => array( 'form' => array(
'tags' => 'method="post" action="'.qa_self_html().'"', 'tags' => 'method="post" action="'.qa_self_html().'"',
'hidden' => array( 'hidden' => array(
'code' => qa_get_form_security_code('vote'), 'code' => qa_get_form_security_code('vote'),
),
), ),
),
'qs' => array(), 'qs' => array(),
); );
$defaults=qa_post_html_defaults('Q'); $defaults=qa_post_html_defaults('Q');
$usershtml=qa_userids_handles_html($questions); $usershtml=qa_userids_handles_html($questions);
foreach ($questions as $question) foreach ($questions as $question)
$q_list['qs'][]=qa_post_html_fields($question, $userid, $cookieid, $usershtml, null, qa_post_html_options($question, $defaults)); $q_list['qs'][]=qa_post_html_fields($question, $userid, $cookieid, $usershtml, null, qa_post_html_options($question, $defaults));
$themeobject->q_list_and_form($q_list); $themeobject->q_list_and_form($q_list);
}
} }
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment