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
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 class eZTemplatePHPOperator
00050 {
00051
00052
00053
00054 function eZTemplatePHPOperator( $php_names )
00055 {
00056 if ( !is_array( $php_names ) )
00057 $php_names = array( $php_names );
00058 $this->PHPNames = $php_names;
00059 reset( $php_names );
00060 while ( list( $key, $val ) = each( $php_names ) )
00061 {
00062 $this->Operators[] = $key;
00063 }
00064 }
00065
00066
00067
00068
00069 function &operatorList()
00070 {
00071 return $this->Operators;
00072 }
00073
00074 function operatorTemplateHints()
00075 {
00076 $hints = array();
00077 foreach ( array_keys( $this->PHPNames ) as $name )
00078 {
00079 $hints[$name] = array( 'input' => true,
00080 'output' => true,
00081 'parameters' => false,
00082 'element-transformation' => true,
00083 'transform-parameters' => true,
00084 'input-as-parameter' => 'always',
00085 'element-transformation-func' => 'phpOperatorTransformation');
00086 }
00087 return $hints;
00088 }
00089
00090 function phpOperatorTransformation( $operatorName, &$node, &$tpl, &$resourceData,
00091 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters )
00092 {
00093 $values = array();
00094 $function = $operatorName;
00095
00096 if ( ( count( $parameters ) != 1) )
00097 {
00098 return false;
00099 }
00100 $newElements = array();
00101 $phpname = $this->PHPNames[$operatorName];
00102
00103 $values[] = $parameters[0];
00104 $code = "%output% = $phpname( %1% );\n";
00105
00106 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
00107 return $newElements;
00108 }
00109
00110
00111
00112
00113 function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$value, $namedParameters, $placement )
00114 {
00115 $phpname = $this->PHPNames[$operatorName];
00116 if ( $value !== null )
00117 $operand = $value;
00118 else
00119 $operand = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
00120 $value = $phpname( $operand );
00121 }
00122
00123
00124 var $Operators;
00125
00126 var $PHPNames;
00127 }
00128
00129 ?>