HTML_Template_Flexy
[ class tree: HTML_Template_Flexy ] [ index: HTML_Template_Flexy ] [ all elements ]

Source for file Tag.php

Documentation is available at Tag.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2002 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors:  Alan Knowles <alan@akbkhome>                               |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Tag.php 329605 2013-03-01 01:59:25Z alan_k $
  20.  
  21.  
  22. $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN_TAG']['activeSelect'= false;
  23. require_once 'HTML/Template/Flexy/Element.php';
  24. /**
  25. * A standard HTML Tag = eg. Table/Body etc.
  26. *
  27. @abstract
  28. *  This is the generic HTML tag
  29. *  a simple one will have some attributes and a name.
  30. *
  31. */
  32.  
  33. class HTML_Template_Flexy_Token_Tag extends HTML_Template_Flexy_Token {
  34.         
  35.     /**
  36.     * HTML Tag: eg. Body or /Body - uppercase
  37.     *
  38.     * @var string 
  39.     * @access public
  40.     */
  41.     var $tag '';
  42.     /**
  43.     * HTML Tag: (original case)
  44.     *
  45.     * @var string 
  46.     * @access public
  47.     */
  48.     var $oTag '';
  49.     /**
  50.     * Associative array of attributes. (original case)
  51.     *
  52.     * key is the left, value is the right..
  53.     * note:
  54.     *     values are raw (eg. include "")
  55.     *     valuse can be
  56.     *                text = standard
  57.     *                array (a parsed value with flexy tags in)
  58.     *                object (normally some PHP code that generates the key as well..)
  59.     *
  60.     *
  61.     * @var array 
  62.     * @access public
  63.     */
  64.  
  65.     var $attributes = array();
  66.     
  67.     /**
  68.     * Associative array of attributes ucase to Original Case for attributes..
  69.     *
  70.     * @var array 
  71.     * @access public
  72.     */
  73.  
  74.     var $ucAttributes = array();
  75.     
  76.     
  77.     
  78.     /**
  79.     * postfix tokens
  80.     * used to add code to end of tags "<xxxx>here....children .. <close tag>"
  81.     *
  82.     * @var array 
  83.     * @access public
  84.     */
  85.     var $postfix '';
  86.      /**
  87.     * prefix tokens
  88.     * used to add code to beginning of tags TODO  "here<xxxx>....children .. <close tag>"
  89.     *
  90.     * @var array 
  91.     * @access public
  92.     */
  93.     var $prefix '';
  94.      
  95.         
  96.     /**
  97.     * Alias to closing tag (built externally).
  98.     * used to add < ? } ? > code to dynamic tags.
  99.     * @var object alias 
  100.     * @access public
  101.     */
  102.     var $close// alias to closing tag.
  103.     
  104.     
  105.     
  106.     /**
  107.     * Setvalue - gets name, attribute as an array
  108.     * @see parent::setValue()
  109.     */
  110.   
  111.     function setValue($value
  112.     {
  113.         global $_HTML_TEMPLATE_FLEXY_TOKEN;
  114.         $this->tag strtoupper($value[0]);
  115.         $this->oTag $value[0];
  116.         if (isset($value[1])) {
  117.             $this->attributes $value[1];
  118.         }
  119.         
  120.         foreach(array_keys($this->attributesas $k{
  121.             $this->ucAttributes[strtoupper($k)=&  $this->attributes[$k];
  122.         }
  123.        
  124.     }
  125.     
  126.   
  127.     
  128.     /**
  129.     * getAttribute = reads an attribute value and strips the quotes
  130.     *
  131.     * TODO
  132.     * does not handle values with flexytags in them
  133.     *
  134.     * @return   string (
  135.     * @access   public
  136.     */
  137.     function getAttribute($key{
  138.         // all attribute keys are stored Upper Case,
  139.         // however just to make sure we have not done a typo :)
  140.         $key strtoupper($key)
  141.         //echo "looking for $key\n";
  142.         //var_dump($this->attributes);
  143.         
  144.         // this is weird case isset() returns false on this being null!
  145.         //smata:
  146.         if (array_key_exists($key$this->ucAttributes&& $this->ucAttributes[$key=== true{
  147.             return true;
  148.         }
  149. //
  150. //        if (@$this->ucAttributes[$key] === true) {
  151. //            return true;
  152. //        }
  153.         
  154.         if (!isset($this->ucAttributes[$key])) {
  155.             return false;
  156.         }
  157.         // general assumption - none of the tools can do much with dynamic
  158.         // attributes - eg. stuff with flexy tags in it.
  159.         if (!is_string($this->ucAttributes[$key])) {
  160.             return false;
  161.         }
  162.         $v $this->ucAttributes[$key];
  163.          
  164.         // unlikely :)
  165.         if ($v==''{
  166.             return $v;
  167.         }
  168.         
  169.         switch($v{0}{
  170.             case "\"":
  171.             case "'":
  172.                 return substr($v,1,-1);
  173.             default:
  174.                 return $v;
  175.         }
  176.     }
  177.       
  178.     /**
  179.     * getAttributes = returns all the attributes key/value without quotes
  180.     *
  181.     *
  182.     * @return   array 
  183.     * @access   string
  184.     */
  185.     
  186.     function getAttributes({
  187.         $ret = array();
  188.         foreach($this->attributes as $k=>$v{
  189.             if (substr(strtoupper($k),0,6== 'FLEXY:'{
  190.                 continue;
  191.             }
  192.             $ret[$k$this->getAttribute($k);
  193.         }
  194.         return $ret;
  195.     }
  196.      
  197.     /**
  198.     * clearAttributes = removes an attribute from the object.
  199.     *
  200.     *
  201.     * @return   array 
  202.     * @access   string
  203.     */
  204.     function clearAttribute($string{
  205.         if (isset($this->attributes[$string])) {
  206.             unset($this->attributes[$string]);
  207.         }
  208.     }
  209.     
  210.     
  211.       /**
  212.      * used to get the contents..
  213.      */
  214.     function toString()
  215.     {
  216.         $ret '<'.$this->oTag;
  217.         foreach($this->attributes as $k=>$v{
  218.             $ret.= " " $k .'='.$v;
  219.         }
  220.         if (empty($this->children)) {
  221.             return $ret '/>';
  222.         }
  223.         $ret .= '>';
  224.         foreach($this->children as $c{
  225.             $ret .= $c->toString();
  226.         }
  227.         return $ret '</'$this->oTag .'>';
  228.     
  229.         
  230.     }
  231.     
  232.      
  233.     
  234. }

Documentation generated on Mon, 11 Mar 2019 15:59:59 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.