[ Index ]
 

Code source de Horde 3.1.3

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

title

Body

[fermer]

/lib/Horde/ -> Block.php (source)

   1  <?php
   2  /**
   3   * The abstract Horde_Block:: class represents a single block within
   4   * the Blocks framework.
   5   *
   6   * $Horde: framework/Block/Block.php,v 1.33.10.5 2006/01/01 21:28:08 jan Exp $
   7   *
   8   * Copyright 2003-2006 Mike Cochrane <mike@graftonhall.co.nz>
   9   * Copyright 2003-2006 Jan Schneider <jan@horde.org>
  10   *
  11   * See the enclosed file COPYING for license information (LGPL). If you
  12   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  13   *
  14   * @author  Mike Cochrane <mike@graftonhall.co.nz>
  15   * @author  Jan Schneider <jan@horde.org>
  16   * @since   Horde 3.0
  17   * @package Horde_Block
  18   */
  19  class Horde_Block {
  20  
  21      /**
  22       * Block specific parameters.
  23       *
  24       * @var array
  25       */
  26      var $_params = array();
  27  
  28      /**
  29       * Application that this block originated from.
  30       *
  31       * @var string
  32       */
  33      var $_app;
  34  
  35      /**
  36       * Constructor.
  37       *
  38       * @param array|boolean $params  Any parameters the block needs. If false,
  39       *                               the default parameter will be used.
  40       */
  41      function Horde_Block($params = array())
  42      {
  43          if ($params === false) {
  44              $params = $this->getParams();
  45              foreach ($params as $name => $param) {
  46                  $this->_params[$name] = $param['default'];
  47              }
  48          } else {
  49              $this->_params = $params;
  50          }
  51      }
  52  
  53      /**
  54       * Returns the application that this block belongs to.
  55       *
  56       * @return string  The application name.
  57       */
  58      function getApp()
  59      {
  60          return $this->_app;
  61      }
  62  
  63      /**
  64       * Returns any settable parameters for this block. This is a
  65       * static method. It does *not* reference $this->_params; that is
  66       * for runtime parameters (the choices made from these options).
  67       *
  68       * @static
  69       *
  70       * @return array  The block's configurable parameters.
  71       */
  72      function getParams()
  73      {
  74          global $registry;
  75  
  76          /* Switch application contexts, if necessary. Return an error
  77           * immediately if pushApp() fails. */
  78          $app_pushed = $registry->pushApp($this->_app);
  79          if (is_a($app_pushed, 'PEAR_Error')) {
  80              return $app_pushed->getMessage();
  81          }
  82  
  83          $params = $this->_params();
  84  
  85          /* If we changed application context in the course of this
  86           * call, undo that change now. */
  87          if ($app_pushed === true) {
  88              $registry->popApp();
  89          }
  90  
  91          return $params;
  92      }
  93  
  94      /**
  95       * Returns the text to go in the title of this block.
  96       *
  97       * This function handles the changing of current application as
  98       * needed so code is executed in the scope of the application the
  99       * block originated from.
 100       *
 101       * @return string  The block's title.
 102       */
 103      function getTitle()
 104      {
 105          global $registry;
 106  
 107          /* Switch application contexts, if necessary. Return an error
 108           * immediately if pushApp() fails. */
 109          $app_pushed = $registry->pushApp($this->_app);
 110          if (is_a($app_pushed, 'PEAR_Error')) {
 111              return $app_pushed->getMessage();
 112          }
 113  
 114          $title = $this->_title();
 115  
 116          /* If we changed application context in the course of this
 117           * call, undo that change now. */
 118          if ($app_pushed === true) {
 119              $registry->popApp();
 120          }
 121  
 122          return $title;
 123      }
 124  
 125      /**
 126       * Returns the content for this block.
 127       *
 128       * This function handles the changing of current application as
 129       * needed so code is executed in the scope of the application the
 130       * block originated from.
 131       *
 132       * @return string  The block's content.
 133       */
 134      function getContent()
 135      {
 136          global $registry;
 137  
 138          /* Switch application contexts, if necessary. Return an error
 139           * immediately if pushApp() fails. */
 140          $app_pushed = $registry->pushApp($this->_app);
 141          if (is_a($app_pushed, 'PEAR_Error')) {
 142              return $app_pushed->getMessage();
 143          }
 144  
 145          $content = $this->_content();
 146  
 147          /* If we changed application context in the course of this
 148           * call, undo that change now. */
 149          if ($app_pushed === true) {
 150              $registry->popApp();
 151          }
 152  
 153          return $content;
 154      }
 155  
 156      function buildTree(&$tree, $indent = 0, $parent = null)
 157      {
 158          global $registry;
 159  
 160          /* Switch application contexts, if necessary. Return an error
 161           * immediately if pushApp() fails. */
 162          $app_pushed = $registry->pushApp($this->_app);
 163          if (is_a($app_pushed, 'PEAR_Error')) {
 164              return $app_pushed->getMessage();
 165          }
 166  
 167          $this->_buildTree($tree, $indent, $parent);
 168  
 169          /* If we changed application context in the course of this
 170           * call, undo that change now. */
 171          if ($app_pushed === true) {
 172              $registry->popApp();
 173          }
 174      }
 175  
 176      /**
 177       * Returns the title to go in this block.
 178       *
 179       * @abstract
 180       *
 181       * @return string  The block title.
 182       */
 183      function _title()
 184      {
 185          return '';
 186      }
 187  
 188      /**
 189       * Returns the parameters needed by block.
 190       *
 191       * @abstract
 192       *
 193       * @return array  The block's parameters.
 194       */
 195      function _params()
 196      {
 197          return array();
 198      }
 199  
 200      /**
 201       * Returns this block's content.
 202       *
 203       * @abstract
 204       *
 205       * @return string  The block's content.
 206       */
 207      function _content()
 208      {
 209          return '';
 210      }
 211  
 212      /**
 213       * Returns this block's content.
 214       *
 215       * @abstract
 216       *
 217       * @return string  The block's content.
 218       */
 219      function _buildTree(&$tree, $indent = 0, $parent = null)
 220      {
 221      }
 222  
 223  }


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