Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezurloperator.php
Go to the documentation of this file.
1 <?php
17 class eZURLOperator
18 {
19 const HTTP_OPERATOR_TYPE_POST = 1;
20 const HTTP_OPERATOR_TYPE_GET = 2;
21 const HTTP_OPERATOR_TYPE_SESSION = 3;
22 const HTTP_OPERATOR_TYPE_COOKIE = 4;
23
38 public function __construct( $url_name = 'ezurl',
39 $urlroot_name = 'ezroot',
40 $ezsys_name = 'ezsys',
41 $design_name = 'ezdesign',
42 $image_name = 'ezimage',
43 $ext_name = 'exturl',
44 $httpName = 'ezhttp',
45 $iniName = 'ezini',
46 $iniNameHasVariable = 'ezini_hasvariable',
47 $httpNameHasVariable = 'ezhttp_hasvariable' )
48 {
49 $this->Operators = array( $url_name, $urlroot_name, $ezsys_name, $design_name, $image_name, $ext_name, $httpName, $iniName, $iniNameHasVariable, $httpNameHasVariable );
50 $this->URLName = $url_name;
51 $this->URLRootName = $urlroot_name;
52 $this->SysName = $ezsys_name;
53 $this->DesignName = $design_name;
54 $this->ImageName = $image_name;
55 $this->ExtName = $ext_name;
56 $this->HTTPName = $httpName;
57 $this->ININame = $iniName;
58 $this->ININameHasVariable = $iniNameHasVariable;
59 $this->HTTPNameHasVariable = $httpNameHasVariable;
60 $this->Sys = eZSys::instance();
61 }
62
63 function operatorTemplateHints()
64 {
65 return array( $this->URLName => array( 'input' => true,
66 'output' => true,
67 'parameters' => true,
68 'element-transformation' => true,
69 'transform-parameters' => true,
70 'input-as-parameter' => 'always',
71 'element-transformation-func' => 'urlTransformation'),
72 $this->URLRootName => array( 'input' => true,
73 'output' => true,
74 'parameters' => true,
75 'element-transformation' => true,
76 'transform-parameters' => true,
77 'input-as-parameter' => 'always',
78 'element-transformation-func' => 'urlTransformation'),
79 $this->SysName => array( 'input' => true,
80 'output' => true,
81 'parameters' => true,
82 'element-transformation' => true,
83 'transform-parameters' => true,
84 'input-as-parameter' => 'always',
85 'element-transformation-func' => 'urlTransformation'),
86 $this->DesignName => array( 'input' => true,
87 'output' => true,
88 'parameters' => true,
89 'element-transformation' => true,
90 'transform-parameters' => true,
91 'input-as-parameter' => 'always',
92 'element-transformation-func' => 'urlTransformation'),
93 $this->ImageName => array( 'input' => true,
94 'output' => true,
95 'parameters' => true,
96 'element-transformation' => true,
97 'transform-parameters' => true,
98 'input-as-parameter' => 'always',
99 'element-transformation-func' => 'urlTransformation'),
100 $this->ExtName => array( 'input' => true,
101 'output' => true,
102 'parameters' => true,
103 'element-transformation' => true,
104 'transform-parameters' => true,
105 'input-as-parameter' => 'always',
106 'element-transformation-func' => 'urlTransformation'),
107 $this->ININame => array( 'input' => true,
108 'output' => true,
109 'parameters' => true,
110 'element-transformation' => true,
111 'transform-parameters' => true,
112 'input-as-parameter' => true,
113 'element-transformation-func' => 'iniTrans'),
114 $this->ININameHasVariable => array( 'input' => true,
115 'output' => true,
116 'parameters' => true,
117 'element-transformation' => true,
118 'transform-parameters' => true,
119 'input-as-parameter' => true,
120 'element-transformation-func' => 'iniTrans' )
121 );
122 }
123
124 function iniTrans( $operatorName, &$node, $tpl, &$resourceData,
125 $element, $lastElement, $elementList, $elementTree, &$parameters )
126 {
127 if ( !isset( $parameters[1] ) )
128 return false;
129
130 if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) &&
131 eZTemplateNodeTool::isConstantElement( $parameters[1] ) )
132 {
133 $iniGroup = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
134 $iniVariable = eZTemplateNodeTool::elementConstantValue( $parameters[1] );
135
136 $iniName = isset( $parameters[2] ) ? eZTemplateNodeTool::elementConstantValue( $parameters[2] ) : false;
137 $iniPath = isset( $parameters[3] ) ? eZTemplateNodeTool::elementConstantValue( $parameters[3] ) : false;
138
139 // If we should check for existence of variable.
140 // You can use like:
141 // ezini( <BlockName>, <SettingName>, <FileName>, <IniPath>, <Dynamic fetch: if 'true()' value of variable will be fetched dynamically>
142 // <Should We Check for existence only: 'hasVariable' or true()> )
143 // ezini_hasvariable( <BlockName>, <SettingName>, <FileName>, <IniPath>... )
144 if ( $operatorName == $this->ININameHasVariable )
145 {
146 $checkExistence = true;
147 }
148 else
149 {
150 $checkExistence = isset( $parameters[5] )
151 ? ( eZTemplateNodeTool::elementConstantValue( $parameters[5] ) === true or
152 eZTemplateNodeTool::elementConstantValue( $parameters[5] ) == 'hasVariable' ) ? true : false
153 : false;
154 }
155
156 if ( isset( $parameters[4] ) )
157 {
158 $dynamic = eZTemplateNodeTool::elementConstantValue( $parameters[4] );
159 }
160 else
161 {
162 $ini = eZINI::instance();
163 $dynamic = $ini->variable( 'eZINISettings', 'DynamicTemplateMode' ) === 'enabled';
164 }
165
166 // Check if we should put implementation of parsing ini variable to compiled php file
167 if ( $dynamic === true )
168 {
169 $values = array();
170 $values[] = $parameters[0];
171 $values[] = $parameters[1];
172
173 if ( $iniPath !== false )
174 {
175 $values[] = $parameters[2];
176 $values[] = $parameters[3];
177 $code = '%tmp1% = eZINI::instance( %3%, %4%, null, null, null, true );' . "\n";
178 }
179 elseif ( $iniName !== false )
180 {
181 $values[] = $parameters[2];
182 $code = '%tmp1% = eZINI::instance( %3% );' . "\n";
183 }
184 else
185 $code = '%tmp1% = eZINI::instance();' . "\n";
186
187 $checkExist = $checkExistence ? 'true' : 'false';
188
189 $code .= 'if ( %tmp1%->hasVariable( %1%, %2% ) )' . "\n" .
190 ' %output% = ' . "!$checkExist" . ' ? %tmp1%->variable( %1%, %2% ) : true;' . "\n" .
191 "else\n" .
192 " %output% = $checkExist ? false : '';\n";
193
194
195 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, 1 ) );
196 }
197
198 if ( $iniPath !== false )
199 $ini = eZINI::instance( $iniName, $iniPath, null, null, null, true );
200 elseif ( $iniName !== false )
201 $ini = eZINI::instance( $iniName );
202 else
203 $ini = eZINI::instance();
204
205 $value = '';
206 if ( $ini->hasVariable( $iniGroup, $iniVariable ) )
207 {
208 $value = !$checkExistence ? $ini->variable( $iniGroup, $iniVariable ) : true;
209 }
210 else
211 {
212 // If we should check for existence then we return only FALSE
213 if ( $checkExistence )
214 {
215 $value = false;
216 }
217 else
218 {
219 if ( $iniName === false )
220 $iniName = 'site.ini';
221 $tpl->error( $operatorName, "No such variable '$iniVariable' in group '$iniGroup' for $iniName" );
222 }
223 }
224 return array( eZTemplateNodeTool::createStringElement( $value ) );
225 }
226 else
227 return false;
228 }
229
230 function urlTransformation( $operatorName, &$node, $tpl, &$resourceData,
231 $element, $lastElement, $elementList, $elementTree, &$parameters )
232 {
233 $ini = eZINI::instance();
234 $shareTemplates = $ini->hasVariable( 'TemplateSettings', 'ShareCompiledTemplates' ) ?
235 $ini->variable( 'TemplateSettings', 'ShareCompiledTemplates' ) == 'enabled' :
236 false;
237
238 $useTmp = false;
239
240 $newElements = array();
241 $values = array();
242 $paramCount = 0;
243 $tmpCount = 0;
244 switch( $operatorName )
245 {
246 case $this->URLName:
247 {
248 if ( !$shareTemplates && eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
249 {
250 $url = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
251
252 $serverURL = isset( $parameters[2] ) ? eZTemplateNodeTool::elementConstantValue( $parameters[2] ) : eZURI::getTransformURIMode();
253
254 eZURI::transformURI( $url, false, $serverURL );
255
256 $url = $this->applyQuotes( $url, $parameters[1] );
257 return array( eZTemplateNodeTool::createStringElement( $url ) );
258 }
259 else if ( $shareTemplates && eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
260 {
261 $url = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
262
263 $values[] = array( eZTemplateNodeTool::createStringElement( $url ) );
264
265 if ( isset( $parameters[2] ) )
266 {
267 $values[] = $parameters[2];
268 $parameter = "%2%";
269 }
270 else
271 {
272 $parameter = "eZURI::getTransformURIMode()";
273 }
274
275 $code = <<<CODEPIECE
276
277 %tmp1% = %1%;
278 eZURI::transformURI( %tmp1%, false, $parameter );
279
280 CODEPIECE;
281 unset( $parameter );
282 $useTmp = true;
283 ++$tmpCount;
284
285 }
286 else
287 {
288 $values[] = $parameters[0];
289
290 if ( isset( $parameters[2] ) )
291 {
292 $values[] = $parameters[2];
293 $parameter = "%2%";
294 }
295 else
296 {
297 $parameter = "eZURI::getTransformURIMode()";
298 }
299
300 $code = <<<CODEPIECE
301
302 eZURI::transformURI( %1%, false, $parameter );
303
304 CODEPIECE;
305 unset( $parameter );
306 }
307
308 ++$paramCount;
309 } break;
310
311 case $this->URLRootName:
312 {
313 if ( !$shareTemplates && eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
314 {
315 $url = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
316
317 if ( preg_match( "#^[a-zA-Z0-9]+:#", $url ) or
318 substr( $url, 0, 2 ) == '//' )
319 $url = '/';
320 else if ( strlen( $url ) > 0 and
321 $url[0] != '/' )
322 $url = '/' . $url;
323
324 $serverURL = isset( $parameters[2] ) ? eZTemplateNodeTool::elementConstantValue( $parameters[2] ) : eZURI::getTransformURIMode();
325
326 // Same as "ezurl" without "index.php" and the siteaccess name in the returned address.
327 eZURI::transformURI( $url, true, $serverURL );
328
329 $url = $this->applyQuotes( $url, $parameters[1] );
330 return array( eZTemplateNodeTool::createStringElement( $url ) );
331 }
332 else if ( $shareTemplates && eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
333 {
334 $url = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
335
336 $values[] = array( eZTemplateNodeTool::createStringElement( $url ) );
337
338 if ( isset( $parameters[2] ) )
339 {
340 $values[] = $parameters[2];
341 $parameter = "%2%";
342 }
343 else
344 {
345 $parameter = "eZURI::getTransformURIMode()";
346 }
347
348 $code = '%tmp1% = %1%;';
349 $code .= 'if ( !is_null( %tmp1% ) && preg_match( "#^[a-zA-Z0-9]+:#", %tmp1% ) or' . "\n" .
350 '!is_null( %tmp1% ) && substr( %tmp1%, 0, 2 ) == \'//\' )' . "\n" .
351 ' %tmp1% = \'/\';' . "\n" .
352 'else if ( !is_null( %tmp1% ) && strlen( %tmp1% ) > 0 and' . "\n" .
353 ' %tmp1%[0] != \'/\' )' . "\n" .
354 '%tmp1% = \'/\' . %tmp1%;' . "\n";
355
356 $code .= "eZURI::transformURI( %tmp1%, true, $parameter );\n";
357
358 unset( $parameter );
359
360 $useTmp = true;
361 ++$tmpCount;
362 }
363 else
364 {
365 $values[] = $parameters[0];
366
367 if ( isset( $parameters[2] ) )
368 {
369 $values[] = $parameters[2];
370 $parameter = "%2%";
371 }
372 else
373 {
374 $parameter = "eZURI::getTransformURIMode()";
375 }
376
377 $code = 'if ( !is_null( %1% ) && preg_match( "#^[a-zA-Z0-9]+:#", %1% ) or' . "\n" .
378 '!is_null( %1% ) && substr( %1%, 0, 2 ) == \'//\' )' . "\n" .
379 ' %1% = \'/\';' . "\n" .
380 'else if ( !is_null( %1% ) && strlen( %1% ) > 0 and' . "\n" .
381 ' %1%[0] != \'/\' )' . "\n" .
382 '%1% = \'/\' . %1%;' . "\n";
383 $code .= "eZURI::transformURI( %1%, true, $parameter );\n";
384
385 unset( $parameter );
386 }
387
388 ++$paramCount;
389 } break;
390
391 case $this->SysName:
392 {
393 if ( !$shareTemplates && eZTemplateNodeTool::isConstantElement( $parameters[1] ) )
394 {
395 $sysAttribute = eZTemplateNodeTool::elementConstantValue( $parameters[1] );
396
397 switch ( $sysAttribute )
398 {
399 // Query string must be evaluated at runtime. See https://jira.ez.no/browse/EZP-20874
400 case 'querystring':
401 case 'hostname':
402 return false;
403 default:
404 return array( eZTemplateNodeTool::createStringElement( $this->Sys->attribute( $sysAttribute ) ) );
405 }
406 }
407 return false;
408 } break;
409
410 case $this->DesignName:
411 {
412 if ( !$shareTemplates && eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
413 {
414 $path = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
415
416 $path = $this->eZDesign( $tpl, $path, $operatorName );
417 $path = $this->applyQuotes( $path, $parameters[1] );
418
419 return array( eZTemplateNodeTool::createStringElement( $path ) );
420 }
421 else if ( $shareTemplates && eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
422 {
423 $path = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
424
425 $values[] = array( eZTemplateNodeTool::createStringElement( $path ) );
426 $code = ( '%tmp1% = %1%;' . "\n" . '%tmp1% = eZURLOperator::eZDesign( $tpl, %tmp1%, "' . $operatorName . '" );' . "\n" );
427
428 $useTmp = true;
429 ++$tmpCount;
430 }
431 else
432 {
433 $values[] = $parameters[0];
434 $code = ( '%1% = eZURLOperator::eZDesign( $tpl, %1%, "' . $operatorName . '" );' . "\n" );
435 }
436
437 ++$paramCount;
438 } break;
439
440 case $this->ImageName:
441 {
442 $skipSlash = count( $parameters ) > 2 ? eZTemplateNodeTool::elementConstantValue( $parameters[2] ) == true : false;
443
444 if ( !$shareTemplates && eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
445 {
446 $path = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
447
448 $path = eZURLOperator::eZImage( $tpl, $path, $operatorName, $skipSlash );
449 $path = $this->applyQuotes( $path, $parameters[1] );
450
451 return array( eZTemplateNodeTool::createStringElement( $path ) );
452 }
453 else if ( $shareTemplates && eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
454 {
455 $path = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
456
457 $values[] = array( eZTemplateNodeTool::createStringElement( $path ) );
458 $values[] = array( eZTemplateNodeTool::createBooleanElement( $skipSlash ) );
459
460 $code = ( '%tmp1% = %1%;' . "\n" . '%tmp1% = eZURLOperator::eZImage( $tpl, %tmp1%, "' . $operatorName . '", %2% );' . "\n" );
461
462 $useTmp = true;
463 ++$tmpCount;
464 }
465 else
466 {
467 $values[] = $parameters[0];
468 $values[] = array( eZTemplateNodeTool::createBooleanElement( $skipSlash ) );
469
470 $code = ( '%1% = eZURLOperator::eZImage( $tpl, %1%, "' . $operatorName . '", %2% );' . "\n" );
471 }
472
473 ++$paramCount;
474 } break;
475
476 case $this->ExtName:
477 {
478 if ( !$shareTemplates && eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
479 {
480 $origUrl = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
481
482 $url = eZURL::urlByMD5( md5( $origUrl ) );
483 if ( $url == false )
484 eZURL::registerURL( $origUrl );
485 else
486 $origUrl = $url;
487
488 $origUrl = $this->applyQuotes( $origUrl, $parameters[1] );
489
490 return array( eZTemplateNodeTool::createStringElement( $origUrl ) );
491 }
492 else if ( $shareTemplates && eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
493 {
494 $origUrl = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
495
496 $values[] = array( eZTemplateNodeTool::createStringElement( $origUrl ) );
497
498 $code .= '%tmp1% = %1%; ' . "\n" .
499 '%tmp2% = eZURL::urlByMD5( md5( %tmp1% ) );' . "\n" .
500 'if ( %tmp2% == false )' . "\n" .
501 ' eZURL::registerURL( %tmp1% );' . "\n" .
502 'else' . "\n" .
503 ' %tmp1% = %tmp2%;' . "\n";
504
505 ++$tmpCount;
506 $useTmp = true;
507 }
508 else
509 {
510 $values[] = $parameters[0];
511
512 $code .= '%tmp1% = eZURL::urlByMD5( md5( %1% ) );' . "\n" .
513 'if ( %tmp1% == false )' . "\n" .
514 ' eZURL::registerURL( %1% );' . "\n" .
515 'else' . "\n" .
516 ' %1% = %tmp1%;' . "\n";
517 }
518
519 ++$tmpCount;
520 ++$paramCount;
521 } break;
522
523 }
524
525 $http = eZHTTPTool::instance();
526
527 if ( isset( $http->UseFullUrl ) and $http->UseFullUrl )
528 {
529 ++$tmpCount;
530 $code .= '%tmp' . $tmpCount . '% = eZHTTPTool::instance();' . "\n" .
531 'if ( isset( %tmp' . $tmpCount . '%->UseFullUrl ) and %tmp' . $tmpCount . '%->UseFullUrl ' . "\n" .
532 ' and strncasecmp( %1%, \'/\' , 1 ) === 0 ) // do not prepend the site path if it\'s not a http url%'. "\n" .
533 '{' . "\n" .
534 ' %1% = %tmp' . $tmpCount . '%->createRedirectUrl( %1%, array( \'pre_url\' => false ) );' . "\n" .
535 '}' . "\n";
536 }
537
538 if ( count( $parameters ) > $paramCount )
539 {
540 if ( eZTemplateNodeTool::isConstantElement( $parameters[$paramCount] ) )
541 {
542 $quote = '"';
543 $val = eZTemplateNodeTool::elementConstantValue( $parameters[$paramCount] );
544 ++$paramCount;
545
546 if ( $val == 'single' )
547 $quote = "'";
548 else if ( $val == 'no' )
549 $quote = false;
550 if ( $quote !== false )
551 {
552 $values[] = array( eZTemplateNodeTool::createStringElement( $quote ) );
553 if ( $useTmp )
554 {
555 $code .= '%tmp1% = %' . count( $values ) . '% . %tmp1% . %' . count( $values ) . '%;' . "\n";
556 }
557 else
558 {
559 $code .= '%1% = %' . count( $values ) . '% . %1% . %' . count( $values ) . '%;' . "\n";
560 }
561 }
562 }
563 else
564 {
565 $values[] = $parameters[$paramCount];
566 if ( $useTmp )
567 {
568 $code .= 'switch (%' . count( $values ) . '%)' . "\n" .
569 '{' . "\n" .
570 ' case \'single\':' . "\n" .
571 ' %tmp1% = \'\\\'\' . %tmp1% . \'\\\'\' ;' . "\n" .
572 ' break;' . "\n" .
573 ' case \'no\':' . "\n" .
574 ' break;' . "\n" .
575 ' default:' . "\n" .
576 ' %tmp1 = \'"\' . %tmp1% . \'"\' ;' . "\n" .
577 '}' . "\n";
578 }
579 else
580 {
581 $code .= 'switch (%' . count( $values ) . '%)' . "\n" .
582 '{' . "\n" .
583 ' case \'single\':' . "\n" .
584 ' %1% = \'\\\'\' . %1% . \'\\\'\' ;' . "\n" .
585 ' break;' . "\n" .
586 ' case \'no\':' . "\n" .
587 ' break;' . "\n" .
588 ' default:' . "\n" .
589 ' %1% = \'"\' . %1% . \'"\' ;' . "\n" .
590 '}' . "\n";
591 }
592 }
593 }
594 else
595 {
596 $quote = '"';
597 $values[] = array( eZTemplateNodeTool::createStringElement( $quote ) );
598 if ( $useTmp )
599 {
600 $code .= '%tmp1% = %' . count( $values ) . '% . %tmp1% . %' . count( $values ) . '%;' . "\n";
601 }
602 else
603 {
604 $code .= '%1% = %' . count( $values ) . '% . %1% . %' . count( $values ) . '%;' . "\n";
605 }
606 }
607
608 if ( $useTmp )
609 {
610 $code .= '%output% = %tmp1%;' . "\n";
611 }
612 else
613 {
614 $code .= '%output% = %1%;' . "\n";
615 }
616
617 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values, false, $tmpCount );
618
619 return $newElements;
620 }
621
631 function applyQuotes( $text, &$parameter, $onlyQuote = false )
632 {
633 $quote = "\"";
634 if ( $parameter != null )
635 {
636 $val = eZTemplateNodeTool::elementConstantValue( $parameter );
637 if ( $val == 'single' )
638 $quote = "'";
639 else if ( $val == 'no' )
640 $quote = false;
641 }
642
643 if ( $onlyQuote )
644 {
645 return $quote;
646 }
647
648 $http = eZHTTPTool::instance();
649
650 if ( isset( $http->UseFullUrl ) and $http->UseFullUrl
651 and strncasecmp( $text, '/' , 1 ) === 0 ) // do not prepend the site path if it's not a http url
652 {
653 $text = $http->createRedirectUrl( $text, array( 'pre_url' => false ) );
654 }
655 if ( $quote !== false )
656 return $quote . $text . $quote;
657
658 return $text;
659 }
660
664 function operatorList()
665 {
666 return $this->Operators;
667 }
668
669 function namedParameterList()
670 {
671 return array( 'quote_val' => array( 'type' => 'string',
672 'required' => false,
673 'default' => 'double' ),
674 'server_url' => array( 'type' => 'string',
675 'required' => false,
676 'default' => 'relative' ) );
677 }
678
679 function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement )
680 {
681 switch ( $operatorName )
682 {
683 case $this->ININameHasVariable:
684 case $this->ININame:
685 {
686 if ( count( $operatorParameters ) > 0 )
687 {
688 $iniGroup = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace );
689 if ( count( $operatorParameters ) == 1 )
690 {
691 $tpl->error( $operatorName, "Missing variable name parameter" );
692 return;
693 }
694 $iniVariable = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
695 $iniName = isset( $operatorParameters[2] ) ? $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ) : false;
696 $iniPath = isset( $operatorParameters[3] ) ? $tpl->elementValue( $operatorParameters[3], $rootNamespace, $currentNamespace ) : false;
697
698 // If we should check for existence of variable.
699 // You can use like:
700 // ezini( <BlockName>, <SettingName>, <FileName>, <IniPath>, _use under template compiling mode_ , <Should We Check for existence: 'hasVariable' or true()> )
701 // ezini_hasvariable( <BlockName>, <SettingName>, <FileName>, <IniPath>... )
702 if ( $operatorName == $this->ININameHasVariable )
703 {
704 $checkExistence = true;
705 }
706 else
707 {
708 $checkExistence = isset( $operatorParameters[5] )
709 ? ( $tpl->elementValue( $operatorParameters[5], $rootNamespace, $currentNamespace ) === true or
710 $tpl->elementValue( $operatorParameters[5], $rootNamespace, $currentNamespace ) == 'hasVariable' ) ? true : false
711 : false;
712 }
713 if ( $iniPath !== false )
714 $ini = eZINI::instance( $iniName, $iniPath, null, null, null, true );
715 elseif ( $iniName !== false )
716 $ini = eZINI::instance( $iniName );
717 else
718 $ini = eZINI::instance();
719
720 if ( $ini->hasVariable( $iniGroup, $iniVariable ) )
721 {
722 $operatorValue = !$checkExistence ? $ini->variable( $iniGroup, $iniVariable ) : true;
723 }
724 else
725 {
726 if ( $checkExistence )
727 {
728 $operatorValue = false;
729 return;
730 }
731 if ( $iniPath !== false )
732 {
733 // Return empty string instead of displaying error when using 'path' parameter
734 // and DirectAccess mode for ezini.
735 $operatorValue = '';
736 }
737 else
738 {
739 if ( $iniName === false )
740 $iniName = 'site.ini';
741 $tpl->error( $operatorName, "!!!No such variable '$iniVariable' in group '$iniGroup' for $iniName" );
742 }
743 }
744 return;
745 }
746 else
747 $tpl->error( $operatorName, "Missing group name parameter" );
748 } break;
749
750 case $this->HTTPNameHasVariable:
751 case $this->HTTPName:
752 {
753 $http = eZHTTPTool::instance();
754 if ( count( $operatorParameters ) > 0 )
755 {
756 $httpType = eZURLOperator::HTTP_OPERATOR_TYPE_POST;
757 $httpName = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace );
758 if ( count( $operatorParameters ) > 1 )
759 {
760 $httpTypeName = strtolower( $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ) );
761
762 $availableTypeList = array(
763 'post' => eZURLOperator::HTTP_OPERATOR_TYPE_POST,
764 'get' => eZURLOperator::HTTP_OPERATOR_TYPE_GET,
765 'session' => eZURLOperator::HTTP_OPERATOR_TYPE_SESSION,
766 'cookie' => eZURLOperator::HTTP_OPERATOR_TYPE_COOKIE,
767 );
768
769 if( !isset( $availableTypeList[$httpTypeName] ) )
770 {
771 $tpl->warning( $operatorName, "Unknown http type '$httpTypeName'" );
772 }
773 else
774 {
775 $httpType = $availableTypeList[$httpTypeName];
776 }
777 }
778
779 // If we should check for existence of http variable
780 // You can use like:
781 // ezhttp( <Variable>, <Method: post, get, session>, <Should We Check for existence: 'hasVariable' or true()> )
782 // ezhttp_hasvariable( <Variable>, <Method> )
783 if ( $operatorName == $this->HTTPNameHasVariable )
784 {
785 $checkExistence = true;
786 }
787 else
788 {
789 $checkExistence = isset( $operatorParameters[2] )
790 ? ( $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ) === true or
791 $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ) == 'hasVariable' ) ? true : false
792 : false;
793 }
794 switch( $httpType )
795 {
796 case eZURLOperator::HTTP_OPERATOR_TYPE_POST:
797 {
798 if ( $http->hasPostVariable( $httpName ) )
799 $operatorValue = !$checkExistence ? $http->postVariable( $httpName ) : true;
800 else
801 {
802 // If only check for existence - return false
803 if ( $checkExistence )
804 {
805 $operatorValue = false;
806 return;
807 }
808 $tpl->error( $operatorName, "Unknown post variable '$httpName'" );
809 }
810 } break;
811 case eZURLOperator::HTTP_OPERATOR_TYPE_GET:
812 {
813 if ( $http->hasGetVariable( $httpName ) )
814 $operatorValue = !$checkExistence ? $http->getVariable( $httpName ) : true;
815 else
816 {
817 if ( $checkExistence )
818 {
819 $operatorValue = false;
820 return;
821 }
822 $tpl->error( $operatorName, "Unknown get variable '$httpName'" );
823 }
824 } break;
825 case eZURLOperator::HTTP_OPERATOR_TYPE_SESSION:
826 {
827 $hasSessionVariable = $http->hasSessionVariable( $httpName, false );
828 // if null, session has not started, useful if using lazy loading
829 if ( $hasSessionVariable === null )
830 {
831 $operatorValue = null;
832 return;
833 }
834 else if ( $hasSessionVariable !== false )
835 {
836 $operatorValue = !$checkExistence ? $http->sessionVariable( $httpName ) : true;
837 }
838 else
839 {
840 if ( $checkExistence )
841 {
842 $operatorValue = false;
843 return;
844 }
845 $tpl->error( $operatorName, "Unknown session variable '$httpName'" );
846 }
847 } break;
848 case eZURLOperator::HTTP_OPERATOR_TYPE_COOKIE:
849 {
850 if ( array_key_exists( $httpName, $_COOKIE ) )
851 $operatorValue = !$checkExistence ? $_COOKIE[$httpName] : true;
852 else
853 {
854 if ( $checkExistence )
855 {
856 $operatorValue = false;
857 return;
858 }
859 $tpl->error( $operatorName, "Unknown cookie variable '$httpName'" );
860 }
861 } break;
862 }
863 }
864 else
865 {
866 $operatorValue = $http;
867 }
868 return;
869 } break;
870
871 case $this->URLName:
872 {
873 eZURI::transformURI( $operatorValue, false, $namedParameters['server_url'] );
874
875 } break;
876
877 case $this->URLRootName:
878 {
879 if ( preg_match( "#^[a-zA-Z0-9]+:#", $operatorValue ) or
880 substr( $operatorValue, 0, 2 ) == '//' )
881 break;
882 if ( strlen( $operatorValue ) > 0 and
883 $operatorValue[0] != '/' )
884 $operatorValue = '/' . $operatorValue;
885
886 // Same as "ezurl" without "index.php" and the siteaccess name in the returned address.
887 eZURI::transformURI( $operatorValue, true, $namedParameters['server_url'] );
888
889 } break;
890
891 case $this->SysName:
892 {
893 if ( count( $operatorParameters ) == 0 )
894 $tpl->warning( 'eZURLOperator' . $operatorName, 'Requires attributename' );
895 else
896 {
897 $sysAttribute = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace );
898 if ( !$this->Sys->hasAttribute( $sysAttribute ) )
899 $tpl->warning( 'eZURLOperator' . $operatorName, "No such attribute '$sysAttribute' for eZSys" );
900 else
901 $operatorValue = $this->Sys->attribute( $sysAttribute );
902 }
903 return;
904 } break;
905
906 case $this->ImageName:
907 {
908 if ( count( $operatorParameters ) == 2 &&
909 $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ) == true &&
910 strlen( $this->Sys->wwwDir() ) == 0 )
911 {
912 $skipSlash = true;
913 }
914 else
915 {
916 $skipSlash = false;
917 }
918
919 $operatorValue = $this->eZImage( $tpl, $operatorValue, $operatorName, $skipSlash );
920 } break;
921
922 case $this->ExtName:
923 {
924 $urlMD5 = md5( $operatorValue );
925 $url = eZURL::urlByMD5( $urlMD5 );
926 if ( $url === false )
927 eZURL::registerURL( $operatorValue );
928 else
929 $operatorValue = $url;
930 } break;
931
932 case $this->DesignName:
933 {
934 $operatorValue = $this->eZDesign( $tpl, $operatorValue, $operatorName );
935 } break;
936 }
937 $quote = "\"";
938 $val = $namedParameters['quote_val'];
939 if ( $val == 'single' )
940 $quote = "'";
941 else if ( $val == 'no' )
942 $quote = false;
943
944 $http = eZHTTPTool::instance();
945
946 if ( isset( $http->UseFullUrl ) and $http->UseFullUrl
947 and strncasecmp( $operatorValue, '/' , 1 ) === 0 ) // do not prepend the site path if it's not a http url
948 {
949 $operatorValue = $http->createRedirectUrl( $operatorValue, array( 'pre_url' => false ) );
950 }
951 if ( $quote !== false )
952 $operatorValue = $quote . $operatorValue . $quote;
953 }
954
958 static function eZDesign( $tpl, $operatorValue, $operatorName )
959 {
960 $sys = eZSys::instance();
961
962 $bases = eZTemplateDesignResource::allDesignBases();
963 $triedFiles = array();
964 $fileInfo = eZTemplateDesignResource::fileMatch( $bases, false, $operatorValue, $triedFiles);
965
966 if ( !$fileInfo )
967 {
968 $tpl->warning( $operatorName, "Design element $operatorValue does not exist in any design" );
969 $tpl->warning( $operatorName, "Tried files: " . implode( ', ', $triedFiles ) );
970 $siteDesign = eZTemplateDesignResource::designSetting( 'site' );
971 $filePath = "design/$siteDesign/$operatorValue";
972 }
973 else
974 {
975 $filePath = $fileInfo['path'];
976 }
977
978 $operatorValue = $sys->wwwDir() . '/' . $filePath;
979 $operatorValue = htmlspecialchars( $operatorValue );
980
981 return $operatorValue;
982 }
983
987 static function eZImage( $tpl, $operatorValue, $operatorName, $skipSlash = false )
988 {
989 $sys = eZSys::instance();
990 if ( $skipSlash && strlen( $sys->wwwDir() ) != 0 )
991 {
992 $skipSlash = false;
993 }
994
995 $bases = eZTemplateDesignResource::allDesignBases();
996 $triedFiles = array();
997 $fileInfo = eZTemplateDesignResource::fileMatch( $bases, 'images', $operatorValue, $triedFiles );
998
999 if ( !$fileInfo )
1000 {
1001 $tpl->warning( $operatorName, "Image '$operatorValue' does not exist in any design" );
1002 $tpl->warning( $operatorName, "Tried files: " . implode( ', ', $triedFiles ) );
1003 $siteDesign = eZTemplateDesignResource::designSetting( 'site' );
1004 $imgPath = "design/$siteDesign/images/$operatorValue";
1005 }
1006 else
1007 {
1008 $imgPath = $fileInfo['path'];
1009 }
1010
1011 $operatorValue = $skipSlash ? $imgPath : $sys->wwwDir() . '/' . $imgPath;
1012 $operatorValue = htmlspecialchars( $operatorValue );
1013
1014 return $operatorValue;
1015 }
1016
1017 public $Operators;
1018 public $URLName, $URLRootName, $DesignName, $ImageName;
1019 public $Sys;
1020 public $SysName;
1021 public $ExtName;
1022 public $HTTPName;
1023 public $ININame;
1024 public $ININameHasVariable;
1025 public $HTTPNameHasVariable;
1026 }
1027
1028 ?>
eZHTTPTool\instance
static instance()
Definition: ezhttptool.php:189
eZSys\instance
static instance()
Definition: ezsys.php:1272
eZTemplateDesignResource\allDesignBases
static allDesignBases( $siteAccess=false)
Definition: eztemplatedesignresource.php:652
eZTemplateDesignResource\designSetting
static designSetting( $type='standard')
Definition: eztemplatedesignresource.php:175
eZTemplateDesignResource\fileMatch
static fileMatch( $bases, $element, $path, &$triedFiles)
Definition: eztemplatedesignresource.php:229
eZTemplateNodeTool\elementConstantValue
static elementConstantValue( $elements)
Definition: eztemplatenodetool.php:197
eZTemplateNodeTool\createCodePieceElement
static createCodePieceElement( $codePiece, $values=false, $placement=false, $tmpValues=false, $knownTypes=true)
Definition: eztemplatenodetool.php:437
eZTemplateNodeTool\createBooleanElement
static createBooleanElement( $boolean, $variablePlacement=false)
Definition: eztemplatenodetool.php:133
eZTemplateNodeTool\createStringElement
static createStringElement( $string, $variablePlacement=false)
Definition: eztemplatenodetool.php:79
eZTemplateNodeTool\isConstantElement
static isConstantElement( $elements)
Definition: eztemplatenodetool.php:233
eZURI\getTransformURIMode
static getTransformURIMode()
Definition: ezuri.php:679
eZURI\transformURI
static transformURI(&$href, $ignoreIndexDir=false, $serverURL=null, $htmlEscape=true)
Definition: ezuri.php:599
eZURLOperator
Collection of url modifying operators.
Definition: ezurloperator.php:18
eZURLOperator\HTTP_OPERATOR_TYPE_SESSION
const HTTP_OPERATOR_TYPE_SESSION
Definition: ezurloperator.php:21
eZURLOperator\iniTrans
iniTrans( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: ezurloperator.php:124
eZURLOperator\$URLName
$URLName
Definition: ezurloperator.php:1018
eZURLOperator\namedParameterList
namedParameterList()
Definition: ezurloperator.php:669
eZURLOperator\$ININame
$ININame
Definition: ezurloperator.php:1023
eZURLOperator\$DesignName
$DesignName
Definition: ezurloperator.php:1018
eZURLOperator\modify
modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement)
Definition: ezurloperator.php:679
eZURLOperator\operatorList
operatorList()
Definition: ezurloperator.php:664
eZURLOperator\$Sys
$Sys
Definition: ezurloperator.php:1019
eZURLOperator\HTTP_OPERATOR_TYPE_POST
const HTTP_OPERATOR_TYPE_POST
Definition: ezurloperator.php:19
eZURLOperator\$ExtName
$ExtName
Definition: ezurloperator.php:1021
eZURLOperator\operatorTemplateHints
operatorTemplateHints()
Definition: ezurloperator.php:63
eZURLOperator\$HTTPNameHasVariable
$HTTPNameHasVariable
Definition: ezurloperator.php:1025
eZURLOperator\HTTP_OPERATOR_TYPE_COOKIE
const HTTP_OPERATOR_TYPE_COOKIE
Definition: ezurloperator.php:22
eZURLOperator\eZImage
static eZImage( $tpl, $operatorValue, $operatorName, $skipSlash=false)
Definition: ezurloperator.php:987
eZURLOperator\$ININameHasVariable
$ININameHasVariable
Definition: ezurloperator.php:1024
eZURLOperator\$URLRootName
$URLRootName
Definition: ezurloperator.php:1018
eZURLOperator\HTTP_OPERATOR_TYPE_GET
const HTTP_OPERATOR_TYPE_GET
Definition: ezurloperator.php:20
eZURLOperator\$ImageName
$ImageName
Definition: ezurloperator.php:1018
eZURLOperator\urlTransformation
urlTransformation( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: ezurloperator.php:230
eZURLOperator\applyQuotes
applyQuotes( $text, &$parameter, $onlyQuote=false)
Definition: ezurloperator.php:631
eZURLOperator\$Operators
$Operators
Definition: ezurloperator.php:1017
eZURLOperator\$HTTPName
$HTTPName
Definition: ezurloperator.php:1022
eZURLOperator\eZDesign
static eZDesign( $tpl, $operatorValue, $operatorName)
Definition: ezurloperator.php:958
eZURLOperator\__construct
__construct( $url_name='ezurl', $urlroot_name='ezroot', $ezsys_name='ezsys', $design_name='ezdesign', $image_name='ezimage', $ext_name='exturl', $httpName='ezhttp', $iniName='ezini', $iniNameHasVariable='ezini_hasvariable', $httpNameHasVariable='ezhttp_hasvariable')
Definition: ezurloperator.php:38
eZURLOperator\$SysName
$SysName
Definition: ezurloperator.php:1020
eZURL\urlByMD5
static urlByMD5( $urlMD5)
Definition: ezurl.php:406
eZURL\registerURL
static registerURL( $url)
Definition: ezurl.php:96
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.