content_image Erweiterung

Alles rund um Module und Plugins in CONTENIDO 4.9.
Antworten
Firesteve
Beiträge: 52
Registriert: Sa 14. Nov 2009, 12:26
Wohnort: Sternenfels
Kontaktdaten:

content_image Erweiterung

Beitrag von Firesteve » Di 28. Jan 2014, 19:53

Hallo zusammen,

ich habe dem standard - Bildmodul "content_image" einen Konfigurations-input Bereich hinzugefügt.
In diesem lässt sich die Anzeigegröße des Bildes einstellen und ein template auswählen, das zur Anzeige verwendet werden soll.

Das ganze ist eher aus der Not heraus geboren, da ich über einigen Artikeln ein Bild anzeigen möchte, welches ich aber auch in anderen Bereichen in anderen Größen verwende.

Eventuell kann es ja einmal jemand brauchen, daher hier mal die Input / Output Codes:

Input:

Code: Alles auswählen

?>
<?php
/***********************************************
 * description: standard image
 *
 * @package Module
 * @subpackage ContentImage
 * @version SVN Revision $Rev:$
 *
 * @author marcus.gnass@4fb.de
 * @copyright four for business AG <www.4fb.de>
 * @license http://www.contenido.org/license/LIZENZ.txt
 * @link http://www.4fb.de
 * @link http://www.contenido.org
 * modify S. Schäfer 28.01.2014
 * aply input functions Image size
 * aply choose list for template
*/


// find Smarty-Templates which belong to THIS module by scanning the appropriate subdir
$mod = new cApiModule($cCurrentModule);
$tplpath = $cfgClient[$client]["path"]["frontend"]."data/modules/".$mod->get("alias")."/template/";
$tplFiles = scanDirectory($tplpath, $bRecursive);
array_multisort($tplFiles, "SORT_ASC", SORT_STRING);


$sSubmitLink     = '<a href="javascript: if (document.tplcfgform.send) {document.tplcfgform.send.value = 0}; document.tplcfgform.submit();"><img class="submitbutton" src="images/submit.gif" title="'.mi18n("Save changes").'" /></a>';

echo '<table>';
echo '<tr>';
echo '<tr><td colspan=2 style="border-left: 1px solid #999999; vertical-align: top;"><strong>'.mi18n("On image side relation 4:3:").'</strong></td></tr>';
echo '<td style="border-left: 1px solid #999999; vertical-align: top;">&nbsp;<strong>'.mi18n("biggest size of Image").':</strong></td>';
echo '<td><input size="5" type="text" name="CMS_VAR[60]" value="CMS_VALUE[60]"></input></td>';
echo '</tr>';
echo '<tr><td colspan=2 style="border-left: 1px solid #999999; border-bottom: 1px solid #999999; vertical-align: top;">'.mi18n("The image will automatic shown horizontal or vertically").'</td></tr>';
echo '<tr><td style="border-bottom: 1px solid #999999;vertical-align: top;">&nbsp;<strong>'.mi18n("or manual settings:").':</strong></td><td style="border-bottom: 1px solid #999999;">';
      if ("CMS_VALUE[70]" != "true") echo '<input type="checkbox" name="CMS_VAR[70]" value="true">&nbsp;&nbsp;&nbsp;&nbsp;'.$sSubmitLink; 
        else echo '<input type="checkbox" name="CMS_VAR[70]" value="true" checked>&nbsp;&nbsp;&nbsp;&nbsp;'.$sSubmitLink;
if (CMS_VALUE[70]) {
	echo '<tr>';
	echo '<td style="border-left: 1px solid #999999; border-bottom: 1px solid #999999; vertical-align: top;">&nbsp;<strong>'.mi18n("image width").':</strong></td>';
	echo '<td style="border-bottom: 1px solid #999999;"><input size="5" type="text" name="CMS_VAR[71]" value="CMS_VALUE[71]"></input></td>';
	echo '</tr>';
	echo '<tr>';
	echo '<td style="border-left: 1px solid #999999; border-bottom: 1px solid #999999; vertical-align: top;">&nbsp;<strong>'.mi18n("image height").':</strong></td>';
	echo '<td style="border-bottom: 1px solid #999999;"><input size="5" type="text" name="CMS_VAR[72]" value="CMS_VALUE[72]"></input></td>';
	echo '</tr>';
}
echo '<tr><td colspan=2 style="border-bottom: 1px solid #999999;">'.mi18n("On empty size-fields the Image will displayed with the original size!").'</td></tr>';

