diff options
author | redmatrix <git@macgirvin.com> | 2016-05-04 18:27:46 -0700 |
---|---|---|
committer | redmatrix <git@macgirvin.com> | 2016-05-04 18:27:46 -0700 |
commit | 566667a263abd6f4b2a8a24579323e65d0016d7c (patch) | |
tree | 674b4a64548d930bc80ba60876f122ffa3f2d5f4 | |
parent | 1b6bc5394b7cf8435928eaa2ace4e321f517ecb6 (diff) | |
download | volse-hubzilla-566667a263abd6f4b2a8a24579323e65d0016d7c.tar.gz volse-hubzilla-566667a263abd6f4b2a8a24579323e65d0016d7c.tar.bz2 volse-hubzilla-566667a263abd6f4b2a8a24579323e65d0016d7c.zip |
provide a tag cloud for app categories and allow filtering apps from this
-rw-r--r-- | Zotlabs/Module/Apps.php | 3 | ||||
-rw-r--r-- | include/apps.php | 19 | ||||
-rw-r--r-- | include/taxonomy.php | 69 | ||||
-rw-r--r-- | include/widgets.php | 7 | ||||
-rw-r--r-- | view/pdl/mod_apps.pdl | 1 | ||||
-rwxr-xr-x | view/tpl/myapps.tpl | 2 |
6 files changed, 98 insertions, 3 deletions
diff --git a/Zotlabs/Module/Apps.php b/Zotlabs/Module/Apps.php index ea6ab1913..33259b319 100644 --- a/Zotlabs/Module/Apps.php +++ b/Zotlabs/Module/Apps.php @@ -21,7 +21,7 @@ class Apps extends \Zotlabs\Web\Controller { if(local_channel()) { import_system_apps(); $syslist = array(); - $list = app_list(local_channel()); + $list = app_list(local_channel(), false, $_GET['cat']); if($list) { foreach($list as $x) { $syslist[] = app_encode($x); @@ -42,6 +42,7 @@ class Apps extends \Zotlabs\Web\Controller { return replace_macros(get_markup_template('myapps.tpl'), array( '$sitename' => get_config('system','sitename'), + '$cat' => ((array_key_exists('cat',$_GET) && $_GET['cat']) ? ' - ' . escape_tags($_GET['cat']) : ''), '$title' => t('Apps'), '$apps' => $apps, )); diff --git a/include/apps.php b/include/apps.php index b3d0c954e..7439be6d4 100644 --- a/include/apps.php +++ b/include/apps.php @@ -370,12 +370,29 @@ function app_installed($uid,$app) { } -function app_list($uid, $deleted = false) { +function app_list($uid, $deleted = false, $cat = '') { if($deleted) $sql_extra = " and app_deleted = 1 "; else $sql_extra = " and app_deleted = 0 "; + if($cat) { + $r = q("select oid from term where otype = %d and term = '%s'", + intval(TERM_OBJ_APP), + dbesc($cat) + ); + if(! $r) + return $r; + $sql_extra .= " and app.id in ( "; + $s = ''; + foreach($r as $rr) { + if($s) + $s .= ','; + $s .= intval($rr['oid']); + } + $sql_extra .= $s . ') '; + } + $r = q("select * from app where app_channel = %d $sql_extra order by app_name asc", intval($uid) ); diff --git a/include/taxonomy.php b/include/taxonomy.php index 71ed6e91d..cc83f0605 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -183,6 +183,10 @@ function tagadelic($uid, $count = 0, $authors = '', $owner = '', $flags = 0, $re } + + + + function tags_sort($a,$b) { if(strtolower($a[0]) == strtolower($b[0])) return 0; @@ -231,6 +235,71 @@ function dir_tagadelic($count = 0) { } +function app_tagblock($link,$count = 0) { + $o = ''; + + $r = app_tagadelic($count); + + if($r) { + $o = '<div class="tagblock widget"><h3>' . t('Categories') . '</h3><div class="tags" align="center">'; + foreach($r as $rr) { + $o .= '<a href="'.$link .'/' . '?f=&cat=' . urlencode($rr[0]).'" class="tag'.$rr[2].'">'.$rr[0].'</a> ' . "\r\n"; + } + $o .= '</div></div>'; + } + + return $o; +} + +function app_tagadelic($count = 0) { + + if(! local_channel()) + return ''; + + $count = intval($count); + + + // Fetch tags + $r = q("select term, count(term) as total from term left join app on term.uid = app_channel where term.uid = %d + and term.otype = %d group by term order by total desc %s", + intval(local_channel()), + intval(TERM_OBJ_APP), + ((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['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(9 * ($tags[$x][1] - $min) / $range); + } + + return $tags; +} + + + + + function tagblock($link,$uid,$count = 0,$authors = '',$owner = '', $flags = 0,$restrict = 0,$type = TERM_HASHTAG) { $o = ''; diff --git a/include/widgets.php b/include/widgets.php index 1b9d3c07a..7384aa399 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -400,6 +400,13 @@ function widget_categories($arr) { } +function widget_appcloud($arr) { + if(! local_channel()) + return ''; + return app_tagblock(z_root() . '/apps'); +} + + function widget_tagcloud_wall($arr) { diff --git a/view/pdl/mod_apps.pdl b/view/pdl/mod_apps.pdl index db93958a3..4cc036fa5 100644 --- a/view/pdl/mod_apps.pdl +++ b/view/pdl/mod_apps.pdl @@ -1,3 +1,4 @@ [region=aside] [widget=appselect][/widget] +[widget=appcloud][/widget] [/region] diff --git a/view/tpl/myapps.tpl b/view/tpl/myapps.tpl index 32d544a86..c654993b7 100755 --- a/view/tpl/myapps.tpl +++ b/view/tpl/myapps.tpl @@ -1,5 +1,5 @@ <div class="generic-content-wrapper-styled"> -<h3>{{$title}}</h3> +<h3>{{$title}}{{$cat}}</h3> {{foreach $apps as $ap}} {{$ap}} |