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

Source for file Widget.php

Documentation is available at Widget.php

  1. <?php
  2. //
  3. // +---------------------------------------------------------------------------+
  4. // | PEAR :: XML :: Transformer :: Widget Namespace Handler                    |
  5. // +---------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> and |
  7. // +---------------------------------------------------------------------------+
  8. // | This source file is subject to version 3.00 of the PHP License,           |
  9. // | that is available at http://www.php.net/license/3_0.txt.                  |
  10. // | If you did not receive a copy of the PHP license and are unable to        |
  11. // | obtain it through the world-wide-web, please send a note to               |
  12. // | license@php.net so we can mail you a copy immediately.                    |
  13. // +---------------------------------------------------------------------------+
  14. //
  15. // $Id$
  16. //
  17.  
  18. require_once 'XML/Transformer/Namespace.php';
  19.  
  20. /**
  21.  * Handler for the Widget Namespace.
  22.  *
  23.  * Implements <widget:obox /> similar to http://docs.roxen.com/roxen/2.2/creator/text/obox.tag.
  24.  * Implements <widget:oboxtitle> as counterpart to <obox><title>..</title></obox> in Roxen.
  25.  *
  26.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  27.  * @author
  28.  * @copyright
  29.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  30.  * @category    XML
  31.  * @package     XML_Transformer
  32.  */
  33.     // {{{ Members
  34.     
  35.     /**
  36.     * @var    boolean 
  37.     * @access public
  38.     */
  39.     var $defaultNamespacePrefix = 'widget';
  40.  
  41.     /**
  42.     * @var    array 
  43.     * @access private
  44.     */
  45.     var $_oboxAttributes = array();
  46.  
  47.     /**
  48.     * @var    string 
  49.     * @access private
  50.     */
  51.     var $_oboxUnitPngPath "";
  52.  
  53.     /**
  54.     * @var    string 
  55.     * @access private
  56.     */
  57.     var $_oboxUnitPngURL  "/cache/unit.png";
  58.  
  59.     // }}}
  60.     // {{{ function _makeUnitPngPath()
  61.  
  62.     /**
  63.     * Create the filesystem pathname for the unitPng
  64.     *
  65.     * @return void 
  66.     * @access private
  67.     */
  68.     function _makeUnitPngPath({
  69.       $this->_oboxUnitPngPath $_SERVER['DOCUMENT_ROOT']
  70.                               . "/"
  71.                               . $this->_oboxUnitPngURL;
  72.  
  73.       return;
  74.     }
  75.  
  76.     // }}}
  77.     // {{{ function _unitPng()
  78.  
  79.     /**
  80.     * Create the transparent unitPng and return its URL
  81.     *
  82.     * @return string 
  83.     * @access private
  84.     */
  85.     function _unitpng({
  86.         if (file_exists($this->_oboxUnitPngPath)) {
  87.             return $this->_oboxUnitPngURL;
  88.         }
  89.  
  90.         $im    = ImageCreate(11);
  91.         $trans = ImageColorAllocate($im128128128);
  92.  
  93.         ImageColorTransparent($im$trans);
  94.         ImageFilledRectangle($im0,0,1,1,$trans);
  95.  
  96.         $this->_makeUnitPngPath();
  97.  
  98.         ImagePNG($im$this->_oboxUnitPngPath);
  99.         ImageDestroy($im);
  100.  
  101.         return $this->_oboxUnitURL;
  102.     }
  103.  
  104.     // }}}
  105.     // {{{ function _imagePlaceholder($h = FALSE, $w = FALSE)
  106.  
  107.     /**
  108.     * Create a placeholder image of $h pixel height and $w pixel width
  109.     *
  110.     * @param  integer 
  111.     * @param  integer 
  112.     * @return string 
  113.     * @access private
  114.     */
  115.     function _imagePlaceholder($h = FALSE$w = FALSE{
  116.         if ($h === FALSE{
  117.             $h = isset($this->_oboxAttributes['outlinewidth']$this->_oboxAttributes['outlinewidth': 1;
  118.         }
  119.  
  120.         if ($w === FALSE{
  121.             $w $h;
  122.         }
  123.  
  124.         return sprintf(
  125.           '<img src="%s" alt="" width="%s" height="%s" />',
  126.           $this->_unitpng(),
  127.           $w,
  128.           $h
  129.         );
  130.     }
  131.  
  132.     // }}}
  133.     // {{{ function _oboxGetAttr($name)
  134.  
  135.     /**
  136.     * Return value of $name suitable for attribute printing (name='value')
  137.     * or an empty string ('')
  138.     *
  139.     * @param  string 
  140.     * @return string 
  141.     * @access private
  142.     */
  143.     function _oboxGetAttr($name{
  144.         if (isset($this->_oboxAttributes[$name])) {
  145.             return sprintf(
  146.               " %s='%s'",
  147.               $name,
  148.               $this->_oboxAttributes[$name]
  149.             );
  150.         else {
  151.             return '';
  152.         }
  153.     }
  154.  
  155.     // }}}
  156.     // {{{ function _oboxGetAttrAs($name, $attributes)
  157.  
  158.     /**
  159.     * Return value of $name suitable as printable attr $attr (attr='valueofname')
  160.     * or an empty string ('')
  161.     *
  162.     * @param  string 
  163.     * @param  string 
  164.     * @return string 
  165.     * @access private
  166.     */
  167.     function _oboxGetAttrAs($name$attributes{
  168.         if (isset($this->_oboxAttributes[$name])) {
  169.             return sprintf(
  170.               " %s='%s'",
  171.               $attributes,
  172.               $this->_oboxAttributes[$name]
  173.             );
  174.         else {
  175.             return '';
  176.         }
  177.     }
  178.  
  179.     // }}}
  180.     // {{{ function _oboxGetValueWithDefault($name, $def)
  181.  
  182.     /**
  183.     * Return value of $name as value or $def, if empty.
  184.     *
  185.     * @param  string 
  186.     * @param  string 
  187.     * @return string 
  188.     * @access private
  189.     */
  190.     function _oboxGetValueWithDefault($name$def{
  191.         if (isset($this->_oboxAttributes[$name])) {
  192.             return $this->_oboxAttributes[$name];
  193.         else {
  194.             return $def;
  195.         }
  196.     }
  197.  
  198.     // }}}
  199.     // {{{ function _titlebox()
  200.  
  201.     /**
  202.     * Create the obox titlebox. Ugly.
  203.     *
  204.     * @return string 
  205.     * @access private
  206.     */
  207.     function _titlebox({
  208.         if (!isset($this->_oboxAttributes['title'])) {
  209.             return sprintf(
  210.               " <tr>\n  <td colspan='5'%s>%s</td>\n </tr>\n",
  211.               $this->_oboxGetAttrAs("outlinecolor""bgcolor"),
  212.               $this->_imagePlaceholder()
  213.             );
  214.         }
  215.  
  216.         $left      $this->_oboxGetValueWithDefault('left',      20);
  217.         $right     $this->_oboxGetValueWithDefault('right',     20);
  218.         $leftskip  $this->_oboxGetValueWithDefault('leftskip',  10);
  219.         $rightskip $this->_oboxGetValueWithDefault('rightskip'10);
  220.  
  221.         if (!isset($this->_oboxAttributes['titlecolor']&&
  222.              isset($this->_oboxAttributes['bgcolor'])) {
  223.             $this->_oboxAttributes['titlecolor'$this->_oboxAttributes['bgcolor'];
  224.         }
  225.  
  226.         $r .= sprintf(
  227.           " <tr>\n  <td>%s</td>\n  <td>%s</td>\n  <td nowrap='nowrap' rowspan='3'%s%s%s>%s%s%s</td>\n  <td>%s</td>\n  <td>%s</td>\n </tr>\n",
  228.           $this->_imagePlaceholder(1,1),
  229.           $this->_imagePlaceholder(1$left),
  230.           $this->_oboxGetAttrAs('titlealign''align'),
  231.           $this->_oboxGetAttrAs('titlevalign''valign'),
  232.           $this->_oboxGetAttrAs('titlecolor''bgcolor'),
  233.           $this->_imagePlaceholder(1$leftskip),
  234.           $this->_oboxAttributes['title'],
  235.           $this->_imagePlaceholder(1$rightskip),
  236.           $this->_imagePlaceholder(1$right),
  237.           $this->_imagePlaceholder(1,1)
  238.         );
  239.  
  240.         $r .= sprintf(
  241.           " <tr%s>\n  <td colspan='2' height='1'%s>%s</td>\n  <td colspan='2' height='1'%s>%s</td>\n </tr>\n",
  242.           $this->_oboxGetAttrAs("bgcolor""bgcolor"),
  243.           $this->_oboxGetAttrAs("outlinecolor""bgcolor"),
  244.           $this->_imagePlaceholder($this->_oboxGetValueWithDefault("outlinewidth"1)1),
  245.           $this->_oboxGetAttrAs("outlinecolor""bgcolor"),
  246.           $this->_imagePlaceholder($this->_oboxGetValueWithDefault("outlinewidth"1)1)
  247.         );
  248.  
  249.         $r .= sprintf(
  250.           " <tr%s>\n  <td%s>%s</td>\n  <td>%s</td>\n  <td>%s</td>\n  <td%s>%s</td>\n </tr>\n",
  251.           $this->_oboxGetAttrAs("bgcolor""bgcolor"),
  252.           $this->_oboxGetAttrAs('outlinecolor''bgcolor'),
  253.           $this->_imagePlaceholder(1$this->_oboxGetValueWithDefault("outlinewidth"1)),
  254.           $this->_imagePlaceholder(11),
  255.           $this->_imagePlaceholder(11),
  256.           $this->_oboxGetAttrAs('outlinecolor''bgcolor'),
  257.           $this->_imagePlaceholder(1$this->_oboxGetValueWithDefault("outlinewidth"1))
  258.         );
  259.  
  260.         return $r;
  261.     }
  262.  
  263.     // }}}
  264.     // {{{ function _box($cdata)
  265.  
  266.     /**
  267.     * Create the actual obox.
  268.     *
  269.     * @param  string 
  270.     * @return string 
  271.     * @access private
  272.     */
  273.     function _box($cdata{
  274.         /* Outer container */
  275.         $r  sprintf(
  276.           "<table border='0' cellpadding='0' cellspacing='0'%s%s>\n",
  277.           $this->_oboxGetAttr("align"),
  278.           $this->_oboxGetAttr("width")
  279.         );
  280.  
  281.         /* Title */
  282.         $r .= $this->_titlebox();
  283.  
  284.         /* Content container */
  285.         $r .= sprintf(
  286.           " <tr%s>\n",
  287.           $this->_oboxGetAttr("bgcolor")
  288.         );
  289.  
  290.         $r .= sprintf(
  291.           "  <td%s%s>%s</td>\n  <td colspan='3'>\n",
  292.           $this->_oboxGetAttrAs("outlinewidth""width"),
  293.           $this->_oboxGetAttrAs("outlinecolor""bgcolor"),
  294.           $this->_imagePlaceholder(1$this->_oboxGetValueWithDefault("outlinewidth"1))
  295.         );
  296.  
  297.         $r .= sprintf(
  298.           "<table %s%s border='0' cellspacing='0' cellpadding='%s'><tr><td%s%s>%s</td></tr></table>\n  </td>\n",
  299.           $this->_oboxGetAttrAs("contentwidth""width"),
  300.           $this->_oboxGetAttrAs("contentheight""height"),
  301.           $this->_oboxGetValueWithDefault("contentpadding"0),
  302.           $this->_oboxGetAttrAs("contentalign""align"),
  303.           $this->_oboxGetAttrAs("contentvalign""valign"),
  304.           $cdata
  305.         );
  306.  
  307.         $r .= sprintf(
  308.           "  <td%s%s>%s</td>\n </tr>\n",
  309.           $this->_oboxGetAttrAs("outlinewidth""width"),
  310.           $this->_oboxGetAttrAs("outlinecolor""bgcolor"),
  311.           $this->_imagePlaceholder(1$this->_oboxGetValueWithDefault("outlinewidth"1))
  312.         );
  313.  
  314.         /* Footer line */
  315.         $r .= sprintf(
  316.           " <tr>\n  <td colspan='5'%s>%s</td>\n </tr>\n</table>\n",
  317.           $this->_oboxGetAttrAs("outlinecolor""bgcolor"),
  318.           $this->_imagePlaceholder()
  319.         );
  320.  
  321.         return $r;
  322.     }
  323.  
  324.     // }}}
  325.     // {{{ function start_obox($attributes)
  326.  
  327.     /**
  328.     * <obox /> -- This container creates an outlined box.
  329.     *
  330.     * The outer Table is controlled by
  331.     *   align=...
  332.     *   width=...
  333.     *
  334.     * The title is controlled by
  335.     *   title=...
  336.     *   titlealign=...
  337.     *   titlevalign=...
  338.     *   titlecolor=...
  339.     *
  340.     * The outline is controlled by
  341.     *   outlinecolor=...
  342.     *   outlinewidth=...
  343.     *   left=...
  344.     *   leftskip=...
  345.     *   right=...
  346.     *   rightskip=...
  347.     *
  348.     * The inner table cell is controlled by
  349.     *   contentalign=...
  350.     *   contentvalign=...
  351.     *   contentpadding=...
  352.     *   contentwidth=...
  353.     *   contentheight=...
  354.     *   bgcolor=...
  355.     *
  356.     * @param  string 
  357.     * @return string 
  358.     * @access public
  359.     */
  360.     function start_obox($attributes{
  361.         $this->_oboxAttributes $attributes;
  362.  
  363.         return '';
  364.     }
  365.  
  366.     // }}}
  367.     // {{{ function end_obox($cdata)
  368.  
  369.     /**
  370.     * @param  string 
  371.     * @return string 
  372.     * @access public
  373.     */
  374.     function end_obox($cdata{
  375.         return $this->_box($cdata);
  376.     }
  377.  
  378.     // }}}
  379.     // {{{ function start_oboxtitle($attributes)
  380.  
  381.     /**
  382.     * <oboxtitle /> -- Alternate method to set the obox title
  383.     *
  384.     * align=...
  385.     * valign=...
  386.     *
  387.     * @param  string 
  388.     * @return string 
  389.     * @access public
  390.     */
  391.     function start_oboxtitle($attributes{
  392.         if (isset($attributes['align'])) {
  393.             $this->_oboxAttributes['titlealign'$attributes['align'];
  394.         }
  395.  
  396.         if (isset($attributes['valign'])) {
  397.             $this->_oboxAttributes['titlevalign'$attributes['valign'];
  398.         }
  399.  
  400.         if (isset($attributes['bgcolor'])) {
  401.             $this->_oboxAttributes['titlecolor'$attributes['bgcolor'];
  402.         }
  403.  
  404.         return '';
  405.     }
  406.  
  407.     // }}}
  408.     // {{{ function end_oboxtitle($cdata)
  409.  
  410.     /**
  411.     * @param  string 
  412.     * @return string 
  413.     * @access public
  414.     */
  415.     function end_oboxtitle($cdata{
  416.         $this->_oboxAttributes['title'$cdata;
  417.  
  418.         return '';
  419.     }
  420.  
  421.     // }}}
  422. }
  423.  
  424. /*
  425.  * vim600:  et sw=2 ts=2 fdm=marker
  426.  * vim<600: et sw=2 ts=2
  427.  */
  428. ?>

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