streams/Code/Module/Fedi_id.php

60 lines
1.7 KiB
PHP
Raw Normal View History

2021-10-16 21:56:36 +00:00
<?php
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2021-10-16 21:56:36 +00:00
2022-02-16 04:08:28 +00:00
use Code\Web\Controller;
use Code\Lib\Channel;
use Code\Render\Theme;
2022-02-12 20:43:29 +00:00
2022-01-25 01:26:12 +00:00
2021-12-02 23:02:31 +00:00
class Fedi_id extends Controller
{
public function post()
{
2022-01-25 01:26:12 +00:00
$channel = Channel::from_id(argv(1));
2021-12-02 23:02:31 +00:00
if (!$channel) {
return;
}
if ($_REQUEST['address']) {
$x = discover_by_webbie(trim($_REQUEST['address']));
if ($x) {
2021-12-03 03:01:39 +00:00
$ab = q(
"select * from abook where abook_xchan = '%s' and abook_channel = %d",
2021-12-02 23:02:31 +00:00
dbesc($x),
intval($channel['channel_id'])
);
if ($ab) {
notice(t('You are already connected with this channel.'));
2022-01-25 01:26:12 +00:00
goaway(Channel::url($channel));
2021-12-02 23:02:31 +00:00
}
2021-12-03 03:01:39 +00:00
$r = q(
"select * from xchan where xchan_hash = '%s'",
2021-12-02 23:02:31 +00:00
dbesc($x)
);
if ($r && $r[0]['xchan_follow']) {
2022-01-25 01:26:12 +00:00
goaway(sprintf($r[0]['xchan_follow'], urlencode(Channel::get_webfinger($channel))));
2021-12-02 23:02:31 +00:00
}
}
notice(t('Unknown or unreachable identifier'));
return;
}
}
public function get()
{
2021-12-03 03:01:39 +00:00
return replace_macros(
2022-02-12 20:43:29 +00:00
Theme::get_template('fedi_id.tpl'),
2021-12-02 23:02:31 +00:00
[
'$title' => t('Home instance'),
'$address' => ['address', t('Enter your channel address or fediverse ID (e.g. channel@example.com)'), '', t('If you do not have a fediverse ID, please use your browser \'back\' button to return to the previous page')],
'$action' => 'fedi_id/' . argv(1),
'$method' => 'post',
'$submit' => t('Connect')
]
);
}
2021-12-03 03:01:39 +00:00
}