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 class eZTemplateDigestOperator
00041 {
00042
00043
00044
00045 function eZTemplateDigestOperator()
00046 {
00047 $this->Operators = array( 'crc32', 'md5', 'rot13' );
00048 if ( function_exists( 'sha1' ) )
00049 {
00050 $this->Operators[] = 'sha1';
00051 }
00052 foreach ( $this->Operators as $operator )
00053 {
00054 $name = $operator . 'Name';
00055 $name[0] = $name[0] & "\xdf";
00056 $this->$name = $operator;
00057 }
00058 }
00059
00060
00061
00062
00063 function &operatorList()
00064 {
00065 return $this->Operators;
00066 }
00067
00068 function operatorTemplateHints()
00069 {
00070 return array( $this->Crc32Name => array( 'input' => true,
00071 'output' => true,
00072 'parameters' => false,
00073 'element-transformation' => true,
00074 'transform-parameters' => true,
00075 'input-as-parameter' => 'always',
00076 'element-transformation-func' => 'hashTransformation'),
00077 $this->Md5Name => array( 'input' => true,
00078 'output' => true,
00079 'parameters' => true,
00080 'element-transformation' => true,
00081 'transform-parameters' => true,
00082 'input-as-parameter' => 'always',
00083 'element-transformation-func' => 'hashTransformation'),
00084 $this->Sha1Name => array( 'input' => true,
00085 'output' => true,
00086 'parameters' => true,
00087 'element-transformation' => true,
00088 'transform-parameters' => true,
00089 'input-as-parameter' => 'always',
00090 'element-transformation-func' => 'hashTransformation'),
00091 $this->Rot13Name => array( 'input' => true,
00092 'output' => true,
00093 'parameters' => true,
00094 'element-transformation' => true,
00095 'transform-parameters' => true,
00096 'input-as-parameter' => 'always',
00097 'element-transformation-func' => 'hashTransformation') );
00098 }
00099
00100
00101
00102
00103 function namedParameterPerOperator()
00104 {
00105 return true;
00106 }
00107
00108
00109
00110
00111 function namedParameterList()
00112 {
00113 return false;
00114 }
00115
00116 function hashTransformation( $operatorName, &$node, &$tpl, &$resourceData,
00117 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters )
00118 {
00119 if ( ( count( $parameters ) != 1) )
00120 {
00121 return false;
00122 }
00123
00124 $code = '';
00125 $function = '';
00126 $newElements = array();
00127 $values = array( $parameters[0] );
00128
00129 switch ( $operatorName )
00130 {
00131 case 'crc32':
00132 {
00133 $code = "include_once( 'lib/ezutils/classes/ezsys.php' );\n";
00134 $function = "eZSys::ezcrc32";
00135 } break;
00136
00137 case 'rot13':
00138 {
00139 $function = 'str_rot13';
00140 } break;
00141
00142 default:
00143 {
00144 $function = $operatorName;
00145 } break;
00146 }
00147
00148 $code .= "%output% = $function( %1% );\n";
00149
00150 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
00151 return $newElements;
00152 }
00153
00154
00155
00156
00157 function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters,
00158 $placement )
00159 {
00160 $digestData = $operatorValue;
00161 switch ( $operatorName )
00162 {
00163
00164 case $this->Crc32Name:
00165 {
00166 include_once( 'lib/ezutils/classes/ezsys.php' );
00167 $operatorValue = eZSys::ezcrc32( $digestData );
00168 }break;
00169
00170
00171 case $this->Md5Name:
00172 {
00173 $operatorValue = md5( $digestData );
00174 }break;
00175
00176
00177 case $this->Sha1Name:
00178 {
00179 $operatorValue = sha1( $digestData );
00180 }break;
00181
00182
00183 case $this->Rot13Name:
00184 {
00185 $operatorValue = str_rot13( $digestData );
00186 }break;
00187
00188
00189 default:
00190 {
00191 $tpl->warning( $operatorName, "Unknown input type '$type'", $placement );
00192 } break;
00193 }
00194 }
00195
00196
00197 var $Operators;
00198 }
00199
00200 ?>