streams/Code/Module/Profile.php

133 lines
3.6 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;
2018-09-03 03:16:33 +00:00
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\Lib\ActivityStreams;
use Code\Lib\Activity;
use Code\Lib\Channel;
use Code\Lib\Navbar;
use Code\Lib\Head;
use Code\Extend\Hook;
2016-04-19 03:38:38 +00:00
require_once("include/bbcode.php");
require_once('include/security.php');
require_once('include/conversation.php');
2021-12-02 22:33:36 +00:00
class Profile extends Controller
{
2016-04-19 03:38:38 +00:00
2021-12-02 23:02:31 +00:00
public function init()
{
2021-12-03 03:01:39 +00:00
if (argc() > 1) {
2021-12-02 23:02:31 +00:00
$which = argv(1);
2021-12-03 03:01:39 +00:00
} else {
2021-12-02 23:02:31 +00:00
notice(t('Requested profile is not available.') . EOL);
App::$error = 404;
return;
}
2022-01-25 04:16:38 +00:00
Navbar::set_selected('Profile');
2021-12-02 23:02:31 +00:00
$profile = '';
$channel = App::get_channel();
if ((local_channel()) && (argc() > 2) && (argv(2) === 'view')) {
$which = $channel['channel_address'];
$profile = argv(1);
2021-12-03 03:01:39 +00:00
$r = q(
"select profile_guid from profile where id = %d and uid = %d limit 1",
2021-12-02 23:02:31 +00:00
intval($profile),
intval(local_channel())
);
2021-12-03 03:01:39 +00:00
if (!$r) {
2021-12-02 23:02:31 +00:00
$profile = '';
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$profile = $r[0]['profile_guid'];
}
2022-02-12 21:54:06 +00:00
Head::add_link([
2021-12-02 23:02:31 +00:00
'rel' => 'alternate',
'type' => 'application/atom+xml',
'title' => t('Posts and comments'),
'href' => z_root() . '/feed/' . $which
]);
2022-02-12 21:54:06 +00:00
Head::add_link([
2021-12-02 23:02:31 +00:00
'rel' => 'alternate',
'type' => 'application/atom+xml',
'title' => t('Only posts'),
'href' => z_root() . '/feed/' . $which . '?f=&top=1'
]);
if (!$profile) {
2021-12-03 03:01:39 +00:00
$x = q(
"select channel_id as profile_uid from channel where channel_address = '%s' limit 1",
2021-12-02 23:02:31 +00:00
dbesc(argv(1))
);
if ($x) {
App::$profile = $x[0];
}
}
if (ActivityStreams::is_as_request()) {
2022-01-25 01:26:12 +00:00
$chan = Channel::from_username(argv(1));
2021-12-03 03:01:39 +00:00
if (!$chan) {
2021-12-02 23:02:31 +00:00
http_status_exit(404, 'Not found');
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$p = Activity::encode_person($chan, true, ((get_config('system', 'activitypub', ACTIVITYPUB_ENABLED)) ? true : false));
if (!$p) {
http_status_exit(404, 'Not found');
}
as_return_and_die(['type' => 'Profile', 'describes' => $p], $chan);
}
Libprofile::load($which, $profile);
}
public function get()
{
$groups = [];
$tab = 'profile';
$o = '';
if (!(perm_is_allowed(App::$profile['profile_uid'], get_observer_hash(), 'view_profile'))) {
notice(t('Permission denied.') . EOL);
2022-09-03 05:23:54 +00:00
return '';
2021-12-02 23:02:31 +00:00
}
if (argc() > 2 && argv(2) === 'vcard') {
header('Content-type: text/vcard');
2022-09-03 05:23:54 +00:00
header('Content-Disposition: attachment; filename="' . t('vcard') . '-' . App::$profile['channel_address'] . '.vcf"');
2021-12-02 23:02:31 +00:00
echo App::$profile['profile_vcard'];
killme();
}
$is_owner = ((local_channel()) && (local_channel() == App::$profile['profile_uid']) ? true : false);
if (App::$profile['hidewall'] && (!$is_owner) && (!remote_channel())) {
notice(t('Permission denied.') . EOL);
2022-09-03 05:23:54 +00:00
return '';
2021-12-02 23:02:31 +00:00
}
2022-02-12 21:54:06 +00:00
Head::add_link([
2021-12-02 23:02:31 +00:00
'rel' => 'alternate',
'type' => 'application/json+oembed',
'href' => z_root() . '/oep?f=&url=' . urlencode(z_root() . '/' . App::$query_string),
'title' => 'oembed'
]);
$o .= Libprofile::advanced();
Hook::call('profile_advanced', $o);
2021-12-02 23:02:31 +00:00
return $o;
}
2016-04-19 03:38:38 +00:00
}