streams/Code/Module/Viewconnections.php

106 lines
3.2 KiB
PHP
Raw Normal View History

2016-04-19 03:38:38 +00:00
<?php
2021-12-03 03:01:39 +00:00
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2019-04-17 23:54:06 +00:00
use App;
2022-02-16 04:08:28 +00:00
use Code\Web\Controller;
use Code\Lib\Libprofile;
use Code\Render\Theme;
2022-02-12 20:43:29 +00:00
2019-01-18 21:04:05 +00:00
2021-12-02 23:02:31 +00:00
class Viewconnections extends Controller
{
public function init()
{
if (argc() > 1) {
Libprofile::load(argv(1));
}
}
public function get()
{
if (!perm_is_allowed(App::$profile['uid'], get_observer_hash(), 'view_contacts')) {
notice(t('Permission denied.') . EOL);
2022-08-26 22:37:04 +00:00
return '';
2021-12-02 23:02:31 +00:00
}
if (!$_REQUEST['aj']) {
$_SESSION['return_url'] = App::$query_string;
}
$is_owner = ((local_channel() && local_channel() == App::$profile['uid']) ? true : false);
$abook_flags = " and abook_pending = 0 and abook_self = 0 ";
$sql_extra = '';
if (!$is_owner) {
$abook_flags .= " and abook_hidden = 0 ";
$sql_extra = " and xchan_hidden = 0 ";
}
2021-12-03 03:01:39 +00:00
$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 ",
2021-12-02 23:02:31 +00:00
intval(App::$profile['uid']),
intval(App::$pager['itemspage']),
intval(App::$pager['start'])
);
if ((!$r) && (!$_REQUEST['aj'])) {
info(t('No connections.') . EOL);
2022-08-26 22:37:04 +00:00
return '';
2021-12-02 23:02:31 +00:00
}
$contacts = [];
foreach ($r as $rr) {
$oneway = false;
if (!their_perms_contains(App::$profile['uid'], $rr['xchan_hash'], 'post_comments')) {
$oneway = true;
}
$url = chanlink_hash($rr['xchan_hash']);
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
];
}
}
if ($_REQUEST['aj']) {
if ($contacts) {
2022-02-12 20:43:29 +00:00
$o = replace_macros(Theme::get_template('viewcontactsajax.tpl'), [
2021-12-02 23:02:31 +00:00
'$contacts' => $contacts
]);
} else {
$o = '<div id="content-complete"></div>';
}
echo $o;
killme();
} else {
2022-08-26 22:37:04 +00:00
$o = "<script> var page_query = '" . escape_tags($_GET['req']) . "'; var extra_args = '" . extra_query_args() . "' ; </script>";
2022-02-12 20:43:29 +00:00
$o .= replace_macros(Theme::get_template('viewcontact_template.tpl'), [
2021-12-02 23:02:31 +00:00
'$title' => t('View Connections'),
'$contacts' => $contacts,
]);
}
if (!$contacts) {
$o .= '<div id="content-complete"></div>';
}
return $o;
}
2016-04-19 03:38:38 +00:00
}