Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

Attributes.php

Go to the documentation of this file.
00001 <?php 00002 /* vim: set expandtab tabstop=4 shiftwidth=4: */ 00003 // 00004 // Copyright (c) 2003 Laurent Bedubourg 00005 // 00006 // This library is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU Lesser General Public 00008 // License as published by the Free Software Foundation; either 00009 // version 2.1 of the License, or (at your option) any later version. 00010 // 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public 00017 // License along with this library; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 // 00020 // Authors: Laurent Bedubourg <laurent.bedubourg@free.fr> 00021 // 00022 00056 class PHPTAL_Attribute_TAL_Attributes extends PHPTAL_Attribute 00057 { 00058 var $_overwritten = array(); 00059 00060 function activate(&$g, &$tag) 00061 { 00062 global $_phptal_xhtml_boolean_attributes; 00063 00064 $g->doPrintString('<', $tag->name()); 00065 00066 $atts = $tag->attributes(); 00067 00068 $exp = new PHPTAL_Expression($g, $tag, $this->expression); 00069 $exp->setPolicy(_PHPTAL_ES_RECEIVER_IS_TEMP); 00070 $err = $exp->prepare(); 00071 if (PEAR::isError($err)) { return $err; } 00072 00073 if ($exp->countSubs() > 0) { 00074 foreach ($exp->subs() as $sub) { 00075 $err = $this->_attributeExpression($g, $tag, $sub); 00076 if (PEAR::isError($err)) { return $err; } 00077 } 00078 } else { 00079 $err = $this->_attributeExpression($g, $tag, $exp); 00080 if (PEAR::isError($err)) { return $err; } 00081 } 00082 00083 // echo non overwritten xhtml attributes 00084 00085 foreach ($atts as $key=>$value) { 00086 $test_key = strtolower($key); 00087 if (!in_array($test_key, $this->_overwritten)) { 00088 // boolean attributes 00089 if ($tag->_parser->_outputMode() == PHPTAL_XHTML 00090 && in_array($test_key, $_phptal_xhtml_boolean_attributes)) { 00091 $g->doPrintString(' '.$key); 00092 } else { 00093 $g->doPrintString(' '.$key .'="'); 00094 $g->doPrintString($value); 00095 $g->doPrintString('"'); 00096 } 00097 } 00098 } 00099 00100 if ($tag->_isXHTMLEmptyElement()) { 00101 $g->doPrintString(' />'); 00102 return; 00103 } 00104 00105 // continue tag show 00106 if ($tag->hasContent()) { 00107 $g->doPrintString('>'); 00108 } else { 00109 $g->doPrintString('/>'); 00110 } 00111 00112 $err = $tag->generateContent($g); 00113 if (PEAR::isError($err)) { return $err; } 00114 00115 if ($tag->hasContent()) { 00116 $g->doPrintString('</', $tag->name(), '>'); 00117 } 00118 } 00119 00120 function _printAttribute(&$g, &$tag, &$realName, &$varName, $default=false) 00121 { 00122 global $_phptal_xhtml_boolean_attributes; 00123 // watch boolean attributes on XHTML mode 00124 if ($tag->_parser->_outputMode() == PHPTAL_XHTML 00125 && in_array($realName, $_phptal_xhtml_boolean_attributes)) { 00126 $g->doIf('!PEAR::isError($'.$varName.') && $'.$varName); 00127 $g->doPrintString(' '.$realName); 00128 $g->endBlock(); 00129 } elseif ($default) { 00130 $g->doIf('!PEAR::isError($'.$varName.') && false !== $'.$varName.' && null !== $'.$varName); 00131 $g->doPrintString(' '. $realName . '="'); 00132 $g->doPrintVar($varName); 00133 $g->doPrintString('"'); 00134 $g->endBlock(); 00135 } else { 00136 $g->doPrintString(' '. $realName . '="'); 00137 $g->doPrintVar($varName); 00138 $g->doPrintString('"'); 00139 } 00140 } 00141 00142 function _attributeExpression(&$g, &$tag, &$sub) 00143 { 00144 $atts = $tag->attributes(); 00145 $default = false; 00146 $name = strtolower($sub->getReceiver()); 00147 00148 // default in tal:attributes use default tag attributes 00149 // if (preg_match('/\|\s*?\bdefault\b/sm', $sub->_src)) { 00150 if (preg_match('/\bdefault\b/sm', $sub->_src)) { 00151 // ensure the attribute as a default value set in source 00152 // template 00153 $attrs = $tag->attributes(); 00154 if (!array_key_exists($name, $atts)){ 00155 $g->doAffectResult('$__default__', 'false'); 00156 } else { 00157 // store the default value in __default__ variable 00158 $g->doAffectResult('$__default__', 00159 '\''. str_replace('\'', '\\\'', $atts[$name]) . '\'' ); 00160 } 00161 $default = true; 00162 } 00163 00164 $real = str_replace('__phptales_dd__', ':', $name); 00165 $this->_overwritten[] = $real; 00166 $err = $sub->generate(); 00167 if (PEAR::isError($err)) { return $err; } 00168 00169 $this->_printAttribute($g, $tag, $real, $name, $default); 00170 } 00171 } 00172 00173 ?>

Generated on Tue Jun 29 23:40:02 2004 for Mediawiki by doxygen 1.3.7