Hab da ne kleine Frage zum Modul. Ich habe das Teil für eine neue Site ein bisschen erweiteret. Nun kann man im gleichen Modul gleich 2 Headlines angeben die dann in Bilder umgewandelt werden, das funktioniert auch prima. (Der Grund warum ich nicht einfach eine mehrzeilige Headline benutzt habe, ist das die 2. Headline eine andere Farbe als die Erste haben soll).
Das Ganze funktioniert bis zum aktualisieren der headlines, wenn ich nämlich die Headlines update werden die gecachten Files nicht überschrieben, sprich bei der 1. Headline wird das alte Bild angezeigt (komischerweise funzts aber mit der 2. (hab das Gefühl das geschieht auch nur bei meiner Variante). Wenn ich nun das gecachte Bild per FTP lösche und die Seite neu lade, erscheint das Bild korrekt... aber das ist eher suboptimal
Code: Alles auswählen
if (!function_exists('renderHeadlineToImage')) {
function renderHeadlineToImage( &$rxmodule ) {
global $REX;
$rxmodule['headlinegfx'] = str_replace('"','"',$rxmodule['headline']);
$rxmodule['headlinegfx'] = str_replace('<br />','',$rxmodule['headlinegfx']);
$rxmodule['headlinegfx'] = str_replace("\r",'',$rxmodule['headlinegfx']);
$rxmodule['headlinegfx'] = mb_strtoupper($rxmodule['headlinegfx']);
$rxmodule['box'] = imagettfbbox($rxmodule['fontsize']*$rxmodule['multi'], 0, $rxmodule['fontpath'], $rxmodule['headlinegfx']);
if ( !$rxmodule['box'] ) {
$rxmodule['font'] = '?';
if ( $REX['REDAXO'] == '1' ) {
$rxmodule['errmess'] .= '<br /><font color="#cc0000">Achtung! Grafik konnte nicht erstellt werden! Evtl. ist der Font fehlerhaft.</font><br />';
}
return;
}
$rxmodule['bigwidth'] = abs($rxmodule['box'][2] - $rxmodule['box'][0]) + ($rxmodule['fontsize']/2) * $rxmodule['multi'] ;
$rxmodule['bigheight'] = abs($rxmodule['box'][7] - $rxmodule['box'][1]) + 6 * $rxmodule['multi'];
$rxmodule['bigxpos'] = abs(0 - $rxmodule['box'][0]) + 0 * $rxmodule['multi'];
$rxmodule['bigypos'] = $rxmodule['bigheight'] - abs($rxmodule['box'][1]) - 3 * $rxmodule['multi'];
$rxmodule['bigim'] = imagecreate( $rxmodule['bigwidth'], $rxmodule['bigheight'] );
$rxmodule['bgclr'] = imagecolorallocate( $rxmodule['bigim'], intval("0x". substr( $rxmodule['bgcolor'], 0, 2 ), 16), intval("0x". substr( $rxmodule['bgcolor'], 2, 2 ), 16), intval("0x". substr( $rxmodule['bgcolor'], 4, 2 ), 16 ));
$rxmodule['sclr'] = imagecolorallocate( $rxmodule['bigim'], intval("0x". substr( $rxmodule['shadowcolor'], 0, 2 ), 16), intval("0x". substr( $rxmodule['shadowcolor'], 2, 2 ), 16), intval("0x". substr( $rxmodule['shadowcolor'], 4, 2 ), 16 ));
$rxmodule['clr'] = imagecolorallocate( $rxmodule['bigim'], intval("0x". substr( $rxmodule['color'], 0, 2 ), 16), intval("0x". substr( $rxmodule['color'], 2, 2 ), 16), intval("0x". substr( $rxmodule['color'], 4, 2 ), 16 ));
if ( $rxmodule['shadowcolor'] <> '' ) {
imagettftext($rxmodule['bigim'], $rxmodule['fontsize']*$rxmodule['multi'], 0, $rxmodule['bigxpos']+$rxmodule['multi'], $rxmodule['bigypos']+$rxmodule['multi'], $rxmodule['sclr'], $rxmodule['fontpath'], $rxmodule['headlinegfx'] );
}
imagettftext($rxmodule['bigim'], $rxmodule['fontsize']*$rxmodule['multi'], 0, $rxmodule['bigxpos'], $rxmodule['bigypos'], $rxmodule['clr'], $rxmodule['fontpath'], $rxmodule['headlinegfx'] );
$rxmodule['width'] = $rxmodule['bigwidth'] / $rxmodule['multi'];
$rxmodule['height'] = $rxmodule['bigheight'] / $rxmodule['multi'];
if ( trim($rxmodule['maxwidth'])<>'' and $rxmodule['width']>$rxmodule['maxwidth'] ) {
$rxmodule['width'] = $rxmodule['maxwidth'];
if ( $REX['REDAXO'] == '1' ) {
$rxmodule['errmess'] .= '<br /><font color="#cc0000">Achtung! Text wird verzerrt dargestellt! Maximale Breite überschritten.</font><br />';
}
}
$rxmodule['im'] = imagecreatetruecolor( $rxmodule['width'], $rxmodule['height'] );
$rxmodule['bgclr2'] = imagecolorallocate( $rxmodule['im'], intval("0x". substr( $rxmodule['bgcolor'], 0, 2 ), 16), intval("0x". substr( $rxmodule['bgcolor'], 2, 2 ), 16), intval("0x". substr( $rxmodule['bgcolor'], 4, 2 ), 16 ));
imageFill($rxmodule['im'], 0, 0, $rxmodule['bgclr2']);
imagecopyresampled($rxmodule['im'],$rxmodule['bigim'],0,0,0,0,$rxmodule['width'], $rxmodule['height'],$rxmodule['bigwidth'], $rxmodule['bigheight']);
imagetruecolortopalette($rxmodule['im'], 0, 256);
imagepalettecopy($rxmodule['im'], $rxmodule['bigim']);
ImageColorTransparent($rxmodule['im'], $rxmodule['bgclr']);
@unlink($rxmodule['image']);
if ( $rxmodule['imagetype'] == 'png' ) {
imagepng( $rxmodule['im'], $rxmodule['image'] );
} else {
imagegif( $rxmodule['im'], $rxmodule['image'] );
}
imagedestroy( $rxmodule['bigim'] );
imagedestroy( $rxmodule['im'] );
$rxmodule['created'] = $rxmodule['imagetype'];
}
} // End function_exists
if (!function_exists('getRenderedHeadlineHtml')) {
function getRenderedHeadlineHtml( &$rxmodule, $secondHeader = "" ) {
global $REX;
$rxmodule['headlinealt'] = str_replace('"','"',trim($rxmodule['headline']));
$rxmodule['headlinealt'] = str_replace('<br />','',$rxmodule['headlinealt']);
$rxmodule['headlinealt'] = str_replace("\r",'',$rxmodule['headlinealt']);
$rxmodule['headlinealt'] = str_replace("\n",'',$rxmodule['headlinealt']);
$secondHeader = trim(htmlentities(mb_strtoupper($secondHeader), ENT_QUOTES, 'ISO-8859-15'));
if ( ($rxmodule['font'] <> '?') and file_exists($rxmodule['image']) ) {
list( $rxmodule['width'], $rxmodule['height'], $rxmodule['info'], $rxmodule['attr'] ) = getimagesize( $rxmodule['image'] );
if ( ($REX['REDAXO'] == '1') and ($rxmodule['width'] > 555 ) ) {
$rxmodule['errmess'] .= '<br /><font color="#006600">Grafik wird im Backend verzerrt oder abgeschnitten dargestellt!</font><br />';
$rxmodule['width'] = 555;
}
if ( $rxmodule['imagereplacement'] == 'phark' ) {
if ( $REX['REDAXO'] == '1' ) { $rxmodule['cssclass'] = ''; $rxmodule['headline'] = ''; } // im Backend nur Bild anzeigen
$rxmodule['html'] = "\n" . '<' . $rxmodule['headtag'];
$rxmodule['html'] .= ' title="' . $rxmodule['headlinealt'] . '"';
$rxmodule['html'] .= ' style="display:block;height:' . $rxmodule['height'] . 'px;';
$rxmodule['html'] .= 'background:url('.$rxmodule['image'].') no-repeat;';
$rxmodule['html'] .= $rxmodule['cssclass'] <> '' ? '"' : 'text-indent:-900px;"';
$rxmodule['html'] .= $rxmodule['cssclass'] <> '' ? ' class="'.$rxmodule['cssclass'].'">' : '>';
$rxmodule['html'] .= $rxmodule['headline'];
$rxmodule['html'] .= '</' . $rxmodule['headtag'] . '>' . "\n";
} else if ( $rxmodule['imagereplacement'] == 'dwyer' ) {
if ( $REX['REDAXO'] == '1' ) { $rxmodule['cssclass'] = ''; $rxmodule['headline'] = ''; } // im Backend nur Bild anzeigen
$rxmodule['html'] = "\n" . '<' . $rxmodule['headtag'];
$rxmodule['html'] .= ' title="' . $rxmodule['headlinealt'] . '"';
if($secondHeader!="")
{
$umlaute = array("Ä","ä","Ö","ö","Ü","ü","È","è","É","é");
$noUmlaute = true;
$noUmlaute2 = true;
foreach($umlaute as $key=>$val)
{
if(stristr($rxmodule['headlinealt'], $val) !== FALSE)$noUmlaute=false;
if(stristr($secondHeader, $val) !== FALSE)$noUmlaute2=false;
}
if($secondHeader!="Y")
{
if($noUmlaute && $noUmlaute2)
{
$rxmodule['html'] .= ' style="display:block;height:36px;';
}
elseif(!$noUmlaute2)
{
$rxmodule['html'] .= ' style="display:block;height:27px;';
}
else
{
$rxmodule['html'] .= ' style="display:block;height:36px;';
}
}
else
{
$rxmodule['html'] .= ($noUmlaute) ? ' style="display:block;height:27px;' : ' style="display:block;height:36px;';
}
}
else
{
$rxmodule['html'] .= ' style="display:block;height:36px;';
}
$rxmodule['headlinealt'] = htmlentities(mb_strtoupper($rxmodule['headlinealt']), ENT_QUOTES, 'ISO-8859-15');
if($secondHeader=="")$rxmodule['cssclass']="nosub";
$rxmodule['html'] .= 'background:url('.$rxmodule['image'].') bottom left no-repeat;"';
$rxmodule['html'] .= $rxmodule['cssclass'] <> '' ? ' class="'.$rxmodule['cssclass'].'">' : '>';
$rxmodule['html'] .= '<span';
$rxmodule['html'] .= ' style="display:block;width:0;height:0;overflow:hidden;"';
$rxmodule['html'] .= '>'.$rxmodule['headlinealt'];
$rxmodule['html'] .= '</span>';
$rxmodule['html'] .= '</' . $rxmodule['headtag'] . '>' . "\n";
} else {
if ( $REX['REDAXO'] == '1' ) { $rxmodule['cssclass'] = ''; } // im Backend nur Bild anzeigen
$rxmodule['html'] = "\n" . '<' . $rxmodule['headtag'];
if ( $rxmodule['cssclass'] == '' ) {
$rxmodule['html'] .= ' style="width:' . $rxmodule['width'] . 'px;height:' . $rxmodule['height'] . 'px;"';
}
$rxmodule['html'] .= $rxmodule['cssclass'] <> '' ? ' class="'.$rxmodule['cssclass'].'">' : '>';
$rxmodule['html'] .= $rxmodule['cssclass'] <> '' ? '<span>' : '<span style="display:none;">';
$rxmodule['html'] .= $rxmodule['headline'] . '</span>';
$rxmodule['html'] .= '<img src="' . $rxmodule['image'] . '" alt="' . $rxmodule['headlinealt'] . '" title="' . $rxmodule['headlinealt'] . '" width="' . $rxmodule['width'] . '" height="' . $rxmodule['height'] . '" />';
$rxmodule['html'] .= '</' . $rxmodule['headtag'] . '>' . "\n";
}
} else {
$rxmodule['html'] = "\n" . '<' . $rxmodule['headtag'];
$rxmodule['html'] .= $rxmodule['cssclass'] <> '' ? ' class="'.$rxmodule['cssclass'].'">' : '>';
$rxmodule['html'] .= $rxmodule['headline'] . '</' . $rxmodule['headtag'] . '>' . "\n";
}
return $rxmodule['html'];
}
} // End function_exists
/**
* Werte übernehmen
*/
unset($rxmodule);
$rxmodule[0]['imagetype'] = $rxmodule[1]['imagetype'] = 'gif'; // gif oder png
$rxmodule[0]['imagereplacement'] = $rxmodule[1]['imagereplacement'] = 'dwyer'; // leer/phark/dwyer
$rxmodule[0]['maxwidth'] = $rxmodule[1]['maxwidth'] = ''; // maximale Breite
$rxmodule[0]['multi'] = $rxmodule[1]['multi'] = 10; // Skalierungsfaktor für Grafikerstellung
// Standardwerte für grafische Headlines
$rxmodule[0]['h1'] = array('font'=>'','cssclass'=>'','fontsize'=>'22','color'=>'3f4e91','bgcolor'=>'ffffff','shadowcolor'=>'');
$rxmodule[1]['h2'] = array('font'=>'','cssclass'=>'','fontsize'=>'22','color'=>'989899','bgcolor'=>'ffffff','shadowcolor'=>'');
$rxmodule[0]['headtag'] = trim("h1");
$rxmodule[1]['headtag'] = trim("h2");
$rxmodule[0]['headline'] = rtrim("REX_VALUE[2]");
$rxmodule[1]['headline'] = rtrim("REX_VALUE[4]");
$rxmodule[0]['font'] = $rxmodule[1]['font'] = trim("LT_70051.TTF");
$rxmodule[0]['fontsize'] = $rxmodule[1]['fontsize'] = trim("22");
$rxmodule[0]['headlineid'] = trim("REX_VALUE[5]");
$rxmodule[1]['headlineid'] = trim("REX_VALUE[3]");
/* $rxmodule['color'] = trim("REX_VALUE[5]");
$rxmodule['bgcolor'] = trim("REX_VALUE[6]");
$rxmodule['cssclass'] = trim("REX_VALUE[8]");
$rxmodule['shadowcolor'] = trim("REX_VALUE[9]");*/
$rxmodule[0]['fontpath'] = $rxmodule[1]['fontpath'] = $REX['HTDOCS_PATH'] . 'files/' . $rxmodule[0]['font'];
$rxmodule[0]['image'] = $REX['HTDOCS_PATH'] . 'files/' . 'cache_resize___headline_' . REX_CATEGORY_ID . '_' . REX_ARTICLE_ID . '_' . $rxmodule[0]['headlineid'] . '_' . $REX['LANG'] . '.' . $rxmodule[0]['imagetype'];
$rxmodule[1]['image'] = $REX['HTDOCS_PATH'] . 'files/' . 'cache_resize___headline_' . REX_CATEGORY_ID . '_' . REX_ARTICLE_ID . '_' . $rxmodule[1]['headlineid'] . '_' . $REX['LANG'] . '.' . $rxmodule[1]['imagetype'];
if (strstr($rxmodule[0]['color'],'#')) $rxmodule[0]['color'] = str_replace('#','',$rxmodule[0]['color']);
if (strstr($rxmodule[1]['color'],'#')) $rxmodule[1]['color'] = str_replace('#','',$rxmodule[1]['color']);
if (strstr($rxmodule[0]['bgcolor'],'#')) $rxmodule[0]['bgcolor'] = str_replace('#','',$rxmodule[0]['bgcolor']);
if (strstr($rxmodule[1]['bgcolor'],'#')) $rxmodule[1]['bgcolor'] = str_replace('#','',$rxmodule[1]['bgcolor']);
if (strstr($rxmodule[0]['shadowcolor'],'#')) $rxmodule[0]['shadowcolor'] = str_replace('#','',$rxmodule[0]['shadowcolor']);
if (strstr($rxmodule[1]['shadowcolor'],'#')) $rxmodule[1]['shadowcolor'] = str_replace('#','',$rxmodule[1]['shadowcolor']);
// Standardwerte setzen
if ( ($rxmodule[0]['font'] == '') and isset($rxmodule[0][$rxmodule[0]['headtag']]['font']) ) {
$rxmodule[0]['font'] = $rxmodule[1]['font'] = $rxmodule['font'] = $rxmodule[0][$rxmodule[0]['headtag']]['font'];
}
if ( ($rxmodule[0]['fontsize'] == '') and isset($rxmodule[0][$rxmodule[0]['headtag']]['fontsize']) ) {
$rxmodule[0]['fontsize'] = $rxmodule[1]['fontsize'] = $rxmodule[0][$rxmodule[0]['headtag']][fontsize];
}
if ( ($rxmodule[0]['color'] == '') and isset($rxmodule[0][$rxmodule[0]['headtag']]['color']) ) {
$rxmodule[0]['color'] = $rxmodule[0][$rxmodule[0]['headtag']]['color'];
}
if ( ($rxmodule[1]['color'] == '') and isset($rxmodule[1][$rxmodule[1]['headtag']]['color']) ) {
$rxmodule[1]['color'] = $rxmodule[1][$rxmodule[1]['headtag']]['color'];
}
if ( ($rxmodule[0]['bgcolor'] == '') and isset($rxmodule[0][$rxmodule[0]['headtag']]['bgcolor']) ) {
$rxmodule[0]['bgcolor'] = $rxmodule[1]['bgcolor'] = $rxmodule[0][$rxmodule[0]['headtag']]['bgcolor'];
}
if ( ($rxmodule[0]['shadowcolor'] == '') and isset($rxmodule[0][$rxmodule[0]['headtag']]['shadowcolor']) ) {
$rxmodule[0]['shadowcolor'] = $rxmodule[1]['shadowcolor'] = $rxmodule[0][$rxmodule[0]['headtag']]['shadowcolor'];
}
/**
* GD-Lib prüfen
*/
if ( $rxmodule['font'] <> '?' ) {
$rxmodule['gdinfo'] = @gd_info();
if ( $REX['REDAXO'] == '1' ) {
if ( !$rxmodule['gdinfo'] ) {
$rxmodule['errmess'] .= '<br /><font color="#cc0000">GD-Lib Version kann nicht ermittelt werden! Evtl nicht installiert?</font><br />';
}
if ( !$rxmodule['gdinfo']['GIF Create Support'] and ($rxmodule['imagetype'] == 'gif') ) {
$rxmodule['errmess'] .= '<br /><font color="#cc0000">GD-Lib (Version: '.$rxmodule['gdinfo']['GD Version'].') unterstützt kein GIF</font><br />';
}
if ( !$rxmodule['gdinfo']['PNG Support'] and ($rxmodule['imagetype'] == 'png') ) {
$rxmodule['errmess'] .= '<br /><font color="#cc0000">GD-Lib (Version: '.$rxmodule['gdinfo']['GD Version'].') unterstützt kein PNG</font><br />';
}
if ( !$rxmodule['gdinfo']['FreeType Support'] ) {
$rxmodule['errmess'] .= '<br /><font color="#cc0000">GD-Lib (Version: '.$rxmodule['gdinfo']['GD Version'].') unterstützt kein Freetype</font><br />';
}
}
if ( !$rxmodule['gdinfo']
or ( !$rxmodule['gdinfo']['GIF Create Support'] and ($rxmodule['imagetype'] == 'gif') )
or ( !$rxmodule['gdinfo']['PNG Support'] and ($rxmodule['imagetype'] == 'png') )
or ( !$rxmodule['gdinfo']['FreeType Support'] ) ) {
$rxmodule['font'] = '?';
}
if (!function_exists('ImageGIF')) $rxmodule['imagetype'] = 'png';
}
/**
* Im Backend die Modulkonfiguration anzeigen
*/
/*if( ($REX['REDAXO'] == '1') and ($rxmodule['font'] <> '?') ) {
echo '<strong>Überschrift-Tag</strong>: ' . $rxmodule[0]['headtag'] . '<br />';
echo $rxmodule[0]['headline'] . '<br />';
echo '<strong>Überschrift-Tag</strong>: ' . $rxmodule[1]['headtag'] . '<br />';
echo $rxmodule[1]['headline'] . '<br />';
}
*/
/**
* Erstellung der Headline-Grafik
* Header-Grafik erstellen falls noch nicht vorhanden bzw. über ResizeImage-Addon gelöscht
*/
if ( ($rxmodule[0]['font'] <> '?') and file_exists($rxmodule[0]['fontpath']) and !file_exists($rxmodule[0]['image']) ) {
renderHeadlineToImage($rxmodule[0]);
}
if ( ($rxmodule[1]['font'] <> '?') and file_exists($rxmodule[1]['fontpath']) and !file_exists($rxmodule[1]['image']) ) {
renderHeadlineToImage($rxmodule[1]);
}
/**
* Ausgabe der Überschrift
*/
if($rxmodule[0]["headline"] !="")
{
getRenderedHeadlineHtml($rxmodule[0],$rxmodule[1]["headline"]);
if (($REX['REDAXO'] == '1') and $rxmodule['errmess']) {
echo $rxmodule['errmess'];
}
echo $rxmodule[0]['html'];
}
if($rxmodule[1]["headline"] !="")
{
getRenderedHeadlineHtml($rxmodule[1],'y');
if (($REX['REDAXO'] == '1') and $rxmodule['errmess']) {
echo $rxmodule['errmess'];
}
echo $rxmodule[1]['html'];
}
/**
* Debugging
*/
// echo "<pre>"; print_r($rxmodule); echo "</pre>";
?>