2019-09-10 04:03:33 +00:00
< ? php
2022-02-16 04:08:28 +00:00
namespace Code\Module ;
2019-09-10 04:03:33 +00:00
use App ;
2022-02-16 04:08:28 +00:00
use Code\Lib\ActivityStreams ;
use Code\Lib\LDSignatures ;
use Code\Lib\Activity ;
use Code\Web\HTTPSig ;
use Code\Web\Controller ;
use Code\Lib\Libprofile ;
use Code\Lib\Channel ;
use Code\Render\Theme ;
2022-02-12 20:43:29 +00:00
2019-09-10 04:03:33 +00:00
2021-12-02 23:02:31 +00:00
class Followers 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 ()
{
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 ));
2019-09-10 04:03:33 +00:00
2021-12-02 23:02:31 +00:00
$observer_hash = get_observer_hash ();
2019-09-10 04:03:33 +00:00
2021-12-02 23:02:31 +00:00
if ((( ! ( is_array ( App :: $profile ) && count ( App :: $profile ))) || ( App :: $profile [ 'hide_friends' ]))) {
http_status_exit ( 403 , 'Forbidden' );
}
2019-09-10 04:03:33 +00:00
2021-12-02 23:02:31 +00:00
if ( ! perm_is_allowed ( $channel [ 'channel_id' ], $observer_hash , 'view_contacts' )) {
http_status_exit ( 403 , 'Forbidden' );
}
2019-09-10 04:03:33 +00:00
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 = 'their_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 );
}
2020-08-07 03:19:03 +00:00
2021-12-02 23:02:31 +00:00
if ( App :: $pager [ 'unset' ] && intval ( $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' ]));
2020-08-07 03:19:03 +00:00
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 = 'their_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' ])
);
2020-08-07 03:19:03 +00:00
2021-12-22 21:15:45 +00:00
$this -> results = $r ;
$ret = Activity :: encode_follow_collection ( $r , App :: $query_string , 'OrderedCollection' , $t [ 0 ][ 'total' ]);
2021-12-02 23:02:31 +00:00
}
2020-08-07 03:19:03 +00:00
2021-12-02 23:02:31 +00:00
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' );
}
}
2022-02-12 20:43:29 +00:00
$o = replace_macros ( Theme :: get_template ( 'listmembers.tpl' ), [
2021-12-22 21:15:45 +00:00
'$title' => t ( 'List members' ),
'$members' => $members
]);
return $o ;
}
2019-09-10 04:03:33 +00:00
}