Add router overwrite method for actor responses
This commit is contained in:
parent
81b9f17cb1
commit
24e8b1579d
@ -35,6 +35,11 @@ class ActivityPubPlugin extends Plugin
|
||||
|
||||
public function onRouterInitialized(URLMapper $m)
|
||||
{
|
||||
ActivitypubURLMapperOverwrite::overwrite_variable($m, ':nickname',
|
||||
['action' => 'showstream'],
|
||||
['nickname' => Nickname::DISPLAY_FMT],
|
||||
'apactorprofile');
|
||||
|
||||
$m->connect(':nickname/profile.json',
|
||||
['action' => 'apActorProfile'],
|
||||
['nickname' => Nickname::DISPLAY_FMT]);
|
||||
@ -56,3 +61,31 @@ class ActivityPubPlugin extends Plugin
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites variables in URL-mapping
|
||||
*
|
||||
*/
|
||||
class ActivitypubURLMapperOverwrite extends URLMapper
|
||||
{
|
||||
static function overwrite_variable($m, $path, $args, $paramPatterns, $newaction)
|
||||
{
|
||||
$mimes = [
|
||||
'application/activity+json',
|
||||
'application/ld+json',
|
||||
'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
|
||||
];
|
||||
|
||||
if (in_array($_SERVER["HTTP_ACCEPT"], $mimes) == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$m->connect($path, array('action' => $newaction), $paramPatterns);
|
||||
$regex = self::makeRegex($path, $paramPatterns);
|
||||
foreach ($m->variables as $n => $v) {
|
||||
if ($v[1] == $regex) {
|
||||
$m->variables[$n][0]['action'] = $newaction;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user