echo '<tr>';
echo '<td style="border-bottom: 1px solid #999999; vertical-align: top;">&nbsp;<strong>'.mi18n("choose template").'</strong></td>';
echo '<td style="border-bottom: 1px solid #999999;">';
echo '<select name="CMS_VAR[73]" value="CMS_VALUE[73]">';
echo '<option value="">'.mi18n("please_choose").'</option>';

foreach ($tplFiles AS $value) {
	$value = str_replace($tplpath, "", $value);
	if ($value == $choose) {
	  echo '<option selected">'.$value.'</option>';
	}
	else {
		echo '<option>'.$value.'</option>';
	}
}

	echo '</select>&nbsp;&nbsp;&nbsp;&nbsp;'.$sSubmitLink;
	echo '</td></tr>';
echo '<tr><td style="border-bottom: 1px solid #999999; vertical-align: top;"><strong>'.mi18n("Your actualy choose:").'</strong></td>';
echo '<td style="border-bottom: 1px solid #999999;"><strong>CMS_VALUE[73]</strong></td></tr>';

echo '<tr><td colspan=2 style="border-bottom: 1px solid #999999;">'.mi18n("If no template selected a standard template will be used!").'</td></tr>';

echo '</table>';

Output:

Code: Alles auswählen

<?php

/**
 * description: standard image
 *
 * @package Module
 * @subpackage ContentImage
 * @version SVN Revision $Rev:$
 *
 * @author marcus.gnass@4fb.de
 * @copyright four for business AG <www.4fb.de>
 * @license http://www.contenido.org/license/LIZENZ.txt
 * @link http://www.4fb.de
 * @link http://www.contenido.org
 * modify S. Schäfer 28.01.2014
 * aply input functions Image size
 * aply choose list for template
 */


// set $template or set a standard template if not choose 
$template = "CMS_VALUE[73]";
if ($template == "") {
	$template = 'get.tpl';
}


// assert framework initialization
defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');

// get image source from content type IMG with index 1
$imageSource = "CMS_IMG[1]";
// get description as content type IMGDESCR with index 1
$imageDescription = "CMS_IMGDESCR[1]";

// get editor as content type IMGEDITOR with index 1
// skip IMGEDITOR in frontend cause it displays the image too!
if (cRegistry::isBackendEditMode()) {
    $imageEditor = "CMS_IMGEDITOR[1]";
}

// build class containing all data necessary to display image
// therefor the image dimensions have to be determined
if (0 < strlen($imageSource)) {
    $clientConfig = cRegistry::getClientConfig(cRegistry::getClientId());
    $filename = str_replace($clientConfig["upl"]["htmlpath"], $clientConfig["upl"]["path"], $imageSource);
    list($imageWidth, $imageHeight) = getimagesize($filename);
	
	if ($imageWidth > 0) { // if image exists
		if ("CMS_VALUE[70]") { // if manual resize selected
			$imageWidth = "CMS_VALUE[71]"; //manual ImageWidth
			$imageHeight = "CMS_VALUE[72]"; //manual ImageHeight
		}
		else {
			if ("CMS_VALUE[60]") { //if exists a Value "ImageSize"
				if ($imageWidth > $imageHeight) {
					$imageWidth = "CMS_VALUE[60]";
					$imageHeight = ($imageWidth*0.75);
				}
				else {
					$imageHeight = "CMS_VALUE[60]";
					$imageWidth = ($imageHeight*0.75);
				}
			}
		}
	}//on empty resize fields in configuration will set the oiginal imagesize
	
	
    $image = new stdClass();
    $image->src = $imageSource;
    $image->alt = $imageDescription;
    $image->width = $imageWidth;
    $image->height = $imageHeight;
} else {
    $image = NULL;
}

