00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 define( 'EZ_HTTP_OPERATOR_TYPE_POST', 1 );
00039 define( 'EZ_HTTP_OPERATOR_TYPE_GET', 2 );
00040 define( 'EZ_HTTP_OPERATOR_TYPE_SESSION', 3 );
00041
00042 class eZURLOperator
00043 {
00044
00045
00046
00047 function eZURLOperator( $url_name = 'ezurl',
00048 $urlroot_name = 'ezroot',
00049 $ezsys_name = 'ezsys',
00050 $design_name = 'ezdesign',
00051 $image_name = 'ezimage',
00052 $ext_name = 'exturl',
00053 $httpName = 'ezhttp',
00054 $iniName = 'ezini',
00055 $iniNameHasVariable = 'ezini_hasvariable',
00056 $httpNameHasVariable = 'ezhttp_hasvariable' )
00057 {
00058 $this->Operators = array( $url_name, $urlroot_name, $ezsys_name, $design_name, $image_name, $ext_name, $httpName, $iniName, $iniNameHasVariable, $httpNameHasVariable );
00059 $this->URLName = $url_name;
00060 $this->URLRootName = $urlroot_name;
00061 $this->SysName = $ezsys_name;
00062 $this->DesignName = $design_name;
00063 $this->ImageName = $image_name;
00064 $this->ExtName = $ext_name;
00065 $this->HTTPName = $httpName;
00066 $this->ININame = $iniName;
00067 $this->ININameHasVariable = $iniNameHasVariable;
00068 $this->HTTPNameHasVariable = $httpNameHasVariable;
00069 $this->Sys =& eZSys::instance();
00070 }
00071
00072 function operatorTemplateHints()
00073 {
00074 return array( $this->URLName => array( 'input' => true,
00075 'output' => true,
00076 'parameters' => true,
00077 'element-transformation' => true,
00078 'transform-parameters' => true,
00079 'input-as-parameter' => 'always',
00080 'element-transformation-func' => 'urlTransformation'),
00081 $this->URLRootName => array( 'input' => true,
00082 'output' => true,
00083 'parameters' => true,
00084 'element-transformation' => true,
00085 'transform-parameters' => true,
00086 'input-as-parameter' => 'always',
00087 'element-transformation-func' => 'urlTransformation'),
00088 $this->SysName => array( 'input' => true,
00089 'output' => true,
00090 'parameters' => true,
00091 'element-transformation' => true,
00092 'transform-parameters' => true,
00093 'input-as-parameter' => 'always',
00094 'element-transformation-func' => 'urlTransformation'),
00095 $this->DesignName => array( 'input' => true,
00096 'output' => true,
00097 'parameters' => true,
00098 'element-transformation' => true,
00099 'transform-parameters' => true,
00100 'input-as-parameter' => 'always',
00101 'element-transformation-func' => 'urlTransformation'),
00102 $this->ImageName => array( 'input' => true,
00103 'output' => true,
00104 'parameters' => true,
00105 'element-transformation' => true,
00106 'transform-parameters' => true,
00107 'input-as-parameter' => 'always',
00108 'element-transformation-func' => 'urlTransformation'),
00109 $this->ExtName => array( 'input' => true,
00110 'output' => true,
00111 'parameters' => true,
00112 'element-transformation' => true,
00113 'transform-parameters' => true,
00114 'input-as-parameter' => 'always',
00115 'element-transformation-func' => 'urlTransformation'),
00116 $this->ININame => array( 'input' => true,
00117 'output' => true,
00118 'parameters' => true,
00119 'element-transformation' => true,
00120 'transform-parameters' => true,
00121 'input-as-parameter' => true,
00122 'element-transformation-func' => 'iniTrans'),
00123 $this->ININameHasVariable => array( 'input' => true,
00124 'output' => true,
00125 'parameters' => true,
00126 'element-transformation' => true,
00127 'transform-parameters' => true,
00128 'input-as-parameter' => true,
00129 'element-transformation-func' => 'iniTrans' )
00130 );
00131 }
00132
00133 function iniTrans( $operatorName, &$node, &$tpl, &$resourceData,
00134 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters )
00135 {
00136 if ( count ( $parameters ) < 2 )
00137 return false;
00138
00139 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) &&
00140 eZTemplateNodeTool::isStaticElement( $parameters[1] ) )
00141 {
00142 $iniGroup = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
00143 $iniVariable = eZTemplateNodeTool::elementStaticValue( $parameters[1] );
00144
00145 $iniName = isset( $parameters[2] ) ? eZTemplateNodeTool::elementStaticValue( $parameters[2] ) : false;
00146 $iniPath = isset( $parameters[3] ) ? eZTemplateNodeTool::elementStaticValue( $parameters[3] ) : false;
00147
00148
00149
00150
00151
00152
00153 if ( $operatorName == $this->ININameHasVariable )
00154 {
00155 $checkExistence = true;
00156 }
00157 else
00158 {
00159 $checkExistence = isset( $parameters[5] )
00160 ? ( eZTemplateNodeTool::elementStaticValue( $parameters[5] ) === true or
00161 eZTemplateNodeTool::elementStaticValue( $parameters[5] ) == 'hasVariable' ) ? true : false
00162 : false;
00163 }
00164
00165 if ( count( $parameters ) > 4 )
00166 {
00167 $inCache = eZTemplateNodeTool::elementStaticValue( $parameters[4] );
00168
00169 if ( $inCache === true )
00170 {
00171 $values = array();
00172 $values[] = $parameters[0];
00173 $values[] = $parameters[1];
00174
00175 $code = "include_once( 'lib/ezutils/classes/ezini.php' );\n";
00176
00177 if ( $iniPath !== false )
00178 {
00179 $values[] = $parameters[2];
00180 $values[] = $parameters[3];
00181 $code .= '%tmp1% =& eZINI::instance( %3%, %4%, null, null, null, true );' . "\n";
00182 }
00183 elseif ( $iniName !== false )
00184 {
00185 $values[] = $parameters[2];
00186 $code .= '%tmp1% =& eZINI::instance( %3% );' . "\n";
00187 }
00188 else
00189 $code .= '%tmp1% =& eZINI::instance();' . "\n";
00190
00191 $checkExist = $checkExistence ? 'true' : 'false';
00192
00193 $code .= 'if ( %tmp1%->hasVariable( %1%, %2% ) )' . "\n" .
00194 ' %output% = ' . "!$checkExist" . ' ? %tmp1%->variable( %1%, %2% ) : true;' . "\n" .
00195 "else\n" .
00196 " %output% = $checkExist ? false : '';\n";
00197
00198
00199 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, 1 ) );
00200 }
00201 }
00202 include_once( 'lib/ezutils/classes/ezini.php' );
00203
00204 if ( $iniPath !== false )
00205 $ini =& eZINI::instance( $iniName, $iniPath, null, null, null, true );
00206 elseif ( $iniName !== false )
00207 $ini =& eZINI::instance( $iniName );
00208 else
00209 $ini =& eZINI::instance();
00210
00211 $value = '';
00212 if ( $ini->hasVariable( $iniGroup, $iniVariable ) )
00213 {
00214 $value = !$checkExistence ? $ini->variable( $iniGroup, $iniVariable ) : true;
00215 }
00216 else
00217 {
00218
00219 if ( $checkExistence )
00220 {
00221 $value = false;
00222 }
00223 else
00224 {
00225 if ( $iniName === false )
00226 $iniName = 'site.ini';
00227 $tpl->error( $operatorName, "No such variable '$iniVariable' in group '$iniGroup' for $iniName" );
00228 }
00229 }
00230 return array( eZTemplateNodeTool::createStringElement( $value ) );
00231 }
00232 else
00233 return false;
00234 }
00235
00236 function urlTransformation( $operatorName, &$node, &$tpl, &$resourceData,
00237 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters )
00238 {
00239 $newElements = array();
00240 $values = array();
00241 $paramCount = 0;
00242 $tmpCount = 0;
00243 switch( $operatorName )
00244 {
00245 case $this->URLName:
00246 {
00247 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
00248 {
00249 $url = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
00250
00251 $serverURL = isset( $parameters[2] ) ? eZTemplateNodeTool::elementStaticValue( $parameters[2] ) : 'relative';
00252
00253 include_once( 'lib/ezutils/classes/ezuri.php' );
00254 eZURI::transformURI( $url, false, $serverURL );
00255
00256 $url = $this->applyQuotes( $url, $parameters[1] );
00257 return array( eZTemplateNodeTool::createStringElement( $url ) );
00258 }
00259 $values[] = $parameters[0];
00260 $values[] = isset( $parameters[2] ) ? $parameters[2] : array( eZTemplateNodeTool::createStringElement( 'relative' ) );
00261 $code = <<<CODEPIECE
00262
00263 include_once( 'lib/ezutils/classes/ezuri.php' );
00264 eZURI::transformURI( %1%, false, %2% );
00265
00266 CODEPIECE;
00267
00268 ++$paramCount;
00269 } break;
00270
00271 case $this->URLRootName:
00272 {
00273 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
00274 {
00275 $url = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
00276
00277 if ( preg_match( "#^[a-zA-Z0-9]+:#", $url ) or
00278 substr( $url, 0, 2 ) == '//' )
00279 $url = '/';
00280 else if ( strlen( $url ) > 0 and
00281 $url[0] != '/' )
00282 $url = '/' . $url;
00283
00284 $serverURL = isset( $parameters[2] ) ? eZTemplateNodeTool::elementStaticValue( $parameters[2] ) : 'relative';
00285
00286
00287 include_once( 'lib/ezutils/classes/ezuri.php' );
00288 eZURI::transformURI( $url, true, $serverURL );
00289
00290 $url = $this->applyQuotes( $url, $parameters[1] );
00291 return array( eZTemplateNodeTool::createStringElement( $url ) );
00292 }
00293 else
00294 {
00295 $code ='if ( preg_match( "#^[a-zA-Z0-9]+:#", %1% ) or' . "\n" .
00296 'substr( %1%, 0, 2 ) == \'//\' )' . "\n" .
00297 ' %1% = \'/\';' . "\n" .
00298 'else if ( strlen( %1% ) > 0 and' . "\n" .
00299 ' %1%[0] != \'/\' )' . "\n" .
00300 '%1% = \'/\' . %1%;' . "\n";
00301 $values[] = $parameters[0];
00302 }
00303 $values[] = isset( $parameters[2] ) ? $parameters[2] : array( eZTemplateNodeTool::createStringElement( 'relative' ) );
00304 $code .= 'include_once( \'lib/ezutils/classes/ezuri.php\' );' . "\n" .
00305 'eZURI::transformURI( %1%, true, %2% );' . "\n";
00306
00307 ++$paramCount;
00308 ++$tmpCount;
00309 } break;
00310
00311 case $this->SysName:
00312 {
00313 if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) )
00314 {
00315 $sysAttribute = eZTemplateNodeTool::elementStaticValue( $parameters[1] );
00316
00317 return array( eZTemplateNodeTool::createStringElement( $this->Sys->attribute( $sysAttribute ) ) );
00318 }
00319 return false;
00320 } break;
00321
00322 case $this->DesignName:
00323 {
00324 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
00325 {
00326 $path = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
00327
00328 $matches = eZTemplateDesignResource::fileMatchingRules( false, $path );
00329
00330 $designResource =& eZTemplateDesignResource::instance();
00331 $matchKeys = $designResource->keys();
00332 $matchedKeys = array();
00333
00334 include_once( 'kernel/common/ezoverride.php' );
00335 $match = eZOverride::selectFile( $matches, $matchKeys, $matchedKeys, "#^(.+)/(.+)(\.[a-zA-Z0-9]+)$#" );
00336 if ( $match === null )
00337 {
00338 $tpl->warning( $operatorName, "Design element $path does not exist in any design" );
00339 $siteDesign = eZTemplateDesignResource::designSetting( 'site' );
00340 $path = "design/$siteDesign/$path";
00341 }
00342 else
00343 {
00344 $path = $match["file"];
00345 }
00346
00347 $path = $this->Sys->wwwDir() . '/' . $path;
00348 $path = htmlspecialchars( $path );
00349
00350 $path = $this->applyQuotes( $path, $parameters[1] );
00351
00352 return array( eZTemplateNodeTool::createStringElement( $path ) );
00353 }
00354
00355 $code = ( '%tmp1% =& eZTemplateDesignResource::instance();' . "\n" .
00356 'include_once( \'kernel/common/ezoverride.php\' );' . "\n" .
00357 '%tmp2% = array();' . "\n" .
00358 '%tmp3% = eZOverride::selectFile( eZTemplateDesignResource::fileMatchingRules( false, %1% ), %tmp1%->keys(), %tmp2%, "#^(.+)/(.+)(\.[a-zA-Z0-9]+)$#" );' . "\n" .
00359 'if ( %tmp3% === null )' . "\n" .
00360 '{' . "\n" .
00361 ' %tmp3% = array();' . "\n" .
00362 ' $tpl->warning( "' . $operatorName . '", "Design element %1% does not exist in any design" );' . "\n" .
00363 ' %tmp4% = eZTemplateDesignResource::designSetting( "site" );' . "\n" .
00364 ' %1% = "design/%tmp4%/%1%";' . "\n" .
00365 '}' . "\n" .
00366 'else' . "\n" .
00367 '{' . "\n" .
00368 ' %1% = %tmp3%["file"];' . "\n" .
00369 '}' . "\n" .
00370 '%1% = %2% . "/" . %1%;' . "\n" .
00371 '%1% = htmlspecialchars( %1% );' . "\n"
00372 );
00373
00374 $values[] = $parameters[0];
00375 $values[] = array( eZTemplateNodeTool::createStringElement( $this->Sys->wwwDir() ) );
00376 $tmpCount += 4;
00377 ++$paramCount;
00378 } break;
00379
00380 case $this->ImageName:
00381 {
00382 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
00383 {
00384 $path = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
00385 $skipSlash = false;
00386 if ( count( $parameters ) > 2 )
00387 {
00388 $skipSlash = eZTemplateNodeTool::elementStaticValue( $parameters[2] );
00389 }
00390
00391 $bases = eZTemplateDesignResource::allDesignBases();
00392 $no_slash_prefix = false;
00393 if ( $skipSlash == true && strlen( $this->Sys->wwwDir() ) == 0 )
00394 $no_slash_prefix = true;
00395
00396 $imageFound = false;
00397 foreach ( $bases as $base )
00398 {
00399 $possiblePath = $base . '/images/' . $path;
00400 if ( file_exists( $possiblePath ) )
00401 {
00402 if ( $no_slash_prefix == true )
00403 $path = $possiblePath;
00404 else
00405 $path = $this->Sys->wwwDir() . '/' . $possiblePath;
00406 $imageFound = true;
00407 break;
00408 }
00409 }
00410
00411 if ( !$imageFound )
00412 {
00413 $tpl->warning( $operatorName, "Image '$path' does not exist in any design" );
00414 $siteDesign = eZTemplateDesignResource::designSetting( 'site' );
00415 $path = "design/$siteDesign/images/$path";
00416 }
00417
00418 $path = htmlspecialchars( $path );
00419 $path = $this->applyQuotes( $path, $parameters[1] );
00420
00421 return array( eZTemplateNodeTool::createStringElement( $path ) );
00422 }
00423 else
00424 {
00425 $values = array();
00426 $values[] = $parameters[0];
00427
00428 $no_slash_prefix = false;
00429 if ( count ( $parameters ) > 2 )
00430 {
00431 if ( eZTemplateNodeTool::elementStaticValue( $parameters[2] ) == true && strlen( $wwwDir ) )
00432 {
00433 $no_slash_prefix = true;
00434 }
00435 }
00436
00437 $ini =& eZINI::instance();
00438 $values[] = array( eZTemplateNodeTool::createStringElement( $this->Sys->wwwDir() ) );
00439 $values[] = array( eZTemplateNodeTool::createArrayElement( eZTemplateDesignResource::allDesignBases() ) );
00440
00441 $code =
00442 '%tmp2% = false;' . "\n" .
00443 'foreach ( %3% as %tmp1% )' . "\n" .
00444 '{' . "\n" .
00445 ' %tmp3% = %tmp1% . "/images/" . %1%;' . "\n" .
00446 ' if ( file_exists( %tmp3% ) )' . "\n" .
00447 ' {' . "\n" ;
00448 if ( $no_slash_prefix == true )
00449 $code .= ' %1% = %tmp3%;';
00450 else
00451 $code .= ' %1% = %2% . "/" . %tmp3%;';
00452
00453 $code .= "\n" .
00454 ' %tmp2% = true;' . "\n" .
00455 ' break;' . "\n" .
00456 ' }' . "\n" .
00457 '}' . "\n" .
00458 'if ( !%tmp2% )' . "\n" .
00459 '{' . "\n" .
00460 ' $tpl->warning( "' . $operatorName .
00461 '", "Image %1% does not exist in any design" );' . "\n" .
00462 ' %tmp3% = eZTemplateDesignResource::designSetting( "site" );' . "\n" .
00463 ' %1% = "design/%tmp3%/images/%1%";' . "\n" .
00464 '}' . "\n" .
00465 '%output% = htmlspecialchars( %1% );' . "\n" ;
00466
00467 $quote = $this->applyQuotes( '', $parameters[1], true );
00468 if ( $quote )
00469 {
00470 $values[] = array( eZTemplateNodeTool::createStringElement( $quote ) );
00471 $code .= '%output% = %4% . %output% . %4%;' . "\n";
00472 }
00473 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values, false, 3 ) );
00474 }
00475 } break;
00476
00477 case $this->ExtName:
00478 {
00479 if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
00480 {
00481 $origUrl = eZTemplateNodeTool::elementStaticValue( $parameters[0] );
00482
00483 include_once( 'kernel/classes/datatypes/ezurl/ezurl.php' );
00484 $url = eZURL::urlByMD5( md5( $origUrl ) );
00485 if ( $url == false )
00486 eZURL::registerURL( $origUrl );
00487 else
00488 $origUrl = $url;
00489
00490 $origUrl = $this->applyQuotes( $origUrl, $parameters[1] );
00491
00492 return array( eZTemplateNodeTool::createStringElement( $origUrl ) );
00493 }
00494
00495 $code .= 'include_once( \'kernel/classes/datatypes/ezurl/ezurl.php\' );' . "\n" .
00496 '%tmp1% = eZURL::urlByMD5( md5( %1% ) );' . "\n" .
00497 'if ( %tmp1% == false )' . "\n" .
00498 ' eZURL::registerURL( %1% );' . "\n" .
00499 'else' . "\n" .
00500 ' %1% = %tmp1%;' . "\n";
00501 $values[] = $parameters[0];
00502 ++$tmpCount;
00503 ++$paramCount;
00504 } break;
00505
00506 }
00507
00508 include_once( 'lib/ezutils/classes/ezhttptool.php' );
00509 $http =& eZHTTPTool::instance();
00510
00511 if ( isset( $http->UseFullUrl ) and $http->UseFullUrl )
00512 {
00513 ++$tmpCount;
00514 $code .= 'include_once( \'lib/ezutils/classes/ezhttptool.php\' );' . "\n" .
00515 '%tmp' . $tmpCount . '% =& eZHTTPTool::instance();' . "\n" .
00516 'if ( isset( %tmp' . $tmpCount . '%->UseFullUrl ) and %tmp' . $tmpCount . '%->UseFullUrl ' . "\n" .
00517 ' and strncasecmp( %1%, \'/\' , 1 ) === 0 ) // do not prepend the site path if it\'s not a http url%'. "\n" .
00518 '{' . "\n" .
00519 ' %1% = %tmp' . $tmpCount . '%->createRedirectUrl( %1%, array( \'pre_url\' => false ) );' . "\n" .
00520 '}' . "\n";
00521 }
00522
00523 if ( count( $parameters ) > $paramCount )
00524 {
00525 if ( eZTemplateNodeTool::isStaticElement( $parameters[$paramCount] ) )
00526 {
00527 $quote = '"';
00528 $val = eZTemplateNodeTool::elementStaticValue( $parameters[$paramCount] );
00529 ++$paramCount;
00530
00531 if ( $val == 'single' )
00532 $quote = "'";
00533 else if ( $val == 'no' )
00534 $quote = false;
00535 if ( $quote !== false )
00536 {
00537 $values[] = array( eZTemplateNodeTool::createStringElement( $quote ) );
00538 $code .= '%1% = %' . count( $values ) . '% . %1% . %' . count( $values ) . '%;' . "\n";
00539 }
00540 }
00541 else
00542 {
00543 $values[] = $parameters[$paramCount];
00544 $code .= 'switch (%' . count( $values ) . '%)' . "\n" .
00545 '{' . "\n" .
00546 ' case \'single\':' . "\n" .
00547 ' %1% = \'\\\'\' . %1% . \'\\\'\' ;' . "\n" .
00548 ' break;' . "\n" .
00549 ' case \'no\':' . "\n" .
00550 ' break;' . "\n" .
00551 ' default:' . "\n" .
00552 ' %1% = \'"\' . %1% . \'"\' ;' . "\n" .
00553 '}' . "\n";
00554 }
00555 }
00556 else
00557 {
00558 $quote = '"';
00559 $values[] = array( eZTemplateNodeTool::createStringElement( $quote ) );
00560 $code .= '%1% = %' . count( $values ) . '% . %1% . %' . count( $values ) . '%;' . "\n";
00561 }
00562
00563 $code .= '%output% = %1%;' . "\n";
00564
00565 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values, false, $tmpCount );
00566
00567 return $newElements;
00568 }
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579 function applyQuotes( $text, &$parameter, $onlyQuote = false )
00580 {
00581 $quote = "\"";
00582 if ( $parameter != null )
00583 {
00584 $val = eZTemplateNodeTool::elementStaticValue( $parameter );
00585 if ( $val == 'single' )
00586 $quote = "'";
00587 else if ( $val == 'no' )
00588 $quote = false;
00589 }
00590
00591 if ( $onlyQuote )
00592 {
00593 return $quote;
00594 }
00595
00596 include_once( 'lib/ezutils/classes/ezhttptool.php' );
00597 $http =& eZHTTPTool::instance();
00598
00599 if ( isset( $http->UseFullUrl ) and $http->UseFullUrl
00600 and strncasecmp( $text, '/' , 1 ) === 0 )
00601 {
00602 $text = $http->createRedirectUrl( $text, array( 'pre_url' => false ) );
00603 }
00604 if ( $quote !== false )
00605 return $quote . $text . $quote;
00606
00607 return $text;
00608 }
00609
00610
00611
00612
00613 function &operatorList()
00614 {
00615 return $this->Operators;
00616 }
00617
00618 function namedParameterList()
00619 {
00620 return array( 'quote_val' => array( 'type' => 'string',
00621 'required' => false,
00622 'default' => 'double' ),
00623 'server_url' => array( 'type' => 'string',
00624 'required' => false,
00625 'default' => 'relative' ) );
00626 }
00627
00628
00629
00630 function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters )
00631 {
00632 switch ( $operatorName )
00633 {
00634 case $this->ININameHasVariable:
00635 case $this->ININame:
00636 {
00637 if ( count( $operatorParameters ) > 0 )
00638 {
00639 $iniGroup = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace );
00640 if ( count( $operatorParameters ) == 1 )
00641 {
00642 $tpl->error( $operatorName, "Missing variable name parameter" );
00643 return;
00644 }
00645 $iniVariable = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
00646 $iniName = isset( $operatorParameters[2] ) ? $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ) : false;
00647 $iniPath = isset( $operatorParameters[3] ) ? $tpl->elementValue( $operatorParameters[3], $rootNamespace, $currentNamespace ) : false;
00648
00649
00650
00651
00652
00653 if ( $operatorName == $this->ININameHasVariable )
00654 {
00655 $checkExistence = true;
00656 }
00657 else
00658 {
00659 $checkExistence = isset( $operatorParameters[5] )
00660 ? ( $tpl->elementValue( $operatorParameters[5], $rootNamespace, $currentNamespace ) === true or
00661 $tpl->elementValue( $operatorParameters[5], $rootNamespace, $currentNamespace ) == 'hasVariable' ) ? true : false
00662 : false;
00663 }
00664 include_once( 'lib/ezutils/classes/ezini.php' );
00665
00666 if ( $iniPath !== false )
00667 $ini =& eZINI::instance( $iniName, $iniPath, null, null, null, true );
00668 elseif ( $iniName !== false )
00669 $ini =& eZINI::instance( $iniName );
00670 else
00671 $ini =& eZINI::instance();
00672
00673 if ( $ini->hasVariable( $iniGroup, $iniVariable ) )
00674 {
00675 $operatorValue = !$checkExistence ? $ini->variable( $iniGroup, $iniVariable ) : true;
00676 }
00677 else
00678 {
00679 if ( $checkExistence )
00680 {
00681 $operatorValue = false;
00682 return;
00683 }
00684 if ( $iniPath !== false )
00685 {
00686
00687
00688 $operatorValue = '';
00689 }
00690 else
00691 {
00692 if ( $iniName === false )
00693 $iniName = 'site.ini';
00694 $tpl->error( $operatorName, "!!!No such variable '$iniVariable' in group '$iniGroup' for $iniName" );
00695 }
00696 }
00697 return;
00698 }
00699 else
00700 $tpl->error( $operatorName, "Missing group name parameter" );
00701 } break;
00702
00703 case $this->HTTPNameHasVariable:
00704 case $this->HTTPName:
00705 {
00706 include_once( 'lib/ezutils/classes/ezhttptool.php' );
00707 $http =& eZHTTPTool::instance();
00708 if ( count( $operatorParameters ) > 0 )
00709 {
00710 $httpType = EZ_HTTP_OPERATOR_TYPE_POST;
00711 $httpName = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace );
00712 if ( count( $operatorParameters ) > 1 )
00713 {
00714 $httpTypeName = strtolower( $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ) );
00715 if ( $httpTypeName == 'post' )
00716 $httpType = EZ_HTTP_OPERATOR_TYPE_POST;
00717 else if ( $httpTypeName == 'get' )
00718 $httpType = EZ_HTTP_OPERATOR_TYPE_GET;
00719 else if ( $httpTypeName == 'session' )
00720 $httpType = EZ_HTTP_OPERATOR_TYPE_SESSION;
00721 else
00722 $tpl->warning( $operatorName, "Unknown http type '$httpTypeName'" );
00723 }
00724
00725
00726
00727
00728
00729 if ( $operatorName == $this->HTTPNameHasVariable )
00730 {
00731 $checkExistence = true;
00732 }
00733 else
00734 {
00735 $checkExistence = isset( $operatorParameters[2] )
00736 ? ( $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ) === true or
00737 $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ) == 'hasVariable' ) ? true : false
00738 : false;
00739 }
00740 switch( $httpType )
00741 {
00742 case EZ_HTTP_OPERATOR_TYPE_POST:
00743 {
00744 if ( $http->hasPostVariable( $httpName ) )
00745 $operatorValue = !$checkExistence ? $http->postVariable( $httpName ) : true;
00746 else
00747 {
00748
00749 if ( $checkExistence )
00750 {
00751 $operatorValue = false;
00752 return;
00753 }
00754 $tpl->error( $operatorName, "Unknown post variable '$httpName'" );
00755 }
00756 } break;
00757 case EZ_HTTP_OPERATOR_TYPE_GET:
00758 {
00759 if ( $http->hasGetVariable( $httpName ) )
00760 $operatorValue = !$checkExistence ? $http->getVariable( $httpName ) : true;
00761 else
00762 {
00763 if ( $checkExistence )
00764 {
00765 $operatorValue = false;
00766 return;
00767 }
00768 $tpl->error( $operatorName, "Unknown get variable '$httpName'" );
00769 }
00770 } break;
00771 case EZ_HTTP_OPERATOR_TYPE_SESSION:
00772 {
00773 if ( $http->hasSessionVariable( $httpName ) )
00774 $operatorValue = !$checkExistence ? $http->sessionVariable( $httpName ) : true;
00775 else
00776 {
00777 if ( $checkExistence )
00778 {
00779 $operatorValue = false;
00780 return;
00781 }
00782 $tpl->error( $operatorName, "Unknown session variable '$httpName'" );
00783 }
00784 } break;
00785 }
00786 }
00787 else
00788 {
00789 $operatorValue = $http;
00790 }
00791 return;
00792 } break;
00793
00794 case $this->URLName:
00795 {
00796 include_once( 'lib/ezutils/classes/ezuri.php' );
00797 eZURI::transformURI( $operatorValue, false, $namedParameters['server_url'] );
00798
00799 } break;
00800
00801 case $this->URLRootName:
00802 {
00803 if ( preg_match( "#^[a-zA-Z0-9]+:#", $operatorValue ) or
00804 substr( $operatorValue, 0, 2 ) == '//' )
00805 break;
00806 if ( strlen( $operatorValue ) > 0 and
00807 $operatorValue[0] != '/' )
00808 $operatorValue = '/' . $operatorValue;
00809
00810
00811 include_once( 'lib/ezutils/classes/ezuri.php' );
00812 eZURI::transformURI( $operatorValue, true, $namedParameters['server_url'] );
00813
00814 } break;
00815
00816 case $this->SysName:
00817 {
00818 if ( count( $operatorParameters ) == 0 )
00819 $tpl->warning( 'eZURLOperator' . $operatorName, 'Requires attributename' );
00820 else
00821 {
00822 $sysAttribute = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace );
00823 if ( !$this->Sys->hasAttribute( $sysAttribute ) )
00824 $tpl->warning( 'eZURLOperator' . $operatorName, "No such attribute '$sysAttribute' for eZSys" );
00825 else
00826 $operatorValue = $this->Sys->attribute( $sysAttribute );
00827 }
00828 return;
00829 } break;
00830
00831 case $this->ImageName:
00832 {
00833 $ini =& eZINI::instance();
00834 $no_slash_prefix = false;
00835 if ( count( $operatorParameters ) == 2 )
00836 {
00837 if ( $operatorParameters[1] == true && strlen( $this->Sys->wwwDir() ) == 0 )
00838 $no_slash_prefix = true;
00839 }
00840
00841 $bases = eZTemplateDesignResource::allDesignBases();
00842
00843 $imageFound = false;
00844 foreach ( $bases as $base )
00845 {
00846 $possiblePath = $base . '/images/' . $operatorValue;
00847 if ( file_exists( $possiblePath ) )
00848 {
00849 if ( $no_slash_prefix == true )
00850 $operatorValue = $possiblePath;
00851 else
00852 $operatorValue = $this->Sys->wwwDir() . '/' . $possiblePath;
00853 $imageFound = true;
00854 break;
00855 }
00856 }
00857
00858 if ( !$imageFound )
00859 {
00860 $tpl->warning( $operatorName, "Image '$operatorValue' does not exist in any design" );
00861 $siteDesign = eZTemplateDesignResource::designSetting( 'site' );
00862 $operatorValue = "design/$siteDesign/images/$operatorValue";
00863 }
00864
00865 $operatorValue = htmlspecialchars( $operatorValue );
00866 } break;
00867
00868 case $this->ExtName:
00869 {
00870 include_once( 'kernel/classes/datatypes/ezurl/ezurl.php' );
00871 $urlMD5 = md5( $operatorValue );
00872 $url = eZURL::urlByMD5( $urlMD5 );
00873 if ( $url === false )
00874 eZURL::registerURL( $operatorValue );
00875 else
00876 $operatorValue = $url;
00877 } break;
00878
00879 case $this->DesignName:
00880 {
00881 $matches = eZTemplateDesignResource::fileMatchingRules( false, $operatorValue );
00882
00883 $designResource =& eZTemplateDesignResource::instance();
00884 $matchKeys = $designResource->keys();
00885 $matchedKeys = array();
00886
00887 include_once( 'kernel/common/ezoverride.php' );
00888 $match = eZOverride::selectFile( $matches, $matchKeys, $matchedKeys, "#^(.+)/(.+)(\.[a-zA-Z0-9]+)$#" );
00889 if ( $match === null )
00890 {
00891 $tpl->warning( $operatorName, "Design element $operatorValue does not exist in any design" );
00892 $siteDesign = eZTemplateDesignResource::designSetting( 'site' );
00893 $file = "design/$siteDesign/$operatorValue";
00894 }
00895 else
00896 $file = $match["file"];
00897
00898 $operatorValue = $this->Sys->wwwDir() . "/$file";
00899 $operatorValue = htmlspecialchars( $operatorValue );
00900
00901 } break;
00902 }
00903 $quote = "\"";
00904 $val = $namedParameters['quote_val'];
00905 if ( $val == 'single' )
00906 $quote = "'";
00907 else if ( $val == 'no' )
00908 $quote = false;
00909
00910 include_once( 'lib/ezutils/classes/ezhttptool.php' );
00911 $http =& eZHTTPTool::instance();
00912
00913 if ( isset( $http->UseFullUrl ) and $http->UseFullUrl
00914 and strncasecmp( $operatorValue, '/' , 1 ) === 0 )
00915 {
00916 $operatorValue = $http->createRedirectUrl( $operatorValue, array( 'pre_url' => false ) );
00917 }
00918 if ( $quote !== false )
00919 $operatorValue = $quote . $operatorValue . $quote;
00920 }
00921
00922 var $Operators;
00923 var $URLName, $URLRootName, $DesignName, $ImageName;
00924 var $Sys;
00925 };
00926
00927 ?>