anbei ein Vorschlag für die Erweiterung der Bildergalerie von Timo A. Hummel um die Sortierung.
In der Artikelkonfiguration kann jetzt die Reihenfolge der Bildanzeige ausgewählt werden.
Funktionsfähig für
*Dateiname*
*Medienname*
*Schluesselwoerter*
*Internenotiz*
Die Sortierung "Nach Beschreibung" ist noch nicht fertig, eine Vervollständigung der folgenden Funktion ist willkommen:
Code: Alles auswählen
function getDescription($filename) {
// beschreibung description $upload->get("description")
return "0";
}
Code: Alles auswählen
?><?php
/***********************************************
* Bildergalerie Input
*
* Author : Timo A. Hummel
* Copyright : four for business AG
* Created : 30-09-2005
************************************************/?>
<table>
<tr>
<td><?php echo mi18n("Breite");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[0]"; ?>" value="<?php echo "CMS_VALUE[0]"; ?>"></td>
</tr>
<tr>
<td><?php echo mi18n("H�he");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[1]"; ?>" value="<?php echo "CMS_VALUE[1]"; ?>"></td>
</tr>
<tr>
<td><?php echo mi18n("Spalten");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[2]"; ?>" value="<?php echo "CMS_VALUE[2]"; ?>"></td>
</tr>
<tr>
<td><?php echo mi18n("Zeilen");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[3]"; ?>" value="<?php echo "CMS_VALUE[3]"; ?>"></td>
</tr>
<tr>
<td><?php echo mi18n("Breite Detailansicht");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[4]"; ?>" value="<?php echo "CMS_VALUE[4]"; ?>"></td>
</tr>
<tr>
<td><?php echo mi18n("Breite Detailansicht");?></td>
<td>
<select name="<?php echo "CMS_VAR[6]"; ?>" value="<?php echo "CMS_VALUE[6]"; ?>">
<option value=Dateiname>Dateiname</option>
<option value=Medienname>Medienname</option>
<option value=Beschreibung>Beschreibung</option>
<option value=Schluesselwoerter>Schluesselwoerter</option>
<option value=Internenotiz>Internenotiz</option>
</select>
</td>
</tr>
<?php echo '<tr><td>'.mi18n("Verzeichnis ausw�hlen").'</td><td>
<select name="CMS_VAR[5]" size="1" style="width: 320px">
<option value="">Nichts ausgew�hlt</option>';
recursive_list($cfgClient[$client]["path"]["frontend"].$cfgClient[$client]["upload"], '->');
echo '</select></td></tr>';?>
</table>
<?php
#Build folder list recursively
function recursive_list($sPathDir, $sPrefix) {
$sSelected = "CMS_VALUE[5]";
$old_path = getcwd();
if (is_dir($sPathDir)) {
chdir($sPathDir);
$myhandle = opendir('.');
while (($mydir = readdir($myhandle)) !== false) {
if (($mydir != ".") && ($mydir != "..")) {
if (is_dir($mydir)) {
if ($sSelected == $sPathDir.$mydir.'/') {
echo '<option selected value="'.$sPathDir.$mydir.'/">'.$sPrefix.$mydir.'</option>';
} else {
echo '<option value="'.$sPathDir.$mydir.'/">'.$sPrefix.$mydir.'</option>';
}
recursive_list($sPathDir.$mydir."/", ' '.$sPrefix);
chdir($sPathDir);
}
}
}
closedir($myhandle);
}
chdir($old_path);
return;
}
Output:
Code: Alles auswählen
<?php
/***********************************************
* Bildergalerie Output
*
* Author : Timo A. Hummel
* Copyright : four for business AG
* Created : 30-09-2005
************************************************/
cInclude("includes", "functions.api.images.php");
cInclude("classes", "class.ui.php");
cInclude("classes", "class.htmlelements.php");
cInclude("classes", "class.properties.php");
cInclude("includes", "functions.upl.php");
$properties = new PropertyCollection;
$sortSelection = "CMS_VALUE[6]";
echo "sort by: " . $sortSelection . "<br>";
$abspfad = "/var/www/contenido/.../upload/";
/* 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]);
}
}
// sorting - start
$table = array ();
foreach ($aGalleryFiles as $cfilename) {
$zeile = array (
Dateiname => $cfilename,
Medienname => getMedianame($cfilename
), Beschreibung => getDescription($cfilename), Schluesselwoerter => getKeywords($cfilename), Internenotiz => getMedianotes($cfilename),);
array_push($table, $zeile);
}
/**
* perform the sorting here
*/
foreach ($table as $key => $row) {
$sfilename[$key] = $row['Dateiname'];
$smedianame[$key] = $row['Medienname'];
$sdescription[$key] = $row['Beschreibung'];
$skeywords[$key] = $row['Schluesselwoerter'];
$smedianotes[$key] = $row['Internenotiz'];
}
//printTable($table);
sort($aGalleryFiles);
switch ($sortSelection) {
case "Medienname" :
{
//echo "MEDIENNAME<BR>";
array_multisort($smedianame, SORT_STRING, $smedianame, SORT_STRING, $table);
break;
};
case "Beschreibung" :
{
//echo "DESCRIPTION<BR>";
array_multisort($sdescription, SORT_STRING, $sdescription, SORT_STRING, $table);
break;
};
case "Schluesselwoerter" :
{
//echo "KEYWORDS<BR>";
array_multisort($skeywords, SORT_STRING, $skeywords, SORT_STRING, $table);
break;
};
case "Internenotiz" :
{
//echo "INTERNENOTIZ<BR>";
array_multisort($smedianotes, SORT_STRING, $smedianotes, SORT_STRING, $table);
break;
};
}
/*
echo "<br>****************************<br>";
printTable($table);
echo "<br>****************************<br>";
*/
$aGa = array ();
foreach ($table as $key => $ra) {
array_push($aGa, $table[$key]['Dateiname']);
}
$aGalleryFiles = $aGa;
/*
foreach ($aGalleryFiles as $key => $k) {
echo "agallerie = " . $aGalleryFiles[$key] . "<br>";
}
*/
// sorting - end
/* 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 . '&start=' . $_REQUEST['start'] . '&view=' . urlencode(str_replace($cfgClient[$client]['path']['frontend'], '', $sImageToDisplay));
$description = ig_getImageDescription($sImageToDisplay);
//$array_des_pfades = explode("/",$sImageToDisplay);
//$bildname_pos = count($array_des_pfades)-1;
if ($description == '') {
$description = ' ';
}
$wname = str_replace($cfgClient[$client]["path"]["frontend"] . "upload/", "", $sImageToDisplay);
$img_title = getMedianotes($wname);
if ($img_title == '') {
$img_title = ' ';
}
$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", "IMG_TITLE", $img_title);
$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&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&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 {
$aGalleryFiles = scanDirectory($sPath, $bRecursive);
$path_all_images = $cfgClient[$client]["path"]["frontend"] . "upload/content/karten/";
$all_images = scanDirectory($path_all_images, true);
$i = 0;
/* Filter out non-images */
//foreach ($aGalleryFiles as $key => $aGalleryFile)
foreach ($all_images as $key => $aGalleryFile) {
$list_image = substr(strrchr($aGalleryFile, "/"), 1);
$current_image = substr(strrchr($_REQUEST['view'], "/"), 1);
if ($list_image == $current_image) {
//$next_image = $aGalleryFiles[$i+1];
$next_image = $all_images[$i +1];
//$previous_image = $aGalleryFiles[$i-1];
$previous_image = $all_images[$i -1];
}
$i++;
}
//if (empty($next_image)) {$next_image = $aGalleryFiles[0];}
//if (empty($previous_image)) {$previous_image=$aGalleryFiles[count($aGalleryFiles)-1];}
if (empty ($next_image)) {
$next_image = $all_images[0];
}
if (empty ($previous_image)) {
$previous_image = $all_images[count($all_images) - 1];
}
$sImageToDisplay = $cfgClient[$client]['path']['frontend'] . $_REQUEST['view'];
$file_path = stristr($sImageToDisplay, "upload");
$sScaledImage = cApiImgScale($sImageToDisplay, $iDetailWidth, 1000);
$description = ig_getImageDescription($sImageToDisplay);
if ($description == '') {
$description = ' ';
}
$download_link = str_replace($cfgClient[$client]['path']['frontend'], $cfgClient[$client]['path']['htmlpath'], $sImageToDisplay);
$download_size = ig_GetReadableFileSize($sImageToDisplay);
$image_size_array = getimagesize($file_path);
//erstellen des Templates gallery_detail
$oImageTpl = new Template;
$oImageTpl->set("s", "IMG", $sScaledImage);
$oImageTpl->set("s", "FILEPATH", $file_path);
$oImageTpl->set("s", "IMAGE_WIDTH", $image_size_array[0]);
$oImageTpl->set("s", "IMAGE_HEIGHT", $image_size_array[1]);
$oImageTpl->set("s", "BACKLINK", 'front_content.php?idcat=' . $idcat . '&idart=' . $idart . '&start=' . $_REQUEST['start']);
$oImageTpl->set("s", "BACKCAPTION", mi18n("Zur Galerie"));
$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("Download"));
$oImageTpl->set("s", "IMAGE_NEXT_LINK", 'front_content.php?idcat=' . $idcat . '&idart=' . $idart . '&view=' . urlencode(str_replace($cfgClient[$client]['path']['frontend'], '', $next_image)));
$oImageTpl->set("s", "IMAGE_PREVIOUS_LINK", 'front_content.php?idcat=' . $idcat . '&idart=' . $idart . '&view=' . urlencode(str_replace($cfgClient[$client]['path']['frontend'], '', $previous_image)));
$oImageTpl->set("s", "IMAGE_NEXT", mi18n("Bild vor >>"));
$oImageTpl->set("s", "IMAGE_PREVIOUS", mi18n("<< Bild zurueck"));
$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()) {
return htmlspecialchars(urldecode($db->f("description")));
} 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;
}
// sorting - functions:
function printTable($tableentire) {
foreach ($tableentire as $tempone) {
foreach ($tempone as $key => $temptwo) {
echo "$key: $temptwo", "<br>";
}
echo "<br>";
}
}
function getKeywords($wname) {
//schluesselwoerter keywords $keywords
global $properties, $abspfad;
$xx = str_replace($abspfad, "", $wname);
$keywords = $properties->getValue("upload", $xx, "file", "keywords");
return $keywords;
}
function getMedianame($wname) {
global $properties, $abspfad;
$xx = str_replace($abspfad, "", $wname);
$medianame = $properties->getValue("upload", $xx, "file", "medianame");
return $medianame;
}
function getMedianotes($wname) {
//internenotiz medianotes $medianotes
global $properties,$abspfad;
$xx = str_replace($abspfad, "", $wname);
$medianotes = $properties->getValue("upload", $xx, "file", "medianotes");
return $medianotes;
}
function getDescription($filename) {
// beschreibung description $upload->get("description")
return "0";
}
?>