PHP 5-ify Ansel_Widget and some other related changes
authorMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 31 Jul 2009 01:09:30 +0000 (21:09 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 31 Jul 2009 01:10:12 +0000 (21:10 -0400)
14 files changed:
ansel/lib/Faces.php
ansel/lib/Faces/opencv.php
ansel/lib/Views/Abstract.php
ansel/lib/Widget.php
ansel/lib/Widget/Actions.php
ansel/lib/Widget/Base.php
ansel/lib/Widget/GalleryFaces.php
ansel/lib/Widget/Geodata.php
ansel/lib/Widget/ImageFaces.php
ansel/lib/Widget/Links.php
ansel/lib/Widget/OtherGalleries.php
ansel/lib/Widget/OwnerFaces.php
ansel/lib/Widget/SimilarPhotos.php
ansel/lib/Widget/Tags.php

index 5c198bb..212a3b1 100755 (executable)
@@ -2,8 +2,6 @@
 /**
  * Face recognition class
  *
- * $Horde: ansel/lib/Faces.php,v 1.29 2009/07/14 00:25:28 mrubinsk Exp $
- *
  * @author  Duck <duck@obala.net>
  * @package Ansel
  */
index 77a87ce..0b20116 100644 (file)
@@ -15,7 +15,7 @@ class Ansel_Faces_opencv extends Ansel_Faces
     /**
      * Create instance
      */
-    function Ansel_Faces_opencv($params)
+    public function __construct($params)
     {
         $this->_defs = $params['defs'];
     }
@@ -25,13 +25,11 @@ class Ansel_Faces_opencv extends Ansel_Faces
      *
      * @param string $file Picture filename
      */
-    function _getFaces($file)
+    protected function _getFaces($file)
     {
         $result = Horde_Util::loadExtension('opencv');
         if (!$result) {
-            $err = PEAR::raiseError(_("You do not have the opencv extension enabled in PHP"));
-            Horde::logMessage($err, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return $err;
+            throw new Horde_Exception('You do not have the opencv extension enabled in PHP');
         }
         $im = cv_image_load($file);
         $haar = cv_object_load($this->_defs);
@@ -59,7 +57,7 @@ class Ansel_Faces_opencv extends Ansel_Faces
      *
      * @param int Face ID containg passed face
      */
-    function _isInFace($face, $faces)
+    protected function _isInFace($face, $faces)
     {
         foreach ($faces as $id => $rect) {
             if ($face['x'] > $rect['x'] && $face['x'] + $face['width'] < $face['x'] + $rect['width']
@@ -71,7 +69,7 @@ class Ansel_Faces_opencv extends Ansel_Faces
         return false;
     }
 
-    function _getParamsArray($face_id, $image, $rect)
+    protected function _getParamsArray($face_id, $image, $rect)
     {
         $params = array($face_id,
                 $image->id,
@@ -83,7 +81,7 @@ class Ansel_Faces_opencv extends Ansel_Faces
        return $params;
     }
 
-    function _createView($face_id, $image, $rect)
+    protected function _createView($face_id, $image, $rect)
     {
         return $this->createView($face_id,
                                 $image,
index bcf79b6..beb9b32 100644 (file)
@@ -111,7 +111,7 @@ class Ansel_View_Abstract {
     {
         echo '<div class="anselWidgets">';
         foreach ($this->_widgets as $widget) {
-            if ($widget->_render == 'auto') {
+            if ($widget->autoRender) {
                 echo $widget->html();
                 echo '<br />';
             }
index 61dedc8..1e0c11a 100644 (file)
@@ -3,8 +3,6 @@
  * Ansel_Widget:: class wraps the display of widgets to be displayed in various
  * Ansel_Views.
  *
- * $Horde: ansel/lib/Widget.php,v 1.10 2009/06/19 22:32:18 mrubinsk Exp $
- *
  * Copyright 2008-2009 The Horde Project (http://www.horde.org/)
  *
  * See the enclosed file COPYING for license information (GPL). If you
  * @author Michael J. Rubinsky <mrubinsk@horde.org>
  * @package Ansel
  */
-class Ansel_Widget {
-
-    /**
-     * Any parameters this widget will need..
-     *
-     * @var array
-     */
-    var $_params = array();
-
-    /**
-     * Reference to the Ansel_View we are attaching to
-     *
-     * @var Ansel_View
-     */
-    var $_view;
-
-    /**
-     * Holds the style definition for the gallery this view is for
-     * (or the image's parent gallery if this is for an image view).
-     *
-     * @var array
-     */
-    var $_style;
-
-    /**
-     * Title for this widget.
-     *
-     * @var string
-     */
-    var $_title;
-
-    /**
-     * Determine if this widget will be automatically rendered, or if it is
-     * the calling code's responsibility to render it.
-     *
-     * @var string
-     */
-    var $_render = 'auto';
-
+class Ansel_Widget
+{
     /**
      * Factory method for creating Ansel_Widgets
      *
-     * @param string $type   The type of widget to create.
-     * @param array $params  Any parameters the widget needs.
+     * @param string $driver  The type of widget to create.
+     * @param array $params   Any parameters the widget needs.
      *
      * @return mixed Ansel_Widget object | PEAR_Error
      */
-    function factory($type, $params = array())
+    static function factory($driver, $params = array())
     {
-        $type = basename($type);
-        $class = 'Ansel_Widget_' . $type;
-        if (!class_exists($class)) {
-            include dirname(__FILE__) . '/Widget/' . $type . '.php';
-        }
+        $driver = basename($driver);
+        $class = 'Ansel_Widget_' . $driver;
         if (class_exists($class)) {
-            $widget = new $class($params);
-            return $widget;
-        }
-
-        return PEAR::raiseError(sprintf(_("Unable to load the definition of %s."), $class));
-    }
-
-    /**
-     * Constructor
-     *
-     * @param array $params
-     * @return Ansel_Widget
-     */
-    function Ansel_Widget($params)
-    {
-        $this->_params = array_merge($params, $this->_params);
-        if (!empty($params['render'])) {
-            $this->_render = $params['render'];
+            return new $class($params);
         }
-    }
 
-    /**
-     * Attach this widget to the passed in view. Normally called
-     * by the Ansel_View once this widget is added.
-     *
-     * @param Ansel_View $view  The view to attach to
-     */
-    function attach($view)
-    {
-        $this->_view = $view;
-
-        if (!empty($this->_params['style'])) {
-            $this->_style = Ansel::getStyleDefinition($this->_params['style']);
-        } else {
-            $this->_style = $view->gallery->getStyle();
-        }
-
-        return true;
-    }
-
-    /**
-     * Get the HTML for this widget
-     *
-     * @abstract
-     */
-    function html()
-    {
-    }
-
-    /**
-     * Default HTML for the beginning of the widget.
-     *
-     * @return string
-     */
-    function _htmlBegin()
-    {
-        $html = '<div class="anselWidget" style="background-color:' . $this->_style['background'] .   ';">';
-        $html .= '<h2 class="header tagTitle">' . $this->_title . '</h2>';
-        return $html;
-    }
-
-    /**
-     * Default HTML for the end of the widget.
-     *
-     * @return string
-     */
-    function _htmlEnd()
-    {
-        return '</div>';
-    }
-
-
-    /**
-     * Determine if a particular view (Image, Gallery etc..) is supported
-     * by this widget.
-     *
-     * @TODO
-     * @param string $view  The view to check
-     *
-     * @return boolean
-     */
-    function isSupported($view)
-    {
-        return true;
+        throw new Horde_Exception('Class definition of ' . $class . ' not found.');
     }
 
 }
index a83b245..06b7269 100644 (file)
@@ -7,28 +7,33 @@
  * @author Michael J. Rubinsky <mrubinsk@horde.org>
  * @package Ansel
  */
-class Ansel_Widget_Actions extends Ansel_Widget {
+class Ansel_Widget_Actions extends Ansel_Widget_Base
+{
+    protected $_supported_views = array('Gallery');
 
-    var $_supported_views = array('Gallery');
-
-    function Ansel_Widget_Actions($params)
+    public function __construct($params)
     {
-        parent::Ansel_Widget($params);
         $this->_title = _("Gallery Actions");
+        parent::__construct($params);
     }
 
-    function html()
+    /**
+     * TODO
+     *
+     * @see ansel/lib/Widget/Ansel_Widget_Base#html()
+     */
+    public function html()
     {
-        global $registry;
         $html = $this->_htmlBegin();
         $id = $this->_view->gallery->id;
-        $galleryurl = Horde_Util::addParameter(Horde::applicationUrl('gallery.php'),
-                                                               'gallery', $id);
+        $galleryurl = Horde_Util::addParameter(Horde::applicationUrl('gallery.php'), 'gallery', $id);
 
         if ($this->_view->gallery->hasFeature('upload')) {
-            $uploadurl = Horde_Util::addParameter(Horde::applicationUrl('img/upload.php'),
-                                            array('gallery' => $id,
-                                                  'page' => !empty($this->_view->_params['page']) ? $this->_view->_params['page'] : 0));
+            $uploadurl = Horde_Util::addParameter(
+                Horde::applicationUrl('img/upload.php'),
+                array('gallery' => $id,
+                      'page' => !empty($this->_view->_params['page']) ? $this->_view->_params['page'] : 0)
+                );
         }
 
         $html .= '<ul style="list-style-type:none;">';
@@ -57,7 +62,7 @@ class Ansel_Widget_Actions extends Ansel_Widget {
 
             /* Subgalleries */
             if ($this->_view->gallery->hasFeature('subgalleries')) {
-                $html .= '<li>' . Horde::link(Horde_Util::addParameter($galleryurl, 'actionID', 'addchild'), '', 'widget') . Horde::img('add.png') . ' ' . _("Create a subgallery") . '</a></li>';
+                $html .= '<li>' . Horde::link(Horde_Util::addParameter($galleryurl, 'actionID', 'addchild'), '', 'widget') . Horde::img('add.png', '[icon]') . ' ' . _("Create a subgallery") . '</a></li>';
             }
         }
         $html .= '</ul>';
@@ -81,19 +86,19 @@ class Ansel_Widget_Actions extends Ansel_Widget {
     *
     * @return string  The HTML
     */
-    function _getGalleryActions()
+    protected function _getGalleryActions()
     {
-        global $registry, $prefs, $conf;
+        global $registry, $conf;
 
         $id = $this->_view->gallery->id;
         $galleryurl = Horde_Util::addParameter(Horde::applicationUrl('gallery.php'),
-                                                               'gallery', $id);
+                                               'gallery', $id);
 
         $selfurl = Horde::selfUrl(true, false, true);
         $count = $this->_view->gallery->countImages();
         $date = $this->_view->gallery->getDate();
 
-        $html = '<div style="display:' . (($prefs->getValue('show_actions')) ? 'block' : 'none') . ';" id="gallery-actions">';
+        $html = '<div style="display:' . (($GLOBALS['prefs']->getValue('show_actions')) ? 'block' : 'none') . ';" id="gallery-actions">';
 
         /* Attach the ajax action */
         ob_start();
@@ -119,10 +124,11 @@ class Ansel_Widget_Actions extends Ansel_Widget {
                 'url' => Ansel::getUrlFor('view', $view_params, true),
                 'title' => $this->_view->gallery->get('name'));
 
-            $url = $registry->call('bookmarks/getAddUrl', array($api_params));
-            if (!is_a($url, 'PEAR_Error')) {
-                $html .= '<li>' . Horde::link($url, '', 'widget') . Horde::img('trean.png', '', '', $registry->getImageDir('trean')) . ' ' . _("Add to bookmarks") . '</a></li>';
-            }
+            try {
+                $url = $registry->bookmarks->getAddUrl(array($api_params));
+            } catch (Horde_Exception $e) {}
+
+            $html .= '<li>' . Horde::link($url, '', 'widget') . Horde::img('trean.png', '', '', $registry->getImageDir('trean')) . ' ' . _("Add to bookmarks") . '</a></li>';
         }
 
         /* Download as ZIP link */
@@ -177,7 +183,7 @@ class Ansel_Widget_Actions extends Ansel_Widget {
                    $conf['report_content']['allow'] == 'all')) {
 
             $reporturl = Horde_Util::addParameter(Horde::applicationUrl('report.php'),
-                                            'gallery', $id);
+                                                  'gallery', $id);
             $html .= '<li>' . Horde::link($reporturl, '', 'widget') . ' ' . _("Report") . "</a></li>\n";
         }
 
index b3d9bbc..ae33827 100644 (file)
@@ -1 +1,138 @@
 <?php
+/**
+ * Ansel_Widget:: class wraps the display of widgets to be displayed in various
+ * Ansel_Views.
+ *
+ * $Horde: ansel/lib/Widget.php,v 1.10 2009/06/19 22:32:18 mrubinsk Exp $
+ *
+ * Copyright 2008-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Ansel
+ */
+abstract class Ansel_Widget_Base
+{
+    /**
+     * Any parameters this widget will need..
+     *
+     * @var array
+     */
+    protected $_params = array();
+
+    /**
+     * Reference to the Ansel_View we are attaching to
+     *
+     * @var Ansel_View
+     */
+    protected $_view;
+
+    /**
+     * Holds the style definition for the gallery this view is for
+     * (or the image's parent gallery if this is for an image view).
+     *
+     * @var array
+     */
+    protected $_style;
+
+    /**
+     * Title for this widget.
+     *
+     * @var string
+     */
+    protected $_title;
+
+    /**
+     * Determine if this widget will be automatically rendered, or if it is
+     * the calling code's responsibility to render it.
+     *
+     * @var string
+     */
+    protected $_autoRender = true;
+
+    /**
+     * Constructor
+     *   render
+     *   style
+     * @param array $params
+     * @return Ansel_Widget
+     */
+    public function __construct($params)
+    {
+        $this->_params = $params;
+        if (!empty($params['render'])) {
+            $this->_autoRender = ($params['render'] == 'auto');
+        }
+    }
+
+    /**
+     * Attach this widget to the passed in view. Normally called
+     * by the Ansel_View once this widget is added.
+     *
+     * @param Ansel_View $view  The view to attach to
+     */
+    public function attach($view)
+    {
+        $this->_view = $view;
+        if (!empty($this->_params['style'])) {
+            $this->_style = Ansel::getStyleDefinition($this->_params['style']);
+        } else {
+            $this->_style = $view->gallery->getStyle();
+        }
+
+        return true;
+    }
+
+    public function __get($property)
+    {
+        switch ($property) {
+        case 'autoRender':
+            return $this->_autoRender;
+        }
+    }
+
+    /**
+     * Get the HTML for this widget
+     */
+    abstract public function html();
+
+    /**
+     * Default HTML for the beginning of the widget.
+     *
+     * @return string
+     */
+    protected function _htmlBegin()
+    {
+        $html = '<div class="anselWidget" style="background-color:' . $this->_style['background'] .   ';">';
+        $html .= '<h2 class="header tagTitle">' . $this->_title . '</h2>';
+        return $html;
+    }
+
+    /**
+     * Default HTML for the end of the widget.
+     *
+     * @return string
+     */
+    protected function _htmlEnd()
+    {
+        return '</div>';
+    }
+
+
+    /**
+     * Determine if a particular view (Image, Gallery etc..) is supported
+     * by this widget.
+     *
+     * @TODO
+     * @param string $view  The view to check
+     *
+     * @return boolean
+     */
+    protected function isSupported($view)
+    {
+        return true;
+    }
+
+}
index 477434d..ec880b7 100644 (file)
@@ -3,8 +3,6 @@
  * Horde_Widget_GalleryFaces:: class to display a widget containing mini
  * thumbnails of faces in the gallery.
  *
- * $Horde: ansel/lib/Widget/GalleryFaces.php,v 1.6 2009/07/08 18:28:46 slusarz Exp $
- *
  * Copyright 2008-2009 The Horde Project (http://www.horde.org/)
  *
  * @author Duck <duck@obala.net>
  *
  * @package Ansel
  */
-class Ansel_Widget_GalleryFaces extends Ansel_Widget {
-
+class Ansel_Widget_GalleryFaces extends Ansel_Widget_Base
+{
     /**
      * @TODO
      *
      * @var unknown_type
      */
-    var $_supported_views = array('Gallery');
+    protected $_supported_views = array('Gallery');
 
     /**
      * Constructor
@@ -27,9 +25,9 @@ class Ansel_Widget_GalleryFaces extends Ansel_Widget {
      * @param array $params  Any parameters for this widget
      * @return Ansel_Widget_ImageFaces
      */
-    function Ansel_Widget_GalleryFaces($params)
+    public function __construct($params)
     {
-        parent::Ansel_Widget($params);
+        parent::__construct($params);
         $this->_title = _("People in this gallery");
     }
 
@@ -38,8 +36,9 @@ class Ansel_Widget_GalleryFaces extends Ansel_Widget {
      *
      * @return string  The HTML for this widget.
      */
-    function html()
-    {   if ($GLOBALS['conf']['faces']['driver']) {
+    public function html()
+    {
+        if ($GLOBALS['conf']['faces']['driver']) {
             $html = $this->_getFaceNames();
             return $this->_htmlBegin() . $html . $this->_htmlEnd();
         } else {
@@ -52,18 +51,14 @@ class Ansel_Widget_GalleryFaces extends Ansel_Widget {
      *
      * @return string  The HTML
      */
-    function _getFaceNames()
+    protected function _getFaceNames()
     {
         if ($this->_view->resource->get('faces')) {
             return '<div id="faces_widget_content">'
                     . '<br /><em>' . _("No faces found") . '</em></div>';
         }
 
-        require_once ANSEL_BASE . '/lib/Faces.php';
         $faces = Ansel_Faces::factory();
-        if (is_a($faces, 'PEAR_Error')) {
-            return $faces->getMessage();
-        }
 
         // Check for existing faces for this gallery.
         $html = '<div style="display: block'
@@ -71,9 +66,7 @@ class Ansel_Widget_GalleryFaces extends Ansel_Widget {
             . ';width:100%;max-height:300px;overflow:auto;" id="faces_widget_content" >';
 
         $images = $faces->getGalleryFaces($this->_view->resource->id);
-        if (is_a($images, 'PEAR_Error')) {
-            return $images->getMessage();
-        }
+
 
         if ($this->_view->gallery->hasPermission(Horde_Auth::getAuth(), PERMS_EDIT)) {
             $link_text = (empty($images) ? _("Find faces") : _("Edit faces"));
index 113e973..364705e 100644 (file)
@@ -8,22 +8,25 @@
  * See the enclosed file COPYING for license information (GPL). If you
  * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  *
+ * @TODO: Refactor the JS out to a seperate file, output needed values in the
+ *        GLOBAL Ansel javascript object.
+ *
  * @author Michael J. Rubinsky <mrubinsk@horde.org>
  * @package Ansel
  */
-class Ansel_Widget_Geodata extends Ansel_Widget {
-
-    var $_supported_views = array('Image', 'Gallery');
-    var $_params = array('default_zoom' => 15,
-                         'max_auto_zoom' => 15);
+class Ansel_Widget_Geodata extends Ansel_Widget_Base
+{
+    protected $_supported_views = array('Image', 'Gallery');
+    protected $_params = array('default_zoom' => 15,
+                               'max_auto_zoom' => 15);
 
-    function Ansel_Widget_Geodata($params)
+    public function __construct($params)
     {
-        parent::Ansel_Widget($params);
+        parent::__construct($params);
         $this->_title = _("Location");
     }
 
-    function attach($view)
+    public function attach($view)
     {
          // Don't even try if we don't have an api key
         if (empty($GLOBALS['conf']['api']['googlemaps'])) {
@@ -34,7 +37,7 @@ class Ansel_Widget_Geodata extends Ansel_Widget {
         return true;
     }
 
-    function html()
+    public function html()
     {
         global $ansel_storage;
 
@@ -59,9 +62,6 @@ class Ansel_Widget_Geodata extends Ansel_Widget {
         }
 
         // Bring in googlemap.js now that we know we need it.
-//        $sfiles = &Ansel_Script_Files::singleton();
-//        $sfiles->addExternalScript('http://maps.google.com/maps?file=api&v=2&sensor=false&key=' . $GLOBALS['conf']['api']['googlemaps']);
-//        $sfiles->addExternalScript('http://gmaps-utility-library.googlecode.com/svn/trunk/markermanager/1.1/src/markermanager.js');
         Horde::addExternalScriptFile('http://maps.google.com/maps?file=api&v=2&sensor=false&key=' . $GLOBALS['conf']['api']['googlemaps'], 'ansel');
         Horde::addExternalScriptFile('http://gmaps-utility-library.googlecode.com/svn/trunk/markermanager/1.1/src/markermanager.js', 'ansel');
         Horde::addScriptFile('googlemap.js');
@@ -227,12 +227,12 @@ EOT;
         return $html;
     }
 
-    function _getGalleryImagesWithGeodata()
+    protected function _getGalleryImagesWithGeodata()
     {
         return $GLOBALS['ansel_storage']->getImagesGeodata(array(), $this->_view->gallery->id);
     }
 
-    function _point2Deg($value, $lat = false)
+    protected function _point2Deg($value, $lat = false)
     {
         $letter = $lat ? ($value > 0 ? "N" : "S") : ($value > 0 ? "E" : "W");
         $value = abs($value);
index acba0ac..f8a11c1 100644 (file)
@@ -3,8 +3,6 @@
  * Horde_Widget_ImageFaces:: class to display a widget containing mini
  * thumbnails of faces in the image.
  *
- * $Horde: ansel/lib/Widget/ImageFaces.php,v 1.29 2009/07/30 13:15:10 mrubinsk Exp $
- *
  * Copyright 2008-2009 The Horde Project (http://www.horde.org/)
  *
  * @author Duck <duck@obala.net>
  *
  * @package Ansel
  */
-class Ansel_Widget_ImageFaces extends Ansel_Widget {
-
+class Ansel_Widget_ImageFaces extends Ansel_Widget_Base
+{
     /**
      * @TODO
      *
      * @var unknown_type
      */
-    var $_supported_views = array('Image');
+    private $_supported_views = array('Image');
 
     /**
      * Constructor
@@ -27,7 +25,7 @@ class Ansel_Widget_ImageFaces extends Ansel_Widget {
      * @param array $params  Any parameters for this widget
      * @return Ansel_Widget_ImageFaces
      */
-    function Ansel_Widget_ImageFaces($params)
+    public function __construct($params)
     {
         parent::Ansel_Widget($params);
         $this->_title = _("People in this photo");
@@ -38,9 +36,8 @@ class Ansel_Widget_ImageFaces extends Ansel_Widget {
      *
      * @return string  The HTML for this widget.
      */
-    function html()
+    public function html()
     {
-
         if ($GLOBALS['conf']['faces']['driver']) {
             $html = $this->_getFaceNames();
             return $this->_htmlBegin() . $html . $this->_htmlEnd();
@@ -54,20 +51,13 @@ class Ansel_Widget_ImageFaces extends Ansel_Widget {
      *
      * @return string  The HTML
      */
-    function _getFaceNames()
+    protected function _getFaceNames()
     {
-        require_once ANSEL_BASE . '/lib/Faces.php';
         $faces = Ansel_Faces::factory();
-        if (is_a($faces, 'PEAR_Error')) {
-            return $faces->getMessage();
-        }
 
         // Check for existing faces for this image.
         $html = '';
         $images = $faces->getImageFacesData($this->_view->resource->id, true);
-        if (is_a($images, 'PEAR_Error')) {
-            return $images->getMessage();
-        }
 
         // Generate the top ajax action links and attach the edit actions. Falls
         // back on going to the find all faces in gallery page if no js...
index f69381d..aa2da24 100644 (file)
@@ -2,22 +2,20 @@
 /**
  * Ansel_Widget_links:: class to wrap the display of various feed links etc...
  *
- * $Horde: ansel/lib/Widget/Links.php,v 1.16 2009/07/30 18:02:15 mrubinsk Exp $
- *
  * @author Michael J. Rubinsky <mrubinsk@horde.org>
  * @package Ansel
  */
-class Ansel_Widget_Links extends Ansel_Widget {
-
-    var $_supported_views = array('Gallery', 'Image');
+class Ansel_Widget_Links extends Ansel_Widget_Base
+{
+    protected $_supported_views = array('Gallery', 'Image');
 
-    function Ansel_Widget_Links($params)
+    public function __construct($params)
     {
-        parent::Ansel_Widget($params);
+        parent::__construct($params);
         $this->_title = _("Links");
     }
 
-    function html()
+    public function html()
     {
         global $registry;
 
@@ -29,7 +27,6 @@ class Ansel_Widget_Links extends Ansel_Widget {
         $html .= '<br />' . Horde::link(Ansel::getUrlFor('rss_gallery', array('gallery' => $this->_view->gallery->id, 'slug' => $slug))) . ' ' .  Horde::img('feed.png', '', '', $registry->getImageDir('horde')) . ' ' . sprintf(_("Recent photos in %s"), htmlspecialchars($this->_view->gallery->get('name'), ENT_COMPAT, Horde_Nls::getCharset())) . '</a>';
 
         /* Embed html */
-
         if (empty($this->_view->_params['image_id'])) {
             /* Gallery view */
             $params = array('count' => 10);
@@ -47,13 +44,10 @@ class Ansel_Widget_Links extends Ansel_Widget {
         }
 
         $embed = htmlentities(Ansel::embedCode($params));
-
-        $html .= '<div class="embedInput">' . _("Embed: ") . '<br /><input type="text" readonly="readonly" value="' . $embed
-            . '" /></div>';
-
+        $html .= '<div class="embedInput">' . _("Embed: ") . '<br /><input type="text" readonly="readonly" value="' . $embed . '" /></div>';
         $html .= $this->_htmlEnd();
+
         return $html;
     }
 
 }
-?>
index 97890ab..f78cc3e 100644 (file)
@@ -9,15 +9,15 @@
  * @author Michael J. Rubinsky <mrubinsk@horde.org>
  * @package Ansel
  */
-class Ansel_Widget_OtherGalleries extends Ansel_Widget {
-
+class Ansel_Widget_OtherGalleries extends Ansel_Widget_Base
+{
     /**
      * Override the parent class' attach method and set the owner in the
      * title string.
      *
      * @param Ansel_View $view  The view we are attaching to
      */
-    function attach($view)
+    public function attach($view)
     {
         parent::attach($view);
 
@@ -36,7 +36,7 @@ class Ansel_Widget_OtherGalleries extends Ansel_Widget {
      *
      * @return string  The HTML representing this widget.
      */
-    function html()
+    public function html()
     {
          if ($GLOBALS['conf']['ansel_cache']['usecache'] &&
              ($widget = $GLOBALS['cache']->get('Ansel_OtherGalleries' . $this->_view->gallery->get('owner'))) !== false) {
@@ -59,12 +59,8 @@ class Ansel_Widget_OtherGalleries extends Ansel_Widget {
      *
      * @return string  The HTML
      */
-    function _getOtherGalleries()
+    protected function _getOtherGalleries()
     {
-        require_once 'Horde/Tree.php';
-
-        global $prefs;
-
         $owner = $this->_view->gallery->get('owner');
 
         /* Set up the tree */
@@ -75,10 +71,12 @@ class Ansel_Widget_OtherGalleries extends Ansel_Widget {
                                                          'name', 0);
 
         $html = '<div style="display:'
-            . (($prefs->getValue('show_othergalleries')) ? 'block' : 'none')
+            . (($GLOBALS['prefs']->getValue('show_othergalleries')) ? 'block' : 'none')
             . ';background:' . $this->_style['background']
             . ';width:100%;max-height:300px;overflow:auto;" id="othergalleries" >';
 
+        //@TODO - for now, Horde_Share will still return PEAR_Error,
+        //        this will be fixed when Ansel_Gallery is refactored.
         foreach($gals as $gal) {
             if (is_a($gal, 'PEAR_Error')) {
                 Horde::logMessage($gal, __FILE__, __LINE__, PEAR_LOG_ERR);
index bc4476f..d473c77 100644 (file)
@@ -6,11 +6,11 @@
  * @author Duck <duck@obala.net>
  * @package Ansel
  */
-class Ansel_Widget_OwnerFaces extends Ansel_Widget {
-
-    var $_faces;
-    var $_count;
-    var $_owner;
+class Ansel_Widget_OwnerFaces extends Ansel_Widget_Base
+{
+    protected $_faces;
+    protected $_count;
+    protected $_owner;
 
     /**
      * Constructor
@@ -18,11 +18,9 @@ class Ansel_Widget_OwnerFaces extends Ansel_Widget {
      * @param array $params  Any parameters for this widget
      * @return Ansel_Widget_ImageFaces
      */
-    function Ansel_Widget_OwnerFaces($params)
+    function __construct($params)
     {
-        parent::Ansel_Widget($params);
-
-        require_once ANSEL_BASE . '/lib/Faces.php';
+        parent::__construct($params);
         $this->_faces = Ansel_Faces::factory();
     }
 
@@ -31,14 +29,17 @@ class Ansel_Widget_OwnerFaces extends Ansel_Widget {
      *
      * @return string  The HTML for this widget.
      */
-    function html()
+    public function html()
     {
         if (!$GLOBALS['conf']['faces']['driver']) {
             return '';
         }
 
         $this->_owner = $this->_view->gallery->get('owner');
-        $this->_count = $this->_faces->countOwnerFaces($this->_owner);
+        //@TODO: Remove the PEAR_Error check when Faces is refactored.
+        try {
+            $this->_count = $this->_faces->countOwnerFaces($this->_owner);
+        } catch (Horde_Exception $e) {}
         if (is_a($this->_count, 'PEAR_error')) {
             $this->_count = 0;
         }
index 5ad72b8..6a57ee0 100755 (executable)
@@ -6,14 +6,14 @@
  * @author Michael J. Rubinsky <mrubinsk@horde.org>
  * @package Ansel
  */
-class Ansel_Widget_SimilarPhotos extends Ansel_Widget {
-
+class Ansel_Widget_SimilarPhotos extends Ansel_Widget_Base
+{
     /**
      * @TODO
      *
      * @var unknown_type
      */
-    var $_supported_views = array('Image');
+    protected $_supported_views = array('Image');
 
     /**
      * Constructor
@@ -21,9 +21,9 @@ class Ansel_Widget_SimilarPhotos extends Ansel_Widget {
      * @param array $params  Any parameters for this widget
      * @return Ansel_Widget_SimilarPhotos
      */
-    function Ansel_Widget_SimilarPhotos($params)
+    public function __construct($params)
     {
-        parent::Ansel_Widget($params);
+        parent::__construct($params);
         $this->_title = _("Similar Photos");
     }
 
@@ -32,11 +32,12 @@ class Ansel_Widget_SimilarPhotos extends Ansel_Widget {
      *
      * @return string  The HTML for this widget.
      */
-    function html()
+    public function html()
     {
         $html = $this->_htmlBegin();
         $html .= '<div id="similar">' . $this->_getRelatedImages() . '</div>';
         $html .= $this->_htmlEnd();
+
         return $html;
     }
 
@@ -49,9 +50,8 @@ class Ansel_Widget_SimilarPhotos extends Ansel_Widget {
      *
      * @return string  The HTML
      */
-    function _getRelatedImages()
+    public function _getRelatedImages()
     {
-        require_once ANSEL_BASE . '/lib/Tags.php';
         global $ansel_storage;
 
         $html = '';
@@ -92,6 +92,7 @@ class Ansel_Widget_SimilarPhotos extends Ansel_Widget {
                 }
             }
         }
+
         return $html;
     }
 }
index 8b3f7fc..58c3479 100644 (file)
@@ -1,22 +1,18 @@
 <?php
-require_once ANSEL_BASE . '/lib/Tags.php';
-
 /**
  * Ansel_Widget_Tags:: class to display a tags widget in the image and gallery
  * views.
  *
- * $Horde: ansel/lib/Widget/Tags.php,v 1.15 2009/07/28 15:15:04 mrubinsk Exp $
- *
  * @author Michael J. Rubinsky <mrubinsk@horde.org>
  * @package Ansel
  */
-class Ansel_Widget_Tags extends Ansel_Widget {
+class Ansel_Widget_Tags extends Ansel_Widget_Base
+{
+    protected $_resourceType;
 
-    var $_resourceType;
-
-    function Ansel_Widget_Tags($params)
+    public function __construct($params)
     {
-        parent::Ansel_Widget($params);
+        parent::__construct($params);
         $this->_resourceType = $params['view'];
         $this->_title = _("Tags");
     }
@@ -26,7 +22,7 @@ class Ansel_Widget_Tags extends Ansel_Widget {
      *
      * @return string  The HTML representing this widget.
      */
-    function html()
+    public function html()
     {
         if ($this->_resourceType == 'image') {
             $image_id = $this->_view->resource->id;
@@ -39,7 +35,6 @@ class Ansel_Widget_Tags extends Ansel_Widget {
         $html .= '<div id="tags">' . $this->_getTagHTML() . '</div>';
         if ($this->_view->gallery->hasPermission(Horde_Auth::getAuth(), PERMS_EDIT)) {
             ob_start();
-
             /* Attach the Ajax action */
             $imple = Horde_Ajax_Imple::factory(array('ansel', 'TagActions'),
                                                array('bindTo' => array('add' => 'tagbutton'),
@@ -48,7 +43,6 @@ class Ansel_Widget_Tags extends Ansel_Widget {
             $imple->attach();
             $html .= ob_get_clean();
 
-            // JS fallback is getting refactoring into xrequest.php
             $actionUrl = Horde_Util::addParameter('image.php',
                                                   array('image' => $this->_view->resource->id,
                                                         'gallery' => $this->_view->gallery->id));
@@ -67,16 +61,15 @@ class Ansel_Widget_Tags extends Ansel_Widget {
      *
      * @return string  The HTML representing the tag list.
      */
-    function _getTagHTML()
+    protected function _getTagHTML()
     {
         global $registry;
 
-            /* Clear the tag cache? */
+        /* Clear the tag cache? */
         if (Horde_Util::getFormData('havesearch', 0) == 0) {
             Ansel_Tags::clearSearch();
         }
 
-        // TODO - Degrade the delete links to work without js
         $hasEdit = $this->_view->gallery->hasPermission(Horde_Auth::getAuth(),
                                                         PERMS_EDIT);
         $owner = $this->_view->gallery->get('owner');