Commit 59ad6e0a by Scott

Coding style (default plugins)

parent 9b5766d2
......@@ -20,93 +20,85 @@
More about this license: http://www.question2answer.org/license.php
*/
class qa_basic_adsense {
public function allow_template($template)
{
return ($template!='admin');
}
class qa_basic_adsense
{
public function allow_template($template)
{
return ($template!='admin');
}
public function allow_region($region)
{
return in_array($region, array('main', 'side', 'full'));
}
public function allow_region($region)
{
return in_array($region, array('main', 'side', 'full'));
}
public function admin_form(&$qa_content)
{
$saved=false;
public function admin_form(&$qa_content)
{
$saved=false;
if (qa_clicked('adsense_save_button')) {
$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));
$saved=true;
}
if (qa_clicked('adsense_save_button')) {
$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));
$saved=true;
}
return array(
'ok' => $saved ? 'AdSense settings saved' : null,
return array(
'ok' => $saved ? 'AdSense settings saved' : null,
'fields' => array(
array(
'label' => 'AdSense Publisher ID:',
'value' => qa_html(qa_opt('adsense_publisher_id')),
'tags' => 'name="adsense_publisher_id_field"',
'note' => 'Example: <i>pub-1234567890123456</i>',
),
'fields' => array(
array(
'label' => 'AdSense Publisher ID:',
'value' => qa_html(qa_opt('adsense_publisher_id')),
'tags' => 'name="adsense_publisher_id_field"',
'note' => 'Example: <i>pub-1234567890123456</i>',
),
),
'buttons' => array(
array(
'label' => 'Save Changes',
'tags' => 'name="adsense_save_button"',
),
'buttons' => array(
array(
'label' => 'Save Changes',
'tags' => 'name="adsense_save_button"',
),
);
}
),
);
}
public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
{
$divstyle='';
public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
{
$divstyle='';
switch ($region) {
case 'full': // Leaderboard
$divstyle='width:728px; margin:0 auto;';
switch ($region) {
case 'full': // Leaderboard
$divstyle='width:728px; margin:0 auto;';
case 'main': // Leaderboard
$width=728;
$height=90;
$format='728x90_as';
break;
case 'main': // Leaderboard
$width=728;
$height=90;
$format='728x90_as';
break;
case 'side': // Wide skyscraper
$width=160;
$height=600;
$format='160x600_as';
break;
}
case 'side': // Wide skyscraper
$width=160;
$height=600;
$format='160x600_as';
break;
}
?>
<div style="<?php echo $divstyle?>">
<script type="text/javascript">
google_ad_client = <?php echo qa_js(qa_opt('adsense_publisher_id'))?>;
google_ad_width = <?php echo qa_js($width)?>;
google_ad_height = <?php echo qa_js($height)?>;
google_ad_format = <?php echo qa_js($format)?>;
google_ad_type = "text_image";
google_ad_channel = "";
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<script type="text/javascript">
google_ad_client = <?php echo qa_js(qa_opt('adsense_publisher_id'))?>;
google_ad_width = <?php echo qa_js($width)?>;
google_ad_height = <?php echo qa_js($height)?>;
google_ad_format = <?php echo qa_js($format)?>;
google_ad_type = "text_image";
google_ad_channel = "";
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</div>
<?php
}
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
}
......@@ -34,15 +34,10 @@
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
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
qa_register_plugin_module('widget', 'qa-basic-adsense.php', 'qa_basic_adsense', 'Basic AdSense');
......@@ -34,15 +34,10 @@
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
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
qa_register_plugin_module('event', 'qa-event-logger.php', 'qa_event_logger', 'Event Logger');
......@@ -20,11 +20,6 @@
More about this license: http://www.question2answer.org/license.php
*/
return array(
'page_title' => 'Example plugin page (US English)',
);
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
return array(
'page_title' => 'Example plugin page (US English)',
);
......@@ -20,11 +20,6 @@
More about this license: http://www.question2answer.org/license.php
*/
return array(
'page_title' => 'Example plugin page (UK English)',
);
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
return array(
'page_title' => 'Example plugin page (UK English)',
);
......@@ -20,85 +20,79 @@
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)
{
$this->directory=$directory;
$this->urltoroot=$urltoroot;
}
public function load_module($directory, $urltoroot)
{
$this->directory=$directory;
$this->urltoroot=$urltoroot;
}
public function suggest_requests() // for display in admin interface
{
return array(
array(
'title' => 'Example',
'request' => 'example-plugin-page',
'nav' => 'M', // 'M'=main, 'F'=footer, 'B'=before main, 'O'=opposite main, null=none
),
);
}
public function suggest_requests() // for display in admin interface
{
return array(
array(
'title' => 'Example',
'request' => 'example-plugin-page',
'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');
$qa_content['error']='An example error';
$qa_content['custom']='Some <b>custom html</b>';
public function process_request($request)
{
$qa_content=qa_content_prepare();
$qa_content['form']=array(
'tags' => 'method="post" action="'.qa_self_html().'"',
$qa_content['title']=qa_lang_html('example_page/page_title');
$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(
'request' => array(
'label' => 'The request',
'tags' => 'name="request"',
'value' => qa_html($request),
'error' => qa_html('Another error'),
),
'title' => 'Form title',
'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(
'hiddenfield' => '1',
'buttons' => array(
'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 @@
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
qa_register_plugin_module('page', 'qa-example-page.php', 'qa_example_page', '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
qa_register_plugin_module('page', 'qa-example-page.php', 'qa_example_page', 'Example Page');
qa_register_plugin_phrases('qa-example-lang-*.php', 'example_page');
......@@ -20,23 +20,18 @@
More about this license: http://www.question2answer.org/license.php
*/
class qa_html_theme_layer extends qa_html_theme_base {
public function head_css()
{
qa_html_theme_base::head_css();
if (strlen(qa_opt('facebook_app_id')) && strlen(qa_opt('facebook_app_secret')))
$this->output(
'<style>',
'.fb-login-button.fb_iframe_widget.fb_hide_iframes span {display:none;}',
'</style>'
);
class qa_html_theme_layer extends qa_html_theme_base
{
public function head_css()
{
qa_html_theme_base::head_css();
if (strlen(qa_opt('facebook_app_id')) && strlen(qa_opt('facebook_app_secret'))) {
$this->output(
'<style>',
'.fb-login-button.fb_iframe_widget.fb_hide_iframes span {display:none;}',
'</style>'
);
}
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
}
......@@ -20,73 +20,68 @@
More about this license: http://www.question2answer.org/license.php
*/
class qa_facebook_login_page {
class qa_facebook_login_page
{
private $directory;
private $urltoroot;
private $directory;
private $urltoroot;
public function load_module($directory, $urltoroot)
{
$this->directory=$directory;
$this->urltoroot=$urltoroot;
}
public function load_module($directory, $urltoroot)
{
$this->directory=$directory;
$this->urltoroot=$urltoroot;
}
public function match_request($request)
{
return ($request=='facebook-login');
}
public function match_request($request)
{
return ($request=='facebook-login');
}
public function process_request($request)
{
if ($request=='facebook-login') {
$app_id=qa_opt('facebook_app_id');
$app_secret=qa_opt('facebook_app_secret');
$tourl=qa_get('to');
if (!strlen($tourl))
$tourl=qa_path_absolute('');
if (strlen($app_id) && strlen($app_secret)) {
require_once $this->directory.'facebook.php';
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true,
));
$fb_userid=$facebook->getUser();
if ($fb_userid) {
try {
$user=$facebook->api('/me?fields=email,name,verified,location,website,about,picture');
if (is_array($user))
qa_log_in_external_user('facebook', $fb_userid, array(
'email' => @$user['email'],
'handle' => @$user['name'],
'confirmed' => @$user['verified'],
'name' => @$user['name'],
'location' => @$user['location']['name'],
'website' => @$user['website'],
'about' => @$user['bio'],
'avatar' => strlen(@$user['picture']['data']['url']) ? qa_retrieve_url($user['picture']['data']['url']) : null,
));
} catch (FacebookApiException $e) {
}
} else {
qa_redirect_raw($facebook->getLoginUrl(array('redirect_uri' => $tourl)));
public function process_request($request)
{
if ($request=='facebook-login') {
$app_id=qa_opt('facebook_app_id');
$app_secret=qa_opt('facebook_app_secret');
$tourl=qa_get('to');
if (!strlen($tourl))
$tourl=qa_path_absolute('');
if (strlen($app_id) && strlen($app_secret)) {
require_once $this->directory.'facebook.php';
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true,
));
$fb_userid=$facebook->getUser();
if ($fb_userid) {
try {
$user=$facebook->api('/me?fields=email,name,verified,location,website,about,picture');
if (is_array($user))
qa_log_in_external_user('facebook', $fb_userid, array(
'email' => @$user['email'],
'handle' => @$user['name'],
'confirmed' => @$user['verified'],
'name' => @$user['name'],
'location' => @$user['location']['name'],
'website' => @$user['website'],
'about' => @$user['bio'],
'avatar' => strlen(@$user['picture']['data']['url']) ? qa_retrieve_url($user['picture']['data']['url']) : null,
));
} catch (FacebookApiException $e) {
}
}
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 @@
More about this license: http://www.question2answer.org/license.php
*/
class qa_facebook_login {
public function match_source($source)
{
return $source=='facebook';
}
class qa_facebook_login
{
public function match_source($source)
{
return $source=='facebook';
}
public function login_html($tourl, $context)
{
$app_id=qa_opt('facebook_app_id');
public function login_html($tourl, $context)
{
$app_id=qa_opt('facebook_app_id');
if (!strlen($app_id))
return;
if (!strlen($app_id))
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)
{
$app_id=qa_opt('facebook_app_id');
public function logout_html($tourl)
{
$app_id=qa_opt('facebook_app_id');
if (!strlen($app_id))
return;
if (!strlen($app_id))
return;
$this->facebook_html($tourl, true, 'menu');
}
$this->facebook_html($tourl, true, 'menu');
}
public function facebook_html($tourl, $logout, $context)
{
if (($context=='login') || ($context=='register'))
$size='large';
else
$size='medium';
public function facebook_html($tourl, $logout, $context)
{
if (($context=='login') || ($context=='register'))
$size='large';
else
$size='medium';
?>
<div id="fb-root" style="display:inline;"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : <?php echo qa_js(qa_opt('facebook_app_id'), true)?>,
status : true,
cookie : true,
xfbml : true,
oauth : true
});
FB.Event.subscribe('<?php echo $logout ? 'auth.logout' : 'auth.login'?>', function(response) {
setTimeout("window.location=<?php echo qa_js($tourl)?>", 100);
});
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</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>
<div id="fb-root" style="display:inline;"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : <?php echo qa_js(qa_opt('facebook_app_id'), true)?>,
status : true,
cookie : true,
xfbml : true,
oauth : true
});
FB.Event.subscribe('<?php echo $logout ? 'auth.logout' : 'auth.login'?>', function(response) {
setTimeout("window.location=<?php echo qa_js($tourl)?>", 100);
});
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</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>
<?php
}
}
public function admin_form()
{
$saved=false;
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;
}
public function admin_form()
{
$saved=false;
$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(
'ok' => $saved ? 'Facebook application details saved' : null,
$ready=strlen(qa_opt('facebook_app_id')) && strlen(qa_opt('facebook_app_secret'));
'fields' => array(
array(
'label' => 'Facebook App ID:',
'value' => qa_html(qa_opt('facebook_app_id')),
'tags' => 'name="facebook_app_id_field"',
),
return array(
'ok' => $saved ? 'Facebook application details saved' : null,
array(
'label' => 'Facebook App Secret:',
'value' => qa_html(qa_opt('facebook_app_secret')),
'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>.',
),
'fields' => array(
array(
'label' => 'Facebook App ID:',
'value' => qa_html(qa_opt('facebook_app_id')),
'tags' => 'name="facebook_app_id_field"',
),
'buttons' => array(
array(
'label' => 'Save Changes',
'tags' => 'name="facebook_save_button"',
),
array(
'label' => 'Facebook App Secret:',
'value' => qa_html(qa_opt('facebook_app_secret')),
'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 @@
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
if (!QA_FINAL_EXTERNAL_USERS) { // login modules don't work with external user integration
qa_register_plugin_module('login', 'qa-facebook-login.php', 'qa_facebook_login', 'Facebook Login');
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
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
// login modules don't work with external user integration
if (!QA_FINAL_EXTERNAL_USERS) {
qa_register_plugin_module('login', 'qa-facebook-login.php', 'qa_facebook_login', 'Facebook Login');
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');
}
......@@ -20,61 +20,55 @@
More about this license: http://www.question2answer.org/license.php
*/
class qa_mouseover_admin_form {
public function option_default($option)
{
if ($option === 'mouseover_content_max_len')
return 480;
}
class qa_mouseover_admin_form
{
public function option_default($option)
{
if ($option === 'mouseover_content_max_len')
return 480;
}
public function admin_form(&$qa_content)
{
$saved = qa_clicked('mouseover_save_button');
if ($saved) {
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'));
}
public function admin_form(&$qa_content)
{
$saved = qa_clicked('mouseover_save_button');
qa_set_display_rules($qa_content, array(
'mouseover_content_max_len_display' => 'mouseover_content_on_field',
));
if ($saved) {
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(
'ok' => $saved ? 'Mouseover settings saved' : null,
qa_set_display_rules($qa_content, array(
'mouseover_content_max_len_display' => 'mouseover_content_on_field',
));
'fields' => array(
array(
'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"',
),
return array(
'ok' => $saved ? 'Mouseover settings saved' : null,
array(
'id' => 'mouseover_content_max_len_display',
'label' => 'Maximum length of preview:',
'suffix' => 'characters',
'type' => 'number',
'value' => (int) qa_opt('mouseover_content_max_len'),
'tags' => 'name="mouseover_content_max_len_field"',
),
'fields' => array(
array(
'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"',
),
'buttons' => array(
array(
'label' => 'Save Changes',
'tags' => 'name="mouseover_save_button"',
),
array(
'id' => 'mouseover_content_max_len_display',
'label' => 'Maximum length of preview:',
'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 @@
More about this license: http://www.question2answer.org/license.php
*/
class qa_html_theme_layer extends qa_html_theme_base {
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
// Collect the question ids of all items in the question list (so we can do this in one DB query)
$postids = array();
foreach ($q_list['qs'] as $question) {
if (isset($question['raw']['postid']))
$postids[] = $question['raw']['postid'];
}
class qa_html_theme_layer extends qa_html_theme_base
{
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
// Collect the question ids of all items in the question list (so we can do this in one DB query)
$postids = array();
foreach ($q_list['qs'] as $question) {
if (isset($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
// the minimal amount of characters needed to determine the string should be shortened or not
// 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
$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);
$postinfo = qa_db_read_all_assoc($result, 'postid');
$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);
$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) {
if (isset($postinfo[$question['raw']['postid']])) {
$thispost = $postinfo[$question['raw']['postid']];
$text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));
$text = qa_shorten_string_line($text, $maxlength);
$title = isset($question['title']) ? $question['title'] : '';
$q_list['qs'][$index]['title'] = sprintf('<span title="%s">%s</span>', qa_html($text), $title);
}
foreach ($q_list['qs'] as $index => $question) {
if (isset($postinfo[$question['raw']['postid']])) {
$thispost = $postinfo[$question['raw']['postid']];
$text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));
$text = qa_shorten_string_line($text, $maxlength);
$title = isset($question['title']) ? $question['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 @@
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
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');
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
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');
......@@ -20,18 +20,12 @@
More about this license: http://www.question2answer.org/license.php
*/
class qa_html_theme_layer extends qa_html_theme_base {
public function 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').'"/>');
}
class qa_html_theme_layer extends qa_html_theme_base
{
public function 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').'"/>');
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
}
......@@ -20,38 +20,32 @@
More about this license: http://www.question2answer.org/license.php
*/
class qa_opensearch_xml {
public function match_request($request)
{
return ($request=='opensearch.xml');
}
public function process_request($request)
{
@ini_set('display_errors', 0); // we don't want to show PHP errors inside XML
class qa_opensearch_xml
{
public function match_request($request)
{
return ($request=='opensearch.xml');
}
$titlexml=qa_xml(qa_opt('site_title'));
$template=str_replace('_searchTerms_placeholder_', '{searchTerms}', qa_path_absolute('search', array('q' => '_searchTerms_placeholder_')));
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');
$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";
echo '<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">'."\n";
header('Content-type: text/xml; charset=utf-8');
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";
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>'."\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 @@
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
qa_register_plugin_layer('qa-opensearch-layer.php', 'OpenSearch Layer');
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
qa_register_plugin_layer('qa-opensearch-layer.php', 'OpenSearch Layer');
qa_register_plugin_module('page', 'qa-opensearch-page.php', 'qa_opensearch_xml', 'OpenSearch XML');
......@@ -34,15 +34,10 @@
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
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
qa_register_plugin_module('captcha', 'qa-recaptcha-captcha.php', 'qa_recaptcha_captcha', 'reCAPTCHA');
......@@ -20,129 +20,117 @@
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../');
exit;
class qa_recaptcha_captcha
{
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)
{
$this->directory=$directory;
$saved=true;
}
$form=array(
'ok' => $saved ? 'reCAPTCHA settings saved' : null,
public function admin_form()
{
$saved=false;
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'));
$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(),
),
'fields' => array(
'public' => array(
'label' => 'reCAPTCHA public key:',
'value' => qa_opt('recaptcha_public_key'),
'tags' => 'name="recaptcha_public_key_field"',
),
'buttons' => array(
array(
'label' => 'Save Changes',
'tags' => 'name="recaptcha_save_button"',
),
'private' => array(
'label' => 'reCAPTCHA private key:',
'value' => qa_opt('recaptcha_private_key'),
'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')))) ) {
require_once $this->directory.'recaptchalib.php';
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.';
$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');
if (strpos('|en|nl|fr|de|pt|ru|es|tr|', '|'.$language.'|')===false) // supported as of 3/2010
$language='en';
public function form_html(&$qa_content, $error)
{
require_once $this->directory.'recaptchalib.php';
$qa_content['script_lines'][]=array(
"var RecaptchaOptions={",
"\ttheme:'white',",
"\tlang:".qa_js($language),
"};",
);
$language=qa_opt('site_language');
if (strpos('|en|nl|fr|de|pt|ru|es|tr|', '|'.$language.'|')===false) // supported as of 3/2010
$language='en';
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(
qa_opt('recaptcha_private_key'),
qa_remote_ip_address(),
$_POST['recaptcha_challenge_field'],
$_POST['recaptcha_response_field']
);
public function validate_post(&$error)
{
if ( (!empty($_POST['recaptcha_challenge_field'])) && (!empty($_POST['recaptcha_response_field'])) ) {
require_once $this->directory.'recaptchalib.php';
if ($answer->is_valid)
return true;
$answer=recaptcha_check_answer(
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 @@
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
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
qa_register_plugin_module('widget', 'qa-tag-cloud.php', 'qa_tag_cloud', 'Tag Cloud');
......@@ -20,131 +20,125 @@
More about this license: http://www.question2answer.org/license.php
*/
class qa_tag_cloud {
public function option_default($option)
{
if ($option === 'tag_cloud_count_tags')
return 100;
if ($option === 'tag_cloud_font_size')
return 24;
if ($option === 'tag_cloud_minimal_font_size')
return 8;
if ($option === 'tag_cloud_size_popular')
return true;
class qa_tag_cloud
{
public function option_default($option)
{
if ($option === 'tag_cloud_count_tags')
return 100;
if ($option === 'tag_cloud_font_size')
return 24;
if ($option === 'tag_cloud_minimal_font_size')
return 8;
if ($option === 'tag_cloud_size_popular')
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()
{
$saved = qa_clicked('tag_cloud_save_button');
'fields' => array(
array(
'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) {
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'));
}
array(
'label' => 'Biggest font size:',
'suffix' => 'pixels',
'type' => 'number',
'value' => (int) qa_opt('tag_cloud_font_size'),
'tags' => 'name="tag_cloud_font_size_field"',
),
return array(
'ok' => $saved ? 'Tag cloud settings saved' : null,
'fields' => array(
array(
'label' => 'Maximum tags to show:',
'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"',
),
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"',
),
'buttons' => array(
array(
'label' => 'Save Changes',
'tags' => 'name="tag_cloud_save_button"',
),
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(
'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');
$minsize = qa_opt('tag_cloud_minimal_font_size');
$scale = qa_opt('tag_cloud_size_popular');
$blockwordspreg = qa_get_block_words_preg();
$themeobject->output('<div style="font-size: 10px;">');
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;
$maxsize = qa_opt('tag_cloud_font_size');
$minsize = qa_opt('tag_cloud_minimal_font_size');
$scale = qa_opt('tag_cloud_size_popular');
$blockwordspreg = qa_get_block_words_preg();
$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 @@
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
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');
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
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');
......@@ -245,8 +245,3 @@ class qa_wysiwyg_editor
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
return null;
}
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
......@@ -34,15 +34,10 @@
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
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
qa_register_plugin_module('page', 'qa-xml-sitemap.php', 'qa_xml_sitemap', 'XML Sitemap');
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