streams/Zotlabs/Module/Viewconnections.php

121 lines
2.9 KiB
PHP
Raw Normal View History

2016-04-19 03:38:38 +00:00
<?php
namespace Zotlabs\Module;
2019-04-17 23:54:06 +00:00
use App;
use Zotlabs\Web\Controller;
use Zotlabs\Lib\Libprofile;
2019-01-18 21:04:05 +00:00
2016-04-19 03:38:38 +00:00
2019-07-11 01:43:20 +00:00
class Viewconnections extends Controller {
2016-04-19 03:38:38 +00:00
function init() {
2019-07-11 01:43:20 +00:00
if (observer_prohibited()) {
2016-04-19 03:38:38 +00:00
return;
}
2016-06-29 03:48:43 +00:00
2019-07-11 01:43:20 +00:00
if (argc() > 1) {
2019-04-17 23:54:06 +00:00
Libprofile::load(argv(1));
2016-06-29 03:48:43 +00:00
}
2016-04-19 03:38:38 +00:00
}
function get() {
2019-07-11 01:43:20 +00:00
// logger('request: ' . print_r($_REQUEST,true));
if (observer_prohibited()) {
2016-04-19 03:38:38 +00:00
notice( t('Public access denied.') . EOL);
return;
}
2019-07-11 01:43:20 +00:00
2019-07-12 05:03:17 +00:00
if (((! (is_array(App::$profile) && count(App::$profile))) || (App::$profile['hide_friends']))) {
2016-04-19 03:38:38 +00:00
notice( t('Permission denied.') . EOL);
return;
}
2019-07-11 01:43:20 +00:00
if (! perm_is_allowed(App::$profile['uid'], get_observer_hash(),'view_contacts')) {
2016-04-19 03:38:38 +00:00
notice( t('Permission denied.') . EOL);
return;
}
2019-07-11 01:43:20 +00:00
if (! $_REQUEST['aj']) {
$_SESSION['return_url'] = App::$query_string;
}
2016-04-19 03:38:38 +00:00
2019-07-11 01:43:20 +00:00
$is_owner = ((local_channel() && local_channel() == App::$profile['uid']) ? true : false);
2016-04-19 03:38:38 +00:00
$abook_flags = " and abook_pending = 0 and abook_self = 0 ";
$sql_extra = '';
2019-07-11 01:43:20 +00:00
if (! $is_owner) {
$abook_flags .= " and abook_hidden = 0 ";
2016-04-19 03:38:38 +00:00
$sql_extra = " and xchan_hidden = 0 ";
}
$r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d $abook_flags and xchan_orphan = 0 and xchan_deleted = 0 $sql_extra order by xchan_name LIMIT %d OFFSET %d ",
2019-07-11 01:43:20 +00:00
intval(App::$profile['uid']),
intval(App::$pager['itemspage']),
intval(App::$pager['start'])
2016-04-19 03:38:38 +00:00
);
2019-07-11 01:43:20 +00:00
if ((! $r) && (! $_REQUEST['aj'])) {
2016-04-19 03:38:38 +00:00
info( t('No connections.') . EOL );
return $o;
}
2019-07-11 01:43:20 +00:00
$contacts = [];
2016-04-19 03:38:38 +00:00
2019-07-11 01:43:20 +00:00
foreach ($r as $rr) {
$oneway = false;
2019-07-11 01:43:20 +00:00
if (! their_perms_contains(App::$profile['uid'],$rr['xchan_hash'],'post_comments')) {
$oneway = true;
}
2016-04-19 03:38:38 +00:00
$url = chanlink_hash($rr['xchan_hash']);
2019-07-11 01:43:20 +00:00
if ($url) {
$contacts[] = [
'id' => $rr['abook_id'],
'archived' => (intval($rr['abook_archived']) ? true : false),
'img_hover' => sprintf( t('Visit %1$s\'s profile [%2$s]'), $rr['xchan_name'], $rr['xchan_url']),
'thumb' => $rr['xchan_photo_m'],
'name' => substr($rr['xchan_name'],0,20),
'username' => $rr['xchan_addr'],
'link' => $url,
'sparkle' => '',
'itemurl' => $rr['url'],
'network' => '',
'oneway' => $oneway
];
2016-04-19 03:38:38 +00:00
}
}
2019-07-11 01:43:20 +00:00
if ($_REQUEST['aj']) {
if ($contacts) {
$o = replace_macros(get_markup_template('viewcontactsajax.tpl'), [
2016-04-19 03:38:38 +00:00
'$contacts' => $contacts
2019-07-11 01:43:20 +00:00
]);
2016-04-19 03:38:38 +00:00
}
else {
$o = '<div id="content-complete"></div>';
}
echo $o;
killme();
}
else {
2019-07-11 01:43:20 +00:00
$o .= "<script> var page_query = '" . escape_tags($_GET['req']) . "'; var extra_args = '" . extra_query_args() . "' ; </script>";
$o .= replace_macros(get_markup_template('viewcontact_template.tpl'), [
'$title' => t('View Connections'),
2016-04-19 03:38:38 +00:00
'$contacts' => $contacts,
2019-07-11 01:43:20 +00:00
]);
2016-04-19 03:38:38 +00:00
}
2019-07-11 01:43:20 +00:00
if (! $contacts) {
2016-04-19 03:38:38 +00:00
$o .= '<div id="content-complete"></div>';
2019-07-11 01:43:20 +00:00
}
2016-04-19 03:38:38 +00:00
return $o;
}
}