Use injector, get rid of more $GLOBALS.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 30 May 2010 22:06:18 +0000 (18:06 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 30 May 2010 22:08:08 +0000 (18:08 -0400)
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...

21 files changed:
ansel/faces/img.php
ansel/img/download.php
ansel/img/full.php
ansel/img/index.php
ansel/img/mini.php
ansel/img/prettythumb.php
ansel/img/screen.php
ansel/img/thumb.php
ansel/lib/Ansel.php
ansel/lib/Api.php
ansel/lib/Application.php
ansel/lib/Faces.php
ansel/lib/Faces/Base.php
ansel/lib/Gallery.php
ansel/lib/GalleryMode/Date.php
ansel/lib/GalleryMode/Normal.php
ansel/lib/Image.php
ansel/lib/Injector/Binder/Storage.php [new file with mode: 0644]
ansel/lib/Injector/Binder/Styles.php [new file with mode: 0644]
ansel/lib/Injector/Factory/Storage.php [new file with mode: 0644]
ansel/lib/Storage.php

index fc49bef..af68ad0 100644 (file)
@@ -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) {
index 260b50e..d508760 100644 (file)
@@ -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);
index b9a1427..3e64f71 100644 (file)
@@ -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);
index 618db21..66e583e 100644 (file)
@@ -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);
index 6a24267..81f18dd 100644 (file)
@@ -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);
index ab4fb98..40a7bcf 100644 (file)
@@ -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);
index af5651d..9e7a17a 100644 (file)
@@ -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);
index 2918cfb..f8a56cb 100644 (file)
@@ -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);
index c222495..7cf0553 100644 (file)
@@ -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 */
index aafed36..c7aa554 100644 (file)
@@ -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');
     }
 
     /**
index f326051..d99d131 100644 (file)
@@ -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'));
     }
 
     /**
index 5e7a8dc..a0339c6 100644 (file)
@@ -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 ');
index 104bef2..b862c6d 100644 (file)
@@ -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);
index 39353cc..af87b7f 100644 (file)
@@ -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');
index b624330..f86386b 100644 (file)
@@ -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) {}
 
index 0f1d76b..3ae1274 100644 (file)
@@ -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. */
index 04c6bf2..ac72939 100644 (file)
@@ -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 (file)
index 0000000..2514d18
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+/**
+ * Binder for Ansel_Storage
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @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 (file)
index 0000000..b288c18
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Binder for all available Ansel styles
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @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 (file)
index 0000000..5f403ea
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+/**
+ * Ansel_Storage:: factory
+ *
+ * @author   Michael J. Rubinsky <mrubinsk@horde.org>
+ * @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
index a388ce0..13ab3dd 100644 (file)
@@ -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');