Teasers in brief format

Gesperrt
geuxor
Beiträge: 7
Registriert: Do 25. Mai 2006, 21:46
Kontaktdaten:

Teasers in brief format

Beitrag von geuxor »

Hi Everyone, I hope you can assist me with a Module Request, although I don't speak german.

I am currently using a layout which contains apart from other things the following code

<!--start:content-->
<p style="margin-top: 0; margin-bottom: 0">
<container id="107" name="Mid Content" types="Content" mode="optional" default="">Content 1</container>
<!--end:content-->

I am then using a Template based on above layout and with a couple of teasers (using the teaser module). The teaser will point to a page called "Package"

However, when the page is displayed the teaser will also display everything within the above container. In my case I have added a picture together with some text, and it will show this where I have called the teaser, exactly as it shows in the "Package" page.

What I would like to do is to change the teaser module to abbreviate the data in the above container (picture and text) so when I use a Teaser to call for the Package page, it will show that in a different format. In other words, I would like it to be limited to e.g. 200 words and I would like the picture to be reduced to e.g. 120px. If possible it would be great to also have a "...more" link that would point to the page "Package".

In some way it will have the same effect as the News List Module, which abbreviates the text and reduces the picture to whatever specified. However, the News List uses a Html template which the Teaser module doesn't.

So would any of you have an idea of how we can change the coding for the Teaser Module in order to do this??

I would be greatful if you could help with this issue and hope you are able to understand what i mean.

I would appreciate your comments.
Thanks
Geuxor
xmurrix
Beiträge: 3215
Registriert: Do 21. Okt 2004, 11:08
Wohnort: Augsburg
Hat sich bedankt: 4 Mal
Danksagung erhalten: 17 Mal
Kontaktdaten:

Re: Teasers in brief format

Beitrag von xmurrix »

hi geuxor,

my english is not fluent, but i'll try to answer your request.
lets tackle it...

the teaser tries to fetch code between '<!--start:content-->' and '<!--end:content-->'

Code: Alles auswählen

...
// extract code between '<!--start:content-->' and '<!--end:content-->'
$startpos = strpos($code, "<!--start:content-->");
$endpos = strpos($code, "<!--end:content-->");
$difflen = $endpos - $startpos;

$sHtmlCode = substr($code, $startpos, $difflen);	
...
now you have the html code block including your image and text.

the next job is to extract image and the text from your code block

Code: Alles auswählen

...

// extract image data (same way like newslist)
$regEx = "/<img[^>]*?>.*?/i";
$match = array ();
preg_match($regEx, $sHtmlCode, $match);

$regEx = "/(src)(=)(['\"]?)([^\"']*)(['\"]?)/i";
$img = array ();
preg_match($regEx, $match[0], $img);
$img_src = preg_split("/\//", $img[0]);

$img_name  = $img_src[count($img_src) - 1];
$img_name  = preg_replace("/\"/", "", $img_name);
$img_split = preg_split("/\./", $img_name);
$img_type  = $img_split[count($img_split) - 1];


// set relative path to the image
// tip: print out content of $sRelPath to be shure you have the correct path to image
//      some provider dont allow open ressources using a network protocoll like http, 
//      therefore you should reference to a local file
$sRelPath = $img_src;

// default image dimentions
$iMaxWidth  = 120;
$iMaxHeight = 120;

// resize image using capiImgScale function, see 'contenido/includes/functions.api.images.php' (from line 489) for more details
$image = capiImgScale($sRelPath, $iMaxWidth, $iMaxHeight, false, false, 10, false);

// get dimensions of scaled image...
list ($width, $height, $type, $attr) = getimagesize($image);

// ...to compose a image tag 
$sTeaserImg = '<img src="'.$image.'" width="'.$width.'" height="'.$height.'" alt="" />';

// lets get content, here you have to strip all html tags, otherwhise you cannot abbreviate text
$sTeaserText = strip_tags($sHtmlCode);

// replace all waste white spaces
$sTeaserText = preg_replace('/\s\s+/', ' ', $sTeaserText);

// get max 200 words from text
$aText = explode(' ', $sTeaserText);
if (count($aText) > 200) {
	$aText = array_slice($aText, 0, 200);
}
$sTeaserText = implode(' ', $aText);


// process the anchor creation using one of following variables for it: $idcat, $idart, $idcatart or $idartlang
// example with idart, value of $idarttopage should be articleid of Package page
$sMoreLink = '<a href="front_content.php?idart='.$idarttopage.'" title="'.mi18n("more...").'">'.mi18n("more...").'</a>';
...

