Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+7 -7
View File
@@ -29,15 +29,15 @@ class IPSUtf8
mb_internal_encoding('UTF-8');
/* Constants */
define( 'THIS_PATH', __DIR__ );
\define( 'THIS_PATH', __DIR__ );
$bits = explode( DIRECTORY_SEPARATOR, THIS_PATH );
$bit = array_pop( $bits );
$bit2 = array_pop( $bits );
define( 'ROOT_PATH', preg_replace( '#' . preg_quote( DIRECTORY_SEPARATOR, '#' ) . $bit2 . preg_quote( DIRECTORY_SEPARATOR, '#' ) . $bit . '$#', '', THIS_PATH ) );
\define( 'ROOT_PATH', preg_replace( '#' . preg_quote( DIRECTORY_SEPARATOR, '#' ) . $bit2 . preg_quote( DIRECTORY_SEPARATOR, '#' ) . $bit . '$#', '', THIS_PATH ) );
define( 'IS_CLI', ( PHP_SAPI == 'cli' || empty( $_SERVER['REMOTE_ADDR'] ) ) ? true : false );
\define( 'IS_CLI', ( PHP_SAPI == 'cli' || empty( $_SERVER['REMOTE_ADDR'] ) ) ? true : false );
/* Set Options - deliberately do not use root constants */
if ( file_exists( './constants.php' ) )
@@ -47,9 +47,9 @@ class IPSUtf8
foreach( static::defaultConstants() AS $k => $v )
{
if ( !defined( $k ) )
if ( !\defined( $k ) )
{
define( $k, $v );
\define( $k, $v );
}
}
@@ -98,7 +98,7 @@ class IPSUtf8
public static function errorHandler( $errno, $errstr, $errfile, $errline, $trace=NULL )
{
/* We don't care about these in production */
if ( in_array( $errno, array( E_WARNING, E_NOTICE, E_STRICT, E_DEPRECATED ) ) )
if ( \in_array( $errno, array( E_WARNING, E_NOTICE, E_STRICT, E_DEPRECATED ) ) )
{
return;
}
@@ -253,7 +253,7 @@ IPSUtf8::init();
eval( '
function mb_ucfirst()
{
$text = func_get_arg( 0 );
$text = \func_get_arg( 0 );
return mb_strtoupper( mb_substr( $text, 0, 1 ) ) . mb_substr( $text, 1 );
}
');
@@ -67,7 +67,7 @@ class archive extends \IPSUtf8\Dispatcher\Controller
$percent = round( ($json['convertedCount'] / \IPSUtf8\Convert\Archive::i()->getTotalRowsToConvert()) * 100, 2 );
$msg = "Processing " . \IPSUtf8\Session::i()->current_table . ' (Total: ' . $percent . '%)';
if ( in_array( \IPSUtf8\Convert\Archive::ARCHIVE_TABLE, array_keys( \IPSUtf8\Session::i()->completed_json ) ) )
if ( \in_array( \IPSUtf8\Convert\Archive::ARCHIVE_TABLE, array_keys( \IPSUtf8\Session::i()->completed_json ) ) )
{
\IPSUtf8\Session::i()->status = 'completed';
\IPSUtf8\Session::i()->save();
@@ -132,14 +132,14 @@ class archive extends \IPSUtf8\Dispatcher\Controller
exit();
}
if ( ! count( \IPSUtf8\Session::i()->has_archive ) )
if ( ! \count( \IPSUtf8\Session::i()->has_archive ) )
{
\IPSUtf8\Output\Browser::i()->error("Cannot locate a separate database for the post archive.");
exit();
}
if ( ! count( \IPSUtf8\Session::i()->tables ) )
if ( ! \count( \IPSUtf8\Session::i()->tables ) )
{
\IPSUtf8\Output\Browser::i()->error("No tables found for processing. Please check to ensure the correct database name and prefix are being used.");
exit();
@@ -160,7 +160,7 @@ class browser extends \IPSUtf8\Dispatcher\Controller
exit();
}
if ( ! count( \IPSUtf8\Session::i()->tables ) )
if ( ! \count( \IPSUtf8\Session::i()->tables ) )
{
\IPSUtf8\Output\Browser::i()->error("No tables found for processing. Please check to ensure the correct database name and prefix are being used.");
exit();
@@ -34,6 +34,15 @@ class tools extends \IPSUtf8\Dispatcher\Controller
*/
public function collation()
{
if( ( version_compare( \IPSUtf8\Db::i()->server_info, '5.5.3', '>=' ) AND \IPSUtf8\Db::i('utf8')->set_charset('utf8mb4') !== FALSE ) )
{
$sessionData = \IPSUtf8\Session::i()->json;
$sessionData['use_utf8mb4'] = 1;
\IPSUtf8\Session::i()->json = $sessionData;
\IPSUtf8\Session::i()->save();
}
\IPSUtf8\Convert::i()->fixCollation();
$this->manage( "Collation checked and fixed where appropriate" );
+10 -24
View File
@@ -77,7 +77,7 @@ class cli
if ( \IPSUtf8\Session::i()->has_archive )
{
if ( ! count( \IPSUtf8\Convert\Archive::i()->getNonUtf8Tables ) )
if ( ! \count( \IPSUtf8\Convert\Archive::i()->getNonUtf8Tables ) )
{
\IPSUtf8\Output\Cli::i()->sendOutput( "You have an archive table in a different database, and it is UTF8 and collations are correct." );
}
@@ -103,7 +103,7 @@ class cli
}
}
if ( ! count( \IPSUtf8\Session::i()->tables ) )
if ( ! \count( \IPSUtf8\Session::i()->tables ) )
{
\IPSUtf8\Output\Cli::i()->sendOutput("No tables found for processing. Please check to ensure the correct database name and prefix are being used.");
exit();
@@ -114,7 +114,7 @@ class cli
if ( $convertClass::i()->databaseIsUtf8() )
{
/* Check collations */
if ( ! count( $convertClass::i()->getNonUtf8CollationTables() ) )
if ( ! \count( $convertClass::i()->getNonUtf8CollationTables() ) )
{
/* We're golden! */
\IPSUtf8\Output\Cli::i()->sendOutput("The database is set to UTF-8, collations are correct and doesn't need converting.\n<choice>[x] Enter 'x' to exit the conversion (RECOMMENDED).\n[y] Enter 'y' to perform a full conversion anyway</choice>", 100 );
@@ -141,29 +141,15 @@ class cli
}
}
\IPSUtf8\Output\Cli::i()->sendOutput( "\n" . count( $convertClass::i()->getNonUtf8Tables() ) . " table(s) are not UTF-8 and need converting.\n");
\IPSUtf8\Output\Cli::i()->sendOutput( "\n" . \count( $convertClass::i()->getNonUtf8Tables() ) . " table(s) are not UTF-8 and need converting.\n");
$origUtf8Charset = \IPSUtf8\Db::i('utf8')->getCharset();
$canMb4 = (bool) \IPSUtf8\Db::i('utf8')->set_charset( 'utf8mb4' );
\IPSUtf8\Db::i('utf8')->set_charset( $origUtf8Charset );
if ( version_compare( \IPSUtf8\Db::i()->server_info, '5.5.3', '>=' ) AND $canMb4 !== FALSE )
{
\IPSUtf8\Output\Cli::i()->sendOutput("Use 4-byte UTF-8 Encoding (utf8mb4)?\nSome non-common symbols (such as historical scripts, music symbols and Emoji) require more space in the database to be stored. If you choose 'no', users will not be able to use these symbols on your site. If 'yes', these characters will be able to be used, but the database will use more disk space.\n<choice>[y] Enter 'y' for Yes\n[n] Enter 'n' for No\n[x] Enter 'x' to exit</choice>", 100 );
$sessionData = \IPSUtf8\Session::i()->json;
if ( \IPSUtf8\Output\Cli::i()->response === 'y' )
{
$sessionData['use_utf8mb4'] = 1;
}
else if ( \IPSUtf8\Output\Cli::i()->response === 'n' )
{
$sessionData['use_utf8mb4'] = 0;
}
else
{
exit;
}
$sessionData['use_utf8mb4'] = 1;
\IPSUtf8\Session::i()->json = $sessionData;
\IPSUtf8\Session::i()->save();
}
@@ -179,7 +165,7 @@ class cli
else
{
$date = date('D j F Y', \IPSUtf8\Session::i()->updated );
$count = count( array_keys( \IPSUtf8\Session::i()->completed_json ) );
$count = \count( array_keys( \IPSUtf8\Session::i()->completed_json ) );
$pcent = round( ( \IPSUtf8\Session::i()->json['convertedCount'] / $convertClass::i()->getTotalRowsToConvert() * 100 ) );
$more = "<warning>You have a conversion session unfinished. The session was last updated on " . $date . " and has processed " . $count . " tables (" . $pcent . "%) so far.</warning>";
@@ -230,7 +216,7 @@ class cli
{
$convertClass = static::$convertClass;
\IPSUtf8\Output\Cli::i()->sendOutput("The database is set to UTF-8 and all tables are UTF-8 but " . count( $convertClass::i()->getNonUtf8CollationTables() ) . " table(s) have incorrect collations and need fixing.\n<choice>[f] Enter 'f' to fix table and field collations (RECOMMENDED)\n[y] Enter 'y' to perform a full conversion\n[x] Enter 'x' to exit the conversion</choice>", 100 );
\IPSUtf8\Output\Cli::i()->sendOutput("The database is set to UTF-8 and all tables are UTF-8 but " . \count( $convertClass::i()->getNonUtf8CollationTables() ) . " table(s) have incorrect collations and need fixing.\n<choice>[f] Enter 'f' to fix table and field collations (RECOMMENDED)\n[y] Enter 'y' to perform a full conversion\n[x] Enter 'x' to exit the conversion</choice>", 100 );
if ( \IPSUtf8\Output\Cli::i()->response === 'x' )
{
@@ -297,7 +283,7 @@ class cli
$convertClass::i()->renameTables();
if ( count( $convertClass::i()->getNonUtf8CollationTables() ) )
if ( \count( $convertClass::i()->getNonUtf8CollationTables() ) )
{
\IPSUtf8\Output\Cli::i()->sendOutput( "Checking and fixing collations." );
$convertClass::i()->fixCollation();
@@ -407,7 +393,7 @@ class cli
$toConvert = $convertClass::i()->getNonUtf8Tables();
if ( ! count( $toConvert ) )
if ( ! \count( $toConvert ) )
{
\IPSUtf8\Output\Cli::i()->sendOutput("Nothing to convert!");
exit();
+6 -6
View File
@@ -117,7 +117,7 @@ class Archive extends \IPSUtf8\Convert
\IPSUtf8\Session::i()->current_pkey = 'archive_id';
\IPSUtf8\Session::i()->save();
if ( in_array( self::ARCHIVE_TABLE, array_keys( \IPSUtf8\Session::i()->completed_json ) ) )
if ( \in_array( self::ARCHIVE_TABLE, array_keys( \IPSUtf8\Session::i()->completed_json ) ) )
{
return null;
}
@@ -191,7 +191,7 @@ class Archive extends \IPSUtf8\Convert
/* Best check the tables, then */
foreach( self::$tableDefinition['definition']['columns'] as $name => $column )
{
if ( $column['collation'] and ! in_array( $column['collation'], array( 'utf8_unicode_ci', 'utf8mb4_unicode_ci' ) ) )
if ( $column['collation'] and ! \in_array( $column['collation'], array( 'utf8_unicode_ci', 'utf8mb4_unicode_ci' ) ) )
{
static::$nonUtf8Collations[] = self::$tableDefinition['name'];
break;
@@ -211,7 +211,7 @@ class Archive extends \IPSUtf8\Convert
*/
public static function getNumericColumns( $name )
{
if ( ! is_string( $name ) )
if ( ! \is_string( $name ) )
{
return false;
}
@@ -220,7 +220,7 @@ class Archive extends \IPSUtf8\Convert
foreach( self::$tableDefinition['definition']['columns'] as $col => $val )
{
if ( in_array( mb_strtolower( $val['type'] ), static::$numericCols ) )
if ( \in_array( mb_strtolower( $val['type'] ), static::$numericCols ) )
{
$return[] = $val['name'];
}
@@ -237,7 +237,7 @@ class Archive extends \IPSUtf8\Convert
*/
public static function getConvertableColumns( $name )
{
if ( ! is_string( $name ) )
if ( ! \is_string( $name ) )
{
return false;
}
@@ -246,7 +246,7 @@ class Archive extends \IPSUtf8\Convert
foreach( self::$tableDefinition['definition']['columns'] as $col => $val )
{
if ( in_array( mb_strtolower( $val['type'] ), static::$convertCols ) )
if ( \in_array( mb_strtolower( $val['type'] ), static::$convertCols ) )
{
$return[] = $val['name'];
}
+81 -116
View File
@@ -70,7 +70,7 @@ class Convert
/**
* @brief Create don't populate
*/
protected static $createOnly = array( 'content_cache_posts', 'content_cache_sigs', 'sessions', 'topic_views', 'search_keywords' );
protected static $createOnly = array( 'content_cache_posts', 'content_cache_sigs', 'sessions', 'topic_views', 'search_keywords', 'core_share_links_log', 'spider_logs', 'inline_notifications' );
/**
* @brief Problem Tables that can cause an error due to serialization while using "fast" mode
@@ -92,7 +92,7 @@ class Convert
if ( self::$instance === NULL )
{
static::$db = \IPSUtf8\Db::i();
if ( defined( 'SOURCE_DB_CHARSET' ) AND SOURCE_DB_CHARSET !== NULL )
if ( \defined( 'SOURCE_DB_CHARSET' ) AND SOURCE_DB_CHARSET !== NULL )
{
static::$db->set_charset( SOURCE_DB_CHARSET );
}
@@ -177,24 +177,24 @@ class Convert
/* Latin1 is actually cp1252, not ISO-8859-1 @link http://dev.mysql.com/doc/refman/5.0/en/charset-we-sets.html */
/* But only if our document character set is ISO-8859-1 or UTF-8. Otherwise, we're using the slow method which needs to real charset despite what the table is set too */
if ( $tableCharSet === 'latin1' AND in_array( mb_strtolower( $currentCharSet ), array( 'iso-8859-1', 'utf-8' ) ) )
if ( $tableCharSet === 'latin1' AND \in_array( mb_strtolower( $currentCharSet ), array( 'iso-8859-1', 'utf-8' ) ) )
{
$currentCharSet = 'windows-1252';
}
if ( defined( 'FORCE_CONVERT_CHARSET' ) AND FORCE_CONVERT_CHARSET !== NULL )
if ( \defined( 'FORCE_CONVERT_CHARSET' ) AND FORCE_CONVERT_CHARSET !== NULL )
{
$currentCharSet = FORCE_CONVERT_CHARSET;
}
}
if ( !defined( 'SOURCE_DB_CHARSET' ) OR SOURCE_DB_CHARSET === NULL )
if ( !\defined( 'SOURCE_DB_CHARSET' ) OR SOURCE_DB_CHARSET === NULL )
{
static::$db->set_charset( $tableCharSet );
}
/* Create table only */
if ( IPB_LOCK and in_array( $table['name'], static::$createOnly ) )
if ( IPB_LOCK and \in_array( $table['name'], static::$createOnly ) )
{
static::log( 'No content conversion of ' . $table['name'] . ' required' );
@@ -213,7 +213,7 @@ class Convert
if ( $table === null )
{
if ( count( array_keys( \IPSUtf8\Session::i()->tables ) ) == count( array_keys( \IPSUtf8\Session::i()->completed_json ) ) )
if ( \count( array_keys( \IPSUtf8\Session::i()->tables ) ) == \count( array_keys( \IPSUtf8\Session::i()->completed_json ) ) )
{
\IPSUtf8\Session::i()->status = 'completed';
\IPSUtf8\Session::i()->save();
@@ -224,7 +224,7 @@ class Convert
}
/* Got any fields to convert? */
if ( count( $convertCols ) === 0 )
if ( \count( $convertCols ) === 0 )
{
/* No data to convert, lets repopulate the easy way! */
$this->preInsert( $table );
@@ -272,7 +272,7 @@ class Convert
}
/* Latin1 or ISO-8559-1? */
if ( ! in_array( $table['name'], static::$problemTables ) AND ( in_array( $tableCharSet, $this->getMysqlCharSets() ) ) and ( \IPSUtf8\Session::i()->current_charset == 'utf-8' or \IPSUtf8\Session::i()->current_charset == 'iso-8859-1' ) AND ( !isset( $sessionData['force_conversion'] ) OR $sessionData['force_conversion'] !== 1 ) )
if ( ! \in_array( $table['name'], static::$problemTables ) AND ( \in_array( $tableCharSet, $this->getMysqlCharSets() ) ) and ( \IPSUtf8\Session::i()->current_charset == 'utf-8' or \IPSUtf8\Session::i()->current_charset == 'iso-8859-1' ) AND ( !isset( $sessionData['force_conversion'] ) OR $sessionData['force_conversion'] !== 1 ) )
{
/* Convert the fast way! */
$count = static::$utf->select( 'COUNT(*)', $table['name'] )->first();
@@ -295,7 +295,7 @@ class Convert
foreach( array_keys( $table['definition']['columns'] ) as $col )
{
if ( in_array( $col, $convertCols ) )
if ( \in_array( $col, $convertCols ) )
{
/* Even if the current charset is set to UTF-8, if the Table Charset is latin1, we need to use this method */
/* ... but only if the actual column isn't using utf8 */
@@ -304,7 +304,7 @@ class Convert
{
$select[] = 'CAST( `' . $col . '` AS BINARY )';
}
else if ( FORCE_MULTI_CONVERT === FALSE AND ( \IPSUtf8\Session::i()->current_charset != 'utf-8' OR ( $tableCharSet != 'utf8' AND ! in_array( $columnCollation, array( 'utf8_unicode_ci', 'utf8mb4_unicode_ci' ) ) ) OR ( $tableCharSet == 'utf8' AND mb_substr( $columnCollation, 0, 5 ) == 'latin' ) ) )
else if ( FORCE_MULTI_CONVERT === FALSE AND ( \IPSUtf8\Session::i()->current_charset != 'utf-8' OR ( $tableCharSet != 'utf8' AND ! \in_array( $columnCollation, array( 'utf8_unicode_ci', 'utf8mb4_unicode_ci' ) ) ) OR ( $tableCharSet == 'utf8' AND mb_substr( $columnCollation, 0, 5 ) == 'latin' ) ) )
{
if ( \IPSUtf8\Session::i()->current_charset == 'iso-8859-1' AND mb_substr( $columnCollation, 0, 5 ) == 'latin' )
{
@@ -336,12 +336,12 @@ class Convert
}
$source_charset = 'latin1';
if ( defined( 'SOURCE_DB_CHARSET' ) AND SOURCE_DB_CHARSET !== NULL )
if ( \defined( 'SOURCE_DB_CHARSET' ) AND SOURCE_DB_CHARSET !== NULL )
{
$source_charset = SOURCE_DB_CHARSET;
}
if ( defined( 'MULTI_NO_CMP' ) AND MULTI_NO_CMP === TRUE )
if ( \defined( 'MULTI_NO_CMP' ) AND MULTI_NO_CMP === TRUE )
{
$select[] = "CONVERT(CONVERT(CONVERT(`{$col}` USING {$source_charset}) USING BINARY) USING {$using})";
}
@@ -385,7 +385,7 @@ class Convert
$rows = static::$db->select(
'*',
$table['name'],
array( \IPSUtf8\Session::i()->current_pkey . ' > ?', intval( $start ) ),
array( \IPSUtf8\Session::i()->current_pkey . ' > ?', \intval( $start ) ),
\IPSUtf8\Session::i()->current_pkey . ' ASC',
( $limit ? array( 0, ( $limit - $convertCount ) ) : null )
);
@@ -404,14 +404,14 @@ class Convert
);
}
if ( !defined( 'FORCE_CONVERT_METHOD' ) OR FORCE_CONVERT_METHOD === NULL )
if ( !\defined( 'FORCE_CONVERT_METHOD' ) OR FORCE_CONVERT_METHOD === NULL )
{
\IPSUtf8\Text\Charset::$method = 'internal';
/* Optimise for latin character sets */
if ( function_exists( 'mb_convert_encoding' ) )
if ( \function_exists( 'mb_convert_encoding' ) )
{
if ( in_array( strtolower( $currentCharSet ), array_map( 'strtolower', mb_list_encodings() ) ) )
if ( \in_array( strtolower( $currentCharSet ), array_map( 'strtolower', mb_list_encodings() ) ) )
{
\IPSUtf8\Text\Charset::$method = 'mb';
}
@@ -419,7 +419,7 @@ class Convert
}
$rowCount = 0;
$gotRows = count( $rows );
$gotRows = \count( $rows );
$batch = array();
$batchBytes = 0;
$max = ( $limit ) ?: 250;
@@ -464,7 +464,7 @@ class Convert
{
if ( isset( $row[ $col ] ) AND ! empty( $row[ $col ] ) )
{
$currentCharSet = ( defined( 'FORCE_CONVERT_CHARSET' ) AND FORCE_CONVERT_CHARSET != NULL ) ? FORCE_CONVERT_CHARSET : $currentCharSet;
$currentCharSet = ( \defined( 'FORCE_CONVERT_CHARSET' ) AND FORCE_CONVERT_CHARSET != NULL ) ? FORCE_CONVERT_CHARSET : $currentCharSet;
if ( static::isSerialized( $row[ $col ] ) AND \IPSUtf8\Text\Charset::i()->needsConverting( $row[ $col ], $currentCharSet, 'UTF-8' ) )
{
/* Store a copy in case it doesn't work */
@@ -484,7 +484,7 @@ class Convert
/* Something went wrong... maybe we can figure it out */
$work = unserialize( $original );
array_walk_recursive( $work, function ( &$input, $key ) use ( $currentCharSet, $tableCharSet ) {
if ( function_exists( 'mb_detect_encoding' ) )
if ( \function_exists( 'mb_detect_encoding' ) )
{
$encoding = mb_detect_encoding( $input );
$input = \IPSUtf8\Text\Charset::i()->convert( $input, $encoding, 'UTF-8' );
@@ -515,7 +515,7 @@ class Convert
{
if ( isset( $row[ $col ] ) AND ! empty( $row[ $col ] ) )
{
if ( $row[ $col ] === null OR ! is_numeric( $row[ $col ] ) )
if ( $row[ $col ] === null OR !\is_numeric( $row[ $col ] ) )
{
$row[ $col ] = 0;
}
@@ -526,7 +526,7 @@ class Convert
$tmp = $row; // Use a copy so the reference in array_walk doesn't overwrite the row to be inserted
/* Make sure it's an associative array as topic_views only has 1 column so DB driver returns an indexed array only */
if ( is_array( $tmp ) )
if ( \is_array( $tmp ) )
{
array_walk_recursive( $tmp, function( &$input, $key )
{
@@ -540,23 +540,23 @@ class Convert
$nextBatch = null;
/* Give us an error margin to account for MySQL syntax */
if ( $batchBytes > ( $this->_data['max_allowed_packet'] - ( ( $this->_data['max_allowed_packet'] / 100 ) * ( count( $batch ) * 0.3 ) ) ) )
if ( $batchBytes > ( $this->_data['max_allowed_packet'] - ( ( $this->_data['max_allowed_packet'] / 100 ) * ( \count( $batch ) * 0.3 ) ) ) )
{
/* Remove last row */
$nextBatch = array_pop( $batch );
static::log( "Max packet hit with " . $batchBytes . 'b with ' . count( $batch ) . ' rows' );
static::log( "Max packet hit with " . $batchBytes . 'b with ' . \count( $batch ) . ' rows' );
}
/* If we have moved the only row from $batch to $nextbatch, then process that now */
if ( count( $nextBatch ) and ! count( $batch ) )
if ( \count( $nextBatch ) and ! \count( $batch ) )
{
$batch = $nextBatch;
$nextBatch = array();
}
/* Got a batch to write? */
if ( $nextBatch !== null OR ( count( $batch ) === $max ) OR ( $gotRows === count( $batch ) ) )
if ( $nextBatch !== null OR ( \count( $batch ) === $max ) OR ( $gotRows === \count( $batch ) ) )
{
try
{
@@ -573,8 +573,8 @@ class Convert
$this->postInsert( $table );
/* Update counts */
$sessionData['convertedCount'] += count( $batch );
$convertCount += count( $batch );
$sessionData['convertedCount'] += \count( $batch );
$convertCount += \count( $batch );
if ( \IPSUtf8\Session::i()->current_pkey )
{
@@ -582,14 +582,14 @@ class Convert
}
else
{
\IPSUtf8\Session::i()->current_row += count( $batch );
\IPSUtf8\Session::i()->current_row += \count( $batch );
}
\IPSUtf8\Session::i()->status = 'processing';
\IPSUtf8\Session::i()->json = $sessionData;
\IPSUtf8\Session::i()->save();
static::log( count( $batch ) . " rows batch inserted using conversion method: " . \IPSUtf8\Text\Charset::$method . ', last insert ID ' . $insertId );
static::log( \count( $batch ) . " rows batch inserted using conversion method: " . \IPSUtf8\Text\Charset::$method . ', last insert ID ' . $insertId );
$batch = ( $nextBatch !== null ) ? array( $nextBatch ) : array();
$batchBytes = 0;
@@ -790,9 +790,9 @@ class Convert
foreach( explode( ";", $currentLocale ) as $locale )
{
$parts = explode( "=", $locale );
if( in_array( $parts[0], array( 'LC_ALL', 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME' ) ) )
if( \in_array( $parts[0], array( 'LC_ALL', 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME' ) ) )
{
setlocale( constant( $parts[0] ), $parts[1] );
setlocale( \constant( $parts[0] ), $parts[1] );
}
}
@@ -979,7 +979,7 @@ class Convert
foreach( \IPSUtf8\Session::i()->tables as $name => $data )
{
if ( in_array( $name, $this->getNonUtf8CollationTables() ) )
if ( \in_array( $name, $this->getNonUtf8CollationTables() ) )
{
/* Skip if it's an _old table */
if( mb_substr( $name, -4 ) == '_old' )
@@ -990,72 +990,37 @@ class Convert
$cols = static::getConvertableColumns( $data['name'] );
$tableData = \IPSUtf8\Session::i()->tables[ $data['name'] ];
if ( count( $cols ) )
if ( \count( $cols ) )
{
$dropIndexes = array();
$addIndexes = array();
$modify = array();
$hasUnique = FALSE;
/* Changing collation can cause issues for duplicate entries in unique keys */
if ( isset( $tableData['definition']['indexes'] ) )
{
foreach( $tableData['definition']['indexes'] as $key => $index )
{
if ( $index['type'] === 'unique' OR $index['type'] === 'primary' )
{
/* Make sure none of the columns in this index are auto_increment */
foreach( $index['columns'] AS $k => $idxcol )
{
if ( $tableData['definition']['columns'][ $idxcol ]['auto_increment'] === TRUE )
{
continue 2;
}
}
if ( static::$db->checkForIndex( $name, $key ) )
{
$hasUnique = TRUE;
break;
}
}
}
}
}
/* We don't need to drop any indexes - just create a copy of the table and insert ignore */
if ( $hasUnique === TRUE )
{
/* Let's try an alter first - below may not be necessary */
try
{
static::$utf->query( "ALTER TABLE `" . static::$db->prefix . $name . "` CONVERT TO CHARACTER SET " . $charset . " COLLATE " . $collation );
static::$utf->query( "ALTER TABLE `" . static::$db->prefix . $name . "` DEFAULT CHARACTER SET " . $charset . " COLLATE " . $collation );
}
catch( \IPSUtf8\Db\Exception $e )
{
/* Did not work - try the long way */
static::$utf->query( "RENAME TABLE `" . static::$db->prefix . $name . "` TO `" . static::$db->prefix . $name . "_temp`" );
static::log( $name . " has Unique Index - temp table created from main." );
/* Previously we used a raw create table query to create a copy, however this does not check index lengths. Leaving this for reference. */
//static::$utf->query( "CREATE TABLE `" . static::$db->prefix . $name . "` LIKE `" . static::$db->prefix . $name . "_temp`" );
static::$db->createTable( $this->checkTable( $tableData['definition'] ) );
static::$utf->query( "ALTER TABLE `" . static::$db->prefix . $name . "` CONVERT TO CHARACTER SET " . $charset . " COLLATE " . $collation );
static::$utf->query( "ALTER TABLE `" . static::$db->prefix . $name . "` DEFAULT CHARACTER SET " . $charset . " COLLATE " . $collation );
static::log( $name . " created from temp table." );
static::$utf->query( "REPLACE INTO `" . static::$db->prefix . $name . "` SELECT * FROM `" . static::$db->prefix . $name . "_temp`" );
static::log( $name . " data copied to new table." );
static::$utf->query( "DROP TABLE `" . static::$db->prefix . $name . "_temp`" );
static::log( $name . "_temp dropped" );
}
}
else
/* Let's try an alter first - below may not be necessary */
try
{
static::$utf->query( "ALTER TABLE `" . static::$db->prefix . $name . "` CONVERT TO CHARACTER SET " . $charset . " COLLATE " . $collation );
static::$utf->query( "ALTER TABLE `" . static::$db->prefix . $name . "` DEFAULT CHARACTER SET " . $charset . " COLLATE " . $collation );
}
catch( \IPSUtf8\Db\Exception $e )
{
/* Did not work - try the long way */
static::$utf->query( "RENAME TABLE `" . static::$db->prefix . $name . "` TO `" . static::$db->prefix . $name . "_temp`" );
static::log( $name . " has Unique Index - temp table created from main." );
/* Previously we used a raw create table query to create a copy, however this does not check index lengths. Leaving this for reference. */
//static::$utf->query( "CREATE TABLE `" . static::$db->prefix . $name . "` LIKE `" . static::$db->prefix . $name . "_temp`" );
static::$db->createTable( $this->checkTable( $tableData['definition'] ) );
static::$utf->query( "ALTER TABLE `" . static::$db->prefix . $name . "` CONVERT TO CHARACTER SET " . $charset . " COLLATE " . $collation );
static::$utf->query( "ALTER TABLE `" . static::$db->prefix . $name . "` DEFAULT CHARACTER SET " . $charset . " COLLATE " . $collation );
static::log( $name . " created from temp table." );
static::$utf->query( "REPLACE INTO `" . static::$db->prefix . $name . "` SELECT * FROM `" . static::$db->prefix . $name . "_temp`" );
static::log( $name . " data copied to new table." );
static::$utf->query( "DROP TABLE `" . static::$db->prefix . $name . "_temp`" );
static::log( $name . "_temp dropped" );
}
if ( count( $cols ) )
if ( \count( $cols ) )
{
foreach( $cols as $col )
{
@@ -1063,14 +1028,14 @@ class Convert
{
$colData = $tableData['definition']['columns'][ $col ];
$modify[] = " MODIFY `" . $col . "` " . $colData['type'] . ( ( is_numeric( $colData['length'] ) AND $colData['length'] > 0 ) ? "(" . $colData['length'] . ")" : '' ) . " CHARACTER SET " . $charset . " COLLATE " . $collation;
$modify[] = " MODIFY `" . $col . "` " . $colData['type'] . ( ( \is_numeric( $colData['length'] ) AND $colData['length'] > 0 ) ? "(" . $colData['length'] . ")" : '' ) . " CHARACTER SET " . $charset . " COLLATE " . $collation;
}
}
}
if ( count( $cols ) )
if ( \count( $cols ) )
{
if ( count( $modify ) )
if ( \count( $modify ) )
{
$query = "ALTER TABLE `" . static::$db->prefix . $name . "` " . implode( ',', $modify );
@@ -1078,7 +1043,7 @@ class Convert
static::$utf->query( $query );
}
if ( /*count( $modify ) and*/ count( $addIndexes ) )
if ( /*count( $modify ) and*/ \count( $addIndexes ) )
{
$query = "ALTER TABLE `" . static::$db->prefix . $name . "` " . implode( ',', $addIndexes );
@@ -1212,13 +1177,13 @@ class Convert
$nonUtf8Tables = array_keys( \IPSUtf8\Session::i()->tables );//$this->getNonUtf8Tables();
/* No table selected */
if ( is_array( $nonUtf8Tables ) and count( $nonUtf8Tables ) )
if ( \is_array( $nonUtf8Tables ) and \count( $nonUtf8Tables ) )
{
if ( is_array( \IPSUtf8\Session::i()->completed_json ) )
if ( \is_array( \IPSUtf8\Session::i()->completed_json ) )
{
$diff = array_diff( $nonUtf8Tables, array_keys( \IPSUtf8\Session::i()->completed_json ) );
if ( count( $diff ) )
if ( \count( $diff ) )
{
$table = \IPSUtf8\Session::i()->tables[ array_shift( $diff ) ];
}
@@ -1309,7 +1274,7 @@ class Convert
{
$thisLength = ( isset( $index['length'][ $i ] ) ) ? $index['length'][ $i ] : ( ( (int) $definition['columns'][ $column ]['length'] or empty( $definition['columns'][ $column ]['length'] ) ) ? $definition['columns'][ $column ]['length'] : 250 );
$isText = in_array( mb_strtolower( $definition['columns'][ $column ]['type'] ), array( 'mediumtext', 'text' ) );
$isText = \in_array( mb_strtolower( $definition['columns'][ $column ]['type'] ), array( 'mediumtext', 'text' ) );
if ( $hasText === false and $isText === true )
{
@@ -1328,7 +1293,7 @@ class Convert
{
$thisLength = ( isset( $index['length'][ $i ] ) ) ? $index['length'][ $i ] : ( (int) $definition['columns'][ $column ]['length'] ? $definition['columns'][ $column ]['length'] : 250 );
if ( isset( $definition['columns'][ $column ] ) and ( ( ! empty( $thisLength ) or in_array( mb_strtolower( $definition['columns'][ $column ]['type'] ), array( 'mediumtext', 'text' ) ) ) ) )
if ( isset( $definition['columns'][ $column ] ) and ( ( ! empty( $thisLength ) or \in_array( mb_strtolower( $definition['columns'][ $column ]['type'] ), array( 'mediumtext', 'text' ) ) ) ) )
{
/* Column name, column length, column type */
$needsFixing[ $key ][ $i ] = array( $column, $thisLength, $definition['columns'][ $column ]['type'] );
@@ -1340,7 +1305,7 @@ class Convert
}
}
if ( count( $needsFixing ) )
if ( \count( $needsFixing ) )
{
foreach( $needsFixing as $key => $i )
{
@@ -1362,7 +1327,7 @@ class Convert
/* Apply debt if we have any. We do not reduce integers */
foreach( $i as $x => $vals )
{
if ( in_array( mb_strtoupper( $vals[2] ), array_keys( static::$numericCols ) ) )
if ( \in_array( mb_strtoupper( $vals[2] ), array_keys( static::$numericCols ) ) )
{
$debt += $vals[1];
}
@@ -1382,7 +1347,7 @@ class Convert
$vals[1] = 250;
}
if ( in_array( mb_strtoupper( $vals[2] ), array_keys( static::$numericCols ) ) )
if ( \in_array( mb_strtoupper( $vals[2] ), array_keys( static::$numericCols ) ) )
{
/* Preserve col len where possible but if the column length is greater than subpart allowed, NULL the length
otherwise MySQL will complain as you cannot use subpart on non-string column. */
@@ -1402,9 +1367,9 @@ class Convert
foreach( $i as $x => $vals )
{
if ( in_array( mb_strtolower( $vals[2] ), static::$convertCols ) AND $definition['columns'][ $definition['indexes'][ $key ]['columns'][ $x ] ]['length'] != $vals[1] )
if ( \in_array( mb_strtolower( $vals[2] ), static::$convertCols ) AND $definition['columns'][ $definition['indexes'][ $key ]['columns'][ $x ] ]['length'] != $vals[1] )
{
$definition['indexes'][ $key ]['length'][ $x ] = intval( $vals[1] );
$definition['indexes'][ $key ]['length'][ $x ] = \intval( $vals[1] );
}
else
{
@@ -1503,7 +1468,7 @@ class Convert
foreach( $table['definition']['columns'] as $col => $val )
{
if ( in_array( mb_strtolower( $val['type'] ), array( 'mediumtext', 'text' ) ) )
if ( \in_array( mb_strtolower( $val['type'] ), array( 'mediumtext', 'text' ) ) )
{
return true;
}
@@ -1529,7 +1494,7 @@ class Convert
{
$total++;
if ( in_array( mb_strtolower( $val['type'] ), array( 'varchar' ) ) )
if ( \in_array( mb_strtolower( $val['type'] ), array( 'varchar' ) ) )
{
$var++;
}
@@ -1580,7 +1545,7 @@ class Convert
/* Best check the tables, then */
$json = \IPSUtf8\Session::i()->json;
if ( count( $this->getNonUtf8Tables() ) )
if ( \count( $this->getNonUtf8Tables() ) )
{
$yeahProbably = false;
}
@@ -1651,7 +1616,7 @@ class Convert
foreach( array_keys( \IPSUtf8\Session::i()->tables ) as $table )
{
static::$rowsToConvert += intval( \IPSUtf8\Session::i()->tables[ $table ]['count'] );
static::$rowsToConvert += \intval( \IPSUtf8\Session::i()->tables[ $table ]['count'] );
}
}
@@ -1673,7 +1638,7 @@ class Convert
foreach( \IPSUtf8\Session::i()->tables as $table => $definition )
{
/* If the table itself is not utf8_unicode_ci, don't bother check columns */
if ( $definition['definition']['collation'] AND !in_array( $definition['definition']['collation'], array( 'utf8_unicode_ci', 'utf8mb4_unicode_ci' ) ) )
if ( $definition['definition']['collation'] AND !\in_array( $definition['definition']['collation'], array( 'utf8_unicode_ci', 'utf8mb4_unicode_ci' ) ) )
{
static::$nonUtf8Collations[] = $table;
continue;
@@ -1681,7 +1646,7 @@ class Convert
foreach( $definition['definition']['columns'] as $name => $column )
{
if ( $column['collation'] and ! in_array( $column['collation'], array( 'utf8_unicode_ci', 'utf8mb4_unicode_ci' ) ) )
if ( $column['collation'] and ! \in_array( $column['collation'], array( 'utf8_unicode_ci', 'utf8mb4_unicode_ci' ) ) )
{
static::$nonUtf8Collations[] = $table;
break;
@@ -1712,10 +1677,10 @@ class Convert
foreach( $json['charSets'] as $charSet => $tablesArray )
{
$data[] = count( $tablesArray ) . ' tables are ' . $charSet;
$data[] = \count( $tablesArray ) . ' tables are ' . $charSet;
}
$data[] = count( $this->getNonUtf8CollationTables() ) . " tables have incorrect collations";
$data[] = \count( $this->getNonUtf8CollationTables() ) . " tables have incorrect collations";
$data[] = "Can use 'dump' method: " . var_export( $this->canDump(), true );
return $data;
@@ -1771,7 +1736,7 @@ class Convert
*/
public static function getNumericColumns( $name )
{
if ( ! is_string( $name ) )
if ( ! \is_string( $name ) )
{
return false;
}
@@ -1781,7 +1746,7 @@ class Convert
foreach( $table['definition']['columns'] as $col => $val )
{
if ( in_array( mb_strtolower( $val['type'] ), static::$numericCols ) )
if ( \in_array( mb_strtolower( $val['type'] ), static::$numericCols ) )
{
$return[] = $val['name'];
}
@@ -1798,7 +1763,7 @@ class Convert
*/
public static function getConvertableColumns( $name )
{
if ( ! is_string( $name ) )
if ( ! \is_string( $name ) )
{
return false;
}
@@ -1808,7 +1773,7 @@ class Convert
foreach( $table['definition']['columns'] as $col => $val )
{
if ( in_array( mb_strtolower( $val['type'] ), static::$convertCols ) )
if ( \in_array( mb_strtolower( $val['type'] ), static::$convertCols ) )
{
$return[] = $val['name'];
}
@@ -1840,7 +1805,7 @@ class Convert
if (
( $tablesOk ) AND
( \IPSUtf8\Session::i()->current_charset == 'utf-8' or \IPSUtf8\Session::i()->current_charset == 'iso-8859-1' ) AND
( ( is_callable( 'exec' ) AND false === stripos( ini_get( 'disable_functions' ), 'exec' ) ) )
( ( \is_callable( 'exec' ) AND false === stripos( ini_get( 'disable_functions' ), 'exec' ) ) )
)
{
try
@@ -1852,7 +1817,7 @@ class Convert
return false;
}
if ( ! array( $output ) or ! count( $output ) or ( ! stristr( implode( "\n", $output ), 'latin' ) ) )
if ( ! array( $output ) or ! \count( $output ) or ( ! stristr( implode( "\n", $output ), 'latin' ) ) )
{
return false;
}
+43 -49
View File
@@ -100,7 +100,7 @@ class Db extends \mysqli
}
/* Connect */
$classname = get_called_class();
$classname = \get_called_class();
self::$multitons[ $identifier ] = @new $classname(
$connectionSettings['sql_host'],
$connectionSettings['sql_user'],
@@ -287,7 +287,7 @@ class Db extends \mysqli
foreach ( $binds as $bindVal )
{
$i++;
switch ( gettype( $bindVal ) )
switch ( \gettype( $bindVal ) )
{
case 'boolean':
case 'integer':
@@ -356,7 +356,7 @@ class Db extends \mysqli
/* Bind values */
if( $bind->haveBinds() === TRUE )
{
call_user_func_array( array( $stmt, 'bind_param' ), $bind->get() );
$stmt->bind_param( ...$bind->get() );
}
/* Execute */
@@ -372,7 +372,6 @@ class Db extends \mysqli
}
const SELECT_DISTINCT = 1;
const SELECT_SQL_CALC_FOUND_ROWS = 2;
/**
* Build SELECT statement
@@ -386,7 +385,6 @@ class Db extends \mysqli
* @param array|string|NULL $having HAVING clause (same format as WHERE clause)
* @param int $flags Bitwise flags
* @li \IPSUtf8\Db::SELECT_DISTINCT Will use SELECT DISTINCT
* @li \IPSUtf8\DB::SELECT_SQL_CALC_FOUND_ROWS Will add SQL_CALC_FOUND_ROWS
* @return \IPSUtf8\Db\Select
*
*/
@@ -400,13 +398,9 @@ class Db extends \mysqli
{
$query .= 'DISTINCT ';
}
if ( $flags & static::SELECT_SQL_CALC_FOUND_ROWS )
{
$query .= 'SQL_CALC_FOUND_ROWS ';
}
/* Columns */
if ( is_string( $columns ) )
if ( \is_string( $columns ) )
{
$query .= $columns;
}
@@ -419,7 +413,7 @@ class Db extends \mysqli
}
/* Tables */
if ( is_array( $table ) )
if ( \is_array( $table ) )
{
$query .= " FROM `{$this->prefix}{$table[0]}` AS `{$table[1]}`";
}
@@ -530,7 +524,7 @@ class Db extends \mysqli
/* Is this just one row? */
foreach ( $set as $k => $v )
{
if ( !is_array( $v ) )
if ( !\is_array( $v ) )
{
$set = array( $set );
}
@@ -548,7 +542,7 @@ class Db extends \mysqli
$columns = array_map( function( $val ){ return "`{$val}`"; }, array_keys( $row ) );
}
if ( count( $set ) > 1 AND $bulkInsertNoPrep )
if ( \count( $set ) > 1 AND $bulkInsertNoPrep )
{
if ( $tableDefinition === NULL )
{
@@ -559,7 +553,7 @@ class Db extends \mysqli
{
if ( isset( $tableDefinition['definition']['columns'][ $k ] ) )
{
$isInt = in_array( \mb_strtolower( $tableDefinition['definition']['columns'][ $k ]['type'] ), array( 'integer', 'int', 'smallint', 'tinyint', 'mediumint', 'bigint', 'decimal', 'numeric', 'float', 'double' ) );
$isInt = \in_array( \mb_strtolower( $tableDefinition['definition']['columns'][ $k ]['type'] ), array( 'integer', 'int', 'smallint', 'tinyint', 'mediumint', 'bigint', 'decimal', 'numeric', 'float', 'double' ) );
if ( $isInt )
{
@@ -616,7 +610,7 @@ class Db extends \mysqli
else
{
$binds = array_merge( $binds, array_values( $row ) );
$values[] = '( ' . implode( ', ', array_fill( 0, count( $columns ), '?' ) ) . ' )';
$values[] = '( ' . implode( ', ', array_fill( 0, \count( $columns ), '?' ) ) . ' )';
}
}
@@ -631,7 +625,7 @@ class Db extends \mysqli
}
/* Run */
if ( count( $set ) > 1 AND $bulkInsertNoPrep )
if ( \count( $set ) > 1 AND $bulkInsertNoPrep )
{
$stmt = $this->query( $query );
return $this->insert_id;
@@ -655,7 +649,7 @@ class Db extends \mysqli
public function replace( $table, $set )
{
$columns = implode( ', ', array_map( function( $val ){ return "`{$val}`"; }, array_keys( $set ) ) );
$query = "REPLACE INTO `{$this->prefix}{$table}` ( " . $columns . " ) VALUES ( " . implode( ', ', array_fill( 0, count( $set ), '?' ) ) . " )";
$query = "REPLACE INTO `{$this->prefix}{$table}` ( " . $columns . " ) VALUES ( " . implode( ', ', array_fill( 0, \count( $set ), '?' ) ) . " )";
$stmt = $this->preparedQuery( $query, array_values( $set ) );
return $stmt->affected_rows;
@@ -678,13 +672,13 @@ class Db extends \mysqli
$binds = array();
/* Work out table */
$table = is_array( $table ) ? "`{$this->prefix}{$table[0]}` {$this->prefix}{$table[1]}" : "`{$this->prefix}{$table}`";
$table = \is_array( $table ) ? "`{$this->prefix}{$table[0]}` {$this->prefix}{$table[1]}" : "`{$this->prefix}{$table}`";
/* Work out joins */
foreach ( $joins as $join )
{
$type = ( isset( $join['type'] ) and in_array( strtoupper( $join['type'] ), array( 'LEFT', 'INNER', 'RIGHT' ) ) ) ? strtoupper( $join['type'] ) : 'LEFT';
$_table = is_array( $join['from'] ) ? "`{$this->prefix}{$join['from'][0]}` {$this->prefix}{$join['from'][1]}" : $join['from'];
$type = ( isset( $join['type'] ) and \in_array( strtoupper( $join['type'] ), array( 'LEFT', 'INNER', 'RIGHT' ) ) ) ? strtoupper( $join['type'] ) : 'LEFT';
$_table = \is_array( $join['from'] ) ? "`{$this->prefix}{$join['from'][0]}` {$this->prefix}{$join['from'][1]}" : $join['from'];
$on = $this->compileWhereClause( $join['where'] );
$binds = array_merge( $binds, $on['binds'] );
@@ -694,7 +688,7 @@ class Db extends \mysqli
$joins = empty( $joins ) ? '' : ( ' ' . implode( "\n", $joins ) );
/* Work out SET clause */
if ( is_array( $set ) )
if ( \is_array( $set ) )
{
$_set = array();
foreach ( $set as $k => $v )
@@ -782,13 +776,13 @@ class Db extends \mysqli
{
$return = array( 'clause' => '1=1', 'binds' => array() );
if( is_string( $data ) )
if( \is_string( $data ) )
{
$return['clause'] = $data;
}
elseif ( is_array( $data ) and ! empty( $data ) )
elseif ( \is_array( $data ) and ! empty( $data ) )
{
if ( is_string( $data[0] ) )
if ( \is_string( $data[0] ) )
{
$data = array( $data );
}
@@ -796,7 +790,7 @@ class Db extends \mysqli
$clauses = array();
foreach ( $data as $bit )
{
if( !is_array( $bit ) )
if( !\is_array( $bit ) )
{
$clauses[] = $bit;
}
@@ -822,14 +816,14 @@ class Db extends \mysqli
protected function compileLimitClause( $data )
{
$limit = NULL;
if( is_array( $data ) )
if( \is_array( $data ) )
{
$offset = intval( $data[0] );
$limit = intval( $data[1] );
$offset = \intval( $data[0] );
$limit = \intval( $data[1] );
}
else
{
$offset = intval( $data );
$offset = \intval( $data );
}
if( $limit !== NULL )
@@ -875,18 +869,18 @@ class Db extends \mysqli
/* Some types specify length */
if(
in_array( $data['type'], array( 'VARCHAR', 'VARBINARY' ) )
\in_array( $data['type'], array( 'VARCHAR', 'VARBINARY' ) )
or
(
isset( $data['length'] ) and $data['length']
and
in_array( $data['type'], array( 'BIT', 'TINYINT', 'SMALLINT', 'MEDIUMINT', 'INT', 'INTEGER', 'BIGINT', 'REAL', 'DOUBLE', 'FLOAT', 'DECIMAL', 'NUMERIC', 'CHAR', 'BINARY' ) )
\in_array( $data['type'], array( 'BIT', 'TINYINT', 'SMALLINT', 'MEDIUMINT', 'INT', 'INTEGER', 'BIGINT', 'REAL', 'DOUBLE', 'FLOAT', 'DECIMAL', 'NUMERIC', 'CHAR', 'BINARY' ) )
)
) {
$definition .= "({$data['length']}";
/* And some of those specify decimals (which may or may not be optional) */
if( in_array( $data['type'], array( 'REAL', 'DOUBLE', 'FLOAT' ) ) or ( in_array( $data['type'], array( 'DECIMAL', 'NUMERIC' ) ) and isset( $data['decimals'] ) ) )
if( \in_array( $data['type'], array( 'REAL', 'DOUBLE', 'FLOAT' ) ) or ( \in_array( $data['type'], array( 'DECIMAL', 'NUMERIC' ) ) and isset( $data['decimals'] ) ) )
{
$definition .= ',' . $data['decimals'];
}
@@ -895,7 +889,7 @@ class Db extends \mysqli
}
/* Numeric types can be UNSIGNED and ZEROFILL */
if( in_array( $data['type'], array( 'TINYINT', 'SMALLINT', 'MEDIUMINT', 'INT', 'INTEGER', 'BIGINT', 'REAL', 'DOUBLE', 'FLOAT', 'DECIMAL', 'NUMERIC' ) ) )
if( \in_array( $data['type'], array( 'TINYINT', 'SMALLINT', 'MEDIUMINT', 'INT', 'INTEGER', 'BIGINT', 'REAL', 'DOUBLE', 'FLOAT', 'DECIMAL', 'NUMERIC' ) ) )
{
if( isset( $data['unsigned'] ) and $data['unsigned'] === TRUE )
{
@@ -908,7 +902,7 @@ class Db extends \mysqli
}
/* ENUM and SETs have values */
if( in_array( $data['type'], array( 'ENUM', 'SET' ) ) )
if( \in_array( $data['type'], array( 'ENUM', 'SET' ) ) )
{
$values = array();
foreach ( $data['values'] as $v )
@@ -920,13 +914,13 @@ class Db extends \mysqli
}
/* Some types can be binary or not */
if( isset( $data['binary'] ) and $data['binary'] === TRUE and in_array( $data['type'], array( 'CHAR', 'VARCHAR', 'TINYTEXT', 'TEXT', 'MEDIUMTEXT', 'LONGTEXT' ) ) )
if( isset( $data['binary'] ) and $data['binary'] === TRUE and \in_array( $data['type'], array( 'CHAR', 'VARCHAR', 'TINYTEXT', 'TEXT', 'MEDIUMTEXT', 'LONGTEXT' ) ) )
{
$definition .= 'BINARY ';
}
/* Text types specify a character set and collation */
if( in_array( $data['type'], array( 'CHAR', 'VARCHAR', 'TINYTEXT', 'TEXT', 'MEDIUMTEXT', 'LONGTEXT', 'ENUM', 'SET' ) ) )
if( \in_array( $data['type'], array( 'CHAR', 'VARCHAR', 'TINYTEXT', 'TEXT', 'MEDIUMTEXT', 'LONGTEXT', 'ENUM', 'SET' ) ) )
{
$definition .= "CHARACTER SET {$this->charset} COLLATE {$this->collation} ";
}
@@ -942,13 +936,13 @@ class Db extends \mysqli
}
/* Default value */
if( isset( $data['default'] ) and !in_array( $data['type'], array( 'TINYTEXT', 'TEXT', 'MEDIUMTEXT', 'LONGTEXT', 'BLOB', 'MEDIUMBLOB', 'BIGBLOB' ) ) )
if( isset( $data['default'] ) and !\in_array( $data['type'], array( 'TINYTEXT', 'TEXT', 'MEDIUMTEXT', 'LONGTEXT', 'BLOB', 'MEDIUMBLOB', 'BIGBLOB' ) ) )
{
$defaultValue = in_array( $data['type'], array( 'TINYINT', 'SMALLINT', 'MEDIUMINT', 'INT', 'INTEGER', 'BIGINT', 'REAL', 'DOUBLE', 'FLOAT', 'DECIMAL', 'NUMERIC', 'BIT' ) ) ? floatval( $data['default'] ) : ( ! in_array( $data['default'], array( 'CURRENT_TIMESTAMP' ) ) ? '\'' . $this->escape_string( $data['default'] ) . '\'' : $data['default'] );
$defaultValue = \in_array( $data['type'], array( 'TINYINT', 'SMALLINT', 'MEDIUMINT', 'INT', 'INTEGER', 'BIGINT', 'REAL', 'DOUBLE', 'FLOAT', 'DECIMAL', 'NUMERIC', 'BIT' ) ) ? \floatval( $data['default'] ) : ( ! \in_array( $data['default'], array( 'CURRENT_TIMESTAMP' ) ) ? '\'' . $this->escape_string( $data['default'] ) . '\'' : $data['default'] );
/* Strict Mode isn't nice */
$toTest = trim( $defaultValue, "'" );
if ( in_array( $data['type'], array( 'DATETIME' ) ) AND empty( $toTest ) ) # array here in case we need to expand later
if ( \in_array( $data['type'], array( 'DATETIME' ) ) AND empty( $toTest ) ) # array here in case we need to expand later
{
$defaultValue = '\'0000-00-00 00:00:00\'';
}
@@ -1030,7 +1024,7 @@ class Db extends \mysqli
$definition .= '(' . implode( ',', array_map( function ( $val, $len )
{
return ( ! empty( $len ) ) ? "`{$val}`({$len})" : "`{$val}`";
}, $data['columns'], ( ( isset( $data['length'] ) AND is_array( $data['length'] ) ) ? $data['length'] : array_fill( 0, count( $data['columns'] ), null ) ) ) ) . ')';
}, $data['columns'], ( ( isset( $data['length'] ) AND \is_array( $data['length'] ) ) ? $data['length'] : array_fill( 0, \count( $data['columns'] ), null ) ) ) ) . ')';
/* Return */
return $definition;
@@ -1199,7 +1193,7 @@ class Db extends \mysqli
{
return '`' . $prefix . $val . '`';
},
( is_array( $table ) ? $table : array( $table ) )
( \is_array( $table ) ? $table : array( $table ) )
) )
);
}
@@ -1260,10 +1254,10 @@ class Db extends \mysqli
else
{
$lengthInfo = explode( ',', $matches[2] );
$columnDefinition['length'] = intval( $lengthInfo[0] );
$columnDefinition['length'] = \intval( $lengthInfo[0] );
if( isset( $lengthInfo[1] ) )
{
$columnDefinition['decimals'] = intval( $lengthInfo[1] );
$columnDefinition['decimals'] = \intval( $lengthInfo[1] );
}
}
}
@@ -1276,10 +1270,10 @@ class Db extends \mysqli
}
/* unsigned? */
$columnDefinition['unsigned'] = in_array( 'unsigned', $typeInfo );
$columnDefinition['unsigned'] = \in_array( 'unsigned', $typeInfo );
/* zerofill? */
$columnDefinition['zerofill'] = in_array( 'zerofill', $typeInfo );
$columnDefinition['zerofill'] = \in_array( 'zerofill', $typeInfo );
/* binary? */
$columnDefinition['binary'] = ( $row['Collation'] === $this->binaryCollation );
@@ -1313,7 +1307,7 @@ class Db extends \mysqli
$query = $this->query( "SHOW INDEXES FROM `{$this->prefix}{$table}`" );
while ( $row = $query->fetch_assoc() )
{
$length = ( isset( $row['Sub_part'] ) AND ! empty( $row['Sub_part'] ) ) ? intval( $row['Sub_part'] ) : null;
$length = ( isset( $row['Sub_part'] ) AND ! empty( $row['Sub_part'] ) ) ? \intval( $row['Sub_part'] ) : null;
if( isset( $indexes[ $row['Key_name'] ] ) )
{
@@ -1499,11 +1493,11 @@ class Db extends \mysqli
foreach( $values as $i )
{
if ( $i and is_numeric( $i ) )
if ( $i and \is_numeric( $i ) )
{
$where[] = "FIND_IN_SET(" . $i . "," . $column . ")";
}
else if ( $i and is_string( $i ) )
else if ( $i and \is_string( $i ) )
{
$in[] = "'" . $this->real_escape_string( $i ) . "'";
}
@@ -1521,7 +1515,7 @@ class Db extends \mysqli
$return[] = $column . ' IN(' . implode( ',', $in ) . ')';
}
if ( count( $return ) )
if ( \count( $return ) )
{
return '(' . implode( ' OR ', $return ) . ')';
}
+1 -1
View File
@@ -52,7 +52,7 @@ class Exception extends \RuntimeException
public function shouldSendDiagnosticsReport()
{
/* Low-end server errors */
if ( $this->getCode() < 1046 or in_array( $this->getCode(), array( 1129, 1130, 1194, 1195, 1203 ) ) )
if ( $this->getCode() < 1046 or \in_array( $this->getCode(), array( 1129, 1130, 1194, 1195, 1203 ) ) )
{
return FALSE;
}
+7 -16
View File
@@ -84,7 +84,7 @@ class Select implements \Iterator, \Countable
break;
}
if ( is_array( $table ) )
if ( \is_array( $table ) )
{
$query .= " `{$this->db->prefix}{$table[0]}` AS `{$table[1]}`";
}
@@ -147,7 +147,7 @@ class Select implements \Iterator, \Countable
$this->rewind();
}
if ( !in_array( $column, $this->columns ) )
if ( !\in_array( $column, $this->columns ) )
{
throw new \InvalidArgumentException;
}
@@ -170,7 +170,7 @@ class Select implements \Iterator, \Countable
$this->rewind();
}
if ( !in_array( $column, $this->columns ) )
if ( !\in_array( $column, $this->columns ) )
{
throw new \InvalidArgumentException;
}
@@ -225,7 +225,7 @@ class Select implements \Iterator, \Countable
$params[] = &$this->row[ $field->name ];
}
$this->columns = array_keys( $this->row );
call_user_func_array( array( $this->stmt, 'bind_result' ), $params );
$this->stmt->bind_result( ...$params );
/* Get the first result */
$this->key = -1;
@@ -243,7 +243,7 @@ class Select implements \Iterator, \Countable
{
return $this->row[ $this->valueField ];
}
elseif ( count( $this->row ) === 1 )
elseif ( \count( $this->row ) === 1 )
{
foreach ( $this->row as $v )
{
@@ -305,24 +305,15 @@ class Select implements \Iterator, \Countable
/**
* [Countable] Get number of rows
*
* @param bool $allRows If TRUE, will get the number of rows ignoring the limit. In order for this to work, the query must have been ran with SQL_CALC_FOUND_ROWS
* @return int
*/
public function count( $allRows = FALSE )
public function count()
{
if ( !$this->stmt )
{
$this->rewind();
}
if ( $allRows )
{
$result = $this->db->query( 'SELECT FOUND_ROWS() AS count;' )->fetch_assoc();
return $result['count'];
}
else
{
return $this->stmt->num_rows;
}
return $this->stmt->num_rows;
}
}
@@ -31,7 +31,7 @@ abstract class Controller
if ( $method !== NULL AND method_exists( $this, $method ) )
{
call_user_func( array( $this, $method ) );
$this->$method();
}
else
{
@@ -39,7 +39,7 @@ abstract class Dispatcher
{
if( self::$instance === NULL )
{
$classname = get_called_class();
$classname = \get_called_class();
if ( $classname === 'IPSUtf8\Dispatcher' )
{
self::$instance = new \IPSUtf8\Dispatcher\Browser;
@@ -18,7 +18,7 @@ class Template
public static function wrapper( $title="IPS Converter", $content="", $isError=false )
{
$iniTime = @ini_get('max_execution_time');
$execTime = ( is_numeric( $iniTime ) ) ? $iniTime : 30;
$execTime = ( \is_numeric( $iniTime ) ) ? $iniTime : 30;
$url = \IPSUtf8\Output\Browser::$url;
$title = ( empty( $title ) ) ? 'IPS Converter' : $title;
$active = array( 'convert' => '', 'tools' => '', 'archive' => '' );
@@ -191,7 +191,7 @@ EOFHTML;
<br>To override this and unlock the UTF8 converter, please create a file called "constants.php" and upload it to your /admin/convertutf8/ directory with the following contents:
</p>
<p><textarea class="form-control" style="height:90px;">&lt;?php
define( 'BYPASS_SAFETY_LOCK', true );
\\define( 'BYPASS_SAFETY_LOCK', true );
</textarea>
</p>
@@ -212,7 +212,7 @@ EOFHTML;
$canUseMb4 = ( version_compare( \IPSUtf8\Db::i()->server_info, '5.5.3', '>=' ) AND \IPSUtf8\Db::i('utf8')->set_charset('utf8mb4') !== FALSE );
\IPSUtf8\Db::i('utf8')->set_charset( $origUtf8Charset );
$badCollations = $convertClass::i()->getNonUtf8CollationTables();
$badTablesCnt = count( $convertClass::i()->getNonUtf8Tables() );
$badTablesCnt = \count( $convertClass::i()->getNonUtf8Tables() );
$path = ROOT_PATH;
$dbCharSetIsCorrect = TRUE;
$isUtf8mb4 = ( $isUtf8 === TRUE AND \IPSUtf8\Convert::i()->database_charset == 'utf8mb4' );
@@ -220,7 +220,7 @@ EOFHTML;
if ( file_exists( ROOT_PATH . '/conf_global.php' ) )
{
require_once( ROOT_PATH . '/conf_global.php' );
if ( !isset( $INFO['sql_charset'] ) OR ! in_array( $INFO['sql_charset'], array( 'utf8', 'utf8mb4' ) ) )
if ( !isset( $INFO['sql_charset'] ) OR ! \in_array( $INFO['sql_charset'], array( 'utf8', 'utf8mb4' ) ) )
{
$dbCharSetIsCorrect = FALSE;
}
@@ -257,9 +257,9 @@ EOFHTML;
}
else if ( $isUtf8 === true )
{
if ( count( $badCollations ) )
if ( \count( $badCollations ) )
{
$cnt = count( $badCollations );
$cnt = \count( $badCollations );
$html .= <<<EOFHTML
<p class="text-info">
The database is set to UTF-8, however {$cnt} table(s) have incorrect collations and need fixing.
@@ -282,33 +282,21 @@ EOFHTML;
}
if ( ! $isUtf8 and $canUseMb4 )
{
$buttonLabel = ( $isUtf8 ) ? "Convert anyway using 4-Byte UTF-8 (utf8mb4)" : "Start using 4-Byte UTF-8 (utf8mb4)";
{
$text = ( $status === 'processing' ) ? "Continue Conversion" : "Begin Conversion";
$html .= <<<EOFHTML
<p>
<a data-status="Start" class="btn btn-lg btn-info" href="{url="?controller={$controller}&amp;do=process&use_utf8mb4=1"}">{$buttonLabel}</a>
<br />
<div class='small'>
<small>
Some non-common symbols (such as historical scripts, music symbols and Emoji) require more space in the database to be stored. If you choose to convert using 4-Byte UTF-8, these characters will be able to be used, but the database will use more disk space.
</small>
</div>
<a data-status="{$status}" class="btn btn-lg btn-info" href="{url="?controller={$controller}&amp;do=process&use_utf8mb4=1"}">{$text}</a>
</p>
EOFHTML;
}
if ( ! $isUtf8 )
if ( ! $isUtf8 and !$canUseMb4 )
{
$label = 'Start using UTF-8 (utf8)';
$label = 'Start using UTF-8 (utf8)';
$selector = 'btn-success';
$more = <<<EOFHTML
<br />
<div class='small'>
<small>
Choose this if you don't wish to store non-common symbols (such as historical scripts, music symbols and Emoji) and wish to use less disk space.
</small>
</div>
<br>
<div class='small'>
<small>
@@ -336,11 +324,11 @@ if ( $status === 'processing' )
}
else if ( ! $isUtf8 )
{
$label = "Convert as UTF-8 (utf8)";
$label = "Begin Conversion";
$selector = 'btn-info';
}
if ( $label and $selector )
if ( $label and $selector AND ! $isUtf8 and ! $canUseMb4 )
{
$html .= <<<EOFHTML
<p>
+1 -1
View File
@@ -35,7 +35,7 @@ abstract class Output
{
if( static::$instance === NULL )
{
$classname = get_called_class();
$classname = \get_called_class();
static::$instance = new $classname;
}
@@ -24,7 +24,7 @@ class Singleton implements \Iterator
{
if( static::$instance === NULL )
{
$classname = get_called_class();
$classname = \get_called_class();
static::$instance = new $classname;
}
+1 -7
View File
@@ -103,7 +103,7 @@ class Request extends \IPSUtf8\Patterns\Singleton
{
foreach( $data as $k => $v )
{
if ( is_array( $v ) )
if ( \is_array( $v ) )
{
array_walk_recursive( $v, array( $this, 'clean' ) );
}
@@ -127,12 +127,6 @@ class Request extends \IPSUtf8\Patterns\Singleton
{
/* Remove NULL bytes and the RTL control byte */
$v = str_replace( array( "\0", "\u202E" ), '', $v );
/* Undo magic quote madness */
if ( get_magic_quotes_gpc() === 1 )
{
$v = stripslashes( $v );
}
}
/**
+11 -8
View File
@@ -361,7 +361,7 @@ class Session
$allTables = array();
$data = array( 'version' => \IPSUtf8\Convert::VERSION_ID, 'tableCount' => 0, 'totalCount' => 0, 'convertedCount' => 0, 'charSets' => array() );
if ( defined( 'FORCE_CONVERT' ) AND FORCE_CONVERT === TRUE )
if ( \defined( 'FORCE_CONVERT' ) AND FORCE_CONVERT === TRUE )
{
$data['force_conversion'] = 1;
}
@@ -406,7 +406,7 @@ class Session
foreach( $tables as $table )
{
/* Get count */
$row = \IPSUtf8\Db::i()->query( "SELECT COUNT(*) as count FROM `" . \IPSUtf8\Db::i()->prefix . "{$table}`" )->fetch_assoc();
$row = \IPSUtf8\Db::i()->query( "SELECT count(*) as count FROM `" . \IPSUtf8\Db::i()->prefix . "{$table}`" )->fetch_assoc();
$count = $row['count'];
$data['totalCount'] += $count;
@@ -485,6 +485,9 @@ class Session
'count' => $count,
'charset' => $tblCharset
);
/* Ping the UTF8 connection just in case this process takes a while, so that connection doesn't die on us */
\IPSUtf8\Db::i('utf8')->ping();
}
return array( 'tables' => $allTables, 'data' => $data );
@@ -513,7 +516,7 @@ class Session
if( isset( $this->_data[ $key ] ) )
{
if ( mb_substr( $key, -5 ) == '_json' AND ! is_array( $this->_data[ $key ] ) )
if ( mb_substr( $key, -5 ) == '_json' AND ! \is_array( $this->_data[ $key ] ) )
{
$this->_data[ $key ] = json_decode( $this->_data[ $key ], true );
}
@@ -606,19 +609,19 @@ class Session
/* JSON encode if required */
foreach ( array_merge( $this->_data, $this->changed ) as $k => $v )
{
$insert[ $k ] = ( mb_substr( $k, -5 ) == '_json' AND is_array( $v ) ) ? json_encode( $v, true ) : $v;
$insert[ $k ] = ( mb_substr( $k, -5 ) == '_json' AND \is_array( $v ) ) ? json_encode( $v, true ) : $v;
}
}
else
{
foreach ( $this->_data as $k => $v )
{
$insert[ $k ] = ( mb_substr( $k, -5 ) == '_json' AND is_array( $v ) ) ? json_encode( $v, true ) : $v;
$insert[ $k ] = ( mb_substr( $k, -5 ) == '_json' AND \is_array( $v ) ) ? json_encode( $v, true ) : $v;
}
}
/* Save */
if ( count( $insert ) == count( static::$sessionTableColumns ) )
if ( \count( $insert ) == \count( static::$sessionTableColumns ) )
{
\IPSUtf8\Db::i('utf8')->update( 'convert_session', $insert );
}
@@ -637,14 +640,14 @@ class Session
*/
public function arrayWalkRecursive( $array, $callback )
{
if ( ! is_array( $array ) )
if ( ! \is_array( $array ) )
{
trigger_error( "\$array is not an array in \IPSUtf8\Session::arrayWalkRecursive()", E_USER_ERROR );
}
foreach( $array AS $key => $value )
{
if ( is_array( $array[$key] ) )
if ( \is_array( $array[$key] ) )
{
$array[$key] = static::arrayWalkRecursive( $array[$key], $callback );
}
+4 -4
View File
@@ -51,15 +51,15 @@ abstract class Charset
/* Try and pick best available */
if ( FORCE_CONVERT_METHOD === NULL )
{
if ( function_exists( 'mb_convert_encoding' ) )
if ( \function_exists( 'mb_convert_encoding' ) )
{
self::$method = 'mb';
}
else if ( function_exists( 'iconv' ) )
else if ( \function_exists( 'iconv' ) )
{
self::$method = 'iconv';
}
else if ( function_exists( 'recode_string' ) )
else if ( \function_exists( 'recode_string' ) )
{
self::$method = 'recode';
}
@@ -103,7 +103,7 @@ abstract class Charset
$to = strtolower($to);
/* Return bools, null, ints, etc. */
if ( ! is_string( $string ) )
if ( ! \is_string( $string ) )
{
return false;
}
@@ -30,7 +30,7 @@ class Iconv extends \IPSUtf8\Text\Charset
return $string;
}
if ( function_exists( 'iconv' ) )
if ( \function_exists( 'iconv' ) )
{
$text = iconv( $from, $to.'//TRANSLIT', $string );
}
@@ -79,7 +79,7 @@ class Internal extends \IPSUtf8\Text\Charset
$charsetTable = $charsetTables[ $from ];
if( !count($charsetTable) )
if( !\count($charsetTable) )
{
static::$errors[] = "Character set table not found";
return $original;
@@ -92,7 +92,7 @@ class Internal extends \IPSUtf8\Text\Charset
{
$hexChar = "";
$unicodeHexChar = "";
$hexChar = strtoupper(dechex(ord($string[$i])));
$hexChar = strtoupper(dechex(\ord($string[$i])));
// This is fix from Mario Klingemann, it prevents
// droping chars below 16 because of missing leading 0 [zeros]
@@ -106,17 +106,17 @@ class Internal extends \IPSUtf8\Text\Charset
if ( ( $from == "gsm0338" ) && ( $hexChar == '1B' ) )
{
$i++;
$hexChar .= strtoupper(dechex(ord($string[$i])));
$hexChar .= strtoupper(dechex(\ord($string[$i])));
}
if ( $to != "utf-8" )
{
if ( in_array( $hexChar, $charsetTable[$from] ) )
if ( \in_array( $hexChar, $charsetTable[$from] ) )
{
$unicodeHexChar = array_search( $hexChar, $charsetTable[$from] );
$unicodeHexChars = explode( "+",$unicodeHexChar );
for( $unicodeHexCharElement = 0; $unicodeHexCharElement < count($unicodeHexChars); $unicodeHexCharElement++ )
for( $unicodeHexCharElement = 0; $unicodeHexCharElement < \count($unicodeHexChars); $unicodeHexCharElement++ )
{
if ( array_key_exists( $unicodeHexChars[$unicodeHexCharElement], $charsetTable[$to] ) )
{
@@ -126,7 +126,7 @@ class Internal extends \IPSUtf8\Text\Charset
}
else
{
$text .= chr(hexdec($charsetTable[$to][$unicodeHexChars[$unicodeHexCharElement]]));
$text .= \chr(hexdec($charsetTable[$to][$unicodeHexChars[$unicodeHexCharElement]]));
}
}
else
@@ -144,7 +144,7 @@ class Internal extends \IPSUtf8\Text\Charset
}
else
{
if ( in_array( $hexChar, $charsetTable[$from] ) )
if ( \in_array( $hexChar, $charsetTable[$from] ) )
{
$unicodeHexChar = array_search( $hexChar, $charsetTable[$from] );
$unicodeHexChars = explode( "+", $unicodeHexChar );
@@ -158,7 +158,7 @@ class Internal extends \IPSUtf8\Text\Charset
* In Mazowia we have 007A+0142, but sometimes it can look like this
* 0x007A+0x0142+0x2034 (that string means nothing, it just shows the possibility...)
*/
for( $unicodeHexCharElement = 0; $unicodeHexCharElement < count($unicodeHexChars); $unicodeHexCharElement++)
for( $unicodeHexCharElement = 0; $unicodeHexCharElement < \count($unicodeHexChars); $unicodeHexCharElement++)
{
if ( self::$entities == true )
{
@@ -189,7 +189,7 @@ class Internal extends \IPSUtf8\Text\Charset
$unicodeHexChar = "";
$charsetTable = self::_makeConversionTable( $to );
if( is_array($charsetTable[$to]) AND count($charsetTable[$to]) )
if( \is_array($charsetTable[$to]) AND \count($charsetTable[$to]) )
{
foreach ( $charsetTable[$to] as $unicodeHexChar => $hexChar )
{
@@ -199,7 +199,7 @@ class Internal extends \IPSUtf8\Text\Charset
}
else
{
$entityOrChar = chr(hexdec($hexChar));
$entityOrChar = \chr(hexdec($hexChar));
}
$string = str_replace( self::_hexToUtf( $unicodeHexChar), $entityOrChar, $string );
@@ -227,7 +227,7 @@ class Internal extends \IPSUtf8\Text\Charset
for( $charPosition = 0; $charPosition < $stringLength; $charPosition++ )
{
$char = $unicodeString [$charPosition];
$asciiChar = ord ($char);
$asciiChar = \ord ($char);
if ($asciiChar < 128) //1 7 0bbbbbbb (127)
{
@@ -238,7 +238,7 @@ class Internal extends \IPSUtf8\Text\Charset
$firstByte = ($asciiChar & 31);
$charPosition++;
$char = $unicodeString [$charPosition];
$asciiChar = ord ($char);
$asciiChar = \ord ($char);
$secondByte = ($asciiChar & 63);
$asciiChar = ($firstByte * 64) + $secondByte;
@@ -250,11 +250,11 @@ class Internal extends \IPSUtf8\Text\Charset
$firstByte = ($asciiChar & 31);
$charPosition++;
$char = $unicodeString [$charPosition];
$asciiChar = ord ($char);
$asciiChar = \ord ($char);
$secondByte = ($asciiChar & 63);
$charPosition++;
$char = $unicodeString [$charPosition];
$asciiChar = ord ($char);
$asciiChar = \ord ($char);
$thirdByte = ($asciiChar & 63);
$asciiChar = ((($firstByte * 64) + $secondByte) * 64) + $thirdByte;
@@ -266,15 +266,15 @@ class Internal extends \IPSUtf8\Text\Charset
$firstByte = ($asciiChar & 31);
$charPosition++;
$char = $unicodeString [$charPosition];
$asciiChar = ord ($char);
$asciiChar = \ord ($char);
$secondByte = ($asciiChar & 63);
$charPosition++;
$char = $unicodeString [$charPosition];
$asciiChar = ord ($char);
$asciiChar = \ord ($char);
$thirdByte = ($asciiChar & 63);
$charPosition++;
$char = $unicodeString [$charPosition];
$asciiChar = ord ($char);
$asciiChar = \ord ($char);
$fourthByte = ($asciiChar & 63);
$asciiChar = ((((($firstByte * 64) + $secondByte) * 64) + $thirdByte) * 64) + $fourthByte;
@@ -302,19 +302,19 @@ class Internal extends \IPSUtf8\Text\Charset
if( $utfCharInDec < 128 )
{
$outputChar .= chr($utfCharInDec);
$outputChar .= \chr($utfCharInDec);
}
else if( $utfCharInDec < 2048 )
{
$outputChar .= chr( ( $utfCharInDec>>6 ) + 192 ) . chr( ( $utfCharInDec&63 ) + 128 );
$outputChar .= \chr( ( $utfCharInDec>>6 ) + 192 ) . \chr( ( $utfCharInDec&63 ) + 128 );
}
else if( $utfCharInDec < 65536 )
{
$outputChar .= chr( ( $utfCharInDec>>12 ) + 224 ) . chr( ( ( $utfCharInDec>>6 ) &63 ) + 128 ) . chr( ( $utfCharInDec&63 ) + 128 );
$outputChar .= \chr( ( $utfCharInDec>>12 ) + 224 ) . \chr( ( ( $utfCharInDec>>6 ) &63 ) + 128 ) . \chr( ( $utfCharInDec&63 ) + 128 );
}
else if( $utfCharInDec < 2097152 )
{
$outputChar .= chr( $utfCharInDec>>18+240 ) . chr( ( ( $utfCharInDec>>12 ) &63 ) + 128 ) . chr( ( $utfCharInDec>>6 ) &63 + 128 ) . chr( $utfCharInDec&63 + 128 );
$outputChar .= \chr( $utfCharInDec>>18+240 ) . \chr( ( ( $utfCharInDec>>12 ) &63 ) + 128 ) . \chr( ( $utfCharInDec>>6 ) &63 + 128 ) . \chr( $utfCharInDec&63 + 128 );
}
return $outputChar;
@@ -360,13 +360,13 @@ class Internal extends \IPSUtf8\Text\Charset
{
$convertTable = array();
for( $i = 0; $i < func_num_args(); $i++ )
for( $i = 0, $j = \func_num_args(); $i < $j; $i++ )
{
/**
* Because func_*** can't be used inside of another function call
* we have to save it as a separate value.
*/
$fileName = func_get_arg($i);
$fileName = \func_get_arg($i);
if ( !is_file( static::$charsetPath . $fileName ) )
{
@@ -406,7 +406,7 @@ class Internal extends \IPSUtf8\Text\Charset
$arrayKey = strtoupper(str_replace(strtolower("0x"), "", $hexValue[1]));
$arrayValue = strtoupper(str_replace(strtolower("0x"), "", $hexValue[0]));
$convertTable[ func_get_arg($i) ][ $arrayKey ] = $arrayValue;
$convertTable[ \func_get_arg($i) ][ $arrayKey ] = $arrayValue;
}
}
}
+2 -2
View File
@@ -30,11 +30,11 @@ class Mb extends \IPSUtf8\Text\Charset
return $string;
}
if ( function_exists( 'mb_convert_encoding' ) )
if ( \function_exists( 'mb_convert_encoding' ) )
{
$encodings = array_map( 'strtolower', mb_list_encodings() );
if( in_array( strtolower( $to ), $encodings ) AND in_array( strtolower( $from ), $encodings ) )
if( \in_array( strtolower( $to ), $encodings ) AND \in_array( strtolower( $from ), $encodings ) )
{
$text = mb_convert_encoding( $string, $to, $from );
}
@@ -30,7 +30,7 @@ class Recode extends \IPSUtf8\Text\Charset
return $string;
}
if ( function_exists( 'recode_string' ) )
if ( \function_exists( 'recode_string' ) )
{
$text = recode_string( $from . '..' . $to, $string );
}