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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
<?php
/**
* The abstract Horde_Block:: class represents a single block within
* the Blocks framework.
*
* $Horde: framework/Block/Block.php,v 1.33.10.5 2006/01/01 21:28:08 jan Exp $
*
* Copyright 2003-2006 Mike Cochrane <mike@graftonhall.co.nz>
* Copyright 2003-2006 Jan Schneider <jan@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 Mike Cochrane <mike@graftonhall.co.nz>
* @author Jan Schneider <jan@horde.org>
* @since Horde 3.0
* @package Horde_Block
*/
class Horde_Block {
/**
* Block specific parameters.
*
* @var array
*/
var $_params = array();
/**
* Application that this block originated from.
*
* @var string
*/
var $_app;
/**
* Constructor.
*
* @param array|boolean $params Any parameters the block needs. If false,
* the default parameter will be used.
*/
function Horde_Block($params = array())
{
if ($params === false) {
$params = $this->getParams();
foreach ($params as $name => $param) {
$this->_params[$name] = $param['default'];
}
} else {
$this->_params = $params;
}
}
/**
* Returns the application that this block belongs to.
*
* @return string The application name.
*/
function getApp()
{
return $this->_app;
}
/**
* Returns any settable parameters for this block. This is a
* static method. It does *not* reference $this->_params; that is
* for runtime parameters (the choices made from these options).
*
* @static
*
* @return array The block's configurable parameters.
*/
function getParams()
{
global $registry;
/* Switch application contexts, if necessary. Return an error
* immediately if pushApp() fails. */
$app_pushed = $registry->pushApp($this->_app);
if (is_a($app_pushed, 'PEAR_Error')) {
return $app_pushed->getMessage();
}
$params = $this->_params();
/* If we changed application context in the course of this
* call, undo that change now. */
if ($app_pushed === true) {
$registry->popApp();
}
return $params;
}
/**
* Returns the text to go in the title of this block.
*
* This function handles the changing of current application as
* needed so code is executed in the scope of the application the
* block originated from.
*
* @return string The block's title.
*/
function getTitle()
{
global $registry;
/* Switch application contexts, if necessary. Return an error
* immediately if pushApp() fails. */
$app_pushed = $registry->pushApp($this->_app);
if (is_a($app_pushed, 'PEAR_Error')) {
return $app_pushed->getMessage();
}
$title = $this->_title();
/* If we changed application context in the course of this
* call, undo that change now. */
if ($app_pushed === true) {
$registry->popApp();
}
return $title;
}
/**
* Returns the content for this block.
*
* This function handles the changing of current application as
* needed so code is executed in the scope of the application the
* block originated from.
*
* @return string The block's content.
*/
function getContent()
{
global $registry;
/* Switch application contexts, if necessary. Return an error
* immediately if pushApp() fails. */
$app_pushed = $registry->pushApp($this->_app);
if (is_a($app_pushed, 'PEAR_Error')) {
return $app_pushed->getMessage();
}
$content = $this->_content();
/* If we changed application context in the course of this
* call, undo that change now. */
if ($app_pushed === true) {
$registry->popApp();
}
return $content;
}
function buildTree(&$tree, $indent = 0, $parent = null)
{
global $registry;
/* Switch application contexts, if necessary. Return an error
* immediately if pushApp() fails. */
$app_pushed = $registry->pushApp($this->_app);
if (is_a($app_pushed, 'PEAR_Error')) {
return $app_pushed->getMessage();
}
$this->_buildTree($tree, $indent, $parent);
/* If we changed application context in the course of this
* call, undo that change now. */
if ($app_pushed === true) {
$registry->popApp();
}
}
/**
* Returns the title to go in this block.
*
* @abstract
*
* @return string The block title.
*/
function _title()
{
return '';
}
/**
* Returns the parameters needed by block.
*
* @abstract
*
* @return array The block's parameters.
*/
function _params()
{
return array();
}
/**
* Returns this block's content.
*
* @abstract
*
* @return string The block's content.
*/
function _content()
{
return '';
}
/**
* Returns this block's content.
*
* @abstract
*
* @return string The block's content.
*/
function _buildTree(&$tree, $indent = 0, $parent = null)
{
}
}
|