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
00050
00051
00052
00053
00054
00055
00056
00057
00058 class eZTemplateAttributeOperator
00059 {
00060
00061
00062
00063 function eZTemplateAttributeOperator( $name = "attribute" )
00064 {
00065 $this->AttributeName = $name;
00066 $this->Operators = array( $name );
00067 }
00068
00069
00070
00071
00072 function &operatorList()
00073 {
00074 return $this->Operators;
00075 }
00076
00077 function operatorTemplateHints()
00078 {
00079 return array( $this->AttributeName => array( 'input' => true,
00080 'output' => true,
00081 'parameters' => 3 ) );
00082 }
00083
00084
00085
00086
00087 function namedParameterList()
00088 {
00089 return array( "show_values" => array( "type" => "string",
00090 "required" => false,
00091 "default" => "" ),
00092 "max_val" => array( "type" => "numerical",
00093 "required" => false,
00094 "default" => 2 ),
00095 "as_html" => array( "type" => "boolean",
00096 "required" => false,
00097 "default" => true ) );
00098 }
00099
00100
00101
00102
00103 function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters )
00104 {
00105 $max = $namedParameters["max_val"];
00106 $as_html = $namedParameters["as_html"];
00107 $show_values = $namedParameters["show_values"] == "show";
00108 $txt = "";
00109 $this->displayVariable( $operatorValue, $as_html, $show_values, $max, 0, $txt );
00110 if ( $as_html )
00111 {
00112 $headers = "<th align=\"left\">Attribute</th>\n<th align=\"left\">Type</th>\n";
00113 if ( $show_values )
00114 $headers .= "<th align=\"left\">Value</th>\n";
00115 $operatorValue = "<table><tr>$headers</tr>\n$txt</table>\n";
00116 }
00117 else
00118 $operatorValue = $txt;
00119 }
00120
00121
00122
00123
00124
00125
00126
00127
00128 function displayVariable( &$value, $as_html, $show_values, $max, $cur_level, &$txt )
00129 {
00130 if ( $max !== false and $cur_level >= $max )
00131 return;
00132 if ( is_array( $value ) )
00133 {
00134 foreach( $value as $key => $item )
00135 {
00136 $type = gettype( $item );
00137 if ( is_object( $item ) )
00138 $type .= "[" . get_class( $item ) . "]";
00139 $itemValue = $item;
00140 if ( is_bool( $item ) )
00141 $itemValue = $item ? "true" : "false";
00142 else if ( is_array( $item ) )
00143 $itemValue = 'Array(' . count( $item ) . ')';
00144 else if ( is_numeric( $item ) )
00145 $itemValue = $item;
00146 else if ( is_string( $item ) )
00147 $itemValue = "'" . $item . "'";
00148 if ( $as_html )
00149 {
00150 $spacing = str_repeat( ">", $cur_level );
00151 if ( $show_values )
00152 $txt .= "<tr><td>$spacing$key</td>\n<td>$type</td>\n<td>$itemValue</td>\n</tr>\n";
00153 else
00154 $txt .= "<tr><td>$spacing$key</td>\n<td>$type</td>\n</tr>\n";
00155 }
00156 else
00157 {
00158 $spacing = str_repeat( " ", $cur_level*4 );
00159 if ( $show_values )
00160 $txt .= "$spacing$key ($type=$item)\n";
00161 else
00162 $txt .= "$spacing$key ($type)\n";
00163 }
00164 $this->displayVariable( $item, $as_html, $show_values, $max, $cur_level + 1, $txt );
00165 }
00166 }
00167 else if ( is_object( $value ) )
00168 {
00169 if ( !method_exists( $value, "attributes" ) or
00170 !method_exists( $value, "attribute" ) )
00171 return;
00172 $attrs = $value->attributes();
00173 foreach ( $attrs as $key )
00174 {
00175 $item =& $value->attribute( $key );
00176 $type = gettype( $item );
00177 if ( is_object( $item ) )
00178 $type .= "[" . get_class( $item ) . "]";
00179 $itemValue = $item;
00180 if ( is_bool( $item ) )
00181 $itemValue = $item ? "true" : "false";
00182 else if ( is_array( $item ) )
00183 $itemValue = 'Array(' . count( $item ) . ')';
00184 else if ( is_numeric( $item ) )
00185 $itemValue = $item;
00186 else if ( is_string( $item ) )
00187 $itemValue = "'" . $item . "'";
00188 if ( $as_html )
00189 {
00190 $spacing = str_repeat( ">", $cur_level );
00191 if ( $show_values )
00192 $txt .= "<tr><td>$spacing$key</td>\n<td>$type</td>\n<td>$itemValue</td>\n</tr>\n";
00193 else
00194 $txt .= "<tr><td>$spacing$key</td>\n<td>$type</td>\n</tr>\n";
00195 }
00196 else
00197 {
00198 $spacing = str_repeat( " ", $cur_level*4 );
00199 if ( $show_values )
00200 $txt .= "$spacing$key ($type=$item)\n";
00201 else
00202 $txt .= "$spacing$key ($type)\n";
00203 }
00204 $this->displayVariable( $item, $as_html, $show_values, $max, $cur_level + 1, $txt );
00205 }
00206 }
00207 }
00208
00209
00210 var $Operators;
00211 }
00212
00213 ?>