// When in backend edit mode add a label so the author
// knows what to type in the shown field.
if (cRegistry::isBackendEditMode()) {
    $label = mi18n("LABEL_IMAGE");
} else {
    $label = NULL;
}

// use smarty template to output header text
$tpl = cSmartyFrontend::getInstance();
$tpl->assign('label', $label);
$tpl->assign('editor', $imageEditor);
$tpl->assign('image', $image);
$tpl->display($template);

?>
Hier noch der Übersetzungstext der lang_de.txt:

Code: Alles auswählen

If no template selected a standard template will be used!=Wenn kein Template ausgewählt wird, wird ein standard template verwendet.
LABEL_IMAGE=Bild
On empty size-fields the Image will displayed with the original size!=Wenn Sie keine Gr&ouml;&szlig;enangaben machen, wird das Bild in Originalgr&ouml;&szlig;e dargestellt.
On image side relation 4:3:=Bei Seitenverh&auml;ltnis 4:3
Save changes=
The image will automatic shown horizontal or vertically=Das Bild wird automatisch horizontal oder vertikal dargestellt!
Your actualy choose:=Ihre aktuelle Auswahl:
biggest size of Image=Gr&ouml;&szlig;tes Seitenma&szlig; des Bildes
choose template=Vorlage w&auml;hlen
image height=Bildhöhe
image width=Bildbreite
or manual settings:=oder manuelle Gr&ouml;&szlig;enangaben
please_choose=Bitte ausw&auml;hlen
Hier noch ein Bild der Konfigurationsseite:
content_image.JPG
content_image.JPG (68.38 KiB) 2560 mal betrachtet
Wie gesagt, falls es jemand brauchen sollte....
Zuletzt geändert von Firesteve am Mi 29. Jan 2014, 05:41, insgesamt 1-mal geändert.
Gruß Stefan
___________________________________________________________________
;-) Natürlich führe ich Selbstgespräche - Ich brauche schließlich auch mal einen Expertenrat
...... nicht ganz so ernstzunehmen ;-)

xmurrix
Beiträge: 3143
Registriert: Do 21. Okt 2004, 11:08
Wohnort: Augsburg
Kontaktdaten:

Re: content_image Erweiterung

Beitrag von xmurrix » Di 28. Jan 2014, 20:52

Danke für das Modul, sieht gut aus!
CONTENIDO Downloads: CONTENIDO 4.10.1
CONTENIDO Links: Dokumentationsportal, FAQ, API-Dokumentation
CONTENIDO @ Github: CONTENIDO 4.10 - Mit einem Entwicklungszweig (develop-branch), das viele Verbesserungen/Optimierungen erhalten hat und auf Stabilität und Kompatibilität mit PHP 8.0 bis 8.2 getrimmt wurde.

Firesteve
Beiträge: 52
Registriert: Sa 14. Nov 2009, 12:26
Wohnort: Sternenfels
Kontaktdaten:

Re: content_image Erweiterung

Beitrag von Firesteve » Mi 29. Jan 2014, 05:41

Ein kleiner Fehler hat sich nun doch eingeschlichen....

Im Outputbereich wird noch das falsche Standard Template gesetzt.

Bitte folgende Zeilen gleich am Anfang des Codes:

Code: Alles auswählen

// set $template or set a standard template if not choose
$template = "CMS_VALUE[73]";
if ($template == "") {
   $template = 'neu.tpl';
}
gegen folgende austauschen:

Code: Alles auswählen

// set $template or set a standard template if not choose
$template = "CMS_VALUE[73]";
if ($template == "") {
   $template = 'get.tpl';
}
Ansonsten wird das Modul vermutlich abbrechen, wenn es das Template nicht findet...

Werde das gleich aber auch im originalcode ändern...
Gruß Stefan
___________________________________________________________________
;-) Natürlich führe ich Selbstgespräche - Ich brauche schließlich auch mal einen Expertenrat
...... nicht ganz so ernstzunehmen ;-)

Antworten