/** * Test scenario for issue #014897: Object/class name pattern and cache issues [patch] * * @result $phpCache->canRestore() returns true * @expected $phpCache->canRestore() should return false * * @link http://issues.ez.no/14897 */ public function testCanRestore() { $db = eZDB::instance(); $dbName = md5($db->DB); $cacheDir = eZSys::cacheDirectory(); $phpCache = new eZPHPCreator($cacheDir, 'classidentifiers_' . $dbName . '.php', '', array('clustering' => 'classidentifiers')); $handler = eZExpiryHandler::instance(); $expiryTime = 0; if ($handler->hasTimestamp('class-identifier-cache')) { $expiryTime = $handler->timestamp('class-identifier-cache'); } $this->assertFalse($phpCache->canRestore($expiryTime)); }
function preferencesTransformation($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { if (count($parameters[0]) == 0) { return false; } $values = array(); if (eZTemplateNodeTool::isConstantElement($parameters[0])) { $name = eZTemplateNodeTool::elementConstantValue($parameters[0]); $nameText = eZPHPCreator::variableText($name, 0, 0, false); } else { $nameText = '%1%'; $values[] = $parameters[0]; } return array(eZTemplateNodeTool::createCodePieceElement("%output% = eZPreferences::value( {$nameText} );\n", $values)); }
/** * @param string $name * @param mixed $value * @param string $cacheFileName * @return mixed|null */ public static function dailyValue( $name, $value = null, $cacheFileName = null ) { if ( $value === null && isset($memoryCache[$name]) && $cacheFileName === null ) { return self::$memoryCache[$name]; } else { if (is_null($cacheFileName)) { $cacheFileName = self::DAILY_CACHE_FILE . '_' . ClusterTool::clusterIdentifier(); } $cache = new eZPHPCreator( eZSys::cacheDirectory(), $cacheFileName . '.php', '', array() ); $expiryTime = time() - 24 * 3600; // reading if ($cache->canRestore($expiryTime)) { $values = $cache->restore(array('cacheTable' => 'cacheTable')); if (is_null($value)) { if (isset($values['cacheTable'][$name])) { return $values['cacheTable'][$name]; } else { return null; } } } else { $values = array('cacheTable' => array()); } $values['cacheTable'][$name] = $value; if ( $cacheFileName == self::DAILY_CACHE_FILE . '_' . ClusterTool::clusterIdentifier() ) self::$memoryCache = $values['cacheTable']; // writing $cache->addVariable('cacheTable', $values['cacheTable']); $cache->store(true); $cache->close(); } return null; }
/** * @param string $name * @param mixed $value * @return array */ public static function dailyValue( $name, $value = null) { if ( $value === null && isset($memoryCache[$name]) ) { return self::$memoryCache[$name]; } else { $cache = new eZPHPCreator( eZSys::cacheDirectory(), self::GLOBAL_CACHE_FILE . '.php', '', array() // removed clustering ); $expiryTime = time() - 24 * 3600; // reading if ($cache->canRestore($expiryTime)) { $values = $cache->restore(array('cacheTable' => 'cacheTable')); self::$memoryCache = $values['cacheTable']; if (is_null($value)) { if (isset($values['cacheTable'][$name])) { return $values['cacheTable'][$name]; } else { return null; } } } else { $values = array('cacheTable' => array()); } if ( !is_null($value) ) { $values['cacheTable'][$name] = $value; $cache->addVariable('cacheTable', $values['cacheTable']); $cache->store(true); $cache->close(); } } return null; }
function templateNodeCaseTransformation($tpl, &$newNodes, &$caseNodes, &$caseCounter, &$node, $privateData) { if ($node[2] == 'case') { if (is_array($node[3]) && count($node[3])) { if (isset($node[3]['match'])) { $match = $node[3]['match']; $match = eZTemplateCompiler::processElementTransformationList($tpl, $node, $match, $privateData); $dynamicCase = false; if (eZTemplateNodeTool::isConstantElement($match)) { $matchValue = eZTemplateNodeTool::elementConstantValue($match); $caseText = eZPHPCreator::variableText($matchValue, 0, 0, false); } else { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $match, false, array(), 'case' . $caseCounter); $caseText = "\$case" . $caseCounter; ++$caseCounter; $dynamicCase = true; } $caseNodes[] = eZTemplateNodeTool::createCodePieceNode(" case {$caseText}:\n {"); if ($dynamicCase) { $caseNodes[] = eZTemplateNodeTool::createCodePieceNode(" unset( {$caseText} );"); } } else { if (isset($node[3]['in'])) { return false; } } } else { $caseNodes[] = eZTemplateNodeTool::createCodePieceNode(" default:\n {"); } $children = eZTemplateNodeTool::extractFunctionNodeChildren($node); if ($children === false) { $children = array(); } else { $children = eZTemplateCompiler::processNodeTransformationNodes($tpl, $node, $children, $privateData); } $caseNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(8); $caseNodes = array_merge($caseNodes, $children); $caseNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(8); $caseNodes[] = eZTemplateNodeTool::createCodePieceNode(" } break;"); } }
static function storeCache($key) { $translationCache = eZTranslationCache::cacheTable(); if (!isset($translationCache[$key])) { eZDebug::writeWarning("Translation cache for key '{$key}' does not exist, cannot store cache", __METHOD__); return; } $internalCharset = eZTextCodec::internalCharset(); // $cacheFileKey = "$key-$internalCharset"; $cacheFileKey = $key; $cacheFileName = md5($cacheFileKey) . '.php'; $cache =& $translationCache[$key]; if (!file_exists(eZTranslationCache::cacheDirectory())) { eZDir::mkdir(eZTranslationCache::cacheDirectory(), false, true); } $php = new eZPHPCreator(eZTranslationCache::cacheDirectory(), $cacheFileName); $php->addRawVariable('eZTranslationCacheCodeDate', self::CODE_DATE); $php->addSpace(); $php->addRawVariable('CacheInfo', array('charset' => $internalCharset)); $php->addRawVariable('TranslationInfo', $cache['info']); $php->addSpace(); $php->addRawVariable('TranslationRoot', $cache['root']); $php->store(); }
/** * Returns an array of limitations useable by the policy system * * @return array */ public static function limitations() { static $limitations; if ($limitations === null) { $db = eZDB::instance(); $dbName = md5($db->DB); $cacheDir = eZSys::cacheDirectory(); $phpCache = new eZPHPCreator($cacheDir, 'statelimitations_' . $dbName . '.php', '', array('clustering' => 'statelimitations')); $handler = eZExpiryHandler::instance(); $storedTimeStamp = $handler->hasTimestamp('state-limitations') ? $handler->timestamp('state-limitations') : false; $expiryTime = $storedTimeStamp !== false ? $storedTimeStamp : 0; if ($phpCache->canRestore($expiryTime)) { $var = $phpCache->restore(array('state_limitations' => 'state_limitations')); $limitations = $var['state_limitations']; } else { $limitations = array(); $groups = self::fetchByConditions(array("identifier NOT LIKE 'ez%'"), false, false); foreach ($groups as $group) { $name = 'StateGroup_' . $group->attribute('identifier'); $limitations[$name] = array('name' => $name, 'values' => array(), 'class' => __CLASS__, 'function' => 'limitationValues', 'parameter' => array($group->attribute('id'))); } $phpCache->addVariable('state_limitations', $limitations); $phpCache->store(); } if ($storedTimeStamp === false) { $handler->setTimestamp('state-limitations', time()); } } return $limitations; }
function operatorTransform($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { if (!eZTemplateNodeTool::isConstantElement($parameters[1]) || count($parameters) > 2 && !eZTemplateNodeTool::isConstantElement($parameters[2])) { return false; } // We do not support non-static values for decimal_count, decimal_symbol and thousands_separator if (count($parameters) > 3 and !eZTemplateNodeTool::isConstantElement($parameters[3])) { return false; } if (count($parameters) > 4 and !eZTemplateNodeTool::isConstantElement($parameters[4])) { return false; } if (count($parameters) > 5 and !eZTemplateNodeTool::isConstantElement($parameters[5])) { return false; } $locale = eZLocale::instance(); $decimalCount = $locale->decimalCount(); $decimalSymbol = $locale->decimalSymbol(); $decimalThousandsSeparator = $locale->thousandsSeparator(); if (count($parameters) > 2) { $prefix = eZTemplateNodeTool::elementConstantValue($parameters[2]); } else { $prefix = 'auto'; } if (count($parameters) > 3) { $decimalCount = eZTemplateNodeTool::elementConstantValue($parameters[3]); } elseif ($prefix == 'none') { $decimalCount = 0; } if (count($parameters) > 4) { $decimalSymbol = eZTemplateNodeTool::elementConstantValue($parameters[4]); } if (count($parameters) > 5) { $decimalThousandsSeparator = eZTemplateNodeTool::elementConstantValue($parameters[5]); } $decimalSymbolText = eZPHPCreator::variableText($decimalSymbol, 0, 0, false); $decimalThousandsSeparatorText = eZPHPCreator::variableText($decimalThousandsSeparator, 0, 0, false); $unit = eZTemplateNodeTool::elementConstantValue($parameters[1]); $ini = eZINI::instance(); if ($prefix == "auto") { $prefixes = $ini->variableArray("UnitSettings", "BinaryUnits"); if (in_array($unit, $prefixes)) { $prefix = "binary"; } else { $prefix = "decimal"; } } $unit_ini = eZINI::instance("units.ini"); $use_si = $ini->variable("UnitSettings", "UseSIUnits") == "true"; $fake = $use_si ? "" : "Fake"; if ($unit_ini->hasVariable("Base", $unit)) { $base = $unit_ini->variable("Base", $unit); } $hasInput = false; $output = false; if (eZTemplateNodeTool::isConstantElement($parameters[0])) { $output = eZTemplateNodeTool::elementConstantValue($parameters[0]); $hasInput = true; } $prefix_var = ""; if ($prefix == "decimal") { $prefixes = $unit_ini->group("DecimalPrefixes"); $prefix_group = $unit_ini->group("DecimalPrefixes"); $prefixes = array(); foreach ($prefix_group as $prefix_item) { $prefixes[] = explode(";", $prefix_item); } usort($prefixes, "eZTemplateUnitCompareFactor"); $prefix_var = ""; if ($hasInput) { if ($output >= 0 and $output < 10) { $prefix_var = ''; } else { foreach ($prefixes as $prefix) { $val = pow(10, (int) $prefix[0]); if ($val <= $output) { $prefix_var = $prefix[1]; $output = number_format($output / $val, $decimalCount, $decimalSymbol, $decimalThousandsSeparator); break; } } } } else { $values = array(); $values[] = $parameters[0]; $values[] = array(eZTemplateNodeTool::createArrayElement($prefixes)); $values[] = array(eZTemplateNodeTool::createStringElement($base)); $code = 'if ( %1% >= 0 and %1% < 10 )' . "\n" . '{' . "\n" . ' %tmp3% = \'\';' . "\n" . '}' . "\n" . 'else' . "\n" . '{' . "\n" . ' %tmp3% = "";' . "\n" . ' foreach ( %2% as %tmp1% )' . "\n" . ' {' . "\n" . ' %tmp2% = pow( 10, (int)%tmp1%[0] );' . "\n" . ' if ( %tmp2% <= %1% )' . "\n" . ' {' . "\n" . ' %tmp3% = %tmp1%[1];' . "\n" . ' %1% = number_format( %1% / %tmp2%, ' . $decimalCount . ', ' . $decimalSymbolText . ', ' . $decimalThousandsSeparatorText . ' );' . "\n" . ' break;' . "\n" . ' }' . "\n" . ' }' . "\n" . '}' . "\n" . '%output% = %1% . \' \' . %tmp3% . %3%;'; return array(eZTemplateNodeTool::createCodePieceElement($code, $values, false, 3)); } } else { if ($prefix == "binary") { $prefix_group = $unit_ini->group($fake . "BinaryPrefixes"); $prefixes = array(); foreach ($prefix_group as $prefix_item) { $prefixes[] = explode(";", $prefix_item); } usort($prefixes, "eZTemplateUnitCompareFactor"); $prefix_var = ""; if ($hasInput) { if ($output >= 0 and $output < 10) { $prefix_var = ''; } foreach ($prefixes as $prefix) { $val = pow(2, (int) $prefix[0]); if ($val <= $output) { $prefix_var = $prefix[1]; $output = number_format($output / $val, $decimalCount, $decimalSymbol, $decimalThousandsSeparator); break; } } } else { $values = array(); $values[] = $parameters[0]; $values[] = array(eZTemplateNodeTool::createArrayElement($prefixes)); $values[] = array(eZTemplateNodeTool::createStringElement($base)); $code = 'if ( %1% >= 0 and %1% < 10 )' . "\n" . '{' . "\n" . ' %tmp3% = \'\';' . "\n" . '}' . "\n" . 'else' . "\n" . '{' . "\n" . ' %tmp3% = "";' . "\n" . ' foreach ( %2% as %tmp1% )' . "\n" . ' {' . "\n" . ' %tmp2% = pow( 2, (int)%tmp1%[0] );' . "\n" . ' if ( %tmp2% <= %1% )' . "\n" . ' {' . "\n" . ' %tmp3% = %tmp1%[1];' . "\n" . ' %1% = number_format( %1% / %tmp2%, ' . $decimalCount . ', ' . $decimalSymbolText . ', ' . $decimalThousandsSeparatorText . ' );' . "\n" . ' break;' . "\n" . ' }' . "\n" . ' }' . "\n" . '}' . "\n" . '%output% = %1% . \' \' . %tmp3% . %3%;'; return array(eZTemplateNodeTool::createCodePieceElement($code, $values, false, 3)); } } else { if ($unit_ini->hasVariable("BinaryPrefixes", $prefix)) { $prefix_base = 2; $prefix_var = $unit_ini->variableArray("BinaryPrefixes", $prefix); } else { if ($unit_ini->hasVariable("DecimalPrefixes", $prefix)) { $prefix_base = 10; $prefix_var = $unit_ini->variableArray("DecimalPrefixes", $prefix); } else { if ($prefix == "none") { $prefix_var = ''; if ($hasInput) { $output = number_format($output, $decimalCount, $decimalSymbol, $decimalThousandsSeparator); } else { $values = array(); $values[] = $parameters[0]; $values[] = array(eZTemplateNodeTool::createStringElement('')); $values[] = array(eZTemplateNodeTool::createStringElement($base)); $code = '%output% = number_format( %1%, ' . $decimalCount . ', ' . $decimalSymbolText . ', ' . $decimalThousandsSeparatorText . ' ) . \' \' . %2% . %3%;'; return array(eZTemplateNodeTool::createCodePieceElement($code, $values)); } } } } if (is_array($prefix_var)) { if ($hasInput) { $val = pow($prefix_base, (int) $prefix_var[0]); $output = number_format($output / $val, $decimalCount, $decimalSymbol, $decimalThousandsSeparator); $prefix_var = $prefix_var[1]; } else { $values = array(); $values[] = $parameters[0]; $values[] = array(eZTemplateNodeTool::createNumericElement(pow($prefix_base, (int) $prefix_var[0]))); $values[] = array(eZTemplateNodeTool::createStringElement($prefix_var[1])); $values[] = array(eZTemplateNodeTool::createStringElement($base)); $code = '%output% = number_format( %1% / %2%, ' . $decimalCount . ', ' . $decimalSymbolText . ', ' . $decimalThousandsSeparatorText . ' ) . \' \' . %3% . %4%;'; return array(eZTemplateNodeTool::createCodePieceElement($code, $values)); } } } } if ($hasInput) { return array(eZTemplateNodeTool::createStringElement($output . ' ' . $prefix_var . $base)); } $values = array(); $values[] = $parameters[0]; $values[] = array(eZTemplateNodeTool::createStringElement($prefix_var)); $values[] = array(eZTemplateNodeTool::createStringElement($base)); $code = '%output% = %1% . \' \' . %2% . %3%;'; return array(eZTemplateNodeTool::createCodePieceElement($code, $values)); }
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData) { $ini = eZINI::instance(); $children = eZTemplateNodeTool::extractFunctionNodeChildren($node); if ($ini->variable('TemplateSettings', 'TemplateCache') != 'enabled') { return $children; } $functionPlacement = eZTemplateNodeTool::extractFunctionNodePlacement($node); $placementKeyString = eZTemplateCacheBlock::placementString($functionPlacement); $newNodes = array(); $ignoreContentExpiry = false; if (isset($parameters['expiry'])) { if (eZTemplateNodeTool::isConstantElement($parameters['expiry'])) { $expiryValue = eZTemplateNodeTool::elementConstantValue($parameters['expiry']); $ttlCode = $expiryValue > 0 ? eZPHPCreator::variableText($expiryValue, 0, 0, false) : 'null'; } else { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['expiry'], false, array(), 'localExpiry'); $ttlCode = "( \$localExpiry > 0 ? \$localExpiry : null )"; } } else { $ttlCode = eZPHPCreator::variableText(self::DEFAULT_TTL, 0, 0, false); } if (isset($parameters['ignore_content_expiry'])) { $ignoreContentExpiry = eZTemplateNodeTool::elementConstantValue($parameters['ignore_content_expiry']); } $keysData = false; $hasKeys = false; $subtreeExpiryData = null; $subtreeValue = null; if (isset($parameters['keys'])) { $keysData = $parameters['keys']; $hasKeys = true; } if (isset($parameters['subtree_expiry'])) { $subtreeExpiryData = $parameters['subtree_expiry']; if (!eZTemplateNodeTool::isConstantElement($subtreeExpiryData)) { $hasKeys = true; } else { $subtreeValue = eZTemplateNodeTool::elementConstantValue($subtreeExpiryData); } $ignoreContentExpiry = true; } $accessName = false; if (isset($GLOBALS['eZCurrentAccess']['name'])) { $accessName = $GLOBALS['eZCurrentAccess']['name']; } if ($hasKeys) { $placementKeyStringText = eZPHPCreator::variableText($placementKeyString, 0, 0, false); $accessNameText = eZPHPCreator::variableText($accessName, 0, 0, false); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $keysData, false, array(), 'cacheKeys'); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $subtreeExpiryData, false, array(), 'subtreeExpiry'); $code = "\$cacheKeys = array( \$cacheKeys, {$placementKeyStringText}, {$accessNameText} );\n"; $cachePathText = "\$cachePath"; } else { $nodeID = $subtreeValue ? eZTemplateCacheBlock::decodeNodeID($subtreeValue) : false; $cachePath = eZTemplateCacheBlock::cachePath(eZTemplateCacheBlock::keyString(array($placementKeyString, $accessName)), $nodeID); $code = ""; $cachePathText = eZPHPCreator::variableText($cachePath, 0, 0, false); } $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code); $code = ''; $codePlacementHash = md5($placementKeyString); if ($hasKeys) { $code .= "list(\$cacheHandler_{$codePlacementHash}, \$contentData) =\n eZTemplateCacheBlock::retrieve( \$cacheKeys, \$subtreeExpiry, {$ttlCode}, " . ($ignoreContentExpiry ? "false" : "true") . " );\n"; } else { $nodeIDText = var_export($nodeID, true); $code .= "list(\$cacheHandler_{$codePlacementHash}, \$contentData) =\n eZTemplateCacheBlock::handle( {$cachePathText}, {$nodeIDText}, {$ttlCode}, " . ($ignoreContentExpiry ? "false" : "true") . " );\n"; } $code .= "if ( !( \$contentData instanceof eZClusterFileFailure ) )\n" . "{\n"; $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code, array('spacing' => 0)); $newNodes[] = eZTemplateNodeTool::createWriteToOutputVariableNode('contentData', array('spacing' => 4)); $newNodes[] = eZTemplateNodeTool::createCodePieceNode(" unset( \$contentData );\n" . "}\n" . "else\n" . "{\n" . " unset( \$contentData );"); $newNodes[] = eZTemplateNodeTool::createOutputVariableIncreaseNode(array('spacing' => 4)); $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(4); $newNodes = array_merge($newNodes, $children); $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(4); $newNodes[] = eZTemplateNodeTool::createAssignFromOutputVariableNode('cachedText', array('spacing' => 4)); $code = "\$cacheHandler_{$codePlacementHash}->storeCache( array( 'scope' => 'template-block', 'binarydata' => \$cachedText ) );\n"; $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code, array('spacing' => 4)); $newNodes[] = eZTemplateNodeTool::createOutputVariableDecreaseNode(array('spacing' => 4)); $newNodes[] = eZTemplateNodeTool::createWriteToOutputVariableNode('cachedText', array('spacing' => 4)); $newNodes[] = eZTemplateNodeTool::createCodePieceNode(" unset( \$cachedText, \$cacheHandler_{$codePlacementHash} );\n}\n"); return $newNodes; }
function condTransform( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters ) { switch( $operatorName ) { case $this->CondName: { $paramCount = count( $parameters ); $clauseCount = floor( $paramCount / 2 ); $hasDefaultClause = ( $paramCount % 2 ) != 0; if ( $paramCount == 1 ) { return $parameters[0]; } $values = array(); $code = ''; $spacing = 0; $spacingCode = ''; for ( $i = 0; $i < $clauseCount; ++$i ) { $prevSpacingCode = $spacingCode; $spacingCode = str_repeat( " ", $spacing*4 ); if ( $i > 0 ) { $code .= $prevSpacingCode . "else\n" . $prevSpacingCode . "{\n"; } $values[] = $parameters[$i*2]; if ( $i > 0 ) { $code .= $spacingCode . "%code" . count( $values ) . "%\n"; } $code .= $spacingCode. 'if ( %' . count( $values ) . "% )\n" . $spacingCode . "{\n"; if ( !eZTemplateNodeTool::isConstantElement( $parameters[$i*2 + 1] ) ) { $values[] = $parameters[$i*2 + 1]; $code .= ( $spacingCode . " %code" . count( $values ) . "%\n" . $spacingCode . " %output% = %" . count( $values ) . "%;\n" ); } else { $code .= $spacingCode . ' %output% = ' . eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameters[$i*2 + 1] ), 0, 0, false ) . ';' . "\n"; } $code .= $spacingCode . "}\n"; ++$spacing; } $bracketCount = $clauseCount - 1; if ( $hasDefaultClause ) { ++$bracketCount; $values[] = $parameters[$paramCount - 1]; if ( $clauseCount > 0 ) { $code .= $spacingCode . "else\n" . $spacingCode . "{\n" . $spacingCode . " %code" . count( $values ) . "%\n "; } $code .= $spacingCode . '%output% = %' . count( $values ) . "%;\n"; } for ( $clauseIndex = 0; $clauseIndex < $bracketCount; ++$clauseIndex ) { $spacingCode = str_repeat( " ", ( $bracketCount - $clauseIndex - 1 ) *4 ); $code .= $spacingCode . "}\n"; } return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); } break; case $this->FirstSetName: { $values = array(); $code = ''; $spacing = 0; $spacingCode = ''; $nestCount = 0; for( $i = 0; $i < count( $parameters ); ++$i ) { if ( $i != 0 ) { $code .= "$spacingCode}\n" . $spacingCode . "else\n$spacingCode{\n"; } $spacingCode = str_repeat( ' ', $spacing*4 ); ++$spacing; if ( eZTemplateNodeTool::isConstantElement( $parameters[$i] ) ) { $code .= "$spacingCode%output% = " . eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameters[$i] ), 0, 0, false ) . ";\n"; break; } ++$nestCount; $values[] = $parameters[$i]; $code .= ( $spacingCode . "%code" . count( $values ) . "%\n" . $spacingCode . 'if ( isset( %' . count( $values ) . "% ) )\n" . $spacingCode . "{\n" . $spacingCode . " %output% = %" . count( $values ) . '%;' . "\n" ); } for ( $i = 0; $i < $nestCount; ++$i ) { $spacing = $nestCount - $i - 1; $spacingCode = str_repeat( ' ', $spacing*4 ); $code .= $spacingCode . "}\n"; } return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); } break; } }
/** * Returns the class attribute identifier hash for the current database. * If it is outdated or non-existent, the method updates/generates the file * * @static * @since Version 4.1 * @access protected * @return array Returns hash of classattributeidentifier => classattributeid */ protected static function classAttributeIdentifiersHash() { if (self::$identifierHash === null) { $db = eZDB::instance(); $dbName = md5($db->DB); $cacheDir = eZSys::cacheDirectory(); $phpCache = new eZPHPCreator($cacheDir, 'classattributeidentifiers_' . $dbName . '.php', '', array('clustering' => 'classattridentifiers')); $handler = eZExpiryHandler::instance(); $expiryTime = 0; if ($handler->hasTimestamp('class-identifier-cache')) { $expiryTime = $handler->timestamp('class-identifier-cache'); } if ($phpCache->canRestore($expiryTime)) { $var = $phpCache->restore(array('identifierHash' => 'identifier_hash')); self::$identifierHash = $var['identifierHash']; } else { // Fetch identifier/id pair from db $query = "SELECT ezcontentclass_attribute.id as attribute_id, ezcontentclass_attribute.identifier as attribute_identifier, ezcontentclass.identifier as class_identifier\n FROM ezcontentclass_attribute, ezcontentclass\n WHERE ezcontentclass.id=ezcontentclass_attribute.contentclass_id"; $identifierArray = $db->arrayQuery($query); self::$identifierHash = array(); foreach ($identifierArray as $identifierRow) { $combinedIdentifier = $identifierRow['class_identifier'] . '/' . $identifierRow['attribute_identifier']; self::$identifierHash[$combinedIdentifier] = (int) $identifierRow['attribute_id']; } // Store identifier list to cache file $phpCache->addVariable('identifier_hash', self::$identifierHash); $phpCache->store(); } } return self::$identifierHash; }
static function generateVariableDataCode($php, $tpl, $variableData, &$knownTypes, $dataInspection, &$persistence, $parameters, &$resourceData) { $staticTypeMap = array(eZTemplate::TYPE_STRING => 'string', eZTemplate::TYPE_NUMERIC => 'numeric', eZTemplate::TYPE_IDENTIFIER => 'string', eZTemplate::TYPE_ARRAY => 'array', eZTemplate::TYPE_BOOLEAN => 'boolean'); $variableAssignmentName = $parameters['variable']; $variableAssignmentCounter = $parameters['counter']; $spacing = 0; $optimizeNode = false; if (isset($parameters['spacing'])) { $spacing = $parameters['spacing']; } if ($variableAssignmentCounter > 0) { $variableAssignmentName .= $variableAssignmentCounter; } // We need to unset the assignment variable before any elements are processed // This ensures that we don't work on existing variables $php->addCodePiece("unset( \${$variableAssignmentName} );\n", array('spacing' => $spacing)); if (is_array($variableData)) { foreach ($variableData as $index => $variableDataItem) { $variableDataType = $variableDataItem[0]; if ($variableDataType == eZTemplate::TYPE_STRING or $variableDataType == eZTemplate::TYPE_NUMERIC or $variableDataType == eZTemplate::TYPE_IDENTIFIER or $variableDataType == eZTemplate::TYPE_ARRAY or $variableDataType == eZTemplate::TYPE_BOOLEAN) { $knownTypes = array_unique(array_merge($knownTypes, array($staticTypeMap[$variableDataType]))); $dataValue = $variableDataItem[1]; $dataText = $php->thisVariableText($dataValue, 0, 0, false); $php->addCodePiece("\${$variableAssignmentName} = {$dataText};\n", array('spacing' => $spacing)); } else { if ($variableDataType == eZTemplate::TYPE_OPTIMIZED_NODE) { $optimizeNode = true; if (!isset($resourceData['node-object-cached'])) { $tpl->error("eZTemplateCompiler" . ($resourceData['use-comments'] ? ":" . __LINE__ : ""), "Attribute node-object-cached of variable \$resourceData was not found but variable node eZTemplate::TYPE_OPTIMIZED_NODE is still present. This should not happen"); } $php->addCodePiece("\${$variableAssignmentName} = \$nod_{$resourceData['uniqid']};\n"); // If optimized node is not set, use unoptimized code. $php->addCodePiece("if ( !\${$variableAssignmentName} )\n{\n"); } else { if ($variableDataType == eZTemplate::TYPE_OPTIMIZED_ARRAY_LOOKUP) { $code = $resourceData['use-comments'] ? "/*TC:" . __LINE__ . "*/\n" : ""; // This code is used a lot so we create a variable for it $phpVar = "\${$variableAssignmentName}"; $indexName = "'{$variableDataItem[1][0][1]}'"; // Add sanity checking $code .= "if ( !isset( {$phpVar}[{$indexName}] ) )\n" . "{\n" . " \$tpl->error( 'eZTemplateCompiler" . ($resourceData['use-comments'] ? ":" . __LINE__ : "") . "', \"PHP variable \\{$phpVar}" . "[{$indexName}] does not exist, cannot fetch the value.\" );\n" . " {$phpVar} = null;\n" . "}\n" . "else\n "; // Add the actual code $code .= "{$phpVar} = {$phpVar}[{$indexName}];\n"; $php->addCodePiece($code); } else { if ($variableDataType == eZTemplate::TYPE_OPTIMIZED_ATTRIBUTE_LOOKUP) { $code = $resourceData['use-comments'] ? "/*TC:" . __LINE__ . "*/\n" : ""; $code .= <<<END if ( !is_object( \${$variableAssignmentName} ) ) { \${$variableAssignmentName} = null; } else if ( \${$variableAssignmentName}->hasAttribute( "{$variableDataItem[1][0][1]}" ) ) { \${$variableAssignmentName} = \${$variableAssignmentName}->attribute( "{$variableDataItem[1][0][1]}" ); } END; $php->addCodePiece($code); } else { if ($variableDataType == eZTemplate::TYPE_OPTIMIZED_CONTENT_CALL) { // Line number comment $code = $resourceData['use-comments'] ? "/*TC:" . __LINE__ . "*/\n" : ""; // This code is used a lot so we create a variable for it $phpVar = "\${$variableAssignmentName}"; // Add sanity checking $code .= "if ( !is_object( {$phpVar} ) )\n" . "{\n" . " \$tpl->error( 'eZTemplateCompiler" . ($resourceData['use-comments'] ? ":" . __LINE__ : "") . "', \"PHP variable \\{$phpVar} is not an object, cannot fetch content()\" );\n" . " {$phpVar} = null;\n" . "}\n" . "else\n" . "{\n"; // Add the actual code $code .= " {$phpVar}Tmp = {$phpVar}->content();\n" . " unset( {$phpVar} );\n" . " {$phpVar} = {$phpVar}Tmp;\n" . " unset( {$phpVar}Tmp );\n}\n"; $php->addCodePiece($code); } else { if ($variableDataType == eZTemplate::TYPE_PHP_VARIABLE) { $knownTypes = array(); $phpVariableName = $variableDataItem[1]; $php->addCodePiece("\${$variableAssignmentName} = \${$phpVariableName};\n", array('spacing' => $spacing)); } else { if ($variableDataType == eZTemplate::TYPE_VARIABLE) { $knownTypes = array(); $namespace = $variableDataItem[1][0]; $namespaceScope = $variableDataItem[1][1]; $variableName = $variableDataItem[1][2]; $namespaceText = eZTemplateCompiler::generateMergeNamespaceCode($php, $tpl, $namespace, $namespaceScope, array('spacing' => $spacing), true); if (!is_string($namespaceText)) { $namespaceText = "\$namespace"; } $variableNameText = $php->thisVariableText($variableName, 0, 0, false); $code = "unset( \${$variableAssignmentName} );\n"; $code .= "\${$variableAssignmentName} = ( array_key_exists( {$namespaceText}, \$vars ) and array_key_exists( {$variableNameText}, \$vars[{$namespaceText}] ) ) ? \$vars[{$namespaceText}][{$variableNameText}] : null;\n"; $php->addCodePiece($code, array('spacing' => $spacing)); } else { if ($variableDataType == eZTemplate::TYPE_ATTRIBUTE) { $knownTypes = array(); $newParameters = $parameters; $newParameters['counter'] += 1; $tmpVariableAssignmentName = $newParameters['variable']; $tmpVariableAssignmentCounter = $newParameters['counter']; if ($tmpVariableAssignmentCounter > 0) { $tmpVariableAssignmentName .= $tmpVariableAssignmentCounter; } if (eZTemplateNodeTool::isStaticElement($variableDataItem[1])) { $attributeStaticValue = eZTemplateNodeTool::elementStaticValue($variableDataItem[1]); $attributeText = $php->thisVariableText($attributeStaticValue, 0, 0, false); } else { $newParameters['counter'] += 1; $tmpKnownTypes = array(); eZTemplateCompiler::generateVariableDataCode($php, $tpl, $variableDataItem[1], $tmpKnownTypes, $dataInspection, $persistence, $newParameters, $resourceData); $newVariableAssignmentName = $newParameters['variable']; $newVariableAssignmentCounter = $newParameters['counter']; if ($newVariableAssignmentCounter > 0) { $newVariableAssignmentName .= $newVariableAssignmentCounter; } $attributeText = "\${$newVariableAssignmentName}"; } $php->addCodePiece("\${$tmpVariableAssignmentName} = compiledFetchAttribute( \${$variableAssignmentName}, {$attributeText} );\n" . "unset( \${$variableAssignmentName} );\n" . "\${$variableAssignmentName} = \${$tmpVariableAssignmentName};\n", array('spacing' => $spacing)); // End if optimized node object is null/false. See also eZTemplateOptimizer::optimizeVariable() if ($optimizeNode && $index == 3) { $php->addCodePiece("}\n"); } } else { if ($variableDataType == eZTemplate::TYPE_OPERATOR) { $knownTypes = array(); $operatorParameters = $variableDataItem[1]; $operatorName = $operatorParameters[0]; $operatorParameters = array_splice($operatorParameters, 1); $operatorNameText = $php->thisVariableText($operatorName, 0, 0, false); $operatorParametersText = $php->thisVariableText($operatorParameters, 23, 0, false); $operatorHint = eZTemplateCompiler::operatorHint($tpl, $operatorName); if (isset($operatorHint['output']) and $operatorHint['output']) { if (isset($operatorHint['output-type'])) { $knownType = $operatorHint['output-type']; if (is_array($knownType)) { $knownTypes = array_merge($knownTypes, $knownType); } else { $knownTypes[] = $knownType; } $knownTypes = array_unique($knownTypes); } else { $knownTypes[] = 'static'; } } $php->addCodePiece("if (! isset( \${$variableAssignmentName} ) ) \${$variableAssignmentName} = NULL;\n", array('spacing' => $spacing)); $php->addCodePiece("while " . ($resourceData['use-comments'] ? "/*TC:" . __LINE__ . "*/" : "") . "( is_object( \${$variableAssignmentName} ) and method_exists( \${$variableAssignmentName}, 'templateValue' ) )\n" . " \${$variableAssignmentName} = \${$variableAssignmentName}" . "->templateValue();\n"); $php->addCodePiece("\$" . $variableAssignmentName . "Data = array( 'value' => \${$variableAssignmentName} );\n\$tpl->processOperator( {$operatorNameText},\n {$operatorParametersText},\n \$rootNamespace, \$currentNamespace, \$" . $variableAssignmentName . "Data, false, false );\n\${$variableAssignmentName} = \$" . $variableAssignmentName . "Data['value'];\nunset( \$" . $variableAssignmentName . "Data );\n", array('spacing' => $spacing)); } else { if ($variableDataType == eZTemplate::TYPE_VOID) { } else { if ($variableDataType == eZTemplate::TYPE_DYNAMIC_ARRAY) { $knownTypes = array_unique(array_merge($knownTypes, array('array'))); $code = '%output% = array( '; $matchMap = array('%input%', '%output%'); $replaceMap = array('$' . $variableAssignmentName, '$' . $variableAssignmentName); $unsetList = array(); $counter = 1; $paramCount = 0; $values = $variableDataItem[2]; $newParameters = $parameters; foreach ($values as $key => $value) { if ($paramCount != 0) { $code .= ', '; } ++$paramCount; $code .= '\'' . $key . '\' => '; if (eZTemplateNodeTool::isStaticElement($value)) { $code .= eZPHPCreator::variableText(eZTemplateNodeTool::elementStaticValue($value), 0, 0, false); continue; } $code .= '%' . $counter . '%'; $newParameters['counter'] += 1; $newVariableAssignmentName = $newParameters['variable']; $newVariableAssignmentCounter = $newParameters['counter']; if ($newVariableAssignmentCounter > 0) { $newVariableAssignmentName .= $newVariableAssignmentCounter; } $matchMap[] = '%' . $counter . '%'; $replaceMap[] = '$' . $newVariableAssignmentName; $unsetList[] = $newVariableAssignmentName; $tmpKnownTypes = array(); eZTemplateCompiler::generateVariableDataCode($php, $tpl, $value, $tmpKnownTypes, $dataInspection, $persistence, $newParameters, $resourceData); ++$counter; } $code .= ' );'; $code = str_replace($matchMap, $replaceMap, $code); $php->addCodePiece($code, array('spacing' => $spacing)); $php->addVariableUnsetList($unsetList, array('spacing' => $spacing)); } else { if ($variableDataType == eZTemplate::TYPE_INTERNAL_CODE_PIECE) { $code = $variableDataItem[1]; $values = false; $matchMap = array('%input%', '%output%'); $replaceMap = array('$' . $variableAssignmentName, '$' . $variableAssignmentName); $unsetList = array(); $counter = 1; if (isset($variableDataItem[3]) && is_array($variableDataItem[3])) { $newParameters = $parameters; $values = $variableDataItem[3]; foreach ($values as $value) { $newParameters['counter'] += 1; $newVariableAssignmentName = $newParameters['variable']; $newVariableAssignmentCounter = $newParameters['counter']; if ($newVariableAssignmentCounter > 0) { $newVariableAssignmentName .= $newVariableAssignmentCounter; } if (eZTemplateNodeTool::isStaticElement($value)) { $staticValue = eZTemplateNodeTool::elementStaticValue($value); $staticValueText = $php->thisVariableText($staticValue, 0, 0, false); if (preg_match("/%code{$counter}%/", $code)) { $matchMap[] = '%code' . $counter . '%'; $replaceMap[] = ''; } $matchMap[] = '%' . $counter . '%'; $replaceMap[] = $staticValueText; } else { $matchMap[] = '%' . $counter . '%'; $replaceMap[] = '$' . $newVariableAssignmentName; $unsetList[] = $newVariableAssignmentName; if (preg_match("/%code{$counter}%/", $code)) { $tmpPHP = new eZPHPCreator('', '', eZTemplateCompiler::TemplatePrefix()); $tmpKnownTypes = array(); eZTemplateCompiler::generateVariableDataCode($tmpPHP, $tpl, $value, $tmpKnownTypes, $dataInspection, $persistence, $newParameters, $resourceData); $newCode = $tmpPHP->fetch(false); if (count($tmpKnownTypes) == 0 or in_array('objectproxy', $tmpKnownTypes)) { $newCode .= "while " . ($resourceData['use-comments'] ? "/*TC:" . __LINE__ . "*/" : "") . "( is_object( \${$newVariableAssignmentName} ) and method_exists( \${$newVariableAssignmentName}, 'templateValue' ) )\n" . " \${$newVariableAssignmentName} = \${$newVariableAssignmentName}" . "->templateValue();\n"; } $matchMap[] = '%code' . $counter . '%'; $replaceMap[] = $newCode; } else { $tmpKnownTypes = array(); eZTemplateCompiler::generateVariableDataCode($php, $tpl, $value, $tmpKnownTypes, $dataInspection, $persistence, $newParameters, $resourceData); if (!$parameters['treat-value-as-non-object'] and (count($tmpKnownTypes) == 0 or in_array('objectproxy', $tmpKnownTypes))) { $php->addCodePiece("while " . ($resourceData['use-comments'] ? "/*TC:" . __LINE__ . "*/" : "") . "( is_object( \${$newVariableAssignmentName} ) and method_exists( \${$newVariableAssignmentName}, 'templateValue' ) )\n" . " \${$newVariableAssignmentName} = \${$newVariableAssignmentName}" . "->templateValue();\n", array('spacing' => $spacing)); } } } ++$counter; } } if (isset($variableDataItem[4]) && $variableDataItem[4] !== false) { $values = $variableDataItem[4]; for ($i = 0; $i < $values; $i++) { $newParameters['counter'] += 1; $newVariableAssignmentName = $newParameters['variable']; $newVariableAssignmentCounter = $newParameters['counter']; if ($newVariableAssignmentCounter > 0) { $newVariableAssignmentName .= $newVariableAssignmentCounter; } $matchMap[] = '%tmp' . ($i + 1) . '%'; $replaceMap[] = '$' . $newVariableAssignmentName; $unsetList[] = $newVariableAssignmentName; } } if (isset($variableDataItem[5]) and $variableDataItem[5]) { if (is_array($variableDataItem[5])) { $knownTypes = array_unique(array_merge($knownTypes, $variableDataItem[5])); } else { if (is_string($variableDataItem[5])) { $knownTypes = array_unique(array_merge($knownTypes, array($variableDataItem[5]))); } else { $knownTypes = array_unique(array_merge($knownTypes, array('static'))); } } } $code = str_replace($matchMap, $replaceMap, $code); $php->addCodePiece($code, array('spacing' => $spacing)); $php->addVariableUnsetList($unsetList, array('spacing' => $spacing)); } } } } } } } } } } } } } } // After the entire expression line is done we try to extract the actual value if proxies are used $php->addCodePiece("if (! isset( \${$variableAssignmentName} ) ) \${$variableAssignmentName} = NULL;\n"); $php->addCodePiece("while " . ($resourceData['use-comments'] ? "/*TC:" . __LINE__ . "*/" : "") . "( is_object( \${$variableAssignmentName} ) and method_exists( \${$variableAssignmentName}, 'templateValue' ) )\n" . " \${$variableAssignmentName} = \${$variableAssignmentName}" . "->templateValue();\n"); }
/** * Return an array with activated extensions. * * @note Default extensions are those who are loaded before a siteaccess are determined while access extensions * are loaded after siteaccess is set. * * @param false|string $extensionType Decides which extension to include in the list, the follow values are possible: * - false - Means add both default and access extensions * - 'default' - Add only default extensions * - 'access' - Add only access extensions * @param eZINI|null $siteINI Optional parameter to be able to only do change on specific instance of site.ini * @return array */ public static function activeExtensions( $extensionType = false, eZINI $siteINI = null ) { if ( $siteINI === null ) { $siteINI = eZINI::instance(); } $activeExtensions = array(); if ( !$extensionType || $extensionType === 'default' ) { $activeExtensions = $siteINI->variable( 'ExtensionSettings', 'ActiveExtensions' ); } if ( !$extensionType || $extensionType === 'access' ) { $activeExtensions = array_merge( $activeExtensions, $siteINI->variable( 'ExtensionSettings', 'ActiveAccessExtensions' ) ); } if ( isset( $GLOBALS['eZActiveExtensions'] ) ) { $activeExtensions = array_merge( $activeExtensions, $GLOBALS['eZActiveExtensions'] ); } // return empty array as is to avoid further unneeded overhead if ( !isset( $activeExtensions[0] ) ) { return $activeExtensions; } // return array as is if ordering is disabled to avoid cache overhead $activeExtensions = array_unique( $activeExtensions ); if ( $siteINI->variable( 'ExtensionSettings', 'ExtensionOrdering' ) !== 'enabled' ) { // @todo Introduce a debug setting or re use existing dev mods to check that all extensions exists return $activeExtensions; } $cacheIdentifier = md5( serialize( $activeExtensions ) ); if ( isset ( self::$activeExtensionsCache[$cacheIdentifier] ) ) { return self::$activeExtensionsCache[$cacheIdentifier]; } // cache has to be stored by siteaccess + $extensionType $extensionDirectory = self::baseDirectory(); $expiryHandler = eZExpiryHandler::instance(); $phpCache = new eZPHPCreator( self::CACHE_DIR, "active_extensions_{$cacheIdentifier}.php" ); $expiryTime = $expiryHandler->hasTimestamp( 'active-extensions-cache' ) ? $expiryHandler->timestamp( 'active-extensions-cache' ) : 0; if ( !$phpCache->canRestore( $expiryTime ) ) { self::$activeExtensionsCache[$cacheIdentifier] = self::extensionOrdering( $activeExtensions ); // Check that all extensions defined actually exists before storing cache foreach ( self::$activeExtensionsCache[$cacheIdentifier] as $activeExtension ) { if ( !file_exists( $extensionDirectory . '/' . $activeExtension ) ) { eZDebug::writeError( "Extension '$activeExtension' does not exist, looked for directory '" . $extensionDirectory . '/' . $activeExtension . "'", __METHOD__ ); } } $phpCache->addVariable( 'activeExtensions', self::$activeExtensionsCache[$cacheIdentifier] ); $phpCache->store(); } else { $data = $phpCache->restore( array( 'activeExtensions' => 'activeExtensions' ) ); self::$activeExtensionsCache[$cacheIdentifier] = $data['activeExtensions']; } return self::$activeExtensionsCache[$cacheIdentifier]; }
static function storeCache($key, $templateFilepath) { if (!eZTemplateTreeCache::isCacheEnabled()) { return false; } $templateCache =& eZTemplateTreeCache::cacheTable(); $key = eZTemplateTreeCache::internalKey($key); if (!isset($templateCache[$key])) { eZDebug::writeDebug("Template cache for key '{$key}' does not exist, cannot store cache", __METHOD__); return; } $cacheFileName = eZTemplateTreeCache::treeCacheFilename($key, $templateFilepath); $cache =& $templateCache[$key]; $php = new eZPHPCreator(eZTemplateTreeCache::cacheDirectory(), $cacheFileName); $php->addVariable('eZTemplateTreeCacheCodeDate', eZTemplateTreeCache::CODE_DATE); $php->addSpace(); $php->addVariable('TemplateInfo', $cache['info']); $php->addSpace(); $php->addVariable('TemplateRoot', $cache['root']); $php->store(); }
function chooseTransformation( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters ) { $values = array(); $function = $operatorName; if ( ( count( $parameters ) < 2) ) { return false; } $tmpValues = false; $newElements = array(); if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) ) { $selected = eZTemplateNodeTool::elementConstantValue( $parameters[0] ); if ( $selected < 0 or $selected > ( count( $parameters ) - 1 ) ) { return false; } return $parameters[$selected + 1]; } else { $values[] = $parameters[0]; $array = $parameters; unset( $array[0] ); $count = count( $parameters ) - 1; $operatorNameText = eZPHPCreator::variableText( $operatorName ); if ( count( $parameters ) == ( 2 + 1 ) ) { $code = "%output% = %1% ? %3% : %2%;\n"; $values[] = $parameters[1]; $values[] = $parameters[2]; } else { $code = ( "if ( %1% < 0 and\n" . " %1% >= $count )\n" . "{\n" . " \$tpl->error( $operatorNameText, \"Index \" . %1% . \" out of range\" );\n" . " %output% = false;\n" . "}\n" ); $code .= "else switch ( %1% )\n{\n"; $valueNumber = 2; for ( $i = 0; $i < $count; ++$i ) { $parameterNumber = $i + 1; $code .= " case $i:"; if ( eZTemplateNodeTool::isConstantElement( $parameters[$parameterNumber] ) ) { $value = eZTemplateNodeTool::elementConstantValue( $parameters[$parameterNumber] ); $valueText = eZPHPCreator::variableText( $value, 0, 0, false ); $code .= " %output% = $valueText; break;\n"; } else { $code .= "\n {\n"; $code .= "%code$valueNumber%\n"; $code .= "%output% = %$valueNumber%;\n"; $code .= " } break;\n"; $values[] = $parameters[$parameterNumber]; ++$valueNumber; } } $code .= "}\n"; } } $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values, eZTemplateNodeTool::extractVariableNodePlacement( $node ), false ); return $newElements; }
function storeCacheObject($filename, $permissionArray) { $dir = dirname($filename); $file = basename($filename); $php = new eZPHPCreator($dir, $file); $php->addVariable("umap", array()); $php->addVariable("utf8map", array()); $php->addVariable("cmap", array()); $php->addVariable("utf8cmap", array()); reset($this->UnicodeMap); while (($key = key($this->UnicodeMap)) !== null) { $item = $this->UnicodeMap[$key]; $php->addVariable("umap[{$key}]", $item); next($this->UnicodeMap); } reset($this->UTF8Map); while (($key = key($this->UTF8Map)) !== null) { $item = $this->UTF8Map[$key]; if ($item == 0) { $php->addCodePiece("\$utf8map[0] = chr(0);\n"); } else { $val = str_replace(array("\\", "'"), array("\\\\", "\\'"), $item); $php->addVariable("utf8map[{$key}]", $val); } next($this->UTF8Map); } reset($this->CodeMap); while (($key = key($this->CodeMap)) !== null) { $item = $this->CodeMap[$key]; $php->addVariable("cmap[{$key}]", $item); next($this->CodeMap); } reset($this->UTF8CodeMap); while (($key = key($this->UTF8CodeMap)) !== null) { $item = $this->UTF8CodeMap[$key]; if ($item == 0) { $php->addVariable("utf8cmap[chr(0)]", 0); } else { $val = str_replace(array("\\", "'"), array("\\\\", "\\'"), $key); $php->addVariable("utf8cmap['{$val}']", $item); } next($this->UTF8CodeMap); } reset($this->ReadExtraMap); while (($key = key($this->ReadExtraMap)) !== null) { $item = $this->ReadExtraMap[$key]; $php->addVariable("read_extra[{$key}]", $item); next($this->ReadExtraMap); } $php->addVariable("eZCodePageCacheCodeDate", self::CACHE_CODE_DATE); $php->addVariable("min_char", $this->MinCharValue); $php->addVariable("max_char", $this->MaxCharValue); $php->store(true); if (file_exists($filename)) { // Store the old umask and set a new one. $oldPermissionSetting = umask(0); // Change the permission setting. @chmod($filename, $permissionArray['file_permission']); // Restore the old umask. umask($oldPermissionSetting); } }
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData) { $useLastValue = false; if (isset($parameters['last-value']) and !eZTemplateNodeTool::isConstantElement($parameters['last-value'])) { return false; } if (isset($parameters['name']) and !eZTemplateNodeTool::isConstantElement($parameters['name'])) { return false; } if (isset($parameters['var']) and !eZTemplateNodeTool::isConstantElement($parameters['var'])) { return false; } if (isset($parameters['reverse']) and !eZTemplateNodeTool::isConstantElement($parameters['reverse'])) { return false; } $varName = false; if (isset($parameters['var'])) { $varName = eZTemplateNodeTool::elementConstantValue($parameters['var']); } if (isset($parameters['last-value'])) { $useLastValue = (bool) eZTemplateNodeTool::elementConstantValue($parameters['last-value']); } if (!$varName) { $useLastValue = false; } $reverseLoop = false; if (isset($parameters['reverse'])) { $reverseLoop = eZTemplateNodeTool::elementConstantValue($parameters['reverse']); } $useLoop = isset($parameters['loop']); $allowLoop = true; $newNodes = array(); $maxText = "false"; $useMax = false; $maxPopText = false; if (isset($parameters['max'])) { if (eZTemplateNodeTool::isConstantElement($parameters['max'])) { $maxValue = eZTemplateNodeTool::elementConstantValue($parameters['max']); if ($maxValue > 0) { $maxText = eZPHPCreator::variableText($maxValue); $useMax = true; } else { return array(eZTemplateNodeTool::createTextNode('')); } } else { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['max'], eZTemplateNodeTool::extractFunctionNodePlacement($node), array(), 'max'); $maxText = "\$max"; $maxPopText = ", \$max"; $useMax = true; } } // Controls whether the 'if' statement with brackets is added $useShow = false; // Controls whether main nodes are handled, also controls delimiter and filters $useMain = true; // Controls wether else nodes are handled $useElse = false; $spacing = 0; if (isset($parameters['show'])) { if (eZTemplateNodeTool::isConstantElement($parameters['show'])) { $showValue = eZTemplateNodeTool::elementConstantValue($parameters['show']); if ($showValue) { $useMain = true; $useElse = false; $useShow = false; } else { $useMain = false; $useElse = true; $useShow = false; } $newNodes[] = eZTemplateNodeTool::createTextNode(''); } else { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['show'], eZTemplateNodeTool::extractFunctionNodePlacement($node), array(), 'show'); $spacing = 4; $useElse = true; $useShow = true; } } $children = eZTemplateNodeTool::extractFunctionNodeChildren($node); if ($useShow) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \$show )\n{\n"); $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode($spacing); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode('show'); } if (isset($parameters['name']) and !$useLoop) { $newNodes[] = eZTemplateNodeTool::createNamespaceChangeNode($parameters['name']); } $mainNodes = eZTemplateNodeTool::extractNodes($children, array('match' => array('type' => 'before', 'matches' => array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => 'section-else')), 'filter' => array(array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => array('delimiter', 'section-exclude', 'section-include'))))))); $delimiterNodes = eZTemplateNodeTool::extractNodes($children, array('match' => array('type' => 'equal', 'matches' => array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => 'delimiter'))))); $filterNodes = eZTemplateNodeTool::extractNodes($children, array('match' => array('type' => 'equal', 'matches' => array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => array('section-exclude', 'section-include')))))); $delimiterNode = false; if (count($delimiterNodes) > 0) { $delimiterNode = $delimiterNodes[0]; } if ($useMain) { // Avoid transformation if the nodes will not be used, saves time $mainNodes = eZTemplateCompiler::processNodeTransformationNodes($tpl, $node, $mainNodes, $privateData); } if ($useLoop and $useMain) { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $parameters['loop'], eZTemplateNodeTool::extractFunctionNodePlacement($node), array(), 'loopItem'); $hasSequence = false; if (isset($parameters['sequence'])) { $sequenceParameter = $parameters['sequence']; $hasSequence = true; $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $sequenceParameter, eZTemplateNodeTool::extractFunctionNodePlacement($node), array(), 'sequence'); } if (isset($parameters['name'])) { $newNodes[] = eZTemplateNodeTool::createNamespaceChangeNode($parameters['name']); } $code = "if ( !isset( \$sectionStack ) )\n" . " \$sectionStack = array();\n"; $variableValuePushText = ''; $variableValuePopText = ''; if ($varName) { $code .= "\$variableValue = new eZTemplateSectionIterator();\n" . "\$lastVariableValue = false;\n"; $variableValuePushText = "&\$variableValue, "; $variableValuePopText = "\$variableValue, "; } $code .= "\$index = 0;\n" . "\$currentIndex = 1;\n"; $arrayCode = ''; $numericCode = ''; $stringCode = ''; $offsetText = '0'; if (isset($parameters['offset'])) { $offsetParameter = $parameters['offset']; if (eZTemplateNodeTool::isConstantElement($offsetParameter)) { $iterationValue = (int) eZTemplateNodeTool::elementConstantValue($offsetParameter); if ($iterationValue > 0) { $arrayCode = " \$loopKeys = array_splice( \$loopKeys, {$iterationValue} );\n"; } $offsetText = $iterationValue; } else { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $offsetParameter, eZTemplateNodeTool::extractFunctionNodePlacement($node), array(), 'offset'); $arrayCode = " if ( \$offset > 0 )\n" . " \$loopKeys = array_splice( \$loopKeys, \$offset );\n"; $offsetText = "\$offset"; } } // Initialization for array $code .= "if ( is_array( \$loopItem ) )\n{\n" . " \$loopKeys = array_keys( \$loopItem );\n"; if ($reverseLoop) { $code .= " \$loopKeys = array_reverse( \$loopKeys );\n"; } $code .= $arrayCode; $code .= " \$loopCount = count( \$loopKeys );\n"; $code .= "}\n"; // Initialization for numeric $code .= "else if ( is_numeric( \$loopItem ) )\n{\n" . " \$loopKeys = false;\n" . $numericCode . " if ( \$loopItem < 0 )\n" . " \$loopCountValue = -\$loopItem;\n" . " else\n" . " \$loopCountValue = \$loopItem;\n" . " \$loopCount = \$loopCountValue - {$offsetText};\n" . "}\n"; // Initialization for string $code .= "else if ( is_string( \$loopItem ) )\n{\n" . " \$loopKeys = false;\n" . $stringCode . " \$loopCount = strlen( \$loopItem ) - {$offsetText};\n" . "}\n"; // Fallback for no item $code .= "else\n{\n" . " \$loopKeys = false;\n" . " \$loopCount = 0;\n" . "}"; // Initialization end $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code); $code = "while ( \$index < \$loopCount )\n" . "{\n"; if ($useMax) { $code .= " if ( \$currentIndex > {$maxText} )\n" . " break;\n" . " unset( \$item );\n"; } // Iterator check for array $code .= " if ( is_array( \$loopItem ) )\n" . " {\n" . " \$loopKey = \$loopKeys[\$index];\n" . " unset( \$item );\n" . " \$item = \$loopItem[\$loopKey];\n" . " }\n"; // Iterator check for numeric $code .= " else if ( is_numeric( \$loopItem ) )\n" . " {\n" . " unset( \$item );\n"; if ($reverseLoop) { $code .= " \$item = \$loopCountValue - \$index - {$offsetText};\n"; } else { $code .= " \$item = \$index + {$offsetText} + 1;\n"; } $code .= " if ( \$loopItem < 0 )\n" . " \$item = -\$item;\n"; if ($reverseLoop) { $code .= " \$loopKey = \$loopCountValue - \$index - {$offsetText} - 1;\n"; } else { $code .= " \$loopKey = \$index + {$offsetText};\n"; } $code .= " }\n"; // Iterator check for string $code .= " else if ( is_string( \$loopItem ) )\n" . " {\n" . " unset( \$item );\n"; if ($reverseLoop) { $code .= " \$loopKey = \$loopCount - \$index - {$offsetText} + 1;\n"; } else { $code .= " \$loopKey = \$index + {$offsetText};\n"; } $code .= " \$item = \$loopItem[\$loopKey];\n" . " }\n"; // Iterator check end $code .= " unset( \$last );\n" . " \$last = false;\n"; $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code); $code = ''; if ($useLastValue) { $code .= " if ( \$currentIndex > 1 )\n" . " {\n" . " \$last = \$lastVariableValue;\n" . " \$variableValue = new eZTemplateSectionIterator();\n" . " }\n"; } if ($varName) { $code .= " \$variableValue->setIteratorValues( \$item, \$loopKey, \$currentIndex - 1, \$currentIndex, false, \$last );"; $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'variableValue', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, $varName), false, true, true); } else { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'loopKey', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, 'key'), false, true, true); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'item', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, 'item'), false, true, true); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\$currentIndexInc = \$currentIndex - 1;\n"); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'currentIndexInc', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, 'index'), false, true, true); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'currentIndex', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, 'number'), false, true, true); } $mainSpacing = 0; $hasFilter = false; if (count($filterNodes) > 0) { $newFilterNodes = array(); $matchValue = true; $hasDynamicFilter = false; foreach ($filterNodes as $filterNode) { $filterParameters = eZTemplateNodeTool::extractFunctionNodeParameters($filterNode); if (!isset($filterParameters['match'])) { continue; } $hasFilter = true; $filterParameterMatch = $filterParameters['match']; $filterParameterMatch = eZTemplateCompiler::processElementTransformationList($tpl, $filterNode, $filterParameterMatch, $privateData); if (eZTemplateNodeTool::isConstantElement($filterParameterMatch)) { $matchValue = eZTemplateNodeTool::elementConstantValue($filterParameterMatch); if (eZTemplateNodeTool::extractFunctionNodeName($filterNode) == 'section-exclude') { if ($matchValue) { $matchValue = false; } } else { if ($matchValue) { $matchValue = true; } } $newFilterNodes = array(); $hasDynamicFilter = false; } else { $newFilterNodes[] = eZTemplateNodeTool::createVariableNode(false, $filterParameterMatch, eZTemplateNodeTool::extractFunctionNodePlacement($filterNode), array('spacing' => 4), 'tmpMatchValue'); if (eZTemplateNodeTool::extractFunctionNodeName($filterNode) == 'section-exclude') { $newFilterNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \$tmpMatchValue )\n \$matchValue = false;", array('spacing' => 4)); } else { $newFilterNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \$tmpMatchValue )\n \$matchValue = true;", array('spacing' => 4)); } $hasDynamicFilter = true; } } if ($hasFilter) { $mainSpacing += 4; $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $matchValue, eZTemplateNodeTool::extractFunctionNodePlacement($filterNode), array('spacing' => 4), 'matchValue'); if ($hasDynamicFilter) { $newNodes = array_merge($newNodes, $newFilterNodes); } $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \$matchValue )\n{\n", array('spacing' => 4)); } } $sequencePopText = ''; if ($hasSequence) { $sequencePopText = ", \$sequence"; if ($varName) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( is_array( \$sequence ) )\n" . "{\n" . " \$sequenceValue = array_shift( \$sequence );\n" . " \$variableValue->setSequence( \$sequenceValue );\n" . " \$sequence[] = \$sequenceValue;\n" . " unset( \$sequenceValue );\n" . "}", array('spacing' => $mainSpacing + 4)); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'variableValue', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, $varName), false, true, true); } else { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( is_array( \$sequence ) )\n" . "{\n" . " \$sequenceValue = array_shift( \$sequence );\n", array('spacing' => $mainSpacing + 4)); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'sequenceValue', eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => $mainSpacing + 4), array('', eZTemplate::NAMESPACE_SCOPE_RELATIVE, 'sequence'), false, true, true); $newNodes[] = eZTemplateNodeTool::createCodePieceNode(" \$sequence[] = \$sequenceValue;\n" . " unset( \$sequenceValue );\n" . "}", array('spacing' => $mainSpacing + 4)); } } $code = "\$sectionStack[] = array( " . $variableValuePushText . "&\$loopItem, \$loopKeys, \$loopCount, \$currentIndex, \$index" . $sequencePopText . $maxPopText . " );\n" . "unset( \$loopItem, \$loopKeys );\n"; $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code, array('spacing' => $mainSpacing + 4)); $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode($mainSpacing + 4); if ($delimiterNode) { $delimiterChildren = eZTemplateNodeTool::extractFunctionNodeChildren($delimiterNode); $delimiterParameters = eZTemplateNodeTool::extractFunctionNodeParameters($delimiterNode); $delimiterChildren = eZTemplateCompiler::processNodeTransformationNodes($tpl, $node, $delimiterChildren, $privateData); $delimiterModulo = false; $matchCode = false; $useModulo = true; if (isset($delimiterParameters['match'])) { $delimiterMatch = $delimiterParameters['match']; $delimiterMatch = eZTemplateCompiler::processElementTransformationList($tpl, $delimiterNode, $delimiterMatch, $privateData); if (eZTemplateNodeTool::isConstantElement($delimiterMatch)) { $moduloValue = eZTemplateNodeTool::elementConstantValue($delimiterMatch); $useModulo = false; } else { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $delimiterMatch, eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 0), 'matchValue'); $matchCode = " and \$matchValue"; } } else { if (isset($delimiterParameters['modulo'])) { $delimiterModulo = $delimiterParameters['modulo']; $delimiterModulo = eZTemplateCompiler::processElementTransformationList($tpl, $delimiterModulo, $delimiterModulo, $privateData); if (eZTemplateNodeTool::isConstantElement($delimiterModulo)) { $moduloValue = (int) eZTemplateNodeTool::elementConstantValue($delimiterModulo); $matchCode = " and ( ( \$currentIndex - 1 ) % {$moduloValue} ) == 0"; } else { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $delimiterModulo, eZTemplateNodeTool::extractFunctionNodePlacement($node), array('spacing' => 0), 'moduloValue'); $matchCode = " and ( ( \$currentIndex - 1 ) % \$moduloValue ) == 0"; } } } if ($useModulo) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( \$currentIndex > 1{$matchCode} )\n{"); $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(4); $newNodes = array_merge($newNodes, $delimiterChildren); $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(4); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}\n"); } } $newNodes = array_merge($newNodes, $mainNodes); $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode($mainSpacing + 4); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("list( " . $variableValuePopText . "\$loopItem, \$loopKeys, \$loopCount, \$currentIndex, \$index" . $sequencePopText . $maxPopText . " ) = array_pop( \$sectionStack );", array('spacing' => $mainSpacing + 4)); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("++\$currentIndex;\n", array('spacing' => $mainSpacing + 4)); if ($varName) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode("\$lastVariableValue = \$variableValue;", array('spacing' => $mainSpacing + 4)); } if ($hasFilter) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode(" }"); $mainSpacing -= 4; } $newNodes[] = eZTemplateNodeTool::createCodePieceNode("++\$index;\n", array('spacing' => $mainSpacing + 4)); $code = "}\n" . "unset( \$loopKeys, \$loopCount, \$index, \$last, \$loopIndex, \$loopItem"; if ($hasSequence) { $code .= ", \$sequence"; } $code .= " );"; $newNodes[] = eZTemplateNodeTool::createCodePieceNode($code); } else { if ($useMain) { $newNodes = array_merge($newNodes, $mainNodes); } } if (isset($parameters['name'])) { $newNodes[] = eZTemplateNodeTool::createNamespaceRestoreNode(); } if ($useShow) { $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode($spacing); } if ($useElse) { $elseNodes = eZTemplateNodeTool::extractNodes($children, array('match' => array('type' => 'after', 'matches' => array(array('match-keys' => array(0), 'match-with' => eZTemplate::NODE_FUNCTION), array('match-keys' => array(2), 'match-with' => 'section-else'))))); $elseNodes = eZTemplateCompiler::processNodeTransformationNodes($tpl, $node, $elseNodes, $privateData); if (count($elseNodes) > 0) { if ($useShow) { // This is needed if a 'if ( $show )' was used earlier $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}\nelse\n{\n"); $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode($spacing); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode('show'); } if (isset($parameters['name'])) { $newNodes[] = eZTemplateNodeTool::createNamespaceChangeNode($parameters['name']); } $newNodes = array_merge($newNodes, $elseNodes); if (isset($parameters['name'])) { $newNodes[] = eZTemplateNodeTool::createNamespaceRestoreNode(); } if ($useShow) { // This is needed if a 'if ( $show )' was used earlier $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode($spacing); } } if ($useShow) { // This is needed if a 'if ( $show )' was used earlier $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}\n"); } } return $newNodes; }
function resourceAcquisitionTransformation( $functionName, &$node, $rule, $inputData, $outputName, $namespaceValue, $templateRoot, $viewDir, $viewValue, $matchFileArray, $acquisitionSpacing, &$resourceData ) { $startRoot = '/' . $templateRoot . $viewDir; $viewFileMatchName = '/' . $templateRoot . '/' . $viewValue . '.tpl'; $startRootLength = strlen( $startRoot ); $matchList = array(); $viewFileMatch = null; foreach ( $matchFileArray as $matchFile ) { if ( !isset( $matchFile['template'] ) ) continue; $path = $matchFile['template']; if ( substr( $path, 0, $startRootLength ) == $startRoot and $path[$startRootLength] == '/' ) { $matchFile['match_part'] = substr( $path, $startRootLength + 1 ); $matchList[] = $matchFile; } if ( $path == $viewFileMatchName ) $viewFileMatch = $matchFile; } $designKeysName = 'dKeys'; $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( !isset( \$$designKeysName ) )\n" . "{\n" . " \$resH = \$tpl->resourceHandler( 'design' );\n" . " \$$designKeysName = \$resH->keys();\n" . "}", array( 'spacing' => $acquisitionSpacing ) ); if ( isset( $rule["attribute_keys"] ) ) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( !isset( \$" . $designKeysName . "Stack ) )\n" . "{\n" . " \$" . $designKeysName . "Stack = array();\n" . "}\n" . "\$" . $designKeysName . "Stack[] = \$$designKeysName;", array( 'spacing' => $acquisitionSpacing ) ); foreach ( $rule["attribute_keys"] as $designKey => $attributeKeyArray ) { $attributeAccessData = array(); $attributeAccessData[] = eZTemplateNodeTool::createVariableElement( $outputName, $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE ); foreach ( $attributeKeyArray as $attributeKey ) { $attributeAccessData[] = eZTemplateNodeTool::createAttributeLookupElement( $attributeKey ); } $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $attributeAccessData, false, array( 'spacing' => 0 ), 'dKey' ); $designKeyText = eZPHPCreator::variableText( $designKey, 0, 0, false ); $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$" . $designKeysName . "[$designKeyText] = \$dKey;", array( 'spacing' => $acquisitionSpacing ) ); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode( 'dKey' ); } } $attributeAccess = $rule["attribute_access"]; $hasAttributeAccess = false; if ( is_array( $attributeAccess ) ) { $hasAttributeAccess = count( $attributeAccess ) > 0; $attributeAccessCount = 0; foreach ( $attributeAccess as $attributeAccessEntries ) { $attributeAccessData = $inputData; $spacing = $acquisitionSpacing; if ( $attributeAccessCount > 1 ) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . " if ( !\$resourceFound )\n{\n", array( 'spacing' => $acquisitionSpacing ) ); $spacing += 4; } else if ( $attributeAccessCount > 0 ) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( !\$resourceFound )\n{\n", array( 'spacing' => $acquisitionSpacing ) ); $spacing += 4; } foreach ( $attributeAccessEntries as $attributeAccessName ) { // $attributeAccessData[] = eZTemplateNodeTool::createCodePieceNode( "" . ( $resourceData['use-comments'] ? ( "/*TC:" . __LINE__ . "*/" ) : "" ) . "" ); $attributeAccessData[] = eZTemplateNodeTool::createAttributeLookupElement( $attributeAccessName ); } $accessNodes = array(); $accessNodes[] = eZTemplateNodeTool::createVariableNode( false, $attributeAccessData, false, array( 'spacing' => $spacing ), 'attributeAccess' ); $acquisitionNodes = array(); $templateCounter = 0; $hasAcquisitionNodes = false; $matchLookupArray = array(); foreach ( $matchList as $matchItem ) { $tmpAcquisitionNodes = array(); $matchPart = $matchItem['match_part']; if ( preg_match( "/^(.+)\.tpl$/", $matchPart, $matches ) ) $matchPart = $matches[1]; $code = "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( \$attributeAccess == '$matchPart' )\n{\n"; if ( $templateCounter > 0 ) $code = "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "" . $code; $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( $code, array( 'spacing' => $spacing ) ); $defaultMatchSpacing = $spacing; $useArrayLookup = false; $addFileResource = true; if ( isset( $matchItem['custom_match'] ) ) { $customSpacing = $spacing + 4; $defaultMatchSpacing = $spacing + 4; $matchCount = 0; foreach ( $matchItem['custom_match'] as $customMatch ) { $matchConditionCount = count( $customMatch['conditions'] ); $code = ''; if ( $matchCount > 0 ) { $code = "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . ""; } if ( $matchConditionCount > 0 ) { if ( $matchCount > 0 ) $code .= " "; $code .= "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( "; } $ifLength = strlen( $code ); $conditionCount = 0; if ( isset( $customMatch['conditions'] ) ) { foreach ( $customMatch['conditions'] as $conditionName => $conditionValue ) { if ( $conditionCount > 0 ) $code .= " and\n" . str_repeat( ' ', $ifLength ); $conditionNameText = eZPHPCreator::variableText( $conditionName, 0 ); $conditionValueText = eZPHPCreator::variableText( $conditionValue, 0 ); $code .= "isset( \$" . $designKeysName . "[$conditionNameText] ) and "; if ( $conditionNameText == '"url_alias"' ) { $code .= "( strpos(\$" . $designKeysName . "[$conditionNameText], $conditionValueText ) === 0 )"; } else { $code .= "( is_array( \$" . $designKeysName . "[$conditionNameText] ) ? " . "in_array( $conditionValueText, \$" . $designKeysName . "[$conditionNameText] ) : " . "\$" . $designKeysName . "[$conditionNameText] == $conditionValueText )"; } ++$conditionCount; } } if ( $matchConditionCount > 0 ) { $code .= " )\n"; } if ( $matchConditionCount > 0 or $matchCount > 0 ) { $code .= "{"; } $matchFile = $customMatch['match_file']; $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( $code, array( 'spacing' => $customSpacing ) ); $hasAcquisitionNodes = true; // If $matchFile is an array we cannot create a transformation for this entry if ( is_array( $matchFile ) ) return false; $tmpAcquisitionNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '', $matchFile, $matchFile, eZTemplate::RESOURCE_FETCH, false, $node[4], array( 'spacing' => $customSpacing + 4 ), $rule['namespace'] ); if ( $matchConditionCount > 0 or $matchCount > 0 ) { $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $customSpacing ) ); } ++$matchCount; if ( $matchConditionCount == 0 ) { $addFileResource = false; break; } } if ( $addFileResource ) $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . " \n{", array( 'spacing' => $customSpacing ) ); } else { $matchFile = $matchItem['base_dir'] . $matchItem['template']; $matchLookupArray[$matchPart] = $matchFile; $useArrayLookup = true; } if ( !$useArrayLookup ) { if ( $addFileResource ) { $matchFile = $matchItem['base_dir'] . $matchItem['template']; $tmpAcquisitionNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '', $matchFile, $matchFile, eZTemplate::RESOURCE_FETCH, false, $node[4], array( 'spacing' => $defaultMatchSpacing + 4 ), $rule['namespace'] ); $hasAcquisitionNodes = true; if ( isset( $matchItem['custom_match'] ) ) $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $customSpacing ) ); } ++$templateCounter; $tmpAcquisitionNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $spacing ) ); $acquisitionNodes = array_merge( $acquisitionNodes, $tmpAcquisitionNodes ); } } if ( count( $matchLookupArray ) > 0 ) { $newNodes = array_merge( $newNodes, $accessNodes ); $accessNodes = array(); // If $matchFile is an array we cannot create a transformation for this entry if ( is_array( $matchLookupArray ) ) return false; $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '', $matchLookupArray, false, eZTemplate::RESOURCE_FETCH, false, $node[4], array( 'spacing' => $spacing ), $rule['namespace'], 'attributeAccess' ); if ( $hasAcquisitionNodes ) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "\n{", array( 'spacing' => $spacing ) ); $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(); } } if ( $hasAcquisitionNodes ) { $newNodes = array_merge( $newNodes, $accessNodes, $acquisitionNodes ); if ( $attributeAccessCount > 0 ) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $acquisitionSpacing ) ); } ++$attributeAccessCount; } else if ( count( $matchLookupArray ) == 0 ) { $newNodes[] = eZTemplateNodeTool::createErrorNode( "Failed to load template", $functionName, eZTemplateNodeTool::extractFunctionNodePlacement( $node ), array( 'spacing' => $acquisitionSpacing ) ); } if ( count( $matchLookupArray ) > 0 and $hasAcquisitionNodes ) { $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(); $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $spacing ) ); } } } if ( $viewFileMatch !== null ) { $mainSpacing = 0; if ( $hasAttributeAccess ) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "\n{\n", array( 'spacing' => $acquisitionSpacing ) ); $mainSpacing = 4; } $templateCounter = 0; $addFileResource = true; if ( isset( $viewFileMatch['custom_match'] ) ) { $spacing = $mainSpacing + 4; $matchCount = 0; foreach ( $viewFileMatch['custom_match'] as $customMatch ) { $matchConditionCount = count( $customMatch['conditions'] ); $code = ''; if ( $matchCount > 0 ) { $code = "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . ""; } if ( $matchConditionCount > 0 ) { if ( $matchCount > 0 ) $code .= " "; $code .= "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( "; $ifLength = strlen( $code ); $conditionCount = 0; if ( is_array( $customMatch['conditions'] ) ) { foreach ( $customMatch['conditions'] as $conditionName => $conditionValue ) { if ( $conditionCount > 0 ) $code .= " and\n" . str_repeat( ' ', $ifLength ); $conditionNameText = eZPHPCreator::variableText( $conditionName, 0 ); $conditionValueText = eZPHPCreator::variableText( $conditionValue, 0 ); $code .= "isset( \$" . $designKeysName . "[$conditionNameText] ) and "; if ( $conditionNameText == '"url_alias"' ) { $code .= "( strpos(\$" . $designKeysName . "[$conditionNameText], $conditionValueText ) === 0 )"; } else { $code .= "( is_array( \$" . $designKeysName . "[$conditionNameText] ) ? " . "in_array( $conditionValueText, \$" . $designKeysName . "[$conditionNameText] ) : " . "\$" . $designKeysName . "[$conditionNameText] == $conditionValueText )"; } ++$conditionCount; } } $code .= " )\n"; } if ( $matchConditionCount > 0 or $matchCount > 0 ) { $code .= "{"; } $matchFile = $customMatch['match_file']; $newNodes[] = eZTemplateNodeTool::createCodePieceNode( $code, array( 'spacing' => $acquisitionSpacing ) ); // If $matchFile is an array we cannot create a transformation for this entry if ( is_array( $matchFile ) ) return false; $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '', $matchFile, $matchFile, eZTemplate::RESOURCE_FETCH, false, $node[4], array( 'spacing' => $spacing ), $rule['namespace'] ); if ( $matchConditionCount > 0 or $matchCount > 0 ) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $acquisitionSpacing ) ); } ++$matchCount; if ( $matchConditionCount == 0 ) { if ( $matchCount > 0 ) $addFileResource = false; break; } } if ( $addFileResource ) $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "\n{", array( 'spacing' => $acquisitionSpacing ) ); } if ( $addFileResource ) { $file = $viewFileMatch['base_dir'] . $viewFileMatch['template']; $newNodes[] = eZTemplateNodeTool::createResourceAcquisitionNode( '', $file, $file, eZTemplate::RESOURCE_FETCH, false, $node[4], array( 'spacing' => $mainSpacing ), $rule['namespace'] ); } if ( isset( $viewFileMatch['custom_match'] ) and $addFileResource ) $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}", array( 'spacing' => $acquisitionSpacing ) ); if ( $hasAttributeAccess ) $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}\n", array( 'spacing' => $acquisitionSpacing ) ); } if ( isset( $rule["attribute_keys"] ) ) { $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$$designKeysName = array_pop( \$" . $designKeysName . "Stack );", array( 'spacing' => $acquisitionSpacing ) ); } return $newNodes; }
function storeCacheFile($filepath, $transformationData, $extraCode, $type, $charsetName) { $file = basename($filepath); $dir = dirname($filepath); $php = new eZPHPCreator($dir, $file); $php->addComment("Cached transformation data"); $php->addComment("Type: {$type}"); $php->addComment("Charset: {$charsetName}"); $php->addComment("Cached transformation data"); $php->addCodePiece('$data = ' . eZCharTransform::varExport($transformationData) . ";\n"); $php->addCodePiece("\$text = strtr( \$text, \$data['table'] );\n"); if ($extraCode) { $php->addCodePiece($extraCode); } return $php->store(true); }
/** * Returns the class identifier hash for the current database. * If it is outdated or non-existent, the method updates/generates the file * * @static * @since Version 4.1 * @access protected * @return array Returns hash of classidentifier => classid */ protected static function classIdentifiersHash() { if (self::$identifierHash === null) { $db = eZDB::instance(); $dbName = md5($db->DB); $cacheDir = eZSys::cacheDirectory(); $phpCache = new eZPHPCreator($cacheDir, 'classidentifiers_' . $dbName . '.php', '', array('clustering' => 'classidentifiers')); eZExpiryHandler::registerShutdownFunction(); $handler = eZExpiryHandler::instance(); $expiryTime = 0; if ($handler->hasTimestamp('class-identifier-cache')) { $expiryTime = $handler->timestamp('class-identifier-cache'); } if ($phpCache->canRestore($expiryTime)) { $var = $phpCache->restore(array('identifierHash' => 'identifier_hash')); self::$identifierHash = $var['identifierHash']; } else { // Fetch identifier/id pair from db $query = "SELECT id, identifier FROM ezcontentclass where version=0"; $identifierArray = $db->arrayQuery($query); self::$identifierHash = array(); foreach ($identifierArray as $identifierRow) { self::$identifierHash[$identifierRow['identifier']] = $identifierRow['id']; } // Store identifier list to cache file $phpCache->addVariable('identifier_hash', self::$identifierHash); $phpCache->store(); } } return self::$identifierHash; }
function writeVariable($variableName, $variableValue, $assignmentType = eZPHPCreator::VARIABLE_ASSIGNMENT, $variableParameters = array()) { $variableParameters = array_merge(array('full-tree' => false, 'spacing' => 0), $variableParameters); $fullTree = $variableParameters['full-tree']; $spacing = $this->Spacing ? $variableParameters['spacing'] : 0; $text = $this->variableNameText($variableName, $assignmentType, $variableParameters); $maxIterations = 2; if ($fullTree) { $maxIterations = false; } $text .= $this->thisVariableText($variableValue, strlen($text), 0, $maxIterations); $text .= ";\n"; $text = eZPHPCreator::prependSpacing($text, $spacing); $this->write($text); }
function fetchTransform( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters ) { $parameterTranslation = false; $constParameters = array(); if ( $operatorName == $this->Fetch ) { if ( !eZTemplateNodeTool::isConstantElement( $parameters[0] ) || !eZTemplateNodeTool::isConstantElement( $parameters[1] ) ) { return false; } $moduleName = eZTemplateNodeTool::elementConstantValue( $parameters[0] ); $functionName = eZTemplateNodeTool::elementConstantValue( $parameters[1] ); $moduleFunctionInfo = eZFunctionHandler::moduleFunctionInfo( $moduleName ); if ( !$moduleFunctionInfo->isValid() ) { eZDebug::writeError( "Cannot execute module '$moduleName', no module found", __METHOD__ ); return array(); } $fetchParameters = array(); if ( isset( $parameters[2] ) ) $fetchParameters = $parameters[2]; } else if ( $operatorName == $this->FetchAlias ) { if ( !eZTemplateNodeTool::isConstantElement( $parameters[0] ) ) { return false; } $aliasFunctionName = eZTemplateNodeTool::elementConstantValue( $parameters[0] ); $aliasSettings = eZINI::instance( 'fetchalias.ini' ); if ( $aliasSettings->hasSection( $aliasFunctionName ) ) { $moduleFunctionInfo = eZFunctionHandler::moduleFunctionInfo( $aliasSettings->variable( $aliasFunctionName, 'Module' ) ); if ( !$moduleFunctionInfo->isValid() ) { eZDebug::writeError( "Cannot execute function '$aliasFunctionName' in module '$moduleName', no valid data", __METHOD__ ); return array(); } $functionName = $aliasSettings->variable( $aliasFunctionName, 'FunctionName' ); $functionArray = array(); if ( $aliasSettings->hasVariable( $aliasFunctionName, 'Parameter' ) ) { $parameterTranslation = $aliasSettings->variable( $aliasFunctionName, 'Parameter' ); } if ( $aliasSettings->hasVariable( $aliasFunctionName, 'Constant' ) ) { $constantParameterArray = $aliasSettings->variable( $aliasFunctionName, 'Constant' ); if ( is_array( $constantParameterArray ) ) { foreach ( array_keys( $constantParameterArray ) as $constKey ) { if ( $moduleFunctionInfo->isParameterArray( $functionName, $constKey ) ) $constParameters[$constKey] = explode( ';', $constantParameterArray[$constKey] ); else $constParameters[$constKey] = $constantParameterArray[$constKey]; } } } } else { $placement = eZTemplateNodeTool::extractFunctionNodePlacement( $node ); $tpl->warning( 'fetch_alias', "Fetch alias '$aliasFunctionName' is not defined in fetchalias.ini", $placement ); return array(); } $fetchParameters = array(); if ( isset( $parameters[1] ) ) $fetchParameters = $parameters[1]; } else { return false; } $functionDefinition = $moduleFunctionInfo->preExecute( $functionName ); if ( $functionDefinition === false ) { return false; } $isDynamic = false; $isVariable = false; if ( eZTemplateNodeTool::isConstantElement( $fetchParameters ) ) { $staticParameters = eZTemplateNodeTool::elementConstantValue( $fetchParameters ); $functionKeys = array_keys( $staticParameters ); } else if ( eZTemplateNodeTool::isDynamicArrayElement( $fetchParameters ) ) { $isDynamic = true; $dynamicParameters = eZTemplateNodeTool::elementDynamicArray( $fetchParameters ); $functionKeys = eZTemplateNodeTool::elementDynamicArrayKeys( $fetchParameters ); } else if ( eZTemplateNodeTool::isVariableElement( $fetchParameters ) or eZTemplateNodeTool::isInternalCodePiece( $fetchParameters ) ) { $isVariable = true; } else { $functionKeys = array(); } $paramCount = 0; $values = array(); if ( $isVariable ) { $values[] = $fetchParameters; $parametersCode = 'array( '; foreach( $functionDefinition['parameters'] as $parameterDefinition ) { if ( $paramCount != 0 ) { $parametersCode .= ',' . "\n"; } ++$paramCount; $parameterName = $parameterDefinition['name']; if ( $parameterTranslation ) { if ( in_array( $parameterName, array_keys( $parameterTranslation ) ) ) { $parameterName = $parameterTranslation[$parameterName]; } } $defaultValue = 'null'; if ( !$parameterDefinition['required'] ) $defaultValue = eZPHPCreator::variableText( $parameterDefinition['default'], 0, 0, false ); $parametersSelection = '%1%[\'' . $parameterName . '\']'; $parametersCode .= '( isset( ' . $parametersSelection . ' ) ? ' . $parametersSelection . " : $defaultValue )"; } $parametersCode .= ' )'; } else { $parametersCode = 'array( '; if ( count( $functionDefinition['parameters'] ) ) { foreach( $functionDefinition['parameters'] as $parameterDefinition ) { if ( $paramCount != 0 ) { $parametersCode .= ',' . "\n"; } ++$paramCount; $parameterName = $parameterDefinition['name']; if ( $parameterTranslation ) { if ( in_array( $parameterName, array_keys( $parameterTranslation ) ) ) { $parameterName = $parameterTranslation[$parameterName]; } } $parametersCode .= ' \'' . $parameterName . '\' => '; if ( in_array( $parameterName, $functionKeys ) ) { if ( $isDynamic ) { if ( eZTemplateNodeTool::isConstantElement( $dynamicParameters[$parameterName] ) ) { $parametersCode .= eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $dynamicParameters[$parameterName] ), 0, 0, false ); } else { $values[] = $dynamicParameters[$parameterName]; $parametersCode .= '%' . count( $values ) . '%'; } } else { $parametersCode .= eZPHPCreator::variableText( $staticParameters[$parameterName], 0, 0, false ); } } else if( $constParameters && isset( $constParameters[$parameterName] ) ) { $parametersCode .= eZPHPCreator::variableText( $constParameters[$parameterName], 0, 0, false ); } else { if ( $parameterDefinition['required'] ) { return false; } else if ( isset( $parameterDefinition['default'] ) ) { $parametersCode .= eZPHPCreator::variableText( $parameterDefinition['default'], 0, 0, false ); } else { $parametersCode .= 'null'; } } } } $parametersCode .= ' )'; } $code = '%output% = call_user_func_array( array( new ' . $functionDefinition['call_method']['class'] . '(), \'' . $functionDefinition['call_method']['method'] . '\' ),' . "\n" . ' ' . $parametersCode . ' );'; $code .= "\n"; $code .= '%output% = isset( %output%[\'result\'] ) ? %output%[\'result\'] : null;' . "\n"; return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); }
function templateNodeTransformation($functionName, &$node, $tpl, $parameters, $privateData) { if ($functionName == $this->BlockName or $functionName == $this->AppendBlockName) { if (!isset($parameters['variable'])) { return false; } $scope = eZTemplate::NAMESPACE_SCOPE_RELATIVE; if (isset($parameters['scope'])) { if (!eZTemplateNodeTool::isConstantElement($parameters['scope'])) { return false; } $scopeText = eZTemplateNodeTool::elementConstantValue($parameters['scope']); if ($scopeText == 'relative') { $scope = eZTemplate::NAMESPACE_SCOPE_RELATIVE; } else { if ($scopeText == 'root') { $scope = eZTemplate::NAMESPACE_SCOPE_LOCAL; } else { if ($scopeText == 'global') { $scope = eZTemplate::NAMESPACE_SCOPE_GLOBAL; } } } } $name = ''; if (isset($parameters['name'])) { if (!eZTemplateNodeTool::isConstantElement($parameters['name'])) { return false; } $name = eZTemplateNodeTool::elementConstantValue($parameters['name']); } $variableName = eZTemplateNodeTool::elementConstantValue($parameters['variable']); $newNodes = array(); $children = eZTemplateNodeTool::extractFunctionNodeChildren($node); $newNodes[] = eZTemplateNodeTool::createOutputVariableIncreaseNode(); $newNodes = array_merge($newNodes, $children); $newNodes[] = eZTemplateNodeTool::createAssignFromOutputVariableNode('blockText'); if ($functionName == $this->AppendBlockName) { $data = array(eZTemplateNodeTool::createVariableElement($variableName, $name, $scope)); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, $data, false, array(), 'blockData'); // This block checks whether the append-block variable is an array or not. // TODO: This is a temporary solution and should also check whether the template variable exists. // This new solution requires probably writing the createVariableElement and createVariableNode your self. $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( is_null ( \$blockData ) ) \$blockData = array();"); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( is_array ( \$blockData ) ) \$blockData[] = \$blockText;"); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("else eZDebug::writeError( \"Variable '{$variableName}' is already in use.\" );"); $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'blockData', false, array(), array($name, $scope, $variableName), false, true, true); $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode('blockData'); } else { $newNodes[] = eZTemplateNodeTool::createVariableNode(false, 'blockText', false, array(), array($name, $scope, $variableName), false, true, true); } $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode('blockText'); $newNodes[] = eZTemplateNodeTool::createOutputVariableDecreaseNode(); return $newNodes; } else { if ($functionName == $this->OnceName) { $functionPlacement = eZTemplateNodeTool::extractFunctionNodePlacement($node); $key = $this->placementKey($functionPlacement); $newNodes = array(); if ($key !== false) { $keyText = eZPHPCreator::variableText($key, 0, 0, false); $placementText = eZPHPCreator::variableText($functionPlacement, 0, 0, false); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("if ( !isset( \$GLOBALS['eZTemplateRunOnceKeys'][{$keyText}] ) )\n" . "{\n" . " \$GLOBALS['eZTemplateRunOnceKeys'][{$keyText}] = {$placementText};"); $children = eZTemplateNodeTool::extractFunctionNodeChildren($node); $newNodes[] = eZTemplateNodeTool::createSpacingIncreaseNode(4); $newNodes = array_merge($newNodes, $children); $newNodes[] = eZTemplateNodeTool::createSpacingDecreaseNode(4); $newNodes[] = eZTemplateNodeTool::createCodePieceNode("}"); } return $newNodes; } } return false; }
function createOverrideCache() { if (isset($GLOBALS['eZSiteBasics'])) { if (isset($GLOBALS['eZSiteBasics']['no-cache-adviced']) and $GLOBALS['eZSiteBasics']['no-cache-adviced']) { return false; } } global $eZTemplateOverrideCacheNoPermission; if ($eZTemplateOverrideCacheNoPermission == "nocache") { return false; } $ini = eZINI::instance('site.ini'); $useOverrideCache = true; if ($ini->hasVariable('OverrideSettings', 'Cache')) { $useOverrideCache = $ini->variable('OverrideSettings', 'Cache') == 'enabled'; } $standardBase = eZTemplateDesignResource::designSetting('standard'); $siteBase = eZTemplateDesignResource::designSetting('site'); $overrideKeys = $this->overrideKeys(); $overrideKey = md5(implode(',', $overrideKeys) . $siteBase . $standardBase); $cacheDir = eZSys::cacheDirectory(); $overrideCacheFile = $cacheDir . '/override/override_' . $overrideKey . '.php'; // Build matching cache only of it does not already exists, // or override file has been updated if (!$useOverrideCache or !file_exists($overrideCacheFile)) { $matchFileArray = eZTemplateDesignResource::overrideArray($this->OverrideSiteAccess); // Generate PHP compiled cache file. $phpCache = new eZPHPCreator("{$cacheDir}/override", "override_{$overrideKey}.php"); $phpCode = "\$GLOBALS['eZOverrideTemplateCacheMap'] = array (\n"; $numMatchFiles = count($matchFileArray); $countMatchFiles = 0; // $phpCode .= "switch ( \$matchFile )\n{\n "; foreach (array_keys($matchFileArray) as $matchKey) { $countMatchFiles++; $phpCode .= '\'' . md5($matchKey) . '\' => '; if (isset($matchFileArray[$matchKey]['custom_match'])) { $baseDir = isset($matchFileArray[$matchKey]['base_dir']) ? $matchFileArray[$matchKey]['base_dir'] : ''; $defaultMatchFile = $baseDir . $matchKey; // Custom override matching // $phpCode .= " case \"$matchKey\":\n {\n"; $matchConditionArray = array(); foreach ($matchFileArray[$matchKey]['custom_match'] as $customMatch) { $matchCondition = ""; $condCount = 0; if (is_array($customMatch['conditions'])) { foreach (array_keys($customMatch['conditions']) as $conditionKey) { if ($condCount > 0) { $matchCondition .= " and "; } // Have a special substring match for subtree matching $matchCondition .= "( isset( \$matchKeys[\\'{$conditionKey}\\'] ) and "; if ($conditionKey == 'url_alias') { $matchCondition .= "( strpos( \$matchKeys[\\'url_alias\\'], \\'" . $customMatch['conditions']['url_alias'] . "\\' ) === 0 ) )"; } else { $matchCondition .= "( is_array( \$matchKeys[\\'{$conditionKey}\\'] ) ? " . "in_array( \\'" . $customMatch['conditions'][$conditionKey] . "\\', \$matchKeys[\\'{$conditionKey}\\'] ) : " . "\$matchKeys[\\'{$conditionKey}\\'] == \\'" . $customMatch['conditions'][$conditionKey] . "\\') )"; } $condCount++; } } // Only create custom match if conditions are defined if ($matchCondition != "") { // $phpCode .= " if ( $matchCondition )\n {\n"; // $phpCode .= " return '" . $customMatch['match_file'] . "';\n }\n"; if ($condCount > 1) { $matchConditionArray[] = array('condition' => '(' . $matchCondition . ')', 'matchFile' => $customMatch['match_file']); } else { $matchConditionArray[] = array('condition' => $matchCondition, 'matchFile' => $customMatch['match_file']); } } else { // No override conditions defined. Override default match file $defaultMatchFile = $customMatch['match_file']; } } $phpCode .= "array ( 'eval' => 1, 'code' => "; $phpCode .= "'"; foreach (array_keys($matchConditionArray) as $key) { $phpCode .= '(' . $matchConditionArray[$key]['condition'] . ' ? ' . "\\'" . $matchConditionArray[$key]['matchFile'] . "\\'" . ' : '; } $phpCode .= "\\'" . $defaultMatchFile . "\\'"; for ($condCount = 0; $condCount < count($matchConditionArray); $condCount++) { $phpCode .= ')'; } $phpCode .= "' )"; } else { $phpCode .= "'" . $matchFileArray[$matchKey]['base_dir'] . $matchKey . "'"; } if ($countMatchFiles < $numMatchFiles) { $phpCode .= ",\n"; } else { $phpCode .= ");\n"; } } $phpCache->addCodePiece($phpCode); if ($useOverrideCache and $phpCache->store()) { } else { if ($useOverrideCache) { eZDebug::writeError("Could not write template override cache file, check permissions in {$cacheDir}/override/.\nRunning eZ Publish without this cache will have a performance impact.", __METHOD__); } $eZTemplateOverrideCacheNoPermission = 'nocache'; $overrideCacheFile = false; } } return $overrideCacheFile; }
function storeCache($directory = false) { if (!file_exists($directory)) { eZDir::mkdir($directory, false, true); } $php = new eZPHPCreator($directory, 'package.php'); $php->addComment("Automatically created cache file for the package format\n" . "Do not modify this file"); $php->addSpace(); $php->addVariable('CacheCodeDate', eZPackage::CACHE_CODE_DATE); $php->addSpace(); $php->addVariable('Parameters', $this->Parameters, eZPHPCreator::VARIABLE_ASSIGNMENT, array('full-tree' => true)); $php->addVariable('InstallData', $this->InstallData, eZPHPCreator::VARIABLE_ASSIGNMENT, array('full-tree' => true)); $php->addVariable('RepositoryPath', $this->RepositoryPath); $php->store(); }
function mergeTrans($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { $code = ''; $stringCode = ''; $paramCount = 0; $values = array(); $staticArray = array(); for ($i = 1; $i < count($parameters); ++$i) { if ($i != 1) { $code .= ', '; $stringCode .= ', '; } if (!eZTemplateNodeTool::isStaticElement($parameters[$i])) { $values[] = $parameters[$i]; ++$paramCount; if ($operatorName == $this->MergeName or $operatorName == $this->ArrayMergeName) { $code .= '%' . $paramCount . '%'; } else { $code .= 'array( %' . $paramCount . '% )'; } $stringCode .= '%' . $paramCount . '%'; } else { if ($paramCount == 0) { $staticArray[] = eZTemplateNodeTool::elementStaticValue($parameters[$i]); } if ($operatorName == $this->MergeName or $operatorName == $this->ArrayMergeName) { $code .= '' . eZPHPCreator::variableText(eZTemplateNodeTool::elementStaticValue($parameters[$i]), 0, 0, false) . ''; } else { $tmp_check = eZPHPCreator::variableText(eZTemplateNodeTool::elementStaticValue($parameters[$i]), 0, 0, false); // hiding "%1%", "%output%" etc. in static input string to avoid replacing it on "$var" inside compiler. $tmp_check = str_replace("%", '"."%"."', $tmp_check); $code .= 'array( ' . $tmp_check . ' )'; } $stringCode .= eZPHPCreator::variableText(eZTemplateNodeTool::elementStaticValue($parameters[$i]), 0, 0, false); } } $isString = false; $isArray = false; $code2 = false; if ($parameters[0]) { if (!eZTemplateNodeTool::isStaticElement($parameters[0])) { $values[] = $parameters[0]; ++$paramCount; $code2 = '%' . $paramCount . '%'; } else { $isString = is_string(eZTemplateNodeTool::elementStaticValue($parameters[0])); $isArray = is_array(eZTemplateNodeTool::elementStaticValue($parameters[0])); if ($paramCount == 0) { // $staticArray[] = eZTemplateNodeTool::elementStaticValue( $parameters[0] ); } else { $code2 = eZPHPCreator::variableText(eZTemplateNodeTool::elementStaticValue($parameters[0]), 0, 0, false); } } } if ($paramCount == 0) { if ($operatorName == $this->AppendName or $operatorName == $this->ArrayAppendName or $operatorName == $this->MergeName or $operatorName == $this->ArrayMergeName) { if ($isString) { $str = eZTemplateNodeTool::elementStaticValue($parameters[0]); for ($i = 0; $i < count($staticArray); ++$i) { $str .= $staticArray[$i]; } return array(eZTemplateNodeTool::createStringElement($str)); } else { if ($isArray) { $returnArray = eZTemplateNodeTool::elementStaticValue($parameters[0]); for ($i = 0; $i < count($staticArray); ++$i) { $returnArray = array_merge($returnArray, $staticArray[$i]); } return array(eZTemplateNodeTool::createArrayElement($returnArray)); } } } else { if ($operatorName == $this->PrependName or $operatorName == $this->ArrayPrependName) { if ($isString) { return array(eZTemplateNodeTool::createStringElement(eZTemplateNodeTool::elementStaticValue($parameters[1]) . eZTemplateNodeTool::elementStaticValue($parameters[0]))); } else { if ($isArray) { return array(eZTemplateNodeTool::createArrayElement(array_merge($staticArray, eZTemplateNodeTool::elementStaticValue($parameters[0])))); } } } } } if ($code2) { if ($operatorName == $this->AppendName) { $code = 'if ( is_string( ' . $code2 . ' ) )' . "\n" . ' %output% = ' . $code2 . ' . implode( \'\', array( ' . $stringCode . ' ) );' . "\n" . 'else if( is_array( ' . $code2 . ' ) )' . "\n" . ' %output% = array_merge( ' . $code2 . ', ' . $code . ' );'; } else { if ($operatorName == $this->ArrayAppendName) { $code = '%output% = array_merge( ' . $code2 . ', ' . $code . ' );'; } else { if ($operatorName == $this->MergeName) { $code = '%output% = array_merge( ' . $code2 . ', ' . $code . ' );'; } else { if ($operatorName == $this->ArrayMergeName) { $code = '%output% = array_merge( ' . $code2 . ', ' . $code . ' );'; } else { if ($operatorName == $this->PrependName) { $code = 'if ( is_string( ' . $code2 . ' ) )' . "\n" . ' %output% = implode( \'\', array( ' . $stringCode . ' ) ) . ' . $code2 . ';' . "\n" . 'else if( is_array( ' . $code2 . ' ) )' . "\n" . ' %output% = array_merge( ' . $code . ', ' . $code2 . ' );'; } else { if ($operatorName == $this->ArrayPrependName) { $code = '%output% = array_merge( ' . $code . ', ' . $code2 . ' );'; } } } } } } } else { if ($operatorName == $this->MergeName) { $code = '%output% = array_merge( ' . $code . ' );'; } else { $code = '%output% = array(' . $code . ');'; } } return array(eZTemplateNodeTool::createCodePieceElement($code . "\n", $values)); }
/** * Register extensions "the YMC way". * * * @return void * @access public * @author ymc-dabe * @see eZExtension::activateExtensions() * @link http://issues.ez.no/IssueView.php?Id=2709 */ public function registerExtensions($virtual_siteaccess = false) { if (!$this->attribute('is_enabled')) { eZDebug::writeError("The ymcExtensionLoader is disabled, but " . __METHOD__ . " has just been called (which really shouldn't be done)!", __METHOD__); } $siteaccess = self::getCurrentSiteaccess(); $isBasicLoad = true; $is_virtual_load = false; $cache_hit = false; $defaultActiveExtensions = self::$alwaysEnabledExtensions; if (!in_array('ymcextensionloader', $defaultActiveExtensions)) { $defaultActiveExtensions[] = 'ymcextensionloader'; } if ($this->standardLoadingCompleted === true and $virtual_siteaccess !== false and $siteaccess !== $virtual_siteaccess) { if ($this->virtualLoadingCompleted === true) { eZDebug::writeError("Unnecessary call to 'ymcExtensionLoader::registerExtensions('.{$virtual_siteaccess}.')'!", __METHOD__); return; } $siteaccess = $virtual_siteaccess; self::setInternalSiteaccess($siteaccess); eZDebug::accumulatorStart('OpenVolanoExtensionLoader_VirtualSiteaccess', 'OpenVolano: Enhanced Extension Loader', "After virtual siteaccess '{$siteaccess}' initialised "); $isBasicLoad = false; $is_virtual_load = true; $this->rebuildIniOverrideArray($siteaccess, $isBasicLoad); } else { if (null !== $siteaccess) { if ($this->standardLoadingCompleted === true) { eZDebug::writeError("Unnecessary call to " . __METHOD__ . "!", __METHOD__); return; } $isBasicLoad = false; eZDebug::accumulatorStart('OpenVolanoExtensionLoader_Siteaccess', 'OpenVolano: Enhanced Extension Loader', "After siteaccess '{$siteaccess}' initialised "); } else { if (self::$earlyLoadingCompleted === true) { eZDebug::writeWarning("Force registering additional extensions - please keep in mind, that it is not possible to unload extensions", __METHOD__); } eZDebug::accumulatorStart('OpenVolanoExtensionLoader_Basic', 'OpenVolano: Enhanced Extension Loader', 'Pre siteaccess initialised'); } } $ini = eZINI::instance(); $allExtensionsRegistered = false; if ($isBasicLoad) { self::$globalCacheDirectory = eZSys::cacheDirectory(); $cacheFileName = 'basic'; $cache_var_name = 'ymcExtensionLoaderRegisterExtensionBasicLoadInformation'; } else { if ($is_virtual_load) { $cacheFileName = 'siteaccess-' . $this->attribute('non_virtual_siteaccess') . '-virtualsiteaccess-' . $siteaccess; $cache_var_name = 'ymcExtensionLoaderRegisterExtensionVirtualSiteaccessLoadInformation'; } else { $cacheFileName = 'siteaccess-' . $siteaccess; $cache_var_name = 'ymcExtensionLoaderRegisterExtensionSiteaccessLoadInformation'; } } $write_cache = false; $can_write_cache = true; $cacheDir = eZSys::cacheDirectory() . '/openvolano/extensions'; if (!is_writable($cacheDir)) { if (!eZDir::mkdir($cacheDir, 0777, true)) { $can_write_cache = false; eZDebug::writeError("Couldn't create cache directory '{$cacheDir}', perhaps wrong permissions", __METHOD__); } } $cacheFilePath = $cacheDir . '/' . $cacheFileName; if (!file_exists($cacheFilePath)) { $write_cache = $can_write_cache; if ($isBasicLoad) { eZDebug::writeNotice("No cache found for loading basic set of extensions", __METHOD__); } else { eZDebug::writeNotice("No cache found for loading per siteaccess set of extensions for siteaccess '{$siteaccess}'", __METHOD__); } } else { include $cacheFilePath; if (!isset(${$cache_var_name})) { eZDebug::writeWarning("Cache '{$cache_var_name}' in file '{$cacheFilePath}' not found. Trying to force rewrite of this cache file...", __METHOD__); $write_cache = $can_write_cache; } else { eZDebug::writeNotice("Cache hit: {$cacheFilePath}", __METHOD__); $defaultActiveExtensions = ${$cache_var_name}; $cache_hit = true; unset($cache_var_name); } } $additional_lookups = 0; //Loop registering of extensions until all are loaded while (!$allExtensionsRegistered) { //First we asume we do not need to check for new extensions $allExtensionsRegistered = true; //these extensions are always active $activeExtensions = $defaultActiveExtensions; //Get all active extension $activeExtensions = array_unique(array_merge($activeExtensions, eZExtension::activeExtensions())); foreach ($activeExtensions as $activeExtension) { //only activate an extension if it has not been registered, yet if (!in_array($activeExtension, $this->registeredExtensions)) { $this->registeredExtensions[] = $activeExtension; $fullExtensionPath = eZExtension::baseDirectory() . '/' . $activeExtension; if (!file_exists($fullExtensionPath)) { eZDebug::writeWarning("Extension '{$activeExtension}' does not exist, looked for directory '{$fullExtensionPath}'", __METHOD__); } else { $fullExtensionAutoloadPath = $fullExtensionPath . '/autoload'; if ($activeExtension !== 'ymcextensionloader' and !in_array($activeExtension, self::$noAutoloadExtensions) and file_exists($fullExtensionAutoloadPath)) { //add the new extension's autoload-dir to the eZ compontents autoload system (if needed) ezcBase::addClassRepository($fullExtensionPath, $fullExtensionAutoloadPath); } //We are about to activate a new extension which might need to load one ore more other extension (if we do not have a cached info about this) $allExtensionsRegistered = $cache_hit; } } } $this->rebuildIniOverrideArray($siteaccess, $isBasicLoad); if (!$allExtensionsRegistered) { $additional_lookups++; } } if (!$cache_hit) { if ($isBasicLoad) { eZDebug::writeNotice("Loaded all basic extensions in {$additional_lookups} additional lookups...", __METHOD__); } else { if ($is_virtual_load) { eZDebug::writeNotice("Loaded all virtual siteaccess extensions in {$additional_lookups} additional lookups...", __METHOD__); } else { eZDebug::writeNotice("Loaded all siteaccess extensions in {$additional_lookups} additional lookups...", __METHOD__); } } } if ($write_cache) { if ($isBasicLoad) { eZDebug::writeNotice("Storing basic extension load information into cache file '{$cacheFilePath}'...", __METHOD__); } else { if ($is_virtual_load) { eZDebug::writeNotice("Storing virtual siteaccess extension load information into cache file '{$cacheFilePath}'...", __METHOD__); } else { eZDebug::writeNotice("Storing siteaccess extension load information into cache file '{$cacheFilePath}'...", __METHOD__); } } $php = new eZPHPCreator($cacheDir, $cacheFileName); $php->addRawVariable($cache_var_name, $this->registeredExtensions); $php->store(); } if ($is_virtual_load) { $this->virtualLoadingCompleted = true; eZDebug::accumulatorStop('OpenVolanoExtensionLoader_VirtualSiteaccess'); } else { if (!$isBasicLoad) { $this->standardLoadingCompleted = true; $this->non_virtual_siteaccess_name = $siteaccess; eZDebug::accumulatorStop('OpenVolanoExtensionLoader_Siteaccess'); } else { self::$earlyLoadingCompleted = true; eZDebug::accumulatorStop('OpenVolanoExtensionLoader_Basic'); } } //Use the following line to take a look into the ini-hierarchy... //ymc_pr($GLOBALS["eZINIOverrideDirList"], $siteaccess.'|'.self::getCurrentSiteaccess()); if (!$is_virtual_load and !$isBasicLoad and $ini->hasVariable('SiteAccessSettings', 'VirtualSiteaccessSystem') and $ini->variable('SiteAccessSettings', 'VirtualSiteaccessSystem') !== 'disabled') { $allowLoadingOfPreviouslyKnownSiteaccesses = false; if ($ini->hasVariable('SiteAccessSettings', 'VirtualSiteaccessSystem') and $ini->variable('VirtualSiteaccessSettings', 'AllowLoadingOfPerviouslyKnowSiteaccesses') === 'enabled') { $allowLoadingOfPreviouslyKnownSiteaccesses = true; } if (isset($GLOBALS['eZURIRequestInstance']) and is_object($GLOBALS['eZURIRequestInstance'])) { $uri = eZURI::instance(); $elements = $uri->elements(false); if (count($elements) > 0 and $elements[0] != '') { $goInVirtualSiteaccessMode = true; if ($ini->hasVariable('VirtualSiteaccessSettings', 'SkipLoadingForUri') and is_array($ini->variable('VirtualSiteaccessSettings', 'SkipLoadingForUri')) and count($ini->variable('VirtualSiteaccessSettings', 'SkipLoadingForUri')) > 0) { $uri_string = $uri->elements(true); foreach ($ini->variable('VirtualSiteaccessSettings', 'SkipLoadingForUri') as $ignoreUriForVirtualSiteaccess) { if (strpos($uri_string, $ignoreUriForVirtualSiteaccess) === 0) { $goInVirtualSiteaccessMode = false; break; } } unset($uri_string); } } else { $goInVirtualSiteaccessMode = false; } if ($goInVirtualSiteaccessMode) { $matchIndex = 1; $name = $elements[0]; //by ymc-dabe //Code taken from /access.php line 241-249 of eZ publish v4.1.3 //KEEP IT IN SYNC! //start $name = preg_replace(array('/[^a-zA-Z0-9]+/', '/_+/', '/^_/', '/_$/'), array('_', '_', '', ''), $name); //by ymc-dabe //Code taken from /access.php line 241-249 of eZ publush v4.1.3 //KEEP IT IN SYNC! //end if ($allowLoadingOfPreviouslyKnownSiteaccesses or !in_array($name, $ini->variable('SiteAccessSettings', 'AvailableSiteAccessList'))) { eZSys::addAccessPath($name); $uri->increase($matchIndex); $uri->dropBase(); $this->registerExtensions($name); //die if virtual siteaccess is not found if (!in_array($name, $ini->variable('SiteAccessSettings', 'AvailableSiteAccessList'))) { header($_SERVER['SERVER_PROTOCOL'] . " 400 Bad Request"); header("Status: 400 Bad Request"); eZExecution::cleanExit(); } } unset($name); } } else { if (isset($GLOBALS['ymcEnhancedExtensionLoaderVirtualSiteaccess']) and $GLOBALS['ymcEnhancedExtensionLoaderVirtualSiteaccess'] != '') { $virtualSiteaccessName = $GLOBALS['ymcEnhancedExtensionLoaderVirtualSiteaccess']; if ($allowLoadingOfPreviouslyKnownSiteaccesses or !in_array($virtualSiteaccessName, $ini->variable('SiteAccessSettings', 'AvailableSiteAccessList'))) { eZSys::addAccessPath($virtualSiteaccessName); $this->registerExtensions($virtualSiteaccessName); if (!in_array($virtualSiteaccessName, $ini->variable('SiteAccessSettings', 'AvailableSiteAccessList'))) { fputs(STDERR, "\n----------\nError: Invalid siteaccess '{$virtualSiteaccessName}'!\n----------\n\n"); eZExecution::cleanExit(); } } unset($virtualSiteaccessName); } } } else { if ($this->standardLoadingCompleted === true) { $this->virtualLoadingCompleted = true; } } if ($this->standardLoadingCompleted === true) { $this->loadingCompleted = true; if ($this->originalNonVirtualSiteaccessName === false) { $this->originalNonVirtualSiteaccessName = $this->attribute('non_virtual_siteaccess'); if ($this->originalVirtualSiteaccessName === false and $siteaccess != $this->attribute('non_virtual_siteaccess')) { $this->originalVirtualSiteaccessName = $siteaccess; } } } }