Commit 2a744533 by Gideon Greenspan

1.5.1

parent b12de3f3
1.5.1
\ No newline at end of file
......@@ -180,6 +180,9 @@
QA_USER_LEVEL_BASIC, QA_USER_LEVEL_EDITOR, QA_USER_LEVEL_ADMIN, QA_USER_LEVEL_SUPER
To indicate that the user is blocked you can also add an element 'blocked' with the value true.
Blocked users are not allowed to perform any write actions such as voting or posting.
The result of this function will be passed to your other function qa_get_logged_in_user_html()
so you may add any other elements to the returned array if they will be useful to you.
......
......@@ -35,14 +35,32 @@
$metadata=qa_admin_addon_metadata(qa_retrieve_url($uri), array(
'version' => $versionkey,
'uri' => $urikey,
// these two elements are only present for plugins, not themes, so we can hard code them here
'min_q2a' => 'Plugin Minimum Question2Answer Version',
'min_php' => 'Plugin Minimum PHP Version',
));
if (strlen(@$metadata['version'])) {
if (strcmp($metadata['version'], $version)) {
$response=qa_lang_html_sub('admin/version_get_x', qa_html('v'.$metadata['version']));
if (strlen(@$metadata['uri']))
$response='<A HREF="'.qa_html($metadata['uri']).'" STYLE="color:#d00;">'.$response.'</A>';
if (qa_qa_version_below(@$metadata['min_q2a']))
$response=strtr(qa_lang_html('admin/version_requires_q2a'), array(
'^1' => qa_html('v'.$metadata['version']),
'^2' => qa_html($metadata['min_q2a']),
));
elseif (qa_php_version_below(@$metadata['min_php']))
$response=strtr(qa_lang_html('admin/version_requires_php'), array(
'^1' => qa_html('v'.$metadata['version']),
'^2' => qa_html($metadata['min_php']),
));
else {
$response=qa_lang_html_sub('admin/version_get_x', qa_html('v'.$metadata['version']));
if (strlen(@$metadata['uri']))
$response='<A HREF="'.qa_html($metadata['uri']).'" STYLE="color:#d00;">'.$response.'</A>';
}
} else
$response=qa_lang_html('admin/version_latest');
......
......@@ -434,7 +434,7 @@
$fields['what']=qa_lang_html($isquestion ? 'main/asked' : ($isanswer ? 'main/answered' : 'main/commented'));
if (@$options['whatlink'] && !$isquestion)
$fields['what_url']='?show='.qa_html($postid).'#'.qa_html($anchor);
$fields['what_url']=qa_path_html(qa_request(), array('show' => $postid), null, null, qa_anchor($post['basetype'], $postid));
}
if (isset($post['created']) && @$options['whenview']) {
......@@ -1091,13 +1091,17 @@
{
if (
(!qa_permit_value_error($page['permit'], qa_get_logged_in_userid(), qa_get_logged_in_level(), qa_get_logged_in_flags())) || !isset($page['permit'])
)
) {
$url=qa_custom_page_url($page);
$navigation[($page['flags'] & QA_PAGE_FLAGS_EXTERNAL) ? ('custom-'.$page['pageid']) : $page['tags']]=array(
'url' => qa_html(qa_custom_page_url($page)),
'url' => qa_html($url),
'label' => qa_html($page['title']),
'opposite' => ($page['nav']=='O'),
'target' => ($page['flags'] & QA_PAGE_FLAGS_NEW_WINDOW) ? '_blank' : null,
'selected' => ($page['flags'] & QA_PAGE_FLAGS_EXTERNAL) && ( ($url==qa_path(qa_request())) || ($url==qa_self_html()) ),
);
}
}
......@@ -1635,7 +1639,8 @@
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
if ($size>0)
return '<IMG SRC="http://www.gravatar.com/avatar/'.md5(strtolower(trim($email))).'?s='.(int)$size.
return '<IMG SRC="'.(qa_is_https_probably() ? 'https' : 'http').
'://www.gravatar.com/avatar/'.md5(strtolower(trim($email))).'?s='.(int)$size.
'" WIDTH="'.(int)$size.'" HEIGHT="'.(int)$size.'" CLASS="qa-avatar-image"/>';
else
return null;
......
......@@ -234,6 +234,27 @@
}
function qa_post_set_created($postid, $created)
/*
Set the created date of $postid to $created, which is a unix timestamp.
*/
{
$oldpost=qa_post_get_full($postid);
qa_db_post_set_created($postid, $created);
switch ($oldpost['basetype']) {
case 'Q':
qa_db_hotness_update($postid);
break;
case 'A':
qa_db_hotness_update($oldpost['parentid']);
break;
}
}
function qa_post_delete($postid)
/*
Delete $postid from the database, hiding it first if appropriate.
......
......@@ -87,6 +87,7 @@
{
require_once QA_INCLUDE_DIR.'qa-util-string.php';
require_once QA_INCLUDE_DIR.'qa-db-maxima.php';
require_once QA_INCLUDE_DIR.'qa-db-users.php';
if (!strlen($handle))
$handle=qa_lang('users/registered_user');
......@@ -99,12 +100,12 @@
$filtermodules=qa_load_modules_with('filter', 'filter_handle');
foreach ($filtermodules as $filtermodule)
$filtermodule->filter_handle($handle, null); // filter first without worrying about errors, since our goal is to get a valid one
$filtermodule->filter_handle($tryhandle, null); // filter first without worrying about errors, since our goal is to get a valid one
$haderror=false;
foreach ($filtermodules as $filtermodule) {
$error=$filtermodule->filter_handle($handle, null); // now check for errors after we've filtered
$error=$filtermodule->filter_handle($tryhandle, null); // now check for errors after we've filtered
if (isset($error))
$haderror=true;
}
......
......@@ -563,7 +563,10 @@
Return flags (see QA_USER_FLAGS_*) of currently logged in user, or null if none
*/
{
return QA_FINAL_EXTERNAL_USERS ? 0 : qa_get_logged_in_user_field('flags');
if (QA_FINAL_EXTERNAL_USERS)
return qa_get_logged_in_user_field('blocked') ? QA_USER_FLAGS_USER_BLOCKED : 0;
else
return qa_get_logged_in_user_field('flags');
}
......
......@@ -25,8 +25,8 @@
*/
define('QA_VERSION', '1.5'); // also used as suffix for .js and .css requests
define('QA_BUILD_DATE', '2012-01-18');
define('QA_VERSION', '1.5.1'); // also used as suffix for .js and .css requests
define('QA_BUILD_DATE', '2012-03-18');
// Execution section of this file - remainder contains function definitions
......@@ -47,6 +47,54 @@
qa_db_allow_connect();
// Version comparison functions
function qa_version_to_float($version)
/*
Converts the $version string (e.g. 1.6.2.2) to a floating point that can be used for greater/lesser comparisons
(PHP's version_compare() function is not quite suitable for our needs)
*/
{
$value=0.0;
if (preg_match('/[0-9\.]+/', $version, $matches)) {
$parts=explode('.', $matches[0]);
$units=1.0;
foreach ($parts as $part) {
$value+=min($part, 999)*$units;
$units/=1000;
}
}
return $value;
}
function qa_qa_version_below($version)
/*
Returns true if the current Q2A version is lower than $version, if both are valid version strings for qa_version_to_float()
*/
{
$minqa=qa_version_to_float($version);
$thisqa=qa_version_to_float(QA_VERSION);
return $minqa && $thisqa && ($thisqa<$minqa);
}
function qa_php_version_below($version)
/*
Returns true if the current PHP version is lower than $version, if both are valid version strings for qa_version_to_float()
*/
{
$minphp=qa_version_to_float($version);
$thisphp=qa_version_to_float(phpversion());
return $minphp && $thisphp && ($thisphp<$minphp);
}
// Initialization functions called above
function qa_initialize_php()
......@@ -54,7 +102,7 @@
Set up and verify the PHP environment for Q2A, including unregistering globals if necessary
*/
{
if ( ((float)phpversion()) < 4.3 )
if (qa_php_version_below('4.3'))
qa_fatal_error('This requires PHP 4.3 or later');
error_reporting(E_ALL); // be ultra-strict about error checking
......@@ -151,12 +199,24 @@
define('QA_FINAL_EXTERNAL_USERS', true);
// Undo WordPress's addition of magic quotes to various things (leave $_COOKIE as is since WP code might need that)
foreach ($_GET as $key => $value)
$_GET[$key]=strtr(stripslashes($value), array('\\\'' => '\'', '\"' => '"')); // also compensate for WordPress's .htaccess file
foreach ($_POST as $key => $value)
$_POST[$key]=stripslashes($value);
function qa_undo_wordpress_quoting($param, $isget)
{
if (is_array($param)) { //
foreach ($param as $key => $value)
$param[$key]=qa_undo_wordpress_quoting($value, $isget);
} else {
$param=stripslashes($param);
if ($isget)
$param=strtr($param, array('\\\'' => '\'', '\"' => '"')); // also compensate for WordPress's .htaccess file
}
return $param;
}
$_GET=qa_undo_wordpress_quoting($_GET, true);
$_POST=qa_undo_wordpress_quoting($_POST, false);
$_SERVER['PHP_SELF']=stripslashes($_SERVER['PHP_SELF']);
} else {
......@@ -226,11 +286,11 @@
$contents=file_get_contents($pluginfile);
if (preg_match('/Plugin[ \t]*Minimum[ \t]*Question2Answer[ \t]*Version\:[ \t]*([0-9\.]+)\s/i', $contents, $matches))
if ( ((float)QA_VERSION>0) && ($matches[1]>(float)QA_VERSION) )
if (qa_qa_version_below($matches[1]))
continue; // skip plugin which requires a later version of Q2A
if (preg_match('/Plugin[ \t]*Minimum[ \t]*PHP[ \t]*Version\:[ \t]*([0-9\.]+)\s/i', $contents, $matches))
if ( ((float)phpversion()>0) && ($matches[1]>(float)phpversion()) )
if (qa_php_version_below($matches[1]))
continue; // skip plugin which requires a later version of PHP
$qa_plugin_directory=dirname($pluginfile).'/';
......
......@@ -175,6 +175,18 @@
}
function qa_db_post_set_created($postid, $created)
/*
Set the created date of $postid to $created, which is a unix timestamp
*/
{
qa_db_query_sub(
'UPDATE ^posts SET created=FROM_UNIXTIME(#) WHERE postid=#',
$created, $postid
);
}
function qa_db_post_delete($postid)
/*
Deletes post $postid from the database (will also delete any votes on the post due to foreign key cascading)
......
......@@ -247,6 +247,8 @@
'users_title' => 'Users',
'users_voted' => 'Users who voted:',
'version_get_x' => 'get ^',
'version_requires_php' => '^1 requires PHP ^2',
'version_requires_q2a' => '^1 requires Q2A ^2',
'version_latest_unknown' => 'latest unknown',
'version_latest' => 'latest',
'viewing_title' => 'Viewing',
......
......@@ -347,7 +347,7 @@
array_push($showoptions, 'show_user_points', '', 'sort_answers_by', 'show_selected_first', 'page_size_q_as', 'show_a_form_immediate');
if (qa_opt('comment_on_qs') || qa_opt('command_on_as'))
if (qa_opt('comment_on_qs') || qa_opt('comment_on_as'))
array_push($showoptions, 'show_fewer_cs_from', 'show_fewer_cs_count', 'show_c_reply_buttons');
$showoptins[]='';
......@@ -544,7 +544,7 @@
array_push($showoptions, 'max_rate_ip_qs', 'max_rate_user_qs', 'max_rate_ip_as', 'max_rate_user_as');
if (qa_opt('comment_on_qs') || qa_opt('command_on_as'))
if (qa_opt('comment_on_qs') || qa_opt('comment_on_as'))
array_push($showoptions, 'max_rate_ip_cs', 'max_rate_user_cs');
$showoptions[]='';
......@@ -970,7 +970,7 @@
$updatehtml='(<SPAN ID="'.$elementid.'">...</SPAN>)';
$qa_content['script_onloads'][]=array(
"qa_version_check(".qa_js($metadata['update']).", 'Theme Version', ".qa_js($metadata['version']).", 'Theme URI', ".qa_js($elementid).");"
"qa_version_check(".qa_js($metadata['update']).", 'Theme Version', ".qa_js($metadata['version'], true).", 'Theme URI', ".qa_js($elementid).");"
);
} else
......
......@@ -133,7 +133,7 @@
$updatehtml='(<SPAN ID="'.$elementid.'">...</SPAN>)';
$qa_content['script_onloads'][]=array(
"qa_version_check(".qa_js($metadata['update']).", 'Plugin Version', ".qa_js($metadata['version']).", 'Plugin URI', ".qa_js($elementid).");"
"qa_version_check(".qa_js($metadata['update']).", 'Plugin Version', ".qa_js($metadata['version'], true).", 'Plugin URI', ".qa_js($elementid).");"
);
} else
......@@ -151,11 +151,11 @@
$pluginhtml=$namehtml.' '.$authorhtml.' '.$updatehtml.'<BR>'.$deschtml.(strlen($deschtml) ? '<BR>' : '').
'<SMALL STYLE="color:#666">'.qa_html($plugindirectory).'</SMALL>';
if (is_numeric(@$metadata['min_q2a']) && ((float)QA_VERSION>0) && $metadata['min_q2a']>(float)QA_VERSION)
if (qa_qa_version_below(@$metadata['min_q2a']))
$pluginhtml='<STRIKE STYLE="color:#999">'.$pluginhtml.'</STRIKE><BR><SPAN STYLE="color:#f00">'.
qa_lang_html_sub('admin/requires_q2a_version', qa_html($metadata['min_q2a'])).'</SPAN>';
elseif (is_numeric(@$metadata['min_php']) && ((float)phpversion()>0) && $metadata['min_php']>(float)phpversion())
elseif (qa_php_version_below(@$metadata['min_php']))
$pluginhtml='<STRIKE STYLE="color:#999">'.$pluginhtml.'</STRIKE><BR><SPAN STYLE="color:#f00">'.
qa_lang_html_sub('admin/requires_php_version', qa_html($metadata['min_php'])).'</SPAN>';
......
......@@ -144,7 +144,8 @@
$qa_content['suggest_next']=qa_lang_html_sub('misc/suggest_favorites_add', '<SPAN CLASS="qa-favorite-image">&nbsp;</SPAN>');
$qa_content['navigation']['sub']=qa_account_sub_navigation();
if (!QA_FINAL_EXTERNAL_USERS)
$qa_content['navigation']['sub']=qa_account_sub_navigation();
return $qa_content;
......
......@@ -449,7 +449,7 @@
if (!isset($in['tags']))
$in['tags']=qa_tagstring_to_tags($question['tags']);
if (!isset($in['categoryid']))
if (!array_key_exists('categoryid', $in))
$in['categoryid']=$question['categoryid'];
$setnotify=$question['isbyuser'] ? qa_combine_notify_email($question['userid'], $in['notify'], $in['email']) : $question['notify'];
......
......@@ -67,7 +67,7 @@
$qa_content['ranking']=array(
'items' => array(),
'rows' => ceil(qa_opt('page_size_users')/qa_opt('columns_users')),
'rows' => ceil(count($users)/qa_opt('columns_users')),
'type' => 'users'
);
......
......@@ -95,7 +95,7 @@
If no user is logged in, call through to the login modules to see if they want to log someone in
*/
{
if (!qa_is_logged_in()) {
if ((!QA_FINAL_EXTERNAL_USERS) && !qa_is_logged_in()) {
$loginmodules=qa_load_modules_with('login', 'check_login');
foreach ($loginmodules as $loginmodule) {
......@@ -222,15 +222,10 @@
// Set appropriate selected flags for navigation (not done in qa_content_prepare() since it also applies to sub-navigation)
$selfpathhtml=qa_path_html($requestlower);
foreach ($qa_content['navigation'] as $navtype => $navigation)
if (is_array($navigation) && ($navtype!='cat'))
foreach ($navigation as $navprefix => $navlink)
if (
(substr($requestlower.'$', 0, strlen($navprefix)) == $navprefix) ||
(strtolower(@$navlink['url'])==$selfpathhtml) // this check is needed for custom links that go to Q2A pages
)
if (substr($requestlower.'$', 0, strlen($navprefix)) == $navprefix)
$qa_content['navigation'][$navtype][$navprefix]['selected']=true;
// Slide down notifications
......@@ -671,15 +666,17 @@
} else {
require_once QA_INCLUDE_DIR.'qa-util-string.php';
$loginmodules=qa_load_modules_with('login', 'login_html');
foreach ($loginmodules as $tryname => $module) {
ob_start();
$module->login_html(isset($topath) ? (qa_opt('site_url').$topath) : qa_path($request, $_GET, qa_opt('site_url')), 'menu');
$label=ob_get_clean();
if (strlen($label))
$qa_content['navigation']['user'][implode('-', qa_string_to_words($tryname))]=array('label' => $label);
if (!QA_FINAL_EXTERNAL_USERS) {
$loginmodules=qa_load_modules_with('login', 'login_html');
foreach ($loginmodules as $tryname => $module) {
ob_start();
$module->login_html(isset($topath) ? (qa_opt('site_url').$topath) : qa_path($request, $_GET, qa_opt('site_url')), 'menu');
$label=ob_get_clean();
if (strlen($label))
$qa_content['navigation']['user'][implode('-', qa_string_to_words($tryname))]=array('label' => $label);
}
}
if (!empty($userlinks['login']))
......
......@@ -867,11 +867,16 @@
$this->output('<TD CLASS="qa-form-'.$style.'-label"'.$extratags.'>');
if ($prefixed)
if ($prefixed) {
$this->output('<LABEL>');
$this->form_field($field, $style);
}
$this->output(@$field['label']);
if ($prefixed)
$this->output('</LABEL>');
if ($suffixed) {
$this->output('&nbsp;');
$this->form_field($field, $style);
......
......@@ -68,8 +68,10 @@
if (is_array($imagesize)) { // if image can't be parsed, don't worry about anything else
$width=$imagesize[0];
$height=$imagesize[1];
$bits=isset($imagesize['bits']) ? $imagesize['bits'] : 8; // these elements can be missing (PHP bug) so assume this as default
$channels=isset($imagesize['channels']) ? $imagesize['channels'] : 3; // for more info: http://gynvael.coldwind.pl/?id=223
$needbytes+=$width*$height*$imagesize['bits']*$imagesize['channels']/8*2; // memory to load original image
$needbytes+=$width*$height*$bits*$channels/8*2; // memory to load original image
if (isset($size) && qa_image_constrain($width, $height, $size)) // memory for constrained image
$needbytes+=$width*$height*3*2; // *2 here and above based on empirical tests
......@@ -93,11 +95,15 @@
$inimage=@imagecreatefromstring($imagedata);
if (is_resource($inimage)) {
$width=imagesx($inimage);
$height=imagesy($inimage);
$inwidth=imagesx($inimage);
$inheight=imagesy($inimage);
if (qa_image_constrain($width, $height, $size))
qa_gd_image_resize($inimage, $width, $height);
$outwidth=$inwidth;
$outheight=$inheight;
// always call qa_gd_image_resize(), even if the size is the same, to take care of possible PNG transparency
qa_image_constrain($outwidth, $outheight, $size);
qa_gd_image_resize($inimage, $outwidth, $outheight);
}
if (is_resource($inimage)) {
......@@ -137,7 +143,9 @@
$image=null;
$newimage=imagecreatetruecolor($width, $height);
$white=imagecolorallocate($newimage, 255, 255, 255); // fill with white first in case we have a transparent PNG
imagefill($newimage, 0, 0, $white);
if (is_resource($newimage)) {
if (imagecopyresampled($newimage, $oldimage, 0, 0, 0, 0, $width, $height, imagesx($oldimage), imagesy($oldimage)))
$image=$newimage;
......
......@@ -640,7 +640,7 @@
return preg_match("/^[\-\!\#\$\%\&\'\*\+\/\=\?\_\`\{\|\}\~a-zA-Z0-9\.\^]+\@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\.\-]+$/", $email) ? true : false;
}
function qa_strlen($string)
/*
Return the number of characters in $string, preferably using PHP's multibyte string functions
......
......@@ -28,14 +28,14 @@
Plugin Name: Facebook Login
Plugin URI:
Plugin Description: Allows users to log in via Facebook
Plugin Version: 1.1
Plugin Date: 2011-12-14
Plugin Version: 1.1.1
Plugin Date: 2012-03-13
Plugin Author: Question2Answer
Plugin Author URI: http://www.question2answer.org/
Plugin License: GPLv2
Plugin Minimum Question2Answer Version: 1.3
Plugin Minimum PHP Version: 5
Plugin Update Check URI:
Plugin Update Check URI:
*/
......@@ -45,7 +45,8 @@
}
qa_register_plugin_module('login', 'qa-facebook-login.php', 'qa_facebook_login', 'Facebook Login');
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');
/*
......
......@@ -179,7 +179,7 @@
foreach ($questions as $question) {
$this->sitemap_output(qa_q_request($question['postid'], $question['title']),
0.1+0.9*($question['hotness']-$hotstats['base'])/$hotstats['spread']);
0.1+0.9*($question['hotness']-$hotstats['base'])/(1+$hotstats['spread']));
$nextpostid=max($nextpostid, $question['postid']+1);
}
}
......
......@@ -421,7 +421,7 @@ h2 {font-size:22px; color:#c659ab; padding-top:12px; clear:both;}
.qa-related-qs {font-size:14px;}
.qa-related-qs h2 {font-size:18px;}
.qa-related-q-list {list-style-type:none; padding:0;}
.qa-related-q-item {margin:0.5em 0;}
.qa-related-q-item {margin:0.5em 0; word-wrap: break-word;}
.qa-activity-count {font-size:14px;}
.qa-activity-count-item {margin:0.5em 0;}
.qa-activity-count-data {font-size:24px; font-weight:bold;}
......
......@@ -390,7 +390,7 @@ h2 {font-size:16px; padding-top:12px; clear:both;}
/* Related questions and activity count widgets */
.qa-related-q-list {list-style-type:none; padding:0;}
.qa-related-q-item {margin:0.5em 0;}
.qa-related-q-item {margin:0.5em 0; word-wrap: break-word;}
.qa-activity-count {font-size:150%;}
.qa-activity-count-item {margin:0.25em 0;}
.qa-activity-count-data {font-weight:bold;}
......
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