resolve some of the issues associated with having multiple suggestion implementations, and add xign sync to this subsystem

This commit is contained in:
zotlabs 2019-04-30 16:52:07 -07:00
parent 9678e44c4a
commit dd0df677a6
7 changed files with 76 additions and 98 deletions

View file

@ -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');
}

View file

@ -1,72 +0,0 @@
<?php
namespace Zotlabs\Module;
require_once('include/socgraph.php');
class Suggest extends \Zotlabs\Web\Controller {
function init() {
if(! local_channel())
return;
if(x($_GET,'ignore')) {
q("insert into xign ( uid, xchan ) values ( %d, '%s' ) ",
intval(local_channel()),
dbesc($_GET['ignore'])
);
}
}
function get() {
$o = '';
if(! local_channel()) {
notice( t('Permission denied.') . EOL);
return;
}
nav_set_selected('Suggest Channels');
$_SESSION['return_url'] = z_root() . '/' . \App::$cmd;
$r = suggestion_query(local_channel(),get_observer_hash());
if(! $r) {
info( t('No suggestions available. If this is a new site, please try again in 24 hours.'));
return;
}
$arr = array();
foreach($r as $rr) {
$connlnk = z_root() . '/follow/?url=' . $rr['xchan_addr'];
$arr[] = array(
'url' => 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;
}
}

View file

@ -0,0 +1,44 @@
<?php
namespace Zotlabs\Module;
use Zotlabs\Lib\Libsync;
use Zotlabs\Lib\Apps;
require_once('include/socgraph.php');
class Suggestions extends \Zotlabs\Web\Controller {
function init() {
if (! local_channel())
return;
if (x($_GET,'ignore')) {
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'] ]]] );
}
}
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 '<div class="section-content-info-wrapper">' . $desc . '</div>';
}
}

View file

@ -2,6 +2,8 @@
namespace Zotlabs\Widget;
use Zotlabs\Lib\Apps;
require_once('include/socgraph.php');
@ -9,17 +11,17 @@ 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;
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.
@ -35,7 +37,7 @@ class Suggestions {
$connlnk = z_root() . '/follow/?url=' . $rr['xchan_addr'];
$arr[] = array(
$arr[] = [
'url' => chanlink_url($rr['xchan_url']),
'profile' => $rr['xchan_url'],
'name' => $rr['xchan_name'],
@ -44,14 +46,14 @@ class Suggestions {
'conntxt' => t('Connect'),
'connlnk' => $connlnk,
'ignore' => t('Ignore/Hide')
);
];
}
$o = replace_macros(get_markup_template('suggest_widget.tpl'),array(
$o = replace_macros(get_markup_template('suggest_widget.tpl'), [
'$title' => t('Suggestions'),
'$more' => t('See more...'),
'$entries' => $arr
));
] );
return $o;
}

View file

@ -1,5 +1,5 @@
version: 1
url: $baseurl/suggest
version: 2
url: $baseurl/suggestions
requires: local_channel
name: Suggest Channels
photo: icon:lightbulb-o

View file

@ -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 );

View file

@ -6,5 +6,5 @@
{{/foreach}}
{{/if}}
<div class="clear"></div>
<div class="suggest-widget-more"><a href="suggest">{{$more}}</a></div>
<div class="suggest-widget-more"><a href="suggestions">{{$more}}</a></div>
</div>