Skip to content
Permalink
Browse files

Fixed that CQC was not properly enforcing bracing style guideline

  • Loading branch information...
chrisgraham committed Jul 24, 2019
1 parent 2f10fa9 commit da37ff6d05b258703ff01933d1c23b4c8e54f20b
@@ -455,8 +455,21 @@ function lex($text = null)
log_warning('Missing surrounding spacing (for ' . $token_found . ') against coding standards', $i, true);
}
}
if (($TEXT[$i] != ' ') && ($TEXT[$i] != "\n") && ($TEXT[$i] != "\r") && (in_array($token_found, array('IF', 'ELSEIF', 'FOREACH', 'FOR', 'WHILE', 'DO')))) {
log_warning('Missing following spacing (for ' . $token_found . ') against coding standards', $i, true);
if (in_array($token_found, array('IF', 'ELSE', 'ELSEIF', 'FOREACH', 'FOR', 'FOREACH', 'WHILE', 'DO', 'TRY', 'CATCH', 'SWITCH', 'INTERFACE', 'CLASS', 'FUNCTION'))) {
$line_end = strpos($TEXT, "\n", $i);
if ($line_end !== false) {
$remaining_line = str_replace("\r", '', substr($TEXT, $i, $line_end - $i + 1));
$next_line_end = strpos($TEXT, "\n", $line_end + 1);
$next_line = ($next_line_end === false) ? '' : substr($TEXT, $line_end + 1, $next_line_end - $line_end - 1 + 1);
if ((strpos($remaining_line, ' {') === false) && (strpos($remaining_line, '/*') === false) && (($token_found != 'WHILE') || (substr($remaining_line, -2) != ";\n")) && (strpos($next_line, '{') !== false/*brace should move to own line for multi-line boolean checks*/) && (in_array($token_found, array('IF', 'ELSE', 'ELSEIF', 'FOREACH', 'FOR', 'FOREACH', 'WHILE', 'DO', 'TRY', 'CATCH', 'SWITCH')))) {
log_warning('Incorrect bracing spacing (for ' . $token_found . ') against coding standards', $i, true);
}
if ((strpos($remaining_line, ' {') !== false) && (strpos($next_line, '{') === false/*To weed out edge cases like when a parameter default contains ' {'*/) && (in_array($token_found, array('INTERFACE', 'CLASS', 'FUNCTION')))) {
log_warning('Incorrect bracing spacing (for ' . $token_found . ') against coding standards', $i, true);
}
}
}
if (($i_current > 0) && (($TEXT[$i_current - 1] != ' ') || (($TEXT[$i] != ' ') && ($TEXT[$i] != "\n") && ($TEXT[$i] != "\r"))) && (in_array($token_found, array('BOOLEAN_AND', 'BOOLEAN_XOR', 'BOOLEAN_OR', 'BOOLEAN_OR_2')))) {
log_warning('Missing surrounding spacing (for ' . $token_found . ') against coding standards', $i, true);
@@ -308,20 +308,16 @@ public function actual()
}
}
$_unbannable = explode("\n", $unbannable);
foreach ($_unbannable as $str)
{
foreach ($_unbannable as $str) {
if (trim($str) == '') {
continue;
}
preg_match('#^([^\s]+)(.*)$#', $str, $matches);
$ip = $matches[1];
if (preg_match('#^[a-f0-9\.]+$#U', $ip) == 0)
{
if (preg_match('#^[a-f0-9\.]+$#U', $ip) == 0) {
attach_message(do_lang_tempcode('IP_ADDRESS_NOT_VALID_MAKE_UNBANNABLE', escape_html($str)), 'warn');
} else
{
if (!in_array($ip, $unbannable_already))
{
} else {
if (!in_array($ip, $unbannable_already)) {
$GLOBALS['SITE_DB']->query_insert('unbannable_ip', array(
'ip' => $ip,
'note' => isset($matches[2]) ? $matches[2] : '',
@@ -146,8 +146,7 @@ public function run()
if (addon_installed('securitylogging')) {
$all_banned = collapse_1d_complexity('ip', $GLOBALS['SITE_DB']->query('SELECT ip FROM ' . get_table_prefix() . 'banned_ip WHERE i_ban_positive=1 AND (i_ban_until IS NULL OR i_ban_until>' . strval(time()) . ')'));
} else
{
} else {
$all_banned = array();
}
@@ -1241,8 +1241,7 @@ public function generate_page_sitemap()
// Sort zones
uasort($zones, 'strnatcasecmp');
if (isset($zones[''])) // Move welcome zone to start of list
{
if (isset($zones[''])) { // Move welcome zone to start of list
$zones = array_merge(array('' => $zones['']), $zones);
}

Large diffs are not rendered by default.

@@ -624,28 +624,24 @@ public function view_calendar()
// Nofollow stuff
$previous_no_follow = ($previous_timestamp < time() - 60 * 60 * 24 * 31);
$test = $GLOBALS['SITE_DB']->query_value_if_there('SELECT id FROM ' . get_table_prefix() . 'calendar_events WHERE e_start_year=' . date('Y', $next_timestamp) . ' AND e_start_month<=' . date('m', $next_timestamp) . ' OR e_start_year<' . date('Y', $next_timestamp));
if (!is_null($test)) // if there really are events before, this takes priority
{
if (!is_null($test)) { // if there really are events before, this takes priority
$previous_no_follow = false;
}
$next_no_follow = ($next_timestamp > time() + 60 * 60 * 24 * 31 * 6/*So can see 6 months of recurrences/empty space*/);
$test = $GLOBALS['SITE_DB']->query_value_if_there('SELECT id FROM ' . get_table_prefix() . 'calendar_events WHERE e_start_year=' . date('Y', $next_timestamp) . ' AND e_start_month>=' . date('m', $next_timestamp) . ' OR e_start_year>' . date('Y', $next_timestamp));
if (!is_null($test)) // if there really are events after, this takes priority
{
if (!is_null($test)) { // if there really are events after, this takes priority
$next_no_follow = false;
}
if (/*get_bot_type()!==null Actually we can't rely on bot detection, so let's just tie to guest && */is_guest()) {
// Some bots ignore nofollow, so let's be more forceful
$past_no_follow = ($timestamp < time() - 60 * 60 * 24 * 31);
$test = $GLOBALS['SITE_DB']->query_value_if_there('SELECT id FROM ' . get_table_prefix() . 'calendar_events WHERE e_start_year=' . date('Y', $timestamp) . ' AND e_start_month<=' . date('m', $timestamp) . ' OR e_start_year<' . date('Y', $timestamp));
if (!is_null($test)) // if there really are events before, this takes priority
{
if (!is_null($test)) { // if there really are events before, this takes priority
$past_no_follow = false;
}
$future_no_follow = ($timestamp > time() + 60 * 60 * 24 * 31 * 6/*So can see 6 months of recurrences/empty space*/);
$test = $GLOBALS['SITE_DB']->query_value_if_there('SELECT id FROM ' . get_table_prefix() . 'calendar_events WHERE e_start_year=' . date('Y', $timestamp) . ' AND e_start_month>=' . date('m', $timestamp) . ' OR e_start_year>' . date('Y', $timestamp));
if (!is_null($test)) // if there really are events after, this takes priority
{
if (!is_null($test)) { // if there really are events after, this takes priority
$future_no_follow = false;
}
if ($past_no_follow || $future_no_follow) {
@@ -531,8 +531,7 @@ function actual_add_catalogue_category($catalogue_name, $title, $description, $n
$order = $GLOBALS['SITE_DB']->query_select_value('catalogue_categories', 'MAX(cc_order)', array('c_name' => $catalogue_name));
if ((is_null($order)) || ($order >= 2147483647)) {
$order = 0;
} else
{
} else {
$order++;
}
}
@@ -191,8 +191,7 @@ function cns_make_member($username, $password, $email_address, $secondary_groups
}
}
if ((get_option('one_per_email_address') != '0') && ($email_address != ''))
{
if ((get_option('one_per_email_address') != '0') && ($email_address != '')) {
$test = $GLOBALS['FORUM_DB']->query_select_value_if_there('f_members', 'id', array('m_email_address' => $email_address));
if (!is_null($test)) {
warn_exit(do_lang_tempcode('_EMAIL_ADDRESS_IN_USE'));
@@ -880,8 +880,7 @@ function cns_edit_member($member_id, $email_address, $preview_posts, $dob_day, $
warn_exit(do_lang_tempcode('_INVALID_EMAIL_ADDRESS', escape_html($email_address)));
}
if ((get_option('one_per_email_address') != '0') && ($email_address != '') && ($email_address != $old_email_address) && ($email_address != STRING_MAGIC_NULL))
{
if ((get_option('one_per_email_address') != '0') && ($email_address != '') && ($email_address != $old_email_address) && ($email_address != STRING_MAGIC_NULL)) {
$test = $GLOBALS['FORUM_DB']->query_select_value_if_there('f_members', 'id', array('m_email_address' => $email_address));
if ((!is_null($test)) && ($test != $member_id)) {
warn_exit(do_lang_tempcode('_EMAIL_ADDRESS_IN_USE'));
@@ -672,8 +672,7 @@ function semihtml_to_comcode($semihtml, $force = false, $quick = false)
$semihtml = cms_preg_replace_safe('#(\s)\s*#', '${1}', $semihtml);
// Clean redundant CSS syntax
do
{
do {
$old = $semihtml;
$semihtml = preg_replace('# style="([^"]*); ?; ?+[^"]*#', ' style="$1;', $semihtml);
}
@@ -921,8 +920,7 @@ function semihtml_to_comcode($semihtml, $force = false, $quick = false)
$semihtml = comcode_preg_replace('center', '#^\[center\]\[right\](.*)\[/right\]\[/center\]$#si', '[center]${1}[/center]', $semihtml);
// Clean redundant CSS syntax (again)
do
{
do {
$old = $semihtml;
$semihtml = preg_replace('# style="([^"]*); ?; ?+[^"]*#', ' style="$1;', $semihtml);
}
@@ -1200,8 +1198,7 @@ function array_html_preg_replace($element, $array, $semihtml)
break;
}
if ($pos == 0) // First iteration is just to find first opener
{
if ($pos == 0) { // First iteration is just to find first opener
$pos = $pos_opener + 1;
continue;
}
@@ -45,8 +45,7 @@ function deep_clean($d, $heading = '')
}
}
}
if ($nesting_tally == 0) // Tags do balance, so it closed right at the end
{
if ($nesting_tally == 0) { // Tags do balance, so it closed right at the end
$d = cms_preg_replace_safe('#^\s*<div[^<>]*>#', '', $d);
$d = cms_preg_replace_safe('#</div>\s*$#s', '', $d);
} else {
@@ -162,22 +161,19 @@ function column_cleanup(&$text)
$temp_text = strip_tags($text, '<br>');
$temp_text = html_entity_decode($temp_text, ENT_QUOTES, get_charset());
$lines = explode('<br />', $temp_text);
if (count($lines) > 5) // Statistically significant
{
if (count($lines) > 5) { // Statistically significant
$lengths = array();
foreach ($lines as $line) {
$lengths[] = strlen($line);
}
$mean_length = (int)(array_sum($lengths) / count($lengths));
if ($mean_length > 5) // Statistically significant
{
if ($mean_length > 5) { // Statistically significant
$dist = 0;
foreach ($lines as $line) {
$dist += abs(strlen($line) - $mean_length);
}
$sd = ((float)$dist) / ((float)count($lines));
if ($sd < 0.6 * (float)$mean_length) // Standard deviation within 60%
{
if ($sd < 0.6 * (float)$mean_length) { // Standard deviation within 60%
$sentence_ends = array('!', '?', '.', '>');
$lines = explode('<br />', $text);
@@ -784,8 +784,7 @@ function create_data_mash($url, $data = null, $extension = null, $direct_path =
$next_ok = _is_valid_data_mash_char($ch);
if (($next_ok) && (!$in_portion)) {
$x = $ch;
for ($j = $i + 1; $j < strlen($data); $j++) // Count how far a new word goes
{
for ($j = $i + 1; $j < strlen($data); $j++) { // Count how far a new word goes
$_ch = $data[$j];
$_next_ok = _is_valid_data_mash_char($_ch);
if ($_next_ok) {
@@ -795,8 +794,7 @@ function create_data_mash($url, $data = null, $extension = null, $direct_path =
break;
}
}
if ((strlen($x) < $min_length) || ($x == strtoupper($x)) || ($x == 'Microsoft Word Document') || ($x == 'WordDocument') || ($x == 'SummaryInformation') || ($x == 'DocumentSummaryInformation')) // Valid word okay
{
if ((strlen($x) < $min_length) || ($x == strtoupper($x)) || ($x == 'Microsoft Word Document') || ($x == 'WordDocument') || ($x == 'SummaryInformation') || ($x == 'DocumentSummaryInformation')) { // Valid word okay
$i = $j;
continue;
}
@@ -43,8 +43,7 @@ function endpoint_script()
require_code('failure');
set_throw_errors(true);
try
{
try {
// Restful
if (!empty($_SERVER['PATH_INFO'])) {
// What response type is desired
@@ -183,8 +183,7 @@ function catalogue_file_script()
if ($size == $new_length) {
cms_ob_end_clean();
fpassthru($myfile);
} else
{
} else {
$i = 0;
flush(); // LEGACY Works around weird PHP bug that sends data before headers, on some PHP versions
while ($i < $new_length) {
@@ -980,8 +980,7 @@ function cms_mb_substr($in, $from, $amount = null, $force = false)
$amount = cms_mb_strlen($in, $force) - $from;
}
if ($in == '' || strlen($in) == $from)
{
if ($in == '' || strlen($in) == $from) {
return ''; // Workaround PHP bug/inconsistency (https://bugs.php.net/bug.php?id=72320)
}
@@ -37,8 +37,7 @@ public function run()
$test_url = get_custom_base_url() . '/data/empty.php';
$test_a = http_download_file($test_url, 0, false, true);
$message_a = $GLOBALS['HTTP_MESSAGE'];
if ($message_a == '200')
{
if ($message_a == '200') {
$test_b = http_download_file($test_url, 0, false, true, 'Composr', array('test_a' => '/usr/bin/unzip -o @_SRC_@ -x -d @_DST_@', 'test_b' => '<iframe src="http://example.com/"></iframe>', 'test_c' => '<script>console.log(document.cookie);</script>'));
$message_b = $GLOBALS['HTTP_MESSAGE'];
if ($message_b != '200') {
@@ -67,8 +67,7 @@ public function run($options, $parameters, &$commandr_fs)
if (addon_installed('securitylogging')) {
$all_banned = collapse_1d_complexity('ip', $GLOBALS['SITE_DB']->query('SELECT ip FROM ' . get_table_prefix() . 'banned_ip WHERE i_ban_positive=1 AND (i_ban_until IS NULL OR i_ban_until>' . strval(time()) . ')'));
} else
{
} else {
$all_banned = array();
}
@@ -71,11 +71,9 @@ public function run()
if ($_message != '') {
$_message .= "\n";
}
if (strlen($_message) + strlen($message['d_message']) < MAXIMUM_DIGEST_LENGTH)
{
if (strlen($_message) + strlen($message['d_message']) < MAXIMUM_DIGEST_LENGTH) {
$_message .= do_lang('DIGEST_EMAIL_INDIVIDUAL_MESSAGE_WRAP', comcode_escape($message['d_subject']), get_translated_text($message['d_message']), array(comcode_escape(get_site_name()), get_timezoned_date($message['d_date_and_time'])));
} else
{
} else {
$_message .= do_lang('DIGEST_ITEM_OMITTED', comcode_escape($message['d_subject']), get_timezoned_date($message['d_date_and_time']), array(comcode_escape(get_site_name())));
}
}
@@ -267,8 +267,7 @@ public function get_field_inputter($_cf_name, $_cf_description, $field, $actual_
$input_size = max(1, intval(option_value_from_field_array($field, 'input_size', '5')));
switch ($widget)
{
switch ($widget) {
case 'vertical_checkboxes':
case 'horizontal_checkboxes':
$_list = array();
@@ -307,8 +306,7 @@ public function inputted_to_field_value($editing, $field, $upload_dir = 'uploads
}
$widget = option_value_from_field_array($field, 'widget', 'multilist');
switch ($widget)
{
switch ($widget) {
case 'vertical_checkboxes':
case 'horizontal_checkboxes':
$i = 0;
@@ -221,8 +221,7 @@ function is_animated_image($c, $ext)
if ($ext == 'gif') {
$str_loc = 0;
$count = 0;
while ($count < 2) // There is no point in continuing after we find a 2nd frame
{
while ($count < 2) { // There is no point in continuing after we find a 2nd frame
$where1 = strpos($c, "\x00\x21\xF9\x04", $str_loc);
if ($where1 === false) {
break;
@@ -97,8 +97,7 @@ function check_input_field_string($name, &$val, $posted = false)
if (!$GLOBALS['BOOTSTRAPPING']) {
// Quickly depose of common spam attacks. Not really security, just a sensible barrier
if (((!function_exists('is_guest')) || (is_guest())) && ((strpos($val, '[url=http://') !== false) || (strpos($val, '[link') !== false)) && (strpos($val, '<a ') !== false)) // Combination of non-Composr-supporting bbcode and HTML, almost certainly a bot trying too hard to get link through
{
if (((!function_exists('is_guest')) || (is_guest())) && ((strpos($val, '[url=http://') !== false) || (strpos($val, '[link') !== false)) && (strpos($val, '<a ') !== false)) { // Combination of non-Composr-supporting bbcode and HTML, almost certainly a bot trying too hard to get link through
log_hack_attack_and_exit('LAME_SPAM_HACK', $val);
}
@@ -405,8 +405,7 @@ public function run_time($key, $value, $flag, $parameters)
$specific_plural = $specific . 's';
}
switch ($type)
{
switch ($type) {
case 'resource':
$reps = array(
'a resource' => $article_word . ' ' . $specific,
@@ -24,16 +24,16 @@
*
* @param ?MEMBER $member_id Member ID to do for (null: all)
*/
function autofill_geo_cpfs($member_id = null) {
function autofill_geo_cpfs($member_id = null)
{
$where = mixed();
if (!is_null($member_id)) {
$where['mf_member_id'] = $member_id;
}
$start = 0;
$max = 100;
do
{
do {
$rows = $GLOBALS['FORUM_DB']->query_select('f_member_custom_fields f JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members m ON m.id=f.mf_member_id', array('f.*', 'm.id', 'm_ip_address'), $where, 'ORDER BY mf_member_id', $max, $start);
foreach ($rows as $row) {
_autofill_geo_cpfs($row);
@@ -50,7 +50,8 @@ function autofill_geo_cpfs($member_id = null) {
*
* @ignore
*/
function _autofill_geo_cpfs($row) {
function _autofill_geo_cpfs($row)
{
require_code('cns_members');
require_code('locations');
require_code('locations_geocoding');
@@ -501,8 +501,7 @@ function sitemap_script_saving()
$changed_privileges = false;
// Read it all in
foreach ($map as $i => $page_link) // For everything we're setting at once
{
foreach ($map as $i => $page_link) { // For everything we're setting at once
$is_root = (($page_link == ((get_option('collapse_user_zones') == '0') ? ':' : '')));
// Decode page link

0 comments on commit da37ff6

Please sign in to comment.
You can’t perform that action at this time.