* (string)slug Ignore gallery_id, and use this as the slug
* </pre>
*
- * @return integer The default image id.
+ * @return integer The key image id.
*/
public function getGalleryKeyImage($gallery_id, $params = array())
{
$gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($gallery_id);
}
- return $gallery->getDefaultImage(empty($params['style']) ? 'ansel_default' : $params['style']);
+ return $gallery->getKeyImage(empty($params['style']) ? 'ansel_default' : $params['style']);
}
/**
true);
$html .= '<noscript>';
$html .= $viewurl->link(array('title' => sprintf(_("View %s"), $gallery->get('name'))));
- if ($iid = $gallery->getDefaultImage('ansel_default') &&
+ if ($iid = $gallery->getKeyImage('ansel_default') &&
$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
- $html .= '<img src="' . Ansel::getImageUrl($gallery->getDefaultImage('ansel_default'), 'thumb', true) . '" alt="' . htmlspecialchars($gallery->get('name')) . '" />';
+ $html .= '<img src="' . Ansel::getImageUrl($gallery->getKeyImage('ansel_default'), 'thumb', true) . '" alt="' . htmlspecialchars($gallery->get('name')) . '" />';
} else {
$html .= Horde::img('thumb-error.png');
}
true);
$html .= '<tr><td>'
. $url->link(array('onmouseout' => '$("ansel_preview").hide();$("ansel_preview").update("");',
- 'onmouseover' => 'previewImageMg(event, ' . $gallery->getDefaultImage('ansel_default') . ');'))
+ 'onmouseover' => 'previewImageMg(event, ' . $gallery->getKeyImage('ansel_default') . ');'))
. @htmlspecialchars($gallery->get('name'), ENT_COMPAT, $GLOBALS['registry']->getCharset()) . '</a></td><td>'
. strftime($GLOBALS['prefs']->getValue('date_format'), $gallery->get('last_modified'))
. '</td><td>' . (int)$gallery->countImages(true) . '</td></tr>';
$image->save();
$this->updateImageCount(1);
- /* Should this be the default image? */
+ /* Should this be the key image? */
if ($default) {
$this->data['attribute_default'] = $image->id;
$this->clearStacks();
{
global $conf;
- //@TODO: Maybe addImage() gets moved to the modeHelper delegate?
/* Normal is the only view mode that can accurately update gallery counts */
$vMode = $this->get('view_mode');
if ($vMode != 'Normal') {
}
}
- /* Should this be the default image? */
+ /* Should this be the key image? */
if (!$default && $this->data['attribute_default_type'] == 'auto') {
$this->data['attribute_default'] = $image->id;
$resetStack = true;
$this->data['default_type'] = 'manual';
}
- /* Reset the gallery default image stacks if needed. */
+ /* Reset the gallery key image stacks if needed. */
if ($resetStack) {
$this->clearStacks();
}
}
/**
- * Clear all of this gallery's default image stacks from the VFS and the
+ * Clear all of this gallery's key image stacks from the VFS and the
* gallery's data store.
*
* @return void
throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied copying photos to \"%s\"."), $gallery->get('name')));
}
- $db = $this->getShareOb()->getWriteDb();
$imgCnt = 0;
foreach ($images as $imageId) {
$img = $this->getImage($imageId);
// go through Ansel_Tags::writeTags() - this saves us a SELECT query
// for each tag - just write the data into the DB ourselves.
$tags = $img->getTags();
- $query = $this->getShareOb()->getWriteDb()->prepare('INSERT INTO ansel_images_tags (image_id, tag_id) VALUES(' . $newId . ',?);');
+ $query = $GLOBALS['ansel_db']->prepare('INSERT INTO ansel_images_tags (image_id, tag_id) VALUES(' . $newId . ',?);');
if ($query instanceof PEAR_Error) {
throw new Ansel_Exception($query);
}
/* exif data */
// First check to see if the exif data was present in the raw data.
- $count = $db->queryOne('SELECT COUNT(image_id) FROM ansel_image_attributes WHERE image_id = ' . (int) $newId . ';');
+ $count = $GLOBALS['ansel_db']->queryOne('SELECT COUNT(image_id) FROM ansel_image_attributes WHERE image_id = ' . (int) $newId . ';');
if ($count == 0) {
- $exif = $db->queryAll('SELECT attr_name, attr_value FROM ansel_image_attributes WHERE image_id = ' . (int) $imageId . ';',null, MDB2_FETCHMODE_ASSOC);
+ $exif = $GLOBALS['ansel_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 (?, ?, ?)');
+ $insert = $GLOBALS['ansel_db']->prepare('INSERT INTO ansel_image_attributes (image_id, attr_name, attr_value) VALUES (?, ?, ?)');
if ($insert instanceof PEAR_Error) {
throw new Horde_Exception($insert->getMessage());
}
*/
public function setImageOrder($imageId, $pos)
{
- return $this->getShareOb()->getWriteDb()->exec('UPDATE ansel_images SET image_sort = ' . (int)$pos . ' WHERE image_id = ' . (int)$imageId);
+ return $GLOBALS['ansel_db']->exec('UPDATE ansel_images SET image_sort = ' . (int)$pos . ' WHERE image_id = ' . (int)$imageId);
}
/**
}
/**
- * Returns the default image for this gallery.
- *
- * @TODO: Rename default images to 'key' images - they really are not
- * 'default' in any sense.
+ * Returns the key image for this gallery.
*
* @param string $style Force the use of this style, if it's available
* otherwise use whatever style is choosen for this
* gallery. If prettythumbs are not available then
* we always use ansel_default style.
*
- * @return mixed The image_id of the default image or false.
+ * @return mixed The image_id of the key image or false.
*/
- public function getDefaultImage($style = null)
+ public function getKeyImage($style = null)
{
/* Get the available styles */
$styles = $GLOBALS['injector']->getInstance('Ansel_Styles');
- // Check for explicitly requested style
+ /* Check for explicitly requested style */
if (!is_null($style)) {
$gal_style = Ansel::getStyleDefinition($style);
} else {
- // Use gallery's default.
$gal_style = $this->getStyle();
if (!isset($styles[$gal_style['name']])) {
$gal_style = $styles['ansel_default'];
}
}
- Horde::logMessage(sprintf("using gallery style: %s in Ansel::getDefaultImage()", $gal_style['name']), 'DEBUG');
+
if (!empty($gal_style['default_galleryimage_type']) &&
$gal_style['default_galleryimage_type'] != 'plain') {
$thumbstyle = $gal_style['default_galleryimage_type'];
$styleHash = $this->getViewHash($thumbstyle, $gal_style['name']);
- // First check for the existence of a default image in the style
- // we are looking for.
+ /* First check for the existence of a key image in the specified style */
if (!empty($this->data['attribute_default_prettythumb'])) {
$thumbs = @unserialize($this->data['attribute_default_prettythumb']);
}
if (!isset($thumbs) || !is_array($thumbs)) {
$thumbs = array();
}
-
if (!empty($thumbs[$styleHash])) {
return $thumbs[$styleHash];
}
- // Don't already have one, must generate it.
+ /* Don't already have one, must generate it. */
$params = array('gallery' => $this, 'style' => $gal_style);
try {
$iview = Ansel_ImageGenerator::factory($gal_style['default_galleryimage_type'], $params);
// but protect against infinite recursion.
Horde::logMessage($e->getMessage(), 'DEBUG');
if ($style != 'ansel_default') {
- return $this->getDefaultImage('ansel_default');
+ return $this->getKeyImage('ansel_default');
}
- Horde::logMessage($e->getMessage(), 'ERR');
}
} else {
- // We are just using an image thumbnail for the gallery default.
+ /* We are just using an image thumbnail. */
if ($this->countImages()) {
if (!empty($this->data['attribute_default']) &&
$this->data['attribute_default'] > 0) {
}
if ($this->hasSubGalleries()) {
- // Fall through to a default image of a sub gallery.
+ /* Fall through to a key image of a sub gallery. */
try {
$galleries = $GLOBALS['injector']
->getInstance('Ansel_Storage')
}
if ($galleries) {
foreach ($galleries as $galleryId => $gallery) {
- if ($default_img = $gallery->getDefaultImage($style)) {
+ if ($default_img = $gallery->getKeyImage($style)) {
return $default_img;
}
}
}
}
+ /* Could not find a key image */
return false;
}
if ($update) {
$db = $this->getShareOb()->getWriteDb();
// Manually convert the charset since we're not going through save()
- // @TODO: Look at this usage - maybe each app's share object should
- // have this method or just keep it public?
$data = $this->getshareOb()->toDriverCharset(array($driver_key => $value));
$query = $db->prepare('UPDATE ' . $this->getShareOb()->getTable() . ' SET ' . $driver_key . ' = ? WHERE share_id = ?', null, MDB2_PREPARE_MANIP);
if ($GLOBALS['conf']['ansel_cache']['usecache']) {
}
/**
- * Returns the default image for this gallery.
+ * Returns the key image for this gallery.
*
* @param string $style Force the use of this style, if it's available
* otherwise use whatever style is choosen for this
* gallery. If prettythumbs are not available then
* we always use ansel_default style.
*
- * @return mixed The image_id of the default image or false.
+ * @return mixed The image_id of the key image or false.
*/
- public function getDefaultImage($style = null)
+ public function getKeyImage($style = null)
{
if (count($this->_images)) {
return reset($this->_images);
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. */
+ /* Sanitize image ids, and see if we're removing our key image. */
$ids = array();
foreach ($images as $imageId) {
$ids[] = (int)$imageId;
}
/* 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 ($result instanceof PEAR_Error) {
- Horde::logMessage($result, 'ERR');
- throw new Ansel_Exception($result);
- }
+ $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->setImagesGallery($ids, $gallery->id);
/* Update the gallery counts for each affected gallery */
if ($this->_gallery->get('has_subgalleries')) {
$image->getVFSName('full'));
} 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 */
- $this->_gallery->getShareOb()->getWriteDb()->exec('DELETE FROM ansel_image_attributes WHERE image_id = ' . (int)$image->id);
+ /* Delete from storage */
+ $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()
+ ->deleteImage($image->id);
if (!$isStack) {
$GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()
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. */
+ /* Sanitize image ids, and see if we're removing our key image. */
$ids = array();
foreach ($images as $imageId) {
$ids[] = (int)$imageId;
}
}
- $result = $this->_gallery->getShareOb()->getWriteDb()->exec('UPDATE ansel_images SET gallery_id = ' . $gallery->id . ' WHERE image_id IN (' . implode(',', $ids) . ')');
- if ($result instanceof PEAR_Error) {
- throw new Ansel_Exception($result->getMessage());
- }
-
+ $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->setImagesGallery($ids, $gallery->id);
$this->_gallery->updateImageCount(count($ids), false);
$gallery->updateImageCount(count($ids), true);
$GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->deleteFile($image->getVFSPath('full'), $image->getVFSName('full'));
} catch (VFS_Exception $e) {}
- /* Delete from SQL. */
- $this->_gallery->getShareOb()->getWriteDb()->exec('DELETE FROM ansel_images WHERE image_id = ' . (int)$image->id);
-
- /* Remove any attributes */
- $this->_gallery->getShareOb()->getWriteDb()->exec('DELETE FROM ansel_image_attributes WHERE image_id = ' . (int)$image->id);
-
+ /* Delete from storage */
+ $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->deleteImage($image->id);
if (!$isStack) {
$this->_gallery->updateImageCount(1, false);
}
/**
* Utility function to return an array of Horde_Images to use in building a
* polaroid stack. Returns a random set of 5 images from the gallery, or the
- * explicitly set default image plus 4 others.
+ * explicitly set key image plus 4 others.
*
* @return array of Horde_Images
*/
}
}
- // Reverse the array to ensure the requested default image
+ // Reverse the array to ensure the requested key image
// is the last in the array (so it will appear on the top of
// the stack.
return array_reverse($images);
min($GLOBALS['conf']['thumbnail']['height'], $this->_dimensions['height']),
true);
- /* Don't bother with these effects for a custom gallery default image
+ /* Don't bother with these effects for a custom gallery key image
(which will have a negative gallery_id). */
if ($this->_image->gallery > 0) {
if (is_null($this->_style)) {
}
/**
+ * Set the gallery id for a set of images. Useful for bulk updating images
+ * when moving from one gallery to another.
+ *
+ * @param array $image_ids An array of image ids
+ * @param integer $gallery_id The gallery id to move the images to.
+ *
+ * @return void
+ * @throws Ansel_Exception
+ */
+ public function setImagesGallery($image_ids, $gallery_id)
+ {
+ $result = $this->_db->exec('UPDATE ansel_images SET gallery_id = ' . $gallery_id . ' WHERE image_id IN (' . implode(',', $image_ids) . ')');
+ if ($result instanceof PEAR_Error) {
+ Horde::logMessage($result, 'ERR');
+ throw new Ansel_Exception($result);
+ }
+ }
+
+ /**
+ * Deletes an Ansel_Image from data storage.
+ *
+ * @param integer $image_id The image id(s) to remove.
+ *
+ * @return void
+ * @throws Ansel_Exception
+ */
+ public function removeImage($image_id)
+ {
+ $this->_db->exec('DELETE FROM ansel_images WHERE image_id = ' . (int)$image_id);
+ $this->_db->exec('DELETE FROM ansel_image_attributes WHERE image_id = ' . (int)$imageid);
+ }
+
+ /**
* Helper function to get a string of field names
*
* @return string
$thumbstyle = $mini ? 'mini' : $style['thumbstyle'];
$gallery_image = Ansel::getImageUrl(
- $dgallery->getDefaultImage(),
+ $dgallery->getKeyImage(),
$thumbstyle, true, $style['name']);
// No need to escape alt here since it's generated enitrely within
$gallery_image = Horde::img('gallery-locked.png');
} else {
$gallery_image = Ansel::getImageUrl(
- $gallery->getDefaultImage($style['name']),
+ $gallery->getKeyImage($style['name']),
$thumbstyle, true, $style['name']);
$gallery_image = '<img src="' . $gallery_image . '" alt="' . htmlspecialchars($gallery->get('name')) . '" />';
}
return '';
}
- /* Ideally, since gallery default images are unique in that each style
+ /* Ideally, since gallery key images are unique in that each style
* needs it's own unique image_id, the thumbsize and style parameters
* are mutually exclusive - specifying a specific gallery style is only
* needed if requesting the prettythumb thumbsize value. Make sure that
* both were not passed in.
*/
if ($thumbsize == 'thumb') {
- $images[] = $gallery->getDefaultImage('ansel_default');
+ $images[] = $gallery->getKeyImage('ansel_default');
} else {
// Default to gallery's defined style if not provided.
$gallery_style = empty($this->_params['style']) ?
$gallery->get('style') :
$this->_params['style'];
- $images[] = $gallery->getDefaultImage($gallery_style);
+ $images[] = $gallery->getKeyImage($gallery_style);
}
}
$json = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getImageJson($images, null, true, $thumbsize, true);
/**
* Contructor.
*
- * Also handles any actions from the view. TODO: These should be done with
- * an init() or handle() method instead.
+ * Also handles any actions from the view.
*
* @return Ansel_View_Results
*/
$parent = array_pop($parents);
}
- $img = (string)Ansel::getImageUrl($gal->getDefaultImage('ansel_default'), 'mini', true);
+ $img = (string)Ansel::getImageUrl($gal->getKeyImage('ansel_default'), 'mini', true);
$link = Ansel::getUrlFor('view', array('gallery' => $gal->id,
'slug' => $gal->get('slug'),
'view' => 'Gallery'),
$images = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getRecentImages($subs);
} else {
$images = $gallery->getRecentImages();
- $owner = &$gallery->getOwner();
+ $owner = $gallery->getIdentity();
$author = $owner->getValue('from_addr');
}
}
array('view' => 'Gallery',
'gallery' => $id),
true);
- $img = &$GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getImage($gallery->getDefaultImage('ansel_default'));
+ $img = &$GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getImage($gallery->getKeyImage('ansel_default'));
$params = array('last_modified' => $gallery->get('last_modified'),
'name' => sprintf(_("%s on %s"),
$gallery->get('name'),
<?php foreach ($preview_gallery as $galleryId => $gallery): ?>
<td align="center">
<?php if ($gallery->isOldEnough() && !$gallery->hasPasswd()): ?>
- <?php echo $link ?><img src="<?php echo Ansel::getImageUrl($gallery->getDefaultImage('ansel_default'), 'mini', false, 'ansel_default'); ?>" alt="<?php echo htmlspecialchars($gallery->get('name'))?>" /></a>
+ <?php echo $link ?><img src="<?php echo Ansel::getImageUrl($gallery->getKeyImage('ansel_default'), 'mini', false, 'ansel_default'); ?>" alt="<?php echo htmlspecialchars($gallery->get('name'))?>" /></a>
<?php else: ?>
<?php echo $link . Horde::img('gallery-locked-mini.png') ?></a>
<?php endif; ?>
<?php for ($i = 0; $i < count($mini_galleries); ++$i): ?>
<td align="center">
<?php if ($mini_galleries[$i]->isOldEnough() && !$mini_galleries[$i]->hasPasswd()): ?>
- <?php echo $link ?><img src="<?php echo Ansel::getImageUrl($mini_galleries[$i]->getDefaultImage('ansel_default'), 'mini', false, 'ansel_default') ?>" alt="<?php echo $owner_title?>" /></a>
+ <?php echo $link ?><img src="<?php echo Ansel::getImageUrl($mini_galleries[$i]->getKeyImage('ansel_default'), 'mini', false, 'ansel_default') ?>" alt="<?php echo $owner_title?>" /></a>
<?php else: ?>
<?php echo $link . Horde::img('gallery-locked-mini.png') ?></a>
<?php endif; ?>