Vor ein paar Monaten erstellte ich eine Webseite welche vorallem aus einer Gallery besteht. Die einzelnen Galerien wurden auf einzelnen Seiten eingebunden. Damit dies möglichst einfach möglich ist, habe ich ein Plugin für AdvancedContent geschrieben, welches die Gallery-Ordner ausliest und als Dropdown zur Verfügung stellt.
Als erstes in den Ordner ./plugins folgende Datei laden:
function.getGalleryTree.php:
<?php
/**
* ------------------------------------------------------------------------
* Liest alle Gallery Ordner aus und übergibt sie als Liste AdvancedContent
* ------------------------------------------------------------------------
* blattertech informatik, Lukas Blatter, lb@blattertech.ch
* Twitter: @lukasblatter
* Web: www.blattertech.ch
* ------------------------------------------------------------------------
* History:
* 2011.08.20 - Lukas Blatter - Inital Release
* 2011.12.02 - Lukas Blatter - Unterstützt nun auch die Auswahl von Unterordnern
* mit subdir="/pfad/zum/ordner"
* $config Aufruf an 1.10.x angepasst.
* ------------------------------------------------------------------------
* This program is distributed under the GNU General Public License, Version 2,
* June 1991. Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin
* St, Fifth Floor, Boston, MA 02110, USA
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* */
function smarty_cms_function_getGalleryTree($params, &$smarty)
{
$config = cmsms()->GetConfig();
$delimiter = "|";
if (!function_exists("getGalleryTreeAsArray"))
{
function getGalleryTreeAsArray($path = '.', $ignore = array()) {
$dirTree = array ();
$dirTreeTemp = array ();
$ignore[] = '.';
$ignore[] = '..';
$ignore[] = '.htaccess';
$ignore[] = 'error_log';
$ignore[] = 'cgi-bin';
$ignore[] = '.DS_Store';
$ignore[] = 'thumb';
$config = cmsms()->GetConfig();
if (strpos($path,$config['uploads_path']) === FALSE)
$path = $config['uploads_path']."/".trim($path,"/");
$dh = @opendir($path);
while (false !== ($file = readdir($dh))) {
if (!in_array($file, $ignore)) {
if (!is_dir("$path/$file")) {
$fileinfo=pathinfo($path."/".$file);
if((strtolower($fileinfo['extension']) == "jpg"
or strtolower($fileinfo['extension']) == "jpeg"
or strtolower($fileinfo['extension']) == "gif"
or strtolower($fileinfo['extension']) == "png") and strpos($file,"thumb") === FALSE)
$dirTree["$path"][] = $file;
} else {
$dirTreeTemp = getGalleryTreeAsArray("$path/$file", $ignore);
if (is_array($dirTreeTemp))$dirTree = array_merge($dirTree, $dirTreeTemp);
}
}
}
closedir($dh);
return $dirTree;
}
}
$subdir = "";
if (isset($params['subdir'])) {
$subdir = "/".trim($params['subdir'],"/");
}
$dirTree = getGalleryTreeAsArray('/images/Gallery'.$subdir);
$gallerys = array();
foreach ($dirTree as $k => $v) {
$pfad = str_replace($config['uploads_path']."/images/Gallery/","",$k);
$gallerys[$pfad] = $pfad." (".count($v)." Fotos)";
}
ksort($gallerys);
$smarty->assign("galleryTreeArray",$gallerys);
$smarty->assign("galleryTreeTitel",implode($delimiter, $gallerys));
$smarty->assign("galleryTreePath",implode($delimiter, array_keys($gallerys)));
if ($params['action'] == "url")
return implode($delimiter, array_keys($gallerys));
else
return implode($delimiter, $gallerys);
}Eingebaut wird das wie folgt:
{* Dropdownfeld mit AdvancedContent erstellen *}
{AdvancedContent block="Gallery" label="Gallery" block_type="dropdown" allow_none=true items="Keine Gallery|:::getGalleryTree :::" values="|:::getGalleryTree action='url':::" smarty=true assign="gallerypath"}
{* Gallery anzeigen wenn eine Gallery ausgewählt wurde *}
{if $gallerypath != ""}{Gallery dir=$gallerypath}{/if}Im Dropdown werden nur Ordner angezeigt welche auch Bilder enthalten:
Soll nur ein bestimmter Teil der Gallery angezeigt werden, kann über den Parameter «subdir» der Pfad zum entsprechenden Unterordner angegeben werden:
{* Dropdownfeld mit AdvancedContent erstellen *}
{AdvancedContent block="Gallery" label="Gallery" block_type="dropdown" allow_none=true items="Keine Gallery|:::getGalleryTree subdir='pfad/zum/unterordner':::" values="|:::getGalleryTree action='url' subdir='pfad/zum/unterordner':::" smarty=true assign="gallerypath"}
Irgendwann diesen Frühling bin ich über das 