well, you have a image tag, teaser text and the more link, do whatever you want with them...

i hope i could help you, or i could at least direct you to a solution.


regards
xmurrix
geuxor
Beiträge: 7
Registriert: Do 25. Mai 2006, 21:46
Kontaktdaten:

Thanks....

Beitrag von geuxor »

Hi Xmurrix,

Thanks for you great help, it was definately useful and I love the scaling function...

I have changed it a bit as much as i could... im not the best at php so....., but here we go if anyone wants it...

Teaser Module - output changes :

....
..
.
$code2 = substr($code, $startpos, $difflen);
// echo $code2;

$sHtmlCode = substr($code, $startpos, $difflen);
//echo $sHtmlCode;

//////////////////////////// ********************* ////////////////////////


// extract image data (same way like newslist)
$regEx = "/<img[^>]*?>.*?/i";

$match = array ();

$imgg = preg_match($regEx, $sHtmlCode, $match);

$regEx = "/(src)(=)(['\"]?)([^\"']*)(['\"]?)/i";

$img = array ();
preg_match($regEx, $match[0], $img);
$img_src = preg_split("/\//", $img[0]);
$img_name = $img_src[count($img_src) - 1];
$img_name = preg_replace("/\"/", "", $img_name); //displays
//echo "image name is..$img_name"; //line 177

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

// set relative path to the image
// tip: print out content of $sRelPath to be shure you have the correct path to image
// some provider dont allow open ressources using a network protocoll like http,
// therefore you should reference to a local file

$sRelPath = $img_src;

//creating the complete path of image
$lastKey = sizeof($sRelPath) - 1;
for ($i = 0; $i < $lastKey; $i ++) {
$sWholePath .= $sRelPath[$i];
$sWholePath .= "/";
}

//echo "whole path is.. $sWholePath";

$sActualImg = "$sWholePath";
$sActualImg .= "$img_name";
//echo "actual image is..$sActualImg";

// default image dimentions
$iMaxWidth = 130;
$iMaxHeight = 90;

// get dimensions of scaled image...
$sActualImg2 = substr($sActualImg, 5);
//echo "actual img 2 is.. $sActualImg2";

// resize image using capiImgScale function, see 'contenido/includes/functions.api.images.php' (from line 489) for more details
$image = capiImgScale($sActualImg2, $iMaxWidth, $iMaxHeight, false, false, 10, false);
//echo $image;
list ($width, $height, $type, $attr) = getimagesize($image);

// ...to compose a rescaled image tag
$sTeaserImg = '<img src="'.$image.'" width="'.$width.'" height="'.$height.'" alt="" align=left class="teaser_img" border=0/>'; //src = img_name

echo $sTeaserImg;

// showing image without rescaling
//$sMyImg = '<img '.$sActualImg.'" width="'.$iMaxWidth.'" alt="" align=left class="teaser_img" border=0 />';
//echo $sMyImg;

// lets get content, here you have to strip all html tags, otherwhise you cannot abbreviate text
$sTeaserText = strip_tags($sHtmlCode);

// replace all waste white spaces
$sTeaserText = preg_replace('/\s\s+/', ' ', $sTeaserText);

// get max 50 words from text
$aText = explode(' ', $sTeaserText);
if (count($aText) > 50) {
$aText = array_slice($aText, 0, 50);
}
$sTeaserText = implode(' ', $aText);
echo "<p align=justify>";
echo $sTeaserText;
echo "...";
echo "</p>";

//echo "<br>";
//echo "idcat is $idcat";
//echo "idart is $idart";
// process the link creation using one of following variables for it: $idcat, $idart, $idcatart or $idartlang
// example with idart, value of $idarttopage should be articleid of Package page
//front_content.php?idcat=$selcat&idart=$article_id
//http://www.euroamerican.dk/cms/cms/fron ... 426&lang=2


$sMoreLink = '<a target="blank" href="front_content.php?idart='.$cms_artid.'&idcat='.$cms_catid.'&lang='.$lang.'" '; ////-- ??
$sMoreLink .= ' title="'.mi18n("more...").'">'.mi18n("more...").'</a>';

echo $sMoreLink;


//////////////////////////// ********************* ////////////////////////


} else {
echo "<!-- ERROR in module Article Include<pre>no code created for article to include!<br>idcat $cms_catid, idart $cms_artid, idlang $lang, idclient $client</pre>-->";
}
}
}
if ($cms_idcat) {
//echo "</div>";
}
?>
:)
Gesperrt