From 8e1fd7e3be3811cb108a074bece2eecd5bcced8f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 29 Jul 2011 10:22:41 +0000 Subject: [PATCH] More usage of wrapper functions --- inc/db/lib-mysql3.php | 22 ++++++++++------------ inc/functions.php | 12 ++++++------ inc/http-functions.php | 6 +++--- inc/language-functions.php | 2 +- inc/libs/admins_functions.php | 2 +- inc/libs/newsletter_functions.php | 4 +++- inc/libs/wernis_functions.php | 2 +- inc/modules/admin/admin-inc.php | 4 ++-- inc/modules/admin/what-config_points.php | 3 ++- inc/modules/admin/what-usage.php | 4 +++- inc/modules/member/what-order.php | 4 ++-- inc/template-functions.php | 8 ++++---- inc/wrapper-functions.php | 2 +- 13 files changed, 39 insertions(+), 36 deletions(-) diff --git a/inc/db/lib-mysql3.php b/inc/db/lib-mysql3.php index c9b033172e..473159e03d 100644 --- a/inc/db/lib-mysql3.php +++ b/inc/db/lib-mysql3.php @@ -365,13 +365,13 @@ function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) { // Determine index/fulltext/unique word $noIndex = ( ( - strpos($sql, 'INDEX') === false + isInStringIgnoreCase('INDEX', $sql) ) && ( - strpos($sql, 'KEY') === false + isInStringIgnoreCase('KEY', $sql) ) && ( - strpos($sql, 'FULLTEXT') === false + isInStringIgnoreCase('FULLTEXT', $sql) ) && ( - strpos($sql, 'UNIQUE') === false + isInStringIgnoreCase('UNIQUE', $sql) ) ); @@ -383,7 +383,7 @@ function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sql=' . $sql . ',tableName=' . $tableName . ',tableArray=
' . print_r($tableArray, true) . '
'); // Shall we add/drop? - if (((strpos($sql, 'ADD') !== false) || (strpos($sql, 'DROP') !== false) || (strpos($sql, 'CHANGE') !== false)) && ($noIndex === true)) { + if (((isInString('ADD', $sql)) || (isInString('DROP', $sql)) || (isInString('CHANGE', $sql))) && ($noIndex === true)) { // Try two columns, one should fix foreach (array(4,5) as $idx) { // If an entry is not set, abort here @@ -400,20 +400,18 @@ function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'columnName=' . $columnName . ',idx=' . $idx . ',sql=' . $sql . ',hasZeroNums=' . intval(isSqlTableColumnFound($tableName, $columnName))); // Do we have no entry on ADD or an entry on DROP/CHANGE? - // 123 4 43 3 4 4 32 23 4 43 34 5 5 4 45 6 6 5 5 5 56 7 76 6 654321 - if (((!isSqlTableColumnFound($tableName, $columnName)) && (strpos($sql, 'ADD') !== false)) || ((isSqlTableColumnFound($tableName, $columnName)) && ((strpos($sql, 'DROP') !== false) || ((strpos($sql, 'CHANGE') !== false) && ($idx == 4) && ((!isSqlTableColumnFound($tableName, $tableArray[5])) || ($columnName == $tableArray[5])))))) { + if (((!isSqlTableColumnFound($tableName, $columnName)) && (isInString('ADD', $sql))) || ((isSqlTableColumnFound($tableName, $columnName)) && ((isInString('DROP', $sql)) || ((isInString('CHANGE', $sql)) && ($idx == 4) && ((!isSqlTableColumnFound($tableName, $tableArray[5])) || ($columnName == $tableArray[5])))))) { // Do the query //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Executing: ' . $sql); $result = SQL_QUERY($sql, $F, $L, false); // Skip further attempt(s) break; - // 1234 5 54 4 5 5 43 34 5 54 45 6 6 54 4 5 5 432 2 21 - } elseif ((((isSqlTableColumnFound($tableName, $columnName)) && (strpos($sql, 'ADD') !== false)) || ((!isSqlTableColumnFound($tableName, $columnName)) && ((strpos($sql, 'DROP') !== false)) || (strpos($sql, 'CHANGE') !== false))) && ($columnName != 'KEY')) { + } elseif ((((isSqlTableColumnFound($tableName, $columnName)) && (isInString('ADD', $sql))) || ((!isSqlTableColumnFound($tableName, $columnName)) && ((isInString('DROP', $sql))) || (isInString('CHANGE', $sql)))) && ($columnName != 'KEY')) { // Abort here because it is alreay there //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Skipped: sql=' . $sql . ',columnName=' . $columnName . ',idx=' . $idx); break; - } elseif ((!isSqlTableColumnFound($tableName, $columnName)) && (strpos($sql, 'DROP') !== false)) { + } elseif ((!isSqlTableColumnFound($tableName, $columnName)) && (isInString('DROP', $sql))) { // Abort here because we tried to drop a column which is not there (never created maybe) //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'No drop: ' . $sql); break; @@ -422,7 +420,7 @@ function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) { logDebugMessage(__FUNCTION__, __LINE__, 'Possible problem: ' . $sql . ',hasZeroNums=' . intval(isSqlTableColumnFound($tableName, $columnName)) . ''); } } // END - foreach - } elseif ((getTableType() == 'InnoDB') && (strpos($sql, 'FULLTEXT') !== false)) { + } elseif ((getTableType() == 'InnoDB') && (isInString('FULLTEXT', $sql))) { // Skip this query silently because InnoDB does not understand fulltext indexes //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Skipped FULLTEXT: sql=%s,tableName=%s,hasZeroNums=%d,file=%s,line=%s", $sql, $tableName, intval((is_bool($result)) ? 0 : isSqlTableColumnFound($columnName)), $F, $L)); } elseif ($noIndex === false) { @@ -435,7 +433,7 @@ function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) { // Init loop $begin = 1; $keyName = ','; - while (strpos($keyName, ',') !== false) { + while (isInString(',', $keyName)) { // Use last //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyName=' . $keyName . 'begin=' . $begin . ' - BEFORE'); $keyName = str_replace('`', '', $tableArray[count($tableArray) - $begin]); diff --git a/inc/functions.php b/inc/functions.php index a452aab357..1c5ee8fd31 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -92,7 +92,7 @@ function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = ' } // END - if // Set from header - if ((!isInStringIgnoreCase('@', str_replace('{AT}', '@', $toEmail))) && ($toEmail > 0)) { + if ((!isInString('@', $toEmail)) && ($toEmail > 0)) { // Does the user exist? if ((isExtensionActive('user')) && (fetchUserData($toEmail))) { // Get the email @@ -1358,7 +1358,7 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0 // Read from source file $line = fgets ($fp, 1024); - if (strpos($line, $search) > -1) { + if (isInString($search, $line)) { $next = '0'; $found = true; } // END - if @@ -2062,7 +2062,7 @@ function getModuleFromFileName ($file, $accessLevel) { // Encodes an URL for adding session id, etc. function encodeUrl ($url, $outputMode = '0') { // Do we have already have a PHPSESSID inside or view.php is called? Then abort here - if ((strpos($url, session_name()) !== false) || (isRawOutputMode())) { + if ((isInStringIgnoreCase(session_name(), $url)) || (isRawOutputMode())) { // Raw output mode detected or session_name() found in URL return $url; } // END - if @@ -2072,7 +2072,7 @@ function encodeUrl ($url, $outputMode = '0') { // Invalid session // Determine right seperator $seperator = '&'; - if (strpos($url, '?') === false) { + if (!isInString('?', $url)) { // No question mark $seperator = '?'; } elseif ((!isHtmlOutputMode()) || ($outputMode != '0')) { @@ -2099,7 +2099,7 @@ function encodeUrl ($url, $outputMode = '0') { // Simple check for spider function isSpider () { // Get the UA and trim it down - $userAgent = trim(strtolower(detectUserAgent(true))); + $userAgent = trim(detectUserAgent(true)); // It should not be empty, if so it is better a spider/bot if (empty($userAgent)) { @@ -2108,7 +2108,7 @@ function isSpider () { } // END - if // Is it a spider? - return ((strpos($userAgent, 'spider') !== false) || (strpos($userAgent, 'slurp') !== false) || (strpos($userAgent, 'bot') !== false) || (strpos($userAgent, 'archiver') !== false)); + return ((isInStringIgnoreCase('spider', $userAgent)) || (isInStringIgnoreCase('slurp', $userAgent)) || (isInStringIgnoreCase('bot', $userAgent)) || (isInStringIgnoreCase('archiver', $userAgent))); } // Function to search for the last modified file diff --git a/inc/http-functions.php b/inc/http-functions.php index 3b9a630eef..9d179379d4 100644 --- a/inc/http-functions.php +++ b/inc/http-functions.php @@ -69,7 +69,7 @@ function sendGetRequest ($baseUrl, $data = array(), $removeHeader = false) { // There should be data, else we don't need to extend $baseUrl with $body if (!empty($body)) { // Do we have a question-mark in the script? - if (strpos($baseUrl, '?') === false) { + if (!isInString('?', $baseUrl)) { // No, so first char must be question mark $body = '?' . $body; } else { @@ -376,10 +376,10 @@ function unchunkHttpResponse ($response) { // Check if we have chunks foreach ($response as $line) { // Make lower-case and trim it - $line = trim(strtolower($line)); + $line = trim($line); // Entry found? - if ((strpos($line, 'transfer-encoding') !== false) && (strpos($line, 'chunked') !== false)) { + if ((isInStringIgnoreCase('transfer-encoding', $line)) && (isInStringIgnoreCase('chunked', $line))) { // Found! $isChunked = true; break; diff --git a/inc/language-functions.php b/inc/language-functions.php index 77f6f2e9e5..b9b0d82f98 100644 --- a/inc/language-functions.php +++ b/inc/language-functions.php @@ -356,7 +356,7 @@ function isMessageMasked ($messageId) { } // END - if // Now simply check it - $masked = (strpos($GLOBALS['messages'][getCurrentLanguage()][$messageId], '%') !== false); + $masked = isInString('%', $GLOBALS['messages'][getCurrentLanguage()][$messageId]); // Return result return $masked; diff --git a/inc/libs/admins_functions.php b/inc/libs/admins_functions.php index 5338cbdf59..7b7758a725 100644 --- a/inc/libs/admins_functions.php +++ b/inc/libs/admins_functions.php @@ -138,7 +138,7 @@ function isAdminsAllowedByAcl ($action, $what) { // Create email link to admins's account function generateAdminEmailLink ($email, $mod = 'admin') { // Is it an email? - if (strpos(str_replace('{AT}', '@', $email), '@') !== false) { + if (isInString('@', $email)) { // Create email link $result = SQL_QUERY_ESC("SELECT `id` FROM diff --git a/inc/libs/newsletter_functions.php b/inc/libs/newsletter_functions.php index b5159ca8ea..1cb6390749 100644 --- a/inc/libs/newsletter_functions.php +++ b/inc/libs/newsletter_functions.php @@ -50,7 +50,9 @@ function insertNewsletterUrls ($text) { // See ext-html.php if you want to add more URL ends... foreach ($GLOBALS['url_ends'] as $end) { - if (isInString($end, $check)) $check = substr($check, 0, strpos($check, $end)); + if (isInString($end, $check)) { + $check = substr($check, 0, strpos($check, $end)); + } // END - if } // END - foreach // Now replace the URL against anchor container and pray... diff --git a/inc/libs/wernis_functions.php b/inc/libs/wernis_functions.php index f3f18392ac..0c64af809e 100644 --- a/inc/libs/wernis_functions.php +++ b/inc/libs/wernis_functions.php @@ -111,7 +111,7 @@ function WERNIS_SEND_REQUEST ($scriptName, $requestData = array()) { $response = sendPostRequest($requestString, $requestData); // Check the response header if all is fine - if (strpos($response[0], '200') === false) { + if (!isInString('200', $response[0])) { // Something bad happend... :( return array( 'status' => 'request_error', diff --git a/inc/modules/admin/admin-inc.php b/inc/modules/admin/admin-inc.php index 308939d9b8..886fd1d07d 100644 --- a/inc/modules/admin/admin-inc.php +++ b/inc/modules/admin/admin-inc.php @@ -594,7 +594,7 @@ function adminAddMenuSelectionBox ($menu, $type, $name, $default = '') { // Walk through all files foreach ($menuArray as $file) { // Is this a PHP script? - if ((!isDirectory($file)) && (strpos($file, '' . $type . '-') > -1) && (strpos($file, '.php') > 0)) { + if ((!isDirectory($file)) && (isInString('' . $type . '-', $file)) && (isInString('.php', $file))) { // Then test if the file is readable $test = sprintf("inc/modules/%s/%s", $menu, $file); @@ -1398,7 +1398,7 @@ function adminTestProxySettings ($settingsArray) { $content = sendGetRequest('check-updates3.php'); // Is the first line with "200 OK"? - $valid = (strpos($content[0], '200 OK') !== false); + $valid = isInString('200 OK', $content[0]); // Return result return $valid; diff --git a/inc/modules/admin/what-config_points.php b/inc/modules/admin/what-config_points.php index 0c60e88fe5..f64589d016 100644 --- a/inc/modules/admin/what-config_points.php +++ b/inc/modules/admin/what-config_points.php @@ -134,7 +134,8 @@ WHERE } // END - switch if ((isSqlsValid()) && (isSqlsValid())) { - if (strpos($GLOBALS['sqls'][0], 'INSERT') > -1) { + // Is INSERT there? + if (isInString('INSERT', $GLOBALS['sqls'][0])) { $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `level`=%s LIMIT 1", array(bigintval(postRequestParameter('level'))), __FILE__, __LINE__); SQL_FREERESULT($result); diff --git a/inc/modules/admin/what-usage.php b/inc/modules/admin/what-usage.php index fe040c30e3..ed7f4adfb2 100644 --- a/inc/modules/admin/what-usage.php +++ b/inc/modules/admin/what-usage.php @@ -59,7 +59,9 @@ if (isGetRequestParameterSet('image')) { getConfig('usage_base') ); } else { - if (strpos(getRequestParameter('image'), "\\") > 0) setGetRequestParameter('image', substr(getRequestParameter('image'), 0, strpos(getRequestParameter('image'), "\\"))); + if (strpos(getRequestParameter('image'), "\\") > 0) { + setGetRequestParameter('image', substr(getRequestParameter('image'), 0, strpos(getRequestParameter('image'), "\\"))); + } // END - if $FQFN = sprintf("%s%s/%s_usage_%s.png", getPath(), getConfig('usage_base'), diff --git a/inc/modules/member/what-order.php b/inc/modules/member/what-order.php index e1587709af..eedeef39b2 100644 --- a/inc/modules/member/what-order.php +++ b/inc/modules/member/what-order.php @@ -92,7 +92,7 @@ LIMIT 1", $url = ''; if (getConfig('allow_url_in_text') == 'Y') { // Test submitted text against some filters (length, URLs in text etc.) - if ((strpos(strtolower(postRequestParameter('text')), 'https://') > -1) || (strpos(strtolower(postRequestParameter('text')), 'http://') > -1) || (strpos(strtolower(postRequestParameter('text')), "www") > -1)) { + if ((isInStringIgnoreCase('https://', postRequestParameter('text'))) || (isInStringIgnoreCase('http://', postRequestParameter('text'))) || (isInStringIgnoreCase('www', postRequestParameter('text')))) { // URL found $url = 'modules.php?module=login&what=order&code=' . getCode('URL_FOUND'); } // END - if @@ -111,7 +111,7 @@ LIMIT 1", if (getConfig('allow_url_in_subject') == 'Y') { // Check the subject line for issues setPostRequestParameter('subject', str_replace("\\", '[nl]', substr(postRequestParameter('subject'), 0, 200))); - if ((strpos(strtolower(postRequestParameter('subject')), 'http://') > -1) || (strpos(strtolower(postRequestParameter('subject')), "www") > -1)) { + if ((isInStringIgnoreCase('https://', postRequestParameter('subject'))) || (isInStringIgnoreCase('http://', postRequestParameter('subject'))) || (isInStringIgnoreCase('www', postRequestParameter('subject')))) { // URL in subject found $url = 'modules.php?module=login&what=order&code=' . getCode('SUBJECT_URL'); } // END - if diff --git a/inc/template-functions.php b/inc/template-functions.php index 36212e608a..8de9960c53 100644 --- a/inc/template-functions.php +++ b/inc/template-functions.php @@ -182,13 +182,13 @@ function compileFinalOutput () { // Compress it? /** * @TODO On some pages this is buggy - if (!empty($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos('gzip', $_SERVER['HTTP_ACCEPT_ENCODING']) !== null)) { + if (!empty($_SERVER['HTTP_ACCEPT_ENCODING']) && (isInStringIgnoreCase('gzip', $_SERVER['HTTP_ACCEPT_ENCODING']))) { // Compress it for HTTP gzip $GLOBALS['output'] = gzencode($GLOBALS['output'], 9); // Add header sendHeader('Content-Encoding: gzip'); - } elseif (!empty($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos('deflate', $_SERVER['HTTP_ACCEPT_ENCODING']) !== null)) { + } elseif (!empty($_SERVER['HTTP_ACCEPT_ENCODING']) && (isInStringIgnoreCase('deflate', $_SERVER['HTTP_ACCEPT_ENCODING']))) { // Compress it for HTTP deflate $GLOBALS['output'] = gzcompress($GLOBALS['output'], 9); @@ -213,7 +213,7 @@ function doFinalCompilation ($code, $insertComments = true, $enableCodes = true) $count = 0; // Compile all out - while (((strpos($code, '{--') !== false) || (strpos($code, '{DQUOTE}') !== false) || (strpos($code, '{?') !== false) || (strpos($code, '{%') !== false)) && ($count < 7)) { + while (((isInString('{--', $code)) || (isInString('{DQUOTE}', $code)) || (isInString('{?', $code)) || (isInString('{%', $code) !== false)) && ($count < 7)) { // Init common variables $content = array(); $newContent = ''; @@ -314,7 +314,7 @@ function loadTemplate ($template, $return = false, $content = array(), $compileC // Do we have to compile the code? $ret = ''; - if ((strpos($GLOBALS['tpl_content'][$template], '$') !== false) || (strpos($GLOBALS['tpl_content'][$template], '{--') !== false) || (strpos($GLOBALS['tpl_content'][$template], '{?') !== false) || (strpos($GLOBALS['tpl_content'][$template], '{%') !== false)) { + if ((isInString('$', $GLOBALS['tpl_content'][$template])) || (isInString('{--', $GLOBALS['tpl_content'][$template])) || (isInString('{?', $GLOBALS['tpl_content'][$template])) || (isInString('{%', $GLOBALS['tpl_content'][$template]))) { // Normal HTML output? if (isHtmlOutputMode()) { // Add surrounding HTML comments to help finding bugs faster diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index 548aa6562e..6266dbed5b 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -1144,7 +1144,7 @@ function sendRawRedirect ($url) { // check if running on IIS < 6 with CGI-PHP if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) && - (strpos($_SERVER['GATEWAY_INTERFACE'], 'CGI') !== false) && + (isInString('CGI', $_SERVER['GATEWAY_INTERFACE'])) && (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) && ($matches[1] < 6)) { // Send the IIS header -- 2.39.5