Commit 59ad6e0a by Scott

Coding style (default plugins)

parent 9b5766d2
...@@ -20,93 +20,85 @@ ...@@ -20,93 +20,85 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
class qa_basic_adsense { class qa_basic_adsense
{
public function allow_template($template) public function allow_template($template)
{ {
return ($template!='admin'); return ($template!='admin');
} }
public function allow_region($region) public function allow_region($region)
{ {
return in_array($region, array('main', 'side', 'full')); return in_array($region, array('main', 'side', 'full'));
} }
public function admin_form(&$qa_content) public function admin_form(&$qa_content)
{ {
$saved=false; $saved=false;
if (qa_clicked('adsense_save_button')) { if (qa_clicked('adsense_save_button')) {
$trimchars="=;\"\' \t\r\n"; // prevent common errors by copying and pasting from Javascript $trimchars="=;\"\' \t\r\n"; // prevent common errors by copying and pasting from Javascript
qa_opt('adsense_publisher_id', trim(qa_post_text('adsense_publisher_id_field'), $trimchars)); qa_opt('adsense_publisher_id', trim(qa_post_text('adsense_publisher_id_field'), $trimchars));
$saved=true; $saved=true;
} }
return array( return array(
'ok' => $saved ? 'AdSense settings saved' : null, 'ok' => $saved ? 'AdSense settings saved' : null,
'fields' => array( 'fields' => array(
array( array(
'label' => 'AdSense Publisher ID:', 'label' => 'AdSense Publisher ID:',
'value' => qa_html(qa_opt('adsense_publisher_id')), 'value' => qa_html(qa_opt('adsense_publisher_id')),
'tags' => 'name="adsense_publisher_id_field"', 'tags' => 'name="adsense_publisher_id_field"',
'note' => 'Example: <i>pub-1234567890123456</i>', 'note' => 'Example: <i>pub-1234567890123456</i>',
),
), ),
),
'buttons' => array( 'buttons' => array(
array( array(
'label' => 'Save Changes', 'label' => 'Save Changes',
'tags' => 'name="adsense_save_button"', 'tags' => 'name="adsense_save_button"',
),
), ),
); ),
} );
}
public function output_widget($region, $place, $themeobject, $template, $request, $qa_content) public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
{ {
$divstyle=''; $divstyle='';
switch ($region) { switch ($region) {
case 'full': // Leaderboard case 'full': // Leaderboard
$divstyle='width:728px; margin:0 auto;'; $divstyle='width:728px; margin:0 auto;';
case 'main': // Leaderboard case 'main': // Leaderboard
$width=728; $width=728;
$height=90; $height=90;
$format='728x90_as'; $format='728x90_as';
break; break;
case 'side': // Wide skyscraper case 'side': // Wide skyscraper
$width=160; $width=160;
$height=600; $height=600;
$format='160x600_as'; $format='160x600_as';
break; break;
} }
?> ?>
<div style="<?php echo $divstyle?>"> <div style="<?php echo $divstyle?>">
<script type="text/javascript"> <script type="text/javascript">
google_ad_client = <?php echo qa_js(qa_opt('adsense_publisher_id'))?>; google_ad_client = <?php echo qa_js(qa_opt('adsense_publisher_id'))?>;
google_ad_width = <?php echo qa_js($width)?>; google_ad_width = <?php echo qa_js($width)?>;
google_ad_height = <?php echo qa_js($height)?>; google_ad_height = <?php echo qa_js($height)?>;
google_ad_format = <?php echo qa_js($format)?>; google_ad_format = <?php echo qa_js($format)?>;
google_ad_type = "text_image"; google_ad_type = "text_image";
google_ad_channel = ""; google_ad_channel = "";
</script> </script>
<script type="text/javascript" <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div> </div>
<?php <?php
}
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -34,15 +34,10 @@ ...@@ -34,15 +34,10 @@
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../'); header('Location: ../../');
exit; exit;
} }
qa_register_plugin_module('widget', 'qa-basic-adsense.php', 'qa_basic_adsense', 'Basic AdSense'); qa_register_plugin_module('widget', 'qa-basic-adsense.php', 'qa_basic_adsense', 'Basic AdSense');
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,218 +20,212 @@ ...@@ -20,218 +20,212 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
class qa_event_logger { 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)) {
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 (15) CHARACTER SET ascii,'. 'ipaddress VARCHAR (15) 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';
}
} }
} }
}
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'));
qa_opt('event_logger_to_files', qa_post_text('event_logger_to_files_field')); qa_opt('event_logger_to_files', qa_post_text('event_logger_to_files_field'));
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;
$error=null;
if (!strlen($directory))
$note='Please specify a directory that is writable by the web server.';
elseif (!file_exists($directory))
$error='This directory cannot be found. Please enter the full path.';
elseif (!is_dir($directory))
$error='This is a file. Please enter the full path of a 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.';
// Create the form for display
$note=null; qa_set_display_rules($qa_content, array(
$error=null; 'event_logger_directory_display' => 'event_logger_to_files_field',
'event_logger_hide_header_display' => 'event_logger_to_files_field',
if (!strlen($directory)) ));
$note='Please specify a directory that is writable by the web server.';
elseif (!file_exists($directory)) return array(
$error='This directory cannot be found. Please enter the full path.'; 'ok' => ($saved && !isset($error)) ? 'Event log settings saved' : null,
elseif (!is_dir($directory))
$error='This is a file. Please enter the full path of a directory.'; 'fields' => array(
elseif (!is_writable($directory)) array(
$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.'; 'label' => 'Log events to <code>'.QA_MYSQL_TABLE_PREFIX.'eventlog</code> database table',
'tags' => 'name="event_logger_to_database_field"',
// Create the form for display 'value' => qa_opt('event_logger_to_database'),
'type' => 'checkbox',
qa_set_display_rules($qa_content, array(
'event_logger_directory_display' => 'event_logger_to_files_field',
'event_logger_hide_header_display' => 'event_logger_to_files_field',
));
return array(
'ok' => ($saved && !isset($error)) ? 'Event log settings saved' : null,
'fields' => array(
array(
'label' => 'Log events to <code>'.QA_MYSQL_TABLE_PREFIX.'eventlog</code> database table',
'tags' => 'name="event_logger_to_database_field"',
'value' => qa_opt('event_logger_to_database'),
'type' => 'checkbox',
),
array(
'label' => 'Log events to daily log files',
'tags' => 'name="event_logger_to_files_field" id="event_logger_to_files_field"',
'value' => qa_opt('event_logger_to_files'),
'type' => 'checkbox',
),
array(
'id' => 'event_logger_directory_display',
'label' => 'Directory for log files - enter full path:',
'value' => qa_html($directory),
'tags' => 'name="event_logger_directory_field"',
'note' => $note,
'error' => qa_html($error),
),
array(
'id' => 'event_logger_hide_header_display',
'label' => 'Include header lines at top of each log file',
'type' => 'checkbox',
'tags' => 'name="event_logger_hide_header_field"',
'value' => !qa_opt('event_logger_hide_header'),
),
), ),
'buttons' => array( array(
array( 'label' => 'Log events to daily log files',
'label' => 'Save Changes', 'tags' => 'name="event_logger_to_files_field" id="event_logger_to_files_field"',
'tags' => 'name="event_logger_save_button"', 'value' => qa_opt('event_logger_to_files'),
), 'type' => 'checkbox',
), ),
);
}
array(
'id' => 'event_logger_directory_display',
'label' => 'Directory for log files - enter full path:',
'value' => qa_html($directory),
'tags' => 'name="event_logger_directory_field"',
'note' => $note,
'error' => qa_html($error),
),
public function value_to_text($value) array(
{ 'id' => 'event_logger_hide_header_display',
if (is_array($value)) 'label' => 'Include header lines at top of each log file',
$text='array('.count($value).')'; 'type' => 'checkbox',
elseif (strlen($value)>40) 'tags' => 'name="event_logger_hide_header_field"',
$text=substr($value, 0, 38).'...'; 'value' => !qa_opt('event_logger_hide_header'),
else ),
$text=$value; ),
return strtr($text, "\t\n\r", ' '); 'buttons' => array(
} array(
'label' => 'Save Changes',
'tags' => 'name="event_logger_save_button"',
),
),
);
}
public function process_event($event, $userid, $handle, $cookieid, $params) public function value_to_text($value)
{ {
if (qa_opt('event_logger_to_database')) { if (is_array($value))
$paramstring=''; $text='array('.count($value).')';
elseif (strlen($value)>40)
$text=substr($value, 0, 38).'...';
else
$text=$value;
foreach ($params as $key => $value) return strtr($text, "\t\n\r", ' ');
$paramstring.=(strlen($paramstring) ? "\t" : '').$key.'='.$this->value_to_text($value); }
qa_db_query_sub(
'INSERT INTO ^eventlog (datetime, ipaddress, userid, handle, cookieid, event, params) '.
'VALUES (NOW(), $, $, $, #, $, $)',
qa_remote_ip_address(), $userid, $handle, $cookieid, $event, $paramstring
);
}
if (qa_opt('event_logger_to_files')) { public function process_event($event, $userid, $handle, $cookieid, $params)
{
if (qa_opt('event_logger_to_database')) {
$paramstring='';
// Substitute some placeholders if certain information is missing foreach ($params as $key => $value)
$paramstring.=(strlen($paramstring) ? "\t" : '').$key.'='.$this->value_to_text($value);
if (!strlen($userid)) qa_db_query_sub(
$userid='no_userid'; 'INSERT INTO ^eventlog (datetime, ipaddress, userid, handle, cookieid, event, params) '.
'VALUES (NOW(), $, $, $, #, $, $)',
qa_remote_ip_address(), $userid, $handle, $cookieid, $event, $paramstring
);
}
if (!strlen($handle)) if (qa_opt('event_logger_to_files')) {
$handle='no_handle';
if (!strlen($cookieid)) // Substitute some placeholders if certain information is missing
$cookieid='no_cookieid';
$ip=qa_remote_ip_address(); if (!strlen($userid))
if (!strlen($ip)) $userid='no_userid';
$ip='no_ipaddress';
// Build the log file line to be written if (!strlen($handle))
$handle='no_handle';
$fixedfields=array( if (!strlen($cookieid))
'Date' => date('Y\-m\-d'), $cookieid='no_cookieid';
'Time' => date('H\:i\:s'),
'IPaddress' => $ip,
'UserID' => $userid,
'Username' => $handle,
'CookieID' => $cookieid,
'Event' => $event,
);
$fields=$fixedfields; $ip=qa_remote_ip_address();
if (!strlen($ip))
$ip='no_ipaddress';
foreach ($params as $key => $value) // Build the log file line to be written
$fields['param_'.$key]=$key.'='.$this->value_to_text($value);
$string=implode("\t", $fields); $fixedfields=array(
'Date' => date('Y\-m\-d'),
'Time' => date('H\:i\:s'),
'IPaddress' => $ip,
'UserID' => $userid,
'Username' => $handle,
'CookieID' => $cookieid,
'Event' => $event,
);
// Build the full path and file name $fields=$fixedfields;
$directory=qa_opt('event_logger_directory'); foreach ($params as $key => $value)
$fields['param_'.$key]=$key.'='.$this->value_to_text($value);
if (substr($directory, -1)!='/') $string=implode("\t", $fields);
$directory.='/';
$filename=$directory.'q2a-log-'.date('Y\-m\-d').'.txt'; // Build the full path and file name
// Open, lock, write, unlock, close (to prevent interference between multiple writes) $directory=qa_opt('event_logger_directory');
$exists=file_exists($filename); if (substr($directory, -1)!='/')
$directory.='/';
$file=@fopen($filename, 'a'); $filename=$directory.'q2a-log-'.date('Y\-m\-d').'.txt';
if (is_resource($file)) { // Open, lock, write, unlock, close (to prevent interference between multiple writes)
if (flock($file, LOCK_EX)) {
if ( (!$exists) && (filesize($filename)===0) && !qa_opt('event_logger_hide_header') )
$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".
implode("\t", array_keys($fixedfields))."\textras...\n\n".$string;
fwrite($file, $string."\n"); $exists=file_exists($filename);
flock($file, LOCK_UN);
}
fclose($file); $file=@fopen($filename, 'a');
if (is_resource($file)) {
if (flock($file, LOCK_EX)) {
if ( (!$exists) && (filesize($filename)===0) && !qa_opt('event_logger_hide_header') )
$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".
implode("\t", array_keys($fixedfields))."\textras...\n\n".$string;
fwrite($file, $string."\n");
flock($file, LOCK_UN);
} }
fclose($file);
} }
} }
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -34,15 +34,10 @@ ...@@ -34,15 +34,10 @@
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../'); header('Location: ../../');
exit; exit;
} }
qa_register_plugin_module('event', 'qa-event-logger.php', 'qa_event_logger', 'Event Logger'); qa_register_plugin_module('event', 'qa-event-logger.php', 'qa_event_logger', 'Event Logger');
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,11 +20,6 @@ ...@@ -20,11 +20,6 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
return array( return array(
'page_title' => 'Example plugin page (US English)', 'page_title' => 'Example plugin page (US English)',
); );
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,11 +20,6 @@ ...@@ -20,11 +20,6 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
return array( return array(
'page_title' => 'Example plugin page (UK English)', 'page_title' => 'Example plugin page (UK English)',
); );
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,85 +20,79 @@ ...@@ -20,85 +20,79 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
class qa_example_page { class qa_example_page
{
private $directory;
private $urltoroot;
private $directory;
private $urltoroot;
public function load_module($directory, $urltoroot)
public function load_module($directory, $urltoroot) {
{ $this->directory=$directory;
$this->directory=$directory; $this->urltoroot=$urltoroot;
$this->urltoroot=$urltoroot; }
}
public function suggest_requests() // for display in admin interface public function suggest_requests() // for display in admin interface
{ {
return array( return array(
array( array(
'title' => 'Example', 'title' => 'Example',
'request' => 'example-plugin-page', 'request' => 'example-plugin-page',
'nav' => 'M', // 'M'=main, 'F'=footer, 'B'=before main, 'O'=opposite main, null=none 'nav' => 'M', // 'M'=main, 'F'=footer, 'B'=before main, 'O'=opposite main, null=none
), ),
); );
} }
public function match_request($request)
{
return $request == 'example-plugin-page';
}
public function match_request($request)
{
return $request == 'example-plugin-page';
}
public function process_request($request)
{
$qa_content=qa_content_prepare();
$qa_content['title']=qa_lang_html('example_page/page_title'); public function process_request($request)
$qa_content['error']='An example error'; {
$qa_content['custom']='Some <b>custom html</b>'; $qa_content=qa_content_prepare();
$qa_content['form']=array( $qa_content['title']=qa_lang_html('example_page/page_title');
'tags' => 'method="post" action="'.qa_self_html().'"', $qa_content['error']='An example error';
$qa_content['custom']='Some <b>custom html</b>';
'style' => 'wide', $qa_content['form']=array(
'tags' => 'method="post" action="'.qa_self_html().'"',
'ok' => qa_post_text('okthen') ? 'You clicked OK then!' : null, 'style' => 'wide',
'title' => 'Form title', 'ok' => qa_post_text('okthen') ? 'You clicked OK then!' : null,
'fields' => array( 'title' => 'Form title',
'request' => array(
'label' => 'The request',
'tags' => 'name="request"',
'value' => qa_html($request),
'error' => qa_html('Another error'),
),
'fields' => array(
'request' => array(
'label' => 'The request',
'tags' => 'name="request"',
'value' => qa_html($request),
'error' => qa_html('Another error'),
), ),
'buttons' => array( ),
'ok' => array(
'tags' => 'name="okthen"',
'label' => 'OK then',
'value' => '1',
),
),
'hidden' => array( 'buttons' => array(
'hiddenfield' => '1', 'ok' => array(
'tags' => 'name="okthen"',
'label' => 'OK then',
'value' => '1',
), ),
); ),
$qa_content['custom_2']='<p><br>More <i>custom html</i></p>'; 'hidden' => array(
'hiddenfield' => '1',
),
);
return $qa_content; $qa_content['custom_2']='<p><br>More <i>custom html</i></p>';
}
return $qa_content;
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -34,16 +34,11 @@ ...@@ -34,16 +34,11 @@
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../'); header('Location: ../../');
exit; exit;
} }
qa_register_plugin_module('page', 'qa-example-page.php', 'qa_example_page', 'Example Page'); qa_register_plugin_module('page', 'qa-example-page.php', 'qa_example_page', 'Example Page');
qa_register_plugin_phrases('qa-example-lang-*.php', 'example_page'); qa_register_plugin_phrases('qa-example-lang-*.php', 'example_page');
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,23 +20,18 @@ ...@@ -20,23 +20,18 @@
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
{
public function head_css() public function head_css()
{ {
qa_html_theme_base::head_css(); qa_html_theme_base::head_css();
if (strlen(qa_opt('facebook_app_id')) && strlen(qa_opt('facebook_app_secret'))) if (strlen(qa_opt('facebook_app_id')) && strlen(qa_opt('facebook_app_secret'))) {
$this->output( $this->output(
'<style>', '<style>',
'.fb-login-button.fb_iframe_widget.fb_hide_iframes span {display:none;}', '.fb-login-button.fb_iframe_widget.fb_hide_iframes span {display:none;}',
'</style>' '</style>'
); );
} }
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,73 +20,68 @@ ...@@ -20,73 +20,68 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
class qa_facebook_login_page { class qa_facebook_login_page
{
private $directory; private $directory;
private $urltoroot; private $urltoroot;
public function load_module($directory, $urltoroot) public function load_module($directory, $urltoroot)
{ {
$this->directory=$directory; $this->directory=$directory;
$this->urltoroot=$urltoroot; $this->urltoroot=$urltoroot;
} }
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,
'secret' => $app_secret, 'secret' => $app_secret,
'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'); $user=$facebook->api('/me?fields=email,name,verified,location,website,about,picture');
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(
'email' => @$user['email'], 'email' => @$user['email'],
'handle' => @$user['name'], 'handle' => @$user['name'],
'confirmed' => @$user['verified'], 'confirmed' => @$user['verified'],
'name' => @$user['name'], 'name' => @$user['name'],
'location' => @$user['location']['name'], 'location' => @$user['location']['name'],
'website' => @$user['website'], 'website' => @$user['website'],
'about' => @$user['bio'], 'about' => @$user['bio'],
'avatar' => strlen(@$user['picture']['data']['url']) ? qa_retrieve_url($user['picture']['data']['url']) : null, 'avatar' => strlen(@$user['picture']['data']['url']) ? qa_retrieve_url($user['picture']['data']['url']) : null,
)); ));
} catch (FacebookApiException $e) { } catch (FacebookApiException $e) {
}
} else {
qa_redirect_raw($facebook->getLoginUrl(array('redirect_uri' => $tourl)));
} }
}
qa_redirect_raw($tourl); } else {
qa_redirect_raw($facebook->getLoginUrl(array('redirect_uri' => $tourl)));
}
} }
}
qa_redirect_raw($tourl);
}
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,116 +20,109 @@ ...@@ -20,116 +20,109 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
class qa_facebook_login { 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;
$this->facebook_html(qa_path_absolute('facebook-login', array('to' => $tourl)), false, $context); $this->facebook_html(qa_path_absolute('facebook-login', array('to' => $tourl)), false, $context);
} }
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;
$this->facebook_html($tourl, true, 'menu'); $this->facebook_html($tourl, true, 'menu');
} }
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>
<script> <script>
window.fbAsyncInit = function() { window.fbAsyncInit = function() {
FB.init({ FB.init({
appId : <?php echo qa_js(qa_opt('facebook_app_id'), true)?>, appId : <?php echo qa_js(qa_opt('facebook_app_id'), true)?>,
status : true, status : true,
cookie : true, cookie : true,
xfbml : true, xfbml : true,
oauth : true oauth : true
}); });
FB.Event.subscribe('<?php echo $logout ? 'auth.logout' : 'auth.login'?>', function(response) { FB.Event.subscribe('<?php echo $logout ? 'auth.logout' : 'auth.login'?>', function(response) {
setTimeout("window.location=<?php echo qa_js($tourl)?>", 100); setTimeout("window.location=<?php echo qa_js($tourl)?>", 100);
}); });
}; };
(function(d){ (function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true; js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js"; js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js); d.getElementsByTagName('head')[0].appendChild(js);
}(document)); }(document));
</script> </script>
<div class="fb-login-button" style="display:inline; vertical-align:middle;" size="<?php echo $size?>" <?php echo $logout ? 'autologoutlink="true"' : 'scope="email,user_about_me,user_location,user_website"'?>> <div class="fb-login-button" style="display:inline; vertical-align:middle;" size="<?php echo $size?>" <?php echo $logout ? 'autologoutlink="true"' : 'scope="email,user_about_me,user_location,user_website"'?>>
</div> </div>
<?php <?php
} }
public function admin_form()
{
$saved=false;
if (qa_clicked('facebook_save_button')) { public function admin_form()
qa_opt('facebook_app_id', qa_post_text('facebook_app_id_field')); {
qa_opt('facebook_app_secret', qa_post_text('facebook_app_secret_field')); $saved=false;
$saved=true;
}
$ready=strlen(qa_opt('facebook_app_id')) && strlen(qa_opt('facebook_app_secret')); if (qa_clicked('facebook_save_button')) {
qa_opt('facebook_app_id', qa_post_text('facebook_app_id_field'));
qa_opt('facebook_app_secret', qa_post_text('facebook_app_secret_field'));
$saved=true;
}
return array( $ready=strlen(qa_opt('facebook_app_id')) && strlen(qa_opt('facebook_app_secret'));
'ok' => $saved ? 'Facebook application details saved' : null,
'fields' => array( return array(
array( 'ok' => $saved ? 'Facebook application details saved' : null,
'label' => 'Facebook App ID:',
'value' => qa_html(qa_opt('facebook_app_id')),
'tags' => 'name="facebook_app_id_field"',
),
array( 'fields' => array(
'label' => 'Facebook App Secret:', array(
'value' => qa_html(qa_opt('facebook_app_secret')), 'label' => 'Facebook App ID:',
'tags' => 'name="facebook_app_secret_field"', 'value' => qa_html(qa_opt('facebook_app_id')),
'error' => $ready ? null : 'To use Facebook Login, please <a href="http://developers.facebook.com/setup/" target="_blank">set up a Facebook application</a>.', 'tags' => 'name="facebook_app_id_field"',
),
), ),
'buttons' => array( array(
array( 'label' => 'Facebook App Secret:',
'label' => 'Save Changes', 'value' => qa_html(qa_opt('facebook_app_secret')),
'tags' => 'name="facebook_save_button"', 'tags' => 'name="facebook_app_secret_field"',
), 'error' => $ready ? null : 'To use Facebook Login, please <a href="http://developers.facebook.com/setup/" target="_blank">set up a Facebook application</a>.',
), ),
); ),
}
'buttons' => array(
array(
'label' => 'Save Changes',
'tags' => 'name="facebook_save_button"',
),
),
);
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -35,19 +35,15 @@ ...@@ -35,19 +35,15 @@
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../'); header('Location: ../../');
exit; exit;
} }
if (!QA_FINAL_EXTERNAL_USERS) { // login modules don't work with external user integration // login modules don't work with external user integration
qa_register_plugin_module('login', 'qa-facebook-login.php', 'qa_facebook_login', 'Facebook Login'); if (!QA_FINAL_EXTERNAL_USERS) {
qa_register_plugin_module('page', 'qa-facebook-login-page.php', 'qa_facebook_login_page', 'Facebook Login Page'); qa_register_plugin_module('login', 'qa-facebook-login.php', 'qa_facebook_login', 'Facebook Login');
qa_register_plugin_layer('qa-facebook-layer.php', 'Facebook Login Layer'); qa_register_plugin_module('page', 'qa-facebook-login-page.php', 'qa_facebook_login_page', 'Facebook Login Page');
} qa_register_plugin_layer('qa-facebook-layer.php', 'Facebook Login Layer');
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,61 +20,55 @@ ...@@ -20,61 +20,55 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
class qa_mouseover_admin_form { class qa_mouseover_admin_form
{
public function option_default($option) public function option_default($option)
{ {
if ($option === 'mouseover_content_max_len') if ($option === 'mouseover_content_max_len')
return 480; return 480;
} }
public function admin_form(&$qa_content)
{
$saved = qa_clicked('mouseover_save_button');
if ($saved) { public function admin_form(&$qa_content)
qa_opt('mouseover_content_on', (int) qa_post_text('mouseover_content_on_field')); {
qa_opt('mouseover_content_max_len', (int) qa_post_text('mouseover_content_max_len_field')); $saved = qa_clicked('mouseover_save_button');
}
qa_set_display_rules($qa_content, array( if ($saved) {
'mouseover_content_max_len_display' => 'mouseover_content_on_field', qa_opt('mouseover_content_on', (int) qa_post_text('mouseover_content_on_field'));
)); qa_opt('mouseover_content_max_len', (int) qa_post_text('mouseover_content_max_len_field'));
}
return array( qa_set_display_rules($qa_content, array(
'ok' => $saved ? 'Mouseover settings saved' : null, 'mouseover_content_max_len_display' => 'mouseover_content_on_field',
));
'fields' => array( return array(
array( 'ok' => $saved ? 'Mouseover settings saved' : null,
'label' => 'Show content preview on mouseover in question lists',
'type' => 'checkbox',
'value' => qa_opt('mouseover_content_on'),
'tags' => 'name="mouseover_content_on_field" id="mouseover_content_on_field"',
),
array( 'fields' => array(
'id' => 'mouseover_content_max_len_display', array(
'label' => 'Maximum length of preview:', 'label' => 'Show content preview on mouseover in question lists',
'suffix' => 'characters', 'type' => 'checkbox',
'type' => 'number', 'value' => qa_opt('mouseover_content_on'),
'value' => (int) qa_opt('mouseover_content_max_len'), 'tags' => 'name="mouseover_content_on_field" id="mouseover_content_on_field"',
'tags' => 'name="mouseover_content_max_len_field"',
),
), ),
'buttons' => array( array(
array( 'id' => 'mouseover_content_max_len_display',
'label' => 'Save Changes', 'label' => 'Maximum length of preview:',
'tags' => 'name="mouseover_save_button"', 'suffix' => 'characters',
), 'type' => 'number',
'value' => (int) qa_opt('mouseover_content_max_len'),
'tags' => 'name="mouseover_content_max_len_field"',
), ),
); ),
}
'buttons' => array(
array(
'label' => 'Save Changes',
'tags' => 'name="mouseover_save_button"',
),
),
);
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,53 +20,47 @@ ...@@ -20,53 +20,47 @@
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
{
public function q_list($q_list) public function q_list($q_list)
{ {
if (!empty($q_list['qs']) && qa_opt('mouseover_content_on')) { // first check it is not an empty list and the feature is turned on if (!empty($q_list['qs']) && qa_opt('mouseover_content_on')) { // first check it is not an empty list and the feature is turned on
// Collect the question ids of all items in the question list (so we can do this in one DB query) // Collect the question ids of all items in the question list (so we can do this in one DB query)
$postids = array(); $postids = array();
foreach ($q_list['qs'] as $question) { foreach ($q_list['qs'] as $question) {
if (isset($question['raw']['postid'])) if (isset($question['raw']['postid']))
$postids[] = $question['raw']['postid']; $postids[] = $question['raw']['postid'];
} }
if (!empty($postids)) { if (!empty($postids)) {
// Retrieve the content for these questions from the database and put into an array fetching // Retrieve the content for these questions from the database and put into an array fetching
// the minimal amount of characters needed to determine the string should be shortened or not // the minimal amount of characters needed to determine the string should be shortened or not
$maxlength = qa_opt('mouseover_content_max_len'); $maxlength = qa_opt('mouseover_content_max_len');
$result = qa_db_query_sub('SELECT postid, LEFT(content, #) content, format FROM ^posts WHERE postid IN (#)', $maxlength + 1, $postids); $result = qa_db_query_sub('SELECT postid, LEFT(content, #) content, format FROM ^posts WHERE postid IN (#)', $maxlength + 1, $postids);
$postinfo = qa_db_read_all_assoc($result, 'postid'); $postinfo = qa_db_read_all_assoc($result, 'postid');
// Get the regular expression fragment to use for blocked words and the maximum length of content to show // Get the regular expression fragment to use for blocked words and the maximum length of content to show
$blockwordspreg = qa_get_block_words_preg(); $blockwordspreg = qa_get_block_words_preg();
// Now add the popup to the title for each question // Now add the popup to the title for each question
foreach ($q_list['qs'] as $index => $question) { foreach ($q_list['qs'] as $index => $question) {
if (isset($postinfo[$question['raw']['postid']])) { if (isset($postinfo[$question['raw']['postid']])) {
$thispost = $postinfo[$question['raw']['postid']]; $thispost = $postinfo[$question['raw']['postid']];
$text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg)); $text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));
$text = qa_shorten_string_line($text, $maxlength); $text = qa_shorten_string_line($text, $maxlength);
$title = isset($question['title']) ? $question['title'] : ''; $title = isset($question['title']) ? $question['title'] : '';
$q_list['qs'][$index]['title'] = sprintf('<span title="%s">%s</span>', qa_html($text), $title); $q_list['qs'][$index]['title'] = sprintf('<span title="%s">%s</span>', qa_html($text), $title);
}
} }
} }
} }
qa_html_theme_base::q_list($q_list); // call back through to the default function
} }
qa_html_theme_base::q_list($q_list); // call back through to the default function
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -34,16 +34,11 @@ ...@@ -34,16 +34,11 @@
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../'); header('Location: ../../');
exit; exit;
} }
qa_register_plugin_layer('qa-mouseover-layer.php', 'Mouseover Layer'); qa_register_plugin_layer('qa-mouseover-layer.php', 'Mouseover Layer');
qa_register_plugin_module('module', 'qa-mouseover-admin-form.php', 'qa_mouseover_admin_form', 'Mouseover Layer'); qa_register_plugin_module('module', 'qa-mouseover-admin-form.php', 'qa_mouseover_admin_form', 'Mouseover Layer');
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,18 +20,12 @@ ...@@ -20,18 +20,12 @@
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
{
public function head_links() public function head_links()
{ {
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').'"/>');
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,38 +20,32 @@ ...@@ -20,38 +20,32 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
class qa_opensearch_xml { 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)
{
@ini_set('display_errors', 0); // we don't want to show PHP errors inside XML
$titlexml=qa_xml(qa_opt('site_title')); public function process_request($request)
$template=str_replace('_searchTerms_placeholder_', '{searchTerms}', qa_path_absolute('search', array('q' => '_searchTerms_placeholder_'))); {
@ini_set('display_errors', 0); // we don't want to show PHP errors inside XML
header('Content-type: text/xml; charset=utf-8'); $titlexml=qa_xml(qa_opt('site_title'));
$template=str_replace('_searchTerms_placeholder_', '{searchTerms}', qa_path_absolute('search', array('q' => '_searchTerms_placeholder_')));
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n"; header('Content-type: text/xml; charset=utf-8');
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 '<?xml version="1.0" encoding="UTF-8"?>'."\n";
echo "\t<Description>".qa_xml(qa_lang('main/search_button')).' '.$titlexml."</Description>\n"; echo '<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">'."\n";
echo "\t".'<Url type="text/html" method="get" template="'.qa_xml($template).'"/>'."\n";
echo "\t<InputEncoding>UTF-8</InputEncoding>\n";
echo '</OpenSearchDescription>'."\n"; echo "\t<ShortName>".$titlexml."</ShortName>\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<InputEncoding>UTF-8</InputEncoding>\n";
return null; echo '</OpenSearchDescription>'."\n";
}
return null;
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -34,16 +34,11 @@ ...@@ -34,16 +34,11 @@
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../'); header('Location: ../../');
exit; exit;
} }
qa_register_plugin_layer('qa-opensearch-layer.php', 'OpenSearch Layer'); qa_register_plugin_layer('qa-opensearch-layer.php', 'OpenSearch Layer');
qa_register_plugin_module('page', 'qa-opensearch-page.php', 'qa_opensearch_xml', 'OpenSearch XML'); qa_register_plugin_module('page', 'qa-opensearch-page.php', 'qa_opensearch_xml', 'OpenSearch XML');
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -34,15 +34,10 @@ ...@@ -34,15 +34,10 @@
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../'); header('Location: ../../');
exit; exit;
} }
qa_register_plugin_module('captcha', 'qa-recaptcha-captcha.php', 'qa_recaptcha_captcha', 'reCAPTCHA'); qa_register_plugin_module('captcha', 'qa-recaptcha-captcha.php', 'qa_recaptcha_captcha', 'reCAPTCHA');
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,129 +20,117 @@ ...@@ -20,129 +20,117 @@
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_recaptcha_captcha
header('Location: ../'); {
exit; private $directory;
public function load_module($directory, $urltoroot)
{
$this->directory=$directory;
} }
class qa_recaptcha_captcha { public function admin_form()
{
$saved=false;
private $directory; if (qa_clicked('recaptcha_save_button')) {
qa_opt('recaptcha_public_key', qa_post_text('recaptcha_public_key_field'));
qa_opt('recaptcha_private_key', qa_post_text('recaptcha_private_key_field'));
public function load_module($directory, $urltoroot) $saved=true;
{
$this->directory=$directory;
} }
$form=array(
'ok' => $saved ? 'reCAPTCHA settings saved' : null,
public function admin_form() 'fields' => array(
{ 'public' => array(
$saved=false; 'label' => 'reCAPTCHA public key:',
'value' => qa_opt('recaptcha_public_key'),
if (qa_clicked('recaptcha_save_button')) { 'tags' => 'name="recaptcha_public_key_field"',
qa_opt('recaptcha_public_key', qa_post_text('recaptcha_public_key_field'));
qa_opt('recaptcha_private_key', qa_post_text('recaptcha_private_key_field'));
$saved=true;
}
$form=array(
'ok' => $saved ? 'reCAPTCHA settings saved' : null,
'fields' => array(
'public' => array(
'label' => 'reCAPTCHA public key:',
'value' => qa_opt('recaptcha_public_key'),
'tags' => 'name="recaptcha_public_key_field"',
),
'private' => array(
'label' => 'reCAPTCHA private key:',
'value' => qa_opt('recaptcha_private_key'),
'tags' => 'name="recaptcha_private_key_field"',
'error' => $this->recaptcha_error_html(),
),
), ),
'buttons' => array( 'private' => array(
array( 'label' => 'reCAPTCHA private key:',
'label' => 'Save Changes', 'value' => qa_opt('recaptcha_private_key'),
'tags' => 'name="recaptcha_save_button"', 'tags' => 'name="recaptcha_private_key_field"',
), 'error' => $this->recaptcha_error_html(),
), ),
); ),
return $form; 'buttons' => array(
} array(
'label' => 'Save Changes',
'tags' => 'name="recaptcha_save_button"',
),
),
);
return $form;
}
public function recaptcha_error_html()
{
if (!function_exists('fsockopen'))
return 'To use reCAPTCHA, the fsockopen() PHP function must be enabled on your server. Please check with your system administrator.';
elseif ( (!strlen(trim(qa_opt('recaptcha_public_key')))) || (!strlen(trim(qa_opt('recaptcha_private_key')))) ) { public function recaptcha_error_html()
require_once $this->directory.'recaptchalib.php'; {
if (!function_exists('fsockopen'))
return 'To use reCAPTCHA, the fsockopen() PHP function must be enabled on your server. Please check with your system administrator.';
$url=recaptcha_get_signup_url(@$_SERVER['HTTP_HOST'], qa_opt('site_title')); elseif ( (!strlen(trim(qa_opt('recaptcha_public_key')))) || (!strlen(trim(qa_opt('recaptcha_private_key')))) ) {
require_once $this->directory.'recaptchalib.php';
return 'To use reCAPTCHA, you must <a href="'.qa_html($url).'">sign up</a> to get these keys.'; $url=recaptcha_get_signup_url(@$_SERVER['HTTP_HOST'], qa_opt('site_title'));
}
return null; return 'To use reCAPTCHA, you must <a href="'.qa_html($url).'">sign up</a> to get these keys.';
} }
return null;
}
public function allow_captcha()
{
return function_exists('fsockopen') && strlen(trim(qa_opt('recaptcha_public_key'))) && strlen(trim(qa_opt('recaptcha_private_key')));
}
public function allow_captcha()
{
return function_exists('fsockopen') && strlen(trim(qa_opt('recaptcha_public_key'))) && strlen(trim(qa_opt('recaptcha_private_key')));
}
public function form_html(&$qa_content, $error)
{
require_once $this->directory.'recaptchalib.php';
$language=qa_opt('site_language'); public function form_html(&$qa_content, $error)
if (strpos('|en|nl|fr|de|pt|ru|es|tr|', '|'.$language.'|')===false) // supported as of 3/2010 {
$language='en'; require_once $this->directory.'recaptchalib.php';
$qa_content['script_lines'][]=array( $language=qa_opt('site_language');
"var RecaptchaOptions={", if (strpos('|en|nl|fr|de|pt|ru|es|tr|', '|'.$language.'|')===false) // supported as of 3/2010
"\ttheme:'white',", $language='en';
"\tlang:".qa_js($language),
"};",
);
return recaptcha_get_html(qa_opt('recaptcha_public_key'), $error, qa_is_https_probably()); $qa_content['script_lines'][]=array(
} "var RecaptchaOptions={",
"\ttheme:'white',",
"\tlang:".qa_js($language),
"};",
);
return recaptcha_get_html(qa_opt('recaptcha_public_key'), $error, qa_is_https_probably());
}
public function validate_post(&$error)
{
if ( (!empty($_POST['recaptcha_challenge_field'])) && (!empty($_POST['recaptcha_response_field'])) ) {
require_once $this->directory.'recaptchalib.php';
$answer=recaptcha_check_answer( public function validate_post(&$error)
qa_opt('recaptcha_private_key'), {
qa_remote_ip_address(), if ( (!empty($_POST['recaptcha_challenge_field'])) && (!empty($_POST['recaptcha_response_field'])) ) {
$_POST['recaptcha_challenge_field'], require_once $this->directory.'recaptchalib.php';
$_POST['recaptcha_response_field']
);
if ($answer->is_valid) $answer=recaptcha_check_answer(
return true; qa_opt('recaptcha_private_key'),
qa_remote_ip_address(),
$_POST['recaptcha_challenge_field'],
$_POST['recaptcha_response_field']
);
$error=@$answer->error; if ($answer->is_valid)
} return true;
return false; $error=@$answer->error;
} }
return false;
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -34,15 +34,10 @@ ...@@ -34,15 +34,10 @@
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../'); header('Location: ../../');
exit; exit;
} }
qa_register_plugin_module('widget', 'qa-tag-cloud.php', 'qa_tag_cloud', 'Tag Cloud'); qa_register_plugin_module('widget', 'qa-tag-cloud.php', 'qa_tag_cloud', 'Tag Cloud');
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,131 +20,125 @@ ...@@ -20,131 +20,125 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
class qa_tag_cloud { class qa_tag_cloud
{
public function option_default($option) public function option_default($option)
{ {
if ($option === 'tag_cloud_count_tags') if ($option === 'tag_cloud_count_tags')
return 100; return 100;
if ($option === 'tag_cloud_font_size') if ($option === 'tag_cloud_font_size')
return 24; return 24;
if ($option === 'tag_cloud_minimal_font_size') if ($option === 'tag_cloud_minimal_font_size')
return 8; return 8;
if ($option === 'tag_cloud_size_popular') if ($option === 'tag_cloud_size_popular')
return true; return true;
}
public function admin_form()
{
$saved = qa_clicked('tag_cloud_save_button');
if ($saved) {
qa_opt('tag_cloud_count_tags', (int) qa_post_text('tag_cloud_count_tags_field'));
qa_opt('tag_cloud_font_size', (int) qa_post_text('tag_cloud_font_size_field'));
qa_opt('tag_cloud_minimal_font_size', (int) qa_post_text('tag_cloud_minimal_font_size_field'));
qa_opt('tag_cloud_size_popular', (int) qa_post_text('tag_cloud_size_popular_field'));
} }
return array(
'ok' => $saved ? 'Tag cloud settings saved' : null,
public function admin_form() 'fields' => array(
{ array(
$saved = qa_clicked('tag_cloud_save_button'); 'label' => 'Maximum tags to show:',
'type' => 'number',
'value' => (int) qa_opt('tag_cloud_count_tags'),
'suffix' => 'tags',
'tags' => 'name="tag_cloud_count_tags_field"',
),
if ($saved) { array(
qa_opt('tag_cloud_count_tags', (int) qa_post_text('tag_cloud_count_tags_field')); 'label' => 'Biggest font size:',
qa_opt('tag_cloud_font_size', (int) qa_post_text('tag_cloud_font_size_field')); 'suffix' => 'pixels',
qa_opt('tag_cloud_minimal_font_size', (int) qa_post_text('tag_cloud_minimal_font_size_field')); 'type' => 'number',
qa_opt('tag_cloud_size_popular', (int) qa_post_text('tag_cloud_size_popular_field')); 'value' => (int) qa_opt('tag_cloud_font_size'),
} 'tags' => 'name="tag_cloud_font_size_field"',
),
return array( array(
'ok' => $saved ? 'Tag cloud settings saved' : null, 'label' => 'Smallest allowed font size:',
'suffix' => 'pixels',
'fields' => array( 'type' => 'number',
array( 'value' => (int) qa_opt('tag_cloud_minimal_font_size'),
'label' => 'Maximum tags to show:', 'tags' => 'name="tag_cloud_minimal_font_size_field"',
'type' => 'number',
'value' => (int) qa_opt('tag_cloud_count_tags'),
'suffix' => 'tags',
'tags' => 'name="tag_cloud_count_tags_field"',
),
array(
'label' => 'Biggest font size:',
'suffix' => 'pixels',
'type' => 'number',
'value' => (int) qa_opt('tag_cloud_font_size'),
'tags' => 'name="tag_cloud_font_size_field"',
),
array(
'label' => 'Smallest allowed font size:',
'suffix' => 'pixels',
'type' => 'number',
'value' => (int) qa_opt('tag_cloud_minimal_font_size'),
'tags' => 'name="tag_cloud_minimal_font_size_field"',
),
array(
'label' => 'Font size represents tag popularity',
'type' => 'checkbox',
'value' => qa_opt('tag_cloud_size_popular'),
'tags' => 'name="tag_cloud_size_popular_field"',
),
), ),
'buttons' => array( array(
array( 'label' => 'Font size represents tag popularity',
'label' => 'Save Changes', 'type' => 'checkbox',
'tags' => 'name="tag_cloud_save_button"', 'value' => qa_opt('tag_cloud_size_popular'),
), 'tags' => 'name="tag_cloud_size_popular_field"',
), ),
); ),
}
'buttons' => array(
array(
'label' => 'Save Changes',
'tags' => 'name="tag_cloud_save_button"',
),
),
);
}
public function allow_template($template)
{
$allowed = array(
'activity', 'qa', 'questions', 'hot', 'ask', 'categories', 'question',
'tag', 'tags', 'unanswered', 'user', 'users', 'search', 'admin', 'custom',
);
return in_array($template, $allowed);
}
public function allow_template($template)
{
$allowed = array(
'activity', 'qa', 'questions', 'hot', 'ask', 'categories', 'question',
'tag', 'tags', 'unanswered', 'user', 'users', 'search', 'admin', 'custom',
);
return in_array($template, $allowed);
}
public function allow_region($region)
{
return ($region === 'side');
}
public function allow_region($region)
{
return ($region === 'side');
}
public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
{
require_once QA_INCLUDE_DIR . 'db/selects.php';
$populartags = qa_db_single_select(qa_db_popular_tags_selectspec(0, (int) qa_opt('tag_cloud_count_tags'))); public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
{
require_once QA_INCLUDE_DIR . 'db/selects.php';
$maxcount = reset($populartags); $populartags = qa_db_single_select(qa_db_popular_tags_selectspec(0, (int) qa_opt('tag_cloud_count_tags')));
$themeobject->output(sprintf('<h2 style="margin-top: 0; padding-top: 0;">%s</h2>', qa_lang_html('main/popular_tags'))); $maxcount = reset($populartags);
$themeobject->output('<div style="font-size: 10px;">'); $themeobject->output(sprintf('<h2 style="margin-top: 0; padding-top: 0;">%s</h2>', qa_lang_html('main/popular_tags')));
$maxsize = qa_opt('tag_cloud_font_size'); $themeobject->output('<div style="font-size: 10px;">');
$minsize = qa_opt('tag_cloud_minimal_font_size');
$scale = qa_opt('tag_cloud_size_popular');
$blockwordspreg = qa_get_block_words_preg();
foreach ($populartags as $tag => $count) { $maxsize = qa_opt('tag_cloud_font_size');
$matches = qa_block_words_match_all($tag, $blockwordspreg); $minsize = qa_opt('tag_cloud_minimal_font_size');
if (empty($matches)) { $scale = qa_opt('tag_cloud_size_popular');
if ($scale) { $blockwordspreg = qa_get_block_words_preg();
$size = number_format($maxsize * $count / $maxcount, 1);
if ($size < $minsize)
$size = $minsize;
} else
$size = $maxsize;
$themeobject->output(sprintf('<a href="%s" style="font-size: %dpx; vertical-align: baseline;">%s</a>', qa_path_html('tag/' . $tag), $size, qa_html($tag))); foreach ($populartags as $tag => $count) {
} $matches = qa_block_words_match_all($tag, $blockwordspreg);
} if (empty($matches)) {
if ($scale) {
$size = number_format($maxsize * $count / $maxcount, 1);
if ($size < $minsize)
$size = $minsize;
} else
$size = $maxsize;
$themeobject->output('</div>'); $themeobject->output(sprintf('<a href="%s" style="font-size: %dpx; vertical-align: baseline;">%s</a>', qa_path_html('tag/' . $tag), $size, qa_html($tag)));
}
} }
$themeobject->output('</div>');
} }
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -34,16 +34,11 @@ ...@@ -34,16 +34,11 @@
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../'); header('Location: ../../');
exit; exit;
} }
qa_register_plugin_module('editor', 'qa-wysiwyg-editor.php', 'qa_wysiwyg_editor', 'WYSIWYG Editor'); qa_register_plugin_module('editor', 'qa-wysiwyg-editor.php', 'qa_wysiwyg_editor', 'WYSIWYG Editor');
qa_register_plugin_module('page', 'qa-wysiwyg-upload.php', 'qa_wysiwyg_upload', 'WYSIWYG Upload'); qa_register_plugin_module('page', 'qa-wysiwyg-upload.php', 'qa_wysiwyg_upload', 'WYSIWYG Upload');
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -245,8 +245,3 @@ class qa_wysiwyg_editor ...@@ -245,8 +245,3 @@ class qa_wysiwyg_editor
return qa_html(number_format($bytes/1048576, 1)); return qa_html(number_format($bytes/1048576, 1));
} }
} }
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -56,8 +56,3 @@ class qa_wysiwyg_upload ...@@ -56,8 +56,3 @@ class qa_wysiwyg_upload
return null; return null;
} }
} }
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -34,15 +34,10 @@ ...@@ -34,15 +34,10 @@
*/ */
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../'); header('Location: ../../');
exit; exit;
} }
qa_register_plugin_module('page', 'qa-xml-sitemap.php', 'qa_xml_sitemap', 'XML Sitemap'); qa_register_plugin_module('page', 'qa-xml-sitemap.php', 'qa_xml_sitemap', 'XML Sitemap');
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -20,278 +20,272 @@ ...@@ -20,278 +20,272 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
class qa_xml_sitemap { class qa_xml_sitemap
{
private $directory; private $directory;
private $urltoroot; private $urltoroot;
public function load_module($directory, $urltoroot) public function load_module($directory, $urltoroot)
{ {
$this->directory=$directory; $this->directory=$directory;
$this->urltoroot=$urltoroot; $this->urltoroot=$urltoroot;
} }
public function option_default($option) public function option_default($option)
{ {
switch ($option) { switch ($option) {
case 'xml_sitemap_show_questions': case 'xml_sitemap_show_questions':
case 'xml_sitemap_show_users': case 'xml_sitemap_show_users':
case 'xml_sitemap_show_tag_qs': case 'xml_sitemap_show_tag_qs':
case 'xml_sitemap_show_category_qs': case 'xml_sitemap_show_category_qs':
case 'xml_sitemap_show_categories': case 'xml_sitemap_show_categories':
return true; return true;
break; break;
}
} }
}
public function admin_form() public function admin_form()
{ {
require_once QA_INCLUDE_DIR.'qa-util-sort.php'; require_once QA_INCLUDE_DIR.'qa-util-sort.php';
$saved=false;
if (qa_clicked('xml_sitemap_save_button')) { $saved=false;
qa_opt('xml_sitemap_show_questions', (int)qa_post_text('xml_sitemap_show_questions_field'));
if (!QA_FINAL_EXTERNAL_USERS) if (qa_clicked('xml_sitemap_save_button')) {
qa_opt('xml_sitemap_show_users', (int)qa_post_text('xml_sitemap_show_users_field')); qa_opt('xml_sitemap_show_questions', (int)qa_post_text('xml_sitemap_show_questions_field'));
if (qa_using_tags()) if (!QA_FINAL_EXTERNAL_USERS)
qa_opt('xml_sitemap_show_tag_qs', (int)qa_post_text('xml_sitemap_show_tag_qs_field')); qa_opt('xml_sitemap_show_users', (int)qa_post_text('xml_sitemap_show_users_field'));
if (qa_using_categories()) { if (qa_using_tags())
qa_opt('xml_sitemap_show_category_qs', (int)qa_post_text('xml_sitemap_show_category_qs_field')); qa_opt('xml_sitemap_show_tag_qs', (int)qa_post_text('xml_sitemap_show_tag_qs_field'));
qa_opt('xml_sitemap_show_categories', (int)qa_post_text('xml_sitemap_show_categories_field'));
}
$saved=true; if (qa_using_categories()) {
qa_opt('xml_sitemap_show_category_qs', (int)qa_post_text('xml_sitemap_show_category_qs_field'));
qa_opt('xml_sitemap_show_categories', (int)qa_post_text('xml_sitemap_show_categories_field'));
} }
$form=array( $saved=true;
'ok' => $saved ? 'XML sitemap settings saved' : null, }
$form=array(
'ok' => $saved ? 'XML sitemap settings saved' : null,
'fields' => array( 'fields' => array(
'questions' => array( 'questions' => array(
'label' => 'Include question pages', 'label' => 'Include question pages',
'type' => 'checkbox', 'type' => 'checkbox',
'value' => (int)qa_opt('xml_sitemap_show_questions'), 'value' => (int)qa_opt('xml_sitemap_show_questions'),
'tags' => 'name="xml_sitemap_show_questions_field"', 'tags' => 'name="xml_sitemap_show_questions_field"',
),
), ),
),
'buttons' => array( 'buttons' => array(
array( array(
'label' => 'Save Changes', 'label' => 'Save Changes',
'tags' => 'name="xml_sitemap_save_button"', 'tags' => 'name="xml_sitemap_save_button"',
),
), ),
),
);
if (!QA_FINAL_EXTERNAL_USERS)
$form['fields']['users']=array(
'label' => 'Include user pages',
'type' => 'checkbox',
'value' => (int)qa_opt('xml_sitemap_show_users'),
'tags' => 'name="xml_sitemap_show_users_field"',
); );
if (!QA_FINAL_EXTERNAL_USERS) if (qa_using_tags())
$form['fields']['users']=array( $form['fields']['tagqs']=array(
'label' => 'Include user pages', 'label' => 'Include question list for each tag',
'type' => 'checkbox', 'type' => 'checkbox',
'value' => (int)qa_opt('xml_sitemap_show_users'), 'value' => (int)qa_opt('xml_sitemap_show_tag_qs'),
'tags' => 'name="xml_sitemap_show_users_field"', 'tags' => 'name="xml_sitemap_show_tag_qs_field"',
); );
if (qa_using_tags())
$form['fields']['tagqs']=array(
'label' => 'Include question list for each tag',
'type' => 'checkbox',
'value' => (int)qa_opt('xml_sitemap_show_tag_qs'),
'tags' => 'name="xml_sitemap_show_tag_qs_field"',
);
if (qa_using_categories()) {
$form['fields']['categoryqs']=array(
'label' => 'Include question list for each category',
'type' => 'checkbox',
'value' => (int)qa_opt('xml_sitemap_show_category_qs'),
'tags' => 'name="xml_sitemap_show_category_qs_field"',
);
$form['fields']['categories']=array( if (qa_using_categories()) {
'label' => 'Include category browser', $form['fields']['categoryqs']=array(
'type' => 'checkbox', 'label' => 'Include question list for each category',
'value' => (int)qa_opt('xml_sitemap_show_categories'), 'type' => 'checkbox',
'tags' => 'name="xml_sitemap_show_categories_field"', 'value' => (int)qa_opt('xml_sitemap_show_category_qs'),
); 'tags' => 'name="xml_sitemap_show_category_qs_field"',
} );
return $form; $form['fields']['categories']=array(
'label' => 'Include category browser',
'type' => 'checkbox',
'value' => (int)qa_opt('xml_sitemap_show_categories'),
'tags' => 'name="xml_sitemap_show_categories_field"',
);
} }
return $form;
}
public function suggest_requests()
{
return array(
array(
'title' => 'XML Sitemap',
'request' => 'sitemap.xml',
'nav' => null, // 'M'=main, 'F'=footer, 'B'=before main, 'O'=opposite main, null=none
),
);
}
public function suggest_requests()
{
return array(
array(
'title' => 'XML Sitemap',
'request' => 'sitemap.xml',
'nav' => null, // 'M'=main, 'F'=footer, 'B'=before main, 'O'=opposite main, null=none
),
);
}
public function match_request($request)
{
return ($request=='sitemap.xml');
}
public function match_request($request)
{
return ($request=='sitemap.xml');
}
public function process_request($request)
{
@ini_set('display_errors', 0); // we don't want to show PHP errors inside XML
$siteurl=qa_opt('site_url'); public function process_request($request)
{
@ini_set('display_errors', 0); // we don't want to show PHP errors inside XML
header('Content-type: text/xml; charset=utf-8'); $siteurl=qa_opt('site_url');
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n"; header('Content-type: text/xml; charset=utf-8');
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n";
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n";
// Question pages
if (qa_opt('xml_sitemap_show_questions')) { // Question pages
$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'"
));
$nextpostid=0; if (qa_opt('xml_sitemap_show_questions')) {
$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'"
));
while (1) { $nextpostid=0;
$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",
$nextpostid
));
if (!count($questions)) while (1) {
break; $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",
$nextpostid
));
foreach ($questions as $question) { if (!count($questions))
$this->sitemap_output(qa_q_request($question['postid'], $question['title']), break;
0.1+0.9*($question['hotness']-$hotstats['base'])/(1+$hotstats['spread']));
$nextpostid=max($nextpostid, $question['postid']+1); foreach ($questions as $question) {
} $this->sitemap_output(qa_q_request($question['postid'], $question['title']),
0.1+0.9*($question['hotness']-$hotstats['base'])/(1+$hotstats['spread']));
$nextpostid=max($nextpostid, $question['postid']+1);
} }
} }
}
// 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
)); ));
if (!count($users)) if (!count($users))
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);
}
} }
} }
}
// 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
)); ));
if (!count($tagwords)) if (!count($tagwords))
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);
}
} }
} }
}
// 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
)); ));
if (!count($categories)) if (!count($categories))
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);
}
} }
} }
}
// Pages in category browser // Pages in category browser
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
)); ));
if (!count($categories)) if (!count($categories))
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);
}
} }
} }
// Finish up...
echo "</urlset>\n";
return null;
} }
private function sitemap_output($request, $priority) // Finish up...
{
echo "\t<url>\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</url>\n";
}
echo "</urlset>\n";
return null;
} }
/* private function sitemap_output($request, $priority)
Omit PHP closing tag to help avoid accidental output {
*/ echo "\t<url>\n".
\ No newline at end of file "\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</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