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