PHP Bildergalerie

matthiasschnueriger

Erfahrenes Mitglied
Moin moin.

Ich arbeite an einem Projekt mit dem CMS Contenido.
Bei der Anpassung eines Bildergalerie-Moduls, bin ich an meine Grenzen gestossen.

Und zwar funktioniert das Ganze so: Die Thumnails werden angezeigt, und bei einem Klick auf ein Thumbnail, erscheint das entsprechende Bild in Grossformat.
Was ich aber möchte ist, dass das Grossformatbild unter den Thumbails angezeigt wird, d.h. das alle anderen Thumbs auch bei der Grossformat-Ansicht sichtbar sind.

Am Ende meines Eintrags findet Ihr den Code. Das Template gallery_image.html steuert die Thumbnail-Seite an, das Template gallery_detail.html die Grossformat-Ansicht.

Wie kann das File jetzt anpassen, damit diese zwei Templates untereinander angezeigt werden?

Ich hoffe, dass ich mein Problem verständlich dargestellt habe!? :confused:

Grüsse Matthias

PHP:
<?php
/***********************************************
* Bildergalerie Output
*
* Author      :     Timo A. Hummel
* Copyright   :     four for business AG
* Created     :     30-09-2005
************************************************/

cInclude("includes", "functions.api.images.php");

/* Gallery variables */
$bRecursive = false;

$sPath = "CMS_VALUE[5]";
if ($sPath=='') {
	$sPath = $cfgClient[$client]["path"]["frontend"] ."upload/bildergalerie/";
}

$iRows = "CMS_VALUE[3]";

if ($iRows == 0)
{
  $iRows = 2;
}

$iColumns = "CMS_VALUE[2]";

if ($iColumns == 0)
{
  $iColumns = 2;
}

if (isset($start))
{
  $iCurrentPage = $start;
} else {
  $iCurrentPage = 1;
}

$iWidth = "CMS_VALUE[0]";
$iHeight = "CMS_VALUE[1]";

if ($iWidth == 0)
{
  $iWidth = 300;
}

if ($iHeight == 0)
{
  $iHeight = 300;
}

$iDetailWidth = "CMS_VALUE[4]";

if ($iDetailWidth == 0)
{
  $iDetailWidth = 300;
}

$aValidExtensions = array("jpg", "jpeg", "gif", "png");

$iImagesPerPage = $iRows * $iColumns;

if ($_REQUEST['view']=='') {
	/* Read all gallery files */
	$aGalleryFiles = scanDirectory($sPath, $bRecursive);
	
         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);
	
	  $link = 'front_content.php?idcatart='.$idcatart.'&amp;start='.$_REQUEST['start'].'&amp;view='.urlencode(str_replace($cfgClient[$client]['path']['frontend'],'',$sImageToDisplay));

	  $description = ig_getImageDescription($sImageToDisplay);
	  if ($description=='') {
	  	$description = '&nbsp;';
	  }
	  
	  $download_link = str_replace($cfgClient[$client]['path']['frontend'],$cfgClient[$client]['path']['htmlpath'],$sImageToDisplay);

	  $download_size = ig_GetReadableFileSize($sImageToDisplay);
	  	  	
	  $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", "DESCRIPTION", $description);
	  $oImageTpl->set("s", "DOWNLOAD_LINK", $download_link);
	  $oImageTpl->set("s", "DOWNLOAD_SIZE", $download_size);
	  $oImageTpl->set("s", "DOWNLOAD_CAPTION", mi18n("runter laden"));
	  $oImageTpl->set("s", "PREVIEW_CAPTION", mi18n("Bildvorschau"));
	  
	  $aRenderedImages[] = $oImageTpl->generate($cfgClient[$client]["path"]["frontend"] . "templates/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/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&amp;start=%s", $idcatart, $iCurrentPage - 1));
	  $oPreviousTpl->set("s", "TITLE", mi18n("Zurück"));
	  $aLinks[] = $oPreviousTpl->generate($cfgClient[$client]["path"]["frontend"] . "templates/gallery_link.html", true, false);
	}
	
	if ($iCurrentPage < $iPages)
	{
	  $oNextTpl = new Template;
	  $oNextTpl->set("s", "LINK", $cfgClient[$client]["path"]["htmlpath"] . sprintf("front_content.php?idcatart=%s&amp;start=%s", $idcatart, $iCurrentPage + 1));
	  $oNextTpl->set("s", "TITLE", mi18n("Vor"));
	  $aLinks[] = $oNextTpl->generate($cfgClient[$client]["path"]["frontend"] . "templates/gallery_link.html", true, false);
	}
	
	$oGalleryTpl->set("s", "NAVIGATION", implode("", $aLinks));
	
	$oGalleryTpl->generate($cfgClient[$client]["path"]["frontend"] . "templates/gallery.html", false, false);
    }
} else {
	$sImageToDisplay = $cfgClient[$client]['path']['frontend'].$_REQUEST['view'];
	$sScaledImage = cApiImgScale($sImageToDisplay, $iDetailWidth, 1000);

    $description = ig_getImageDescription($sImageToDisplay);
	if ($description=='') {
	  $description = '&nbsp;';
	}

    $download_link = str_replace($cfgClient[$client]['path']['frontend'],$cfgClient[$client]['path']['htmlpath'],$sImageToDisplay);

	$download_size = ig_GetReadableFileSize($sImageToDisplay);
	
	$oImageTpl = new Template;
	$oImageTpl->set("s", "IMG",$sScaledImage);
	$oImageTpl->set("s", "BACKLINK",'front_content.php?idcat='.$idcat.'&amp;idart='.$idart.'&amp;start='.$_REQUEST['start']);
	$oImageTpl->set("s", "BACKCAPTION",mi18n("Zurück"));
    $oImageTpl->set("s", "DESCRIPTION", $description);
    $oImageTpl->set("s", "DOWNLOAD_LINK", $download_link);
	$oImageTpl->set("s", "DOWNLOAD_SIZE", $download_size);
	$oImageTpl->set("s", "DOWNLOAD_CAPTION", mi18n("runter laden"));
	
	$oImageTpl->generate($cfgClient[$client]["path"]["frontend"] . "templates/gallery_detail.html", false, false);
}

