diff --git a/assets/components/gallery/images/album-empty.jpg b/assets/components/gallery/images/album-empty.jpg new file mode 100644 index 0000000..42d511e Binary files /dev/null and b/assets/components/gallery/images/album-empty.jpg differ diff --git a/core/components/gallery/docs/changelog.txt b/core/components/gallery/docs/changelog.txt index 4dfa488..6f3af19 100755 --- a/core/components/gallery/docs/changelog.txt +++ b/core/components/gallery/docs/changelog.txt @@ -1,5 +1,9 @@ Changelog for Gallery. +Gallery 1.5.2 +==================================== +- [#217] Add default cover when using GalleryAlbums with cover displays and no item is in the album + Gallery 1.5.1 ==================================== - Add DB caching to Gallery and GalleryAlbums snippets, reducing page load times diff --git a/core/components/gallery/model/gallery/galalbum.class.php b/core/components/gallery/model/gallery/galalbum.class.php index 6ee10a7..1a78251 100644 --- a/core/components/gallery/model/gallery/galalbum.class.php +++ b/core/components/gallery/model/gallery/galalbum.class.php @@ -241,7 +241,7 @@ public function getCoverItem($albumCoverSort = 'rank',$albumCoverSortDir = 'ASC' if ($this->xpdo->getCacheManager()) { $cache = $this->xpdo->cacheManager->get($cacheKey); } - if (!$cache) { + if (!$cache || true) { $c = $this->xpdo->newQuery('galItem'); $c->innerJoin('galAlbumItem','AlbumItems'); $c->where(array( @@ -250,8 +250,22 @@ public function getCoverItem($albumCoverSort = 'rank',$albumCoverSortDir = 'ASC' $c->sortby($albumCoverSort,$albumCoverSortDir); $count = $this->xpdo->getCount('galItem', $c); $c->limit(1); + /** @var galItem $item */ $item = $this->xpdo->getObject('galItem',$c); + if (empty($item)) { + $assetsUrl = $this->xpdo->getOption('gallery.assets_url',null,$this->xpdo->getOption('assets_url',null,MODX_ASSETS_URL).'gallery/'); + if (strpos($assetsUrl,'http') === false && defined('MODX_URL_SCHEME') && defined('MODX_HTTP_HOST')) { + $assetsUrl = MODX_URL_SCHEME.MODX_HTTP_HOST.$assetsUrl; + } + $item = $this->xpdo->newObject('galItem'); + $item->fromArray(array( + 'name' => '', + 'filename' => $assetsUrl.'images/album-empty.jpg', + 'absolute_filename' => true, + 'active' => true, + )); + } $item->set('total',$count); $cache = $item->toArray(); $this->xpdo->cacheManager->set($cacheKey,$cache); diff --git a/core/components/gallery/model/gallery/galitem.class.php b/core/components/gallery/model/gallery/galitem.class.php index e720043..1dc9915 100644 --- a/core/components/gallery/model/gallery/galitem.class.php +++ b/core/components/gallery/model/gallery/galitem.class.php @@ -28,8 +28,13 @@ public function get($k, $format = null, $formatTemplate= null) { case 'thumbnail': $value = $this->getPhpThumbUrl(); if (empty($format)) $format = array(); - $format['src'] = $this->getSiteUrl(); - $format['src'] .= $this->xpdo->call('galAlbum','getFilesUrl',array(&$this->xpdo)).$this->get('filename'); + $filename = $this->get('filename'); + if ($this->get('absolute_filename')) { + $format['src'] = $filename; + } else { + $format['src'] = $this->getSiteUrl(); + $format['src'] .= $this->xpdo->call('galAlbum','getFilesUrl',array(&$this->xpdo)).$filename; + } $url = $value.'&'.http_build_query($format,'','&'); if ($this->xpdo->getOption('xhtml_urls',null,false)) { $value = str_replace('&','&',$url); @@ -40,9 +45,13 @@ public function get($k, $format = null, $formatTemplate= null) { break; case 'image': if (empty($format)) $format = array(); - $format['src'] = $this->getSiteUrl(); - $format['src'] .= $this->xpdo->call('galAlbum','getFilesUrl',array(&$this->xpdo)).$this->get('filename'); - + $filename = $this->get('filename'); + if ($this->get('absolute_filename')) { + $format['src'] = $filename; + } else { + $format['src'] = $this->getSiteUrl(); + $format['src'] .= $this->xpdo->call('galAlbum','getFilesUrl',array(&$this->xpdo)).$filename; + } $value = $this->getPhpThumbUrl().'&'.http_build_query($format,'','&'); $value = $this->xpdo->getOption('xhtml_urls',null,false) ? str_replace('&','&',$value) : $value; break;