⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 element.php

📁 FP2 CRM code+Mysql DB
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/* vim: set expandtab tabstop=4 shiftwidth=4: */// +----------------------------------------------------------------------+// | PHP Version 4                                                        |// +----------------------------------------------------------------------+// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group             |// +----------------------------------------------------------------------+// | This source file is subject to version 2.0 of the PHP license,       |// | that is bundled with this package in the file LICENSE, and is        |// | available at through the world-wide-web at                           |// | http://www.php.net/license/2_02.txt.                                 |// | If you did not receive a copy of the PHP license and are unable to   |// | obtain it through the world-wide-web, please send a note to          |// | license@php.net so we can mail you a copy immediately.               |// +----------------------------------------------------------------------+// | Author: Alan Knowles <alan@akbkhome.com>                             |// | Based on HTML_Common by: Adam Daniel <adaniel1@eesus.jnj.com>        |// +----------------------------------------------------------------------+//// $Id: Element.php,v 1.37 2005/10/10 05:36:08 alan_k Exp $/** * Lightweight HTML Element builder and render * * This differs from HTML_Common in the following ways: * * $element->attributes is Public * $element->override if set to anything other than false, renders the value rather than  *   the defined element * * $element->children is a recursvable child array which is rendered by toHTML * $element->toHtml() is implemented * $element->toHtmlNoClose() renders  only the first tag and children (designed for <form * No support for tab offsets, comments ... * * Full support for Select, and common Form elements using * setValue() * setOptions() *  * overlay support with SetFrom - base + inherited.. * * attributes array values: *  key="value" // standard key="value" in output *  key = true // outputs just key. * * children can be  *  another HTML_Element *  or string (raw text) * * * @author      Adam Daniel <adaniel1@eesus.jnj.com> * @version     1.6 * @since       PHP 4.0.3pl1 * @abstract */class HTML_Template_Flexy_Element {        /**     * Tag that this Element represents.     * @var  array     * @access   public     */    var $tag =  '';    /**     * Associative array of table attributes     * Note Special values:     *   true == only display the key      *   false == remove     *     * @var  array     * @access   public     */    var $attributes = array();    /**     * Sequence array of children     * children that are strings are assumed to be text      * @var  array     * @access   public     */    var $children = array();        /**     * override the tag.     * if this is set to anything other than false, it will be output      * rather than the tags+children     * @var  array     * @access   public     */    var $override = false;    /**     * prefix the tag.     * this is output by toHtml as a prefix to the tag (can be used for require tags)     * @var  array     * @access   private     */    var $prefix = '';    /**     * suffix the tag.     * this is output by toHtml as a suffix to the tag (can be used for error messages)     * @var  array     * @access   private     */    var $suffix = '';        /**     * a value for delayed merging into live objects     * if you set this on an element, it is merged by setValue, at merge time.     * @var  array     * @access   public     */    var $value = null;    /**     * Class constructor     * @param    mixed   $attributes     Associative array of table tag attributes      *                                   or HTML attributes name="value" pairs     * @access   public     */    function HTML_Template_Flexy_Element($tag='', $attributes=null)    {                $this->tag = strtolower($tag);        if (false !== strpos($tag, ':')) {            $bits = explode(':',$this->tag);            $this->tag = $bits[0] . ':'.strtolower($bits[1]);        }                $this->setAttributes($attributes);    } // end constructor          /**     * Returns an HTML formatted attribute string     * @param    array   $attributes     * @return   string     * @access   private     */    function attributesToHTML()    {        $strAttr = '';        $xhtmlclose = '';                foreach ($this->attributes as $key => $value) {                    // you shouldn't do this, but It shouldnt barf when you do..            if (is_array($value) || is_object($value)) {                continue;            }                        if ($key == 'flexy:xhtml') {                continue;            }            if ($value === false) {                continue;            }            if ($value === true) {                // this is not xhtml compatible..                if ($key == '/') {                    $xhtmlclose = ' /';                    continue;                }                if (isset($this->attributes['flexy:xhtml'])) {                    $strAttr .= " {$key}=\"{$key}\"";                } else {                    $strAttr .= ' ' . $key;                }            } else {                // dont replace & with &amp;                $strAttr .= ' ' . $key . '="' .                     str_replace('&amp;','&',htmlspecialchars($value)) . '"';            }                    }        $strAttr .= $xhtmlclose;        return $strAttr;    } // end func _getAttrString    /**     * Static Method to get key/value array from attributes.     * Returns a valid atrributes array from either a string or array     * @param    mixed   $attributes     Either a typical HTML attribute string or an associative array     * @access   private     */    function parseAttributes($attributes)    {        if (is_array($attributes)) {            $ret = array();            foreach ($attributes as $key => $value) {                if (is_int($key)) {                    $ret[strtolower($value)] = true;                } else {                    $ret[strtolower($key)]   = $value;                }            }            return $ret;        } elseif (is_string($attributes)) {            $preg = "/(([A-Za-z_:]|[^\\x00-\\x7F])([A-Za-z0-9_:.-]|[^\\x00-\\x7F])*)" .                "([ \\n\\t\\r]+)?(=([ \\n\\t\\r]+)?(\"[^\"]*\"|'[^']*'|[^ \\n\\t\\r]*))?/";            if (preg_match_all($preg, $attributes, $regs)) {                for ($counter=0; $counter<count($regs[1]); $counter++) {                    $name  = $regs[1][$counter];                    $check = $regs[0][$counter];                    $value = $regs[7][$counter];                    if (trim($name) == trim($check)) {                        $arrAttr[strtolower(trim($name))] = strtolower(trim($name));                    } else {                        if (substr($value, 0, 1) == "\"" || substr($value, 0, 1) == "'") {                            $value = substr($value, 1, -1);                        }                        $arrAttr[strtolower(trim($name))] = trim($value);                    }                }                return $arrAttr;            }        }    } // end func _parseAttributes                     /**     * Utility function to set values from common tag types.     * @param    HTML_Element   $from  override settings from another element.     * @access   public     */         function setValue($value) {        // store the value in all situations        $this->value = $value;        $tag = strtolower($this->tag);        if (strpos($tag,':') !==  false) {            $bits = explode(':',$tag);            $tag = $bits[1];        }        switch ($tag) {            case 'input':                switch (isset($this->attributes['type']) ? strtolower($this->attributes['type']) : '') {                    case 'checkbox':                        if (isset($this->attributes['checked'])) {                            unset($this->attributes['checked']);                        }                        // if value is nto set, it doesnt make any difference what you set ?                        if (!isset($this->attributes['value'])) {                            return;                        }                        //print_r($this); echo "SET TO "; serialize($value);                        if (substr($this->attributes['name'],-2) == '[]') {                            if (is_array($value) &&                                 in_array((string) $this->attributes['value'],$value)                                ) {                                $this->attributes['checked'] =  true;                            }                            return;                        }                        if ($this->attributes['value'] == $value) {                            $this->attributes['checked'] =  true;                        }                                                                        return;                    case 'radio':                        if (isset($this->attributes['checked'])) {                            unset($this->attributes['checked']);                        }                        // if we dont have values associated yet, store it..                        if (!isset($this->attributes['value'])) {                            $this->value = $value;                            return;                        }                        if ($this->attributes['value'] == $value) {                            $this->attributes['checked'] =  true;                        }                        return;                                        default:                        // no other input accepts array as a value.                        if (is_array($value)) {                            return;                        }                                            $this->attributes['value'] = $value;                        return;                }                            case 'select':                                if (!is_array($value)) {                    $value = array($value);                }                                // its setting the default value..                                foreach($this->children as $i=>$child) {                                        if (is_string($child)) {                        continue;                    }                    if ($child->tag == 'optgroup') {                        foreach($this->children[$i]->children as $ii=>$child) {                        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -