Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztemplatetoolbarfunction.php
Go to the documentation of this file.
1 <?php
17 class eZTemplateToolbarFunction
18 {
24 public function __construct( $blockName = 'tool_bar' )
25 {
26 $this->BlockName = $blockName;
27 }
28
33 function functionList()
34 {
35 return array( $this->BlockName );
36 }
37
38 function functionTemplateHints()
39 {
40 return array( $this->BlockName => array( 'parameters' => true,
41 'static' => false,
42 'transform-children' => false,
43 'tree-transformation' => true,
44 'transform-parameters' => true ) );
45 }
46
47 function templateNodeTransformation( $functionName, &$node,
48 $tpl, $parameters, $privateData )
49 {
50 if ( $functionName != $this->BlockName )
51 return false;
52
53 $parameters = eZTemplateNodeTool::extractFunctionNodeParameters( $node );
54
55 if ( !isset( $parameters['name'] ) )
56 return false;
57
58 // Read ini file
59 $toolbarIni = eZINI::instance( "toolbar.ini" );
60
61 if ( isset( $parameters["view"] ) )
62 {
63 $viewData = $parameters["view"];
64 $viewMode = eZTemplateNodeTool::elementConstantValue( $viewData );
65 }
66 else
67 {
68 $viewMode = "full";
69 }
70
71 $params = $parameters;
72 $namespaceValue = false;
73 if ( isset( $parameters["name"] ) )
74 {
75 $nameData = $parameters["name"];
76 if ( !eZTemplateNodeTool::isConstantElement( $nameData ) )
77 return false;
78
79 $nameValue = eZTemplateNodeTool::elementConstantValue( $nameData );
80
81 $toolbarPosition = $nameValue;
82 $toolbarName = "Toolbar_" . $toolbarPosition;
83 $toolArray = $toolbarIni->variable( $toolbarName, 'Tool' );
84 if ( !is_array( $toolArray ) )
85 $toolArray = array();
86
87 $newNodes = array();
88 foreach ( array_keys( $toolArray ) as $toolKey )
89 {
90 $tool = $toolArray[$toolKey];
91 $placement = $toolKey + 1;
92
93 $uriString = "design:toolbar/$viewMode/$tool.tpl";
94
95 $placementValue = "";
96 $firstValue = false;
97 $lastValue = false;
98 if ( $placement == 1 )
99 {
100 if ( $placement == count( $toolArray ) )
101 {
102 $firstValue = true;
103 $lastValue = true;
104 $placementValue = "last";
105 }
106 else
107 {
108 $firstValue = true;
109 $placementValue = "first";
110 }
111 }
112 else if ( $placement == count( $toolArray ) )
113 {
114 $lastValue = true;
115 $placementValue = "last";
116 }
117
118 $resourceName = "";
119 $templateName = "";
120 $resource = $tpl->resourceFor( $uriString, $resourceName, $templateName );
121 $resourceData = $tpl->resourceData( $resource, $uriString, $resourceName, $templateName );
122 $resourceData['use-comments'] = eZTemplateCompiler::isCommentsEnabled();
123
124 $includeNodes = $resource->templateNodeTransformation( $functionName, $node, $tpl, $resourceData, $parameters, $namespaceValue );
125 if ( $includeNodes === false )
126 return false;
127
128 $uniqID = md5( uniqid('inc') );
129 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$oldRestoreIncludeArray" . "_$uniqID = isset( \$restoreIncludeArray ) ? \$restoreIncludeArray : array();\n".
130 "\$restoreIncludeArray = array();\n");
131 $variableList = array();
132 foreach ( array_keys( $parameters ) as $parameterName )
133 {
134 if ( $parameterName == 'name' or
135 $parameterName == 'view' )
136 continue;
137 $parameterData =& $parameters[$parameterName];
138 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if ( isset( \$vars['']['$parameterName'] ) )\n".
139 " \$restoreIncludeArray[] = array( '', '$parameterName', \$vars['']['$parameterName'] );\n".
140 "elseif ( !isset( \$vars['']['$parameterName'] ) ) \n".
141 " \$restoreIncludeArray[] = array( '', '$parameterName', 'unset' );\n" );
142
143 $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $parameterData, false, array(),
144 array( $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $parameterName ) );
145 $variableList[] = $parameterName;
146 }
147
148 $actionParameters = array();
149 if ( $toolbarIni->hasGroup( "Tool_" . $tool ) )
150 {
151 $actionParameters = $toolbarIni->group( "Tool_" . $tool );
152 }
153 if ( $toolbarIni->hasGroup( "Tool_" . $toolbarPosition . "_" . $tool . "_" . $placement ) )
154 {
155 $actionParameters = array_merge( $actionParameters, $toolbarIni->group( "Tool_" . $toolbarPosition . "_" . $tool . "_" . $placement ) );
156 }
157 foreach ( array_keys( $actionParameters ) as $key )
158 {
159 $itemValue = $actionParameters[$key];
160 $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $itemValue, false, array(),
161 array( $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, $key ) );
162 $variableList[] = $key;
163 }
164
165 // Add parameter tool_id and offset
166 $toolIDValue = "Tool_" . $toolbarPosition . "_" . $tool . "_" . $placement;
167 $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $toolIDValue, false, array(),
168 array( $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, "tool_id" ) );
169 $variableList[] = "tool_id";
170
171 $toolOffset = $placement;
172 $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $toolOffset, false, array(),
173 array( $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, "offset" ) );
174 $variableList[] = "offset";
175
176 // Add parameter first, last and placement
177 $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $firstValue, false, array(),
178 array( $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, "first" ) );
179 $variableList[] = "first";
180
181 $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $lastValue, false, array(),
182 array( $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, "last" ) );
183 $variableList[] = "last";
184
185 $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $placementValue, false, array(),
186 array( $namespaceValue, eZTemplate::NAMESPACE_SCOPE_RELATIVE, "placement" ) );
187 $variableList[] = "placement";
188
189 $newNodes = array_merge( $newNodes, $includeNodes );
190
191 // Restore previous variables, before including
192 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "foreach ( \$restoreIncludeArray as \$element )\n".
193 "{\n".
194 " if ( \$element[2] === 'unset' )\n".
195 " {\n".
196 " unset( \$vars[\$element[0]][\$element[1]] );\n".
197 " continue;\n".
198 " }\n".
199 " \$vars[\$element[0]][\$element[1]] = \$element[2];\n".
200 "}\n".
201 "\$restoreIncludeArray = \$oldRestoreIncludeArray" . "_$uniqID;\n" );
202 }
203 }
204 return $newNodes;
205 }
206
210 function process( $tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace )
211 {
212 $params = $functionParameters;
213 switch ( $functionName )
214 {
215 case $this->BlockName:
216 {
217 $viewMode = "full";
218 $name = $currentNamespace;
219 // Read ini file
220 $toolbarIni = eZINI::instance( "toolbar.ini" );
221
222 if ( isset( $functionParameters["view"] ) )
223 {
224 $viewMode = $tpl->elementValue( $functionParameters["view"], $rootNamespace, $currentNamespace, $functionPlacement );
225 }
226
227 if ( isset( $functionParameters["name"] ) )
228 {
229 reset( $params );
230 $whatParamsShouldBeUnset = array();
231 $whatParamsShouldBeReplaced = array();
232 while ( ( $key = key( $params ) ) !== null )
233 {
234 $item =& $params[$key];
235 switch ( $key )
236 {
237 case "name":
238 case "view":
239 break;
240
241 default:
242 {
243 if ( !$tpl->hasVariable( $key, $name ) )
244 {
245 $whatParamsShouldBeUnset[] = $key; // Tpl vars should be removed after including
246 }
247 else
248 {
249 $whatParamsShouldBeReplaced[$key] = $tpl->variable( $key, $name ); // Tpl vars should be replaced after including
250 }
251
252 $item_value = $tpl->elementValue( $item, $rootNamespace, $currentNamespace, $functionPlacement );
253 $tpl->setVariable( $key, $item_value, $name );
254 } break;
255 }
256 next( $params );
257 }
258 $toolbarPosition = $tpl->elementValue( $functionParameters["name"], $rootNamespace, $currentNamespace, $functionPlacement );
259 $definedVariables = array();
260 $toolbarName = "Toolbar_" . $toolbarPosition;
261 $toolArray = $toolbarIni->variable( $toolbarName, 'Tool' );
262
263 if ( !is_array( $toolArray ) )
264 $toolArray = array();
265
266 $actionParameters = array();
267 foreach ( array_keys( $toolArray ) as $toolKey )
268 {
269 $definedVariables = array();
270 $tool = $toolArray[$toolKey];
271 $placement = $toolKey + 1;
272 if ( $toolbarIni->hasGroup( "Tool_" . $tool ) )
273 {
274 $actionParameters = $toolbarIni->group( "Tool_" . $tool );
275 }
276 if ( $toolbarIni->hasGroup( "Tool_" . $toolbarPosition . "_" . $tool . "_" . $placement ) )
277 {
278 $actionParameters = array_merge( $actionParameters, $toolbarIni->group( "Tool_" . $toolbarPosition . "_" . $tool . "_" . $placement ) );
279 }
280 foreach ( array_keys( $actionParameters ) as $key )
281 {
282 $itemValue = $actionParameters[$key];
283 $tpl->setVariable( $key, $itemValue, $name );
284 $definedVariables[] = $key;
285 }
286 $toolIDValue = "Tool_" . $toolbarPosition . "_" . $tool . "_" . $placement;
287 $tpl->setVariable( "tool_id", $toolIDValue, $name );
288 $definedVariables[] = "tool_id";
289 $toolOffset = $placement;
290 $tpl->setVariable( "offset", $toolOffset, $name );
291 $definedVariables[] = "offset";
292 $uri = "design:toolbar/$viewMode/$tool.tpl";
293
294 if ( $placement == 1 )
295 {
296 if ( count( $toolArray ) == 1 )
297 {
298 $tpl->setVariable( "first", true );
299 $tpl->setVariable( "last", true );
300 $tpl->setVariable( "placement", "last" );
301 $definedVariables[] = "first";
302 $definedVariables[] = "last";
303 $definedVariables[] = "placement";
304 }
305 else
306 {
307 $tpl->setVariable( "first", true );
308 $tpl->setVariable( "last", false );
309 $tpl->setVariable( "placement", "first" );
310 $definedVariables[] = "first";
311 $definedVariables[] = "last";
312 $definedVariables[] = "placement";
313 }
314 }
315 else if ( $placement == count( $toolArray ) )
316 {
317 $tpl->setVariable( "first", false );
318 $tpl->setVariable( "last", true );
319 $tpl->setVariable( "placement", "last" );
320 $definedVariables[] = "first";
321 $definedVariables[] = "last";
322 $definedVariables[] = "placement";
323 }
324 else
325 {
326 $tpl->setVariable( "first", false );
327 $tpl->setVariable( "last", false );
328 $tpl->setVariable( "placement", "" );
329 $definedVariables[] = "placement";
330 }
331 $tpl->processURI( $uri, true, $extraParameters, $textElements, $name, $name );
332 // unset var
333 foreach ( $whatParamsShouldBeUnset as $key )
334 {
335 $tpl->unsetVariable( $key, $name );
336 }
337 // replace var
338 foreach ( $whatParamsShouldBeReplaced as $key => $item_value )
339 {
340 $tpl->setVariable( $key, $item_value, $name );
341 }
342 }
343 }
344 }
345 }
346 }
347
351 function hasChildren()
352 {
353 return false;
354 }
355
356 public $BlockName;
357 }
358
359 ?>
eZTemplateCompiler\isCommentsEnabled
static isCommentsEnabled()
Definition: eztemplatecompiler.php:124
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
eZTemplateToolbarFunction
The class eZTemplateToolarFunction does.
Definition: eztemplatetoolbarfunction.php:18
eZTemplateToolbarFunction\$BlockName
$BlockName
Definition: eztemplatetoolbarfunction.php:356
eZTemplateToolbarFunction\functionList
functionList()
Definition: eztemplatetoolbarfunction.php:33
eZTemplateToolbarFunction\functionTemplateHints
functionTemplateHints()
Definition: eztemplatetoolbarfunction.php:38
eZTemplateToolbarFunction\hasChildren
hasChildren()
Definition: eztemplatetoolbarfunction.php:351
eZTemplateToolbarFunction\__construct
__construct( $blockName='tool_bar')
Definition: eztemplatetoolbarfunction.php:24
eZTemplateToolbarFunction\process
process( $tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace)
Definition: eztemplatetoolbarfunction.php:210
eZTemplateToolbarFunction\templateNodeTransformation
templateNodeTransformation( $functionName, &$node, $tpl, $parameters, $privateData)
Definition: eztemplatetoolbarfunction.php:47
eZTemplate\NAMESPACE_SCOPE_RELATIVE
const NAMESPACE_SCOPE_RELATIVE
Definition: eztemplate.php:286
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.