Horde_Registry::appInit('ansel');
$vars = Horde_Variables::getDefaultVariables();
-$gallery = $ansel_storage->getGallery($vars->get('gallery'));
-if (is_a($gallery, 'PEAR_Error')) {
+try {
+ $gallery = $ansel_storage->getGallery($vars->get('gallery'));
+} catch (Ansel_Exception $e) {
$notification->push($gallery->getMessage());
header('Location: ' . Horde::applicationUrl('view.php?view=List', true));
exit;
}
$url = $vars->get('url');
-
-
$form = new Horde_Form($vars, _("Content Disclaimer"), 'disclamer');
$form->addVariable($gallery->get('name'), 'name', 'description', false);
$form->addVariable($gallery->get('desc'), 'desc', 'description', false);
require ANSEL_TEMPLATES . '/common-header.inc';
require ANSEL_TEMPLATES . '/menu.inc';
-
$form->renderActive(null, null, null, 'post');
-
require $registry->get('templates', 'horde') . '/common-footer.inc';
if ($actionID == 'edit_dates') {
$count = 0;
foreach (array_keys($images) as $image_id) {
- $image = $ansel_storage->getImage($image_id);
- if (!is_a($image, 'PEAR_Error')) {
+ try {
+ $image = $ansel_storage->getImage($image_id);
if (empty($gallery_id)) {
// Images might be from different galleries
$gallery = $ansel_storage->getGallery($image->gallery);
- if (is_a($gallery, 'PEAR_Error') ||
- !$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+ if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
continue;
}
}
$image->originalDate = (int)$newDate->timestamp();
$image->save();
++$count;
- } else {
- $notification->push(sprintf(_("There was an error editing the dates: %s"), $image->getMessage()), 'horde.error');
+ } catch (Ansel_Exception $e) {
+ $notification->push(sprintf(_("There was an error editing the dates: %s"), $e->getMessage()), 'horde.error');
echo Horde::wrapInlineScript(array(
'window.opener.location.href = window.opener.location.href;',
'window.close();'
));
exit;
}
-
}
$notification->push(sprintf(_("Successfully modified the date on %d photos."), $count), 'horde.success');
if (Horde_Util::getFormData('submitbutton') == _("Cancel")) {
$notification->push(_("Action was cancelled."), 'horde.warning');
} else {
- require ANSEL_BASE . '/lib/Report.php';
$report = Ansel_Report::factory();
$gallery = $ansel_storage->getGallery($face['gallery_id']);
Horde::applicationUrl('faces/custom.php', true),
array('name' => $vars->get('person'),
'face' => $face_id,
- 'image' => $face['image_id']), null, false);
+ 'image' => $face['image_id']),
+ null,
+ false);
$title = _("I know who is on one of your photos");
$body = _("Gallery Name") . ': ' . $gallery->get('name') . "\n"
. _("Face") . ': ' . $face_link;
$report->setTitle($title);
- $result = $report->report($body, $gallery->get('owner'));
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(_("Face name was not reported.") . ' ' .
- $result->getMessage(), 'horde.error');
- } else {
+ try {
+ $result = $report->report($body, $gallery->get('owner'));
$notification->push(_("The owner of the photo, who will delegate the face name, was notified."), 'horde.success');
+ } catch (Ansel_Exception $e) {
+ $notification->push(_("Face name was not reported.") . ' ' . $e->getMessage(), 'horde.error');
}
}
require ANSEL_TEMPLATES . '/common-header.inc';
require ANSEL_TEMPLATES . '/menu.inc';
-
$form->renderActive(null, null, null, 'post');
-
require $registry->get('templates', 'horde') . '/common-footer.inc';
}
$form_post = Horde_Util::addParameter(Horde::applicationUrl('faces/savecustom.php'), $urlparams);
-$image = &$ansel_storage->getImage($image_id);
-if (is_a($image, 'PEAR_Error')) {
+try {
+ $image = $ansel_storage->getImage($image_id);
+} catch (Ansel_Exception $e) {
$notification->push($image);
header('Location: ' . Horde::applicationUrl('list.php'));
exit;
$faces = Ansel_Faces::factory();
try {
$face = $faces->getFaceById($face_id, true);
+ $x1 = $face['face_x1'];
+ $y1 = $face['face_y1'];
+ $x2 = $face['face_x2'];
+ $y2 = $face['face_y2'];
+ if (!empty($face['face_name'])) {
+ $name = $face['face_name'];
+ }
} catch (Horde_Exception $e) {
$notification->push($e->getMessage());
+ header('Location: ' . Horde::applicationUrl('list.php'));
}
-
- $x1 = $face['face_x1'];
- $y1 = $face['face_y1'];
- $x2 = $face['face_x2'];
- $y2 = $face['face_y2'];
- if (!empty($face['face_name'])) {
- $name = $face['face_name'];
- }
-
}
$height = $x2 - $x1;
header('Location: ' . Ansel::getUrlFor('default_view', array()));
exit;
}
-$gallery = $ansel_storage->getGallery($gallery_id);
-if (is_a($gallery, 'PEAR_Error')) {
- $notification->push($gallery->getMessage(), 'horde.error');
+try {
+ $gallery = $ansel_storage->getGallery($gallery_id);
+} catch (Ansel_Exception $e) {
+ $notification->push($e->getMessage(), 'horde.error');
header('Location: ' . Ansel::getUrlFor('view', array('gallery' => $gallery_id)));
exit;
-} elseif (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+}
+if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
$notification->push(sprintf(_("Access denied editing gallery \"%s\"."), $gallery->get('name')), 'horde.error');
header('Location: ' . Ansel::getUrlFor('view', array('gallery' => $gallery_id)));
exit;
$customurl = Horde_Util::addParameter(Horde::applicationUrl('faces/custom.php'), 'page', $page);
$face = Ansel_Faces::factory();
$autogenerate = $face->canAutogenerate();
+
$vars = Horde_Variables::getDefaultVariables();
$pager = new Horde_Ui_Pager(
- 'page', $vars,
- array('num' => $gallery->countImages(),
- 'url' => 'faces/gallery.php',
- 'perpage' => $perpage));
+ 'page',
+ $vars,
+ array(
+ 'num' => $gallery->countImages(),
+ 'url' => 'faces/gallery.php',
+ 'perpage' => $perpage
+ )
+);
$pager->preserve('gallery', $gallery_id);
$title = sprintf(_("Searching for faces in %s"), Horde::link(Ansel::getUrlFor('view', array('gallery' => $gallery_id, 'view' => 'Gallery'))) . $gallery->get('name') . '</a>');
$page = Horde_Util::getFormData('page', 0);
$perpage = $prefs->getValue('facesperpage');
-$count = $faces->countAllFaces();
-if (is_a($count, 'PEAR_Error')) {
+try {
+ $count = $faces->countAllFaces();
+ $results = $faces->allFaces($page * $perpage, $perpage);
+} catch (Ansel_Exception $e) {
$notification->push($count->getDebugInfo());
$count = 0;
$results = array();
-} else {
- $results = $faces->allFaces($page * $perpage, $perpage);
}
-
$vars = Horde_Variables::getDefaultVariables();
$pager = new Horde_Ui_Pager(
'page', $vars,
- array('num' => $count,
- 'url' => 'faces/search/all.php',
- 'perpage' => $perpage));
+ array(
+ 'num' => $count,
+ 'url' => 'faces/search/all.php',
+ 'perpage' => $perpage
+ )
+);
require ANSEL_TEMPLATES . '/common-header.inc';
require ANSEL_TEMPLATES . '/menu.inc';
$x2 = 0;
$y2 = 0;
-$faces = $faces->getFaces($path);
-if (is_a($faces, 'PEAR_Error')) {
+try {
+ $faces = $faces->getFaces($path);
+} catch (Ansel_Exception $e) {
exit;
}
$perpage = $prefs->getValue('facesperpage');
if (($face_id = Horde_Util::getGet('face_id')) !== null) {
- $face = $faces->getFaceById($face_id, true);
- if (is_a($face, 'PEAR_Error')) {
- $notification->push($face->getMessage());
+ try {
+ $face = $faces->getFaceById($face_id, true);
+ $signature = $face['face_signature'];
+ $results = $faces->getSignatureMatches($signature, $face_id, $perpage * $page, $perpage);
+ } catch (Ansel_Exception $e) {
+ $notification->push($e->getMessage());
header('Location: ' . Horde::applicationUrl('faces/search/image.php'));
}
- $signature = $face['face_signature'];
- $results = $faces->getSignatureMatches($signature, $face_id, $perpage * $page, $perpage);
} else {
$tmp = Horde::getTempDir();
$path = $tmp . '/search_face_' . Horde_Auth::getAuth() . '.sig';
header('Location: ' . Horde::applicationUrl('faces/search/image.php'));
}
$signature = file_get_contents($path);
- $results = $faces->getSignatureMatches($signature, 0, $perpage * $page, $perpage);
-}
-if (is_a($results, 'PEAR_Error')) {
- $notification->push($results);
- $results = array();
+ try {
+ $results = $faces->getSignatureMatches($signature, 0, $perpage * $page, $perpage);
+ } catch (Ansel_Exception $e) {
+ $notification->push($e->getMessage());
+ $results = array();
+ }
}
$title = _("Photo search");
$vars = Horde_Variables::getDefaultVariables();
$pager = new Horde_Ui_Pager(
- 'page', $vars,
- array('num' => count($results),
- 'url' => 'faces/search/image_search.php',
- 'perpage' => $perpage));
+ 'page',
+ $vars,
+ array(
+ 'num' => count($results),
+ 'url' => 'faces/search/image_search.php',
+ 'perpage' => $perpage
+ )
+);
require ANSEL_TEMPLATES . '/common-header.inc';
require ANSEL_TEMPLATES . '/menu.inc';
$page = Horde_Util::getFormData('page', 0);
$perpage = $prefs->getValue('facesperpage');
$results = array();
-$count = $faces->countNamedFaces();
-if (is_a($count, 'PEAR_Error')) {
+try {
+ $count = $faces->countNamedFaces();
+ $results = $faces->namedFaces($page * $perpage, $perpage);
+} catch (Ansel_Exception $e) {
$notification->push($count->getDebugInfo());
$count = 0;
-} elseif ($count > 0) {
- $results = $faces->namedFaces($page * $perpage, $perpage);
}
$vars = Horde_Variables::getDefaultVariables();
$pager = new Horde_Ui_Pager(
'page', $vars,
- array('num' => $count,
- 'url' => 'faces/search/named.php',
- 'perpage' => $perpage));
+ array(
+ 'num' => $count,
+ 'url' => 'faces/search/named.php',
+ 'perpage' => $perpage
+ )
+);
require ANSEL_TEMPLATES . '/common-header.inc';
require ANSEL_TEMPLATES . '/menu.inc';
$title = sprintf(_("From galleries of %s"), $owner);
}
-$count = $faces->countOwnerFaces($owner);
-if (is_a($count, 'PEAR_Error')) {
- $notification->push($count);
+try {
+ $count = $faces->countOwnerFaces($owner);
+ $results = $faces->ownerFaces($owner, $page * $perpage, $perpage);
+} catch (Ansel_Exception $e) {
+ $notification->push($e->getMessage(), 'horde.err');
$results = array();
$count = 0;
-} else {
- $results = $faces->ownerFaces($owner, $page * $perpage, $perpage);
}
$vars = Horde_Variables::getDefaultVariables();
$pager = new Horde_Ui_Pager(
- 'page', $vars,
- array('num' => $count,
- 'url' => 'faces/search/owner.php',
- 'perpage' => $perpage));
+ 'page',
+ $vars,
+ array(
+ 'num' => $count,
+ 'url' => 'faces/search/owner.php',
+ 'perpage' => $perpage
+ )
+);
$pager->preserve('owner', $owner);
-
require ANSEL_TEMPLATES . '/common-header.inc';
require ANSEL_TEMPLATES . '/menu.inc';
-
include ANSEL_TEMPLATES . '/faces/faces.inc';
-
require $registry->get('templates', 'horde') . '/common-footer.inc';
// Get the parent and make sure that it exists and that we have
// permissions to add to it.
$parentId = Horde_Util::getFormData('gallery');
- $parent = $ansel_storage->getGallery($parentId);
- if (is_a($parent, 'PEAR_Error')) {
- $notification->push($parent->getMessage(), 'horde.error');
+ try {
+ $parent = $ansel_storage->getGallery($parentId);
+ } catch (Ansel_Exception $e) {
+ $notification->push($e->getMessage(), 'horde.error');
header('Location: ' . Horde::applicationUrl('view.php?view=List', true));
exit;
- } elseif (!$parent->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
- $notification->push(
- sprintf(_("Access denied adding a gallery to \"%s\"."),
- $parent->get('name')), 'horde.error');
+ }
+
+ if (!$parent->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+ $notification->push(sprintf(_("Access denied adding a gallery to \"%s\"."),
+ $parent->get('name')), 'horde.error');
header('Location: ' . Horde::applicationUrl('view.php?view=List', true));
exit;
}
$gallery_passwd = '';
$notification->push('document.gallery.gallery_name.focus();', 'javascript');
-
$title = sprintf(_("Adding A Subgallery to %s"), $parent->get('name'));
break;
case 'downloadzip':
$galleryId = Horde_Util::getFormData('gallery');
$gallery = $ansel_storage->getGallery($galleryId);
- if (!Horde_Auth::getAuth() || is_a($gallery, 'PEAR_Error') ||
+ if (!Horde_Auth::getAuth() ||
!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
- $name = is_a($gallery, 'PEAR_Error')
- ? $galleryId
- : $gallery->get('name');
- $notification->push(sprintf(_("Access denied downloading photos from \"%s\"."), $name),
- 'horde.error');
+ $notification->push(sprintf(_("Access denied downloading photos from \"%s\"."), $gallery->get('name')), 'horde.error');
header('Location: ' . Horde::applicationUrl('view.php?view=List', true));
exit;
}
case 'modify':
$galleryId = Horde_Util::getFormData('gallery');
- $gallery = $ansel_storage->getGallery($galleryId);
- if (!is_a($gallery, 'PEAR_Error')) {
- // Set up the gallery attributes.
+
+ try {
+ $gallery = $ansel_storage->getGallery($galleryId);
+ // Set up the gallery attributes.
$gallery_name = $gallery->get('name');
$gallery_desc = $gallery->get('desc');
$gallery_category = $gallery->get('category');
}
$gallery_mode = $gallery->get('view_mode');
$gallery_passwd = $gallery->get('passwd');
- } else {
- $title = _("Unknown gallery");
+ } catch (Ansel_Exception $e) {
+ $title = _("Unknown Gallery");
}
+
break;
case 'save':
// Modifying an existing gallery.
$gallery = $ansel_storage->getGallery($galleryId);
- if (is_a($gallery, 'PEAR_Error') ||
- !$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
-
- $name = is_a($gallery, 'PEAR_Error')
- ? $galleryId
- : $gallery->get('name');
-
- $notification->push(sprintf(_("Access denied saving gallery \"%s\"."),
- $name), 'horde.error');
+ if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+ $notification->push(sprintf(_("Access denied saving gallery \"%s\"."), $gallery->get('name')), 'horde.error');
} else {
// Don't allow the display name to be nulled out.
if ($gallery_name) {
if ($gallery_parent != $old_parent_id) {
if (!is_null($gallery_parent)) {
$new_parent = $ansel_storage->getGallery($gallery_parent);
- if (is_a($new_parent, 'PEAR_Error')) {
- return $new_parent;
- }
} else {
$new_parent = null;
}
- $result = $gallery->setParent($new_parent);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result->getMessage(), 'horde.error');
- header('Location: ' . Horde::applicationUrl(
- Ansel::getUrlFor('view', array('view' => 'List'), true)));
+ try {
+ $result = $gallery->setParent($new_parent);
+ } catch (Ansel_Exception $e) {
+ $notification->push($e->getMessage(), 'horde.error');
+ header('Location: ' . Horde::applicationUrl(Ansel::getUrlFor('view', array('view' => 'List'), true)));
exit;
}
}
- $result = $gallery->save();
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result->getMessage(), 'horde.error');
- } else {
- $notification->push(_("The gallery was saved."),
- 'horde.success');
+ try {
+ $result = $gallery->save();
+ $notification->push(_("The gallery was saved."),'horde.success');
+ } catch (Ansel_Exception $e) {
+ $notification->push($e->getMessage(), 'horde.error');
}
}
} else {
// Is this a new subgallery?
if ($gallery_parent) {
- $parent = $ansel_storage->getGallery($gallery_parent);
- if (is_a($parent, 'PEAR_Error')) {
- $notification->push($parent->getMessage(), 'horde.error');
- header('Location: ' . Horde::applicationUrl(
- Ansel::getUrlFor('view', array('view' => 'List'), true)));
+ try {
+ $parent = $ansel_storage->getGallery($gallery_parent);
+ } catch (Ansel_Exception $e) {
+ $notification->push($e->getMessage(), 'horde.error');
+ header('Location: ' . Horde::applicationUrl(Ansel::getUrlFor('view', array('view' => 'List'), true)));
exit;
- } elseif (!$parent->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+ }
+ if (!$parent->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
$notification->push(sprintf(
_("You do not have permission to add children to %s."),
$parent->get('name')), 'horde.error');
- header('Location: ' . Horde::applicationUrl(
- Ansel::getUrlFor('view', array('view' => 'List'), true)));
+ header('Location: ' . Horde::applicationUrl(Ansel::getUrlFor('view', array('view' => 'List'), true)));
exit;
}
}
$perm = (!empty($parent)) ? $parent->getPermission() : null;
$parent = (!empty($gallery_parent)) ? $gallery_parent : null;
- $gallery = $ansel_storage->createGallery(array('name' => $gallery_name,
- 'desc' => $gallery_desc,
- 'category' => $gallery_category,
- 'tags' => explode(',', $gallery_tags),
- 'style' => $gallery_thumbstyle,
- 'slug' => $gallery_slug,
- 'age' => $gallery_age,
- 'download' => $gallery_download,
- 'view_mode' => $gallery_mode,
- 'passwd' => $gallery_passwd,
- ), $perm, $parent);
- if (is_a($gallery, 'PEAR_Error')) {
+ try {
+ $gallery = $ansel_storage->createGallery(
+ array('name' => $gallery_name,
+ 'desc' => $gallery_desc,
+ 'category' => $gallery_category,
+ 'tags' => explode(',', $gallery_tags),
+ 'style' => $gallery_thumbstyle,
+ 'slug' => $gallery_slug,
+ 'age' => $gallery_age,
+ 'download' => $gallery_download,
+ 'view_mode' => $gallery_mode,
+ 'passwd' => $gallery_passwd,
+ ),
+ $perm, $parent);
+
+ $galleryId = $gallery->getId();
+ $msg = sprintf(_("The gallery \"%s\" was created successfully."), $gallery_name);
+ Horde::logMessage($msg, 'DEBUG');
+ $notification->push($msg, 'horde.success');
+ } catch (Ansel_Exception $e) {
$galleryId = null;
$error = sprintf(_("The gallery \"%s\" couldn't be created: %s"),
$gallery_name, $gallery->getMessage());
Horde::logMessage($error, 'ERR');
$notification->push($error, 'horde.error');
- } else {
- $galleryId = $gallery->getId();
- $msg = sprintf(_("The gallery \"%s\" was created successfully."),
- $gallery_name);
- Horde::logMessage($msg, 'DEBUG');
- $notification->push($msg, 'horde.success');
}
+
}
// Clear the OtherGalleries widget cache
if ($GLOBALS['conf']['ansel_cache']['usecache']) {
$GLOBALS['cache']->expire('Ansel_OtherGalleries' . $gallery->get('owner'));
}
+
// Return to the last view.
$url = Horde_Util::getFormData('url');
- if (empty($url) && empty($exists) && !is_a($gallery, 'PEAR_Error')) {
+ if (empty($url) && empty($exists)) {
// Redirect to the images upload page for newly creted galleries
- $url = Horde_Util::addParameter(Horde::applicationUrl('img/upload.php'),
- 'gallery', $galleryId);
+ $url = Horde_Util::addParameter(Horde::applicationUrl('img/upload.php'), 'gallery', $galleryId);
} elseif (empty($url)) {
$url = Horde::applicationUrl('index.php', true);
}
// Print the confirmation screen.
$galleryId = Horde_Util::getFormData('gallery');
if ($galleryId) {
- $gallery = $ansel_storage->getGallery($galleryId);
- if (is_a($gallery, 'PEAR_Error')) {
- $notification->push($gallery->getMessage(), 'horde.error');
- } else {
+ try {
+ $gallery = $ansel_storage->getGallery($galleryId);
require ANSEL_TEMPLATES . '/common-header.inc';
require ANSEL_TEMPLATES . '/menu.inc';
require ANSEL_TEMPLATES . '/gallery/delete_confirmation.inc';
require $registry->get('templates', 'horde') . '/common-footer.inc';
exit;
+ } catch (Ansel_Exception $e) {
+ $notification->push($gallery->getMessage(), 'horde.error');
}
}
// Return to the gallery list.
- header('Location: ' . Horde::applicationUrl(
- Ansel::getUrlFor('view', array('view' => 'List'), true)));
+ header('Location: ' . Horde::applicationUrl(Ansel::getUrlFor('view', array('view' => 'List'), true)));
exit;
case 'generateDefault':
// Re-generate the default pretty gallery image.
$galleryId = Horde_Util::getFormData('gallery');
- $gallery = $ansel_storage->getGallery($galleryId);
- if (is_a($gallery, 'PEAR_Error')) {
- $notification->push($gallery->getMessage(), 'horde.error');
+ try {
+ $gallery = $ansel_storage->getGallery($galleryId);
+ $gallery->clearStacks();
+ $notification->push(_("The gallery's default photo has successfully been reset."), 'horde.success');
+ header('Location: ' . Horde::applicationUrl(Horde_Util::addParameter('view.php', 'gallery', $galleryId), true));
+ exit;
+ } catch (Ansel_Exception $e) {
+ $notification->push($e->getMessage(), 'horde.error');
header('Location: ' . Horde::applicationUrl('index.php', true));
exit;
}
- $gallery->clearStacks();
- $notification->push(
- _("The gallery's default photo has successfully been reset."),
- 'horde.success');
- $url = Horde_Util::addParameter('view.php', 'gallery', $galleryId);
- header('Location: ' . Horde::applicationUrl($url, true));
- exit;
case 'generateThumbs':
// Re-generate all of this gallery's prettythumbs.
$galleryId = Horde_Util::getFormData('gallery');
- $gallery = $ansel_storage->getGallery($galleryId);
- if (is_a($gallery, 'PEAR_Error')) {
+ try {
+ $gallery = $ansel_storage->getGallery($galleryId);
+ } catch (Ansel_Exception $e) {
$notification->push($gallery->getMessage(), 'horde.error');
header('Location: ' . Horde::applicationUrl('index.php', true));
exit;
}
$gallery->clearThumbs();
- $notification->push(
- _("The gallery's thumbnails have successfully been reset."),
- 'horde.success');
- $url = Horde_Util::addParameter('view.php', 'gallery', $galleryId);
- header('Location: ' . Horde::applicationUrl($url, true));
+ $notification->push(_("The gallery's thumbnails have successfully been reset."), 'horde.success');
+ header('Location: ' . Horde::applicationUrl(Horde_Util::addParameter('view.php', 'gallery', $galleryId), true));
exit;
case 'deleteCache':
- // Delete all cached image views. This will NOT immediately regenerate
- // all views that existed prior to this action. However it will remove all
- // cached views (leaving the originals) which will be generated on demand
- // by users browsing the site. Note that the first time each image is
- // viewed there will be a delay as the view is generated and cached.
- // This can be useful when changing the configured "screen" size in Ansel's
- // configuration.
+ // Delete all cached image views.
$galleryId = Horde_Util::getFormData('gallery');
- $gallery = $ansel_storage->getGallery($galleryId);
- if (is_a($gallery, 'PEAR_Error')) {
+ try {
+ $gallery = $ansel_storage->getGallery($galleryId);
+ } catch (Ansel_Exception $e) {
$notification->push($gallery->getMessage(), 'horde.error');
header('Location: ' . Horde::applicationUrl('index.php', true));
exit;
}
$gallery->clearViews();
- $notification->push(
- _("The gallery's views have successfully been reset."),
- 'horde.success');
- $url = Horde_Util::addParameter('view.php', 'gallery', $galleryId);
- header('Location: ' . Horde::applicationUrl($url, true));
+ $notification->push(_("The gallery's views have successfully been reset."), 'horde.success');
+ header('Location: ' . Horde::applicationUrl(Horde_Util::addParameter('view.php', 'gallery', $galleryId), true));
exit;
default:
- header('Location: ' . Horde::applicationUrl(
- Ansel::getUrlFor('view', array('view' => 'List'), true)));
+ header('Location: ' . Horde::applicationUrl(Ansel::getUrlFor('view', array('view' => 'List'), true)));
exit;
}
true));
exit;
}
-
-$gallery = $ansel_storage->getGallery($galleryId);
-if (is_a($gallery, 'PEAR_Error')) {
- $notification->push(sprintf(_("Error accessing %s: %s"), $galleryId, $gallery->getMessage()), 'horde.error');
- header('Location: ' . Ansel::getUrlFor('view', array('view' => 'List'),
- true));
+try {
+ $gallery = $ansel_storage->getGallery($galleryId);
+} catch (Ansel_Exception $e) {
+ $notification->push(sprintf(_("Error accessing %s: %s"), $galleryId, $e->getMessage()), 'horde.error');
+ header('Location: ' . Ansel::getUrlFor('view', array('view' => 'List'), true));
exit;
}
if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
$notification->push(sprintf(_("Access denied setting captions for %s."), $gallery->get('name')), 'horde.error');
- header('Location: ' . Ansel::getUrlFor('view', array('view' => 'List'),
- true));
+ header('Location: ' . Ansel::getUrlFor('view', array('view' => 'List'), true));
exit;
}
$galleryId = Horde_Util::getPost('gallery');
if ($galleryId) {
- $gallery = $ansel_storage->getGallery($galleryId);
-
+ try {
+ $gallery = $ansel_storage->getGallery($galleryId);
+ } catch (Ansel_Exception $e) {
+ $notification->push($e->getMessage(), 'horde.error');
+ // Return to the default view.
+ header('Location: ' . Ansel::getUrlFor('default_view', array()));
+ exit;
+ }
switch ($actionID) {
case 'delete':
- if (is_a($gallery, 'PEAR_Error')) {
- $notification->push($gallery->getMessage(), 'horde.error');
- } elseif (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
+ if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
$notification->push(sprintf(_("Access denied deleting gallery \"%s\"."),
$gallery->get('name')), 'horde.error');
} else {
- $result = $ansel_storage->removeGallery($gallery);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(sprintf(
- _("There was a problem deleting %s: %s"),
- $gallery->get('name'), $result->getMessage()),
- 'horde.error');
- } else {
+ try {
+ $ansel_storage->removeGallery($gallery);
$notification->push(sprintf(
_("Successfully deleted %s."),
$gallery->get('name')), 'horde.success');
+ } catch (Ansel_Exception $e) {
+ $notification->push(sprintf(
+ _("There was a problem deleting %s: %s"),
+ $gallery->get('name'), $e->getMessage()),
+ 'horde.error');
}
}
exit;
case 'empty':
- if (is_a($gallery, 'PEAR_Error')) {
- $notification->push($gallery->getMessage(), 'horde.error');
- } elseif (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
+ if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
$notification->push(sprintf(_("Access denied deleting gallery \"%s\"."),
$gallery->get('name')),
'horde.error');
true));
exit;
}
-
-$gallery = $ansel_storage->getGallery($galleryId);
-if (is_a($gallery, 'PEAR_Error')) {
+try {
+ $gallery = $ansel_storage->getGallery($galleryId);
+} catch (Ansel_Excception $e) {
$notification->push(_("There was an error accessing the gallery."), 'horde.error');
- header('Location: ' . Ansel::getUrlFor('view', array('view' => 'List'),
- true));
+ header('Location: ' . Ansel::getUrlFor('view', array('view' => 'List'), true));
exit;
-} elseif (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+}
+
+if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
$notification->push(sprintf(_("Access denied editing gallery \"%s\"."), $gallery->get('name')), 'horde.error');
- header('Location: ' . Ansel::getUrlFor('view', array('view' => 'List'),
- true));
+ header('Location: ' . Ansel::getUrlFor('view', array('view' => 'List'), true));
exit;
}
+
$style = $gallery->getStyle();
$date = Ansel::getDateParameter();
$gallery->setDate($date);
switch ($groupby) {
case 'category':
- $num_groups = $ansel_storage->countCategories(Horde_Perms::SHOW);
- if (is_a($num_groups, 'PEAR_Error')) {
+ try {
+ $num_groups = $ansel_storage->countCategories(Horde_Perms::SHOW);
+ } catch (Ansel_Exception $e) {
$notification->push($num_groups);
$num_groups = 0;
$groups = array();
- } elseif ($num_groups) {
+ }
+ if ($num_groups) {
$groups = $ansel_storage->listCategories(Horde_Perms::SHOW,
$gbpage * $groups_perpage,
$groups_perpage);
default:
header('Location: ' . Ansel::getUrlFor('view',
- array('view' => 'List',
- 'groupby' => $groupby),
+ array(
+ 'view' => 'List',
+ 'groupby' => $groupby
+ ),
true));
exit;
}
// Set up pager.
$vars = Horde_Variables::getDefaultVariables();
-$group_pager = new Horde_Ui_Pager('gbpage', $vars,
- array('num' => $num_groups,
- 'url' => 'group.php',
- 'perpage' => $groups_perpage));
+$group_pager = new Horde_Ui_Pager('gbpage',
+ $vars,
+ array(
+ 'num' => $num_groups,
+ 'url' => 'group.php',
+ 'perpage' => $groups_perpage
+ ));
$min = $gbpage * $groups_perpage;
$max = $min + $groups_perpage;
}
/* Get the gallery object and style information */
-$gallery = $ansel_storage->getGallery($gallery_id);
-if (is_a($gallery, 'PEAR_Error')) {
+try {
+ $gallery = $ansel_storage->getGallery($gallery_id);
+} catch (Ansel_Exception $e) {
$notification->push(sprintf(_("Gallery %s not found."), $gallery_id), 'horde.error');
header('Location: ' . Ansel::getUrlFor('view', array('view' => 'List'), true));
exit;
exit;
case 'modify':
- $image = &$ansel_storage->getImage($image_id);
- $ret = Horde_Util::getFormData('ret', 'gallery');
-
- if (is_a($image, 'PEAR_Error')) {
+ try {
+ $image = &$ansel_storage->getImage($image_id);
+ $ret = Horde_Util::getFormData('ret', 'gallery');
+ } catch (Ansel_Exception $e) {
$notification->push(_("Photo not found."), 'horde.error');
header('Location: ' . Ansel::getUrlFor('view', array('view' => 'List'), true));
exit;
$vars->set('image_uploaded', $image->uploaded);
require ANSEL_TEMPLATES . '/common-header.inc';
- $form->renderActive($renderer, $vars, 'image.php', 'post',
- 'multipart/form-data');
-
+ $form->renderActive($renderer, $vars, 'image.php', 'post', 'multipart/form-data');
require $registry->get('templates', 'horde') . '/common-footer.inc';
exit;
$image->originalDate = (int)$newDate->timestamp();
if (!empty($data)) {
- $result = $image->replace($data);
- if (is_a($result, 'PEAR_Error')) {
+ try {
+ $image->replace($data);
+ } catch (Ansel_Exception $e) {
$notification->push(_("There was an error replacing the photo."), 'horde.error');
}
}
$gallery->get('name')),
'horde.error');
} else {
- $image = &$ansel_storage->getImage($image_id);
- if (is_a($image, 'PEAR_Error')) {
- $notification->push($image->getMessage(), 'horde.error');
+ try {
+ $image = $ansel_storage->getImage($image_id);
+ } catch (Ansel_Exception $e) {
+ $notification->push($e->getMessage(), 'horde.error');
header('Location: ' . Ansel::getUrlFor('view', array('view' => 'List'), true));
exit;
}
case 'crop':
$image->load('full');
$params = Horde_Util::getFormData('params');
- list($x1, $y1, $x2, $y2) = explode('.', $params);
- $result = $image->crop($x1, $y1, $x2, $y2);
- if (is_a($result, 'PEAR_Error')) {
+ list($x1, $y1, $x2, $y2) = explode('.', $params
+ try {
+ $result = $image->crop($x1, $y1, $x2, $y2);
+ } catch (Ansel_Exception $e) {
Horde::logMessage($result, 'ERR');
$notification->push($result->getMessage(), 'horde.error');
$error = true;
case 'setwatermark':
$title = _("Watermark");
- $image = &$ansel_storage->getImage($image_id);
- if (is_a($image, 'PEAR_Error')) {
+ try {
+ $image = $ansel_storage->getImage($image_id);
+ } catch (Ansel_Exception $e) {
$notification->push($image->getMessage(), 'horde.error');
header('Location: ' . Ansel::getUrlFor('view', array('view' => 'List'), true));
exit;
$notification->push(sprintf(_("Access denied deleting photos from \"%s\"."), $gallery->get('name')), 'horde.error');
} else {
foreach ($images as $image) {
- $result = $gallery->removeImage($image);
- if (is_a($result, 'PEAR_Error')) {
+ try {
+ $gallery->removeImage($image);
+ $notification->push(_("Deleted the photo."), 'horde.success');
+ } catch (Ansel_Exception $e) {
$notification->push(
sprintf(_("There was a problem deleting photos: %s"),
$result->getMessage()), 'horde.error');
- } else {
- $notification->push(_("Deleted the photo."),
- 'horde.success');
}
}
}
/* Move the images if we're provided with at least one valid image_id. */
$newGallery = Horde_Util::getFormData('new_gallery');
if ($images && $newGallery) {
- $newGallery = $ansel_storage->getGallery($newGallery);
- if (is_a($newGallery, 'PEAR_Error')) {
- $notification->push(_("Bad input."), 'horde.error');
- } else {
+ try {
+ $newGallery = $ansel_storage->getGallery($newGallery);
$result = $gallery->moveImagesTo($images, $newGallery);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result, 'horde.error');
- } else {
- $notification->push(
- sprintf(ngettext("Moved %d photo from \"%s\" to \"%s\"",
- "Moved %d photos from \"%s\" to \"%s\"",
- $result),
- $result, $gallery->get('name'), $newGallery->get('name')),
- 'horde.success');
- }
+ $notification->push(
+ sprintf(ngettext("Moved %d photo from \"%s\" to \"%s\"",
+ "Moved %d photos from \"%s\" to \"%s\"",
+ $result),
+ $result, $gallery->get('name'), $newGallery->get('name')),
+ 'horde.success');
+ } catch (Ansel_Exception $e) {
+ $notification->push(_("Bad input."), 'horde.error');
}
}
* ID. */
$newGallery = Horde_Util::getFormData('new_gallery');
if ($images && $newGallery) {
- $newGallery = $ansel_storage->getGallery($newGallery);
- if (is_a($newGallery, 'PEAR_Error')) {
- $notification->push(_("Bad input."), 'horde.error');
- } else {
+ try {
+ $newGallery = $ansel_storage->getGallery($newGallery);
$result = $gallery->copyImagesTo($images, $newGallery);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result, 'horde.error');
- } else {
- $notification->push(
+ $notification->push(
sprintf(ngettext("Copied %d photo to %s",
"Copied %d photos to %s", $result),
$result, $newGallery->get('name')),
'horde.success');
- }
- }
+ } catch (Ansel_Exception $e) {
+ $notification->push(_("Bad input."), 'horde.error');
+
+ }
}
/* Return to the image list. */
$galleryId = Horde_Util::getFormData('gallery');
if ($galleryId) {
$gallery = $ansel_storage->getGallery($galleryId);
- if (!Horde_Auth::getAuth() || is_a($gallery, 'PEAR_Error') ||
+ if (!Horde_Auth::getAuth() ||
!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ) ||
$gallery->hasPasswd() || !$gallery->isOldEnough()) {
- $name = is_a($gallery, 'PEAR_Error') ? $galleryId : $gallery->get('name');
- $notification->push(sprintf(_("Access denied downloading photos from \"%s\"."), $name),
- 'horde.error');
+ $notification->push(sprintf(_("Access denied downloading photos from \"%s\"."), $gallery->get('name')), 'horde.error');
header('Location: ' . Horde::applicationUrl('view.php?view=List', true));
exit;
}
require_once dirname(__FILE__) . '/../lib/Application.php';
Horde_Registry::appInit('ansel');
-$id = Horde_Util::getFormData('image');
-$image = &$ansel_storage->getImage($id);
-if (is_a($image, 'PEAR_Error')) {
- Horde::fatal($image, __FILE__, __LINE__);
-}
+$image = $ansel_storage->getImage(Horde_Util::getFormData('image'));
$gallery = $ansel_storage->getGallery($image->gallery);
-if (is_a($gallery, 'PEAR_Error')) {
- Horde::fatal($gallery, __FILE__, __LINE__);
-}
-if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ) ||
- !$gallery->canDownload()) {
- Horde::fatal(_("Access denied viewing this photo."), __FILE__, __LINE__);
+if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ) || !$gallery->canDownload()) {
+ throw new Horde_Exception_PermissionDenied(_("Access denied viewing this photo."), __FILE__, __LINE__);
}
-
$image->downloadHeaders();
/* Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file header */
exit;
}
-if (is_a($result = $image->display('full'), 'PEAR_Error')) {
- Horde::fatal($result, __FILE__, __LINE__);
-}
+$image->display('full');
/* Get the gallery and the image, and abort if either fails. */
$gallery = $ansel_storage->getGallery(Horde_Util::getFormData('gallery'));
-if (is_a($gallery, 'PEAR_Error')) {
- exit;
-}
$image = &$gallery->getImage(Horde_Util::getFormData('image'));
-if (is_a($image, 'PEAR_Error')) {
- exit;
-}
/* Run through the action handlers. */
switch (Horde_Util::getFormData('actionID')) {
$alt->setBasePart($alternative);
/* Send. */
- $result = $alt->send($injector->getInstance('Horde_Mail'));
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(sprintf(_("There was an error sending your message: %s"), $result->getMessage()), 'horde.error');
- } else {
- echo Horde::wrapInlineScript(array('window.close();'));
- exit;
+ try {
+ $result = $alt->send($injector->getInstance('Horde_Mail'));
+ } catch (Horde_Mime_Exception $e) {
+ $notification->push(sprintf(_("There was an error sending your message: %s"), $e->getMessage()), 'horde.error');
}
+ echo Horde::wrapInlineScript(array('window.close();'));
+ exit;
}
$title = sprintf(_("Send Ecard :: %s"), $image->filename);
require_once dirname(__FILE__) . '/../lib/Application.php';
Horde_Registry::appInit('ansel');
-$id = Horde_Util::getFormData('image');
-$image = &$ansel_storage->getImage($id);
-if (is_a($image, 'PEAR_Error')) {
- Horde::fatal($image, __FILE__, __LINE__);
-}
+$image = $ansel_storage->getImage(Horde_Util::getFormData('image'));
$gallery = $ansel_storage->getGallery($image->gallery);
-if (is_a($gallery, 'PEAR_Error')) {
- Horde::fatal($gallery, __FILE__, __LINE__);
-}
-if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ) ||
- !$gallery->canDownload()) {
- Horde::fatal(_("Access denied viewing this photo."), __FILE__, __LINE__);
+if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ) || !$gallery->canDownload()) {
+ throw new Horde_Exception_PermissionDenied(_("Access denied viewing this photo."));
}
/* Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file header */
header('X-Sendfile: ' . $filename);
exit;
}
-
-if (is_a($result = $image->display('full'), 'PEAR_Error')) {
- Horde::fatal($result, __FILE__, __LINE__);
-}
+$image->display('full');
require_once dirname(__FILE__) . '/../lib/Application.php';
Horde_Registry::appInit('ansel');
-$id = Horde_Util::getFormData('image');
-$image = &$ansel_storage->getImage($id);
-if (is_a($image, 'PEAR_Error')) {
- Horde::fatal($image, __FILE__, __LINE__);
-}
+$image = &$ansel_storage->getImage(Horde_Util::getFormData('image'));
$gallery = $ansel_storage->getGallery($image->gallery);
-if (is_a($gallery, 'PEAR_Error')) {
- Horde::fatal($gallery, __FILE__, __LINE__);
-}
if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
- Horde::fatal(_("Access denied viewing this photo."), __FILE__, __LINE__);
+ throw new Horde_Exception_PermissionDenied(_("Access denied viewing this photo."));
}
/* Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file header */
exit;
}
-if (is_a($result = $image->display('screen'), 'PEAR_Error')) {
- Horde::fatal($result, __FILE__, __LINE__);
-}
+$image->display('screen');
require_once dirname(__FILE__) . '/../lib/Application.php';
Horde_Registry::appInit('ansel');
-$id = Horde_Util::getFormData('image');
-$image = &$ansel_storage->getImage($id);
-if (is_a($image, 'PEAR_Error')) {
- Horde::fatal($image, __FILE__, __LINE__);
-}
+$image = $ansel_storage->getImage(Horde_Util::getFormData('image'));
$gallery = $ansel_storage->getGallery(abs($image->gallery));
-if (is_a($gallery, 'PEAR_Error')) {
- Horde::fatal($gallery, __FILE__, __LINE__);
-}
if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
- Horde::fatal(_("Access denied viewing this photo."), __FILE__, __LINE__);
+ throw new Horde_Exception_PermissionDenied(_("Access denied viewing this photo."));
}
/* Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file header */
header('X-Sendfile: ' . $filename);
exit;
}
-
-if (is_a($result = $image->display('mini'), 'PEAR_Error')) {
- Horde::fatal($result, __FILE__, __LINE__);
-}
+$image->display('mini');
Horde_Registry::appInit('ansel');
$style = Horde_Util::getFormData('style');
-$id = Horde_Util::getFormData('image');
-$image = &$ansel_storage->getImage($id);
-if (is_a($image, 'PEAR_Error')) {
- Horde::fatal($image, __FILE__, __LINE__);
-}
+$image = $ansel_storage->getImage(Horde_Util::getFormData('image'));
$gallery = $ansel_storage->getGallery(abs($image->gallery));
-if (is_a($gallery, 'PEAR_Error')) {
- Horde::fatal($gallery, __FILE__, __LINE__);
-}
if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
- Horde::fatal(_("Access denied viewing this photo."), __FILE__, __LINE__);
+ throw new Horde_Exception_PermissionDenied(_("Access denied viewing this photo."));
}
/* Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file header */
require_once dirname(__FILE__) . '/../lib/Application.php';
Horde_Registry::appInit('ansel');
-$id = Horde_Util::getFormData('image');
-$image = &$ansel_storage->getImage($id);
-if (is_a($image, 'PEAR_Error')) {
- Horde::fatal($image, __FILE__, __LINE__);
-}
+$image = &$ansel_storage->getImage(Horde_Util::getFormData('image'));
$gallery = $ansel_storage->getGallery($image->gallery);
-if (is_a($gallery, 'PEAR_Error')) {
- Horde::fatal($gallery, __FILE__, __LINE__);
-}
if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
- Horde::fatal(_("Access denied viewing this photo."), __FILE__, __LINE__);
+ throw new Horde_Exception_PermissionDenied(_("Access denied viewing this photo."));
}
/* Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file header */
header('X-Sendfile: ' . $filename);
exit;
}
-
-if (is_a($result = $image->display('screen'), 'PEAR_Error')) {
- Horde::fatal($result, __FILE__, __LINE__);
-}
+$image->display('screen');
require_once dirname(__FILE__) . '/../lib/Application.php';
Horde_Registry::appInit('ansel');
-$id = Horde_Util::getFormData('image');
-$image = &$ansel_storage->getImage($id);
-if (is_a($image, 'PEAR_Error')) {
- Horde::fatal($image, __FILE__, __LINE__);
-}
+$image = $ansel_storage->getImage(Horde_Util::getFormData('image'));
$gallery = $ansel_storage->getGallery(abs($image->gallery));
-if (is_a($gallery, 'PEAR_Error')) {
- Horde::fatal($gallery, __FILE__, __LINE__);
-}
if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
- Horde::fatal(_("Access denied viewing this photo."), __FILE__, __LINE__);
+ throw new Horde_Exception_PermissionDenied(_("Access denied viewing this photo."));
}
/* Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file header */
exit;
}
-if (is_a($result = $image->display('thumb'), 'PEAR_Error')) {
- Horde::fatal($result, __FILE__, __LINE__);
-}
+$image->display('thumb');
Horde_Registry::appInit('ansel');
$gallery_id = Horde_Util::getFormData('gallery');
-$gallery = &$ansel_storage->getGallery($gallery_id);
-if (is_a($gallery, 'PEAR_Error')) {
+try {
+ $gallery = $ansel_storage->getGallery($gallery_id);
+} catch (Ansel_Exception $e) {
$notification->push(sprintf(_("Gallery %s not found."), $gallery_id), 'horde.error');
header('Location: ' . Ansel::getUrlFor('view', array('view' => 'List'), true));
exit;
break;
}
- /* If we successfully got data, try adding the
- * image to the gallery. */
- $image_id = $gallery->addImage(array(
- 'image_filename' => $zinfo['name'],
- 'image_caption' => '',
- 'data' => $zdata,
- ));
- unset($zdata);
- if (!is_a($image_id, 'PEAR_Error')) {
+ /* If we successfully got data, try adding the image */
+ try {
+ $image_id = $gallery->addImage(
+ array(
+ 'image_filename' => $zinfo['name'],
+ 'image_caption' => '',
+ 'data' => $zdata)
+ );
++$uploaded;
if ($conf['image']['autogen'] > count($image_ids)) {
$image_ids[] = $image_id;
}
- } else {
+ } catch (Ansel_Exception $e) {
$notification->push(sprintf(_("There was a problem saving the photo: %s"), $image_id), 'horde.error');
}
+ unset($zdata);
}
$zip->close();
$data = file_get_contents($info['file' . $i]['file']);
/* Get the list of files in the zipfile. */
- $zip = Horde_Compress::factory('zip');
- $files = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_LIST));
-
- if (is_a($files, 'PEAR_Error')) {
- $notification->push(sprintf(_("There was an error processing the uploaded archive: %s"), $files->getMessage()), 'horde.error');
+ try {
+ $zip = Horde_Compress::factory('zip');
+ $files = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_LIST));
+ } catch (Horde_Exception $e) {
+ $notification->push(sprintf(_("There was an error processing the uploaded archive: %s"), $e->getMessage()), 'horde.error');
continue;
}
continue;
}
- $zdata = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_DATA,
- 'info' => $files,
- 'key' => $key));
- if (is_a($zdata, 'PEAR_Error')) {
- $notification->push(sprintf(_("There was an error processing the uploaded archive: %s"), $zdata->getMessage()), 'horde.error');
+ try {
+ $zdata = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_DATA,
+ 'info' => $files,
+ 'key' => $key));
+ } catch (Horde_Exception $e) {
+ $notification->push(sprintf(_("There was an error processing the uploaded archive: %s"), $e->getMessage()), 'horde.error');
break;
}
- /* If we successfully got data, try adding the
- * image to the gallery. */
- $image_id = $gallery->addImage(array(
- 'image_filename' => $zinfo['name'],
- 'image_caption' => '',
- 'data' => $zdata,
- ));
- unset($zdata);
- if (!is_a($image_id, 'PEAR_Error')) {
+ /* If we successfully got data, try adding the image */
+ try {
+ $image_id = $gallery->addImage(
+ array(
+ 'image_filename' => $zinfo['name'],
+ 'image_caption' => '',
+ 'data' => $zdata)
+ );
++$uploaded;
if ($conf['image']['autogen'] > count($image_ids)) {
$image_ids[] = $image_id;
}
- } else {
+ } catch (Ansel_Exception $e) {
$notification->push(sprintf(_("There was a problem saving the photo: %s"), $image_id), 'horde.error');
}
+ unset($zdata);
}
-
unset($zip);
unset($data);
}
'image_type' => $info['file' . $i]['type'],
'data' => $data,
'tags' => (isset($info['image' . $i . '_tags']) ? explode(',', $info['image' . $i . '_tags']) : array()));
- $image_id = $gallery->addImage($image_data, (bool)$vars->get('image' . $i . '_default'));
- unset($data);
- if (is_a($image_id, 'PEAR_Error')) {
- $notification->push(sprintf(_("There was a problem saving the photo: %s"), $image_id->getMessage()), 'horde.error');
- $valid = false;
- } else {
+ try {
+ $image_id = $gallery->addImage($image_data, (bool)$vars->get('image' . $i . '_default'));
++$uploaded;
$image_ids[] = $image_id;
+ } catch (Ansel_Exception $e) {
+ $notification->push(sprintf(_("There was a problem saving the photo: %s"), $image_id->getMessage()), 'horde.error');
+ $valid = false;
}
+ unset($data);
}
}
require_once dirname(__FILE__) . '/../lib/Application.php';
Horde_Registry::appInit('ansel');
-
-$gallery_id = (int)Horde_Util::getFormData('gallery');
-$gallery = $ansel_storage->getGallery($gallery_id);
-if (is_a($gallery, 'PEAR_Error') ||
- !$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
- die(sprintf(_("Gallery %s not found."), $gallery_id));
+$gallery = $ansel_storage->getGallery((int)Horde_Util::getFormData('gallery'));
+if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
+ throw new Horde_Exception_PermissionDenied();
}
$from = (int)Horde_Util::getFormData('from');
$count = $to - $from + 1;
$images = $gallery->getImages($from, $count);
-if (is_a($images, 'PEAR_Error')) {
- die($images->getError());
-}
-
foreach ($images as $image) {
echo '<li class="small">';
echo '<div style="width:90px;">';
$g = $GLOBALS['ansel_storage']->getGallery($image->gallery);
if ($g->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
$image->caption = $pref_value;
- $result = $image->save();
- if (is_a($result, 'PEAR_Error')) {
+ try {
+ $result = $image->save();
+ } catch (Ansel_Exception $e) {
return '';
}
}
}
// Get the image and gallery to check perms
- $image = $GLOBALS['ansel_storage']->getImage((int)$img);
- if (is_a($image, 'PEAR_Error')) {
- return array('response' => 0);
- }
- $gallery = $GLOBALS['ansel_storage']->getGallery($image->gallery);
- if (is_a($gallery, 'PEAR_Error')) {
+ try {
+ $image = $GLOBALS['ansel_storage']->getImage((int)$img);
+ $gallery = $GLOBALS['ansel_storage']->getGallery($image->gallery);
+ } catch (Ansel_Exception $e) {
return array('response' => 0);
}
+
// Bail out if no perms on the image.
if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
return array('response' => 0);
!($input = Horde_Util::getFormData($args['input']))) {
return array();
}
- $locs = $GLOBALS['ansel_storage']->searchLocations($input);
- if (is_a($locs, 'PEAR_Error')) {
- Horde::logMessage($locs->getMessage(), 'ERR');
- $locs = new StdClass();
- }
- if (!count($locs)) {
+ try {
+ $locs = $GLOBALS['ansel_storage']->searchLocations($input);
+ if (!count($locs)) {
+ $locs = new StdClass();
+ }
+ } catch (Ansel_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
$locs = new StdClass();
}
return $locs;
/**
* Create and initialize the database object.
*
- * @return mixed MDB2 object || PEAR_Error
+ * @return mixed MDB2 object
+ * @throws Ansel_Exception
*/
static public function &getDb()
{
$config = $GLOBALS['conf']['sql'];
unset($config['charset']);
$mdb = MDB2::singleton($config);
- if (is_a($mdb, 'PEAR_Error')) {
- return $mdb;
+ if ($mdb instanceof PEAR_Error) {
+ throw new Ansel_Exception($mdb->getMessage());
}
$mdb->setOption('seqcol_name', 'id');
*/
static public function getVFS()
{
+ // @TODO: need to refactor the Vfs binder to a factory so we can handle
+ // vfs objects for different scopes.
$v_params = Horde::getVFSConfig('images');
return VFS::singleton($v_params['type'], $v_params['params']);
}
}
/**
- * Return a link to a photo placeholder, suitable for use in an <img/>
- * tag (or a Horde::img() call, with the path parameter set to * '').
* This photo should be used as a placeholder if the correct photo can't
* be retrieved
*
* @param string $controller The controller to generate a URL for.
* @param array $data The data needed to generate the URL.
* @param boolean $full Generate a full URL.
- * @param integer $append_session 0 = only if needed, 1 = always,
- * -1 = never.
+ * @param integer $append_session 0 = only if needed, 1 = always, -1 = never.
*
- * @param string The generated URL
+ * @return Horde_Url The generated URL
*/
static public function getUrlFor($controller, $data, $full = false, $append_session = 0)
{
if ($data['view'] == 'Gallery' || $data['view'] == 'Image') {
/**
- * This is needed to correctly generate URLs for images in
+ * @TODO: This is needed to correctly generate URLs for images in
* places that are not specifically requested by the user,
* for instance, in a gallery block. Otherwise, the proper
* date variables would not be attached to the url, since we
// Getting these objects is not ideal, but at this point
// they should already be locally cached so the cost
// is minimized.
- $i = &$GLOBALS['ansel_storage']->getImage($data['image']);
- $g = &$GLOBALS['ansel_storage']->getGallery($data['gallery']);
- if (!is_a($g, 'PEAR_Error') &&
- !is_a($i, 'PEAR_Error') &&
- $g->get('view_mode') == 'Date') {
+ $i = $GLOBALS['ansel_storage']->getImage($data['image']);
+ $g = $GLOBALS['ansel_storage']->getGallery($data['gallery']);
+ if ($g->get('view_mode') == 'Date') {
$imgDate = new Horde_Date($i->originalDate);
$data['year'] = $imgDate->year;
* @param boolean $full Return a path that includes the server name?
* @param string $style Use this gallery style
*
- * @return string The image path.
+ * @return Horde_Url The image path.
*/
static public function getImageUrl($imageId, $view = 'screen', $full = false, $style = null)
{
}
if (empty($imageId)) {
- return Ansel::getErrorImage($view);
+ return Horde::applicationUrl((string)Ansel::getErrorImage($view), $full);
}
// Default to ansel_default since we really only need to know the style
$image = $ansel_storage->getImage($imageId);
} catch (Ansel_Exception $e) {
Horde::logMessage($e, 'ERR');
- return Ansel::getErrorImage($view);
+ return Horde::applicationUrl((string)Ansel::getErrorImage($view), $full);
}
try {
$image->createView($view, $style, false);
} catch (Ansel_Exception $e) {
- return Ansel::getErrorImage($view);
+ return Horde::applicationUrl((string)Ansel::getErrorImage($view), $full);
}
- $viewHash = $image->getViewHash($view, $style) . '/'
- . $image->getVFSName($view);
+ $viewHash = $image->getViewHash($view, $style) . '/' . $image->getVFSName($view);
}
// First check for vfs-direct. If we are not using it, pass this off to
if (!is_null($style)) {
$params['style'] = $style;
}
- $url = Horde_Util::addParameter('img/' . $view . '.php', $params);
- return Horde::applicationUrl($url, $full);
+ return Horde::applicationUrl(Horde_Util::addParameter('img/' . $view . '.php', $params), $full);
}
// Using vfs-direct
- $path = substr(str_pad($imageId, 2, 0, STR_PAD_LEFT), -2) . '/'
- . $viewHash;
+ $path = substr(str_pad($imageId, 2, 0, STR_PAD_LEFT), -2) . '/' . $viewHash;
if ($full && substr($conf['vfs']['path'], 0, 7) != 'http://') {
return Horde::url($conf['vfs']['path'] . $path, true, -1);
} else {
- return $conf['vfs']['path'] . htmlspecialchars($path);
+ return new Horde_Url($conf['vfs']['path'] . htmlspecialchars($path));
}
}
*
* @param array $params Any additional parameters
*
- * @return Horde_Image object | PEAR_Error
+ * @return Horde_Image object
*/
static public function getImageObject($params = array())
{
* @param string $file The filename of the image.
* @param array $override Overwrite the file array with these values.
*
- * @return array The image data of the file as an array or PEAR_Error
+ * @return array The image data of the file as an array
+ * @throws Horde_Exception_NotFound
*/
static public function getImageFromFile($file, $override = array())
{
if (!file_exists($file)) {
- return PEAR::raiseError(sprintf(_("The file \"%s\" doesn't exist."),
- $file));
+ throw new Horde_Exception_NotFound(sprintf(_("The file \"%s\" doesn't exist."), $file));
}
global $conf;
// Get the mime type of the file (and make sure it's an image).
$mime_type = Horde_Mime_Magic::analyzeFile($file, isset($conf['mime']['magic_db']) ? $conf['mime']['magic_db'] : null);
if (strpos($mime_type, 'image') === false) {
- return PEAR::raiseError(sprintf(_("Can't get unknown file type \"%s\"."), $file));
+ throw new Horde_Exception_NotFound(sprintf(_("Can't get unknown file type \"%s\"."), $file));
}
$image = array('image_filename' => basename($file),
/**
* Build Ansel's list of menu items.
+ *
+ * @return Horde_Menu
*/
static public function getMenu()
{
/**
* Generate a list of breadcrumbs showing where we are in the gallery
* tree.
+ *
+ * @return string
*/
static public function getBreadCrumbs($separator = ' » ', $gallery = null)
{
if (is_null($gallery)) {
$gallery_id = (int)Horde_Util::getFormData('gallery');
$gallery_slug = Horde_Util::getFormData('slug');
- if (!empty($gallery_slug)) {
- $gallery = $ansel_storage->getGalleryBySlug($gallery_slug);
- } elseif (!empty($gallery_id)) {
- $gallery = $ansel_storage->getGallery($gallery_id);
- }
- }
-
- if (is_a($gallery, 'PEAR_Error')) {
- $gallery = null;
+ try {
+ if (!empty($gallery_slug)) {
+ $gallery = $ansel_storage->getGalleryBySlug($gallery_slug);
+ } elseif (!empty($gallery_id)) {
+ $gallery = $ansel_storage->getGallery($gallery_id);
+ }
+ } catch (Ansel_Exception $e) {}
}
if ($gallery) {
}
if (!empty($image_id)) {
- $image = &$ansel_storage->getImage($image_id);
- if (empty($gallery) && !is_a($image, 'PEAR_Error')) {
+ $image = $ansel_storage->getImage($image_id);
+ if (empty($gallery)) {
$gallery = $ansel_storage->getGallery($image->gallery);
}
}
- if (isset($gallery) && !is_a($gallery, 'PEAR_Error')) {
+ if (isset($gallery)) {
$owner = $gallery->get('owner');
}
if (!empty($owner)) {
'force_grouping' => true);
// Check for an active image
- if (!empty($image_id) && !is_a($image, 'PEAR_Error')) {
+ if (!empty($image_id)) {
$text = '<span class="thiscrumb" id="PhotoName">' . htmlspecialchars($image->filename, ENT_COMPAT, Horde_Nls::getCharset()) . '</span>';
$nav = $separator . $text . $nav;
$levels++;
$nav = $text . $nav;
}
- $nav = '<span class="breadcrumbs">' . $nav;
-
- return $nav;
+ return '<span class="breadcrumbs">' . $nav . '</span>';
}
/**
foreach ($options as $key => $option) {
$html .= ' <option value="' . $key . '"' . (($selected == $key) ? 'selected="selected"' : '') . '>' . $option . '</option>';
}
- $html .= '</select>';
- return $html;
+
+ return $html .= '</select>';
}
/**
* Get an array of all currently viewable styles.
+ *
+ * @return array
*/
static public function getAvailableStyles()
{
}
}
}
+
return $styles;
}
*
* @param array $date A full date parts array or an empty array.
*
- * @return A trimmed down (if necessary) date parts array.
+ * @return array A trimmed down (if necessary) date parts array.
*/
static public function getDateParameter($date = array())
{
/**
* Downloads all requested images as a zip file. Assumes all permissions
- * have been checked on the requested resource.
+ * have been checked on the requested resource. Can request either a
+ * single gallery of images, OR an array of individual image ids.
*
- * @param array $gallery
- * @param array $images
+ * @param Ansel_Gallery $gallery The galleries to download
+ * @param array $images The images to download
*/
static public function downloadImagesAsZip($gallery = null, $images = array())
{
$zipfiles = array();
foreach ($images as $id) {
- $image = &$GLOBALS['ansel_storage']->getImage($id);
- if (!is_a($image, 'PEAR_Error')) {
- // If we didn't select an entire gallery, check the download
- // size for each image.
- if (!isset($view)) {
- $g = $GLOBALS['ansel_storage']->getGallery($image->gallery);
- $v = $g->canDownload() ? 'full' : 'screen';
- } else {
- $v = $view;
- }
-
- $zipfiles[] = array('data' => $image->raw($v),
- 'name' => $image->filename);
+ $image = $GLOBALS['ansel_storage']->getImage($id);
+ // If we didn't select an entire gallery, check the download
+ // size for each image.
+ if (!isset($view)) {
+ $g = $GLOBALS['ansel_storage']->getGallery($image->gallery);
+ $v = $g->canDownload() ? 'full' : 'screen';
+ } else {
+ $v = $view;
}
+
+ $zipfiles[] = array('data' => $image->raw($v),
+ 'name' => $image->filename);
}
$zip = Horde_Compress::factory('zip');
*
* @param array $options The options to build the view.
*
- * @return string The javascript
+ * @return string The javascript code
*/
static public function embedCode($options)
{
} else {
if (count($parts) == 1) {
// This request is for all galleries owned by the requested user.
- $galleries = $GLOBALS['ansel_storage']->listGalleries(
- Horde_Perms::SHOW, $parts[0], null, false);
+ $galleries = $GLOBALS['ansel_storage']->listGalleries(Horde_Perms::SHOW, $parts[0], null, false);
$images = array();
} elseif ($this->galleryExists(null, end($parts))) {
// This request if for a certain gallery, list all sub-galleries
// and images.
$gallery_id = end($parts);
- $galleries = $GLOBALS['ansel_storage']->getGalleries(
- array($gallery_id));
+ $galleries = $GLOBALS['ansel_storage']->getGalleries(array($gallery_id));
if (!isset($galleries[$gallery_id]) ||
- !$galleries[$gallery_id]->hasPermission(Horde_Auth::getAuth(),
- Horde_Perms::READ)) {
- return PEAR::raiseError(_("Invalid gallery specified."), 404);
- }
- $galleries = $GLOBALS['ansel_storage']->listGalleries(
- Horde_Perms::SHOW, null, $gallery_id, false);
+ !$galleries[$gallery_id]->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
+ throw new Horde_Exception_NotFound(_("Invalid gallery specified."));
+ }
+ $galleries = $GLOBALS['ansel_storage']->listGalleries(Horde_Perms::SHOW, null, $gallery_id, false);
$images = $this->listImages(null, $gallery_id, Horde_Perms::SHOW, 'mini');
+
} elseif (count($parts) > 2 &&
- $this->galleryExists(null, $parts[count($parts) - 2]) &&
- !is_a($image = $GLOBALS['ansel_storage']->getImage(end($parts)), 'PEAR_Error')) {
- return array('data' => $image->raw(),
- 'mimetype' => $image->type,
- 'mtime' => $image->uploaded);
- } else {
- return PEAR::raiseError(_("File not found."), 404);
- }
+ $this->galleryExists(null, $parts[count($parts) - 2]) &&
+ ($image = $GLOBALS['ansel_storage']->getImage(end($parts)))) {
+
+ return array('data' => $image->raw(),
+ 'mimetype' => $image->type,
+ 'mtime' => $image->uploaded);
+
+ } else {
+ throw new Horde_Exception_NotFound(_("File not found."));
+ }
$results = array();
foreach ($galleries as $galleryId => $gallery) {
}
- return PEAR::raiseError(_("File not found."), 404);
+ throw Horde_Exception_NotFound(_("File not found."), 404);
}
/**
$parts = explode('/', $path);
if (count($parts) < 3) {
- return PEAR::raiseError("Gallery does not exist");
+ throw new Horde_Exception_NotFound("Gallery does not exist");
}
$image_name = array_pop($parts);
$gallery_id = end($parts);
if (!$GLOBALS['ansel_storage']->galleryExists($gallery_id)) {
- return PEAR::raiseError("Gallery does not exist");
+ throw new Horde_Exception_NotFound("Gallery does not exist");
}
$gallery = $GLOBALS['ansel_storage']->getGallery($gallery_id);
if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
- return PEAR::raiseError(_("Access denied adding photos to \"%s\"."));
+ throw new Horde_Exception_PermissionDenied(_("Access denied adding photos to \"%s\"."));
}
- return $gallery->addImage(array('image_type' => $content_type,
+ return $gallery->addImage(array(
+ 'image_type' => $content_type,
'image_filename' => $image_name,
'image_caption' => '',
'data' => $content));
return false;
}
- $image = $GLOBALS['ansel_storage']->getImage($image_id);
- if (!$image || is_a($image, 'PEAR_Error')) {
+ try {
+ if (!($image = $GLOBALS['ansel_storage']->getImage($image_id))) {
+ return false;
+ }
+ } catch (Ansel_Exception $e) {
return false;
}
* @return mixed An array of image/gallery data || PEAR_Error
*/
public function saveImage($app = null, $gallery_id, $image, $default = false,
- $gallery_data = null, $encoding = null, $slug = null,
- $compression = 'none', $skiphook = false)
+ $gallery_data = null, $encoding = null, $slug = null,
+ $compression = 'none', $skiphook = false)
{
$image_data = null;
}
if (is_null($image_data) && getimagesize($image['file']) === false) {
- return PEAR::raiseError(_("The file you uploaded does not appear to be a valid photo."));
+ throw new InvalidArgumentException(_("The file you uploaded does not appear to be a valid photo."));
}
if (empty($slug) && empty($gallery_id)) {
- return PEAR::raiseError(_("A gallery to add this photo to is required."));
+ throw new InvalidArgumentException(_("A gallery to add this photo to is required."));
}
if (!empty($slug)) {
$gallery = $GLOBALS['ansel_storage']->getGalleryBySlug($slug);
- if (is_a($gallery, 'PEAR_Error')) {
- return $gallery;
- }
} elseif ($GLOBALS['ansel_storage']->galleryExists($gallery_id)) {
$gallery = $GLOBALS['ansel_storage']->getGallery($gallery_id);
- if (is_a($gallery, 'PEAR_Error')) {
- return $gallery;
- }
}
if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
- return PEAR::raiseError(sprintf(_("Access denied adding photos to \"%s\"."), $gallery->get('name')));
+ throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied adding photos to \"%s\"."), $gallery->get('name')));
}
if (!empty($gallery_data)) {
foreach ($gallery_data as $key => $value) {
}
$image_id = $gallery->addImage($image_data, $default);
- if (is_a($image_id, 'PEAR_Error')) {
- return $image_id;
- }
// Call the postupload hook if needed
if (!empty($GLOBALS['conf']['hooks']['postupload']) && !$skiphook) {
}
return array('image_id' => (int)$image_id,
- 'gallery_id' => (int)$gallery->id,
- 'gallery_slug' => $gallery->get('slug'),
- 'image_count' => (int)$gallery->countImages());
+ 'gallery_id' => (int)$gallery->id,
+ 'gallery_slug' => $gallery->get('slug'),
+ 'image_count' => (int)$gallery->countImages());
}
/**
{
/* Check global Ansel permissions */
if (!$GLOBALS['injector']->getInstance('Horde_Perms')->getPermissions('ansel')) {
- return PEAR::raiseError(_("Access denied deleting galleries."));
+ throw new Horde_Exception_PermissionDenied(_("Access denied deleting galleries."));
}
/* If no app is given use Ansel's own gallery which is initialized in
}
$image = $GLOBALS['ansel_storage']->getImage($image_id);
- if (is_a($image, 'PEAR_Error')) {
- return $image;
- }
$gallery = $GLOBALS['ansel_storage']->getGallery($image->gallery);
- if (is_a($gallery, 'PEAR_Error') ||
- !$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
-
- return PEAR::raiseError(sprintf(_("Access denied deleting photos from \"%s\"."), $gallery->get('name')));
- }
+ if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
+ throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied deleting photos from \"%s\"."), $gallery->get('name')));
+ }
return $gallery->removeImage($image);
}
if (!(Horde_Auth::isAdmin() ||
(!$GLOBALS['injector']->getInstance('Horde_Perms')->exists('ansel') && Horde_Auth::getAuth()) ||
$GLOBALS['injector']->getInstance('Horde_Perms')->hasPermission('ansel', Horde_Auth::getAuth(), Horde_Perms::EDIT))) {
- return PEAR::raiseError(_("Access denied creating new galleries."));
- }
+
+ throw new Horde_Exception_PermissionDenied(_("Access denied creating new galleries."));
+ }
if (!is_null($app)) {
$GLOBALS['ansel_storage'] = new Ansel_Storage($app);
}
$gallery = $GLOBALS['ansel_storage']->createGallery($attributes, $permobj, $parent);
- if (is_a($gallery, 'PEAR_Error')) {
- return $gallery;
- }
+
return $gallery->id;
}
{
/* Check global Ansel permissions */
if (!$GLOBALS['injector']->getInstance('Horde_Perms')->getPermissions('ansel')) {
- return PEAR::raiseError(_("Access denied deleting galleries."));
+ throw new Horde_Exception_PermissionDenied(_("Access denied deleting galleries."));
}
/* If no app is given use Ansel's own gallery which is initialized in
}
$gallery = $GLOBALS['ansel_storage']->getGallery($gallery_id);
- if (is_a($gallery, 'PEAR_Error')) {
- return PEAR::raiseError(sprintf(_("Access denied deleting gallery \"%s\"."),
- $gallery->getMessage()));
- } elseif (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
- return PEAR::raiseError(sprintf(_("Access denied deleting gallery \"%s\"."),
- $gallery->get('name')));
+ if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
+ throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied deleting gallery \"%s\"."), $gallery->get('name')));
} else {
$imageList = $gallery->listImages();
if ($imageList) {
$gallery->removeImage($id);
}
}
- $result = $GLOBALS['ansel_storage']->removeGallery($gallery);
- if (!is_a($result, 'PEAR_Error')) {
- return true;
- } else {
- return PEAR::raiseError(sprintf(_("There was a problem deleting %s: %s"),
- $gallery->get('name'),
- $result->getMessage()));
- }
+
+ return $GLOBALS['ansel_storage']->removeGallery($gallery);
}
}
$GLOBALS['ansel_storage'] = new Ansel_Storage($app);
}
- if (!empty($slug)) {
- $gallery = $GLOBALS['ansel_storage']->getGalleryBySlug($slug);
- } else {
- $gallery = $GLOBALS['ansel_storage']->getGallery($gallery_id);
- }
-
- if (is_a($gallery, 'PEAR_Error')) {
- return 0;
- } else {
+ try {
+ if (!empty($slug)) {
+ $gallery = $GLOBALS['ansel_storage']->getGalleryBySlug($slug);
+ } else {
+ $gallery = $GLOBALS['ansel_storage']->getGallery($gallery_id);
+ }
return (int)$gallery->countImages();
+ } catch (Ansel_Exception $e) {
+ return 0;
}
}
$gallery = $GLOBALS['ansel_storage']->getGallery($gallery_id);
}
- if (is_a($gallery, 'PEAR_Error')) {
- return $gallery;
- } else {
- return $gallery->getDefaultImage($style);
- }
+ return $gallery->getDefaultImage($style);
}
/**
* @return string The image path.
*/
public function getImageContent($image_id, $view = 'screen', $style = null,
- $app = null, $encoding = null, $compression = 'none')
+ $app = null, $encoding = null,
+ $compression = 'none')
{
- /* If no app is given use Ansel's own gallery which is initialized in
- base.php */
+ /* If no app is given use Ansel's own gallery which is initialized in base.php */
if (!is_null($app)) {
$GLOBALS['ansel_storage'] = new Ansel_Storage($app);
}
- // Get image
+ /* Get image and gallery */
$image = $GLOBALS['ansel_storage']->getImage($image_id);
- if (is_a($image, 'PEAR_Error')) {
- return $image;
- }
-
- // Get gallery
$gallery = $GLOBALS['ansel_storage']->getGallery($image->gallery);
- if (is_a($gallery, 'PEAR_Error')) {
- return $gallery;
- }
- // Check age and password
+ /* Check age and password */
if (!$gallery->hasPasswd() || !$gallery->isOldEnough()) {
- return PEAR::raiseError(_("Locked galleries are not viewable via the api."));
+ throw new Horde_Exception(_("Locked galleries are not viewable via the api."));
}
if ($view == 'full') {
- // Check permissions for full view
+ /* Check permissions for full view */
if (!$gallery->canDownload()) {
- return PEAR::RaiseError(sprintf(_("Access denied downloading photos from \"%s\"."), $gallery->get('name')));
+ 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['ansel_vfs']->read($image->getVFSPath('full'), $image->getVFSName('full'));
} catch (VFS_Exception $e) {
- return PEAR::raiseError($data->getMessage());
+ Horde::logMessage($e->getMessage(), 'ERR');
+ throw new Ansel_Exception($e->getMessage());
}
} else {
- // Load View
$result = $image->load($view, $style);
-
- // Return image content
$data = $image->_image->raw();
}
- if (is_a($data, 'PEAR_Error')) {
- return $data;
- }
-
return $this->_getImageData($data, $encoding, $compression, false);
}
* @return array An array of gallery information.
*/
public function listGalleries($app = null, $perm = Horde_Perms::SHOW,
- $parent = null,
- $allLevels = true, $from = 0, $count = 0,
- $attributes = null, $sort_by = null, $direction = 0)
+ $parent = null, $allLevels = true, $from = 0,
+ $count = 0, $attributes = null, $sort_by = null,
+ $direction = 0)
{
/* If no app is given use Ansel's own gallery which is initialized in
base.php */
if (!is_null($app)) {
$GLOBALS['ansel_storage'] = new Ansel_Storage($app);
}
-
-
$galleries = $GLOBALS['ansel_storage']->listGalleries(
$perm, $attributes, $parent, $allLevels, $from, $count, $sort_by, $direction);
- if (is_a($galleries, 'PEAR_Error')) {
- return $galleries;
- }
-
$return = array();
foreach ($galleries as $gallery) {
$return[$gallery->id] = array_merge($gallery->data, array('crumbs' => $gallery->getGalleryCrumbData()));
$results = $GLOBALS['ansel_storage']->getGalleries($ids);
}
- if (is_a($results, 'PEAR_Error')) {
- return $results;
- }
-
/* We can't just return the results of the getGalleries call - we need to
ensure the caller has at least Horde_Perms::READ on the galleries. */
$galleries = array();
} else {
$gallery = $GLOBALS['ansel_storage']->getGallery($gallery_id);
}
- if (is_a($gallery, 'PEAR_Error')) {
- return $gallery;
- }
$images = $gallery->listImages();
- if (is_a($images, 'PEAR_Error')) {
- return $images;
- }
$counter = 0;
$imagelist = array();
foreach ($images as $id) {
$image = $GLOBALS['ansel_storage']->getImage($id);
- if (is_a($image, 'PEAR_Error')) {
- return $image;
- }
$imagelist[$id]['name'] = $image->filename;
$imagelist[$id]['caption'] = $image->caption;
$imagelist[$id]['type'] = $image->type;
* @return mixed An array of results | PEAR_Error
*/
public function searchTags($names, $max = 10, $from = 0,
- $resource_type = 'all', $user = null, $raw = false,
- $app = null)
+ $resource_type = 'all', $user = null, $raw = false,
+ $app = null)
{
if (!is_null($app)) {
$GLOBALS['ansel_storage'] = new Ansel_Storage($app);
} else {
$app = 'ansel';
}
-
- $results = Ansel_Tags::searchTags($names, $max, $from, $resource_type,
- $user);
+ $results = Ansel_Tags::searchTags($names, $max, $from, $resource_type, $user);
/* Check for error or if we requested the raw data array */
- if (is_a($results, 'PEAR_Error') || $raw) {
+ if ($raw) {
return $results;
}
}
}
-
return $return;
}
// Create db, share, and vfs instances.
$GLOBALS['ansel_db'] = Ansel::getDb();
- if (is_a($GLOBALS['ansel_db'], 'PEAR_Error')) {
- throw new Horde_Exception_Prior($GLOBALS['ansel_db']);
- }
-
$GLOBALS['ansel_storage'] = new Ansel_Storage();
$GLOBALS['ansel_vfs'] = Ansel::getVFS();
function _title()
{
- $gallery = $this->_getGallery();
- if (is_a($gallery, 'PEAR_Error')) {
+ try {
+ $gallery = $this->_getGallery();
+ } catch (Horde_Exception $e) {
return Horde::link(Ansel::getUrlFor('view', array('view' => 'List'),
true)) . _("Gallery") . '</a>';
}
}
function _content()
{
- $gallery = $this->_getGallery();
- if (is_a($gallery, 'PEAR_Error')) {
+ try {
+ $gallery = $this->_getGallery();
+ } catch (Horde_Exception $e) {
return $gallery->getMessage();
}
function _getGallery($retry = false)
{
// Make sure we haven't already selected a gallery.
- if (is_a($this->_gallery, 'Ansel_Gallery')) {
+ if ($this->_gallery instanceof Ansel_Gallery) {
return $this->_gallery;
}
}
if (empty($this->_gallery)) {
- return PEAR::raiseError(_("Gallery does not exist."));
- } elseif (is_a($this->_gallery, 'PEAR_Error') ||
- !$this->_gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW) ||
+ throw new Horde_Exception_NotFound(_("Gallery does not exist."));
+ } elseif (!$this->_gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW) ||
!$this->_gallery->isOldEnough() || $this->_gallery->hasPasswd()) {
- return PEAR::raiseError(_("Access denied viewing this gallery."));
+ throw new Horde_Exception_PermissionDenied(_("Access denied viewing this gallery."));
}
// Return the gallery.
{
Horde::addScriptFile('tooltips.js', 'horde');
/* Get the top level galleries */
- $galleries = $GLOBALS['ansel_storage']->listGalleries(
- Horde_Perms::EDIT, Horde_Auth::getAuth(), null, false, 0,
- empty($this->_params['limit']) ? 0 : $this->_params['limit'],
- 'last_modified', 1);
+ try {
+ $galleries = $GLOBALS['ansel_storage']->listGalleries(
+ Horde_Perms::EDIT, Horde_Auth::getAuth(), null, false, 0,
+ empty($this->_params['limit']) ? 0 : $this->_params['limit'],
+ 'last_modified', 1);
- if (is_a($galleries, 'PEAR_Error')) {
- return $galleries->getMessage();
+ } catch (Ansel_Exception $e) {
+ return $e->getMessage();
}
$preview_url = Horde::applicationUrl('preview.php');
function _title()
{
if ($this->_params['gallery'] != 'all') {
- $gallery = $this->_getGallery();
- if (is_a($gallery, 'PEAR_Error')) {
+ try {
+ $gallery = $this->_getGallery();
+ } catch (Horde_Exception $e) {
return Horde::link(
Ansel::getUrlFor('view', array('view' => 'List'), true))
. _("Gallery") . '</a>';
$image_ids[] = $thread['forum_name'];
}
} else {
- $gallery = $this->_getGallery();
- if (is_a($gallery, 'PEAR_Error')) {
- return $gallery->getMessage();
+ try {
+ $gallery = $this->_getGallery();
+ } catch (Horde_Exception $e) {
+ return $e->getMessage();
}
$results = array();
$image_ids = $gallery->listImages();
. '<table class="linedRow" cellspacing="0" style="width:100%"><thead><tr class="item nowrap"><th class="item leftAlign">' . _("Date") . '</th><th class="item leftAlign">' . _("Image") . '</th><th class="item leftAlign">' . _("Subject") . '</th><th class="item leftAlign">' . _("By") . '</th></tr></thead><tbody>';
foreach ($results as $comment) {
- $image = &$ansel_storage->getImage($comment['image_id']);
- if (!is_a($image, 'PEAR_Error')) {
+ try {
+ $image = &$ansel_storage->getImage($comment['image_id']);
$url = Ansel::getUrlFor('view',
array('view' => 'Image',
'gallery' => abs($image->gallery),
. '</a></td><td class="nowrap">'
. $comment['message_subject'] . '</td><td class="nowrap">'
. $comment['message_author'] . '</td></tr>';
- }
+ } catch (Horde_Exception $e) {}
}
$html .= '</tbody></table>';
function _getGallery()
{
// Make sure we haven't already selected a gallery.
- if (is_a($this->_gallery, 'Ansel_Gallery')) {
+ if ($this->_gallery instanceof Ansel_Gallery) {
return $this->_gallery;
}
}
if (empty($this->_gallery)) {
- return PEAR::raiseError(_("Gallery does not exist."));
- } elseif (is_a($this->_gallery, 'PEAR_Error') ||
- !$this->_gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
- return PEAR::raiseError(_("Access denied viewing this gallery."));
+ throw new Horde_Exception_NotFount(_("Gallery does not exist."));
+ } elseif (!$this->_gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
+ throw new Horde_Exception_PermissionDenied(_("Access denied viewing this gallery."));
}
// Return a reference to the gallery.
function _title()
{
if ($this->_params['gallery'] != 'all') {
- $gallery = $this->_getGallery();
- if (is_a($gallery, 'PEAR_Error')) {
+ try {
+ $gallery = $this->_getGallery();
+ } catch (Exception $e) {
return Horde::link(
Ansel::getUrlFor('view', array('view' => 'List'), true))
. _("Gallery") . '</a>';
// Retrieve the images, but protect against very large values for
// limit.
- $results = $GLOBALS['ansel_storage']->getRecentImages(
+ try {
+ $results = $GLOBALS['ansel_storage']->getRecentImages(
$galleries, min($this->_params['limit'], 100));
- if (is_a($results, 'PEAR_Error')) {
- return $results->getMessage();
+ } catch (Ansel_Exception $e) {
+ return $e->getMessage();
}
$preview_url = Horde::applicationUrl('preview.php', true);
$header = array(_("Date"), _("Photo"), _("Gallery"));
HEADER;
foreach ($results as $image) {
- if (is_a($image, 'PEAR_Error')) {
- continue;
- }
$gallery = $GLOBALS['ansel_storage']->getGallery($image->gallery);
// Don't show locked galleries in the block.
function _getGallery()
{
- // Make sure we haven't already selected a gallery.
- if (is_a($this->_gallery, 'Ansel_Gallery')) {
+ /* Make sure we haven't already selected a gallery. */
+ if ($this->_gallery instanceof Ansel_Gallery) {
return $this->_gallery;
}
- // Get the gallery object and cache it.
+ /* Get the gallery object and cache it. */
if (isset($this->_params['gallery']) &&
$this->_params['gallery'] != '__random') {
- $this->_gallery = $GLOBALS['ansel_storage']->getGallery(
- $this->_params['gallery']);
+ $this->_gallery = $GLOBALS['ansel_storage']->getGallery($this->_params['gallery']);
} else {
$this->_gallery = $GLOBALS['ansel_storage']->getRandomGallery();
}
if (empty($this->_gallery)) {
- return PEAR::raiseError(_("Gallery does not exist."));
- } elseif (is_a($this->_gallery, 'PEAR_Error') ||
- !$this->_gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
- return PEAR::raiseError(_("Access denied viewing this gallery."));
+ throw new Horde_Exception_NotFound(_("Gallery not found."));
+ } elseif (!$this->_gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
+ throw new Horde_Exception_PermissionDenied(_("Access denied viewing this gallery."));
}
- // Return a reference to the gallery.
+ /* Return a reference to the gallery. */
return $this->_gallery;
}
Horde::addScriptFile('http://gmaps-utility-library.googlecode.com/svn/trunk/markermanager/1.1/src/markermanager.js', 'ansel', array('external' => true));
Horde::addScriptFile('googlemap.js');
if ($this->_params['gallery'] != 'all') {
- $gallery = $this->_getGallery();
- if (is_a($gallery, 'PEAR_Error')) {
- return Horde::link(
- Ansel::getUrlFor('view', array('view' => 'List'), true))
+ try {
+ $gallery = $this->_getGallery();
+ } catch (Exception $e) {
+ return Horde::link(Ansel::getUrlFor('view', array('view' => 'List'), true))
. _("Gallery") . '</a>';
}
// Build the gallery name.
if (isset($this->_params['gallery'])) {
- $name = @htmlspecialchars($gallery->get('name'), ENT_COMPAT,
- Horde_Nls::getCharset());
+ $name = @htmlspecialchars($gallery->get('name'), ENT_COMPAT, Horde_Nls::getCharset());
}
$style = $gallery->getStyle();
$galleries = $this->_params['gallery'];
}
- $images = $GLOBALS['ansel_storage']->getRecentImagesGeodata(null, 0, min($this->_params['limit'], 100));
- if (is_a($images, 'PEAR_Error')) {
- return $images->getMessage();
+ try {
+ $images = $GLOBALS['ansel_storage']->getRecentImagesGeodata(null, 0, min($this->_params['limit'], 100));
+ } catch (Ansel_Exception $e) {
+ return $e->getMessage();
}
$images = array_reverse($images);
foreach ($images as $key => $image) {
- if (is_a($image, 'PEAR_Error')) {
- continue;
- }
$id = $image['image_id'];
$gallery = $GLOBALS['ansel_storage']->getGallery($image['gallery_id']);
function _getGallery()
{
- // Make sure we haven't already selected a gallery.
- if (is_a($this->_gallery, 'Ansel_Gallery')) {
+ if ($this->_gallery instanceof Ansel_Gallery) {
return $this->_gallery;
}
- // Get the gallery object and cache it.
if (isset($this->_params['gallery']) &&
$this->_params['gallery'] != '__random') {
$this->_gallery = $GLOBALS['ansel_storage']->getGallery(
}
if (empty($this->_gallery)) {
- return PEAR::raiseError(_("Gallery does not exist."));
- } elseif (is_a($this->_gallery, 'PEAR_Error') ||
- !$this->_gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
- return PEAR::raiseError(_("Access denied viewing this gallery."));
+ throw new Horde_Exception_NotFound(_("Gallery not found."));
+ } elseif (!$this->_gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
+ throw new Horde_Exception_PermissionDenied(_("Access denied viewing this gallery."));
}
- // Return a reference to the gallery.
return $this->_gallery;
}
* Count faces
*
* @param array $info Array of select criteria
+ *
+ * @return integer The count of faces
+ * @throws Ansel_Exception
*/
protected function _countFaces($info)
{
. ' ) AND f.gallery_id = s.share_id'
. (isset($info['filter']) ? ' AND ' . $info['filter'] : '');
- return $GLOBALS['ansel_db']->queryOne($sql);
+ $result = $GLOBALS['ansel_db']->queryOne($sql);
+ if ($result instanceof PEAR_Error) {
+ throw new Ansel_Exception($result);
+ }
+
+ return $result;
}
/**
* @param boolen $create Create images or store data?
*
* @return array Faces found
+ * @throws Horde_Exception_PermissionDenied
+ * @throws Ansel_Exception
*/
- public function getFromPicture(&$image, $create = false)
+ public function getFromPicture($image, $create = false)
{
// get image if ID is passed
- if (!is_a($image, 'Ansel_Image')) {
- $image = &$GLOBALS['ansel_storage']->getImage($image);
+ if (!($image instanceof Ansel_Image)) {
+ $image = $GLOBALS['ansel_storage']->getImage($image);
$gallery = $GLOBALS['ansel_storage']->getGallery($image->gallery);
if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
- throw new Horde_Exception('Access denied editing the photo.');
+ throw new Horde_Exception_PermissionDenied('Access denied editing the photo.');
}
}
}
// Clean up any existing faces we may have had in this image.
- $result = Ansel_Faces::delete($image);
+ Ansel_Faces::delete($image);
// Process faces
$fids = array();
// Create Face id
$face_id = $GLOBALS['ansel_db']->nextId('ansel_faces');
if ($face_id instanceof PEAR_Error) {
- throw new Horde_Exception_Prior($face_id);
+ throw new Ansel_Exception($face_id);
}
// Store face id db
$q = $GLOBALS['ansel_db']->prepare($sql, null, MDB2_PREPARE_MANIP);
if ($q instanceof PEAR_Error) {
- throw new Horde_Exception_Prior($q);
+ throw new Ansel_Exception($q);
}
$result = $q->execute($params);
$q->free();
if ($result instanceof PEAR_Error) {
- throw new Horde_Exception_Prior($result);
+ throw new Ansel_Exception($result);
}
if ($create) {
- // Process image
- $result = $this->_createView($face_id, $image, $rect);
+ $this->_createView($face_id, $image, $rect);
// Clear any loaded views to save on memory usage.
$image->reset();
$this->saveSignature($image->id, $face_id);
}
$face = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
- if (is_a($face, 'PEAR_Error')) {
+ if ($face instanceof PEAR_Error) {
throw new Horde_Exception_Prior($face);
}
$this->_setModeHelper($mode);
}
+ /**
+ * Helper for accessing the gallery id
+ *
+ * @param string $property
+ *
+ * @return mixed
+ */
public function __get($property)
{
switch ($property) {
/**
* Check for special capabilities of this gallery.
*
+ * @return boolean
*/
public function hasFeature($feature)
{
/**
* Saves any changes to this object to the backend permanently.
*
- * @TODO: this needs to stay public b/c Horde_Share_Object (which this extends)
- * is not yet ported to PHP5. This will be fixed when we no longer
- * extend Horde_Share_Object here.
- *
- * @return mixed true || PEAR_Error on failure.
+ * @return boolean
*/
- public function _save()
+ protected function _save()
{
// Check for invalid characters in the slug.
if (!empty($this->data['attribute_slug']) &&
preg_match('/[^a-zA-Z0-9_@]/', $this->data['attribute_slug'])) {
- // TODO: Need to keep the pear error here since Horde_Share still
- // uses them.
- return PEAR::raiseError(
+ throw new InvalidArgumentException(
sprintf(_("Could not save gallery, the slug, \"%s\", contains invalid characters."),
$this->data['attribute_slug']));
}
// Check for slug uniqueness
$slugGalleryId = $GLOBALS['ansel_storage']->slugExists($this->data['attribute_slug']);
if ($slugGalleryId > 0 && $slugGalleryId <> $this->id) {
- return PEAR::raiseError(sprintf(_("Could not save gallery, the slug, \"%s\", already exists."),
- $this->data['attribute_slug']));
+ throw InvalidArgumentException(
+ sprintf(_("Could not save gallery, the slug, \"%s\", already exists."),
+ $this->data['attribute_slug']));
}
if ($GLOBALS['conf']['ansel_cache']['usecache']) {
$GLOBALS['cache']->expire('Ansel_Gallery' . $this->id);
}
+
return parent::_save();
}
* Update the gallery image count.
*
* @param integer $images Number of images in action
- * @param boolean $add Action to take (add or remove)
- * @param integer $gallery_id Gallery id to update images for
+ * @param boolean $add True if adding, false if removing
+ * @param integer $gallery_id Gallery id to update images for, if not self
+ *
+ * @return boolean true on success
+ * @throws Ansel_Exception
*/
public function updateImageCount($images, $add = true, $gallery_id = null)
{
- // We do the query directly here to avoid having to instantiate a
- // gallery object just to increment/decrement one value in the table.
- // TODO: Change this - should always use the appropriate object, not
- // direct manipulation of the share table...
- $sql = 'UPDATE ' . $this->_shareOb->getTable()
- . ' SET attribute_images = attribute_images '
- . ($add ? ' + ' : ' - ') . $images . ' WHERE share_id = '
- . ($gallery_id ? $gallery_id : $this->id);
-
- // Make sure to update the local value as well, so it doesn't get
- // overwritten by any other updates from ->set() calls.
if (is_null($gallery_id) || $gallery_id === $this->id) {
+ /* Updating self */
if ($add) {
$this->data['attribute_images'] += $images;
} else {
$this->data['attribute_images'] -= $images;
}
+ try {
+ $this->save();
+ } catch (Horde_Share_Exception $e) {
+ Horde::logMessage($e->getMessage, 'ERR');
+ throw Ansel_Exception($e);
+ }
+ } else {
+ /* Updating other gallery */
+ $g = $GLOBALS['ansel_storage']->getGallery($gallery_id);
+ $count = $g->get('images');
+ if ($add) {
+ $count += $images;
+ } else {
+ $count['attribute_images'] -= $images;
+ }
+ try {
+ $g->save();
+ } catch (Horde_Share_Exception $e) {
+ Horde::logMessage($e->getMessage, 'ERR');
+ throw Ansel_Exception($e);
+ }
}
/* Need to expire the cache for the gallery that was changed */
$GLOBALS['cache']->expire('Ansel_Gallery' . $id);
}
- return $this->_shareOb->getWriteDb()->exec($sql);
+ return true;
}
/**
* Adds an Ansel_Image object to this gallery.
*
- * @param $image Ansel_Image
+ * @param Ansel_Image $image The ansel image object to add
+ * @param boolean $default Set this image as the gallery's key image.
+ *
+ * @return integer The new image id
*/
public function addImageObject(Ansel_Image $image, $default = false)
{
- // Make sure it's taken as a new image
+ /* Make sure it's taken as a new image */
$image->id = null;
$image->gallery = $this->getId();
$image->sort = $this->countImages();
$this->updateImageCount(1);
/* Should this be the default image? */
- $this->data['attribute_default'] = $image->id;
- $this->clearStacks();
+ if ($default) {
+ $this->data['attribute_default'] = $image->id;
+ $this->clearStacks();
+ }
/* Save all changes to the gallery */
$this->save();
* @param Ansel_Gallery $gallery The gallery to copy images to.
*
* @return integer The number of images copied
- * @throws Horde_Exception
+ * @throws Ansel_Exception
*/
public function copyImagesTo($images, $gallery)
{
if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
- throw new Horde_Exception(sprintf(_("Access denied copying photos to \"%s\"."), $gallery->get('name')));
+ throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied copying photos to \"%s\"."), $gallery->get('name')));
}
$db = $this->_shareOb->getWriteDb();
$imgCnt = 0;
foreach ($images as $imageId) {
- $img = &$this->getImage($imageId);
+ $img = $this->getImage($imageId);
// Note that we don't pass the tags when adding the image..see below
$newId = $gallery->addImage(array(
'image_caption' => $img->caption,
// for each tag - just write the data into the DB ourselves.
$tags = $img->getTags();
$query = $this->_shareOb->getWriteDb()->prepare('INSERT INTO ansel_images_tags (image_id, tag_id) VALUES(' . $newId . ',?);');
- if (is_a($query, 'PEAR_Error')) {
- throw new Horde_Exception($query->getMessage());
+ if ($query instanceof PEAR_Error) {
+ throw new Ansel_Exception($query);
}
foreach ($tags as $tag_id => $tag_name) {
$result = $query->execute($tag_id);
- if (is_a($result, 'PEAR_Error')) {
- throw new Horde_Exception($result->getMessge());
+ if ($result instanceof PEAR_Error) {
+ throw new Ansel_Exception($result);
}
}
$query->free();
$exif = $db->queryAll('SELECT attr_name, attr_value FROM ansel_image_attributes WHERE image_id = ' . (int) $imageId . ';',null, MDB2_FETCHMODE_ASSOC);
if (is_array($exif) && count($exif) > 0) {
$insert = $db->prepare('INSERT INTO ansel_image_attributes (image_id, attr_name, attr_value) VALUES (?, ?, ?)');
- if (is_a($insert, 'PEAR_Error')) {
+ if ($insert instanceof PEAR_Error) {
throw new Horde_Exception($insert->getMessage());
}
foreach ($exif as $attr){
$result = $insert->execute(array($newId, $attr['attr_name'], $attr['attr_value']));
- if (is_a($result, 'PEAR_Error')) {
+ if ($result instanceof PEAR_Error) {
throw new Horde_Exception($result->getMessage());
}
}
public function setParent($parent)
{
/* Make sure we have a gallery object */
- if (!is_null($parent) && !is_a($parent, 'Ansel_Gallery')) {
+ if (!is_null($parent) && !($parent instanceof Ansel_Gallery)) {
$parent = $GLOBALS['ansel_storage']->getGallery($parent);
}
}
/* Call the parent class method */
- $result = parent::setParent($parent);
- if (is_a($result, 'PEAR_Error')) {
- // Horde_Share still uses PEAR_Error
- throw new Horde_Exception($result->getMessage());
- }
+ parent::setParent($parent);
/* Tell the parent the good news */
if (!is_null($parent) && !$parent->get('has_subgalleries')) {
}
$result = $query->execute(array($data[$driver_key], $this->id));
$query->free();
- if (is_a($result, 'PEAR_Error')) {
+ if ($result instanceof PEAR_Error) {
throw new Horde_Exception($result->getMessage());
}
* @author Michael J. Rubinsky <mrubinsk@horde.org>
* @package Ansel
*/
-class Ansel_GalleryMode_Date {
-
+class Ansel_GalleryMode_Date
+{
/**
* @var Ansel_Gallery
*/
if (!is_array($this->_subGalleries)) {
/* Get a list of all the subgalleries */
$subs = $GLOBALS['ansel_storage']->listGalleries(Horde_Perms::SHOW, null, $this->_gallery);
- if (is_a($subs, 'PEAR_Error')) {
- return $subs;
- }
$this->_subGalleries = array_keys($subs);
}
}
if (!count($this->_date) || empty($this->_date['year'])) {
/* All available images - grouped by year */
$images = $ansel_storage->listImages($this->_gallery->id, 0, 0, array('image_id', 'image_original_date'), $gallery_where);
- if (is_a($images, 'PEAR_Error')) {
- return $images;
- }
$dates = array();
foreach ($images as $key => $image) {
$dates[date('Y', $image['image_original_date'])][] = $key;
}
$images= $ansel_storage->listImages($this->_gallery->id, $from, $to, 'image_id', $where, 'image_sort');
$results = $ansel_storage->getImages(array('ids' => $images, 'preserve' => true));
- if (!is_a($results, 'PEAR_Error')) {
- if ($this->_gallery->get('has_subgalleries')) {
- $images = array();
- foreach ($results as $id => $image) {
- $image->gallery = $this->_gallery->id;
- $images[$id] = $image;
- }
- $children[$cache_key] = $images;
- } else {
- $children[$cache_key] = $results;
+
+ if ($this->_gallery->get('has_subgalleries')) {
+ $images = array();
+ foreach ($results as $id => $image) {
+ $image->gallery = $this->_gallery->id;
+ $images[$id] = $image;
}
+ $children[$cache_key] = $images;
+ } else {
+ $children[$cache_key] = $results;
}
return $children[$cache_key];
return $results;
}
-
/**
* Return the count of this gallery's children
*
function countGalleryChildren($perm = Horde_Perms::SHOW, $galleries_only = false, $noauto = true)
{
$results = $this->getGalleryChildren($this->_date, 0, 0, $noauto);
- if (is_a($results, 'PEAR_Error')) {
- return $results;
- }
-
return count($results);
}
-
/**
* Lists a slice of the image ids in this gallery.
* In Date mode, this only makes sense if we are currently viewing a
function moveImagesTo($images, $gallery)
{
if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
- return PEAR::raiseError(sprintf(_("Access denied moving photos to \"%s\"."), $newGallery->get('name')));
+ throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied moving photos to \"%s\"."), $newGallery->get('name')));
} elseif (!$this->_gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
- return PEAR::raiseError(sprintf(_("Access denied removing photos from \"%s\"."), $gallery->get('name')));
+ throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied removing photos from \"%s\"."), $gallery->get('name')));
}
/* Sanitize image ids, and see if we're removing our default image. */
}
/* Bulk update the images to their new gallery_id */
+ // @TODO: Move this to Ansel_Storage::
$result = $this->_gallery->getShareOb()->getWriteDb()->exec('UPDATE ansel_images SET gallery_id = ' . $gallery->id . ' WHERE image_id IN (' . implode(',', $ids) . ')');
- if (is_a($result, 'PEAR_Error')) {
- return $result;
+ if ($result instanceof PEAR_Error) {
+ Horde::logMessage($result, 'ERR');
+ throw new Ansel_Exception($result);
}
/* Update the gallery counts for each affected gallery */
* @param mixed $image An image_id or Ansel_Image object to delete.
* @param boolean $isStack Image is a stack image (doesn't update count).
*
- * @return mixed boolean || PEAR_Error
+ * @return boolean
*/
function removeImage($image, $isStack)
{
-
/* Make sure $image is an Ansel_Image; if not, try loading it. */
- if (!is_a($image, 'Ansel_Image')) {
- $img = &$GLOBALS['ansel_storage']->getImage($image);
- if (is_a($img, 'PEAR_Error')) {
- return $img;
- }
- $image = $img;
+ if (!($image instanceof Ansel_Image)) {
+ $image = $GLOBALS['ansel_storage']->getImage($image);
}
/* Make sure the image is in this gallery. */
} catch (VFS_Exception $e) {}
/* Delete from SQL. */
+ // @TODO: Move to Horde_Storage
$this->_gallery->getShareOb()->getWriteDb()->exec('DELETE FROM ansel_images WHERE image_id = ' . (int)$image->id);
/* Remove any attributes */
if (($GLOBALS['conf']['comments']['allow'] == 'all' || ($GLOBALS['conf']['comments']['allow'] == 'authenticated' && Horde_Auth::getAuth())) &&
$GLOBALS['registry']->hasMethod('forums/deleteForum')) {
- $result = $GLOBALS['registry']->call('forums/deleteForum',
- array('ansel', $image->id));
-
- if (is_a($result, 'PEAR_Error')) {
+ $result = $GLOBALS['registry']->call('forums/deleteForum', array('ansel', $image->id));
+ if ($result instanceof PEAR_Error) {
Horde::logMessage($result, 'ERR');
return false;
}
/* Now grab any images if we still have room */
if (($to - count($galleries) > 0) || ($from == 0 && $to == 0) &&
$this->_gallery->data['attribute_images']) {
- $images = $this->getImages(max(0, $from - $num_galleries), $to - count($galleries));
- if (is_a($images, 'PEAR_Error')) {
- Horde::logMessage($images, 'ERR');
+
+ try {
+ $images = $this->getImages(max(0, $from - $num_galleries), $to - count($galleries));
+ } catch (Ansel_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
$images = array();
}
} else {
$result = $GLOBALS['registry']->call('forums/deleteForum',
array('ansel', $image->id));
- if (is_a($result, 'PEAR_Error')) {
+ if ($result instanceof PEAR_Error) {
Horde::logMessage($result, 'ERR');
return false;
}
*
* @TODO: Move all SQL queries to Ansel_Storage::
*
- * @return The image id
+ * @return integer image id
* @throws Ansel_Exception
*/
public function save()
* @return Ansel_Gallery object
* @throws Horde_Exception_NotFound
*/
- public function &getGalleryBySlug($slug, $overrides = array())
+ public function getGalleryBySlug($slug, $overrides = array())
{
$id = $this->slugExists($slug);
if ($id) {
* @return Ansel_Gallery
* @throws Ansel_Exception
*/
- public function &getGallery($gallery_id, $overrides = array())
+ public function getGallery($gallery_id, $overrides = array())
{
// avoid cache server hits
if (isset($this->_galleries[$gallery_id]) && !count($overrides)) {
/* If we have an id, then it's an existing image.*/
if ($image->id) {
$update = $this->_db->prepare('UPDATE ansel_images SET image_filename = ?, image_type = ?, image_caption = ?, image_sort = ?, image_original_date = ?, image_latitude = ?, image_longitude = ?, image_location = ?, image_geotag_date = ? WHERE image_id = ?');
- if (is_a($update, 'PEAR_Error')) {
+ if ($update instanceof PEAR_Error) {
Horde::logMessage($update, 'ERR');
throw new Ansel_Exception($update);
}
$image->location,
$image->geotag_timestamp,
$image->id));
- if (is_a($result, 'PEAR_Error')) {
+ if ($result instanceof PEAR_Error) {
Horde::logMessage($update, 'ERR');
throw new Ansel_Exception($result);
}
/* Get the next image_id */
$image_id = $this->_db->nextId('ansel_images');
- if (is_a($image_id, 'PEAR_Error')) {
+ if ($image_id instanceof PEAR_Error) {
throw new Ansel_Exception($image_id);
}
/* Prepare the SQL statement */
$insert = $this->_db->prepare('INSERT INTO ansel_images (image_id, gallery_id, image_filename, image_type, image_caption, image_uploaded_date, image_sort, image_original_date, image_latitude, image_longitude, image_location, image_geotag_date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
- if (is_a($insert, 'PEAR_Error')) {
+ if ($insert instanceof PEAR_Error) {
Horde::logMessage($insert, 'ERR');
throw new Ansel_Exception($insert);
}
$image->location,
(empty($image->lat) ? 0 : $image->uploaded)));
$insert->free();
- if (is_a($result, 'PEAR_Error')) {
+ if ($result instanceof PEAR_Error) {
Horde::logMessage($result, 'ERR');
throw new Ansel_Exception($result);
}
/**
* Static helper class for writing/reading tag values
*
+ * @TODO: Move tag storage to Content_Tagger
* @static
*/
-class Ansel_Tags {
-
+class Ansel_Tags
+{
/**
* Write out the tags for a specific resource.
*
* @param array $tags An array of tags.
* @param string $resource_type The type of resource (image or gallery)
*
- * @return mixed True | PEAR_Error
+ * @return boolean True on success
+ * @throws InvalidArgumentException
+ * @throws Ansel_Exception
*/
- function writeTags($resource_id, $tags, $resource_type = 'image')
+ static public function writeTags($resource_id, $tags, $resource_type = 'image')
{
// First, make sure all tag names exist in the DB.
$tagkeys = array();
foreach ($tags as $tag) {
if (!empty($tag)) {
if (!preg_match("/^[a-zA-Z0-9%_+.!*',()~-]*$/", $tag)) {
- return PEAR::raiseError(_("Invalid characters in tag"));
+ throw new InvalidArgumentException('Invalid characters in tag.');
}
$tag = Horde_String::lower(trim($tag));
$sql = $GLOBALS['ansel_db']->prepare('SELECT tag_id FROM ansel_tags WHERE tag_name = ?');
$id = $GLOBALS['ansel_db']->nextId('ansel_tags');
$result = $insert->execute(array($id, Horde_String::convertCharset($tag, Horde_Nls::getCharset(), $GLOBALS['conf']['sql']['charset'])));
$tagkeys[] = $id;
- } elseif (is_a($results, 'PEAR_Error')) {
- return $results;
+ } elseif ($results instanceof PEAR_Error) {
+ Horde::logMessage($results->getMessage(), 'ERR');
+ throw new Ansel_Exception($results);
} else {
$tagkeys[] = $results['tag_id'];
}
/**
* Retrieve the tags for a specified resource.
*
- * @param int $resource_id The resource to get tags for.
+ * @param integer $resource_id The resource to get tags for.
* @param string $resource_type The type of resource (gallery or image)
*
- * @return mixed An array of tags | PEAR_Error
+ * @return mixed An array of tags
*/
- function readTags($resource_id, $resource_type = 'image')
+ static public function readTags($resource_id, $resource_type = 'image')
{
if ($resource_type == 'image') {
$stmt = $GLOBALS['ansel_db']->prepare('SELECT ansel_tags.tag_id, tag_name FROM ansel_tags INNER JOIN ansel_images_tags ON ansel_images_tags.tag_id = ansel_tags.tag_id WHERE ansel_images_tags.image_id = ?');
} else {
$stmt = $GLOBALS['ansel_db']->prepare('SELECT ansel_tags.tag_id, tag_name FROM ansel_tags INNER JOIN ansel_galleries_tags ON ansel_galleries_tags.tag_id = ansel_tags.tag_id WHERE ansel_galleries_tags.gallery_id = ?');
}
- if (is_a($stmt, 'PEAR_Error')) {
- return $stmt;
+ if ($stmt instanceof PEAR_Error) {
+ throw new Ansel_Exception($stmt);
}
Horde::logMessage('SQL query by Ansel_Tags::readTags ' . $stmt->query, 'DEBUG');
$result = $stmt->execute((int)$resource_id);
* will be included.
* @param integer $limit Limit the number of tags returned to this value.
*
- * @return mixed An array containing tag_name, and total | PEAR_Error
+ * @return Array An array containing tag_name, and total
*/
- function listTagInfo($tags = null, $limit = 500)
+ static public function listTagInfo($tags = null, $limit = 500)
{
global $conf;
// Only return the full list if $tags is omitted, not if
* @param string $user Limit the result set to resources
* owned by this user.
*
- * @return mixed An array of image_ids and galery_ids objects | PEAR_Error
+ * @return array An array of image_ids and gallery_ids
*/
- function searchTagsById($ids, $max = 0, $from = 0,
- $resource_type = 'all', $user = null)
+ static public function searchTagsById($ids, $max = 0, $from = 0,
+ $resource_type = 'all', $user = null)
{
if (!is_array($ids) || !count($ids)) {
return array('galleries' => array(), 'images' => array());
Horde::logMessage('SQL query by Ansel_Tags::searchTags: ' . $sql, 'DEBUG');
$GLOBALS['ansel_db']->setLimit($max, $from);
$images = $GLOBALS['ansel_db']->queryCol($sql);
- if (is_a($images, 'PEAR_Error')) {
+ if ($images instanceof PEAR_Error) {
Horde::logMessage($images, 'ERR');
$results['images'] = array();
} else {
/* Check permissions and filter on $user if required */
$imgs = array();
foreach ($images as $id) {
- $img = &$GLOBALS['ansel_storage']->getImage($id);
- if (is_a($img, 'PEAR_Error')) {
- break;
- }
- $gal = $GLOBALS['ansel_storage']->getGallery($img->gallery);
- if (!is_a($gal, 'PEAR_Error')) {
+ try {
+ $img = $GLOBALS['ansel_storage']->getImage($id);
+ $gal = $GLOBALS['ansel_storage']->getGallery($img->gallery);
$owner = $gal->get('owner');
if ($gal->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW) &&
(!isset($user) || (isset($user) && $owner && $owner == $user))) {
$imgs[] = $id;
}
- } else {
- Horde::logMessage($gal, 'ERR');
+ } catch (Ansel_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
+ break;
}
}
- $results['images'] = $imgs;
+ $results['images'] = $imgs;
}
}
$GLOBALS['ansel_db']->setLimit($max, $from);
$galleries = $GLOBALS['ansel_db']->queryCol($sql);
- if (is_a($galleries, 'PEAR_Error')) {
+ if ($galleries instanceof PEAR_Error) {
Horde::logMessage($galleries, 'ERR');
} else {
/* Check perms */
foreach ($galleries as $id) {
- $gallery = $GLOBALS['ansel_storage']->getGallery($id);
- if (is_a($gallery, 'PEAR_Error')) {
- Horde::logMessage($gallery, 'ERR');
+ try {
+ $gallery = $GLOBALS['ansel_storage']->getGallery($id);
+ } catch (Ansel_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
continue;
}
if ($gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW) && (!isset($user) || (isset($user) && $gallery->get('owner') && $gallery->get('owner') == $user))) {
* @param string $user Limit the result set to resources owned by
* specified user.
*
- * @return mixed An array of image_ids and gallery_ids | PEAR_Error
+ * @return mixed An array of image_ids and gallery_ids
*/
- function searchTags($names = array(), $max = 10, $from = 0,
- $resource_type = 'all', $user = null)
+ static public function searchTags($names = array(), $max = 10, $from = 0,
+ $resource_type = 'all', $user = null)
{
/* Get the tag_ids */
$ids = Ansel_Tags::getTagIds($names);
*
* @return mixed A hash of tag_id -> tag_name | PEAR_Error
*/
- function getRelatedTags($ids)
+ static public function getRelatedTags($ids)
{
if (!count($ids)) {
return array();
*
* @return string The URL for this tag and action
*/
- function getTagLinks($tags, $action = 'add', $owner = null)
+ static public function getTagLinks($tags, $action = 'add', $owner = null)
{
$results = array();
foreach ($tags as $id => $taginfo) {
*
* @param array $tags An array of tag_names
*
- * @return mixed An array of tag_names => tag_ids | PEAR_Error
+ * @return array An array of tag_names => tag_ids
*/
- function getTagIds($tags)
+ static public function getTagIds($tags)
{
if (!count($tags)) {
return array();
}
/**
+ * Get the tag names from ids
*
+ * @param array $ids An array of tag ids
+ *
+ * @return array A hash of tag_id => tag_names
*/
- function getTagNames($ids)
+ static public function getTagNames($ids)
{
if (!count($ids)) {
return array();
/**
* Retrieve an Ansel_Tags_Search object
+ *
+ * @return Ansel_Tags_Search
+ * @TODO: refactor into Ansel_Search
*/
- function getSearch($tags = null, $owner = null)
+ static public function getSearch($tags = null, $owner = null)
{
return new Ansel_Tags_Search($tags, $owner);
}
/**
* Clear the session cache
*/
- function clearSearch()
+ static public function clearSearch()
{
unset($_SESSION['ansel_tags_search']);
}
- function clearCache()
+ static public function clearCache()
{
if ($GLOBALS['conf']['ansel_cache']['usecache']) {
$GLOBALS['cache']->expire(Horde_Auth::getAuth() . '__anseltagsearches');
/**
* Class that represents a slice of a tag search
+ *
+ * @TODO: Move this to Ansel_Search_Tags
+ *
+ *
*/
class Ansel_Tags_Search {
/**
* Fetch the matching resources that should appear on the current page
*
- * @return Array of Ansel_Images and Ansel_Galleries | PEAR_Error
+ * @return Array of Ansel_Images and Ansel_Galleries
*/
function getSlice($page, $perpage)
{
$gstart,
'galleries',
$this->_owner);
-
- if (is_a($gresults, 'PEAR_Error')) {
- return $gresults;
- }
-
$galleries = array();
foreach ($gresults['galleries'] as $gallery) {
$galleries[] = $GLOBALS['ansel_storage']->getGallery($gallery);
$istart,
'images',
$this->_owner);
- if (is_a($iresults, 'PEAR_Error')) {
- return $iresults;
- }
$images = count($iresults['images']) ? array_values($GLOBALS['ansel_storage']->getImages(array('ids' => $iresults['images']))) : array();
if (($conf['comments']['allow'] == 'all' || ($conf['comments']['allow'] == 'authenticated' && Horde_Auth::getAuth())) &&
$ids = array_keys($images);
$ccounts = $GLOBALS['registry']->call('forums/numMessagesBatch', array($ids, 'ansel'));
- if (!is_a($ccounts, 'PEAR_Error')) {
+ if (!($ccounts instanceof PEAR_Error)) {
foreach ($images as $image) {
$image->commentCount = (!empty($ccounts[$image->id]) ? $ccounts[$image->id] : 0);
}
* @return Ansel_Gallery The requested Ansel_Gallery object
* @throws Horde_Exception
*/
- protected function &_getGallery($galleryId = null, $slug = '')
+ protected function _getGallery($galleryId = null, $slug = '')
{
if (is_null($galleryId) && empty($slug)) {
$galleryId = !empty($this->_params['gallery_id']) ? $this->_params['gallery_id'] : null;
// If we have a slug, use it.
if (!empty($slug)) {
- $gallery = &$GLOBALS['ansel_storage']->getGalleryBySlug($slug);
+ $gallery = $GLOBALS['ansel_storage']->getGalleryBySlug($slug);
} else {
- $gallery = &$GLOBALS['ansel_storage']->getGallery($galleryId);
+ $gallery = $GLOBALS['ansel_storage']->getGallery($galleryId);
}
- if (is_a($gallery, 'PEAR_Error')) {
- throw new Horde_Exception($gallery->getMessage());
- } elseif (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
+ if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
throw new Horde_Exception(sprintf(_("Access denied to gallery \"%s\"."), $gallery->get('name')));
}
//$image_ids = $this->view->gallery->listImages($this->pagestart, $this->pagestart + $this->perpage);
$ids = array();
foreach ($this->children as $child) {
- if (is_a($child, 'Ansel_Image')) {
+ if ($child instanceof Ansel_Image) {
$ids[] = $child->id;
}
}
array('ansel', $this->resource->id,
'commentCallback', true, null,
$url));
- if (is_a($comments, 'PEAR_Error')) {
+ if ($comments instanceof PEAR_Error) {
Horde::logMessage($comments, 'DEBUG');
$comments = array();
}
$this->_faces = Ansel_Faces::factory();
$this->_owner = $this->_view->gallery->get('owner');
- //@TODO: Remove the PEAR_Error check when Faces is refactored.
try {
$this->_count = $this->_faces->countOwnerFaces($this->_owner);
- } catch (Horde_Exception $e) {}
- if (is_a($this->_count, 'PEAR_error')) {
+ } catch (Horde_Exception $e) {
+ Horde::logMessage($e->getMessage, 'ERR');
$this->_count = 0;
}
break;
}
if ($imgId != $this->_view->resource->id) {
- $rImg = &$ansel_storage->getImage($imgId);
- if (is_a($rImg, 'PEAR_Error')) {
- continue;
- }
- $rGal = $ansel_storage->getGallery($rImg->gallery);
- if (is_a($rGal, 'PEAR_Error')) {
+ try {
+ $rImg = $ansel_storage->getImage($imgId);
+ $rGal = $ansel_storage->getGallery($rImg->gallery);
+ } catch (Ansel_Exception $e) {
continue;
}
+
$title = sprintf(_("%s from %s"), $rImg->filename, $rGal->get('name'));
$html .= Horde::link(
Ansel::getUrlFor('view',
Horde::fatal(_("An error has occured retrieving the image. Details have been logged."), __FILE__, __LINE__, true);
}
$image = $ansel_storage->getImage($image_id);
-if (is_a($image, 'PEAR_Error')) {
- Horde::fatal(_("An error has occured retrieving the image. Details have been logged."), __FILE__, __LINE__, true);
-}
$gallery = $ansel_storage->getGallery($image->gallery);
-if (is_a($gallery, 'PEAR_Error')) {
- Horde::fatal(_("An error has occured retrieving the image. Details have been logged."), __FILE__, __LINE__, true);
-}
if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
- Horde::fatal(_("Not Authorized. Details have been logged for the server administrator."), __FILE__, __LINE__, true);
+ throw new Horde_Exception_PermissionDenied(_("Not Authorized. Details have been logged for the server administrator."));
}
/* Determine if we already have a geotag or are we tagging it for the 1st time */
Horde_Registry::appInit('ansel');
$imageId = Horde_Util::getFormData('image');
-$image = &$ansel_storage->getImage($imageId);
-if (is_a($image, 'PEAR_Error')) {
- Horde::logMessage($image, 'ERR');
+try {
+ $image = $ansel_storage->getImage($imageId);
+ $gal = $ansel_storage->getGallery(abs($image->gallery));
+ $img = Ansel::getImageUrl($imageId, 'thumb', false);
+} catch (Ansel_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
exit;
}
-$gal = $ansel_storage->getGallery(abs($image->gallery));
-if (is_a($gal, 'PEAR_Error')) {
- Horde::logMessage($image, 'ERR');
- exit;
-}
-$img = Ansel::getImageUrl($imageId, 'thumb', false);
-if (!is_a($img, 'PEAR_Error') &&
- $gal->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW) &&
- !$gal->hasPasswd() &&
- $gal->isOldEnough()) {
+if ($gal->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW) &&
+ !$gal->hasPasswd() &&
+ $gal->isOldEnough()) {
+
echo '<img src="' . $img . '" alt="' . htmlspecialchars($image->filename) . '" />';
} else {
echo '';
Horde_Registry::appInit('ansel');
$vars = Horde_Variables::getDefaultVariables();
-$gallery = $ansel_storage->getGallery($vars->get('gallery'));
-if (is_a($gallery, 'PEAR_Error')) {
- $notification->push($gallery->getMessage());
+try {
+ $gallery = $ansel_storage->getGallery($vars->get('gallery'));
+} catch (Ansel_Exception $e) {
+ $notification->push($e->getMessage());
header('Location: ' . Horde::applicationUrl('list.php'));
exit;
}
$title = _("Do you really want to report this gallery?");
$gallery_id = (int)Horde_Util::getFormData('gallery');
-
-$gallery = $ansel_storage->getGallery($gallery_id);
-if (is_a($gallery, 'PEAR_Error')) {
+try {
+ $gallery = $ansel_storage->getGallery($gallery_id);
+} catch (Ansel_Exception $e) {
$notification->push($gallery->getMessage());
header('Location: ' . Horde::applicationUrl('view.php?view=List', true));
exit;
} else {
$style = $gallery->getStyle();
$return_url = Ansel::getUrlFor('view',
- array('gallery' => $gallery_id,
- 'view' => 'Gallery'),
- true);
+ array('gallery' => $gallery_id,
+ 'view' => 'Gallery'),
+ true);
}
$vars = Horde_Variables::getDefaultVariables();
if ($form->validate()) {
if (Horde_Util::getFormData('submitbutton') == _("Report")) {
- require ANSEL_BASE . '/lib/Report.php';
$report = Ansel_Report::factory();
-
$body = _("Gallery Name") . ': ' . $gallery->get('name') . "\n"
. _("Gallery Description") . ': ' . $gallery->get('desc') . "\n"
. _("Gallery Id") . ': ' . $gallery->id . "\n"
. _("Report reason") . ': ' . $vars->get('reason') . "\n"
. $return_url;
- $result = $report->report($body);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(_("Gallery was not reported.") . ' ' .
- $result->getMessage(), 'horde.error');
- } else {
+ try {
+ $result = $report->report($body);
$notification->push(_("Gallery was reported."), 'horde.success');
+ } catch (Horde_Exception $e) {
+ $notification->push(_("Gallery was not reported.") . ' ' . $result->getMessage(), 'horde.error');
}
} else {
$notification->push(_("Gallery was not reported."), 'horde.warning');
$ret = Console_Getopt::getopt(Console_Getopt::readPHPArgv(), 'hu:p:f:',
array('help', 'username=', 'password=', 'fields='));
-if (is_a($ret, 'PEAR_Error')) {
+if ($ret instanceof PEAR_Error) {
$cli->fatal($ret->getMessage());
}
// Get the list of image ids that have exif data.
$sql = 'SELECT DISTINCT image_id from ansel_image_attributes;';
$results = $GLOBALS['ansel_db']->query($sql);
-if (is_a($results, 'PEAR_Error')) {
+if ($results instanceof PEAR_Error) {
$cli->fatal($results->getMessage());
}
$image_ids = $results->fetchAll(MDB2_FETCHMODE_ASSOC);
$results->free();
foreach (array_values($image_ids) as $image_id) {
$image = $ansel_storage->getImage($image_id['image_id']);
- if (!is_a($image, 'PEAR_Error')) {
- $results = $image->exifToTags($exif_fields);
- if (is_a($results, 'PEAR_Error')) {
- $cli->message(sprintf(_("Could not extract exif fields from %s: %s"), $image_id['image_id'], $results->getMessage()), 'cli.error');
- }
- $cli->message(sprintf(_("Extracted exif fields from %s"), $image->filename), 'cli.success');
- } else {
- $cli->message(sprintf(_("Could not extract exif fields from %s: %s"), $image_id['image_id'], $image->getMessage()), 'cli.error');
- }
+ $results = $image->exifToTags($exif_fields);
+ $cli->message(sprintf(_("Extracted exif fields from %s"), $image->filename), 'cli.success');
}
$cli->message(_("Done"));
exit;
'create=', 'gallery=', 'add=', 'dir=',
'caption='));
-if (is_a($ret, 'PEAR_Error')) {
+if ($ret instanceof PEAR_Error) {
$error = _("Couldn't read command-line options.");
Horde::logMessage($error, 'DEBUG');
$cli->fatal($error);
$cli->fatal($error);
} else {
$gallery = $ansel_storage->getGallery($galleryId);
- if (is_a($gallery, 'PEAR_Error') ||
- !$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
- $error = sprintf(_("Access denied adding photos to \"%s\"."),
- $galleryId);
+ if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+ $error = sprintf(_("Access denied adding photos to \"%s\"."), $galleryId);
Horde::logMessage($error, 'WARN');
$cli->fatal($error);
}
$attributes = array('name' => $gallery_name,
'desc' => $gallery_desc,
'owner' => $gallery_owner);
- $gallery = $ansel_storage->createGallery($attributes, null, $parent);
- if (is_a($gallery, 'PEAR_Error')) {
+ try {
+ $gallery = $ansel_storage->createGallery($attributes, null, $parent);
+ } catch (Ansel_Exception $e) {
$galleryId = null;
$error = sprintf(_("The gallery \"%s\" couldn't be created: %s"),
$gallery_name, $gallery->getMessage());
Horde::logMessage($error, 'ERR');
$cli->fatal($error);
- } else {
- $msg = sprintf(_("The gallery \"%s\" was created successfully."),
- $gallery_name);
- Horde::logMessage($msg, 'DEBUG');
- $cli->message($msg, 'cli.success');
}
+ $msg = sprintf(_("The gallery \"%s\" was created successfully."), $gallery_name);
+ Horde::logMessage($msg, 'DEBUG');
+ $cli->message($msg, 'cli.success');
}
// List galleries/images.
if (!empty($list)) {
if (!empty($gallery)) {
$images = $gallery->listImages();
- if (is_a($images, 'PEAR_Error')) {
- $cli->fatal($images->getMessage());
- }
-
$cli->message(sprintf(_("Listing photos in %s"), $gallery->get('name')), 'cli.success');
$cli->writeln();
$images = array_keys($images);
foreach ($images as $id) {
- $image = &$ansel_storage->getImage($id);
+ $image = $ansel_storage->getImage($id);
$cli->writeln(str_pad($image->filename, 30) . $image->getVFSPath() . '/' . $id);
}
} else {
$galleries = $GLOBALS['ansel_storage']->listGalleries();
- if (is_a($galleries, 'PEAR_Error')) {
- $error = _("Couldn't list galleries.");
- Horde::logMessage($error, 'DEBUG');
- $cli->fatal($error);
- }
-
$cli->message(_("Listing Gallery/Name"), 'cli.success');
$cli->writeln();
-
foreach ($galleries as $id => $gallery) {
$name = $gallery->get('name');
$msg = "$id/$name";
}
// Add an image from the filesystem.
-if (!empty($file) && isset($gallery) && !is_a($gallery, 'PEAR_Error')) {
- $image = &Ansel::getImageFromFile($file, array('caption' => $caption));
- if (is_a($image, 'PEAR_Error')) {
- Horde::logMessage($image, 'WARN');
- $cli->fatal($image->getMessage());
- }
-
- $cli->message(sprintf(_("Storing photo \"%s\"..."), $file), 'cli.message');
- $image_id = $gallery->addImage($image);
- if (is_a($image_id, 'PEAR_Error')) {
+if (!empty($file) && isset($gallery)) {
+ try {
+ $image = Ansel::getImageFromFile($file, array('caption' => $caption));
+ $cli->message(sprintf(_("Storing photo \"%s\"..."), $file), 'cli.message');
+ $image_id = $gallery->addImage($image);
+ } catch (Ansel_Exception $e) {
$error = sprintf(_("There was a problem adding the photo \"%s\" to gallery \"%s\": %s"),
- basename($file), $galleryId, $image_id->getMessage());
+ basename($file), $galleryId, $e->getMessage());
Horde::logMessage($error, 'ERR');
$cli->fatal($error);
}
-
- $msg = sprintf(_("Successfully added photo \"%s\" to gallery \"%s\"."),
- basename($file), $galleryId);
+ $msg = sprintf(_("Successfully added photo \"%s\" to gallery \"%s\"."), basename($file), $galleryId);
$cli->message($msg, 'cli.success');
Horde::logMessage($msg, 'NOTICE');
}
// Add all images from a directory on the filesystem.
-if (!empty($dir) && isset($gallery) && !is_a($gallery, 'PEAR_Error')) {
+if (!empty($dir) && isset($gallery)) {
$msg = addDirToGallery($dir, $gallery);
- if (is_a($msg, 'PEAR_Error')) {
- Horde::logMessage($msg, 'ERR');
- $cli->fatal($msg->getMessage());
- }
if ($msg) {
$msg = sprintf(ngettext("Successfully added %d photo (%s) to gallery \"%s\" from \"%s\".", "Successfully added %d photos (%s) to gallery \"%s\" from \"%s\".", count($msg)),
count($msg), join(', ', $msg), $galleryId, $dir);
// Process each file and upload to the gallery.
$added_images = array();
foreach ($files_array as $file) {
- $image = Ansel::getImageFromFile($dir . '/' . $file);
- if (is_a($image, 'PEAR_Error')) {
- Horde::logMessage($image, 'WARN');
+ try {
+ $image = Ansel::getImageFromFile($dir . '/' . $file);
+ $cli->message(sprintf(_("Storing photo \"%s\"..."), $file), 'cli.message');
+ $image_id = $gallery->addImage($image);
+ } catch (Ansel_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'WARN');
$cli->message($image->getMessage(), 'cli.error');
continue;
}
-
- $cli->message(sprintf(_("Storing photo \"%s\"..."), $file), 'cli.message');
- $image_id = $gallery->addImage($image);
- if (is_a($image_id, 'PEAR_Error')) {
- $error = sprintf(_("There was a problem adding the photo \"%s\" to gallery \"%s\"."),
- $file, $galleryId);
- Horde::logMessage($error, 'ERR');
- $cli->message($image_id->getMessage(), 'cli.error');
- continue;
- }
-
$added_images[] = $file;
}
$ret = Console_Getopt::getopt(Console_Getopt::readPHPArgv(), 'mv',
array('move', 'verbose'));
-if (is_a($ret, 'PEAR_Error')) {
+if ($ret instanceof PEAR_Error) {
die("Couldn't read command-line options.\n");
}
list($opts, $args) = $ret;
$ret = Console_Getopt::getopt(Console_Getopt::readPHPArgv(), 'hu:p:lc:g:a:d:k',
array('help', 'username=', 'password=', 'dir=', 'keep'));
-if (is_a($ret, 'PEAR_Error')) {
+if ($ret instanceof PEAR_Error) {
$cli->fatal($ret->getMessage());
}
Horde_Nls::setCharset('utf-8');
$gallery_id = processDirectory($dir);
-if (!$keepEmpties && !is_a($gallery_id, 'PEAR_Error')) {
+if (!$keepEmpties) {
$gallery = $ansel_storage->getGallery($gallery_id);
- if (!is_a($gallery, 'PEAR_Error')) {
- emptyGalleryCheck($gallery);
- }
+ emptyGalleryCheck($gallery);
}
exit;
$name = basename($dir);
$cli->message(sprintf(_("Creating gallery: \"%s\""), $name), 'cli.message');
$gallery = $GLOBALS['ansel_storage']->createGallery(array('name' => $name), null, $parent);
- if (is_a($gallery, 'PEAR_Error')) {
- $cli->fatal(sprintf(_("The gallery \"%s\" couldn't be created: %s"), $name, $gallery->getMessage()));
- } else {
- $cli->message(sprintf(_("The gallery \"%s\" was created successfully."), $name), 'cli.success');
- }
+ $cli->message(sprintf(_("The gallery \"%s\" was created successfully."), $name), 'cli.success');
// Read all the files into an array.
$files = array();
$added_images = array();
foreach ($files as $file) {
$image = Ansel::getImageFromFile($dir . '/' . $file);
- if (is_a($image, 'PEAR_Error')) {
- $cli->message($image->getMessage(), 'cli.error');
- continue;
- }
-
$cli->message(sprintf(_("Storing photo \"%s\"..."), $file), 'cli.message');
$image_id = $gallery->addImage($image);
- if (is_a($image_id, 'PEAR_Error')) {
- $cli->message($image_id->getMessage(), 'cli.error');
- continue;
- }
-
$added_images[] = $file;
}
$ret = Console_Getopt::getopt(Console_Getopt::readPHPArgv(), 'hu:p:g:s:d:kr:zl',
array('help', 'username=', 'password=', 'gallery=', 'slug=', 'dir=', 'keep', 'remotehost=', 'gzip', 'lzf'));
-if (is_a($ret, 'PEAR_Error')) {
+if ($ret instanceof PEAR_Error) {
$cli->fatal($ret->getMessage());
}
null,
is_null($slug) ? null : array($slug),
);
- $result = Horde_RPC::request('jsonrpc', $rpc_endpoint, $method, $params, $rpc_auth);
- if (is_a($result, 'PEAR_Error')) {
- $cli->fatal($result->getMessage());
- }
+ $result = Horde_Rpc::request('jsonrpc', $rpc_endpoint, $method, $params, $rpc_auth);
$result = $result->result;
- if (is_a($result, 'PEAR_Error')) {
- $cli->fatal($result->getMessage());
- }
if (empty($result)) {
$cli->fatal(sprintf(_("Gallery %s not found."), (empty($slug) ? $gallery_id : $slug)));
}
$cli->message(sprintf(_("Creating gallery: \"%s\""), $name), 'cli.message');
$method = 'images.createGallery';
$params = array(null, array('name' => $name), null, $parent);
- $result = Horde_RPC::request('jsonrpc', $rpc_endpoint, $method, $params, $rpc_auth);
- if (is_a($result, 'PEAR_Error')) {
- $cli->fatal($result->getMessage());
- }
+ $result = Horde_Rpc::request('jsonrpc', $rpc_endpoint, $method, $params, $rpc_auth);
$gallery_id = $result->result;
- if (is_a($gallery_id, 'PEAR_Error')) {
- $cli->fatal(sprintf(_("The gallery \"%s\" couldn't be created: %s"), $name, $gallery_id->getMessage()));
- } else {
- $cli->message(sprintf(_("The gallery \"%s\" was created successfully."), $name), 'cli.success');
- }
+ $cli->message(sprintf(_("The gallery \"%s\" was created successfully."), $name), 'cli.success');
}
/* Get the files and directories */
$added_images = array();
foreach ($files as $file) {
$image = getImageFromFile($dir . '/' . $file, $compress);
- if (is_a($image, 'PEAR_Error')) {
- $cli->message($image->getMessage(), 'cli.error');
- continue;
- }
-
$cli->message(sprintf(_("Storing photo \"%s\"..."), $file), 'cli.message');
$method = 'images.saveImage';
$params = array(null, $gallery_id, $image, false, null, 'binhex', $slug, $compress);
- $result = Horde_RPC::request('jsonrpc', $rpc_endpoint, $method, $params, $rpc_auth);
- if (is_a($result, 'PEAR_Error')) {
- $cli->fatal($result->getMessage());
- }
-
- if (!is_a($result, 'stdClass')) {
+ $result = Horde_Rpc::request('jsonrpc', $rpc_endpoint, $method, $params, $rpc_auth);
+ if (!($result instanceof stdClass)) {
$cli->fatal(sprintf(_("There was an unspecified error. The server returned: %s"), print_r($result, true)));
}
$image_id = $result->result;
- if (is_a($image_id, 'PEAR_Error')) {
- $cli->message($image_id->getMessage(), 'cli.error');
- continue;
- }
-
$added_images[] = $file;
}
}
$sql = 'UPDATE ansel_images SET image_original_date = ' . (int)$datetime . ' WHERE image_id = ' . (int)$image['image_id'];
$result = $ansel_db->exec($sql);
- if (is_a($result, 'PEAR_Error')) {
+ if ($result instanceof PEAR_Error) {
$cli->fatal($result->getMessage());
}
$cli->message(sprintf("Image %d updated.", $image['image_id']), 'cli.message');
if (!$galleryId || !$ansel_storage->galleryExists($galleryId)) {
$error = _("Invalid gallery specified.") . "<br />\n";
} else {
- $gallery = $ansel_storage->getGallery($galleryId);
- if (is_a($gallery, 'PEAR_ERROR')) {
- $error = _("There was an error accessing the gallery");
- } else {
+ try {
+ $gallery = $ansel_storage->getGallery($galleryId);
$error = false;
+ } catch (Ansel_Exception $e) {
+ $error = _("There was an error accessing the gallery");
}
}
$gallery_desc = Horde_Util::getFormData('gallery_desc');
if ($create) {
/* Creating a new gallery. */
- $gallery = $ansel_storage->createGallery(array('name' => $gallery_name,
- 'desc' => $gallery_desc));
- if (is_a($gallery, 'PEAR_Error')) {
- $error = sprintf(_("The gallery \"%s\" couldn't be created: %s"), $gallery_name, $gallery->getMessage());
- Horde::logMessage($error, 'ERR');
- } else {
+ try {
+ $gallery = $ansel_storage->createGallery(
+ array('name' => $gallery_name, 'desc' => $gallery_desc));
$galleryId = $gallery->id;
$msg = sprintf(_("The gallery \"%s\" was created successfully."), $gallery_name);
Horde::logMessage($msg, 'DEBUG');
- }
+ } catch (Ansel_Exception $e) {
+ $error = sprintf(_("The gallery \"%s\" couldn't be created: %s"), $gallery_name, $e->getMessage());
+ Horde::logMessage($error, 'ERR');
+ }
} else {
if (empty($galleryId) && $prefs->getValue('autoname')) {
$galleryId = md5(microtime());
if (!$galleryId || !$ansel_storage->galleryExists($galleryId)) {
$error = _("Invalid gallery specified.") . "<br />\n";
} else {
- $gallery = $ansel_storage->getGallery($galleryId);
- if (is_a($gallery, 'PEAR_ERROR') || !$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
- $error = sprintf(_("Access denied adding photos to \"%s\"."), $gallery->get('name'));
- } else {
- $error = false;
+ try {
+ $gallery = $ansel_storage->getGallery($galleryId);
+ if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+ $error = sprintf(_("Access denied adding photos to \"%s\"."), $gallery->get('name'));
+ } else {
+ $error = false;
+ }
+ } catch (Ansel_Exception $e) {
+ $error = _("There was an error accessing the gallery");
}
}
if (!$name || $error) {
} else {
try {
$GLOBALS['browser']->wasFileUploaded('imagefile', _("photo"));
- $image = &Ansel::getImageFromFile($file, array('image_filename' => $name));
- if (is_a($image, 'PEAR_Error')) {
- $error = $image->getMessage();
- } else {
- $gallery = $ansel_storage->getGallery($galleryId);
+ try {
+ $image = Ansel::getImageFromFile($file, array('image_filename' => $name));
+ } catch (Ansel_Exception $e) {
+ $error = $e->getMessage();
+ }
+
+ $gallery = $ansel_storage->getGallery($galleryId);
+ try {
$image_id = $gallery->addImage($image);
- if (is_a($image_id, 'PEAR_Error')) {
- $error = _("There was a problem uploading the photo.");
- } else {
- $error = false;
- }
- if (is_a($image_id, 'PEAR_Error')) {
- $image_id = $image_id->getMessage();
- }
+ $error = false;
+ } catch (Ansel_Exception $e) {
+ $error = _("There was a problem uploading the photo.");
}
} catch (Horde_Browser_Exception $e) {
$error = $e->getMessage();