streams/Code/Module/Common.php

82 lines
1.8 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;
2016-04-19 03:38:38 +00:00
2019-04-17 23:54:06 +00:00
use App;
2022-02-16 04:08:28 +00:00
use Code\Lib\Libprofile;
use Code\Web\Controller;
use Code\Render\Theme;
2022-02-16 06:10:50 +00:00
use Code\Lib\Socgraph;
2016-04-19 03:38:38 +00:00
2021-12-02 23:02:31 +00:00
class Common extends Controller
{
public function init()
{
2021-12-03 03:01:39 +00:00
if (argc() > 1 && intval(argv(1))) {
2021-12-02 23:02:31 +00:00
$channel_id = intval(argv(1));
2021-12-03 03:01:39 +00:00
} else {
2021-12-02 23:02:31 +00:00
notice(t('No channel.') . EOL);
App::$error = 404;
return;
}
2021-12-03 03:01:39 +00:00
$x = q(
"select channel_address from channel where channel_id = %d limit 1",
2021-12-02 23:02:31 +00:00
intval($channel_id)
);
2021-12-03 03:01:39 +00:00
if ($x) {
2021-12-02 23:02:31 +00:00
Libprofile::load($x[0]['channel_address'], 0);
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
}
public function get()
{
$o = '';
2021-12-03 03:01:39 +00:00
if (!App::$profile['profile_uid']) {
2021-12-02 23:02:31 +00:00
return;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$observer_hash = get_observer_hash();
if (!perm_is_allowed(App::$profile['profile_uid'], $observer_hash, 'view_contacts')) {
notice(t('Permission denied.') . EOL);
return;
}
2022-02-14 19:55:01 +00:00
$t = Socgraph::count_common_friends(App::$profile['profile_uid'], $observer_hash);
2021-12-02 23:02:31 +00:00
if (!$t) {
notice(t('No connections in common.') . EOL);
return;
}
2022-02-14 19:55:01 +00:00
$r = Socgraph::common_friends(App::$profile['profile_uid'], $observer_hash);
2021-12-02 23:02:31 +00:00
if ($r) {
foreach ($r as $rr) {
$items[] = [
'url' => $rr['xchan_url'],
'name' => $rr['xchan_name'],
'photo' => $rr['xchan_photo_m'],
'tags' => ''
];
}
}
2022-02-12 20:43:29 +00:00
$tpl = Theme::get_template('common_friends.tpl');
2021-12-02 23:02:31 +00:00
$o = replace_macros($tpl, [
'$title' => t('View Common Connections'),
'$items' => $items
]);
return $o;
}
2016-04-19 03:38:38 +00:00
}