Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
 /**
  * (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 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;
 }
 /**
  * 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;
 }
Exemplo n.º 6
0
 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;
                     }
                 }
             }
         }
     }
 }
 /**
  * Validates the input from the object edit form concerning this attribute.
  *
  * @param mixed  $http                   Class eZHTTPTool.
  * @param string $base                   Seems to be always 'ContentObjectAttribute'.
  * @param mixed  $contentObjectAttribute Class eZContentObjectAttribute.
  *
  * @return int eZInputValidator::STATE_INVALID/STATE_ACCEPTED
  */
 public function validateObjectAttributeHTTPInput($http, $base, $contentObjectAttribute)
 {
     if ($http->hasPostVariable($base . '_ymcmschapv2_data_text_' . $contentObjectAttribute->attribute('id'))) {
         $data = $http->postVariable($base . '_ymcmschapv2_data_text_' . $contentObjectAttribute->attribute('id'));
         $classAttribute = $contentObjectAttribute->contentClassAttribute();
         if ($data == "") {
             if ($contentObjectAttribute->validateIsRequired()) {
                 $contentObjectAttribute->setValidationError(ezi18n('kernel/classes/datatypes', 'Input required.'));
                 return eZInputValidator::STATE_INVALID;
             }
         } else {
             $maxLen = $classAttribute->attribute(self::MAX_LEN_FIELD);
             $textCodec = eZTextCodec::instance(false);
             if ($textCodec->strlen($data) > $maxLen and $maxLen > 0) {
                 $contentObjectAttribute->setValidationError(ezi18n('kernel/classes/datatypes', 'The input text is too long. The maximum number of characters allowed is %1.'), $maxLen);
                 return eZInputValidator::STATE_INVALID;
             }
             $minLen = $classAttribute->attribute(self::MIN_LEN_FIELD);
             if ($textCodec->strlen($data) < $minLen and $minLen > 0) {
                 $contentObjectAttribute->setValidationError(ezi18n('kernel/classes/datatypes', 'The input text is too short. The minimum number of characters is %1.'), $minLen);
                 return eZInputValidator::STATE_INVALID;
             }
             //Make the user input asomething different from his normal password //start
             //ToDo: Do not return valid if the user has changed his pwassword but the new password is not in the "_POST-Array...
             $found_login = false;
             $found_password = false;
             //ToDO: Don't walk through the $_POST-array...
             foreach ($_POST as $key => $content) {
                 if (strpos($key, '_data_user_login_') != false and $content != '') {
                     $found_login = $content;
                 } else {
                     if (strpos($key, '_data_user_password_') != false and $content != '') {
                         $found_password = $content;
                     }
                 }
             }
             if ($found_password !== false and $found_password == $data) {
                 $contentObjectAttribute->setValidationError(ezi18n('kernel/classes/datatypes', 'This has to be different from your new user account password.'));
                 return eZInputValidator::STATE_INVALID;
             } else {
                 $objectID = $contentObjectAttribute->attribute('contentobject_id');
                 include_once "kernel/classes/datatypes/ezuser/ezuser.php";
                 $user = eZUser::fetch($objectID);
                 if (is_object($user)) {
                     if ($found_login === false) {
                         $found_login = $user->attribute('login');
                     }
                     $passHash = eZUser::createHash($found_login, $data, eZUser::site(), $user->attribute('password_hash_type'));
                     if ($passHash == $user->attribute('password_hash')) {
                         $contentObjectAttribute->setValidationError(ezi18n('kernel/classes/datatypes', 'This has to be different from your current user account password.'));
                         return eZInputValidator::STATE_INVALID;
                     }
                 }
             }
             //Make the user input asomething different from his normal password //end
             return eZInputValidator::STATE_ACCEPTED;
         }
     }
     return eZInputValidator::STATE_ACCEPTED;
 }
 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;
     }
 }
Exemplo n.º 9
0
}

$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" );

