I promised a new version of the "TagCloudInc" snippet.
Well, here it is:
/****************************************************<?
* Name: TagCloudInc
* Version 1.1
* Desc: Displays how frequently the members of a wordlist appear in the site's content in a "tag cloud"
* created by Paul Paulousek [email protected]
* date July, 21. 2006
* based on tagcloud of Marc Hinse, [email protected], www.modxcms.de
* Version: 1.1.
*
* Usage: [[TagCloudInc?parent=`1,3,5,6,7,14`&min=`3`&landing=`12`]]
* Parameters:
* parent: comma separated list of the folders that contain the documents which are to be counted
* min: Minimum occurrences of a word to be displayed
* landing: the id of your search result page. If you don¥t have one, create it like: [!FlexSearchForm?FSF_showResults=`1` &FSF_showForm=`0`!]
* (this is required for linking the tags)
* if a chunk named "cloudwords" exists, the snippet will take the content of it for building the cloud
* the chunk must contain a comma-separated list of words.
* ***************************************************/
$parent = isset($parent)? $parent : "0";
$min = isset($min)? $min : "2";
$landing = isset($landing)? $landing : "[~[*id*]~]";
$include = $modx->getChunk('cloudwords');
$include = explode(",",$include);
//try to get a Chunk for the include-words
if (sizeof($include)<2) {
$include = array('blog','method','edit','content','design','links','quickedit','MODx','customize');
//include list (sample, put in your words here)
}
//try to get a Chunk for the include-words
if (!isset($include)) {
$include = array('blog','method','edit','content','design','links','quickedit','MODx','customize');
}
//include list (sample, put in your words here)
$zeichen = array(',','.',':'); //array of chars to be deleted
if (strpos($parent,',')){
$parent= explode(',',$parent);
}
$table = $modx->getFullTableName("site_content");
foreach ($parent as $daddy){
$select = $modx->db->select("pagetitle,content,introtext", $table, "parent = $daddy"); // record: title, content, introtext
while ($contents = $modx->db->getRow($select)) {
$content.=$contents['content'].' '.$contents['introtext'].' '.$contents['pagetitle']; //put them together
}
}
$output='<div class="tagcloud">';
$content=strtolower(str_replace($zeichen,'',$modx->stripTags($content))); //all to lower and without HTML
$words=array();
foreach($include as $incword) {
$wert = substr_count($content,$incword);
if($wert>$min) { //look if the word counts the required minimum and is in the include list
$words[$incword] = $wert; //put them in a new array
}
}
//unset($words['modx']); //if you want to override the value of words (in this case 'modx'), uncomment it and put in your word
$max_size=max($words); //word with most hits
//$words['modx']=8; // put in again your deleted word and value from two lines above
ksort($words); //sort them alphabetically (just comment that out, then they will be unsortet
$multiplier=300/$max_size; //define the multiplier for the size (play with that to fit your site!)
$min_size=30; //minimum size
foreach($words as $key => $wert) {
$font_size=$multiplier*$wert;
//$countvalues='('.$wert.')'; //uncomment this for displaying the hits next to the links
$output.='<span><a style="font-size:'.max($font_size,$min_size).'%;" href="[~'.$landing.'~]&FSF_search='.$key.'">'.$key.'</a>'.$countvalues.'</span> ';
$output.="\r\n";
}
$output.='</div>';
return $output;
Changes:
The site-content is not exploded into an array anymore, substr_count is used instead.
The loop does not go thru all the words as in the previous version, but just thru the words in the include-list.
The include-list can also be stored in a chunk named "cloudwords" (as a comma separated list), so that you do not have to edit the snippet’s source if you want to change your include-list.
If you think it’s worth to be put into the repository, please do so yourself or just let me know.