Commit 4932f19c by Scott

Coding style (misc)

parent c20678fb
......@@ -20,7 +20,7 @@
More about this license: http://www.question2answer.org/license.php
*/
return array(
return array(
'active_widgets_explanation' => 'Currently active widgets:',
'add_category_button' => 'Add Category',
'add_field_button' => 'Add Field',
......@@ -276,9 +276,4 @@
'widget_not_available' => 'This widget is not available. This could be because the plugin providing the widget is no longer installed.',
'widget_pages_explanation' => 'Show widget in this position on the following pages:',
'widgets_explanation' => 'Available widgets:',
);
/*
Omit PHP closing tag to help avoid accidental output
*/
);
......@@ -20,7 +20,7 @@
More about this license: http://www.question2answer.org/license.php
*/
return array(
return array(
'a_commented_body' => "Your answer on ^site_title has a new comment by ^c_handle:\n\n^open^c_content^close\n\nYour answer was:\n\n^open^c_context^close\n\nYou may respond by adding your own comment:\n\n^url\n\nThank you,\n\n^site_title",
'a_commented_subject' => 'Your ^site_title answer has a new comment',
......@@ -83,9 +83,4 @@
'welcome_body' => "Thank you for registering for ^site_title.\n\n^custom^confirmYour login details are as follows:\n\nUsername: ^handle\nEmail: ^email\n\nPlease keep this information safe for future reference.\n\nThank you,\n\n^site_title\n^url",
'welcome_confirm' => "Please click below to confirm your email address.\n\n^url\n\n",
'welcome_subject' => 'Welcome to ^site_title!',
);
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
);
......@@ -20,7 +20,7 @@
More about this license: http://www.question2answer.org/license.php
*/
return array(
return array(
'_decimal_point' => '.',
'_thousands_separator' => ',',
'_thousands_suffix' => 'k',
......@@ -227,9 +227,4 @@
'x_votes' => '^ votes',
'x_weeks' => '^ weeks',
'x_years' => '^ years',
);
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
);
......@@ -20,7 +20,7 @@
More about this license: http://www.question2answer.org/license.php
*/
return array(
return array(
'block_ip_button' => 'Block IP address',
'browse_categories' => 'Browse categories',
'captcha_approve_fix' => 'This verification will stop appearing once your account is approved.',
......@@ -117,9 +117,4 @@
'your_q_reopened' => 'your question reopened',
'your_q_reshown' => 'your question reshown',
'your_q_retagged' => 'your question retagged',
);
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
);
......@@ -20,7 +20,7 @@
More about this license: http://www.question2answer.org/license.php
*/
return array(
return array(
'allow_change_usernames' => 'Allow users with posts to change their username:',
'allow_close_questions' => 'Allow questions to be manually closed:',
'allow_login_email_only' => 'Only log in by email address (not username):',
......@@ -292,9 +292,4 @@
'voting_on_as' => 'Allow voting on answers:',
'voting_on_q_page_only' => 'Allow voting on question page only:',
'voting_on_qs' => 'Allow voting on questions:',
);
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
);
......@@ -20,7 +20,7 @@
More about this license: http://www.question2answer.org/license.php
*/
return array(
return array(
'1_chosen_as_best' => ' (1 chosen as best)',
'1_down_vote' => '1 down vote',
'1_up_vote' => '1 up vote',
......@@ -87,9 +87,4 @@
'x_down_votes' => '^ down votes',
'x_up_votes' => '^ up votes',
'x_with_best_chosen' => ' (^ with best answer chosen)',
);
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
);
......@@ -20,7 +20,7 @@
More about this license: http://www.question2answer.org/license.php
*/
return array(
return array(
'1_answer_title' => '1 Answer',
'a_convert_to_c' => 'Convert this answer into a comment',
'a_convert_to_c_on' => 'Convert this answer into a comment on:',
......@@ -172,9 +172,4 @@
'your_answer_title' => 'Your answer',
'your_comment_a' => 'Your comment on this answer:',
'your_comment_q' => 'Your comment on this question:',
);
/*
Omit PHP closing tag to help avoid accidental output
*/
);
......@@ -20,7 +20,7 @@
More about this license: http://www.question2answer.org/license.php
*/
return array(
return array(
'about' => 'About',
'add_user_x_favorites' => 'Add user ^ to my favorites',
'approve_required' => 'Please wait for your account to be approved or ^1add more information^2.',
......@@ -134,9 +134,4 @@
'wall_posts_explanation' => 'Allow users to post on your wall (you will also be emailed)',
'website' => 'Website',
'x_ago_from_y' => '^1 ago from ^2',
);
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
);
......@@ -26,7 +26,7 @@ class qa_html_theme_layer extends qa_html_theme_base
private $qa_voters_flaggers_cache = array();
// Collect up all required postids for the entire page to save DB queries - common case where whole page output
// Collect up all required postids for the entire page to save DB queries - common case where whole page output
public function main()
{
......@@ -55,7 +55,7 @@ class qa_html_theme_layer extends qa_html_theme_base
}
// Other functions which also collect up required postids for lists to save DB queries - helps with widget output and Ajax calls
// Other functions which also collect up required postids for lists to save DB queries - helps with widget output and Ajax calls
public function q_list_items($q_items)
{
......@@ -79,7 +79,7 @@ class qa_html_theme_layer extends qa_html_theme_base
}
// Actual output of the voters and flaggers
// Actual output of the voters and flaggers
public function vote_count($post)
{
......@@ -141,7 +141,7 @@ class qa_html_theme_layer extends qa_html_theme_base
}
// Utility functions for this layer
// Utility functions for this layer
/**
* @deprecated This function will become private in Q2A 1.8. It is specific to this plugin and
......
......@@ -20,44 +20,44 @@
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
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../');
exit;
}
}
function qa_get_mysql_user_column_type()
{
function qa_get_mysql_user_column_type()
{
return 'BIGINT UNSIGNED';
}
}
function qa_get_login_links($relative_url_prefix, $redirect_back_to_url)
{
function qa_get_login_links($relative_url_prefix, $redirect_back_to_url)
{
return array(
'login' => wp_login_url(qa_opt('site_url').$redirect_back_to_url),
'login' => wp_login_url(qa_opt('site_url') . $redirect_back_to_url),
'register' => function_exists('wp_registration_url') ? wp_registration_url() : site_url('wp-login.php?action=register'),
'logout' => strtr(wp_logout_url(), array('&' => '&')),
);
}
}
function qa_get_logged_in_user()
{
$wordpressuser=wp_get_current_user();
function qa_get_logged_in_user()
{
$wordpressuser = wp_get_current_user();
if ($wordpressuser->ID==0)
if ($wordpressuser->ID == 0)
return null;
else {
if (current_user_can('administrator'))
$level=QA_USER_LEVEL_ADMIN;
$level = QA_USER_LEVEL_ADMIN;
elseif (current_user_can('editor'))
$level=QA_USER_LEVEL_EDITOR;
$level = QA_USER_LEVEL_EDITOR;
elseif (current_user_can('contributor'))
$level=QA_USER_LEVEL_EXPERT;
$level = QA_USER_LEVEL_EXPERT;
else
$level=QA_USER_LEVEL_BASIC;
$level = QA_USER_LEVEL_BASIC;
return array(
'userid' => $wordpressuser->ID,
......@@ -66,86 +66,86 @@
'level' => $level,
);
}
}
}
function qa_get_user_email($userid)
{
$user=get_userdata($userid);
function qa_get_user_email($userid)
{
$user = get_userdata($userid);
return @$user->user_email;
}
}
function qa_get_userids_from_public($publicusernames)
{
function qa_get_userids_from_public($publicusernames)
{
global $wpdb;
if (count($publicusernames))
return qa_db_read_all_assoc(qa_db_query_sub(
'SELECT user_nicename, ID FROM '.$wpdb->base_prefix.'users WHERE user_nicename IN ($)',
'SELECT user_nicename, ID FROM ' . $wpdb->base_prefix . 'users WHERE user_nicename IN ($)',
$publicusernames
), 'user_nicename', 'ID');
else
return array();
}
}
function qa_get_public_from_userids($userids)
{
function qa_get_public_from_userids($userids)
{
global $wpdb, $qa_cache_wp_user_emails;
if (count($userids)) {
$useridtopublic=array();
$qa_cache_wp_user_emails=array();
$useridtopublic = array();
$qa_cache_wp_user_emails = array();
$userfields=qa_db_read_all_assoc(qa_db_query_sub(
'SELECT ID, user_nicename, user_email FROM '.$wpdb->base_prefix.'users WHERE ID IN (#)',
$userfields = qa_db_read_all_assoc(qa_db_query_sub(
'SELECT ID, user_nicename, user_email FROM ' . $wpdb->base_prefix . 'users WHERE ID IN (#)',
$userids
), 'ID');
foreach ($userfields as $id => $fields) {
$useridtopublic[$id]=$fields['user_nicename'];
$qa_cache_wp_user_emails[$id]=$fields['user_email'];
$useridtopublic[$id] = $fields['user_nicename'];
$qa_cache_wp_user_emails[$id] = $fields['user_email'];
}
return $useridtopublic;
} else
return array();
}
}
function qa_get_logged_in_user_html($logged_in_user, $relative_url_prefix)
{
$publicusername=$logged_in_user['publicusername'];
function qa_get_logged_in_user_html($logged_in_user, $relative_url_prefix)
{
$publicusername = $logged_in_user['publicusername'];
return '<a href="'.qa_path_html('user/'.$publicusername).'" class="qa-user-link">'.htmlspecialchars($publicusername).'</a>';
}
return '<a href="' . qa_path_html('user/' . $publicusername) . '" class="qa-user-link">' . htmlspecialchars($publicusername) . '</a>';
}
function qa_get_users_html($userids, $should_include_link, $relative_url_prefix)
{
$useridtopublic=qa_get_public_from_userids($userids);
function qa_get_users_html($userids, $should_include_link, $relative_url_prefix)
{
$useridtopublic = qa_get_public_from_userids($userids);
$usershtml=array();
$usershtml = array();
foreach ($userids as $userid) {
$publicusername=$useridtopublic[$userid];
$publicusername = $useridtopublic[$userid];
$usershtml[$userid]=htmlspecialchars($publicusername);
$usershtml[$userid] = htmlspecialchars($publicusername);
if ($should_include_link)
$usershtml[$userid]='<a href="'.qa_path_html('user/'.$publicusername).'" class="qa-user-link">'.$usershtml[$userid].'</a>';
$usershtml[$userid] = '<a href="' . qa_path_html('user/' . $publicusername) . '" class="qa-user-link">' . $usershtml[$userid] . '</a>';
}
return $usershtml;
}
}
function qa_avatar_html_from_userid($userid, $size, $padding)
{
require_once QA_INCLUDE_DIR.'app/format.php';
function qa_avatar_html_from_userid($userid, $size, $padding)
{
require_once QA_INCLUDE_DIR . 'app/format.php';
global $qa_cache_wp_user_emails;
......@@ -153,14 +153,9 @@
return qa_get_gravatar_html($qa_cache_wp_user_emails[$userid], $size);
return null;
}
}
function qa_user_report_action($userid, $action)
{
}
/*
Omit PHP closing tag to help avoid accidental output
*/
function qa_user_report_action($userid, $action)
{
}
......@@ -20,73 +20,82 @@
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
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../');
exit;
}
}
function qa_has_gd_image()
/*
Return true if PHP has the GD extension installed and it appears to be usable
*/
{
/**
* Return true if PHP has the GD extension installed and it appears to be usable
*/
function qa_has_gd_image()
{
return extension_loaded('gd') && function_exists('imagecreatefromstring') && function_exists('imagejpeg');
}
function qa_image_file_too_big($imagefile, $size=null)
/*
Check if the image in $imagefile will be too big for PHP/GD to process given memory usage and limits
Pass the width and height limit beyond which the image will require scaling in $size (if any)
Returns false if the image will fit fine, otherwise a safe estimate of the factor the image should be sized by
*/
{
}
/**
* Check if the image in $imagefile will be too big for PHP/GD to process given memory usage and limits
* Pass the width and height limit beyond which the image will require scaling in $size (if any)
* Returns false if the image will fit fine, otherwise a safe estimate of the factor the image should be sized by
* @param $imagefile
* @param int $size
* @return bool|float
*/
function qa_image_file_too_big($imagefile, $size = null)
{
if (function_exists('memory_get_usage')) {
$gotbytes=trim(@ini_get('memory_limit'));
$gotbytes = trim(@ini_get('memory_limit'));
$gotbytes = convert_to_bytes(substr($gotbytes, -1), $gotbytes);
if ($gotbytes>0) { // otherwise we clearly don't know our limit
$gotbytes=($gotbytes-memory_get_usage())*0.9; // safety margin of 10%
if ($gotbytes > 0) { // otherwise we clearly don't know our limit
$gotbytes = ($gotbytes - memory_get_usage()) * 0.9; // safety margin of 10%
$needbytes=filesize($imagefile); // memory to store file contents
$needbytes = filesize($imagefile); // memory to store file contents
$imagesize=@getimagesize($imagefile);
$imagesize = @getimagesize($imagefile);
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
$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*$bits*$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
$needbytes += $width * $height * 3 * 2; // *2 here and above based on empirical tests
}
if ($needbytes>$gotbytes)
return sqrt($gotbytes/($needbytes*1.5)); // additional 50% safety margin since JPEG quality may change
if ($needbytes > $gotbytes)
return sqrt($gotbytes / ($needbytes * 1.5)); // additional 50% safety margin since JPEG quality may change
}
}
return false;
}
function qa_image_constrain_data($imagedata, &$width, &$height, $maxwidth, $maxheight=null)
/*
Given $imagedata containing JPEG/GIF/PNG data, constrain it proportionally to fit in $maxwidth x $maxheight.
Return the new image data (will always be a JPEG), and set the $width and $height variables.
If $maxheight is omitted or set to null, assume it to be the same as $maxwidth.
*/
{
$inimage=@imagecreatefromstring($imagedata);
}
/**
* Given $imagedata containing JPEG/GIF/PNG data, constrain it proportionally to fit in $maxwidth x $maxheight.
* Return the new image data (will always be a JPEG), and set the $width and $height variables.
* If $maxheight is omitted or set to null, assume it to be the same as $maxwidth.
* @param $imagedata
* @param int $width
* @param int $height
* @param int $maxwidth
* @param int $maxheight
* @return null|string
*/
function qa_image_constrain_data($imagedata, &$width, &$height, $maxwidth, $maxheight = null)
{
$inimage = @imagecreatefromstring($imagedata);
if (is_resource($inimage)) {
$width=imagesx($inimage);
$height=imagesy($inimage);
$width = imagesx($inimage);
$height = imagesy($inimage);
// always call qa_gd_image_resize(), even if the size is the same, to take care of possible PNG transparency
qa_image_constrain($width, $height, $maxwidth, $maxheight);
......@@ -94,92 +103,98 @@
}
if (is_resource($inimage)) {
$imagedata=qa_gd_image_jpeg($inimage);
$imagedata = qa_gd_image_jpeg($inimage);
imagedestroy($inimage);
return $imagedata;
}
return null;
}
function qa_image_constrain(&$width, &$height, $maxwidth, $maxheight=null)
/*
Given and $width and $height, return true if those need to be contrained to fit in $maxwidth x $maxheight.
If so, also set $width and $height to the new proportionally constrained values.
If $maxheight is omitted or set to null, assume it to be the same as $maxwidth.
*/
{
}
/**
* Given and $width and $height, return true if those need to be contrained to fit in $maxwidth x $maxheight.
* If so, also set $width and $height to the new proportionally constrained values.
* If $maxheight is omitted or set to null, assume it to be the same as $maxwidth.
* @param int $width
* @param int $height
* @param int $maxwidth
* @param int $maxheight
* @return bool
*/
function qa_image_constrain(&$width, &$height, $maxwidth, $maxheight = null)
{
if (!isset($maxheight))
$maxheight=$maxwidth;
$maxheight = $maxwidth;
if (($width>$maxwidth) || ($height>$maxheight)) {
$multiplier=min($maxwidth/$width, $maxheight/$height);
$width=floor($width*$multiplier);
$height=floor($height*$multiplier);
if (($width > $maxwidth) || ($height > $maxheight)) {
$multiplier = min($maxwidth / $width, $maxheight / $height);
$width = floor($width * $multiplier);
$height = floor($height * $multiplier);
return true;
}
return false;
}
function qa_gd_image_resize(&$image, $width, $height)
/*
Resize the GD $image to $width and $height, setting it to null if the resize failed
*/
{
$oldimage=$image;
$image=null;
$newimage=imagecreatetruecolor($width, $height);
$white=imagecolorallocate($newimage, 255, 255, 255); // fill with white first in case we have a transparent PNG
}
/**
* Resize the GD $image to $width and $height, setting it to null if the resize failed
* @param $image
* @param $width
* @param $height
*/
function qa_gd_image_resize(&$image, $width, $height)
{
$oldimage = $image;
$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;
$image = $newimage;
else
imagedestroy($newimage);
}
imagedestroy($oldimage);
}
}
function qa_gd_image_jpeg($image, $output=false)
/*
Return the JPEG data for GD $image, also echoing it to browser if $output is true
*/
{
/**
* Return the JPEG data for GD $image, also echoing it to browser if $output is true
* @param resource $image
* @param bool $output
* @return string
*/
function qa_gd_image_jpeg($image, $output = false)
{
ob_start();
imagejpeg($image, null, 90);
return $output ? ob_get_flush() : ob_get_clean();
}
}
function qa_gd_image_formats()
/*
Return an array of strings listing the image formats that are supported
*/
{
$imagetypebits=imagetypes();
/**
* Return an array of strings listing the image formats that are supported
*/
function qa_gd_image_formats()
{
$imagetypebits = imagetypes();
$bitstrings=array(
$bitstrings = array(
IMG_GIF => 'GIF',
IMG_JPG => 'JPG',
IMG_PNG => 'PNG',
);
foreach (array_keys($bitstrings) as $bit)
if (!($imagetypebits&$bit))
if (!($imagetypebits & $bit))
unset($bitstrings[$bit]);
return $bitstrings;
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
}
......@@ -20,12 +20,7 @@
More about this license: http://www.question2answer.org/license.php
*/
return array(
return array(
'admin_title' => 'Administration Centre',
'url_format_note' => 'Options with the ^ label are working for your site\'s configuration. For best search engine optimisation (SEO), use the first ^ option available.',
);
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
);
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