continue;
}
- try {
- $pushed = $GLOBALS['registry']->pushApp($app);
- } catch (Horde_Exception $e) {
- continue;
- }
-
$blockdir = $GLOBALS['registry']->get('fileroot', $app) . '/lib/Block';
- $dh = @opendir($blockdir);
- if (is_resource($dh)) {
- while (($file = readdir($dh)) !== false) {
- if (substr($file, -4) == '.php') {
- $block_name = null;
- $block_type = null;
- if (is_readable($blockdir . '/' . $file)) {
- include_once $blockdir . '/' . $file;
- }
- if (!is_null($block_type) && !is_null($this->_type) &&
- $block_type != $this->_type) {
- continue;
- }
- if (!empty($block_name)) {
- $this->_blocks[$app][substr($file, 0, -4)]['name'] = $block_name;
- }
+ if (file_exists($blockdir)) {
+ try {
+ $pushed = $GLOBALS['registry']->pushApp($app);
+ } catch (Horde_Exception $e) {
+ continue;
+ }
+
+ $d = dir($blockdir);
+ while (($file = $d->read()) !== false) {
+ if (substr($file, -4) != '.php') {
+ continue;
+ }
+
+ $block_name = $block_type = null;
+
+ if (is_readable($blockdir . '/' . $file)) {
+ include_once $blockdir . '/' . $file;
+ }
+
+ if (!empty($block_name) &&
+ (is_null($block_type) ||
+ is_null($this->_type) ||
+ ($block_type == $this->_type))) {
+ $this->_blocks[$app][substr($file, 0, -4)]['name'] = $block_name;
}
}
- closedir($dh);
- }
+ $d->close();
- // Don't pop an application if we didn't have to push one.
- if ($pushed) {
- $GLOBALS['registry']->popApp($app);
+ if ($pushed) {
+ $GLOBALS['registry']->popApp($app);
+ }
}
}
/**
* TODO
+ *
+ * @throws Horde_Exception
*/
public function getBlock($app, $name, $params = null, $row = null,
$col = null)
{
- if ($GLOBALS['registry']->get('status', $app) == 'inactive' ||
- ($GLOBALS['registry']->get('status', $app) == 'admin' &&
+ if (($GLOBALS['registry']->get('status', $app) == 'inactive') ||
+ (($GLOBALS['registry']->get('status', $app) == 'admin') &&
!Horde_Auth::isAdmin())) {
- $error = PEAR::raiseError(sprintf(_("%s is not activated."), $GLOBALS['registry']->get('name', $app)));
- return $error;
+ throw new Horde_Exception(sprintf('%s is not activated.', $GLOBALS['registry']->get('name', $app)));
}
$path = $GLOBALS['registry']->get('fileroot', $app) . '/lib/Block/' . $name . '.php';
if (is_readable($path)) {
include_once $path;
}
+
$class = 'Horde_Block_' . $app . '_' . $name;
if (!class_exists($class)) {
- $error = PEAR::raiseError(sprintf(_("%s not found."), $class));
- return $error;
+ throw new Horde_Exception(sprintf('%s not found.', $class));
+ }
+
+ $pushed = $GLOBALS['registry']->pushApp($app);
+ $ob = new $class($params, $row, $col);
+ if ($pushed) {
+ $GLOBALS['registry']->popApp($app);
}
- return new $class($params, $row, $col);
+ return $ob;
}
/**
/* Blocks. */
/**
- * Helper method to return an instance of the Horde_Block class. This
- * should not be exposed directly in the API; it is used by
- * blockTitle() and BlockContent().
- *
- * @param string $app Block application.
- * @param string $name Block name.
- * @param array $params Block parameters.
- *
- * @return Horde_Block The Horde_Block instance.
- * @throws Horde_Exception
- */
- protected function _block($app, $name, $params = array())
- {
- $GLOBALS['registry']->pushApp($app);
- $result = Horde_Block_Collection::getBlock($app, $name, $params);
- $GLOBALS['registry']->popApp($app);
-
- return $result;
- }
-
- /**
* Returns a Horde_Block's title.
*
* @param string $app Block application.
*/
public function blockTitle($app, $name, $params = array())
{
- $block = $this->_block($app, $name, $params);
- if (is_a($block, 'PEAR_Error')) {
- return $block->getMessage();
+ try {
+ $block = Horde_Block_Collection::getBlock($app, $name, $params);
+ return $block->getTitle();
+ } catch (Horde_Exception $e) {
+ return $e->getMessage();
}
- return $block->getTitle();
}
/**
*/
public function blockContent($app, $name, $params = array())
{
- $block = $this->_block($app, $name, $params);
- if (is_a($block, 'PEAR_Error')) {
- return $block->getMessage();
+ try {
+ $block = Horde_Block_Collection::getBlock($app, $name, $params);
+ return $block->getContent();
+ } catch (Horde_Exception $e) {
+ return $e->getMessage();
}
- return $block->getContent();
}
/**
*/
public function blocks()
{
- $collection = Horde_Block_Collection::singleton();
- if (is_a($collection, 'PEAR_Error')) {
- return $collection;
- } else {
- return $collection->getBlocksList();
- }
+ return Horde_Block_Collection::singleton()->getBlocksList();
}
/* User data. */