1: <?php
 2: /**
 3:  * Ansel_Ajax_Imple_Embed:: Class for embedding a small gallery widget in external
 4:  * websites. Meant to be called via a single script tag, therefore this will
 5:  * always return nothing but valid javascript.
 6:  *
 7:  * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
 8:  *
 9:  * @author Michael J. Rubinsky <mrubinsk@horde.org>
10:  *
11:  * @package Ansel
12:  */
13: class Ansel_Ajax_Imple_Embed extends Horde_Core_Ajax_Imple
14: {
15:     // Noop since we don't attach this to any UI element.
16:     public function attach(){}
17: 
18:     public function getUrl()
19:     {
20:         return $this->_getUrl('Embed', 'ansel', $this->_params, true);
21:     }
22: 
23:     /**
24:      * Handles the output of the embedded widget. This must always be valid
25:      * javascript.
26:      *
27:      * @see Ansel_View_Embedded for parameters.
28:      *
29:      * @param array $args  Arguments for this view.
30:      */
31:     public function handle($args, $post)
32:     {
33:         /* First, determine the type of view we are asking for */
34:         $view = empty($args['gallery_view']) ? 'Mini' : $args['gallery_view'];
35:         $class = 'Ansel_View_EmbeddedRenderer_' . basename($view);
36:         if (!class_exists($class)) {
37:             throw new Horde_Exception(sprintf("Class definition for %s not found.", $class));
38:         }
39: 
40:         try {
41:             $view = new $class($args);
42:             header('Content-Type: script/javascript');
43:             return $view->html();
44:         } catch (Exception $e) {}
45:     }
46: 
47: }
48: