function fetchOverrideTemplateList($classID) { $class = eZContentClass::fetch($classID); $classIdentifier = $class->attribute('identifier'); $result = array(); $ini = eZINI::instance(); $siteAccessArray = $ini->variable('SiteAccessSettings', 'AvailableSiteAccessList'); foreach ($siteAccessArray as $siteAccess) { $overrides = eZTemplateDesignResource::overrideArray($siteAccess); foreach ($overrides as $override) { if (isset($override['custom_match'])) { foreach ($override['custom_match'] as $customMatch) { if (isset($customMatch['conditions']['class_identifier']) && $customMatch['conditions']['class_identifier'] == $classIdentifier) { $result[] = array('siteaccess' => $siteAccess, 'block' => $customMatch['override_name'], 'source' => $override['template'], 'target' => $customMatch['match_file']); } if (isset($customMatch['conditions']['class']) && $customMatch['conditions']['class'] == $classID) { $result[] = array('siteaccess' => $siteAccess, 'block' => $customMatch['override_name'], 'source' => $override['template'], 'target' => $customMatch['match_file']); } } } } } return array('result' => $result); }
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 templateNodeTransformation( $functionName, &$node, $tpl, $parameters, $privateData ) { if ( !isset( $this->Rules[$functionName] ) ) return false; $rule = $this->Rules[$functionName]; $resourceData = $privateData['resource-data']; $parameters = eZTemplateNodeTool::extractFunctionNodeParameters( $node ); $inputName = $rule['input_name']; if ( !isset( $parameters[$inputName] ) ) { return false; } $inputData = $parameters[$inputName]; $outputName = $rule['output_name']; $newNodes = array(); $viewDir = ''; $renderMode = false; if ( isset( $rule["render_mode"] ) ) { $renderMode = $rule["render_mode"]; } if ( isset( $parameters['render-mode'] ) ) { $renderData = $parameters['render-mode']; if ( !eZTemplateNodeTool::isConstantElement( $renderData ) ) { return false; } $renderMode = eZTemplateNodeTool::elementConstantValue( $renderData ); } if ( $renderMode ) $view_dir .= "/render-$renderMode"; $viewValue = false; $viewName = false; if ( $rule['use_views'] ) { $viewName = $rule['use_views']; if ( isset( $parameters[$viewName] ) ) { $viewData = $parameters[$viewName]; if ( !eZTemplateNodeTool::isConstantElement( $viewData ) ) { return false; } $viewValue = eZTemplateNodeTool::elementConstantValue( $viewData ); $viewDir .= '/' . $viewValue; } else { if ( !( isset( $rule['optional_views'] ) && $rule['optional_views'] ) ) { return false; } } } $namespaceValue = false; if ( isset( $rule['namespace'] ) ) { $namespaceValue = $rule['namespace']; } $variableList = array(); $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $inputData, false, array(), array( $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $outputName ) ); $variableList[] = $outputName; foreach ( array_keys( $parameters ) as $parameterName ) { if ( $parameterName == $inputName or $parameterName == $outputName or $parameterName == $viewName ) continue; $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $parameters[$parameterName], false, array(), array( $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $parameterName ) ); $variableList[] = $parameterName; } $templateRoot = $rule["template_root"]; $matchFileArray = eZTemplateDesignResource::overrideArray(); if ( is_string( $templateRoot ) ) { $resourceNodes = $this->resourceAcquisitionTransformation( $functionName, $node, $rule, $inputData, $outputName, $namespaceValue, $templateRoot, $viewDir, $viewValue, $matchFileArray, 0, $resourceData ); // If the transformation failed we return false to invoke interpreted mode if ( $resourceNodes === false ) return false; $newNodes = array_merge( $newNodes, $resourceNodes ); } else { if ( isset( $templateRoot['type'] ) and $templateRoot['type'] == 'multi_match' and isset( $templateRoot['attributes'] ) and isset( $templateRoot['matches'] ) ) { $attributeAccessData = array(); $attributeAccessData[] = eZTemplateNodeTool::createVariableElement( $outputName, $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE ); foreach ( $templateRoot['attributes'] as $rootAttributeName ) { $attributeAccessData[] = eZTemplateNodeTool::createAttributeLookupElement( $rootAttributeName ); } $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $attributeAccessData, false, array( 'spacing' => 0 ), 'templateRootMatch' ); $rootMatchCounter = 0; foreach ( $templateRoot['matches'] as $rootMatch ) { $templateRoot = $rootMatch[1]; if ( is_array( $templateRoot ) ) { $templateRoot = $templateRoot[0]; } $resourceNodes = $this->resourceAcquisitionTransformation( $functionName, $node, $rule, $inputData, $outputName, $namespaceValue, $templateRoot, $viewDir, $viewValue, $matchFileArray, 4, $resourceData ); // If this transformation failed we continue to the next root match if ( $resourceNodes === false ) continue; $rootMatchValueText = eZPHPCreator::variableText( $rootMatch[0], 0, 0, false ); $code = ''; if ( $rootMatchCounter > 0 ) { $code .= "else " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . ""; } $code .= "if " . ( $resourceData['use-comments'] ? ( "/*OF:" . __LINE__ . "*/" ) : "" ) . "( \$templateRootMatch == $rootMatchValueText )\n{"; $newNodes[] = eZTemplateNodeTool::createCodePieceNode( $code ); $newNodes = array_merge( $newNodes, $resourceNodes ); $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "}" ); ++$rootMatchCounter; } // If the transformation failed we invoke interpreted mode if ( $rootMatchCounter == 0 ) { return false; } $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode( 'templateRootMatch' ); } } foreach ( $variableList as $variableName ) { $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode( array( $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $variableName ) ); } return $newNodes; }
function &generateTemplateFilenameArray() { $dom = new DOMDocument( '1.0', 'utf-8' ); $templateListDOMNode = $dom->createElement( 'template-list' ); $dom->appendChild( $templateListDOMNode ); foreach( array_keys( $this->OverrideSettingsArray ) as $siteAccess ) { $this->TemplateFileArray[$siteAccess] = array(); $overrideArray = eZTemplateDesignResource::overrideArray( $siteAccess ); foreach( $this->OverrideSettingsArray[$siteAccess] as $override ) { $customMatchArray = $overrideArray['/' . $override['Source']]['custom_match']; foreach( $customMatchArray as $customMatch ) { if ( $customMatch['conditions'] == null ) { //$templateListDOMNode->appendChild( $this->createDOMNodeFromFile( $customMatch['match_file'], $siteAccess, 'design' ) ); //$this->TemplateFileArray[$siteAccess][] = $customMatch['match_file']; } else if ( count( array_diff( $customMatch['conditions'], $override['Match'] ) ) == 0 && count( array_diff( $override['Match'], $customMatch['conditions'] ) ) == 0 ) { unset( $node ); $node = $this->createDOMNodeFromFile( $customMatch['match_file'], $siteAccess, 'design' ); $importedNode = $dom->importNode( $node, true ); $templateListDOMNode->appendChild( $importedNode ); $this->TemplateFileArray[$siteAccess][] = $customMatch['match_file']; } } } } return $templateListDOMNode; //TODO : add templates included in templates here. }
$i = 0; foreach ( $parameters as $param ) { if ( $i > 0 ) $template .= "/"; $template .= "$param"; $i++; } $siteAccess = $Params['SiteAccess']; if( $siteAccess ) $http->setSessionVariable( 'eZTemplateAdminCurrentSiteAccess', $siteAccess ); else $siteAccess = $http->sessionVariable( 'eZTemplateAdminCurrentSiteAccess' ); $overrideArray = eZTemplateDesignResource::overrideArray( $siteAccess ); // Check if template already exists $isExistingTemplate = false; foreach ( $overrideArray as $overrideSetting ) { if ( $overrideSetting['base_dir'] . $overrideSetting['template'] == $template ) { $isExistingTemplate = true; break; } elseif ( isset( $overrideSetting['custom_match'] ) ) { foreach ( $overrideSetting['custom_match'] as $customMatch ) { if ( $customMatch['match_file'] == $template )
function generateDefaultTemplate( $http, $template, $fileName ) { $templateCode = ""; // Check what kind of contents we should create in the template switch ( $http->postVariable( 'TemplateContent' ) ) { case 'DefaultCopy' : { $siteAccess = $http->sessionVariable( 'eZTemplateAdminCurrentSiteAccess' ); $overrideArray = eZTemplateDesignResource::overrideArray( $siteAccess ); $fileName = $overrideArray[$template]['base_dir'] . $overrideArray[$template]['template']; $fp = fopen( $fileName, 'rb' ); if ( $fp ) { $codeFromFile = fread( $fp, filesize( $fileName ) ); // Remove the "{* DO NOT EDIT... *}" first line (if exists). $templateCode = preg_replace('@^{\*\s*DO\sNOT\sEDIT.*?\*}\n(.*)@s', '$1', $codeFromFile); } else { eZDebug::writeError( "Could not open file $fileName, check read permissions" ); } fclose( $fp ); }break; default: case 'EmptyFile' : { $templateCode = '{*?template charset=latin1?*}' . '<!DOCTYPE html>' . "\n" . '<html lang="en">' . '<head>' . "\n" . ' <link rel="stylesheet" type="text/css" href={"stylesheets/core.css"|ezdesign} />' . "\n" . ' <link rel="stylesheet" type="text/css" href={"stylesheets/debug.css"|ezdesign} />' . "\n" . ' {include uri="design:page_head.tpl"}' . "\n" . '</head>' . "\n" . '<body>' . "\n" . '{$module_result.content}' . "\n" . '<!--DEBUG_REPORT-->' . "\n" . '</body>' . "\n" . '</html>' . "\n"; }break; } return $templateCode; }