From 915027da14f7b892c0790896264146249b54d68a Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Sun, 30 May 2010 18:06:18 -0400 Subject: [PATCH] Use injector, get rid of more $GLOBALS. Use injector for vfs, and for style config. Added a binder and factory for Ansel_Storage, but still need to work out the need to be able to support different scopes. Will probably need to be passing the scope string around everywhere... --- ansel/faces/img.php | 2 +- ansel/img/download.php | 2 +- ansel/img/full.php | 2 +- ansel/img/index.php | 2 +- ansel/img/mini.php | 2 +- ansel/img/prettythumb.php | 2 +- ansel/img/screen.php | 2 +- ansel/img/thumb.php | 2 +- ansel/lib/Ansel.php | 46 +++--------------------------- ansel/lib/Api.php | 4 +-- ansel/lib/Application.php | 19 +++++++------ ansel/lib/Faces.php | 4 +-- ansel/lib/Faces/Base.php | 10 +++---- ansel/lib/Gallery.php | 7 +++-- ansel/lib/GalleryMode/Date.php | 2 +- ansel/lib/GalleryMode/Normal.php | 3 +- ansel/lib/Image.php | 28 +++++++++--------- ansel/lib/Injector/Binder/Storage.php | 23 +++++++++++++++ ansel/lib/Injector/Binder/Styles.php | 52 ++++++++++++++++++++++++++++++++++ ansel/lib/Injector/Factory/Storage.php | 50 ++++++++++++++++++++++++++++++++ ansel/lib/Storage.php | 12 +++----- 21 files changed, 182 insertions(+), 94 deletions(-) create mode 100644 ansel/lib/Injector/Binder/Storage.php create mode 100644 ansel/lib/Injector/Binder/Styles.php create mode 100644 ansel/lib/Injector/Factory/Storage.php diff --git a/ansel/faces/img.php b/ansel/faces/img.php index fc49befbc..af68ad0fb 100644 --- a/ansel/faces/img.php +++ b/ansel/faces/img.php @@ -30,7 +30,7 @@ if ($conf['vfs']['src'] == 'sendfile') { // We definitely have an image for the face. try { - $filename = $ansel_vfs->readFile( + $filename = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->readFile( Ansel_Faces::getVFSPath($face['image_id']) . 'faces', $face_id . Ansel_Faces::getExtension()); } catch (VFS_Exception $e) { diff --git a/ansel/img/download.php b/ansel/img/download.php index 260b50e28..d50876011 100644 --- a/ansel/img/download.php +++ b/ansel/img/download.php @@ -20,7 +20,7 @@ $image->downloadHeaders(); /* Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file header */ if ($conf['vfs']['src'] == 'sendfile') { - $filename = $ansel_vfs->readFile($image->getVFSPath('full'), $image->getVFSName('full')); + $filename = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->readFile($image->getVFSPath('full'), $image->getVFSName('full')); header('Content-Type: ' . $image->getType('full')); header('X-LIGHTTPD-send-file: ' . $filename); header('X-Sendfile: ' . $filename); diff --git a/ansel/img/full.php b/ansel/img/full.php index b9a142739..3e64f7181 100644 --- a/ansel/img/full.php +++ b/ansel/img/full.php @@ -19,7 +19,7 @@ if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ) || !$gall /* Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file header */ if ($conf['vfs']['src'] == 'sendfile') { - $filename = $ansel_vfs->readFile($image->getVFSPath('full'), $image->getVFSName('full')); + $filename = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->readFile($image->getVFSPath('full'), $image->getVFSName('full')); header('Content-Type: ' . $image->getType('full')); header('X-LIGHTTPD-send-file: ' . $filename); header('X-Sendfile: ' . $filename); diff --git a/ansel/img/index.php b/ansel/img/index.php index 618db219c..66e583ee8 100644 --- a/ansel/img/index.php +++ b/ansel/img/index.php @@ -19,7 +19,7 @@ if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) { /* Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file header */ if ($conf['vfs']['src'] == 'sendfile') { - $filename = $ansel_vfs->readFile($image->getVFSPath('screen'), $image->getVFSName('screen')); + $filename = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->readFile($image->getVFSPath('screen'), $image->getVFSName('screen')); header('Content-Type: ' . $image->getType('screen')); header('X-LIGHTTPD-send-file: ' . $filename); header('X-Sendfile: ' . $filename); diff --git a/ansel/img/mini.php b/ansel/img/mini.php index 6a24267c7..81f18dd37 100644 --- a/ansel/img/mini.php +++ b/ansel/img/mini.php @@ -26,7 +26,7 @@ if ($conf['vfs']['src'] == 'sendfile') { Horde::logMessage($e, 'ERR'); exit; } - $filename = $ansel_vfs->readFile($image->getVFSPath('mini'), $image->getVFSName('mini')); + $filename = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->readFile($image->getVFSPath('mini'), $image->getVFSName('mini')); header('Content-Type: ' . $image->getType('mini')); header('X-LIGHTTPD-send-file: ' . $filename); header('X-Sendfile: ' . $filename); diff --git a/ansel/img/prettythumb.php b/ansel/img/prettythumb.php index ab4fb98f9..40a7bcfe9 100644 --- a/ansel/img/prettythumb.php +++ b/ansel/img/prettythumb.php @@ -27,7 +27,7 @@ if ($conf['vfs']['src'] == 'sendfile') { Horde::logMessage($e, 'ERR'); exit; } - $filename = $ansel_vfs->readFile($image->getVFSPath('prettythumb', $style), $image->getVFSName('prettythumb')); + $filename = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->readFile($image->getVFSPath('prettythumb', $style), $image->getVFSName('prettythumb')); header('Content-Type: ' . $image->getType('prettythumb')); header('X-LIGHTTPD-send-file: ' . $filename); header('X-Sendfile: ' . $filename); diff --git a/ansel/img/screen.php b/ansel/img/screen.php index af5651df4..9e7a17a90 100644 --- a/ansel/img/screen.php +++ b/ansel/img/screen.php @@ -26,7 +26,7 @@ if ($conf['vfs']['src'] == 'sendfile') { Horde::logMessage($result, 'ERR'); exit; } - $filename = $ansel_vfs->readFile($image->getVFSPath('screen'), $image->getVFSName('screen')); + $filename = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->readFile($image->getVFSPath('screen'), $image->getVFSName('screen')); header('Content-Type: ' . $image->getType('screen')); header('X-LIGHTTPD-send-file: ' . $filename); header('X-Sendfile: ' . $filename); diff --git a/ansel/img/thumb.php b/ansel/img/thumb.php index 2918cfbe0..f8a56cb6d 100644 --- a/ansel/img/thumb.php +++ b/ansel/img/thumb.php @@ -26,7 +26,7 @@ if ($conf['vfs']['src'] == 'sendfile') { Horde::logMessage($result, 'ERR'); exit; } - $filename = $ansel_vfs->readFile($image->getVFSPath('thumb'), $image->getVFSName('thumb')); + $filename = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->readFile($image->getVFSPath('thumb'), $image->getVFSName('thumb')); header('Content-Type: ' . $image->getType('thumb')); header('X-LIGHTTPD-send-file: ' . $filename); header('X-Sendfile: ' . $filename); diff --git a/ansel/lib/Ansel.php b/ansel/lib/Ansel.php index c222495d6..7cf055338 100644 --- a/ansel/lib/Ansel.php +++ b/ansel/lib/Ansel.php @@ -787,45 +787,6 @@ class Ansel } /** - * Get an array of all currently viewable styles. - * - * @return array - */ - static public function getAvailableStyles() - { - /* Brings in the $styles array in this scope only */ - $styles = Horde::loadConfiguration('styles.php', 'styles', 'ansel'); - - /* No prettythumbs allowed at all by admin choice */ - if (empty($GLOBALS['conf']['image']['prettythumbs'])) { - $test = $styles; - foreach ($test as $key => $style) { - if ($style['thumbstyle'] != 'thumb') { - unset($styles[$key]); - } - } - } - - /* Check if the browser / server has png support */ - if ($GLOBALS['browser']->hasQuirk('png_transparency') || - $GLOBALS['conf']['image']['type'] != 'png') { - - $test = $styles; - foreach ($test as $key => $style) { - if (!empty($style['requires_png'])) { - if (!empty($style['fallback'])) { - $styles[$key] = $styles[$style['fallback']]; - } else { - unset($styles[$key]); - } - } - } - } - - return $styles; - } - - /** * Get a style definition for the requested named style * * @param string $style The name of the style to fetch @@ -835,10 +796,11 @@ class Ansel */ static public function getStyleDefinition($style) { - if (isset($GLOBALS['ansel_styles'][$style])) { - $style_def = $GLOBALS['ansel_styles'][$style]; + $styles = $GLOBALS['injector']->getInstance('Ansel_Styles'); + if (isset($styles[$style])) { + $style_def = $styles[$style]; } else { - $style_def = $GLOBALS['ansel_styles']['ansel_default']; + $style_def = $styles['ansel_default']; } /* Fill in defaults */ diff --git a/ansel/lib/Api.php b/ansel/lib/Api.php index aafed3659..c7aa5545d 100644 --- a/ansel/lib/Api.php +++ b/ansel/lib/Api.php @@ -615,7 +615,7 @@ class Ansel_Api extends Horde_Registry_Api throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied downloading photos from \"%s\"."), $gallery->get('name'))); } try { - $data = $GLOBALS['ansel_vfs']->read($image->getVFSPath('full'), $image->getVFSName('full')); + $data = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->read($image->getVFSPath('full'), $image->getVFSName('full')); } catch (VFS_Exception $e) { Horde::logMessage($e->getMessage(), 'ERR'); throw new Ansel_Exception($e->getMessage()); @@ -982,7 +982,7 @@ class Ansel_Api extends Horde_Registry_Api */ public function getGalleryStyles() { - return Ansel::getAvailableStyles(); + return $GLOBALS['injector']->getInstance('Ansel_Styles'); } /** diff --git a/ansel/lib/Application.php b/ansel/lib/Application.php index f32605149..d99d13164 100644 --- a/ansel/lib/Application.php +++ b/ansel/lib/Application.php @@ -49,9 +49,6 @@ class Ansel_Application extends Horde_Registry_Application * Global variables defined: * $ansel_db - TODO * $ansel_storage - TODO - * $ansel_styles - TODO - * $ansel_vfs - TODO - * $cache - A Horde_Cache object. * * @throws Horde_Exception */ @@ -61,14 +58,20 @@ class Ansel_Application extends Horde_Registry_Application throw new Horde_Exception('You must configure a Horde_Image driver to use Ansel'); } + $binders = array( + 'Ansel_Storage' => new Ansel_Injector_Binder_Storage(), + 'Ansel_Styles' => new Ansel_Injector_Binder_Styles(), + ); + foreach ($binders as $interface => $binder) { + $GLOBALS['injector']->addBinder($interface, $binder); + } + // Create db, share, and vfs instances. $GLOBALS['ansel_db'] = Ansel::getDb(); - $GLOBALS['ansel_storage'] = new Ansel_Storage(); - $GLOBALS['ansel_vfs'] = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images'); + $GLOBALS['ansel_storage'] = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope('ansel'); - // Get list of available styles for this client. - $GLOBALS['ansel_styles'] = Ansel::getAvailableStyles(); - $GLOBALS['ansel_vfs']->setLogger($GLOBALS['injector']->getInstance('Horde_Log_Logger')); + /* Set a logger for the Vfs */ + $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->setLogger($GLOBALS['injector']->getInstance('Horde_Log_Logger')); } /** diff --git a/ansel/lib/Faces.php b/ansel/lib/Faces.php index 5e7a8dc5f..a0339c6c4 100644 --- a/ansel/lib/Faces.php +++ b/ansel/lib/Faces.php @@ -56,7 +56,7 @@ class Ansel_Faces } try { foreach ($face as $id) { - $GLOBALS['ansel_vfs']->deleteFile($path, $id . $ext); + $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->deleteFile($path, $id . $ext); } } catch (VFS_Exception $e) {} $GLOBALS['ansel_db']->exec('DELETE FROM ansel_faces WHERE image_id = ' . $image->id); @@ -64,7 +64,7 @@ class Ansel_Faces $GLOBALS['ansel_db']->exec('UPDATE ansel_shares SET attribute_faces = attribute_faces - ' . count($face) . ' WHERE gallery_id = ' . $image->gallery . ' AND attribute_faces > 0 '); } else { try { - $GLOBALS['ansel_vfs']->deleteFile($path, (int)$face . $ext); + $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->deleteFile($path, (int)$face . $ext); } catch (VFS_Exception $e) {} $GLOBALS['ansel_db']->exec('DELETE FROM ansel_faces WHERE face_id = ' . (int)$face); $GLOBALS['ansel_db']->exec('UPDATE ansel_images SET image_faces = image_faces - 1 WHERE image_id = ' . $image->id . ' AND image_faces > 0 '); diff --git a/ansel/lib/Faces/Base.php b/ansel/lib/Faces/Base.php index 104bef2bd..b862c6d88 100644 --- a/ansel/lib/Faces/Base.php +++ b/ansel/lib/Faces/Base.php @@ -42,7 +42,7 @@ class Ansel_Faces_Base $image->load('screen'); // Make sure we have an on-disk copy of the file. - $file = $GLOBALS['ansel_vfs']->readFile($image->getVFSPath('screen'), + $file = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->readFile($image->getVFSPath('screen'), $image->getVFSName('screen')); } elseif (empty($file) || !is_string($image)) { return array(); @@ -341,7 +341,7 @@ class Ansel_Faces_Base { $vfspath = Ansel_Faces::getVFSPath($image_id) . 'faces'; $vfsname = $face_id . Ansel_Faces::getExtension(); - if (!$GLOBALS['ansel_vfs']->exists($vfspath, $vfsname)) { + if (!$GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->exists($vfspath, $vfsname)) { if (!$create) { return false; } @@ -384,7 +384,7 @@ class Ansel_Faces_Base $vfsname = $face_id . Ansel_Faces::getExtension(); $img = Ansel::getImageObject(); try { - $data = $GLOBALS['ansel_vfs']->read($vfspath, $vfsname); + $data = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->read($vfspath, $vfsname); } catch (VFS_Exception $e) { throw new Horde_Exception_Prior($e); } @@ -621,7 +621,7 @@ class Ansel_Faces_Base $path = Ansel_Faces::getVFSPath($image->id); $image->getHordeImage()->resize(50, 50, false); try { - $GLOBALS['ansel_vfs']->writeData($path . 'faces', $face_id . $ext, + $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->writeData($path . 'faces', $face_id . $ext, $image->getHordeImage()->raw(), true); } catch (VFS_Exception $e) { throw new Horde_Exception_Prior($e); @@ -648,7 +648,7 @@ class Ansel_Faces_Base } // Ensure we have an on-disk file to read the signature from. - $path = $GLOBALS['ansel_vfs']->readFile(Ansel_Faces::getVFSPath($image_id) . '/faces', + $path = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->readFile(Ansel_Faces::getVFSPath($image_id) . '/faces', $face_id . Ansel_Faces::getExtension()); $signature = puzzle_fill_cvec_from_file($path); diff --git a/ansel/lib/Gallery.php b/ansel/lib/Gallery.php index 39353cc7e..af87b7f6a 100644 --- a/ansel/lib/Gallery.php +++ b/ansel/lib/Gallery.php @@ -615,14 +615,17 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical */ public function getDefaultImage($style = null) { + /* Get the available styles */ + $styles = $GLOBALS['injector']->getInstance('Ansel_Styles'); + // Check for explicitly requested style if (!is_null($style)) { $gal_style = Ansel::getStyleDefinition($style); } else { // Use gallery's default. $gal_style = $this->getStyle(); - if (!isset($GLOBALS['ansel_styles'][$gal_style['name']])) { - $gal_style = $GLOBALS['ansel_styles']['ansel_default']; + if (!isset($styles[$gal_style['name']])) { + $gal_style = $styles['ansel_default']; } } Horde::logMessage(sprintf("using gallery style: %s in Ansel::getDefaultImage()", $gal_style['name']), 'DEBUG'); diff --git a/ansel/lib/GalleryMode/Date.php b/ansel/lib/GalleryMode/Date.php index b62433067..f86386ba4 100644 --- a/ansel/lib/GalleryMode/Date.php +++ b/ansel/lib/GalleryMode/Date.php @@ -505,7 +505,7 @@ class Ansel_GalleryMode_Date /* Delete original image from VFS. */ try { - $GLOBALS['ansel_vfs']->deleteFile($image->getVFSPath('full'), + $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->deleteFile($image->getVFSPath('full'), $image->getVFSName('full')); } catch (VFS_Exception $e) {} diff --git a/ansel/lib/GalleryMode/Normal.php b/ansel/lib/GalleryMode/Normal.php index 0f1d76bed..3ae1274c4 100644 --- a/ansel/lib/GalleryMode/Normal.php +++ b/ansel/lib/GalleryMode/Normal.php @@ -241,8 +241,7 @@ class Ansel_GalleryMode_Normal { /* Delete original image from VFS. */ try { - $GLOBALS['ansel_vfs']->deleteFile($image->getVFSPath('full'), - $image->getVFSName('full')); + $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->deleteFile($image->getVFSPath('full'), $image->getVFSName('full')); } catch (VFS_Exception $e) {} /* Delete from SQL. */ diff --git a/ansel/lib/Image.php b/ansel/lib/Image.php index 04c6bf2d5..ac729393f 100644 --- a/ansel/lib/Image.php +++ b/ansel/lib/Image.php @@ -307,7 +307,7 @@ class Ansel_Image Implements Iterator /* Read in the requested view. */ try { - $data = $GLOBALS['ansel_vfs']->read($vfspath, $this->getVFSName($view)); + $data = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->read($vfspath, $this->getVFSName($view)); } catch (VFS_Exception $e) { Horde::logMessage($e, 'ERR'); throw new Ansel_Exception($e); @@ -355,7 +355,7 @@ class Ansel_Image Implements Iterator $vfsname .= 'png'; } - if ($GLOBALS['ansel_vfs']->exists($vfspath, $vfsname)) { + if ($GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->exists($vfspath, $vfsname)) { return $view . '/' . $vfsname; } else { return false; @@ -380,11 +380,11 @@ class Ansel_Image Implements Iterator /* Get the VFS info. */ $vfspath = $this->getVFSPath($view, $style); - if ($GLOBALS['ansel_vfs']->exists($vfspath, $this->getVFSName($view))) { + if ($GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->exists($vfspath, $this->getVFSName($view))) { return true; } try { - $data = $GLOBALS['ansel_vfs']->read($this->getVFSPath('full'), $this->getVFSName('full')); + $data = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->read($this->getVFSPath('full'), $this->getVFSName('full')); } catch (VFS_Exception $e) { Horde::logMessage($e, 'ERR'); throw new Ansel_Exception($e); @@ -427,7 +427,7 @@ class Ansel_Image Implements Iterator /* ...and put it in Horde_Image obejct, then save */ $this->_image->loadString($this->_data[$vHash]); $this->_loaded[$vHash] = true; - $GLOBALS['ansel_vfs']->writeData($vfspath, $this->getVFSName($vHash), $this->_data[$vHash], true); + $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->writeData($vfspath, $this->getVFSName($vHash), $this->_data[$vHash], true); /* Autowatermark the screen view */ if ($view == 'screen' && @@ -435,7 +435,7 @@ class Ansel_Image Implements Iterator $GLOBALS['prefs']->getValue('watermark_text') != '') { $this->watermark('screen'); - $GLOBALS['ansel_vfs']->writeData($vfspath, $this->getVFSName($view), $this->_image->_data); + $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->writeData($vfspath, $this->getVFSName($view), $this->_image->_data); } return true; @@ -452,7 +452,7 @@ class Ansel_Image Implements Iterator $this->_dirty = false; try { - $GLOBALS['ansel_vfs']->writeData($this->getVFSPath('full'), + $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->writeData($this->getVFSPath('full'), $this->getVFSName('full'), $this->_data['full'], true); } catch (VFS_Exception $e) { @@ -481,7 +481,7 @@ class Ansel_Image Implements Iterator } try { - $GLOBALS['ansel_vfs']->writeData($this->getVFSPath($view), + $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->writeData($this->getVFSPath($view), $this->getVFSName($view), $data, true); } catch (VFS_Exception $e) { @@ -626,7 +626,7 @@ class Ansel_Image Implements Iterator /* Get the data */ try { - $imageFile = $GLOBALS['ansel_vfs']->readFile($this->getVFSPath('full'), + $imageFile = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->readFile($this->getVFSPath('full'), $this->getVFSName('full')); } catch (VFS_Exception $e) { throw new Ansel_Exception($e); @@ -752,19 +752,19 @@ class Ansel_Image Implements Iterator try { /* Delete cached screen image. (We don't care if the file is not found) */ if ($view == 'all' || $view == 'screen') { - $GLOBALS['ansel_vfs']->deleteFile($this->getVFSPath('screen'), + $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->deleteFile($this->getVFSPath('screen'), $this->getVFSName('screen')); } /* Delete cached thumbnail. */ if ($view == 'all' || $view == 'thumb') { - $GLOBALS['ansel_vfs']->deleteFile($this->getVFSPath('thumb'), + $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->deleteFile($this->getVFSPath('thumb'), $this->getVFSName('thumb')); } /* Delete cached mini image. */ if ($view == 'all' || $view == 'mini') { - $GLOBALS['ansel_vfs']->deleteFile($this->getVFSPath('mini'), + $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->deleteFile($this->getVFSPath('mini'), $this->getVFSName('mini')); } @@ -778,7 +778,7 @@ class Ansel_Image Implements Iterator foreach ($styles as $style) { $hash = md5($style['thumbstyle'] . '.' . $style['background']); if (empty($deleted[$hash])) { - $GLOBALS['ansel_vfs']->deleteFile($this->getVFSPath($hash), + $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->deleteFile($this->getVFSPath($hash), $this->getVFSName($hash)); $deleted[$hash] = true; } @@ -847,7 +847,7 @@ class Ansel_Image Implements Iterator } try { - $data = $GLOBALS['ansel_vfs']->read($this->getVFSPath('full'), + $data = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->read($this->getVFSPath('full'), $this->getVFSName('full')); } catch (VFS_Exception $e) { throw new Ansel_Exception($e); diff --git a/ansel/lib/Injector/Binder/Storage.php b/ansel/lib/Injector/Binder/Storage.php new file mode 100644 index 000000000..2514d1893 --- /dev/null +++ b/ansel/lib/Injector/Binder/Storage.php @@ -0,0 +1,23 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Ansel + */ +class Ansel_Injector_Binder_Storage Implements Horde_Injector_Binder +{ + public function create (Horde_Injector $injector) + { + return new Ansel_Injector_Factory_Storage($injector); + } + + /** + */ + public function equals(Horde_Injector_Binder $binder) + { + return false; + } +} \ No newline at end of file diff --git a/ansel/lib/Injector/Binder/Styles.php b/ansel/lib/Injector/Binder/Styles.php new file mode 100644 index 000000000..b288c185a --- /dev/null +++ b/ansel/lib/Injector/Binder/Styles.php @@ -0,0 +1,52 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Ansel + */ +class Ansel_Injector_Binder_Styles Implements Horde_Injector_Binder +{ + public function create (Horde_Injector $injector) + { + /* Brings in the $styles array in this scope only */ + $styles = Horde::loadConfiguration('styles.php', 'styles', 'ansel'); + + /* No prettythumbs allowed at all by admin choice */ + if (empty($GLOBALS['conf']['image']['prettythumbs'])) { + $test = $styles; + foreach ($test as $key => $style) { + if ($style['thumbstyle'] != 'thumb') { + unset($styles[$key]); + } + } + } + + /* Check if the browser / server has png support */ + if ($GLOBALS['browser']->hasQuirk('png_transparency') || + $GLOBALS['conf']['image']['type'] != 'png') { + + $test = $styles; + foreach ($test as $key => $style) { + if (!empty($style['requires_png'])) { + if (!empty($style['fallback'])) { + $styles[$key] = $styles[$style['fallback']]; + } else { + unset($styles[$key]); + } + } + } + } + + return $styles; + } + + /** + */ + public function equals(Horde_Injector_Binder $binder) + { + return false; + } +} \ No newline at end of file diff --git a/ansel/lib/Injector/Factory/Storage.php b/ansel/lib/Injector/Factory/Storage.php new file mode 100644 index 000000000..5f403ea28 --- /dev/null +++ b/ansel/lib/Injector/Factory/Storage.php @@ -0,0 +1,50 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Ansel + */ +class Ansel_Injector_Factory_Storage +{ + /** + * + * @var array + */ + private $_instances = array(); + + /** + * @var Horde_Injector + */ + private $_injector; + + /** + * + * @param Horde_Injector $injector + * + * @return Horde_Injector_Factory_Storage + */ + public function __construct(Horde_Injector $injector) + { + $this->_injector = $injector; + } + + /** + * Obtain a Ansel_Storage object for the requested scope. + * + * @param string $scope The application scope + * + * @return Ansel_Storage + */ + public function getScope($scope = 'ansel') + { + if (!isset($this->_instances[$scope])) { + $this->_instances[$scope] = new Ansel_Storage($this->_injector->getInstance('Horde_Share')->getScope($scope, 'Sql_Hierarchical')); + } + + return $this->_instances[$scope]; + } + +} \ No newline at end of file diff --git a/ansel/lib/Storage.php b/ansel/lib/Storage.php index a388ce021..13ab3dd3e 100644 --- a/ansel/lib/Storage.php +++ b/ansel/lib/Storage.php @@ -50,19 +50,15 @@ class Ansel_Storage /** * Const'r * - * @param string $scope The application scope to store images under. + * @param Horde_Share_Sql_Hierarchical The share object * * @return Ansel_Storage */ - public function __construct($scope = null) + public function __construct(Horde_Share_Sql_Hierarchical $shareOb) { - /* Check for a scope other than the default Ansel scope.*/ - if (!is_null($scope)) { - $this->_scope = $scope; - } - /* This is the only supported share backend for Ansel */ - $this->_shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($this->_scope, 'Sql_Hierarchical'); + $this->_shares = $shareOb; + /* Ansel_Gallery is just a subclass of Horde_Share_Object */ $this->_shares->setShareClass('Ansel_Gallery'); -- 2.11.0