Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztemplateincludefunction.php
Go to the documentation of this file.
1 <?php
32 class eZTemplateIncludeFunction
33 {
39 public function __construct( $inc_name = "include" )
40 {
41 $this->IncludeName = $inc_name;
42 }
43
47 function functionList()
48 {
49 return array( $this->IncludeName );
50 }
51
52 function functionTemplateHints()
53 {
54 return array( $this->IncludeName => array( 'parameters' => true,
55 'static' => false,
56 'transform-children' => true,
57 'tree-transformation' => true,
58 'transform-parameters' => true ) );
59 }
60
61 function templateNodeTransformation( $functionName, &$node,
62 $tpl, $parameters, $privateData )
63 {
64 if ( $functionName != $this->IncludeName )
65 return false;
66 $parameters = eZTemplateNodeTool::extractFunctionNodeParameters( $node );
67 if ( !isset( $parameters['uri'] ) )
68 return false;
69
70 $uriData = $parameters['uri'];
71 if ( !eZTemplateNodeTool::isConstantElement( $uriData ) )
72 return false;
73
74 $namespaceValue = false;
75 $namespaceName = '$currentNamespace';
76 if ( isset( $parameters['name'] ) )
77 {
78 $nameData = $parameters['name'];
79 if ( !eZTemplateNodeTool::isConstantElement( $nameData ) )
80 return false;
81 $namespaceValue = eZTemplateNodeTool::elementConstantValue( $nameData );
82 $namespaceName = '$namespace';
83 }
84
85 $uriString = eZTemplateNodeTool::elementConstantValue( $uriData );
86
87 $resourceName = "";
88 $templateName = "";
89 $resource = $tpl->resourceFor( $uriString, $resourceName, $templateName );
90 $resourceData = $tpl->resourceData( $resource, $uriString, $resourceName, $templateName );
91 $resourceData['use-comments'] = eZTemplateCompiler::isCommentsEnabled();
92
93 $includeNodes = $resource->templateNodeTransformation( $functionName, $node, $tpl, $resourceData, $parameters, $namespaceValue );
94 if ( $includeNodes === false )
95 return false;
96
97 $newNodes = array();
98
99 $variableList = array();
100 $uniqID = md5( uniqid('inc') );
101 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$oldRestoreIncludeArray" . "_$uniqID = isset( \$restoreIncludeArray ) ? \$restoreIncludeArray : array();\n".
102 "\$restoreIncludeArray = array();\n");
103 foreach ( array_keys( $parameters ) as $parameterName )
104 {
105 if ( $parameterName == 'uri' or
106 $parameterName == 'name' )
107 continue;
108 $parameterData =& $parameters[$parameterName];
109 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if ( isset( $namespaceName ) and isset( \$vars[$namespaceName]['$parameterName'] ) )\n".
110 " \$restoreIncludeArray[] = array( $namespaceName, '$parameterName', \$vars[$namespaceName]['$parameterName'] );\n".
111 "elseif ( !isset( \$vars[( isset( $namespaceName ) ? $namespaceName : '' )]['$parameterName'] ) ) \n".
112 " \$restoreIncludeArray[] = array( ( isset( $namespaceName ) ? $namespaceName : '' ), '$parameterName', 'unset' );\n" );
113
114 $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $parameterData, false, array(),
115 array( $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $parameterName ) );
116 $variableList[] = $parameterName;
117 }
118
119 $newNodes = array_merge( $newNodes, $includeNodes );
120 // Restore previous variables, before including
121 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "foreach ( \$restoreIncludeArray as \$element )\n".
122 "{\n".
123 " if ( \$element[2] === 'unset' )\n".
124 " {\n".
125 " unset( \$vars[\$element[0]][\$element[1]] );\n".
126 " continue;\n".
127 " }\n".
128 " \$vars[\$element[0]][\$element[1]] = \$element[2];\n".
129 "}\n".
130 "\$restoreIncludeArray = \$oldRestoreIncludeArray" . "_$uniqID;\n" );
131
132 return $newNodes;
133 }
134
138 function process( $tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace )
139 {
140 $params = $functionParameters;
141 if ( !isset( $params["uri"] ) )
142 {
143 $tpl->missingParameter( $this->IncludeName, "uri" );
144 return false;
145 }
146 $uri = $tpl->elementValue( $params["uri"], $rootNamespace, $currentNamespace, $functionPlacement );
147 $name = "";
148 if ( isset( $params["name"] ) )
149 $name = $tpl->elementValue( $params["name"], $rootNamespace, $currentNamespace, $functionPlacement );
150 if ( $currentNamespace != "" )
151 {
152 if ( $name != "" )
153 $name = "$currentNamespace:$name";
154 else
155 $name = $currentNamespace;
156 }
157 reset( $params );
158 $whatParamsShouldBeUnset = array();
159 $whatParamsShouldBeReplaced = array();
160 while ( ( $key = key( $params ) ) !== null )
161 {
162 $item =& $params[$key];
163 switch ( $key )
164 {
165 case "name":
166 case "uri":
167 break;
168
169 default:
170 {
171 if ( !$tpl->hasVariable( $key, $name ) )
172 {
173 $whatParamsShouldBeUnset[] = $key; // Tpl vars should be removed after including
174 }
175 else
176 {
177 $whatParamsShouldBeReplaced[$key] = $tpl->variable( $key, $name ); // Tpl vars should be replaced after including
178 }
179
180 $item_value = $tpl->elementValue( $item, $rootNamespace, $currentNamespace, $functionPlacement );
181 $tpl->setVariable( $key, $item_value, $name );
182 } break;
183 }
184 next( $params );
185 }
186 eZTemplateIncludeFunction::handleInclude( $textElements, $uri, $tpl, $rootNamespace, $name );
187 // unset var
188 foreach ( $whatParamsShouldBeUnset as $key )
189 {
190 $tpl->unsetVariable( $key, $name );
191 }
192 // replace var
193 foreach ( $whatParamsShouldBeReplaced as $key => $item_value )
194 {
195 $tpl->setVariable( $key, $item_value, $name );
196 }
197 }
198
203 static function handleInclude( &$textElements, &$uri, $tpl, $rootNamespace, $name )
204 {
205 $tpl->processURI( $uri, true, $extraParameters, $textElements, $name, $name );
206 }
207
211 function hasChildren()
212 {
213 return false;
214 }
215
218 public $IncludeName;
219 }
220
221 ?>
eZTemplateCompiler\isCommentsEnabled
static isCommentsEnabled()
Definition: eztemplatecompiler.php:124
eZTemplateIncludeFunction
Includes external template code using function "include".
Definition: eztemplateincludefunction.php:33
eZTemplateIncludeFunction\$IncludeName
$IncludeName
Definition: eztemplateincludefunction.php:218
eZTemplateIncludeFunction\__construct
__construct( $inc_name="include")
Definition: eztemplateincludefunction.php:39
eZTemplateIncludeFunction\process
process( $tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace)
Definition: eztemplateincludefunction.php:138
eZTemplateIncludeFunction\functionList
functionList()
Definition: eztemplateincludefunction.php:47
eZTemplateIncludeFunction\functionTemplateHints
functionTemplateHints()
Definition: eztemplateincludefunction.php:52
eZTemplateIncludeFunction\handleInclude
static handleInclude(&$textElements, &$uri, $tpl, $rootNamespace, $name)
Definition: eztemplateincludefunction.php:203
eZTemplateIncludeFunction\hasChildren
hasChildren()
Definition: eztemplateincludefunction.php:211
eZTemplateIncludeFunction\templateNodeTransformation
templateNodeTransformation( $functionName, &$node, $tpl, $parameters, $privateData)
Definition: eztemplateincludefunction.php:61
eZTemplateNodeTool\createVariableNode
static createVariableNode( $originalNode=false, $variableData=false, $variablePlacement=false, $parameters=array(), $variableAssignmentName=false, $onlyExisting=false, $overWrite=true, $assignFromVariable=false, $rememberSet=false)
Definition: eztemplatenodetool.php:395
eZTemplateNodeTool\elementConstantValue
static elementConstantValue( $elements)
Definition: eztemplatenodetool.php:197
eZTemplateNodeTool\createCodePieceNode
static createCodePieceNode( $codePiece, $parameters=array())
Definition: eztemplatenodetool.php:457
eZTemplateNodeTool\extractFunctionNodeParameters
static extractFunctionNodeParameters(&$node)
Definition: eztemplatenodetool.php:678
eZTemplateNodeTool\isConstantElement
static isConstantElement( $elements)
Definition: eztemplatenodetool.php:233
eZTemplate\NAMESPACE_SCOPE_RELATIVE
const NAMESPACE_SCOPE_RELATIVE
Definition: eztemplate.php:286
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.