Use the Ansel_View const'r
authorMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 31 Jul 2009 15:59:37 +0000 (11:59 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 31 Jul 2009 15:59:37 +0000 (11:59 -0400)
ansel/lib/Ajax/Imple/Embed.php
ansel/lib/api.php
ansel/view.php

index 1417916..a6bce56 100644 (file)
@@ -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();
     }
index cdfe0b3..a76fa38 100644 (file)
@@ -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;
+
 }
index d041f77..2c6b966 100644 (file)
@@ -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));
 }