Commit 2089b48f by Scott

Coding style (misc)

parent c1b82ae1
...@@ -108,7 +108,7 @@ ...@@ -108,7 +108,7 @@
and the value should be the replacement for that standard part, e.g. 'topics'. If you edit this and the value should be the replacement for that standard part, e.g. 'topics'. If you edit this
file in UTF-8 encoding you can also use non-ASCII characters in these URLs. file in UTF-8 encoding you can also use non-ASCII characters in these URLs.
$QA_CONST_PATH_MAP=array( $QA_CONST_PATH_MAP = array(
'questions' => 'topics', 'questions' => 'topics',
'categories' => 'sections', 'categories' => 'sections',
'users' => 'contributors', 'users' => 'contributors',
...@@ -197,7 +197,3 @@ ...@@ -197,7 +197,3 @@
file to override the default setting. Just make sure you know what you're doing! file to override the default setting. Just make sure you know what you're doing!
*/ */
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
...@@ -573,7 +573,7 @@ function qa_db_missing_columns($table, $definition) ...@@ -573,7 +573,7 @@ function qa_db_missing_columns($table, $definition)
$missing = array(); $missing = array();
foreach ($definition as $colname => $coldefn) foreach ($definition as $colname => $coldefn)
if ((!is_int($colname)) && !isset($keycolumns[$colname])) if (!is_int($colname) && !isset($keycolumns[$colname]))
$missing[$colname] = $coldefn; $missing[$colname] = $coldefn;
return $missing; return $missing;
...@@ -649,7 +649,7 @@ function qa_db_check_tables() ...@@ -649,7 +649,7 @@ function qa_db_check_tables()
$datamissing++; $datamissing++;
} }
if (($datacount == $datamissing) && ($datamissing == count($missing))) if ($datacount == $datamissing && $datamissing == count($missing))
return 'non-users-missing'; return 'non-users-missing';
} }
......
...@@ -148,45 +148,45 @@ function qa_db_points_update_ifuser($userid, $columns) ...@@ -148,45 +148,45 @@ function qa_db_points_update_ifuser($userid, $columns)
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
if (qa_should_update_counts() && isset($userid)) { if (qa_should_update_counts() && isset($userid)) {
require_once QA_INCLUDE_DIR.'app/options.php'; require_once QA_INCLUDE_DIR . 'app/options.php';
require_once QA_INCLUDE_DIR.'app/cookies.php'; require_once QA_INCLUDE_DIR . 'app/cookies.php';
$calculations=qa_db_points_calculations(); $calculations = qa_db_points_calculations();
if ($columns===true) if ($columns === true)
$keycolumns=$calculations; $keycolumns = $calculations;
elseif (empty($columns)) elseif (empty($columns))
$keycolumns=array(); $keycolumns = array();
elseif (is_array($columns)) elseif (is_array($columns))
$keycolumns=array_flip($columns); $keycolumns = array_flip($columns);
else else
$keycolumns=array($columns => true); $keycolumns = array($columns => true);
$insertfields='userid, '; $insertfields = 'userid, ';
$insertvalues='$, '; $insertvalues = '$, ';
$insertpoints=(int)qa_opt('points_base'); $insertpoints = (int)qa_opt('points_base');
$updates=''; $updates = '';
$updatepoints=$insertpoints; $updatepoints = $insertpoints;
foreach ($calculations as $field => $calculation) { foreach ($calculations as $field => $calculation) {
$multiple=(int)$calculation['multiple']; $multiple = (int)$calculation['multiple'];
if (isset($keycolumns[$field])) { if (isset($keycolumns[$field])) {
$insertfields.=$field.', '; $insertfields .= $field . ', ';
$insertvalues.='@_'.$field.':=(SELECT '.$calculation['formula'].'), '; $insertvalues .= '@_' . $field . ':=(SELECT ' . $calculation['formula'] . '), ';
$updates.=$field.'=@_'.$field.', '; $updates .= $field . '=@_' . $field . ', ';
$insertpoints.='+('.(int)$multiple.'*@_'.$field.')'; $insertpoints .= '+(' . (int)$multiple . '*@_' . $field . ')';
} }
$updatepoints.='+('.$multiple.'*'.(isset($keycolumns[$field]) ? '@_' : '').$field.')'; $updatepoints .= '+(' . $multiple . '*' . (isset($keycolumns[$field]) ? '@_' : '') . $field . ')';
} }
$query='INSERT INTO ^userpoints ('.$insertfields.'points) VALUES ('.$insertvalues.$insertpoints.') '. $query = 'INSERT INTO ^userpoints (' . $insertfields . 'points) VALUES (' . $insertvalues . $insertpoints . ') ' .
'ON DUPLICATE KEY UPDATE '.$updates.'points='.$updatepoints.'+bonus'; 'ON DUPLICATE KEY UPDATE ' . $updates . 'points=' . $updatepoints . '+bonus';
qa_db_query_raw(str_replace('~', "='".qa_db_escape_string($userid)."'", qa_db_apply_sub($query, array($userid))));
// build like this so that a #, $ or ^ character in the $userid (if external integration) isn't substituted // build like this so that a #, $ or ^ character in the $userid (if external integration) isn't substituted
qa_db_query_raw(str_replace('~', "='" . qa_db_escape_string($userid) . "'", qa_db_apply_sub($query, array($userid))));
if (qa_db_insert_on_duplicate_inserted()) if (qa_db_insert_on_duplicate_inserted())
qa_db_userpointscount_update(); qa_db_userpointscount_update();
......
...@@ -190,7 +190,7 @@ if (qa_clicked('docancel')) { ...@@ -190,7 +190,7 @@ if (qa_clicked('docancel')) {
$errors['slug'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_CAT_PAGE_TAGS_LENGTH); $errors['slug'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_CAT_PAGE_TAGS_LENGTH);
elseif (preg_match('/[\\+\\/]/', $inslug)) elseif (preg_match('/[\\+\\/]/', $inslug))
$errors['slug'] = qa_lang_sub('admin/slug_bad_chars', '+ /'); $errors['slug'] = qa_lang_sub('admin/slug_bad_chars', '+ /');
elseif ((!isset($inparentid)) && qa_admin_is_slug_reserved($inslug)) // only top level is a problem elseif (!isset($inparentid) && qa_admin_is_slug_reserved($inslug)) // only top level is a problem
$errors['slug'] = qa_lang('admin/slug_reserved'); $errors['slug'] = qa_lang('admin/slug_reserved');
elseif (isset($matchcategoryid) && strcmp($matchcategoryid, @$editcategory['categoryid'])) elseif (isset($matchcategoryid) && strcmp($matchcategoryid, @$editcategory['categoryid']))
$errors['slug'] = qa_lang('admin/category_already_used'); $errors['slug'] = qa_lang('admin/category_already_used');
......
...@@ -1300,7 +1300,7 @@ foreach ($showoptions as $optionname) { ...@@ -1300,7 +1300,7 @@ foreach ($showoptions as $optionname) {
foreach ($searchmodules as $modulename => $module) { foreach ($searchmodules as $modulename => $module) {
$selectoptions[qa_html($modulename)] = strlen($modulename) ? qa_html($modulename) : qa_lang_html('options/option_default'); $selectoptions[qa_html($modulename)] = strlen($modulename) ? qa_html($modulename) : qa_lang_html('options/option_default');
if (($modulename == $value) && method_exists($module, 'admin_form')) { if ($modulename == $value && method_exists($module, 'admin_form')) {
$optionfield['note'] = '<a href="' . qa_admin_module_options_path('search', $modulename) . '">' . qa_lang_html('admin/options') . '</a>'; $optionfield['note'] = '<a href="' . qa_admin_module_options_path('search', $modulename) . '">' . qa_lang_html('admin/options') . '</a>';
} }
} }
......
...@@ -142,7 +142,7 @@ if (count($questions)) { ...@@ -142,7 +142,7 @@ if (count($questions)) {
); );
} }
if ((!qa_user_post_permit_error('permit_delete_hidden', $question)) && !$dependcounts[$qhiddenpostid[$key]]) { if (!qa_user_post_permit_error('permit_delete_hidden', $question) && !$dependcounts[$qhiddenpostid[$key]]) {
// Possible values for popup: delete_q_popup, delete_a_popup, delete_c_popup // Possible values for popup: delete_q_popup, delete_a_popup, delete_c_popup
$buttons['delete'] = array( $buttons['delete'] = array(
'tags' => 'name="admin_' . qa_html($qhiddenpostid[$key]) . '_delete" onclick="return qa_admin_click(this);"', 'tags' => 'name="admin_' . qa_html($qhiddenpostid[$key]) . '_delete" onclick="return qa_admin_click(this);"',
......
...@@ -319,7 +319,7 @@ if (isset($editpage)) { ...@@ -319,7 +319,7 @@ if (isset($editpage)) {
} }
} }
if ((!isset($editpage['pageid'])) || $nav != @$editpage['nav']) { if (!isset($editpage['pageid']) || $nav != @$editpage['nav']) {
$positionvalue = isset($previous) ? qa_lang_html_sub('admin/after_x_tab', qa_html($previous['title'])) : qa_lang_html($langkey); $positionvalue = isset($previous) ? qa_lang_html_sub('admin/after_x_tab', qa_html($previous['title'])) : qa_lang_html($langkey);
$positionoptions[$nav . (isset($previous) ? (1 + $maxposition) : 1)] = $positionvalue; $positionoptions[$nav . (isset($previous) ? (1 + $maxposition) : 1)] = $positionvalue;
} }
......
...@@ -94,7 +94,7 @@ if ($explicitqa && (!qa_is_http_post()) && !qa_has_custom_home()) ...@@ -94,7 +94,7 @@ if ($explicitqa && (!qa_is_http_post()) && !qa_has_custom_home())
// Then, if there's a slug that matches no category, check page modules provided by plugins // Then, if there's a slug that matches no category, check page modules provided by plugins
if ((!$explicitqa) && $countslugs && !isset($categoryid)) { if (!$explicitqa && $countslugs && !isset($categoryid)) {
$pagemodules = qa_load_modules_with('page', 'match_request'); $pagemodules = qa_load_modules_with('page', 'match_request');
$request = qa_request(); $request = qa_request();
...@@ -110,7 +110,7 @@ if ((!$explicitqa) && $countslugs && !isset($categoryid)) { ...@@ -110,7 +110,7 @@ if ((!$explicitqa) && $countslugs && !isset($categoryid)) {
// Then, check whether we are showing a custom home page // Then, check whether we are showing a custom home page
if ((!$explicitqa) && (!$countslugs) && qa_opt('show_custom_home')) { if (!$explicitqa && !$countslugs && qa_opt('show_custom_home')) {
qa_set_template('custom'); qa_set_template('custom');
$qa_content = qa_content_prepare(); $qa_content = qa_content_prepare();
$qa_content['title'] = qa_html(qa_opt('custom_home_heading')); $qa_content['title'] = qa_html(qa_opt('custom_home_heading'));
......
...@@ -98,7 +98,7 @@ if ($question['closeable']) { ...@@ -98,7 +98,7 @@ if ($question['closeable']) {
else else
$formtype = 'q_close'; // keep editing if an error $formtype = 'q_close'; // keep editing if an error
} elseif (($pagestate == 'close') && qa_page_q_permit_edit($question, 'permit_close_q', $pageerror)) } elseif ($pagestate == 'close' && qa_page_q_permit_edit($question, 'permit_close_q', $pageerror))
$formtype = 'q_close'; $formtype = 'q_close';
} }
...@@ -220,7 +220,7 @@ foreach ($commentsfollows as $commentid => $comment) { ...@@ -220,7 +220,7 @@ foreach ($commentsfollows as $commentid => $comment) {
$formtype = 'c_edit'; $formtype = 'c_edit';
$formpostid = $commentid; // keep editing if an error $formpostid = $commentid; // keep editing if an error
} }
} elseif (($pagestate == ('edit-' . $commentid)) && qa_page_q_permit_edit($comment, 'permit_edit_c', $pageerror)) { } elseif ($pagestate == ('edit-' . $commentid) && qa_page_q_permit_edit($comment, 'permit_edit_c', $pageerror)) {
$formtype = 'c_edit'; $formtype = 'c_edit';
$formpostid = $commentid; $formpostid = $commentid;
} }
......
...@@ -468,7 +468,7 @@ function qa_page_q_add_c_submit($question, $parent, $commentsfollows, $usecaptch ...@@ -468,7 +468,7 @@ function qa_page_q_add_c_submit($question, $parent, $commentsfollows, $usecaptch
$testwords = implode(' ', qa_string_to_words($in['content'])); $testwords = implode(' ', qa_string_to_words($in['content']));
foreach ($commentsfollows as $comment) { foreach ($commentsfollows as $comment) {
if (($comment['basetype'] == 'C') && ($comment['parentid'] == $parentid) && !$comment['hidden']) { if ($comment['basetype'] == 'C' && $comment['parentid'] == $parentid && !$comment['hidden']) {
if (implode(' ', qa_string_to_words($comment['content'])) == $testwords) { if (implode(' ', qa_string_to_words($comment['content'])) == $testwords) {
$errors['content'] = qa_lang_html('question/duplicate_content'); $errors['content'] = qa_lang_html('question/duplicate_content');
break; break;
......
...@@ -198,10 +198,10 @@ if (qa_is_http_post() || strlen($pagestate)) ...@@ -198,10 +198,10 @@ if (qa_is_http_post() || strlen($pagestate))
$formrequested = isset($formtype); $formrequested = isset($formtype);
if ((!$formrequested) && $question['answerbutton']) { if (!$formrequested && $question['answerbutton']) {
$immedoption = qa_opt('show_a_form_immediate'); $immedoption = qa_opt('show_a_form_immediate');
if (($immedoption == 'always') || (($immedoption == 'if_no_as') && (!$question['isbyuser']) && (!$question['acount']))) if ($immedoption == 'always' || ($immedoption == 'if_no_as' && !$question['isbyuser'] && !$question['acount']))
$formtype = 'a_add'; // show answer form by default $formtype = 'a_add'; // show answer form by default
} }
...@@ -275,7 +275,7 @@ if ($formtype == 'a_edit') { ...@@ -275,7 +275,7 @@ if ($formtype == 'a_edit') {
$jumptoanchor = 'a' . $formpostid; $jumptoanchor = 'a' . $formpostid;
} elseif (($formtype == 'a_add') || ($question['answerbutton'] && !$formrequested)) { } elseif ($formtype == 'a_add' || ($question['answerbutton'] && !$formrequested)) {
$qa_content['a_form'] = qa_page_q_add_a_form($qa_content, 'anew', $captchareason, $question, @$anewin, @$anewerrors, $formtype == 'a_add', $formrequested); $qa_content['a_form'] = qa_page_q_add_a_form($qa_content, 'anew', $captchareason, $question, @$anewin, @$anewerrors, $formtype == 'a_add', $formrequested);
if ($formrequested) { if ($formrequested) {
...@@ -294,16 +294,16 @@ if ($formtype == 'q_close') { ...@@ -294,16 +294,16 @@ if ($formtype == 'q_close') {
$qa_content['q_view']['c_form'] = qa_page_q_close_q_form($qa_content, $question, 'close', @$closein, @$closeerrors); $qa_content['q_view']['c_form'] = qa_page_q_close_q_form($qa_content, $question, 'close', @$closein, @$closeerrors);
$jumptoanchor = 'close'; $jumptoanchor = 'close';
} elseif ((($formtype == 'c_add') && ($formpostid == $questionid)) || ($question['commentbutton'] && !$formrequested)) { // ...to be added } elseif (($formtype == 'c_add' && $formpostid == $questionid) || ($question['commentbutton'] && !$formrequested)) { // ...to be added
$qa_content['q_view']['c_form'] = qa_page_q_add_c_form($qa_content, $question, $question, 'c' . $questionid, $qa_content['q_view']['c_form'] = qa_page_q_add_c_form($qa_content, $question, $question, 'c' . $questionid,
$captchareason, @$cnewin[$questionid], @$cnewerrors[$questionid], $formtype == 'c_add'); $captchareason, @$cnewin[$questionid], @$cnewerrors[$questionid], $formtype == 'c_add');
if (($formtype == 'c_add') && ($formpostid == $questionid)) { if ($formtype == 'c_add' && $formpostid == $questionid) {
$jumptoanchor = 'c' . $questionid; $jumptoanchor = 'c' . $questionid;
$commentsall = $questionid; $commentsall = $questionid;
} }
} elseif (($formtype == 'c_edit') && (@$commentsfollows[$formpostid]['parentid'] == $questionid)) { // ...being edited } elseif ($formtype == 'c_edit' && @$commentsfollows[$formpostid]['parentid'] == $questionid) { // ...being edited
$qa_content['q_view']['c_form'] = qa_page_q_edit_c_form($qa_content, 'c' . $formpostid, $commentsfollows[$formpostid], $qa_content['q_view']['c_form'] = qa_page_q_edit_c_form($qa_content, 'c' . $formpostid, $commentsfollows[$formpostid],
@$ceditin[$formpostid], @$cediterrors[$formpostid]); @$ceditin[$formpostid], @$cediterrors[$formpostid]);
...@@ -470,8 +470,3 @@ if ( ...@@ -470,8 +470,3 @@ if (
return $qa_content; return $qa_content;
/*
Omit PHP closing tag to help avoid accidental output
*/
...@@ -51,7 +51,7 @@ if (!empty($inhandle)) { // match based on code and handle provided on URL ...@@ -51,7 +51,7 @@ if (!empty($inhandle)) { // match based on code and handle provided on URL
} }
} }
if ((!$unsubscribed) && isset($loginuserid)) { // as a backup, also unsubscribe logged in user if (!$unsubscribed && isset($loginuserid)) { // as a backup, also unsubscribe logged in user
qa_db_user_set_flag($loginuserid, QA_USER_FLAGS_NO_MAILINGS, true); qa_db_user_set_flag($loginuserid, QA_USER_FLAGS_NO_MAILINGS, true);
$unsubscribed = true; $unsubscribed = true;
} }
......
...@@ -75,7 +75,7 @@ $loginlevel = qa_get_logged_in_level(); ...@@ -75,7 +75,7 @@ $loginlevel = qa_get_logged_in_level();
if (!QA_FINAL_EXTERNAL_USERS) { // if we're using integrated user management, we can know and show more if (!QA_FINAL_EXTERNAL_USERS) { // if we're using integrated user management, we can know and show more
require_once QA_INCLUDE_DIR . 'app/messages.php'; require_once QA_INCLUDE_DIR . 'app/messages.php';
if ((!is_array($userpoints)) && !is_array($useraccount)) if (!is_array($userpoints) && !is_array($useraccount))
return include QA_INCLUDE_DIR . 'qa-page-not-found.php'; return include QA_INCLUDE_DIR . 'qa-page-not-found.php';
$userid = $useraccount['userid']; $userid = $useraccount['userid'];
...@@ -435,7 +435,7 @@ if (!QA_FINAL_EXTERNAL_USERS) { ...@@ -435,7 +435,7 @@ if (!QA_FINAL_EXTERNAL_USERS) {
if (qa_using_categories()) { if (qa_using_categories()) {
$catleveladd = strlen(qa_get('catleveladd')) > 0; $catleveladd = strlen(qa_get('catleveladd')) > 0;
if ((!$catleveladd) && !count($userlevels)) { if (!$catleveladd && !count($userlevels)) {
$qa_content['form_profile']['fields']['level']['suffix'] = strtr(qa_lang_html('users/category_level_add'), array( $qa_content['form_profile']['fields']['level']['suffix'] = strtr(qa_lang_html('users/category_level_add'), array(
'^1' => '<a href="' . qa_path_html(qa_request(), array('state' => 'edit', 'catleveladd' => 1)) . '">', '^1' => '<a href="' . qa_path_html(qa_request(), array('state' => 'edit', 'catleveladd' => 1)) . '">',
'^2' => '</a>', '^2' => '</a>',
......
...@@ -1843,7 +1843,7 @@ function qa_suspend_event_reports($suspend = true) ...@@ -1843,7 +1843,7 @@ function qa_suspend_event_reports($suspend = true)
* @param array $params * @param array $params
* @return mixed|void * @return mixed|void
*/ */
function qa_report_event($event, $userid, $handle, $cookieid, $params=array()) function qa_report_event($event, $userid, $handle, $cookieid, $params = array())
{ {
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
......
...@@ -20,16 +20,17 @@ ...@@ -20,16 +20,17 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
define('QA_BASE_DIR', dirname(dirname(empty($_SERVER['SCRIPT_FILENAME']) ? __FILE__ : $_SERVER['SCRIPT_FILENAME'])).'/'); define('QA_BASE_DIR', dirname(dirname(empty($_SERVER['SCRIPT_FILENAME']) ? __FILE__ : $_SERVER['SCRIPT_FILENAME'])) . '/');
require 'qa-base.php'; require 'qa-base.php';
require_once QA_INCLUDE_DIR.'app/users.php'; require_once QA_INCLUDE_DIR . 'app/users.php';
if (qa_get_logged_in_level() < QA_USER_LEVEL_ADMIN) if (qa_get_logged_in_level() < QA_USER_LEVEL_ADMIN)
qa_redirect('admin/general', null, qa_opt('site_url')); qa_redirect('admin/general', null, qa_opt('site_url'));
header('Content-type: text/html; charset=utf-8'); header('Content-type: text/html; charset=utf-8');
?>
?><!DOCTYPE html>
<html> <html>
<head> <head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/> <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
...@@ -48,123 +49,135 @@ ...@@ -48,123 +49,135 @@
<body> <body>
<?php <?php
function get_phrase_substitutions($phrase) function get_phrase_substitutions($phrase)
{ {
$substitutions=array(); $substitutions = array();
if (preg_match_all('/\^(([0-9]+)|([a-z_]+)|)/', $phrase, $matches)) if (preg_match_all('/\^(([0-9]+)|([a-z_]+)|)/', $phrase, $matches))
foreach ($matches[0] as $match) foreach ($matches[0] as $match) {
@$substitutions[$match]++; @$substitutions[$match]++;
}
return $substitutions; return $substitutions;
} }
echo '<code class="severe">Red = important to review.</code><br>'; echo '<code class="severe">Red = important to review.</code><br>';
echo '<code class="warning">Orange = probably safe to ignore.</code>'; echo '<code class="warning">Orange = probably safe to ignore.</code>';
echo '<h1>Checking US English files in <code>qa-include</code>...</h1>'; echo '<h1>Checking US English files in <code>qa-include</code>...</h1>';
$includefiles=array_merge(glob(QA_INCLUDE_DIR.'qa-*.php'), glob(QA_INCLUDE_DIR.'*/qa-*.php'), glob(QA_PLUGIN_DIR.'*/qa-*.php')); $includefiles = array_merge(glob(QA_INCLUDE_DIR . 'qa-*.php'), glob(QA_INCLUDE_DIR . '*/qa-*.php'), glob(QA_PLUGIN_DIR . '*/qa-*.php'));
$definite=array(); $definite = array();
$probable=array(); $probable = array();
$possible=array(); $possible = array();
$defined=array(); $defined = array();
$english=array(); $english = array();
$backmap=array(); $backmap = array();
$substitutions=array(); $substitutions = array();
output_start_includes(); output_start_includes();
foreach ($includefiles as $includefile) { foreach ($includefiles as $includefile) {
$contents=file_get_contents($includefile); $contents = file_get_contents($includefile);
preg_match_all('/qa_lang[a-z_]*\s*\(\s*[\'\"]([a-z]+)\/([0-9a-z_]+)[\'\"]/', $contents, $matches, PREG_SET_ORDER); preg_match_all('/qa_lang[a-z_]*\s*\(\s*[\'\"]([a-z]+)\/([0-9a-z_]+)[\'\"]/', $contents, $matches, PREG_SET_ORDER);
foreach ($matches as $matchparts) foreach ($matches as $matchparts) {
if ($matchparts[2]=='date_month_') { // special case for month names if ($matchparts[2] == 'date_month_') { // special case for month names
for ($month=1; $month<=12; $month++) for ($month = 1; $month <= 12; $month++) {
@$definite[$matchparts[1]][$matchparts[2].$month]++; @$definite[$matchparts[1]][$matchparts[2] . $month]++;
}
} else } else
@$definite[$matchparts[1]][$matchparts[2]]++; @$definite[$matchparts[1]][$matchparts[2]]++;
}
preg_match_all('/[\'\"]([a-z]+)\/([0-9a-z_]+)[\'\"]/', $contents, $matches, PREG_SET_ORDER); preg_match_all('/[\'\"]([a-z]+)\/([0-9a-z_]+)[\'\"]/', $contents, $matches, PREG_SET_ORDER);
foreach ($matches as $matchparts) foreach ($matches as $matchparts) {
@$probable[$matchparts[1]][$matchparts[2]]++; @$probable[$matchparts[1]][$matchparts[2]]++;
}
if (preg_match('|/qa-include/qa-lang-([a-z]+)\.php$|', $includefile, $matches)) { // it's a lang file if (preg_match('|/qa-include/qa-lang-([a-z]+)\.php$|', $includefile, $matches)) { // it's a lang file
$prefix=$matches[1]; $prefix = $matches[1];
output_reading_include($includefile); output_reading_include($includefile);
$phrases=@include $includefile; $phrases = @include $includefile;
foreach ($phrases as $key => $value) { foreach ($phrases as $key => $value) {
@$defined[$prefix][$key]++; @$defined[$prefix][$key]++;
$english[$prefix][$key]=$value; $english[$prefix][$key] = $value;
$backmap[$value][]=array('prefix' => $prefix, 'key' => $key); $backmap[$value][] = array('prefix' => $prefix, 'key' => $key);
$substitutions[$prefix][$key]=get_phrase_substitutions($value); $substitutions[$prefix][$key] = get_phrase_substitutions($value);
} }
} else { // it's a different file } else { // it's a different file
preg_match_all('/[\'\"\/]([0-9a-z_]+)[\'\"]/', $contents, $matches, PREG_SET_ORDER); preg_match_all('/[\'\"\/]([0-9a-z_]+)[\'\"]/', $contents, $matches, PREG_SET_ORDER);
foreach ($matches as $matchparts) foreach ($matches as $matchparts) {
@$possible[$matchparts[1]]++; @$possible[$matchparts[1]]++;
} }
} }
}
output_finish_includes(); output_finish_includes();
foreach ($definite as $key => $valuecount) foreach ($definite as $key => $valuecount) {
foreach ($valuecount as $value => $count) foreach ($valuecount as $value => $count) {
if (!@$defined[$key][$value]) if (!@$defined[$key][$value])
output_lang_issue($key, $value, 'used by '.$count.' file/s but not defined'); output_lang_issue($key, $value, 'used by ' . $count . ' file/s but not defined');
}
}
foreach ($defined as $key => $valuecount) foreach ($defined as $key => $valuecount) {
foreach ($valuecount as $value => $count) foreach ($valuecount as $value => $count) {
if ( (!@$definite[$key][$value]) && (!@$probable[$key][$value]) && (!@$possible[$value]) ) if (!@$definite[$key][$value] && !@$probable[$key][$value] && !@$possible[$value])
output_lang_issue($key, $value, 'defined but apparently not used'); output_lang_issue($key, $value, 'defined but apparently not used');
}
}
foreach ($backmap as $phrase => $where) foreach ($backmap as $phrase => $where) {
if (count($where)>1) if (count($where) > 1)
foreach ($where as $onewhere) foreach ($where as $onewhere) {
output_lang_issue($onewhere['prefix'], $onewhere['key'], 'contains the shared phrase "'.$phrase.'"', false); output_lang_issue($onewhere['prefix'], $onewhere['key'], 'contains the shared phrase "' . $phrase . '"', false);
}
}
require_once QA_INCLUDE_DIR.'app/admin.php'; require_once QA_INCLUDE_DIR . 'app/admin.php';
$languages=qa_admin_language_options(); $languages = qa_admin_language_options();
unset($languages['']); unset($languages['']);
foreach ($languages as $code => $language) { foreach ($languages as $code => $language) {
echo '<h1>Checking '.$language.' files in <code>qa-lang/'.$code.'</code>...</h1>'; echo '<h1>Checking ' . $language . ' files in <code>qa-lang/' . $code . '</code>...</h1>';
$langdefined=array(); $langdefined = array();
$langdifferent=array(); $langdifferent = array();
$langsubstitutions=array(); $langsubstitutions = array();
$langincludefiles=glob(QA_LANG_DIR.$code.'/qa-*.php'); $langincludefiles = glob(QA_LANG_DIR . $code . '/qa-*.php');
$langnewphrases=array(); $langnewphrases = array();
output_start_includes(); output_start_includes();
foreach ($langincludefiles as $langincludefile) foreach ($langincludefiles as $langincludefile) {
if (preg_match('/qa-lang-([a-z]+)\.php$/', $langincludefile, $matches)) { // it's a lang file if (preg_match('/qa-lang-([a-z]+)\.php$/', $langincludefile, $matches)) { // it's a lang file
$prefix=$matches[1]; $prefix = $matches[1];
output_reading_include($langincludefile); output_reading_include($langincludefile);
$phrases=@include $langincludefile; $phrases = @include $langincludefile;
foreach ($phrases as $key => $value) { foreach ($phrases as $key => $value) {
@$langdefined[$prefix][$key]++; @$langdefined[$prefix][$key]++;
$langdifferent[$prefix][$key]=($value!=@$english[$prefix][$key]); $langdifferent[$prefix][$key] = ($value != @$english[$prefix][$key]);
$langsubstitutions[$prefix][$key]=get_phrase_substitutions($value); $langsubstitutions[$prefix][$key] = get_phrase_substitutions($value);
}
} }
} }
output_finish_includes(); output_finish_includes();
foreach ($langdefined as $key => $valuecount) foreach ($langdefined as $key => $valuecount) {
foreach ($valuecount as $value => $count) { foreach ($valuecount as $value => $count) {
if (!@$defined[$key][$value]) if (!@$defined[$key][$value])
output_lang_issue($key, $value, 'defined but not in US English files'); output_lang_issue($key, $value, 'defined but not in US English files');
...@@ -173,47 +186,51 @@ ...@@ -173,47 +186,51 @@
output_lang_issue($key, $value, 'identical to US English files', false); output_lang_issue($key, $value, 'identical to US English files', false);
else else
foreach ($substitutions[$key][$value] as $substitution => $subcount) foreach ($substitutions[$key][$value] as $substitution => $subcount) {
if (!@$langsubstitutions[$key][$value][$substitution]) if (!@$langsubstitutions[$key][$value][$substitution])
output_lang_issue($key, $value, 'omitted the substitution '.$substitution); output_lang_issue($key, $value, 'omitted the substitution ' . $substitution);
elseif ($subcount > @$langsubstitutions[$key][$value][$substitution]) elseif ($subcount > @$langsubstitutions[$key][$value][$substitution])
output_lang_issue($key, $value, 'has fewer of the substitution '.$substitution); output_lang_issue($key, $value, 'has fewer of the substitution ' . $substitution);
}
}
} }
foreach ($defined as $key => $valuecount) { foreach ($defined as $key => $valuecount) {
$showaserror=!(($key=='admin') || ($key=='options') || ($code=='en-GB')); $showaserror = !(($key == 'admin') || ($key == 'options') || ($code == 'en-GB'));
if (@$langdefined[$key]) { if (@$langdefined[$key]) {
if (count($langdefined[$key]) < (count($valuecount)/2)) { // only a few phrases defined if (count($langdefined[$key]) < (count($valuecount) / 2)) { // only a few phrases defined
output_lang_issue($key, null, 'few translations provided so will use US English defaults', $showaserror); output_lang_issue($key, null, 'few translations provided so will use US English defaults', $showaserror);
} else } else
foreach ($valuecount as $value => $count) foreach ($valuecount as $value => $count) {
if (!@$langdefined[$key][$value]) { if (!@$langdefined[$key][$value]) {
output_lang_issue($key, $value, 'undefined so will use US English defaults', $showaserror); output_lang_issue($key, $value, 'undefined so will use US English defaults', $showaserror);
$langnewphrases[$key][$value]=$english[$key][$value]; $langnewphrases[$key][$value] = $english[$key][$value];
}
} }
} else } else
output_lang_issue($key, null, 'no translations provided so will use US English defaults', $showaserror); output_lang_issue($key, null, 'no translations provided so will use US English defaults', $showaserror);
} }
foreach ($langnewphrases as $prefix => $phrases) { foreach ($langnewphrases as $prefix => $phrases) {
echo '<h2>'.$language.' phrases to add to <code>qa-lang/'.$code.'/qa-lang-'.$prefix.'.php</code>:</h2>'; echo '<h2>' . $language . ' phrases to add to <code>qa-lang/' . $code . '/qa-lang-' . $prefix . '.php</code>:</h2>';
echo 'Copy and paste this into the middle of <code>qa-lang/'.$code.'/qa-lang-'.$prefix.'.php</code> then translate the right-hand side after the <code>=></code> symbol.'; echo 'Copy and paste this into the middle of <code>qa-lang/' . $code . '/qa-lang-' . $prefix . '.php</code> then translate the right-hand side after the <code>=></code> symbol.';
echo '<pre>'; echo '<pre>';
foreach ($phrases as $key => $value) foreach ($phrases as $key => $value) {
echo '<span style="font-size:25%;">'."\t\t</span>'".$key."' => \"".strtr($value, array('\\' => '\\\\', '"' => '\"', '$' => '\$', "\n" => '\n', "\t" => '\t'))."\",\n"; echo '<span style="font-size:25%;">' . "\t\t</span>'" . $key . "' => \"" . strtr($value, array('\\' => '\\\\', '"' => '\"', '$' => '\$', "\n" => '\n', "\t" => '\t')) . "\",\n";
}
echo '</pre>'; echo '</pre>';
} }
} }
function output_lang_issue($prefix, $key, $issue, $error=true) function output_lang_issue($prefix, $key, $issue, $error = true)
{ {
$colorClass = $error ? 'severe' : 'warning'; $colorClass = $error ? 'severe' : 'warning';
$htmlKey = strlen($key) > 0 ? "'<strong>" . qa_html($key) . "</strong>'" : ''; $htmlKey = strlen($key) > 0 ? "'<strong>" . qa_html($key) . "</strong>'" : '';
...@@ -222,37 +239,37 @@ ...@@ -222,37 +239,37 @@
'<code class="%s">qa-lang-<strong>%s</strong>.php:%s</code> &nbsp; %s<br>', '<code class="%s">qa-lang-<strong>%s</strong>.php:%s</code> &nbsp; %s<br>',
$colorClass, qa_html($prefix), $htmlKey, qa_html($issue) $colorClass, qa_html($prefix), $htmlKey, qa_html($issue)
); );
} }
function output_start_includes() function output_start_includes()
{ {
global $oneread; global $oneread;
$oneread=false; $oneread = false;
echo '<p class="includes">Reading: '; echo '<p class="includes">Reading: ';
} }
function output_reading_include($file) function output_reading_include($file)
{ {
global $oneread; global $oneread;
echo ($oneread ? ', ' : '').htmlspecialchars(basename($file)); echo ($oneread ? ', ' : '') . htmlspecialchars(basename($file));
flush(); flush();
$oneread=true; $oneread = true;
} }
function output_finish_includes() function output_finish_includes()
{ {
echo '</p>'; echo '</p>';
} }
echo '<h1>Finished scanning for problems!</h1>'; echo '<h1>Finished scanning for problems!</h1>';
?> ?>
......
...@@ -40,7 +40,7 @@ if (!function_exists('qa_install_db_fail_handler')) { ...@@ -40,7 +40,7 @@ if (!function_exists('qa_install_db_fail_handler')) {
* @param string $error * @param string $error
* @param string $query * @param string $query
*/ */
function qa_install_db_fail_handler($type, $errno=null, $error=null, $query=null) function qa_install_db_fail_handler($type, $errno = null, $error = null, $query = null)
{ {
global $pass_failure_from_install; global $pass_failure_from_install;
......
...@@ -244,10 +244,10 @@ class qa_html_theme_base ...@@ -244,10 +244,10 @@ class qa_html_theme_base
} }
// From here on, we have a large number of class methods which output particular pieces of HTML markup // From here on, we have a large number of class methods which output particular pieces of HTML markup
// The calling chain is initiated from qa-page.php, or qa-ajax-*.php for refreshing parts of a page, // The calling chain is initiated from qa-page.php, or qa-ajax-*.php for refreshing parts of a page,
// For most HTML elements, the name of the function is similar to the element's CSS class, for example: // For most HTML elements, the name of the function is similar to the element's CSS class, for example:
// search() outputs <div class="qa-search">, q_list() outputs <div class="qa-q-list">, etc... // search() outputs <div class="qa-search">, q_list() outputs <div class="qa-q-list">, etc...
public function doctype() public function doctype()
{ {
......
...@@ -127,7 +127,7 @@ function qa_image_constrain(&$width, &$height, $maxwidth, $maxheight = null) ...@@ -127,7 +127,7 @@ function qa_image_constrain(&$width, &$height, $maxwidth, $maxheight = null)
if (!isset($maxheight)) if (!isset($maxheight))
$maxheight = $maxwidth; $maxheight = $maxwidth;
if (($width > $maxwidth) || ($height > $maxheight)) { if ($width > $maxwidth || $height > $maxheight) {
$multiplier = min($maxwidth / $width, $maxheight / $height); $multiplier = min($maxwidth / $width, $maxheight / $height);
$width = floor($width * $multiplier); $width = floor($width * $multiplier);
$height = floor($height * $multiplier); $height = floor($height * $multiplier);
......
...@@ -52,7 +52,7 @@ class qa_facebook_login ...@@ -52,7 +52,7 @@ class qa_facebook_login
public function facebook_html($tourl, $logout, $context) public function facebook_html($tourl, $logout, $context)
{ {
if (($context == 'login') || ($context == 'register')) if ($context == 'login' || $context == 'register')
$size = 'large'; $size = 'large';
else else
$size = 'medium'; $size = 'medium';
......
...@@ -173,7 +173,7 @@ class qa_xml_sitemap ...@@ -173,7 +173,7 @@ class qa_xml_sitemap
// User pages // User pages
if ((!QA_FINAL_EXTERNAL_USERS) && qa_opt('xml_sitemap_show_users')) { if (!QA_FINAL_EXTERNAL_USERS && qa_opt('xml_sitemap_show_users')) {
$nextuserid = 0; $nextuserid = 0;
while (1) { while (1) {
......
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