?>
Exemplo n.º 10
0
 /**
  * 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;
 }
Exemplo n.º 11
0
 /**
  * Creates a new eZDBInterface object and connects to the database backend.
  *
  * @param array $parameters
  */
 function eZDBInterface($parameters)
 {
     $server = $parameters['server'];
     $port = $parameters['port'];
     $user = $parameters['user'];
     $password = $parameters['password'];
     $db = $parameters['database'];
     $useSlaveServer = $parameters['use_slave_server'];
     $slaveServer = $parameters['slave_server'];
     $slavePort = $parameters['slave_port'];
     $slaveUser = $parameters['slave_user'];
     $slavePassword = $parameters['slave_password'];
     $slaveDB = $parameters['slave_database'];
     $socketPath = $parameters['socket'];
     $charset = $parameters['charset'];
     $isInternalCharset = $parameters['is_internal_charset'];
     $builtinEncoding = $parameters['builtin_encoding'];
     $connectRetries = $parameters['connect_retries'];
     if ($parameters['use_persistent_connection'] == 'enabled') {
         $this->UsePersistentConnection = true;
     }
     $this->DB = $db;
     $this->Server = $server;
     $this->Port = $port;
     $this->SocketPath = $socketPath;
     $this->User = $user;
     $this->Password = $password;
     $this->UseSlaveServer = $useSlaveServer;
     $this->SlaveDB = $slaveDB;
     $this->SlaveServer = $slaveServer;
     $this->SlavePort = $slavePort;
     $this->SlaveUser = $slaveUser;
     $this->SlavePassword = $slavePassword;
     $this->Charset = $charset;
     $this->IsInternalCharset = $isInternalCharset;
     $this->UseBuiltinEncoding = $builtinEncoding;
     $this->ConnectRetries = $connectRetries;
     $this->DBConnection = false;
     $this->DBWriteConnection = false;
     $this->TransactionCounter = 0;
     $this->TransactionIsValid = false;
     $this->TransactionStackTree = false;
     $this->OutputTextCodec = null;
     $this->InputTextCodec = null;
     $tmpOutputTextCodec = eZTextCodec::instance($charset, false, false);
     $tmpInputTextCodec = eZTextCodec::instance(false, $charset, false);
     unset($this->OutputTextCodec);
     unset($this->InputTextCodec);
     $this->OutputTextCodec = null;
     $this->InputTextCodec = null;
     if ($tmpOutputTextCodec && $tmpInputTextCodec) {
         if ($tmpOutputTextCodec->conversionRequired() && $tmpInputTextCodec->conversionRequired()) {
             $this->OutputTextCodec =& $tmpOutputTextCodec;
             $this->InputTextCodec =& $tmpInputTextCodec;
         }
     }
     $this->OutputSQL = false;
     $this->SlowSQLTimeout = 0;
     $ini = eZINI::instance();
     if ($ini->variable("DatabaseSettings", "SQLOutput") == "enabled" and $ini->variable("DebugSettings", "DebugOutput") == "enabled") {
         $this->OutputSQL = true;
         $this->SlowSQLTimeout = (int) $ini->variable("DatabaseSettings", "SlowQueriesOutput");
     }
     if ($ini->variable("DatabaseSettings", "DebugTransactions") == "enabled") {
         // Setting it to an array turns on the debugging
         $this->TransactionStackTree = array();
     }
     $this->QueryAnalysisOutput = false;
     if ($ini->variable("DatabaseSettings", "QueryAnalysisOutput") == "enabled") {
         $this->QueryAnalysisOutput = true;
     }
     $this->IsConnected = false;
     $this->NumQueries = 0;
     $this->StartTime = false;
     $this->EndTime = false;
     $this->TimeTaken = false;
     $this->AttributeVariableMap = array('database_name' => 'DB', 'database_server' => 'Server', 'database_port' => 'Port', 'database_socket_path' => 'SocketPath', 'database_user' => 'User', 'use_slave_server' => 'UseSlaveServer', 'slave_database_name' => 'SlaveDB', 'slave_database_server' => 'SlaveServer', 'slave_database_port' => 'SlavePort', 'slave_database_user' => 'SlaveUser', 'charset' => 'Charset', 'is_internal_charset' => 'IsInternalCharset', 'use_builting_encoding' => 'UseBuiltinEncoding', 'retry_count' => 'ConnectRetries');
 }
