Illustrationsmodul mit alt- und title-Tag aus "Descript

Gesperrt
homtata
Beiträge: 1145
Registriert: Mi 14. Jan 2004, 14:41
Kontaktdaten:

Illustrationsmodul mit alt- und title-Tag aus "Descript

Beitrag von homtata »

Hallo,

nachdem ich keine ähnliche Umsetzung gefunden habe, hier eine Erweiterung des Illustrationsmoduls. Die Bilder zeigen dann statt "Illustration" einen alt- bzw. title-Tag an, der aus der "Description" bezogen wird, die im Dateimodul hinterlegt ist. Für einsprachige Projekte benutze ich diese Version recht häufig, da ich nicht - wie in anderen Umsetzungen - auf jeder Einzelseite in den Artikeleigenschaften erneut Bildbeschreibungen eingeben möchte.

Außerdem wird kein verwaister alt-Tag mehr angegeben, wenn in den Artikeleigenschaften kein Bild ausgewählt wurde; statt dessen erfolgt KEINERLEI Ausgabe. Somit kann das Modul auch in Templates eingesetzt werden, selbst wenn dann kein Bild zur Anzeige spezifiziert wird.
Die Bildgrößen-Variablen bitte noch jeweils selbst anpassen.

Der INPUT-Code entspricht dem Code des Original-"Illustration"-Modul, daher habe ich diesen hier nicht mehr gepostet.

Code: Alles auswählen

<?php
/***********************************************
* CONTENIDO MODUL - OUTPUT
*
* Modulname   :     Illustration
* Author(s)   :     Andreas Lindner, 4fb
* Copyright   :     Contenido - four for business, Andreas Lindner
* Created     :     12.08.2005
************************************************/

#Selected img directory
$cms_dirname = "CMS_VALUE[1]";
#Selected img
$cms_filename = "CMS_VALUE[2]";

#Default settings
$img_width = 460;
$img_height = 334;
$defaultImage = '';

$htmlpath = $cfgClient[$client]['path']['htmlpath'];
$frontendpath = $cfgClient[$client]['path']['frontend'];

$img_path = $htmlpath.$cfgClient[$client]['upload'].$defaultImage;
$img_path_fs = $frontendpath.$cfgClient[$client]['upload'].$defaultImage;

#Check configured images
if ($cms_dirname != '0' && $cms_filename != '0' && strlen($cms_dirname) > 0 && strlen($cms_filename) > 0) {
	$img_path = $htmlpath.$cfgClient[$client]['upload'].$cms_dirname.$cms_filename;
	$img_path_fs = $frontendpath.$cfgClient[$client]['upload'].$cms_dirname.$cms_filename;

	$img_split = preg_split("/\./", $cms_filename);
	$count = count($img_split);
	$type = $img_split[$count -1];

	if (!file_exists($img_path_fs)) {
		$img_path = $htmlpath.$cfgClient[$client]['upload'].$defaultImage;
		$img_path_fs = $frontendpath.$cfgClient[$client]['upload'].$defaultImage;
	}
}

#Scale image
$image = capiImgScale($img_path_fs, $img_width, $img_height, false, false, 10, false);

#Get dimensions of scaled image
list ($width, $height, $type, $attr) = getimagesize(str_replace($cfgClient[$client]["path"]["htmlpath"], $cfgClient[$client]["path"]["frontend"], $image));

#Output header with logo and illustration
$description = ig_getImageDescription($img_path);
if ($description=='') {
	$description = 'No description available';
   }

#Output image tag
if ($cms_filename != '' && $cms_filename != '0') {

echo '<div id="img_rechts"><img src="'.$img_path.'" width="'.$width.'" height="'.$height.'" alt="'.$description.'" title="'.$description.'"/></div>';
}

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 '';
	}
}

?>
Gesperrt