[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZTemplateTextOperator class 4 // 5 // Created on: <01-Aug-2002 11:38:40 amos> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file eztemplatetextoperator.php 30 */ 31 32 /*! 33 \class eZTemplateTextOperator eztemplatetextoperator.php 34 \brief The class eZTemplateTextOperator does 35 36 */ 37 38 class eZTemplateTextOperator 39 { 40 /*! 41 Constructor 42 */ 43 function eZTemplateTextOperator() 44 { 45 $this->Operators= array( 'concat', 'indent' ); 46 47 foreach ( $this->Operators as $operator ) 48 { 49 $name = $operator . 'Name'; 50 $name[0] = $name[0] & "\xdf"; 51 $this->$name = $operator; 52 } 53 } 54 55 /*! 56 Returns the operators in this class. 57 */ 58 function &operatorList() 59 { 60 return $this->Operators; 61 } 62 63 function operatorTemplateHints() 64 { 65 return array( $this->ConcatName => array( 'input' => true, 66 'output' => true, 67 'parameters' => true, 68 'element-transformation' => true, 69 'transform-parameters' => true, 70 'input-as-parameter' => true, 71 'element-transformation-func' => 'concatTransformation'), 72 $this->IndentName => array( 'input' => true, 73 'output' => true, 74 'parameters' => 3, 75 'element-transformation' => true, 76 'transform-parameters' => true, 77 'input-as-parameter' => true, 78 'element-transformation-func' => 'indentTransformation') ) ; 79 } 80 81 /*! 82 \return true to tell the template engine that the parameter list exists per operator type. 83 */ 84 function namedParameterPerOperator() 85 { 86 return true; 87 } 88 89 /*! 90 See eZTemplateOperator::namedParameterList 91 */ 92 function namedParameterList() 93 { 94 return array( $this->IndentName => array( 'indent_count' => array( 'type' => 'integer', 95 'required' => true, 96 'default' => false ), 97 'indent_type' => array( 'type' => 'identifier', 98 'required' => false, 99 'default' => 'space' ), 100 'indent_filler' => array( 'type' => 'string', 101 'required' => false, 102 'default' => false ) ) ); 103 } 104 105 function indentTransformation( $operatorName, &$node, &$tpl, &$resourceData, 106 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters ) 107 { 108 $values = array(); 109 $count = $type = $filler = false; 110 $paramCount = count( $parameters ); 111 112 if ( $paramCount == 4 ) 113 { 114 if ( eZTemplateNodeTool::isStaticElement( $parameters[3] ) ) 115 { 116 $filler = eZTemplateNodeTool::elementStaticValue( $parameters[3] ); 117 } 118 } 119 if ( $paramCount >= 3 ) 120 { 121 if ( eZTemplateNodeTool::isStaticElement( $parameters[2] ) ) 122 { 123 $type = eZTemplateNodeTool::elementStaticValue( $parameters[2] ); 124 if ( $type == 'space' ) 125 { 126 $filler = ' '; 127 } 128 else if ( $type == 'tab' ) 129 { 130 $filler = "\t"; 131 } 132 else if ( $type != 'custom' ) 133 { 134 $filler = ' '; 135 } 136 } 137 } 138 if ( $paramCount >= 2 ) 139 { 140 if ( eZTemplateNodeTool::isStaticElement( $parameters[1] ) ) 141 { 142 $count = eZTemplateNodeTool::elementStaticValue( $parameters[1] ); 143 } 144 if ( $paramCount < 3 ) 145 { 146 $type = 'space'; 147 $filler = ' '; 148 } 149 } 150 $newElements = array(); 151 152 if ( $count and $type and $filler ) 153 { 154 $tmpCount = 0; 155 $values[] = $parameters[0]; 156 $indentation = str_repeat( $filler, $count ); 157 $code = ( "%output% = '$indentation' . str_replace( '\n', '\n$indentation', %1% );\n" ); 158 } 159 else if ( $filler and $type ) 160 { 161 $tmpCount = 1; 162 $values[] = $parameters[0]; 163 $values[] = $parameters[1]; 164 $code = ( "%tmp1% = str_repeat( '$filler', %2% );\n" . 165 "%output% = %tmp1% . str_replace( '\n', '\n' . %tmp1%, %1% );\n" ); 166 } 167 else 168 { 169 $tmpCount = 2; 170 $code = "if ( %3% == 'tab' )\n{\n\t%tmp1% = \"\\t\";\n}\nelse "; 171 $code .= "if ( %3% == 'space' )\n{\n\t%tmp1% = ' ';\n}\nelse\n"; 172 if ( count ( $parameters ) == 4 ) 173 { 174 $code .= "{\n\t%tmp1% = %4%;\n}\n"; 175 } 176 else 177 { 178 $code.= "{\n\t%tmp1% = ' ';\n}\n"; 179 } 180 $code .= ( "%tmp2% = str_repeat( %tmp1%, %2% );\n" . 181 "%output% = %tmp2% . str_replace( '\n', '\n' . %tmp2%, %1% );\n" ); 182 foreach ( $parameters as $parameter ) 183 { 184 $values[] = $parameter; 185 } 186 } 187 188 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values, 'false', $tmpCount ); 189 return $newElements; 190 } 191 192 function concatTransformation( $operatorName, &$node, &$tpl, &$resourceData, 193 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters ) 194 { 195 $values = array(); 196 $function = $operatorName; 197 198 if ( ( count( $parameters ) < 1 ) ) 199 { 200 return false; 201 } 202 if ( ( count( $parameters ) == 1 ) and 203 eZTemplateNodeTool::isStaticElement( $parameters[0] ) ) 204 { 205 return array( eZTemplateNodeTool::createStaticElement( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) ) ); 206 } 207 $newElements = array(); 208 209 $counter = 1; 210 $code = "%output% = ( "; 211 foreach ( $parameters as $parameter ) 212 { 213 $values[] = $parameter; 214 if ( $counter > 1 ) 215 { 216 $code .= ' . '; 217 } 218 $code .= "%$counter%"; 219 $counter++; 220 } 221 $code .= " );\n"; 222 223 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values ); 224 return $newElements; 225 } 226 227 /*! 228 Handles concat and indent operators. 229 */ 230 function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters, 231 $placement ) 232 { 233 switch ( $operatorName ) 234 { 235 case $this->ConcatName: 236 { 237 $operands = array(); 238 if ( $operatorValue !== null ) 239 $operands[] = $operatorValue; 240 for ( $i = 0; $i < count( $operatorParameters ); ++$i ) 241 { 242 $operand = $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement ); 243 if ( !is_object( $operand ) ) 244 $operands[] = $operand; 245 } 246 $operatorValue = implode( '', $operands ); 247 } break; 248 case $this->IndentName: 249 { 250 $indentCount = $namedParameters['indent_count']; 251 $indentType = $namedParameters['indent_type']; 252 $filler = false; 253 switch ( $indentType ) 254 { 255 case 'space': 256 default: 257 { 258 $filler = ' '; 259 } break; 260 case 'tab': 261 { 262 $filler = "\t"; 263 } break; 264 case 'custom': 265 { 266 $filler = $namedParameters['indent_filler']; 267 } break; 268 } 269 $fillText = str_repeat( $filler, $indentCount ); 270 $operatorValue = $fillText . str_replace( "\n", "\n" . $fillText, $operatorValue ); 271 } break; 272 } 273 } 274 275 /// \privatesection 276 var $ConcatName; 277 var $Operators; 278 } 279 280 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |