2016-08-31
@used-by df_xml_g()
@param string $tag
@param array(string => mixed) $contents
@param array(string => mixed) $p [optional]
@return string
2901
static function p($tag, array $contents, array $p = []) {return
		(new static([self::$P__CONTENTS => $contents, self::$P__TAG => $tag] + $p))->_p();
	}
1309900
private function parseForeignContents(string $tag, string $html): string
    {
        $remainingHtml = \ltrim($html);

        // Find all contents.
        $remainingHtml = $this->determineRemainingHtmlOfForeignContents(
            $tag,
            $html,
            $remainingHtml
        );

        // Handle no contents.
        if ($this->value === '') {
            return $remainingHtml;
        }

        if ($tag === 'script') {
            $text = new TextJs($this, $this->value);
        } elseif ($tag === 'style') {
            $text = new TextCss($this, $this->value);
        } else {
            $text = new Text($this, $this->value);
        }

        $this->children[] = $text;

        return $remainingHtml;
    }
498835
public function _compare($tag,$content,$type='eq') {
        $name       =   $tag['name'];
        $value      =   $tag['value'];
        $type       =   isset($tag['type'])?$tag['type']:$type;
        $type       =   $this->parseCondition(' '.$type.' ');
        $varArray   =   explode('|',$name);
        $name       =   array_shift($varArray);
        $name       =   $this->autoBuildVar($name);
        if(count($varArray)>0)
            $name = $this->tpl->parseVarFunction($name,$varArray);
        if('$' == substr($value,0,1)) {
            $value  =  $this->autoBuildVar(substr($value,1));
        }else {
            $value  =   '"'.$value.'"';
        }
        $parseStr   =   '<?php if(('.$name.') '.$type.' '.$value.'): ?>'.$content.'<?php endif; ?>';
        return $parseStr;
    }
583703
public static function createTag($tag, $attributes, $content = null)
    {
        $tag = strtolower($tag);

        // Build list of arguments
        $preparedAttributes = '';
        foreach ($attributes as $attributeKey => $attributeValue) {
            // Only set non-empty strings (ensures strlen(0) > 0)
            if (strlen($attributeValue) > 0) {
                $preparedAttributes .= sprintf(
                    ' %s="%s"',
                    $attributeKey,
                    Convert::raw2att($attributeValue)
                );
            }
        }

        // Check void element type
        if (in_array($tag, static::config()->get('void_elements'))) {
            if ($content) {
                throw new InvalidArgumentException("Void element \"{$tag}\" cannot have content");
            }
            return "<{$tag}{$preparedAttributes} />";
        }

        // Closed tag type
        return "<{$tag}{$preparedAttributes}>{$content}</{$tag}>";
    }
397413
public function tag($name, $content, $attributes = array())
    {
        static $instance;

        $instance = $instance ? clone $instance : new LibBaseTemplateHelperHtmlElement();
        $instance->name = $name;
        $instance->content = $content;
        $instance->attributes = $attributes;

        return $instance;
    }
133113
public function _foreach($tag,$content) {
        $name       =   $tag['name'];
        $item       =   $tag['item'];
        $key        =   !empty($tag['key'])?$tag['key']:'key';
        $name       =   $this->autoBuildVar($name);
        $parseStr   =   '<?php if(is_array('.$name.')): foreach('.$name.' as $'.$key.'=>$'.$item.'): ?>';
        $parseStr  .=   $this->tpl->parse($content);
        $parseStr  .=   '<?php endforeach; endif; ?>';

        if(!empty($parseStr)) {
            return $parseStr;
        }
        return ;
    }
103183
public function createTag($tag, $attr = NULL, $content = NULL)
    {
        $temp = '<'.$tag;
        if($attr != NULL) {
            $attr = (array) $attr;
            foreach($attr as $key => $val) {
                if(is_numeric($key)) {
                    $val = strtolower(trim($val));
                    if(isset($this->attr[$tag][$val])) {
                        $args[$val] = $this->attr[$tag][$val];
                        //$args[] = $val.($this->attr[$tag][$val] == NULL ? '' : "=\"{$this->attr[$tag][$val]}\"");
                    }
                    else {
                        $args[$val] = NULL;
                    }
                }
                else {
                    if(!isset($args[$key])) {
                        $args[$key] = $val;
                    }
                }
                if(isset($this->attr[$tag][$key])) {
                    if(is_array($this->attr[$tag][$key])) {
                        foreach($this->attr[$tag][$key] as $k => $v) {
                            if(isset($v[$val]) && !isset($args[$val])) {
                                $args[$k] = $v[$val];
                            }
                        }
                    }
                    else {
                        if(!isset($args[$val])) {
                            $args[$key] = $this->attr[$tag][$key];
                        }
                    }
                }
            }
            unset($attr);
            foreach($args as $key => $val) {
                $attr[] = $key.($val == NULL ? '' : "=\"$val\"");
            }
            unset($args);
            $args = array_unique($attr);
            $args = implode(' ', $args);
        }
        $temp .= isset($args) ? ' '.$args.'>' : '>'; 
        if($content != NULL) {
            if(is_array($content)) {
                array_walk($content, function(&$val, $key) { $val = trim($val); } );//5.3
                $content = implode("\n",$content);
                $content = explode("\n", $content);
                $content = preg_replace('/^/', "\t", $content);
                #$content = preg_filter('/^/', "@", $content);
                $content = rtrim("\n".implode("\n", $content), "\n")."\n";
            }
            $temp .= $content;
        }
        if($this->tags[$tag] === true) {
            $temp .= '</'.$tag.'>';
        }
        return $temp;
    }
