| [ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZTemplateAttributeOperator class 4 // 5 // Created on: <01-Mar-2002 13:50:09 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 /*! 30 \class eZTemplateAttributeOperator eztemplateattributeoperator.php 31 \ingroup eZTemplateOperators 32 \brief Display of variable attributes using operator "attribute" 33 34 This class allows for displaying template variable attributes. The display 35 is recursive and the number of levels can be maximized. 36 37 The operator can take three parameters. The first is the maximum number of 38 levels to recurse, if blank or omitted the maxium level is infinity. 39 The second is the type of display, if set to "text" the output is as pure text 40 otherwise as html. 41 The third is whether to show variable values or not, default is to not show. 42 43 \code 44 // Example template code 45 46 // Display attributes of $myvar 47 {$myvar|attribute} 48 // Display 2 levels of $tree 49 {$tree|attribute(2)} 50 // Display attributes and values of $item 51 {$item|attribute(,,show)} 52 \endcode 53 54 */ 55 56 class eZTemplateAttributeOperator 57 { 58 /*! 59 Initializes the object with the name $name, default is "attribute". 60 */ 61 function eZTemplateAttributeOperator( $name = "attribute" ) 62 { 63 $this->AttributeName = $name; 64 $this->Operators = array( $name ); 65 } 66 67 /*! 68 Returns the template operators. 69 */ 70 function &operatorList() 71 { 72 return $this->Operators; 73 } 74 75 function operatorTemplateHints() 76 { 77 return array( $this->AttributeName => array( 'input' => true, 78 'output' => true, 79 'parameters' => 3 ) ); 80 } 81 82 /*! 83 See eZTemplateOperator::namedParameterList() 84 */ 85 function namedParameterList() 86 { 87 return array( "show_values" => array( "type" => "string", 88 "required" => false, 89 "default" => "" ), 90 "max_val" => array( "type" => "numerical", 91 "required" => false, 92 "default" => 2 ), 93 "as_html" => array( "type" => "boolean", 94 "required" => false, 95 "default" => true ) ); 96 } 97 98 /*! 99 Display the variable. 100 */ 101 function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters ) 102 { 103 $max = $namedParameters["max_val"]; 104 $as_html = $namedParameters["as_html"]; 105 $show_values = $namedParameters["show_values"] == "show"; 106 $txt = ""; 107 $this->displayVariable( $operatorValue, $as_html, $show_values, $max, 0, $txt ); 108 if ( $as_html ) 109 { 110 $headers = "<th align=\"left\">Attribute</th>\n<th align=\"left\">Type</th>\n"; 111 if ( $show_values ) 112 $headers .= "<th align=\"left\">Value</th>\n"; 113 $operatorValue = "<table><tr>$headers</tr>\n$txt</table>\n"; 114 } 115 else 116 $operatorValue = $txt; 117 } 118 119 /*! 120 \private 121 Helper function for recursive display of attributes. 122 $value is the current variable, $as_html is true if display as html, 123 $max is the maximum number of levels, $cur_level the current level 124 and $txt is the output text which the function adds to. 125 */ 126 function displayVariable( &$value, $as_html, $show_values, $max, $cur_level, &$txt ) 127 { 128 if ( $max !== false and $cur_level >= $max ) 129 return; 130 if ( is_array( $value ) ) 131 { 132 foreach( $value as $key => $item ) 133 { 134 $type = gettype( $item ); 135 if ( is_object( $item ) ) 136 $type .= "[" . get_class( $item ) . "]"; 137 $itemValue = $item; 138 if ( is_bool( $item ) ) 139 $itemValue = $item ? "true" : "false"; 140 else if ( is_array( $item ) ) 141 $itemValue = 'Array(' . count( $item ) . ')'; 142 else if ( is_numeric( $item ) ) 143 $itemValue = $item; 144 else if ( is_string( $item ) ) 145 $itemValue = "'" . $item . "'"; 146 if ( $as_html ) 147 { 148 $spacing = str_repeat( ">", $cur_level ); 149 if ( $show_values ) 150 $txt .= "<tr><td>$spacing$key</td>\n<td>$type</td>\n<td>$itemValue</td>\n</tr>\n"; 151 else 152 $txt .= "<tr><td>$spacing$key</td>\n<td>$type</td>\n</tr>\n"; 153 } 154 else 155 { 156 $spacing = str_repeat( " ", $cur_level*4 ); 157 if ( $show_values ) 158 $txt .= "$spacing$key ($type=$item)\n"; 159 else 160 $txt .= "$spacing$key ($type)\n"; 161 } 162 $this->displayVariable( $item, $as_html, $show_values, $max, $cur_level + 1, $txt ); 163 } 164 } 165 else if ( is_object( $value ) ) 166 { 167 if ( !method_exists( $value, "attributes" ) or 168 !method_exists( $value, "attribute" ) ) 169 return; 170 $attrs = $value->attributes(); 171 foreach ( $attrs as $key ) 172 { 173 $item =& $value->attribute( $key ); 174 $type = gettype( $item ); 175 if ( is_object( $item ) ) 176 $type .= "[" . get_class( $item ) . "]"; 177 $itemValue = $item; 178 if ( is_bool( $item ) ) 179 $itemValue = $item ? "true" : "false"; 180 else if ( is_array( $item ) ) 181 $itemValue = 'Array(' . count( $item ) . ')'; 182 else if ( is_numeric( $item ) ) 183 $itemValue = $item; 184 else if ( is_string( $item ) ) 185 $itemValue = "'" . $item . "'"; 186 if ( $as_html ) 187 { 188 $spacing = str_repeat( ">", $cur_level ); 189 if ( $show_values ) 190 $txt .= "<tr><td>$spacing$key</td>\n<td>$type</td>\n<td>$itemValue</td>\n</tr>\n"; 191 else 192 $txt .= "<tr><td>$spacing$key</td>\n<td>$type</td>\n</tr>\n"; 193 } 194 else 195 { 196 $spacing = str_repeat( " ", $cur_level*4 ); 197 if ( $show_values ) 198 $txt .= "$spacing$key ($type=$item)\n"; 199 else 200 $txt .= "$spacing$key ($type)\n"; 201 } 202 $this->displayVariable( $item, $as_html, $show_values, $max, $cur_level + 1, $txt ); 203 } 204 } 205 } 206 207 /// The array of operators, used for registering operators 208 var $Operators; 209 } 210 211 ?>
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 |