From 0b2c1a248e4889d5df74b25bcbf93b5f9aa6b317 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Fri, 31 Jul 2009 11:59:37 -0400 Subject: [PATCH] Use the Ansel_View const'r --- ansel/lib/Ajax/Imple/Embed.php | 8 ++------ ansel/lib/api.php | 31 +++++++++++++------------------ ansel/view.php | 2 +- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/ansel/lib/Ajax/Imple/Embed.php b/ansel/lib/Ajax/Imple/Embed.php index 141791647..a6bce56c3 100644 --- a/ansel/lib/Ajax/Imple/Embed.php +++ b/ansel/lib/Ajax/Imple/Embed.php @@ -34,15 +34,11 @@ class Ansel_Ajax_Imple_Embed extends Horde_Ajax_Imple_Base /* First, determine the type of view we are asking for */ $view = empty($args['gallery_view']) ? 'Mini' : $args['gallery_view']; - - require_once ANSEL_BASE . '/lib/Views/EmbeddedRenderers/' . basename($view) . '.php'; $class = 'Ansel_View_EmbeddedRenderer_' . basename($view); if (!class_exists($class)) { - return ''; + throw new Horde_Exception(sprintf("Class definition for %s not found.", $class)); } - - $view = call_user_func(array($class, 'makeView'), $args); - + $view = new $class($args); header('Content-Type: script/javascript'); return $view->html(); } diff --git a/ansel/lib/api.php b/ansel/lib/api.php index cdfe0b3c4..a76fa38ec 100644 --- a/ansel/lib/api.php +++ b/ansel/lib/api.php @@ -1321,24 +1321,19 @@ function _ansel_renderView($params = array(), $app = null, $params['view'] = $view; $trail = array(); $return = array(); - - if (is_callable(array($classname, 'makeView'))) { - $view = call_user_func_array(array($classname, 'makeView'), array($params)); - if (is_a($view, 'PEAR_Error')) { - $return['html'] = $view->getMessage(); - $return['crumbs'] = array(); - return $return; - } - - $return['html'] = $view->html(); - if ($params['view'] == 'Gallery' || $params['view'] == 'Image') { - $trail = $view->getGalleryCrumbData(); - } - $return['crumbs'] = $trail; - + try { + $view = new $classname($params); + } catch (Horde_Exception $e) { + $return['html'] = $e->getMessage(); + $return['crumbs'] = array(); return $return; - } else { - return PEAR::raiseError(sprintf( - _("Unable to load the definition of %s."), $view)); } + $return['html'] = $view->html(); + if ($params['view'] == 'Gallery' || $params['view'] == 'Image') { + $trail = $view->getGalleryCrumbData(); + } + $return['crumbs'] = $trail; + + return $return; + } diff --git a/ansel/view.php b/ansel/view.php index d041f773e..2c6b9668d 100644 --- a/ansel/view.php +++ b/ansel/view.php @@ -12,7 +12,7 @@ require_once dirname(__FILE__) . '/lib/base.php'; $viewname = basename(Horde_Util::getFormData('view', 'Gallery')); $view = 'Ansel_View_' . $viewname; -if (!$view || !class_exists($view)) { +if (!class_exists($view)) { throw new Horde_Exception(sprintf("Could not load class definition of %s", $view)); } -- 2.11.0