From f7acc94bfedae6f23e0bc883541ca23132e95a06 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 17 Sep 2013 22:52:46 -0700 Subject: provide the back-end for a directory tag cloud --- include/taxonomy.php | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'include') 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 = '

' . t('Keywords') . '

'; + foreach($r as $rr) { + $o .= ''.$rr['term'].' ' . "\r\n"; + } + $o .= '
'; + } + return $o; +} + + + + + /** * verbs: [0] = first person singular, e.g. "I want", [1] = 3rd person singular, e.g. "Bill wants" -- cgit v1.2.3