Commit c1b82ae1 by Scott

Coding style (plugins)

parent 936231ab
...@@ -30,7 +30,7 @@ class qa_event_limits ...@@ -30,7 +30,7 @@ class qa_event_limits
if (isset($params['delayed'])) if (isset($params['delayed']))
return; return;
require_once QA_INCLUDE_DIR.'app/limits.php'; require_once QA_INCLUDE_DIR . 'app/limits.php';
switch ($event) { switch ($event) {
case 'q_queue': case 'q_queue':
...@@ -76,7 +76,7 @@ class qa_event_limits ...@@ -76,7 +76,7 @@ class qa_event_limits
break; 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',
......
...@@ -27,8 +27,8 @@ class qa_event_updates ...@@ -27,8 +27,8 @@ class qa_event_updates
if (@$params['silent']) // don't create updates about silent edits, and possibly other silent events in future if (@$params['silent']) // don't create updates about silent edits, and possibly other silent events in future
return; return;
require_once QA_INCLUDE_DIR.'db/events.php'; require_once QA_INCLUDE_DIR . 'db/events.php';
require_once QA_INCLUDE_DIR.'app/events.php'; require_once QA_INCLUDE_DIR . 'app/events.php';
switch ($event) { switch ($event) {
case 'q_post': case 'q_post':
...@@ -47,44 +47,46 @@ class qa_event_updates ...@@ -47,44 +47,46 @@ class qa_event_updates
case 'c_post': case 'c_post':
$keyuserids=array(); $keyuserids = array();
foreach ($params['thread'] as $comment) // previous comments in thread (but not author of parent again) foreach ($params['thread'] as $comment) // previous comments in thread (but not author of parent again)
{
if (isset($comment['userid'])) if (isset($comment['userid']))
$keyuserids[$comment['userid']]=true; $keyuserids[$comment['userid']] = true;
}
foreach ($keyuserids as $keyuserid => $dummy) foreach ($keyuserids as $keyuserid => $dummy) {
if ($keyuserid != $userid) if ($keyuserid != $userid)
qa_db_event_create_not_entity($keyuserid, $params['questionid'], $params['postid'], QA_UPDATE_FOLLOWS, $userid); qa_db_event_create_not_entity($keyuserid, $params['questionid'], $params['postid'], QA_UPDATE_FOLLOWS, $userid);
}
switch ($params['parent']['basetype']) switch ($params['parent']['basetype']) {
{
case 'Q': case 'Q':
$updatetype=QA_UPDATE_C_FOR_Q; $updatetype = QA_UPDATE_C_FOR_Q;
break; break;
case 'A': case 'A':
$updatetype=QA_UPDATE_C_FOR_A; $updatetype = QA_UPDATE_C_FOR_A;
break; break;
default: default:
$updatetype=null; $updatetype = null;
break; break;
} }
// give precedence to 'your comment followed' rather than 'your Q/A commented' if both are true
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
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']);
......
...@@ -82,11 +82,9 @@ class qa_filter_basic ...@@ -82,11 +82,9 @@ class qa_filter_basic
if ($counttags < $mintags) { if ($counttags < $mintags) {
$errors['tags'] = qa_lang_sub('question/min_tags_x', $mintags); $errors['tags'] = qa_lang_sub('question/min_tags_x', $mintags);
} } elseif ($counttags > $maxtags) {
elseif ($counttags > $maxtags) {
$errors['tags'] = qa_lang_sub('question/max_tags_x', $maxtags); $errors['tags'] = qa_lang_sub('question/max_tags_x', $maxtags);
} } else {
else {
$tagstring = qa_tags_to_tagstring($question['tags']); $tagstring = qa_tags_to_tagstring($question['tags']);
if (qa_strlen($tagstring) > QA_DB_MAX_TAGS_LENGTH) { // for storage if (qa_strlen($tagstring) > QA_DB_MAX_TAGS_LENGTH) { // for storage
$errors['tags'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_TAGS_LENGTH); $errors['tags'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_TAGS_LENGTH);
...@@ -115,7 +113,7 @@ class qa_filter_basic ...@@ -115,7 +113,7 @@ class qa_filter_basic
{ {
foreach (array_keys($profile) as $field) { foreach (array_keys($profile) as $field) {
// ensure fields are not NULL // ensure fields are not NULL
$profile[$field] = (string) $profile[$field]; $profile[$field] = (string)$profile[$field];
$this->validate_field_length($errors, $profile, $field, 0, QA_DB_MAX_CONTENT_LENGTH); $this->validate_field_length($errors, $profile, $field, 0, QA_DB_MAX_CONTENT_LENGTH);
} }
} }
...@@ -147,7 +145,7 @@ class qa_filter_basic ...@@ -147,7 +145,7 @@ class qa_filter_basic
* @param int $minlength * @param int $minlength
* @param int $maxlength * @param int $maxlength
*/ */
private function validate_field_length(&$errors, &$post, $key, $minlength, $maxlength, $errorKey=null) private function validate_field_length(&$errors, &$post, $key, $minlength, $maxlength, $errorKey = null)
{ {
if (!$errorKey) { if (!$errorKey) {
$errorKey = $key; $errorKey = $key;
...@@ -159,8 +157,7 @@ class qa_filter_basic ...@@ -159,8 +157,7 @@ class qa_filter_basic
if ($length < $minlength) { if ($length < $minlength) {
$errors[$errorKey] = $minlength == 1 ? qa_lang('main/field_required') : qa_lang_sub('main/min_length_x', $minlength); $errors[$errorKey] = $minlength == 1 ? qa_lang('main/field_required') : qa_lang_sub('main/min_length_x', $minlength);
} } else if (isset($maxlength) && ($length > $maxlength)) {
else if (isset($maxlength) && ($length > $maxlength)) {
$errors[$errorKey] = qa_lang_sub('main/max_length_x', $maxlength); $errors[$errorKey] = qa_lang_sub('main/max_length_x', $maxlength);
} }
} }
......
...@@ -183,23 +183,27 @@ class qa_html_theme_layer extends qa_html_theme_base ...@@ -183,23 +183,27 @@ class qa_html_theme_layer extends qa_html_theme_base
$postids = array_keys($this->qa_voters_flaggers_queue); $postids = array_keys($this->qa_voters_flaggers_queue);
foreach ($postids as $postid) foreach ($postids as $postid) {
$this->qa_voters_flaggers_cache[$postid] = array(); $this->qa_voters_flaggers_cache[$postid] = array();
}
$newvotersflaggers = qa_db_uservoteflag_posts_get($postids); $newvotersflaggers = qa_db_uservoteflag_posts_get($postids);
if (QA_FINAL_EXTERNAL_USERS) { if (QA_FINAL_EXTERNAL_USERS) {
$keyuserids = array(); $keyuserids = array();
foreach ($newvotersflaggers as $voterflagger) foreach ($newvotersflaggers as $voterflagger) {
$keyuserids[$voterflagger['userid']] = true; $keyuserids[$voterflagger['userid']] = true;
}
$useridhandles = qa_get_public_from_userids(array_keys($keyuserids)); $useridhandles = qa_get_public_from_userids(array_keys($keyuserids));
foreach ($newvotersflaggers as $index => $voterflagger) foreach ($newvotersflaggers as $index => $voterflagger) {
$newvotersflaggers[$index]['handle'] = isset($useridhandles[$voterflagger['userid']]) ? $useridhandles[$voterflagger['userid']] : null; $newvotersflaggers[$index]['handle'] = isset($useridhandles[$voterflagger['userid']]) ? $useridhandles[$voterflagger['userid']] : null;
} }
}
foreach ($newvotersflaggers as $voterflagger) foreach ($newvotersflaggers as $voterflagger) {
$this->qa_voters_flaggers_cache[$voterflagger['postid']][] = $voterflagger; $this->qa_voters_flaggers_cache[$voterflagger['postid']][] = $voterflagger;
}
$this->qa_voters_flaggers_queue = array(); $this->qa_voters_flaggers_queue = array();
} }
......
...@@ -24,42 +24,43 @@ class qa_search_basic ...@@ -24,42 +24,43 @@ class qa_search_basic
{ {
public 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.'db/post-create.php'; require_once QA_INCLUDE_DIR . 'db/post-create.php';
// Get words from each textual element // Get words from each textual element
$titlewords=array_unique(qa_string_to_words($title)); $titlewords = array_unique(qa_string_to_words($title));
$contentcount=array_count_values(qa_string_to_words($text)); $contentcount = array_count_values(qa_string_to_words($text));
$tagwords=array_unique(qa_string_to_words($tagstring)); $tagwords = array_unique(qa_string_to_words($tagstring));
$wholetags=array_unique(qa_tagstring_to_tags($tagstring)); $wholetags = array_unique(qa_tagstring_to_tags($tagstring));
// Map all words to their word IDs // Map all words to their word IDs
$words=array_unique(array_merge($titlewords, array_keys($contentcount), $tagwords, $wholetags)); $words = array_unique(array_merge($titlewords, array_keys($contentcount), $tagwords, $wholetags));
$wordtoid=qa_db_word_mapto_ids_add($words); $wordtoid = qa_db_word_mapto_ids_add($words);
// Add to title words index // Add to title words index
$titlewordids=qa_array_filter_by_keys($wordtoid, $titlewords); $titlewordids = qa_array_filter_by_keys($wordtoid, $titlewords);
qa_db_titlewords_add_post_wordids($postid, $titlewordids); qa_db_titlewords_add_post_wordids($postid, $titlewordids);
// Add to content words index (including word counts) // Add to content words index (including word counts)
$contentwordidcounts=array(); $contentwordidcounts = array();
foreach ($contentcount as $word => $count) foreach ($contentcount as $word => $count) {
if (isset($wordtoid[$word])) if (isset($wordtoid[$word]))
$contentwordidcounts[$wordtoid[$word]]=$count; $contentwordidcounts[$wordtoid[$word]] = $count;
}
qa_db_contentwords_add_post_wordidcounts($postid, $type, $questionid, $contentwordidcounts); qa_db_contentwords_add_post_wordidcounts($postid, $type, $questionid, $contentwordidcounts);
// Add to tag words index // Add to tag words index
$tagwordids=qa_array_filter_by_keys($wordtoid, $tagwords); $tagwordids = qa_array_filter_by_keys($wordtoid, $tagwords);
qa_db_tagwords_add_post_wordids($postid, $tagwordids); qa_db_tagwords_add_post_wordids($postid, $tagwordids);
// Add to whole tags index // Add to whole tags index
$wholetagids=qa_array_filter_by_keys($wordtoid, $wholetags); $wholetagids = qa_array_filter_by_keys($wordtoid, $wholetags);
qa_db_posttags_add_post_wordids($postid, $wholetagids); qa_db_posttags_add_post_wordids($postid, $wholetagids);
// Update counts cached in database (will be skipped if qa_suspend_update_counts() was called // Update counts cached in database (will be skipped if qa_suspend_update_counts() was called
...@@ -73,21 +74,21 @@ class qa_search_basic ...@@ -73,21 +74,21 @@ class qa_search_basic
public function unindex_post($postid) public function unindex_post($postid)
{ {
require_once QA_INCLUDE_DIR.'db/post-update.php'; require_once QA_INCLUDE_DIR . 'db/post-update.php';
$titlewordids=qa_db_titlewords_get_post_wordids($postid); $titlewordids = qa_db_titlewords_get_post_wordids($postid);
qa_db_titlewords_delete_post($postid); qa_db_titlewords_delete_post($postid);
qa_db_word_titlecount_update($titlewordids); qa_db_word_titlecount_update($titlewordids);
$contentwordids=qa_db_contentwords_get_post_wordids($postid); $contentwordids = qa_db_contentwords_get_post_wordids($postid);
qa_db_contentwords_delete_post($postid); qa_db_contentwords_delete_post($postid);
qa_db_word_contentcount_update($contentwordids); qa_db_word_contentcount_update($contentwordids);
$tagwordids=qa_db_tagwords_get_post_wordids($postid); $tagwordids = qa_db_tagwords_get_post_wordids($postid);
qa_db_tagwords_delete_post($postid); qa_db_tagwords_delete_post($postid);
qa_db_word_tagwordcount_update($tagwordids); qa_db_word_tagwordcount_update($tagwordids);
$wholetagids=qa_db_posttags_get_post_wordids($postid); $wholetagids = qa_db_posttags_get_post_wordids($postid);
qa_db_posttags_delete_post($postid); qa_db_posttags_delete_post($postid);
qa_db_word_tagcount_update($wholetagids); qa_db_word_tagcount_update($wholetagids);
} }
...@@ -109,21 +110,21 @@ class qa_search_basic ...@@ -109,21 +110,21 @@ class qa_search_basic
public function process_search($query, $start, $count, $userid, $absoluteurls, $fullcontent) public function process_search($query, $start, $count, $userid, $absoluteurls, $fullcontent)
{ {
require_once QA_INCLUDE_DIR.'db/selects.php'; require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR.'util/string.php'; require_once QA_INCLUDE_DIR . 'util/string.php';
$words=qa_string_to_words($query); $words = qa_string_to_words($query);
$questions=qa_db_select_with_pending( $questions = qa_db_select_with_pending(
qa_db_search_posts_selectspec($userid, $words, $words, $words, $words, trim($query), $start, $fullcontent, $count) qa_db_search_posts_selectspec($userid, $words, $words, $words, $words, trim($query), $start, $fullcontent, $count)
); );
$results=array(); $results = array();
foreach ($questions as $question) { foreach ($questions as $question) {
qa_search_set_max_match($question, $type, $postid); // to link straight to best part qa_search_set_max_match($question, $type, $postid); // to link straight to best part
$results[]=array( $results[] = array(
'question' => $question, 'question' => $question,
'match_type' => $type, 'match_type' => $type,
'match_postid' => $postid, 'match_postid' => $postid,
......
...@@ -28,14 +28,14 @@ class qa_viewer_basic ...@@ -28,14 +28,14 @@ class qa_viewer_basic
public function load_module($localdir, $htmldir) public function load_module($localdir, $htmldir)
{ {
$this->htmllineseparators='br|option'; $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'. $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'; '|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) public function calc_quality($content, $format)
{ {
if ( ($format=='') || ($format=='html') ) if ($format == '' || $format == 'html')
return 1.0; 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
...@@ -43,104 +43,102 @@ class qa_viewer_basic ...@@ -43,104 +43,102 @@ class qa_viewer_basic
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.'util/string.php'; require_once QA_INCLUDE_DIR . '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.'util/string.php'; require_once QA_INCLUDE_DIR . '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 == '') {
elseif ($format=='') {
if (isset($options['blockwordspreg'])) { if (isset($options['blockwordspreg'])) {
require_once QA_INCLUDE_DIR.'util/string.php'; require_once QA_INCLUDE_DIR . 'util/string.php';
$content=qa_block_words_replace($content, $options['blockwordspreg']); $content = qa_block_words_replace($content, $options['blockwordspreg']);
} }
$html=qa_html($content, true); $html = qa_html($content, true);
if (@$options['showurllinks']) { if (@$options['showurllinks']) {
require_once QA_INCLUDE_DIR.'app/format.php'; require_once QA_INCLUDE_DIR . 'app/format.php';
$html=qa_html_convert_urls($html, qa_opt('links_in_new_window')); $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
$html='[no viewer found for format: '.qa_html($format).']'; // for unknown formats
return $html; 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",
...@@ -153,17 +151,16 @@ class qa_viewer_basic ...@@ -153,17 +151,16 @@ class qa_viewer_basic
'&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 == '')
elseif ($format=='') $text = $content;
$text=$content;
else else
$text='[no viewer found for format: '.$format.']'; // for unknown formats $text = '[no viewer found for format: ' . $format . ']'; // for unknown formats
if (isset($options['blockwordspreg'])) { if (isset($options['blockwordspreg'])) {
require_once QA_INCLUDE_DIR.'util/string.php'; require_once QA_INCLUDE_DIR . 'util/string.php';
$text=qa_block_words_replace($text, $options['blockwordspreg']); $text = qa_block_words_replace($text, $options['blockwordspreg']);
} }
return $text; return $text;
......
...@@ -29,7 +29,7 @@ class qa_activity_count ...@@ -29,7 +29,7 @@ class qa_activity_count
public function allow_region($region) public function allow_region($region)
{ {
return ($region=='side'); return ($region == 'side');
} }
public function output_widget($region, $place, $themeobject, $template, $request, $qa_content) public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
...@@ -53,10 +53,10 @@ class qa_activity_count ...@@ -53,10 +53,10 @@ class qa_activity_count
$themeobject->output('<p class="qa-activity-count-item">'); $themeobject->output('<p class="qa-activity-count-item">');
if ($value==1) if ($value == 1)
$themeobject->output(qa_lang_html_sub($langsingular, '<span class="qa-activity-count-data">1</span>', '1')); $themeobject->output(qa_lang_html_sub($langsingular, '<span class="qa-activity-count-data">1</span>', '1'));
else else
$themeobject->output(qa_lang_html_sub($langplural, '<span class="qa-activity-count-data">'.qa_format_number((int) $value, 0, true).'</span>')); $themeobject->output(qa_lang_html_sub($langplural, '<span class="qa-activity-count-data">' . qa_format_number((int)$value, 0, true) . '</span>'));
$themeobject->output('</p>'); $themeobject->output('</p>');
} }
......
...@@ -26,7 +26,7 @@ class qa_ask_box ...@@ -26,7 +26,7 @@ class qa_ask_box
{ {
$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);
} }
...@@ -39,9 +39,10 @@ class qa_ask_box ...@@ -39,9 +39,10 @@ class qa_ask_box
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); ?>">
...@@ -50,14 +51,10 @@ class qa_ask_box ...@@ -50,14 +51,10 @@ class qa_ask_box
<td class="qa-form-tall-label" style="padding:8px; white-space:nowrap; <?php echo ($region=='side') ? 'padding-bottom:0;' : 'text-align:right;'?>" width="1"> <td class="qa-form-tall-label" style="padding:8px; white-space:nowrap; <?php echo ($region=='side') ? 'padding-bottom:0;' : 'text-align:right;'?>" width="1">
<?php echo strtr(qa_lang_html('question/ask_title'), array(' ' => '&nbsp;'))?>: <?php echo strtr(qa_lang_html('question/ask_title'), array(' ' => '&nbsp;'))?>:
</td> </td>
<?php <?php if ($region=='side') : ?>
if ($region=='side') {
?>
</tr> </tr>
<tr> <tr>
<?php <?php endif; ?>
}
?>
<td class="qa-form-tall-data" style="padding:8px;" width="*"> <td class="qa-form-tall-data" style="padding:8px;" width="*">
<input name="title" type="text" class="qa-form-tall-text" style="width:95%;"> <input name="title" type="text" class="qa-form-tall-text" style="width:95%;">
</td> </td>
......
...@@ -40,8 +40,7 @@ class qa_category_list ...@@ -40,8 +40,7 @@ class qa_category_list
if (isset($qa_content['navigation']['cat'])) { if (isset($qa_content['navigation']['cat'])) {
$nav = $qa_content['navigation']['cat']; $nav = $qa_content['navigation']['cat'];
} } else {
else {
$selectspec = qa_db_category_nav_selectspec(null, true, false, true); $selectspec = qa_db_category_nav_selectspec(null, true, false, true);
$selectspec['caching'] = array( $selectspec['caching'] = array(
'key' => 'qa_db_category_nav_selectspec:default:full', 'key' => 'qa_db_category_nav_selectspec:default:full',
...@@ -51,7 +50,7 @@ class qa_category_list ...@@ -51,7 +50,7 @@ class qa_category_list
$nav = qa_category_navigation($navcategories); $nav = qa_category_navigation($navcategories);
} }
$this->themeobject->output('<h2>'.qa_lang_html('main/nav_categories').'</h2>'); $this->themeobject->output('<h2>' . qa_lang_html('main/nav_categories') . '</h2>');
$this->themeobject->set_context('nav_type', 'cat'); $this->themeobject->set_context('nav_type', 'cat');
$this->themeobject->nav_list($nav, 'nav-cat', 1); $this->themeobject->nav_list($nav, 'nav-cat', 1);
$this->themeobject->nav_clear('cat'); $this->themeobject->nav_clear('cat');
......
...@@ -34,7 +34,7 @@ class qa_related_qs ...@@ -34,7 +34,7 @@ class qa_related_qs
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 (!isset($qa_content['q_view']['raw']['type']) || $qa_content['q_view']['raw']['type'] != 'Q') // question might not be visible, etc... if (!isset($qa_content['q_view']['raw']['type']) || $qa_content['q_view']['raw']['type'] != 'Q') // question might not be visible, etc...
return; return;
...@@ -99,8 +99,9 @@ class qa_related_qs ...@@ -99,8 +99,9 @@ class qa_related_qs
$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);
} }
......
...@@ -25,25 +25,25 @@ class qa_event_logger ...@@ -25,25 +25,25 @@ class qa_event_logger
public function init_queries($table_list) public function init_queries($table_list)
{ {
if (qa_opt('event_logger_to_database')) { if (qa_opt('event_logger_to_database')) {
$tablename=qa_db_add_table_prefix('eventlog'); $tablename = qa_db_add_table_prefix('eventlog');
if (!in_array($tablename, $table_list)) { if (!in_array($tablename, $table_list)) {
// table does not exist, so create it // table does not exist, so create it
require_once QA_INCLUDE_DIR.'app/users.php'; require_once QA_INCLUDE_DIR . 'app/users.php';
require_once QA_INCLUDE_DIR.'db/maxima.php'; require_once QA_INCLUDE_DIR . 'db/maxima.php';
return 'CREATE TABLE ^eventlog ('. return 'CREATE TABLE ^eventlog (' .
'datetime DATETIME NOT NULL,'. 'datetime DATETIME NOT NULL,' .
'ipaddress VARCHAR (45) CHARACTER SET ascii,'. 'ipaddress VARCHAR (45) CHARACTER SET ascii,' .
'userid '.qa_get_mysql_user_column_type().','. 'userid ' . qa_get_mysql_user_column_type() . ',' .
'handle VARCHAR('.QA_DB_MAX_HANDLE_LENGTH.'),'. 'handle VARCHAR(' . QA_DB_MAX_HANDLE_LENGTH . '),' .
'cookieid BIGINT UNSIGNED,'. 'cookieid BIGINT UNSIGNED,' .
'event VARCHAR (20) CHARACTER SET ascii NOT NULL,'. 'event VARCHAR (20) CHARACTER SET ascii NOT NULL,' .
'params VARCHAR (800) NOT NULL,'. 'params VARCHAR (800) NOT NULL,' .
'KEY datetime (datetime),'. 'KEY datetime (datetime),' .
'KEY ipaddress (ipaddress),'. 'KEY ipaddress (ipaddress),' .
'KEY userid (userid),'. 'KEY userid (userid),' .
'KEY event (event)'. 'KEY event (event)' .
') ENGINE=MyISAM DEFAULT CHARSET=utf8'; ') ENGINE=MyISAM DEFAULT CHARSET=utf8';
} else { } else {
// table exists: check it has the correct schema // table exists: check it has the correct schema
...@@ -61,10 +61,9 @@ class qa_event_logger ...@@ -61,10 +61,9 @@ class qa_event_logger
public function admin_form(&$qa_content) public function admin_form(&$qa_content)
{ {
// Process form input // Process form input
$saved=false; $saved = false;
if (qa_clicked('event_logger_save_button')) { if (qa_clicked('event_logger_save_button')) {
qa_opt('event_logger_to_database', (int)qa_post_text('event_logger_to_database_field')); qa_opt('event_logger_to_database', (int)qa_post_text('event_logger_to_database_field'));
...@@ -72,24 +71,24 @@ class qa_event_logger ...@@ -72,24 +71,24 @@ class qa_event_logger
qa_opt('event_logger_directory', qa_post_text('event_logger_directory_field')); qa_opt('event_logger_directory', qa_post_text('event_logger_directory_field'));
qa_opt('event_logger_hide_header', !qa_post_text('event_logger_hide_header_field')); qa_opt('event_logger_hide_header', !qa_post_text('event_logger_hide_header_field'));
$saved=true; $saved = true;
} }
// Check the validity of the currently entered directory (if any) // Check the validity of the currently entered directory (if any)
$directory=qa_opt('event_logger_directory'); $directory = qa_opt('event_logger_directory');
$note=null; $note = null;
$error=null; $error = null;
if (!strlen($directory)) if (!strlen($directory))
$note='Please specify a directory that is writable by the web server.'; $note = 'Please specify a directory that is writable by the web server.';
elseif (!file_exists($directory)) elseif (!file_exists($directory))
$error='This directory cannot be found. Please enter the full path.'; $error = 'This directory cannot be found. Please enter the full path.';
elseif (!is_dir($directory)) elseif (!is_dir($directory))
$error='This is a file. Please enter the full path of a directory.'; $error = 'This is a file. Please enter the full path of a directory.';
elseif (!is_writable($directory)) elseif (!is_writable($directory))
$error='This directory is not writable by the web server. Please choose a different directory, use chown/chmod to change permissions, or contact your web hosting company for assistance.'; $error = 'This directory is not writable by the web server. Please choose a different directory, use chown/chmod to change permissions, or contact your web hosting company for assistance.';
// Create the form for display // Create the form for display
...@@ -103,7 +102,7 @@ class qa_event_logger ...@@ -103,7 +102,7 @@ class qa_event_logger
'fields' => array( 'fields' => array(
array( array(
'label' => 'Log events to <code>'.QA_MYSQL_TABLE_PREFIX.'eventlog</code> database table', 'label' => 'Log events to <code>' . QA_MYSQL_TABLE_PREFIX . 'eventlog</code> database table',
'tags' => 'name="event_logger_to_database_field"', 'tags' => 'name="event_logger_to_database_field"',
'value' => qa_opt('event_logger_to_database'), 'value' => qa_opt('event_logger_to_database'),
'type' => 'checkbox', 'type' => 'checkbox',
...@@ -147,11 +146,11 @@ class qa_event_logger ...@@ -147,11 +146,11 @@ class qa_event_logger
public function value_to_text($value) public function value_to_text($value)
{ {
if (is_array($value)) if (is_array($value))
$text='array('.count($value).')'; $text = 'array(' . count($value) . ')';
elseif (strlen($value)>40) elseif (strlen($value) > 40)
$text=substr($value, 0, 38).'...'; $text = substr($value, 0, 38) . '...';
else else
$text=$value; $text = $value;
return strtr($text, "\t\n\r", ' '); return strtr($text, "\t\n\r", ' ');
} }
...@@ -160,13 +159,14 @@ class qa_event_logger ...@@ -160,13 +159,14 @@ class qa_event_logger
public function process_event($event, $userid, $handle, $cookieid, $params) public function process_event($event, $userid, $handle, $cookieid, $params)
{ {
if (qa_opt('event_logger_to_database')) { if (qa_opt('event_logger_to_database')) {
$paramstring=''; $paramstring = '';
foreach ($params as $key => $value) foreach ($params as $key => $value) {
$paramstring.=(strlen($paramstring) ? "\t" : '').$key.'='.$this->value_to_text($value); $paramstring .= (strlen($paramstring) ? "\t" : '') . $key . '=' . $this->value_to_text($value);
}
qa_db_query_sub( qa_db_query_sub(
'INSERT INTO ^eventlog (datetime, ipaddress, userid, handle, cookieid, event, params) '. 'INSERT INTO ^eventlog (datetime, ipaddress, userid, handle, cookieid, event, params) ' .
'VALUES (NOW(), $, $, $, #, $, $)', 'VALUES (NOW(), $, $, $, #, $, $)',
qa_remote_ip_address(), $userid, $handle, $cookieid, $event, $paramstring qa_remote_ip_address(), $userid, $handle, $cookieid, $event, $paramstring
); );
...@@ -177,21 +177,21 @@ class qa_event_logger ...@@ -177,21 +177,21 @@ class qa_event_logger
// Substitute some placeholders if certain information is missing // Substitute some placeholders if certain information is missing
if (!strlen($userid)) if (!strlen($userid))
$userid='no_userid'; $userid = 'no_userid';
if (!strlen($handle)) if (!strlen($handle))
$handle='no_handle'; $handle = 'no_handle';
if (!strlen($cookieid)) if (!strlen($cookieid))
$cookieid='no_cookieid'; $cookieid = 'no_cookieid';
$ip=qa_remote_ip_address(); $ip = qa_remote_ip_address();
if (!strlen($ip)) if (!strlen($ip))
$ip='no_ipaddress'; $ip = 'no_ipaddress';
// Build the log file line to be written // Build the log file line to be written
$fixedfields=array( $fixedfields = array(
'Date' => date('Y\-m\-d'), 'Date' => date('Y\-m\-d'),
'Time' => date('H\:i\:s'), 'Time' => date('H\:i\:s'),
'IPaddress' => $ip, 'IPaddress' => $ip,
...@@ -201,36 +201,38 @@ class qa_event_logger ...@@ -201,36 +201,38 @@ class qa_event_logger
'Event' => $event, 'Event' => $event,
); );
$fields=$fixedfields; $fields = $fixedfields;
foreach ($params as $key => $value) foreach ($params as $key => $value) {
$fields['param_'.$key]=$key.'='.$this->value_to_text($value); $fields['param_' . $key] = $key . '=' . $this->value_to_text($value);
}
$string=implode("\t", $fields); $string = implode("\t", $fields);
// Build the full path and file name // Build the full path and file name
$directory=qa_opt('event_logger_directory'); $directory = qa_opt('event_logger_directory');
if (substr($directory, -1)!='/') if (substr($directory, -1) != '/')
$directory.='/'; $directory .= '/';
$filename=$directory.'q2a-log-'.date('Y\-m\-d').'.txt'; $filename = $directory . 'q2a-log-' . date('Y\-m\-d') . '.txt';
// Open, lock, write, unlock, close (to prevent interference between multiple writes) // Open, lock, write, unlock, close (to prevent interference between multiple writes)
$exists=file_exists($filename); $exists = file_exists($filename);
$file=@fopen($filename, 'a'); $file = @fopen($filename, 'a');
if (is_resource($file)) { if (is_resource($file)) {
if (flock($file, LOCK_EX)) { if (flock($file, LOCK_EX)) {
if ( (!$exists) && (filesize($filename)===0) && !qa_opt('event_logger_hide_header') ) if (!$exists && filesize($filename) === 0 && !qa_opt('event_logger_hide_header')) {
$string="Question2Answer ".QA_VERSION." log file generated by Event Logger plugin.\n". $string = "Question2Answer " . QA_VERSION . " log file generated by Event Logger plugin.\n" .
"This file is formatted as tab-delimited text with UTF-8 encoding.\n\n". "This file is formatted as tab-delimited text with UTF-8 encoding.\n\n" .
implode("\t", array_keys($fixedfields))."\textras...\n\n".$string; implode("\t", array_keys($fixedfields)) . "\textras...\n\n" . $string;
}
fwrite($file, $string."\n"); fwrite($file, $string . "\n");
flock($file, LOCK_UN); flock($file, LOCK_UN);
} }
......
...@@ -28,8 +28,8 @@ class qa_example_page ...@@ -28,8 +28,8 @@ class qa_example_page
public function load_module($directory, $urltoroot) public function load_module($directory, $urltoroot)
{ {
$this->directory=$directory; $this->directory = $directory;
$this->urltoroot=$urltoroot; $this->urltoroot = $urltoroot;
} }
...@@ -53,14 +53,14 @@ class qa_example_page ...@@ -53,14 +53,14 @@ class qa_example_page
public function process_request($request) public function process_request($request)
{ {
$qa_content=qa_content_prepare(); $qa_content = qa_content_prepare();
$qa_content['title']=qa_lang_html('example_page/page_title'); $qa_content['title'] = qa_lang_html('example_page/page_title');
$qa_content['error']='An example error'; $qa_content['error'] = 'An example error';
$qa_content['custom']='Some <b>custom html</b>'; $qa_content['custom'] = 'Some <b>custom html</b>';
$qa_content['form']=array( $qa_content['form'] = array(
'tags' => 'method="post" action="'.qa_self_html().'"', 'tags' => 'method="post" action="' . qa_self_html() . '"',
'style' => 'wide', 'style' => 'wide',
...@@ -91,7 +91,7 @@ class qa_example_page ...@@ -91,7 +91,7 @@ class qa_example_page
), ),
); );
$qa_content['custom_2']='<p><br>More <i>custom html</i></p>'; $qa_content['custom_2'] = '<p><br>More <i>custom html</i></p>';
return $qa_content; return $qa_content;
} }
......
...@@ -26,25 +26,25 @@ class qa_facebook_login_page ...@@ -26,25 +26,25 @@ class qa_facebook_login_page
public function load_module($directory, $urltoroot) public function load_module($directory, $urltoroot)
{ {
$this->directory=$directory; $this->directory = $directory;
} }
public function match_request($request) public function match_request($request)
{ {
return ($request=='facebook-login'); return ($request == 'facebook-login');
} }
public function process_request($request) public function process_request($request)
{ {
if ($request=='facebook-login') { if ($request == 'facebook-login') {
$app_id=qa_opt('facebook_app_id'); $app_id = qa_opt('facebook_app_id');
$app_secret=qa_opt('facebook_app_secret'); $app_secret = qa_opt('facebook_app_secret');
$tourl=qa_get('to'); $tourl = qa_get('to');
if (!strlen($tourl)) if (!strlen($tourl))
$tourl=qa_path_absolute(''); $tourl = qa_path_absolute('');
if (strlen($app_id) && strlen($app_secret)) { if (strlen($app_id) && strlen($app_secret)) {
require_once $this->directory.'facebook.php'; require_once $this->directory . 'facebook.php';
$facebook = new Facebook(array( $facebook = new Facebook(array(
'appId' => $app_id, 'appId' => $app_id,
...@@ -52,11 +52,11 @@ class qa_facebook_login_page ...@@ -52,11 +52,11 @@ class qa_facebook_login_page
'cookie' => true, 'cookie' => true,
)); ));
$fb_userid=$facebook->getUser(); $fb_userid = $facebook->getUser();
if ($fb_userid) { if ($fb_userid) {
try { try {
$user=$facebook->api('/me?fields=email,name,verified,location,website,about,picture.width(250)'); $user = $facebook->api('/me?fields=email,name,verified,location,website,about,picture.width(250)');
if (is_array($user)) if (is_array($user))
qa_log_in_external_user('facebook', $fb_userid, array( qa_log_in_external_user('facebook', $fb_userid, array(
......
...@@ -24,13 +24,13 @@ class qa_facebook_login ...@@ -24,13 +24,13 @@ class qa_facebook_login
{ {
public function match_source($source) public function match_source($source)
{ {
return $source=='facebook'; return $source == 'facebook';
} }
public function login_html($tourl, $context) public function login_html($tourl, $context)
{ {
$app_id=qa_opt('facebook_app_id'); $app_id = qa_opt('facebook_app_id');
if (!strlen($app_id)) if (!strlen($app_id))
return; return;
...@@ -41,7 +41,7 @@ class qa_facebook_login ...@@ -41,7 +41,7 @@ class qa_facebook_login
public function logout_html($tourl) public function logout_html($tourl)
{ {
$app_id=qa_opt('facebook_app_id'); $app_id = qa_opt('facebook_app_id');
if (!strlen($app_id)) if (!strlen($app_id))
return; return;
...@@ -52,10 +52,10 @@ class qa_facebook_login ...@@ -52,10 +52,10 @@ class qa_facebook_login
public function facebook_html($tourl, $logout, $context) public function facebook_html($tourl, $logout, $context)
{ {
if (($context=='login') || ($context=='register')) if (($context == 'login') || ($context == 'register'))
$size='large'; $size = 'large';
else else
$size='medium'; $size = 'medium';
?> ?>
<div id="fb-root" style="display:inline;"></div> <div id="fb-root" style="display:inline;"></div>
...@@ -89,15 +89,15 @@ class qa_facebook_login ...@@ -89,15 +89,15 @@ class qa_facebook_login
public function admin_form() public function admin_form()
{ {
$saved=false; $saved = false;
if (qa_clicked('facebook_save_button')) { if (qa_clicked('facebook_save_button')) {
qa_opt('facebook_app_id', qa_post_text('facebook_app_id_field')); qa_opt('facebook_app_id', qa_post_text('facebook_app_id_field'));
qa_opt('facebook_app_secret', qa_post_text('facebook_app_secret_field')); qa_opt('facebook_app_secret', qa_post_text('facebook_app_secret_field'));
$saved=true; $saved = true;
} }
$ready=strlen(qa_opt('facebook_app_id')) && strlen(qa_opt('facebook_app_secret')); $ready = strlen(qa_opt('facebook_app_id')) && strlen(qa_opt('facebook_app_secret'));
return array( return array(
'ok' => $saved ? 'Facebook application details saved' : null, 'ok' => $saved ? 'Facebook application details saved' : null,
......
...@@ -26,6 +26,6 @@ class qa_html_theme_layer extends qa_html_theme_base ...@@ -26,6 +26,6 @@ class qa_html_theme_layer extends qa_html_theme_base
{ {
qa_html_theme_base::head_links(); qa_html_theme_base::head_links();
$this->output('<link rel="search" type="application/opensearchdescription+xml" title="'.qa_html(qa_opt('site_title')).'" href="'.qa_path_html('opensearch.xml').'"/>'); $this->output('<link rel="search" type="application/opensearchdescription+xml" title="' . qa_html(qa_opt('site_title')) . '" href="' . qa_path_html('opensearch.xml') . '"/>');
} }
} }
...@@ -24,27 +24,27 @@ class qa_opensearch_xml ...@@ -24,27 +24,27 @@ class qa_opensearch_xml
{ {
public function match_request($request) public function match_request($request)
{ {
return ($request=='opensearch.xml'); return ($request == 'opensearch.xml');
} }
public function process_request($request) public function process_request($request)
{ {
@ini_set('display_errors', 0); // we don't want to show PHP errors inside XML @ini_set('display_errors', 0); // we don't want to show PHP errors inside XML
$titlexml=qa_xml(qa_opt('site_title')); $titlexml = qa_xml(qa_opt('site_title'));
$template=str_replace('_searchTerms_placeholder_', '{searchTerms}', qa_path_absolute('search', array('q' => '_searchTerms_placeholder_'))); $template = str_replace('_searchTerms_placeholder_', '{searchTerms}', qa_path_absolute('search', array('q' => '_searchTerms_placeholder_')));
header('Content-type: text/xml; charset=utf-8'); header('Content-type: text/xml; charset=utf-8');
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n"; echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">'."\n"; echo '<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">' . "\n";
echo "\t<ShortName>".$titlexml."</ShortName>\n"; echo "\t<ShortName>" . $titlexml . "</ShortName>\n";
echo "\t<Description>".qa_xml(qa_lang('main/search_button')).' '.$titlexml."</Description>\n"; echo "\t<Description>" . qa_xml(qa_lang('main/search_button')) . ' ' . $titlexml . "</Description>\n";
echo "\t".'<Url type="text/html" method="get" template="'.qa_xml($template).'"/>'."\n"; echo "\t" . '<Url type="text/html" method="get" template="' . qa_xml($template) . '"/>' . "\n";
echo "\t<InputEncoding>UTF-8</InputEncoding>\n"; echo "\t<InputEncoding>UTF-8</InputEncoding>\n";
echo '</OpenSearchDescription>'."\n"; echo '</OpenSearchDescription>' . "\n";
return null; return null;
} }
......
...@@ -37,9 +37,9 @@ class qa_xml_sitemap ...@@ -37,9 +37,9 @@ class qa_xml_sitemap
public function admin_form() public function admin_form()
{ {
require_once QA_INCLUDE_DIR.'util/sort.php'; require_once QA_INCLUDE_DIR . 'util/sort.php';
$saved=false; $saved = false;
if (qa_clicked('xml_sitemap_save_button')) { if (qa_clicked('xml_sitemap_save_button')) {
qa_opt('xml_sitemap_show_questions', (int)qa_post_text('xml_sitemap_show_questions_field')); qa_opt('xml_sitemap_show_questions', (int)qa_post_text('xml_sitemap_show_questions_field'));
...@@ -55,10 +55,10 @@ class qa_xml_sitemap ...@@ -55,10 +55,10 @@ class qa_xml_sitemap
qa_opt('xml_sitemap_show_categories', (int)qa_post_text('xml_sitemap_show_categories_field')); qa_opt('xml_sitemap_show_categories', (int)qa_post_text('xml_sitemap_show_categories_field'));
} }
$saved=true; $saved = true;
} }
$form=array( $form = array(
'ok' => $saved ? 'XML sitemap settings saved' : null, 'ok' => $saved ? 'XML sitemap settings saved' : null,
'fields' => array( 'fields' => array(
...@@ -78,31 +78,33 @@ class qa_xml_sitemap ...@@ -78,31 +78,33 @@ class qa_xml_sitemap
), ),
); );
if (!QA_FINAL_EXTERNAL_USERS) if (!QA_FINAL_EXTERNAL_USERS) {
$form['fields']['users']=array( $form['fields']['users'] = array(
'label' => 'Include user pages', 'label' => 'Include user pages',
'type' => 'checkbox', 'type' => 'checkbox',
'value' => (int)qa_opt('xml_sitemap_show_users'), 'value' => (int)qa_opt('xml_sitemap_show_users'),
'tags' => 'name="xml_sitemap_show_users_field"', 'tags' => 'name="xml_sitemap_show_users_field"',
); );
}
if (qa_using_tags()) if (qa_using_tags()) {
$form['fields']['tagqs']=array( $form['fields']['tagqs'] = array(
'label' => 'Include question list for each tag', 'label' => 'Include question list for each tag',
'type' => 'checkbox', 'type' => 'checkbox',
'value' => (int)qa_opt('xml_sitemap_show_tag_qs'), 'value' => (int)qa_opt('xml_sitemap_show_tag_qs'),
'tags' => 'name="xml_sitemap_show_tag_qs_field"', 'tags' => 'name="xml_sitemap_show_tag_qs_field"',
); );
}
if (qa_using_categories()) { if (qa_using_categories()) {
$form['fields']['categoryqs']=array( $form['fields']['categoryqs'] = array(
'label' => 'Include question list for each category', 'label' => 'Include question list for each category',
'type' => 'checkbox', 'type' => 'checkbox',
'value' => (int)qa_opt('xml_sitemap_show_category_qs'), 'value' => (int)qa_opt('xml_sitemap_show_category_qs'),
'tags' => 'name="xml_sitemap_show_category_qs_field"', 'tags' => 'name="xml_sitemap_show_category_qs_field"',
); );
$form['fields']['categories']=array( $form['fields']['categories'] = array(
'label' => 'Include category browser', 'label' => 'Include category browser',
'type' => 'checkbox', 'type' => 'checkbox',
'value' => (int)qa_opt('xml_sitemap_show_categories'), 'value' => (int)qa_opt('xml_sitemap_show_categories'),
...@@ -128,7 +130,7 @@ class qa_xml_sitemap ...@@ -128,7 +130,7 @@ class qa_xml_sitemap
public function match_request($request) public function match_request($request)
{ {
return ($request=='sitemap.xml'); return ($request == 'sitemap.xml');
} }
...@@ -138,21 +140,21 @@ class qa_xml_sitemap ...@@ -138,21 +140,21 @@ class qa_xml_sitemap
header('Content-type: text/xml; charset=utf-8'); header('Content-type: text/xml; charset=utf-8');
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n"; echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n"; echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
// Question pages // Question pages
if (qa_opt('xml_sitemap_show_questions')) { if (qa_opt('xml_sitemap_show_questions')) {
$hotstats=qa_db_read_one_assoc(qa_db_query_sub( $hotstats = qa_db_read_one_assoc(qa_db_query_sub(
"SELECT MIN(hotness) AS base, MAX(hotness)-MIN(hotness) AS spread FROM ^posts WHERE type='Q'" "SELECT MIN(hotness) AS base, MAX(hotness)-MIN(hotness) AS spread FROM ^posts WHERE type='Q'"
)); ));
$nextpostid=0; $nextpostid = 0;
while (1) { while (1) {
$questions=qa_db_read_all_assoc(qa_db_query_sub( $questions = qa_db_read_all_assoc(qa_db_query_sub(
"SELECT postid, title, hotness FROM ^posts WHERE postid>=# AND type='Q' ORDER BY postid LIMIT 100", "SELECT postid, title, hotness FROM ^posts WHERE postid>=# AND type='Q' ORDER BY postid LIMIT 100",
$nextpostid $nextpostid
)); ));
...@@ -162,8 +164,8 @@ class qa_xml_sitemap ...@@ -162,8 +164,8 @@ class qa_xml_sitemap
foreach ($questions as $question) { foreach ($questions as $question) {
$this->sitemap_output(qa_q_request($question['postid'], $question['title']), $this->sitemap_output(qa_q_request($question['postid'], $question['title']),
0.1+0.9*($question['hotness']-$hotstats['base'])/(1+$hotstats['spread'])); 0.1 + 0.9 * ($question['hotness'] - $hotstats['base']) / (1 + $hotstats['spread']));
$nextpostid=max($nextpostid, $question['postid']+1); $nextpostid = max($nextpostid, $question['postid'] + 1);
} }
} }
} }
...@@ -172,10 +174,10 @@ class qa_xml_sitemap ...@@ -172,10 +174,10 @@ class qa_xml_sitemap
// User pages // User pages
if ((!QA_FINAL_EXTERNAL_USERS) && qa_opt('xml_sitemap_show_users')) { if ((!QA_FINAL_EXTERNAL_USERS) && qa_opt('xml_sitemap_show_users')) {
$nextuserid=0; $nextuserid = 0;
while (1) { while (1) {
$users=qa_db_read_all_assoc(qa_db_query_sub( $users = qa_db_read_all_assoc(qa_db_query_sub(
"SELECT userid, handle FROM ^users WHERE userid>=# ORDER BY userid LIMIT 100", "SELECT userid, handle FROM ^users WHERE userid>=# ORDER BY userid LIMIT 100",
$nextuserid $nextuserid
)); ));
...@@ -184,8 +186,8 @@ class qa_xml_sitemap ...@@ -184,8 +186,8 @@ class qa_xml_sitemap
break; break;
foreach ($users as $user) { foreach ($users as $user) {
$this->sitemap_output('user/'.$user['handle'], 0.25); $this->sitemap_output('user/' . $user['handle'], 0.25);
$nextuserid=max($nextuserid, $user['userid']+1); $nextuserid = max($nextuserid, $user['userid'] + 1);
} }
} }
} }
...@@ -194,10 +196,10 @@ class qa_xml_sitemap ...@@ -194,10 +196,10 @@ class qa_xml_sitemap
// Tag pages // Tag pages
if (qa_using_tags() && qa_opt('xml_sitemap_show_tag_qs')) { if (qa_using_tags() && qa_opt('xml_sitemap_show_tag_qs')) {
$nextwordid=0; $nextwordid = 0;
while (1) { while (1) {
$tagwords=qa_db_read_all_assoc(qa_db_query_sub( $tagwords = qa_db_read_all_assoc(qa_db_query_sub(
"SELECT wordid, word, tagcount FROM ^words WHERE wordid>=# AND tagcount>0 ORDER BY wordid LIMIT 100", "SELECT wordid, word, tagcount FROM ^words WHERE wordid>=# AND tagcount>0 ORDER BY wordid LIMIT 100",
$nextwordid $nextwordid
)); ));
...@@ -206,8 +208,8 @@ class qa_xml_sitemap ...@@ -206,8 +208,8 @@ class qa_xml_sitemap
break; break;
foreach ($tagwords as $tagword) { foreach ($tagwords as $tagword) {
$this->sitemap_output('tag/'.$tagword['word'], 0.5/(1+(1/$tagword['tagcount']))); // priority between 0.25 and 0.5 depending on tag frequency $this->sitemap_output('tag/' . $tagword['word'], 0.5 / (1 + (1 / $tagword['tagcount']))); // priority between 0.25 and 0.5 depending on tag frequency
$nextwordid=max($nextwordid, $tagword['wordid']+1); $nextwordid = max($nextwordid, $tagword['wordid'] + 1);
} }
} }
} }
...@@ -216,10 +218,10 @@ class qa_xml_sitemap ...@@ -216,10 +218,10 @@ class qa_xml_sitemap
// Question list for each category // Question list for each category
if (qa_using_categories() && qa_opt('xml_sitemap_show_category_qs')) { if (qa_using_categories() && qa_opt('xml_sitemap_show_category_qs')) {
$nextcategoryid=0; $nextcategoryid = 0;
while (1) { while (1) {
$categories=qa_db_read_all_assoc(qa_db_query_sub( $categories = qa_db_read_all_assoc(qa_db_query_sub(
"SELECT categoryid, backpath FROM ^categories WHERE categoryid>=# AND qcount>0 ORDER BY categoryid LIMIT 2", "SELECT categoryid, backpath FROM ^categories WHERE categoryid>=# AND qcount>0 ORDER BY categoryid LIMIT 2",
$nextcategoryid $nextcategoryid
)); ));
...@@ -228,8 +230,8 @@ class qa_xml_sitemap ...@@ -228,8 +230,8 @@ class qa_xml_sitemap
break; break;
foreach ($categories as $category) { foreach ($categories as $category) {
$this->sitemap_output('questions/'.implode('/', array_reverse(explode('/', $category['backpath']))), 0.5); $this->sitemap_output('questions/' . implode('/', array_reverse(explode('/', $category['backpath']))), 0.5);
$nextcategoryid=max($nextcategoryid, $category['categoryid']+1); $nextcategoryid = max($nextcategoryid, $category['categoryid'] + 1);
} }
} }
} }
...@@ -240,11 +242,11 @@ class qa_xml_sitemap ...@@ -240,11 +242,11 @@ class qa_xml_sitemap
if (qa_using_categories() && qa_opt('xml_sitemap_show_categories')) { if (qa_using_categories() && qa_opt('xml_sitemap_show_categories')) {
$this->sitemap_output('categories', 0.5); $this->sitemap_output('categories', 0.5);
$nextcategoryid=0; $nextcategoryid = 0;
while (1) { // only find categories with a child while (1) { // only find categories with a child
$categories=qa_db_read_all_assoc(qa_db_query_sub( $categories = qa_db_read_all_assoc(qa_db_query_sub(
"SELECT parent.categoryid, parent.backpath FROM ^categories AS parent ". "SELECT parent.categoryid, parent.backpath FROM ^categories AS parent " .
"JOIN ^categories AS child ON child.parentid=parent.categoryid WHERE parent.categoryid>=# GROUP BY parent.categoryid LIMIT 100", "JOIN ^categories AS child ON child.parentid=parent.categoryid WHERE parent.categoryid>=# GROUP BY parent.categoryid LIMIT 100",
$nextcategoryid $nextcategoryid
)); ));
...@@ -253,8 +255,8 @@ class qa_xml_sitemap ...@@ -253,8 +255,8 @@ class qa_xml_sitemap
break; break;
foreach ($categories as $category) { foreach ($categories as $category) {
$this->sitemap_output('categories/'.implode('/', array_reverse(explode('/', $category['backpath']))), 0.5); $this->sitemap_output('categories/' . implode('/', array_reverse(explode('/', $category['backpath']))), 0.5);
$nextcategoryid=max($nextcategoryid, $category['categoryid']+1); $nextcategoryid = max($nextcategoryid, $category['categoryid'] + 1);
} }
} }
} }
...@@ -271,9 +273,9 @@ class qa_xml_sitemap ...@@ -271,9 +273,9 @@ class qa_xml_sitemap
*/ */
public function sitemap_output($request, $priority) public function sitemap_output($request, $priority)
{ {
echo "\t<url>\n". echo "\t<url>\n" .
"\t\t<loc>".qa_xml(qa_path($request, null, qa_opt('site_url')))."</loc>\n". "\t\t<loc>" . qa_xml(qa_path($request, null, qa_opt('site_url'))) . "</loc>\n" .
"\t\t<priority>".max(0, min(1.0, $priority))."</priority>\n". "\t\t<priority>" . max(0, min(1.0, $priority)) . "</priority>\n" .
"\t</url>\n"; "\t</url>\n";
} }
} }
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