/** Reads settings from i18n.ini and passes them to eZTextCodec. */ function eZUpdateTextCodecSettings() { $ini = eZINI::instance('i18n.ini'); list($i18nSettings['internal-charset'], $i18nSettings['http-charset'], $i18nSettings['mbstring-extension']) = $ini->variableMulti('CharacterSettings', array('Charset', 'HTTPCharset', 'MBStringExtension'), array(false, false, 'enabled')); //include_once( 'lib/ezi18n/classes/eztextcodec.php' ); eZTextCodec::updateSettings($i18nSettings); }
/** * Reimplement parent's method to make use of a tracing dfs backend class */ public function _connect() { $siteINI = eZINI::instance('site.ini'); // DB Connection setup // This part is not actually required since _connect will only be called // once, but it is useful to run the unit tests. So be it. // @todo refactor this using eZINI::setVariable in unit tests if (parent::$dbparams === null) { $fileINI = eZINI::instance('file.ini'); parent::$dbparams = array(); parent::$dbparams['host'] = $fileINI->variable('eZDFSClusteringSettings', 'DBHost'); $dbPort = $fileINI->variable('eZDFSClusteringSettings', 'DBPort'); parent::$dbparams['port'] = $dbPort !== '' ? $dbPort : null; parent::$dbparams['socket'] = $fileINI->variable('eZDFSClusteringSettings', 'DBSocket'); parent::$dbparams['dbname'] = $fileINI->variable('eZDFSClusteringSettings', 'DBName'); parent::$dbparams['user'] = $fileINI->variable('eZDFSClusteringSettings', 'DBUser'); parent::$dbparams['pass'] = $fileINI->variable('eZDFSClusteringSettings', 'DBPassword'); parent::$dbparams['max_connect_tries'] = $fileINI->variable('eZDFSClusteringSettings', 'DBConnectRetries'); parent::$dbparams['max_execute_tries'] = $fileINI->variable('eZDFSClusteringSettings', 'DBExecuteRetries'); parent::$dbparams['sql_output'] = $siteINI->variable("DatabaseSettings", "SQLOutput") == "enabled"; parent::$dbparams['cache_generation_timeout'] = $siteINI->variable("ContentSettings", "CacheGenerationTimeout"); } $serverString = parent::$dbparams['host']; if (parent::$dbparams['socket']) { $serverString .= ':' . parent::$dbparams['socket']; } elseif (parent::$dbparams['port']) { $serverString .= ':' . parent::$dbparams['port']; } $maxTries = parent::$dbparams['max_connect_tries']; $tries = 0; eZPerfLogger::accumulatorStart('mysql_cluster_connect', 'MySQL Cluster', 'Cluster database connection'); while ($tries < $maxTries) { if ($this->db = mysqli_connect(parent::$dbparams['host'], parent::$dbparams['user'], parent::$dbparams['pass'], parent::$dbparams['dbname'], parent::$dbparams['port'])) { break; } ++$tries; } eZPerfLogger::accumulatorStop('mysql_cluster_connect'); if (!$this->db) { throw new eZClusterHandlerDBNoConnectionException($serverString, parent::$dbparams['user'], parent::$dbparams['pass']); } /*if ( !mysql_select_db( parent::$dbparams['dbname'], $this->db ) ) throw new eZClusterHandlerDBNoDatabaseException( parent::$dbparams['dbname'] );*/ // DFS setup if ($this->dfsbackend === null) { $this->dfsbackend = new eZDFSFileHandlerTracing46DFSBackend(); } $charset = trim($siteINI->variable('DatabaseSettings', 'Charset')); if ($charset === '') { $charset = eZTextCodec::internalCharset(); } if ($charset) { if (!mysqli_set_charset($this->db, eZMySQLCharset::mapTo($charset))) { $this->_fail("Failed to set Database charset to {$charset}."); } } }
function validateStringHTTPInput($data, $contentObjectAttribute, $classAttribute) { $maxLen = $classAttribute->attribute(self::MAX_LEN_FIELD); $textCodec = eZTextCodec::instance(false); if ($textCodec->strlen($data) > $maxLen and $maxLen > 0) { $contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'The input text is too long. The maximum number of characters allowed is %1.'), $maxLen); return eZInputValidator::STATE_INVALID; } return eZInputValidator::STATE_ACCEPTED; }
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; }
function _connect() { $siteINI = eZINI::instance('site.ini'); if (!isset($GLOBALS['eZDBFileHandlerMysqlBackend_dbparams'])) { $fileINI = eZINI::instance('file.ini'); $params['host'] = $fileINI->variable('ClusteringSettings', 'DBHost'); $params['port'] = $fileINI->variable('ClusteringSettings', 'DBPort'); $params['socket'] = $fileINI->variable('ClusteringSettings', 'DBSocket'); $params['dbname'] = $fileINI->variable('ClusteringSettings', 'DBName'); $params['user'] = $fileINI->variable('ClusteringSettings', 'DBUser'); $params['pass'] = $fileINI->variable('ClusteringSettings', 'DBPassword'); $params['chunk_size'] = $fileINI->variable('ClusteringSettings', 'DBChunkSize'); $params['max_connect_tries'] = $fileINI->variable('ClusteringSettings', 'DBConnectRetries'); $params['max_execute_tries'] = $fileINI->variable('ClusteringSettings', 'DBExecuteRetries'); $params['sql_output'] = $siteINI->variable("DatabaseSettings", "SQLOutput") == "enabled"; $params['cache_generation_timeout'] = $siteINI->variable("ContentSettings", "CacheGenerationTimeout"); $GLOBALS['eZDBFileHandlerMysqlBackend_dbparams'] = $params; } else { $params = $GLOBALS['eZDBFileHandlerMysqlBackend_dbparams']; } $this->dbparams = $params; $maxTries = $params['max_connect_tries']; $tries = 0; eZDebug::accumulatorStart('mysql_cluster_connect', 'mysql_cluster_total', 'Cluster_database_connection'); while ($tries < $maxTries) { /// @todo what if port is null, '' ??? to be tested if ($this->db = mysqli_connect($params['host'], $params['user'], $params['pass'], $params['dbname'], $params['port'])) { break; } ++$tries; } eZDebug::accumulatorStop('mysql_cluster_connect'); if (!$this->db) { return $this->_die("Unable to connect to storage server"); } $charset = trim($siteINI->variable('DatabaseSettings', 'Charset')); if ($charset === '') { $charset = eZTextCodec::internalCharset(); } if ($charset) { if (!mysqli_set_charset($this->db, eZMySQLCharset::mapTo($charset))) { return $this->_die("Failed to set Database charset to {$charset}."); } } }
public static function instance() { if ( is_null(self::$_instance) ) { $ini = eZINI::instance(); if ( !$ini->hasSection( 'MMDatabaseSettings') ) return eZDB::instance(); list( $server, $port, $user, $pwd, $db ) = $ini->variableMulti( 'MMDatabaseSettings', array( 'Server', 'Port', 'User', 'Password', 'Database' ) ); list( $charset, $retries, $usePersistentConnection ) = $ini->variableMulti( 'DatabaseSettings', array( 'Charset', 'ConnectRetries', 'UserPersistentConnection' ) ); $isInternalCharset = false; if ( trim( $charset ) == '' ) { $charset = eZTextCodec::internalCharset(); $isInternalCharset = true; } $builtinEncoding = ( $ini->variable( 'DatabaseSettings', 'UseBuiltinEncoding' ) == 'true' ); $params = array('server' => $server, 'port' => $port, 'user' => $user, 'password' => $pwd, 'database' => $db, 'use_slave_server' => false, 'slave_server' => null, 'slave_port' => null, 'slave_user' => null, 'slave_password' => null, 'slave_database' => null, 'charset' => $charset, 'is_internal_charset' => $isInternalCharset, 'socket' => false, 'builtin_encoding' => $builtinEncoding, 'connect_retries' => $retries, 'use_persistent_connection' => $usePersistentConnection, 'show_errors' => true ); self::$_instance = new eZMySQLiDB( $params ); } return self::$_instance; }
static function fetchAlphabet() { $contentINI = eZINI::instance('content.ini'); $alphabetRangeList = $contentINI->hasVariable('AlphabeticalFilterSettings', 'AlphabetList') ? $contentINI->variable('AlphabeticalFilterSettings', 'AlphabetList') : array(); $alphabetFromArray = $contentINI->hasVariable('AlphabeticalFilterSettings', 'ContentFilterList') ? $contentINI->variable('AlphabeticalFilterSettings', 'ContentFilterList') : array('default'); // If alphabet list is empty if (count($alphabetFromArray) == 0) { return false; } $alphabetRangeList = array_merge($alphabetRangeList, array('default' => '97-122')); $alphabet = array(); foreach ($alphabetFromArray as $alphabetFrom) { // If $alphabetFrom exists in range array $alphabetRangeList if (isset($alphabetRangeList[$alphabetFrom])) { $lettersArray = explode(',', $alphabetRangeList[$alphabetFrom]); foreach ($lettersArray as $letter) { $rangeArray = explode('-', $letter); if (isset($rangeArray[1])) { $alphabet = array_merge($alphabet, range(trim($rangeArray[0]), trim($rangeArray[1]))); } else { $alphabet = array_merge($alphabet, array(trim($letter))); } } } } // Get alphabet by default (eng-GB) if (count($alphabet) == 0) { $rangeArray = explode('-', $alphabetRangeList['default']); $alphabet = range($rangeArray[0], $rangeArray[1]); } $resAlphabet = array(); $i18nINI = eZINI::instance('i18n.ini'); $charset = $i18nINI->variable('CharacterSettings', 'Charset'); $codec = eZTextCodec::instance('utf-8', $charset); $utf8_codec = eZUTF8Codec::instance(); // Convert all letters of alphabet from unicode to utf-8 and from utf-8 to current locale foreach ($alphabet as $item) { $utf8Letter = $utf8_codec->toUtf8($item); $resAlphabet[] = $codec ? $codec->convertString($utf8Letter) : $utf8Letter; } return $resAlphabet; }
/** * (called for each obj attribute) */ public function checkObjectAttribute(array $contentObjectAttribute) { // we adopt the ez api instead of acting on raw data $contentObjectAttribute = new eZContentObjectAttribute($contentObjectAttribute); // do not check attributes which do not even contain images if ($contentObjectAttribute->attribute('has_content')) { if ($this->maxLen > 0) { /// @todo check that this is the appropriate way of counting length of db data $textCodec = eZTextCodec::instance(false); $stringLength = $textCodec->strlen($contentObjectAttribute->attribute('content')); if ($stringLength > $this->maxLen) { return array("String longer than {$this->maxLen} chars: {$stringLength}" . $this->postfixErrorMsg($contentObjectAttribute)); } } } else { if (!$this->nullable) { return array("Attribute is null and it should not be" . $this->postfixErrorMsg($contentObjectAttribute)); } } return array(); }
function convertNumericEntities($text) { if (strlen($text) < 4) { return $text; } // Convert other HTML entities to the current charset characters. $codec = eZTextCodec::instance('unicode', false); $pos = 0; $domString = ""; while ($pos < strlen($text) - 1) { $startPos = $pos; while (!($text[$pos] == '&' && isset($text[$pos + 1]) && $text[$pos + 1] == '#') && $pos < strlen($text) - 1) { $pos++; } $domString .= substr($text, $startPos, $pos - $startPos); if ($pos < strlen($text) - 1) { $endPos = strpos($text, ';', $pos + 2); if ($endPos === false) { $pos += 2; continue; } $code = substr($text, $pos + 2, $endPos - ($pos + 2)); $char = $codec->convertString(array($code)); $pos = $endPos + 1; $domString .= $char; } else { $domString .= substr($text, $pos, 2); } } return $domString; }
} $templateContent = file_get_contents( $fileName ); /* 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 { $templateCharset = $templateConfig->variable( 'CharsetSettings', 'DefaultTemplateCharset'); } /* If we're loading a template for editting we need to convert it to the HTTP * Charset. */ $codec = eZTextCodec::instance( $templateCharset, $outputCharset, false ); if ( $codec ) { $templateContent = $codec->convertString( $templateContent ); } $tpl->setVariable( 'template', $template ); $tpl->setVariable( 'template_content', $templateContent ); $Result['content'] = $tpl->fetch( "design:visual/templateedit.tpl" ); ?>
$ifModifiedSince = $_SERVER['HTTP_IF_MODIFIED_SINCE']; // Internet Explorer specific $pos = strpos($ifModifiedSince, ';'); if ($pos !== false) { $ifModifiedSince = substr($ifModifiedSince, 0, $pos); } if (strcmp($lastModified, $ifModifiedSince) == 0) { header('HTTP/1.1 304 Not Modified'); header('Last-Modified: ' . $lastModified); header('X-Powered-By: ' . eZPublishSDK::EDITION); eZExecution::cleanExit(); } } $rssContent = $cacheFile->fetchContents(); } } // Set header settings $httpCharset = eZTextCodec::httpCharset(); header('Last-Modified: ' . $lastModified); if ($RSSExport->attribute('rss_version') === 'ATOM') { header('Content-Type: application/xml; charset=' . $httpCharset); } else { header('Content-Type: application/rss+xml; charset=' . $httpCharset); } header('Content-Length: ' . strlen($rssContent)); header('X-Powered-By: ' . eZPublishSDK::EDITION); for ($i = 0, $obLevel = ob_get_level(); $i < $obLevel; ++$i) { ob_end_clean(); } echo $rssContent; eZExecution::cleanExit();
function writeDocument() { $ooINI = eZINI::instance('odf.ini'); // Initalize directories eZDir::mkdir($this->OORootDir); eZDir::mkdir($this->OOExportDir . "META-INF", false, true); eZDir::mkdir($this->OOTemplateDir); $metaXML = "<?xml version='1.0' encoding='UTF-8'?>" . "<office:document-meta xmlns:office='urn:oasis:names:tc:opendocument:xmlns:office:1.0' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:meta='urn:oasis:names:tc:opendocument:xmlns:meta:1.0' xmlns:ooo='http://openoffice.org/2004/office' office:version='1.0' xmlns:ezpublish='http://www.ez.no/ezpublish/oasis'>" . "<office:meta>" . "<meta:generator>eZ Publish</meta:generator>" . " <meta:creation-date>2004-11-10T11:39:50</meta:creation-date>" . " <dc:date>2004-11-10T11:40:15</dc:date>" . " <dc:language>en-US</dc:language>" . " <meta:editing-cycles>3</meta:editing-cycles>" . " <meta:editing-duration>PT26S</meta:editing-duration>" . " <meta:user-defined meta:name='Info 1'/>" . " <meta:user-defined meta:name='Info 2'/>" . " <meta:user-defined meta:name='Info 3'/>" . " <meta:user-defined meta:name='Info 4'/>" . " <meta:document-statistic meta:table-count='0' meta:image-count='0' meta:object-count='0' meta:page-count='1' meta:paragraph-count='1' meta:word-count='2' meta:character-count='10'/>" . " </office:meta>" . "</office:document-meta>"; file_put_contents($this->OOExportDir . "meta.xml", $metaXML); $settingsXML = "<?xml version='1.0' encoding='UTF-8'?>" . "<office:document-settings xmlns:office='urn:oasis:names:tc:opendocument:xmlns:office:1.0' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:config='urn:oasis:names:tc:opendocument:xmlns:config:1.0' xmlns:ooo='http://openoffice.org/2004/office' office:version='1.0'>" . " <office:settings>" . " </office:settings>" . "</office:document-settings>"; file_put_contents($this->OOExportDir . "settings.xml", $settingsXML); $useTemplate = $ooINI->variable('ODFExport', 'UseTemplate') == "true"; $templateName = $ooINI->variable('ODFExport', 'TemplateName'); if ($useTemplate) { $templateFile = "extension/ezodf/templates/" . $templateName; $archiveOptions = new ezcArchiveOptions(array('readOnly' => true)); $archive = ezcArchive::open($templateFile, null, $archiveOptions); $archive->extract($this->OOTemplateDir); // Copy styles.xml and images, if any to the document being generated if (!copy($this->OOTemplateDir . "styles.xml", $this->OOExportDir . "styles.xml")) { return array(self::ERROR_COULD_NOT_COPY, "Could not copy the styles.xml file."); } $sourceDir = $this->OOTemplateDir . "Pictures"; $destDir = $this->OOExportDir . "Pictures"; eZDir::mkdir($destDir, false, true); eZDir::copy($sourceDir, $destDir, false, true); } else { // Generate a default empty styles.xml file $stylesXML = "<?xml version='1.0' encoding='UTF-8'?>" . "<office:document-styles xmlns:office='urn:oasis:names:tc:opendocument:xmlns:office:1.0' xmlns:style='urn:oasis:names:tc:opendocument:xmlns:style:1.0' xmlns:text='urn:oasis:names:tc:opendocument:xmlns:text:1.0' xmlns:table='urn:oasis:names:tc:opendocument:xmlns:table:1.0' xmlns:draw='urn:oasis:names:tc:opendocument:xmlns:drawing:1.0' xmlns:fo='urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:meta='urn:oasis:names:tc:opendocument:xmlns:meta:1.0' xmlns:number='urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0' xmlns:svg='urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0' xmlns:chart='urn:oasis:names:tc:opendocument:xmlns:chart:1.0' xmlns:dr3d='urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0' xmlns:math='http://www.w3.org/1998/Math/MathML' xmlns:form='urn:oasis:names:tc:opendocument:xmlns:form:1.0' xmlns:script='urn:oasis:names:tc:opendocument:xmlns:script:1.0' xmlns:ooo='http://openoffice.org/2004/office' xmlns:ooow='http://openoffice.org/2004/writer' xmlns:oooc='http://openoffice.org/2004/calc' xmlns:dom='http://www.w3.org/2001/xml-events' office:version='1.0'>" . " <office:font-face-decls>" . " </office:font-face-decls>" . " <office:styles>" . " <style:style style:name='Table_20_Heading' style:display-name='Table Heading' style:family='paragraph' style:parent-style-name='Table_20_Contents' style:class='extra'>" . " <style:paragraph-properties fo:text-align='center' style:justify-single-word='false' text:number-lines='false' text:line-number='0'/>" . " <style:text-properties fo:font-style='italic' fo:font-weight='bold' style:font-style-asian='italic' style:font-weight-asian='bold' style:font-style-complex='italic' style:font-weight-complex='bold'/>" . " </style:style>" . " <style:style style:name='Preformatted_20_Text' style:display-name='Preformatted Text' style:family='paragraph' style:parent-style-name='Standard' style:class='html'>" . " <style:paragraph-properties fo:margin-top='0in' fo:margin-bottom='0in'/>" . " <style:text-properties style:font-name='Courier New' fo:font-size='10pt' style:font-name-asian='Courier New' style:font-size-asian='10pt' style:font-name-complex='Courier New' style:font-size-complex='10pt'/>" . " </style:style>" . " <style:style style:name='eZCustom_20_factbox' style:display-name='eZCustom_20_factbox' style:family='paragraph' style:parent-style-name='Standard' style:class='text'>" . " <style:paragraph-properties fo:margin-top='0in' fo:margin-bottom='0in'/>" . " <style:text-properties style:font-name='Helvetica' fo:font-size='10pt' style:font-name-asian='Helvetica' style:font-size-asian='10pt' style:font-name-complex='Helvetica' style:font-size-complex='10pt'/>" . " </style:style>" . " <style:style style:name='eZCustom_20_quote' style:display-name='eZCustom_20_quote' style:family='paragraph' style:parent-style-name='Standard' style:class='text'>" . " <style:paragraph-properties fo:margin-top='0in' fo:margin-bottom='0in'/>" . " <style:text-properties style:font-name='Helvetica' fo:font-size='10pt' style:font-name-asian='Helvetica' style:font-size-asian='10pt' style:font-name-complex='Helvetica' style:font-size-complex='10pt'/>" . " </style:style>" . " </office:styles>" . "</office:document-styles>"; file_put_contents($this->OOExportDir . "styles.xml", $stylesXML); } $mimeType = "application/vnd.oasis.opendocument.text"; file_put_contents($this->OOExportDir . "mimetype", $mimeType); // Write content XML file $contentXML = "<?xml version='1.0' encoding='UTF-8'?>" . "<!DOCTYPE office:document-content PUBLIC '-//OpenOffice.org//DTD OfficeDocument1.0//EN' 'office.dtd'>" . "<office:document-content xmlns:office='urn:oasis:names:tc:opendocument:xmlns:office:1.0'" . " xmlns:meta='urn:oasis:names:tc:opendocument:xmlns:meta:1.0'" . " xmlns:config='urn:oasis:names:tc:opendocument:xmlns:config:1.0'" . " xmlns:text='urn:oasis:names:tc:opendocument:xmlns:text:1.0'" . " xmlns:table='urn:oasis:names:tc:opendocument:xmlns:table:1.0'" . " xmlns:draw='urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'" . " xmlns:presentation='urn:oasis:names:tc:opendocument:xmlns:presentation:1.0'" . " xmlns:dr3d='urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'" . " xmlns:chart='urn:oasis:names:tc:opendocument:xmlns:chart:1.0'" . " xmlns:form='urn:oasis:names:tc:opendocument:xmlns:form:1.0'" . " xmlns:script='urn:oasis:names:tc:opendocument:xmlns:script:1.0'" . " xmlns:style='urn:oasis:names:tc:opendocument:xmlns:style:1.0'" . " xmlns:number='urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'" . " xmlns:math='http://www.w3.org/1998/Math/MathML'" . " xmlns:svg='urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'" . " xmlns:fo='urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'" . " xmlns:koffice='http://www.koffice.org/2005/'" . " xmlns:dc='http://purl.org/dc/elements/1.1/'" . " xmlns:xlink='http://www.w3.org/1999/xlink'>" . " <office:script/>" . " <office:font-face-decls/>" . " <office:automatic-styles>" . " <text:list-style style:name='bulletlist'>" . " <text:list-level-style-bullet text:level='1' text:style-name='Bullet_20_Symbols' style:num-suffix='.' text:bullet-char='●'>" . " <style:list-level-properties text:space-before='0.25in' text:min-label-width='0.25in'/>" . " <style:text-properties style:font-name='StarSymbol'/>" . " </text:list-level-style-bullet>" . " <text:list-level-style-bullet text:level='2' text:style-name='Bullet_20_Symbols' style:num-suffix='.' text:bullet-char='○'>" . " <style:list-level-properties text:space-before='0.5in' text:min-label-width='0.25in'/>" . " <style:text-properties style:font-name='StarSymbol'/>" . " </text:list-level-style-bullet>" . " <text:list-level-style-bullet text:level='3' text:style-name='Bullet_20_Symbols' style:num-suffix='.' text:bullet-char='■'>" . " <style:list-level-properties text:space-before='0.75in' text:min-label-width='0.25in'/>" . " <style:text-properties style:font-name='StarSymbol'/>" . " </text:list-level-style-bullet>" . " </text:list-style>" . " <text:list-style style:name='numberedlist'>" . " <text:list-level-style-number text:level='1' text:style-name='Numbering_20_Symbols' style:num-suffix='.' style:num-format='1'>" . " <style:list-level-properties text:space-before='0.25in' text:min-label-width='0.25in'/>" . " </text:list-level-style-number>" . " </text:list-style>" . " <style:style style:name='imagecentered' style:family='graphic' style:parent-style-name='Graphics'>" . " <style:graphic-properties style:horizontal-pos='center' style:horizontal-rel='paragraph' style:mirror='none' fo:clip='rect(0in 0in 0in 0in)' draw:luminance='0%' draw:contrast='0%' draw:red='0%' draw:green='0%' draw:blue='0%' draw:gamma='100%' draw:color-inversion='false' draw:image-opacity='100%' draw:color-mode='standard'/>" . " </style:style>" . " <style:style style:name='imageleft' style:family='graphic' style:parent-style-name='Graphics'>" . " <style:graphic-properties style:wrap='right' style:horizontal-pos='left' style:horizontal-rel='paragraph' style:mirror='none' fo:clip='rect(0in 0in 0in 0in)' draw:luminance='0%' draw:contrast='0%' draw:red='0%' draw:green='0%' draw:blue='0%' draw:gamma='100%' draw:color-inversion='false' draw:image-opacity='100%' draw:color-mode='standard'/>" . " </style:style>" . " <style:style style:name='imageright' style:family='graphic' style:parent-style-name='Graphics'>" . " <style:graphic-properties style:wrap='left' style:horizontal-pos='right' style:horizontal-rel='paragraph' style:mirror='none' fo:clip='rect(0in 0in 0in 0in)' draw:luminance='0%' draw:contrast='0%' draw:red='0%' draw:green='0%' draw:blue='0%' draw:gamma='100%' draw:color-inversion='false' draw:image-opacity='100%' draw:color-mode='standard'/>" . " </style:style>" . " <style:style style:name='T1' style:family='text'>" . " <style:text-properties fo:font-weight='bold' style:font-weight-asian='bold' style:font-weight-complex='bold'/>" . " </style:style>" . " <style:style style:name='T2' style:family='text'>" . " <style:text-properties fo:font-style='italic' style:font-style-asian='italic' style:font-style-complex='italic'/>" . " </style:style>" . " </office:automatic-styles>" . " <office:body>" . " <office:text>"; $bodyXML = ""; // Add body contents foreach ($this->DocumentArray as $element) { $bodyXML .= $this->handleElement($element); } // Handle charset conversion if needed $charset = 'UTF-8'; $codec = eZTextCodec::instance(false, $charset); $bodyXML = $codec->convertString($bodyXML); $contentXML .= $bodyXML; // Add the content end $contentXML .= "</office:text></office:body></office:document-content>"; file_put_contents($this->OOExportDir . "content.xml", $contentXML); // Write the manifest file $manifestXML = "<?xml version='1.0' encoding='UTF-8'?>" . "<!DOCTYPE manifest:manifest PUBLIC '-//OpenOffice.org//DTD Manifest 1.0//EN' 'Manifest.dtd'>" . "<manifest:manifest xmlns:manifest='urn:oasis:names:tc:opendocument:xmlns:manifest:1.0'>" . "<manifest:file-entry manifest:media-type='application/vnd.oasis.opendocument.text' manifest:full-path='/'/>" . "<manifest:file-entry manifest:media-type='application/vnd.sun.xml.ui.configuration' manifest:full-path='Configurations2/'/>" . "<manifest:file-entry manifest:media-type='' manifest:full-path='Pictures/'/>" . "<manifest:file-entry manifest:media-type='text/xml' manifest:full-path='content.xml'/>" . "<manifest:file-entry manifest:media-type='text/xml' manifest:full-path='styles.xml'/>" . "<manifest:file-entry manifest:media-type='text/xml' manifest:full-path='meta.xml'/>" . "<manifest:file-entry manifest:media-type='' manifest:full-path='Thumbnails/'/>" . "<manifest:file-entry manifest:media-type='text/xml' manifest:full-path='settings.xml'/>"; // Do not include the thumnail file. // "<manifest:file-entry manifest:media-type='' manifest:full-path='Thumbnails/thumbnail.png'/>" . foreach ($this->ImageFileArray as $imageFile) { $manifestXML .= "<manifest:file-entry manifest:media-type='' manifest:full-path='{$imageFile}'/>\n"; } $manifestXML .= "</manifest:manifest>"; file_put_contents($this->OOExportDir . "META-INF/manifest.xml", $manifestXML); $fileName = $this->OORootDir . "ootest.odt"; $zipArchive = ezcArchive::open($fileName, ezcArchive::ZIP); $zipArchive->truncate(); $prefix = $this->OOExportDir; $fileList = array(); eZDir::recursiveList($this->OOExportDir, $this->OOExportDir, $fileList); foreach ($fileList as $fileInfo) { $path = $fileInfo['type'] === 'dir' ? $fileInfo['path'] . '/' . $fileInfo['name'] . '/' : $fileInfo['path'] . '/' . $fileInfo['name']; $zipArchive->append(array($path), $prefix); } $zipArchive->close(); // Clean up eZDir::recursiveDelete($this->OOExportDir); eZDir::recursiveDelete($this->OOTemplateDir); // Clean up temporary image files if any $fileHandler = eZClusterFileHandler::instance(); foreach ($this->SourceImageArray as $sourceImageFile) { $fileHandler->fileDeleteLocal($sourceImageFile); } return $fileName; }
/** * Returns a shared instance of the eZDBInterface class aka database object. * If you want to change the current database values you should use $forceNewInstance. * * @param string|false $databaseImplementation * @param array|false $databaseParameters If array, then key 'use_defaults' (bool) is used. * @param bool $forceNewInstance * @return eZDBInterface */ static function instance($databaseImplementation = false, $databaseParameters = false, $forceNewInstance = false) { $impl =& $GLOBALS['eZDBGlobalInstance']; $fetchInstance = false; if (!$impl instanceof eZDBInterface) { $fetchInstance = true; } if ($forceNewInstance) { unset($impl); $impl = false; $fetchInstance = true; } $useDefaults = true; if (is_array($databaseParameters) and isset($databaseParameters['use_defaults'])) { $useDefaults = $databaseParameters['use_defaults']; } if ($fetchInstance) { $ini = eZINI::instance(); if ($databaseImplementation === false and $useDefaults) { $databaseImplementation = $ini->variable('DatabaseSettings', 'DatabaseImplementation'); } $server = $user = $pwd = $db = $usePersistentConnection = $port = false; if ($useDefaults) { list($server, $port, $user, $pwd, $db, $usePersistentConnection) = $ini->variableMulti('DatabaseSettings', array('Server', 'Port', 'User', 'Password', 'Database', 'UsePersistentConnection')); } $socketPath = false; if ($useDefaults) { $socket = $ini->variable('DatabaseSettings', 'Socket'); if (trim($socket != "") and $socket != "disabled") { $socketPath = $socket; } } // Check slave servers $slaveServer = null; $slaveServerPort = null; $slaveServerUser = null; $slaveServerPassword = null; $slaveServerDatabase = null; $useSlave = $ini->variable('DatabaseSettings', 'UseSlaveServer'); if ($useSlave == "enabled") { $slaveServers = $ini->variable('DatabaseSettings', 'SlaveServerArray'); $slaveServerPorts = $ini->variable('DatabaseSettings', 'SlaveServerPort'); $slaveServerUsers = $ini->variable('DatabaseSettings', 'SlaverServerUser'); $slaveServerPasswords = $ini->variable('DatabaseSettings', 'SlaverServerPassword'); $slaveServerDatabases = $ini->variable('DatabaseSettings', 'SlaverServerDatabase'); $numberServers = count($slaveServers); if ($numberServers > 1) { $index = mt_rand(1, $numberServers) - 1; } else { $index = 0; } $slaveServer = $slaveServers[$index]; $slaveServerPort = $slaveServerPorts[$index]; $slaveServerUser = $slaveServerUsers[$index]; $slaveServerPassword = $slaveServerPasswords[$index]; $slaveServerDatabase = $slaveServerDatabases[$index]; } list($charset, $retries) = $ini->variableMulti('DatabaseSettings', array('Charset', 'ConnectRetries')); $isInternalCharset = false; if (trim($charset) == '') { $charset = eZTextCodec::internalCharset(); $isInternalCharset = true; } $builtinEncoding = $ini->variable('DatabaseSettings', 'UseBuiltinEncoding') == 'true'; $impl = null; $useSlaveServer = false; if ($useSlave == "enabled") { $useSlaveServer = true; } $defaultDatabaseParameters = array('server' => $server, 'port' => $port, 'user' => $user, 'password' => $pwd, 'database' => $db, 'use_slave_server' => $useSlaveServer, 'slave_server' => $slaveServer, 'slave_port' => $slaveServerPort, 'slave_user' => $slaveServerUser, 'slave_password' => $slaveServerPassword, 'slave_database' => $slaveServerDatabase, 'charset' => $charset, 'is_internal_charset' => $isInternalCharset, 'socket' => $socketPath, 'builtin_encoding' => $builtinEncoding, 'connect_retries' => $retries, 'use_persistent_connection' => $usePersistentConnection, 'show_errors' => true); /* This looks funny, but is needed to fix a crash in PHP */ $b = $databaseParameters; $databaseParameters = $defaultDatabaseParameters; if (isset($b['server'])) { $databaseParameters['server'] = $b['server']; } if (isset($b['port'])) { $databaseParameters['port'] = $b['port']; } if (isset($b['user'])) { $databaseParameters['user'] = $b['user']; } if (isset($b['password'])) { $databaseParameters['password'] = $b['password']; } if (isset($b['database'])) { $databaseParameters['database'] = $b['database']; } if (isset($b['use_slave_server'])) { $databaseParameters['use_slave_server'] = $b['use_slave_server']; } if (isset($b['slave_server'])) { $databaseParameters['slave_server'] = $b['slave_server']; } if (isset($b['slave_port'])) { $databaseParameters['slave_port'] = $b['slave_port']; } if (isset($b['slave_user'])) { $databaseParameters['slave_user'] = $b['slave_user']; } if (isset($b['slave_password'])) { $databaseParameters['slave_password'] = $b['slave_password']; } if (isset($b['slave_database'])) { $databaseParameters['slave_database'] = $b['slave_database']; } if (isset($b['charset'])) { $databaseParameters['charset'] = $b['charset']; $databaseParameters['is_internal_charset'] = false; } if (isset($b['socket'])) { $databaseParameters['socket'] = $b['socket']; } if (isset($b['builtin_encoding'])) { $databaseParameters['builtin_encoding'] = $b['builtin_encoding']; } if (isset($b['connect_retries'])) { $databaseParameters['connect_retries'] = $b['connect_retries']; } if (isset($b['use_persistent_connection'])) { $databaseParameters['use_persistent_connection'] = $b['use_persistent_connection']; } if (isset($b['show_errors'])) { $databaseParameters['show_errors'] = $b['show_errors']; } $optionArray = array('iniFile' => 'site.ini', 'iniSection' => 'DatabaseSettings', 'iniVariable' => 'ImplementationAlias', 'handlerIndex' => $databaseImplementation, 'handlerParams' => array($databaseParameters)); $options = new ezpExtensionOptions($optionArray); $impl = eZExtension::getHandlerClass($options); if (!$impl) { $impl = new eZNullDB($databaseParameters); $impl->ErrorMessage = "No database handler was found for '{$databaseImplementation}'"; $impl->ErrorNumber = -1; if ($databaseParameters['show_errors']) { eZDebug::writeError('Database implementation not supported: ' . $databaseImplementation, __METHOD__); } } $impl->setErrorHandling(self::$errorHandling); } return $impl; }
function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement ) { $config = eZINI::instance( 'pdf.ini' ); switch ( $namedParameters['operation'] ) { case 'toc': { $operatorValue = '<C:callTOC'; if ( count( $operatorParameters ) > 1 ) { $params = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); $operatorValue .= isset( $params['size'] ) ? ':size:'. implode(',', $params['size'] ) : ''; $operatorValue .= isset( $params['dots'] ) ? ':dots:'. $params['dots'] : ''; $operatorValue .= isset( $params['contentText'] ) ? ':contentText:'. $params['contentText'] : ''; $operatorValue .= isset( $params['indent'] ) ? ':indent:'. implode(',', $params['indent'] ) : ''; } $operatorValue .= '>'; eZDebug::writeNotice( 'PDF: Generating TOC', __METHOD__ ); } break; case 'set_font': { $params = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); $operatorValue = '<ezCall:callFont'; foreach ( $params as $key => $value ) { if ( $key == 'colorCMYK' ) { $operatorValue .= ':cmyk:' . implode( ',', $value ); } else if ( $key == 'colorRGB' ) { $operatorValue .= ':cmyk:' . implode( ',', eZMath::rgbToCMYK2( $value[0]/255, $value[1]/255, $value[2]/255 ) ); } else { $operatorValue .= ':' . $key . ':' . $value; } } $operatorValue .= '>'; eZDebug::writeNotice( 'PDF: Changed font.' ); } break; case 'table': { $operatorValue = '<ezGroup:callTable'; if ( count( $operatorParameters > 2 ) ) { $tableSettings = $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ); if ( is_array( $tableSettings ) ) { foreach( array_keys( $tableSettings ) as $key ) { switch( $key ) { case 'headerCMYK': case 'cellCMYK': case 'textCMYK': case 'titleCellCMYK': case 'titleTextCMYK': { $operatorValue .= ':' . $key . ':' . implode( ',', $tableSettings[$key] ); } break; default: { $operatorValue .= ':' . $key . ':' . $tableSettings[$key]; } break; } } } } $operatorValue .= '>'; $rows = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); $rows = str_replace( array( ' ', "\t", "\r\n", "\n" ), '', $rows ); $httpCharset = eZTextCodec::internalCharset(); $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' ) ? $config->variable( 'PDFGeneral', 'OutputCharset' ) : 'iso-8859-1'; $codec = eZTextCodec::instance( $httpCharset, $outputCharset ); // Convert current text to $outputCharset (by default iso-8859-1) $rows = $codec->convertString( $rows ); $operatorValue .= urlencode( $rows ); $operatorValue .= '</ezGroup:callTable><C:callNewLine>'; eZDebug::writeNotice( 'PDF: Added table to PDF', __METHOD__ ); } break; case 'header': { $header = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); $header['text'] = str_replace( array( ' ', "\t", "\r\n", "\n" ), '', $header['text'] ); $operatorValue = '<ezCall:callHeader:level:'. $header['level'] .':size:'. $header['size']; if ( isset( $header['align'] ) ) { $operatorValue .= ':justification:'. $header['align']; } if ( isset( $header['font'] ) ) { $operatorValue .= ':fontName:'. $header['font']; } $operatorValue .= ':label:'. rawurlencode( $header['text'] ); $operatorValue .= '><C:callNewLine>'. $header['text'] .'</ezCall:callHeader><C:callNewLine>'; eZDebug::writeNotice( 'PDF: Added header: '. $header['text'] .', size: '. $header['size'] . ', align: '. $header['align'] .', level: '. $header['level'], __METHOD__ ); } break; case 'create': { $this->createPDF(); } break; case 'new_line': case 'newline': // Deprecated { $operatorValue = '<C:callNewLine>'; } break; case 'new_page': case 'newpage': // Deprecated { $operatorValue = '<C:callNewPage><C:callNewLine>'; eZDebug::writeNotice( 'PDF: New page', __METHOD__ ); } break; case 'image': { $image = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); $width = isset( $image['width'] ) ? $image['width']: 100; $height = isset( $image['height'] ) ? $image['height']: 100; $operatorValue = '<C:callImage:src:'. rawurlencode( $image['src'] ) .':width:'. $width .':height:'. $height; if ( isset( $image['static'] ) ) { $operatorValue .= ':static:' . $image['static']; } if ( isset ( $image['x'] ) ) { $operatorValue .= ':x:' . $image['x']; } if ( isset( $image['y'] ) ) { $operatorValue .= ':y:' . $image['y']; } if ( isset( $image['dpi'] ) ) { $operatorValue .= ':dpi:' . $image['dpi']; } if ( isset( $image['align'] ) ) // left, right, center, full { $operatorValue .= ':align:' . $image['align']; } $operatorValue .= '>'; eZDebug::writeNotice( 'PDF: Added Image '.$image['src'].' to PDF file', __METHOD__ ); } break; case 'anchor': { $name = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); $operatorValue = '<C:callAnchor:'. $name['name'] .':FitH:>'; eZDebug::writeNotice( 'PDF: Added anchor: '.$name['name'], __METHOD__ ); } break; case 'link': // external link { $link = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); $link['text'] = str_replace( '"', '"', $link['text'] ); $operatorValue = '<c:alink:'. rawurlencode( $link['url'] ) .'>'. $link['text'] .'</c:alink>'; eZDebug::writeNotice( 'PDF: Added link: '. $link['text'] .', url: '.$link['url'], __METHOD__ ); } break; case 'stream': { $this->PDF->ezStream(); } case 'close': { $filename = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); eZDir::mkdir( eZDir::dirpath( $filename ), false, true ); $file = eZClusterFileHandler::instance( $filename ); $file->storeContents( $this->PDF->ezOutput(), 'viewcache', 'pdf' ); eZDebug::writeNotice( 'PDF file closed and saved to '. $filename, __METHOD__ ); } break; case 'strike': { $text = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); $operatorValue = '<c:strike>'. $text .'</c:strike>'; eZDebug::writeNotice( 'Striked text added to PDF: "'. $text .'"', __METHOD__ ); } break; /* usage : execute/add text to pdf file, pdf(execute,<text>) */ case 'execute': { $text = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); if ( count ( $operatorParameters ) > 2 ) { $options = $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ); $size = isset( $options['size'] ) ? $options['size'] : $config->variable( 'PDFGeneral', 'Format' ); $orientation = isset( $options['orientation'] ) ? $options['orientation'] : $config->variable( 'PDFGeneral', 'Orientation' ); $this->createPDF( $size, $orientation ); } else { $this->createPDF( $config->variable( 'PDFGeneral', 'Format' ), $config->variable( 'PDFGeneral', 'Orientation' ) ); } $text = str_replace( array( ' ', "\n", "\t" ), '', $text ); $httpCharset = eZTextCodec::internalCharset(); $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' ) ? $config->variable( 'PDFGeneral', 'OutputCharset' ) : 'iso-8859-1'; $codec = eZTextCodec::instance( $httpCharset, $outputCharset ); // Convert current text to $outputCharset (by default iso-8859-1) $text = $codec->convertString( $text ); $this->PDF->ezText( $text ); eZDebug::writeNotice( 'Execute text in PDF, length: "'. strlen( $text ) .'"', __METHOD__ ); } break; case 'page_number': case 'pageNumber': { $numberDesc = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); if ( isset( $numberDesc['identifier'] ) ) { $identifier = $numberDesc['identifier']; } else { $identifier = 'main'; } if ( isset( $numberDesc['start'] ) ) { $operatorValue = '<C:callStartPageCounter:start:'. $numberDesc['start'] .':identifier:'. $identifier .'>'; } else if ( isset( $numberDesc['stop'] ) ) { $operatorValue = '<C:callStartPageCounter:stop:1:identifier:'. $identifier .'>'; } } break; /* usage {pdf( line, hash( x1, <x>, y1, <y>, x2, <x2>, y2, <y2>, pages, <all|current>, thickness, <1..100>, ) )} */ case 'line': { $lineDesc = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); if ( isset( $lineDesc['pages']) and $lineDesc['pages'] == 'all' ) { $operatorValue = '<ezGroup:callLine'; } else { $operatorValue = '<C:callDrawLine'; } $operatorValue .= ':x1:' . $lineDesc['x1']; $operatorValue .= ':x2:' . $lineDesc['x2']; $operatorValue .= ':y1:' . $lineDesc['y1']; $operatorValue .= ':y2:' . $lineDesc['y2']; $operatorValue .= ':thickness:' . ( isset( $lineDesc['thickness'] ) ? $lineDesc['thickness'] : '1' ); $operatorValue .= '>'; if ( $lineDesc['pages'] == 'all' ) { $operatorValue .= '___</ezGroup:callLine>'; } return $operatorValue; } break; case 'footer_block': case 'header_block': { $frameDesc = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); $operatorValue = '<ezGroup:callBlockFrame'; $operatorValue .= ':location:'. $namedParameters['operation']; $operatorValue .= '>'; if ( isset( $frameDesc['block_code'] ) ) { $httpCharset = eZTextCodec::internalCharset(); $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' ) ? $config->variable( 'PDFGeneral', 'OutputCharset' ) : 'iso-8859-1'; $codec = eZTextCodec::instance( $httpCharset, $outputCharset ); // Convert current text to $outputCharset (by default iso-8859-1) $frameDesc['block_code'] = $codec->convertString( $frameDesc['block_code'] ); $operatorValue .= urlencode( $frameDesc['block_code'] ); } $operatorValue .= '</ezGroup:callBlockFrame>'; eZDebug::writeNotice( 'PDF: Added Block '.$namedParameters['operation'] .': '.$operatorValue, __METHOD__ ); return $operatorValue; } break; /* deprecated */ case 'footer': case 'frame_header': { $frameDesc = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); $operatorValue = '<ezGroup:callFrame'; $operatorValue .= ':location:'. $namedParameters['operation']; if ( $namedParameters['operation'] == 'footer' ) { $frameType = 'Footer'; } else if( $namedParameters['operation'] == 'frame_header' ) { $frameType = 'Header'; } if ( isset( $frameDesc['align'] ) ) { $operatorValue .= ':justification:'. $frameDesc['align']; } if ( isset( $frameDesc['page'] ) ) { $operatorValue .= ':page:'. $frameDesc['page']; } else { $operatorValue .= ':page:all'; } $operatorValue .= ':newline:' . ( isset( $frameDesc['newline'] ) ? $frameDesc['newline'] : 0 ); $operatorValue .= ':pageOffset:'; if ( isset( $frameDesc['pageOffset'] ) ) { $operatorValue .= $frameDesc['pageOffset']; } else { $operatorValue .= $this->Config->variable( $frameType, 'PageOffset' ); } if ( isset( $frameDesc['size'] ) ) { $operatorValue .= ':size:'. $frameDesc['size']; } if ( isset( $frameDesc['font'] ) ) { $operatorValue .= ':font:'. $frameDesc['font']; } $operatorValue .= '>'; if ( isset( $frameDesc['text'] ) ) { $httpCharset = eZTextCodec::internalCharset(); $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' ) ? $config->variable( 'PDFGeneral', 'OutputCharset' ) : 'iso-8859-1'; $codec = eZTextCodec::instance( $httpCharset, $outputCharset ); // Convert current text to $outputCharset (by default iso-8859-1) $frameDesc['text'] = $codec->convertString( $frameDesc['text'] ); $operatorValue .= urlencode( $frameDesc['text'] ); } $operatorValue .= '</ezGroup:callFrame>'; if ( isset( $frameDesc['margin'] ) ) { $operatorValue .= '<C:callFrameMargins'; $operatorValue .= ':identifier:'. $namedParameters['operation']; $operatorValue .= ':topMargin:'; if ( isset( $frameDesc['margin']['top'] ) ) { $operatorValue .= $frameDesc['margin']['top']; } else { $operatorValue .= $this->Config->variable( $frameType, 'TopMargin' ); } $operatorValue .= ':bottomMargin:'; if ( isset( $frameDesc['margin']['bottom'] ) ) { $operatorValue .= $frameDesc['margin']['bottom']; } else { $operatorValue .= $this->Config->variable( $frameType, 'BottomMargin' ); } $operatorValue .= ':leftMargin:'; if ( isset( $frameDesc['margin']['left'] ) ) { $operatorValue .= $frameDesc['margin']['left']; } else { $operatorValue .= $this->Config->variable( $frameType, 'LeftMargin' ); } $operatorValue .= ':rightMargin:'; if ( isset( $frameDesc['margin']['right'] ) ) { $operatorValue .= $frameDesc['margin']['right']; } else { $operatorValue .= $this->Config->variable( $frameType, 'RightMargin' ); } $operatorValue .= ':height:'; if ( isset( $frameDesc['margin']['height'] ) ) { $operatorValue .= $frameDesc['margin']['height']; } else { $operatorValue .= $this->Config->variable( $frameType, 'Height' ); } $operatorValue .= '>'; } if ( isset( $frameDesc['line'] ) ) { $operatorValue .= '<C:callFrameLine'; $operatorValue .= ':location:'. $namedParameters['operation']; $operatorValue .= ':margin:'; if( isset( $frameDesc['line']['margin'] ) ) { $operatorValue .= $frameDesc['line']['margin']; } else { $operatorValue .= $this->Config->variable( $frameType, 'LineMargin' ); } if ( isset( $frameDesc['line']['leftMargin'] ) ) { $operatorValue .= ':leftMargin:'. $frameDesc['line']['leftMargin']; } if ( isset( $frameDesc['line']['rightMargin'] ) ) { $operatorValue .= ':rightMargin:'. $frameDesc['line']['rightMargin']; } $operatorValue .= ':pageOffset:'; if ( isset( $frameDesc['line']['pageOffset'] ) ) { $operatorValue .= $frameDesc['line']['pageOffset']; } else { $operatorValue .= $this->Config->variable( $frameType, 'PageOffset' ); } $operatorValue .= ':page:'; if ( isset( $frameDesc['line']['page'] ) ) { $operatorValue .= $frameDesc['line']['page']; } else { $operatorValue .= $this->Config->variable( $frameType, 'Page' ); } $operatorValue .= ':thickness:'; if ( isset( $frameDesc['line']['thickness'] ) ) { $operatorValue .= $frameDesc['line']['thickness']; } else { $operatorValue .= $this->Config->variable( $frameType, 'LineThickness' ); } $operatorValue .= '>'; } eZDebug::writeNotice( 'PDF: Added frame '.$frameType .': '.$operatorValue, __METHOD__ ); } break; case 'frontpage': { $pageDesc = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); $align = isset( $pageDesc['align'] ) ? $pageDesc['align'] : 'center'; $text = isset( $pageDesc['text'] ) ? $pageDesc['text'] : ''; $top_margin = isset( $pageDesc['top_margin'] ) ? $pageDesc['top_margin'] : 100; $operatorValue = '<ezGroup:callFrontpage:justification:'. $align .':top_margin:'. $top_margin; if ( isset( $pageDesc['size'] ) ) { $operatorValue .= ':size:'. $pageDesc['size']; } $text = str_replace( array( ' ', "\t", "\r\n", "\n" ), '', $text ); $httpCharset = eZTextCodec::internalCharset(); $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' ) ? $config->variable( 'PDFGeneral', 'OutputCharset' ) : 'iso-8859-1'; $codec = eZTextCodec::instance( $httpCharset, $outputCharset ); // Convert current text to $outputCharset (by default iso-8859-1) $text = $codec->convertString( $text ); $operatorValue .= '>'. urlencode( $text ) .'</ezGroup:callFrontpage>'; eZDebug::writeNotice( 'Added content to frontpage: '. $operatorValue, __METHOD__ ); } break; /* usage: pdf(set_margin( hash( left, <left_margin>, right, <right_margin>, x, <x offset>, y, <y offset> ))) */ case 'set_margin': { $operatorValue = '<C:callSetMargin'; $options = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); foreach( array_keys( $options ) as $key ) { $operatorValue .= ':' . $key . ':' . $options[$key]; } $operatorValue .= '>'; eZDebug::writeNotice( 'Added new margin/offset setup: ' . $operatorValue ); return $operatorValue; } break; /* add keyword to pdf document */ case 'keyword': { $text = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); $text = str_replace( array( ' ', "\n", "\t" ), '', $text ); $httpCharset = eZTextCodec::internalCharset(); $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' ) ? $config->variable( 'PDFGeneral', 'OutputCharset' ) : 'iso-8859-1'; $codec = eZTextCodec::instance( $httpCharset, $outputCharset ); // Convert current text to $outputCharset (by default iso-8859-1) $text = $codec->convertString( $text ); $operatorValue = '<C:callKeyword:'. rawurlencode( $text ) .'>'; } break; /* add Keyword index to pdf document */ case 'createIndex': case 'create_index': { $operatorValue = '<C:callIndex>'; eZDebug::writeNotice( 'Adding Keyword index to PDF', __METHOD__ ); } break; case 'ul': { $text = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); if ( count( $operatorParameters ) > 2 ) { $params = $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ); } else { $params = array(); } if ( isset( $params['rgb'] ) ) { $params['rgb'] = eZMath::normalizeColorArray( $params['rgb'] ); $params['cmyk'] = eZMath::rgbToCMYK2( $params['rgb'][0]/255, $params['rgb'][1]/255, $params['rgb'][2]/255 ); } if ( !isset( $params['cmyk'] ) ) { $params['cmyk'] = eZMath::rgbToCMYK2( 0, 0, 0 ); } if ( !isset( $params['radius'] ) ) { $params['radius'] = 2; } if ( !isset ( $params['pre_indent'] ) ) { $params['pre_indent'] = 0; } if ( !isset ( $params['indent'] ) ) { $params['indent'] = 2; } if ( !isset ( $params['yOffset'] ) ) { $params['yOffset'] = -1; } $operatorValue = '<C:callCircle' . ':pages:current' . ':x:-1' . ':yOffset:' . $params['yOffset'] . ':y:-1' . ':indent:' . $params['indent'] . ':pre_indent:' . $params['pre_indent'] . ':radius:' . $params['radius'] . ':cmyk:' . implode( ',', $params['cmyk'] ) . '>'; $operatorValue .= '<C:callSetMargin' . ':delta_left:' . ( $params['indent'] + $params['radius'] * 2 + $params['pre_indent'] ) . '>'; $operatorValue .= $text; $operatorValue .= '<C:callSetMargin' . ':delta_left:' . -1 * ( $params['indent'] + $params['radius'] * 2 + $params['pre_indent'] ) . '>'; } break; case 'filled_circle': { $operatorValue = ''; $options = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); if ( !isset( $options['pages'] ) ) { $options['pages'] = 'current'; } if ( !isset( $options['x'] ) ) { $options['x'] = -1; } if ( !isset( $options['y'] ) ) { $options['y'] = -1; } if ( isset( $options['rgb'] ) ) { $options['rgb'] = eZMath::normalizeColorArray( $options['rgb'] ); $options['cmyk'] = eZMath::rgbToCMYK2( $options['rgb'][0]/255, $options['rgb'][1]/255, $options['rgb'][2]/255 ); } $operatorValue = '<C:callCircle' . ':pages:' . $options['pages'] . ':x:' . $options['x'] . ':y:' . $options['y'] . ':radius:' . $options['radius']; if ( isset( $options['cmyk'] ) ) { $operatorValue .= ':cmyk:' . implode( ',', $options['cmyk'] ); } $operatorValue .= '>'; eZDebug::writeNotice( 'PDF Added circle: ' . $operatorValue ); return $operatorValue; } break; case 'rectangle': { $operatorValue = ''; $options = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); if ( !isset( $options['pages'] ) ) { $options['pages'] = 'current'; } if ( !isset( $options['line_width'] ) ) { $options['line_width'] = 1; } if ( !isset( $options['round_corner'] ) ) { $options['round_corner'] = false; } $operatorValue = '<C:callRectangle'; foreach ( $options as $key => $value ) { if ( $key == 'rgb' ) { $options['rgb'] = eZMath::normalizeColorArray( $options['rgb'] ); $operatorValue .= ':cmyk:' . implode( ',', eZMath::rgbToCMYK2( $options['rgb'][0]/255, $options['rgb'][1]/255, $options['rgb'][2]/255 ) ); } else if ( $key == 'cmyk' ) { $operatorValue .= ':cmyk:' . implode( ',', $value ); } else { $operatorValue .= ':' . $key . ':' . $value; } } $operatorValue .= '>'; eZDebug::writeNotice( 'PDF Added rectangle: ' . $operatorValue ); return $operatorValue; } break; /* usage: pdf( filled_rectangle, hash( 'x', <x offset>, 'y' => <y offset>, 'width' => <width>, 'height' => <height>, 'pages', <'all'|'current'|odd|even>, (supported, current) 'rgb', array( <r>, <g>, <b> ), 'cmyk', array( <c>, <m>, <y>, <k> ), 'rgbTop', array( <r>, <b>, <g> ), 'rgbBottom', array( <r>, <b>, <g> ), 'cmykTop', array( <c>, <m>, <y>, <k> ), 'cmykBottom', array( <c>, <m>, <y>, <k> ) ) ) */ case 'filled_rectangle': { $operatorValue = ''; $options = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); if ( !isset( $options['pages'] ) ) { $options['pages'] = 'current'; } if ( isset( $options['rgb'] ) ) { $options['rgb'] = eZMath::normalizeColorArray( $options['rgb'] ); $options['cmyk'] = eZMath::rgbToCMYK2( $options['rgb'][0]/255, $options['rgb'][1]/255, $options['rgb'][2]/255 ); } if ( isset( $options['cmyk'] ) ) { $options['cmykTop'] = $options['cmyk']; $options['cmykBottom'] = $options['cmyk']; } if ( !isset( $options['cmykTop'] ) ) { if ( isset( $options['rgbTop'] ) ) { $options['rgbTop'] = eZMath::normalizeColorArray( $options['rgbTop'] ); $options['cmykTop'] = eZMath::rgbToCMYK2( $options['rgbTop'][0]/255, $options['rgbTop'][1]/255, $options['rgbTop'][2]/255 ); } else { $options['cmykTop'] = eZMath::rgbToCMYK2( 0, 0, 0 ); } } if ( !isset( $options['cmykBottom'] ) ) { if ( isset( $options['rgbBottom'] ) ) { $options['rgbBottom'] = eZMath::normalizeColorArray( $options['rgbBottom'] ); $options['cmykBottom'] = eZMath::rgbToCMYK2( $options['rgbBottom'][0]/255, $options['rgbBottom'][1]/255, $options['rgbBottom'][2]/255 ); } else { $options['cmykBottom'] = eZMath::rgbToCMYK2( 0, 0, 0 ); } } if ( !isset( $options['pages'] ) ) { $options['pages'] = 'current'; } $operatorValue = '<C:callFilledRectangle' . ':pages:' . $options['pages'] . ':x:' . $options['x'] . ':y:' . $options['y'] . ':width:' . $options['width'] . ':height:' . $options['height'] . ':cmykTop:' . implode( ',', $options['cmykTop'] ) . ':cmykBottom:' . implode( ',', $options['cmykBottom'] ) . '>'; eZDebug::writeNotice( 'Added rectangle: ' . $operatorValue ); } break; /* usage : pdf(text, <text>, array( 'font' => <fontname>, 'size' => <fontsize> )) */ case 'text': { $text = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); $operatorValue = ''; $changeFont = false; if ( count( $operatorParameters ) >= 3) { $textSettings = $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ); if ( isset( $textSettings ) ) { $operatorValue .= '<ezCall:callText'; $changeFont = true; if ( isset( $textSettings['font'] ) ) { $operatorValue .= ':font:'. $textSettings['font']; } if ( isset( $textSettings['size'] ) ) { $operatorValue .= ':size:'. $textSettings['size']; } if ( isset( $textSettings['align'] ) ) { $operatorValue .= ':justification:'. $textSettings['align']; } if ( isset( $textSettings['rgb'] ) ) { $textSettings['cmyk'] = eZMath::rgbToCMYK2( $textSettings['rgb'][0]/255, $textSettings['rgb'][1]/255, $textSettings['rgb'][2]/255 ); } if ( isset( $textSettings['cmyk'] ) ) { $operatorValue .= ':cmyk:' . implode( ',', $textSettings['cmyk'] ); } $operatorValue .= '>'; } } $operatorValue .= $text; if ( $changeFont ) { $operatorValue .= '</ezCall:callText>'; } } break; case 'text_box': { $parameters = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); $operatorValue = '<ezGroup:callTextBox'; foreach( array_keys( $parameters ) as $key ) { if ( $key != 'text' ) { $operatorValue .= ':' . $key . ':' . urlencode( $parameters[$key] ); } } $httpCharset = eZTextCodec::internalCharset(); $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' ) ? $config->variable( 'PDFGeneral', 'OutputCharset' ) : 'iso-8859-1'; $codec = eZTextCodec::instance( $httpCharset, $outputCharset ); // Convert current text to $outputCharset (by default iso-8859-1) $parameters['text'] = $codec->convertString( $parameters['text'] ); $operatorValue .= '>'; $operatorValue .= urlencode( $parameters['text'] ); $operatorValue .= '</ezGroup:callTextBox>'; return $operatorValue; } break; case 'text_frame': { $text = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); $operatorValue = ''; $changeFont = false; if ( count( $operatorParameters ) >= 3) { $textSettings = $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ); if ( isset( $textSettings ) ) { $operatorValue .= '<ezGroup:callTextFrame'; $changeFont = true; foreach ( array_keys( $textSettings ) as $key ) //settings, padding (left, right, top, bottom), textcmyk, framecmyk { if ( $key == 'frameCMYK' ) { $operatorValue .= ':frameCMYK:' . implode( ',', $textSettings['frameCMYK'] ); } else if ( $key == 'frameRGB' ) { $operatorValue .= ':frameCMYK:' . implode( ',', eZMath::rgbToCMYK2( $textSettings['frameRGB'][0]/255, $textSettings['frameRGB'][1]/255, $textSettings['frameRGB'][2]/255 ) ); } else if ( $key == 'textCMYK' ) { $operatorValue .= ':textCMYK:' . implode( ',', $textSettings['textCMYK'] ); } else if ( $key == 'textRGB' ) { $operatorValue .= ':textCMYK:' . implode( ',', eZMath::rgbToCMYK2( $textSettings['textRGB'][0]/255, $textSettings['textRGB'][1]/255, $textSettings['textRGB'][2]/255 ) ); } else { $operatorValue .= ':' . $key . ':' . $textSettings[$key]; } } $httpCharset = eZTextCodec::internalCharset(); $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' ) ? $config->variable( 'PDFGeneral', 'OutputCharset' ) : 'iso-8859-1'; $codec = eZTextCodec::instance( $httpCharset, $outputCharset ); // Convert current text to $outputCharset (by default iso-8859-1) $text = $codec->convertString( $text ); $operatorValue .= '>' . urlencode( $text ) . '</ezGroup::callTextFrame>'; } } eZDebug::writeNotice( 'Added TextFrame: ' . $operatorValue ); } break; default: { eZDebug::writeError( 'PDF operation "'. $namedParameters['operation'] .'" undefined', __METHOD__ ); } } }
static function storeCache($key) { $translationCache = eZTranslationCache::cacheTable(); if (!isset($translationCache[$key])) { eZDebug::writeWarning("Translation cache for key '{$key}' does not exist, cannot store cache", __METHOD__); return; } $internalCharset = eZTextCodec::internalCharset(); // $cacheFileKey = "$key-$internalCharset"; $cacheFileKey = $key; $cacheFileName = md5($cacheFileKey) . '.php'; $cache =& $translationCache[$key]; if (!file_exists(eZTranslationCache::cacheDirectory())) { eZDir::mkdir(eZTranslationCache::cacheDirectory(), false, true); } $php = new eZPHPCreator(eZTranslationCache::cacheDirectory(), $cacheFileName); $php->addRawVariable('eZTranslationCacheCodeDate', self::CODE_DATE); $php->addSpace(); $php->addRawVariable('CacheInfo', array('charset' => $internalCharset)); $php->addRawVariable('TranslationInfo', $cache['info']); $php->addSpace(); $php->addRawVariable('TranslationRoot', $cache['root']); $php->store(); }
$childResponse['languages'] = $childObject->availableLanguages(); $childResponse['is_hidden'] = $child->IsHidden; $childResponse['is_invisible'] = $child->IsInvisible; if ($createHereMenu == 'full') { $childResponse['class_list'] = array(); foreach ($child->canCreateClassList() as $class) { $childResponse['class_list'][] = $class['id']; } } $response['children'][] = $childResponse; unset($object); eZContentObject::clearCache(); } $httpCharset = eZTextCodec::httpCharset(); $jsonText = arrayToJSON($response); $codec = eZTextCodec::instance($httpCharset, 'unicode'); $jsonTextArray = $codec->convertString($jsonText); $jsonText = ''; foreach ($jsonTextArray as $character) { if ($character < 128) { $jsonText .= chr($character); } else { $jsonText .= '\\u' . str_pad(dechex($character), 4, '0000', STR_PAD_LEFT); } } header('Expires: ' . gmdate('D, d M Y H:i:s', time() + MAX_AGE) . ' GMT'); header('Cache-Control: cache, max-age=' . MAX_AGE . ', post-check=' . MAX_AGE . ', pre-check=' . MAX_AGE); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $node->ModifiedSubNode) . ' GMT'); header('Pragma: cache'); header('Content-Type: application/json'); header('Content-Length: ' . strlen($jsonText));
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; }
function parseFile($file, $placement = false) { if (eZINI::isDebugEnabled()) { eZDebug::writeNotice("Parsing file '{$file}'", __METHOD__); } $contents = file_get_contents($file); if ($contents === false) { eZDebug::writeError("Failed opening file '{$file}' for reading", __METHOD__); return false; } $contents = str_replace("\r", '', $contents); $endOfLine = strpos($contents, "\n"); $line = substr($contents, 0, $endOfLine); $currentBlock = ""; if ($line) { // check for charset if (preg_match("/#\\?ini(.+)\\?/", $line, $ini_arr)) { $args = explode(" ", trim($ini_arr[1])); foreach ($args as $arg) { $vars = explode('=', trim($arg)); if ($vars[0] == "charset") { $val = $vars[1]; if ($val[0] == '"' and strlen($val) > 0 and $val[strlen($val) - 1] == '"') { $val = substr($val, 1, strlen($val) - 2); } $this->Charset = $val; } } } } unset($this->Codec); if ($this->UseTextCodec) { $this->Codec = eZTextCodec::instance($this->Charset, false, false); if ($this->Codec) { eZDebug::accumulatorStart('ini_conversion', false, 'INI string conversion'); $contents = $this->Codec->convertString($contents); eZDebug::accumulatorStop('ini_conversion', false, 'INI string conversion'); } } else { $this->Codec = null; } foreach (explode("\n", $contents) as $line) { if ($line == '' or $line[0] == '#') { continue; } if (preg_match("/^(.+)##.*/", $line, $regs)) { $line = $regs[1]; } if (trim($line) == '') { continue; } // check for new block if (preg_match("#^\\[(.+)\\]\\s*\$#", $line, $newBlockNameArray)) { $newBlockName = trim($newBlockNameArray[1]); $currentBlock = $newBlockName; continue; } // check for variable if (preg_match("#^([\\w_*@-]+)\\[\\]\$#", $line, $valueArray)) { $varName = trim($valueArray[1]); if ($placement) { if (isset($this->BlockValuesPlacement[$currentBlock][$varName]) && !is_array($this->BlockValuesPlacement[$currentBlock][$varName])) { eZDebug::writeError("Wrong operation on the ini setting array '{$varName}'", __METHOD__); continue; } $this->BlockValuesPlacement[$currentBlock][$varName][] = $file; } else { $this->BlockValues[$currentBlock][$varName] = array(); // In direct access mode we create empty elements at the beginning of an array // in case it is redefined in this ini file. So when we will save it, definition // will be created as well. if ($this->AddArrayDefinition) { $this->BlockValues[$currentBlock][$varName][] = ""; } } } else { if (preg_match("#^([\\w_*@-]+)(\\[([^\\]]*)\\])?=(.*)\$#", $line, $valueArray)) { $varName = trim($valueArray[1]); $varValue = $valueArray[4]; if ($valueArray[2]) { if ($valueArray[3]) { $keyName = $valueArray[3]; if ($placement) { $this->BlockValuesPlacement[$currentBlock][$varName][$keyName] = $file; } else { $this->BlockValues[$currentBlock][$varName][$keyName] = $varValue; } } else { if ($placement) { $this->BlockValuesPlacement[$currentBlock][$varName][] = $file; } else { $this->BlockValues[$currentBlock][$varName][] = $varValue; } } } else { if ($placement) { $this->BlockValuesPlacement[$currentBlock][$varName] = $file; } else { $this->BlockValues[$currentBlock][$varName] = $varValue; } } } } } }
function convertText( $text, $isHeader = false ) { $charset = $this->contentCharset(); if ( $this->isAllowedCharset( $charset ) ) return $text; $outputCharset = $this->outputCharset(); if ( !$this->TextCodec ) { $this->TextCodec = eZTextCodec::instance( $charset, $outputCharset ); } $newText = $this->TextCodec->convertString( $text ); return $newText; }
static function rawXMLText($contentObjectAttribute) { $text = $contentObjectAttribute->attribute('data_text'); $timestamp = $contentObjectAttribute->attribute('data_int'); if ($timestamp < self::VERSION_30_TIMESTAMP) { $charset = 'UTF-8'; $codec = eZTextCodec::instance(false, $charset); $text = $codec->convertString($text); $timestamp = self::VERSION_30_TIMESTAMP; } return $text; }
/** * Handles a translation message DOM node * @param string $contextName * @param DOMNode $message */ function handleMessageNode($contextName, $message) { $source = null; $translation = null; $comment = null; $message_children = $message->childNodes; for ($i = 0; $i < $message_children->length; $i++) { $message_child = $message_children->item($i); if ($message_child->nodeType == XML_ELEMENT_NODE) { $childName = $message_child->tagName; if ($childName == "source") { if ($message_child->childNodes->length > 0) { $source = ''; foreach ($message_child->childNodes as $textEl) { if ($textEl instanceof DOMText) { $source .= $textEl->nodeValue; } else { if ($textEl instanceof DOMElement && $textEl->tagName == 'byte') { $source .= chr(intval('0' . $textEl->getAttribute('value'))); } } } } } else { if ($childName == "translation") { if ($message_child->childNodes->length > 0) { $translation = ''; foreach ($message_child->childNodes as $textEl) { if ($textEl instanceof DOMText) { $translation .= $textEl->nodeValue; } else { if ($textEl instanceof DOMElement && $textEl->tagName == 'byte') { $translation .= chr(intval('0' . $textEl->getAttribute('value'))); } } } } } else { if ($childName == "comment") { $comment_el = $message_child->firstChild; $comment = $comment_el->nodeValue; } else { if ($childName == "translatorcomment") { //Ignore it. } else { if ($childName == "location") { //Handle location element. No functionality yet. } else { eZDebug::writeError("Unknown element name: " . $childName, __METHOD__); } } } } } } } if ($source === null) { eZDebug::writeError("No source name found, skipping message in context '{$contextName}'", __METHOD__); return false; } if ($translation === null) { // eZDebug::writeError( "No translation, skipping message", __METHOD__ ); $translation = $source; } /* we need to convert ourselves if we're using libxml stuff here */ if ($message instanceof DOMElement) { $codec = eZTextCodec::instance("utf8"); $source = $codec->convertString($source); $translation = $codec->convertString($translation); $comment = $codec->convertString($comment); } $this->insert($contextName, $source, $translation, $comment); return true; }
function _connect($newLink = false) { $siteINI = eZINI::instance('site.ini'); if (!isset($GLOBALS['eZDBFileHandlerMysqlBackend_dbparams'])) { $fileINI = eZINI::instance('file.ini'); $params['host'] = $fileINI->variable('ClusteringSettings', 'DBHost'); $params['port'] = $fileINI->variable('ClusteringSettings', 'DBPort'); $params['socket'] = $fileINI->variable('ClusteringSettings', 'DBSocket'); $params['dbname'] = $fileINI->variable('ClusteringSettings', 'DBName'); $params['user'] = $fileINI->variable('ClusteringSettings', 'DBUser'); $params['pass'] = $fileINI->variable('ClusteringSettings', 'DBPassword'); $params['chunk_size'] = $fileINI->variable('ClusteringSettings', 'DBChunkSize'); $params['max_connect_tries'] = $fileINI->variable('ClusteringSettings', 'DBConnectRetries'); $params['max_execute_tries'] = $fileINI->variable('ClusteringSettings', 'DBExecuteRetries'); $params['sql_output'] = $siteINI->variable("DatabaseSettings", "SQLOutput") == "enabled"; $params['cache_generation_timeout'] = $siteINI->variable("ContentSettings", "CacheGenerationTimeout"); $GLOBALS['eZDBFileHandlerMysqlBackend_dbparams'] = $params; } else { $params = $GLOBALS['eZDBFileHandlerMysqlBackend_dbparams']; } $this->dbparams = $params; $serverString = $params['host']; if ($params['socket']) { $serverString .= ':' . $params['socket']; } elseif ($params['port']) { $serverString .= ':' . $params['port']; } $maxTries = $params['max_connect_tries']; $tries = 0; while ($tries < $maxTries) { if ($this->db = mysql_connect($serverString, $params['user'], $params['pass'], $newLink)) { break; } ++$tries; } if (!$this->db) { return $this->_die("Unable to connect to storage server"); } if (!mysql_select_db($params['dbname'], $this->db)) { return $this->_die("Unable to select database {$params['dbname']}"); } $charset = trim($siteINI->variable('DatabaseSettings', 'Charset')); if ($charset === '') { $charset = eZTextCodec::internalCharset(); } if ($charset) { if (!mysql_query("SET NAMES '" . eZMySQLCharset::mapTo($charset) . "'", $this->db)) { return $this->_die("Failed to set Database charset to {$charset}."); } } }
function modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement) { switch ($operatorName) { // Convert all alphabetical chars of operatorvalue to uppercase. case $this->UpcaseName: $funcName = function_exists('mb_strtoupper') ? 'mb_strtoupper' : 'strtoupper'; $operatorValue = $funcName($operatorValue); break; // Convert all alphabetical chars of operatorvalue to lowercase. // Convert all alphabetical chars of operatorvalue to lowercase. case $this->DowncaseName: $funcName = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; $operatorValue = $funcName($operatorValue); break; // Count and return the number of words in operatorvalue. // Count and return the number of words in operatorvalue. case $this->Count_wordsName: $operatorValue = preg_match_all("#(\\w+)#", $operatorValue, $dummy_match); break; // Count and return the number of chars in operatorvalue. // Count and return the number of chars in operatorvalue. case $this->Count_charsName: $funcName = function_exists('mb_strlen') ? 'mb_strlen' : 'strlen'; $operatorValue = $funcName($operatorValue); break; // Insert HTML line breaks before newlines. // Insert HTML line breaks before newlines. case $this->BreakName: $operatorValue = nl2br($operatorValue); break; // Wrap line (insert newlines). // Wrap line (insert newlines). case $this->WrapName: $parameters = array($operatorValue); if ($namedParameters['wrap_at_position']) { $parameters[] = $namedParameters['wrap_at_position']; if ($namedParameters['break_sequence']) { $parameters[] = $namedParameters['break_sequence']; if ($namedParameters['cut']) { $parameters[] = $namedParameters['cut']; } } } $operatorValue = call_user_func_array('wordwrap', $parameters); break; // Convert the first character to uppercase. // Convert the first character to uppercase. case $this->UpfirstName: $i18nIni = eZINI::instance('i18n.ini'); $hasMBString = ($i18nIni->variable('CharacterSettings', 'MBStringExtension') == 'enabled' and function_exists("mb_strtoupper") and function_exists("mb_substr") and function_exists("mb_strlen")); if ($hasMBString) { $encoding = eZTextCodec::internalCharset(); $firstLetter = mb_strtoupper(mb_substr($operatorValue, 0, 1, $encoding), $encoding); $remainingText = mb_substr($operatorValue, 1, mb_strlen($operatorValue, $encoding), $encoding); $operatorValue = $firstLetter . $remainingText; } else { $operatorValue = ucfirst($operatorValue); } break; // Simplify / transform multiple consecutive characters into one. // Simplify / transform multiple consecutive characters into one. case $this->SimplifyName: $simplifyCharacter = $namedParameters['char']; if ($namedParameters['char'] === false) { $replace_this = "/ {2,}/"; $simplifyCharacter = ' '; } else { $replace_this = "/" . $simplifyCharacter . "{2,}/"; } $operatorValue = preg_replace($replace_this, $simplifyCharacter, $operatorValue); break; // Convert all first characters [in all words] to uppercase. // Convert all first characters [in all words] to uppercase. case $this->UpwordName: $i18nIni = eZINI::instance('i18n.ini'); $hasMBString = ($i18nIni->variable('CharacterSettings', 'MBStringExtension') == 'enabled' and function_exists("mb_strtoupper") and function_exists("mb_substr") and function_exists("mb_strlen")); if ($hasMBString) { $encoding = eZTextCodec::internalCharset(); $words = explode(" ", $operatorValue); $newString = array(); foreach ($words as $word) { $firstLetter = mb_strtoupper(mb_substr($word, 0, 1, $encoding), $encoding); $remainingText = mb_substr($word, 1, mb_strlen($word, $encoding), $encoding); $newString[] = $firstLetter . $remainingText; } $operatorValue = implode(" ", $newString); unset($newString, $words); } else { $operatorValue = ucwords($operatorValue); } break; // Strip whitespace from the beginning and end of a string. // Strip whitespace from the beginning and end of a string. case $this->TrimName: if ($namedParameters['chars_to_remove'] === false) { $operatorValue = trim($operatorValue); } else { $operatorValue = trim($operatorValue, $namedParameters['chars_to_remove']); } break; // Pad... // Pad... case $this->PadName: if (strlen($operatorValue) < $namedParameters['desired_length']) { $operatorValue = str_pad($operatorValue, $namedParameters['desired_length'], $namedParameters['pad_sequence']); } break; // Shorten string [default or specified length, length=text+"..."] and add '...' // Shorten string [default or specified length, length=text+"..."] and add '...' case $this->ShortenName: $strlenFunc = function_exists('mb_strlen') ? 'mb_strlen' : 'strlen'; $substrFunc = function_exists('mb_substr') ? 'mb_substr' : 'substr'; if ($strlenFunc($operatorValue) > $namedParameters['chars_to_keep']) { $operatorLength = $strlenFunc($operatorValue); if ($namedParameters['trim_type'] === 'middle') { $appendedStrLen = $strlenFunc($namedParameters['str_to_append']); if ($namedParameters['chars_to_keep'] > $appendedStrLen) { $chop = $namedParameters['chars_to_keep'] - $appendedStrLen; $middlePos = (int) ($chop / 2); $leftPartLength = $middlePos; $rightPartLength = $chop - $middlePos; $operatorValue = trim($substrFunc($operatorValue, 0, $leftPartLength) . $namedParameters['str_to_append'] . $substrFunc($operatorValue, $operatorLength - $rightPartLength, $rightPartLength)); } else { $operatorValue = $namedParameters['str_to_append']; } } else { $chop = $namedParameters['chars_to_keep'] - $strlenFunc($namedParameters['str_to_append']); $operatorValue = $substrFunc($operatorValue, 0, $chop); $operatorValue = trim($operatorValue); if ($operatorLength > $chop) { $operatorValue = $operatorValue . $namedParameters['str_to_append']; } } } break; // Wash (translate strings to non-spammable text): // Wash (translate strings to non-spammable text): case $this->WashName: $type = $namedParameters['type']; $operatorValue = $this->wash($operatorValue, $tpl, $type); break; // Ord (translate a unicode string to actual unicode id/numbers): // Ord (translate a unicode string to actual unicode id/numbers): case $this->OrdName: $codec = eZTextCodec::instance(false, 'unicode'); $output = $codec->convertString($operatorValue); $operatorValue = $output; break; // Chr (generate unicode characters based on input): // Chr (generate unicode characters based on input): case $this->ChrName: $codec = eZTextCodec::instance('unicode', false); $output = $codec->convertString($operatorValue); $operatorValue = $output; break; // Default case: something went wrong - unknown things... // Default case: something went wrong - unknown things... default: $tpl->warning($operatorName, "Unknown string type '{$type}'", $placement); break; } }
/** * Converts filter string to current locale. When an user types in browser * url like: "/content/view/full/2/(namefilter)/a" 'a' letter should be * urldecoded and converted from utf-8 to current locale. * * @return string converted string */ public function convertFilterString() { foreach (array_keys($this->UserArray) as $paramKey) { if ($paramKey == 'namefilter') { $char = $this->UserArray[$paramKey]; $char = urldecode($char); $codec = eZTextCodec::instance('utf-8', false); if ($codec) { $char = $codec->convertString($char); } } } }
static function treeCacheFilename($key, $templateFilepath) { $internalCharset = eZTextCodec::internalCharset(); $extraName = ''; if (preg_match("#^.+/(.*)\\.tpl\$#", $templateFilepath, $matches)) { $extraName = '-' . $matches[1]; } else { if (preg_match("#^(.*)\\.tpl\$#", $templateFilepath, $matches)) { $extraName = '-' . $matches[1]; } } $cacheFileKey = "{$key}-{$internalCharset}"; $cacheFileName = md5($cacheFileKey) . $extraName . '.php'; return $cacheFileName; }
$dom = new DOMDocument('1.0', 'utf-8'); if ($dom->loadXML($xmlText)) { $OriginalFilename = $dom->getElementsByTagName('OriginalFilename')->item(0)->textContent; $FileType = $dom->getElementsByTagName('Type')->item(0)->textContent; $Filename = $dom->getElementsByTagName('Filename')->item(0)->textContent; if (file_exists(eZSys::wwwDir() . $Filename)) { $fileAttachments[] = array(eZSys::wwwDir() . $Filename, $OriginalFilename, $FileType); } } } } } if (count($fileAttachments) != 0) { $mime_boundary = "==Multipart_Boundary_" . md5(time()); //Plain Text part of Message $message = "--{$mime_boundary}\n" . "Content-Type: text/html; " . eZTextCodec::internalCharset() . "\n" . "Content-Transfer-Encoding: 8bit\n\n"; //Form Result $message .= $templateResult; //Attachment(s) part of message foreach ($fileAttachments as $attacharray) { $filedata = chunk_split(base64_encode(eZFile::getContents($attacharray[0]))); $message .= "\n\n\n--{$mime_boundary}\n" . "Content-Type: " . $attacharray[2] . ";\n" . " name=\"" . $attacharray[1] . "\"\n" . "Content-Transfer-Encoding: base64\n" . "Content-Disposition: inline;\n" . " filename=\"" . $attacharray[1] . "\"\n\n" . $filedata . "\n"; } $message .= "--{$mime_boundary}--\n\n\n"; $templateResult = $message; $mail->setContentType("multipart/mixed;boundary={$mime_boundary}", false, false, false); } //END ENHANCED BINARY EXTENSION MAIL CODE ADDITION $mail->setBody($templateResult); $mailResult = eZMailTransport::send($mail); }
static function compilationFilename($key, $resourceData) { $internalCharset = eZTextCodec::internalCharset(); $templateFilepath = $resourceData['template-filename']; $extraName = ''; if (preg_match("#^.+/(.*)\\.tpl\$#", $templateFilepath, $matches)) { $extraName = $matches[1] . '-'; } else { if (preg_match("#^(.*)\\.tpl\$#", $templateFilepath, $matches)) { $extraName = $matches[1] . '-'; } } $accessText = false; if (isset($GLOBALS['eZCurrentAccess']['name'])) { $accessText = '-' . $GLOBALS['eZCurrentAccess']['name']; } $locale = eZLocale::instance(); $language = $locale->localeFullCode(); $http = eZHTTPTool::instance(); $useFullUrlText = $http->UseFullUrl ? 'full' : 'relative'; $pageLayoutVariable = ""; if (isset($GLOBALS['eZCustomPageLayout'])) { $pageLayoutVariable = $GLOBALS['eZCustomPageLayout']; } $ini = eZINI::instance(); $shareTemplates = $ini->hasVariable('TemplateSettings', 'ShareCompiledTemplates') ? $ini->variable('TemplateSettings', 'ShareCompiledTemplates') == 'enabled' : false; if ($shareTemplates) { $cacheFileKey = $key . '-' . $language; } else { $cacheFileKey = $key . '-' . $internalCharset . '-' . $language . '-' . $useFullUrlText . $accessText . "-" . $pageLayoutVariable . '-' . eZSys::indexFile(); } $cacheFileName = $extraName . md5($cacheFileKey) . '.php'; return $cacheFileName; }
/** * Recodes $string from charset $fromCharset to charset $toCharset. * * Method from eZWebDAVServer. * * @param string $string * @param string $fromCharset * @param string $toCharset * @param bool $stop * @return string */ protected static function recode($string, $fromCharset, $toCharset, $stop = false) { $codec = eZTextCodec::instance($fromCharset, $toCharset, false); if ($codec) { $string = $codec->convertString($string); } return $string; }
static function strtolower($text) { //We need to detect our internal charset if (self::$charset === null) { self::$charset = eZTextCodec::internalCharset(); } //First try to use mbstring if (extension_loaded('mbstring')) { return mb_strtolower($text, self::$charset); } else { // Fall back if mbstring is not available $char = eZCharTransform::instance(); return $char->transformByGroup($text, 'lowercase'); } }
function handleResourceData($tpl, $handler, &$resourceData, $method, &$extraParameters) { // &$templateRoot, &$text, &$tstamp, $uri, $resourceName, &$path, &$keyData $templateRoot =& $resourceData['root-node']; $text =& $resourceData['text']; $tstamp =& $resourceData['time-stamp']; $uri =& $resourceData['uri']; $resourceName =& $resourceData['resource']; $path =& $resourceData['template-filename']; $keyData =& $resourceData['key-data']; $localeData =& $resourceData['locales']; if (!file_exists($path)) { return false; } $tstamp = filemtime($path); $result = false; $canCache = true; $templateRoot = null; if (!$handler->servesStaticData()) { $canCache = false; } if (!$tpl->isCachingAllowed()) { $canCache = false; } $keyData = 'file:' . $path; if ($method == eZTemplate::RESOURCE_FETCH) { if ($canCache) { if ($handler->hasCompiledTemplate($keyData, $uri, $resourceData, $path, $extraParameters, $tstamp)) { $resourceData['compiled-template'] = true; return true; } } if ($canCache) { $templateRoot = $handler->cachedTemplateTree($keyData, $uri, $resourceName, $path, $extraParameters, $tstamp); } if ($templateRoot !== null) { return true; } if (is_readable($path)) { $text = file_get_contents($path); $text = preg_replace("/\n|\r\n|\r/", "\n", $text); $tplINI = $tpl->ini(); $charset = $tplINI->variable('CharsetSettings', 'DefaultTemplateCharset'); $locales = array(); $pos = strpos($text, "\n"); if ($pos !== false) { $line = substr($text, 0, $pos); if (preg_match("/^\\{\\*\\?template(.+)\\?\\*\\}/", $line, $tpl_arr)) { $args = explode(" ", trim($tpl_arr[1])); foreach ($args as $arg) { $vars = explode('=', trim($arg)); switch ($vars[0]) { case 'charset': $val = $vars[1]; if ($val[0] == '"' and strlen($val) > 0 and $val[strlen($val) - 1] == '"') { $val = substr($val, 1, strlen($val) - 2); } $charset = $val; break; case 'locale': $val = $vars[1]; if ($val[0] == '"' and strlen($val) > 0 and $val[strlen($val) - 1] == '"') { $val = substr($val, 1, strlen($val) - 2); } $locales = explode(',', $val); break; } } } } /* Setting locale to allow standard PHP functions to handle * strtoupper/lower() */ $defaultLocale = trim($tplINI->variable('CharsetSettings', 'DefaultTemplateLocale')); if ($defaultLocale != '') { $locales = array_merge($locales, explode(',', $defaultLocale)); } $localeData = $locales; if ($locales && count($locales)) { setlocale(LC_CTYPE, $locales); } if (eZTemplate::isDebugEnabled()) { eZDebug::writeNotice("{$path}, {$charset}"); } $codec = eZTextCodec::instance($charset, false, false); if ($codec) { eZDebug::accumulatorStart('template_resource_conversion', 'template_total', 'String conversion in template resource'); $text = $codec->convertString($text); eZDebug::accumulatorStop('template_resource_conversion'); } $result = true; } } else { if ($method == eZTemplate::RESOURCE_QUERY) { $result = true; } } return $result; }