From dd0df677a66e58988daeec04208ffdd8295b786e Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 30 Apr 2019 16:52:07 -0700 Subject: [PATCH] resolve some of the issues associated with having multiple suggestion implementations, and add xign sync to this subsystem --- Zotlabs/Module/Directory.php | 6 ++- Zotlabs/Module/Suggest.php | 72 ---------------------------------- Zotlabs/Module/Suggestions.php | 44 +++++++++++++++++++++ Zotlabs/Widget/Suggestions.php | 44 +++++++++++---------- app/suggest.apd | 4 +- boot.php | 2 +- view/tpl/suggest_widget.tpl | 2 +- 7 files changed, 76 insertions(+), 98 deletions(-) delete mode 100644 Zotlabs/Module/Suggest.php create mode 100644 Zotlabs/Module/Suggestions.php diff --git a/Zotlabs/Module/Directory.php b/Zotlabs/Module/Directory.php index 213b6a5ef..970d921e0 100644 --- a/Zotlabs/Module/Directory.php +++ b/Zotlabs/Module/Directory.php @@ -3,6 +3,7 @@ namespace Zotlabs\Module; use Zotlabs\Lib\Libzotdir; +use Zotlabs\Lib\Libsync; require_once('include/socgraph.php'); require_once('include/bbcode.php'); @@ -13,11 +14,14 @@ class Directory extends \Zotlabs\Web\Controller { function init() { \App::set_pager_itemspage(60); - if(x($_GET,'ignore')) { + if(x($_GET,'ignore') && local_channel()) { q("insert into xign ( uid, xchan ) values ( %d, '%s' ) ", intval(local_channel()), dbesc($_GET['ignore']) ); + + Libsync::build_sync_packet(local_channel(), [ 'xign' => [ [ 'uid' => local_channel(), 'xchan' => $_GET['ignore'] ]]] ); + goaway(z_root() . '/directory?f=&suggest=1'); } diff --git a/Zotlabs/Module/Suggest.php b/Zotlabs/Module/Suggest.php deleted file mode 100644 index 2ea71752c..000000000 --- a/Zotlabs/Module/Suggest.php +++ /dev/null @@ -1,72 +0,0 @@ - chanlink_url($rr['xchan_url']), - 'common' => $rr['total'], - 'profile' => $rr['xchan_url'], - 'name' => $rr['xchan_name'], - 'photo' => $rr['xchan_photo_m'], - 'ignlnk' => z_root() . '/suggest?ignore=' . $rr['xchan_hash'], - 'conntxt' => t('Connect'), - 'connlnk' => $connlnk, - 'ignore' => t('Ignore/Hide') - ); - } - - - $o = replace_macros(get_markup_template('suggest_page.tpl'),array( - '$title' => t('Channel Suggestions'), - '$entries' => $arr - )); - - return $o; - - } - -} diff --git a/Zotlabs/Module/Suggestions.php b/Zotlabs/Module/Suggestions.php new file mode 100644 index 000000000..bcf148c8d --- /dev/null +++ b/Zotlabs/Module/Suggestions.php @@ -0,0 +1,44 @@ + [ [ 'uid' => local_channel(), 'xchan' => $_GET['ignore'] ]]] ); + } + } + + + function get() { + + $o = ''; + if (! local_channel()) { + notice( t('Permission denied.') . EOL); + return; + } + + if (Apps::system_app_installed(local_channel(),'Suggest Channels')) { + goaway(z_root() . '/directory?f=&suggest=1'); + } + + $desc = t('This app (when installed) displays a small number of friend suggestions on selected pages or you can run the app to display a full list of channel suggestions.'); + + return '
' . $desc . '
'; + + } + +} diff --git a/Zotlabs/Widget/Suggestions.php b/Zotlabs/Widget/Suggestions.php index 5fb3d3e8b..5207496de 100644 --- a/Zotlabs/Widget/Suggestions.php +++ b/Zotlabs/Widget/Suggestions.php @@ -2,6 +2,8 @@ namespace Zotlabs\Widget; +use Zotlabs\Lib\Apps; + require_once('include/socgraph.php'); @@ -9,49 +11,49 @@ class Suggestions { function widget($arr) { - if((! local_channel()) || (! feature_enabled(local_channel(),'suggest'))) - return ''; - - + if ((! local_channel()) || (! Apps::system_app_installed(local_channel(),'Suggest Channels'))) { + return EMPTY_STR; + } + $r = suggestion_query(local_channel(),get_observer_hash(),0,20); - if(! $r) { - return; + if (! $r) { + return EMPTY_STR; } - $arr = array(); + $arr = []; // Get two random entries from the top 20 returned. // We'll grab the first one and the one immediately following. - // This will throw some entropy intot he situation so you won't + // This will throw some entropy into the situation so you won't // be looking at the same two mug shots every time the widget runs $index = ((count($r) > 2) ? mt_rand(0,count($r) - 2) : 0); - for($x = $index; $x <= ($index+1); $x ++) { + for ($x = $index; $x <= ($index+1); $x ++) { $rr = $r[$x]; - if(! $rr['xchan_url']) + if (! $rr['xchan_url']) break; $connlnk = z_root() . '/follow/?url=' . $rr['xchan_addr']; - $arr[] = array( - 'url' => chanlink_url($rr['xchan_url']), + $arr[] = [ + 'url' => chanlink_url($rr['xchan_url']), 'profile' => $rr['xchan_url'], - 'name' => $rr['xchan_name'], - 'photo' => $rr['xchan_photo_m'], - 'ignlnk' => z_root() . '/directory?ignore=' . $rr['xchan_hash'], + 'name' => $rr['xchan_name'], + 'photo' => $rr['xchan_photo_m'], + 'ignlnk' => z_root() . '/directory?ignore=' . $rr['xchan_hash'], 'conntxt' => t('Connect'), 'connlnk' => $connlnk, - 'ignore' => t('Ignore/Hide') - ); + 'ignore' => t('Ignore/Hide') + ]; } - $o = replace_macros(get_markup_template('suggest_widget.tpl'),array( - '$title' => t('Suggestions'), - '$more' => t('See more...'), + $o = replace_macros(get_markup_template('suggest_widget.tpl'), [ + '$title' => t('Suggestions'), + '$more' => t('See more...'), '$entries' => $arr - )); + ] ); return $o; } diff --git a/app/suggest.apd b/app/suggest.apd index 51b555264..760f3cf23 100644 --- a/app/suggest.apd +++ b/app/suggest.apd @@ -1,5 +1,5 @@ -version: 1 -url: $baseurl/suggest +version: 2 +url: $baseurl/suggestions requires: local_channel name: Suggest Channels photo: icon:lightbulb-o diff --git a/boot.php b/boot.php index 7d1590595..761ba4dcd 100755 --- a/boot.php +++ b/boot.php @@ -45,7 +45,7 @@ require_once('include/items.php'); -define ( 'STD_VERSION', '2.11' ); +define ( 'STD_VERSION', '2.13' ); define ( 'ZOT_REVISION', '6.0' ); define ( 'DB_UPDATE_VERSION', 1232 ); diff --git a/view/tpl/suggest_widget.tpl b/view/tpl/suggest_widget.tpl index 7b9afa668..1299f639c 100644 --- a/view/tpl/suggest_widget.tpl +++ b/view/tpl/suggest_widget.tpl @@ -6,5 +6,5 @@ {{/foreach}} {{/if}}
-
{{$more}}
+
{{$more}}