Skip to content

Commit

Permalink
Use a global storage object instead of getting it from injetor hundre…
Browse files Browse the repository at this point in the history
…ds of times.
  • Loading branch information
mrubinsk committed May 9, 2014
1 parent 75fdeee commit 904f1b2
Show file tree
Hide file tree
Showing 73 changed files with 519 additions and 681 deletions.
61 changes: 23 additions & 38 deletions ansel/bin/ansel
Expand Up @@ -224,18 +224,16 @@ abstract class Ansel_Cli_Helper_Base
*/
public function emptyGalleryCheck(Ansel_Gallery $gallery)
{
global $storage;

if ($gallery->hasSubGalleries()) {
$children = $GLOBALS['injector']
->getInstance('Ansel_Storage')
->listGalleries(array('parent' => $gallery->id));
$children = $storage->listGalleries(array('parent' => $gallery->id));
foreach ($children as $child) {
// First check all children to see if they are empty...
$this->emptyGalleryCheck($child);
if (!$child->countImages() && !$child->hasSubGalleries()) {
try {
$GLOBALS['injector']
->getInstance('Ansel_Storage')
->removeGallery($child);
$storage->removeGallery($child);
} catch (Ansel_Exception $e) {
throw new Exception($e->getMessage());
}
Expand All @@ -246,16 +244,12 @@ abstract class Ansel_Cli_Helper_Base
}

// Refresh the gallery values since we mucked around a bit with it
$gallery = $GLOBALS['injector']
->getInstance('Ansel_Storage')
->getGallery($gallery->id);
$gallery = $storage->getGallery($gallery->id);

// Now that any empty children are removed, see if we are empty
if (!$gallery->countImages() && !$gallery->hasSubGalleries()) {
try {
$GLOBALS['injector']
->getInstance('Ansel_Storage')
->removeGallery($gallery);
$storage->removeGallery($gallery);
} catch (Ansel_Exception $e) {
throw new Exception($e->getMessage());
}
Expand Down Expand Up @@ -576,12 +570,10 @@ class Ansel_Cli_Helper_Local extends Ansel_Cli_Helper_Base
if (!$gallery = $this->_getGallery($gallery_id, $slug)) {
$name = basename($dir);
$this->_cli->message(sprintf(_("Creating gallery: \"%s\""), $name), 'cli.message');
$gallery = $GLOBALS['injector']
->getInstance('Ansel_Storage')
->createGallery(
array('name' => $name),
null,
$parent);
$gallery = $GLOBALS['storage']->createGallery(
array('name' => $name),
null,
$parent);
$this->_cli->message(
sprintf(_("The gallery \"%s\" was created successfully."), $name),
'cli.success');
Expand Down Expand Up @@ -646,22 +638,22 @@ class Ansel_Cli_Helper_Local extends Ansel_Cli_Helper_Base

public function listObjects($gallery = null, $slug = null)
{
global $storage;

if ($gallery = $this->_getGallery($gallery, $slug)) {
$images = $gallery->listImages();
$this->_cli->message(
sprintf(_("Listing photos in %s"), $gallery->get('name')), 'cli.success');
foreach ($images as $id) {
try {
$image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($id);
$image = $storage->getImage($id);
$this->_cli->writeln(str_pad($image->filename, 30) . $image->getVFSPath() . '/' . $id);
} catch (Exception $e) {
$this->_cli->message($e->getMessage(), 'cli.error');
}
}
} else {
$galleries = $GLOBALS['injector']
->getInstance('Ansel_Storage')
->listGalleries();
$galleries = $storage->listGalleries();
$this->_cli->message(_("Listing Gallery/Name"), 'cli.success');
$this->_cli->writeln();
foreach ($galleries as $gallery) {
Expand All @@ -688,9 +680,7 @@ class Ansel_Cli_Helper_Local extends Ansel_Cli_Helper_Base
'desc' => $desc,
'owner' => $GLOBALS['registry']->getAuth());
try {
$gallery = $GLOBALS['injector']
->getInstance('Ansel_Storage')
->createGallery($attributes, null, $parent_id);
$gallery = $GLOBALS['storage']->createGallery($attributes, null, $parent_id);
$msg = sprintf(
_("The gallery \"%s\" was created successfully."),
$name);
Expand Down Expand Up @@ -729,6 +719,8 @@ class Ansel_Cli_Helper_Local extends Ansel_Cli_Helper_Base
*/
public function reset($type = null)
{
global $storage;

if ($type && $type != 'thumbs' && $type != 'stacks') {
$this->_cli->message('Invalid image type. Must be either \"stacks\" or \"thumbs\"', 'cli.error');
return;
Expand All @@ -740,9 +732,7 @@ class Ansel_Cli_Helper_Local extends Ansel_Cli_Helper_Base
}
$this->_cli->message('Resetting thumbnails: ', 'cli.info');
try {
$galleries = $GLOBALS['injector']
->getInstance('Ansel_Storage')
->listAllGalleries();
$galleries = $storage->listAllGalleries();
} catch (Ansel_Exception $e) {
$this->_cli->fatal($e->getMessage());
}
Expand All @@ -766,10 +756,7 @@ class Ansel_Cli_Helper_Local extends Ansel_Cli_Helper_Base

public function exif($gallery)
{
$gallery = $GLOBALS['injector']
->getInstance('Ansel_Storage')
->getGallery($gallery);

$gallery = $GLOBALS['storage']->getGallery($gallery);
foreach ($gallery->getImages() as $image) {
$this->_cli->message(sprintf(_("Extracting EXIF for image %d"), $image->id));
$image->getEXIF(true);
Expand All @@ -783,16 +770,14 @@ class Ansel_Cli_Helper_Local extends Ansel_Cli_Helper_Base
*/
protected function _getGallery($gallery_id = null, $slug = null)
{
global $storage;

$gallery = false;
// Create a gallery or use an existing one?
if (!empty($gallery_id)) {
$gallery = $GLOBALS['injector']
->getInstance('Ansel_Storage')
->getGallery($gallery_id);
$gallery = $storage->getGallery($gallery_id);
} elseif (!empty($slug)) {
$gallery = $GLOBALS['injector']
->getInstance('Ansel_Storage')
->getGalleryBySlug($slug);
$gallery = $storage->getGalleryBySlug($slug);
}

return $gallery;
Expand Down
2 changes: 1 addition & 1 deletion ansel/disclamer.php
Expand Up @@ -13,7 +13,7 @@

$vars = Horde_Variables::getDefaultVariables();
try {
$gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($vars->get('gallery'));
$gallery = $storage->getGallery($vars->get('gallery'));
} catch (Ansel_Exception $e) {
$notification->push($gallery->getMessage());
Horde::url('view.php?view=List', true)->redirect();
Expand Down
8 changes: 4 additions & 4 deletions ansel/edit_dates.php
Expand Up @@ -18,7 +18,7 @@

/* If we have a single gallery, check perms now */
if (!empty($gallery_id)) {
$gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_id);
$gallery = $storage->getGallery($gallery_id);
if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) {
$notification->push(_("You are not allowed to edit these photos."), 'horde.error');
echo Horde::wrapInlineScript(array(
Expand Down Expand Up @@ -47,10 +47,10 @@
$count = 0;
foreach (array_keys($images) as $image_id) {
try {
$image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($image_id);
$image = $storage->getImage($image_id);
if (empty($gallery_id)) {
// Images might be from different galleries
$gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image->gallery);
$gallery = $storage->getGallery($image->gallery);
if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) {
continue;
}
Expand Down Expand Up @@ -82,7 +82,7 @@
foreach ($keys as $key) {
$html .= '<img src="' . Ansel::getImageUrl($key, 'mini', false) . '" style="margin:2px;" alt="[thumbnail]" />';
}
$image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage(array_pop($keys));
$image = $storage->getImage(array_pop($keys));
/* Display the form */
$vars->set('image', $images);
$vars->set('gallery', $gallery_id);
Expand Down
2 changes: 1 addition & 1 deletion ansel/faces/claim.php
Expand Up @@ -35,7 +35,7 @@
$notification->push(_("Action was cancelled."), 'horde.warning');
} else {
$report = Ansel_Report::factory();
$gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($face['gallery_id']);
$gallery = $storage->getGallery($face['gallery_id']);

$face_link = Horde::url('faces/custom.php', true)->add(
array('name' => $vars->get('person'),
Expand Down
4 changes: 2 additions & 2 deletions ansel/faces/custom.php
Expand Up @@ -24,14 +24,14 @@
$form_post = Horde::url('faces/savecustom.php')->add($urlparams);

try {
$image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($image_id);
$image = $storage->getImage($image_id);
} catch (Ansel_Exception $e) {
$notification->push($image);
Horde::url('list.php')->redirect();
exit;
}

$gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image->gallery);
$gallery = $storage->getGallery($image->gallery);
if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) {
$notification->push(_("Access denied editing the photo."));
Ansel::getUrlFor('view', array('gallery' => $image->gallery))->redirect();
Expand Down
2 changes: 1 addition & 1 deletion ansel/faces/gallery.php
Expand Up @@ -22,7 +22,7 @@
exit;
}
try {
$gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_id);
$gallery = $storage->getGallery($gallery_id);
} catch (Ansel_Exception $e) {
$notification->push($e->getMessage(), 'horde.error');
Ansel::getUrlFor('view', array('gallery' => $gallery_id))->redirect();
Expand Down
8 changes: 3 additions & 5 deletions ansel/faces/image.php
Expand Up @@ -23,15 +23,13 @@
// Attempt to get faces from the picture if we don't already have results,
// or if we were asked to explicitly try again.
if (($reload || empty($results))) {
$image = $GLOBALS['injector']
->getInstance('Ansel_Storage')
->getImage($image_id);
$image = $storage->getImage($image_id);
try {
$image->createView(
'screen',
null,
($GLOBALS['prefs']->getValue('watermark_auto') ?
$GLOBALS['prefs']->getValue('watermark_text', '') : '')
($prefs->getValue('watermark_auto') ?
$prefs->getValue('watermark_text', '') : '')
);
$results = $faces->getFromPicture($image_id, true);
} catch (Ansel_Exception $e) {
Expand Down
4 changes: 2 additions & 2 deletions ansel/faces/name.php
Expand Up @@ -17,8 +17,8 @@
$face_id = (int)Horde_Util::getFormData('face');
$name = Horde_Util::getFormData('name');

$image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($image_id);
$gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')>getGallery($image->gallery);
$image = $storage->getImage($image_id);
$gallery = $storage->getGallery($image->gallery);
if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) {
throw new Ansel_Exception('Access denied editing the photo.');
}
Expand Down
4 changes: 2 additions & 2 deletions ansel/faces/report.php
Expand Up @@ -15,7 +15,7 @@

$face_id = Horde_Util::getFormData('face');

$faces = $GLOBALS['injector']->getInstance('Ansel_Faces');
$faces = $injector->getInstance('Ansel_Faces');
try {
$face = $faces->getFaceById($face_id);
} catch (Ansel_Exception $e) {
Expand All @@ -39,7 +39,7 @@
} else {
require ANSEL_BASE . '/lib/Report.php';
$report = Ansel_Report::factory();
$gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($face['gallery_id']);
$gallery = $storage->getGallery($face['gallery_id']);

$face_link = Horde::url('faces/face.php', true)->add(
array('name' => $vars->get('person'),
Expand Down
4 changes: 1 addition & 3 deletions ansel/gallery/captions.php
Expand Up @@ -17,9 +17,7 @@
exit;
}
try {
$gallery = $GLOBALS['injector']
->getInstance('Ansel_Storage')
->getGallery($galleryId);
$gallery = $storage->getGallery($galleryId);
} catch (Ansel_Exception $e) {
$notification->push(
sprintf(_("Error accessing %s: %s"), $galleryId, $e->getMessage()),
Expand Down
8 changes: 5 additions & 3 deletions ansel/gallery/sort.php
Expand Up @@ -19,7 +19,7 @@
exit;
}
try {
$gallery = $injector->getInstance('Ansel_Storage')->getGallery($galleryId);
$gallery = $storage->getGallery($galleryId);
} catch (Ansel_Excception $e) {
$notification->push(_("There was an error accessing the gallery."), 'horde.error');
Ansel::getUrlFor('view', array('view' => 'List'), true)->redirect();
Expand Down Expand Up @@ -57,8 +57,10 @@
exit;
case 'Reset':
// Reset the sort order by date.
$images = $injector->getInstance('Ansel_Storage')
->listImages(array('gallery_id' => $galleryId, 'sort' => 'image_original_date'));
$images = $storage->listImages(array(
'gallery_id' => $galleryId,
'sort' => 'image_original_date')
);
$pos = 0;
foreach ($images as $id) {
$gallery->setImageOrder($id, $pos++);
Expand Down
4 changes: 2 additions & 2 deletions ansel/group.php
Expand Up @@ -29,8 +29,8 @@
switch ($groupby) {
case 'owner':
try {
if ($num_groups = $GLOBALS['injector']->getInstance('Ansel_Storage')->shares->countOwners(Horde_Perms::SHOW, null, false)) {
$groups = $GLOBALS['injector']->getInstance('Ansel_Storage')->shares->listOwners(
if ($num_groups = $storage->shares->countOwners(Horde_Perms::SHOW, null, false)) {
$groups = $storage->shares->listOwners(
Horde_Perms::SHOW,
null,
false,
Expand Down
2 changes: 1 addition & 1 deletion ansel/image.php
Expand Up @@ -25,7 +25,7 @@
// Check basic image actions.
if (Ansel_ActionHandler::imageActions($actionID)) {
$gallery_id = Horde_Util::getFormData('gallery');
$gallery = $injector->getInstance('Ansel_Storage')->getGallery($gallery_id);
$gallery = $storage->getGallery($gallery_id);
$children = $gallery->countGalleryChildren(Horde_Perms::SHOW);
$perpage = min(
$prefs->getValue('tilesperpage'),
Expand Down
4 changes: 2 additions & 2 deletions ansel/img/download.php
Expand Up @@ -11,8 +11,8 @@
require_once __DIR__ . '/../lib/Application.php';
Horde_Registry::appInit('ansel');

$image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage(Horde_Util::getFormData('image'));
$gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image->gallery);
$image = $storage->getImage(Horde_Util::getFormData('image'));
$gallery = $storage->getGallery($image->gallery);
if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::READ) || !$gallery->canDownload()) {
throw new Horde_Exception_PermissionDenied(_("Access denied viewing this photo."));
}
Expand Down
2 changes: 1 addition & 1 deletion ansel/img/ecard.php
Expand Up @@ -17,7 +17,7 @@
}

/* Get the gallery and the image, and abort if either fails. */
$gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery(Horde_Util::getFormData('gallery'));
$gallery = $storage->getGallery(Horde_Util::getFormData('gallery'));
$image = $gallery->getImage(Horde_Util::getFormData('image'));

/* Run through the action handlers. */
Expand Down
4 changes: 2 additions & 2 deletions ansel/img/full.php
Expand Up @@ -11,8 +11,8 @@
require_once __DIR__ . '/../lib/Application.php';
Horde_Registry::appInit('ansel');

$image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage(Horde_Util::getFormData('image'));
$gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image->gallery);
$image = $storage->getImage(Horde_Util::getFormData('image'));
$gallery = $storage->getGallery($image->gallery);
if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::READ) || !$gallery->canDownload()) {
throw new Horde_Exception_PermissionDenied(_("Access denied viewing this photo."));
}
Expand Down
4 changes: 2 additions & 2 deletions ansel/img/index.php
Expand Up @@ -11,8 +11,8 @@
require_once __DIR__ . '/../lib/Application.php';
Horde_Registry::appInit('ansel');

$image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage(Horde_Util::getFormData('image'));
$gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image->gallery);
$image = $storage->getImage(Horde_Util::getFormData('image'));
$gallery = $storage->getGallery($image->gallery);
if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::READ)) {
throw new Horde_Exception_PermissionDenied(_("Access denied viewing this photo."));
}
Expand Down
4 changes: 2 additions & 2 deletions ansel/img/mini.php
Expand Up @@ -11,8 +11,8 @@
require_once __DIR__ . '/../lib/Application.php';
Horde_Registry::appInit('ansel');

$image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage(Horde_Util::getFormData('image'));
$gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery(abs($image->gallery));
$image = $storage->getImage(Horde_Util::getFormData('image'));
$gallery = $storage->getGallery(abs($image->gallery));
if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::READ)) {
throw new Horde_Exception_PermissionDenied(_("Access denied viewing this photo."));
}
Expand Down
4 changes: 2 additions & 2 deletions ansel/img/screen.php
Expand Up @@ -11,8 +11,8 @@
require_once __DIR__ . '/../lib/Application.php';
Horde_Registry::appInit('ansel');

$image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage(Horde_Util::getFormData('image'));
$gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image->gallery);
$image = $storage->getImage(Horde_Util::getFormData('image'));
$gallery = $storage->getGallery($image->gallery);
if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::READ)) {
throw new Horde_Exception_PermissionDenied(_("Access denied viewing this photo."));
}
Expand Down

0 comments on commit 904f1b2

Please sign in to comment.