From f438dcabae18ad965dfff6b2a155ac8f7c11029c Mon Sep 17 00:00:00 2001 From: Spuds Date: Wed, 25 Jan 2012 09:26:41 -0600 Subject: [PATCH] ! Change @ini_get to ini_get. It never returns an error. ! @version_compare() never returns an error... neither does version_compare() ! Change version_compare() == # to the nicer, more readable format of version_compare(,,'') ! Changed some substr() == string to strpos() === # ! Substr is slower than other methods such as strpos and indexs (Many PHP Files) ! [WIP 4176] --- SSI.php | 6 ++-- Sources/Admin.php | 2 +- Sources/Class-Package.php | 20 +++++------ Sources/DbPackages-mysql.php | 4 +-- Sources/Display.php | 6 ++-- Sources/DumpDatabase.php | 2 +- Sources/Help.php | 2 +- Sources/Load.php | 12 +++---- Sources/LogInOut.php | 2 +- Sources/Logging.php | 2 +- Sources/ManageErrors.php | 4 +-- Sources/ManageLanguages.php | 4 +-- Sources/ManageMaintenance.php | 4 +-- Sources/ManageNews.php | 2 +- Sources/ManageSettings.php | 2 +- Sources/ManageSmileys.php | 6 ++-- Sources/Memberlist.php | 2 +- Sources/Modlog.php | 2 +- Sources/News.php | 4 +-- Sources/PackageGet.php | 4 +-- Sources/Packages.php | 2 +- Sources/PersonalMessage.php | 4 +-- Sources/Profile-Modify.php | 4 +-- Sources/QueryString.php | 12 +++---- Sources/Register.php | 2 +- Sources/Reports.php | 4 +-- Sources/ScheduledTasks.php | 2 +- Sources/Session.php | 10 +++--- Sources/Subs-Admin.php | 6 ++-- Sources/Subs-Auth.php | 4 +-- Sources/Subs-Db-mysql.php | 2 +- Sources/Subs-Db-postgresql.php | 2 +- Sources/Subs-Db-sqlite.php | 2 +- Sources/Subs-Editor.php | 2 +- Sources/Subs-Graphics.php | 2 +- Sources/Subs-Membergroups.php | 2 +- Sources/Subs-Members.php | 2 +- Sources/Subs-OpenID.php | 2 +- Sources/Subs-Package.php | 14 ++++---- Sources/Subs-Post.php | 8 ++--- Sources/Subs.php | 44 +++++++++++------------ Sources/Subscriptions-PayPal.php | 2 +- Sources/Themes.php | 12 +++---- Sources/ViewQuery.php | 2 +- Themes/default/Admin.template.php | 2 +- Themes/default/languages/Help.english.php | 2 +- index.php | 4 +-- 47 files changed, 124 insertions(+), 124 deletions(-) diff --git a/SSI.php b/SSI.php index 85d029769a..5f938260db 100644 --- a/SSI.php +++ b/SSI.php @@ -55,7 +55,7 @@ die($mmessage); // Fix for using the current directory as a path. -if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') +if (strpos($sourcedir, '.') === 0 && strpos($sourcedir, '.') !== 1) $sourcedir = dirname(__FILE__) . substr($sourcedir, 1); // Load the important includes. @@ -68,7 +68,7 @@ require_once($sourcedir . '/Security.php'); // Using an pre-PHP 5.1 version? -if (@version_compare(PHP_VERSION, '5.1') == -1) +if (version_compare(PHP_VERSION, '5.1', '<')) require_once($sourcedir . '/Subs-Compat.php'); // Create a variable to store some SMF specific functions in. @@ -102,7 +102,7 @@ define('WIRELESS', false); // Gzip output? (because it must be boolean and true, this can't be hacked.) -if (isset($ssi_gzip) && $ssi_gzip === true && @ini_get('zlib.output_compression') != '1' && @ini_get('output_handler') != 'ob_gzhandler' && @version_compare(PHP_VERSION, '4.2.0') != -1) +if (isset($ssi_gzip) && $ssi_gzip === true && ini_get('zlib.output_compression') != '1' && ini_get('output_handler') != 'ob_gzhandler' && version_compare(PHP_VERSION, '4.2.0', '>=')) ob_start('ob_gzhandler'); else $modSettings['enableCompressedOutput'] = '0'; diff --git a/Sources/Admin.php b/Sources/Admin.php index 390f2b70ca..5d5164ef24 100644 --- a/Sources/Admin.php +++ b/Sources/Admin.php @@ -828,7 +828,7 @@ function AdminSearchInternal() $name = preg_replace('~<(?:div|span)\sclass="smalltext">.+?~', '', $name); $context['search_results'][] = array( - 'url' => (substr($item[1], 0, 4) == 'area' ? $scripturl . '?action=admin;' . $item[1] : $item[1]) . ';' . $context['session_var'] . '=' . $context['session_id'] . ((substr($item[1], 0, 4) == 'area' && $section == 'settings' ? '#' . $item[0][0] : '')), + 'url' => (strpos($item[1], 'area') === 0 ? $scripturl . '?action=admin;' . $item[1] : $item[1]) . ';' . $context['session_var'] . '=' . $context['session_id'] . ((strpos($item[1], 'area') === 0 && $section == 'settings' ? '#' . $item[0][0] : '')), 'name' => $name, 'type' => $section, 'help' => shorten_subject(isset($item[2]) ? strip_tags($helptxt[$item2]) : (isset($helptxt[$found]) ? strip_tags($helptxt[$found]) : ''), 255), diff --git a/Sources/Class-Package.php b/Sources/Class-Package.php index 214058500a..73651c6647 100644 --- a/Sources/Class-Package.php +++ b/Sources/Class-Package.php @@ -138,7 +138,7 @@ public function path($path, $return_full = false) $el = substr($el, 0, strpos($el, '[')); } // Find an attribute. - elseif (substr($el, 0, 1) == '@') + elseif (strpos($el, '@') === 0) { // It simplifies things if the attribute is already there ;). if (isset($array[$el])) @@ -205,7 +205,7 @@ public function exists($path) $el = substr($el, 0, strpos($el, '[')); } // Find an attribute. - elseif (substr($el, 0, 1) == '@') + elseif (strpos($el, '@') === 0) return isset($array[$el]); else $lvl = null; @@ -506,7 +506,7 @@ protected function _xml($array, $indent) // Run through and recurively output all the elements or attrbutes inside this. foreach ($array as $k => $v) { - if (substr($k, 0, 1) == '@') + if (strpos($k, '@') === 0) $output .= ' ' . substr($k, 1) . '="' . $v . '"'; elseif (is_array($v)) { @@ -716,11 +716,11 @@ public function __construct($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous' public function connect($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = 'ftpclient@simplemachines.org') { - if (substr($ftp_server, 0, 6) == 'ftp://') + if (strpos($ftp_server, 'ftp://') === 0) $ftp_server = substr($ftp_server, 6); - elseif (substr($ftp_server, 0, 7) == 'ftps://') + elseif (strpos($ftp_server, 'ftps://') === 0) $ftp_server = 'ssl://' . substr($ftp_server, 7); - if (substr($ftp_server, 0, 7) == 'http://') + if (strpos($ftp_server, 'http://') === 0) $ftp_server = substr($ftp_server, 7); $ftp_server = strtr($ftp_server, array('/' => '', ':' => '', '@' => '')); @@ -823,7 +823,7 @@ public function check_response($desired) $time = time(); do $this->last_message = fgets($this->connection, 1024); - while ((strlen($this->last_message) < 4 || substr($this->last_message, 0, 1) == ' ' || substr($this->last_message, 3, 1) != ' ') && time() - $time < 5); + while ((strlen($this->last_message) < 4 || strpos($this->last_message, ' ') === 0 || strpos($this->last_message, ' ') !== 3) && time() - $time < 5); // Was the desired response returned? return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired; @@ -840,10 +840,10 @@ public function passive() $time = time(); do $response = fgets($this->connection, 1024); - while (substr($response, 3, 1) != ' ' && time() - $time < 5); + while (strpos($response, ' ') !== 3 && time() - $time < 5); // If it's not 227, we weren't given an IP and port, which means it failed. - if (substr($response, 0, 4) != '227 ') + if (strpos($response, '227 ') !== 0) { $this->error = 'bad_response'; return false; @@ -1008,7 +1008,7 @@ public function detect_path($filesystem_path, $lookup_file = null) if (strlen(dirname($_SERVER['PHP_SELF'])) > 1) $path .= dirname($_SERVER['PHP_SELF']); } - elseif (substr($filesystem_path, 0, 9) == '/var/www/') + elseif (strpos($filesystem_path, '/var/www/') === 0) $path = substr($filesystem_path, 8); else $path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => '')); diff --git a/Sources/DbPackages-mysql.php b/Sources/DbPackages-mysql.php index 48c77fcac1..1b949be72c 100644 --- a/Sources/DbPackages-mysql.php +++ b/Sources/DbPackages-mysql.php @@ -534,7 +534,7 @@ function smf_db_list_columns($table_name, $detail = false, $parameters = array() SHOW FIELDS FROM {raw:table_name}', array( - 'table_name' => substr($table_name, 0, 1) == '`' ? $table_name : '`' . $table_name . '`', + 'table_name' => strpos($table_name, '`') === 0 ? $table_name : '`' . $table_name . '`', ) ); $columns = array(); @@ -601,7 +601,7 @@ function smf_db_list_indexes($table_name, $detail = false, $parameters = array() SHOW KEYS FROM {raw:table_name}', array( - 'table_name' => substr($table_name, 0, 1) == '`' ? $table_name : '`' . $table_name . '`', + 'table_name' => strpos($table_name, '`') === 0 ? $table_name : '`' . $table_name . '`', ) ); $indexes = array(); diff --git a/Sources/Display.php b/Sources/Display.php index 86d01307ca..36a3c55b5a 100644 --- a/Sources/Display.php +++ b/Sources/Display.php @@ -129,7 +129,7 @@ function Display() } // Add 1 to the number of views of this topic. - if (empty($_SESSION['last_read_topic']) || $_SESSION['last_read_topic'] != $topic) + if (!$user_info['possibly_robot'] && empty($_SESSION['last_read_topic']) || $_SESSION['last_read_topic'] != $topic) { $smcFunc['db_query']('', ' UPDATE {db_prefix}topics @@ -250,7 +250,7 @@ function Display() } // Start from a certain time index, not a message. - if (substr($_REQUEST['start'], 0, 4) == 'from') + if (strpos($_REQUEST['start'], 'from') === 0) { $timestamp = (int) substr($_REQUEST['start'], 4); if ($timestamp === 0) @@ -280,7 +280,7 @@ function Display() } // Link to a message... - elseif (substr($_REQUEST['start'], 0, 3) == 'msg') + elseif (strpos($_REQUEST['start'], 'msg') === 0) { $virtual_msg = (int) substr($_REQUEST['start'], 3); if (!$topicinfo['unapproved_posts'] && $virtual_msg >= $topicinfo['id_last_msg']) diff --git a/Sources/DumpDatabase.php b/Sources/DumpDatabase.php index 0c2b8ac4e4..a92d8e36cf 100644 --- a/Sources/DumpDatabase.php +++ b/Sources/DumpDatabase.php @@ -44,7 +44,7 @@ function DumpDatabase2() // Attempt to stop from dying... @set_time_limit(600); - if (@ini_get('memory_limit') < 256) + if (ini_get('memory_limit') < 256) @ini_set('memory_limit', '256M'); // Start saving the output... (don't do it otherwise for memory reasons.) diff --git a/Sources/Help.php b/Sources/Help.php index 6a8b4739f9..1e7f0b0802 100644 --- a/Sources/Help.php +++ b/Sources/Help.php @@ -87,7 +87,7 @@ function ShowAdminHelp() loadLanguage('Help'); // Permission specific help? - if (isset($_GET['help']) && substr($_GET['help'], 0, 14) == 'permissionhelp') + if (isset($_GET['help']) && strpos($_GET['help'], 'permissionhelp') === 0) loadLanguage('ManagePermissions'); loadTemplate('Help'); diff --git a/Sources/Load.php b/Sources/Load.php index 42e8acb57c..62b5f9ff58 100644 --- a/Sources/Load.php +++ b/Sources/Load.php @@ -63,14 +63,14 @@ function reloadSettings() } // UTF-8 in regular expressions is unsupported on PHP(win) versions < 4.2.3. - $utf8 = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8' && (strpos(strtolower(PHP_OS), 'win') === false || @version_compare(PHP_VERSION, '4.2.3') != -1); + $utf8 = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8' && (strpos(strtolower(PHP_OS), 'win') === false || version_compare(PHP_VERSION, '4.2.3', '>=')); // Set a list of common functions. $ent_list = empty($modSettings['disableEntityCheck']) ? '&(#\d{1,7}|quot|amp|lt|gt|nbsp);' : '&(#021|quot|amp|lt|gt|nbsp);'; $ent_check = empty($modSettings['disableEntityCheck']) ? array('preg_replace(\'~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~e\', \'$smcFunc[\\\'entity_fix\\\'](\\\'\\2\\\')\', ', ')') : array('', ''); // Preg_replace can handle complex characters only for higher PHP versions. - $space_chars = $utf8 ? (@version_compare(PHP_VERSION, '4.3.3') != -1 ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : "\xC2\xA0\xC2\xAD\xE2\x80\x80-\xE2\x80\x8F\xE2\x80\x9F\xE2\x80\xAF\xE2\x80\x9F\xE3\x80\x80\xEF\xBB\xBF") : '\x00-\x08\x0B\x0C\x0E-\x19\xA0'; + $space_chars = $utf8 ? (version_compare(PHP_VERSION, '4.3.3', '>=') ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : "\xC2\xA0\xC2\xAD\xE2\x80\x80-\xE2\x80\x8F\xE2\x80\x9F\xE2\x80\xAF\xE2\x80\x9F\xE3\x80\x80\xEF\xBB\xBF") : '\x00-\x08\x0B\x0C\x0E-\x19\xA0'; /** * @global array An array of anonymous helper functions. @@ -1358,7 +1358,7 @@ function loadTheme($id_theme = 0, $initialize = true) // If this isn't set yet, is a theme option, or is not the default theme.. if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') - $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; + $themeData[$row['id_member']][$row['variable']] = strpos($row['variable'], 'show_') === 0 ? $row['value'] == '1' : $row['value']; } $smcFunc['db_free_result']($result); @@ -1654,7 +1654,7 @@ function loadTheme($id_theme = 0, $initialize = true) // Set the character set from the template. $context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']; - $context['utf8'] = $context['character_set'] === 'UTF-8' && (strpos(strtolower(PHP_OS), 'win') === false || @version_compare(PHP_VERSION, '4.2.3') != -1); + $context['utf8'] = $context['character_set'] === 'UTF-8' && (strpos(strtolower(PHP_OS), 'win') === false || version_compare(PHP_VERSION, '4.2.3', '>=')); $context['right_to_left'] = !empty($txt['lang_rtl']); $context['tabindex'] = 1; @@ -1780,7 +1780,7 @@ function loadTemplate($template_name, $style_sheets = array(), $fatal = true) if ($loaded) { // For compatibility reasons, if this is the index template without new functions, include compatible stuff. - if (substr($template_name, 0, 5) == 'index' && !function_exists('template_button_strip')) + if (strpos($template_name, 'index') === 0 && !function_exists('template_button_strip')) loadTemplate('Compat'); if ($db_show_debug === true) @@ -2318,7 +2318,7 @@ function template_include($filename, $once = false) echo '', sprintf('%' . strlen($n) . 's', $line), ': '; if (isset($data2[$line]) && $data2[$line] != '') - echo substr($data2[$line], 0, 2) == ']+>~', '', $data2[$line]) : $last_line . $data2[$line]; + echo strpos($data2[$line], ']+>~', '', $data2[$line]) : $last_line . $data2[$line]; if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0) { diff --git a/Sources/LogInOut.php b/Sources/LogInOut.php index 17cf1c3105..95bdfa8782 100644 --- a/Sources/LogInOut.php +++ b/Sources/LogInOut.php @@ -648,7 +648,7 @@ function phpBB3_password_check($passwd, $passwd_hash) $salt = substr($passwd_hash, 4, 8); // Things are done differently for PHP 5. - if (@version_compare(PHP_VERSION, '5') >= 0) + if (version_compare(PHP_VERSION, '5', '>=')) { $hash = md5($salt . $passwd, true); for (; $count != 0; --$count) diff --git a/Sources/Logging.php b/Sources/Logging.php index c318cd4b02..954504c25e 100644 --- a/Sources/Logging.php +++ b/Sources/Logging.php @@ -309,7 +309,7 @@ function displayDebug() if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) foreach ($db_cache as $q => $qq) { - $is_select = substr(trim($qq['q']), 0, 6) == 'SELECT' || preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+SELECT .+$~s', trim($qq['q'])) != 0; + $is_select = strpos(trim($qq['q']), 'SELECT') === 0 || preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+SELECT .+$~s', trim($qq['q'])) != 0; // Temporary tables created in earlier queries are not explainable. if ($is_select) { diff --git a/Sources/ManageErrors.php b/Sources/ManageErrors.php index 5d27dbec05..a74af5b481 100644 --- a/Sources/ManageErrors.php +++ b/Sources/ManageErrors.php @@ -125,7 +125,7 @@ function ViewErrorLog() 'time' => timeformat($row['log_time']), 'timestamp' => $row['log_time'], 'url' => array( - 'html' => htmlspecialchars((substr($row['url'], 0, 1) == '?' ? $scripturl : '') . $row['url']), + 'html' => htmlspecialchars((strpos($row['url'], '?') === 0 ? $scripturl : '') . $row['url']), 'href' => base64_encode($smcFunc['db_escape_wildcard_string']($row['url'])) ), 'message' => array( @@ -206,7 +206,7 @@ function ViewErrorLog() $context['filter']['value']['html'] = '' . $user_profile[$id]['real_name'] . ''; } elseif ($filter['variable'] == 'url') - $context['filter']['value']['html'] = '\'' . strtr(htmlspecialchars((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\''; + $context['filter']['value']['html'] = '\'' . strtr(htmlspecialchars((strpos($filter['value']['sql'], '?') === 0 ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\''; elseif ($filter['variable'] == 'message') { $context['filter']['value']['html'] = '\'' . strtr(htmlspecialchars($filter['value']['sql']), array("\n" => '
', '<br />' => '
', "\t" => '   ', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\''; diff --git a/Sources/ManageLanguages.php b/Sources/ManageLanguages.php index c72729d138..f376bcd231 100644 --- a/Sources/ManageLanguages.php +++ b/Sources/ManageLanguages.php @@ -152,7 +152,7 @@ function DownloadLanguage() foreach ($_POST['copy_file'] as $file) { // Check it's not very bad. - if (strpos($file, '..') !== false || (substr($file, 0, 6) != 'Themes' && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file))) + if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file))) fatal_error($txt['languages_download_illegal_paths']); $chmod_files[] = $boarddir . '/' . $file; @@ -290,7 +290,7 @@ function DownloadLanguage() else { // If we think it's a theme thing, work out what the theme is. - if (substr($dirname, 0, 6) == 'Themes' && preg_match('~Themes[\\/]([^\\/]+)[\\/]~', $dirname, $match)) + if (strpos($dirname, 'Themes') === 0 && preg_match('~Themes[\\/]([^\\/]+)[\\/]~', $dirname, $match)) $theme_name = $match[1]; else $theme_name = 'misc'; diff --git a/Sources/ManageMaintenance.php b/Sources/ManageMaintenance.php index 363131eb5e..e0e8d2f1bd 100644 --- a/Sources/ManageMaintenance.php +++ b/Sources/ManageMaintenance.php @@ -128,7 +128,7 @@ function MaintainDatabase() global $context, $db_type, $db_character_set, $modSettings, $smcFunc, $txt; // Show some conversion options? - $context['convert_utf8'] = $db_type == 'mysql' && (!isset($db_character_set) || $db_character_set !== 'utf8' || empty($modSettings['global_character_set']) || $modSettings['global_character_set'] !== 'UTF-8') && version_compare('4.1.2', preg_replace('~\-.+?$~', '', $smcFunc['db_server_info']())) <= 0; + $context['convert_utf8'] = $db_type == 'mysql' && (!isset($db_character_set) || $db_character_set !== 'utf8' || empty($modSettings['global_character_set']) || $modSettings['global_character_set'] !== 'UTF-8') && version_compare('4.1.2', preg_replace('~\-.+?$~', '', $smcFunc['db_server_info']()), '<='); $context['convert_entities'] = $db_type == 'mysql' && isset($db_character_set, $modSettings['global_character_set']) && $db_character_set === 'utf8' && $modSettings['global_character_set'] === 'UTF-8'; if (isset($_GET['done']) && $_GET['done'] == 'convertutf8') @@ -372,7 +372,7 @@ function ConvertUtf8() validateToken('admin-maint'); // Character set conversions are only supported as of MySQL 4.1.2. - if (version_compare('4.1.2', preg_replace('~\-.+?$~', '', $smcFunc['db_server_info']())) > 0) + if (version_compare('4.1.2', preg_replace('~\-.+?$~', '', $smcFunc['db_server_info']()), '>')) fatal_lang_error('utf8_db_version_too_low'); // Use the messages.body column as indicator for the database charset. diff --git a/Sources/ManageNews.php b/Sources/ManageNews.php index 72eef75d3b..b48f23288d 100644 --- a/Sources/ManageNews.php +++ b/Sources/ManageNews.php @@ -67,7 +67,7 @@ function ManageNews() ); // Force the right area... - if (substr($_REQUEST['sa'], 0, 7) == 'mailing') + if (strpos($_REQUEST['sa'], 'mailing') === 0) $context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers'; $subActions[$_REQUEST['sa']][0](); diff --git a/Sources/ManageSettings.php b/Sources/ManageSettings.php index e8ccf97041..0f9f2e031c 100644 --- a/Sources/ManageSettings.php +++ b/Sources/ManageSettings.php @@ -1657,7 +1657,7 @@ function EditCustomProfiles() 'private' => $row['private'], 'can_search' => $row['can_search'], 'mask' => $row['mask'], - 'regex' => substr($row['mask'], 0, 5) == 'regex' ? substr($row['mask'], 5) : '', + 'regex' => strpos($row['mask'], 'regex') === 0 ? substr($row['mask'], 5) : '', 'enclose' => $row['enclose'], 'placement' => $row['placement'], ); diff --git a/Sources/ManageSmileys.php b/Sources/ManageSmileys.php index 3508d2811e..21207fb0d0 100644 --- a/Sources/ManageSmileys.php +++ b/Sources/ManageSmileys.php @@ -573,7 +573,7 @@ function AddSmiley() // Uploading just one smiley for all of them? if (isset($_POST['sameall']) && isset($_FILES['uploadSmiley']['name']) && $_FILES['uploadSmiley']['name'] != '') { - if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (@ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) + if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) fatal_lang_error('smileys_upload_error'); // Sorry, no spaces, dots, or anything else but letters allowed. @@ -644,7 +644,7 @@ function AddSmiley() continue; // Got one... - if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (@ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) + if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) fatal_lang_error('smileys_upload_error'); // Sorry, no spaces, dots, or anything else but letters allowed. @@ -1392,7 +1392,7 @@ function InstallSmileySet() /** * @todo Decide: overwrite or not? */ - if (isset($_FILES['set_gz']) && is_uploaded_file($_FILES['set_gz']['tmp_name']) && (@ini_get('open_basedir') != '' || file_exists($_FILES['set_gz']['tmp_name']))) + if (isset($_FILES['set_gz']) && is_uploaded_file($_FILES['set_gz']['tmp_name']) && (ini_get('open_basedir') != '' || file_exists($_FILES['set_gz']['tmp_name']))) $extracted = read_tgz_file($_FILES['set_gz']['tmp_name'], $boarddir . '/Smileys/' . $name); elseif (isset($_REQUEST['set_gz'])) { diff --git a/Sources/Memberlist.php b/Sources/Memberlist.php index d4f9d80a91..9de201fecf 100644 --- a/Sources/Memberlist.php +++ b/Sources/Memberlist.php @@ -475,7 +475,7 @@ function MLSearch() foreach ($_POST['fields'] as $field) { $curField = substr($field, 5); - if (substr($field, 0, 5) == 'cust_' && isset($context['custom_search_fields'][$curField])) + if (strpos($field, 'cust_') === 0 && isset($context['custom_search_fields'][$curField])) { $customJoin[] = 'LEFT JOIN {db_prefix}themes AS t' . $curField . ' ON (t' . $curField . '.variable = {string:t' . $curField . '} AND t' . $curField . '.id_theme = 1 AND t' . $curField . '.id_member = mem.id_member)'; $query_parameters['t' . $curField] = $curField; diff --git a/Sources/Modlog.php b/Sources/Modlog.php index 8c086c6bcb..3c347b6e0d 100644 --- a/Sources/Modlog.php +++ b/Sources/Modlog.php @@ -143,7 +143,7 @@ function ViewModlog() // For the moment they can only search for ONE action! foreach ($txt as $key => $text) { - if (substr($key, 0, 10) == 'modlog_ac_' && strpos($text, $search_params['string']) !== false) + if (strpos($key, 'modlog_ac_') === 0 && strpos($text, $search_params['string']) !== false) { $search_params['string'] = substr($key, 10); break; diff --git a/Sources/News.php b/Sources/News.php index 6104c5a747..7e44f78784 100644 --- a/Sources/News.php +++ b/Sources/News.php @@ -350,7 +350,7 @@ function fix_possible_url($val) call_integration_hook('integrate_fix_url', array(&$val)); - if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && @ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) + if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) return $val; $val = preg_replace('/^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?$/e', '\'\' . $scripturl . \'/\' . strtr(\'$1\', \'&;=\', \'//,\') . \'.html$2\'', $val); @@ -973,7 +973,7 @@ function getXmlProfile($xml_format) if (in_array($profile['show_email'], array('yes', 'yes_permission_override'))) $data['email'] = $profile['email']; - if (!empty($profile['birth_date']) && substr($profile['birth_date'], 0, 4) != '0000') + if (!empty($profile['birth_date']) && strpos($profile['birth_date'], '0000') !== 0) { list ($birth_year, $birth_month, $birth_day) = sscanf($profile['birth_date'], '%d-%d-%d'); $datearray = getdate(forum_time()); diff --git a/Sources/PackageGet.php b/Sources/PackageGet.php index 4a54dde973..003ac9f753 100644 --- a/Sources/PackageGet.php +++ b/Sources/PackageGet.php @@ -333,7 +333,7 @@ function PackageGBrowse() { $remote_type = $thisPackage->exists('@type') ? $thisPackage->fetch('@type') : 'relative'; - if ($remote_type == 'relative' && substr($thisPackage->fetch('@href'), 0, 7) != 'http://') + if ($remote_type == 'relative' && strpos($thisPackage->fetch('@href'), 'http://') !== 0) { if (isset($_GET['absolute'])) $current_url = $_GET['absolute'] . '/'; @@ -633,7 +633,7 @@ function PackageUpload() // Check the file was even sent! if (!isset($_FILES['package']['name']) || $_FILES['package']['name'] == '') fatal_lang_error('package_upload_error_nofile'); - elseif (!is_uploaded_file($_FILES['package']['tmp_name']) || (@ini_get('open_basedir') == '' && !file_exists($_FILES['package']['tmp_name']))) + elseif (!is_uploaded_file($_FILES['package']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['package']['tmp_name']))) fatal_lang_error('package_upload_error_failure'); // Make sure it has a sane filename. diff --git a/Sources/Packages.php b/Sources/Packages.php index 5bec7262bf..463666f5cb 100644 --- a/Sources/Packages.php +++ b/Sources/Packages.php @@ -1235,7 +1235,7 @@ function PackageRemove() $_GET['package'] = preg_replace('~[\.]+~', '.', strtr($_GET['package'], array('/' => '_', '\\' => '_'))); // Can't delete what's not there. - if (file_exists($boarddir . '/Packages/' . $_GET['package']) && (substr($_GET['package'], -4) == '.zip' || substr($_GET['package'], -4) == '.tgz' || substr($_GET['package'], -7) == '.tar.gz' || is_dir($boarddir . '/Packages/' . $_GET['package'])) && $_GET['package'] != 'backups' && substr($_GET['package'], 0, 1) != '.') + if (file_exists($boarddir . '/Packages/' . $_GET['package']) && (substr($_GET['package'], -4) == '.zip' || substr($_GET['package'], -4) == '.tgz' || substr($_GET['package'], -7) == '.tar.gz' || is_dir($boarddir . '/Packages/' . $_GET['package'])) && $_GET['package'] != 'backups' && strpos($_GET['package'], '.') !== 0) { create_chmod_control(array($boarddir . '/Packages/' . $_GET['package']), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=remove;package=' . $_GET['package'], 'crash_on_error' => true)); diff --git a/Sources/PersonalMessage.php b/Sources/PersonalMessage.php index a924693fcf..fbdea9a227 100644 --- a/Sources/PersonalMessage.php +++ b/Sources/PersonalMessage.php @@ -2353,12 +2353,12 @@ function MessageActionsApply() $to_delete[] = (int) $pm; else { - if (substr($action, 0, 4) == 'add_') + if (strpos($action, 'add_') === 0) { $type = 'add'; $action = substr($action, 4); } - elseif (substr($action, 0, 4) == 'rem_') + elseif (strpos($action, 'rem_') === 0) { $type = 'rem'; $action = substr($action, 4); diff --git a/Sources/Profile-Modify.php b/Sources/Profile-Modify.php index 5f4f47f033..58a582af16 100644 --- a/Sources/Profile-Modify.php +++ b/Sources/Profile-Modify.php @@ -1220,7 +1220,7 @@ function makeCustomFieldChanges($memID, $area, $sanitize = true) { $value = (int) $value; } - elseif (substr($row['mask'], 0, 5) == 'regex' && preg_match(substr($row['mask'], 5), $value) === 0) + elseif (strpos($row['mask'], 'regex') === 0 && preg_match(substr($row['mask'], 5), $value) === 0) $value = ''; } } @@ -2666,7 +2666,7 @@ function profileSaveAvatarData(&$value) if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') $profile_vars['avatar'] = ''; // Trying to make us do something we'll regret? - elseif (substr($profile_vars['avatar'], 0, 7) != 'http://') + elseif (strpos($profile_vars['avatar'], 'http://') !== 0) return 'bad_avatar'; // Should we check dimensions? elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external'])) diff --git a/Sources/QueryString.php b/Sources/QueryString.php index b926a75d29..99541708b6 100644 --- a/Sources/QueryString.php +++ b/Sources/QueryString.php @@ -37,7 +37,7 @@ function cleanRequest() $scripturl = $boardurl . '/index.php'; // What function to use to reverse magic quotes - if sybase is on we assume that the database sensibly has the right unescape function! - $removeMagicQuoteFunction = @ini_get('magic_quotes_sybase') || strtolower(@ini_get('magic_quotes_sybase')) == 'on' ? 'unescapestring__recursive' : 'stripslashes__recursive'; + $removeMagicQuoteFunction = ini_get('magic_quotes_sybase') || strtolower(ini_get('magic_quotes_sybase')) == 'on' ? 'unescapestring__recursive' : 'stripslashes__recursive'; // Save some memory.. (since we don't use these anyway.) unset($GLOBALS['HTTP_POST_VARS'], $GLOBALS['HTTP_POST_VARS']); @@ -69,7 +69,7 @@ function cleanRequest() } // Are we going to need to parse the ; out? - if ((strpos(@ini_get('arg_separator.input'), ';') === false || @version_compare(PHP_VERSION, '4.2.0') == -1) && !empty($_SERVER['QUERY_STRING'])) + if ((strpos(ini_get('arg_separator.input'), ';') === false || version_compare(PHP_VERSION, '4.2.0', '<')) && !empty($_SERVER['QUERY_STRING'])) { // Get rid of the old one! You don't know where it's been! $_GET = array(); @@ -86,7 +86,7 @@ function cleanRequest() if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) $_GET = $removeMagicQuoteFunction($_GET); } - elseif (strpos(@ini_get('arg_separator.input'), ';') !== false) + elseif (strpos(ini_get('arg_separator.input'), ';') !== false) { if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) $_GET = $removeMagicQuoteFunction($_GET); @@ -453,7 +453,7 @@ function cleanXml($string) global $context; // http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char - return preg_replace('~[\x00-\x08\x0B\x0C\x0E-\x19' . ($context['utf8'] ? (@version_compare(PHP_VERSION, '4.3.3') != -1 ? '\x{D800}-\x{DFFF}\x{FFFE}\x{FFFF}' : "\xED\xA0\x80-\xED\xBF\xBF\xEF\xBF\xBE\xEF\xBF\xBF") : '') . ']~' . ($context['utf8'] ? 'u' : ''), '', $string); + return preg_replace('~[\x00-\x08\x0B\x0C\x0E-\x19' . ($context['utf8'] ? (version_compare(PHP_VERSION, '4.3.3', '>=') ? '\x{D800}-\x{DFFF}\x{FFFE}\x{FFFF}' : "\xED\xA0\x80-\xED\xBF\xBF\xEF\xBF\xBE\xEF\xBF\xBF") : '') . ']~' . ($context['utf8'] ? 'u' : ''), '', $string); } /** @@ -503,14 +503,14 @@ function ob_sessrewrite($buffer) // Do nothing if the session is cookied, or they are a crawler - guests are caught by redirectexit(). This doesn't work below PHP 4.3.0, because it makes the output buffer bigger. // @todo smflib - if (empty($_COOKIE) && SID != '' && empty($context['browser']['possibly_robot']) && @version_compare(PHP_VERSION, '4.3.0') != -1) + if (empty($_COOKIE) && SID != '' && empty($context['browser']['possibly_robot']) && version_compare(PHP_VERSION, '4.3.0', '>=')) $buffer = preg_replace('/"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&', $buffer); // Debugging templates, are we? elseif (isset($_GET['debug'])) $buffer = preg_replace('/(? empty($inc_data[$key]) ? $context['tables'][$table]['default_value'] : $inc_data[$key], ); // Special "hack" the adding separators when doing data by column. - if (substr($key, 0, 5) == '#sep#') + if (strpos($key, '#sep#') === 0) $data[$key]['separator'] = true; } } @@ -891,7 +891,7 @@ function addData($inc_data, $custom_table = null) $data[$key] = array( 'v' => $value, ); - if (substr($key, 0, 5) == '#sep#') + if (strpos($key, '#sep#') === 0) $data[$key]['separator'] = true; } } diff --git a/Sources/ScheduledTasks.php b/Sources/ScheduledTasks.php index 1180e6aac6..444f3d0390 100644 --- a/Sources/ScheduledTasks.php +++ b/Sources/ScheduledTasks.php @@ -1279,7 +1279,7 @@ function scheduled_fetchSMfiles() foreach ($js_files as $ID_FILE => $file) { // Create the url - $server = empty($file['path']) || substr($file['path'], 0, 7) != 'http://' ? 'http://www.simplemachines.org' : ''; + $server = empty($file['path']) || strpos($file['path'], 'http://') !== 0 ? 'http://www.simplemachines.org' : ''; $url = $server . (!empty($file['path']) ? $file['path'] : $file['path']) . $file['filename'] . (!empty($file['parameters']) ? '?' . $file['parameters'] : ''); // Get the file diff --git a/Sources/Session.php b/Sources/Session.php index 0bb12c3c2f..aa3fd7b22f 100644 --- a/Sources/Session.php +++ b/Sources/Session.php @@ -44,10 +44,10 @@ function loadSession() // @todo Set the session cookie path? // If it's already been started... probably best to skip this. - if ((@ini_get('session.auto_start') == 1 && !empty($modSettings['databaseSession_enable'])) || session_id() == '') + if ((ini_get('session.auto_start') == 1 && !empty($modSettings['databaseSession_enable'])) || session_id() == '') { // Attempt to end the already-started session. - if (@ini_get('session.auto_start') == 1) + if (ini_get('session.auto_start') == 1) @session_write_close(); // This is here to stop people from using bad junky PHPSESSIDs. @@ -60,12 +60,12 @@ function loadSession() } // Use database sessions? (they don't work in 4.1.x!) - if (!empty($modSettings['databaseSession_enable']) && @version_compare(PHP_VERSION, '4.2.0') != -1) + if (!empty($modSettings['databaseSession_enable']) && version_compare(PHP_VERSION, '4.2.0', '>=')) { session_set_save_handler('sessionOpen', 'sessionClose', 'sessionRead', 'sessionWrite', 'sessionDestroy', 'sessionGC'); @ini_set('session.gc_probability', '1'); } - elseif (@ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) + elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) @ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60)); // Use cache setting sessions? @@ -85,7 +85,7 @@ function loadSession() } // While PHP 4.1.x should use $_SESSION, it seems to need this to do it right. - if (@version_compare(PHP_VERSION, '4.2.0') == -1) + if (version_compare(PHP_VERSION, '4.2.0', '<')) $HTTP_SESSION_VARS['php_412_bugfix'] = true; // Set the randomly generated code. diff --git a/Sources/Subs-Admin.php b/Sources/Subs-Admin.php index 9a2147220f..31df862ffe 100644 --- a/Sources/Subs-Admin.php +++ b/Sources/Subs-Admin.php @@ -252,7 +252,7 @@ function updateSettingsFile($config_vars) if (count($config_vars) == 1 && isset($config_vars['db_last_error'])) { $temp = trim(implode("\n", $settingsArray)); - if (substr($temp, 0, 5) != '') + if (strpos($temp, '<' . '?php') !== 0 || substr($temp, -2) != '?' . '>') return; if (strpos($temp, 'sourcedir') === false || strpos($temp, 'boarddir') === false) return; @@ -268,7 +268,7 @@ function updateSettingsFile($config_vars) for ($i = 0, $n = count($settingsArray); $i < $n; $i++) { // Don't trim or bother with it if it's not a variable. - if (substr($settingsArray[$i], 0, 1) != '$') + if (strpos($settingsArray[$i], '$') !== 0) continue; $settingsArray[$i] = trim($settingsArray[$i]) . "\n"; @@ -286,7 +286,7 @@ function updateSettingsFile($config_vars) } } - if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>') + if (strpos(trim($settingsArray[$i]), '?' . '>')) $end = $i; } diff --git a/Sources/Subs-Auth.php b/Sources/Subs-Auth.php index 02fbaec0b9..6df57509e3 100644 --- a/Sources/Subs-Auth.php +++ b/Sources/Subs-Auth.php @@ -174,9 +174,9 @@ function setLoginCookie($cookie_length, $id, $password = '') $_SESSION = $oldSessionData; // Version 4.3.2 didn't store the cookie of the new session. - if (version_compare(PHP_VERSION, '4.3.2') === 0) + if (version_compare(PHP_VERSION, '4.3.2', '==')) { - $sessionCookieLifetime = @ini_get('session.cookie_lifetime'); + $sessionCookieLifetime = ini_get('session.cookie_lifetime'); setcookie(session_name(), session_id(), time() + (empty($sessionCookieLifetime) ? $cookie_length : $sessionCookieLifetime), $cookie_url[1], $cookie_url[0], !empty($modSettings['secureCookies'])); } diff --git a/Sources/Subs-Db-mysql.php b/Sources/Subs-Db-mysql.php index 9968ed1933..fd2f5793bf 100644 --- a/Sources/Subs-Db-mysql.php +++ b/Sources/Subs-Db-mysql.php @@ -712,7 +712,7 @@ function smf_db_error_backtrace($error_message, $log_message = '', $error_type = foreach (debug_backtrace() as $step) { // Found it? - if (strpos($step['function'], 'query') === false && !in_array(substr($step['function'], 0, 7), array('smf_db_', 'preg_re', 'db_erro', 'call_us')) && substr($step['function'], 0, 2) != '__') + if (strpos($step['function'], 'query') === false && !in_array(substr($step['function'], 0, 7), array('smf_db_', 'preg_re', 'db_erro', 'call_us')) && strpos($step['function'], '__') !== 0) { $log_message .= '
Function: ' . $step['function']; break; diff --git a/Sources/Subs-Db-postgresql.php b/Sources/Subs-Db-postgresql.php index eb4355655c..25cff4c241 100644 --- a/Sources/Subs-Db-postgresql.php +++ b/Sources/Subs-Db-postgresql.php @@ -787,7 +787,7 @@ function smf_db_error_backtrace($error_message, $log_message = '', $error_type = foreach (debug_backtrace() as $step) { // Found it? - if (strpos($step['function'], 'query') === false && !in_array(substr($step['function'], 0, 7), array('smf_db_', 'preg_re', 'db_erro', 'call_us')) && substr($step['function'], 0, 2) != '__') + if (strpos($step['function'], 'query') === false && !in_array(substr($step['function'], 0, 7), array('smf_db_', 'preg_re', 'db_erro', 'call_us')) && strpos($step['function'], '__') !== 0) { $log_message .= '
Function: ' . $step['function']; break; diff --git a/Sources/Subs-Db-sqlite.php b/Sources/Subs-Db-sqlite.php index d0a1a38b44..d52ff62fb0 100644 --- a/Sources/Subs-Db-sqlite.php +++ b/Sources/Subs-Db-sqlite.php @@ -662,7 +662,7 @@ function smf_db_error_backtrace($error_message, $log_message = '', $error_type = foreach (debug_backtrace() as $step) { // Found it? - if (strpos($step['function'], 'query') === false && !in_array(substr($step['function'], 0, 7), array('smf_db_', 'preg_re', 'db_erro', 'call_us')) && substr($step['function'], 0, 2) != '__') + if (strpos($step['function'], 'query') === false && !in_array(substr($step['function'], 0, 7), array('smf_db_', 'preg_re', 'db_erro', 'call_us')) && strpos($step['function'], '__') !== 0) { $log_message .= '
Function: ' . $step['function']; break; diff --git a/Sources/Subs-Editor.php b/Sources/Subs-Editor.php index 251087e111..925ddc3570 100644 --- a/Sources/Subs-Editor.php +++ b/Sources/Subs-Editor.php @@ -837,7 +837,7 @@ function html_to_bbc($text) $tag_type = 'ftp'; // Or is this a link to an email address? - elseif (substr($href, 0, 7) == 'mailto:') + elseif (strpos($href, 'mailto:') === 0) { $tag_type = 'email'; $href = substr($href, 7); diff --git a/Sources/Subs-Graphics.php b/Sources/Subs-Graphics.php index bdcefdce5c..75e23b22ca 100644 --- a/Sources/Subs-Graphics.php +++ b/Sources/Subs-Graphics.php @@ -190,7 +190,7 @@ function resizeImageFile($source, $destination, $max_width, $max_height, $prefer // Get the image file, we have to work with something after all $fp_destination = fopen($destination, 'wb'); - if ($fp_destination && substr($source, 0, 7) == 'http://') + if ($fp_destination && strpos($source, 'http://') === 0) { $fileContents = fetch_web_data($source); diff --git a/Sources/Subs-Membergroups.php b/Sources/Subs-Membergroups.php index f5a02ec036..d3d65d25ca 100644 --- a/Sources/Subs-Membergroups.php +++ b/Sources/Subs-Membergroups.php @@ -745,7 +745,7 @@ function list_getMembergroups($start, $items_per_page, $sort, $membergroup_type) } // Apply manual sorting if the 'number of members' column is selected. - if (substr($sort, 0, 1) == '1' || strpos($sort, ', 1') !== false) + if (strpos($sort, '1') === 0 || strpos($sort, ', 1') !== false) { $sort_ascending = strpos($sort, 'DESC') === false; diff --git a/Sources/Subs-Members.php b/Sources/Subs-Members.php index c4d8da9e7f..af06e684d6 100644 --- a/Sources/Subs-Members.php +++ b/Sources/Subs-Members.php @@ -40,7 +40,7 @@ function deleteMembers($users, $check_not_admin = false) // Try give us a while to sort this out... @set_time_limit(600); // Try to get some more memory. - if (@ini_get('memory_limit') < 128) + if (ini_get('memory_limit') < 128) @ini_set('memory_limit', '128M'); // If it's not an array, make it so! diff --git a/Sources/Subs-OpenID.php b/Sources/Subs-OpenID.php index 314cfd0222..780c9753b4 100644 --- a/Sources/Subs-OpenID.php +++ b/Sources/Subs-OpenID.php @@ -530,7 +530,7 @@ function sha1_hmac($data, $key) function sha1_raw($text) { - if (version_compare(PHP_VERSION, '5.0.0') >= 0) + if (version_compare(PHP_VERSION, '5.0.0', '<=')) return sha1($text, true); $hex = sha1($text); diff --git a/Sources/Subs-Package.php b/Sources/Subs-Package.php index 26b095de75..c3b37b59ca 100644 --- a/Sources/Subs-Package.php +++ b/Sources/Subs-Package.php @@ -164,7 +164,7 @@ function. // Get the data from the file and extract it. function read_tgz_file($gzfilename, $destination, $single_file = false, $overwrite = false, $files_to_extract = null) { - if (substr($gzfilename, 0, 7) == 'http://') + if (strpos($gzfilename, 'http://') === 0) { $data = fetch_web_data($gzfilename); @@ -204,7 +204,7 @@ function read_tgz_data($data, $destination, $single_file = false, $overwrite = f if (strtolower($id['a'] . $id['b']) != '1f8b') { // Okay, this ain't no tar.gz, but maybe it's a zip file. - if (substr($data, 0, 2) == 'PK') + if (strpos($data, 'PK') === 0) return read_zip_data($data, $destination, $single_file, $overwrite, $files_to_extract); else return false; @@ -342,7 +342,7 @@ function read_zip_data($data, $destination, $single_file = false, $overwrite = f mktree($destination, 0777); // Look for the PK header... - if (substr($data, 0, 2) != 'PK') + if (strpos($data, 'PK') !== 0) return false; // Find the central whosamawhatsit at the end; if there's a comment it's a pain. @@ -775,7 +775,7 @@ function list_restoreFiles($dummy1, $dummy2, $dummy3, $do_change) if (!in_array($_POST['ftp_path'], array('', '/'))) { $ftp_root = strtr($boarddir, array($_POST['ftp_path'] => '')); - if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/')) + if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || strpos($_POST['ftp_path'], '/') === 0)) $ftp_root = substr($ftp_root, 0, -1); } else @@ -1033,7 +1033,7 @@ function packageRequireFTP($destination_url, $files = null, $return = false) if (!in_array($_POST['ftp_path'], array('', '/'))) { $ftp_root = strtr($boarddir, array($_POST['ftp_path'] => '')); - if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/')) + if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || strpos($_POST['ftp_path'], '/') === 0)) $ftp_root = substr($ftp_root, 0, -1); } else @@ -1193,7 +1193,7 @@ function parsePackageInfo(&$packageXML, $testing_only = true, $method = 'install ); // If there is a destination, make sure it makes sense. - if (substr($actionType, 0, 6) != 'remove') + if (strpos($actionType, 'remove') !== 0) { $this_action['unparsed_destination'] = $action->fetch('@destination'); $this_action['destination'] = parse_path($action->fetch('@destination')) . '/' . basename($this_action['filename']); @@ -1205,7 +1205,7 @@ function parsePackageInfo(&$packageXML, $testing_only = true, $method = 'install } // If we're moving or requiring (copying) a file. - if (substr($actionType, 0, 4) == 'move' || substr($actionType, 0, 7) == 'require') + if (strpos($actionType, 'move') === 0 || strpos($actionType, 'require') === 0) { if ($action->exists('@from')) $this_action['source'] = parse_path($action->fetch('@from')); diff --git a/Sources/Subs-Post.php b/Sources/Subs-Post.php index 25d4b95994..c893542b14 100644 --- a/Sources/Subs-Post.php +++ b/Sources/Subs-Post.php @@ -45,7 +45,7 @@ function preparsecode(&$message, $previewing = false) // Trim off trailing quotes - these often happen by accident. while (substr($message, -7) == '[quote]') $message = substr($message, 0, -7); - while (substr($message, 0, 8) == '[/quote]') + while (strpos($message, '[/quote]') === 0) $message = substr($message, 8); // Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed. @@ -461,11 +461,11 @@ function fixTag(&$message, $myTag, $protocols, $embeddedUrl = false, $hasEqualSi if (!$found && $protocols[0] == 'http') { - if (substr($replace, 0, 1) == '/') + if (strpos($replace, '/') === 0) $replace = $domain_url . $replace; - elseif (substr($replace, 0, 1) == '?') + elseif (strpos($replace, '?') === 0) $replace = $scripturl . $replace; - elseif (substr($replace, 0, 1) == '#' && $embeddedUrl) + elseif (strpos($replace, '#') === 0 && $embeddedUrl) { $replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1)); $this_tag = 'iurl'; diff --git a/Sources/Subs.php b/Sources/Subs.php index 4f8eac5ae4..191faa8be3 100644 --- a/Sources/Subs.php +++ b/Sources/Subs.php @@ -1454,7 +1454,7 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra 'validate' => isset($disabled['php']) ? null : create_function('&$tag, &$data, $disabled', ' if (!isset($disabled[\'php\'])) { - $add_begin = substr(trim($data), 0, 5) != \'<?\'; + $add_begin = strpos(trim($data), \'<?\') === 0; $data = highlight_php_code($add_begin ? \'<?php \' . $data . \'?>\' : $data); if ($add_begin) $data = preg_replace(array(\'~^(.+?)<\?.{0,40}?php(?: |\s)~\', \'~\?>((?:)*)$~\'), \'$1\', $data, 2); @@ -1960,7 +1960,7 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra if ($pos >= strlen($message) - 1) break; - $tags = strtolower(substr($message, $pos + 1, 1)); + $tags = strtolower($message[$pos + 1]); if ($tags == '/' && !empty($open_tags)) { @@ -2043,7 +2043,7 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra $pos2 = $pos - 1; // See the comment at the end of the big loop - just eating whitespace ;). - if (!empty($tag['block_level']) && substr($message, $pos, 6) == '
') + if (!empty($tag['block_level']) && strpos($message, '
') === $pos) $message = substr($message, 0, $pos) . substr($message, $pos + 6); if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(
| |\s)*~', substr($message, $pos), $matches) != 0) $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); @@ -2067,10 +2067,10 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra foreach ($bbc_codes[$tags] as $possible) { // Not a match? - if (strtolower(substr($message, $pos + 1, strlen($possible['tag']))) != $possible['tag']) + if (stripos($message, $possible['tag']) !== $pos + 1) continue; - $next_c = substr($message, $pos + 1 + strlen($possible['tag']), 1); + $next_c = $message[$pos + 1 + strlen($possible['tag'])]; // A test validation? if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + strlen($possible['tag']) + 1)) == 0) @@ -2087,7 +2087,7 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') continue; // Maybe we just want a /... - if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + strlen($possible['tag']), 2) != '/]' && substr($message, $pos + 1 + strlen($possible['tag']), 3) != ' /]') + if ($possible['type'] == 'closed' && $next_c != ']' && strpos($message, '/]') !== $pos + 1 + strlen($possible['tag']) && strpos($message, ' /]') !== $pos + 1 + strlen($possible['tag'])) continue; // An immediate ]? if ($possible['type'] == 'unparsed_content' && $next_c != ']') @@ -2183,11 +2183,11 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra } // Item codes are complicated buggers... they are implicit [li]s and can make [list]s! - if ($smileys !== false && $tag === null && isset($itemcodes[substr($message, $pos + 1, 1)]) && substr($message, $pos + 2, 1) == ']' && !isset($disabled['list']) && !isset($disabled['li'])) + if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li'])) { - if (substr($message, $pos + 1, 1) == '0' && !in_array(substr($message, $pos - 1, 1), array(';', ' ', "\t", '>'))) + if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", '>'))) continue; - $tag = $itemcodes[substr($message, $pos + 1, 1)]; + $tag = $itemcodes[$message[$pos + 1]]; // First let's set up the tree: it needs to be in a list, or after an li. if ($inside === null || ($inside['tag'] != 'list' && $inside['tag'] != 'li')) @@ -2295,7 +2295,7 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra $pos1 += strlen($open_tags[$i]['after']) + 2; // Trim or eat trailing stuff... see comment at the end of the big loop. - if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 6) == '
') + if (!empty($open_tags[$i]['block_level']) && strpos($message, '
') === $pos) $message = substr($message, 0, $pos) . substr($message, $pos + 6); if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(
| |\s)*~', substr($message, $pos), $matches) != 0) $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); @@ -2321,7 +2321,7 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra $data = substr($message, $pos1, $pos2 - $pos1); - if (!empty($tag['block_level']) && substr($data, 0, 6) == '
') + if (!empty($tag['block_level']) && strpos($data, '
') === 0) $data = substr($data, 6); if (isset($tag['validate'])) @@ -2340,7 +2340,7 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra // The value may be quoted for some tags - check. if (isset($tag['quoted'])) { - $quoted = substr($message, $pos1, 6) == '"'; + $quoted = strpos($message, '"') == $pos1; if ($tag['quoted'] != 'optional' && !$quoted) continue; @@ -2362,7 +2362,7 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra substr($message, $pos1, $pos2 - $pos1) ); - if (!empty($tag['block_level']) && substr($data[0], 0, 6) == '
') + if (!empty($tag['block_level']) && substr($data[0], '
') === 0) $data[0] = substr($data[0], 6); // Validation for my parking, please! @@ -2434,7 +2434,7 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra // The value may be quoted for some tags - check. if (isset($tag['quoted'])) { - $quoted = substr($message, $pos1, 6) == '"'; + $quoted = substr($message, '"') === $pos1; if ($tag['quoted'] != 'optional' && !$quoted) continue; @@ -2468,7 +2468,7 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra } // If this is block level, eat any breaks after it. - if (!empty($tag['block_level']) && substr($message, $pos + 1, 6) == '
') + if (!empty($tag['block_level']) && substr($message, '
') === $pos + 1) $message = substr($message, 0, $pos + 1) . substr($message, $pos + 7); // Are we trimming outside this tag? @@ -2605,7 +2605,7 @@ function highlight_php_code($code) $oldlevel = error_reporting(0); // It's easier in 4.2.x+. - if (@version_compare(PHP_VERSION, '4.2.0') == -1) + if (version_compare(PHP_VERSION, '4.2.0', '<')) { ob_start(); @highlight_string($code); @@ -2636,7 +2636,7 @@ function redirectexit($setLocation = '', $refresh = false) // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ AddMailQueue(true); - $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:'; + $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && strpos($setLocation, 'about:') !== 0; if (WIRELESS) { @@ -2661,7 +2661,7 @@ function redirectexit($setLocation = '', $refresh = false) elseif (isset($_GET['debug'])) $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); - if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || @ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed']))) + if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed']))) { if (defined('SID') && SID != '') $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$/e', "\$scripturl . '/' . strtr('\$1', '&;=', '//,') . '.html\$2?' . SID", $setLocation); @@ -2880,7 +2880,7 @@ function setupThemeContext($forceload = false) if ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar'; // Full URL? - elseif (substr($user_info['avatar']['url'], 0, 7) == 'http://') + elseif (strpos($user_info['avatar']['url'], 'http://') === 0) { $context['user']['avatar']['href'] = $user_info['avatar']['url']; @@ -3254,7 +3254,7 @@ function host_from_ip($ip) $t = microtime(); // If we can't access nslookup/host, PHP 4.1.x might just crash. - if (@version_compare(PHP_VERSION, '4.2.0') == -1) + if (version_compare(PHP_VERSION, '4.2.0', '<')) $host = false; // Try the Linux host command, perhaps? @@ -3392,7 +3392,7 @@ function loadClassFile($filename) fatal_lang_error('error_bad_file', 'general', array($sourcedir . '/' . $filename)); // Using a version below PHP 5.0? Do a compatibility conversion. - if (@version_compare(PHP_VERSION, '5.0.0') != 1) + if (version_compare(PHP_VERSION, '5.0.0', '<=')) { // Check if it was included before. if (in_array($filename, $files_included)) @@ -3710,7 +3710,7 @@ function smf_seed_generator() updateSettings(array('rand_seed' => $modSettings['rand_seed'])); } - if (@version_compare(PHP_VERSION, '4.2.0') == -1) + if (version_compare(PHP_VERSION, '4.2.0', '<')) { $seed = ($modSettings['rand_seed'] + ((double) microtime() * 1000003)) & 0x7fffffff; mt_srand($seed); diff --git a/Sources/Subscriptions-PayPal.php b/Sources/Subscriptions-PayPal.php index 671cfa3541..b59ab3f3cf 100644 --- a/Sources/Subscriptions-PayPal.php +++ b/Sources/Subscriptions-PayPal.php @@ -223,7 +223,7 @@ public function isRefund() // Is this a subscription? public function isSubscription() { - if (substr($_POST['txn_type'], 0, 14) == 'subscr_payment') + if (strpos($_POST['txn_type'], 'subscr_payment') === 0) return true; else return false; diff --git a/Sources/Themes.php b/Sources/Themes.php index 3cc73db492..18544ae861 100644 --- a/Sources/Themes.php +++ b/Sources/Themes.php @@ -1433,7 +1433,7 @@ function ThemeInstall() $theme_name = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $theme_name); $theme_dir = $boarddir . '/Themes/' . $theme_name; - if (isset($_FILES['theme_gz']) && is_uploaded_file($_FILES['theme_gz']['tmp_name']) && (@ini_get('open_basedir') != '' || file_exists($_FILES['theme_gz']['tmp_name']))) + if (isset($_FILES['theme_gz']) && is_uploaded_file($_FILES['theme_gz']['tmp_name']) && (ini_get('open_basedir') != '' || file_exists($_FILES['theme_gz']['tmp_name']))) $extracted = read_tgz_file($_FILES['theme_gz']['tmp_name'], $boarddir . '/Themes/' . $theme_name, false, true); elseif (isset($_REQUEST['theme_gz'])) { @@ -1788,7 +1788,7 @@ function EditTheme() { if (isset($_GET['directory'])) { - if (substr($_GET['directory'], 0, 1) == '.') + if (strpos($_GET['directory'], '.') === 0) $_GET['directory'] = ''; else { @@ -1825,7 +1825,7 @@ function EditTheme() } else { - if (substr($_REQUEST['filename'], 0, 1) == '.') + if (strpos($_REQUEST['filename'], '.') === 0) $_REQUEST['filename'] = ''; else { @@ -1849,7 +1849,7 @@ function EditTheme() $_POST['entire_file'] = rtrim(strtr($_POST['entire_file'], array("\r" => '', ' ' => "\t"))); // Check for a parse error! - if (substr($_REQUEST['filename'], -13) == '.template.php' && is_writable($theme_dir) && @ini_get('display_errors')) + if (substr($_REQUEST['filename'], -13) == '.template.php' && is_writable($theme_dir) && ini_get('display_errors')) { $request = $smcFunc['db_query']('', ' SELECT value @@ -1937,7 +1937,7 @@ function EditTheme() $context['file_parts'] = array(array('lines' => 0, 'line' => 1, 'data' => '')); for ($i = 0, $n = count($file_data); $i < $n; $i++) { - if (isset($file_data[$i + 1]) && substr($file_data[$i + 1], 0, 9) == 'function ') + if (isset($file_data[$i + 1]) && strpos($file_data[$i + 1], 'function ') === 0) { // Try to format the functions a little nicer... $context['file_parts'][$j]['data'] = trim($context['file_parts'][$j]['data']) . "\n"; @@ -1986,7 +1986,7 @@ function get_file_listing($path, $relative) foreach ($entries as $entry) { // Skip all dot files, including .htaccess. - if (substr($entry, 0, 1) == '.' || $entry == 'CVS') + if (strpos($entry, '.') === 0 || $entry == 'CVS') continue; if (is_dir($path . '/' . $entry)) diff --git a/Sources/ViewQuery.php b/Sources/ViewQuery.php index 349a3835ef..885c567799 100644 --- a/Sources/ViewQuery.php +++ b/Sources/ViewQuery.php @@ -95,7 +95,7 @@ function ViewQuery() if (isset($query_data['f'])) $query_data['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $query_data['f']); - $is_select_query = substr(trim($query_data['q']), 0, 6) == 'SELECT'; + $is_select_query = strpos(trim($query_data['q']), 'SELECT') === 0; if ($is_select_query) $select = $query_data['q']; elseif (preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+(SELECT .+)$~s', trim($query_data['q']), $matches) != 0) diff --git a/Themes/default/Admin.template.php b/Themes/default/Admin.template.php index a6dfef2bf1..337445d503 100644 --- a/Themes/default/Admin.template.php +++ b/Themes/default/Admin.template.php @@ -1218,7 +1218,7 @@ function addOption() - +
diff --git a/Themes/default/languages/Help.english.php b/Themes/default/languages/Help.english.php index 3879ad3474..f626b40489 100644 --- a/Themes/default/languages/Help.english.php +++ b/Themes/default/languages/Help.english.php @@ -406,7 +406,7 @@ $helptxt['queryless_urls'] = 'This changes the format of URLs a little so search engines will like them better. They will look like index.php/topic,1.0.html.

This feature will ' . (isset($_SERVER['SERVER_SOFTWARE']) && (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'lighttpd') !== false) ? '' : 'not') . ' work on your server.'; $helptxt['countChildPosts'] = 'Checking this option will mean that posts and topics in a board\'s child board will count toward its totals on the index page.

This will make things notably slower, but means that a parent with no posts in it won\'t show \'0\'.'; -$helptxt['fixLongWords'] = 'This option breaks words longer than a certain length into pieces so they don\'t disturb the forum\'s layout. (as much...) This option should not be set to a value under 40. This option will not work with forums using UTF-8 and PHP less than 4.4.0. This ' . (empty($GLOBALS['context']['utf8']) || version_compare(PHP_VERSION, '4.4.0') != -1 ? 'WILL' : 'WILL NOT') . ' work on your server'; +$helptxt['fixLongWords'] = 'This option breaks words longer than a certain length into pieces so they don\'t disturb the forum\'s layout. (as much...) This option should not be set to a value under 40. This option will not work with forums using UTF-8 and PHP less than 4.4.0. This ' . (empty($GLOBALS['context']['utf8']) || version_compare(PHP_VERSION, '4.4.0', '>=') ? 'WILL' : 'WILL NOT') . ' work on your server'; $helptxt['allow_ignore_boards'] = 'Checking this option will allow users to select boards they wish to ignore.'; $helptxt['who_enabled'] = 'This option allows you to turn on or off the ability for users to see who is browsing the forum and what they are doing.'; diff --git a/index.php b/index.php index e31b0fac1a..50e7b15411 100644 --- a/index.php +++ b/index.php @@ -54,7 +54,7 @@ require_once($sourcedir . '/Security.php'); // Using an pre-PHP 5.1 version? -if (@version_compare(PHP_VERSION, '5.1') == -1) +if (version_compare(PHP_VERSION, '5.1', '<')) require_once($sourcedir . '/Subs-Compat.php'); // If $maintenance is set specifically to 2, then we're upgrading or something. @@ -88,7 +88,7 @@ if (!empty($modSettings['enableCompressedOutput']) && !headers_sent()) { // If zlib is being used, turn off output compression. - if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') === 'ob_gzhandler' || @version_compare(PHP_VERSION, '4.2.0') == -1) + if (ini_get('zlib.output_compression') == '1' || ini_get('output_handler') === 'ob_gzhandler' || version_compare(PHP_VERSION, '4.2.0', '<')) $modSettings['enableCompressedOutput'] = '0'; else {