diff options
author | friendica <info@friendica.com> | 2013-09-17 22:52:46 -0700 |
---|---|---|
committer | friendica <info@friendica.com> | 2013-09-17 22:52:46 -0700 |
commit | f7acc94bfedae6f23e0bc883541ca23132e95a06 (patch) | |
tree | 856b4828ff44ece7cb04a5881b57b269a06a86b8 /include/taxonomy.php | |
parent | d3aa31be4d84764e4d119343d8bc5eba5a84272b (diff) | |
download | volse-hubzilla-f7acc94bfedae6f23e0bc883541ca23132e95a06.tar.gz volse-hubzilla-f7acc94bfedae6f23e0bc883541ca23132e95a06.tar.bz2 volse-hubzilla-f7acc94bfedae6f23e0bc883541ca23132e95a06.zip |
provide the back-end for a directory tag cloud
Diffstat (limited to 'include/taxonomy.php')
-rw-r--r-- | include/taxonomy.php | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/include/taxonomy.php b/include/taxonomy.php index b6803743a..b8180f7c8 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -99,6 +99,7 @@ function format_term_for_display($term) { function tagadelic($uid, $count = 0, $authors = '', $flags = 0, $type = TERM_HASHTAG) { $sql_options = ''; + $count = intval($count); if($flags) $sql_options .= " and ((item_flags & " . intval($flags) . ") = " . intval($flags) . ") "; @@ -157,6 +158,47 @@ function tags_sort($a,$b) { } +function dir_tagadelic($count = 0) { + + $sql_options = ''; + $count = intval($count); + + // Fetch tags + $r = q("select xtag_term, count(xtag_term) as total from xtag + group by term order by total desc %s", + ((intval($count)) ? "limit $count" : '') + ); + + if(! $r) + return array(); + + // Find minimum and maximum log-count. + $tags = array(); + $min = 1e9; + $max = -1e9; + + $x = 0; + foreach($r as $rr) { + $tags[$x][0] = $rr['xtag_term']; + $tags[$x][1] = log($rr['total']); + $tags[$x][2] = 0; + $min = min($min,$tags[$x][1]); + $max = max($max,$tags[$x][1]); + $x ++; + } + + usort($tags,'tags_sort'); + + $range = max(.01, $max - $min) * 1.0001; + + for($x = 0; $x < count($tags); $x ++) { + $tags[$x][2] = 1 + floor(5 * ($tags[$x][1] - $min) / $range); + } + + return $tags; +} + + function tagblock($link,$uid,$count = 0,$authors = '',$flags = 0,$type = TERM_HASHTAG) { $o = ''; $tab = 0; @@ -172,6 +214,24 @@ function tagblock($link,$uid,$count = 0,$authors = '',$flags = 0,$type = TERM_HA return $o; } +function dir_tagblock($link,$r) { + $o = ''; + $tab = 0; + + if($r) { + $o = '<div class="dirtagblock widget"><h3>' . t('Keywords') . '</h3><div class="tags" align="center">'; + foreach($r as $rr) { + $o .= '<a href="'.$link .'/' . '?f=&keyword=' . urlencode($rr['term']).'" class="tag'.$rr['weight'].'">'.$rr['term'].'</a> ' . "\r\n"; + } + $o .= '</div></div>'; + } + return $o; +} + + + + + /** * verbs: [0] = first person singular, e.g. "I want", [1] = 3rd person singular, e.g. "Bill wants" |