diff options
author | redmatrix <git@macgirvin.com> | 2016-05-04 19:39:39 -0700 |
---|---|---|
committer | redmatrix <git@macgirvin.com> | 2016-05-04 19:39:39 -0700 |
commit | 9eac9ef2b94533c7dbec3c13b1374a96bc88e4de (patch) | |
tree | 840987beb6c945c29e5cd448b54cbfc98dc05ad7 /Zotlabs/Text | |
parent | 566667a263abd6f4b2a8a24579323e65d0016d7c (diff) | |
download | volse-hubzilla-9eac9ef2b94533c7dbec3c13b1374a96bc88e4de.tar.gz volse-hubzilla-9eac9ef2b94533c7dbec3c13b1374a96bc88e4de.tar.bz2 volse-hubzilla-9eac9ef2b94533c7dbec3c13b1374a96bc88e4de.zip |
isolate all the tagadelic core code into a class and reuse it
Diffstat (limited to 'Zotlabs/Text')
-rw-r--r-- | Zotlabs/Text/Tagadelic.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Zotlabs/Text/Tagadelic.php b/Zotlabs/Text/Tagadelic.php new file mode 100644 index 000000000..55ecf2d75 --- /dev/null +++ b/Zotlabs/Text/Tagadelic.php @@ -0,0 +1,44 @@ +<?php + +namespace Zotlabs\Text; + + +class Tagadelic { + + static public function calc($arr) { + + $tags = array(); + $min = 1e9; + $max = -1e9; + + $x = 0; + if(! $arr) + return array(); + + foreach($arr as $rr) { + $tags[$x][0] = $rr['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,'self::tags_sort'); + + $range = max(.01, $max - $min) * 1.0001; + + for($x = 0; $x < count($tags); $x ++) { + $tags[$x][2] = 1 + floor(9 * ($tags[$x][1] - $min) / $range); + } + + return $tags; + } + + static public function tags_sort($a,$b) { + if(strtolower($a[0]) == strtolower($b[0])) + return 0; + return((strtolower($a[0]) < strtolower($b[0])) ? -1 : 1); + } + +}
\ No newline at end of file |