Exemplo n.º 12
0
 function executeCommandCode(&$text, $command, $charsetName)
 {
     if ($command['command'] == 'url_cleanup_iri') {
         $text = eZCharTransform::commandUrlCleanupIRI($text, $charsetName);
         return true;
     } else {
         if ($command['command'] == 'url_cleanup') {
             $text = eZCharTransform::commandUrlCleanup($text, $charsetName);
             return true;
         } else {
             if ($command['command'] == 'url_cleanup_compat') {
                 $text = eZCharTransform::commandUrlCleanupCompat($text, $charsetName);
                 return true;
             } else {
                 if ($command['command'] == 'identifier_cleanup') {
                     $text = strtolower($text);
                     $text = preg_replace(array("#[^a-z0-9_ ]#", "/ /", "/__+/", "/^_|_\$/"), array(" ", "_", "_", ""), $text);
                     return true;
                 } else {
                     if ($command['command'] == 'search_cleanup') {
                         $nonCJKCharsets = $this->nonCJKCharsets();
                         if (!in_array($charsetName, $nonCJKCharsets)) {
                             // 4 Add spaces after chinese / japanese / korean multibyte characters
                             $codec = eZTextCodec::instance(false, 'unicode');
                             $unicodeValueArray = $codec->convertString($text);
                             $normalizedTextArray = array();
                             $bFlag = false;
                             foreach (array_keys($unicodeValueArray) as $valueKey) {
                                 // Check for word characters that should be broken up for search
                                 if ($unicodeValueArray[$valueKey] >= 12289 and $unicodeValueArray[$valueKey] <= 12542 or $unicodeValueArray[$valueKey] >= 13312 and $unicodeValueArray[$valueKey] <= 40863 or $unicodeValueArray[$valueKey] >= 44032 and $unicodeValueArray[$valueKey] <= 55203) {
                                     if ($bFlag) {
                                         $normalizedTextArray[] = $unicodeValueArray[$valueKey];
                                     }
                                     $normalizedTextArray[] = 32;
                                     // A space
                                     $normalizedTextArray[] = $unicodeValueArray[$valueKey];
                                     $bFlag = true;
                                 } else {
                                     if ($bFlag) {
                                         $normalizedTextArray[] = 32;
                                         // A space
                                     }
                                     $normalizedTextArray[] = $unicodeValueArray[$valueKey];
                                     $bFlag = false;
                                 }
                             }
                             if ($bFlag) {
                                 $normalizedTextArray[count($normalizedTextArray) - 1] = 32;
                             }
                             $revCodec = eZTextCodec::instance('unicode', false);
                             // false means use internal charset
                             $text = $revCodec->convertString($normalizedTextArray);
                         }
                         // Make sure dots inside words/numbers are kept, the rest is turned into space
                         $text = preg_replace(array("#(\\.){2,}#", "#^\\.#", "#\\s\\.#", "#\\.\\s#", "#\\.\$#", "#([^0-9])%#"), array(" ", " ", " ", " ", " ", "\$1 "), $text);
                         $ini = eZINI::instance();
                         if ($ini->variable('SearchSettings', 'EnableWildcard') != 'true') {
                             $text = str_replace("*", " ", $text);
                         }
                         $charset = eZTextCodec::internalCharset();
                         $hasUTF8 = $charset == "utf-8";
                         if ($hasUTF8) {
                             $text = preg_replace("#(\\s+)#u", " ", $text);
                         } else {
                             $text = preg_replace("#(\\s+)#", " ", $text);
                         }
                         return true;
                     } else {
                         $ini = eZINI::instance('transform.ini');
                         $commands = $ini->variable('Extensions', 'Commands');
                         if (isset($commands[$command['command']])) {
                             list($path, $className) = explode(':', $commands[$command['command']], 2);
                             if (file_exists($path)) {
                                 include_once $path;
                                 $text = call_user_func_array(array($className, 'executeCommand'), array($text, $command['command'], $charsetName));
                                 return true;
                             } else {
                                 eZDebug::writeError("Could not locate include file '{$path}' for transformation '" . $command['command'] . "'");
                             }
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
        $normalizedTextArray[] = 32;
        // A space
        $normalizedTextArray[] = $unicodeValueArray[$valueKey];
        $bFlag = true;
    } else {
        if ($bFlag) {
            $normalizedTextArray[] = 32;
            // A space
        }
        $normalizedTextArray[] = $unicodeValueArray[$valueKey];
        $bFlag = false;
    }
}
if ($bFlag) {
    $normalizedTextArray[count($normalizedTextArray) - 1] = 32;
}
$revCodec = eZTextCodec::instance('unicode', false);
// false means use internal charset
$text = $revCodec->convertString($normalizedTextArray);
$text = preg_replace(array("#(\\.){2,}#", "#^\\.#", "#\\s\\.#", "#\\.\\s#", "#\\.\$#", "#([^0-9])%#"), array(" ", " ", " ", " ", " ", " "), $text);
$ini = eZINI::instance();
if ($ini->variable('SearchSettings', 'EnableWildcard') != 'true') {
    $text = str_replace("*", " ", $text);
}
$charset = eZTextCodec::internalCharset();
$hasUTF8 = $charset == "utf-8";
if ($hasUTF8) {
    $text = preg_replace("#(\\s+)#u", " ", $text);
} else {
    $text = preg_replace("#(\\s+)#", " ", $text);
}
Exemplo n.º 14
0
 /**
  * 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);
             }
         }
     }
 }
Exemplo n.º 15
0
    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( '&quot;',
                                             '"',
                                             $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__ );
            }

        }

    }
 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;
 }
Exemplo n.º 17
0
 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;
 }
Exemplo n.º 18
0
 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;
 }
Exemplo n.º 19
0
    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;
    }
Exemplo n.º 20
0
     $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));
 /**
  * Validates the input from the object edit form concerning this attribute.
  * 
  * @param mixed  $http                   Class eZHTTPTool.
  * @param string $base                   Seems to be always 'ContentObjectAttribute'.
  * @param mixed  $contentObjectAttribute Class eZContentObjectAttribute.
  *
  * @return int eZInputValidator::STATE_...
  */
 public function validateObjectAttributeHTTPInput($http, $base, $contentObjectAttribute)
 {
     if ($http->hasPostVariable($base . '_ymcnumberasstring_data_text_' . $contentObjectAttribute->attribute('id'))) {
         $data = $http->postVariable($base . '_ymcnumberasstring_data_text_' . $contentObjectAttribute->attribute('id'));
         $classAttribute = $contentObjectAttribute->contentClassAttribute();
         if ($data == "") {
             if ($contentObjectAttribute->validateIsRequired()) {
                 $contentObjectAttribute->setValidationError(ezi18n('kernel/classes/datatypes', 'Input required.'));
                 return eZInputValidator::STATE_INVALID;
             }
         } else {
             $maxLen = $classAttribute->attribute(self::MAX_LEN_FIELD);
             $textCodec = eZTextCodec::instance(false);
             if ($textCodec->strlen($data) > $maxLen and $maxLen > 0) {
                 $contentObjectAttribute->setValidationError(ezi18n('kernel/classes/datatypes', 'The input text is too long. The maximum number of characters allowed is %1.'), $maxLen);
                 return eZInputValidator::STATE_INVALID;
             }
             $this->IntegerValidator->setRange(false, false);
             $state = $this->IntegerValidator->validate($data);
             if ($state === eZInputValidator::STATE_INVALID || $state === eZInputValidator::STATE_INTERMEDIATE) {
                 $contentObjectAttribute->setValidationError(ezi18n('kernel/classes/datatypes', 'The input is not a valid integer.'));
                 return eZInputValidator::STATE_INVALID;
             }
             return eZInputValidator::STATE_ACCEPTED;
         }
     }
     return eZInputValidator::STATE_ACCEPTED;
 }