content_image und Metadaten

Fragen zur Installation von CONTENIDO 4.9? Probleme bei der Konfiguration? Hinweise oder Fragen zur Entwicklung des Systemes oder zur Sicherheit?
Antworten
derju
Beiträge: 301
Registriert: Do 15. Jan 2009, 09:00
Kontaktdaten:

content_image und Metadaten

Beitrag von derju »

Hallo,

ich habe folgendes Problem:
ich benötige den Medianame des Bildes doch leider weiss ich nicht wie ich daran komme.

Mein Code:

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
 */

// 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]";

$imageSource10 = "CMS_IMG[1]";
$filesource   = str_replace($clientConfig["upl"]["htmlpath"], "", $imageSource10);

// 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]";
}

$slider_str_url = getEffectiveSetting('slider', 'strURL', 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);

	$aa = cApiImgScale($filename, 600, 600, false, false, 100);
	$img = str_replace($slider_str_url, '', $aa);
	
    list($imageWidth, $imageHeight, $imageTitle) = getimagesize($filename);
	$image = new stdClass();
	$image->src = cApiImgScale($img, 350, 233, true, 95);
    $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('get.tpl');

?>
Danke für den einen oder anderen Tipp.

LG - derJu
Contenido 4.8.20 | Contenido 4.9.12
homtata
Beiträge: 1145
Registriert: Mi 14. Jan 2004, 14:41
Kontaktdaten:

Re: content_image und Metadaten

Beitrag von homtata »

Ich habe dir mal einen etwas umfangreicheren Modulcode von mir eingedampft und hoffe, ich habe keinen zu großen Fehler beim Umschreiben reingehauen. Am Ende des Moduls hängt eine Funktion, die ein Objekt instanziert und die Metadaten zurückgibt und das neue Objekt dann noch mit weiteren Werten füllt, damit es dann an Smarty übergeben werden kann. In meiner Version steht diese Funktion aber nicht im Modul, sondern ausgelagert, damit ich sie in weiteren Modulen recht schnell einsetzen kann, weil das IMG[]-Dingens leider diese wichtigen Metainformationen nicht von Haus aus mitliefert, was eigentlich Käse ist ;-)

Code: Alles auswählen

<?php


// get image source and description from content type IMG with index 10 and 20
$imageSource = "CMS_IMG[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($imageSource10)) {
    $clientConfig = cRegistry::getClientConfig(cRegistry::getClientId());
    $filename   = str_replace($clientConfig["upl"]["htmlpath"], "", $imageSource);
	
	list($imageWidth, $imageHeight) = getimagesize($filename);

	$image = findUplMeta($filesource);
	$image->src = cApiImgScale($img, 350, 233, true, 95);
    $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('get.tpl');

function findUplMeta ($filesource) {
	// function expects an upload path, style: bilder/galerien/bild.jpg
	// will return an object that contains metatags, readable as $meta->get("medianame") etc.
	// Create a new OBJECT instance and return it so that it can be filles with other values in the main area
	global $lang;
	
	$newImgObj = new stdClass();
	
	$findimage = explode("/",$filesource);
	$imagename = array_pop($findimage); // finden und kürzen
	$imagepath = implode("/",$findimage) . "/";
	$getuplid = new cApiUpload();
	$getuplid->loadByMany( array("filename"=>$imagename, "dirname"=>$imagepath) );
	$meta = new cApiUploadMeta();
	$meta->loadByUploadIdAndLanguageId( $getuplid->get("idupl"), $lang );
	$newImgObj->medianame = $meta->get("medianame");
	$newImgObj->description = $meta->get('description');
	$newImgObj->copyright = "&copy; ".$meta->get('copyright');
	$newImgObj->keywords = $meta->get('keywords');
	$newImgObj->internal_description = $meta->get('internal_description');
	return $newImgObj;

}
?>
derju
Beiträge: 301
Registriert: Do 15. Jan 2009, 09:00
Kontaktdaten:

Re: content_image und Metadaten

Beitrag von derju »

Bei mir sieht das jetzt so aus, leider funktioniert es mit den Metadaten nicht:

Code: Alles auswählen

<?php


// get image source and description from content type IMG with index 10 and 20
$imageSource = "CMS_IMG[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]";
}

$slider_str_url = getEffectiveSetting('slider', 'strURL', 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"], "", $imageSource);
	
	$aa = cApiImgScale($filename, 600, 600, false, false, 100);
   $img = str_replace($slider_str_url, '', $aa);
   
   list($imageWidth, $imageHeight) = getimagesize($filename);

   $image = findUplMeta($imageSource);
   $image->src = cApiImgScale($img, 350, 233, true, 95);
    $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('get.tpl');

function findUplMeta ($imageSource) {
   // function expects an upload path, style: bilder/galerien/bild.jpg
   // will return an object that contains metatags, readable as $meta->get("medianame") etc.
   // Create a new OBJECT instance and return it so that it can be filles with other values in the main area
   global $lang;
   
   $newImgObj = new stdClass();
   
   $findimage = explode("/",$imageSource);
   $imagename = array_pop($findimage); // finden und kürzen
   $imagepath = implode("/",$findimage) . "/";
   $getuplid = new cApiUpload();
   $getuplid->loadByMany( array("filename"=>$imagename, "dirname"=>$imagepath) );
   $meta = new cApiUploadMeta();
   $meta->loadByUploadIdAndLanguageId( $getuplid->get("idupl"), $lang );
   $newImgObj->medianame = $meta->get("medianame");
   $newImgObj->description = $meta->get('description');
   $newImgObj->copyright = "&copy; ".$meta->get('copyright');
   $newImgObj->keywords = $meta->get('keywords');
   $newImgObj->internal_description = $meta->get('internal_description');
   return $newImgObj;

}
?>
So sieht der Code in der Smarty Ausgabe aus:

Code: Alles auswählen

<!-- content_image -->

{if 0 lt $label|strlen}
    <label class="content_type_label">{$label}</label>
{/if}

{$editor}

{if NULL neq $image}
	<h2>{$image->medianame}</h2>
<a href="/{$image->alt}" class="thumbnail">
    	<img src="{$image->src}" alt="{$image->medianame}" />
	</a>
{/if}

<!-- /content_image -->

LG - derJu
Contenido 4.8.20 | Contenido 4.9.12
homtata
Beiträge: 1145
Registriert: Mi 14. Jan 2004, 14:41
Kontaktdaten:

Re: content_image und Metadaten

Beitrag von homtata »

ich meine, dass nicht die richtige Variable in die Funktion übergeben wird und statt

Code: Alles auswählen

$image = findUplMeta($imageSource);
es bei dir eher

Code: Alles auswählen

$image = findUplMeta($filename);
heißen müsste.
Zur Not in der Funktion oder im Modul an sich mal Zeile für Zeile tracken, wann es das ganze zerschießt...
derju
Beiträge: 301
Registriert: Do 15. Jan 2009, 09:00
Kontaktdaten:

Re: content_image und Metadaten

Beitrag von derju »

Danke habe es soeben selbst gemerkt.

Danke für deine Hilfe!

LG - derJu
Contenido 4.8.20 | Contenido 4.9.12
Antworten