Ungetestet:
Code: Alles auswählen
<?php
/***********************************************
* CONTENIDO MODUL - OUTPUT
*
* Modulname : Illustration (specified by output)
* Author(s) : Andreas Lindner, 4fb, HerrB
* Copyright : Contenido - four for business, Andreas Lindner
* Created : 20.02.2007
************************************************/
cInclude("classes", "class.htmlelements.php");
cInclude("classes", "contenido/class.client.php");
$oClient = new cApiClient($client);
#Default settings
$img_width = 792;
$img_height = 211;
$sFallbackDirName = 'kopfbilder/';
$defaultImage = 'kopfbilder/test.jpg';
if ($edit) {
if ($_REQUEST["illustration_action"] == "save")
{
$oClient->setProperty("ModulIllustration", "dirname", $_REQUEST["selDirName"]);
$oClient->setProperty("ModulIllustration", "filename", $_REQUEST["selFileName"]);
} else {
#Selected img directory
$_REQUEST["selDirName"] = $oClient->getProperty("ModulIllustration", "dirname");
#Selected img
$_REQUEST["selFileName"] = $oClient->getProperty("ModulIllustration", "filename");
}
unset ($oClient); # Not needed anymore
# Check external data
if ($_REQUEST["selDirName"] == '' || $_REQUEST["selDirName"] == '0') {
$_REQUEST["selDirName"] = $sFallbackDirName;
}
#Choose image folder
echo '<form name="frmIllustration" method="post" action="'.$sess->url('front_content.php?area=con_editcontent&idart='.$idart.'&idcat='.$idcat.'&lang='.$lang.'&action=20').'"><table cellpadding="0" cellspacing="0" border="0">
<tr><td class="text_medium" style="padding:5px">'.mi18n("Das Bild soll folgende Größe haben: 792 x 211 px").'</td></tr>
<tr><td class="text_medium" style="padding:5px">'.mi18n("Bildverzeichnis wählen").': </td></tr>
<tr><td class="text_medium" style="padding:5px">';
$oSelDirName = new cHTMLSelectElement ("selDirName");
$oSelDirName->setStyle("width:200px");
$oOption = new cHTMLOptionElement(mi18n("Bitte wählen"), "0");
$oSelDirName->addOptionElement(0, $oOption);
#Get upload directories
$sql = "SELECT DISTINCT dirname
FROM ".$cfg["tab"]["upl"]."
WHERE
idclient='$client' AND
filetype IN ('jpeg','jpg','gif','png')
ORDER BY dirname";
$db->query($sql);
$i = 1;
while ($db->next_record())
{
$oOption = new cHTMLOptionElement(" ".$db->f('dirname'), $db->f('dirname'));
$oSelDirName->addOptionElement($i, $oOption);
$i++;
}
$oSelDirName->setDefault($_REQUEST["selDirName"]);
$oHidAction = new cHTMLHiddenField("illustration_action","save"); # Add action to know, when it is time to save changes
$oBtnSubmit = new cHTMLButton ("btnSubmit", mi18n("Save"));
echo $oSelDirName->render().$oHidAction->render().' ';
#Choose image file
echo '<input type="image" src="../contenido/images/submit.gif"></td><tr><td class="text_medium" style="padding:5px">'.mi18n("Bild wählen").': </td></tr>
<tr><td class="text_medium" style="padding:5px">';
$oSelFileName = new cHTMLSelectElement ("selFileName");
$oSelFileName->setStyle("width:200px");
$oOption = new cHTMLOptionElement(mi18n("Bitte wählen"), "0");
$oSelFileName->addOptionElement(0, $oOption);
if ($_REQUEST["selDirName"] != '0') {
#Get uploaded files
$sql = "SELECT filename
FROM ".$cfg["tab"]["upl"]."
WHERE
idclient = '$client' AND
filetype IN ('jpeg','jpg','gif','png','swf') AND
dirname = '".$_REQUEST["selDirName"]."'
ORDER BY filename";
$db->query($sql);
$i = 1;
while ($db->next_record())
{
$oOption = new cHTMLOptionElement(" ".$db->f('filename'), $db->f('filename'));
$oSelFileName->addOptionElement($i, $oOption);
$i++;
}
}
$oSelFileName->setDefault($_REQUEST["selFileName"]);
echo $oSelFileName->render().' ';
echo '<input type="image" src="../contenido/images/submit.gif"></td>';
#Preview image
if ($_REQUEST["selDirName"] != '0' AND $_REQUEST["selFileName"] != '0' AND strlen($_REQUEST["selDirName"]) > 0 AND strlen($_REQUEST["selFileName"]) > 0) {
$img_path = $cfgClient[$client]["upl"]["htmlpath"].$_REQUEST["selDirName"].$_REQUEST["selFileName"];
$img_split = preg_split("/\./", $_REQUEST["selFileName"]);
$count = count($img_split);
$type = $img_split[$count -1];
echo '<tr><td colspan="2" style="padding:5px"><img src="'.$img_path.'"></td></tr>';
}
echo '</td></tr>';
echo '</table></form>';
} else {
#Selected img directory
$cms_dirname = $oClient->getProperty("ModulIllustration", "dirname");
#Selected img
$cms_filename = $oClient->getProperty("ModulIllustration", "filename");
unset ($oClient); # Not needed anymore
$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' AND $cms_filename != '0' AND strlen($cms_dirname) > 0 AND 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($image);
#Output image tag
echo '<img src="'.$img_path.'" alt="Kopfbild" title="Kopfbild >';
}
?>
Zur Frage: Weil CMS_VAR/CMS_VALUE-Werte nur im Input behandelt werden.
Die gepostete Variante ermöglicht genu einen Wert für die Illustration - global, für alle Artikel, die dieses Modul einsetzen. Wenn man pro Bereich Grafiken festlegen möchte, muss man nur bei getProperty und setProperty dirname bzw. filename anpassen (also z.B. erster Bereich: dirname1, filename1, zweiter Bereich: dirname2, filename2). Natürlich benötigt man dann ein Modul pro Bereich.
Natürlich könnte man im Input ein Eingabefeld für die Bereichsnummer vorsehen (hier wieder CMS_VAR/CMS_VALUE) und diese im Output verwenden (dann braucht man nur ein Modul):
Beispiel für Output (zusätzlich):
Code: Alles auswählen
$iArea = "CMS_VALUE[1]";
$iArea = (int)$iArea;
...
... $oClient->getProperty("ModulIllustration", "dirname".$iArea);
... $oClient->getProperty("ModulIllustration", "filename".$iArea);
Gruß
HerrB