[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/Horde/Mobile/ -> Renderer.php (source)

   1  <?php
   2  /**
   3   * Horde_Mobile_Renderer:: framework for mobile device markup
   4   * renderers.
   5   *
   6   * $Horde: framework/Mobile/Mobile/Renderer.php,v 1.15.10.8 2006/01/01 21:28:26 jan Exp $
   7   *
   8   * Copyright 2002-2006 Chuck Hagenbuch <chuck@horde.org>
   9   *
  10   * See the enclosed file COPYING for license information (LGPL). If you
  11   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  12   *
  13   * @author  Chuck Hagenbuch <chuck@horde.org>
  14   * @since   Horde 3.0
  15   * @package Horde_Mobile
  16   */
  17  class Horde_Mobile_Renderer extends Horde_Mobile {
  18  
  19      var $_browser;
  20  
  21      function Horde_Mobile_Renderer($browser = null)
  22      {
  23          if (is_null($browser)) {
  24              $this->_browser = &new Browser();
  25          } else {
  26              $this->_browser = $browser;
  27          }
  28      }
  29  
  30      function isBrowser($agent)
  31      {
  32          return $this->_browser->isBrowser($agent);
  33      }
  34  
  35      function hasQuirk($quirk)
  36      {
  37          return $this->_browser->hasQuirk($quirk);
  38      }
  39  
  40      /**
  41       * Render any Horde_Mobile_element object. Looks for the
  42       * appropriate rendering function in the renderer; if there isn't
  43       * one, we ignore this element.
  44       *
  45       * @param Horde_Mobile_element $element  The element to render.
  46       */
  47      function renderElement(&$element)
  48      {
  49          $func = '_render' . ucfirst(str_replace('horde_mobile_', '', strtolower(get_class($element))));
  50          if (method_exists($this, $func)) {
  51              $this->$func($element);
  52          }
  53      }
  54  
  55      function _renderBlock(&$block)
  56      {
  57          if (count($block->_elements)) {
  58              echo '<p>';
  59              foreach ($block->_elements as $blockElement) {
  60                  $this->renderElement($blockElement);
  61              }
  62              echo "</p>\n";
  63          }
  64      }
  65  
  66      function _renderForm(&$form)
  67      {
  68          foreach ($form->_elements as $formElement) {
  69              $this->renderElement($formElement);
  70          }
  71      }
  72  
  73      function _renderTable(&$table)
  74      {
  75          foreach ($table->_rows as $row) {
  76              $this->_renderRow($row);
  77          }
  78      }
  79  
  80      function _renderRow(&$row)
  81      {
  82          echo '<tr>';
  83          foreach ($row->_columns as $column) {
  84              echo '<td>';
  85              // Call create function for each cellelement that is a
  86              // Horde_Mobile object.
  87              if (!is_null($column)) {
  88                  $this->renderElement($column);
  89              }
  90              echo '</td>';
  91          }
  92          echo "</tr>\n";
  93      }
  94  
  95      /**
  96       * Attempts to return a concrete Horde_Mobile_Renderer instance
  97       * based on $type.
  98       *
  99       * @param string $type      The kind of markup (html, hdml, wml) we want to
 100       *                          generate.
 101       * @param Browser $browser  The Browser object to use.
 102       * @param array $params     A hash containing any options for the renderer.
 103       *
 104       * @return Horde_Mobile_Renderer  The newly created concrete
 105       *                                Horde_Mobile_Renderer instance, or a
 106       *                                PEAR_Error object on an error.
 107       */
 108      function &factory($type, $browser = null, $params = array())
 109      {
 110          $type = basename($type);
 111  
 112          if (@file_exists(dirname(__FILE__) . '/Renderer/' . $type . '.php')) {
 113              include_once dirname(__FILE__) . '/Renderer/' . $type . '.php';
 114          } else {
 115              @include_once 'Horde/Mobile/Renderer/' . $type . '.php';
 116          }
 117  
 118          $class = 'Horde_Mobile_Renderer_' . $type;
 119          if (class_exists($class)) {
 120              $renderer = &new $class($browser, $params);
 121          } else {
 122              $renderer = PEAR::raiseError('Class definition of ' . $class . ' not found.');
 123          }
 124  
 125          return $renderer;
 126      }
 127  
 128      /**
 129       * Attempts to return a concrete Horde_Mobile_Renderer instance
 130       * based on $type. It will only create a new instance if no
 131       * renderer with the same parameters currently exists.
 132       *
 133       * @param string $type      The kind of markup (html, hdml, wml) we want to
 134       *                          generate.
 135       * @param Browser $browser  The Browser object to use.
 136       * @param array $params     A hash containing any options for the renderer.
 137       *
 138       * @return Horde_Mobile_Renderer  The newly created concrete
 139       *                                Horde_Mobile_Renderer instance, or a
 140       *                                PEAR_Error object on an error.
 141       */
 142      function &singleton($type, $browser = null, $params = array())
 143      {
 144          static $instances = array();
 145  
 146          $signature = md5(serialize(array($type, $browser, $params)));
 147          if (!isset($instances[$signature])) {
 148              $instances[$signature] = &Horde_Mobile_Renderer::factory($type, $browser, $params);
 149          }
 150  
 151          return $instances[$signature];
 152      }
 153  
 154  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7