Hello,
i’ve adapted an existing Snippet who can generate tag cloud in order to let it generate html for wp cumulus.
I will not show my Work in progress website since it’s currently not close to be finished but i can give you the original creator website so you can view what cumulus is:
http://www.roytanck.com/2009/01/15/assorted-wp-cumulus-news/
It’s the flash tag cloud on the sidebar!
First you need to download the cumulus plugin from the wordpress website:
http://wordpress.org/extend/plugins/wp-cumulus/
take the file called tagcloud.swf and put in a directory on your website, the default one is: assets/flash/
Or you can modify two line on the snippets:
# Set flash path
$flashPath = "assets/flash/";
$movie = $flashPath.’tagcloud.swf’;
The snippet in question, create a new Snippet, call it cumulus and paste the code below:
<?php
/* Passed parameter */
$parent = isset ($parent) ? $parent : "0";
$depth = isset ($depth) ? $depth : 10;
$days = isset ($days) ? $days : 0;
$min = isset ($min) ? $min : "0";
$landing = isset ($landing) ? $landing : "[~[*id*]~]";
$tvTags = isset ($tvTags) ? $tvTags : 'tags';
$tagDelim = isset ($tagDelim) ? $tagDelim : ',';
$caseSensitive = isset ($caseSensitive) ? $caseSensitive : 0;
$limit = isset ($limit) ? $limit : 0;
$height = isset($height) ? $height : '300';
$width = isset($width) ? $width : '400';
$tcolor = isset($tcolor) ? $tcolor : '363636';
$tcolor2 = isset($tcolor2) ? $tcolor2 : '363636';
$hicolor = isset($hicolor) ? $hicolor : '363636';
$bgcolor = isset($bgcolor) ? $bgcolor : 'ededed';
$speed = isset($speed) ? $speed : '100';
$distr = isset($distr) ? $distr : 'true';
$wmode = isset($wmode) ? $wmode : false;
# Set flash path
$flashPath = "assets/flash/";
$movie = $flashPath.'tagcloud.swf';
/* -------------------------------- Functions -------------------------------- */
/* ---------------- getTags ---------------- */
if (!function_exists('getTags')) {
function getTags($cIDs, $tvTags, $days) {
global $modx, $parent;
$docTags = array ();
$baspath= $modx->config["base_path"] . "manager/includes";
include_once $baspath . "/tmplvars.format.inc.php";
include_once $baspath . "/tmplvars.commands.inc.php";
if ($days > 0) {
$pub_date = mktime() - $days*24*60*60;
} else {
$pub_date = 0;
}
$tb1 = $modx->getFullTableName("site_tmplvar_contentvalues");
$tb2 = $modx->getFullTableName("site_tmplvars");
$tb_content = $modx->getFullTableName("site_content");
$query = "SELECT stv.name,stc.tmplvarid,stc.contentid,stv.type,stv.display,stv.display_params,stc.value";
$query .= " FROM ".$tb1." stc LEFT JOIN ".$tb2." stv ON stv.id=stc.tmplvarid ";
$query .= " LEFT JOIN $tb_content tb_content ON stc.contentid=tb_content.id ";
$query .= " WHERE stv.name='".$tvTags."' AND stc.contentid IN (".implode($cIDs,",").") ";
$query .= " AND tb_content.pub_date >= '$pub_date' ";
$query .= " AND tb_content.published = 1 ";
$query .= " ORDER BY stc.contentid ASC;";
$rs = $modx->db->query($query);
$tot = $modx->db->getRecordCount($rs);
$resourceArray = array();
for($i=0;$i<$tot;$i++) {
$row = @$modx->fetchRow($rs);
$docTags[$row['contentid']]['tags'] = getTVDisplayFormat($row['name'], $row['value'], $row['display'], $row['display_params'], $row['type'],$row['contentid']);
}
if ($tot != count($cIDs)) {
$query = "SELECT name,type,display,display_params,default_text";
$query .= " FROM $tb2";
$query .= " WHERE name='".$tvTags."' LIMIT 1";
$rs = $modx->db->query($query);
$row = @$modx->fetchRow($rs);
$defaultOutput = getTVDisplayFormat($row['name'], $row['default_text'], $row['display'], $row['display_params'], $row['type'],$row['contentid']);
foreach ($cIDs as $id) {
if (!isset($docTags[$id]['tags'])) {
$docTags[$id]['tags'] = $defaultOutput;
}
}
}
return $docTags;
}
}
// Get the subentities of the supplied parent
$parents = explode(',',$parent);
$subEntities = $parents;
foreach ($parents as $parentDoc) {
$subDocs = $modx->getChildIds($parentDoc, $depth);
$subEntities = array_merge($subDocs,$subEntities);
}
$docTags = getTags(array_unique($subEntities), $tvTags, $days);
// docTags now contains an array indexed by docId, with each value containing an array of tags, e.g.:
// go through each document, split the works into an array, and add them to a
// master array with the word as the key, and a value containing an array consisting of count and style name
$tags = array();
$tag_count = 0;
foreach ($docTags as $n => $v) {
if (is_array($v)){ // We should have an array containing only one key (tags)
$this_tags = explode($tagDelim,$v['tags']); // Split it by the tag delimiter
foreach ($this_tags as $tag) { // Each of the new found tags
$tag = trim($tag); // Remove any whitespace
$tag = ($caseSensitive) ? $tag : strtolower($tag); // If not case sensitive, lower-case it
if ($tag != '') { // if its not empty after all this
$tag_count++;
if (isset($tags[$tag]['count'])) { // if we've already met this tag, increment its counter
$tags[$tag]['count']++;
} else { // Otherwise create a counter for it
$tags[$tag]['count'] = 1;
}
}
}
}
}
$count = $value['count'];
$countvalues = '(' . $count . ')';
$this_style = $value['style'];
$tag = trim($tag);
$tagString = '';
foreach ($tags as $tag => $value) {
$url_amp = $modx->config['xhtml_urls']?'&':'&';
$query_string_seperator = ($modx->config['friendly_urls'])?'?':$url_amp;
$tagString .= '<a href="[~' . $landing .'~]'. $query_string_seperator . 'tags=' . urlencode($tag) . '&start=0" style="16" rel="tag" title="' . $tag . $countvalues . '">' . $tag . '</a>';
}
ob_start();
?>
<div id="cumulus">Veuillez installer Flash Player.</div>
<script type="text/javascript">
$(document).ready(function(){
var rnumber = Math.floor(Math.random()*9999999);
$('#cumulus').flash(
{
src: '<?php echo $movie; ?>?r='+rnumber,
width: <?php echo $width; ?>,
height: <?php echo $height; ?>,
<?php if($wmode == false){
echo 'bgcolor: "#'. $bgcolor .'",'."\r"; } else { echo 'wmode: "'. $wmode .'",'."\r"; } ?>
allowScriptAccess: 'always',
flashvars: {
tcolor: '0x<?php echo $tcolor; ?>',
tcolor2: '0x<?php echo ($tcolor2 == "" ? $tcolor : $tcolor2); ?>',
hicolor: '0x<?php echo ($hicolor == "" ? $tcolor : $hicolor); ?>',
mode: 'tags',
distr: '<?php echo $distr; ?>',
tspeed: '<?php echo $speed; ?>',
tagcloud: '<tags><?php echo $tagString; ?></tags>'
}
},
{ version: 8 }
);
});
</script>
<?php
$output = ob_get_contents();
ob_end_clean();
return $output;
?>
And here a sampler code for the snippet call:
[!cumulus? &tvTags=`
TV Tags` &tagDelim=`
tag delimiter set in your tv ` &bgcolor=`
The background color` &width=`220` &height=`150` &tcolor=`
Text color` &tcolor2=`
Second text color, not working for the moment` &hicolor=`
Hover text and border color`!]
Note:
1 - The snippet need jquery and jquery flash plugin
http://jquery.lukelutman.com/plugins/flash/example-flashvars.html as you can see the snippet code.
Since i use jquery on all my websites, i do not provide an option to load it from the snippet.
2 - I’ve tested it first with the original example and it work great with swfobject too.
3 - As you can see, the code is absolutely not cleaned from the original tag cloud snippet. It was for testing purpose so i can’t finish it atm.