diff options
author | Andrew Manning <tamanning@zoho.com> | 2016-05-05 05:35:00 -0400 |
---|---|---|
committer | Andrew Manning <tamanning@zoho.com> | 2016-05-05 05:35:00 -0400 |
commit | 6ce939491bf932c20c9777a8518da5875e02a6b1 (patch) | |
tree | e49b75c9017015677e6d550d75e4ce62ffaddc75 | |
parent | 8cb06e7af8c3a14a6513d2aee2beba091f3ecfb5 (diff) | |
parent | 8ffdc4859baa9f2ae9567a4c443dfbb227919167 (diff) | |
download | volse-hubzilla-6ce939491bf932c20c9777a8518da5875e02a6b1.tar.gz volse-hubzilla-6ce939491bf932c20c9777a8518da5875e02a6b1.tar.bz2 volse-hubzilla-6ce939491bf932c20c9777a8518da5875e02a6b1.zip |
Merge remote-tracking branch 'upstream/dev' into plugin-repo
-rw-r--r-- | Zotlabs/Module/Appman.php | 26 | ||||
-rw-r--r-- | Zotlabs/Module/Apps.php | 3 | ||||
-rw-r--r-- | Zotlabs/Module/Follow.php | 5 | ||||
-rw-r--r-- | Zotlabs/Text/Tagadelic.php | 44 | ||||
-rw-r--r-- | include/apps.php | 128 | ||||
-rw-r--r-- | include/contact_widgets.php | 2 | ||||
-rw-r--r-- | include/identity.php | 11 | ||||
-rw-r--r-- | include/import.php | 73 | ||||
-rw-r--r-- | include/taxonomy.php | 88 | ||||
-rw-r--r-- | include/widgets.php | 49 | ||||
-rw-r--r-- | view/pdl/mod_apps.pdl | 1 | ||||
-rw-r--r-- | view/tpl/app_create.tpl | 1 | ||||
-rwxr-xr-x | view/tpl/myapps.tpl | 2 |
13 files changed, 346 insertions, 87 deletions
diff --git a/Zotlabs/Module/Appman.php b/Zotlabs/Module/Appman.php index b0dd887f4..ba2a64f35 100644 --- a/Zotlabs/Module/Appman.php +++ b/Zotlabs/Module/Appman.php @@ -1,5 +1,6 @@ -<?php -namespace Zotlabs\Module; /** @file */ +<?php /** @file */ + +namespace Zotlabs\Module; require_once('include/apps.php'); @@ -25,7 +26,8 @@ class Appman extends \Zotlabs\Web\Controller { 'price' => escape_tags($_REQUEST['price']), 'requires' => escape_tags($_REQUEST['requires']), 'system' => intval($_REQUEST['system']), - 'sig' => escape_tags($_REQUEST['sig']) + 'sig' => escape_tags($_REQUEST['sig']), + 'categories' => escape_tags($_REQUEST['categories']) ); $_REQUEST['appid'] = app_install(local_channel(),$arr); @@ -81,8 +83,23 @@ class Appman extends \Zotlabs\Web\Controller { dbesc($_REQUEST['appid']), dbesc(local_channel()) ); - if($r) + if($r) { $app = $r[0]; + + $term = q("select * from term where otype = %d and oid = %d", + intval(TERM_OBJ_APP), + intval($r[0]['id']) + ); + if($term) { + $app['categories'] = ''; + foreach($term as $t) { + if($app['categories']) + $app['categories'] .= ','; + $app['categories'] .= $t['term']; + } + } + } + $embed = array('embed', t('Embed code'), app_encode($app,true),'', 'onclick="this.select();"'); } @@ -98,6 +115,7 @@ class Appman extends \Zotlabs\Web\Controller { '$url' => array('url', t('Location (URL) of app'),(($app) ? $app['app_url'] : ''), t('Required')), '$desc' => array('desc', t('Description'),(($app) ? $app['app_desc'] : ''), ''), '$photo' => array('photo', t('Photo icon URL'),(($app) ? $app['app_photo'] : ''), t('80 x 80 pixels - optional')), + '$categories' => array('categories',t('Categories (optional, comma separated list)'),(($app) ? $app['categories'] : ''),''), '$version' => array('version', t('Version ID'),(($app) ? $app['app_version'] : ''), ''), '$price' => array('price', t('Price of app'),(($app) ? $app['app_price'] : ''), ''), '$page' => array('page', t('Location (URL) to purchase app'),(($app) ? $app['app_page'] : ''), ''), 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/Zotlabs/Module/Follow.php b/Zotlabs/Module/Follow.php index d3114557b..1701328bf 100644 --- a/Zotlabs/Module/Follow.php +++ b/Zotlabs/Module/Follow.php @@ -19,7 +19,10 @@ class Follow extends \Zotlabs\Web\Controller { $confirm = intval($_REQUEST['confirm']); $channel = \App::get_channel(); - + + // Warning: Do not edit the following line. The first symbol is UTF-8 @ + $url = str_replace('@','@',$url); + $result = new_contact($uid,$url,$channel,true,$confirm); if($result['success'] == false) { 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 diff --git a/include/apps.php b/include/apps.php index 30fed361d..7439be6d4 100644 --- a/include/apps.php +++ b/include/apps.php @@ -69,6 +69,7 @@ function app_name_compare($a,$b) { return strcmp($a['name'],$b['name']); } + function parse_app_description($f,$translate = true) { $ret = array(); @@ -295,6 +296,7 @@ function app_render($papp,$mode = 'view') { function app_install($uid,$app) { $app['uid'] = $uid; + if(app_installed($uid,$app)) $x = app_update($app); else @@ -305,9 +307,17 @@ function app_install($uid,$app) { dbesc($x['app_id']), intval($uid) ); - if($r) - build_sync_packet($uid,array('app' => $r[0])); - + if($r) { + if(! $r[0]['app_system']) { + if($app['categories'] && (! $app['term'])) { + $r[0]['term'] = q("select * from term where otype = %d and oid = d", + intval(TERM_OBJ_APP), + intval($r[0]['id']) + ); + build_sync_packet($uid,array('app' => $r[0])); + } + } + } return $x['app_id']; } return false; @@ -322,22 +332,28 @@ function app_destroy($uid,$app) { dbesc($app['guid']), intval($uid) ); - $x[0]['app_deleted'] = 1; - - if($x[0]['app_system']) { - $r = q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d", - dbesc($app['guid']), - intval($uid) - ); - } - else { - $r = q("delete from app where app_id = '%s' and app_channel = %d", - dbesc($app['guid']), - intval($uid) + if($x) { + $x[0]['app_deleted'] = 1; + q("delete from term where otype = %d and oid = %d", + intval(TERM_OBJ_APP), + intval($x[0]['id']) ); + if($x[0]['app_system']) { + $r = q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d", + dbesc($app['guid']), + intval($uid) + ); + } + else { + $r = q("delete from app where app_id = '%s' and app_channel = %d", + dbesc($app['guid']), + intval($uid) + ); + + // we don't sync system apps - they may be completely different on the other system + build_sync_packet($uid,array('app' => $x)); + } } - - build_sync_packet($uid,array('app' => $x)); } } @@ -354,18 +370,40 @@ 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) ); if($r) { for($x = 0; $x < count($r); $x ++) { - $r[$x]['type'] = 'personal'; + if(! $r[$x]['app_system']) + $r[$x]['type'] = 'personal'; + $r[$x]['term'] = q("select * from term where otype = %d and oid = %d", + intval(TERM_OBJ_APP), + intval($r[$x]['id']) + ); } } return($r); @@ -436,6 +474,22 @@ function app_store($arr) { $ret['success'] = true; $ret['app_id'] = $darray['app_id']; } + if($arr['categories']) { + $x = q("select id from app where app_id = '%s' and app_channel = %d limit 1", + dbesc($darray['app_id']), + intval($darray['app_channel']) + ); + $y = explode(',',$arr['categories']); + if($y) { + foreach($y as $t) { + $t = trim($t); + if($t) { + store_item_tag($darray['app_channel'],$x[0]['id'],TERM_OBJ_APP,TERM_CATEGORY,escape_tags($t),escape_tags(z_root() . '/apps/?f=&cat=' . escape_tags($t))); + } + } + } + } + return $ret; } @@ -495,6 +549,28 @@ function app_update($arr) { $ret['app_id'] = $darray['app_id']; } + $x = q("select id from app where app_id = '%s' and app_channel = %d limit 1", + dbesc($darray['app_id']), + intval($darray['app_channel']) + ); + if($x) { + q("delete from term where otype = %d and oid = %d", + intval(TERM_OBJ_APP), + intval($x[0]['id']) + ); + if($arr['categories']) { + $y = explode(',',$arr['categories']); + if($y) { + foreach($y as $t) { + $t = trim($t); + if($t) { + store_item_tag($darray['app_channel'],$x[0]['id'],TERM_OBJ_APP,TERM_CATEGORY,escape_tags($t),escape_tags(z_root() . '/apps/?f=&cat=' . escape_tags($t))); + } + } + } + } + } + return $ret; } @@ -551,9 +627,23 @@ function app_encode($app,$embed = false) { if($app['app_deleted']) $ret['deleted'] = $app['app_deleted']; + if($app['term']) { + $s = ''; + foreach($app['term'] as $t) { + if($s) + $s .= ','; + $s .= $t['term']; + } + $ret['categories'] = $s; + } + + if(! $embed) return $ret; + if(array_key_exists('categories',$ret)) + unset($ret['categories']); + $j = json_encode($ret); return '[app]' . chunk_split(base64_encode($j),72,"\n") . '[/app]'; diff --git a/include/contact_widgets.php b/include/contact_widgets.php index ba1241fcb..e62d57aa2 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -79,12 +79,14 @@ function categories_widget($baseurl,$selected = '') { where item.uid = %d and term.uid = item.uid and term.type = %d + and term.otype = %d and item.owner_xchan = '%s' and item.item_wall = 1 $item_normal order by term.term asc", intval(App::$profile['profile_uid']), intval(TERM_CATEGORY), + intval(TERM_OBJ_POST), dbesc(App::$profile['channel_hash']) ); if($r && count($r)) { diff --git a/include/identity.php b/include/identity.php index c60c846c0..53bed7c0f 100644 --- a/include/identity.php +++ b/include/identity.php @@ -580,11 +580,18 @@ function identity_basic_export($channel_id, $items = false) { if($r) $ret['obj'] = $r; - $r = q("select * from app where app_channel = %d", + $r = q("select * from app where app_channel = %d and app_system = 0", intval($channel_id) ); - if($r) + if($r) { + for($x = 0; $x < count($r); $x ++) { + $r[$x]['term'] = q("select * from term where otype = %d and oid = %d", + intval(TERM_OBJ_APP), + intval($r[$x]['id']) + ); + } $ret['app'] = $r; + } $r = q("select * from chatroom where cr_uid = %d", intval($channel_id) diff --git a/include/import.php b/include/import.php index f6e62f9e0..321f275b1 100644 --- a/include/import.php +++ b/include/import.php @@ -297,8 +297,11 @@ function import_apps($channel,$apps) { if($channel && $apps) { foreach($apps as $app) { + $term = ((array_key_exists('term',$app) && is_array($app['term'])) ? $app['term'] : null); + unset($app['id']); unset($app['app_channel']); + unset($app['term']); $app['app_channel'] = $channel['channel_id']; @@ -307,6 +310,8 @@ function import_apps($channel,$apps) { $app['app_photo'] = $x[0]; } + $hash = $app['app_id']; + dbesc_array($app); $r = dbq("INSERT INTO app (`" . implode("`, `", array_keys($app)) @@ -314,6 +319,21 @@ function import_apps($channel,$apps) { . implode("', '", array_values($app)) . "')" ); + + if($term) { + $x = q("select * from app where app_id = '%s' and app_channel = %d limit 1", + dbesc($hash), + intval($channel['channel_id']) + ); + if($x) { + foreach($term as $t) { + store_item_tag($channel['channel_id'],$x[0]['id'],TERM_OBJ_APP,$t['type'],escape_tags($t['term']),escape_tags($t['url'])); + } + } + } + + + } } } @@ -325,16 +345,41 @@ function sync_apps($channel,$apps) { if($channel && $apps) { foreach($apps as $app) { - if(array_key_exists('app_deleted',$app) && $app['app_deleted'] && $app['app_id']) { + $exists = false; + $term = ((array_key_exists('term',$app)) ? $app['term'] : null); + + $x = q("select * from app where app_id = '%s' and app_channel = %d limit 1", + dbesc($app['app_id']), + intval($channel['channel_id']) + ); + if($x) { + $exists = $x[0]; + } + + if(array_key_exists('app_deleted',$app) && $app['app_deleted'] && $app['app_id']) { q("delete from app where app_id = '%s' and app_channel = %d limit 1", dbesc($app['app_id']), intval($channel['channel_id']) ); + if($exists) { + q("delete from term where otype = %d and oid = %d", + intval(TERM_OBJ_APP), + intval($exists['id']) + ); + } continue; } unset($app['id']); unset($app['app_channel']); + unset($app['term']); + + if($exists) { + q("delete from term where otype = %d and oid = %d", + intval(TERM_OBJ_APP), + intval($exists['id']) + ); + } if(! $app['app_created'] || $app['app_created'] === NULL_DATE) $app['app_created'] = datetime_convert(); @@ -348,16 +393,15 @@ function sync_apps($channel,$apps) { $app['app_photo'] = $x[0]; } - $exists = false; + if($exists && $term) { + foreach($term as $t) { + store_item_tag($channel['channel_id'],$exists['id'],TERM_OBJ_APP,$t['type'],escape_tags($t['term']),escape_tags($t['url'])); + } + } - $x = q("select * from app where app_id = '%s' and app_channel = %d limit 1", - dbesc($app['app_id']), - intval($channel['channel_id']) - ); - if($x) { - if($x[0]['app_edited'] >= $app['app_edited']) + if($exists) { + if($exists['app_edited'] >= $app['app_edited']) continue; - $exists = true; } $hash = $app['app_id']; @@ -380,6 +424,17 @@ function sync_apps($channel,$apps) { . implode("', '", array_values($app)) . "')" ); + if($term) { + $x = q("select * from app where app_id = '%s' and app_channel = %d limit 1", + dbesc($hash), + intval($channel['channel_id']) + ); + if($x) { + foreach($term as $t) { + store_item_tag($channel['channel_id'],$x[0]['id'],TERM_OBJ_APP,$t['type'],escape_tags($t['term']),escape_tags($t['url'])); + } + } + } } } } diff --git a/include/taxonomy.php b/include/taxonomy.php index 71ed6e91d..e43f5e5d0 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -156,78 +156,66 @@ function tagadelic($uid, $count = 0, $authors = '', $owner = '', $flags = 0, $re 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 ++; - } + return Zotlabs\Text\Tagadelic::calc($r); - usort($tags,'tags_sort'); +} - $range = max(.01, $max - $min) * 1.0001; +function dir_tagadelic($count = 0) { - for($x = 0; $x < count($tags); $x ++) { - $tags[$x][2] = 1 + floor(9 * ($tags[$x][1] - $min) / $range); - } + $count = intval($count); + + // Fetch tags + $r = q("select xtag_term as term, count(xtag_term) as total from xtag where xtag_flags = 0 + group by xtag_term order by total desc %s", + ((intval($count)) ? "limit $count" : '') + ); + + if(! $r) + return array(); + + + return Zotlabs\Text\Tagadelic::calc($r); - return $tags; } -function tags_sort($a,$b) { - if(strtolower($a[0]) == strtolower($b[0])) - return 0; +function app_tagblock($link,$count = 0) { + $o = ''; + + $r = app_tagadelic($count); - return((strtolower($a[0]) < strtolower($b[0])) ? -1 : 1); + 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) { -function dir_tagadelic($count = 0) { + if(! local_channel()) + return ''; $count = intval($count); + // Fetch tags - $r = q("select xtag_term, count(xtag_term) as total from xtag where xtag_flags = 0 - group by xtag_term order by total desc %s", + $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['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(9 * ($tags[$x][1] - $min) / $range); - } + return Zotlabs\Text\Tagadelic::calc($r); - return $tags; } diff --git a/include/widgets.php b/include/widgets.php index 1b9d3c07a..2641a718e 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -400,6 +400,55 @@ function widget_categories($arr) { } +function widget_appcategories($arr) { + + if(! local_channel()) + return ''; + + $cat = ((x($_REQUEST,'cat')) ? htmlspecialchars($_REQUEST['cat'],ENT_COMPAT,'UTF-8') : ''); + $srchurl = App::$query_string; + $srchurl = rtrim(preg_replace('/cat\=[^\&].*?(\&|$)/is','',$srchurl),'&'); + $srchurl = str_replace(array('?f=','&f='),array('',''),$srchurl); + + $terms = array(); + + $r = q("select distinct(term.term) + from term join app on term.oid = app.id + where app_channel = %d + and term.uid = app_channel + and term.otype = %d + order by term.term asc", + intval(local_channel()), + intval(TERM_OBJ_APP) + ); + if($r) { + foreach($r as $rr) + $terms[] = array('name' => $rr['term'], 'selected' => (($selected == $rr['term']) ? 'selected' : '')); + + return replace_macros(get_markup_template('categories_widget.tpl'),array( + '$title' => t('Categories'), + '$desc' => '', + '$sel_all' => (($selected == '') ? 'selected' : ''), + '$all' => t('Everything'), + '$terms' => $terms, + '$base' => $srchurl, + + )); + } + + + +} + + + +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..32fef28e9 100644 --- a/view/pdl/mod_apps.pdl +++ b/view/pdl/mod_apps.pdl @@ -1,3 +1,4 @@ [region=aside] [widget=appselect][/widget] +[widget=appcategories][/widget] [/region] diff --git a/view/tpl/app_create.tpl b/view/tpl/app_create.tpl index 0590e7031..06fbcaaa7 100644 --- a/view/tpl/app_create.tpl +++ b/view/tpl/app_create.tpl @@ -17,6 +17,7 @@ {{include file="field_input.tpl" field=$name}} +{{include file="field_input.tpl" field=$categories}} {{include file="field_input.tpl" field=$url}} {{include file="field_textarea.tpl" field=$desc}} {{include file="field_input.tpl" field=$photo}} 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}} |