📄 tag.php
字号:
return HTML_Template_Flexy::raiseError( "Missing Arguments: An flexy:foreach attribute was foundon Line {$this->element->line} in tag <{$this->element->tag} flexy:foreach="$foreach" .....><BR> the syntax is <sometag flexy:foreach="onarray,withvariable[,withanothervar] ><BR>", null, HTML_TEMPLATE_FLEXY_ERROR_DIE); } // does it have a closetag? if (!$this->element->close) { if ($this->element->getAttribute('/') === false) { return HTML_Template_Flexy::raiseError( "A flexy:foreach attribute was found in <{$this->element->tag} tag without a corresponding </{$this->element->tag} tag on {$_HTML_TEMPLATE_FLEXY['filename']}:{$this->element->line} ", null, HTML_TEMPLATE_FLEXY_ERROR_DIE); } // it's an xhtml tag! $this->element->postfix = array($this->element->factory("End", '', $this->element->line)); } else { $this->element->close->postfix = array($this->element->factory("End", '', $this->element->line)); } $this->element->clearAttribute('FLEXY:FOREACH'); return $foreachObj->compile($this->compiler); } /** * Reads an flexy:if attribute - * * * @return string to add to output. * @access public */ function parseAttributeIf() { // dont use the together, if is depreciated.. $if = $this->element->getAttribute('FLEXY:IF'); if ($if === false) { return ''; } if (isset($this->element->hasForeach)) { return HTML_Template_Flexy::raiseError( "You may not use FOREACH and IF tags in the same tag on Line {$this->element->line} <{$this->element->tag}>", null, HTML_TEMPLATE_FLEXY_ERROR_DIE); } // allow if="!somevar" $ifnegative = ''; if ($if{0} == '!') { $ifnegative = '!'; $if = substr($if,1); } // if="xxxxx" // if="xxxx.xxxx()" - should create a method prefixed with 'if:' // these checks should really be in the if/method class..!!! if (!preg_match('/^[_A-Z][A-Z0-9_]*(\[[0-9]+\])?((\[|%5B)[A-Z0-9_]+(\]|%5D))*'. '(\.[_A-Z][A-Z0-9_]*((\[|%5B)[A-Z0-9_]+(\]|%5D))*)*(\\([^)]*\))?$/i',$if)) { return HTML_Template_Flexy::raiseError( "IF tags only accept simple object.variable or object.method() values on Line {$this->element->line} <{$this->element->tag}> {$if}", null, HTML_TEMPLATE_FLEXY_ERROR_DIE); } if (substr($if,-1) == ')') { // grab args.. $args = substr($if,strpos($if,'(')+1,-1); // simple explode ... $args = strlen(trim($args)) ? explode(',',$args) : array(); //print_R($args); // this is nasty... - we need to check for quotes = eg. # at beg. & end.. $args_clean = array(); for ($i=0; $i<count($args); $i++) { if ($args[$i]{0} != '#') { $args_clean[] = $args[$i]; continue; } // single # - so , must be inside.. if ((strlen($args[$i]) > 1) && ($args[$i]{strlen($args[$i])-1}=='#')) { $args_clean[] = $args[$i]; continue; } $args[$i] .=',' . $args[$i+1]; // remove args+1.. array_splice($args,$i+1,1); $i--; // reparse.. } $ifObj = $this->element->factory('Method', array('if:'.$ifnegative.substr($if,0,strpos($if,'(')), $args_clean), $this->element->line); } else { $ifObj = $this->element->factory('If', $ifnegative.$if, $this->element->line); } // does it have a closetag? - you must have one - so you will have to hack in <span flexy:if=..><img></span> on tags // that do not have close tags - it's done this way to try and avoid mistakes. if (!$this->element->close) { //echo "<PRE>";print_R($this->element); if ($this->element->getAttribute('/') !== false) { $this->element->postfix = array($this->element->factory("End",'', $this->element->line)); } else { return HTML_Template_Flexy::raiseError( "An flexy:if attribute was found in <{$this->element->name} tag without a corresponding </{$this->element->name} tag on Line {$this->element->line} <{$this->element->tag}>", null, HTML_TEMPLATE_FLEXY_ERROR_DIE); } } else { $this->element->close->postfix = array($this->element->factory("End",'', $this->element->line)); } $this->element->clearAttribute('FLEXY:IF'); return $ifObj->compile($this->compiler); } /** * Reads Tags - and relays to parseTagXXXXXXX * * * @return string | false = html output or ignore (just output the tag) * @access private */ function _parseTags() { global $_HTML_TEMPLATE_FLEXY_TOKEN; // doesnt really need strtolower etc. as php functions are not case sensitive! /* always render script correctly */ if (0 == strcasecmp($this->element->tag,"script")) { return $this->parseTagScript(); } if ($this->element->getAttribute('FLEXY:DYNAMIC')) { return $this->compiler->appendPhp( $this->getElementPhp( $this->element->getAttribute('ID') ) ); } if ($this->element->getAttribute('FLEXY:IGNOREONLY') !== false) { return false; } if ($_HTML_TEMPLATE_FLEXY_TOKEN['flexyIgnore']) { return false; } $tag = $this->element->tag; if (strpos($tag,':') !== false) { $bits = explode(':',$tag); $tag = $bits[1]; } $method = 'parseTag'.$tag; if (!method_exists($this,$method)) { return false; } if (($this->element->getAttribute('NAME') === false) && ($this->element->getAttribute('ID') === false) ) { return false; } // do any of the attributes use flexy data... //foreach ($this->element->attributes as $k=>$v) { // if (is_array($v)) { // return false; // } //} //echo "call $method" . serialize($this->element->attributes). "\n"; return $this->$method(); // allow the parse methods to return output. } /** * produces the code for dynamic elements * * @return string | false = html output or ignore (just output the tag) * @access public */ function getElementPhp($id,$mergeWithName=false,$varsOnly = false) { global $_HTML_TEMPLATE_FLEXY; static $tmpId=0; if (!$id) { return HTML_Template_Flexy::raiseError( "Error:{$_HTML_TEMPLATE_FLEXY['filename']} on Line {$this->element->line} <{$this->element->tag}>: " . " Dynamic tags require an ID value", null, HTML_TEMPLATE_FLEXY_ERROR_DIE); } // dont mix and match.. if (($this->element->getAttribute('FLEXY:IF') !== false) || ($this->element->getAttribute('FLEXY:FOREACH') !== false) ) { return HTML_Template_Flexy::raiseError( "Error:{$_HTML_TEMPLATE_FLEXY['filename']} on Line {$this->element->line} <{$this->element->tag}>: " . " You can not mix flexy:if= or flexy:foreach= with dynamic form elements " . " (turn off tag to element code with flexyIgnore=0, use flexy:ignore="yes" in the tag" . " or put the conditional outside in a span tag", null, HTML_TEMPLATE_FLEXY_ERROR_DIE); } if ((strtolower($this->element->getAttribute('TYPE')) == 'checkbox' ) && (substr($this->element->getAttribute('NAME'),-2) == '[]')) { if ($this->element->getAttribute('ID') === false) { $id = 'tmpId'. (++$tmpId); $this->element->attributes['id'] = $id; $this->element->ucAttributes['ID'] = $id; } $mergeWithName = true; } if (isset($_HTML_TEMPLATE_FLEXY['elements'][$id])) { // echo "<PRE>";print_r($this);print_r($_HTML_TEMPLATE_FLEXY['elements']);echo "</PRE>"; return HTML_Template_Flexy::raiseError( "Error:{$_HTML_TEMPLATE_FLEXY['filename']} on Line {$this->element->line} in Tag <{$this->element->tag}>:<BR> " . "The Dynamic tag Name '$id' has already been used previously by tag <{$_HTML_TEMPLATE_FLEXY['elements'][$id]->tag}>", null,HTML_TEMPLATE_FLEXY_ERROR_DIE); } $ret = ''; $unset = ''; //echo '<PRE>';print_r($this->element);echo '</PRE>'; if (isset($this->element->ucAttributes['FLEXY:USE'])) { $ar = $this->element->ucAttributes['FLEXY:USE']; $str = ''; for($i =1; $i < count($ar) -1; $i++) { switch(true) { case is_a($ar[$i], 'HTML_Template_Flexy_Token_Var'): $str .= '. ' . $ar[$i]->toVar($ar[$i]->value). ' '; break; case is_string($ar[$i]): $str .= '. ' . $ar[0] . $ar[$i] . $ar[0]; break; default: return HTML_Template_Flexy::raiseError( "unsupported type found in attribute, use flexy:ignore to prevent parsing or remove it. " . print_r($this->element,true), null,HTML_TEMPLATE_FLEXY_ERROR_DIE); } } $str = trim(ltrim($str,'.')); $_HTML_TEMPLATE_FLEXY['elements'][$id] = $this->toElement($this->element); return $ret . ' if (!isset($this->elements['.$str.'])) { echo "ELEMENT MISSING $str"; } echo $this->elements['.$str.']->toHtml();' .$unset; } if ($this->elementUsesDynamic($this->element)) { $used = array(); foreach ($this->element->attributes as $attribute => $attributeValue) { if (!is_array($attributeValue)) { continue; } if (strtoupper(substr($attribute,0,6)) == 'FLEXY:') { continue; } unset($this->element->attributes[$attribute]); // generate code to put data into value.. $output_avar = '$this->elements[\''.$id.'\']->attributes[\''.$attribute.'\']'; $used[] = "'{$attribute}'"; $ret .= "\nif (!isset({$output_avar})) {\n"; // get the " or ' that encapsulates the element. $wrapper = array_shift($attributeValue); array_pop($attributeValue); $ret .= " {$output_avar} = '';\n"; //echo '<PRE>';print_r($attributeValue);echo '</PRE>'; foreach($attributeValue as $item) { if (is_string($item)) { $ret .= " {$output_avar} .= {$wrapper}{$item}{$wrapper};\n"; continue; } if (!is_object($item) || !is_a($item, 'HTML_Template_Flexy_Token_Var')) { return HTML_Template_Flexy::raiseError( "unsupported type found in attribute, use flexy:ignore to prevent parsing or remove it. " . print_r($this->element,true), null,HTML_TEMPLATE_FLEXY_ERROR_DIE); } $var = $item->toVar($item->value); if (is_a($var, 'PEAR_Error')) { return $var; } list($prefix,$suffix) = $this->compiler->getModifierWrapper($item); $prefix = substr($prefix,4); $ret .= " {$output_avar} .= {$prefix}{$var}{$suffix};\n"; } $ret .= "}\n"; } $ret .= "\$_attributes_used = array(".implode(',',$used).");\n"; $unset = "\n".'if (isset($_attributes_used)) { foreach($_attributes_used as $_a) {'."\n". ' unset($this->elements[\''. $id .'\']->attributes[$_a]);'."\n" . "}}\n"; } // this is for a case where you can use a sprintf as the name, and overlay it with a variable element.. $_HTML_TEMPLATE_FLEXY['elements'][$id] = $this->toElement($this->element); if ($varsOnly) { // used by form tag. return array($ret,$unset); } if ($var = $this->element->getAttribute('FLEXY:NAMEUSES')) { // force var to use name (as radio buttons pick up id.) $ename = $this->element->getAttribute('NAME'); $printfnamevar = $printfvar = 'sprintf(\''.$ename .'\','.$this->element->toVar($var) .')'; // support id replacement as well ... $idreplace = ''; if (strtolower($this->element->getAttribute('TYPE')) == 'radio') { $ename = $this->element->getAttribute('ID'); $printfvar = 'sprintf(\''.$ename .'\','.$this->element->toVar($var) .')'; } if ($this->element->getAttribute('ID')) { $idvar = 'sprintf(\''.$this->element->getAttribute('ID') .'\','.$this->element->toVar($var) .')'; $idreplace = '$this->elements['.$printfvar.']->attributes[\'id\'] = '.$idvar.';'; } return $ret . ' if (!isset($this->elements['.$printfvar.'])) { $this->elements['.$printfvar.']= $this->elements[\''.$id.'\']; } $this->elements['.$printfvar.'] = $this->mergeElement( $this->elements[\''.$id.'\'], $this->elements['.$printfnamevar .'] ); $this->elements['.$printfvar.']->attributes[\'name\'] = '.$printfnamevar. '; ' . $idreplace . ' echo $this->elements['.$printfvar.']->toHtml();' .$unset; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -