2019-09-10 04:03:33 +00:00
< ? php
2021-12-03 03:01:39 +00:00
2019-09-10 04:03:33 +00:00
namespace Zotlabs\Module ;
use App ;
use Zotlabs\Lib\ActivityStreams ;
use Zotlabs\Lib\LDSignatures ;
use Zotlabs\Lib\Activity ;
use Zotlabs\Web\HTTPSig ;
use Zotlabs\Web\Controller ;
use Zotlabs\Lib\Libprofile ;
2022-01-25 01:26:12 +00:00
use Zotlabs\Lib\Channel ;
2019-09-10 04:03:33 +00:00
2021-12-02 23:02:31 +00:00
class Following extends Controller
{
2019-09-10 04:03:33 +00:00
2021-12-22 21:15:45 +00:00
private $results = [];
2021-12-02 23:02:31 +00:00
public function init ()
{
2019-09-10 04:03:33 +00:00
2021-12-02 23:02:31 +00:00
if ( observer_prohibited ( true )) {
http_status_exit ( 403 , 'Forbidden' );
}
2019-09-10 04:03:33 +00:00
2021-12-02 23:02:31 +00:00
if ( argc () < 2 ) {
http_status_exit ( 404 , 'Not found' );
}
2019-09-10 04:03:33 +00:00
2022-01-25 01:26:12 +00:00
$channel = Channel :: from_username ( argv ( 1 ));
2021-12-02 23:02:31 +00:00
if ( ! $channel ) {
http_status_exit ( 404 , 'Not found' );
}
2019-09-10 04:03:33 +00:00
2021-12-02 23:02:31 +00:00
Libprofile :: load ( argv ( 1 ));
$observer_hash = get_observer_hash ();
if ((( ! ( is_array ( App :: $profile ) && count ( App :: $profile ))) || ( App :: $profile [ 'hide_friends' ]))) {
http_status_exit ( 403 , 'Forbidden' );
}
if ( ! perm_is_allowed ( $channel [ 'channel_id' ], $observer_hash , 'view_contacts' )) {
http_status_exit ( 403 , 'Forbidden' );
}
2021-12-03 03:01:39 +00:00
$t = q (
" select count(xchan_hash) as total from xchan left join abconfig on abconfig.xchan = xchan_hash left join abook on abook_xchan = xchan_hash where abook_channel = %d and abconfig.chan = %d and abconfig.cat = 'system' and abconfig.k = 'my_perms' and abconfig.v like '%%send_stream%%' and xchan_hash != '%s' and xchan_orphan = 0 and xchan_deleted = 0 and abook_hidden = 0 and abook_pending = 0 and abook_self = 0 " ,
2021-12-02 23:02:31 +00:00
intval ( $channel [ 'channel_id' ]),
intval ( $channel [ 'channel_id' ]),
dbesc ( $channel [ 'channel_hash' ])
);
if ( $t ) {
App :: set_pager_total ( $t [ 0 ][ 'total' ]);
App :: set_pager_itemspage ( 100 );
}
if ( App :: $pager [ 'unset' ] && $t [ 0 ][ 'total' ] > 100 ) {
$ret = Activity :: paged_collection_init ( $t [ 0 ][ 'total' ], App :: $query_string );
} else {
$pager_sql = sprintf ( " LIMIT %d OFFSET %d " , intval ( App :: $pager [ 'itemspage' ]), intval ( App :: $pager [ 'start' ]));
2021-12-03 03:01:39 +00:00
$r = q (
" select * from xchan left join abconfig on abconfig.xchan = xchan_hash left join abook on abook_xchan = xchan_hash where abook_channel = %d and abconfig.chan = %d and abconfig.cat = 'system' and abconfig.k = 'my_perms' and abconfig.v like '%%send_stream%%' and xchan_hash != '%s' and xchan_orphan = 0 and xchan_deleted = 0 and abook_hidden = 0 and abook_pending = 0 and abook_self = 0 $pager_sql " ,
2021-12-02 23:02:31 +00:00
intval ( $channel [ 'channel_id' ]),
intval ( $channel [ 'channel_id' ]),
dbesc ( $channel [ 'channel_hash' ])
);
2021-12-22 21:15:45 +00:00
$this -> results = $r ;
2021-12-02 23:02:31 +00:00
$ret = Activity :: encode_follow_collection ( $r , App :: $query_string , 'OrderedCollection' , $t [ 0 ][ 'total' ]);
}
if ( ActivityStreams :: is_as_request ()) {
as_return_and_die ( $ret , $channel );
}
}
2021-12-22 21:15:45 +00:00
function get () {
if ( $this -> results ) {
foreach ( $this -> results as $member ) {
$members [] = micropro ( $member , true , 'mpgroup' , 'card' );
}
}
$o = replace_macros ( get_markup_template ( 'listmembers.tpl' ), [
'$title' => t ( 'List members' ),
'$members' => $members
]);
return $o ;
}
2019-09-10 04:03:33 +00:00
}