function ig_getImageDescription($idupl){

	global $cfg, $cfgClient, $db, $client, $lang;
	
    $cApiClient = new cApiClient($client);
	$language_separator = $cApiClient->getProperty('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()){
		$arrDescriptions = explode($language_separator,htmlspecialchars(urldecode($db->f("description"))));
		if(count($arrDescriptions)==1){
			$retval=$arrDescriptions[0];
		}else{
			$t1 = $cfg['sql']['sqlprefix'].'_lang';
			$t2 = $cfg['sql']['sqlprefix'].'_clients_lang';
			$query = "SELECT ".$t1.".* FROM ".$t2." INNER JOIN ".$t1." ON ".$t1.".idlang = ".$t2.".idlang WHERE (".$t2.".idclient = 1) AND (".$t1.".active = 1) ORDER BY ".$t1.".idlang";
			echo $query;
		    $db->query($query);
			$i=0;
			$index=0;
		    while($db->next_record()){
				if($db->f("idlang")==$lang){
					$index=$i;
				}
				$i++;
			}
			if($index<count($arrDescriptions)){
				$retval=$arrDescriptions[$index];
			}else{
				$retval=$arrDescriptions[0];
			}
		}
		return htmlspecialchars(urldecode($retval));
	}else{
		return '';
	}
}

function ig_GetReadableFileSize($path) {
	$filesize = filesize($path);
	$unit = "bytes";
	
	if ($filesize > 1024) {
	$filesize = ($filesize / 1024);
	$unit = "kB"; }
	if ($filesize > 1024) {
	$filesize = ($filesize / 1024);
	$unit = "MB"; }
	if ($filesize > 1024) {
	$filesize = ($filesize / 1024);
	$unit = "GB"; }
	if ($filesize > 1024) {
	$filesize = ($filesize / 1024);
	$unit = "TB"; }
	
	$filesize = round($filesize, 0);
	return $filesize." ".$unit;
}
?>
 
Kann mir den niemand helfen? :confused:

Ich bin der Sache schon mal ein wenig näher gekommen.
Und zwar sieht das Ganze momentan so aus: Link

Das Problem ist der Link auf den Thumbnails, vermutlich liegt es in diesem Codeteil:
PHP:
/* Do Scaling */
	  $sScaledImage = cApiImgScale($sImageToDisplay, $iWidth, $iHeight);
	
	  $link = 'front_content.php?idcatart='.$idcatart.'&amp;start='.$_REQUEST['start'].'&amp;view='.urlencode(str_replace($cfgClient[$client]['path']['frontend'],'',$sImageToDisplay));

	  $description = ig_getImageDescription($sImageToDisplay);
	  if ($description=='') {
	  	$description = '&nbsp;';
	  }
	  
	  $_link = str_replace($cfgClient[$client]['path']['frontend'],$cfgClient[$client]['path']['htmlpath'],$sImageToDisplay);

Meine Ausgabe des grossen Bildes sieht so aus:
PHP:
echo '<table width=\"100%\"><tr><td width="'.$iDetailWidth.'">';
echo '<img src="'.$_link.'">';
echo '</td><td valign="top"><strong>';
echo ''.$download_size.'';
echo '</strong><br><br>';
echo ''.$description.'';
echo '</td></tr></table>';

Was muss ich machen, damit die Links funktionieren?
 
Zurück