diff --git a/changelog.php b/changelog.php index 5066ffe03e..7d42ea185a 100644 --- a/changelog.php +++ b/changelog.php @@ -23,7 +23,7 @@ $filename = CHANGELOG_FILE; if (is_readable($filename)) { // Test if the if is in a compressed format - if (substr($filename, -3) == '.gz') { + if ($GLOBALS['PMA_String']->substr($filename, -3) == '.gz') { ob_start(); readgzfile($filename); $changelog = ob_get_contents(); diff --git a/db_datadict.php b/db_datadict.php index bb0f4eba0a..8fa41c8488 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -36,7 +36,7 @@ PMA_Util::checkParameters(array('db')); /** * Defines the url to return to in case of error in a sql statement */ -if (strlen($table)) { +if ($GLOBALS['PMA_String']->strlen($table)) { $err_url = 'tbl_sql.php?' . PMA_URL_getCommon($db, $table); } else { $err_url = 'db_sql.php?' . PMA_URL_getCommon($db); diff --git a/db_operations.php b/db_operations.php index 2e88b45d8c..9d48bb3009 100644 --- a/db_operations.php +++ b/db_operations.php @@ -32,7 +32,9 @@ $scripts->addFile('db_operations.js'); /** * Rename/move or copy database */ -if (strlen($GLOBALS['db']) +/** @var PMA_String $pmaString */ +$pmaString = $GLOBALS['PMA_String']; +if ($pmaString->strlen($GLOBALS['db']) && (! empty($_REQUEST['db_rename']) || ! empty($_REQUEST['db_copy'])) ) { if (! empty($_REQUEST['db_rename'])) { @@ -41,7 +43,9 @@ if (strlen($GLOBALS['db']) $move = false; } - if (! isset($_REQUEST['newname']) || ! strlen($_REQUEST['newname'])) { + if (! isset($_REQUEST['newname']) + || ! $pmaString->strlen($_REQUEST['newname']) + ) { $message = PMA_Message::error(__('The database name is empty!')); } else { $sql_query = ''; // in case target db exists diff --git a/db_printview.php b/db_printview.php index edb25d82da..56edcbe9c4 100644 --- a/db_printview.php +++ b/db_printview.php @@ -59,7 +59,7 @@ if ($num_tables == 0) { $odd_row = true; foreach ($tables as $sts_data) { if (PMA_Table::isMerge($db, $sts_data['TABLE_NAME']) - || strtoupper($sts_data['ENGINE']) == 'FEDERATED' + || $GLOBALS['PMA_String']->strtoupper($sts_data['ENGINE']) == 'FEDERATED' ) { $merged_size = true; } else { diff --git a/examples/openid.php b/examples/openid.php index bc0a6bf902..804fa4c0a8 100644 --- a/examples/openid.php +++ b/examples/openid.php @@ -79,7 +79,7 @@ $base .= '://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']; $realm = $base . '/'; $returnTo = $base . dirname($_SERVER['PHP_SELF']); -if ($returnTo[strlen($returnTo) - 1] != '/') { +if ($returnTo[$GLOBALS['PMA_String']->strlen($returnTo) - 1] != '/') { $returnTo .= '/'; } $returnTo .= 'openid.php'; diff --git a/export.php b/export.php index b8e46d4dcf..f861ac7be2 100644 --- a/export.php +++ b/export.php @@ -238,9 +238,13 @@ if (!defined('TESTSUITE')) { } // Generate error url and check for needed variables + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; if ($export_type == 'server') { $err_url = 'server_export.php?' . PMA_URL_getCommon(); - } elseif ($export_type == 'database' && strlen($db)) { + } elseif ($export_type == 'database' + && $pmaString->strlen($db) + ) { $err_url = 'db_export.php?' . PMA_URL_getCommon($db); // Check if we have something to export if (isset($table_select)) { @@ -248,7 +252,9 @@ if (!defined('TESTSUITE')) { } else { $tables = array(); } - } elseif ($export_type == 'table' && strlen($db) && strlen($table)) { + } elseif ($export_type == 'table' && $pmaString->strlen($db) + && $pmaString->strlen($table) + ) { $err_url = 'tbl_export.php?' . PMA_URL_getCommon($db, $table); } else { PMA_fatalError(__('Bad parameters!')); diff --git a/file_echo.php b/file_echo.php index d910b74e28..21b16796e3 100644 --- a/file_echo.php +++ b/file_echo.php @@ -41,16 +41,26 @@ if (isset($_REQUEST['filename']) && isset($_REQUEST['image'])) { $filename = $_REQUEST['filename']; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + /* Decode data */ if ($extension != 'svg') { - $data = substr($_REQUEST['image'], strpos($_REQUEST['image'], ',') + 1); + $data = $pmaString->substr( + $_REQUEST['image'], + $pmaString->strpos($_REQUEST['image'], ',') + 1 + ); $data = base64_decode($data); } else { $data = $_REQUEST['image']; } /* Send download header */ - PMA_downloadHeader($filename, $_REQUEST['type'], strlen($data)); + PMA_downloadHeader( + $filename, + $_REQUEST['type'], + $pmaString->strlen($data) + ); /* Send data */ echo $data; diff --git a/gis_data_editor.php b/gis_data_editor.php index 546f700fb7..57add856c2 100644 --- a/gis_data_editor.php +++ b/gis_data_editor.php @@ -40,16 +40,21 @@ $gis_types = array( 'GEOMETRYCOLLECTION' ); +/** @var PMA_String $pmaString */ +$pmaString = $GLOBALS['PMA_String']; + // Extract type from the initial call and make sure that it's a valid one. -// Extract from field's values if availbale, if not use the column type passed. +// Extract from field's values if available, if not use the column type passed. if (! isset($gis_data['gis_type'])) { if (isset($_REQUEST['type']) && $_REQUEST['type'] != '') { - $gis_data['gis_type'] = strtoupper($_REQUEST['type']); + $gis_data['gis_type'] = $pmaString->strtoupper($_REQUEST['type']); } if (isset($_REQUEST['value']) && trim($_REQUEST['value']) != '') { - $start = (substr($_REQUEST['value'], 0, 1) == "'") ? 1 : 0; - $gis_data['gis_type'] = substr( - $_REQUEST['value'], $start, strpos($_REQUEST['value'], "(") - $start + $start = ($pmaString->substr($_REQUEST['value'], 0, 1) == "'") ? 1 : 0; + $gis_data['gis_type'] = $pmaString->substr( + $_REQUEST['value'], + $start, + $pmaString->strpos($_REQUEST['value'], "(") - $start ); } if ((! isset($gis_data['gis_type'])) diff --git a/import.php b/import.php index 046b08bc59..ae8d48d517 100644 --- a/import.php +++ b/import.php @@ -97,7 +97,7 @@ $_SESSION['Import_message']['go_back_url'] = null; // default values $GLOBALS['reload'] = false; -// Use to identify curren cycle is executing +// Use to identify current cycle is executing // a multiquery statement or stored routine if (!isset($_SESSION['is_multi_query'])) { $_SESSION['is_multi_query'] = false; @@ -222,6 +222,8 @@ PMA_Util::checkParameters(array('import_type', 'format')); // We don't want anything special in format $format = PMA_securePath($format); +/** @var PMA_String $pmaString */ +$pmaString = $GLOBALS['PMA_String']; // Create error and goto url if ($import_type == 'table') { @@ -238,17 +240,17 @@ if ($import_type == 'table') { $goto = 'server_import.php'; } else { if (empty($goto) || !preg_match('@^(server|db|tbl)(_[a-z]*)*\.php$@i', $goto)) { - if (strlen($table) && strlen($db)) { + if ($pmaString->strlen($table) && $pmaString->strlen($db)) { $goto = 'tbl_structure.php'; - } elseif (strlen($db)) { + } elseif ($pmaString->strlen($db)) { $goto = 'db_structure.php'; } else { $goto = 'server_sql.php'; } } - if (strlen($table) && strlen($db)) { + if ($pmaString->strlen($table) && $pmaString->strlen($db)) { $common = PMA_URL_getCommon($db, $table); - } elseif (strlen($db)) { + } elseif ($pmaString->strlen($db)) { $common = PMA_URL_getCommon($db); } else { $common = PMA_URL_getCommon(); @@ -266,7 +268,7 @@ if (basename($_SERVER['SCRIPT_NAME']) === 'import.php') { } -if (strlen($db)) { +if ($pmaString->strlen($db)) { $GLOBALS['dbi']->selectDb($db); } @@ -390,12 +392,13 @@ if ($memory_limit == -1) { } // Calculate value of the limit -if (strtolower(substr($memory_limit, -1)) == 'm') { - $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024; -} elseif (strtolower(substr($memory_limit, -1)) == 'k') { - $memory_limit = (int)substr($memory_limit, 0, -1) * 1024; -} elseif (strtolower(substr($memory_limit, -1)) == 'g') { - $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024 * 1024; +if ($pmaString->strtolower($pmaString->substr($memory_limit, -1)) == 'm') { + $memory_limit = (int)$pmaString->substr($memory_limit, 0, -1) * 1024 * 1024; +} elseif ($pmaString->strtolower($pmaString->substr($memory_limit, -1)) == 'k') { + $memory_limit = (int)$pmaString->substr($memory_limit, 0, -1) * 1024; +} elseif ($pmaString->strtolower($pmaString->substr($memory_limit, -1)) == 'g') { + $memory_limit + = (int)$pmaString->substr($memory_limit, 0, -1) * 1024 * 1024 * 1024; } else { $memory_limit = (int)$memory_limit; } @@ -584,7 +587,7 @@ if (! $error && isset($skip)) { $sql_data = array('valid_sql' => array(), 'valid_queries' => 0); if (! $error) { - // Check for file existance + // Check for file existence include_once "libraries/plugin_interface.lib.php"; $import_plugin = PMA_getPlugin( "import", @@ -677,7 +680,8 @@ if (isset($message)) { // in case of a query typed in the query window // (but if the query is too large, in case of an imported file, the parser // can choke on it so avoid parsing) -if (strlen($sql_query) <= $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) { +if ($pmaString->strlen($sql_query) <= $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] +) { include_once 'libraries/parse_analyze.inc.php'; } diff --git a/import_status.php b/import_status.php index 45e11fcd31..6b6e04b369 100644 --- a/import_status.php +++ b/import_status.php @@ -32,9 +32,12 @@ if (version_compare(PHP_VERSION, '5.4.0', '>=') define('UPLOAD_PREFIX', ini_get('session.upload_progress.prefix')); session_start(); + /** @var PMA_String $pmaString / + $pmaString = $GLOBALS['PMA_String']; foreach ($_SESSION as $key => $value) { // only copy session-prefixed data - if (substr($key, 0, strlen(UPLOAD_PREFIX)) == UPLOAD_PREFIX) { + if ($pmaString->substr($key, 0, $pmaString->strlen(UPLOAD_PREFIX)) + == UPLOAD_PREFIX) { $sessionupload[$key] = $value; } } @@ -61,9 +64,12 @@ if (defined('SESSIONUPLOAD')) { $_SESSION[$key] = $value; } + /** @var PMA_String $pmaString / + $pmaString = $GLOBALS['PMA_String']; // remove session upload data that are not set anymore foreach ($_SESSION as $key => $value) { - if (substr($key, 0, strlen(UPLOAD_PREFIX)) == UPLOAD_PREFIX + if ($pmaString->substr($key, 0, $pmaString->strlen(UPLOAD_PREFIX)) + == UPLOAD_PREFIX && ! isset($sessionupload[$key]) ) { unset($_SESSION[$key]); diff --git a/index.php b/index.php index bdae1102f1..15be026dcd 100644 --- a/index.php +++ b/index.php @@ -553,20 +553,25 @@ if (isset($GLOBALS['dbi']) && !PMA_DRIZZLE && $cfg['ServerLibraryDifference_DisableWarning'] == false ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $_client_info = $GLOBALS['dbi']->getClientInfo(); if ($server > 0 - && strpos($_client_info, 'mysqlnd') === false - && substr(PMA_MYSQL_CLIENT_API, 0, 3) != substr(PMA_MYSQL_INT_VERSION, 0, 3) + && $pmaString->strpos($_client_info, 'mysqlnd') === false + && $pmaString->substr(PMA_MYSQL_CLIENT_API, 0, 3) != $pmaString->substr( + PMA_MYSQL_INT_VERSION, 0, 3 + ) ) { trigger_error( PMA_sanitize( sprintf( __('Your PHP MySQL library version %s differs from your MySQL server version %s. This may cause unpredictable behavior.'), $_client_info, - substr( + $pmaString->substr( PMA_MYSQL_STR_VERSION, 0, - strpos(PMA_MYSQL_STR_VERSION . '-', '-') + $pmaString->strpos(PMA_MYSQL_STR_VERSION . '-', '-') ) ) ), diff --git a/libraries/Advisor.class.php b/libraries/Advisor.class.php index 61ce36ec71..593d55a996 100644 --- a/libraries/Advisor.class.php +++ b/libraries/Advisor.class.php @@ -382,6 +382,9 @@ class Advisor $ruleNo = -1; $ruleLine = -1; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + for ($i = 0; $i < $numLines; $i++) { $line = $file[$i]; if ($line == "" || $line[0] == '#') { @@ -389,7 +392,7 @@ class Advisor } // Reading new rule - if (substr($line, 0, 4) == 'rule') { + if ($pmaString->substr($line, 0, 4) == 'rule') { if ($ruleLine > 0) { $errors[] = sprintf( __( @@ -443,7 +446,9 @@ class Advisor ); continue; } - $rules[$ruleNo][$ruleSyntax[$ruleLine]] = chop(substr($line, 1)); + $rules[$ruleNo][$ruleSyntax[$ruleLine]] = chop( + $pmaString->substr($line, 1) + ); $lines[$ruleNo][$ruleSyntax[$ruleLine]] = $i + 1; $ruleLine += 1; } diff --git a/libraries/Config.class.php b/libraries/Config.class.php index a0a8707533..d3b33fc8f1 100644 --- a/libraries/Config.class.php +++ b/libraries/Config.class.php @@ -148,7 +148,7 @@ class PMA_Config } // disable output-buffering (if set to 'auto') for IE6, else enable it. - if (strtolower($this->get('OBGzip')) == 'auto') { + if ($GLOBALS['PMA_String']->strtolower($this->get('OBGzip')) == 'auto') { if ($this->get('PMA_USR_BROWSER_AGENT') == 'IE' && $this->get('PMA_USR_BROWSER_VER') >= 6 && $this->get('PMA_USR_BROWSER_VER') < 7 @@ -176,16 +176,19 @@ class PMA_Config $HTTP_USER_AGENT = ''; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // 1. Platform - if (strstr($HTTP_USER_AGENT, 'Win')) { + if ($pmaString->strstr($HTTP_USER_AGENT, 'Win')) { $this->set('PMA_USR_OS', 'Win'); - } elseif (strstr($HTTP_USER_AGENT, 'Mac')) { + } elseif ($pmaString->strstr($HTTP_USER_AGENT, 'Mac')) { $this->set('PMA_USR_OS', 'Mac'); - } elseif (strstr($HTTP_USER_AGENT, 'Linux')) { + } elseif ($pmaString->strstr($HTTP_USER_AGENT, 'Linux')) { $this->set('PMA_USR_OS', 'Linux'); - } elseif (strstr($HTTP_USER_AGENT, 'Unix')) { + } elseif ($pmaString->strstr($HTTP_USER_AGENT, 'Unix')) { $this->set('PMA_USR_OS', 'Unix'); - } elseif (strstr($HTTP_USER_AGENT, 'OS/2')) { + } elseif ($pmaString->strstr($HTTP_USER_AGENT, 'OS/2')) { $this->set('PMA_USR_OS', 'OS/2'); } else { $this->set('PMA_USR_OS', 'Other'); @@ -260,7 +263,7 @@ class PMA_Config ); $this->set('PMA_USR_BROWSER_AGENT', 'SAFARI'); // Firefox - } elseif (! strstr($HTTP_USER_AGENT, 'compatible') + } elseif (! $pmaString->strstr($HTTP_USER_AGENT, 'compatible') && preg_match('@Firefox/([\w.]+)@', $HTTP_USER_AGENT, $log_version) ) { $this->set( @@ -288,23 +291,28 @@ class PMA_Config { if ($this->get('GD2Available') == 'yes') { $this->set('PMA_IS_GD2', 1); - } elseif ($this->get('GD2Available') == 'no') { + return; + } + + if ($this->get('GD2Available') == 'no') { $this->set('PMA_IS_GD2', 0); - } else { - if (!@function_exists('imagecreatetruecolor')) { - $this->set('PMA_IS_GD2', 0); + return; + } + + if (!@function_exists('imagecreatetruecolor')) { + $this->set('PMA_IS_GD2', 0); + return; + } + + if (@function_exists('gd_info')) { + $gd_nfo = gd_info(); + if ($GLOBALS['PMA_String']->strstr($gd_nfo["GD Version"], '2.')) { + $this->set('PMA_IS_GD2', 1); } else { - if (@function_exists('gd_info')) { - $gd_nfo = gd_info(); - if (strstr($gd_nfo["GD Version"], '2.')) { - $this->set('PMA_IS_GD2', 1); - } else { - $this->set('PMA_IS_GD2', 0); - } - } else { - $this->set('PMA_IS_GD2', 0); - } + $this->set('PMA_IS_GD2', 0); } + } else { + $this->set('PMA_IS_GD2', 0); } } @@ -426,12 +434,16 @@ class PMA_Config if (! $ref_head = @file_get_contents($git_folder . '/HEAD')) { return; } + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; $branch = false; // are we on any branch? - if (strstr($ref_head, '/')) { - $ref_head = substr(trim($ref_head), 5); - if (substr($ref_head, 0, 11) === 'refs/heads/') { - $branch = substr($ref_head, 11); + //@TODO Implement strstr in PMA_String + if ($pmaString->strstr($ref_head, '/')) { + $ref_head = $pmaString->substr(trim($ref_head), 5); + if ($pmaString->substr($ref_head, 0, 11) === 'refs/heads/') { + $branch = $pmaString->substr($ref_head, 11); } else { $branch = basename($ref_head); } @@ -479,8 +491,9 @@ class PMA_Config $commit = false; if (! isset($_SESSION['PMA_VERSION_COMMITDATA_' . $hash])) { - $git_file_name = $git_folder . '/objects/' . substr($hash, 0, 2) - . '/' . substr($hash, 2); + $git_file_name = $git_folder . '/objects/' + . $pmaString->substr($hash, 0, 2) + . '/' . $pmaString->substr($hash, 2); if (file_exists($git_file_name) ) { if (! $commit = @file_get_contents($git_file_name)) { return; @@ -499,7 +512,7 @@ class PMA_Config // packs. (to look for them in .git/object/pack directory later) foreach (explode("\n", $packs) as $line) { // skip blank lines - if (strlen(trim($line)) == 0) { + if ($pmaString->strlen(trim($line)) == 0) { continue; } // skip non pack lines @@ -507,7 +520,7 @@ class PMA_Config continue; } // parse names - $pack_names[] = substr($line, 2); + $pack_names[] = $pmaString->substr($line, 2); } } else { // '.git/objects/info/packs' file can be missing @@ -522,13 +535,13 @@ class PMA_Config $file_name = $file_info->getFilename(); // if this is a .pack file if ($file_info->isFile() - && substr($file_name, -5) == '.pack' + && $pmaString->substr($file_name, -5) == '.pack' ) { $pack_names[] = $file_name; } } } - $hash = strtolower($hash); + $hash = $pmaString->strtolower($hash); foreach ($pack_names as $pack_name) { $index_name = str_replace('.pack', '.idx', $pack_name); @@ -540,19 +553,22 @@ class PMA_Config continue; } // check format - if (substr($index_data, 0, 4) != "\377tOc") { + if ($pmaString->substr($index_data, 0, 4) != "\377tOc") { continue; } // check version - $version = unpack('N', substr($index_data, 4, 4)); + $version = unpack('N', $pmaString->substr($index_data, 4, 4)); if ($version[1] != 2) { continue; } // parse fanout table - $fanout = unpack("N*", substr($index_data, 8, 256 * 4)); + $fanout = unpack( + "N*", + $pmaString->substr($index_data, 8, 256 * 4) + ); // find where we should search - $firstbyte = intval(substr($hash, 0, 2), 16); + $firstbyte = intval($pmaString->substr($hash, 0, 2), 16); // array is indexed from 1 and we need to get // previous entry for start if ($firstbyte == 0) { @@ -566,9 +582,9 @@ class PMA_Config $found = false; $offset = 8 + (256 * 4); for ($position = $start; $position < $end; $position++) { - $sha = strtolower( + $sha = $pmaString->strtolower( bin2hex( - substr( + $pmaString->substr( $index_data, $offset + ($position * 20), 20 ) ) @@ -584,7 +600,8 @@ class PMA_Config // read pack offset $offset = 8 + (256 * 4) + (24 * $fanout[256]); $pack_offset = unpack( - 'N', substr($index_data, $offset + ($position * 4), 4) + 'N', + $pmaString->substr($index_data, $offset + ($position * 4), 4) ); $pack_offset = $pack_offset[1]; @@ -599,14 +616,14 @@ class PMA_Config fseek($pack_file, $pack_offset); // parse header - $header = ord(fread($pack_file, 1)); + $header = $pmaString->ord(fread($pack_file, 1)); $type = ($header >> 4) & 7; $hasnext = ($header & 128) >> 7; $size = $header & 0xf; $offset = 4; while ($hasnext) { - $byte = ord(fread($pack_file, 1)); + $byte = $pmaString->ord(fread($pack_file, 1)); $size |= ($byte & 0x7f) << $offset; $hasnext = ($byte & 128) >> 7; $offset += 7; @@ -769,9 +786,24 @@ class PMA_Config } $httpOk = 'HTTP/1.1 200 OK'; $httpNotFound = 'HTTP/1.1 404 Not Found'; - if (substr($data, 0, strlen($httpOk)) === $httpOk) { - return $get_body ? substr($data, strpos($data, "\r\n\r\n") + 4) : true; - } elseif (substr($data, 0, strlen($httpNotFound)) === $httpNotFound) { + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if ($pmaString->substr($data, 0, $pmaString->strlen($httpOk)) === $httpOk) { + return $get_body + ? $pmaString->substr( + $data, + $pmaString->strpos($data, "\r\n\r\n") + 4 + ) + : true; + } + + $httpNOK = $pmaString->substr( + $data, + 0, + $pmaString->strlen($httpNotFound) + ); + if ($httpNOK === $httpNotFound) { return false; } return null; @@ -1259,7 +1291,9 @@ class PMA_Config $pma_absolute_uri = $this->get('PmaAbsoluteUri'); $is_https = $this->detectHttps(); - if (strlen($pma_absolute_uri) < 5) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if ($pmaString->strlen($pma_absolute_uri) < 5) { $url = array(); // If we don't have scheme, we didn't have full URL so we need to @@ -1355,7 +1389,7 @@ class PMA_Config $path = ''; } // in vhost situations, there could be already an ending slash - if (substr($path, -1) != '/') { + if ($pmaString->substr($path, -1) != '/') { $path .= '/'; } $pma_absolute_uri .= $path; @@ -1377,18 +1411,21 @@ class PMA_Config // Adds a trailing slash et the end of the phpMyAdmin uri if it // does not exist. - if (substr($pma_absolute_uri, -1) != '/') { + if ($pmaString->substr($pma_absolute_uri, -1) != '/') { $pma_absolute_uri .= '/'; } // If URI doesn't start with http:// or https://, we will add // this. - if (substr($pma_absolute_uri, 0, 7) != 'http://' - && substr($pma_absolute_uri, 0, 8) != 'https://' + if ($pmaString->substr($pma_absolute_uri, 0, 7) != 'http://' + && $pmaString->substr($pma_absolute_uri, 0, 8) != 'https://' ) { $pma_absolute_uri = ($is_https ? 'https' : 'http') - . ':' . (substr($pma_absolute_uri, 0, 2) == '//' ? '' : '//') + . ':' + . ( + $pmaString->substr($pma_absolute_uri, 0, 2) == '//' ? '' : '//' + ) . $pma_absolute_uri; } } @@ -1474,14 +1511,15 @@ class PMA_Config */ function checkUpload() { - if (ini_get('file_uploads')) { - $this->set('enable_upload', true); - // if set "php_admin_value file_uploads Off" in httpd.conf - // ini_get() also returns the string "Off" in this case: - if ('off' == strtolower(ini_get('file_uploads'))) { - $this->set('enable_upload', false); - } - } else { + if (!ini_get('file_uploads')) { + $this->set('enable_upload', false); + return; + } + + $this->set('enable_upload', true); + // if set "php_admin_value file_uploads Off" in httpd.conf + // ini_get() also returns the string "Off" in this case: + if ('off' == $GLOBALS['PMA_String']->strtolower(ini_get('file_uploads'))) { $this->set('enable_upload', false); } } @@ -1558,6 +1596,9 @@ class PMA_Config } } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // If we don't have scheme, we didn't have full URL so we need to // dig deeper if (empty($url['scheme'])) { @@ -1565,18 +1606,19 @@ class PMA_Config if (PMA_getenv('HTTP_SCHEME')) { $url['scheme'] = PMA_getenv('HTTP_SCHEME'); } elseif (PMA_getenv('HTTPS') - && strtolower(PMA_getenv('HTTPS')) == 'on' + && $pmaString->strtolower(PMA_getenv('HTTPS')) == 'on' ) { $url['scheme'] = 'https'; // A10 Networks load balancer: } elseif (PMA_getenv('HTTP_HTTPS_FROM_LB') - && strtolower(PMA_getenv('HTTP_HTTPS_FROM_LB')) == 'on' + && $pmaString->strtolower(PMA_getenv('HTTP_HTTPS_FROM_LB')) == 'on' ) { $url['scheme'] = 'https'; } elseif (PMA_getenv('HTTP_X_FORWARDED_PROTO')) { - $url['scheme'] = strtolower(PMA_getenv('HTTP_X_FORWARDED_PROTO')); + $url['scheme'] + = $pmaString->strtolower(PMA_getenv('HTTP_X_FORWARDED_PROTO')); } elseif (PMA_getenv('HTTP_FRONT_END_HTTPS') - && strtolower(PMA_getenv('HTTP_FRONT_END_HTTPS')) == 'on' + && $pmaString->strtolower(PMA_getenv('HTTP_FRONT_END_HTTPS')) == 'on' ) { $url['scheme'] = 'https'; } else { @@ -1815,7 +1857,9 @@ class PMA_Config function setCookie($cookie, $value, $default = null, $validity = null, $httponly = true ) { - if (strlen($value) && null !== $default && $value === $default) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if ($pmaString->strlen($value) && null !== $default && $value === $default) { // default value is used if (isset($_COOKIE[$cookie])) { // remove cookie @@ -1824,7 +1868,7 @@ class PMA_Config return false; } - if (! strlen($value) && isset($_COOKIE[$cookie])) { + if (!$pmaString->strlen($value) && isset($_COOKIE[$cookie])) { // remove cookie, value is empty return $this->removeCookie($cookie); } diff --git a/libraries/DBQbe.class.php b/libraries/DBQbe.class.php index dd14979ec5..fbcca2f34b 100644 --- a/libraries/DBQbe.class.php +++ b/libraries/DBQbe.class.php @@ -334,7 +334,7 @@ class PMA_DbQbe $this->_columnNames[] = $each_column; // increase the width if necessary $this->_form_column_width = max( - strlen($each_column), + $GLOBALS['PMA_String']->strlen($each_column), $this->_form_column_width ); } // end foreach @@ -454,49 +454,53 @@ class PMA_DbQbe $html_output = '
' . __('SQL query:') . '' . "\n"; - if (strstr(strtolower($formatted_sql), 'select')) { + if ($pmaString->strstr($pmaString->strtolower($formatted_sql), 'select') + ) { // please show me help to the error on select $error_msg .= self::showMySQLDocu('SELECT'); } @@ -647,12 +659,12 @@ class PMA_Util 'sql_query' => $the_query, 'show_query' => 1, ); - if (strlen($table)) { + if ($pmaString->strlen($table)) { $_url_params['db'] = $db; $_url_params['table'] = $table; $doedit_goto = ''; - } elseif (strlen($db)) { + } elseif ($pmaString->strlen($db)) { $_url_params['db'] = $db; $doedit_goto = ''; @@ -706,38 +718,38 @@ class PMA_Util $_SESSION['Import_message']['message'] = $error_msg; - if ($exit) { - /** - * If in an Ajax request - * - avoid displaying a Back link - * - use PMA_Response() to transmit the message and exit - */ - if (isset($GLOBALS['is_ajax_request']) - && $GLOBALS['is_ajax_request'] == true - ) { - $response = PMA_Response::getInstance(); - $response->isSuccess(false); - $response->addJSON('message', $error_msg); - exit; - } - if (! empty($back_url)) { - if (strstr($back_url, '?')) { - $back_url .= '&no_history=true'; - } else { - $back_url .= '?no_history=true'; - } - - $_SESSION['Import_message']['go_back_url'] = $back_url; - - $error_msg .= '
' - . strtoupper( - substr($current_grant, 0, strlen($current_grant) - 5) + . $pmaString->strtoupper( + $pmaString->substr( + $current_grant, + 0, + $pmaString->strlen($current_grant) - 5 + ) ) . '
' . "\n" @@ -2692,8 +2737,8 @@ function PMA_getHtmlForUserRights($db_rights, $dbname, ) . "\n" . '
1'; - var_dump($GLOBALS['PMA_String']->isSqlIdentifier($c, false)); + var_dump($pmaString->isSqlIdentifier($c, false)); var_dump($c == '@'); var_dump($c == '.'); var_dump( - $GLOBALS['PMA_String']->isDigit( - $GLOBALS['PMA_String']->substr($sql, $count2 + 1, 1) + $pmaString->isDigit( + $pmaString->substr($sql, $count2 + 1, 1) ) ); var_dump($previous_was_space); @@ -505,16 +506,15 @@ function PMA_SQP_parse($sql) */ // Checks for identifier (alpha or numeric) - if ($GLOBALS['PMA_String']->isSqlIdentifier($c, false) + if ($pmaString->isSqlIdentifier($c, false) || $c == '@' || ($c == '.' - && $GLOBALS['PMA_String']->isDigit( - $GLOBALS['PMA_String']->substr($sql, $count2 + 1, 1) - ) && ($previous_was_space || $previous_was_bracket + && $pmaString->isDigit($pmaString->substr($sql, $count2 + 1, 1)) + && ($previous_was_space || $previous_was_bracket || $previous_was_listsep)) ) { /* DEBUG - echo $GLOBALS['PMA_String']->substr($sql, $count2); + echo $pmaString->substr($sql, $count2); echo ''; */ @@ -531,13 +531,13 @@ function PMA_SQP_parse($sql) $is_digit = ( !$is_identifier && !$is_sql_variable - && $GLOBALS['PMA_String']->isDigit($c) + && $pmaString->isDigit($c) ); $is_hex_digit = ( $is_digit && $c == '0' && $count2 < $len - && $GLOBALS['PMA_String']->substr($sql, $count2, 1) == 'x' + && $pmaString->substr($sql, $count2, 1) == 'x' ); $is_float_digit = $c == '.'; $is_float_digit_exponent = false; @@ -568,12 +568,12 @@ function PMA_SQP_parse($sql) } while (($count2 < $len) - && $GLOBALS['PMA_String']->isSqlIdentifier( - $GLOBALS['PMA_String']->substr($sql, $count2, 1), + && $pmaString->isSqlIdentifier( + $pmaString->substr($sql, $count2, 1), ($is_sql_variable || $is_digit) ) ) { - $c2 = $GLOBALS['PMA_String']->substr($sql, $count2, 1); + $c2 = $pmaString->substr($sql, $count2, 1); if ($is_sql_variable && ($c2 == '.')) { $count2++; continue; @@ -587,7 +587,7 @@ function PMA_SQP_parse($sql) $debugstr = __('Invalid Identifer') . ' @ ' . ($count1+1) . "\n" . 'STR: ' . htmlspecialchars( - $GLOBALS['PMA_String']->substr( + $pmaString->substr( $sql, $count1, $count2 - $count1 ) ); @@ -609,8 +609,8 @@ function PMA_SQP_parse($sql) $is_float_digit = false; } } - if (($is_hex_digit && $GLOBALS['PMA_String']->isHexDigit($c2)) - || ($is_digit && $GLOBALS['PMA_String']->isDigit($c2)) + if (($is_hex_digit && $pmaString->isHexDigit($c2)) + || ($is_digit && $pmaString->isDigit($c2)) ) { $count2++; continue; @@ -623,7 +623,7 @@ function PMA_SQP_parse($sql) } // end while $l = $count2 - $count1; - $str = $GLOBALS['PMA_String']->substr($sql, $count1, $l); + $str = $pmaString->substr($sql, $count1, $l); if ($is_digit || $is_float_digit || $is_hex_digit) { $type = 'digit'; @@ -647,10 +647,10 @@ function PMA_SQP_parse($sql) } // Checks for punct - if ($GLOBALS['PMA_String']->strpos($allpunct_list, $c) !== false) { + if ($pmaString->strpos($allpunct_list, $c) !== false) { while (($count2 < $len) - && $GLOBALS['PMA_String']->strpos( - $allpunct_list, $GLOBALS['PMA_String']->substr( + && $pmaString->strpos( + $allpunct_list, $pmaString->substr( $sql, $count2, 1 ) ) !== false @@ -661,7 +661,7 @@ function PMA_SQP_parse($sql) if ($l == 1) { $punct_data = $c; } else { - $punct_data = $GLOBALS['PMA_String']->substr($sql, $count1, $l); + $punct_data = $pmaString->substr($sql, $count1, $l); } // Special case, sometimes, although two characters are @@ -713,15 +713,15 @@ function PMA_SQP_parse($sql) } elseif (($last2 == '/*') || (($last2 == '--') && ($count2 == $len - || $GLOBALS['PMA_String']->substr($sql, $count2, 1) <= ' ')) + || $pmaString->substr($sql, $count2, 1) <= ' ')) ) { $count2 -= 2; - $punct_data = $GLOBALS['PMA_String']->substr( + $punct_data = $pmaString->substr( $sql, $count1, $count2 - $count1 ); } elseif (($last == '-') || ($last == '+') || ($last == '!')) { $count2--; - $punct_data = $GLOBALS['PMA_String']->substr( + $punct_data = $pmaString->substr( $sql, $count1, $count2 - $count1 ); } elseif ($last != '~') { @@ -748,7 +748,7 @@ function PMA_SQP_parse($sql) $count2++; $debugstr = 'C1 C2 LEN: ' . $count1 . ' ' . $count2 . ' ' . $len . "\n" - . 'STR: ' . $GLOBALS['PMA_String']->substr( + . 'STR: ' . $pmaString->substr( $sql, $count1, $count2 - $count1 ) . "\n"; PMA_SQP_bug($debugstr, $sql); @@ -771,7 +771,9 @@ function PMA_SQP_parse($sql) $d_prev = ''; $d_bef_prev = ''; $d_cur = ''; - $d_next_upper = $t_next == 'alpha' ? strtoupper($d_next) : $d_next; + $d_next_upper = $t_next == 'alpha' + ? $pmaString->strtoupper($d_next) + : $d_next; $d_prev_upper = ''; $d_bef_prev_upper = ''; $d_cur_upper = ''; @@ -790,7 +792,8 @@ function PMA_SQP_parse($sql) if (($i + 1) < $arraysize) { $t_next = $sql_array[$i + 1]['type']; $d_next = $sql_array[$i + 1]['data']; - $d_next_upper = $t_next == 'alpha' ? strtoupper($d_next) : $d_next; + $d_next_upper + = $t_next == 'alpha' ? $pmaString->strtoupper($d_next) : $d_next; } else { $t_next = ''; $d_next = ''; @@ -886,7 +889,8 @@ function PMA_SQP_parse($sql) } } elseif (in_array($d_cur, $mysql_charsets) || in_array($d_cur, $mysql_collations_flat) - || ($d_cur{0} == '_' && in_array(substr($d_cur, 1), $mysql_charsets)) + || ($d_cur{0} == '_' + && in_array($pmaString->substr($d_cur, 1), $mysql_charsets)) ) { $t_suffix = '_charset'; } else { @@ -928,16 +932,19 @@ function PMA_SQP_typeCheck($toCheck, $whatWeWant) $typeSeparator = '_'; if (strcmp($whatWeWant, $toCheck) == 0) { return true; - } else { - if (strpos($whatWeWant, $typeSeparator) === false) { - return strncmp( - $whatWeWant, $toCheck, - strpos($toCheck, $typeSeparator) - ) == 0; - } else { - return false; - } } + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + if ($pmaString->strpos($whatWeWant, $typeSeparator) !== false) { + return false; + } + + return strncmp( + $whatWeWant, $toCheck, + $pmaString->strpos($toCheck, $typeSeparator) + ) == 0; } @@ -1170,6 +1177,9 @@ function PMA_SQP_analyze($arr) */ ); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // loop #1 for each token: select_expr, table_ref for SELECT for ($i = 0; $i < $size; $i++) { @@ -1239,7 +1249,7 @@ function PMA_SQP_analyze($arr) } // ============================================================== if ($arr[$i]['type'] == 'alpha_functionName') { - $upper_data = strtoupper($arr[$i]['data']); + $upper_data = $pmaString->strtoupper($arr[$i]['data']); if ($upper_data =='EXTRACT') { $in_extract = true; $number_of_brackets_in_extract = 0; @@ -1254,7 +1264,7 @@ function PMA_SQP_analyze($arr) if ($arr[$i]['type'] == 'alpha_reservedWord') { // We don't know what type of query yet, so run this if ($subresult['querytype'] == '') { - $subresult['querytype'] = strtoupper($arr[$i]['data']); + $subresult['querytype'] = $pmaString->strtoupper($arr[$i]['data']); } // end if (querytype was empty) // Check if we support this type of query @@ -1265,7 +1275,7 @@ function PMA_SQP_analyze($arr) } // end if (query not supported) // upper once - $upper_data = strtoupper($arr[$i]['data']); + $upper_data = $pmaString->strtoupper($arr[$i]['data']); /** * @todo reset for each query? */ @@ -1399,7 +1409,9 @@ function PMA_SQP_analyze($arr) 'column' => '' ); - if (isset($alias_for_select_expr) && strlen($alias_for_select_expr)) { + if (isset($alias_for_select_expr) + && $pmaString->strlen($alias_for_select_expr) + ) { // we had found an alias for this select expression $subresult['select_expr'][$current_select_expr]['alias'] = $alias_for_select_expr; @@ -1472,7 +1484,9 @@ function PMA_SQP_analyze($arr) 'table_alias' => '', 'table_true_name' => '' ); - if (isset($alias_for_table_ref) && strlen($alias_for_table_ref)) { + if (isset($alias_for_table_ref) + && $pmaString->strlen($alias_for_table_ref) + ) { $subresult['table_ref'][$current_table_ref]['table_alias'] = $alias_for_table_ref; unset($alias_for_table_ref); @@ -1516,7 +1530,7 @@ function PMA_SQP_analyze($arr) $truename = $subresult['table_ref'][$tr]['table_true_name']; for ($se=0; $se <= $current_select_expr; $se++) { if (isset($alias) - && strlen($alias) + && $pmaString->strlen($alias) && $subresult['select_expr'][$se]['table_true_name'] == $alias ) { $subresult['select_expr'][$se]['table_true_name'] @@ -1671,7 +1685,7 @@ function PMA_SQP_analyze($arr) } if ($arr[$i]['type'] == 'alpha_reservedWord') { - $upper_data = strtoupper($arr[$i]['data']); + $upper_data = $pmaString->strtoupper($arr[$i]['data']); if ($upper_data == 'SELECT' && $number_of_brackets > 0) { $in_subquery = true; @@ -1727,7 +1741,9 @@ function PMA_SQP_analyze($arr) } if ($upper_data == 'LIMIT' && ! $in_subquery) { - $section_before_limit = substr($arr['raw'], 0, $arr[$i]['pos'] - 5); + $section_before_limit = $pmaString->substr( + $arr['raw'], 0, $arr[$i]['pos'] - 5 + ); $in_limit = true; $seen_limit = true; $limit_clause = ''; @@ -1744,7 +1760,7 @@ function PMA_SQP_analyze($arr) && $subresult['queryflags']['select_from'] == 1 && ($i + 1) < $size && $arr[$i + 1]['type'] == 'alpha_reservedWord' - && strtoupper($arr[$i + 1]['data']) == 'ANALYSE' + && $pmaString->strtoupper($arr[$i + 1]['data']) == 'ANALYSE' ) { $subresult['queryflags']['is_analyse'] = 1; } @@ -1756,7 +1772,7 @@ function PMA_SQP_analyze($arr) && $subresult['queryflags']['select_from'] == 1 && ($i + 1) < $size && $arr[$i + 1]['type'] == 'alpha_reservedWord' - && strtoupper($arr[$i + 1]['data']) == 'OUTFILE' + && $pmaString->strtoupper($arr[$i + 1]['data']) == 'OUTFILE' ) { $subresult['queryflags']['is_export'] = 1; } @@ -1773,7 +1789,7 @@ function PMA_SQP_analyze($arr) && !isset($subresult['queryflags']['is_group']) && ($i + 1) < $size && $arr[$i + 1]['type'] == 'alpha_functionName' - && strtoupper($arr[$i + 1]['data']) == 'COUNT' + && $pmaString->strtoupper($arr[$i + 1]['data']) == 'COUNT' ) { $subresult['queryflags']['is_count'] = 1; } @@ -1830,10 +1846,13 @@ function PMA_SQP_analyze($arr) && $subresult['queryflags']['select_from'] == 1 && ($i + 1) < $size && $arr[$i + 1]['type'] == 'alpha_reservedWord' - && in_array(strtoupper($arr[$i + 1]['data']), $arrayKeyWords) + && in_array( + $pmaString->strtoupper($arr[$i + 1]['data']), + $arrayKeyWords + ) && ($i + 2) < $size && $arr[$i + 2]['type'] == 'alpha_reservedWord' - && strtoupper($arr[$i + 2]['data']) == 'DISTINCT' + && $pmaString->strtoupper($arr[$i + 2]['data']) == 'DISTINCT' ) { $subresult['queryflags']['is_group'] = 1; } @@ -1913,7 +1932,7 @@ function PMA_SQP_analyze($arr) $sep = ' '; if ($arr[$i]['type'] == 'alpha_functionName') { $sep=''; - $upper_data = strtoupper($arr[$i]['data']); + $upper_data = $pmaString->strtoupper($arr[$i]['data']); if ($upper_data =='GROUP_CONCAT') { $in_group_concat = true; $number_of_brackets_in_group_concat = 0; @@ -1950,10 +1969,13 @@ function PMA_SQP_analyze($arr) // for the presence of INSERT|LOAD DATA if ($arr[$i]['type'] == 'alpha_identifier' - && strtoupper($arr[$i]['data']) == 'DATA' + && $pmaString->strtoupper($arr[$i]['data']) == 'DATA' && ($i - 1) >= 0 && $arr[$i - 1]['type'] == 'alpha_reservedWord' - && in_array(strtoupper($arr[$i - 1]['data']), array("INSERT", "LOAD")) + && in_array( + $pmaString->strtoupper($arr[$i - 1]['data']), + array("INSERT", "LOAD") + ) ) { $subresult['queryflags']['is_insert'] = 1; $subresult['queryflags']['is_affected'] = 1; @@ -1961,7 +1983,7 @@ function PMA_SQP_analyze($arr) // for the presence of SUM|AVG|STD|STDDEV|MIN|MAX|BIT_OR|BIT_AND if ($arr[$i]['type'] == 'alpha_functionName' - && in_array(strtoupper($arr[$i]['data']), $arrayFunctions) + && in_array($pmaString->strtoupper($arr[$i]['data']), $arrayFunctions) && isset($subresult['queryflags']['select_from']) && $subresult['queryflags']['select_from'] == 1 && !isset($subresult['queryflags']['is_group']) @@ -2064,7 +2086,7 @@ function PMA_SQP_analyze($arr) for ($i = 0; $i < $size; $i++) { if ($arr[$i]['type'] == 'alpha_reservedWord') { - $upper_data = strtoupper($arr[$i]['data']); + $upper_data = $pmaString->strtoupper($arr[$i]['data']); if ($upper_data == 'NOT' && $in_timestamp_options) { if (! isset($create_table_fields)) { @@ -2127,7 +2149,7 @@ function PMA_SQP_analyze($arr) if (isset($arr[$i+1]) && $arr[$i+1]['type'] == 'alpha_reservedWord' ) { - $second_upper_data = strtoupper($arr[$i+1]['data']); + $second_upper_data = $pmaString->strtoupper($arr[$i+1]['data']); if ($second_upper_data == 'DELETE') { $clause = 'on_delete'; } @@ -2141,9 +2163,10 @@ function PMA_SQP_analyze($arr) if (isset($clause) && ($arr[$i+2]['type'] == 'alpha_reservedWord' || ($arr[$i+2]['type'] == 'alpha_identifier' - && strtoupper($arr[$i+2]['data'])=='NO')) + && $pmaString->strtoupper($arr[$i+2]['data'])=='NO')) ) { - $third_upper_data = strtoupper($arr[$i+2]['data']); + $third_upper_data = $pmaString + ->strtoupper($arr[$i+2]['data']); if ($third_upper_data == 'CASCADE' || $third_upper_data == 'RESTRICT' ) { @@ -2153,7 +2176,7 @@ function PMA_SQP_analyze($arr) ) { if ($arr[$i+3]['type'] == 'alpha_reservedWord') { $value = $third_upper_data . '_' - . strtoupper($arr[$i+3]['data']); + . $pmaString->strtoupper($arr[$i+3]['data']); } } elseif ($third_upper_data == 'CURRENT_TIMESTAMP') { if ($clause == 'on_update' @@ -2197,7 +2220,7 @@ function PMA_SQP_analyze($arr) } if (($arr[$i]['type'] == 'alpha_columnAttrib')) { - $upper_data = strtoupper($arr[$i]['data']); + $upper_data = $pmaString->strtoupper($arr[$i]['data']); if ($seen_create_table && $in_create_table_fields) { if ($upper_data == 'DEFAULT') { $seen_default = true; @@ -2213,7 +2236,7 @@ function PMA_SQP_analyze($arr) if (($arr[$i]['type'] == 'alpha_columnType') || ($arr[$i]['type'] == 'alpha_functionName' && $seen_create_table) ) { - $upper_data = strtoupper($arr[$i]['data']); + $upper_data = $pmaString->strtoupper($arr[$i]['data']); if ($seen_create_table && $in_create_table_fields && isset($current_identifier) ) { @@ -2429,6 +2452,9 @@ function PMA_SQP_format( $typearr[3] = $arr[$start_token]['type']; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $in_priv_list = false; for ($i = $start_token; $i < $number_of_tokens; $i++) { // DEBUG echo "Loop format " . $arr[$i]['data'] @@ -2464,10 +2490,14 @@ function PMA_SQP_format( $bracketlevel++; $infunction = false; $keyword_brackets_2before = isset( - $keywords_with_brackets_2before[strtoupper($arr[$i - 2]['data'])] + $keywords_with_brackets_2before[ + $pmaString->strtoupper($arr[$i - 2]['data']) + ] ); $keyword_brackets_1before = isset( - $keywords_with_brackets_1before[strtoupper($arr[$i - 1]['data'])] + $keywords_with_brackets_1before[ + $pmaString->strtoupper($arr[$i - 1]['data']) + ] ); // Make sure this array is sorted! if (($typearr[1] == 'alpha_functionName') @@ -2599,7 +2629,7 @@ function PMA_SQP_format( // select * from mysql.user where binary user="root" // binary is marked as alpha_columnAttrib // but should be marked as a reserved word - if (strtoupper($arr[$i]['data']) == 'BINARY' + if ($pmaString->strtoupper($arr[$i]['data']) == 'BINARY' && $typearr[3] == 'alpha_identifier' ) { $after .= ' '; @@ -2615,7 +2645,7 @@ function PMA_SQP_format( // as an identifier name) if ($mode != 'query_only') { - $arr[$i]['data'] = strtoupper($arr[$i]['data']); + $arr[$i]['data'] = $pmaString->strtoupper($arr[$i]['data']); } list($before, $in_priv_list) = PMA_SQP_format_getBeforeAndInPrivList( @@ -2729,9 +2759,11 @@ function PMA_SQP_format_getBeforeAndInPrivList( $arr, $typearr, $keywords_no_newline, $index, $in_priv_list, $space_alpha_reserved_word, $before, $keywords_priv_list ) { + $data = $arr[$index - 1]['data']; + if (!((($typearr[1] != 'alpha_reservedWord') || (($typearr[1] == 'alpha_reservedWord') - && isset($keywords_no_newline[strtoupper($arr[$index - 1]['data'])]))) + && isset($keywords_no_newline[$GLOBALS['PMA_String']->strtoupper($data)]))) && ($typearr[1] != 'punct_level_plus') && (!isset($keywords_no_newline[$arr[$index]['data']]))) ) { @@ -2893,7 +2925,10 @@ function PMA_SQP_formatNone($arr) function PMA_SQP_isKeyWord($column) { global $PMA_SQPdata_forbidden_word; - return in_array(strtoupper($column), $PMA_SQPdata_forbidden_word); + return in_array( + $GLOBALS['PMA_String']->strtoupper($column), + $PMA_SQPdata_forbidden_word + ); } /** diff --git a/libraries/structure.lib.php b/libraries/structure.lib.php index 7d9268f554..95d025e302 100644 --- a/libraries/structure.lib.php +++ b/libraries/structure.lib.php @@ -730,7 +730,7 @@ function PMA_getHtmlForNotNullEngineViewTable($table_is_view, $current_table, $html_output .= '' . ($table_is_view ? __('View') : $current_table['ENGINE']) . ''; - if (strlen($collation)) { + if ($GLOBALS['PMA_String']->strlen($collation)) { $html_output .= '' . $collation . ''; } } @@ -1016,40 +1016,52 @@ function PMA_getServerSlaveStatus($server_slave_status, $truename) $ignored = false; $do = false; include_once 'libraries/replication.inc.php'; - if ($server_slave_status) { - $nbServerSlaveDoDb = count($server_slave_Do_DB); - $nbServerSlaveIgnoreDb = count($server_slave_Ignore_DB); - if ((strlen(array_search($truename, $server_slave_Do_Table)) > 0) - || (strlen(array_search($GLOBALS['db'], $server_slave_Do_DB)) > 0) - || ($nbServerSlaveDoDb == 1 && $nbServerSlaveIgnoreDb == 1) + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + if (!$server_slave_status) { + return array($do, $ignored); + } + + $nbServerSlaveDoDb = count($server_slave_Do_DB); + $nbServerSlaveIgnoreDb = count($server_slave_Ignore_DB); + if (($pmaString->strlen(array_search($truename, $server_slave_Do_Table)) > 0) + || $pmaString->strlen(array_search($GLOBALS['db'], $server_slave_Do_DB)) > 0 + || ($nbServerSlaveDoDb == 1 && $nbServerSlaveIgnoreDb == 1) + ) { + $do = true; + } + foreach ($server_slave_Wild_Do_Table as $db_table) { + $table_part = PMA_extractDbOrTable($db_table, 'table'); + $pattern = "@^" + . $pmaString->substr($table_part, 0, $pmaString->strlen($table_part) - 1) + . "@"; + if (($GLOBALS['db'] == PMA_extractDbOrTable($db_table, 'db')) + && (preg_match($pattern, $truename)) ) { $do = true; } - foreach ($server_slave_Wild_Do_Table as $db_table) { - $table_part = PMA_extractDbOrTable($db_table, 'table'); - $pattern = "@^" . substr($table_part, 0, strlen($table_part) - 1) . "@"; - if (($GLOBALS['db'] == PMA_extractDbOrTable($db_table, 'db')) - && (preg_match($pattern, $truename)) - ) { - $do = true; - } - } + } - if ((strlen(array_search($truename, $server_slave_Ignore_Table)) > 0) - || (strlen(array_search($GLOBALS['db'], $server_slave_Ignore_DB)) > 0) + $search = array_search($GLOBALS['db'], $server_slave_Ignore_DB); + if (($pmaString->strlen(array_search($truename, $server_slave_Ignore_Table)) > 0) + || $pmaString->strlen($search) > 0 + ) { + $ignored = true; + } + foreach ($server_slave_Wild_Ignore_Table as $db_table) { + $table_part = PMA_extractDbOrTable($db_table, 'table'); + $pattern = "@^" + . $pmaString->substr($table_part, 0, $pmaString->strlen($table_part) - 1) + . "@"; + if (($db == PMA_extractDbOrTable($db_table)) + && (preg_match($pattern, $truename)) ) { $ignored = true; } - foreach ($server_slave_Wild_Ignore_Table as $db_table) { - $table_part = PMA_extractDbOrTable($db_table, 'table'); - $pattern = "@^" . substr($table_part, 0, strlen($table_part) - 1) . "@"; - if (($db == PMA_extractDbOrTable($db_table)) - && (preg_match($pattern, $truename)) - ) { - $ignored = true; - } - } } + return array($do, $ignored); } @@ -1353,7 +1365,8 @@ function PMA_getHtmlTableStructureRow($row, $rownum, } $html_output .= ''; - $html_output .= '' . strtoupper($row['Extra']) . ''; + $html_output .= '' + . $GLOBALS['PMA_String']->strtoupper($row['Extra']) . ''; $html_output .= PMA_getHtmlForDropColumn( $tbl_is_view, $db_is_system_schema, @@ -1954,13 +1967,17 @@ function PMA_getHtmlForActionRowInStructureTable($type, $tbl_storage_engine, function PMA_getHtmlForFullTextAction($tbl_storage_engine, $type, $url_query, $row, $titles ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $html_output = ''; if (! empty($tbl_storage_engine) && ($tbl_storage_engine == 'MYISAM' || $tbl_storage_engine == 'ARIA' || $tbl_storage_engine == 'MARIA' || ($tbl_storage_engine == 'INNODB' && PMA_MYSQL_INT_VERSION >= 50604)) - && (strpos($type, 'text') !== false || strpos($type, 'char') !== false) + && ($pmaString->strpos($type, 'text') !== false + || $pmaString->strpos($type, 'char') !== false) ) { $html_output .= 'substr($buf, 0, $pmaString->strpos($buf, "\n")) + ); return Array( 'busy' => $nums[1] + $nums[2] + $nums[3], 'idle' => intval($nums[4]) diff --git a/libraries/tbl_columns_definition_form.inc.php b/libraries/tbl_columns_definition_form.inc.php index 8a9d660bb6..c83215a156 100644 --- a/libraries/tbl_columns_definition_form.inc.php +++ b/libraries/tbl_columns_definition_form.inc.php @@ -124,9 +124,9 @@ for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) { // some types, for example longtext, are reported as // "longtext character set latin7" when their charset and / or collation // differs from the ones of the corresponding database. - $tmp = strpos($type, 'character set'); + $tmp = $pmaString->strpos($type, 'character set'); if ($tmp) { - $type = substr($type, 0, $tmp - 1); + $type = $pmaString->substr($type, 0, $tmp - 1); } // rtrim the type, for cases like "float unsigned" $type = rtrim($type); @@ -154,7 +154,7 @@ for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) { $content_cells[$columnNumber] = PMA_getHtmlForColumnAttributes( $columnNumber, isset($columnMeta) ? $columnMeta : array(), - strtoupper($type), $length_values_input_size, $length, + $pmaString->strtoupper($type), $length_values_input_size, $length, isset($default_current_timestamp) ? $default_current_timestamp : null, isset($extracted_columnspec) ? $extracted_columnspec : null, isset($submit_attribute) ? $submit_attribute : null, diff --git a/libraries/tbl_columns_definition_form.lib.php b/libraries/tbl_columns_definition_form.lib.php index 78b5c9a33c..64369eb582 100644 --- a/libraries/tbl_columns_definition_form.lib.php +++ b/libraries/tbl_columns_definition_form.lib.php @@ -865,10 +865,13 @@ function PMA_getHtmlForColumnComment($columnNumber, $ci, $ci_offset, $columnMeta function PMA_getHtmlForColumnAutoIncrement($columnNumber, $ci, $ci_offset, $columnMeta ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $html = 'strtolower($columnMeta['Extra']) == 'auto_increment' ) { $html .= ' checked="checked"'; } @@ -928,13 +931,15 @@ function PMA_getHtmlForColumnIndexes($columnNumber, $ci, $ci_offset, $columnMeta function PMA_getHtmlForIndexTypeOption($columnNumber, $columnMeta, $type, $key) { - $html = ''; + $html .= '>' . $pmaString->strtoupper($type) . ''; return $html; } @@ -1037,12 +1042,15 @@ function PMA_getHtmlForColumnAttribute($columnNumber, $ci, $ci_offset, $default_current_timestamp = false; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $attribute_types = $GLOBALS['PMA_Types']->getAttributes(); $cnt_attribute_types = count($attribute_types); for ($j = 0; $j < $cnt_attribute_types; $j++) { - $html - .= ' strtoupper($attribute); + if ($attrUpper == $pmaString->strtoupper($attribute_types[$j])) { $html .= ' selected="selected"'; } $html .= '>' . $attribute_types[$j] . ''; @@ -1369,16 +1377,20 @@ function PMA_getFormParamsForOldColumn( } else { $form_params['field_orig[' . $columnNumber . ']'] = ''; } + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // old column type if (isset($columnMeta['Type'])) { // keep in uppercase because the new type will be in uppercase $form_params['field_type_orig[' . $columnNumber . ']'] - = strtoupper($type); + = $pmaString->strtoupper($type); if (isset($columnMeta['column_status']) && !$columnMeta['column_status']['isEditable'] ) { $form_params['field_type[' . $columnNumber . ']'] - = strtoupper($type); + = $pmaString->strtoupper($type); } } else { $form_params['field_type_orig[' . $columnNumber . ']'] = ''; diff --git a/libraries/tbl_indexes.lib.php b/libraries/tbl_indexes.lib.php index 1b6c0f2aee..b5c2a74d9b 100644 --- a/libraries/tbl_indexes.lib.php +++ b/libraries/tbl_indexes.lib.php @@ -19,10 +19,13 @@ if (! defined('PHPMYADMIN')) { */ function PMA_getNameAndTypeOfTheColumns($db, $table) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $columns = array(); foreach ($GLOBALS['dbi']->getColumnsFull($db, $table) as $row) { if (preg_match('@^(set|enum)\((.+)\)$@i', $row['Type'], $tmp)) { - $tmp[2] = substr( + $tmp[2] = $pmaString->substr( preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1 ); $columns[$row['Field']] = $tmp[1] . '(' diff --git a/libraries/tbl_info.inc.php b/libraries/tbl_info.inc.php index c1ed2cd75e..58eb69c633 100644 --- a/libraries/tbl_info.inc.php +++ b/libraries/tbl_info.inc.php @@ -54,6 +54,9 @@ $GLOBALS['showtable'] = PMA_Table::sGetStatusInfo( // and we don't want to mess up the $tbl_storage_engine coming from the form if ($showtable) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if (PMA_Table::isView($GLOBALS['db'], $GLOBALS['table'])) { $tbl_is_view = true; $tbl_storage_engine = __('View'); @@ -61,7 +64,7 @@ if ($showtable) { } else { $tbl_is_view = false; $tbl_storage_engine = isset($showtable['Engine']) - ? strtoupper($showtable['Engine']) + ? $pmaString->strtoupper($showtable['Engine']) : ''; $show_comment = ''; if (isset($showtable['Comment'])) { @@ -97,7 +100,7 @@ if ($showtable) { } } // we need explicit DEFAULT value here (different from '0') - $pack_keys = (! isset($pack_keys) || strlen($pack_keys) == 0) + $pack_keys = (! isset($pack_keys) || $pmaString->strlen($pack_keys) == 0) ? 'DEFAULT' : $pack_keys; unset($create_options, $each_create_option); diff --git a/libraries/tbl_relation.lib.php b/libraries/tbl_relation.lib.php index c32547f1f9..32668eb12c 100644 --- a/libraries/tbl_relation.lib.php +++ b/libraries/tbl_relation.lib.php @@ -48,21 +48,25 @@ function PMA_generateDropdown( */ function PMA_backquoteSplit($text) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $elements = array(); - $final_pos = strlen($text) - 1; + $final_pos = $pmaString->strlen($text) - 1; $pos = 0; while ($pos <= $final_pos) { - $first_backquote = strpos($text, '`', $pos); - $second_backquote = strpos($text, '`', $first_backquote + 1); + $first_backquote = $pmaString->strpos($text, '`', $pos); + $second_backquote = $pmaString->strpos($text, '`', $first_backquote + 1); // after the second one, there might be another one which means // this is an escaped backquote if ($second_backquote < $final_pos && '`' == $text[$second_backquote + 1]) { - $second_backquote = strpos($text, '`', $second_backquote + 2); + $second_backquote + = $pmaString->strpos($text, '`', $second_backquote + 2); } if (false === $first_backquote || false === $second_backquote) { break; } - $elements[] = substr( + $elements[] = $pmaString->substr( $text, $first_backquote, $second_backquote - $first_backquote + 1 ); $pos = $second_backquote + 1; @@ -551,6 +555,9 @@ function PMA_getHtmlForForeignKeyRow($one_key, $odd_row, $columns, $i, $foreign_table = isset($one_key['ref_table_name']) ? $one_key['ref_table_name'] : ''; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // In Drizzle, 'SHOW TABLE STATUS' will show status only for the tables // which are currently in the table cache. Hence we have to use // 'SHOW TABLES' and manully retrieve table engine values. @@ -567,7 +574,7 @@ function PMA_getHtmlForForeignKeyRow($one_key, $odd_row, $columns, $i, 'Engine' ); if (isset($engine) - && strtoupper($engine) == $tbl_storage_engine + && $pmaString->strtoupper($engine) == $tbl_storage_engine ) { $tables[] = $row[0]; } @@ -580,7 +587,7 @@ function PMA_getHtmlForForeignKeyRow($one_key, $odd_row, $columns, $i, ); while ($row = $GLOBALS['dbi']->fetchRow($tables_rs)) { if (isset($row[1]) - && strtoupper($row[1]) == $tbl_storage_engine + && $pmaString->strtoupper($row[1]) == $tbl_storage_engine ) { $tables[] = $row[0]; } @@ -731,12 +738,15 @@ function PMA_sendHtmlForColumnDropdownList() */ function PMA_sendHtmlForTableDropdownList() { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $response = PMA_Response::getInstance(); $tables = array(); $foreign = isset($_REQUEST['foreign']) && $_REQUEST['foreign'] === 'true'; if ($foreign) { - $tbl_storage_engine = strtoupper( + $tbl_storage_engine = $pmaString->strtoupper( PMA_Table::sGetStatusInfo( $_REQUEST['db'], $_REQUEST['table'], @@ -759,7 +769,7 @@ function PMA_sendHtmlForTableDropdownList() while ($row = $GLOBALS['dbi']->fetchArray($tables_rs)) { if (isset($row['Engine']) - && strtoupper($row['Engine']) == $tbl_storage_engine + && $pmaString->strtoupper($row['Engine']) == $tbl_storage_engine ) { $tables[] = htmlspecialchars($row['Name']); } @@ -774,7 +784,7 @@ function PMA_sendHtmlForTableDropdownList() ); while ($row = $GLOBALS['dbi']->fetchArray($tables_rs)) { if ($foreign && PMA_DRIZZLE) { - $engine = strtoupper( + $engine = $pmaString->strtoupper( PMA_Table::sGetStatusInfo( $_REQUEST['foreignDb'], $row[0], @@ -1126,63 +1136,65 @@ function PMA_handleUpdateForForeignKey($multi_edit_columns_name, $master_field_m } } $tmp_error_create = false; - if ($create) { - $create_query = PMA_getSQLToCreateForeignKey( - $table, $master_field, $foreign_db, $foreign_table, $foreign_field, - $_REQUEST['constraint_name'][$master_field_md5], - $options_array[$_REQUEST['on_delete'][$master_field_md5]], - $options_array[$_REQUEST['on_update'][$master_field_md5]] - ); + if (!$create) { + return array($html_output, $preview_sql_data); + } - if (! $preview_sql) { - $display_query .= $create_query . "\n"; - $GLOBALS['dbi']->tryQuery($create_query); - $tmp_error_create = $GLOBALS['dbi']->getError(); - if (! empty($tmp_error_create)) { - $seen_error = true; + $create_query = PMA_getSQLToCreateForeignKey( + $table, $master_field, $foreign_db, $foreign_table, $foreign_field, + $_REQUEST['constraint_name'][$master_field_md5], + $options_array[$_REQUEST['on_delete'][$master_field_md5]], + $options_array[$_REQUEST['on_update'][$master_field_md5]] + ); - if (substr($tmp_error_create, 1, 4) == '1005') { - $message = PMA_Message::error( - __('Error creating foreign key on %1$s (check data types)') - ); - $message->addParam(implode(', ', $master_field)); - $html_output .= $message->getDisplay(); - } else { - $html_output .= PMA_Util::mysqlDie( - $tmp_error_create, $create_query, false, '', false - ); - } - $html_output .= PMA_Util::showMySQLDocu( - 'InnoDB_foreign_key_constraints' - ) . "\n"; - } - } else { - $preview_sql_data .= $create_query . "\n"; - } + if (! $preview_sql) { + $display_query .= $create_query . "\n"; + $GLOBALS['dbi']->tryQuery($create_query); + $tmp_error_create = $GLOBALS['dbi']->getError(); + if (! empty($tmp_error_create)) { + $seen_error = true; - // this is an alteration and the old constraint has been dropped - // without creation of a new one - if ($drop && $create && empty($tmp_error_drop) - && ! empty($tmp_error_create) - ) { - // a rollback may be better here - $sql_query_recreate = '# Restoring the dropped constraint...' . "\n"; - $sql_query_recreate .= PMA_getSQLToCreateForeignKey( - $table, - $master_field, - $existrel_foreign[$master_field_md5]['ref_db_name'], - $existrel_foreign[$master_field_md5]['ref_table_name'], - $existrel_foreign[$master_field_md5]['ref_index_list'], - $existrel_foreign[$master_field_md5]['constraint'], - $options_array[$existrel_foreign[$master_field_md5]['on_delete']], - $options_array[$existrel_foreign[$master_field_md5]['on_update']] - ); - if (! $preview_sql) { - $display_query .= $sql_query_recreate . "\n"; - $GLOBALS['dbi']->tryQuery($sql_query_recreate); + if ($GLOBALS['PMA_String']->substr($tmp_error_create, 1, 4) == '1005') { + $message = PMA_Message::error( + __('Error creating foreign key on %1$s (check data types)') + ); + $message->addParam(implode(', ', $master_field)); + $html_output .= $message->getDisplay(); } else { - $preview_sql_data .= $sql_query_recreate; + $html_output .= PMA_Util::mysqlDie( + $tmp_error_create, $create_query, false, '', false + ); } + $html_output .= PMA_Util::showMySQLDocu( + 'InnoDB_foreign_key_constraints' + ) . "\n"; + } + } else { + $preview_sql_data .= $create_query . "\n"; + } + + // this is an alteration and the old constraint has been dropped + // without creation of a new one + if ($drop && $create && empty($tmp_error_drop) + && ! empty($tmp_error_create) + ) { + // a rollback may be better here + $sql_query_recreate = '# Restoring the dropped constraint...' . "\n"; + $sql_query_recreate .= PMA_getSQLToCreateForeignKey( + $table, + $master_field, + $existrel_foreign[$master_field_md5]['ref_db_name'], + $existrel_foreign[$master_field_md5]['ref_table_name'], + $existrel_foreign[$master_field_md5]['ref_index_list'], + $existrel_foreign[$master_field_md5]['constraint'], + $options_array[$existrel_foreign[$master_field_md5]['on_delete']], + $options_array[$existrel_foreign[$master_field_md5]['on_update']] + ); + if (! $preview_sql) { + $display_query .= $sql_query_recreate . "\n"; + $GLOBALS['dbi']->tryQuery($sql_query_recreate); + } else { + $preview_sql_data .= $sql_query_recreate; } } diff --git a/libraries/tbl_tracking.lib.php b/libraries/tbl_tracking.lib.php index da41907b01..2eb0b71dbc 100644 --- a/libraries/tbl_tracking.lib.php +++ b/libraries/tbl_tracking.lib.php @@ -51,6 +51,9 @@ function PMA_filterTracking( function PMA_getHtmlForDataDefinitionAndManipulationStatements($url_query, $last_version ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $html = ''; $html .= ''; $html .= PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']); @@ -67,63 +70,63 @@ function PMA_getHtmlForDataDefinitionAndManipulationStatements($url_query, $html .= '' . __('Track these data definition statements:') . ''; $html .= 'stripos( $GLOBALS['cfg']['Server']['tracking_default_statements'], 'ALTER TABLE' ) !== false ? ' checked="checked"' : '') . ' /> ALTER TABLE'; $html .= 'stripos( $GLOBALS['cfg']['Server']['tracking_default_statements'], 'RENAME TABLE' ) !== false ? ' checked="checked"' : '') . ' /> RENAME TABLE'; $html .= 'stripos( $GLOBALS['cfg']['Server']['tracking_default_statements'], 'CREATE TABLE' ) !== false ? ' checked="checked"' : '') . ' /> CREATE TABLE'; $html .= 'stripos( $GLOBALS['cfg']['Server']['tracking_default_statements'], 'DROP TABLE' ) !== false ? ' checked="checked"' : '') . ' /> DROP TABLE'; $html .= ''; $html .= 'stripos( $GLOBALS['cfg']['Server']['tracking_default_statements'], 'CREATE INDEX' ) !== false ? ' checked="checked"' : '') . ' /> CREATE INDEX'; $html .= 'stripos( $GLOBALS['cfg']['Server']['tracking_default_statements'], 'DROP INDEX' ) !== false ? ' checked="checked"' : '') . ' /> DROP INDEX'; $html .= '' . __('Track these data manipulation statements:') . ''; $html .= 'stripos( $GLOBALS['cfg']['Server']['tracking_default_statements'], 'INSERT' ) !== false ? ' checked="checked"' : '') . ' /> INSERT'; $html .= 'stripos( $GLOBALS['cfg']['Server']['tracking_default_statements'], 'UPDATE' ) !== false ? ' checked="checked"' : '') . ' /> UPDATE'; $html .= 'stripos( $GLOBALS['cfg']['Server']['tracking_default_statements'], 'DELETE' ) !== false ? ' checked="checked"' : '') . ' /> DELETE'; $html .= 'stripos( $GLOBALS['cfg']['Server']['tracking_default_statements'], 'TRUNCATE' ) !== false ? ' checked="checked"' : '') @@ -809,8 +812,11 @@ function PMA_getHtmlForSchemaSnapshot($url_query) // Get first DROP TABLE/VIEW and CREATE TABLE/VIEW statements $drop_create_statements = $data['ddlog'][0]['statement']; - if (strstr($data['ddlog'][0]['statement'], 'DROP TABLE') - || strstr($data['ddlog'][0]['statement'], 'DROP VIEW') + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + if ($pmaString->strstr($data['ddlog'][0]['statement'], 'DROP TABLE') + || $pmaString->strstr($data['ddlog'][0]['statement'], 'DROP VIEW') ) { $drop_create_statements .= $data['ddlog'][1]['statement']; } @@ -1156,7 +1162,11 @@ function PMA_exportAsFileDownload($entries) $dump .= $entry['statement']; } $filename = 'log_' . htmlspecialchars($_REQUEST['table']) . '.sql'; - PMA_downloadHeader($filename, 'text/x-sql', strlen($dump)); + PMA_downloadHeader( + $filename, + 'text/x-sql', + $GLOBALS['PMA_String']->strlen($dump) + ); $response = PMA_Response::getInstance(); $response->addHTML($dump); diff --git a/libraries/transformations.lib.php b/libraries/transformations.lib.php index 9c83fef649..8fdcea41ac 100644 --- a/libraries/transformations.lib.php +++ b/libraries/transformations.lib.php @@ -41,7 +41,10 @@ function PMA_Transformation_getOptions($option_string) { $result = array(); - if (! strlen($option_string) + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + if (! $pmaString->strlen($option_string) || ! $transform_options = preg_split('/,/', $option_string) ) { return $result; @@ -49,12 +52,12 @@ function PMA_Transformation_getOptions($option_string) while (($option = array_shift($transform_options)) !== null) { $trimmed = trim($option); - if (strlen($trimmed) > 1 + if ($pmaString->strlen($trimmed) > 1 && $trimmed[0] == "'" - && $trimmed[strlen($trimmed) - 1] == "'" + && $trimmed[$pmaString->strlen($trimmed) - 1] == "'" ) { // '...' - $option = substr($trimmed, 1, -1); + $option = $pmaString->substr($trimmed, 1, -1); } elseif (isset($trimmed[0]) && $trimmed[0] == "'") { // '..., $trimmed = ltrim($option); @@ -62,12 +65,12 @@ function PMA_Transformation_getOptions($option_string) // ..., $trimmed .= ',' . $option; $rtrimmed = rtrim($trimmed); - if ($rtrimmed[strlen($rtrimmed) - 1] == "'") { + if ($rtrimmed[$pmaString->strlen($rtrimmed) - 1] == "'") { // ,...' break; } } - $option = substr($rtrimmed, 1, -1); + $option = $pmaString->substr($rtrimmed, 1, -1); } $result[] = stripslashes($option); } @@ -290,9 +293,12 @@ function PMA_setMIME($db, $table, $key, $mimetype, $transformation, return false; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // lowercase mimetype & transformation - $mimetype = strtolower($mimetype); - $transformation = strtolower($transformation); + $mimetype = $pmaString->strtolower($mimetype); + $transformation = $pmaString->strtolower($transformation); $test_qry = ' SELECT `mimetype`, @@ -312,8 +318,9 @@ function PMA_setMIME($db, $table, $key, $mimetype, $transformation, $GLOBALS['dbi']->freeResult($test_rs); if (! $forcedelete - && (strlen($mimetype) || strlen($transformation) - || strlen($transformationOpts) || strlen($row['comment'])) + && ($pmaString->strlen($mimetype) || $pmaString->strlen($transformation) + || $pmaString->strlen($transformationOpts) + || $pmaString->strlen($row['comment'])) ) { $upd_query = 'UPDATE ' . PMA_Util::backquote($cfgRelation['db']) . '.' . PMA_Util::backquote($cfgRelation['column_info']) @@ -336,9 +343,9 @@ function PMA_setMIME($db, $table, $key, $mimetype, $transformation, WHERE `db_name` = \'' . PMA_Util::sqlAddSlashes($db) . '\' AND `table_name` = \'' . PMA_Util::sqlAddSlashes($table) . '\' AND `column_name` = \'' . PMA_Util::sqlAddSlashes($key) . '\''; - } elseif (strlen($mimetype) - || strlen($transformation) - || strlen($transformationOpts) + } elseif ($pmaString->strlen($mimetype) + || $pmaString->strlen($transformation) + || $pmaString->strlen($transformationOpts) ) { $upd_query = 'INSERT INTO ' . PMA_Util::backquote($cfgRelation['db']) diff --git a/libraries/url_generating.lib.php b/libraries/url_generating.lib.php index 475e673970..a18fdf46a3 100644 --- a/libraries/url_generating.lib.php +++ b/libraries/url_generating.lib.php @@ -42,11 +42,14 @@ function PMA_URL_getHiddenInputs($db = '', $table = '', $indent =& $_indent; $skip =& $_skip; } else { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $params = array(); - if (strlen($db)) { + if ($pmaString->strlen($db)) { $params['db'] = $db; } - if (strlen($table)) { + if ($pmaString->strlen($table)) { $params['table'] = $table; } } @@ -284,15 +287,18 @@ function PMA_URL_getArgSeparator($encode = 'none') static $separator = null; static $html_separator = null; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if (null === $separator) { // use separators defined by php, but prefer ';' // as recommended by W3C // (see http://www.w3.org/TR/1999/REC-html401-19991224/appendix // /notes.html#h-B.2.2) $arg_separator = ini_get('arg_separator.input'); - if (strpos($arg_separator, ';') !== false) { + if ($pmaString->strpos($arg_separator, ';') !== false) { $separator = ';'; - } elseif (strlen($arg_separator) > 0) { + } elseif ($pmaString->strlen($arg_separator) > 0) { $separator = $arg_separator{0}; } else { $separator = '&'; diff --git a/prefs_manage.php b/prefs_manage.php index b79e2d6d6d..7291ad3f58 100644 --- a/prefs_manage.php +++ b/prefs_manage.php @@ -171,13 +171,17 @@ if (isset($_POST['submit_export']) if ($return_url) { $query = explode('&', parse_url($return_url, PHP_URL_QUERY)); $return_url = parse_url($return_url, PHP_URL_PATH); + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + foreach ($query as $q) { - $pos = strpos($q, '='); - $k = substr($q, 0, $pos); + $pos = $pmaString->strpos($q, '='); + $k = $pmaString->substr($q, 0, $pos); if ($k == 'token') { continue; } - $params[$k] = substr($q, $pos+1); + $params[$k] = $pmaString->substr($q, $pos+1); } } else { $return_url = 'prefs_manage.php'; diff --git a/scripts/decode_bug.php b/scripts/decode_bug.php index a310e643c6..6334f2377a 100644 --- a/scripts/decode_bug.php +++ b/scripts/decode_bug.php @@ -82,9 +82,12 @@ if (!empty($bug_encoded) && is_string($bug_encoded)) { $bug_encoded = stripslashes($bug_encoded); } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $bug_encoded = preg_replace('/[[:space:]]/', '', $bug_encoded); $bug_decoded = base64_decode($bug_encoded); - if (substr($bug_encoded, 0, 2) == 'eN') { + if ($pmaString->substr($bug_encoded, 0, 2) == 'eN') { if (function_exists('gzuncompress')) { $result = PMA_printDecodedBug(gzuncompress($bug_decoded)); } else { diff --git a/setup/frames/index.inc.php b/setup/frames/index.inc.php index a24d058ef9..16823da658 100644 --- a/setup/frames/index.inc.php +++ b/setup/frames/index.inc.php @@ -64,7 +64,8 @@ if (!$config_writable || !$config_readable) { // // Check https connection // -$is_https = !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on'; +$is_https = !empty($_SERVER['HTTPS']) + && $GLOBALS['PMA_String']->strtolower($_SERVER['HTTPS']) == 'on'; if (!$is_https) { $text = __( 'You are not using a secure connection; all data (including potentially ' diff --git a/setup/lib/ConfigGenerator.class.php b/setup/lib/ConfigGenerator.class.php index 5497eff4ab..07a6a65fc0 100644 --- a/setup/lib/ConfigGenerator.class.php +++ b/setup/lib/ConfigGenerator.class.php @@ -71,7 +71,7 @@ class ConfigGenerator } // keep 1d array keys which are present in $persist_keys (config.values.php) foreach (array_keys($persistKeys) as $k) { - if (strpos($k, '/') === false) { + if ($GLOBALS['PMA_String']->strpos($k, '/') === false) { $k = preg_replace('/[^A-Za-z0-9_]/', '_', $k); $ret .= self::_getVarExport($k, $cf->getDefault($k), $crlf); } diff --git a/sql.php b/sql.php index 0630122f06..291bf43f8d 100644 --- a/sql.php +++ b/sql.php @@ -57,10 +57,13 @@ if (! empty($goto)) { $is_gotofile = true; } // end if +/** @var PMA_String $pmaString */ +$pmaString = $GLOBALS['PMA_String']; if (! isset($err_url)) { $err_url = (! empty($back) ? $back : $goto) . '?' . PMA_URL_getCommon($GLOBALS['db']) - . ((strpos(' ' . $goto, 'db_') != 1 && strlen($table)) + . (($pmaString->strpos(' ' . $goto, 'db_') != 1 + && $pmaString->strlen($table)) ? '&table=' . urlencode($table) : '' ); @@ -110,7 +113,7 @@ if (isset($_REQUEST['set_col_prefs']) && $_REQUEST['set_col_prefs'] == true) { // Default to browse if no query set and we have table // (needed for browsing from DefaultTabTable) -if (empty($sql_query) && strlen($table) && strlen($db)) { +if (empty($sql_query) && $pmaString->strlen($table) && $pmaString->strlen($db)) { $sql_query = PMA_getDefaultSqlQueryForBrowse($db, $table); // set $goto to what will be displayed if query returns 0 rows diff --git a/tbl_addfield.php b/tbl_addfield.php index 305765ce18..3946efeacc 100644 --- a/tbl_addfield.php +++ b/tbl_addfield.php @@ -64,9 +64,11 @@ if (isset($_REQUEST['do_save_data'])) { && is_array($_REQUEST['field_mimetype']) && $cfg['BrowseMIME'] ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) { if (isset($_REQUEST['field_name'][$fieldindex]) - && strlen($_REQUEST['field_name'][$fieldindex]) + && $pmaString->strlen($_REQUEST['field_name'][$fieldindex]) ) { PMA_setMIME( $db, $table, diff --git a/tbl_change.php b/tbl_change.php index 2288cb64f2..c0f468d355 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -47,7 +47,7 @@ require_once 'libraries/file_listing.lib.php'; * (at this point, $GLOBALS['goto'] will be set but could be empty) */ if (empty($GLOBALS['goto'])) { - if (strlen($table)) { + if ($GLOBALS['PMA_String']->strlen($table)) { // avoid a problem (see bug #2202709) $GLOBALS['goto'] = 'tbl_sql.php'; } else { diff --git a/tbl_chart.php b/tbl_chart.php index f5a6264d33..6d5f316c30 100644 --- a/tbl_chart.php +++ b/tbl_chart.php @@ -8,6 +8,10 @@ require_once 'libraries/common.inc.php'; require_once 'libraries/tbl_chart.lib.php'; + +/** @var PMA_String $pmaString */ +$pmaString = $GLOBALS['PMA_String']; + /* * Execute the query and return the result */ @@ -17,7 +21,8 @@ if (isset($_REQUEST['ajax_request']) ) { $response = PMA_Response::getInstance(); - if (strlen($GLOBALS['table']) && strlen($GLOBALS['db'])) { + if ($pmaString->strlen($GLOBALS['table']) && $pmaString->strlen($GLOBALS['db']) + ) { include './libraries/tbl_common.inc.php'; } @@ -76,12 +81,12 @@ $scripts->addFile('jqplot/plugins/jqplot.highlighter.js'); /** * Runs common work */ -if (strlen($GLOBALS['table'])) { +if ($pmaString->strlen($GLOBALS['table'])) { $url_params['goto'] = $cfg['DefaultTabTable']; $url_params['back'] = 'tbl_sql.php'; include 'libraries/tbl_common.inc.php'; include 'libraries/tbl_info.inc.php'; -} elseif (strlen($GLOBALS['db'])) { +} elseif ($pmaString->strlen($GLOBALS['db'])) { $url_params['goto'] = $cfg['DefaultTabDatabase']; $url_params['back'] = 'sql.php'; include 'libraries/db_common.inc.php'; diff --git a/tbl_create.php b/tbl_create.php index a6209d6c4b..b685ea5692 100644 --- a/tbl_create.php +++ b/tbl_create.php @@ -15,8 +15,11 @@ require_once 'libraries/create_addfield.lib.php'; // Check parameters PMA_Util::checkParameters(array('db')); +/** @var PMA_String $pmaString */ +$pmaString = $GLOBALS['PMA_String']; + /* Check if database name is empty */ -if (strlen($db) == 0) { +if ($pmaString->strlen($db) == 0) { PMA_Util::mysqlDie( __('The database name is empty!'), '', false, 'index.php' ); @@ -73,7 +76,7 @@ if (isset($_REQUEST['do_save_data'])) { ) { foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) { if (isset($_REQUEST['field_name'][$fieldindex]) - && strlen($_REQUEST['field_name'][$fieldindex]) + && $pmaString->strlen($_REQUEST['field_name'][$fieldindex]) ) { PMA_setMIME( $db, $table, diff --git a/tbl_get_field.php b/tbl_get_field.php index 3c9a867117..be42d20cbe 100644 --- a/tbl_get_field.php +++ b/tbl_get_field.php @@ -49,7 +49,7 @@ if ($result === false) { PMA_downloadHeader( $table . '-' . $_GET['transform_key'] . '.bin', PMA_detectMIME($result), - strlen($result) + $GLOBALS['PMA_String']->strlen($result) ); echo $result; ?> diff --git a/tbl_operations.php b/tbl_operations.php index c27b5e9c00..c4c0a47094 100644 --- a/tbl_operations.php +++ b/tbl_operations.php @@ -73,6 +73,9 @@ if ($is_aria) { $reread_info = false; $table_alters = array(); +/** @var PMA_String $pmaString */ +$pmaString = $GLOBALS['PMA_String']; + /** * If the table has to be moved to some other database */ @@ -108,7 +111,7 @@ if (isset($_REQUEST['submitoptions'])) { } if (! empty($_REQUEST['new_tbl_storage_engine']) - && strtolower($_REQUEST['new_tbl_storage_engine']) !== strtolower($tbl_storage_engine) + && $pmaString->strtolower($_REQUEST['new_tbl_storage_engine']) !== $pmaString->strtolower($tbl_storage_engine) ) { $new_tbl_storage_engine = $_REQUEST['new_tbl_storage_engine']; // reset the globals for the new engine @@ -270,8 +273,8 @@ if (! $hideOrderTable) { */ $response->addHTML(PMA_getHtmlForMoveTable()); -if (strstr($show_comment, '; InnoDB free') === false) { - if (strstr($show_comment, 'InnoDB free') === false) { +if ($pmaString->strstr($show_comment, '; InnoDB free') === false) { + if ($pmaString->strstr($show_comment, 'InnoDB free') === false) { // only user entered comment $comment = $show_comment; } else { diff --git a/tbl_printview.php b/tbl_printview.php index 725c2fb9e8..94542728a3 100644 --- a/tbl_printview.php +++ b/tbl_printview.php @@ -31,10 +31,13 @@ require_once 'libraries/tbl_printview.lib.php'; $cfgRelation = PMA_getRelationsParam(); +/** @var PMA_String $pmaString */ +$pmaString = $GLOBALS['PMA_String']; + /** * Defines the url to return to in case of error in a sql statement */ -if (strlen($table)) { +if ($pmaString->strlen($table)) { $err_url = 'tbl_sql.php?' . PMA_URL_getCommon($db, $table); } else { $err_url = 'db_sql.php?' . PMA_URL_getCommon($db); @@ -51,7 +54,7 @@ $GLOBALS['dbi']->selectDb($db); */ if (isset($_POST['selected_tbl']) && is_array($_POST['selected_tbl'])) { $the_tables = $_POST['selected_tbl']; -} elseif (strlen($table)) { +} elseif ($pmaString->strlen($table)) { $the_tables[] = $table; } diff --git a/test/bootstrap-dist.php b/test/bootstrap-dist.php index dde8f7f9e9..4e74a52351 100644 --- a/test/bootstrap-dist.php +++ b/test/bootstrap-dist.php @@ -45,6 +45,7 @@ foreach ($test_defaults as $varname => $defvalue) { // Initialize PMA_VERSION variable require_once 'libraries/core.lib.php'; +$GLOBALS['PMA_String'] = $PMA_String; require_once 'libraries/Config.class.php'; $CFG = new PMA_Config(); define('PMA_VERSION', $CFG->get('PMA_VERSION')); diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index c3c3763414..9ae5c91e19 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -40,8 +40,6 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase */ protected $permTestObj; - - /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. @@ -343,10 +341,13 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase ); } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if (@function_exists('gd_info')) { $this->object->checkGd2(); $gd_nfo = gd_info(); - if (strstr($gd_nfo["GD Version"], '2.')) { + if ($pmaString->strstr($gd_nfo["GD Version"], '2.')) { $this->assertEquals( 1, $this->object->get('PMA_IS_GD2'), @@ -368,7 +369,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase ob_end_clean(); if (preg_match('@GD Version[[:space:]]*\(.*\)@', $a, $v)) { - if (strstr($v, '2.')) { + if ($pmaString->strstr($v, '2.')) { $this->assertEquals( 1, $this->object->get('PMA_IS_GD2'), @@ -387,7 +388,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase /** * Web server detection test * - * @param string $server Server indentification + * @param string $server Server identification * @param boolean $iis Whether server should be detected as IIS * * @return void @@ -439,7 +440,6 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase $this->assertEquals(1, $this->object->get('PMA_IS_WINDOWS')); } elseif (stristr(PHP_OS, 'OS/2')) { $this->assertEquals(1, $this->object->get('PMA_IS_WINDOWS')); - break; } elseif (stristr(PHP_OS, 'Linux')) { $this->assertEquals(0, $this->object->get('PMA_IS_WINDOWS')); } else { @@ -883,7 +883,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase * Test for loading user preferences * * @return void - * @todo Test actualy preferences loading + * @todo Test actually preferences loading */ public function testLoadUserPreferences() { @@ -919,7 +919,6 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase * Should test getting unique value for theme * * @return void - * @todo Implement testGetThemeUniqueValue(). */ public function testGetThemeUniqueValue() { @@ -953,13 +952,12 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase * Should test checking of config permissions * * @return void - * @todo Implement testCheckPermissions(). */ public function testCheckPermissions() { //load file permissions for the current permissions file $perms = @fileperms($this->object->getSource()); - //testing for permissions for no configration file + //testing for permissions for no configuration file $this->assertFalse(!($perms === false) && ($perms & 2)); //load file permissions for the current permissions file diff --git a/test/classes/PMA_DisplayResults_test.php b/test/classes/PMA_DisplayResults_test.php index c04fc4d328..db3d71ce4c 100644 --- a/test/classes/PMA_DisplayResults_test.php +++ b/test/classes/PMA_DisplayResults_test.php @@ -46,7 +46,6 @@ class PMA_DisplayResults_Test extends PHPUnit_Framework_TestCase $GLOBALS['PMA_Config'] = new PMA_Config(); $GLOBALS['PMA_Config']->enableBc(); $GLOBALS['text_dir'] = 'ltr'; - $GLOBALS['PMA_String'] = new PMA_String(); include_once 'libraries/Response.class.php'; $dbi = $this->getMockBuilder('PMA_DatabaseInterface') diff --git a/test/classes/plugin/auth/PMA_AuthenticationCookie_test.php b/test/classes/plugin/auth/PMA_AuthenticationCookie_test.php index 42d42a1352..dc6ea29c50 100644 --- a/test/classes/plugin/auth/PMA_AuthenticationCookie_test.php +++ b/test/classes/plugin/auth/PMA_AuthenticationCookie_test.php @@ -1042,7 +1042,7 @@ class PMA_AuthenticationCookie_Test extends PHPUnit_Framework_TestCase $this->assertEquals( 256, - strlen($result) + $GLOBALS['PMA_String']->strlen($result) ); // case 2 diff --git a/test/classes/plugin/import/ImportShp_test.php b/test/classes/plugin/import/ImportShp_test.php index 780c5dce78..98e4cd6ea6 100644 --- a/test/classes/plugin/import/ImportShp_test.php +++ b/test/classes/plugin/import/ImportShp_test.php @@ -28,6 +28,7 @@ require_once 'libraries/Message.class.php'; class ImportShp_Test extends PHPUnit_Framework_TestCase { /** + * @var ImportShp * @access protected */ protected $object; diff --git a/test/libraries/PMA_StringMB_test.php b/test/libraries/PMA_StringMB_test.php index 89fe57d11b..5b5e1aa0c4 100644 --- a/test/libraries/PMA_StringMB_test.php +++ b/test/libraries/PMA_StringMB_test.php @@ -39,6 +39,54 @@ class PMA_String_Mb_Test extends PMA_StringNative_Test } } + /** + * Test for PMA_StringNative::strrchr + * + * @param string $expected Expected substring + * @param string $haystack String to cut + * @param string $needle Searched string + * + * @return void + * @test + * @dataProvider providerStrrchr + */ + public function testStrrchr($expected, $haystack, $needle) + { + $this->assertEquals( + $expected, + $this->testObject->strrchr($haystack, $needle) + ); + } + + /** + * Data provider for testStrrchr + * + * @return array Test data + */ + public function providerStrrchr() + { + return array( + array('abcdef', 'abcdefabcdef', 'a'), + array(false, 'abcdefabcdef', 'A'), + array('f', 'abcdefabcdef', 'f'), + array(false, 'abcdefabcdef', 'z'), + array(false, 'abcdefabcdef', ''), + array(false, 'abcdefabcdef', false), + array(false, 'abcdefabcdef', true), + array(false, '789456123', true), + array(false, 'abcdefabcdef', null), + array(false, null, null), + array(false, null, 'a'), + array(false, null, '0'), + array(false, false, null), + array(false, false, 'a'), + array(false, false, '0'), + array(false, true, null), + array(false, true, 'a'), + array(false, true, '0'), + ); + } + /** * TearDown function for tests, restores internal encoding * diff --git a/test/libraries/PMA_StringNative_test.php b/test/libraries/PMA_StringNative_test.php index 170eb81474..c3543248d1 100644 --- a/test/libraries/PMA_StringNative_test.php +++ b/test/libraries/PMA_StringNative_test.php @@ -159,5 +159,53 @@ class PMA_StringNative_Test extends PHPUnit_Framework_TestCase array("test string", "TEST STRING") ); } + + /** + * Test for PMA_StringNative::strrchr + * + * @param string $expected Expected substring + * @param string $haystack String to cut + * @param string $needle Searched string + * + * @return void + * @test + * @dataProvider providerStrrchr + */ + public function testStrrchr($expected, $haystack, $needle) + { + $this->assertEquals( + $expected, + $this->testObject->strrchr($haystack, $needle) + ); + } + + /** + * Data provider for testStrrchr + * + * @return array Test data + */ + public function providerStrrchr() + { + return array( + array('abcdef', 'abcdefabcdef', 'a'), + array(false, 'abcdefabcdef', 'A'), + array('f', 'abcdefabcdef', 'f'), + array(false, 'abcdefabcdef', 'z'), + array(false, 'abcdefabcdef', ''), + array(false, 'abcdefabcdef', false), + array(false, 'abcdefabcdef', true), + array(false, '789456123', true), + array(false, 'abcdefabcdef', null), + array(false, null, null), + array(false, null, 'a'), + array(false, null, '0'), + array(false, false, null), + array(false, false, 'a'), + array(false, false, '0'), + array(false, true, null), + array(false, true, 'a'), + array(false, true, '0'), + ); + } } ?> diff --git a/test/libraries/PMA_String_Compare_test.php b/test/libraries/PMA_String_Compare_test.php new file mode 100644 index 0000000000..582cb9da3d --- /dev/null +++ b/test/libraries/PMA_String_Compare_test.php @@ -0,0 +1,1259 @@ +markTestSkipped('Multibyte String Functions are not available.'); + } + $this->_native = new PMA_StringNative(); + $this->_mb = new PMA_StringMB(); + } + + /** + * Tests for strlen + * + * @param mixed $value Value to test + * + * @return void + * @test + * @dataProvider providerStrlen + */ + public function testStrlen($value) + { + $native = $this->_native->strlen($value); + $multibytes = $this->_mb->strlen($value); + $this->assertTrue( + $native === $multibytes, + 'native length: ' . var_export($native, true) + . ' - mb length: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testStrlen + * + * @return array Test data + */ + public function providerStrlen() + { + return array( + array('test'), + array('3'), + array(''), + array(""), + array(false), + array(true), + array(null), + array(3), + array(10), + ); + } + + /** + * Tests for substr + * + * @param mixed $value Value to test + * @param int $start Position to start cutting + * @param int $length Number of characters to cut + * + * @return void + * @test + * @dataProvider providerSubstr + */ + public function testSubstr($value, $start, $length = 2147483647) + { + $native = $this->_native->substr($value, $start, $length); + $multibytes = $this->_mb->substr($value, $start, $length); + $this->assertTrue( + $native === $multibytes, + 'native substr: ' . var_export($native, true) + . ' - mb substr: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testSubstr + * + * @return array Test data + */ + public function providerSubstr() + { + return array( + array('abcdefabcdef', 0), + array('abcdefabcdef', 0, 3), + array('abcdefabcdef', 0, 10), + array('abcdefabcdef', 0, -2), + array('abcdefabcdef', 2), + array('abcdefabcdef', 2, 3), + array('abcdefabcdef', 2, 10), + array('abcdefabcdef', 2, -1), + array('abcdefabcdef', 2, -4), + array('abcdefabcdef', 2, -5), + array('abcdefabcdef', 6), + array('abcdefabcdef', 6, 2), + array('abcdefabcdef', 6, 10), + array('abcdefabcdef', 6, -4), + array('abcdefabcdef', -3), + array('abcdefabcdef', -3, 1), + array('abcdefabcdef', -3, 10), + array('abcdefabcdef', -3, -1), + array('abcdefabcdef', -3, -3), + array('abcdefabcdef', -3, -5), + array(false, 0), + array(false, 0, 2), + array(false, 10), + array(false, 10, 2), + array(true, 0), + array(true, 0, 1), + array(true, 0, 10), + array(true, 0, -1), + array(true, 0, -10), + array(true, 10), + array(true, 10, 1), + array(true, 10, 10), + array(true, 10, -3), + array(3, 0), + array(3, 0, 1), + array(3, 0, 2), + array(3, 0, -1), + array(3, 10), + array(3, 10, 1), + array(3, 10, 10), + array(3, 10, -1), + array('3', 0), + array('3', 0, 1), + array('3', 0, 2), + array('3', 0, -1), + array('3', 10), + array('3', 10, 1), + array('3', 10, 10), + array('3', 10, -1), + array('', 0), + array('', 0, 1), + array('', 0, 10), + array('', 0, -1), + array('', 10), + array('', 10, 1), + array('', 10, 10), + array('', 10, -1), + array(null, 10), + array(null, 10, 1), + array(null, 10, 10), + array(null, 10, -1), + ); + } + + /** + * Tests for substr_count + * + * @param string $haystack String to look into + * @param int $needle String to look for + * + * @return void + * @test + * @dataProvider providerSubstrCount + */ + public function testSubstrCount($haystack, $needle) + { + $native = $this->_native->substrCount($haystack, $needle); + $multibytes = $this->_mb->substrCount($haystack, $needle); + $this->assertTrue( + $native === $multibytes, + 'native substrCount: ' . var_export($native, true) + . ' - mb substrCount: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testSubstrCount + * + * @return array Test data + */ + public function providerSubstrCount() + { + return array( + array('abcdefabcdef', 'a'), + array('abcdefabcdef', 'ab'), + array('abcdefabcdef', 'ba'), + array('abcdefabcdef', 'A'), + array('abcdefabcdef', 'e'), + array('abcdefabcdef', 'z'), + array(false, 'a'), + array(false, 0), + array(true, 0), + array(true, 0, 1), + array(true, 1), + array(true, 1, 1), + array(3, 0), + array(3, 3), + array(3, '3'), + array('3', '3'), + array(null, 0), + array('', 0), + ); + } + + /** + * Tests for substr_count + * + * @param string $haystack String to look into + * @param int $needle String to look for + * + * @return void + * @test + * @dataProvider providerSubstrCountException + */ + public function testSubstrCountException($haystack, $needle) + { + $native = null; + $multibytes = null; + $nativeException = false; + $multibytesException = false; + try { + $native = $this->_native->substrCount($haystack, $needle); + } catch (PHPUnit_Framework_Error $e) { + $nativeException = true; + } + try { + $multibytes = $this->_mb->substrCount($haystack, $needle); + } catch (PHPUnit_Framework_Error $e) { + $multibytesException = true; + } + + $this->assertTrue( + true === $nativeException && true === $multibytesException, + 'native substrCount: ' . var_export($native, true) + . ' - mb substrCount: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testSubstrCountException + * + * @return array Test data + */ + public function providerSubstrCountException() + { + return array( + array('abcdefabcdef', false), + array(false, false), + array(null, false), + array('', false), + ); + } + + /** + * Tests for strpos + * + * @param string $haystack String to search in + * @param mixed $needle Characters to search + * @param int $offset Start position + * + * @return void + * @test + * @dataProvider providerStrpos + */ + public function testStrpos($haystack, $needle, $offset = 0) + { + $native = $this->_native->strpos($haystack, $needle, $offset); + $multibytes = $this->_mb->strpos($haystack, $needle, $offset); + $this->assertTrue( + $native === $multibytes, + 'native strpos: ' . var_export($native, true) + . ' - mb strpos: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testStrpos + * + * @return array Test data + */ + public function providerStrpos() + { + return array( + array('abcdefabcdef', 'a'), + array('abcdefabcdef', 'a', 2), + array('abcdefabcdef', 'a', 10), + array('abcdefabcdef', 'A'), + array('abcdefabcdef', 'A', 2), + array('abcdefabcdef', 'A', 10), + array('abcdefabcdef', 'e'), + array('abcdefabcdef', 'e', 2), + array('abcdefabcdef', 'e', 10), + array('abcdefabcdef', 'z'), + array('abcdefabcdef', 'z', 2), + array('abcdefabcdef', ord('a')), + array('abcdefabcdef', ord('a'), 2), + array('abcdefabcdef', ord('A')), + array('abcdefabcdef', ord('A'), 2), + array('abcdefabcdef', ord('e')), + array('abcdefabcdef', ord('e'), 2), + array('abcdefabcdef', ord('z')), + array('abcdefabcdef', ord('z'), 2), + array('abcdefabcdef', false), + array(false, 'a'), + array(false, 0), + array(false, false), + array(true, 0), + array(true, 0, 1), + array(true, 1), + array(true, 1, 1), + array(3, 0), + array(3, 3), + array(3, '3'), + array('3', '3'), + array(null, 0), + array(null, false), + array('', 0), + array('', false), + ); + } + + /** + * Tests for strpos + * + * @param string $haystack String to search in + * @param mixed $needle Characters to search + * @param int $offset Start position + * + * @return void + * @test + * @dataProvider providerStrposException + */ + public function testStrposException($haystack, $needle, $offset = 0) + { + $native = null; + $multibytes = null; + $nativeException = false; + $multibytesException = false; + try { + $native = $this->_native->strpos($haystack, $needle, $offset); + } catch (PHPUnit_Framework_Error $e) { + $nativeException = true; + } + try { + $multibytes = $this->_mb->strpos($haystack, $needle, $offset); + } catch (PHPUnit_Framework_Error $e) { + $multibytesException = true; + } + + $this->assertTrue( + true === $nativeException && true === $multibytesException, + 'native strpos: ' . var_export($native, true) + . ' - mb strpos: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testStrposException + * + * @return array Test data + */ + public function providerStrposException() + { + return array( + array('abcdefabcdef', 'a', 20), + array('abcdefabcdef', 'e', 20), + array('abcdefabcdef', 'z', 20), + array('abcdefabcdef', ord('a'), 20), + array('abcdefabcdef', ord('e'), 20), + array('abcdefabcdef', ord('z'), 20), + array(false, 0, 1), + array(3, 0, 2), + array(3, 3, 2), + array(3, '3', 2), + array('3', '3', 2), + array('', 0, 2), + ); + } + + /** + * Tests for stripos + * + * @param string $haystack String to search in + * @param mixed $needle Characters to search + * @param int $offset Start position + * + * @return void + * @test + * @dataProvider providerStripos + */ + public function testStripos($haystack, $needle, $offset = 0) + { + $native = $this->_native->stripos($haystack, $needle, $offset); + $multibytes = $this->_mb->stripos($haystack, $needle, $offset); + $this->assertTrue( + $native === $multibytes, + 'native stripos: ' . var_export($native, true) + . ' - mb stripos: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testStripos + * + * @return array Test data + */ + public function providerStripos() + { + return array( + array('abcdefabcdef', 'a'), + array('abcdefabcdef', 'a', 2), + array('abcdefabcdef', 'a', 10), + array('abcdefabcdef', 'A'), + array('abcdefabcdef', 'A', 2), + array('abcdefabcdef', 'A', 10), + array('abcdefabcdef', 'e'), + array('abcdefabcdef', 'e', 2), + array('abcdefabcdef', 'e', 10), + array('abcdefabcdef', 'e'), + array('abcdefabcdef', 'z'), + array('abcdefabcdef', 'z', 2), + array('abcdefabcdef', ord('a')), + array('abcdefabcdef', ord('a'), 2), + array('abcdefabcdef', ord('A')), + array('abcdefabcdef', ord('A'), 2), + array('abcdefabcdef', ord('e')), + array('abcdefabcdef', ord('e'), 2), + array('abcdefabcdef', ord('z')), + array('abcdefabcdef', ord('z'), 2), + array('abcdefabcdef', false), + array(false, 'a'), + array(false, 0), + array(false, 0, 1), + array(false, false), + array(true, 0), + array(true, 0, 1), + array(true, 1), + array(true, 1, 1), + array(3, 0), + array(3, 3), + array(3, '3'), + array('3', '3'), + array(null, 0), + array(null, false), + array('', 0), + array('', 0, 2), + array('', false), + ); + } + + /** + * Tests for stripos + * + * @param string $haystack String to search in + * @param mixed $needle Characters to search + * @param int $offset Start position + * + * @return void + * @test + * @dataProvider providerStriposException + */ + public function testStriposException($haystack, $needle, $offset = 0) + { + $native = null; + $multibytes = null; + $nativeException = false; + $multibytesException = false; + try { + $native = $this->_native->stripos($haystack, $needle, $offset); + } catch (PHPUnit_Framework_Error $e) { + $nativeException = true; + } + try { + $multibytes = $this->_mb->stripos($haystack, $needle, $offset); + } catch (PHPUnit_Framework_Error $e) { + $multibytesException = true; + } + + $this->assertTrue( + true === $nativeException && true === $multibytesException, + 'native stripos: ' . var_export($native, true) + . ' - mb stripos: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testStriposException + * + * @return array Test data + */ + public function providerStriposException() + { + return array( + array('abcdefabcdef', 'a', 20), + array('abcdefabcdef', 'e', 20), + array('abcdefabcdef', 'z', 20), + array('abcdefabcdef', ord('a'), 20), + array('abcdefabcdef', ord('e'), 20), + array('abcdefabcdef', ord('z'), 20), + array(3, 0, 2), + array(3, 3, 2), + array(3, '3', 2), + array('3', '3', 2), + ); + } + + /** + * Tests for strrpos + * + * @param string $haystack String to search in + * @param mixed $needle Characters to search + * @param int $offset Start position + * + * @return void + * @test + * @dataProvider providerStrrpos + */ + public function testStrrpos($haystack, $needle, $offset = 0) + { + $native = $this->_native->strrpos($haystack, $needle, $offset); + $multibytes = $this->_mb->strrpos($haystack, $needle, $offset); + $this->assertTrue( + $native === $multibytes, + 'native strrpos: ' . var_export($native, true) + . ' - mb strrpos: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testStrrpos + * + * @return array Test data + */ + public function providerStrrpos() + { + return array( + array('abcdefabcdef', 'a'), + array('abcdefabcdef', 'a', 2), + array('abcdefabcdef', 'a', 10), + array('abcdefabcdef', 'a', -10), + array('abcdefabcdef', 'A'), + array('abcdefabcdef', 'A', 2), + array('abcdefabcdef', 'A', 10), + array('abcdefabcdef', 'A', -10), + array('abcdefabcdef', 'e'), + array('abcdefabcdef', 'e', 2), + array('abcdefabcdef', 'e', 10), + array('abcdefabcdef', 'e', -2), + array('abcdefabcdef', 'e'), + array('abcdefabcdef', 'z'), + array('abcdefabcdef', 'z', 2), + array('abcdefabcdef', 'z', -2), + array('abcdefabcdef', ord('a')), + array('abcdefabcdef', ord('a'), 2), + array('abcdefabcdef', ord('a'), -2), + array('abcdefabcdef', ord('A')), + array('abcdefabcdef', ord('A'), 2), + array('abcdefabcdef', ord('A'), -2), + array('abcdefabcdef', ord('e')), + array('abcdefabcdef', ord('e'), 2), + array('abcdefabcdef', ord('e'), -2), + array('abcdefabcdef', ord('z')), + array('abcdefabcdef', ord('z'), 2), + array('abcdefabcdef', ord('z'), -2), + array('abcdefabcdef', false), + array(false, 'a'), + array(false, 0), + array(false, 0, 1), + array(false, false), + array(true, 0), + array(true, 0, 1), + array(true, 1), + array(true, 1, 1), + array(3, 0), + array(3, 3), + array(3, '3'), + array('3', '3'), + array(null, 0), + array(null, false), + array('', 0), + array('', 0, 2), + array('', false), + ); + } + + /** + * Tests for strrpos + * + * @param string $haystack String to search in + * @param mixed $needle Characters to search + * @param int $offset Start position + * + * @return void + * @test + * @dataProvider providerStrrposException + */ + public function testStrrposException($haystack, $needle, $offset = 0) + { + $native = null; + $multibytes = null; + $nativeException = false; + $multibytesException = false; + try { + $native = $this->_native->strrpos($haystack, $needle, $offset); + } catch (PHPUnit_Framework_Error $e) { + $nativeException = true; + } + try { + $multibytes = $this->_mb->strrpos($haystack, $needle, $offset); + } catch (PHPUnit_Framework_Error $e) { + $multibytesException = true; + } + + $this->assertTrue( + true === $nativeException && true === $multibytesException, + 'native strrpos: ' . var_export($native, true) + . ' - mb strrpos: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testStrrposException + * + * @return array Test data + */ + public function providerStrrposException() + { + return array( + array('abcdefabcdef', 'a', 20), + array('abcdefabcdef', 'a', -20), + array('abcdefabcdef', 'e', 20), + array('abcdefabcdef', 'e', -20), + array('abcdefabcdef', 'z', 20), + array('abcdefabcdef', 'z', -20), + array('abcdefabcdef', ord('a'), 20), + array('abcdefabcdef', ord('e'), 20), + array('abcdefabcdef', ord('z'), 20), + array(3, 0, 2), + array(3, 3, 2), + array(3, '3', 2), + array('3', '3', 2), + ); + } + + /** + * Tests for strripos + * + * @param string $haystack String to search in + * @param mixed $needle Characters to search + * @param int $offset Start position + * + * @return void + * @test + * @dataProvider providerStrripos + */ + public function testStrripos($haystack, $needle, $offset = 0) + { + $native = $this->_native->strripos($haystack, $needle, $offset); + $multibytes = $this->_mb->strripos($haystack, $needle, $offset); + $this->assertTrue( + $native === $multibytes, + 'native strripos: ' . var_export($native, true) + . ' - mb strripos: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testStrripos + * + * @return array Test data + */ + public function providerStrripos() + { + return array( + array('abcdefabcdef', 'a'), + array('abcdefabcdef', 'a', 2), + array('abcdefabcdef', 'a', 10), + array('abcdefabcdef', 'a', -10), + array('abcdefabcdef', 'A'), + array('abcdefabcdef', 'A', 2), + array('abcdefabcdef', 'A', 10), + array('abcdefabcdef', 'A', -10), + array('abcdefabcdef', 'e'), + array('abcdefabcdef', 'e', 2), + array('abcdefabcdef', 'e', 10), + array('abcdefabcdef', 'e', -2), + array('abcdefabcdef', 'e'), + array('abcdefabcdef', 'z'), + array('abcdefabcdef', 'z', 2), + array('abcdefabcdef', 'z', -2), + array('abcdefabcdef', ord('a')), + array('abcdefabcdef', ord('a'), 2), + array('abcdefabcdef', ord('a'), -2), + array('abcdefabcdef', ord('A')), + array('abcdefabcdef', ord('A'), 2), + array('abcdefabcdef', ord('A'), -2), + array('abcdefabcdef', ord('e')), + array('abcdefabcdef', ord('e'), 2), + array('abcdefabcdef', ord('e'), -2), + array('abcdefabcdef', ord('z')), + array('abcdefabcdef', ord('z'), 2), + array('abcdefabcdef', ord('z'), -2), + array('abcdefabcdef', false), + array(false, 'a'), + array(false, 0), + array(false, 0, 1), + array(false, false), + array(true, 0), + array(true, 0, 1), + array(true, 1), + array(true, 1, 1), + array(3, 0), + array(3, 3), + array(3, '3'), + array('3', '3'), + array(null, 0), + array(null, false), + array('', 0), + array('', 0, 2), + array('', false), + ); + } + + /** + * Tests for strripos + * + * @param string $haystack String to search in + * @param mixed $needle Characters to search + * @param int $offset Start position + * + * @return void + * @test + * @dataProvider providerStrriposException + */ + public function testStrriposException($haystack, $needle, $offset = 0) + { + $native = null; + $multibytes = null; + $nativeException = false; + $multibytesException = false; + try { + $native = $this->_native->strripos($haystack, $needle, $offset); + } catch (PHPUnit_Framework_Error $e) { + $nativeException = true; + } + try { + $multibytes = $this->_mb->strripos($haystack, $needle, $offset); + } catch (PHPUnit_Framework_Error $e) { + $multibytesException = true; + } + + $this->assertTrue( + true === $nativeException && true === $multibytesException, + 'native strripos: ' . var_export($native, true) + . ' - mb strripos: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testStrriposException + * + * @return array Test data + */ + public function providerStrriposException() + { + return array( + array('abcdefabcdef', 'a', 20), + array('abcdefabcdef', 'a', -20), + array('abcdefabcdef', 'e', 20), + array('abcdefabcdef', 'e', -20), + array('abcdefabcdef', 'z', 20), + array('abcdefabcdef', 'z', -20), + array('abcdefabcdef', ord('a'), 20), + array('abcdefabcdef', ord('e'), 20), + array('abcdefabcdef', ord('z'), 20), + array(3, 0, 2), + array(3, 3, 2), + array(3, '3', 2), + array('3', '3', 2), + ); + } + + /** + * Tests for strstr + * + * @param string $haystack String to search in + * @param mixed $needle Characters to search + * @param bool $before_needle Start position + * + * @return void + * @test + * @dataProvider providerStrstr + */ + public function testStrstr($haystack, $needle, $before_needle = false) + { + $native = $this->_native->strstr($haystack, $needle, $before_needle); + $multibytes = $this->_mb->strstr($haystack, $needle, $before_needle); + $this->assertTrue( + $native === $multibytes, + 'native strstr: ' . var_export($native, true) + . ' - mb strstr: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testStrstr + * + * @return array Test data + */ + public function providerStrstr() + { + return array( + array('abcdefabcdef', 'a'), + array('abcdefabcdef', 'a', true), + array('abcdefabcdef', 'A'), + array('abcdefabcdef', 'A', true), + array('abcdefabcdef', 97), + array('abcdefabcdef', 97, true), + array('abcdefabcdef', 65), + array('abcdefabcdef', 65, true), + array('abcdefabcdef', 'e'), + array('abcdefabcdef', 'e', true), + array('abcdefabcdef', 'z'), + array('abcdefabcdef', 'z', true), + array('abcdefabcdef', null), + array('abcdefabcdef', null, true), + array('abcdefabcdef', false), + array('abcdefabcdef', false, true), + array(false, 'a'), + array(false, false), + array(true, 0), + array(true, 1), + array(true, true), + array(true, true, true), + array(3, 0), + array(3, 3), + array(3, 3, true), + array(123456789, 0), + array(123456789, 3), + array(123456789, 3, true), + array('3', '3'), + array('3', '3', true), + array('123456789', 3), + array('123456789', 3, true), + array('123456789', 49), //ASCII 49 = 1 + array('123456789', 49, true), + array(null, 0), + array(null, null), + array('', 0), + array('', false), + array('', null), + ); + } + + /** + * Tests for strstr + * + * @param string $haystack String to search in + * @param mixed $needle Characters to search + * @param bool $before_needle Start position + * + * @return void + * @test + * @dataProvider providerStrstrException + */ + public function testStrstrException($haystack, $needle, $before_needle = false) + { + $native = null; + $multibytes = null; + $nativeException = false; + $multibytesException = false; + try { + $native = $this->_native->strstr($haystack, $needle, $before_needle); + } catch (PHPUnit_Framework_Error $e) { + $nativeException = true; + } + try { + $multibytes = $this->_mb->strstr($haystack, $needle, $before_needle); + } catch (PHPUnit_Framework_Error $e) { + $multibytesException = true; + } + + $this->assertTrue( + true === $nativeException && true === $multibytesException, + 'native strstr: ' . var_export($native, true) + . ' - mb strstr: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testStrstrException + * + * @return array Test data + */ + public function providerStrstrException() + { + return array( + array('abcdefabcdef', ''), + array('abcdefabcdef', '', true), + ); + } + + /** + * Tests for stristr + * + * @param string $haystack String to search in + * @param mixed $needle Characters to search + * @param bool $before_needle Start position + * + * @return void + * @test + * @dataProvider providerStristr + */ + public function testStristr($haystack, $needle, $before_needle = false) + { + $this->markTestSkipped('Skip until hhvm implements third parameter.'); + $native = $this->_native->stristr($haystack, $needle, $before_needle); + $multibytes = $this->_mb->stristr($haystack, $needle, $before_needle); + $this->assertTrue( + $native === $multibytes, + 'native stristr: ' . var_export($native, true) + . ' - mb stristr: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testStristr + * + * @return array Test data + */ + public function providerStristr() + { + return array( + array('abcdefabcdef', 'a'), + array('abcdefabcdef', 'a', true), + array('abcdefabcdef', 'A'), + array('abcdefabcdef', 'A', true), + array('abcdefabcdef', 97), + array('abcdefabcdef', 97, true), + array('abcdefabcdef', 65), + array('abcdefabcdef', 65, true), + array('abcdefabcdef', 'e'), + array('abcdefabcdef', 'e', true), + array('abcdefabcdef', 'z'), + array('abcdefabcdef', 'z', true), + array('abcdefabcdef', null), + array('abcdefabcdef', null, true), + array('abcdefabcdef', false), + array('abcdefabcdef', false, true), + array(false, 'a'), + array(false, false), + array(true, 0), + array(true, 1), + array(true, true), + array(true, true, true), + array(3, 0), + array(3, 3), + array(3, 3, true), + array(123456789, 0), + array(123456789, 3), + array(123456789, 3, true), + array('3', '3'), + array('3', '3', true), + array('123456789', 3), + array('123456789', 3, true), + array('123456789', 49), //ASCII 49 = 1 + array('123456789', 49, true), + array(null, 0), + array(null, null), + array('', 0), + array('', false), + array('', null), + ); + } + + /** + * Tests for stristr + * + * @param string $haystack String to search in + * @param mixed $needle Characters to search + * @param bool $before_needle Start position + * + * @return void + * @test + * @dataProvider providerStristrException + */ + public function testStristrException($haystack, $needle, $before_needle = false) + { + $this->markTestSkipped('Skip until hhvm implements third parameter.'); + $native = null; + $multibytes = null; + $nativeException = false; + $multibytesException = false; + try { + $native = $this->_native->stristr($haystack, $needle, $before_needle); + } catch (PHPUnit_Framework_Error $e) { + $nativeException = true; + } + try { + $multibytes = $this->_mb->stristr($haystack, $needle, $before_needle); + } catch (PHPUnit_Framework_Error $e) { + $multibytesException = true; + } + + $this->assertTrue( + true === $nativeException && true === $multibytesException, + 'native stristr: ' . var_export($native, true) + . ' - mb stristr: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testStristrException + * + * @return array Test data + */ + public function providerStristrException() + { + return array( + array('abcdefabcdef', ''), + array('abcdefabcdef', '', true), + ); + } + + /** + * Tests for strrchr + * + * @param string $haystack String to search in + * @param mixed $needle Characters to search + * + * @return void + * @test + * @dataProvider providerStrstr + */ + public function testStrrchr($haystack, $needle) + { + $native = $this->_native->strrchr($haystack, $needle); + $multibytes = $this->_mb->strrchr($haystack, $needle); + $this->assertTrue( + $native === $multibytes, + 'native strrchr: ' . var_export($native, true) + . ' - mb strrchr: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testStrrchr + * + * @return array Test data + */ + public function providerStrrchr() + { + return array( + array('abcdefabcdef', 'a'), + array('abcdefabcdef', 'A'), + array('abcdefabcdef', 97), + array('abcdefabcdef', 65), + array('abcdefabcdef', 'e'), + array('abcdefabcdef', 'z'), + array('abcdefabcdef', ''), + array('abcdefabcdef', null), + array('abcdefabcdef', false), + array(false, 'a'), + array(false, false), + array(true, 0), + array(true, 1), + array(true, true), + array(3, 0), + array(3, 3), + array(123456789, 0), + array(123456789, 3), + array('3', '3'), + array('123456789', 3), + array('123456789', 49), //ASCII 49 = 1 + array(null, 0), + array(null, null), + array('', 0), + array('', false), + array('', null), + ); + } + + /** + * Tests for strtolower + * + * @param string $str Input string + * + * @return void + * @test + * @dataProvider providerCase + */ + public function testStrtolower($str) + { + $native = $this->_native->strtolower($str); + $multibytes = $this->_mb->strtolower($str); + $this->assertTrue( + $native === $multibytes, + 'native strtolower: ' . var_export($native, true) + . ' - mb strtolower: ' . var_export($multibytes, true) + ); + } + + /** + * Tests for strtoupper + * + * @param string $str Input string + * + * @return void + * @test + * @dataProvider providerCase + */ + public function testStrtoupper($str) + { + $native = $this->_native->strtoupper($str); + $multibytes = $this->_mb->strtoupper($str); + $this->assertTrue( + $native === $multibytes, + 'native strtoupper: ' . var_export($native, true) + . ' - mb strtoupper: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testStrtolower and testStrtoupper + * + * @return array Test data + */ + public function providerCase() + { + return array( + array('abcdefabcdef'), + array('abcdefABCDEF'), + //array('abcdefABCDEFàéÀÉ'), //Error with those characters. + array('abcdefABCDEF@+12345'), + array(false), + array(true), + array(3), + array(123456789), + array('3'), + array('4k'), + array('4kb'), + array('4K'), + array('4KB'), + array('123456789'), + array(null), + array(''), + ); + } + + /** + * Tests for ord + * + * @param string $chr Input char + * + * @return void + * @test + * @dataProvider providerOrd + */ + public function testOrd($chr) + { + $native = $this->_native->ord($chr); + $multibytes = $this->_mb->ord($chr); + $this->assertTrue( + $native === $multibytes, + 'native ord: ' . var_export($native, true) + . ' - mb ord: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testOrd + * + * @return array Test data + */ + public function providerOrd() + { + return array( + array('a'), + array('A'), + array('az'), + array('AZ'), + array('3a'), + array(3), + array(3.1), + array(true), + array(false), + array(null), + array(''), + ); + } + + /** + * Tests for chr + * + * @param string $ascii Ascii code + * + * @return void + * @test + * @dataProvider providerChr + */ + public function testChr($ascii) + { + $native = $this->_native->chr($ascii); + $multibytes = $this->_mb->chr($ascii); + $this->assertTrue( + $native === $multibytes, + 'native chr: ' . var_export($native, true) + . ' - mb chr: ' . var_export($multibytes, true) + ); + } + + /** + * Data provider for testChr + * + * @return array Test data + */ + public function providerChr() + { + return array( + array('a'), + array('A'), + array('az'), + array('AZ'), + array('a3'), + array(3), + array(3.1), + array(false), + array(true), + array(null), + array(''), + ); + } +} diff --git a/test/libraries/PMA_browse_foreigners_test.php b/test/libraries/PMA_browse_foreigners_test.php index 574fe0612c..97a6be88ee 100644 --- a/test/libraries/PMA_browse_foreigners_test.php +++ b/test/libraries/PMA_browse_foreigners_test.php @@ -232,7 +232,6 @@ class PMA_BrowseForeignersTest extends PHPUnit_Framework_TestCase */ function testGetDescriptionAndTitle() { - $GLOBALS['PMA_String'] = new PMA_String(); $GLOBALS['cfg']['LimitChars'] = 30; $desc = 'foobar'col_test', 'col_type'=>'int', @@ -369,7 +372,7 @@ class PMA_Central_Columns_Test extends PHPUnit_Framework_TestCase ); $this->assertContains( PMA_getHtmlForColumnDefault( - 1, 5, 0, strtoupper($row['col_type']), '', + 1, 5, 0, $pmaString->strtoupper($row['col_type']), '', array('DefaultType'=>'NONE') ), $result @@ -380,7 +383,7 @@ class PMA_Central_Columns_Test extends PHPUnit_Framework_TestCase ); $this->assertContains( PMA_getHtmlForColumnDefault( - 1, 5, 0, strtoupper($row['col_type']), '', + 1, 5, 0, $pmaString->strtoupper($row['col_type']), '', array('DefaultType'=>'USER_DEFINED', 'DefaultValue'=>100) ), $result_1 @@ -391,7 +394,7 @@ class PMA_Central_Columns_Test extends PHPUnit_Framework_TestCase ); $this->assertContains( PMA_getHtmlForColumnDefault( - 1, 5, 0, strtoupper($row['col_type']), '', + 1, 5, 0, $pmaString->strtoupper($row['col_type']), '', array('DefaultType'=>'CURRENT_TIMESTAMP') ), $result_2 diff --git a/test/libraries/PMA_display_export_test.php b/test/libraries/PMA_display_export_test.php index 332ca869d7..166da0d329 100644 --- a/test/libraries/PMA_display_export_test.php +++ b/test/libraries/PMA_display_export_test.php @@ -340,7 +340,7 @@ class PMA_DisplayExport_Test extends PHPUnit_Framework_TestCase ); $name_attr = 'aliases[test\'_db][tables][test_<b>table][alias]'; - $id_attr = substr(md5($name_attr), 0, 12); + $id_attr = $GLOBALS['PMA_String']->substr(md5($name_attr), 0, 12); $this->assertContains( 'stripos($sql, "column_info") !== false) { unset($this->values[$this->indexs['column_info']]); } - if (stripos($sql, "table_info") !== false) { + if ($pmaString->stripos($sql, "table_info") !== false) { unset ($this->values[$this->indexs['table_info']]); } - if (stripos($sql, "table_coords") !== false) { + if ($pmaString->stripos($sql, "table_coords") !== false) { unset($this->values[$this->indexs['table_coords']]); } - if (stripos($sql, "relation") !== false) { + if ($pmaString->stripos($sql, "relation") !== false) { unset($this->values[$this->indexs['relation']]); } - if (stripos($sql, "pdf_pages") !== false) { + if ($pmaString->stripos($sql, "pdf_pages") !== false) { unset($GLOBALS [$this->indexs['pdf_pages']]); } - if (stripos($sql, "bookmark") !== false) { + if ($pmaString->stripos($sql, "bookmark") !== false) { unset($GLOBALS [$this->indexs['bookmark']]); } return true; diff --git a/test/libraries/core/PMA_warnMissingExtension_test.php b/test/libraries/core/PMA_warnMissingExtension_test.php index 9eff0f11d7..1cf4f28307 100644 --- a/test/libraries/core/PMA_warnMissingExtension_test.php +++ b/test/libraries/core/PMA_warnMissingExtension_test.php @@ -89,6 +89,6 @@ class PMA_WarnMissingExtension_Test extends PHPUnit_Framework_TestCase $printed = ob_get_contents(); ob_end_clean(); - $this->assertGreaterThan(0, strpos($printed, $warn)); + $this->assertGreaterThan(0, $GLOBALS['PMA_String']->strpos($printed, $warn)); } } diff --git a/test/selenium/PmaSeleniumTableInsertTest.php b/test/selenium/PmaSeleniumTableInsertTest.php index 48e1882134..965ba1bff1 100644 --- a/test/selenium/PmaSeleniumTableInsertTest.php +++ b/test/selenium/PmaSeleniumTableInsertTest.php @@ -58,7 +58,7 @@ class PMA_SeleniumTableInsertTest extends PMA_SeleniumBase */ public function testAddData() { - if (strtolower($this->getBrowser()) == 'safari') { + if ($GLOBALS['PMA_String']->strtolower($this->getBrowser()) == 'safari') { /* TODO: this should be fixed, but the cause is unclear to me */ $this->markTestIncomplete('Fails with Safari'); } diff --git a/test/selenium/PmaSeleniumXssTest.php b/test/selenium/PmaSeleniumXssTest.php index 5579b981fc..a1150dbe6a 100644 --- a/test/selenium/PmaSeleniumXssTest.php +++ b/test/selenium/PmaSeleniumXssTest.php @@ -27,7 +27,7 @@ class PMA_SeleniumXSSTest extends PMA_SeleniumBase */ public function testQueryTabWithNullValue() { - if (strtolower($this->getBrowser()) == 'safari') { + if ($GLOBALS['PMA_String']->strtolower($this->getBrowser()) == 'safari') { $this->markTestSkipped('Alerts not supported on Safari browser.'); } $this->login(); diff --git a/test/selenium/TestBase.php b/test/selenium/TestBase.php index 30d3436442..e1bb2687f2 100644 --- a/test/selenium/TestBase.php +++ b/test/selenium/TestBase.php @@ -156,6 +156,8 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase * Configures the selenium and database link. * * @return void + * + * @throws Exception */ protected function setUp() { @@ -184,7 +186,7 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase ); } $this->database_name = $GLOBALS['TESTSUITE_DATABASE'] - . substr(md5(rand()), 0, 7); + . $GLOBALS['PMA_String']->substr(md5(rand()), 0, 7); $this->dbQuery( 'CREATE DATABASE IF NOT EXISTS ' . $this->database_name ); @@ -461,7 +463,7 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase * Not supported in Safari Webdriver, see * http://code.google.com/p/selenium/issues/detail?id=4136 */ - if (strtolower($this->getBrowser()) == 'safari') { + if ($GLOBALS['PMA_String']->strtolower($this->getBrowser()) == 'safari') { $this->markTestSkipped('Can not send keys to Safari browser.'); } parent::keys($text); @@ -481,7 +483,7 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase * Not supported in Safari Webdriver, see * http://code.google.com/p/selenium/issues/detail?id=4136 */ - if (strtolower($this->getBrowser()) == 'safari') { + if ($GLOBALS['PMA_String']->strtolower($this->getBrowser()) == 'safari') { $this->markTestSkipped('MoveTo not supported on Safari browser.'); } parent::moveto($element); @@ -499,7 +501,7 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase * Not supported in Safari Webdriver, see * http://code.google.com/p/selenium/issues/detail?id=4136 */ - if (strtolower($this->getBrowser()) == 'safari') { + if ($GLOBALS['PMA_String']->strtolower($this->getBrowser()) == 'safari') { $this->markTestSkipped('Alerts not supported on Safari browser.'); } return parent::alertText(); @@ -518,7 +520,7 @@ abstract class PMA_SeleniumBase extends PHPUnit_Extensions_Selenium2TestCase * Firefox needs some escaping of a text, see * http://code.google.com/p/selenium/issues/detail?id=1723 */ - if (strtolower($this->getBrowser()) == 'firefox') { + if ($GLOBALS['PMA_String']->strtolower($this->getBrowser()) == 'firefox') { $text = str_replace( "(", PHPUnit_Extensions_Selenium2TestCase_Keys::SHIFT diff --git a/themes/svg_gradient.php b/themes/svg_gradient.php index 7e49037293..bebb691f8d 100644 --- a/themes/svg_gradient.php +++ b/themes/svg_gradient.php @@ -17,7 +17,7 @@ header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 3600) . ' GMT'); */ function PMA_gradientGetColor($get_name, $default) { - // get color from GET args, only alphanumeric chcracters + // get color from GET args, only alphanumeric characters $opts = array('options' => array('regexp' => '/^[a-z0-9]+$/i')); $color = filter_input(INPUT_GET, $get_name, FILTER_VALIDATE_REGEXP, $opts); if (preg_match('/^[a-f0-9]{6}$/', $color)) { diff --git a/transformation_wrapper.php b/transformation_wrapper.php index ac0b04973d..f1462143bc 100644 --- a/transformation_wrapper.php +++ b/transformation_wrapper.php @@ -77,7 +77,7 @@ if ($cfgRelation['commwork'] && $cfgRelation['mimework']) { ); foreach ($mime_options as $key => $option) { - if (substr($option, 0, 10) == '; charset=') { + if ($GLOBALS['PMA_String']->substr($option, 0, 10) == '; charset=') { $mime_options['charset'] = $option; } }
' . __('Track these data definition statements:') . '
' . __('Track these data manipulation statements:') . '