Skip to content

Commit

Permalink
Bug: 14028 Fix generating thubnails for keyimages in mobile view.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Jun 26, 2015
1 parent faa0b5a commit 46a810f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
61 changes: 36 additions & 25 deletions ansel/lib/Gallery.php
Expand Up @@ -757,6 +757,9 @@ public function getKeyImage(Ansel_Style $style = null)
// Don't already have one, must generate it.
$params = array('gallery' => $this, 'style' => $style);
try {
if (!$params['image'] = $this->getImage($this->_getDefaultImageId())) {
return false;
}
$iview = Ansel_ImageGenerator::factory($style->keyimage_type, $params);
$img = $iview->create();

Expand Down Expand Up @@ -790,37 +793,45 @@ public function getKeyImage(Ansel_Style $style = null)
}
} else {
// We are just using an image thumbnail.
if ($this->countImages()) {
if ($default = $this->get('default')) {
return $default;
}
$keys = $this->listImages();
$this->set('default', $keys[count($keys) - 1]);
$this->set('default_type', 'auto');
$this->save();
return $keys[count($keys) - 1];
}
return $this->_getDefaultImageId();
}

if ($this->hasSubGalleries()) {
// Fall through to a key image of a sub gallery.
try {
$galleries = $GLOBALS['injector']
->getInstance('Ansel_Storage')
->listGalleries(array('parent' => $this->id, 'all_levels' => false));
// Could not find a key image
return false;
}

/**
* Returns the id for the key image of this gallery.
*
* @return integer|boolean The image id or false if none found.
*/
protected function _getDefaultImageId()
{
if ($this->countImages()) {
if ($default = $this->get('default')) {
return $default;
}
$keys = $this->listImages();
$this->set('default', $keys[count($keys) - 1]);
$this->set('default_type', 'auto');
$this->save();
return $keys[count($keys) - 1];
}
if ($this->hasSubGalleries()) {
try {
$galleries = $GLOBALS['injector']
->getInstance('Ansel_Storage')
->listGalleries(array('parent' => $this->id, 'all_levels' => false));

foreach ($galleries as $gallery) {
if ($default_img = $gallery->getKeyImage($style)) {
return $default_img;
}
foreach ($galleries as $gallery) {
if ($default_img = $gallery->getKeyImage($style)) {
return $default_img;
}
} catch (Ansel_Exception $e) {
return false;
}
} catch (Ansel_Exception $e) {
return false;
}
}

// Could not find a key image
return false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion ansel/lib/Image.php
Expand Up @@ -915,7 +915,7 @@ public function display($view = 'full', Ansel_Style $style = null)
// Check full photo permissions
$gallery = $GLOBALS['injector']
->getInstance('Ansel_Storage')
->getGallery($this->gallery);
->getGallery(abs($this->gallery));
if (!$gallery->canDownload()) {
throw Horde_Exception_PermissionDenied(
_("Access denied downloading photos from this gallery."));
Expand Down
4 changes: 2 additions & 2 deletions ansel/lib/ImageGenerator.php
Expand Up @@ -92,8 +92,8 @@ public function __construct($params)
public function create()
{
if (!empty($this->_image)) {
// Use Horde_Image since we don't know at this point which
// view we have loaded.
// Make sure to load the image.
$this->_image->load('full');
$img = $this->_image->getHordeImage();
$this->_dimensions = $img->getDimensions();
}
Expand Down

0 comments on commit 46a810f

Please sign in to comment.