Ok,
Chunks:
galAlbumRowTpl
<div class="albumPreview">
<h3><a href="[[~[[*id]]? &[[+albumRequestVar]]=`[[+id]]`]]">[[+name]]</a></h3>
<div class="thumb">
<a href="[[~[[*id]]? &[[+albumRequestVar]]=`[[+id]]`]]"><img src="[[+image]]" alt="[[+name]]"/></a>
</div>
<div class="desc">
<p>[[+description]]</p>
<a href="[[~[[*id]]? &[[+albumRequestVar]]=`[[+id]]`]]" class="view">View gallery</a>
</div>
</div>
galAlbumTpl
<h1>[[+album_name]]</h1>
<p>[[+album_description]]</p>
[[+thumbnails]]
galItemThumb
<div class="[[+cls]]">
<a href="[[+linkToImage:if=`[[+linkToImage]]`:is=`1`:then=`[[+image_absolute]]`:else=`[[~[[*id]]?
&[[+imageGetParam]]=`[[+id]]`
&[[+albumRequestVar]]=`[[+album]]`
&[[+tagRequestVar]]=`[[+tag]]` ]]`]]">
<img class="[[+imgCls]]" src="[[+thumbnail]]" alt="[[+name]]" />
</a>
</div>
Snippets
Gallery
<?php
/**
* Gallery
*
* Copyright 2010 by Shaun McCormick <[email protected]>
*
* Gallery is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* Gallery is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* Gallery; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package gallery
*/
/**
* The main Gallery snippet.
*
* @package gallery
*/
$gallery = $modx->getService('gallery','Gallery',$modx->getOption('gallery.core_path',null,$modx->getOption('core_path').'components/gallery/').'model/gallery/',$scriptProperties);
if (!($gallery instanceof Gallery)) return '';
/* setup default properties */
$album = $modx->getOption('album',$scriptProperties,false);
$plugin = $modx->getOption('plugin',$scriptProperties,'');
$tag = $modx->getOption('tag',$scriptProperties,'');
$limit = $modx->getOption('limit',$scriptProperties,0);
$start = $modx->getOption('start',$scriptProperties,0);
$sort = $modx->getOption('sort',$scriptProperties,'rank');
$sortAlias = $modx->getOption('sortAlias',$scriptProperties,'galItem');
if ($sort == 'rank') $sortAlias = 'AlbumItems';
$dir = $modx->getOption('dir',$scriptProperties,'ASC');
$showInactive = $modx->getOption('showInactive',$scriptProperties,false);
$linkToImage = $modx->getOption('linkToImage',$scriptProperties,false);
$imageGetParam = $modx->getOption('imageGetParam',$scriptProperties,'galItem');
$albumRequestVar = $modx->getOption('albumRequestVar',$scriptProperties,'galAlbum');
$tagRequestVar = $modx->getOption('tagRequestVar',$scriptProperties,'galTag');
$itemCls = $modx->getOption('itemCls',$scriptProperties,'gal-item');
/* check for REQUEST vars if property set */
if ($modx->getOption('checkForRequestAlbumVar',$scriptProperties,true)) {
if (!empty($_REQUEST[$albumRequestVar])) $album = $_REQUEST[$albumRequestVar];
}
if ($modx->getOption('checkForRequestTagVar',$scriptProperties,true)) {
if (!empty($_REQUEST[$tagRequestVar])) $tag = $_REQUEST[$tagRequestVar];
}
if (empty($album) && empty($tag)) return '';
/* build query */
$tagc = $modx->newQuery('galTag');
$tagc->setClassAlias('TagsJoin');
$tagc->select('GROUP_CONCAT('.$modx->getSelectColumns('galTag','TagsJoin','',array('tag')).')');
$tagc->where($modx->getSelectColumns('galTag','TagsJoin','',array('item')).' = '.$modx->getSelectColumns('galItem','galItem','',array('id')));
$tagc->prepare();
$tagSql = $tagc->toSql();
$c = $modx->newQuery('galItem');
$c->select(array('galItem.*'));
$c->select('('.$tagSql.') AS `tags`');
$c->innerJoin('galAlbumItem','AlbumItems');
$c->innerJoin('galAlbum','Album',$modx->getSelectColumns('galAlbumItem','AlbumItems','',array('album')).' = '.$modx->getSelectColumns('galAlbum','Album','',array('id')));
/* pull by album */
if (!empty($album)) {
$albumField = is_numeric($album) ? 'id' : 'name';
$albumWhere = $albumField == 'name' ? array('name' => $album) : $album;
$album = $modx->getObject('galAlbum',$albumWhere);
if (empty($album)) return '';
$c->where(array(
'Album.'.$albumField => $album->get($albumField),
));
$galleryId = $album->get('id');
$galleryName = $album->get('name');
$galleryDescription = $album->get('description');
unset($albumWhere,$albumField);
}
if (!empty($tag)) { /* pull by tag */
$c->innerJoin('galTag','Tags');
$c->where(array(
'Tags.tag' => $tag,
));
if (empty($album)) {
$galleryId = 0;
$galleryName = $tag;
$galleryDescription = '';
}
}
$c->where(array(
'galItem.mediatype' => $modx->getOption('mediatype',$scriptProperties,'image'),
));
if (!$showInactive) {
$c->where(array(
'galItem.active' => true,
));
}
if (strcasecmp($sort,'rand')==0) {
$c->sortby('RAND()',$dir);
} else {
$c->sortby($sortAlias.'.'.$sort,$dir);
}
if (!empty($limit)) $c->limit($limit,$start);
$items = $modx->getCollection('galItem',$c);
/* load plugins */
if (!empty($plugin)) {
if (($className = $modx->loadClass('gallery.plugins.'.$plugin,$gallery->config['modelPath'],true,true))) {
$plugin = new $className($gallery,$scriptProperties);
$plugin->load();
$scriptProperties = $plugin->adjustSettings($scriptProperties);
}
} else {
if ($modx->getOption('useCss',$scriptProperties,true)) {
$modx->regClientCSS($gallery->config['cssUrl'].'web.css');
}
}
/* iterate */
$output = '';
foreach ($items as $item) {
$itemArray = $item->toArray();
$itemArray['cls'] = $itemCls;
$itemArray['filename'] = basename($item->get('filename'));
$itemArray['image_absolute'] = $modx->getOption('gallery.files_url').$item->get('filename');
$itemArray['fileurl'] = $itemArray['image_absolute'];
$itemArray['filepath'] = $modx->getOption('gallery.files_path').$item->get('filename');
$itemArray['filesize'] = $item->get('filesize');
$itemArray['thumbnail'] = $item->get('thumbnail',array(
'w' => (int)$modx->getOption('thumbWidth',$scriptProperties,100),
'h' => (int)$modx->getOption('thumbHeight',$scriptProperties,100),
'zc' => (boolean)$modx->getOption('thumbZoomCrop',$scriptProperties,1),
'far' => (boolean)$modx->getOption('thumbFar',$scriptProperties,'C'),
'q' => $modx->getOption('thumbQuality',$scriptProperties,90),
));
$itemArray['image'] = $item->get('thumbnail',array(
'w' => (int)$modx->getOption('imageWidth',$scriptProperties,500),
'h' => (int)$modx->getOption('imageHeight',$scriptProperties,500),
'zc' => (boolean)$modx->getOption('imageZoomCrop',$scriptProperties,false),
'far' => (string)$modx->getOption('imageFar',$scriptProperties,''),
'q' => $modx->getOption('imageQuality',$scriptProperties,90),
));
if (!empty($album)) $itemArray['album'] = $album->get('id');
if (!empty($tag)) $itemArray['tag'] = $tag;
$itemArray['linkToImage'] = $linkToImage;
$itemArray['imageGetParam'] = $imageGetParam;
$itemArray['albumRequestVar'] = $albumRequestVar;
$itemArray['tagRequestVar'] = $tagRequestVar;
$itemArray['tag'] = '';
$output .= $gallery->getChunk($modx->getOption('thumbTpl',$scriptProperties,'galItemThumb'),$itemArray);
}
$containerTpl = $modx->getOption('containerTpl',$scriptProperties,false);
if (!empty($containerTpl)) {
$ct = $gallery->getChunk($containerTpl,array(
'thumbnails' => $output,
'album_name' => $galleryName,
'album_description' => $galleryDescription,
));
if (!empty($ct)) $output = $ct;
}
$toPlaceholder = $modx->getOption('toPlaceholder',$scriptProperties,false);
if (!empty($toPlaceholder)) {
$modx->toPlaceholders(array(
$toPlaceholder => $output,
$toPlaceholder.'.id' => $galleryId,
$toPlaceholder.'.name' => $galleryName,
$toPlaceholder.'.description' => $galleryDescription,
));
} else {
$placeholderPrefix = $modx->getOption('placeholderPrefix',$scriptProperties,'gallery.');
$modx->toPlaceholders(array(
$placeholderPrefix.'id' => $galleryId,
$placeholderPrefix.'name' => $galleryName,
$placeholderPrefix.'description' => $galleryDescription,
));
return $output;
}
return '';
GalleryAlbums
<?php
/**
* Gallery
*
* Copyright 2010 by Shaun McCormick <[email protected]>
*
* Gallery is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* Gallery is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* Gallery; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package gallery
*/
/**
* Loads a list of Albums
*
* @package gallery
*/
$gallery = $modx->getService('gallery','Gallery',$modx->getOption('gallery.core_path',null,$modx->getOption('core_path').'components/gallery/').'model/gallery/',$scriptProperties);
if (!($gallery instanceof Gallery)) return '';
/* setup default properties */
$rowTpl = $modx->getOption('rowTpl',$scriptProperties,'galAlbumRowTpl');
$tplCover = $modx->getOption('albumCover',$scriptProperties,'galAlbumCoverRowTpl');
$showInactive = $modx->getOption('showInactive',$scriptProperties,false);
$prominentOnly = $modx->getOption('prominentOnly',$scriptProperties,true);
$toPlaceholder = $modx->getOption('toPlaceholder',$scriptProperties,false);
$sort = $modx->getOption('sort',$scriptProperties,'createdon');
$sortAlias = $modx->getOption('sortAlias',$scriptProperties,'galAlbum');
$dir = $modx->getOption('dir',$scriptProperties,'DESC');
$limit = $modx->getOption('limit',$scriptProperties,10);
$start = $modx->getOption('start',$scriptProperties,0);
$parent = $modx->getOption('parent',$scriptProperties,0);
$showAll = $modx->getOption('showAll',$scriptProperties,false);
$albumRequestVar = $modx->getOption('albumRequestVar',$scriptProperties,'galAlbum');
$tag = $modx->getOption('tag',$scriptProperties,'');
// NOT NECESSARY, MAYBE FOR ANOTHER NEW PROJECT
/*$tagc = $modx->newQuery('galItem');
$tagc->setClassAlias('ItemsJoin');
$tagc->select($modx->getSelectColumns('galItem','ItemsJoin','',array('filename')));
$tagc->innerJoin('galAlbumItem','AlbumItems');
$tagc->innerJoin('galAlbum','Album',$modx->getSelectColumns('galAlbumItem','AlbumItems','',array('album')).' = '.$modx->getSelectColumns('galAlbum','Album','',array('id')));
$tagc->innerJoin('galTag','Tags');
$tagc->where($modx->getSelectColumns('galItem','ItemsJoin','',array('id')).' = '.$modx->getSelectColumns('galAlbumItem','AlbumItems','',array('item')));
$tagc->where(array(
'Tags.tag' => "albumcover"
));
$tagc->where(array(
'Album.id' => 'galAlbum.'.'id'
));
$tagc->prepare();
$tagSql = $tagc->toSql();*/
/* build query */
$c = $modx->newQuery('galAlbum');
$c->select(array('galAlbum.*'));
if (!$showInactive) {
$c->where(array(
'active' => true,
));
}
if ($prominentOnly) {
$c->where(array(
'prominent' => true,
));
}
if (empty($showAll)) {
$c->where(array(
'parent' => $parent,
));
}
$c->sortby($sortAlias.'.'.$sort,$dir);
if ($limit > 0) { $c->limit($limit,$start); }
$albums = $modx->getCollection('galAlbum',$c);
/* iterate */
/* CODE PART ADDED BY greenVisions ([email protected]) BASED ON Shaun McCormick's GALLERYALBUM SNIPPET */
$output = '';
foreach ($albums as $album) {
$albumArray = $album->toArray();
$albumArray['totalPictures'] = 0;
$albumItems = $album->getMany('AlbumItems');
foreach ($albumItems as $albumItem) {
$albumArray['totalPictures'] += 1;
$item = $albumItem->getOne('Item');
$tags = $item->getMany('Tags');
foreach ($tags as $tag) {
$tagArray = $tag->toArray();
if(!empty($tagArray) && $tagArray['tag'] = $tag){
$itemArray = $item->toArray();
$itemArray['filename'] = basename($item->get('filename'));
$itemArray['image_absolute'] = $modx->getOption('gallery.files_url').$item->get('filename');
$itemArray['filesize'] = $item->get('filesize');
$itemArray['thumbnail'] = $item->get('thumbnail',array(
'w' => (int)$modx->getOption('thumbWidth',$scriptProperties,100),
'h' => (int)$modx->getOption('thumbHeight',$scriptProperties,100),
'zc' => (boolean)$modx->getOption('thumbZoomCrop',$scriptProperties,1),
'far' => (boolean)$modx->getOption('thumbFar',$scriptProperties,'C'),
));
$itemArray['image'] = $item->get('thumbnail',array(
'w' => (int)$modx->getOption('imageWidth',$scriptProperties,500),
'h' => (int)$modx->getOption('imageHeight',$scriptProperties,500),
'zc' => (boolean)$modx->getOption('imageZoomCrop',$scriptProperties,false),
'far' => (string)$modx->getOption('imageFar',$scriptProperties,''),
));
$thumbOutput = $modx->getChunk($tplCover,$itemArray);
$albumArray['albumThumb'] = $thumbOutput;
}
}
}
$albumArray['albumRequestVar'] = $albumRequestVar;
$output .= $gallery->getChunk($rowTpl,$albumArray);
}
if ($toPlaceholder) {
$modx->setPlaceholder($toPlaceholder,$output);
return '';
}
return $output;
GalleryItem
<?php
/**
* Gallery
*
* Copyright 2010 by Shaun McCormick <[email protected]>
*
* Gallery is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* Gallery is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* Gallery; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package gallery
*/
/**
* Display a single Gallery Item
*
* @package gallery
*/
$gallery = $modx->getService('gallery','Gallery',$modx->getOption('gallery.core_path',null,$modx->getOption('core_path').'components/gallery/').'model/gallery/',$scriptProperties);
if (!($gallery instanceof Gallery)) return '';
/* get ID of item */
$id = (int)$modx->getOption('id',$scriptProperties,false);
if ($modx->getOption('checkForRequestVar',$scriptProperties,true)) {
$getParam = $modx->getOption('getParam',$scriptProperties,'galItem');
if (!empty($_REQUEST[$getParam])) { $id = (int)$_REQUEST[$getParam]; }
}
if (empty($id)) return '';
/* setup default properties */
$tpl = $modx->getOption('tpl',$scriptProperties,'galItem');
$toPlaceholders = $modx->getOption('toPlaceholders',$scriptProperties,true);
$toPlaceholdersPrefix = $modx->getOption('toPlaceholdersPrefix',$scriptProperties,'galitem');
$albumTpl = $modx->getOption('albumTpl',$scriptProperties,'galItemAlbum');
$albumSeparator = $modx->getOption('albumSeparator',$scriptProperties,', ');
$albumRequestVar = $modx->getOption('albumRequestVar',$scriptProperties,'galAlbum');
$tagTpl = $modx->getOption('tagTpl',$scriptProperties,'galItemTag');
$tagSeparator = $modx->getOption('tagSeparator',$scriptProperties,', ');
$tagSortDir = $modx->getOption('tagSortDir',$scriptProperties,'DESC');
$tagRequestVar = $modx->getOption('tagRequestVar',$scriptProperties,'galTag');
/* get item */
$c = $modx->newQuery('galItem');
$c->select($modx->getSelectColumns('galItem','galItem'));
$c->where(array(
'id' => $id,
));
$item = $modx->getObject('galItem',$c);
if (empty($item)) return '';
/* setup placeholders */
$itemArray = $item->toArray();
$itemArray['filename'] = basename($item->get('filename'));
$itemArray['filesize'] = $item->get('filesize');
$itemArray['thumbnail'] = $item->get('thumbnail',array(
'w' => $modx->getOption('thumbWidth',$scriptProperties,100),
'h' => $modx->getOption('thumbHeight',$scriptProperties,100),
'zc' => $modx->getOption('thumbZoomCrop',$scriptProperties,0),
'far' => $modx->getOption('thumbFar',$scriptProperties,'C'),
'q' => $modx->getOption('thumbQuality',$scriptProperties,90),
));
$itemArray['image'] = $item->get('thumbnail',array(
'w' => $modx->getOption('imageWidth',$scriptProperties,500),
'h' => $modx->getOption('imageHeight',$scriptProperties,500),
'zc' => $modx->getOption('imageZoomCrop',$scriptProperties,0),
'far' => $modx->getOption('imageFar',$scriptProperties,false),
'q' => $modx->getOption('imageQuality',$scriptProperties,90),
));
/* get albums */
$c = $modx->newQuery('galAlbum');
$c->innerJoin('galAlbumItem','AlbumItems',$modx->getSelectColumns('galAlbumItem','AlbumItems','',array('album')).' = '.$modx->getSelectColumns('galAlbum','galAlbum','',array('id'))
.' AND '.$modx->getSelectColumns('galAlbumItem','AlbumItems','',array('item')).' = '.$item->get('id'));
$c->sortby('AlbumItems.rank','ASC');
$albums = $modx->getCollection('galAlbum',$c);
$itemArray['albums'] = '';
$i = 0; $count = count($albums);
foreach ($albums as $album) {
$albumArray = $album->toArray('',true,true);
$albumArray['albumRequestVar'] = $albumRequestVar;
$itemArray['albums'] .= $gallery->getChunk($albumTpl,$albumArray);
if ($i+1 < $count) $itemArray['albums'] .= $albumSeparator;
$i++;
}
/* get tags */
$c = $modx->newQuery('galTag');
$c->where(array(
'item' => $item->get('id'),
));
$c->sortby('tag',$tagSortDir);
$tags = $modx->getCollection('galTag',$c);
$itemArray['tags'] = '';
$i = 0; $count = count($tags);
foreach ($tags as $tag) {
$tagArray = $tag->toArray();
$tagArray['tagRequestVar'] = $tagRequestVar;
$itemArray['tags'] .= $gallery->getChunk($tagTpl,$tagArray);
if ($i+1 < $count) $itemArray['tags'] .= $tagSeparator;
$i++;
}
/* if outputting to placeholders, use this, otherwise, use tpl */
if ($toPlaceholders) {
$modx->toPlaceholders($itemArray,$toPlaceholdersPrefix);
return '';
}
if (empty($tpl)) return '';
$output .= $gallery->getChunk($tpl,$itemArray);
return $output;