Commit b2da9e7e by Scott

Refactor various classes for PHP 5

Add public/private etc.
parent 00c12dfc
......@@ -32,23 +32,24 @@
class qa_editor_basic {
function load_module($localdir, $htmldir)
public function load_module($localdir, $htmldir)
{
}
function calc_quality($content, $format)
public function calc_quality($content, $format)
{
if ($format=='')
return 1.0;
elseif ($format=='html')
if ($format=='html')
return 0.2;
else
return 0;
return 0;
}
function get_field(&$qa_content, $content, $format, $fieldname, $rows /* $autofocus parameter deprecated */)
public function get_field(&$qa_content, $content, $format, $fieldname, $rows /* $autofocus parameter deprecated */)
{
return array(
'type' => 'textarea',
......@@ -58,13 +59,13 @@
);
}
function focus_script($fieldname)
public function focus_script($fieldname)
{
return "document.getElementById('".$fieldname."').focus();";
}
function read_post($fieldname)
public function read_post($fieldname)
{
return array(
'format' => '',
......
......@@ -32,7 +32,7 @@
class qa_event_limits {
function process_event($event, $userid, $handle, $cookieid, $params)
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.
......
......@@ -32,7 +32,7 @@
class qa_event_notify {
function process_event($event, $userid, $handle, $cookieid, $params)
public function process_event($event, $userid, $handle, $cookieid, $params)
{
require_once QA_INCLUDE_DIR.'qa-app-emails.php';
require_once QA_INCLUDE_DIR.'qa-app-format.php';
......
......@@ -32,7 +32,7 @@
class qa_event_updates {
function process_event($event, $userid, $handle, $cookieid, $params)
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;
......
......@@ -33,11 +33,9 @@
require_once QA_INCLUDE_DIR.'qa-util-string.php';
class qa_filter_basic {
function filter_email(&$email, $olduser)
public function filter_email(&$email, $olduser)
{
if (!strlen($email))
return qa_lang('users/email_required');
......@@ -50,7 +48,7 @@
}
function filter_handle(&$handle, $olduser)
public function filter_handle(&$handle, $olduser)
{
if (!strlen($handle))
return qa_lang('users/handle_empty');
......@@ -63,7 +61,7 @@
}
function filter_question(&$question, &$errors, $oldquestion)
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)));
......@@ -88,7 +86,7 @@
}
function filter_answer(&$answer, &$errors, $question, $oldanswer)
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
......@@ -96,7 +94,7 @@
}
function filter_comment(&$comment, &$errors, $question, $parent, $oldcomment)
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
......@@ -104,7 +102,7 @@
}
function filter_profile(&$profile, &$errors, $user, $oldprofile)
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);
......@@ -113,7 +111,7 @@
// The definitions below are not part of a standard filter module, but just used within this one
function validate_length(&$errors, $field, $input, $minlength, $maxlength)
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
*/
......@@ -129,7 +127,7 @@
}
function validate_post_email(&$errors, $post)
private function validate_post_email(&$errors, $post)
{
if (@$post['notify'] && strlen(@$post['email'])) {
$error=$this->filter_email($post['email'], null);
......
......@@ -26,13 +26,13 @@
class qa_html_theme_layer extends qa_html_theme_base {
var $qa_voters_flaggers_queue=array();
var $qa_voters_flaggers_cache=array();
private $qa_voters_flaggers_queue=array();
private $qa_voters_flaggers_cache=array();
// Utility functions for this layer
function queue_post_voters_flaggers($post)
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
......@@ -43,7 +43,7 @@
}
}
function queue_raw_posts_voters_flaggers($posts)
private function queue_raw_posts_voters_flaggers($posts)
{
if (is_array($posts))
foreach ($posts as $post)
......@@ -51,7 +51,7 @@
$this->queue_post_voters_flaggers($post['raw']);
}
function retrieve_queued_voters_flaggers()
private function retrieve_queued_voters_flaggers()
{
if (count($this->qa_voters_flaggers_queue)) {
require_once QA_INCLUDE_DIR.'qa-db-votes.php';
......@@ -80,7 +80,7 @@
}
}
function get_post_voters_flaggers($post, $postid)
private function get_post_voters_flaggers($post, $postid)
{
require_once QA_INCLUDE_DIR.'qa-util-sort.php';
......@@ -100,7 +100,7 @@
// Collect up all required postids for the entire page to save DB queries - common case where whole page output
function main()
public function main()
{
foreach ($this->content as $key => $part) {
if (strpos($key, 'q_list')===0)
......@@ -126,21 +126,21 @@
// Other functions which also collect up required postids for lists to save DB queries - helps with widget output and Ajax calls
function q_list_items($q_items)
public function q_list_items($q_items)
{
$this->queue_raw_posts_voters_flaggers($q_items);
qa_html_theme_base::q_list_items($q_items);
}
function a_list_items($a_items)
public function a_list_items($a_items)
{
$this->queue_raw_posts_voters_flaggers($a_items);
qa_html_theme_base::a_list_items($a_items);
}
function c_list_items($c_items)
public function c_list_items($c_items)
{
$this->queue_raw_posts_voters_flaggers($c_items);
......@@ -150,7 +150,7 @@
// Actual output of the voters and flaggers
function vote_count($post)
public function vote_count($post)
{
$votersflaggers=$this->get_post_voters_flaggers($post['raw'], @$post['vote_opostid'] ? $post['raw']['opostid'] : $post['raw']['postid']);
......@@ -177,7 +177,7 @@
}
function post_meta_flags($post, $class)
public function post_meta_flags($post, $class)
{
$postid=@$post['raw']['opostid'];
if (!isset($postid))
......
......@@ -32,7 +32,7 @@
class qa_search_basic {
function index_post($postid, $type, $questionid, $parentid, $title, $content, $format, $text, $tagstring, $categoryid)
public function index_post($postid, $type, $questionid, $parentid, $title, $content, $format, $text, $tagstring, $categoryid)
{
require_once QA_INCLUDE_DIR.'qa-db-post-create.php';
......@@ -82,7 +82,7 @@
}
function unindex_post($postid)
public function unindex_post($postid)
{
require_once QA_INCLUDE_DIR.'qa-db-post-update.php';
......@@ -104,25 +104,25 @@
}
function move_post($postid, $categoryid)
public function move_post($postid, $categoryid)
{
// for now, the built-in search engine ignores categories
}
function index_page($pageid, $request, $title, $content, $format, $text)
public function index_page($pageid, $request, $title, $content, $format, $text)
{
// for now, the built-in search engine ignores custom pages
}
function unindex_page($pageid)
public function unindex_page($pageid)
{
// for now, the built-in search engine ignores custom pages
}
function process_search($query, $start, $count, $userid, $absoluteurls, $fullcontent)
public function process_search($query, $start, $count, $userid, $absoluteurls, $fullcontent)
{
require_once QA_INCLUDE_DIR.'qa-db-selects.php';
require_once QA_INCLUDE_DIR.'qa-util-string.php';
......
......@@ -32,11 +32,11 @@
class qa_viewer_basic {
var $htmllineseparators;
var $htmlparagraphseparators;
private $htmllineseparators;
private $htmlparagraphseparators;
function load_module($localdir, $htmldir)
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'.
......@@ -44,16 +44,16 @@
}
function calc_quality($content, $format)
public function calc_quality($content, $format)
{
if ( ($format=='') || ($format=='html') )
return 1.0;
else
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
}
function get_html($content, $format, $options)
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
......@@ -121,7 +121,8 @@
}
}
} elseif ($format=='') {
}
elseif ($format=='') {
if (isset($options['blockwordspreg'])) {
require_once QA_INCLUDE_DIR.'qa-util-string.php';
$content=qa_block_words_replace($content, $options['blockwordspreg']);
......@@ -134,14 +135,15 @@
$html=qa_html_convert_urls($html, qa_opt('links_in_new_window'));
}
} else
}
else
$html='[no viewer found for format: '.qa_html($format).']'; // for unknown formats
return $html;
}
function get_text($content, $format, $options)
public function get_text($content, $format, $options)
{
if ($format=='html') {
$text=strtr($content, "\n\r\t", ' '); // convert all white space in HTML to spaces
......@@ -166,9 +168,9 @@
$text=trim($text);
} elseif ($format=='')
}
elseif ($format=='')
$text=$content;
else
$text='[no viewer found for format: '.$format.']'; // for unknown formats
......
......@@ -26,19 +26,19 @@
class qa_activity_count {
function allow_template($template)
public function allow_template($template)
{
return true;
}
function allow_region($region)
public function allow_region($region)
{
return ($region=='side');
}
function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
{
$themeobject->output('<div class="qa-activity-count">');
......@@ -54,7 +54,7 @@
}
function output_count($themeobject, $value, $langsingular, $langplural)
public function output_count($themeobject, $value, $langsingular, $langplural)
{
$themeobject->output('<p class="qa-activity-count-item">');
......
......@@ -26,49 +26,24 @@
class qa_ask_box {
function allow_template($template)
public function allow_template($template)
{
$allow=false;
switch ($template)
{
case 'activity':
case 'categories':
case 'custom':
case 'feedback':
case 'qa':
case 'questions':
case 'hot':
case 'search':
case 'tag':
case 'tags':
case 'unanswered':
$allow=true;
break;
}
$allowed = array(
'activity', 'categories', 'custom', 'feedback', 'qa', 'questions',
'hot', 'search', 'tag', 'tags', 'unanswered'
);
return $allow;
return in_array($template, $allowed);
}
function allow_region($region)
public function allow_region($region)
{
$allow=false;
switch ($region)
{
case 'main':
case 'side':
case 'full':
$allow=true;
break;
}
return $allow;
return in_array($region, array('main', 'side', 'full'));
}
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']))
$params=array('cat' => end($qa_content['categoryids']));
......
......@@ -26,22 +26,19 @@
class qa_related_qs {
var $voteformcode;
function allow_template($template)
public function allow_template($template)
{
return ($template=='question');
}
function allow_region($region)
public function allow_region($region)
{
return ($region=='side') || ($region=='main') || ($region=='full');
}
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.'qa-db-selects.php';
......
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