From 9b77d746aba7ded13aa68f98ac4b5840f2d438f8 Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Fri, 15 Aug 2014 18:19:20 +0200 Subject: [PATCH 1/5] Mass modifications to use PMA_String. Signed-off-by: Hugues Peccatte --- changelog.php | 2 +- db_datadict.php | 2 +- db_operations.php | 8 +- db_printview.php | 2 +- examples/openid.php | 2 +- export.php | 10 +- file_echo.php | 14 +- gis_data_editor.php | 15 +- import.php | 32 +- import_status.php | 10 +- index.php | 13 +- libraries/Advisor.class.php | 9 +- libraries/Config.class.php | 170 ++- libraries/DBQbe.class.php | 65 +- libraries/DatabaseInterface.class.php | 76 +- libraries/DbSearch.class.php | 6 +- libraries/DisplayResults.class.php | 718 +++++----- libraries/Error.class.php | 6 +- libraries/File.class.php | 2 +- libraries/Font.class.php | 11 +- libraries/Header.class.php | 8 +- libraries/Index.class.php | 8 +- libraries/List_Database.class.php | 4 +- libraries/Menu.class.php | 25 +- libraries/Message.class.php | 8 +- libraries/PDF.class.php | 6 +- libraries/RecentFavoriteTable.class.php | 7 +- libraries/Response.class.php | 8 +- libraries/Scripts.class.php | 21 +- libraries/ServerStatusData.class.php | 7 +- libraries/StorageEngine.class.php | 20 +- libraries/String.class.php | 125 +- libraries/StringByte.int.php | 94 +- libraries/StringMB.class.php | 196 ++- libraries/StringNative.class.php | 124 ++ libraries/StringType.int.php | 1 - libraries/Table.class.php | 65 +- libraries/TableSearch.class.php | 13 +- libraries/Tracker.class.php | 74 +- libraries/Types.class.php | 8 +- libraries/Util.class.php | 301 +++-- libraries/bookmark.lib.php | 6 +- libraries/build_html_for_db.lib.php | 7 +- libraries/central_columns.lib.php | 7 +- libraries/check_user_privileges.lib.php | 22 +- libraries/common.inc.php | 28 +- libraries/config/Form.class.php | 21 +- libraries/config/FormDisplay.class.php | 12 +- libraries/config/FormDisplay.tpl.php | 4 +- libraries/config/ServerConfigChecks.class.php | 2 +- libraries/config/Validator.class.php | 11 +- libraries/core.lib.php | 49 +- libraries/db_common.inc.php | 6 +- libraries/db_designer.lib.php | 21 +- libraries/db_table_exists.lib.php | 12 +- libraries/display_change_password.lib.php | 11 +- libraries/display_export.lib.php | 17 +- libraries/display_git_revision.lib.php | 4 +- libraries/error_report.lib.php | 6 +- libraries/export.lib.php | 60 +- libraries/file_listing.lib.php | 2 +- libraries/gis/GIS_Factory.class.php | 8 +- libraries/gis/GIS_Geometry.class.php | 42 +- .../gis/GIS_Geometrycollection.class.php | 85 +- libraries/gis/GIS_Linestring.class.php | 70 +- libraries/gis/GIS_Multilinestring.class.php | 88 +- libraries/gis/GIS_Multipoint.class.php | 79 +- libraries/gis/GIS_Multipolygon.class.php | 106 +- libraries/gis/GIS_Point.class.php | 42 +- libraries/gis/GIS_Polygon.class.php | 90 +- libraries/gis/GIS_Visualization.class.php | 28 +- libraries/iconv_wrapper.lib.php | 25 +- libraries/import.lib.php | 101 +- libraries/insert_edit.lib.php | 121 +- libraries/ip_allow_deny.lib.php | 22 +- libraries/mime.lib.php | 8 +- libraries/mult_submits.inc.php | 6 +- libraries/mult_submits.lib.php | 21 +- .../navigation/NavigationHeader.class.php | 94 +- libraries/navigation/NavigationTree.class.php | 24 +- .../navigation/Nodes/Node_Database.class.php | 4 +- libraries/normalization.lib.php | 4 +- libraries/operations.lib.php | 25 +- libraries/parse_analyze.inc.php | 2 +- libraries/plugin_interface.lib.php | 42 +- .../auth/AuthenticationCookie.class.php | 7 +- libraries/plugins/export/ExportCsv.class.php | 8 +- .../plugins/export/ExportLatex.class.php | 18 +- libraries/plugins/export/ExportSql.class.php | 656 +++++----- libraries/plugins/export/ExportXml.class.php | 5 +- .../plugins/export/TableProperty.class.php | 44 +- libraries/plugins/import/ImportCsv.class.php | 33 +- .../plugins/import/ImportMediawiki.class.php | 27 +- libraries/plugins/import/ImportShp.class.php | 18 +- libraries/plugins/import/ImportSql.class.php | 69 +- .../schema/dia/Dia_Relation_Schema.class.php | 4 +- .../schema/eps/Eps_Relation_Schema.class.php | 6 +- .../schema/pdf/Pdf_Relation_Schema.class.php | 7 +- .../schema/svg/Svg_Relation_Schema.class.php | 6 +- .../DateFormatTransformationsPlugin.class.php | 37 +- .../SubstringTransformationsPlugin.class.php | 10 +- libraries/pmd_common.php | 18 +- libraries/relation.lib.php | 26 +- libraries/replication.inc.php | 7 +- libraries/replication_gui.lib.php | 14 +- libraries/rte/rte_events.lib.php | 14 +- libraries/rte/rte_footer.lib.php | 9 +- libraries/rte/rte_main.inc.php | 2 +- libraries/rte/rte_routines.lib.php | 83 +- libraries/rte/rte_triggers.lib.php | 14 +- libraries/rte/rte_words.lib.php | 2 +- libraries/sanitizing.lib.php | 6 +- libraries/select_lang.lib.php | 13 +- libraries/server_databases.lib.php | 2 +- libraries/server_plugins.lib.php | 9 +- libraries/server_privileges.lib.php | 207 ++- libraries/server_status_monitor.lib.php | 30 +- libraries/server_status_processes.lib.php | 8 +- libraries/server_status_variables.lib.php | 9 +- libraries/server_user_groups.lib.php | 17 +- libraries/server_variables.lib.php | 2 +- libraries/sql.lib.php | 31 +- libraries/sql_query_form.lib.php | 16 +- libraries/sqlparser.lib.php | 215 +-- libraries/structure.lib.php | 81 +- libraries/sysinfo.lib.php | 8 +- libraries/tbl_columns_definition_form.inc.php | 6 +- libraries/tbl_columns_definition_form.lib.php | 28 +- libraries/tbl_indexes.lib.php | 5 +- libraries/tbl_info.inc.php | 7 +- libraries/tbl_relation.lib.php | 136 +- libraries/tbl_tracking.lib.php | 36 +- libraries/transformations.lib.php | 33 +- libraries/url_generating.lib.php | 14 +- prefs_manage.php | 10 +- scripts/decode_bug.php | 5 +- setup/frames/index.inc.php | 3 +- setup/lib/ConfigGenerator.class.php | 2 +- sql.php | 7 +- tbl_addfield.php | 4 +- tbl_change.php | 2 +- tbl_chart.php | 11 +- tbl_create.php | 7 +- tbl_get_field.php | 2 +- tbl_operations.php | 9 +- tbl_printview.php | 7 +- test/bootstrap-dist.php | 1 + test/classes/PMA_Config_test.php | 18 +- test/classes/PMA_DisplayResults_test.php | 1 - .../auth/PMA_AuthenticationCookie_test.php | 2 +- test/classes/plugin/import/ImportShp_test.php | 1 + test/libraries/PMA_StringMB_test.php | 48 + test/libraries/PMA_StringNative_test.php | 48 + test/libraries/PMA_String_Compare_test.php | 1161 +++++++++++++++++ test/libraries/PMA_browse_foreigners_test.php | 1 - test/libraries/PMA_central_columns_test.php | 9 +- test/libraries/PMA_display_export_test.php | 2 +- test/libraries/PMA_relation_cleanup_test.php | 15 +- .../core/PMA_warnMissingExtension_test.php | 2 +- test/selenium/PmaSeleniumTableInsertTest.php | 2 +- test/selenium/PmaSeleniumXssTest.php | 2 +- test/selenium/TestBase.php | 12 +- themes/svg_gradient.php | 2 +- transformation_wrapper.php | 2 +- 164 files changed, 5187 insertions(+), 2015 deletions(-) create mode 100644 test/libraries/PMA_String_Compare_test.php 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..a2c271a702 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,6 +454,10 @@ class PMA_DbQbe $html_output = ''; $html_output .= '' . __('Sort:') . ''; $new_column_count = 0; + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + for ( $column_index = 0; $column_index < $this->_criteria_column_count; @@ -477,7 +481,7 @@ class PMA_DbQbe // then sorting is not available, Fix for Bug #570698 if (isset($_REQUEST['criteriaSort'][$column_index]) && isset($_REQUEST['criteriaColumn'][$column_index]) - && substr($_REQUEST['criteriaColumn'][$column_index], -2) == '.*' + && $pmaString->substr($_REQUEST['criteriaColumn'][$column_index], -2) == '.*' ) { $_REQUEST['criteriaSort'][$column_index] = ''; } //end if @@ -995,6 +999,9 @@ class PMA_DbQbe */ private function _getWhereClause() { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $where_clause = ''; $criteria_cnt = 0; for ( @@ -1009,7 +1016,7 @@ class PMA_DbQbe && isset($this->_curAndOrCol) ) { $where_clause .= ' ' - . strtoupper($this->_curAndOrCol[$last_where]) . ' '; + . $pmaString->strtoupper($this->_curAndOrCol[$last_where]) . ' '; } if (! empty($this->_curField[$column_index]) && ! empty($this->_curCriteria[$column_index]) @@ -1045,7 +1052,8 @@ class PMA_DbQbe && $column_index ) { $qry_orwhere .= ' ' - . strtoupper($this->_curAndOrCol[$last_orwhere]) . ' '; + . $pmaString->strtoupper($this->_curAndOrCol[$last_orwhere]) + . ' '; } if (! empty($this->_curField[$column_index]) && ! empty($_REQUEST['Or' . $row_index][$column_index]) @@ -1063,7 +1071,7 @@ class PMA_DbQbe } if (! empty($qry_orwhere)) { $where_clause .= "\n" - . strtoupper( + . $pmaString->strtoupper( isset($this->_curAndOrRow[$row_index]) ? $this->_curAndOrRow[$row_index] . ' ' : '' @@ -1087,6 +1095,10 @@ class PMA_DbQbe { $orderby_clause = ''; $orderby_clauses = array(); + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + for ( $column_index = 0; $column_index < $this->_criteria_column_count; @@ -1095,15 +1107,18 @@ class PMA_DbQbe // if all columns are chosen with * selector, // then sorting isn't available // Fix for Bug #570698 - if (! empty($this->_curField[$column_index]) - && ! empty($this->_curSort[$column_index]) + if (empty($this->_curField[$column_index]) + && empty($this->_curSort[$column_index]) ) { - if (substr($this->_curField[$column_index], -2) == '.*') { - continue; - } - $orderby_clauses[] = $this->_curField[$column_index] . ' ' - . $this->_curSort[$column_index]; + continue; } + + if ($pmaString->substr($this->_curField[$column_index], -2) == '.*') { + continue; + } + + $orderby_clauses[] = $this->_curField[$column_index] . ' ' + . $this->_curSort[$column_index]; } // end for if ($orderby_clauses) { $orderby_clause = 'ORDER BY ' @@ -1243,7 +1258,7 @@ class PMA_DbQbe // table, whether they have any matching row in child table or not. // So we select candidate tables which are foreign tables. $foreign_tables = array(); - foreach ($candidate_columns as $key => $one_table) { + foreach ($candidate_columns as $one_table) { $foreigners = PMA_getForeigners($this->_db, $one_table); foreach ($foreigners as $key => $foreigner) { if ($key != 'foreign_keys_data') { @@ -1251,16 +1266,12 @@ class PMA_DbQbe $foreign_tables[$foreigner['foreign_table']] = $foreigner['foreign_table']; } - } else { - foreach ($foreigner as $one_key) { - if (in_array( - $one_key['ref_table_name'], - $candidate_columns - ) - ) { - $foreign_tables[$one_key['ref_table_name']] - = $one_key['ref_table_name']; - } + continue; + } + foreach ($foreigner as $one_key) { + if (in_array($one_key['ref_table_name'], $candidate_columns)) { + $foreign_tables[$one_key['ref_table_name']] + = $one_key['ref_table_name']; } } } @@ -1311,6 +1322,10 @@ class PMA_DbQbe { $where_clause_columns = array(); $where_clause_tables = array(); + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Now we need all tables that we have in the where clause for ( $column_index = 0, $nb = count($this->_criteria); @@ -1327,8 +1342,8 @@ class PMA_DbQbe // Now we know that our array has the same numbers as $criteria // we can check which of our columns has a where clause if (! empty($this->_criteria[$column_index])) { - if (substr($this->_criteria[$column_index], 0, 1) == '=' - || stristr($this->_criteria[$column_index], 'is') + if ($pmaString->substr($this->_criteria[$column_index], 0, 1) == '=' + || /*$pmaString->*/stristr($this->_criteria[$column_index], 'is') ) { $where_clause_columns[$column] = $column; $where_clause_tables[$table] = $table; diff --git a/libraries/DatabaseInterface.class.php b/libraries/DatabaseInterface.class.php index 8eda8304ae..0f2bcc378c 100644 --- a/libraries/DatabaseInterface.class.php +++ b/libraries/DatabaseInterface.class.php @@ -497,12 +497,15 @@ class PMA_DatabaseInterface $sql, array('TABLE_SCHEMA', 'TABLE_NAME'), null, $link ); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if (PMA_DRIZZLE) { // correct I_S and D_D names returned by D_D.TABLES - // Drizzle generally uses lower case for them, // but TABLES returns uppercase foreach ((array)$database as $db) { - $db_upper = strtoupper($db); + $db_upper = $pmaString->strtoupper($db); if (!isset($tables[$db]) && isset($tables[$db_upper])) { $tables[$db] = $tables[$db_upper]; unset($tables[$db_upper]); @@ -543,32 +546,36 @@ class PMA_DatabaseInterface $this->_cacheTableData($tables, $table); - if (! is_array($database)) { - if (isset($tables[$database])) { - return $tables[$database]; - } elseif (isset($tables[strtolower($database)])) { - // on windows with lower_case_table_names = 1 - // MySQL returns - // with SHOW DATABASES or information_schema.SCHEMATA: `Test` - // but information_schema.TABLES gives `test` - // bug #2036 - // https://sourceforge.net/p/phpmyadmin/bugs/2036/ - return $tables[strtolower($database)]; - } else { - // one database but inexact letter case match - // as Drizzle is always case insensitive, - // we can safely return the only result - if (PMA_DRIZZLE && count($tables) == 1) { - $keys = array_keys($tables); - if (strlen(array_pop($keys)) == strlen($database)) { - return array_pop($tables); - } - } - return $tables; - } - } else { + if (is_array($database)) { return $tables; } + + if (isset($tables[$database])) { + return $tables[$database]; + } + + if (isset($tables[$pmaString->strtolower($database)])) { + // on windows with lower_case_table_names = 1 + // MySQL returns + // with SHOW DATABASES or information_schema.SCHEMATA: `Test` + // but information_schema.TABLES gives `test` + // bug #2036 + // https://sourceforge.net/p/phpmyadmin/bugs/2036/ + return $tables[$pmaString->strtolower($database)]; + } + + // one database but inexact letter case match + // as Drizzle is always case insensitive, + // we can safely return the only result + if (!PMA_DRIZZLE || !count($tables) == 1) { + return $tables; + } + + $keys = array_keys($tables); + if ($pmaString->strlen(array_pop($keys)) == $pmaString->strlen($database)) { + return array_pop($tables); + } + return $tables; } /** @@ -640,7 +647,9 @@ class PMA_DatabaseInterface $tables[$table_name]['TABLE_COMMENT'] =& $tables[$table_name]['Comment']; - if (strtoupper($tables[$table_name]['Comment']) === 'VIEW' + $commentUpper = $GLOBALS['PMA_String'] + ->strtoupper($tables[$table_name]['Comment']); + if ($commentUpper === 'VIEW' && $tables[$table_name]['Engine'] == null ) { $tables[$table_name]['TABLE_TYPE'] = 'VIEW'; @@ -701,7 +710,7 @@ class PMA_DatabaseInterface $link = null, $sort_by = 'SCHEMA_NAME', $sort_order = 'ASC', $limit_offset = 0, $limit_count = false ) { - $sort_order = strtoupper($sort_order); + $sort_order = $GLOBALS['PMA_String']->strtoupper($sort_order); if (true === $limit_count) { $limit_count = $GLOBALS['cfg']['MaxDbList']; @@ -1830,7 +1839,8 @@ class PMA_DatabaseInterface $error .= ' - ' . $error_message; $error .= '
' . __('The server is not responding.'); } elseif ($error_number == 1005) { - if (strpos($error_message, 'errno: 13') !== false) { + if ($GLOBALS['PMA_String']->strpos($error_message, 'errno: 13') !== false + ) { $error .= ' - ' . $error_message; $error .= '
' . __('Please check privileges of directory containing database.'); @@ -1951,9 +1961,13 @@ class PMA_DatabaseInterface */ public function isSystemSchema($schema_name, $testForMysqlSchema = false) { - return strtolower($schema_name) == 'information_schema' - || (!PMA_DRIZZLE && strtolower($schema_name) == 'performance_schema') - || (PMA_DRIZZLE && strtolower($schema_name) == 'data_dictionary') + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + return $pmaString->strtolower($schema_name) == 'information_schema' + || (!PMA_DRIZZLE + && $pmaString->strtolower($schema_name) == 'performance_schema') + || (PMA_DRIZZLE + && $pmaString->strtolower($schema_name) == 'data_dictionary') || ($testForMysqlSchema && !PMA_DRIZZLE && $schema_name == 'mysql'); } diff --git a/libraries/DbSearch.class.php b/libraries/DbSearch.class.php index 9fcd2e75f4..8d029dc827 100644 --- a/libraries/DbSearch.class.php +++ b/libraries/DbSearch.class.php @@ -214,16 +214,18 @@ class PMA_DbSearch ? array($this->_criteriaSearchString) : explode(' ', $this->_criteriaSearchString)); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; foreach ($search_words as $search_word) { // Eliminates empty values - if (strlen($search_word) === 0) { + if ($pmaString->strlen($search_word) === 0) { continue; } $likeClausesPerColumn = array(); // for each column in the table foreach ($allColumns as $column) { if (! isset($this->_criteriaColumnName) - || strlen($this->_criteriaColumnName) == 0 + || $pmaString->strlen($this->_criteriaColumnName) == 0 || $column['Field'] == $this->_criteriaColumnName ) { // Drizzle has no CONVERT and all text columns are UTF-8 diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index 921fa09628..7553dbd3e5 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -387,6 +387,8 @@ class PMA_DisplayResults // 2. Display mode is not "false for all elements" -> updates the // display mode + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; if ($the_disp_mode != 'nnnn000000') { if (isset($printview) && ($printview == '1')) { @@ -433,7 +435,7 @@ class PMA_DisplayResults $this->__get('sql_query'), $which ); if (isset($which[1]) - && (strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) + && ($pmaString->strpos(' ' . $pmaString->strtoupper($which[1]), 'PROCESSLIST') > 0) ) { // no edit link $do_display['edit_lnk'] = self::NO_EDIT_OR_DELETE; @@ -500,7 +502,7 @@ class PMA_DisplayResults $the_total = $unlim_num_rows; } elseif ((($do_display['nav_bar'] == '1') || ($do_display['sort_lnk'] == '1')) - && (strlen($db) && !empty($table)) + && ($pmaString->strlen($db) && !empty($table)) ) { $the_total = PMA_Table::countRecords($db, $table); } @@ -1842,7 +1844,7 @@ class PMA_DisplayResults // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2` $sort_tbl = (isset($fields_meta->table) - && strlen($fields_meta->table)) + && $GLOBALS['PMA_String']->strlen($fields_meta->table)) ? PMA_Util::backquote( $fields_meta->table ) . '.' @@ -1945,6 +1947,9 @@ class PMA_DisplayResults )) ? self::DESCENDING_SORT_DIR : self::ASCENDING_SORT_DIR; } + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; $sort_expression_nodirection = array_filter($sort_expression_nodirection); foreach ($sort_expression_nodirection as $index=>$expression) { // check if this is the first clause, @@ -1954,7 +1959,7 @@ class PMA_DisplayResults $sort_tbl_new = $sort_tbl; // Test to detect if the column name is a standard name // Standard name has the table name prefixed to the column name - if (strpos($name_to_use_in_sort, '.') !== false) { + if ($pmaString->strpos($name_to_use_in_sort, '.') !== false) { $matches = explode('.', $name_to_use_in_sort); // Matches[0] has the table name // Matches[1] has the column name @@ -1972,7 +1977,7 @@ class PMA_DisplayResults // order by clause to the column name $query_head = $is_first_clause ? "\nORDER BY " : ""; // Again a check to see if the given column is a aggregate column - if (strpos($name_to_use_in_sort, '(') !== false) { + if ($pmaString->strpos($name_to_use_in_sort, '(') !== false) { $sort_order .= $query_head . $name_to_use_in_sort . ' ' ; } else { $sort_order .= $query_head . $sort_tbl_new . "." @@ -1986,7 +1991,7 @@ class PMA_DisplayResults $sort_order = preg_replace("/\.\./", ".", $sort_order); // Incase this is the current column save $single_sort_order if ($current_name == $name_to_use_in_sort) { - if (strpos($current_name, '(') !== false) { + if ($pmaString->strpos($current_name, '(') !== false) { $single_sort_order = "\n" . 'ORDER BY ' . $current_name . ' '; } else { $single_sort_order = "\n" . 'ORDER BY ' . $sort_tbl @@ -1999,7 +2004,8 @@ class PMA_DisplayResults $sort_direction, $single_sort_order, $column_index, $index ); } else { - $single_sort_order .= strtoupper($sort_direction[$index]); + $single_sort_order .= $pmaString + ->strtoupper($sort_direction[$index]); } } if ($current_name == $name_to_use_in_sort && $is_in_sort) { @@ -2009,7 +2015,7 @@ class PMA_DisplayResults ); $order_img .= " " . ($index + 1) . ""; } else { - $sort_order .= strtoupper($sort_direction[$index]); + $sort_order .= $pmaString->strtoupper($sort_direction[$index]); } // Separate columns by a comma $sort_order .= ", "; @@ -2018,7 +2024,11 @@ class PMA_DisplayResults } // remove the comma from the last column name in the newly // constructed clause - $sort_order = substr($sort_order, 0, strlen($sort_order)-2); + $sort_order = $pmaString->substr( + $sort_order, + 0, + $pmaString->strlen($sort_order)-2 + ); if (empty($order_img)) { $order_img = ''; } @@ -2046,8 +2056,10 @@ class PMA_DisplayResults $index_in_expression = 0; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; foreach ($sort_expression_nodirection as $index => $clause) { - if (strpos($clause, '.') !== false) { + if ($pmaString->strpos($clause, '.') !== false) { $fragments = explode('.', $clause); $clause2 = $fragments[0] . "." . str_replace('`', '', $fragments[1]); } else { @@ -2071,8 +2083,8 @@ class PMA_DisplayResults // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p // (and try clicking on each column's header twice) if (! empty($sort_tbl) - && strpos($sort_expression_nodirection[$index_in_expression], $sort_tbl) === false - && strpos($sort_expression_nodirection[$index_in_expression], '(') === false + && $pmaString->strpos($sort_expression_nodirection[$index_in_expression], $sort_tbl) === false + && $pmaString->strpos($sort_expression_nodirection[$index_in_expression], '(') === false ) { $new_sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection[$index_in_expression]; @@ -2117,7 +2129,7 @@ class PMA_DisplayResults private function _getSortingUrlParams( $sort_direction, $sort_order, $column_index, $index ) { - if (strtoupper(trim($sort_direction[$index])) == self::DESCENDING_SORT_DIR) { + if ($GLOBALS['PMA_String']->strtoupper(trim($sort_direction[$index])) == self::DESCENDING_SORT_DIR) { $sort_order .= ' ASC'; $order_img = ' ' . PMA_Util::getImage( 's_desc.png', __('Descending'), @@ -2161,13 +2173,15 @@ class PMA_DisplayResults private function _getSortOrderLink( $order_img, $col_index, $direction, $fields_meta, $order_url, $multi_order_url ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; $order_link_params = array(); if (isset($order_img) && ($order_img != '')) { - if (strstr($order_img, 'asc')) { + if ($pmaString->strstr($order_img, 'asc')) { $order_link_params['onmouseover'] = "$('.soimg$col_index').toggle()"; $order_link_params['onmouseout'] = "$('.soimg$col_index').toggle()"; - } elseif (strstr($order_img, 'desc')) { + } elseif ($pmaString->strstr($order_img, 'desc')) { $order_link_params['onmouseover'] = "$('.soimg$col_index').toggle()"; $order_link_params['onmouseout'] = "$('.soimg$col_index').toggle()"; } @@ -2537,13 +2551,15 @@ class PMA_DisplayResults 'binary' => 'hex', ); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; foreach ($matches as $key => $value) { - if (strpos($meta->flags, $key) !== false) { + if ($pmaString->strpos($meta->flags, $key) !== false) { $classes[] = $value; } } - if (strpos($meta->type, 'bit') !== false) { + if ($pmaString->strpos($meta->type, 'bit') !== false) { $classes[] = 'bit'; } @@ -2813,6 +2829,8 @@ class PMA_DisplayResults $row_info = $this->_getRowInfoForSpecialLinks($row, $col_order); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; for ($currentColumn = 0; $currentColumn < $this->__get('fields_cnt'); ++$currentColumn) { @@ -2912,18 +2930,18 @@ class PMA_DisplayResults // Check whether the field needs to display with syntax highlighting - if (! empty($this->transformation_info[strtolower($this->__get('db'))][strtolower($this->__get('table'))][strtolower($meta->name)]) + if (! empty($this->transformation_info[$pmaString->strtolower($this->__get('db'))][$pmaString->strtolower($this->__get('table'))][$pmaString->strtolower($meta->name)]) && (trim($row[$i]) != '') ) { $row[$i] = PMA_Util::formatSql($row[$i]); include_once $this->transformation_info - [strtolower($this->__get('db'))] - [strtolower($this->__get('table'))] - [strtolower($meta->name)][0]; + [$pmaString->strtolower($this->__get('db'))] + [$pmaString->strtolower($this->__get('table'))] + [$pmaString->strtolower($meta->name)][0]; $transformation_plugin = new $this->transformation_info - [strtolower($this->__get('db'))] - [strtolower($this->__get('table'))] - [strtolower($meta->name)][1](null); + [$pmaString->strtolower($this->__get('db'))] + [$pmaString->strtolower($this->__get('table'))] + [$pmaString->strtolower($meta->name)][1](null); $transform_options = PMA_Transformation_getOptions( isset($mime_map[$meta->name]['transformation_options']) @@ -2931,11 +2949,12 @@ class PMA_DisplayResults : '' ); + $dbLower = $pmaString->strtolower($this->__get('db')); $meta->mimetype = str_replace( '_', '/', - $this->transformation_info[strtolower($this->__get('db'))] - [strtolower($this->__get('table'))] - [strtolower($meta->name)][2] + $this->transformation_info[$dbLower] + [$pmaString->strtolower($this->__get('table'))] + [$pmaString->strtolower($meta->name)][2] ); } @@ -2944,11 +2963,11 @@ class PMA_DisplayResults include_once 'libraries/special_schema_links.lib.php'; if (isset($GLOBALS['special_schema_links']) - && (! empty($GLOBALS['special_schema_links'][strtolower($this->__get('db'))][strtolower($this->__get('table'))][strtolower($meta->name)])) + && (! empty($GLOBALS['special_schema_links'][$pmaString->strtolower($this->__get('db'))][$pmaString->strtolower($this->__get('table'))][$pmaString->strtolower($meta->name)])) ) { $linking_url = $this->_getSpecialLinkUrl( - $row[$i], $row_info, strtolower($meta->name) + $row[$i], $row_info, $pmaString->strtolower($meta->name) ); include_once "libraries/plugins/transformations/Text_Plain_Link.class.php"; @@ -3151,10 +3170,12 @@ class PMA_DisplayResults private function _getSpecialLinkUrl($column_value, $row_info, $field_name) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; $linking_url_params = array(); $link_relations = $GLOBALS['special_schema_links'] - [strtolower($this->__get('db'))] - [strtolower($this->__get('table'))] + [$pmaString->strtolower($this->__get('db'))] + [$pmaString->strtolower($this->__get('table'))] [$field_name]; if (! is_array($link_relations['link_param'])) { @@ -3168,39 +3189,41 @@ class PMA_DisplayResults $linking_url_params[$link_relations['link_param'][0]] = $sql; } - if (! empty($link_relations['link_dependancy_params'])) { + if (empty($link_relations['link_dependancy_params'])) { + return $link_relations['default_page'] + . PMA_URL_getCommon($linking_url_params); + } - foreach ($link_relations['link_dependancy_params'] as $new_param) { + foreach ($link_relations['link_dependancy_params'] as $new_param) { - // If param_info is an array, set the key and value - // from that array - if (is_array($new_param['param_info'])) { - $linking_url_params[$new_param['param_info'][0]] - = $new_param['param_info'][1]; - } else { + // If param_info is an array, set the key and value + // from that array + if (is_array($new_param['param_info'])) { + $linking_url_params[$new_param['param_info'][0]] + = $new_param['param_info'][1]; + continue; + } - $linking_url_params[$new_param['param_info']] - = $row_info[strtolower($new_param['column_name'])]; + $linking_url_params[$new_param['param_info']] + = $row_info[$pmaString->strtolower($new_param['column_name'])]; - // Special case 1 - when executing routines, according - // to the type of the routine, url param changes - if (!empty($row_info['routine_type'])) { - $lowerRoutineType = strtolower($row_info['routine_type']); - if ($lowerRoutineType == self::ROUTINE_PROCEDURE - || $lowerRoutineType == self::ROUTINE_FUNCTION - ) { - $linking_url_params['edit_item'] = 1; - } - } - } + // Special case 1 - when executing routines, according + // to the type of the routine, url param changes + if (empty($row_info['routine_type'])) { + continue; + } + $lowerRoutineType = $pmaString->strtolower($row_info['routine_type']); + if ($lowerRoutineType == self::ROUTINE_PROCEDURE + || $lowerRoutineType == self::ROUTINE_FUNCTION + ) { + $linking_url_params['edit_item'] = 1; } } return $link_relations['default_page'] . PMA_URL_getCommon($linking_url_params); - } @@ -3220,7 +3243,8 @@ class PMA_DisplayResults for ($n = 0; $n < $this->__get('fields_cnt'); ++$n) { $m = $col_order ? $col_order[$n] : $n; - $row_info[strtolower($fields_meta[$m]->name)] = $row[$m]; + $row_info[$GLOBALS['PMA_String']->strtolower($fields_meta[$m]->name)] + = $row[$m]; } return $row_info; @@ -3246,7 +3270,7 @@ class PMA_DisplayResults && isset($analyzed_sql[0]) && isset($analyzed_sql[0]['querytype']) && ($analyzed_sql[0]['querytype'] == self::QUERY_TYPE_SELECT) - && (strlen($this->__get('sql_query')) > 200) + && ($GLOBALS['PMA_String']->strlen($this->__get('sql_query')) > 200) ) { $url_sql_query = 'SELECT '; @@ -3647,7 +3671,7 @@ class PMA_DisplayResults */ private function _getClassForDateTimeRelatedFields($type) { - if ((substr($type, 0, 9) == self::TIMESTAMP_FIELD) + if (($GLOBALS['PMA_String']->substr($type, 0, 9) == self::TIMESTAMP_FIELD) || ($type == self::DATETIME_FIELD) ) { $field_type_class = 'datetimefield'; @@ -3750,76 +3774,78 @@ class PMA_DisplayResults $transformation_plugin, $default_function, $transform_options, $is_field_truncated, $analyzed_sql ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; if (! isset($column) || is_null($column)) { - $cell = $this->_buildNullDisplay($class, $condition_field, $meta); - - } elseif ($column != '') { - - // Display as [GEOMETRY - (size)] - if ($_SESSION['tmpval']['geoOption'] == self::GEOMETRY_DISP_GEOM) { - - $geometry_text = $this->_handleNonPrintableContents( - strtoupper(self::GEOMETRY_FIELD), - (isset($column) ? $column : ''), $transformation_plugin, - $transform_options, $default_function, $meta - ); - - $cell = $this->_buildValueDisplay( - $class, $condition_field, $geometry_text - ); - - } elseif ($_SESSION['tmpval']['geoOption'] == self::GEOMETRY_DISP_WKT) { - // Prepare in Well Known Text(WKT) format. - - $where_comparison = ' = ' . $column; - - // Convert to WKT format - $wktval = PMA_Util::asWKT($column); - $is_field_truncated = $this->_getPartialText($wktval); - - $cell = $this->_getRowData( - $class, $condition_field, $analyzed_sql, $meta, $map, - $wktval, $transformation_plugin, $default_function, '', - $where_comparison, $transform_options, - $is_field_truncated - ); - - } else { - // Prepare in Well Known Binary (WKB) format. - - if ($_SESSION['tmpval']['display_binary']) { - - $where_comparison = ' = ' . $column; - - $wkbval = $GLOBALS['PMA_String']->substr(bin2hex($column), 8); - $is_field_truncated = $this->_getPartialText($wkbval); - - $cell = $this->_getRowData( - $class, $condition_field, - $analyzed_sql, $meta, $map, $wkbval, - $transformation_plugin, $default_function, '', - $where_comparison, $transform_options, - $is_field_truncated - ); - - } else { - $wkbval = $this->_handleNonPrintableContents( - self::BINARY_FIELD, $column, $transformation_plugin, - $transform_options, $default_function, $meta, - $_url_params - ); - - $cell = $this->_buildValueDisplay( - $class, $condition_field, $wkbval - ); - } - } - } else { - $cell = $this->_buildEmptyDisplay($class, $condition_field, $meta); + return $cell; } + if ($column == '') { + $cell = $this->_buildEmptyDisplay($class, $condition_field, $meta); + return $cell; + } + + // Display as [GEOMETRY - (size)] + if ($_SESSION['tmpval']['geoOption'] == self::GEOMETRY_DISP_GEOM) { + $geometry_text = $this->_handleNonPrintableContents( + $pmaString->strtoupper(self::GEOMETRY_FIELD), + (isset($column) ? $column : ''), $transformation_plugin, + $transform_options, $default_function, $meta + ); + + $cell = $this->_buildValueDisplay( + $class, $condition_field, $geometry_text + ); + return $cell; + } + + if ($_SESSION['tmpval']['geoOption'] == self::GEOMETRY_DISP_WKT) { + // Prepare in Well Known Text(WKT) format. + $where_comparison = ' = ' . $column; + + // Convert to WKT format + $wktval = PMA_Util::asWKT($column); + $is_field_truncated = $this->_getPartialText($wktval); + + $cell = $this->_getRowData( + $class, $condition_field, $analyzed_sql, $meta, $map, + $wktval, $transformation_plugin, $default_function, '', + $where_comparison, $transform_options, + $is_field_truncated + ); + return $cell; + } + + // Prepare in Well Known Binary (WKB) format. + + if ($_SESSION['tmpval']['display_binary']) { + $where_comparison = ' = ' . $column; + + $wkbval = $pmaString->substr(bin2hex($column), 8); + $is_field_truncated = $this->_getPartialText($wkbval); + + $cell = $this->_getRowData( + $class, $condition_field, + $analyzed_sql, $meta, $map, $wkbval, + $transformation_plugin, $default_function, '', + $where_comparison, $transform_options, + $is_field_truncated + ); + return $cell; + } + + $wkbval = $this->_handleNonPrintableContents( + self::BINARY_FIELD, $column, $transformation_plugin, + $transform_options, $default_function, $meta, + $_url_params + ); + + $cell = $this->_buildValueDisplay( + $class, $condition_field, $wkbval + ); + return $cell; } // end of the '_getDataCellForGeometryColumns()' function @@ -3861,6 +3887,8 @@ class PMA_DisplayResults $transformation_plugin, $default_function, $transform_options, $is_field_truncated, $analyzed_sql, &$dt_result, $col_index ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; $is_analyse = $this->__get('is_analyse'); $field_flags = $GLOBALS['dbi']->fieldFlags($dt_result, $col_index); @@ -3875,108 +3903,106 @@ class PMA_DisplayResults || ($GLOBALS['cfg']['ProtectBinary'] === 'blob' && stristr($meta->type, self::BLOB_FIELD)))) || (gettype($transformation_plugin) === 'object' - && strpos($transformation_plugin->getMIMEtype(), 'Text') === false) + && $pmaString->strpos($transformation_plugin->getMIMEtype(), 'Text') === false) ) { $class = str_replace('grid_edit', '', $class); } if (! isset($column) || is_null($column)) { - $cell = $this->_buildNullDisplay($class, $condition_field, $meta); - - } elseif ($column != '') { - - // Cut all fields to $GLOBALS['cfg']['LimitChars'] - // (unless it's a link-type transformation or binary) - if (!(gettype($transformation_plugin) === "object" - && strpos($transformation_plugin->getName(), 'Link') !== false) - && !stristr($field_flags, self::BINARY_FIELD) - ) { - $is_field_truncated = $this->_getPartialText($column); - } - - $formatted = false; - if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) { - - $column = PMA_Util::printableBitValue( - $column, $meta->length - ); - - // some results of PROCEDURE ANALYSE() are reported as - // being BINARY but they are quite readable, - // so don't treat them as BINARY - } elseif (stristr($field_flags, self::BINARY_FIELD) - && !(isset($is_analyse) && $is_analyse) - ) { - // we show the BINARY or BLOB message and field's size - // (or maybe use a transformation) - $binary_or_blob = self::BLOB_FIELD; - if ($meta->type === self::STRING_FIELD) { - $binary_or_blob = self::BINARY_FIELD; - } - $column = $this->_handleNonPrintableContents( - $binary_or_blob, $column, $transformation_plugin, - $transform_options, $default_function, - $meta, $_url_params, $is_field_truncated - ); - $class = $this->_addClass( - $class, $condition_field, $meta, '', - $is_field_truncated, $transformation_plugin, $default_function - ); - $result = strip_tags($column); - // disable inline grid editing - // if binary or blob data is not shown - if (stristr($result, $binary_or_blob)) { - $class = str_replace('grid_edit', '', $class); - } - $formatted = true; - - } elseif (((substr($meta->type, 0, 9) == self::TIMESTAMP_FIELD) - || ($meta->type == self::DATETIME_FIELD) - || ($meta->type == self::TIME_FIELD) - || ($meta->type == self::TIME_FIELD)) - && (strpos($column, ".") === true) - ) { - $column = PMA_Util::addMicroseconds($column); - } - - if ($formatted) { - - $cell = $this->_buildValueDisplay( - $class, $condition_field, $column - ); - - } else { - - // transform functions may enable no-wrapping: - $function_nowrap = 'applyTransformationNoWrap'; - - $bool_nowrap = (($default_function != $transformation_plugin) - && function_exists($transformation_plugin->$function_nowrap())) - ? $transformation_plugin->$function_nowrap($transform_options) - : false; - - // do not wrap if date field type - $nowrap = (preg_match('@DATE|TIME@i', $meta->type) - || $bool_nowrap) ? ' nowrap' : ''; - - $where_comparison = ' = \'' - . PMA_Util::sqlAddSlashes($column) - . '\''; - - $cell = $this->_getRowData( - $class, $condition_field, - $analyzed_sql, $meta, $map, $column, - $transformation_plugin, $default_function, $nowrap, - $where_comparison, $transform_options, - $is_field_truncated - ); - } - - } else { - $cell = $this->_buildEmptyDisplay($class, $condition_field, $meta); + return $cell; } + if ($column == '') { + $cell = $this->_buildEmptyDisplay($class, $condition_field, $meta); + return $cell; + } + + // Cut all fields to $GLOBALS['cfg']['LimitChars'] + // (unless it's a link-type transformation or binary) + if (!(gettype($transformation_plugin) === "object" + && $pmaString->strpos($transformation_plugin->getName(), 'Link') !== false) + && !stristr($field_flags, self::BINARY_FIELD) + ) { + $is_field_truncated = $this->_getPartialText($column); + } + + $formatted = false; + if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) { + + $column = PMA_Util::printableBitValue( + $column, $meta->length + ); + + // some results of PROCEDURE ANALYSE() are reported as + // being BINARY but they are quite readable, + // so don't treat them as BINARY + } elseif (stristr($field_flags, self::BINARY_FIELD) + && !(isset($is_analyse) && $is_analyse) + ) { + // we show the BINARY or BLOB message and field's size + // (or maybe use a transformation) + $binary_or_blob = self::BLOB_FIELD; + if ($meta->type === self::STRING_FIELD) { + $binary_or_blob = self::BINARY_FIELD; + } + $column = $this->_handleNonPrintableContents( + $binary_or_blob, $column, $transformation_plugin, + $transform_options, $default_function, + $meta, $_url_params, $is_field_truncated + ); + $class = $this->_addClass( + $class, $condition_field, $meta, '', + $is_field_truncated, $transformation_plugin, $default_function + ); + $result = strip_tags($column); + // disable inline grid editing + // if binary or blob data is not shown + if (stristr($result, $binary_or_blob)) { + $class = str_replace('grid_edit', '', $class); + } + $formatted = true; + + } elseif ((($pmaString->substr($meta->type, 0, 9) == self::TIMESTAMP_FIELD) + || ($meta->type == self::DATETIME_FIELD) + || ($meta->type == self::TIME_FIELD) + || ($meta->type == self::TIME_FIELD)) + && ($pmaString->strpos($column, ".") === true) + ) { + $column = PMA_Util::addMicroseconds($column); + } + + if ($formatted) { + $cell = $this->_buildValueDisplay( + $class, $condition_field, $column + ); + return $cell; + } + + // transform functions may enable no-wrapping: + $function_nowrap = 'applyTransformationNoWrap'; + + $bool_nowrap = (($default_function != $transformation_plugin) + && function_exists($transformation_plugin->$function_nowrap())) + ? $transformation_plugin->$function_nowrap($transform_options) + : false; + + // do not wrap if date field type + $nowrap = (preg_match('@DATE|TIME@i', $meta->type) + || $bool_nowrap) ? ' nowrap' : ''; + + $where_comparison = ' = \'' + . PMA_Util::sqlAddSlashes($column) + . '\''; + + $cell = $this->_getRowData( + $class, $condition_field, + $analyzed_sql, $meta, $map, $column, + $transformation_plugin, $default_function, $nowrap, + $where_comparison, $transform_options, + $is_field_truncated + ); + return $cell; } // end of the '_getDataCellForNonNumericColumns()' function @@ -4509,8 +4535,11 @@ class PMA_DisplayResults ); } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // 2.3 Prepare the navigation bars - if (! strlen($this->__get('table'))) { + if (!$pmaString->strlen($this->__get('table'))) { if (isset($analyzed_sql[0]['query_type']) && ($analyzed_sql[0]['query_type'] == self::QUERY_TYPE_SELECT) @@ -4558,7 +4587,7 @@ class PMA_DisplayResults } - if (strlen($this->__get('table'))) { + if ($pmaString->strlen($this->__get('table'))) { // This method set the values for $map array $this->_setParamForLinkForeignKeyRelatedTables($map); } // end if @@ -4730,97 +4759,102 @@ class PMA_DisplayResults $fields_meta = $this->__get('fields_meta'); // To use array indexes - if (! empty($sort_expression_nodirection)) { + if (empty($sort_expression_nodirection)) { + return null; + } - if (strpos($sort_expression_nodirection, '.') === false) { - $sort_table = $this->__get('table'); - $sort_column = $sort_expression_nodirection; - } else { - list($sort_table, $sort_column) - = explode('.', $sort_expression_nodirection); - } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if ($pmaString->strpos($sort_expression_nodirection, '.') === false) { + $sort_table = $this->__get('table'); + $sort_column = $sort_expression_nodirection; + } else { + list($sort_table, $sort_column) + = explode('.', $sort_expression_nodirection); + } - $sort_table = PMA_Util::unQuote($sort_table); - $sort_column = PMA_Util::unQuote($sort_column); + $sort_table = PMA_Util::unQuote($sort_table); + $sort_column = PMA_Util::unQuote($sort_column); - // find the sorted column index in row result - // (this might be a multi-table query) - $sorted_column_index = false; + // find the sorted column index in row result + // (this might be a multi-table query) + $sorted_column_index = false; - foreach ($fields_meta as $key => $meta) { - if (($meta->table == $sort_table) && ($meta->name == $sort_column)) { - $sorted_column_index = $key; - break; - } - } - - if ($sorted_column_index !== false) { - - // fetch first row of the result set - $row = $GLOBALS['dbi']->fetchRow($dt_result); - - // initializing default arguments - $default_function = 'PMA_mimeDefaultFunction'; - $transformation_plugin = $default_function; - $transform_options = array(); - - // check for non printable sorted row data - $meta = $fields_meta[$sorted_column_index]; - - if (stristr($meta->type, self::BLOB_FIELD) - || ($meta->type == self::GEOMETRY_FIELD) - ) { - - $column_for_first_row = $this->_handleNonPrintableContents( - $meta->type, $row[$sorted_column_index], - $transformation_plugin, $transform_options, - $default_function, $meta, null - ); - - } else { - $column_for_first_row = $row[$sorted_column_index]; - } - - $column_for_first_row = strtoupper( - substr($column_for_first_row, 0, $GLOBALS['cfg']['LimitChars']) - ); - - // fetch last row of the result set - $GLOBALS['dbi']->dataSeek($dt_result, $this->__get('num_rows') - 1); - $row = $GLOBALS['dbi']->fetchRow($dt_result); - - // check for non printable sorted row data - $meta = $fields_meta[$sorted_column_index]; - if (stristr($meta->type, self::BLOB_FIELD) - || ($meta->type == self::GEOMETRY_FIELD) - ) { - - $column_for_last_row = $this->_handleNonPrintableContents( - $meta->type, $row[$sorted_column_index], - $transformation_plugin, $transform_options, - $default_function, $meta, null - ); - - } else { - $column_for_last_row = $row[$sorted_column_index]; - } - - $column_for_last_row = strtoupper( - substr($column_for_last_row, 0, $GLOBALS['cfg']['LimitChars']) - ); - - // reset to first row for the loop in _getTableBody() - $GLOBALS['dbi']->dataSeek($dt_result, 0); - - // we could also use here $sort_expression_nodirection - return ' [' . htmlspecialchars($sort_column) - . ': ' . htmlspecialchars($column_for_first_row) . ' - ' - . htmlspecialchars($column_for_last_row) . ']'; + foreach ($fields_meta as $key => $meta) { + if (($meta->table == $sort_table) && ($meta->name == $sort_column)) { + $sorted_column_index = $key; + break; } } - return null; + if ($sorted_column_index === false) { + return null; + } + // fetch first row of the result set + $row = $GLOBALS['dbi']->fetchRow($dt_result); + + // initializing default arguments + $default_function = 'PMA_mimeDefaultFunction'; + $transformation_plugin = $default_function; + $transform_options = array(); + + // check for non printable sorted row data + $meta = $fields_meta[$sorted_column_index]; + + if (stristr($meta->type, self::BLOB_FIELD) + || ($meta->type == self::GEOMETRY_FIELD) + ) { + + $column_for_first_row = $this->_handleNonPrintableContents( + $meta->type, $row[$sorted_column_index], + $transformation_plugin, $transform_options, + $default_function, $meta, null + ); + + } else { + $column_for_first_row = $row[$sorted_column_index]; + } + + $column_for_first_row = $pmaString->strtoupper( + $pmaString->substr( + $column_for_first_row, 0, $GLOBALS['cfg']['LimitChars'] + ) + ); + + // fetch last row of the result set + $GLOBALS['dbi']->dataSeek($dt_result, $this->__get('num_rows') - 1); + $row = $GLOBALS['dbi']->fetchRow($dt_result); + + // check for non printable sorted row data + $meta = $fields_meta[$sorted_column_index]; + if (stristr($meta->type, self::BLOB_FIELD) + || ($meta->type == self::GEOMETRY_FIELD) + ) { + + $column_for_last_row = $this->_handleNonPrintableContents( + $meta->type, $row[$sorted_column_index], + $transformation_plugin, $transform_options, + $default_function, $meta, null + ); + + } else { + $column_for_last_row = $row[$sorted_column_index]; + } + + $column_for_last_row = $pmaString->strtoupper( + $pmaString->substr( + $column_for_last_row, 0, $GLOBALS['cfg']['LimitChars'] + ) + ); + + // reset to first row for the loop in _getTableBody() + $GLOBALS['dbi']->dataSeek($dt_result, 0); + + // we could also use here $sort_expression_nodirection + return ' [' . htmlspecialchars($sort_column) + . ': ' . htmlspecialchars($column_for_first_row) . ' - ' + . htmlspecialchars($column_for_last_row) . ']'; } // end of the '_getSortedColumnMessage()' function @@ -5431,9 +5465,11 @@ class PMA_DisplayResults $is_truncated = false; $result = '[' . $category; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; if (isset($content)) { - $size = strlen($content); + $size = $pmaString->strlen($content); $display_size = PMA_Util::formatByteDown($size, 3, 1); $result .= ' - ' . $display_size[0] . ' ' . $display_size[1]; @@ -5447,44 +5483,50 @@ class PMA_DisplayResults $result .= ']'; // if we want to use a text transformation on a BLOB column - if (gettype($transformation_plugin) === "object" - && (strpos($transformation_plugin->getMIMESubtype(), 'Octetstream') - || strpos($transformation_plugin->getMIMEtype(), 'Text') !== false) - ) { - // Applying Transformations on hex string of binary data - // seems more appropriate - $result = bin2hex($content); + if (gettype($transformation_plugin) === "object") { + $posMimeOctetstream = $pmaString + ->strpos($transformation_plugin->getMIMESubtype(), 'Octetstream'); + $posMimeText = $pmaString + ->strpos($transformation_plugin->getMIMEtype(), 'Text'); + if ($posMimeOctetstream + || $posMimeText !== false + ) { + // Applying Transformations on hex string of binary data + // seems more appropriate + $result = bin2hex($content); + } } - if ($size > 0) { + if ($size <= 0) { + return($result); + } - if ($default_function != $transformation_plugin) { - $result = $transformation_plugin->applyTransformation( - $result, - $transform_options, - $meta - ); - } else { + if ($default_function != $transformation_plugin) { + $result = $transformation_plugin->applyTransformation( + $result, + $transform_options, + $meta + ); + return($result); + } - $result = $default_function($result, array(), $meta); - if (($_SESSION['tmpval']['display_binary'] - && $meta->type === self::STRING_FIELD) - || ($_SESSION['tmpval']['display_blob'] - && stristr($meta->type, self::BLOB_FIELD)) - ) { - // in this case, restart from the original $content - $result = bin2hex($content); - $is_truncated = $this->_getPartialText($result); - } + $result = $default_function($result, array(), $meta); + if (($_SESSION['tmpval']['display_binary'] + && $meta->type === self::STRING_FIELD) + || ($_SESSION['tmpval']['display_blob'] + && stristr($meta->type, self::BLOB_FIELD)) + ) { + // in this case, restart from the original $content + $result = bin2hex($content); + $is_truncated = $this->_getPartialText($result); + } - /* Create link to download */ - if (count($url_params) > 0) { - $result = '' - . $result . ''; - } - } + /* Create link to download */ + if (count($url_params) > 0) { + $result = '' + . $result . ''; } return($result); @@ -5538,6 +5580,8 @@ class PMA_DisplayResults ) . '">'; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr']) ) { @@ -5549,7 +5593,7 @@ class PMA_DisplayResults $alias = $analyzed_sql[0]['select_expr'] [$select_expr_position]['alias']; - if (!isset($alias) || !strlen($alias)) { + if (!isset($alias) || !$pmaString->strlen($alias)) { continue; } // end if @@ -5568,7 +5612,9 @@ class PMA_DisplayResults if (isset($map[$meta->name])) { // Field to display from the foreign table? - if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) { + if (isset($map[$meta->name][2]) + && $pmaString->strlen($map[$meta->name][2]) + ) { $dispsql = 'SELECT ' . PMA_Util::backquote($map[$meta->name][2]) diff --git a/libraries/Error.class.php b/libraries/Error.class.php index 842af8c66e..4e5b22ca2b 100644 --- a/libraries/Error.class.php +++ b/libraries/Error.class.php @@ -251,7 +251,9 @@ class PMA_Error extends PMA_Message */ public function getHtmlTitle() { - return htmlspecialchars(substr($this->getTitle(), 0, 100)); + return htmlspecialchars( + $GLOBALS['PMA_String']->substr($this->getTitle(), 0, 100) + ); } /** @@ -435,7 +437,7 @@ class PMA_Error extends PMA_Message { $dest = realpath($dest); - if (substr(PHP_OS, 0, 3) == 'WIN') { + if ($GLOBALS['PMA_String']->substr(PHP_OS, 0, 3) == 'WIN') { $separator = '\\'; } else { $separator = '/'; diff --git a/libraries/File.class.php b/libraries/File.class.php index 600e2f8706..78596ff594 100644 --- a/libraries/File.class.php +++ b/libraries/File.class.php @@ -714,7 +714,7 @@ class PMA_File */ public function getContentLength() { - return strlen($this->_content); + return $GLOBALS['PMA_String']->strlen($this->_content); } /** diff --git a/libraries/Font.class.php b/libraries/Font.class.php index 3fdfda67cb..d32ce510be 100644 --- a/libraries/Font.class.php +++ b/libraries/Font.class.php @@ -104,18 +104,21 @@ class PMA_Font */ $count = 0; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; foreach ($charLists as $charList) { - $count += ((strlen($text) - - strlen(str_replace($charList["chars"], "", $text)) + $count += (($pmaString->strlen($text) + - $pmaString->strlen(str_replace($charList["chars"], "", $text)) ) * $charList["modifier"]); } $text = str_replace(" ", "", $text);//remove the " "'s //all other chars - $count = $count + (strlen(preg_replace("/[a-z0-9]/i", "", $text)) * 0.3); + $count = $count + + ($pmaString->strlen(preg_replace("/[a-z0-9]/i", "", $text)) * 0.3); $modifier = 1; - $font = strtolower($font); + $font = $pmaString->strtolower($font); switch ($font) { /* * no modifier for arial and sans-serif diff --git a/libraries/Header.class.php b/libraries/Header.class.php index 8438c55df2..552cf7f4f0 100644 --- a/libraries/Header.class.php +++ b/libraries/Header.class.php @@ -557,10 +557,12 @@ class PMA_Header $lang = $GLOBALS['available_languages'][$GLOBALS['lang']][1]; $dir = $GLOBALS['text_dir']; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; $retval = ""; $retval .= ""; return $retval; @@ -704,7 +706,7 @@ class PMA_Header { $retval = ''; if ($this->_menuEnabled - && strlen($table) + && $GLOBALS['PMA_String']->strlen($table) && $GLOBALS['cfg']['NumRecentTables'] > 0 ) { $tmp_result = PMA_RecentFavoriteTable::getInstance('recent')->add($db, $table); diff --git a/libraries/Index.class.php b/libraries/Index.class.php index a8bd0117bf..5128138c26 100644 --- a/libraries/Index.class.php +++ b/libraries/Index.class.php @@ -111,7 +111,7 @@ class PMA_Index PMA_Index::_loadIndexes($table, $schema); if (! isset(PMA_Index::$_registry[$schema][$table][$index_name])) { $index = new PMA_Index; - if (strlen($index_name)) { + if ($GLOBALS['PMA_String']->strlen($index_name)) { $index->setName($index_name); PMA_Index::$_registry[$schema][$table][$index->getName()] = $index; } @@ -199,7 +199,9 @@ class PMA_Index */ public function addColumn($params) { - if (isset($params['Column_name']) && strlen($params['Column_name'])) { + if (isset($params['Column_name']) + && $GLOBALS['PMA_String']->strlen($params['Column_name']) + ) { $this->_columns[$params['Column_name']] = new PMA_Index_Column($params); } } @@ -339,7 +341,7 @@ class PMA_Index public function getComments() { $comments = $this->getRemarks(); - if (strlen($comments)) { + if ($GLOBALS['PMA_String']->strlen($comments)) { $comments .= "\n"; } $comments .= $this->getComment(); diff --git a/libraries/List_Database.class.php b/libraries/List_Database.class.php index fbf9315c70..efe1f87a17 100644 --- a/libraries/List_Database.class.php +++ b/libraries/List_Database.class.php @@ -142,7 +142,7 @@ class PMA_List_Database extends PMA_List protected function checkOnlyDatabase() { if (is_string($GLOBALS['cfg']['Server']['only_db']) - && strlen($GLOBALS['cfg']['Server']['only_db']) + && $GLOBALS['PMA_String']->strlen($GLOBALS['cfg']['Server']['only_db']) ) { $GLOBALS['cfg']['Server']['only_db'] = array( $GLOBALS['cfg']['Server']['only_db'] @@ -183,7 +183,7 @@ class PMA_List_Database extends PMA_List */ public function getDefault() { - if (strlen($GLOBALS['db'])) { + if ($GLOBALS['PMA_String']->strlen($GLOBALS['db'])) { return $GLOBALS['db']; } diff --git a/libraries/Menu.class.php b/libraries/Menu.class.php index 824038ccb6..11ea715ea0 100644 --- a/libraries/Menu.class.php +++ b/libraries/Menu.class.php @@ -81,7 +81,7 @@ class PMA_Menu */ public function getHash() { - return substr( + return $GLOBALS['PMA_String']->substr( md5($this->_getMenu() . $this->_getBreadcrumbs()), 0, 8 @@ -98,11 +98,13 @@ class PMA_Menu $url_params = array('db' => $this->_db); $level = ''; - if (strlen($this->_table)) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if ($pmaString->strlen($this->_table)) { $tabs = $this->_getTableTabs(); $url_params['table'] = $this->_table; $level = 'table'; - } else if (strlen($this->_db)) { + } else if ($pmaString->strlen($this->_db)) { $tabs = $this->_getDbTabs(); $level = 'db'; } else { @@ -146,8 +148,14 @@ class PMA_Menu $result = PMA_queryAsControlUser($sql_query, false); if ($result) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + while ($row = $GLOBALS['dbi']->fetchAssoc($result)) { - $tabName = substr($row['tab'], strpos($row['tab'], '_') + 1); + $tabName = $pmaString->substr( + $row['tab'], + $pmaString->strpos($row['tab'], '_') + 1 + ); unset($allowedTabs[$tabName]); } } @@ -195,7 +203,10 @@ class PMA_Menu __('Server') ); - if (strlen($this->_db)) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + if ($pmaString->strlen($this->_db)) { $retval .= $separator; if (PMA_Util::showIcons('TabsMode')) { $retval .= PMA_Util::getImage( @@ -213,7 +224,7 @@ class PMA_Menu ); // if the table is being dropped, $_REQUEST['purge'] is set to '1' // so do not display the table name in upper div - if (strlen($this->_table) + if ($pmaString->strlen($this->_table) && ! (isset($_REQUEST['purge']) && $_REQUEST['purge'] == '1') ) { include './libraries/tbl_info.inc.php'; @@ -241,7 +252,7 @@ class PMA_Menu if (! empty($show_comment) && ! isset($GLOBALS['avoid_show_comment']) ) { - if (strstr($show_comment, '; InnoDB free')) { + if ($pmaString->strstr($show_comment, '; InnoDB free')) { $show_comment = preg_replace( '@; InnoDB free:.*?$@', '', diff --git a/libraries/Message.class.php b/libraries/Message.class.php index 60a0424ca1..fe3cdae875 100644 --- a/libraries/Message.class.php +++ b/libraries/Message.class.php @@ -501,7 +501,7 @@ class PMA_Message */ public function addMessage($message, $separator = ' ') { - if (strlen($separator)) { + if ($GLOBALS['PMA_String']->strlen($separator)) { $this->addedMessages[] = $separator; } @@ -628,11 +628,13 @@ class PMA_Message { $message = $this->message; - if (0 === strlen($message)) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if (0 === $pmaString->strlen($message)) { $string = $this->getString(); if (isset($GLOBALS[$string])) { $message = $GLOBALS[$string]; - } elseif (0 === strlen($string)) { + } elseif (0 === $pmaString->strlen($string)) { $message = ''; } else { $message = $string; diff --git a/libraries/PDF.class.php b/libraries/PDF.class.php index 2a939b8b16..4b3225922b 100644 --- a/libraries/PDF.class.php +++ b/libraries/PDF.class.php @@ -139,7 +139,11 @@ class PMA_PDF extends TCPDF { $pdfData = $this->getPDFData(); PMA_Response::getInstance()->disable(); - PMA_downloadHeader($filename, 'application/pdf', strlen($pdfData)); + PMA_downloadHeader( + $filename, + 'application/pdf', + $GLOBALS['PMA_String']->strlen($pdfData) + ); echo $pdfData; } } diff --git a/libraries/RecentFavoriteTable.class.php b/libraries/RecentFavoriteTable.class.php index d5ef859fd8..ec753cadce 100644 --- a/libraries/RecentFavoriteTable.class.php +++ b/libraries/RecentFavoriteTable.class.php @@ -63,9 +63,12 @@ class PMA_RecentFavoriteTable */ private function __construct($type) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $this->_tableType = $type; - if (strlen($GLOBALS['cfg']['Server']['pmadb']) - && strlen($GLOBALS['cfg']['Server'][$this->_tableType]) + if ($pmaString->strlen($GLOBALS['cfg']['Server']['pmadb']) + && $pmaString->strlen($GLOBALS['cfg']['Server'][$this->_tableType]) ) { $this->_pmaTable = PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . "." diff --git a/libraries/Response.class.php b/libraries/Response.class.php index 7f60173e6f..09d51cff13 100644 --- a/libraries/Response.class.php +++ b/libraries/Response.class.php @@ -317,7 +317,11 @@ class PMA_Response $this->addJSON('_selflink', $this->getFooter()->getSelfUrl('unencoded')); $this->addJSON('_displayMessage', $this->getHeader()->getMessage()); $errors = $this->_footer->getErrorMessages(); - if (strlen($errors)) { + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + if ($pmaString->strlen($errors)) { $this->addJSON('_errors', $errors); } $promptPhpErrors = $GLOBALS['error_handler']->hasErrorsForPrompt(); @@ -328,7 +332,7 @@ class PMA_Response $query = ''; $maxChars = $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']; if (isset($GLOBALS['sql_query']) - && strlen($GLOBALS['sql_query']) < $maxChars + && $pmaString->strlen($GLOBALS['sql_query']) < $maxChars ) { $query = $GLOBALS['sql_query']; } diff --git a/libraries/Scripts.class.php b/libraries/Scripts.class.php index e6ba610fd6..c1ea5fc17e 100644 --- a/libraries/Scripts.class.php +++ b/libraries/Scripts.class.php @@ -53,7 +53,7 @@ class PMA_Scripts $dynamic_scripts = ""; $scripts = array(); foreach ($files as $value) { - if (strpos($value['filename'], "?") !== false) { + if ($GLOBALS['PMA_String']->strpos($value['filename'], "?") !== false) { $dynamic_scripts .= ""; continue; @@ -149,13 +149,16 @@ class PMA_Scripts */ private function _eventBlacklist($filename) { - if ( strpos($filename, 'jquery') !== false - || strpos($filename, 'codemirror') !== false - || strpos($filename, 'messages.php') !== false - || strpos($filename, 'ajax.js') !== false - || strpos($filename, 'navigation.js') !== false - || strpos($filename, 'get_image.js.php') !== false - || strpos($filename, 'cross_framing_protection.js') !== false + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + if ( $pmaString->strpos($filename, 'jquery') !== false + || $pmaString->strpos($filename, 'codemirror') !== false + || $pmaString->strpos($filename, 'messages.php') !== false + || $pmaString->strpos($filename, 'ajax.js') !== false + || $pmaString->strpos($filename, 'navigation.js') !== false + || $pmaString->strpos($filename, 'get_image.js.php') !== false + || $pmaString->strpos($filename, 'cross_framing_protection.js') !== false ) { return 0; } @@ -204,7 +207,7 @@ class PMA_Scripts $retval = array(); foreach ($this->_files as $file) { //If filename contains a "?", continue. - if (strpos($file['filename'], "?") !== false) { + if ($GLOBALS['PMA_String']->strpos($file['filename'], "?") !== false) { continue; } diff --git a/libraries/ServerStatusData.class.php b/libraries/ServerStatusData.class.php index a07e671f15..fd7368a667 100644 --- a/libraries/ServerStatusData.class.php +++ b/libraries/ServerStatusData.class.php @@ -280,11 +280,14 @@ class PMA_ServerStatusData // Variable to mark used sections $categoryUsed = array(); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // sort vars into arrays foreach ($server_status as $name => $value) { $section_found = false; foreach ($allocations as $filter => $section) { - if (strpos($name, $filter) !== false) { + if ($pmaString->strpos($name, $filter) !== false) { $allocationMap[$name] = $section; $categoryUsed[$section] = true; $section_found = true; @@ -315,7 +318,7 @@ class PMA_ServerStatusData // Set all class properties $this->db_isLocal = false; - if (strtolower($GLOBALS['cfg']['Server']['host']) === 'localhost' + if ($pmaString->strtolower($GLOBALS['cfg']['Server']['host']) === 'localhost' || $GLOBALS['cfg']['Server']['host'] === '127.0.0.1' || $GLOBALS['cfg']['Server']['host'] === '::1' ) { diff --git a/libraries/StorageEngine.class.php b/libraries/StorageEngine.class.php index f2c01501ac..dead6f1dd0 100644 --- a/libraries/StorageEngine.class.php +++ b/libraries/StorageEngine.class.php @@ -132,7 +132,10 @@ class PMA_StorageEngine $name = 'engine', $id = null, $selected = null, $offerUnavailableEngines = false ) { - $selected = strtolower($selected); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + $selected = $pmaString->strtolower($selected); $output = '' . '' . __('Change password') . '' . '' . '' diff --git a/libraries/display_export.lib.php b/libraries/display_export.lib.php index 9c1734ee1c..91e1f13cfd 100644 --- a/libraries/display_export.lib.php +++ b/libraries/display_export.lib.php @@ -74,7 +74,10 @@ function PMA_getHtmlForExportSelectOptions($tmp_select = '') $is_selected = ''; } } elseif (!empty($tmp_select)) { - if (strpos(' ' . $tmp_select, '|' . $current_db . '|')) { + if ($GLOBALS['PMA_String']->strpos( + ' ' . $tmp_select, + '|' . $current_db . '|' + )) { $is_selected = ' selected="selected"'; } else { $is_selected = ''; @@ -710,7 +713,8 @@ function PMA_getHtmlForExportOptions( $html .= PMA_getHtmlForExportOptionsMethod(); $html .= PMA_getHtmlForExportOptionsSelection($export_type, $multi_values); - if (strlen($table) && empty($num_tables) && ! PMA_Table::isMerge($db, $table)) { + $tableLength = $GLOBALS['PMA_String']->strlen($table); + if ($tableLength && empty($num_tables) && ! PMA_Table::isMerge($db, $table)) { $html .= PMA_getHtmlForExportOptionsRows($db, $table, $unlim_num_rows); } @@ -772,6 +776,9 @@ function PMA_getHtmlForAliasModalDialog($db = '', $table = '') ); } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $html = '
'; $db_html = '
'; $col_html .= ''; diff --git a/libraries/display_git_revision.lib.php b/libraries/display_git_revision.lib.php index d794832eeb..f192451b64 100644 --- a/libraries/display_git_revision.lib.php +++ b/libraries/display_git_revision.lib.php @@ -25,8 +25,8 @@ function PMA_printGitRevision() // load revision data from repo $GLOBALS['PMA_Config']->checkGitRevision(); - // if using a remote commit fast-forwarded, link to Github - $commit_hash = substr( + // if using a remote commit fast-forwarded, link to GitHub + $commit_hash = $GLOBALS['PMA_String']->substr( $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITHASH'), 0, 7 diff --git a/libraries/error_report.lib.php b/libraries/error_report.lib.php index 02fc4389c9..199025bf6a 100644 --- a/libraries/error_report.lib.php +++ b/libraries/error_report.lib.php @@ -293,10 +293,12 @@ function PMA_getLineNumber($filenames, $cumulative_number) */ function PMA_translateStacktrace($stack) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; foreach ($stack as &$level) { foreach ($level["context"] as &$line) { - if (strlen($line) > 80) { - $line = substr($line, 0, 75) . "//..."; + if ($pmaString->strlen($line) > 80) { + $line = $pmaString->substr($line, 0, 75) . "//..."; } } if (preg_match("", $level["url"], $matches)) { diff --git a/libraries/export.lib.php b/libraries/export.lib.php index 3ed20a4fb1..573718d861 100644 --- a/libraries/export.lib.php +++ b/libraries/export.lib.php @@ -19,7 +19,9 @@ if (! defined('PHPMYADMIN')) { function PMA_shutdownDuringExport() { $a = error_get_last(); - if ($a != null && strpos($a['message'], "execution time")) { + if ($a != null + && $GLOBALS['PMA_String']->strpos($a['message'], "execution time") + ) { //write in partially downloaded file for future reference of user print_r($a); //set session variable to check if there was error while exporting @@ -83,13 +85,17 @@ function PMA_exportOutputHandler($line) isset($GLOBALS['xkana']) ? $GLOBALS['xkana'] : '' ); } + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // If we have to buffer data, we will perform everything at once at the end if ($GLOBALS['buffer_needed']) { $dump_buffer .= $line; if ($GLOBALS['onfly_compression']) { - $dump_buffer_len += strlen($line); + $dump_buffer_len += $pmaString->strlen($line); if ($dump_buffer_len > $GLOBALS['memory_limit']) { if ($GLOBALS['output_charset_conversion']) { @@ -108,7 +114,7 @@ function PMA_exportOutputHandler($line) } if ($GLOBALS['save_on_server']) { $write_result = @fwrite($GLOBALS['file_handle'], $dump_buffer); - if ($write_result != strlen($dump_buffer)) { + if ($write_result != $pmaString->strlen($dump_buffer)) { $GLOBALS['message'] = PMA_Message::error( __('Insufficient space to save the file %s.') ); @@ -137,9 +143,11 @@ function PMA_exportOutputHandler($line) $line ); } - if ($GLOBALS['save_on_server'] && strlen($line) > 0) { + if ($GLOBALS['save_on_server'] && $pmaString->strlen($line) > 0) { $write_result = @fwrite($GLOBALS['file_handle'], $line); - if (! $write_result || ($write_result != strlen($line))) { + if (! $write_result + || $write_result != $pmaString->strlen($line) + ) { $GLOBALS['message'] = PMA_Message::error( __('Insufficient space to save the file %s.') ); @@ -198,16 +206,20 @@ function PMA_getHtmlForDisplayedExportFooter($back_button) */ function PMA_getMemoryLimitForExport() { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $memory_limit = trim(@ini_get('memory_limit')); - $memory_limit_num = (int)substr($memory_limit, 0, -1); + $memory_limit_num = (int)$pmaString->substr($memory_limit, 0, -1); + $lowerLastChar = $pmaString->strtolower($pmaString->substr($memory_limit, -1)); // 2 MB as default if (empty($memory_limit) || '-1' == $memory_limit) { $memory_limit = 2 * 1024 * 1024; - } elseif (strtolower(substr($memory_limit, -1)) == 'm') { + } elseif ($lowerLastChar == 'm') { $memory_limit = $memory_limit_num * 1024 * 1024; - } elseif (strtolower(substr($memory_limit, -1)) == 'k') { + } elseif ($lowerLastChar == 'k') { $memory_limit = $memory_limit_num * 1024; - } elseif (strtolower(substr($memory_limit, -1)) == 'g') { + } elseif ($lowerLastChar == 'g') { $memory_limit = $memory_limit_num * 1024 * 1024 * 1024; } else { $memory_limit = (int)$memory_limit; @@ -270,15 +282,19 @@ function PMA_getExportFilenameAndMimetype( // part of the filename) to avoid a remote code execution vulnerability $filename = PMA_sanitizeFilename($filename, $replaceDots = true); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; // Grab basic dump extension and mime type // Check if the user already added extension; // get the substring where the extension would be if it was included - $extension_start_pos = strlen($filename) - strlen( + $extension_start_pos = $pmaString->strlen($filename) - $pmaString->strlen( $export_plugin->getProperties()->getExtension() ) - 1; - $user_extension = substr($filename, $extension_start_pos, strlen($filename)); + $user_extension = $pmaString->substr( + $filename, $extension_start_pos, $pmaString->strlen($filename) + ); $required_extension = "." . $export_plugin->getProperties()->getExtension(); - if (strtolower($user_extension) != $required_extension) { + if ($pmaString->strtolower($user_extension) != $required_extension) { $filename .= $required_extension; } $mime_type = $export_plugin->getProperties()->getMimeType(); @@ -354,10 +370,13 @@ function PMA_openExportFile($filename, $quick_export) */ function PMA_closeExportFile($file_handle, $dump_buffer, $save_filename) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $write_result = @fwrite($file_handle, $dump_buffer); fclose($file_handle); - if (strlen($dump_buffer) > 0 - && (! $write_result || ($write_result != strlen($dump_buffer))) + if ($pmaString->strlen($dump_buffer) > 0 + && (! $write_result || ($write_result != $pmaString->strlen($dump_buffer))) ) { $message = new PMA_Message( __('Insufficient space to save the file %s.'), @@ -387,7 +406,10 @@ function PMA_compressExport($dump_buffer, $compression, $filename) { if ($compression == 'zip' && @function_exists('gzcompress')) { $zipfile = new ZipFile(); - $zipfile->addFile($dump_buffer, substr($filename, 0, -4)); + $zipfile->addFile( + $dump_buffer, + $GLOBALS['PMA_String']->substr($filename, 0, -4) + ); $dump_buffer = $zipfile->file(); } elseif ($compression == 'gzip' && PMA_gzencodeNeeded()) { // without the optional parameter level because it bugs @@ -475,7 +497,8 @@ function PMA_exportServer( // Walk over databases foreach ($GLOBALS['pma']->databases as $current_db) { if (isset($tmp_select) - && strpos(' ' . $tmp_select, '|' . $current_db . '|') + && $GLOBALS['PMA_String'] + ->strpos(' ' . $tmp_select, '|' . $current_db . '|') ) { $tables = $GLOBALS['dbi']->getTables($current_db); PMA_exportDatabase( @@ -520,7 +543,10 @@ function PMA_exportDatabase( } if (method_exists($export_plugin, 'exportRoutines') - && strpos($GLOBALS['sql_structure_or_data'], 'structure') !== false + && $GLOBALS['PMA_String']->strpos( + $GLOBALS['sql_structure_or_data'], + 'structure' + ) !== false && isset($GLOBALS['sql_procedure_function']) ) { $export_plugin->exportRoutines($db, $aliases); diff --git a/libraries/file_listing.lib.php b/libraries/file_listing.lib.php index 929dfaaea4..cf63e1dd26 100644 --- a/libraries/file_listing.lib.php +++ b/libraries/file_listing.lib.php @@ -24,7 +24,7 @@ function PMA_getDirContent($dir, $expression = '') } $result = array(); - if (substr($dir, -1) != '/') { + if ($GLOBALS['PMA_String']->substr($dir, -1) != '/') { $dir .= '/'; } while ($file = @readdir($handle)) { diff --git a/libraries/gis/GIS_Factory.class.php b/libraries/gis/GIS_Factory.class.php index 0b9a11bc12..c9f1d92794 100644 --- a/libraries/gis/GIS_Factory.class.php +++ b/libraries/gis/GIS_Factory.class.php @@ -32,12 +32,16 @@ class PMA_GIS_Factory { include_once './libraries/gis/GIS_Geometry.class.php'; - $file = './libraries/gis/GIS_' . ucfirst(strtolower($type)) . '.class.php'; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + $file = './libraries/gis/GIS_' + . ucfirst($pmaString->strtolower($type)) . '.class.php'; if (! file_exists($file)) { return false; } if (include_once $file) { - switch(strtoupper($type)) { + switch($pmaString->strtoupper($type)) { case 'MULTIPOLYGON' : return PMA_GIS_Multipolygon::singleton(); case 'POLYGON' : diff --git a/libraries/gis/GIS_Geometry.class.php b/libraries/gis/GIS_Geometry.class.php index f27640e37b..b2be72e4da 100644 --- a/libraries/gis/GIS_Geometry.class.php +++ b/libraries/gis/GIS_Geometry.class.php @@ -84,7 +84,7 @@ abstract class PMA_GIS_Geometry * * @param string $spatial spatial data of a row * - * @return array array containing the min, max values for x and y cordinates + * @return array array containing the min, max values for x and y coordinates * @access public */ public abstract function scaleRow($spatial); @@ -176,10 +176,14 @@ abstract class PMA_GIS_Geometry . '|POLYGON|MULTIPOLYGON|GEOMETRYCOLLECTION)'; $srid = 0; $wkt = ''; + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if (preg_match("/^'" . $geom_types . "\(.*\)',[0-9]*$/i", $value)) { - $last_comma = strripos($value, ","); - $srid = trim(substr($value, $last_comma + 1)); - $wkt = trim(substr($value, 1, $last_comma - 2)); + $last_comma = $pmaString->strripos($value, ","); + $srid = trim($pmaString->substr($value, $last_comma + 1)); + $wkt = trim($pmaString->substr($value, 1, $last_comma - 2)); } elseif (preg_match("/^" . $geom_types . "\(.*\)$/i", $value)) { $wkt = $value; } @@ -250,7 +254,15 @@ abstract class PMA_GIS_Geometry $rings = explode("),(", $polygon); $ol_array .= $this->getPolygonForOpenLayers($rings, $srid) . ', '; } - $ol_array = substr($ol_array, 0, strlen($ol_array) - 2); + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + $ol_array = $pmaString->substr( + $ol_array, + 0, + $pmaString->strlen($ol_array) - 2 + ); $ol_array .= ')'; return $ol_array; @@ -295,7 +307,15 @@ abstract class PMA_GIS_Geometry ); $ol_array .= ', '; } - $ol_array = substr($ol_array, 0, strlen($ol_array) - 2); + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + $ol_array = $pmaString->substr( + $ol_array, + 0, + $pmaString->strlen($ol_array) - 2 + ); $ol_array .= ')'; return $ol_array; @@ -335,7 +355,15 @@ abstract class PMA_GIS_Geometry foreach ($points_arr as $point) { $ol_array .= $this->getPointForOpenLayers($point, $srid) . ', '; } - $ol_array = substr($ol_array, 0, strlen($ol_array) - 2); + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + $ol_array = $pmaString->substr( + $ol_array, + 0, + $pmaString->strlen($ol_array) - 2 + ); $ol_array .= ')'; return $ol_array; diff --git a/libraries/gis/GIS_Geometrycollection.class.php b/libraries/gis/GIS_Geometrycollection.class.php index 80cc225102..5ef0f97817 100644 --- a/libraries/gis/GIS_Geometrycollection.class.php +++ b/libraries/gis/GIS_Geometrycollection.class.php @@ -57,15 +57,22 @@ class PMA_GIS_Geometrycollection extends PMA_GIS_Geometry { $min_max = array(); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')' - $goem_col = substr($spatial, 19, (strlen($spatial) - 20)); + $goem_col = $pmaString->substr( + $spatial, + 19, + $pmaString->strlen($spatial) - 20 + ); // Split the geometry collection object to get its constituents. $sub_parts = $this->_explodeGeomCol($goem_col); foreach ($sub_parts as $sub_part) { - $type_pos = stripos($sub_part, '('); - $type = substr($sub_part, 0, $type_pos); + $type_pos = $pmaString->stripos($sub_part, '('); + $type = $pmaString->substr($sub_part, 0, $type_pos); $gis_obj = PMA_GIS_Factory::factory($type); if (! $gis_obj) { @@ -111,14 +118,21 @@ class PMA_GIS_Geometrycollection extends PMA_GIS_Geometry */ public function prepareRowAsPng($spatial, $label, $color, $scale_data, $image) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')' - $goem_col = substr($spatial, 19, (strlen($spatial) - 20)); + $goem_col = $pmaString->substr( + $spatial, + 19, + $pmaString->strlen($spatial) - 20 + ); // Split the geometry collection object to get its constituents. $sub_parts = $this->_explodeGeomCol($goem_col); foreach ($sub_parts as $sub_part) { - $type_pos = stripos($sub_part, '('); - $type = substr($sub_part, 0, $type_pos); + $type_pos = $pmaString->stripos($sub_part, '('); + $type = $pmaString->substr($sub_part, 0, $type_pos); $gis_obj = PMA_GIS_Factory::factory($type); if (! $gis_obj) { @@ -145,14 +159,21 @@ class PMA_GIS_Geometrycollection extends PMA_GIS_Geometry */ public function prepareRowAsPdf($spatial, $label, $color, $scale_data, $pdf) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')' - $goem_col = substr($spatial, 19, (strlen($spatial) - 20)); + $goem_col = $pmaString->substr( + $spatial, + 19, + $pmaString->strlen($spatial) - 20 + ); // Split the geometry collection object to get its constituents. $sub_parts = $this->_explodeGeomCol($goem_col); foreach ($sub_parts as $sub_part) { - $type_pos = stripos($sub_part, '('); - $type = substr($sub_part, 0, $type_pos); + $type_pos = $pmaString->stripos($sub_part, '('); + $type = $pmaString->substr($sub_part, 0, $type_pos); $gis_obj = PMA_GIS_Factory::factory($type); if (! $gis_obj) { @@ -180,14 +201,21 @@ class PMA_GIS_Geometrycollection extends PMA_GIS_Geometry { $row = ''; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')' - $goem_col = substr($spatial, 19, (strlen($spatial) - 20)); + $goem_col = $pmaString->substr( + $spatial, + 19, + $pmaString->strlen($spatial) - 20 + ); // Split the geometry collection object to get its constituents. $sub_parts = $this->_explodeGeomCol($goem_col); foreach ($sub_parts as $sub_part) { - $type_pos = stripos($sub_part, '('); - $type = substr($sub_part, 0, $type_pos); + $type_pos = $pmaString->stripos($sub_part, '('); + $type = $pmaString->substr($sub_part, 0, $type_pos); $gis_obj = PMA_GIS_Factory::factory($type); if (! $gis_obj) { @@ -217,14 +245,21 @@ class PMA_GIS_Geometrycollection extends PMA_GIS_Geometry { $row = ''; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')' - $goem_col = substr($spatial, 19, (strlen($spatial) - 20)); + $goem_col = $pmaString->substr( + $spatial, + 19, + $pmaString->strlen($spatial) - 20 + ); // Split the geometry collection object to get its constituents. $sub_parts = $this->_explodeGeomCol($goem_col); foreach ($sub_parts as $sub_part) { - $type_pos = stripos($sub_part, '('); - $type = substr($sub_part, 0, $type_pos); + $type_pos = $pmaString->stripos($sub_part, '('); + $type = $pmaString->substr($sub_part, 0, $type_pos); $gis_obj = PMA_GIS_Factory::factory($type); if (! $gis_obj) { @@ -257,7 +292,11 @@ class PMA_GIS_Geometrycollection extends PMA_GIS_Geometry } elseif ($char == ')') { $br_count--; if ($br_count == 0) { - $sub_parts[] = substr($goem_col, $start, ($count + 1 - $start)); + $sub_parts[] = $GLOBALS['PMA_String']->substr( + $goem_col, + $start, + ($count + 1 - $start) + ); $start = $count + 2; } } @@ -292,7 +331,10 @@ class PMA_GIS_Geometrycollection extends PMA_GIS_Geometry } } if (isset($gis_data[0]['gis_type'])) { - $wkt = substr($wkt, 0, strlen($wkt) - 1); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + $wkt = $pmaString->substr($wkt, 0, $pmaString->strlen($wkt) - 1); } $wkt .= ')'; return $wkt; @@ -313,16 +355,19 @@ class PMA_GIS_Geometrycollection extends PMA_GIS_Geometry $params['srid'] = $data['srid']; $wkt = $data['wkt']; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')' - $goem_col = substr($wkt, 19, (strlen($wkt) - 20)); + $goem_col = $pmaString->substr($wkt, 19, ($pmaString->strlen($wkt) - 20)); // Split the geometry collection object to get its constituents. $sub_parts = $this->_explodeGeomCol($goem_col); $params['GEOMETRYCOLLECTION']['geom_count'] = count($sub_parts); $i = 0; foreach ($sub_parts as $sub_part) { - $type_pos = stripos($sub_part, '('); - $type = substr($sub_part, 0, $type_pos); + $type_pos = $pmaString->stripos($sub_part, '('); + $type = $pmaString->substr($sub_part, 0, $type_pos); $gis_obj = PMA_GIS_Factory::factory($type); if (! $gis_obj) { continue; diff --git a/libraries/gis/GIS_Linestring.class.php b/libraries/gis/GIS_Linestring.class.php index 3baac59067..edb6193b0c 100644 --- a/libraries/gis/GIS_Linestring.class.php +++ b/libraries/gis/GIS_Linestring.class.php @@ -55,8 +55,15 @@ class PMA_GIS_Linestring extends PMA_GIS_Geometry */ public function scaleRow($spatial) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'LINESTRING(' and trailing ')' - $linesrting = substr($spatial, 11, (strlen($spatial) - 12)); + $linesrting = $pmaString->substr( + $spatial, + 11, + $pmaString->strlen($spatial) - 12 + ); return $this->setMinMax($linesrting, array()); } @@ -75,15 +82,25 @@ class PMA_GIS_Linestring extends PMA_GIS_Geometry public function prepareRowAsPng($spatial, $label, $line_color, $scale_data, $image ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // allocate colors $black = imagecolorallocate($image, 0, 0, 0); - $red = hexdec(substr($line_color, 1, 2)); - $green = hexdec(substr($line_color, 3, 2)); - $blue = hexdec(substr($line_color, 4, 2)); + $red = hexdec($pmaString->substr($line_color, 1, 2)); + $green = hexdec($pmaString->substr($line_color, 3, 2)); + $blue = hexdec($pmaString->substr($line_color, 4, 2)); $color = imagecolorallocate($image, $red, $green, $blue); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'LINESTRING(' and trailing ')' - $linesrting = substr($spatial, 11, (strlen($spatial) - 12)); + $linesrting = $pmaString->substr( + $spatial, + 11, + $pmaString->strlen($spatial) - 12 + ); $points_arr = $this->extractPoints($linesrting, $scale_data); foreach ($points_arr as $point) { @@ -122,14 +139,21 @@ class PMA_GIS_Linestring extends PMA_GIS_Geometry */ public function prepareRowAsPdf($spatial, $label, $line_color, $scale_data, $pdf) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // allocate colors - $red = hexdec(substr($line_color, 1, 2)); - $green = hexdec(substr($line_color, 3, 2)); - $blue = hexdec(substr($line_color, 4, 2)); + $red = hexdec($pmaString->substr($line_color, 1, 2)); + $green = hexdec($pmaString->substr($line_color, 3, 2)); + $blue = hexdec($pmaString->substr($line_color, 4, 2)); $line = array('width' => 1.5, 'color' => array($red, $green, $blue)); // Trim to remove leading 'LINESTRING(' and trailing ')' - $linesrting = substr($spatial, 11, (strlen($spatial) - 12)); + $linesrting = $pmaString->substr( + $spatial, + 11, + $pmaString->strlen($spatial) - 12 + ); $points_arr = $this->extractPoints($linesrting, $scale_data); foreach ($points_arr as $point) { @@ -175,8 +199,15 @@ class PMA_GIS_Linestring extends PMA_GIS_Geometry 'stroke-width'=> 2, ); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'LINESTRING(' and trailing ')' - $linesrting = substr($spatial, 11, (strlen($spatial) - 12)); + $linesrting = $pmaString->substr( + $spatial, + 11, + $pmaString->strlen($spatial) - 12 + ); $points_arr = $this->extractPoints($linesrting, $scale_data); $row = 'substr($line_color, 1, 2)); + $green = hexdec($pmaString->substr($line_color, 3, 2)); + $blue = hexdec($pmaString->substr($line_color, 4, 2)); $color = imagecolorallocate($image, $red, $green, $blue); // Trim to remove leading 'MULTILINESTRING((' and trailing '))' - $multilinestirng = substr($spatial, 17, (strlen($spatial) - 19)); - // Seperate each linestring + $multilinestirng = $pmaString->substr( + $spatial, + 17, + $pmaString->strlen($spatial) - 19 + ); + // Separate each linestring $linestirngs = explode("),(", $multilinestirng); $first_line = true; @@ -138,15 +152,21 @@ class PMA_GIS_Multilinestring extends PMA_GIS_Geometry */ public function prepareRowAsPdf($spatial, $label, $line_color, $scale_data, $pdf) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // allocate colors - $red = hexdec(substr($line_color, 1, 2)); - $green = hexdec(substr($line_color, 3, 2)); - $blue = hexdec(substr($line_color, 4, 2)); + $red = hexdec($pmaString->substr($line_color, 1, 2)); + $green = hexdec($pmaString->substr($line_color, 3, 2)); + $blue = hexdec($pmaString->substr($line_color, 4, 2)); $line = array('width' => 1.5, 'color' => array($red, $green, $blue)); // Trim to remove leading 'MULTILINESTRING((' and trailing '))' - $multilinestirng = substr($spatial, 17, (strlen($spatial) - 19)); - // Seperate each linestring + $multilinestirng = $pmaString->substr( + $spatial, + 17, $pmaString->strlen($spatial) - 19 + ); + // Separate each linestring $linestirngs = explode("),(", $multilinestirng); $first_line = true; @@ -196,9 +216,16 @@ class PMA_GIS_Multilinestring extends PMA_GIS_Geometry 'stroke-width'=> 2, ); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'MULTILINESTRING((' and trailing '))' - $multilinestirng = substr($spatial, 17, (strlen($spatial) - 19)); - // Seperate each linestring + $multilinestirng = $pmaString->substr( + $spatial, + 17, + $pmaString->strlen($spatial) - 19 + ); + // Separate each linestring $linestirngs = explode("),(", $multilinestirng); $row = ''; @@ -246,9 +273,16 @@ class PMA_GIS_Multilinestring extends PMA_GIS_Geometry } $row = $this->getBoundsForOl($srid, $scale_data); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'MULTILINESTRING((' and trailing '))' - $multilinestirng = substr($spatial, 17, (strlen($spatial) - 19)); - // Seperate each linestring + $multilinestirng = $pmaString->substr( + $spatial, + 17, + $pmaString->strlen($spatial) - 19 + ); + // Separate each linestring $linestirngs = explode("),(", $multilinestirng); $row .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector(' @@ -277,6 +311,10 @@ class PMA_GIS_Multilinestring extends PMA_GIS_Geometry if ($no_of_lines < 1) { $no_of_lines = 1; } + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $wkt = 'MULTILINESTRING('; for ($i = 0; $i < $no_of_lines; $i++) { $no_of_points = isset($data_row[$i]['no_of_points']) @@ -293,10 +331,10 @@ class PMA_GIS_Multilinestring extends PMA_GIS_Geometry && trim($data_row[$i][$j]['y']) != '') ? $data_row[$i][$j]['y'] : $empty) . ','; } - $wkt = substr($wkt, 0, strlen($wkt) - 1); + $wkt = $pmaString->substr($wkt, 0, $pmaString->strlen($wkt) - 1); $wkt .= '),'; } - $wkt = substr($wkt, 0, strlen($wkt) - 1); + $wkt = $pmaString->substr($wkt, 0, $pmaString->strlen($wkt) - 1); $wkt .= ')'; return $wkt; } @@ -311,16 +349,19 @@ class PMA_GIS_Multilinestring extends PMA_GIS_Geometry */ public function getShape($row_data) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $wkt = 'MULTILINESTRING('; for ($i = 0; $i < $row_data['numparts']; $i++) { $wkt .= '('; foreach ($row_data['parts'][$i]['points'] as $point) { $wkt .= $point['x'] . ' ' . $point['y'] . ','; } - $wkt = substr($wkt, 0, strlen($wkt) - 1); + $wkt = $pmaString->substr($wkt, 0, $pmaString->strlen($wkt) - 1); $wkt .= '),'; } - $wkt = substr($wkt, 0, strlen($wkt) - 1); + $wkt = $pmaString->substr($wkt, 0, $pmaString->strlen($wkt) - 1); $wkt .= ')'; return $wkt; } @@ -347,8 +388,15 @@ class PMA_GIS_Multilinestring extends PMA_GIS_Geometry $wkt = $value; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'MULTILINESTRING((' and trailing '))' - $multilinestirng = substr($wkt, 17, (strlen($wkt) - 19)); + $multilinestirng = $pmaString->substr( + $wkt, + 17, + $pmaString->strlen($wkt) - 19 + ); // Seperate each linestring $linestirngs = explode("),(", $multilinestirng); $params[$index]['MULTILINESTRING']['no_of_lines'] = count($linestirngs); diff --git a/libraries/gis/GIS_Multipoint.class.php b/libraries/gis/GIS_Multipoint.class.php index 515780deb5..c96ace4e76 100644 --- a/libraries/gis/GIS_Multipoint.class.php +++ b/libraries/gis/GIS_Multipoint.class.php @@ -55,8 +55,11 @@ class PMA_GIS_Multipoint extends PMA_GIS_Geometry */ public function scaleRow($spatial) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'MULTIPOINT(' and trailing ')' - $multipoint = substr($spatial, 11, (strlen($spatial) - 12)); + $multipoint = $pmaString->substr($spatial, 11, ($pmaString->strlen($spatial) - 12)); return $this->setMinMax($multipoint, array()); } @@ -75,15 +78,22 @@ class PMA_GIS_Multipoint extends PMA_GIS_Geometry public function prepareRowAsPng($spatial, $label, $point_color, $scale_data, $image ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // allocate colors $black = imagecolorallocate($image, 0, 0, 0); - $red = hexdec(substr($point_color, 1, 2)); - $green = hexdec(substr($point_color, 3, 2)); - $blue = hexdec(substr($point_color, 4, 2)); + $red = hexdec($pmaString->substr($point_color, 1, 2)); + $green = hexdec($pmaString->substr($point_color, 3, 2)); + $blue = hexdec($pmaString->substr($point_color, 4, 2)); $color = imagecolorallocate($image, $red, $green, $blue); // Trim to remove leading 'MULTIPOINT(' and trailing ')' - $multipoint = substr($spatial, 11, (strlen($spatial) - 12)); + $multipoint = $pmaString->substr( + $spatial, + 11, + $pmaString->strlen($spatial) - 12 + ); $points_arr = $this->extractPoints($multipoint, $scale_data); foreach ($points_arr as $point) { @@ -118,14 +128,21 @@ class PMA_GIS_Multipoint extends PMA_GIS_Geometry public function prepareRowAsPdf($spatial, $label, $point_color, $scale_data, $pdf ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // allocate colors - $red = hexdec(substr($point_color, 1, 2)); - $green = hexdec(substr($point_color, 3, 2)); - $blue = hexdec(substr($point_color, 4, 2)); + $red = hexdec($pmaString->substr($point_color, 1, 2)); + $green = hexdec($pmaString->substr($point_color, 3, 2)); + $blue = hexdec($pmaString->substr($point_color, 4, 2)); $line = array('width' => 1.25, 'color' => array($red, $green, $blue)); // Trim to remove leading 'MULTIPOINT(' and trailing ')' - $multipoint = substr($spatial, 11, (strlen($spatial) - 12)); + $multipoint = $pmaString->substr( + $spatial, + 11, + $pmaString->strlen($spatial) - 12 + ); $points_arr = $this->extractPoints($multipoint, $scale_data); foreach ($points_arr as $point) { @@ -166,8 +183,15 @@ class PMA_GIS_Multipoint extends PMA_GIS_Geometry 'stroke-width'=> 2, ); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'MULTIPOINT(' and trailing ')' - $multipoint = substr($spatial, 11, (strlen($spatial) - 12)); + $multipoint = $pmaString->substr( + $spatial, + 11, + $pmaString->strlen($spatial) - 12 + ); $points_arr = $this->extractPoints($multipoint, $scale_data); $row = ''; @@ -216,8 +240,15 @@ class PMA_GIS_Multipoint extends PMA_GIS_Geometry } $result = $this->getBoundsForOl($srid, $scale_data); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'MULTIPOINT(' and trailing ')' - $multipoint = substr($spatial, 11, (strlen($spatial) - 12)); + $multipoint = $pmaString->substr( + $spatial, + 11, + $pmaString->strlen($spatial) - 12 + ); $points_arr = $this->extractPoints($multipoint, null); $result .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector(' @@ -253,7 +284,11 @@ class PMA_GIS_Multipoint extends PMA_GIS_Geometry && trim($gis_data[$index]['MULTIPOINT'][$i]['y']) != '') ? $gis_data[$index]['MULTIPOINT'][$i]['y'] : '') . ','; } - $wkt = substr($wkt, 0, strlen($wkt) - 1); + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + $wkt = $pmaString->substr($wkt, 0, $pmaString->strlen($wkt) - 1); $wkt .= ')'; return $wkt; } @@ -273,7 +308,11 @@ class PMA_GIS_Multipoint extends PMA_GIS_Geometry $wkt .= $row_data['points'][$i]['x'] . ' ' . $row_data['points'][$i]['y'] . ','; } - $wkt = substr($wkt, 0, strlen($wkt) - 1); + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + $wkt = $pmaString->substr($wkt, 0, $pmaString->strlen($wkt) - 1); $wkt .= ')'; return $wkt; } @@ -300,8 +339,11 @@ class PMA_GIS_Multipoint extends PMA_GIS_Geometry $wkt = $value; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'MULTIPOINT(' and trailing ')' - $points = substr($wkt, 11, (strlen($wkt) - 12)); + $points = $pmaString->substr($wkt, 11, $pmaString->strlen($wkt) - 12); $points_arr = $this->extractPoints($points, null); $no_of_points = count($points_arr); @@ -332,8 +374,13 @@ class PMA_GIS_Multipoint extends PMA_GIS_Geometry $ol_array .= $this->getPointForOpenLayers($point, $srid) . ', '; } } - if (substr($ol_array, strlen($ol_array) - 2) == ', ') { - $ol_array = substr($ol_array, 0, strlen($ol_array) - 2); + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + $olArrayLength = $pmaString->strlen($ol_array); + if ($pmaString->substr($ol_array, $olArrayLength - 2) == ', ') { + $ol_array = $pmaString->substr($ol_array, 0, $olArrayLength - 2); } $ol_array .= ')'; diff --git a/libraries/gis/GIS_Multipolygon.class.php b/libraries/gis/GIS_Multipolygon.class.php index 275ca3e463..c3fa35cbae 100644 --- a/libraries/gis/GIS_Multipolygon.class.php +++ b/libraries/gis/GIS_Multipolygon.class.php @@ -55,19 +55,26 @@ class PMA_GIS_Multipolygon extends PMA_GIS_Geometry */ public function scaleRow($spatial) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $min_max = array(); // Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))' - $multipolygon = substr($spatial, 15, (strlen($spatial) - 18)); - // Seperate each polygon + $multipolygon = $pmaString->substr( + $spatial, + 15, + $pmaString->strlen($spatial) - 18 + ); + // Separate each polygon $polygons = explode(")),((", $multipolygon); foreach ($polygons as $polygon) { // If the polygon doesn't have an inner ring, use polygon itself - if (strpos($polygon, "),(") === false) { + if ($pmaString->strpos($polygon, "),(") === false) { $ring = $polygon; } else { - // Seperate outer ring and use it to determin min-max + // Separate outer ring and use it to determine min-max $parts = explode("),(", $polygon); $ring = $parts[0]; } @@ -92,25 +99,32 @@ class PMA_GIS_Multipolygon extends PMA_GIS_Geometry public function prepareRowAsPng($spatial, $label, $fill_color, $scale_data, $image ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // allocate colors $black = imagecolorallocate($image, 0, 0, 0); - $red = hexdec(substr($fill_color, 1, 2)); - $green = hexdec(substr($fill_color, 3, 2)); - $blue = hexdec(substr($fill_color, 4, 2)); + $red = hexdec($pmaString->substr($fill_color, 1, 2)); + $green = hexdec($pmaString->substr($fill_color, 3, 2)); + $blue = hexdec($pmaString->substr($fill_color, 4, 2)); $color = imagecolorallocate($image, $red, $green, $blue); // Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))' - $multipolygon = substr($spatial, 15, (strlen($spatial) - 18)); - // Seperate each polygon + $multipolygon = $pmaString->substr( + $spatial, + 15, + $pmaString->strlen($spatial) - 18 + ); + // Separate each polygon $polygons = explode(")),((", $multipolygon); $first_poly = true; foreach ($polygons as $polygon) { - // If the polygon doesnt have an inner polygon - if (strpos($polygon, "),(") === false) { + // If the polygon doesn't have an inner polygon + if ($pmaString->strpos($polygon, "),(") === false) { $points_arr = $this->extractPoints($polygon, $scale_data, true); } else { - // Seperate outer and inner polygons + // Separate outer and inner polygons $parts = explode("),(", $polygon); $outer = $parts[0]; $inner = array_slice($parts, 1); @@ -155,21 +169,24 @@ class PMA_GIS_Multipolygon extends PMA_GIS_Geometry */ public function prepareRowAsPdf($spatial, $label, $fill_color, $scale_data, $pdf) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // allocate colors - $red = hexdec(substr($fill_color, 1, 2)); - $green = hexdec(substr($fill_color, 3, 2)); - $blue = hexdec(substr($fill_color, 4, 2)); + $red = hexdec($pmaString->substr($fill_color, 1, 2)); + $green = hexdec($pmaString->substr($fill_color, 3, 2)); + $blue = hexdec($pmaString->substr($fill_color, 4, 2)); $color = array($red, $green, $blue); // Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))' - $multipolygon = substr($spatial, 15, (strlen($spatial) - 18)); - // Seperate each polygon + $multipolygon = $pmaString->substr($spatial, 15, $pmaString->strlen($spatial) - 18); + // Separate each polygon $polygons = explode(")),((", $multipolygon); $first_poly = true; foreach ($polygons as $polygon) { // If the polygon doesnt have an inner polygon - if (strpos($polygon, "),(") === false) { + if ($pmaString->strpos($polygon, "),(") === false) { $points_arr = $this->extractPoints($polygon, $scale_data, true); } else { // Seperate outer and inner polygons @@ -229,16 +246,23 @@ class PMA_GIS_Multipolygon extends PMA_GIS_Geometry $row = ''; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))' - $multipolygon = substr($spatial, 15, (strlen($spatial) - 18)); - // Seperate each polygon + $multipolygon = $pmaString->substr( + $spatial, + 15, + $pmaString->strlen($spatial) - 18 + ); + // Separate each polygon $polygons = explode(")),((", $multipolygon); foreach ($polygons as $polygon) { $row .= 'strpos($polygon, "),(") === false) { $row .= $this->_drawPath($polygon, $scale_data); } else { // Seperate outer and inner polygons @@ -291,9 +315,16 @@ class PMA_GIS_Multipolygon extends PMA_GIS_Geometry } $row = $this->getBoundsForOl($srid, $scale_data); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))' - $multipolygon = substr($spatial, 15, (strlen($spatial) - 18)); - // Seperate each polygon + $multipolygon = $pmaString->substr( + $spatial, + 15, + $pmaString->strlen($spatial) - 18 + ); + // Separate each polygon $polygons = explode(")),((", $multipolygon); $row .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector(' @@ -346,6 +377,9 @@ class PMA_GIS_Multipolygon extends PMA_GIS_Geometry $no_of_polygons = 1; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $wkt = 'MULTIPOLYGON('; for ($k = 0; $k < $no_of_polygons; $k++) { $no_of_lines = isset($data_row[$k]['no_of_lines']) @@ -369,13 +403,13 @@ class PMA_GIS_Multipolygon extends PMA_GIS_Geometry && trim($data_row[$k][$i][$j]['y']) != '') ? $data_row[$k][$i][$j]['y'] : $empty) . ','; } - $wkt = substr($wkt, 0, strlen($wkt) - 1); + $wkt = $pmaString->substr($wkt, 0, $pmaString->strlen($wkt) - 1); $wkt .= '),'; } - $wkt = substr($wkt, 0, strlen($wkt) - 1); + $wkt = $pmaString->substr($wkt, 0, $pmaString->strlen($wkt) - 1); $wkt .= '),'; } - $wkt = substr($wkt, 0, strlen($wkt) - 1); + $wkt = $pmaString->substr($wkt, 0, $pmaString->strlen($wkt) - 1); $wkt .= ')'; return $wkt; } @@ -430,6 +464,9 @@ class PMA_GIS_Multipolygon extends PMA_GIS_Geometry } } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $wkt = 'MULTIPOLYGON('; // for each polygon foreach ($row_data['parts'] as $ring) { @@ -443,7 +480,7 @@ class PMA_GIS_Multipolygon extends PMA_GIS_Geometry foreach ($ring['points'] as $point) { $wkt .= $point['x'] . ' ' . $point['y'] . ','; } - $wkt = substr($wkt, 0, strlen($wkt) - 1); + $wkt = $pmaString->substr($wkt, 0, $pmaString->strlen($wkt) - 1); $wkt .= ')'; // end of outer ring // inner rings if any @@ -453,14 +490,14 @@ class PMA_GIS_Multipolygon extends PMA_GIS_Geometry foreach ($row_data['parts'][$j]['points'] as $innerPoint) { $wkt .= $innerPoint['x'] . ' ' . $innerPoint['y'] . ','; } - $wkt = substr($wkt, 0, strlen($wkt) - 1); + $wkt = $pmaString->substr($wkt, 0, $pmaString->strlen($wkt) - 1); $wkt .= ')'; // end of inner ring } } $wkt .= '),'; // end of polygon } - $wkt = substr($wkt, 0, strlen($wkt) - 1); + $wkt = $pmaString->substr($wkt, 0, $pmaString->strlen($wkt) - 1); $wkt .= ')'; // end of multipolygon return $wkt; @@ -488,9 +525,12 @@ class PMA_GIS_Multipolygon extends PMA_GIS_Geometry $wkt = $value; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))' - $multipolygon = substr($wkt, 15, (strlen($wkt) - 18)); - // Seperate each polygon + $multipolygon = $pmaString->substr($wkt, 15, $pmaString->strlen($wkt) - 18); + // Separate each polygon $polygons = explode(")),((", $multipolygon); $param_row =& $params[$index]['MULTIPOLYGON']; @@ -499,7 +539,7 @@ class PMA_GIS_Multipolygon extends PMA_GIS_Geometry $k = 0; foreach ($polygons as $polygon) { // If the polygon doesnt have an inner polygon - if (strpos($polygon, "),(") === false) { + if ($pmaString->strpos($polygon, "),(") === false) { $param_row[$k]['no_of_lines'] = 1; $points_arr = $this->extractPoints($polygon, null); $no_of_points = count($points_arr); @@ -509,7 +549,7 @@ class PMA_GIS_Multipolygon extends PMA_GIS_Geometry $param_row[$k][0][$i]['y'] = $points_arr[$i][1]; } } else { - // Seperate outer and inner polygons + // Separate outer and inner polygons $parts = explode("),(", $polygon); $param_row[$k]['no_of_lines'] = count($parts); $j = 0; diff --git a/libraries/gis/GIS_Point.class.php b/libraries/gis/GIS_Point.class.php index 35fff43621..6c1ccfc327 100644 --- a/libraries/gis/GIS_Point.class.php +++ b/libraries/gis/GIS_Point.class.php @@ -55,8 +55,11 @@ class PMA_GIS_Point extends PMA_GIS_Geometry */ public function scaleRow($spatial) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'POINT(' and trailing ')' - $point = substr($spatial, 6, (strlen($spatial) - 7)); + $point = $pmaString->substr($spatial, 6, $pmaString->strlen($spatial) - 7); return $this->setMinMax($point, array()); } @@ -75,15 +78,18 @@ class PMA_GIS_Point extends PMA_GIS_Geometry public function prepareRowAsPng($spatial, $label, $point_color, $scale_data, $image ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // allocate colors $black = imagecolorallocate($image, 0, 0, 0); - $red = hexdec(substr($point_color, 1, 2)); - $green = hexdec(substr($point_color, 3, 2)); - $blue = hexdec(substr($point_color, 4, 2)); + $red = hexdec($pmaString->substr($point_color, 1, 2)); + $green = hexdec($pmaString->substr($point_color, 3, 2)); + $blue = hexdec($pmaString->substr($point_color, 4, 2)); $color = imagecolorallocate($image, $red, $green, $blue); // Trim to remove leading 'POINT(' and trailing ')' - $point = substr($spatial, 6, (strlen($spatial) - 7)); + $point = $pmaString->substr($spatial, 6, $pmaString->strlen($spatial) - 7); $points_arr = $this->extractPoints($point, $scale_data); // draw a small circle to mark the point @@ -117,14 +123,17 @@ class PMA_GIS_Point extends PMA_GIS_Geometry public function prepareRowAsPdf($spatial, $label, $point_color, $scale_data, $pdf ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // allocate colors - $red = hexdec(substr($point_color, 1, 2)); - $green = hexdec(substr($point_color, 3, 2)); - $blue = hexdec(substr($point_color, 4, 2)); + $red = hexdec($pmaString->substr($point_color, 1, 2)); + $green = hexdec($pmaString->substr($point_color, 3, 2)); + $blue = hexdec($pmaString->substr($point_color, 4, 2)); $line = array('width' => 1.25, 'color' => array($red, $green, $blue)); // Trim to remove leading 'POINT(' and trailing ')' - $point = substr($spatial, 6, (strlen($spatial) - 7)); + $point = $pmaString->substr($spatial, 6, $pmaString->strlen($spatial) - 7); $points_arr = $this->extractPoints($point, $scale_data); // draw a small circle to mark the point @@ -164,8 +173,11 @@ class PMA_GIS_Point extends PMA_GIS_Geometry 'stroke-width'=> 2, ); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'POINT(' and trailing ')' - $point = substr($spatial, 6, (strlen($spatial) - 7)); + $point = $pmaString->substr($spatial, 6, $pmaString->strlen($spatial) - 7); $points_arr = $this->extractPoints($point, $scale_data); $row = ''; @@ -211,8 +223,11 @@ class PMA_GIS_Point extends PMA_GIS_Geometry } $result = $this->getBoundsForOl($srid, $scale_data); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'POINT(' and trailing ')' - $point = substr($spatial, 6, (strlen($spatial) - 7)); + $point = $pmaString->substr($spatial, 6, $pmaString->strlen($spatial) - 7); $points_arr = $this->extractPoints($point, null); if ($points_arr[0][0] != '' && $points_arr[0][1] != '') { @@ -281,8 +296,11 @@ class PMA_GIS_Point extends PMA_GIS_Geometry $wkt = $value; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'POINT(' and trailing ')' - $point = substr($wkt, 6, (strlen($wkt) - 7)); + $point = $pmaString->substr($wkt, 6, $pmaString->strlen($wkt) - 7); $points_arr = $this->extractPoints($point, null); $params[$index]['POINT']['x'] = $points_arr[0][0]; diff --git a/libraries/gis/GIS_Polygon.class.php b/libraries/gis/GIS_Polygon.class.php index ed944f4a0d..d7d096ae5a 100644 --- a/libraries/gis/GIS_Polygon.class.php +++ b/libraries/gis/GIS_Polygon.class.php @@ -55,14 +55,21 @@ class PMA_GIS_Polygon extends PMA_GIS_Geometry */ public function scaleRow($spatial) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'POLYGON((' and trailing '))' - $polygon = substr($spatial, 9, (strlen($spatial) - 11)); + $polygon = $pmaString->substr( + $spatial, + 9, + $pmaString->strlen($spatial) - 11 + ); // If the polygon doesn't have an inner ring, use polygon itself - if (strpos($polygon, "),(") === false) { + if ($pmaString->strpos($polygon, "),(") === false) { $ring = $polygon; } else { - // Seperate outer ring and use it to determin min-max + // Separate outer ring and use it to determine min-max $parts = explode("),(", $polygon); $ring = $parts[0]; } @@ -84,21 +91,28 @@ class PMA_GIS_Polygon extends PMA_GIS_Geometry public function prepareRowAsPng($spatial, $label, $fill_color, $scale_data, $image ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // allocate colors $black = imagecolorallocate($image, 0, 0, 0); - $red = hexdec(substr($fill_color, 1, 2)); - $green = hexdec(substr($fill_color, 3, 2)); - $blue = hexdec(substr($fill_color, 4, 2)); + $red = hexdec($pmaString->substr($fill_color, 1, 2)); + $green = hexdec($pmaString->substr($fill_color, 3, 2)); + $blue = hexdec($pmaString->substr($fill_color, 4, 2)); $color = imagecolorallocate($image, $red, $green, $blue); // Trim to remove leading 'POLYGON((' and trailing '))' - $polygon = substr($spatial, 9, (strlen($spatial) - 11)); + $polygon = $pmaString->substr( + $spatial, + 9, + $pmaString->strlen($spatial) - 11 + ); - // If the polygon doesnt have an inner polygon - if (strpos($polygon, "),(") === false) { + // If the polygon doesn't have an inner polygon + if ($pmaString->strpos($polygon, "),(") === false) { $points_arr = $this->extractPoints($polygon, $scale_data, true); } else { - // Seperate outer and inner polygons + // Separate outer and inner polygons $parts = explode("),(", $polygon); $outer = $parts[0]; $inner = array_slice($parts, 1); @@ -137,20 +151,23 @@ class PMA_GIS_Polygon extends PMA_GIS_Geometry */ public function prepareRowAsPdf($spatial, $label, $fill_color, $scale_data, $pdf) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // allocate colors - $red = hexdec(substr($fill_color, 1, 2)); - $green = hexdec(substr($fill_color, 3, 2)); - $blue = hexdec(substr($fill_color, 4, 2)); + $red = hexdec($pmaString->substr($fill_color, 1, 2)); + $green = hexdec($pmaString->substr($fill_color, 3, 2)); + $blue = hexdec($pmaString->substr($fill_color, 4, 2)); $color = array($red, $green, $blue); // Trim to remove leading 'POLYGON((' and trailing '))' - $polygon = substr($spatial, 9, (strlen($spatial) - 11)); + $polygon = $pmaString->substr($spatial, 9, ($pmaString->strlen($spatial) - 11)); - // If the polygon doesnt have an inner polygon - if (strpos($polygon, "),(") === false) { + // If the polygon doesn't have an inner polygon + if ($pmaString->strpos($polygon, "),(") === false) { $points_arr = $this->extractPoints($polygon, $scale_data, true); } else { - // Seperate outer and inner polygons + // Separate outer and inner polygons $parts = explode("),(", $polygon); $outer = $parts[0]; $inner = array_slice($parts, 1); @@ -199,16 +216,23 @@ class PMA_GIS_Polygon extends PMA_GIS_Geometry 'fill-opacity'=> 0.8, ); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'POLYGON((' and trailing '))' - $polygon = substr($spatial, 9, (strlen($spatial) - 11)); + $polygon = $pmaString->substr( + $spatial, + 9, + $pmaString->strlen($spatial) - 11 + ); $row = 'strpos($polygon, "),(") === false) { $row .= $this->_drawPath($polygon, $scale_data); } else { - // Seperate outer and inner polygons + // Separate outer and inner polygons $parts = explode("),(", $polygon); $outer = $parts[0]; $inner = array_slice($parts, 1); @@ -256,10 +280,17 @@ class PMA_GIS_Polygon extends PMA_GIS_Geometry } $row = $this->getBoundsForOl($srid, $scale_data); - // Trim to remove leading 'POLYGON((' and trailing '))' - $polygon = substr($spatial, 9, (strlen($spatial) - 11)); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; - // Seperate outer and inner polygons + // Trim to remove leading 'POLYGON((' and trailing '))' + $polygon = $pmaString->substr( + $spatial, + 9, + $pmaString->strlen($spatial) - 11 + ); + + // Separate outer and inner polygons $parts = explode("),(", $polygon); $row .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector(' . $this->getPolygonForOpenLayers($parts, $srid) @@ -307,6 +338,10 @@ class PMA_GIS_Polygon extends PMA_GIS_Geometry if ($no_of_lines < 1) { $no_of_lines = 1; } + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $wkt = 'POLYGON('; for ($i = 0; $i < $no_of_lines; $i++) { $no_of_points = isset($gis_data[$index]['POLYGON'][$i]['no_of_points']) @@ -323,10 +358,10 @@ class PMA_GIS_Polygon extends PMA_GIS_Geometry && trim($gis_data[$index]['POLYGON'][$i][$j]['y']) != '') ? $gis_data[$index]['POLYGON'][$i][$j]['y'] : $empty) . ','; } - $wkt = substr($wkt, 0, strlen($wkt) - 1); + $wkt = $pmaString->substr($wkt, 0, $pmaString->strlen($wkt) - 1); $wkt .= '),'; } - $wkt = substr($wkt, 0, strlen($wkt) - 1); + $wkt = $pmaString->substr($wkt, 0, $pmaString->strlen($wkt) - 1); $wkt .= ')'; return $wkt; } @@ -536,8 +571,11 @@ class PMA_GIS_Polygon extends PMA_GIS_Geometry $wkt = $value; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Trim to remove leading 'POLYGON((' and trailing '))' - $polygon = substr($wkt, 9, (strlen($wkt) - 11)); + $polygon = $pmaString->substr($wkt, 9, ($pmaString->strlen($wkt) - 11)); // Seperate each linestring $linerings = explode("),(", $polygon); $params[$index]['POLYGON']['no_of_lines'] = count($linerings); diff --git a/libraries/gis/GIS_Visualization.class.php b/libraries/gis/GIS_Visualization.class.php index 20fd75f881..4f5d8f7bf2 100644 --- a/libraries/gis/GIS_Visualization.class.php +++ b/libraries/gis/GIS_Visualization.class.php @@ -126,14 +126,18 @@ class PMA_GIS_Visualization { $file_name = PMA_sanitizeFilename($file_name); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Check if the user already added extension; // get the substring where the extension would be if it was included - $extension_start_pos = strlen($file_name) - strlen($ext) - 1; - $user_extension = substr( - $file_name, $extension_start_pos, strlen($file_name) + $extension_start_pos = $pmaString->strlen($file_name) + - $pmaString->strlen($ext) - 1; + $user_extension = $pmaString->substr( + $file_name, $extension_start_pos, $pmaString->strlen($file_name) ); $required_extension = "." . $ext; - if (strtolower($user_extension) != $required_extension) { + if ($pmaString->strtolower($user_extension) != $required_extension) { $file_name .= $required_extension; } return $file_name; @@ -370,12 +374,15 @@ class PMA_GIS_Visualization $plot_width = $this->_settings['width'] - 2 * $border; $plot_height = $this->_settings['height'] - 2 * $border; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + foreach ($data as $row) { // Figure out the data type $ref_data = $row[$this->_settings['spatialColumn']]; - $type_pos = stripos($ref_data, '('); - $type = substr($ref_data, 0, $type_pos); + $type_pos = $pmaString->stripos($ref_data, '('); + $type = $pmaString->substr($ref_data, 0, $type_pos); $gis_obj = PMA_GIS_Factory::factory($type); if (! $gis_obj) { @@ -385,7 +392,7 @@ class PMA_GIS_Visualization $row[$this->_settings['spatialColumn']] ); - // Upadate minimum/maximum values for x and y cordinates. + // Update minimum/maximum values for x and y cordinates. $c_maxX = (float) $scale_data['maxX']; if (! isset($min_max['maxX']) || $c_maxX > $min_max['maxX']) { $min_max['maxX'] = $c_maxX; @@ -454,14 +461,17 @@ class PMA_GIS_Visualization { $color_number = 0; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // loop through the rows foreach ($data as $row) { $index = $color_number % sizeof($this->_settings['colors']); // Figure out the data type $ref_data = $row[$this->_settings['spatialColumn']]; - $type_pos = stripos($ref_data, '('); - $type = substr($ref_data, 0, $type_pos); + $type_pos = $pmaString->stripos($ref_data, '('); + $type = $pmaString->substr($ref_data, 0, $type_pos); $gis_obj = PMA_GIS_Factory::factory($type); if (! $gis_obj) { diff --git a/libraries/iconv_wrapper.lib.php b/libraries/iconv_wrapper.lib.php index bc822e6fee..67ee0a14af 100644 --- a/libraries/iconv_wrapper.lib.php +++ b/libraries/iconv_wrapper.lib.php @@ -75,40 +75,51 @@ function PMA_convertAIXMapCharsets($in_charset, $out_charset) { global $gnu_iconv_to_aix_iconv_codepage_map; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Check for transliteration argument at the end of output character set name - $translit_search = strpos(strtolower($out_charset), '//translit'); + $translit_search = $pmaString->strpos( + $pmaString->strtolower($out_charset), + '//translit' + ); $using_translit = (!($translit_search === false)); // Extract "plain" output character set name // (without any transliteration argument) $out_charset_plain = ($using_translit - ? substr($out_charset, 0, $translit_search) + ? $pmaString->substr($out_charset, 0, $translit_search) : $out_charset); // Transform name of input character set (if found) $in_charset_exisits = array_key_exists( - strtolower($in_charset), + $pmaString->strtolower($in_charset), $gnu_iconv_to_aix_iconv_codepage_map ); if ($in_charset_exisits) { - $in_charset = $gnu_iconv_to_aix_iconv_codepage_map[strtolower($in_charset)]; + $in_charset = $gnu_iconv_to_aix_iconv_codepage_map[ + $pmaString->strtolower($in_charset) + ]; } // Transform name of "plain" output character set (if found) $out_charset_plain_exists = array_key_exists( - strtolower($out_charset_plain), + $pmaString->strtolower($out_charset_plain), $gnu_iconv_to_aix_iconv_codepage_map ); if ($out_charset_plain_exists) { $out_charset_plain = $gnu_iconv_to_aix_iconv_codepage_map[ - strtolower($out_charset_plain)]; + $pmaString->strtolower($out_charset_plain) + ]; } // Add transliteration argument again (exactly as specified by user) if used // Build the output character set name that we will use + /* Not needed because always overwritten $out_charset = ($using_translit - ? $out_charset_plain . substr($out_charset, $translit_search) + ? $out_charset_plain . $pmaString->substr($out_charset, $translit_search) : $out_charset_plain); + */ // NOTE: Transliteration not supported; we will use the "plain" // output character set name diff --git a/libraries/import.lib.php b/libraries/import.lib.php index 07be7759b5..2ee6a76190 100644 --- a/libraries/import.lib.php +++ b/libraries/import.lib.php @@ -97,6 +97,8 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false, return; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; if (! empty($import_run_buffer['sql']) && trim($import_run_buffer['sql']) != '' ) { @@ -104,11 +106,14 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false, // USE query changes the database, son need to track // while running multiple queries $is_use_query - = (stripos($import_run_buffer['sql'], "use ") !== false) + = ($pmaString->stripos($import_run_buffer['sql'], "use ") !== false) ? true : false; - $max_sql_len = max($max_sql_len, strlen($import_run_buffer['sql'])); + $max_sql_len = max( + $max_sql_len, + $pmaString->strlen($import_run_buffer['sql']) + ); if (! $sql_query_disabled) { $sql_query .= $import_run_buffer['full']; } @@ -250,7 +255,7 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false, // the complete query in the textarea) if (! $go_sql && $run_query) { if (! empty($sql_query)) { - if (strlen($sql_query) > 50000 + if ($pmaString->strlen($sql_query) > 50000 || $executed_queries > 50 || $max_sql_len > 1000 ) { @@ -350,16 +355,19 @@ function PMA_importGetNextChunk($size = 32768) return true; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; if ($GLOBALS['import_file'] == 'none') { // Well this is not yet supported and tested, // but should return content of textarea - if (strlen($GLOBALS['import_text']) < $size) { + if ($pmaString->strlen($GLOBALS['import_text']) < $size) { $GLOBALS['finished'] = true; return $GLOBALS['import_text']; } else { - $r = substr($GLOBALS['import_text'], 0, $size); + $r = $pmaString->substr($GLOBALS['import_text'], 0, $size); $GLOBALS['offset'] += $size; - $GLOBALS['import_text'] = substr($GLOBALS['import_text'], $size); + $GLOBALS['import_text'] = $pmaString + ->substr($GLOBALS['import_text'], $size); return $r; } } @@ -374,8 +382,8 @@ function PMA_importGetNextChunk($size = 32768) $GLOBALS['finished'] = feof($import_handle); break; case 'application/zip': - $result = substr($GLOBALS['import_text'], 0, $size); - $GLOBALS['import_text'] = substr($GLOBALS['import_text'], $size); + $result = $pmaString->substr($GLOBALS['import_text'], 0, $size); + $GLOBALS['import_text'] = $pmaString->substr($GLOBALS['import_text'], $size); $GLOBALS['finished'] = empty($GLOBALS['import_text']); break; case 'none': @@ -399,12 +407,12 @@ function PMA_importGetNextChunk($size = 32768) if ($GLOBALS['offset'] == $size) { // UTF-8 if (strncmp($result, "\xEF\xBB\xBF", 3) == 0) { - $result = substr($result, 3); + $result = $pmaString->substr($result, 3); // UTF-16 BE, LE } elseif (strncmp($result, "\xFE\xFF", 2) == 0 || strncmp($result, "\xFF\xFE", 2) == 0 ) { - $result = substr($result, 2); + $result = $pmaString->substr($result, 2); } } return $result; @@ -456,13 +464,16 @@ function PMA_getColumnAlphaName($num) $num = $remain; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if ($num == 0) { // use 'Z' if column number is 0, // this is necessary because A-Z has no 'zero' - $col_name .= chr(($A + 26) - 1); + $col_name .= $pmaString->chr(($A + 26) - 1); } else { // convert column number to ASCII character - $col_name .= chr(($A + $num) - 1); + $col_name .= $pmaString->chr(($A + $num) - 1); } return $col_name; @@ -488,8 +499,10 @@ function PMA_getColumnNumberFromName($name) return 0; } - $name = strtoupper($name); - $num_chars = strlen($name); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $name = $pmaString->strtoupper($name); + $num_chars = $pmaString->strlen($name); $column_number = 0; for ($i = 0; $i < $num_chars; ++$i) { // read string from back to front @@ -499,7 +512,7 @@ function PMA_getColumnNumberFromName($name) // and subtract 64 to get corresponding decimal value // ASCII value of "A" is 65, "B" is 66, etc. // Decimal equivalent of "A" is 1, "B" is 2, etc. - $number = (ord($name[$char_pos]) - 64); + $number = (int)($pmaString->ord($name[$char_pos]) - 64); // base26 to base10 conversion : multiply each number // with corresponding value of the position, in this case @@ -546,7 +559,13 @@ define("FORMATTEDSQL", 2); */ function PMA_getDecimalPrecision($last_cumulative_size) { - return (int)substr($last_cumulative_size, 0, strpos($last_cumulative_size, ",")); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + return (int)$pmaString->substr( + $last_cumulative_size, + 0, + $pmaString->strpos($last_cumulative_size, ",") + ); } /** @@ -560,10 +579,13 @@ function PMA_getDecimalPrecision($last_cumulative_size) */ function PMA_getDecimalScale($last_cumulative_size) { - return (int) substr( + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + return (int) $pmaString->substr( $last_cumulative_size, - (strpos($last_cumulative_size, ",") + 1), - (strlen($last_cumulative_size) - strpos($last_cumulative_size, ",")) + ($pmaString->strpos($last_cumulative_size, ",") + 1), + ($pmaString->strlen($last_cumulative_size) + - $pmaString->strpos($last_cumulative_size, ",")) ); } @@ -578,8 +600,10 @@ function PMA_getDecimalScale($last_cumulative_size) */ function PMA_getDecimalSize($cell) { - $curr_size = strlen((string)$cell); - $decPos = strpos($cell, "."); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $curr_size = $pmaString->strlen((string)$cell); + $decPos = $pmaString->strpos($cell, "."); $decPrecision = ($curr_size - 1) - $decPos; $m = $curr_size - 1; @@ -606,7 +630,9 @@ function PMA_getDecimalSize($cell) function PMA_detectSize($last_cumulative_size, $last_cumulative_type, $curr_type, $cell ) { - $curr_size = strlen((string)$cell); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $curr_size = $pmaString->strlen((string)$cell); /** * If the cell is NULL, don't treat it as a varchar @@ -744,7 +770,7 @@ function PMA_detectSize($last_cumulative_size, $last_cumulative_type, $oldM = PMA_getDecimalPrecision($last_cumulative_size); $oldD = PMA_getDecimalScale($last_cumulative_size); $oldInt = $oldM - $oldD; - $newInt = strlen((string)$cell); + $newInt = $pmaString->strlen((string)$cell); /* See which has the larger integer length */ if ($oldInt >= $newInt) { @@ -817,22 +843,25 @@ function PMA_detectType($last_cumulative_type, $cell) return $last_cumulative_type; } - if (is_numeric($cell)) { - if ($cell == (string)(float)$cell - && strpos($cell, ".") !== false - && substr_count($cell, ".") == 1 - ) { - return DECIMAL; - } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; - if (abs($cell) > 2147483647) { - return BIGINT; - } - - return INT; + if (!is_numeric($cell)) { + return VARCHAR; } - return VARCHAR; + if ($cell == (string)(float)$cell + && $pmaString->strpos($cell, ".") !== false + && substr_count($cell, ".") == 1 + ) { + return DECIMAL; + } + + if (abs($cell) > 2147483647) { + return BIGINT; + } + + return INT; } /** diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index d628f5ca5d..c53e79694d 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -342,12 +342,15 @@ function PMA_getColumnTitle($column, $comments_map) */ function PMA_isColumnBinary($column) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // The type column. // Fix for bug #3152931 'ENUM and SET cannot have "Binary" option' - if (stripos($column['Type'], 'binary') === 0 - || stripos($column['Type'], 'varbinary') === 0 + if ($pmaString->stripos($column['Type'], 'binary') === 0 + || $pmaString->stripos($column['Type'], 'varbinary') === 0 ) { - return stristr($column['Type'], 'binary'); + return $pmaString->stristr($column['Type'], 'binary'); } else { return false; } @@ -365,12 +368,15 @@ function PMA_isColumnBinary($column) */ function PMA_isColumnBlob($column) { - if (stripos($column['Type'], 'blob') === 0 - || stripos($column['Type'], 'tinyblob') === 0 - || stripos($column['Type'], 'mediumblob') === 0 - || stripos($column['Type'], 'longblob') === 0 + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + if ($pmaString->stripos($column['Type'], 'blob') === 0 + || $pmaString->stripos($column['Type'], 'tinyblob') === 0 + || $pmaString->stripos($column['Type'], 'mediumblob') === 0 + || $pmaString->stripos($column['Type'], 'longblob') === 0 ) { - return stristr($column['Type'], 'blob'); + return $pmaString->stristr($column['Type'], 'blob'); } else { return false; } @@ -386,10 +392,13 @@ function PMA_isColumnBlob($column) */ function PMA_isColumnChar($column) { - if (stripos($column['Type'], 'char') === 0 - || stripos($column['Type'], 'varchar') === 0 + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + if ($pmaString->stripos($column['Type'], 'char') === 0 + || $pmaString->stripos($column['Type'], 'varchar') === 0 ) { - return stristr($column['Type'], 'char'); + return $pmaString->stristr($column['Type'], 'char'); } else { return false; } @@ -453,6 +462,9 @@ function PMA_getFunctionColumn($column, $is_upload, $column_name_appendix, $unnullify_trigger, $no_support_types, $tabindex_for_function, $tabindex, $idindex, $insert_mode ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $html_output = ''; if (($GLOBALS['cfg']['ProtectBinary'] === 'blob' && $column['is_blob'] && !$is_upload) @@ -462,8 +474,8 @@ function PMA_getFunctionColumn($column, $is_upload, $column_name_appendix, && $column['is_binary']) ) { $html_output .= '' . "\n"; - } elseif (strstr($column['True_Type'], 'enum') - || strstr($column['True_Type'], 'set') + } elseif ($pmaString->strstr($column['True_Type'], 'enum') + || $pmaString->strstr($column['True_Type'], 'set') || in_array($column['pma_type'], $no_support_types) ) { $html_output .= '' . "\n"; @@ -547,14 +559,16 @@ function PMA_getNullColumn($column, $column_name_appendix, $real_null_value, */ function PMA_getNullifyCodeForNullColumn($column, $foreigners, $foreignData) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; $foreigner = PMA_searchColumnInForeigners($foreigners, $column['Field']); - if (strstr($column['True_Type'], 'enum')) { - if (strlen($column['Type']) > 20) { + if ($pmaString->strstr($column['True_Type'], 'enum')) { + if ($pmaString->strlen($column['Type']) > 20) { $nullify_code = '1'; } else { $nullify_code = '2'; } - } elseif (strstr($column['True_Type'], 'set')) { + } elseif ($pmaString->strstr($column['True_Type'], 'set')) { $nullify_code = '3'; } elseif ($foreigners && $foreigner @@ -622,6 +636,8 @@ function PMA_getValueColumn($column, $backup_field, $column_name_appendix, $data_type = $GLOBALS['PMA_Types']->getTypeClass($column['True_Type']); $html_output = ''; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; if ($foreignData['foreign_link'] == true) { $html_output .= PMA_getForeignLink( $column, $backup_field, $column_name_appendix, @@ -637,7 +653,7 @@ function PMA_getValueColumn($column, $backup_field, $column_name_appendix, ); } elseif ($GLOBALS['cfg']['LongtextDoubleTextarea'] - && strstr($column['pma_type'], 'longtext') + && $pmaString->strstr($column['pma_type'], 'longtext') ) { $html_output = ' '; $html_output .= ''; @@ -649,7 +665,7 @@ function PMA_getValueColumn($column, $backup_field, $column_name_appendix, $special_chars_encoded, $data_type ); - } elseif (strstr($column['pma_type'], 'text')) { + } elseif ($pmaString->strstr($column['pma_type'], 'text')) { $html_output .= PMA_getTextarea( $column, $backup_field, $column_name_appendix, $unnullify_trigger, @@ -657,7 +673,7 @@ function PMA_getValueColumn($column, $backup_field, $column_name_appendix, $special_chars_encoded, $data_type ); $html_output .= "\n"; - if (strlen($special_chars) > 32000) { + if ($pmaString->strlen($special_chars) > 32000) { $html_output .= "\n"; $html_output .= '' . '' . '
' . __('Binary') . '--
' . __( 'Because of its length,
this column might not be editable.' @@ -827,7 +843,7 @@ function PMA_getTextarea($column, $backup_field, $column_name_appendix, $extracted_columnspec = PMA_Util::extractColumnSpec($column['Type']); $maxlength = $extracted_columnspec['spec_in_brackets']; } elseif ($GLOBALS['cfg']['LongtextDoubleTextarea'] - && strstr($column['pma_type'], 'longtext') + && $GLOBALS['PMA_String']->strstr($column['pma_type'], 'longtext') ) { $textAreaRows = $GLOBALS['cfg']['TextareaRows'] * 2; $textareaCols = $GLOBALS['cfg']['TextareaCols'] * 2; @@ -882,7 +898,7 @@ function PMA_getPmaTypeEnum($column, $backup_field, $column_name_appendix, $html_output .= ''; $html_output .= "\n" . ' ' . $backup_field . "\n"; - if (strlen($column['Type']) > 20) { + if ($GLOBALS['PMA_String']->strlen($column['Type']) > 20) { $html_output .= PMA_getDropDownDependingOnLength( $column, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data, $column_enum_values @@ -1115,7 +1131,7 @@ function PMA_getBinaryAndBlobColumn( $html_output .= __('Binary - do not edit'); if (isset($data)) { $data_size = PMA_Util::formatByteDown( - strlen(stripslashes($data)), 3, 1 + $GLOBALS['PMA_String']->strlen(stripslashes($data)), 3, 1 ); $html_output .= ' (' . $data_size[0] . ' ' . $data_size[1] . ')'; unset($data_size); @@ -1319,13 +1335,16 @@ function PMA_getValueColumnForOtherDatatypes($column, $default_char_editing, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded, $data, $extracted_columnspec ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // HTML5 data-* attribute data-type $data_type = $GLOBALS['PMA_Types']->getTypeClass($column['True_Type']); $fieldsize = PMA_getColumnSize($column, $extracted_columnspec); $html_output = $backup_field . "\n"; if ($column['is_char'] && ($GLOBALS['cfg']['CharEditing'] == 'textarea' - || strpos($data, "\n") !== false) + || $pmaString->strpos($data, "\n") !== false) ) { $html_output .= "\n"; $GLOBALS['cfg']['CharEditing'] = $default_char_editing; @@ -1344,11 +1363,11 @@ function PMA_getValueColumnForOtherDatatypes($column, $default_char_editing, $html_output .= ''; } - if (substr($column['pma_type'], 0, 9) == 'timestamp') { + if ($pmaString->substr($column['pma_type'], 0, 9) == 'timestamp') { $html_output .= ''; } - if (substr($column['pma_type'], 0, 8) == 'datetime') { + if ($pmaString->substr($column['pma_type'], 0, 8) == 'datetime') { $html_output .= ''; } @@ -1358,7 +1377,7 @@ function PMA_getValueColumnForOtherDatatypes($column, $default_char_editing, } if ($column['pma_type'] == 'date' || $column['pma_type'] == 'datetime' - || substr($column['pma_type'], 0, 9) == 'timestamp' + || $pmaString->substr($column['pma_type'], 0, 9) == 'timestamp' ) { // the _3 suffix points to the date field // the _2 suffix points to the corresponding NULL checkbox @@ -1671,6 +1690,9 @@ function PMA_getSpecialCharsAndBackupFieldForExistingRow( $current_row, $column, $extracted_columnspec, $real_null_value, $gis_data_types, $column_name_appendix, $as_is ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $special_chars_encoded = ''; $data = null; // (we are editing) @@ -1686,10 +1708,10 @@ function PMA_getSpecialCharsAndBackupFieldForExistingRow( $current_row[$column['Field']], $extracted_columnspec['spec_in_brackets'] ); - } elseif ((substr($column['True_Type'], 0, 9) == 'timestamp' + } elseif (($pmaString->substr($column['True_Type'], 0, 9) == 'timestamp' || $column['True_Type'] == 'datetime' || $column['True_Type'] == 'time') - && (strpos($current_row[$column['Field']], ".") === true) + && ($pmaString->strpos($current_row[$column['Field']], ".") === true) ) { $current_row[$column['Field']] = $as_is ? $current_row[$column['Field']] @@ -1732,7 +1754,7 @@ function PMA_getSpecialCharsAndBackupFieldForExistingRow( && $_REQUEST['default_action'] === 'insert' ) { if ($column['Key'] === 'PRI' - && strpos($column['Extra'], 'auto_increment') !== false + && $pmaString->strpos($column['Extra'], 'auto_increment') !== false ) { $data = $special_chars_encoded = $special_chars = null; } @@ -1774,11 +1796,13 @@ function PMA_getSpecialCharsAndBackupFieldForInsertingMode( $data = $column['Default']; } - if ($column['True_Type'] == 'bit') { + $trueType = $column['True_Type']; + + if ($trueType == 'bit') { $special_chars = PMA_Util::convertBitDefaultValue($column['Default']); - } elseif (substr($column['True_Type'], 0, 9) == 'timestamp' - || $column['True_Type'] == 'datetime' - || $column['True_Type'] == 'time' + } elseif ($GLOBALS['PMA_String']->substr($trueType, 0, 9) == 'timestamp' + || $trueType == 'datetime' + || $trueType == 'time' ) { $special_chars = PMA_Util::addMicroseconds($column['Default']); } else { @@ -1885,6 +1909,9 @@ function PMA_setSessionForEditNext($one_where_clause) */ function PMA_getGotoInclude($goto_include) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $valid_options = array('new_insert', 'same_insert', 'edit_next'); if (isset($_REQUEST['after_insert']) && in_array($_REQUEST['after_insert'], $valid_options) @@ -1898,12 +1925,14 @@ function PMA_getGotoInclude($goto_include) } else { $goto_include = $GLOBALS['goto']; } - if ($GLOBALS['goto'] == 'db_sql.php' && strlen($GLOBALS['table'])) { + if ($GLOBALS['goto'] == 'db_sql.php' + && $pmaString->strlen($GLOBALS['table']) + ) { $GLOBALS['table'] = ''; } } if (! $goto_include) { - if (! strlen($GLOBALS['table'])) { + if (! $pmaString->strlen($GLOBALS['table'])) { $goto_include = 'db_sql.php'; } else { $goto_include = 'tbl_sql.php'; @@ -2062,7 +2091,7 @@ function PMA_getDisplayValueForForeignTableColumn($where_comparison, $foreigner['foreign_table'] ); // Field to display from the foreign table? - if (isset($display_field) && strlen($display_field)) { + if (isset($display_field) && $GLOBALS['PMA_String']->strlen($display_field)) { $dispsql = 'SELECT ' . PMA_Util::backquote($display_field) . ' FROM ' . PMA_Util::backquote($foreigner['foreign_db']) . '.' . PMA_Util::backquote($foreigner['foreign_table']) @@ -2201,6 +2230,9 @@ function PMA_getCurrentValueAsAnArrayForMultipleEdit( $multi_edit_funcs, $gis_from_text_functions, $current_value, $gis_from_wkb_functions, $func_optional_param, $func_no_param, $key ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if (empty($multi_edit_funcs[$key])) { return $current_value; } elseif ('UUID' === $multi_edit_funcs[$key]) { @@ -2208,11 +2240,13 @@ function PMA_getCurrentValueAsAnArrayForMultipleEdit( $multi_edit_funcs, $uuid = $GLOBALS['dbi']->fetchValue('SELECT UUID()'); return "'" . $uuid . "'"; } elseif ((in_array($multi_edit_funcs[$key], $gis_from_text_functions) - && substr($current_value, 0, 3) == "'''") + && $pmaString->substr($current_value, 0, 3) == "'''") || in_array($multi_edit_funcs[$key], $gis_from_wkb_functions) ) { // Remove enclosing apostrophes - $current_value = substr($current_value, 1, strlen($current_value) - 2); + $current_value = $pmaString->substr( + $current_value, 1, $pmaString->strlen($current_value) - 2 + ); // Remove escaping apostrophes $current_value = str_replace("''", "'", $current_value); return $multi_edit_funcs[$key] . '(' . $current_value . ')'; @@ -2261,7 +2295,7 @@ function PMA_getQueryValuesForInsertAndUpdateInMultipleEdit($multi_edit_columns_ // i n s e r t if ($is_insert) { // no need to add column into the valuelist - if (strlen($current_value_as_an_array)) { + if ($GLOBALS['PMA_String']->strlen($current_value_as_an_array)) { $query_values[] = $current_value_as_an_array; // first inserted row so prepare the list of fields if (empty($value_sets)) { @@ -2347,7 +2381,9 @@ function PMA_getCurrentValueForDifferentTypes($possibly_uploaded_val, $key, $type = ''; } - if ($type != 'protected' && $type != 'set' && 0 === strlen($current_value)) { + if ($type != 'protected' && $type != 'set' + && 0 === $GLOBALS['PMA_String']->strlen($current_value) + ) { // best way to avoid problems in strict mode // (works also in non-strict mode) if (isset($multi_edit_auto_increment) @@ -2441,7 +2477,7 @@ function PMA_verifyWhetherValueCanBeTruncatedAndAppendExtraData( $meta = $fields_meta[0]; $new_value = $GLOBALS['dbi']->fetchValue($result); if ($new_value !== false) { - if ((substr($meta->type, 0, 9) == 'timestamp') + if (($GLOBALS['PMA_String']->substr($meta->type, 0, 9) == 'timestamp') || ($meta->type == 'datetime') || ($meta->type == 'time') ) { @@ -2630,7 +2666,8 @@ function PMA_getHtmlForFunctionOption($odd_row, $column, $column_name_appendix) $longDoubleTextArea = $GLOBALS['cfg']['LongtextDoubleTextarea']; return '
strstr($column['True_Type'], 'longtext') ? 'rowspan="2"' : '' ) diff --git a/libraries/ip_allow_deny.lib.php b/libraries/ip_allow_deny.lib.php index df46013ed2..b4209fc75c 100644 --- a/libraries/ip_allow_deny.lib.php +++ b/libraries/ip_allow_deny.lib.php @@ -67,7 +67,12 @@ function PMA_ipMaskTest($testRange, $ipToTest) { $result = true; - if (strpos($testRange, ':') > -1 || strpos($ipToTest, ':') > -1) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + if ($pmaString->strpos($testRange, ':') > -1 + || $pmaString->strpos($ipToTest, ':') > -1 + ) { // assume IPv6 $result = PMA_ipv6MaskTest($testRange, $ipToTest); } else { @@ -178,12 +183,15 @@ function PMA_ipv6MaskTest($test_range, $ip_to_test) { $result = true; - // convert to lowercase for easier comparison - $test_range = strtolower($test_range); - $ip_to_test = strtolower($ip_to_test); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; - $is_cidr = strpos($test_range, '/') > -1; - $is_range = strpos($test_range, '[') > -1; + // convert to lowercase for easier comparison + $test_range = $pmaString->strtolower($test_range); + $ip_to_test = $pmaString->strtolower($ip_to_test); + + $is_cidr = $pmaString->strpos($test_range, '/') > -1; + $is_range = $pmaString->strpos($test_range, '[') > -1; $is_single = ! $is_cidr && ! $is_range; $ip_hex = bin2hex(inet_pton($ip_to_test)); @@ -235,7 +243,7 @@ function PMA_ipv6MaskTest($test_range, $ip_to_test) $pos = 31; while ($flexbits > 0) { // Get the character at this position - $orig = substr($last_hex, $pos, 1); + $orig = $pmaString->substr($last_hex, $pos, 1); // Convert it to an integer $origval = hexdec($orig); diff --git a/libraries/mime.lib.php b/libraries/mime.lib.php index 399b36d859..529a2d1d27 100644 --- a/libraries/mime.lib.php +++ b/libraries/mime.lib.php @@ -19,14 +19,16 @@ if (! defined('PHPMYADMIN')) { */ function PMA_detectMIME(&$test) { - $len = strlen($test); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $len = $pmaString->strlen($test); if ($len >= 2 && $test[0] == chr(0xff) && $test[1] == chr(0xd8)) { return 'image/jpeg'; } - if ($len >= 3 && substr($test, 0, 3) == 'GIF') { + if ($len >= 3 && $pmaString->substr($test, 0, 3) == 'GIF') { return 'image/gif'; } - if ($len >= 4 && substr($test, 0, 4) == "\x89PNG") { + if ($len >= 4 && $pmaString->substr($test, 0, 4) == "\x89PNG") { return 'image/png'; } return 'application/octet-stream'; diff --git a/libraries/mult_submits.inc.php b/libraries/mult_submits.inc.php index 531967dd09..e0065c1ba5 100644 --- a/libraries/mult_submits.inc.php +++ b/libraries/mult_submits.inc.php @@ -152,11 +152,13 @@ $views = $GLOBALS['dbi']->getVirtualTables($db); if (!empty($submit_mult) && !empty($what)) { unset($message); - if (strlen($table)) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if ($pmaString->strlen($table)) { include './libraries/tbl_common.inc.php'; $url_query .= '&goto=tbl_sql.php&back=tbl_sql.php'; include './libraries/tbl_info.inc.php'; - } elseif (strlen($db)) { + } elseif ($pmaString->strlen($db)) { include './libraries/db_common.inc.php'; include './libraries/db_info.inc.php'; } else { diff --git a/libraries/mult_submits.lib.php b/libraries/mult_submits.lib.php index 25bbda6965..c6f55e3205 100644 --- a/libraries/mult_submits.lib.php +++ b/libraries/mult_submits.lib.php @@ -34,9 +34,13 @@ function PMA_getUrlParams( 'query_type' => $what, 'reload' => (! empty($reload) ? 1 : 0), ); - if (strpos(' ' . $action, 'db_') == 1) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if ($pmaString->strpos(' ' . $action, 'db_') == 1) { $_url_params['db']= $db; - } elseif (strpos(' ' . $action, 'tbl_') == 1 || $what == 'row_delete') { + } elseif ($pmaString->strpos(' ' . $action, 'tbl_') == 1 + || $what == 'row_delete' + ) { $_url_params['db']= $db; $_url_params['table']= $table; } @@ -100,6 +104,9 @@ function PMA_getQueryStrFromSelected( $selected_cnt = count($selected); $deletes = false; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + for ($i = 0; $i < $selected_cnt; $i++) { switch ($query_type) { case 'row_delete': @@ -224,8 +231,11 @@ function PMA_getQueryStrFromSelected( case 'replace_prefix_tbl': $current = $selected[$i]; - if (substr($current, 0, strlen($from_prefix)) == $from_prefix) { - $newtablename = $to_prefix . substr($current, strlen($from_prefix)); + $subFromPrefix = $pmaString + ->substr($current, 0, $pmaString->strlen($from_prefix)); + if ($subFromPrefix == $from_prefix) { + $newtablename = $to_prefix + . $pmaString->substr($current, $pmaString->strlen($from_prefix)); } else { $newtablename = $current; } @@ -239,7 +249,8 @@ function PMA_getQueryStrFromSelected( case 'copy_tbl_change_prefix': $current = $selected[$i]; - $newtablename = $to_prefix . substr($current, strlen($from_prefix)); + $newtablename = $to_prefix . + $pmaString->substr($current, $pmaString->strlen($from_prefix)); // COPY TABLE AND CHANGE PREFIX PATTERN $a_query = 'CREATE TABLE ' . PMA_Util::backquote($newtablename) diff --git a/libraries/navigation/NavigationHeader.class.php b/libraries/navigation/NavigationHeader.class.php index 732e9bd32b..97f06e60d4 100644 --- a/libraries/navigation/NavigationHeader.class.php +++ b/libraries/navigation/NavigationHeader.class.php @@ -75,50 +75,58 @@ class PMA_NavigationHeader { $retval = ''; // display Logo, depending on $GLOBALS['cfg']['NavigationDisplayLogo'] - if ($GLOBALS['cfg']['NavigationDisplayLogo']) { - $logo = 'phpMyAdmin'; - if (@file_exists($GLOBALS['pmaThemeImage'] . 'logo_left.png')) { - $logo = ''; - } elseif (@file_exists($GLOBALS['pmaThemeImage'] . 'pma_logo2.png')) { - $logo = ''; - } - $retval .= '
' @@ -875,7 +877,8 @@ function PMA_getTableOptionFieldset($comment, $tbl_collation, // (if the table was compressed, it can be seen on the Structure page) if (isset($possible_row_formats[$tbl_storage_engine])) { - $current_row_format = strtoupper($GLOBALS['showtable']['Row_format']); + $current_row_format + = $pmaString->strtoupper($GLOBALS['showtable']['Row_format']); $html_output .= '
' . ''; @@ -1447,8 +1450,11 @@ function PMA_getTableAltersArray($is_myisam_or_aria, $is_isam, $pack_keys, $table_alters[] = 'COMMENT = \'' . PMA_Util::sqlAddSlashes($_REQUEST['comment']) . '\''; } + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; if (! empty($newTblStorageEngine) - && strtolower($newTblStorageEngine) !== strtolower($GLOBALS['tbl_storage_engine']) + && $pmaString->strtolower($newTblStorageEngine) !== $pmaString->strtolower($GLOBALS['tbl_storage_engine']) ) { $table_alters[] = 'ENGINE = ' . $newTblStorageEngine; } @@ -1506,13 +1512,14 @@ function PMA_getTableAltersArray($is_myisam_or_aria, $is_isam, $pack_keys, . PMA_Util::sqlAddSlashes($_REQUEST['new_auto_increment']); } + $newRowFormat = $_REQUEST['new_row_format']; + $newRowFormatLower = $pmaString->strtolower($newRowFormat); if (($is_myisam_or_aria || $is_innodb || $is_pbxt) - && ! empty($_REQUEST['new_row_format']) - && (!strlen($row_format) - || strtolower($_REQUEST['new_row_format']) !== strtolower($row_format)) + && ! empty($newRowFormat) + && (!$pmaString->strlen($row_format) + || $newRowFormatLower !== $pmaString->strtolower($row_format)) ) { - $table_alters[] = 'ROW_FORMAT = ' - . PMA_Util::sqlAddSlashes($_REQUEST['new_row_format']); + $table_alters[] = 'ROW_FORMAT = ' . PMA_Util::sqlAddSlashes($newRowFormat); } return $table_alters; @@ -1528,7 +1535,7 @@ function PMA_getTableAltersArray($is_myisam_or_aria, $is_isam, $pack_keys, */ function PMA_setGlobalVariablesForEngine($tbl_storage_engine) { - $upperTblStorEngine = strtoupper($tbl_storage_engine); + $upperTblStorEngine = $GLOBALS['PMA_String']->strtoupper($tbl_storage_engine); //Options that apply to MYISAM usually apply to ARIA $is_myisam_or_aria = ($upperTblStorEngine == 'MYISAM' diff --git a/libraries/parse_analyze.inc.php b/libraries/parse_analyze.inc.php index eb7704efcb..b01162d51e 100644 --- a/libraries/parse_analyze.inc.php +++ b/libraries/parse_analyze.inc.php @@ -130,7 +130,7 @@ if ($is_select) { $table = $analyzed_sql[0]['table_ref'][0]['table_true_name']; } if (isset($analyzed_sql[0]['table_ref'][0]['db']) - && strlen($analyzed_sql[0]['table_ref'][0]['db']) + && $GLOBALS['PMA_String']->strlen($analyzed_sql[0]['table_ref'][0]['db']) ) { $db = $analyzed_sql[0]['table_ref'][0]['db']; } else { diff --git a/libraries/plugin_interface.lib.php b/libraries/plugin_interface.lib.php index 25698e2174..e8c7a4a637 100644 --- a/libraries/plugin_interface.lib.php +++ b/libraries/plugin_interface.lib.php @@ -23,11 +23,14 @@ function PMA_getPlugin( $plugins_dir, $plugin_param = false ) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $GLOBALS['plugin_param'] = $plugin_param; - $class_name = strtoupper($plugin_type[0]) - . strtolower(substr($plugin_type, 1)) - . strtoupper($plugin_format[0]) - . strtolower(substr($plugin_format, 1)); + $class_name = $pmaString->strtoupper($plugin_type[0]) + . $pmaString->strtolower($pmaString->substr($plugin_type, 1)) + . $pmaString->strtoupper($plugin_format[0]) + . $pmaString->strtolower($pmaString->substr($plugin_format, 1)); $file = $class_name . ".class.php"; if (is_file($plugins_dir . $file)) { include_once $plugins_dir . $file; @@ -41,7 +44,7 @@ function PMA_getPlugin( * Reads all plugin information from directory $plugins_dir * * @param string $plugin_type the type of the plugin (import, export, etc) - * @param string $plugins_dir directrory with plugins + * @param string $plugins_dir directory with plugins * @param mixed $plugin_param parameter to plugin by which they can * decide whether they can work * @@ -57,13 +60,16 @@ function PMA_getPlugins($plugin_type, $plugins_dir, $plugin_param) return $plugin_list; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + //@todo Find a way to use PMA_StringMB with UTF-8 instead of mb_*. while ($file = @readdir($handle)) { // In some situations, Mac OS creates a new file for each file // (for example ._csv.php) so the following regexp // matches a file which does not start with a dot but ends // with ".php" $class_type = mb_strtoupper($plugin_type[0], 'UTF-8') - . mb_strtolower(substr($plugin_type, 1), 'UTF-8'); + . mb_strtolower($pmaString->substr($plugin_type, 1), 'UTF-8'); if (is_file($plugins_dir . $file) && preg_match( '@^' . $class_type . '(.+)\.class\.php$@i', @@ -190,8 +196,12 @@ function PMA_pluginGetChoice($section, $name, &$list, $cfgname = null) } $ret = 'strpos(get_class($propertyGroup), "PropertyItem")) { $properties = array($propertyGroup); } else { // for main groups @@ -282,7 +297,7 @@ function PMA_pluginGetOneOption( foreach ($properties as $propertyItem) { $property_class = get_class($propertyItem); // if the property is a subgroup, we deal with it recursively - if (strpos($property_class, "Subgroup")) { + if ($pmaString->strpos($property_class, "Subgroup")) { // for subgroups // each subgroup can have a header, which may also be a form element $subgroup_header = $propertyItem->getSubgroupHeader(); @@ -475,6 +490,9 @@ function PMA_pluginGetOneOption( */ function PMA_pluginGetOptions($section, &$list) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $ret = ''; // Options for plugins that support them foreach ($list as $plugin) { @@ -484,7 +502,9 @@ function PMA_pluginGetOptions($section, &$list) $options = $properties->getOptions(); } - $plugin_name = strtolower(substr(get_class($plugin), strlen($section))); + $plugin_name = $pmaString->strtolower( + $pmaString->substr(get_class($plugin), $pmaString->strlen($section)) + ); $ret .= '
'; $ret .= '

' . PMA_getString($text) . '

'; diff --git a/libraries/plugins/auth/AuthenticationCookie.class.php b/libraries/plugins/auth/AuthenticationCookie.class.php index 95f9efdecc..625d67344f 100644 --- a/libraries/plugins/auth/AuthenticationCookie.class.php +++ b/libraries/plugins/auth/AuthenticationCookie.class.php @@ -587,12 +587,15 @@ class AuthenticationCookie extends AuthenticationPlugin // URL where to go: $redirect_url = $cfg['PmaAbsoluteUri'] . 'index.php'; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // any parameters to pass? $url_params = array(); - if (strlen($GLOBALS['db'])) { + if ($pmaString->strlen($GLOBALS['db'])) { $url_params['db'] = $GLOBALS['db']; } - if (strlen($GLOBALS['table'])) { + if ($pmaString->strlen($GLOBALS['table'])) { $url_params['table'] = $GLOBALS['table']; } // any target to pass? diff --git a/libraries/plugins/export/ExportCsv.class.php b/libraries/plugins/export/ExportCsv.class.php index 70acb1c672..21d0c1121b 100644 --- a/libraries/plugins/export/ExportCsv.class.php +++ b/libraries/plugins/export/ExportCsv.class.php @@ -131,7 +131,9 @@ class ExportCsv extends ExportPlugin $GLOBALS['csv_columns'] = 'yes'; } } else { - if (empty($csv_terminated) || strtolower($csv_terminated) == 'auto') { + if (empty($csv_terminated) + || $GLOBALS['PMA_String']->strtolower($csv_terminated) == 'auto' + ) { $csv_terminated = $GLOBALS['crlf']; } else { $csv_terminated = str_replace('\\r', "\015", $csv_terminated); @@ -241,7 +243,9 @@ class ExportCsv extends ExportPlugin } $schema_insert .= $csv_separator; } // end for - $schema_insert = trim(substr($schema_insert, 0, -1)); + $schema_insert = trim( + $GLOBALS['PMA_String']->substr($schema_insert, 0, -1) + ); if (! PMA_exportOutputHandler($schema_insert . $csv_terminated)) { return false; } diff --git a/libraries/plugins/export/ExportLatex.class.php b/libraries/plugins/export/ExportLatex.class.php index 5519c58b58..a2b126bd3f 100644 --- a/libraries/plugins/export/ExportLatex.class.php +++ b/libraries/plugins/export/ExportLatex.class.php @@ -343,7 +343,8 @@ class ExportLatex extends ExportPlugin . self::texEscape(stripslashes($columns_alias[$i])) . '}} & '; } - $buffer = substr($buffer, 0, -2) . '\\\\ \\hline \hline '; + $buffer = $GLOBALS['PMA_String']->substr($buffer, 0, -2) + . '\\\\ \\hline \hline '; if (! PMA_exportOutputHandler($buffer . ' \\endfirsthead ' . $crlf)) { return false; } @@ -574,6 +575,9 @@ class ExportLatex extends ExportPlugin return false; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $fields = $GLOBALS['dbi']->getColumns($db, $table); foreach ($fields as $row) { $extracted_columnspec @@ -625,16 +629,16 @@ class ExportLatex extends ExportPlugin } $local_buffer = self::texEscape($local_buffer); if ($row['Key']=='PRI') { - $pos=strpos($local_buffer, "\000"); + $pos = $pmaString->strpos($local_buffer, "\000"); $local_buffer = '\\textit{' - . substr($local_buffer, 0, $pos) - . '}' . substr($local_buffer, $pos); + . $pmaString->substr($local_buffer, 0, $pos) + . '}' . $pmaString->substr($local_buffer, $pos); } if (in_array($field_name, $unique_keys)) { - $pos=strpos($local_buffer, "\000"); + $pos = $pmaString->strpos($local_buffer, "\000"); $local_buffer = '\\textbf{' - . substr($local_buffer, 0, $pos) - . '}' . substr($local_buffer, $pos); + . $pmaString->substr($local_buffer, 0, $pos) + . '}' . $pmaString->substr($local_buffer, $pos); } $buffer = str_replace("\000", ' & ', $local_buffer); $buffer .= ' \\\\ \\hline ' . $crlf; diff --git a/libraries/plugins/export/ExportSql.class.php b/libraries/plugins/export/ExportSql.class.php index a15279a835..bc98579aca 100644 --- a/libraries/plugins/export/ExportSql.class.php +++ b/libraries/plugins/export/ExportSql.class.php @@ -785,42 +785,49 @@ class ExportSql extends ExportPlugin return false; } } - if (isset($GLOBALS['sql_create_database'])) { - $create_query = 'CREATE DATABASE IF NOT EXISTS ' - . (isset($GLOBALS['sql_backquotes']) - ? PMA_Util::backquoteCompat($db_alias, $compat) : $db_alias); - $collation = PMA_getDbCollation($db); - if (PMA_DRIZZLE) { - $create_query .= ' COLLATE ' . $collation; - } else { - if (strpos($collation, '_')) { - $create_query .= ' DEFAULT CHARACTER SET ' - . substr($collation, 0, strpos($collation, '_')) - . ' COLLATE ' . $collation; - } else { - $create_query .= ' DEFAULT CHARACTER SET ' . $collation; - } - } - $create_query .= ';' . $crlf; - if (! PMA_exportOutputHandler($create_query)) { - return false; - } - if (isset($GLOBALS['sql_backquotes']) - && ((isset($GLOBALS['sql_compatibility']) - && $GLOBALS['sql_compatibility'] == 'NONE') - || PMA_DRIZZLE) - ) { - $result = PMA_exportOutputHandler( - 'USE ' . PMA_Util::backquoteCompat($db_alias, $compat) - . ';' . $crlf - ); - } else { - $result = PMA_exportOutputHandler('USE ' . $db_alias . ';' . $crlf); - } - return $result; - } else { + if (!isset($GLOBALS['sql_create_database'])) { return true; } + + $create_query = 'CREATE DATABASE IF NOT EXISTS ' + . (isset($GLOBALS['sql_backquotes']) + ? PMA_Util::backquoteCompat($db_alias, $compat) : $db_alias); + $collation = PMA_getDbCollation($db); + if (PMA_DRIZZLE) { + $create_query .= ' COLLATE ' . $collation; + } else { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + if ($pmaString->strpos($collation, '_')) { + $create_query .= ' DEFAULT CHARACTER SET ' + . $pmaString->substr( + $collation, + 0, + $pmaString->strpos($collation, '_') + ) + . ' COLLATE ' . $collation; + } else { + $create_query .= ' DEFAULT CHARACTER SET ' . $collation; + } + } + $create_query .= ';' . $crlf; + if (! PMA_exportOutputHandler($create_query)) { + return false; + } + if (isset($GLOBALS['sql_backquotes']) + && ((isset($GLOBALS['sql_compatibility']) + && $GLOBALS['sql_compatibility'] == 'NONE') + || PMA_DRIZZLE) + ) { + $result = PMA_exportOutputHandler( + 'USE ' . PMA_Util::backquoteCompat($db_alias, $compat) + . ';' . $crlf + ); + } else { + $result = PMA_exportOutputHandler('USE ' . $db_alias . ';' . $crlf); + } + return $result; } /** @@ -1219,17 +1226,20 @@ class ExportSql extends ExportPlugin return $this->_exportComment(__('in use') . '(' . $tmp_error . ')'); } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $warning = ''; if ($result != false && ($row = $GLOBALS['dbi']->fetchRow($result))) { $create_query = $row[1]; unset($row); // Convert end of line chars to one that we want (note that MySQL // doesn't return query it will accept in all cases) - if (strpos($create_query, "(\r\n ")) { + if ($pmaString->strpos($create_query, "(\r\n ")) { $create_query = str_replace("\r\n", $crlf, $create_query); - } elseif (strpos($create_query, "(\n ")) { + } elseif ($pmaString->strpos($create_query, "(\n ")) { $create_query = str_replace("\n", $crlf, $create_query); - } elseif (strpos($create_query, "(\r ")) { + } elseif ($pmaString->strpos($create_query, "(\r ")) { $create_query = str_replace("\r", $crlf, $create_query); } @@ -1443,9 +1453,9 @@ class ExportSql extends ExportPlugin $sql_lines[$k] )) { //adds auto increment value - $increment_value = substr( + $increment_value = $pmaString->substr( $sql_lines[$k], - strpos($sql_lines[$k], "AUTO_INCREMENT") + $pmaString->strpos($sql_lines[$k], "AUTO_INCREMENT") ); $increment_value_array = explode(' ', $increment_value); $sql_auto_increments .= $increment_value_array[0] . ";"; @@ -1454,7 +1464,7 @@ class ExportSql extends ExportPlugin } if ($sql_auto_increments != '') { - $sql_auto_increments = substr( + $sql_auto_increments = $pmaString->substr( $sql_auto_increments, 0, -1 ) . ';'; } @@ -1480,7 +1490,7 @@ class ExportSql extends ExportPlugin if (! $first) { $sql_constraints .= $crlf; } - if (strpos($sql_lines[$j], 'CONSTRAINT') === false) { + if ($pmaString->strpos($sql_lines[$j], 'CONSTRAINT') === false) { $tmp_str = preg_replace( '/(FOREIGN[\s]+KEY)/', 'ADD \1', @@ -1937,304 +1947,308 @@ class ExportSql extends ExportPlugin ); } - if ($result != false) { - $fields_cnt = $GLOBALS['dbi']->numFields($result); + if ($result == false) { + $GLOBALS['dbi']->freeResult($result); + return true; + } - // Get field information - $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result); - $field_flags = array(); - for ($j = 0; $j < $fields_cnt; $j++) { - $field_flags[$j] = $GLOBALS['dbi']->fieldFlags($result, $j); + $fields_cnt = $GLOBALS['dbi']->numFields($result); + + // Get field information + $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result); + $field_flags = array(); + for ($j = 0; $j < $fields_cnt; $j++) { + $field_flags[$j] = $GLOBALS['dbi']->fieldFlags($result, $j); + } + + $field_set = array(); + for ($j = 0; $j < $fields_cnt; $j++) { + $col_as = $fields_meta[$j]->name; + if (!empty($aliases[$db]['tables'][$table]['columns'][$col_as])) { + $col_as = $aliases[$db]['tables'][$table]['columns'][$col_as]; } + $field_set[$j] = PMA_Util::backquoteCompat( + $col_as, + $compat, + $sql_backquotes + ); + } - $field_set = array(); - for ($j = 0; $j < $fields_cnt; $j++) { - $col_as = $fields_meta[$j]->name; - if (!empty($aliases[$db]['tables'][$table]['columns'][$col_as])) { - $col_as = $aliases[$db]['tables'][$table]['columns'][$col_as]; - } - $field_set[$j] = PMA_Util::backquoteCompat( - $col_as, - $compat, - $sql_backquotes - ); + if (isset($GLOBALS['sql_type']) + && $GLOBALS['sql_type'] == 'UPDATE' + ) { + // update + $schema_insert = 'UPDATE '; + if (isset($GLOBALS['sql_ignore'])) { + $schema_insert .= 'IGNORE '; } - + // avoid EOL blank + $schema_insert .= PMA_Util::backquoteCompat( + $table_alias, + $compat, + $sql_backquotes + ) . ' SET'; + } else { + // insert or replace if (isset($GLOBALS['sql_type']) - && $GLOBALS['sql_type'] == 'UPDATE' + && $GLOBALS['sql_type'] == 'REPLACE' ) { - // update - $schema_insert = 'UPDATE '; - if (isset($GLOBALS['sql_ignore'])) { - $schema_insert .= 'IGNORE '; - } - // avoid EOL blank - $schema_insert .= PMA_Util::backquoteCompat( - $table_alias, - $compat, - $sql_backquotes - ) . ' SET'; + $sql_command = 'REPLACE'; } else { - // insert or replace - if (isset($GLOBALS['sql_type']) - && $GLOBALS['sql_type'] == 'REPLACE' - ) { - $sql_command = 'REPLACE'; - } else { - $sql_command = 'INSERT'; - } - - // delayed inserts? - if (isset($GLOBALS['sql_delayed'])) { - $insert_delayed = ' DELAYED'; - } else { - $insert_delayed = ''; - } - - // insert ignore? - if (isset($GLOBALS['sql_type']) - && $GLOBALS['sql_type'] == 'INSERT' - && isset($GLOBALS['sql_ignore']) - ) { - $insert_delayed .= ' IGNORE'; - } - //truncate table before insert - if (isset($GLOBALS['sql_truncate']) - && $GLOBALS['sql_truncate'] - && $sql_command == 'INSERT' - ) { - $truncate = 'TRUNCATE TABLE ' - . PMA_Util::backquoteCompat( - $table_alias, - $compat, - $sql_backquotes - ) . ";"; - $truncatehead = $this->_possibleCRLF() - . $this->_exportComment() - . $this->_exportComment( - __('Truncate table before insert') . ' ' - . $formatted_table_name - ) - . $this->_exportComment() - . $crlf; - PMA_exportOutputHandler($truncatehead); - PMA_exportOutputHandler($truncate); - } - - // scheme for inserting fields - if ($GLOBALS['sql_insert_syntax'] == 'complete' - || $GLOBALS['sql_insert_syntax'] == 'both' - ) { - $fields = implode(', ', $field_set); - $schema_insert = $sql_command . $insert_delayed . ' INTO ' - . PMA_Util::backquoteCompat( - $table_alias, - $compat, - $sql_backquotes - ) - // avoid EOL blank - . ' (' . $fields . ') VALUES'; - } else { - $schema_insert = $sql_command . $insert_delayed . ' INTO ' - . PMA_Util::backquoteCompat( - $table_alias, - $compat, - $sql_backquotes - ) - . ' VALUES'; - } + $sql_command = 'INSERT'; } - //\x08\\x09, not required - $search = array("\x00", "\x0a", "\x0d", "\x1a"); - $replace = array('\0', '\n', '\r', '\Z'); - $current_row = 0; - $query_size = 0; - if (($GLOBALS['sql_insert_syntax'] == 'extended' - || $GLOBALS['sql_insert_syntax'] == 'both') - && (! isset($GLOBALS['sql_type']) - || $GLOBALS['sql_type'] != 'UPDATE') - ) { - $separator = ','; - $schema_insert .= $crlf; + // delayed inserts? + if (isset($GLOBALS['sql_delayed'])) { + $insert_delayed = ' DELAYED'; } else { - $separator = ';'; + $insert_delayed = ''; } - while ($row = $GLOBALS['dbi']->fetchRow($result)) { - if ($current_row == 0) { - $head = $this->_possibleCRLF() - . $this->_exportComment() - . $this->_exportComment( - __('Dumping data for table') . ' ' - . $formatted_table_name - ) - . $this->_exportComment() - . $crlf; - if (! PMA_exportOutputHandler($head)) { - return false; - } + // insert ignore? + if (isset($GLOBALS['sql_type']) + && $GLOBALS['sql_type'] == 'INSERT' + && isset($GLOBALS['sql_ignore']) + ) { + $insert_delayed .= ' IGNORE'; + } + //truncate table before insert + if (isset($GLOBALS['sql_truncate']) + && $GLOBALS['sql_truncate'] + && $sql_command == 'INSERT' + ) { + $truncate = 'TRUNCATE TABLE ' + . PMA_Util::backquoteCompat( + $table_alias, + $compat, + $sql_backquotes + ) . ";"; + $truncatehead = $this->_possibleCRLF() + . $this->_exportComment() + . $this->_exportComment( + __('Truncate table before insert') . ' ' + . $formatted_table_name + ) + . $this->_exportComment() + . $crlf; + PMA_exportOutputHandler($truncatehead); + PMA_exportOutputHandler($truncate); + } + + // scheme for inserting fields + if ($GLOBALS['sql_insert_syntax'] == 'complete' + || $GLOBALS['sql_insert_syntax'] == 'both' + ) { + $fields = implode(', ', $field_set); + $schema_insert = $sql_command . $insert_delayed . ' INTO ' + . PMA_Util::backquoteCompat( + $table_alias, + $compat, + $sql_backquotes + ) + // avoid EOL blank + . ' (' . $fields . ') VALUES'; + } else { + $schema_insert = $sql_command . $insert_delayed . ' INTO ' + . PMA_Util::backquoteCompat( + $table_alias, + $compat, + $sql_backquotes + ) + . ' VALUES'; + } + } + + //\x08\\x09, not required + $search = array("\x00", "\x0a", "\x0d", "\x1a"); + $replace = array('\0', '\n', '\r', '\Z'); + $current_row = 0; + $query_size = 0; + if (($GLOBALS['sql_insert_syntax'] == 'extended' + || $GLOBALS['sql_insert_syntax'] == 'both') + && (! isset($GLOBALS['sql_type']) + || $GLOBALS['sql_type'] != 'UPDATE') + ) { + $separator = ','; + $schema_insert .= $crlf; + } else { + $separator = ';'; + } + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + while ($row = $GLOBALS['dbi']->fetchRow($result)) { + if ($current_row == 0) { + $head = $this->_possibleCRLF() + . $this->_exportComment() + . $this->_exportComment( + __('Dumping data for table') . ' ' + . $formatted_table_name + ) + . $this->_exportComment() + . $crlf; + if (! PMA_exportOutputHandler($head)) { + return false; } - // We need to SET IDENTITY_INSERT ON for MSSQL - if (isset($GLOBALS['sql_compatibility']) - && $GLOBALS['sql_compatibility'] == 'MSSQL' - && $current_row == 0 - ) { - if (! PMA_exportOutputHandler( - 'SET IDENTITY_INSERT ' - . PMA_Util::backquoteCompat( - $table_alias, - $compat - ) - . ' ON ;' . $crlf - )) { - return false; - } - } - $current_row++; - $values = array(); - for ($j = 0; $j < $fields_cnt; $j++) { - // NULL - if (! isset($row[$j]) || is_null($row[$j])) { - $values[] = 'NULL'; - } elseif ($fields_meta[$j]->numeric - && $fields_meta[$j]->type != 'timestamp' - && ! $fields_meta[$j]->blob - ) { - // a number - // timestamp is numeric on some MySQL 4.1, BLOBs are - // sometimes numeric - $values[] = $row[$j]; - } elseif (stristr($field_flags[$j], 'BINARY') !== false - && isset($GLOBALS['sql_hex_for_binary']) - ) { - // a true BLOB - // - mysqldump only generates hex data when the --hex-blob - // option is used, for fields having the binary attribute - // no hex is generated - // - a TEXT field returns type blob but a real blob - // returns also the 'binary' flag - - // empty blobs need to be different, but '0' is also empty - // :-( - if (empty($row[$j]) && $row[$j] != '0') { - $values[] = '\'\''; - } else { - $values[] = '0x' . bin2hex($row[$j]); - } - } elseif ($fields_meta[$j]->type == 'bit') { - // detection of 'bit' works only on mysqli extension - $values[] = "b'" . PMA_Util::sqlAddSlashes( - PMA_Util::printableBitValue( - $row[$j], $fields_meta[$j]->length - ) - ) - . "'"; - } else { - // something else -> treat as a string - $values[] = '\'' - . str_replace( - $search, $replace, - PMA_Util::sqlAddSlashes($row[$j]) - ) - . '\''; - } // end if - } // end for - - // should we make update? - if (isset($GLOBALS['sql_type']) - && $GLOBALS['sql_type'] == 'UPDATE' - ) { - - $insert_line = $schema_insert; - for ($i = 0; $i < $fields_cnt; $i++) { - if (0 == $i) { - $insert_line .= ' '; - } - if ($i > 0) { - // avoid EOL blank - $insert_line .= ','; - } - $insert_line .= $field_set[$i] . ' = ' . $values[$i]; - } - - list($tmp_unique_condition, $tmp_clause_is_unique) - = PMA_Util::getUniqueCondition( - $result, - $fields_cnt, - $fields_meta, - $row - ); - $insert_line .= ' WHERE ' . $tmp_unique_condition; - unset($tmp_unique_condition, $tmp_clause_is_unique); - - } else { - - // Extended inserts case - if ($GLOBALS['sql_insert_syntax'] == 'extended' - || $GLOBALS['sql_insert_syntax'] == 'both' - ) { - if ($current_row == 1) { - $insert_line = $schema_insert . '(' - . implode(', ', $values) . ')'; - } else { - $insert_line = '(' . implode(', ', $values) . ')'; - $sql_max_size = $GLOBALS['sql_max_query_size']; - if (isset($sql_max_size) - && $sql_max_size > 0 - && $query_size + strlen($insert_line) > $sql_max_size - ) { - if (! PMA_exportOutputHandler(';' . $crlf)) { - return false; - } - $query_size = 0; - $current_row = 1; - $insert_line = $schema_insert . $insert_line; - } - } - $query_size += strlen($insert_line); - // Other inserts case - } else { - $insert_line = $schema_insert - . '(' - . implode(', ', $values) - . ')'; - } - } - unset($values); - + } + // We need to SET IDENTITY_INSERT ON for MSSQL + if (isset($GLOBALS['sql_compatibility']) + && $GLOBALS['sql_compatibility'] == 'MSSQL' + && $current_row == 0 + ) { if (! PMA_exportOutputHandler( - ($current_row == 1 ? '' : $separator . $crlf) - . $insert_line + 'SET IDENTITY_INSERT ' + . PMA_Util::backquoteCompat( + $table_alias, + $compat + ) + . ' ON ;' . $crlf )) { return false; } - - } // end while - - if ($current_row > 0) { - if (! PMA_exportOutputHandler(';' . $crlf)) { - return false; - } } + $current_row++; + $values = array(); + for ($j = 0; $j < $fields_cnt; $j++) { + // NULL + if (! isset($row[$j]) || is_null($row[$j])) { + $values[] = 'NULL'; + } elseif ($fields_meta[$j]->numeric + && $fields_meta[$j]->type != 'timestamp' + && ! $fields_meta[$j]->blob + ) { + // a number + // timestamp is numeric on some MySQL 4.1, BLOBs are + // sometimes numeric + $values[] = $row[$j]; + } elseif (stristr($field_flags[$j], 'BINARY') !== false + && isset($GLOBALS['sql_hex_for_binary']) + ) { + // a true BLOB + // - mysqldump only generates hex data when the --hex-blob + // option is used, for fields having the binary attribute + // no hex is generated + // - a TEXT field returns type blob but a real blob + // returns also the 'binary' flag - // We need to SET IDENTITY_INSERT OFF for MSSQL - if (isset($GLOBALS['sql_compatibility']) - && $GLOBALS['sql_compatibility'] == 'MSSQL' - && $current_row > 0 + // empty blobs need to be different, but '0' is also empty + // :-( + if (empty($row[$j]) && $row[$j] != '0') { + $values[] = '\'\''; + } else { + $values[] = '0x' . bin2hex($row[$j]); + } + } elseif ($fields_meta[$j]->type == 'bit') { + // detection of 'bit' works only on mysqli extension + $values[] = "b'" . PMA_Util::sqlAddSlashes( + PMA_Util::printableBitValue( + $row[$j], $fields_meta[$j]->length + ) + ) + . "'"; + } else { + // something else -> treat as a string + $values[] = '\'' + . str_replace( + $search, $replace, + PMA_Util::sqlAddSlashes($row[$j]) + ) + . '\''; + } // end if + } // end for + + // should we make update? + if (isset($GLOBALS['sql_type']) + && $GLOBALS['sql_type'] == 'UPDATE' ) { - $outputSucceeded = PMA_exportOutputHandler( - $crlf . 'SET IDENTITY_INSERT ' - . PMA_Util::backquoteCompat($table_alias, $compat) - . ' OFF;' . $crlf - ); - if (! $outputSucceeded) { - return false; + + $insert_line = $schema_insert; + for ($i = 0; $i < $fields_cnt; $i++) { + if (0 == $i) { + $insert_line .= ' '; + } + if ($i > 0) { + // avoid EOL blank + $insert_line .= ','; + } + $insert_line .= $field_set[$i] . ' = ' . $values[$i]; + } + + list($tmp_unique_condition, $tmp_clause_is_unique) + = PMA_Util::getUniqueCondition( + $result, + $fields_cnt, + $fields_meta, + $row + ); + $insert_line .= ' WHERE ' . $tmp_unique_condition; + unset($tmp_unique_condition, $tmp_clause_is_unique); + + } else { + + // Extended inserts case + if ($GLOBALS['sql_insert_syntax'] == 'extended' + || $GLOBALS['sql_insert_syntax'] == 'both' + ) { + if ($current_row == 1) { + $insert_line = $schema_insert . '(' + . implode(', ', $values) . ')'; + } else { + $insert_line = '(' . implode(', ', $values) . ')'; + $insertLineSize = $pmaString->strlen($insert_line); + $sql_max_size = $GLOBALS['sql_max_query_size']; + if (isset($sql_max_size) + && $sql_max_size > 0 + && $query_size + $insertLineSize > $sql_max_size + ) { + if (! PMA_exportOutputHandler(';' . $crlf)) { + return false; + } + $query_size = 0; + $current_row = 1; + $insert_line = $schema_insert . $insert_line; + } + } + $query_size += $pmaString->strlen($insert_line); + // Other inserts case + } else { + $insert_line = $schema_insert + . '(' . implode(', ', $values) . ')'; } } - } // end if ($result != false) - $GLOBALS['dbi']->freeResult($result); + unset($values); + if (! PMA_exportOutputHandler( + ($current_row == 1 ? '' : $separator . $crlf) + . $insert_line + )) { + return false; + } + + } // end while + + if ($current_row > 0) { + if (! PMA_exportOutputHandler(';' . $crlf)) { + return false; + } + } + + // We need to SET IDENTITY_INSERT OFF for MSSQL + if (isset($GLOBALS['sql_compatibility']) + && $GLOBALS['sql_compatibility'] == 'MSSQL' + && $current_row > 0 + ) { + $outputSucceeded = PMA_exportOutputHandler( + $crlf . 'SET IDENTITY_INSERT ' + . PMA_Util::backquoteCompat($table_alias, $compat) + . ' OFF;' . $crlf + ); + if (! $outputSucceeded) { + return false; + } + } + + $GLOBALS['dbi']->freeResult($result); return true; } // end of the 'exportData()' function @@ -2395,6 +2409,10 @@ class ExportSql extends ExportPlugin $old_table = $table; $on_seen = false; $size = $tokens['len']; + + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + for ($i = 0; $i < $size && !$query_end; $i++) { $type = $tokens[$i]['type']; $data = $tokens[$i]['data']; @@ -2404,9 +2422,9 @@ class ExportSql extends ExportPlugin $d_unq = PMA_Util::unQuote($data); $d_unq_next = PMA_Util::unQuote($data_next); $d_unq_prev = PMA_Util::unQuote($data_prev); - $d_upper = strtoupper($d_unq); - $d_upper_next = strtoupper($d_unq_next); - $d_upper_prev = strtoupper($d_unq_prev); + $d_upper = $pmaString->strtoupper($d_unq); + $d_upper_next = $pmaString->strtoupper($d_unq_next); + $d_upper_prev = $pmaString->strtoupper($d_unq_prev); $pos = $tokens[$i]['pos'] + $offset; if ($type === 'alpha_reservedWord') { if ($query_type === '' diff --git a/libraries/plugins/export/ExportXml.class.php b/libraries/plugins/export/ExportXml.class.php index da7ced9ad2..527fd0627a 100644 --- a/libraries/plugins/export/ExportXml.class.php +++ b/libraries/plugins/export/ExportXml.class.php @@ -9,7 +9,7 @@ if (! defined('PHPMYADMIN')) { exit; } -if (! strlen($GLOBALS['db'])) { /* Can't do server export */ +if (!$GLOBALS['PMA_String']->strlen($GLOBALS['db'])) { /* Can't do server export */ $GLOBALS['skip_import'] = true; return; } @@ -270,7 +270,8 @@ class ExportXml extends ExportPlugin . $trigger['name'] . '">' . $crlf; // Do some formatting - $code = substr(rtrim($code), 0, -3); + $code = $GLOBALS['PMA_String'] + ->substr(rtrim($code), 0, -3); $code = " " . htmlspecialchars($code); $code = str_replace("\n", "\n ", $code); diff --git a/libraries/plugins/export/TableProperty.class.php b/libraries/plugins/export/TableProperty.class.php index 4affb7c0d5..3ff5780058 100644 --- a/libraries/plugins/export/TableProperty.class.php +++ b/libraries/plugins/export/TableProperty.class.php @@ -82,9 +82,11 @@ class TableProperty */ function getPureType() { - $pos = strpos($this->type, "("); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $pos = $pmaString->strpos($this->type, "("); if ($pos > 0) { - return substr($this->type, 0, $pos); + return $pmaString->substr($this->type, 0, $pos); } return $this->type; } @@ -116,28 +118,30 @@ class TableProperty */ function getDotNetPrimitiveType() { - if (strpos($this->type, "int") === 0) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if ($pmaString->strpos($this->type, "int") === 0) { return "int"; } - if (strpos($this->type, "longtext") === 0) { + if ($pmaString->strpos($this->type, "longtext") === 0) { return "string"; } - if (strpos($this->type, "long") === 0) { + if ($pmaString->strpos($this->type, "long") === 0) { return "long"; } - if (strpos($this->type, "char") === 0) { + if ($pmaString->strpos($this->type, "char") === 0) { return "string"; } - if (strpos($this->type, "varchar") === 0) { + if ($pmaString->strpos($this->type, "varchar") === 0) { return "string"; } - if (strpos($this->type, "text") === 0) { + if ($pmaString->strpos($this->type, "text") === 0) { return "string"; } - if (strpos($this->type, "tinyint") === 0) { + if ($pmaString->strpos($this->type, "tinyint") === 0) { return "bool"; } - if (strpos($this->type, "datetime") === 0) { + if ($pmaString->strpos($this->type, "datetime") === 0) { return "DateTime"; } return "unknown"; @@ -150,28 +154,30 @@ class TableProperty */ function getDotNetObjectType() { - if (strpos($this->type, "int") === 0) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if ($pmaString->strpos($this->type, "int") === 0) { return "Int32"; } - if (strpos($this->type, "longtext") === 0) { + if ($pmaString->strpos($this->type, "longtext") === 0) { return "String"; } - if (strpos($this->type, "long") === 0) { + if ($pmaString->strpos($this->type, "long") === 0) { return "Long"; } - if (strpos($this->type, "char") === 0) { + if ($pmaString->strpos($this->type, "char") === 0) { return "String"; } - if (strpos($this->type, "varchar") === 0) { + if ($pmaString->strpos($this->type, "varchar") === 0) { return "String"; } - if (strpos($this->type, "text") === 0) { + if ($pmaString->strpos($this->type, "text") === 0) { return "String"; } - if (strpos($this->type, "tinyint") === 0) { + if ($pmaString->strpos($this->type, "tinyint") === 0) { return "Boolean"; } - if (strpos($this->type, "datetime") === 0) { + if ($pmaString->strpos($this->type, "datetime") === 0) { return "DateTime"; } return "Unknown"; @@ -184,7 +190,7 @@ class TableProperty */ function getIndexName() { - if (strlen($this->key) > 0) { + if ($GLOBALS['PMA_String']->strlen($this->key) > 0) { return "index=\"" . htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8') . "\""; diff --git a/libraries/plugins/import/ImportCsv.class.php b/libraries/plugins/import/ImportCsv.class.php index 05f53420ce..4e65d42943 100644 --- a/libraries/plugins/import/ImportCsv.class.php +++ b/libraries/plugins/import/ImportCsv.class.php @@ -104,6 +104,9 @@ class ImportCsv extends AbstractImportCsv // but we use directly from $_POST global $error, $timeout_passed, $finished, $message; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $replacements = array( '\\n' => "\n", '\\t' => "\t", @@ -115,7 +118,7 @@ class ImportCsv extends AbstractImportCsv $csv_new_line = strtr($csv_new_line, $replacements); $param_error = false; - if (strlen($csv_terminated) < 1) { + if ($pmaString->strlen($csv_terminated) < 1) { $message = PMA_Message::error( __('Invalid parameter for CSV import: %s') ); @@ -130,21 +133,23 @@ class ImportCsv extends AbstractImportCsv // confuses this script. // But the parser won't work correctly with strings so we allow just // one character. - } elseif (strlen($csv_enclosed) > 1) { + } elseif ($pmaString->strlen($csv_enclosed) > 1) { $message = PMA_Message::error( __('Invalid parameter for CSV import: %s') ); $message->addParam(__('Columns enclosed with'), false); $error = true; $param_error = true; - } elseif (strlen($csv_escaped) != 1) { + } elseif ($pmaString->strlen($csv_escaped) != 1) { $message = PMA_Message::error( __('Invalid parameter for CSV import: %s') ); $message->addParam(__('Columns escaped with'), false); $error = true; $param_error = true; - } elseif (strlen($csv_new_line) != 1 && $csv_new_line != 'auto') { + } elseif ($pmaString->strlen($csv_new_line) != 1 + && $csv_new_line != 'auto' + ) { $message = PMA_Message::error( __('Invalid parameter for CSV import: %s') ); @@ -233,7 +238,7 @@ class ImportCsv extends AbstractImportCsv $col_count = 0; $max_cols = 0; - $csv_terminated_len = strlen($csv_terminated); + $csv_terminated_len = $pmaString->strlen($csv_terminated); while (! ($finished && $i >= $len) && ! $error && ! $timeout_passed) { $data = PMA_importGetNextChunk(); if ($data === false) { @@ -249,7 +254,7 @@ class ImportCsv extends AbstractImportCsv // Force a trailing new line at EOF to prevent parsing problems if ($finished && $buffer) { - $finalch = substr($buffer, -1); + $finalch = $pmaString->substr($buffer, -1); if ($csv_new_line == 'auto' && $finalch != "\r" && $finalch != "\n" @@ -265,17 +270,17 @@ class ImportCsv extends AbstractImportCsv // Do not parse string when we're not at the end // and don't have new line inside if (($csv_new_line == 'auto' - && strpos($buffer, "\r") === false - && strpos($buffer, "\n") === false) + && $pmaString->strpos($buffer, "\r") === false + && $pmaString->strpos($buffer, "\n") === false) || ($csv_new_line != 'auto' - && strpos($buffer, $csv_new_line) === false) + && $pmaString->strpos($buffer, $csv_new_line) === false) ) { continue; } } // Current length of our buffer - $len = strlen($buffer); + $len = $pmaString->strlen($buffer); // Currently parsed char $ch = $buffer[$i]; if ($csv_terminated_len > 1 && $ch == $csv_terminated[0]) { @@ -548,8 +553,8 @@ class ImportCsv extends AbstractImportCsv $line++; $csv_finish = false; $values = array(); - $buffer = substr($buffer, $i + 1); - $len = strlen($buffer); + $buffer = $pmaString->substr($buffer, $i + 1); + $len = $pmaString->strlen($buffer); $i = 0; $lasti = -1; $ch = $buffer[0]; @@ -584,7 +589,7 @@ class ImportCsv extends AbstractImportCsv } } - if (strlen($db)) { + if ($pmaString->strlen($db)) { $result = $GLOBALS['dbi']->fetchResult('SHOW TABLES'); $tbl_name = 'TABLE ' . (count($result) + 1); } else { @@ -612,7 +617,7 @@ class ImportCsv extends AbstractImportCsv */ /* Set database name to the currently selected one, if applicable */ - if (strlen($db)) { + if ($pmaString->strlen($db)) { $db_name = $db; $options = array('create_db' => false); } else { diff --git a/libraries/plugins/import/ImportMediawiki.class.php b/libraries/plugins/import/ImportMediawiki.class.php index 20d274859e..bd15d161c9 100644 --- a/libraries/plugins/import/ImportMediawiki.class.php +++ b/libraries/plugins/import/ImportMediawiki.class.php @@ -93,12 +93,15 @@ class ImportMediawiki extends ImportPlugin // Initialize the name of the current table $cur_table_name = ""; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + while (! $finished && ! $error && ! $timeout_passed ) { $data = PMA_importGetNextChunk(); if ($data === false) { // Subtract data we didn't handle yet and stop processing - $GLOBALS['offset'] -= strlen($buffer); + $GLOBALS['offset'] -= $pmaString->strlen($buffer); break; } elseif ($data === true) { // Handle rest of buffer @@ -108,7 +111,7 @@ class ImportMediawiki extends ImportPlugin unset($data); // Don't parse string if we're not at the end // and don't have a new line inside - if ( strpos($buffer, $mediawiki_new_line) === false ) { + if ($pmaString->strpos($buffer, $mediawiki_new_line) === false ) { continue; } } @@ -141,13 +144,13 @@ class ImportMediawiki extends ImportPlugin $first_character = $cur_buffer_line[0]; $matches = array(); - // Check beginnning of comment - if (! strcmp(substr($cur_buffer_line, 0, 4), "")) { + if (!strcmp($pmaString->substr($cur_buffer_line, 0, 4), "-->")) { // Only data comments are closed. The structure comments // will be closed when a data comment begins (in order to // skip structure tables) @@ -203,9 +206,9 @@ class ImportMediawiki extends ImportPlugin $in_table_header = false; // End processing because the current line does not // contain any column information - } elseif (substr($cur_buffer_line, 0, 2) === '|-' - || substr($cur_buffer_line, 0, 2) === '|+' - || substr($cur_buffer_line, 0, 2) === '|}' + } elseif ($pmaString->substr($cur_buffer_line, 0, 2) === '|-' + || $pmaString->substr($cur_buffer_line, 0, 2) === '|+' + || $pmaString->substr($cur_buffer_line, 0, 2) === '|}' ) { // Check begin row or end table @@ -227,7 +230,7 @@ class ImportMediawiki extends ImportPlugin $cur_temp_line = array(); // No more processing required at the end of the table - if (substr($cur_buffer_line, 0, 2) === '|}') { + if ($pmaString->substr($cur_buffer_line, 0, 2) === '|}') { $current_table = array( $cur_table_name, $cur_temp_table_headers, @@ -263,7 +266,7 @@ class ImportMediawiki extends ImportPlugin // A '|' inside an invalid link should not // be mistaken as delimiting cell parameters - if (strpos($cell_data[0], '[[') === true ) { + if ($pmaString->strpos($cell_data[0], '[[') === true ) { if (count($cell_data) == 1) { $cell = $cell_data[0]; } else { @@ -275,8 +278,8 @@ class ImportMediawiki extends ImportPlugin $cell = trim($cell); $col_start_chars = array( "|", "!"); foreach ($col_start_chars as $col_start_char) { - if (strpos($cell, $col_start_char) === 0) { - $cell = trim(substr($cell, 1)); + if ($pmaString->strpos($cell, $col_start_char) === 0) { + $cell = trim($pmaString->substr($cell, 1)); } } diff --git a/libraries/plugins/import/ImportShp.class.php b/libraries/plugins/import/ImportShp.class.php index 89dba9d2d7..c4601decdd 100644 --- a/libraries/plugins/import/ImportShp.class.php +++ b/libraries/plugins/import/ImportShp.class.php @@ -69,6 +69,9 @@ class ImportShp extends ImportPlugin global $db, $error, $finished, $compression, $import_file, $local_import_file, $message; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $GLOBALS['finished'] = false; $shp = new PMA_ShapeFile(1); @@ -107,8 +110,8 @@ class ImportShp extends ImportPlugin $temp_dbf_file = true; // Replace the .dbf with .*, as required // by the bsShapeFiles library. - $file_name = substr( - $dbf_file_path, 0, strlen($dbf_file_path) - 4 + $file_name = $pmaString->substr( + $dbf_file_path, 0, $pmaString->strlen($dbf_file_path) - 4 ) . '.*'; $shp->FileName = $file_name; } @@ -121,8 +124,11 @@ class ImportShp extends ImportPlugin // to load extra data. // Replace the .shp with .*, // so the bsShapeFiles library correctly locates .dbf file. - $file_name = substr($import_file, 0, strlen($import_file) - 4) - . '.*'; + $file_name = $pmaString->substr( + $import_file, + 0, + $pmaString->strlen($import_file) - 4 + ) . '.*'; $shp->FileName = $file_name; } } @@ -255,7 +261,7 @@ class ImportShp extends ImportPlugin } // Set table name based on the number of tables - if (strlen($db)) { + if ($pmaString->strlen($db)) { $result = $GLOBALS['dbi']->fetchResult('SHOW TABLES'); $table_name = 'TABLE ' . (count($result) + 1); } else { @@ -272,7 +278,7 @@ class ImportShp extends ImportPlugin $analyses[$table_no][FORMATTEDSQL][$spatial_col] = true; // Set database name to the currently selected one, if applicable - if (strlen($db)) { + if ($pmaString->strlen($db)) { $db_name = $db; $options = array('create_db' => false); } else { diff --git a/libraries/plugins/import/ImportSql.class.php b/libraries/plugins/import/ImportSql.class.php index 79423e7482..351cb9f9f6 100644 --- a/libraries/plugins/import/ImportSql.class.php +++ b/libraries/plugins/import/ImportSql.class.php @@ -111,6 +111,9 @@ class ImportSql extends ImportPlugin { global $error, $timeout_passed; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $buffer = ''; // Defaults for parser $sql = ''; @@ -120,7 +123,7 @@ class ImportSql extends ImportPlugin $big_value = 2147483647; // include the space because it's mandatory $delimiter_keyword = 'DELIMITER '; - $length_of_delimiter_keyword = strlen($delimiter_keyword); + $length_of_delimiter_keyword = $pmaString->strlen($delimiter_keyword); if (isset($_POST['sql_delimiter'])) { $sql_delimiter = $_POST['sql_delimiter']; @@ -159,7 +162,7 @@ class ImportSql extends ImportPlugin $data = PMA_importGetNextChunk(); if ($data === false) { // subtract data we didn't handle yet and stop processing - $GLOBALS['offset'] -= strlen($buffer); + $GLOBALS['offset'] -= $pmaString->strlen($buffer); break; } elseif ($data === true) { // Handle rest of buffer @@ -170,7 +173,7 @@ class ImportSql extends ImportPlugin unset($data); // Do not parse string when we're not at the end // and don't have ; inside - if ((strpos($buffer, $sql_delimiter, $i) === false) + if (($pmaString->strpos($buffer, $sql_delimiter, $i) === false) && ! $GLOBALS['finished'] ) { continue; @@ -182,7 +185,7 @@ class ImportSql extends ImportPlugin $buffer = preg_replace("/\r($|[^\n])/", "\n$1", $buffer); // Current length of our buffer - $len = strlen($buffer); + $len = $pmaString->strlen($buffer); // Grab some SQL queries out of it while ($i < $len) { @@ -211,7 +214,11 @@ class ImportSql extends ImportPlugin * inside quotes (or even double-quotes) */ // the cost of doing this one with preg_match() would be too high - $first_sql_delimiter = strpos($buffer, $sql_delimiter, $i); + $first_sql_delimiter = $pmaString->strpos( + $buffer, + $sql_delimiter, + $i + ); if ($first_sql_delimiter === false) { $first_sql_delimiter = $big_value; } else { @@ -236,19 +243,19 @@ class ImportSql extends ImportPlugin break; } // We hit end of query, go there! - $i = strlen($buffer) - 1; + $i = $pmaString->strlen($buffer) - 1; } // Grab current character $ch = $buffer[$i]; // Quotes - if (strpos('\'"`', $ch) !== false) { + if ($pmaString->strpos('\'"`', $ch) !== false) { $quote = $ch; $endq = false; while (! $endq) { // Find next quote - $pos = strpos($buffer, $quote, $i + 1); + $pos = $pmaString->strpos($buffer, $quote, $i + 1); /* * Behave same as MySQL and accept end of query as end * of backtick. @@ -314,13 +321,17 @@ class ImportSql extends ImportPlugin ) { // Copy current string to SQL if ($start_pos != $i) { - $sql .= substr($buffer, $start_pos, $i - $start_pos); + $sql .= $pmaString->substr( + $buffer, + $start_pos, + $i - $start_pos + ); } // Skip the rest $start_of_comment = $i; // do not use PHP_EOL here instead of "\n", because the export // file might have been produced on a different system - $i = strpos($buffer, $ch == '/' ? '*/' : "\n", $i); + $i = $pmaString->strpos($buffer, $ch == '/' ? '*/' : "\n", $i); // didn't we hit end of string? if ($i === false) { if ($GLOBALS['finished']) { @@ -337,7 +348,7 @@ class ImportSql extends ImportPlugin $i++; // We need to send the comment part in case we are defining // a procedure or function and comments in it are valuable - $sql .= substr( + $sql .= $pmaString->substr( $buffer, $start_of_comment, $i - $start_of_comment @@ -354,13 +365,13 @@ class ImportSql extends ImportPlugin // Change delimiter, if redefined, and skip it // (don't send to server!) if (($i + $length_of_delimiter_keyword < $len) - && strtoupper( - substr($buffer, $i, $length_of_delimiter_keyword) + && $pmaString->strtoupper( + $pmaString->substr($buffer, $i, $length_of_delimiter_keyword) ) == $delimiter_keyword ) { // look for EOL on the character immediately after 'DELIMITER ' // (see previous comment about PHP_EOL) - $new_line_pos = strpos( + $new_line_pos = $pmaString->strpos( $buffer, "\n", $i + $length_of_delimiter_keyword @@ -369,7 +380,7 @@ class ImportSql extends ImportPlugin if (false === $new_line_pos) { $new_line_pos = $len; } - $sql_delimiter = substr( + $sql_delimiter = $pmaString->substr( $buffer, $i + $length_of_delimiter_keyword, $new_line_pos - $i - $length_of_delimiter_keyword @@ -392,7 +403,11 @@ class ImportSql extends ImportPlugin if (! $found_delimiter) { $length_to_grab++; } - $tmp_sql .= substr($buffer, $start_pos, $length_to_grab); + $tmp_sql .= $pmaString->substr( + $buffer, + $start_pos, + $length_to_grab + ); unset($length_to_grab); } // Do not try to execute empty SQL @@ -400,20 +415,27 @@ class ImportSql extends ImportPlugin $sql = $tmp_sql; PMA_importRunQuery( $sql, - substr($buffer, 0, $i + strlen($sql_delimiter)), + $pmaString->substr( + $buffer, + 0, + $i + $pmaString->strlen($sql_delimiter) + ), false, $sql_data ); - $buffer = substr($buffer, $i + strlen($sql_delimiter)); + $buffer = $pmaString->substr( + $buffer, + $i + $pmaString->strlen($sql_delimiter) + ); // Reset parser: - $len = strlen($buffer); + $len = $pmaString->strlen($buffer); $sql = ''; $i = 0; $start_pos = 0; // Any chance we will get a complete query? //if ((strpos($buffer, ';') === false) //&& ! $GLOBALS['finished']) { - if (strpos($buffer, $sql_delimiter) === false + if ($pmaString->strpos($buffer, $sql_delimiter) === false && ! $GLOBALS['finished'] ) { break; @@ -426,7 +448,12 @@ class ImportSql extends ImportPlugin } // End of parser loop } // End of import loop // Commit any possible data in buffers - PMA_importRunQuery('', substr($buffer, 0, $len), false, $sql_data); + PMA_importRunQuery( + '', + $pmaString->substr($buffer, 0, $len), + false, + $sql_data + ); PMA_importRunQuery('', '', false, $sql_data); } diff --git a/libraries/plugins/schema/dia/Dia_Relation_Schema.class.php b/libraries/plugins/schema/dia/Dia_Relation_Schema.class.php index 3e078061f8..29358e6845 100644 --- a/libraries/plugins/schema/dia/Dia_Relation_Schema.class.php +++ b/libraries/plugins/schema/dia/Dia_Relation_Schema.class.php @@ -176,7 +176,9 @@ class PMA_DIA extends XMLWriter $output = $this->flush(); PMA_Response::getInstance()->disable(); PMA_downloadHeader( - $fileName . '.dia', 'application/x-dia-diagram', strlen($output) + $fileName . '.dia', + 'application/x-dia-diagram', + $GLOBALS['PMA_String']->strlen($output) ); print $output; } diff --git a/libraries/plugins/schema/eps/Eps_Relation_Schema.class.php b/libraries/plugins/schema/eps/Eps_Relation_Schema.class.php index 30b7f17c6e..0f42eb8310 100644 --- a/libraries/plugins/schema/eps/Eps_Relation_Schema.class.php +++ b/libraries/plugins/schema/eps/Eps_Relation_Schema.class.php @@ -294,7 +294,11 @@ class PMA_EPS //} $output = $this->stringCommands; PMA_Response::getInstance()->disable(); - PMA_downloadHeader($fileName . '.eps', 'image/x-eps', strlen($output)); + PMA_downloadHeader( + $fileName . '.eps', + 'image/x-eps', + $GLOBALS['PMA_String']->strlen($output) + ); print $output; } } diff --git a/libraries/plugins/schema/pdf/Pdf_Relation_Schema.class.php b/libraries/plugins/schema/pdf/Pdf_Relation_Schema.class.php index ae2418fc20..dfba41beee 100644 --- a/libraries/plugins/schema/pdf/Pdf_Relation_Schema.class.php +++ b/libraries/plugins/schema/pdf/Pdf_Relation_Schema.class.php @@ -345,13 +345,16 @@ class PMA_Schema_PDF extends PMA_PDF */ function NbLines($w, $txt) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $cw = &$this->CurrentFont['cw']; if ($w == 0) { $w = $this->w - $this->rMargin - $this->x; } $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize; $s = str_replace("\r", '', $txt); - $nb = strlen($s); + $nb = $pmaString->strlen($s); if ($nb > 0 and $s[$nb-1] == "\n") { $nb--; } @@ -373,7 +376,7 @@ class PMA_Schema_PDF extends PMA_PDF if ($c == ' ') { $sep = $i; } - $l += isset($cw[ord($c)])?$cw[ord($c)]:0 ; + $l += isset($cw[$pmaString->ord($c)])?$cw[$pmaString->ord($c)]:0 ; if ($l > $wmax) { if ($sep == -1) { if ($i == $j) { diff --git a/libraries/plugins/schema/svg/Svg_Relation_Schema.class.php b/libraries/plugins/schema/svg/Svg_Relation_Schema.class.php index 725fbda794..1b8865bfa2 100644 --- a/libraries/plugins/schema/svg/Svg_Relation_Schema.class.php +++ b/libraries/plugins/schema/svg/Svg_Relation_Schema.class.php @@ -187,7 +187,11 @@ class PMA_SVG extends XMLWriter //ob_get_clean(); $output = $this->flush(); PMA_Response::getInstance()->disable(); - PMA_downloadHeader($fileName . '.svg', 'image/svg+xml', strlen($output)); + PMA_downloadHeader( + $fileName . '.svg', + 'image/svg+xml', + $GLOBALS['PMA_String']->strlen($output) + ); print $output; } diff --git a/libraries/plugins/transformations/abstract/DateFormatTransformationsPlugin.class.php b/libraries/plugins/transformations/abstract/DateFormatTransformationsPlugin.class.php index bc4c822ed7..719c6ff761 100644 --- a/libraries/plugins/transformations/abstract/DateFormatTransformationsPlugin.class.php +++ b/libraries/plugins/transformations/abstract/DateFormatTransformationsPlugin.class.php @@ -58,10 +58,13 @@ abstract class DateFormatTransformationsPlugin extends TransformationsPlugin $options[0] = 0; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if (empty($options[2])) { $options[2] = 'local'; } else { - $options[2] = strtolower($options[2]); + $options[2] = $pmaString->strtolower($options[2]); } if (empty($options[1])) { @@ -86,28 +89,30 @@ abstract class DateFormatTransformationsPlugin extends TransformationsPlugin // for example TIMESTAMP(8) means YYYYMMDD) } else if (preg_match('/^(\d{2}){3,7}$/', $buffer)) { - if (strlen($buffer) == 14 || strlen($buffer) == 8) { + if ($pmaString->strlen($buffer) == 14 + || $pmaString->strlen($buffer) == 8 + ) { $offset = 4; } else { $offset = 2; } - $d = array(); - $d['year'] = substr($buffer, 0, $offset); - $d['month'] = substr($buffer, $offset, 2); - $d['day'] = substr($buffer, $offset + 2, 2); - $d['hour'] = substr($buffer, $offset + 4, 2); - $d['minute'] = substr($buffer, $offset + 6, 2); - $d['second'] = substr($buffer, $offset + 8, 2); + $aDate = array(); + $aDate['year'] = $pmaString->substr($buffer, 0, $offset); + $aDate['month'] = $pmaString->substr($buffer, $offset, 2); + $aDate['day'] = $pmaString->substr($buffer, $offset + 2, 2); + $aDate['hour'] = $pmaString->substr($buffer, $offset + 4, 2); + $aDate['minute'] = $pmaString->substr($buffer, $offset + 6, 2); + $aDate['second'] = $pmaString->substr($buffer, $offset + 8, 2); - if (checkdate($d['month'], $d['day'], $d['year'])) { + if (checkdate($aDate['month'], $aDate['day'], $aDate['year'])) { $timestamp = mktime( - $d['hour'], - $d['minute'], - $d['second'], - $d['month'], - $d['day'], - $d['year'] + $aDate['hour'], + $aDate['minute'], + $aDate['second'], + $aDate['month'], + $aDate['day'], + $aDate['year'] ); } // If all fails, assume one of the dozens of valid strtime() syntaxes diff --git a/libraries/plugins/transformations/abstract/SubstringTransformationsPlugin.class.php b/libraries/plugins/transformations/abstract/SubstringTransformationsPlugin.class.php index 32af2649fd..33a4f4ee17 100644 --- a/libraries/plugins/transformations/abstract/SubstringTransformationsPlugin.class.php +++ b/libraries/plugins/transformations/abstract/SubstringTransformationsPlugin.class.php @@ -52,16 +52,18 @@ abstract class SubstringTransformationsPlugin extends TransformationsPlugin // further operations on $buffer using the $options[] array. $options = $this->getOptions($options, array(0, 'all', '…')); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; if ($options[1] != 'all') { - $newtext = $GLOBALS['PMA_String']->substr( + $newtext = $pmaString->substr( $buffer, $options[0], $options[1] ); } else { - $newtext = $GLOBALS['PMA_String']->substr($buffer, $options[0]); + $newtext = $pmaString->substr($buffer, $options[0]); } - $length = strlen($newtext); - $baselength = strlen($buffer); + $length = $pmaString->strlen($newtext); + $baselength = $pmaString->strlen($buffer); if ($length != $baselength) { if ($options[0] != 0) { $newtext = $options[2] . $newtext; diff --git a/libraries/pmd_common.php b/libraries/pmd_common.php index 5552ab8d80..cb094c2edc 100644 --- a/libraries/pmd_common.php +++ b/libraries/pmd_common.php @@ -55,7 +55,9 @@ function PMA_getTablesInfo() $one_table['TABLE_NAME'], ENT_QUOTES ); - $GLOBALS['PMD']['TABLE_TYPE'][$i] = strtoupper($one_table['ENGINE']); + $GLOBALS['PMD']['TABLE_TYPE'][$i] = $GLOBALS['PMA_String']->strtoupper( + $one_table['ENGINE'] + ); $DF = PMA_getDisplayField($GLOBALS['db'], $one_table['TABLE_NAME']); if ($DF != '') { @@ -469,10 +471,13 @@ function PMA_saveDisplayField($db, $table, $field) */ function PMA_addNewRelation($db, $T1, $F1, $T2, $F2, $on_delete, $on_update) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $tables = $GLOBALS['dbi']->getTablesFull($db, $T1); - $type_T1 = strtoupper($tables[$T1]['ENGINE']); + $type_T1 = $pmaString->strtoupper($tables[$T1]['ENGINE']); $tables = $GLOBALS['dbi']->getTablesFull($db, $T2); - $type_T2 = strtoupper($tables[$T2]['ENGINE']); + $type_T2 = $pmaString->strtoupper($tables[$T2]['ENGINE']); // native foreign key if (PMA_Util::isForeignKeySupported($type_T1) @@ -576,13 +581,16 @@ function PMA_addNewRelation($db, $T1, $F1, $T2, $F2, $on_delete, $on_update) */ function PMA_removeRelation($T1, $F1, $T2, $F2) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + list($DB1, $T1) = explode(".", $T1); list($DB2, $T2) = explode(".", $T2); $tables = $GLOBALS['dbi']->getTablesFull($DB1, $T1); - $type_T1 = strtoupper($tables[$T1]['ENGINE']); + $type_T1 = $pmaString->strtoupper($tables[$T1]['ENGINE']); $tables = $GLOBALS['dbi']->getTablesFull($DB2, $T2); - $type_T2 = strtoupper($tables[$T2]['ENGINE']); + $type_T2 = $pmaString->strtoupper($tables[$T2]['ENGINE']); $try_to_delete_internal_relation = false; diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php index 78d76a230d..f96e167fde 100644 --- a/libraries/relation.lib.php +++ b/libraries/relation.lib.php @@ -646,6 +646,9 @@ function PMA_getForeigners($db, $table, $column = '', $source = 'both') $cfgRelation = PMA_getRelationsParam(); $foreign = array(); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if ($cfgRelation['relwork'] && ($source == 'both' || $source == 'internal')) { $rel_query = ' SELECT `master_field`, @@ -656,7 +659,7 @@ function PMA_getForeigners($db, $table, $column = '', $source = 'both') . '.' . PMA_Util::backquote($cfgRelation['relation']) . ' WHERE `master_db` = \'' . PMA_Util::sqlAddSlashes($db) . '\' AND `master_table` = \'' . PMA_Util::sqlAddSlashes($table) . '\' '; - if (strlen($column)) { + if ($pmaString->strlen($column)) { $rel_query .= ' AND `master_field` = ' . '\'' . PMA_Util::sqlAddSlashes($column) . '\''; } @@ -665,7 +668,7 @@ function PMA_getForeigners($db, $table, $column = '', $source = 'both') ); } - if (($source == 'both' || $source == 'foreign') && strlen($table)) { + if (($source == 'both' || $source == 'foreign') && $pmaString->strlen($table)) { $showCreateTableQuery = 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table); @@ -680,8 +683,9 @@ function PMA_getForeigners($db, $table, $column = '', $source = 'both') /** * Emulating relations for some information_schema and data_dictionary tables */ - $isInformationSchema = strtolower($db) == 'information_schema'; - $is_data_dictionary = PMA_DRIZZLE && strtolower($db) == 'data_dictionary'; + $isInformationSchema = $pmaString->strtolower($db) == 'information_schema'; + $is_data_dictionary = PMA_DRIZZLE + && $pmaString->strtolower($db) == 'data_dictionary'; if (($isInformationSchema || $is_data_dictionary) && ($source == 'internal' || $source == 'both') ) { @@ -694,8 +698,9 @@ function PMA_getForeigners($db, $table, $column = '', $source = 'both') } if (isset($GLOBALS[$relations_key][$table])) { foreach ($GLOBALS[$relations_key][$table] as $field => $relations) { - if ((! strlen($column) || $column == $field) - && (! isset($foreign[$field]) || ! strlen($foreign[$field])) + if ((! $pmaString->strlen($column) || $column == $field) + && (! isset($foreign[$field]) + || ! $pmaString->strlen($foreign[$field])) ) { $foreign[$field] = $relations; } @@ -878,7 +883,7 @@ function PMA_setDbComment($db, $comment = '') return false; } - if (strlen($comment)) { + if ($GLOBALS['PMA_String']->strlen($comment)) { $upd_query = 'INSERT INTO ' . PMA_Util::backquote($cfgRelation['db']) . '.' . PMA_Util::backquote($cfgRelation['column_info']) @@ -920,9 +925,10 @@ function PMA_setDbComment($db, $comment = '') */ function PMA_setHistory($db, $table, $username, $sqlquery) { + $maxCharactersInDisplayedSQL = $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']; // Prevent to run this automatically on Footer class destroying in testsuite if (defined('TESTSUITE') - || strlen($sqlquery) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] + || $GLOBALS['PMA_String']->strlen($sqlquery) > $maxCharactersInDisplayedSQL ) { return; } @@ -1094,7 +1100,9 @@ function PMA_buildForeignDropdown($foreign, $data, $mode) } else { $vtitle = htmlspecialchars($value); $value = htmlspecialchars( - substr($value, 0, $GLOBALS['cfg']['LimitChars']) . '...' + $GLOBALS['PMA_String']->substr( + $value, 0, $GLOBALS['cfg']['LimitChars'] + ) . '...' ); } diff --git a/libraries/replication.inc.php b/libraries/replication.inc.php index d1b14e6179..593ec12d5b 100644 --- a/libraries/replication.inc.php +++ b/libraries/replication.inc.php @@ -191,8 +191,11 @@ function PMA_extractDbOrTable($string, $what = 'db') */ function PMA_Replication_Slave_control($action, $control = null, $link = null) { - $action = strtoupper($action); - $control = strtoupper($control); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + $action = $pmaString->strtoupper($action); + $control = $pmaString->strtoupper($control); if ($action != "START" && $action != "STOP") { return -1; diff --git a/libraries/replication_gui.lib.php b/libraries/replication_gui.lib.php index 684521c550..e260a58230 100644 --- a/libraries/replication_gui.lib.php +++ b/libraries/replication_gui.lib.php @@ -659,7 +659,12 @@ function PMA_getHtmlForReplicationMasterAddSlaveuser() list($username_length, $hostname_length) = PMA_replicationGetUsernameHostnameLength(); - if (isset($_REQUEST['username']) && strlen($_REQUEST['username']) === 0) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + if (isset($_REQUEST['username']) + && $pmaString->strlen($_REQUEST['username']) === 0 + ) { $GLOBALS['pred_username'] = 'any'; } $html .= '
'; @@ -683,7 +688,10 @@ function PMA_getHtmlForReplicationMasterAddSlaveuser() $thishost = str_replace( "'", '', - substr($_current_user, (strrpos($_current_user, '@') + 1)) + $pmaString->substr( + $_current_user, + ($pmaString->strrpos($_current_user, '@') + 1) + ) ); if ($thishost == 'localhost' || $thishost == '127.0.0.1') { unset($thishost); @@ -704,7 +712,7 @@ function PMA_getHtmlForReplicationMasterAddSlaveuser() // when we start editing a user, $GLOBALS['pred_hostname'] is not defined if (! isset($GLOBALS['pred_hostname']) && isset($_REQUEST['hostname'])) { - switch (strtolower($_REQUEST['hostname'])) { + switch ($pmaString->strtolower($_REQUEST['hostname'])) { case 'localhost': case '127.0.0.1': $GLOBALS['pred_hostname'] = 'localhost'; diff --git a/libraries/rte/rte_events.lib.php b/libraries/rte/rte_events.lib.php index 0a17686639..9c3f1694c0 100644 --- a/libraries/rte/rte_events.lib.php +++ b/libraries/rte/rte_events.lib.php @@ -199,7 +199,9 @@ function PMA_EVN_handleEditor() $event = $GLOBALS['dbi']->fetchSingleRow($query); $response->addJSON( 'name', - htmlspecialchars(strtoupper($_REQUEST['item_name'])) + htmlspecialchars( + $GLOBALS['PMA_String']->strtoupper($_REQUEST['item_name']) + ) ); $response->addJSON('new_row', PMA_EVN_getRowForList($event)); $response->addJSON('insert', ! empty($event)); @@ -374,6 +376,9 @@ function PMA_EVN_getEditorForm($mode, $operation, $item) { global $db, $table, $event_status, $event_type, $event_interval; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Escape special characters $need_escape = array( 'item_original_name', @@ -414,7 +419,7 @@ function PMA_EVN_getEditorForm($mode, $operation, $item) } // Create the output $retval = ""; - $retval .= "\n\n"; + $retval .= "\n\n"; $retval .= "
\n"; $retval .= "\n"; $retval .= $original_data; @@ -549,7 +554,7 @@ function PMA_EVN_getEditorForm($mode, $operation, $item) $retval .= "\n"; } $retval .= "
\n\n"; - $retval .= "\n\n"; + $retval .= "\n\n"; return $retval; } // end PMA_EVN_getEditorForm() @@ -565,7 +570,8 @@ function PMA_EVN_getQueryFromRequest() $query = 'CREATE '; if (! empty($_REQUEST['item_definer'])) { - if (strpos($_REQUEST['item_definer'], '@') !== false) { + if ($GLOBALS['PMA_String']->strpos($_REQUEST['item_definer'], '@') !== false + ) { $arr = explode('@', $_REQUEST['item_definer']); $query .= 'DEFINER=' . PMA_Util::backquote($arr[0]); $query .= '@' . PMA_Util::backquote($arr[1]) . ' '; diff --git a/libraries/rte/rte_footer.lib.php b/libraries/rte/rte_footer.lib.php index 9fe85f49a5..415f0164a5 100644 --- a/libraries/rte/rte_footer.lib.php +++ b/libraries/rte/rte_footer.lib.php @@ -22,14 +22,17 @@ function PMA_RTE_getFooterLinks($docu, $priv, $name) { global $db, $url_query, $ajax_class; - $icon = 'b_' . strtolower($name) . '_add.png'; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + $icon = 'b_' . $pmaString->strtolower($name) . '_add.png'; $retval = ""; $retval .= "\n"; $retval .= "
\n"; $retval .= "" . _pgettext('Create new procedure', 'New') . "\n"; $retval .= "
\n"; $retval .= " strtolower($name) . "s.php"; $retval .= "?$url_query&add_item=1' onclick='$.datepicker.initialized = false;'>"; $retval .= PMA_Util::getIcon($icon); $retval .= PMA_RTE_getWord('add') . "\n"; @@ -80,7 +83,7 @@ function PMA_EVN_getFooterLinks() 0, 1 ); - $es_state = strtolower($es_state); + $es_state = $GLOBALS['PMA_String']->strtolower($es_state); $options = array( 0 => array( 'label' => __('OFF'), diff --git a/libraries/rte/rte_main.inc.php b/libraries/rte/rte_main.inc.php index 9abb9a3080..845c2978d4 100644 --- a/libraries/rte/rte_main.inc.php +++ b/libraries/rte/rte_main.inc.php @@ -35,7 +35,7 @@ if ($GLOBALS['is_ajax_request'] != true) { * to manually select the required database and * create the missing $url_query variable */ - if (strlen($db)) { + if ($GLOBALS['PMA_String']->strlen($db)) { $GLOBALS['dbi']->selectDb($db); if (! isset($url_query)) { $url_query = PMA_URL_getCommon($db, $table); diff --git a/libraries/rte/rte_routines.lib.php b/libraries/rte/rte_routines.lib.php index 2055f4a9ac..8a63709a52 100644 --- a/libraries/rte/rte_routines.lib.php +++ b/libraries/rte/rte_routines.lib.php @@ -97,6 +97,9 @@ function PMA_RTN_parseOneParameter($value) { global $param_directions; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $retval = array(0 => '', 1 => '', 2 => '', @@ -104,8 +107,11 @@ function PMA_RTN_parseOneParameter($value) 4 => ''); $parsed_param = PMA_SQP_parse($value); $pos = 0; - if (in_array(strtoupper($parsed_param[$pos]['data']), $param_directions)) { - $retval[0] = strtoupper($parsed_param[0]['data']); + if (in_array( + $pmaString->strtoupper($parsed_param[$pos]['data']), + $param_directions + )) { + $retval[0] = $pmaString->strtoupper($parsed_param[0]['data']); $pos++; } if ($parsed_param[$pos]['type'] == 'alpha_identifier' @@ -123,7 +129,7 @@ function PMA_RTN_parseOneParameter($value) if (($parsed_param[$i]['type'] == 'alpha_columnType' || $parsed_param[$i]['type'] == 'alpha_functionName') && $depth == 0 ) { - $retval[2] = strtoupper($parsed_param[$i]['data']); + $retval[2] = $pmaString->strtoupper($parsed_param[$i]['data']); } else if ($parsed_param[$i]['type'] == 'punct_bracket_open_round' && $depth == 0 ) { @@ -135,17 +141,18 @@ function PMA_RTN_parseOneParameter($value) } else if ($depth == 1) { $param_length .= $parsed_param[$i]['data']; } else if ($parsed_param[$i]['type'] == 'alpha_reservedWord' - && strtoupper($parsed_param[$i]['data']) == 'CHARSET' && $depth == 0 + && $pmaString->strtoupper($parsed_param[$i]['data']) == 'CHARSET' + && $depth == 0 ) { if ($parsed_param[$i+1]['type'] == 'alpha_charset' || $parsed_param[$i+1]['type'] == 'alpha_identifier' ) { - $param_opts[] = strtolower($parsed_param[$i+1]['data']); + $param_opts[] = $pmaString->strtolower($parsed_param[$i+1]['data']); } } else if ($parsed_param[$i]['type'] == 'alpha_columnAttrib' && $depth == 0 ) { - $param_opts[] = strtoupper($parsed_param[$i]['data']); + $param_opts[] = $pmaString->strtoupper($parsed_param[$i]['data']); } } $retval[3] = $param_length; @@ -238,6 +245,9 @@ function PMA_RTN_parseAllParameters($parsed_query, $routine_type) */ function PMA_RTN_parseRoutineDefiner($parsed_query) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $retval = ''; $fetching = false; for ($i=0; $i<$parsed_query['len']; $i++) { @@ -247,7 +257,7 @@ function PMA_RTN_parseRoutineDefiner($parsed_query) $fetching = true; } else if ($fetching == true && $parsed_query[$i]['type'] != 'quote_backtick' - && substr($parsed_query[$i]['type'], 0, 5) != 'punct' + && $pmaString->substr($parsed_query[$i]['type'], 0, 5) != 'punct' ) { break; } else if ($fetching == true @@ -402,7 +412,10 @@ function PMA_RTN_handleEditor() . " WHERE $where;" ); $response->addJSON( - 'name', htmlspecialchars(strtoupper($_REQUEST['item_name'])) + 'name', + htmlspecialchars( + $GLOBALS['PMA_String']->strtoupper($_REQUEST['item_name']) + ) ); $response->addJSON('new_row', PMA_RTN_getRowForList($routine)); $response->addJSON('insert', ! empty($routine)); @@ -512,7 +525,7 @@ function PMA_RTN_getDataFromRequest() 'item_definition', 'item_comment', 'item_definer'); - foreach ($indices as $key => $index) { + foreach ($indices as $index) { $retval[$index] = isset($_REQUEST[$index]) ? $_REQUEST[$index] : ''; } @@ -579,9 +592,12 @@ function PMA_RTN_getDataFromRequest() $retval['item_returntype'] = $_REQUEST['item_returntype']; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $retval['item_isdeterministic'] = ''; if (isset($_REQUEST['item_isdeterministic']) - && strtolower($_REQUEST['item_isdeterministic']) == 'on' + && $pmaString->strtolower($_REQUEST['item_isdeterministic']) == 'on' ) { $retval['item_isdeterministic'] = " checked='checked'"; } @@ -670,7 +686,9 @@ function PMA_RTN_getDataFromName($name, $type, $all = true) $retval['item_returnopts_num'] = ''; $retval['item_returnopts_text'] = ''; if (! empty($routine['DTD_IDENTIFIER'])) { - if (strlen($routine['DTD_IDENTIFIER']) > 63) { + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + if ($pmaString->strlen($routine['DTD_IDENTIFIER']) > 63) { // If the DTD_IDENTIFIER string from INFORMATION_SCHEMA is // at least 64 characters, then it may actually have been // chopped because that column is a varchar(64), so we will @@ -680,7 +698,7 @@ function PMA_RTN_getDataFromName($name, $type, $all = true) $fetching = false; for ($i=0; $i<$parsed_query['len']; $i++) { if ($parsed_query[$i]['type'] == 'alpha_reservedWord' - && strtoupper($parsed_query[$i]['data']) == 'RETURNS' + && $pmaString->strtoupper($parsed_query[$i]['data']) == 'RETURNS' ) { $fetching = true; } else if ($fetching == true @@ -692,7 +710,7 @@ function PMA_RTN_getDataFromName($name, $type, $all = true) // characters. We can safely assume that the return // datatype is either ENUM or SET, so we only look // for CHARSET. - $word = strtoupper($parsed_query[$i]['data']); + $word = $pmaString->strtoupper($parsed_query[$i]['data']); if ($word == 'CHARSET' && ($parsed_query[$i+1]['type'] == 'alpha_charset' || $parsed_query[$i+1]['type'] == 'alpha_identifier') @@ -935,9 +953,13 @@ function PMA_RTN_getEditorForm($mode, $operation, $routine) $isfunction_select = " selected='selected'"; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Create the output $retval = ""; - $retval .= "\n\n"; + $retval .= "\n\n"; $retval .= "
\n"; $retval .= "\n"; $retval .= $original_routine; @@ -1096,7 +1118,7 @@ function PMA_RTN_getEditorForm($mode, $operation, $routine) $retval .= "
"; } $retval .= ""; - $retval .= ""; + $retval .= ""; return $retval; } // end PMA_RTN_getEditorForm() @@ -1113,9 +1135,12 @@ function PMA_RTN_getQueryFromRequest() $_REQUEST['item_type'] = isset($_REQUEST['item_type']) ? $_REQUEST['item_type'] : ''; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + $query = 'CREATE '; if (! empty($_REQUEST['item_definer'])) { - if (strpos($_REQUEST['item_definer'], '@') !== false) { + if ($pmaString->strpos($_REQUEST['item_definer'], '@') !== false) { $arr = explode('@', $_REQUEST['item_definer']); $query .= 'DEFINER=' . PMA_Util::backquote($arr[0]); $query .= '@' . PMA_Util::backquote($arr[1]) . ' '; @@ -1201,13 +1226,17 @@ function PMA_RTN_getQueryFromRequest() if (! empty($_REQUEST['item_param_opts_text'][$i])) { if ($PMA_Types->getTypeClass($item_param_type[$i]) == 'CHAR') { $params .= ' CHARSET ' - . strtolower($_REQUEST['item_param_opts_text'][$i]); + . $pmaString->strtolower( + $_REQUEST['item_param_opts_text'][$i] + ); } } if (! empty($_REQUEST['item_param_opts_num'][$i])) { if ($PMA_Types->getTypeClass($item_param_type[$i]) == 'NUMBER') { $params .= ' ' - . strtoupper($_REQUEST['item_param_opts_num'][$i]); + . $pmaString->strtoupper( + $_REQUEST['item_param_opts_num'][$i] + ); } } if ($i != (count($item_param_name) - 1)) { @@ -1261,12 +1290,13 @@ function PMA_RTN_getQueryFromRequest() if (! empty($_REQUEST['item_returnopts_text'])) { if ($PMA_Types->getTypeClass($item_returntype) == 'CHAR') { $query .= ' CHARSET ' - . strtolower($_REQUEST['item_returnopts_text']); + . $pmaString->strtolower($_REQUEST['item_returnopts_text']); } } if (! empty($_REQUEST['item_returnopts_num'])) { if ($PMA_Types->getTypeClass($item_returntype) == 'NUMBER') { - $query .= ' ' . strtoupper($_REQUEST['item_returnopts_num']); + $query .= ' ' + . $pmaString->strtoupper($_REQUEST['item_returnopts_num']); } } $query .= ' '; @@ -1570,6 +1600,9 @@ function PMA_RTN_getExecuteForm($routine) { global $db, $cfg; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Escape special characters $routine['item_name'] = htmlentities($routine['item_name'], ENT_QUOTES); for ($i=0; $i<$routine['item_num_params']; $i++) { @@ -1624,13 +1657,16 @@ function PMA_RTN_getExecuteForm($routine) if (stristr($routine['item_param_type'][$i], 'enum') || stristr($routine['item_param_type'][$i], 'set') || in_array( - strtolower($routine['item_param_type'][$i]), $no_support_types + $pmaString->strtolower($routine['item_param_type'][$i]), + $no_support_types ) ) { $retval .= "--\n"; } else { $field = array( - 'True_Type' => strtolower($routine['item_param_type'][$i]), + 'True_Type' => $pmaString->strtolower( + $routine['item_param_type'][$i] + ), 'Type' => '', 'Key' => '', 'Field' => '', @@ -1676,7 +1712,8 @@ function PMA_RTN_getExecuteForm($routine) } } } else if (in_array( - strtolower($routine['item_param_type'][$i]), $no_support_types + $pmaString->strtolower($routine['item_param_type'][$i]), + $no_support_types )) { $retval .= "\n"; } else { diff --git a/libraries/rte/rte_triggers.lib.php b/libraries/rte/rte_triggers.lib.php index 1650ae7a51..46718d29b9 100644 --- a/libraries/rte/rte_triggers.lib.php +++ b/libraries/rte/rte_triggers.lib.php @@ -178,7 +178,9 @@ function PMA_TRI_handleEditor() $response->addJSON( 'name', htmlspecialchars( - strtoupper($_REQUEST['item_name']) + $GLOBALS['PMA_String']->strtoupper( + $_REQUEST['item_name'] + ) ) ); } @@ -322,6 +324,9 @@ function PMA_TRI_getEditorForm($mode, $item) { global $db, $table, $event_manipulations, $action_timings; + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + // Escape special characters $need_escape = array( 'item_original_name', @@ -344,7 +349,7 @@ function PMA_TRI_getEditorForm($mode, $item) // Create the output $retval = ""; - $retval .= "\n\n"; + $retval .= "\n\n"; $retval .= "
\n"; $retval .= "\n"; $retval .= $original_data; @@ -427,7 +432,7 @@ function PMA_TRI_getEditorForm($mode, $item) $retval .= "\n"; } $retval .= "
\n\n"; - $retval .= "\n\n"; + $retval .= "\n\n"; return $retval; } // end PMA_TRI_getEditorForm() @@ -443,7 +448,8 @@ function PMA_TRI_getQueryFromRequest() $query = 'CREATE '; if (! empty($_REQUEST['item_definer'])) { - if (strpos($_REQUEST['item_definer'], '@') !== false) { + if ($GLOBALS['PMA_String']->strpos($_REQUEST['item_definer'], '@') !== false + ) { $arr = explode('@', $_REQUEST['item_definer']); $query .= 'DEFINER=' . PMA_Util::backquote($arr[0]); $query .= '@' . PMA_Util::backquote($arr[1]) . ' '; diff --git a/libraries/rte/rte_words.lib.php b/libraries/rte/rte_words.lib.php index a9f5f5c4f0..db40ca73a7 100644 --- a/libraries/rte/rte_words.lib.php +++ b/libraries/rte/rte_words.lib.php @@ -10,7 +10,7 @@ if (! defined('PHPMYADMIN')) { } /** - * This function is used to retreive some language strings that are used + * This function is used to retrieve some language strings that are used * in functionalities that are common to routines, triggers and events. * * @param string $index The index of the string to get diff --git a/libraries/sanitizing.lib.php b/libraries/sanitizing.lib.php index 7e6e84db5b..0b14de8ab4 100644 --- a/libraries/sanitizing.lib.php +++ b/libraries/sanitizing.lib.php @@ -29,8 +29,10 @@ function PMA_checkLink($url) $valid_starts[] = '?page=form&'; $valid_starts[] = '?page=servers&'; } + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; foreach ($valid_starts as $val) { - if (substr($url, 0, strlen($val)) == $val) { + if ($pmaString->substr($url, 0, $pmaString->strlen($val)) == $val) { return true; } } @@ -62,7 +64,7 @@ function PMA_replaceBBLink($found) } /* Construct url */ - if (substr($found[1], 0, 4) == 'http') { + if ($GLOBALS['PMA_String']->substr($found[1], 0, 4) == 'http') { $url = PMA_linkURL($found[1]); } else { $url = $found[1]; diff --git a/libraries/select_lang.lib.php b/libraries/select_lang.lib.php index 625f7cf229..23d6e0ff19 100644 --- a/libraries/select_lang.lib.php +++ b/libraries/select_lang.lib.php @@ -18,7 +18,12 @@ if (! defined('PHPMYADMIN')) { */ function PMA_languageName($tmplang) { - $lang_name = ucfirst(substr(strrchr($tmplang[0], '|'), 1)); + /** @var PMA_String $pmaString */ + $pmaString = $GLOBALS['PMA_String']; + + $lang_name = ucfirst( + $pmaString->substr($pmaString->strrchr($tmplang[0], '|'), 1) + ); // Include native name if non empty if (!empty($tmplang[2])) { @@ -84,7 +89,9 @@ function PMA_langCheck() // try to find out user's language by checking its HTTP_ACCEPT_LANGUAGE variable; // prevent XSS $accepted_languages = PMA_getenv('HTTP_ACCEPT_LANGUAGE'); - if ($accepted_languages && false === strpos($accepted_languages, '<')) { + if ($accepted_languages + && false === $GLOBALS['PMA_String']->strpos($accepted_languages, '<') + ) { foreach (explode(',', $accepted_languages) as $lang) { if (PMA_langDetect($lang, 1)) { return true; @@ -153,7 +160,7 @@ function PMA_langDetect($str, $envType) // $envType = 1 for the 'HTTP_ACCEPT_LANGUAGE' environment variable, // 2 for the 'HTTP_USER_AGENT' one $expr = $value[0]; - if (strpos($expr, '[-_]') === false) { + if ($GLOBALS['PMA_String']->strpos($expr, '[-_]') === false) { $expr = str_replace('|', '([-_][[:alpha:]]{2,3})?|', $expr); } $pattern1 = '/^(' . addcslashes($expr, '/') . ')(;q=[0-9]\\.[0-9])?$/i'; diff --git a/libraries/server_databases.lib.php b/libraries/server_databases.lib.php index 83ac53ae6d..b3d42e11ce 100644 --- a/libraries/server_databases.lib.php +++ b/libraries/server_databases.lib.php @@ -439,7 +439,7 @@ function PMA_getListForSortDatabase() } if (isset($_REQUEST['sort_order']) - && strtolower($_REQUEST['sort_order']) == 'desc' + && $GLOBALS['PMA_String']->strtolower($_REQUEST['sort_order']) == 'desc' ) { $sort_order = 'desc'; } else { diff --git a/libraries/server_plugins.lib.php b/libraries/server_plugins.lib.php index a85aaead20..7661b9ee27 100644 --- a/libraries/server_plugins.lib.php +++ b/libraries/server_plugins.lib.php @@ -49,8 +49,12 @@ function PMA_getPluginTab($plugins) $html = '
'; $html .= '