public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
cmsmadesimple-2-0 / plugins / modifier.summarize.php
100644 33 lines (27 sloc) 0.985 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
/**
* Smarty plugin
* ----------------------------------------------------------------
* Type: modifier
* Name: summarize
* Purpose: returns desired amount of words from the full string
* ideal for article text, etc.
* Auther: MarkS, AKA Skram, mark@mark-s.net /
* http://dev.cmsmadesimple.org/users/marks/
* ----------------------------------------------------------------
**/
function smarty_cms_modifier_summarize($string,$numwords='5',$etc='...'){
 
//=Put each word (any character or group of characters seperated by a space) into the field's array
$stringarray = explode(" ",$string);
 
//=While loop to add int ($numwords) words to the summary string ($returnstring)
$i = 0;
while($i < $numwords){
    $returnstring .= " ".$stringarray[$i];
    $i++;
}
 
//If set, the suffix (by default "...") will now be added to the summary ($returnstring)
$returnstring .= "...";
 
//Return the summary!
return $returnstring;
    
}//end of function
?>