// 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) {
/* 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);
/* 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);
/* 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);
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);
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);
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);
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);
}
/**
- * 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
*/
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 */
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());
*/
public function getGalleryStyles()
{
- return Ansel::getAvailableStyles();
+ return $GLOBALS['injector']->getInstance('Ansel_Styles');
}
/**
* Global variables defined:
* $ansel_db - TODO
* $ansel_storage - TODO
- * $ansel_styles - TODO
- * $ansel_vfs - TODO
- * $cache - A Horde_Cache object.
*
* @throws Horde_Exception
*/
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'));
}
/**
}
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);
$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 ');
$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();
{
$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;
}
$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);
}
$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);
}
// 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);
*/
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');
/* 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) {}
/* 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. */
/* 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);
$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;
/* 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);
/* ...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' &&
$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;
$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) {
}
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) {
/* 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);
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'));
}
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;
}
}
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);
--- /dev/null
+<?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
--- /dev/null
+<?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
--- /dev/null
+<?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
/**
* 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');