1311735
public function parse(array $tag, $content) {

        // If more than 1 http:// is found in the string, possible XSS attack
        if ((mb_substr_count($content, 'http://') + mb_substr_count($content, 'https://')) > 1) {
            return null;
        }

        $tag['attributes']['src'] = $content;

        if (!empty($tag['attributes']['default'])) {
            list($width, $height) = explode('x', $tag['attributes']['default']);

            $tag['attributes']['width'] = $width;
            $tag['attributes']['height'] = $height;
        }

        if (empty($tag['attributes']['alt'])) {
            $tag['attributes']['alt'] = '';
        }

        return parent::parse($tag, $content);
    }
1125775
public function tagCompare($tag, $content)
    {
        $name  = $tag['name'];
        $value = $tag['value'];
        $type  = isset($tag['type']) ? $tag['type'] : 'eq'; // 比较类型
        $name  = $this->autoBuildVar($name);
        $flag  = substr($value, 0, 1);

        if ('$' == $flag || ':' == $flag) {
            $value = $this->autoBuildVar($value);
        } else {
            $value = '\'' . $value . '\'';
        }

        switch ($type) {
            case 'equal':
                $type = 'eq';
                break;
            case 'notequal':
                $type = 'neq';
                break;
        }
        $type     = $this->parseCondition(' ' . $type . ' ');
        $parseStr = '<?php if(' . $name . ' ' . $type . ' ' . $value . '): ?>' . $content . '<?php endif; ?>';

        return $parseStr;
    }
492580
public function _if($tag,$content) {
        $condition  =   $this->parseCondition($tag['condition']);
        $parseStr   =   '<?php if('.$condition.'): ?>'.$content.'<?php endif; ?>';
        return $parseStr;
    }
653863
protected function reserveTag($content, $tag)
    {
        if (stripos($content, '<' . $tag) !== false) {

            if (in_array(strtolower($tag), array('img'))) {
                $pattern = '~(<' . preg_quote($tag, '~') . '[^>]+\>)~i';
            } else {
                $pattern = '~(<' . preg_quote($tag, '~') . '\\b[^>]*?>[\\s\\S]*?<\\/' . preg_quote($tag, '~') . '>)~i';
            }

            return preg_replace_callback($pattern, array($this, 'placeHolder'), $content);
        }

        return $content;
    }
1246686
public function a($href = null, $contents = null)
    {
        return A::create()
            ->attributeIf($href, 'href', $href)
            ->html($contents);
    }
888417
protected static function prepare_content ($tag, $attributes) {
		$in = '';
		if (
			$tag == 'select' ||
			$tag == 'optgroup' ||
			$tag == 'datalist'
		) {
			$in = [
				'in' => $attributes['in']
			];
			if (isset($attributes['value'])) {
				$in['value'] = $attributes['value'];
			}
			unset($attributes['in'], $attributes['value']);
		} elseif (isset($attributes['in'])) {
			$in = $attributes['in'];
			unset($attributes['in']);
		}
		return [$in, $attributes];
	}
1151458
public static function tag($name, $content = NULL, Array $attributes = NULL) {
    $tag = new HTMLTag($name, $content, $attributes);
    return $tag;
  }
468061
public static function replaceTag($tag, $replacement, $content, $attributes = null)
        {
            $content = preg_replace("/<{$tag}.*?>/", "<{$replacement} {$attributes}>", $content);
            $content = preg_replace("/<\/{$tag}>/", "</{$replacement}>", $content);
            return $content;
        }
526998
public function parseXmlTag($tagLib,$tag,$attr,$content) {
        if(ini_get('magic_quotes_sybase'))
            $attr   =   str_replace('\"','\'',$attr);
        $parse      =   '_'.$tag;
        $content    =   trim($content);
        $tags       =   $tagLib->parseXmlAttr($attr,$tag);
        return $tagLib->$parse($tags,$content);
    }
972816
public static function th(
        string $content = null, 
        array $attributes = []
    ) : string 
    {
        return self::tag("th", $content, $attributes);
    }