本文整理汇总了PHP中eZCharsetInfo类的典型用法代码示例。如果您正苦于以下问题:PHP eZCharsetInfo类的具体用法?PHP eZCharsetInfo怎么用?PHP eZCharsetInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了eZCharsetInfo类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connect
function connect($server, $db, $user, $password, $socketPath, $charset = null, $port = false)
{
$connection = false;
if ($socketPath !== false) {
ini_set("mysqli.default_socket", $socketPath);
}
if ($this->UsePersistentConnection == true) {
// Only supported on PHP 5.3 (mysqlnd)
if (version_compare(PHP_VERSION, '5.3') > 0) {
$this->Server = 'p:' . $this->Server;
} else {
eZDebug::writeWarning('mysqli only supports persistent connections when using php 5.3 and higher', 'eZMySQLiDB::connect');
}
}
eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
$connection = mysqli_connect($server, $user, $password, null, (int) $port, $socketPath);
$dbErrorText = mysqli_connect_error();
eZPerfLogger::accumulatorStop('mysqli_connection');
$maxAttempts = $this->connectRetryCount();
$waitTime = $this->connectRetryWaitTime();
$numAttempts = 1;
while (!$connection && $numAttempts <= $maxAttempts) {
sleep($waitTime);
eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
$connection = mysqli_connect($this->Server, $this->User, $this->Password, null, (int) $this->Port, $this->SocketPath);
eZPerfLogger::accumulatorStop('mysqli_connection');
$numAttempts++;
}
$this->setError();
$this->IsConnected = true;
if (!$connection) {
eZDebug::writeError("Connection error: Couldn't connect to database. Please try again later or inform the system administrator.\n{$dbErrorText}", __CLASS__);
$this->IsConnected = false;
throw new eZDBNoConnectionException($server);
}
if ($this->IsConnected && $db != null) {
eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
$ret = mysqli_select_db($connection, $db);
eZPerfLogger::accumulatorStop('mysqli_connection');
if (!$ret) {
//$this->setError();
eZDebug::writeError("Connection error: " . mysqli_errno($connection) . ": " . mysqli_error($connection), "eZMySQLiDB");
$this->IsConnected = false;
}
}
if ($charset !== null) {
$originalCharset = $charset;
$charset = eZCharsetInfo::realCharsetCode($charset);
}
if ($this->IsConnected and $charset !== null) {
eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
$status = mysqli_set_charset($connection, eZMySQLCharset::mapTo($charset));
eZPerfLogger::accumulatorStop('mysqli_connection');
if (!$status) {
$this->setError();
eZDebug::writeWarning("Connection warning: " . mysqli_errno($connection) . ": " . mysqli_error($connection), "eZMySQLiDB");
}
}
return $connection;
}
示例2: eZCodePageMapper
function eZCodePageMapper( $input_charset_code, $output_charset_code, $use_cache = true )
{
$this->RequestedInputCharsetCode = $input_charset_code;
$this->InputCharsetCode = eZCharsetInfo::realCharsetCode( $input_charset_code );
$this->RequestedOutputCharsetCode = $output_charset_code;
$this->OutputCharsetCode = eZCharsetInfo::realCharsetCode( $output_charset_code );
$this->Valid = false;
$this->load( $use_cache );
$this->setSubstituteCharacter( 63 ); // ?
}
示例3: transformByGroup
function transformByGroup($text, $group, $charset = false, $useCache = true)
{
if ($text === '') {
return $text;
}
$charsetName = $charset === false ? eZTextCodec::internalCharset() : eZCharsetInfo::realCharsetCode($charset);
if ($useCache) {
// CRC32 is used for speed, MD5 would be more unique but is slower
$keyText = 'Group:' . $group;
$key = eZSys::ezcrc32($keyText . '-' . $charset);
$filepath = $this->cacheFilePath('g-' . $group . '-', '-' . $charsetName, $key);
// Try to execute code in the cache file, if it succeeds
// \a $text will/ transformated
$retText = $this->executeCacheFile($text, $filepath);
if ($retText !== false) {
return $retText;
}
}
$commands = $this->groupCommands($group);
if ($commands === false) {
return false;
}
$mapper = new eZCodeMapper();
$mapper->loadTransformationFiles($charsetName, $group);
$rules = array();
foreach ($commands as $command) {
$rules = array_merge($rules, $mapper->decodeCommand($command['command'], $command['parameters']));
}
// First generate a unicode based mapping table from the rules
$unicodeTable = $mapper->generateMappingCode($rules);
unset($unicodeTable[0]);
// Then transform that to a table that works with the current charset
// Any character not available in the current charset will be removed
$charsetTable = $mapper->generateCharsetMappingTable($unicodeTable, $charset);
$transformationData = array('table' => $charsetTable);
unset($unicodeTable);
if ($useCache) {
$extraCode = '';
foreach ($commands as $command) {
$code = $mapper->generateCommandCode($command, $charsetName);
if ($code !== false) {
$extraCode .= $code . "\n";
}
}
$this->storeCacheFile($filepath, $transformationData, $extraCode, 'Group:' . $group, $charsetName);
}
// Execute transformations
$text = strtr($text, $transformationData['table']);
// Execute custom code
foreach ($commands as $command) {
$mapper->executeCommandCode($text, $command, $charsetName);
}
return $text;
}
示例4: domString
function domString($domDocument)
{
$ini = eZINI::instance();
$xmlCharset = $ini->variable('RegionalSettings', 'ContentXMLCharset');
if ($xmlCharset == 'enabled') {
$charset = eZTextCodec::internalCharset();
} else {
if ($xmlCharset == 'disabled') {
$charset = true;
} else {
$charset = $xmlCharset;
}
}
if ($charset !== true) {
$charset = eZCharsetInfo::realCharsetCode($charset);
}
$domString = $domDocument->saveXML();
return $domString;
}
示例5: findAppropriateCharsetsList
/**
* @param \eZLocale $primaryLanguage
* @param \eZLocale[]|null $allLanguages
* @param bool $canUseUnicode
* @return array
*/
function findAppropriateCharsetsList($primaryLanguage, $allLanguages, $canUseUnicode)
{
$commonCharsets = array();
if (is_array($allLanguages) and count($allLanguages) > 0) {
$language = $allLanguages[0];
$charsets = $language->allowedCharsets();
foreach ($charsets as $charset) {
$commonCharsets[] = eZCharsetInfo::realCharsetCode($charset);
}
$commonCharsets = array_unique($commonCharsets);
for ($i = 1; $i < count($allLanguages); ++$i) {
$language = $allLanguages[$i];
$charsets = $language->allowedCharsets();
$realCharsets = array();
foreach ($charsets as $charset) {
$realCharsets[] = eZCharsetInfo::realCharsetCode($charset);
}
$realCharsets = array_unique($realCharsets);
$commonCharsets = array_intersect($commonCharsets, $realCharsets);
}
}
$usableCharsets = array_values($commonCharsets);
if (count($usableCharsets) > 0) {
if (in_array($primaryLanguage->charset(), $usableCharsets)) {
array_unshift($usableCharsets, $primaryLanguage->charset());
$usableCharsets = array_unique($usableCharsets);
}
} else {
if ($canUseUnicode) {
$usableCharsets[] = eZCharsetInfo::realCharsetCode('utf-8');
}
}
return $usableCharsets;
}
示例6: tableCharsetName
function tableCharsetName( $charset )
{
$charset = eZCharsetInfo::realCharsetCode( $charset );
// Convert charset names into something MySQL will understand
$charsetMapping = array( 'iso-8859-1' => 'latin1',
'iso-8859-2' => 'latin2',
'iso-8859-8' => 'hebrew',
'iso-8859-7' => 'greek',
'iso-8859-9' => 'latin5',
'iso-8859-13' => 'latin7',
'windows-1250' => 'cp1250',
'windows-1251' => 'cp1251',
'windows-1256' => 'cp1256',
'windows-1257' => 'cp1257',
'utf-8' => 'utf8',
'koi8-r' => 'koi8r',
'koi8-u' => 'koi8u' );
$charset = strtolower( $charset );
if ( isset( $charsetMapping[$charset] ) )
return $charsetMapping[$charset];
return $charset;
}
示例7: preg_replace
if ( $http->hasPostVariable( 'TemplateContent' ) )
{
$templateContent = $http->postVariable( 'TemplateContent' );
if ( $templateConfig->variable( 'CharsetSettings', 'AutoConvertOnSave') == 'enabled' )
{
$outputCharset = eZCharsetInfo::realCharsetCode( $outputCharset );
if ( preg_match( '|{\*\?template.*charset=([a-zA-Z0-9-]*).*\?\*}|', $templateContent, $matches ) )
{
$templateContent = preg_replace( '|({\*\?template.*charset=)[a-zA-Z0-9-]*(.*\?\*})|',
'\\1'. $outputCharset. '\\2',
$templateContent );
}
else
{
$templateCharset = eZCharsetInfo::realCharsetCode( $templateConfig->variable( 'CharsetSettings', 'DefaultTemplateCharset') );
if ( $templateCharset != $outputCharset )
$templateContent = "{*?template charset=$outputCharset?*}\n" . $templateContent;
}
}
else
{
/* Here we figure out the characterset of the template. If there is a charset
* associated with the template in the header we use that one, if not we fall
* back to the INI setting "DefaultTemplateCharset". */
if ( preg_match( '|{\*\?template.*charset=([a-zA-Z0-9-]*).*\?\*}|', $templateContent, $matches ) )
{
$templateCharset = $matches[1];
}
else
{
示例8: checkCharsetPriv
function checkCharsetPriv( $charset, &$currentCharset )
{
$query = "SHOW CREATE DATABASE `{$this->DB}`";
$status = mysql_query( $query, $this->DBConnection );
$this->reportQuery( __CLASS__, $query, false, false );
if ( !$status )
{
$this->setError();
eZDebug::writeWarning( "Connection warning: " . mysql_errno( $this->DBConnection ) . ": " . mysql_error( $this->DBConnection ), "eZMySQLDB" );
return false;
}
$numRows = mysql_num_rows( $status );
if ( $numRows == 0 )
return false;
for ( $i = 0; $i < $numRows; ++$i )
{
$tmpRow = mysql_fetch_array( $status, MYSQL_ASSOC );
if ( $tmpRow['Database'] == $this->DB )
{
$createText = $tmpRow['Create Database'];
if ( preg_match( '#DEFAULT CHARACTER SET ([a-zA-Z0-9_-]+)#', $createText, $matches ) )
{
$currentCharset = $matches[1];
$currentCharset = eZCharsetInfo::realCharsetCode( $currentCharset );
// Convert charset names into something MySQL will understand
$unmappedCurrentCharset = eZMySQLCharset::mapFrom( $currentCharset );
if ( is_array( $charset ) )
{
if ( in_array( $unmappedCurrentCharset, $charset ) )
{
return $unmappedCurrentCharset;
}
}
else if ( $unmappedCurrentCharset == $charset )
{
return true;
}
return false;
}
break;
}
}
return true;
}
示例9: isAllowedCharset
function isAllowedCharset( $charset )
{
$realCharset = eZCharsetInfo::realCharsetCode( $charset );
$charsets = $this->allowedCharsets();
foreach ( $charsets as $charsetName )
{
$realName = eZCharsetInfo::realCharsetCode( $charsetName );
if ( $realName == $realCharset )
return true;
}
return false;
}
示例10: httpCharset
static function httpCharset()
{
$realCharset =& $GLOBALS['eZTextCodecHTTPCharsetReal'];
if (!isset($realCharset)) {
$charset = '';
if (isset($GLOBALS['eZTextCodecHTTPCharset'])) {
$charset = $GLOBALS['eZTextCodecHTTPCharset'];
}
if ($charset == '') {
if (isset($GLOBALS['eZTextCodecInternalCharsetReal'])) {
$realCharset = $GLOBALS['eZTextCodecInternalCharsetReal'];
} else {
$realCharset = eZTextCodec::internalCharset();
}
} else {
$realCharset = eZCharsetInfo::realCharsetCode($charset);
}
}
return $realCharset;
}
示例11: loadTransformationFiles
function loadTransformationFiles($currentCharset, $transformationGroup)
{
$ini = eZINI::instance('transform.ini');
$repositoryList = array($ini->variable('Transformation', 'Repository'));
$files = $ini->variable('Transformation', 'Files');
$extensions = $ini->variable('Transformation', 'Extensions');
$repositoryList = array_merge($repositoryList, eZExtension::expandedPathList($extensions, 'transformations'));
// Check if the current charset maps to a unicode group
// If it does it can trigger loading of additional files
$unicodeGroups = array();
$charsets = $ini->variable('Transformation', 'Charsets');
foreach ($charsets as $entry) {
list($charset, $group) = explode(';', $entry, 2);
$charset = eZCharsetInfo::realCharsetCode($charset);
if ($charset == $currentCharset) {
if (!in_array($group, $unicodeGroups)) {
$unicodeGroups[] = $group;
}
}
}
// If we are using transformation groups then add that as
// a unicode group. This causes it load transformation files
// specific to that group.
if ($transformationGroup !== false) {
$unicodeGroups[] = $transformationGroup;
}
// Add any extra files from the unicode groups
foreach ($unicodeGroups as $unicodeGroup) {
if ($ini->hasGroup($unicodeGroup)) {
$files = array_merge($files, $ini->variable($unicodeGroup, 'Files'));
$extensions = $ini->variable($unicodeGroup, 'Extensions');
$repositoryList = array_merge($repositoryList, eZExtension::expandedPathList($extensions, 'transformations'));
}
}
foreach ($files as $file) {
// Only load files that are not currently loaded
if ($this->isTranformationLoaded($file)) {
continue;
}
foreach ($repositoryList as $repository) {
$trFile = $repository . '/' . $file;
if (file_exists($trFile)) {
$this->parseTransformationFile($trFile, $file);
}
}
}
}
示例12: cacheFileName
function cacheFileName($charset_code)
{
$permissionArray = eZCodePage::permissionSetting();
if ($permissionArray === false) {
return false;
}
$charset_code = eZCharsetInfo::realCharsetCode($charset_code);
$cache_dir = $permissionArray['var_directory'] . "/codepages/";
$cache_filename = md5($charset_code);
$cache = $cache_dir . $cache_filename . ".php";
return $cache;
}
示例13: isCharsetSupported
function isCharsetSupported( $charset_code )
{
$charset_code = eZCharsetInfo::realCharsetCode( $charset_code );
return in_array( $charset_code, eZMBStringMapper::charsetList() );
}
示例14: characterEncodingScheme
static function characterEncodingScheme($charsetCode, $isRealCharset = false)
{
if (!$isRealCharset) {
$charsetCode = eZCharsetInfo::realCharsetCode($charsetCode);
}
$reverseEncodingTable =& eZCharsetInfo::reverseEncodingTable();
if (isset($reverseEncodingTable[$charsetCode])) {
return $reverseEncodingTable[$charsetCode];
}
return 'singlebyte';
}