From: Michael J. Rubinsky Date: Fri, 31 Jul 2009 01:09:30 +0000 (-0400) Subject: PHP 5-ify Ansel_Widget and some other related changes X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=800267fa83ea045f8ad831517418055e71deaf3b;p=horde.git PHP 5-ify Ansel_Widget and some other related changes --- diff --git a/ansel/lib/Faces.php b/ansel/lib/Faces.php index 5c198bb28..212a3b1ff 100755 --- a/ansel/lib/Faces.php +++ b/ansel/lib/Faces.php @@ -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 * @package Ansel */ diff --git a/ansel/lib/Faces/opencv.php b/ansel/lib/Faces/opencv.php index 77a87ce8d..0b201162d 100644 --- a/ansel/lib/Faces/opencv.php +++ b/ansel/lib/Faces/opencv.php @@ -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, diff --git a/ansel/lib/Views/Abstract.php b/ansel/lib/Views/Abstract.php index bcf79b6e3..beb9b3235 100644 --- a/ansel/lib/Views/Abstract.php +++ b/ansel/lib/Views/Abstract.php @@ -111,7 +111,7 @@ class Ansel_View_Abstract { { echo '
'; foreach ($this->_widgets as $widget) { - if ($widget->_render == 'auto') { + if ($widget->autoRender) { echo $widget->html(); echo '
'; } diff --git a/ansel/lib/Widget.php b/ansel/lib/Widget.php index 61dedc87f..1e0c11a2f 100644 --- a/ansel/lib/Widget.php +++ b/ansel/lib/Widget.php @@ -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 @@ -13,145 +11,25 @@ * @author Michael J. Rubinsky * @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 = '
'; - $html .= '

' . $this->_title . '

'; - return $html; - } - - /** - * Default HTML for the end of the widget. - * - * @return string - */ - function _htmlEnd() - { - return '
'; - } - - - /** - * 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.'); } } diff --git a/ansel/lib/Widget/Actions.php b/ansel/lib/Widget/Actions.php index a83b2451c..06b7269b8 100644 --- a/ansel/lib/Widget/Actions.php +++ b/ansel/lib/Widget/Actions.php @@ -7,28 +7,33 @@ * @author Michael J. Rubinsky * @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 .= '
    '; @@ -57,7 +62,7 @@ class Ansel_Widget_Actions extends Ansel_Widget { /* Subgalleries */ if ($this->_view->gallery->hasFeature('subgalleries')) { - $html .= '
  • ' . Horde::link(Horde_Util::addParameter($galleryurl, 'actionID', 'addchild'), '', 'widget') . Horde::img('add.png') . ' ' . _("Create a subgallery") . '
  • '; + $html .= '
  • ' . Horde::link(Horde_Util::addParameter($galleryurl, 'actionID', 'addchild'), '', 'widget') . Horde::img('add.png', '[icon]') . ' ' . _("Create a subgallery") . '
  • '; } } $html .= '
'; @@ -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 = '