Beschreibung: JavaScript basierende Bildergalerie mit Titel und Beschreibung für Bilder. Thumbnails werden von System automatisch generiert. Als Basis hat mir die Bildergalerie von Timo A. Hummel aus der Standard Contenido Version 4.6.x und und Lightbox JS gedient.
Code: Alles auswählen
<?php
cInclude("includes", "functions.api.images.php");
/* Gallery variables */
$bRecursive = false;
/* Input variables */
$iWidth = "CMS_VALUE[0]";
$iHeight = "CMS_VALUE[1]";
if ($iWidth == 0) {
$iWidth = 300;
}
if ($iHeight == 0) {
$iHeight = 300;
}
$iColumns = "CMS_VALUE[2]";
if ($iColumns == 0) {
$iColumns = 2;
}
$iRows = "CMS_VALUE[3]";
if ($iRows == 0) {
$iRows = 2;
}
$sPath = "CMS_VALUE[4]";
if ($sPath=='') {
$sPath = $cfgClient[$client]["path"]["frontend"] . $cfgClient[$client]["upl"]["frontendpath"] . "bildergalerie/";
} else {
$sPath = $cfgClient[$client]["path"]["frontend"] . $cfgClient[$client]["upl"]["frontendpath"] . "CMS_VALUE[4]";
}
$sort = "CMS_VALUE[5]";
if( $sort == "asc" ) {
$sort = SORT_ASC;
} else {
$sort = SORT_DESC;
}
$words = "CMS_VALUE[6]";
if (isset($start)) {
$iCurrentPage = $start;
} else {
$iCurrentPage = 1;
}
$aValidExtensions = array("jpg", "jpeg", "gif", "png");
$iImagesPerPage = $iRows * $iColumns;
/* Read all gallery files */
$aGalleryFiles = scanDirectory($sPath, $bRecursive);
array_multisort($aGalleryFiles, $sort, SORT_STRING);
if (is_array($aGalleryFiles)) {
/* Filter out non-images */
foreach ($aGalleryFiles as $key => $aGalleryFile) {
$sExtension = strtolower(getFileExtension($aGalleryFile));
if (!in_array($sExtension, $aValidExtensions)) {
unset($aGalleryFiles[$key]);
}
}
/* Calculate effective variables */
$iFileCount = count($aGalleryFiles);
$iPages = ceil($iFileCount / $iImagesPerPage);
$aImagesToDisplay = array_slice($aGalleryFiles, ($iCurrentPage - 1) * $iImagesPerPage, $iImagesPerPage);
$oImageTpl = new Template;
$oGalleryTpl = new Template;
$oEmptyImageTpl = new Template;
$aRenderedImages = array();
$iRow = 0;
$iImagesRendered = 0;
foreach ($aImagesToDisplay as $sImageToDisplay) {
/* Do Scaling */
$sScaledImage = cApiImgScale($sImageToDisplay, $iWidth, $iHeight);
$sScaledImage = str_replace($cfgClient[$client]["path"]["htmlpath"],"",$sScaledImage);
$link = str_replace($cfgClient[$client]['path']['frontend'],$cfgClient['htmlpath'],$sImageToDisplay);
$media_name = ig_getMedienName($sImageToDisplay);
$link_description = ig_getImageDescription($sImageToDisplay);
$description = htmlentities(capiStrTrimAfterWord($link_description, $words));
if( $media_name != "" && $link_description != "") {
$link_description = $media_name.': '.$link_description;
} elseif( $media_name != "" ) {
$link_description = $link_description;
} elseif( $description != "" ) {
$link_description = $link_description;
$media_name = " ";
}
$oImageTpl->reset();
$oImageTpl->set("s", "FILE", $sScaledImage);
$oImageTpl->set("s", "WIDTH", $iWidth);
$oImageTpl->set("s", "HEIGHT", $iHeight);
$oImageTpl->set("s", "LINK", $link);
$oImageTpl->set("s", "MEDIANAME", $media_name);
$oImageTpl->set("s", "DESCRIPTION", $description);
$oImageTpl->set("s", "LINKDESCRIPTION", $link_description);
$aRenderedImages[] = $oImageTpl->generate($cfgClient[$client]["path"]["frontend"] . "templates/lightbox-gallery_image.html", true, false);
$iImagesRendered++;
if ($iImagesRendered == $iColumns) {
$oGalleryTpl->set("d", "COLUMNS", implode("", $aRenderedImages));
$oGalleryTpl->next();
$iImagesRendered = 0;
$aRenderedImages = array();
}
}
if (count($aRenderedImages) < $iColumns && count($aRenderedImages) > 0) {
$iEmptyCells = $iColumns - count($aRenderedImages);
$oEmptyImageTpl->set("s", "WIDTH", $iWidth);
$oEmptyImageTpl->set("s", "HEIGHT", $iHeight);
$sEmptyCells = str_repeat($oEmptyImageTpl->generate($cfgClient[$client]["path"]["frontend"] . "templates/lightbox-gallery_empty.html", true, false),$iEmptyCells);
$oGalleryTpl->set("d", "COLUMNS", implode("", $aRenderedImages) . $sEmptyCells);
$oGalleryTpl->next();
}
$aLinks = array();
if ($iCurrentPage > 1) {
$oPreviousTpl = new Template;
$oPreviousTpl->set("s", "LINK", $cfgClient[$client]["path"]["htmlpath"] . sprintf("front_content.php?idcatart=%s&start=%s", $idcatart, $iCurrentPage - 1));
$oPreviousTpl->set("s", "TITLE", mi18n("Zurück"));
$aLinks[] = $oPreviousTpl->generate($cfgClient[$client]["path"]["frontend"] . "templates/lightbox-gallery_link.html", true, false);
}
if (($iCurrentPage < $iPages) && $iCurrentPage) {
$oNextTpl = new Template;
$oNextTpl->set("s", "LINK", $cfgClient[$client]["path"]["htmlpath"] . sprintf("front_content.php?idcatart=%s&start=%s", $idcatart, $iCurrentPage + 1));
$oNextTpl->set("s", "TITLE", mi18n("Vor"));
$aLinks[] = $oNextTpl->generate($cfgClient[$client]["path"]["frontend"] . "templates/lightbox-gallery_link.html", true, false);
}
$oGalleryTpl->set("s", "NAVIGATION", implode("", $aLinks));
$oGalleryTpl->generate($cfgClient[$client]["path"]["frontend"] . "templates/lightbox-gallery.html", false, false);
}
function ig_getImageDescription($idupl){
global $cfg, $cfgClient, $db, $client, $lang;
$cApiClient = new cApiClient($client);
$language_separator = $cApiClient->getProperty('language','separator');
if ($language_separator == "") {
//Sanity, if module used in client without set client setting
$language_separator = "§§§";
$cApiClient->setProperty('language','separator', $language_separator);
}
if(is_numeric($idupl)) {
//ID is a number
$query = "SELECT description FROM ".$cfg["tab"]["upl"]." WHERE idupl = ".$idupl;
} else {
//ID is a string
$path_parts = pathinfo($idupl);
$upload = $cfgClient[$client]['upl']['frontendpath'];
$len = strlen($upload);
$pos = strpos($idupl,$upload);
$dirname = substr($path_parts['dirname'],$pos+$len).'/';
$query = "SELECT description FROM ".$cfg["tab"]["upl"]." WHERE (dirname = '".$dirname."') AND (filename='".$path_parts['basename']."') AND (filetype='".$path_parts['extension']."')";
}
$db->query($query);
if($db->next_record()) {
return htmlspecialchars(urldecode($db->f("description")));
} else {
return '';
}
}
function ig_getMedienName($idupl) {
global $cfg, $cfgClient, $db, $client, $lang;
$cApiClient = new cApiClient($client);
$language_separator = $cApiClient->getProperty('language','separator');
if ($language_separator == "") {
//Sanity, if module used in client without set client setting
$language_separator = "§§§";
$cApiClient->setProperty('language','separator', $language_separator);
}
if( is_numeric($idupl) ) {
//ID is a number
$query = "SELECT description FROM ".$cfg["tab"]["upl"]." WHERE idupl = ".$idupl;
} else {
//ID is a string
$path_parts = pathinfo($idupl);
$upload = $cfgClient[$client]['upl']['frontendpath'];
$len = strlen($upload);
$pos = strpos($idupl,$upload);
$dirname = substr($path_parts['dirname'],$pos+$len).'/';
$danis = $dirname.$path_parts['basename'];
$query = "SELECT value FROM ".$cfg["tab"]["properties"]." WHERE itemid = '".$dirname.$path_parts['basename']."' AND name = 'medianame'";
}
$db->query($query);
if( $db->next_record() ) {
return htmlspecialchars(urldecode($db->f("value")));
} else {
return '';
}
}
?>
Ich denke du hast Recht, im Quelltext steht dann immer title="...Beschreibung.."
und da lässt sich mit eingefügten "br" im Text nicht viel machen.Ich komme aber mit der Vorgehensweise und den veieln Modul-Templates nicht klar. Immer wird irgendetwas zerschossen.
Gibt es vielleicht ein anderes Bildergallerie-Modul was die Textformatierung kann?