Add and fix some code documentation
This commit is contained in:
parent
80b9d1873c
commit
fc5b344864
@ -2,9 +2,7 @@
|
||||
/**
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* Plugin that handles ActivityPub
|
||||
*
|
||||
* PHP version 5
|
||||
* ActivityPubPlugin implementation for GNU Social
|
||||
*
|
||||
* LICENCE: This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
@ -23,91 +21,130 @@
|
||||
* @package GNUsocial
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @copyright 2014 Free Software Foundation http://fsf.org
|
||||
* @copyright 2018 Free Software Foundation http://fsf.org
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link https://www.gnu.org/software/social/
|
||||
*/
|
||||
if (!defined ('GNUSOCIAL')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
|
||||
/**
|
||||
* @category Plugin
|
||||
* @package GNUsocial
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://www.gnu.org/software/social/
|
||||
*/
|
||||
class ActivityPubPlugin extends Plugin
|
||||
{
|
||||
/**
|
||||
* Route/Reroute urls
|
||||
*
|
||||
* @param URLMapper $m
|
||||
* @return void
|
||||
*/
|
||||
public function onRouterInitialized(URLMapper $m) {
|
||||
ActivityPubURLMapperOverwrite::overwrite_variable ($m, ':nickname',
|
||||
['action' => 'showstream'],
|
||||
['nickname' => Nickname::DISPLAY_FMT],
|
||||
'apactorprofile');
|
||||
|
||||
public function onRouterInitialized(URLMapper $m)
|
||||
{
|
||||
ActivityPubURLMapperOverwrite::overwrite_variable($m, ':nickname',
|
||||
['action' => 'showstream'],
|
||||
['nickname' => Nickname::DISPLAY_FMT],
|
||||
'apactorprofile');
|
||||
|
||||
$m->connect(':nickname/liked.json',
|
||||
['action' => 'apActorLikedCollection'],
|
||||
['nickname' => Nickname::DISPLAY_FMT]);
|
||||
|
||||
$m->connect(':nickname/followers.json',
|
||||
['action' => 'apActorFollowers'],
|
||||
['nickname' => Nickname::DISPLAY_FMT]);
|
||||
|
||||
$m->connect(':nickname/following.json',
|
||||
['action' => 'apActorFollowing'],
|
||||
['nickname' => Nickname::DISPLAY_FMT]);
|
||||
}
|
||||
$m->connect (':nickname/liked.json',
|
||||
['action' => 'apActorLikedCollection'],
|
||||
['nickname' => Nickname::DISPLAY_FMT]);
|
||||
|
||||
public function onPluginVersion(array &$versions)
|
||||
{
|
||||
$versions[] = [ 'name' => 'ActivityPub',
|
||||
'version' => GNUSOCIAL_VERSION,
|
||||
'author' => 'Daniel Supernault, Diogo Cordeiro',
|
||||
'homepage' => 'https://www.gnu.org/software/social/',
|
||||
'rawdescription' =>
|
||||
// Todo: Translation
|
||||
'Adds ActivityPub Support'];
|
||||
return true;
|
||||
}
|
||||
$m->connect (':nickname/followers.json',
|
||||
['action' => 'apActorFollowers'],
|
||||
['nickname' => Nickname::DISPLAY_FMT]);
|
||||
|
||||
$m->connect (':nickname/following.json',
|
||||
['action' => 'apActorFollowing'],
|
||||
['nickname' => Nickname::DISPLAY_FMT]);
|
||||
|
||||
$m->connect (':nickname/inbox.json',
|
||||
['action' => 'apActorInbox'],
|
||||
['nickname' => Nickname::DISPLAY_FMT]);
|
||||
|
||||
$m->connect ('inbox.json',
|
||||
array('action' => 'apSharedInbox'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin version information
|
||||
*
|
||||
* @param array $versions
|
||||
* @return boolean true
|
||||
*/
|
||||
public function onPluginVersion (array & $versions) {
|
||||
$versions[] = [ 'name' => 'ActivityPub',
|
||||
'version' => GNUSOCIAL_VERSION,
|
||||
'author' => 'Daniel Supernault, Diogo Cordeiro',
|
||||
'homepage' => 'https://www.gnu.org/software/social/',
|
||||
'rawdescription' =>
|
||||
// Todo: Translation
|
||||
'Adds ActivityPub Support'];
|
||||
|
||||
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"'
|
||||
];
|
||||
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 true;
|
||||
if (in_array ($_SERVER["HTTP_ACCEPT"], $mimes) == false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin return handler
|
||||
*/
|
||||
class ActivityPubReturn
|
||||
{
|
||||
static function answer ($res)
|
||||
{
|
||||
header('Content-Type: application/activity+json');
|
||||
echo json_encode($res, JSON_UNESCAPED_SLASHES | (isset($_GET["pretty"]) ? JSON_PRETTY_PRINT : null));
|
||||
exit;
|
||||
}
|
||||
static function error ($m, $code=500)
|
||||
{
|
||||
http_response_code ($code);
|
||||
header('Content-Type: application/activity+json');
|
||||
$res[] = Activitypub_error::errorMessageToObject($m);
|
||||
echo json_encode($res, JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
/**
|
||||
* Return a valid answer
|
||||
*
|
||||
* @param array $res
|
||||
* @return void
|
||||
*/
|
||||
static function answer ($res) {
|
||||
header ('Content-Type: application/activity+json');
|
||||
echo json_encode ($res, JSON_UNESCAPED_SLASHES | (isset ($_GET["pretty"]) ? JSON_PRETTY_PRINT : null));
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an error
|
||||
*
|
||||
* @param string $m
|
||||
* @param int32 $code
|
||||
* @return void
|
||||
*/
|
||||
static function error ($m, $code = 500) {
|
||||
http_response_code ($code);
|
||||
header ('Content-Type: application/activity+json');
|
||||
$res[] = Activitypub_error::errorMessageToObject ($m);
|
||||
echo json_encode ($res, JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,7 @@
|
||||
/**
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* Todo: Description
|
||||
*
|
||||
* PHP version 5
|
||||
* ActivityPubPlugin implementation for GNU Social
|
||||
*
|
||||
* LICENCE: This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
@ -23,76 +21,89 @@
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @copyright 2015 Free Software Foundaction, Inc.
|
||||
* @copyright 2018 Free Software Foundation http://fsf.org
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link https://gnu.io/social
|
||||
* @link https://www.gnu.org/software/social/
|
||||
*/
|
||||
if (!defined ('GNUSOCIAL')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
|
||||
/**
|
||||
* @category Plugin
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://www.gnu.org/software/social/
|
||||
*/
|
||||
class apActorFollowersAction extends ManagedAction
|
||||
{
|
||||
protected $needLogin = false;
|
||||
protected $canPost = true;
|
||||
protected $needLogin = false;
|
||||
protected $canPost = true;
|
||||
|
||||
protected function handle()
|
||||
{
|
||||
$nickname = $this->trimmed('nickname');
|
||||
try {
|
||||
$user = User::getByNickname($nickname);
|
||||
$profile = $user->getProfile();
|
||||
$url = $profile->profileurl;
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error ('Invalid username');
|
||||
/**
|
||||
* Handle the Followers Collection request
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function handle () {
|
||||
$nickname = $this->trimmed ('nickname');
|
||||
try {
|
||||
$user = User::getByNickname ($nickname);
|
||||
$profile = $user->getProfile ();
|
||||
$url = $profile->profileurl;
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error ('Invalid username');
|
||||
}
|
||||
|
||||
$page = intval ($this->trimmed ('page'));
|
||||
|
||||
if ($page <= 0) {
|
||||
ActivityPubReturn::error ('Invalid page number');
|
||||
}
|
||||
|
||||
/* Fetch Followers */
|
||||
try {
|
||||
$since = ($page - 1) * PROFILES_PER_MINILIST;
|
||||
$limit = (($page - 1) == 0 ? 1 : $page) * PROFILES_PER_MINILIST;
|
||||
$sub = $profile->getSubscribers ($since, $limit);
|
||||
}
|
||||
catch(NoResultException $e) {
|
||||
ActivityPubReturn::error ('This user has no followers');
|
||||
}
|
||||
|
||||
/* Calculate total items */
|
||||
$total_subs = $profile->subscriberCount ();
|
||||
$total_pages = ceil ($total_subs / PROFILES_PER_MINILIST);
|
||||
|
||||
if ($total_pages == 0) {
|
||||
ActivityPubReturn::error ('This user has no followers');
|
||||
}
|
||||
|
||||
if ($page > $total_pages) {
|
||||
ActivityPubReturn::error ("There are only {$total_pages} pages");
|
||||
}
|
||||
|
||||
/* Get followers' URLs */
|
||||
$subs = array ();
|
||||
while ($sub->fetch ()) {
|
||||
$subs[] = $sub->profileurl;
|
||||
}
|
||||
|
||||
$res = [
|
||||
'@context' => [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
],
|
||||
'id' => "{$url}/followers.json",
|
||||
'type' => ($page == 0 ? 'OrderedCollection' : 'OrderedCollectionPage'),
|
||||
'totalItems' => $total_subs,
|
||||
'next' => $page+1 > $total_pages ? null : "{$url}/followers.json?page=".($page+1 == 1 ? 2 : $page+1),
|
||||
'prev' => $page == 1 ? null : "{$url}/followers.json?page=".($page-1 <= 0 ? 1 : $page-1),
|
||||
'orderedItems' => $subs
|
||||
];
|
||||
|
||||
ActivityPubReturn::answer ($res);
|
||||
}
|
||||
|
||||
$page = intval($this->trimmed('page'));
|
||||
|
||||
if ($page <= 0)
|
||||
ActivityPubReturn::error ('Invalid page number');
|
||||
|
||||
/* Fetch Followers */
|
||||
try {
|
||||
$since = ($page-1) * PROFILES_PER_MINILIST;
|
||||
$limit = (($page-1) == 0 ? 1 : $page)*PROFILES_PER_MINILIST;
|
||||
$sub = $profile->getSubscribers($since, $limit);
|
||||
} catch (NoResultException $e) {
|
||||
ActivityPubReturn::error ('This user has no followers');
|
||||
}
|
||||
|
||||
/* Calculate total items */
|
||||
$total_subs = $profile->subscriberCount();
|
||||
$total_pages = ceil($total_subs/PROFILES_PER_MINILIST);
|
||||
|
||||
if ($total_pages == 0)
|
||||
ActivityPubReturn::error ('This user has no followers');
|
||||
|
||||
if ($page > $total_pages)
|
||||
ActivityPubReturn::error ("There are only {$total_pages} pages");
|
||||
|
||||
/* Get followers' URLs */
|
||||
$subs = [];
|
||||
while ($sub->fetch())
|
||||
$subs[] = $this->pretty_sub (clone($sub));
|
||||
|
||||
$res = [
|
||||
'@context' => [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
],
|
||||
'id' => "{$url}/followers.json",
|
||||
'type' => ($page == 0 ? 'OrderedCollection' : 'OrderedCollectionPage'),
|
||||
'totalItems' => $total_subs,
|
||||
'next' => $page+1 > $total_pages ? null : "{$url}/followers.json?page=".($page+1 == 1 ? 2 : $page+1),
|
||||
'prev' => $page == 1 ? null : "{$url}/followers.json?page=".($page-1 <= 0 ? 1 : $page-1),
|
||||
'orderedItems' => $subs
|
||||
];
|
||||
|
||||
ActivityPubReturn::answer ($res);
|
||||
}
|
||||
|
||||
protected function pretty_sub ($sub_object)
|
||||
{
|
||||
return $sub_object->profileurl;
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,7 @@
|
||||
/**
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* Todo: Description
|
||||
*
|
||||
* PHP version 5
|
||||
* ActivityPubPlugin implementation for GNU Social
|
||||
*
|
||||
* LICENCE: This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
@ -23,76 +21,88 @@
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @copyright 2015 Free Software Foundaction, Inc.
|
||||
* @copyright 2018 Free Software Foundation http://fsf.org
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link https://gnu.io/social
|
||||
* @link https://www.gnu.org/software/social/
|
||||
*/
|
||||
if (!defined ('GNUSOCIAL')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
|
||||
/**
|
||||
* @category Plugin
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://www.gnu.org/software/social/
|
||||
*/
|
||||
class apActorFollowingAction extends ManagedAction
|
||||
{
|
||||
protected $needLogin = false;
|
||||
protected $canPost = true;
|
||||
protected $needLogin = false;
|
||||
protected $canPost = true;
|
||||
|
||||
protected function handle()
|
||||
{
|
||||
$nickname = $this->trimmed('nickname');
|
||||
try {
|
||||
$user = User::getByNickname($nickname);
|
||||
$profile = $user->getProfile();
|
||||
$url = $profile->profileurl;
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error ('Invalid username');
|
||||
/**
|
||||
* Handle the Following Collection request
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function handle () {
|
||||
$nickname = $this->trimmed ('nickname');
|
||||
try {
|
||||
$user = User::getByNickname ($nickname);
|
||||
$profile = $user->getProfile ();
|
||||
$url = $profile->profileurl;
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error ('Invalid username');
|
||||
}
|
||||
|
||||
$page = intval ($this->trimmed ('page'));
|
||||
|
||||
if ($page <= 0) {
|
||||
ActivityPubReturn::error ('Invalid page number');
|
||||
}
|
||||
|
||||
/* Fetch Following */
|
||||
try {
|
||||
$since = ($page - 1) * PROFILES_PER_MINILIST;
|
||||
$limit = (($page - 1) == 0 ? 1 : $page) * PROFILES_PER_MINILIST;
|
||||
$sub = $profile->getSubscribed($since, $limit);
|
||||
} catch(NoResultException $e) {
|
||||
ActivityPubReturn::error ('This user is not following anyone');
|
||||
}
|
||||
|
||||
/* Calculate total items */
|
||||
$total_subs = $profile->subscriptionCount();
|
||||
$total_pages = ceil ($total_subs / PROFILES_PER_MINILIST);
|
||||
|
||||
if ($total_pages == 0) {
|
||||
ActivityPubReturn::error ('This user has no followers');
|
||||
}
|
||||
|
||||
if ($page > $total_pages) {
|
||||
ActivityPubReturn::error ("There are only {$total_pages} pages");
|
||||
}
|
||||
|
||||
/* Get followed' URLs */
|
||||
$subs = array ();
|
||||
while ($sub->fetch ()) {
|
||||
$subs[] = $sub->profileurl;
|
||||
}
|
||||
|
||||
$res = [
|
||||
'@context' => [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
],
|
||||
'id' => "{$url}/following.json",
|
||||
'type' => ($page == 0 ? 'OrderedCollection' : 'OrderedCollectionPage'),
|
||||
'totalItems' => $total_subs,
|
||||
'next' => $page+1 > $total_pages ? null : "{$url}/followers.json?page=".($page+1 == 1 ? 2 : $page+1),
|
||||
'prev' => $page == 1 ? null : "{$url}/followers.json?page=".($page-1 <= 0 ? 1 : $page-1),
|
||||
'orderedItems' => $subs
|
||||
];
|
||||
|
||||
ActivityPubReturn::answer ($res);
|
||||
}
|
||||
|
||||
$page = intval($this->trimmed('page'));
|
||||
|
||||
if ($page <= 0)
|
||||
ActivityPubReturn::error ('Invalid page number');
|
||||
|
||||
/* Fetch Following */
|
||||
try {
|
||||
$since = ($page-1) * PROFILES_PER_MINILIST;
|
||||
$limit = (($page-1) == 0 ? 1 : $page)*PROFILES_PER_MINILIST;
|
||||
$sub = $profile->getSubscribed($since, $limit);
|
||||
} catch (NoResultException $e) {
|
||||
ActivityPubReturn::error ('This user is not following anyone');
|
||||
}
|
||||
|
||||
/* Calculate total items */
|
||||
$total_subs = $profile->subscriptionCount();
|
||||
$total_pages = ceil($total_subs/PROFILES_PER_MINILIST);
|
||||
|
||||
if ($total_pages == 0)
|
||||
ActivityPubReturn::error ('This user has no followers');
|
||||
|
||||
if ($page > $total_pages)
|
||||
ActivityPubReturn::error ("There are only {$total_pages} pages");
|
||||
|
||||
/* Get followed' URLs */
|
||||
$subs = [];
|
||||
while ($sub->fetch())
|
||||
$subs[] = $this->pretty_sub (clone($sub));
|
||||
|
||||
$res = [
|
||||
'@context' => [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
],
|
||||
'id' => "{$url}/following.json",
|
||||
'type' => ($page == 0 ? 'OrderedCollection' : 'OrderedCollectionPage'),
|
||||
'totalItems' => $total_subs,
|
||||
'next' => $page+1 > $total_pages ? null : "{$url}/followers.json?page=".($page+1 == 1 ? 2 : $page+1),
|
||||
'prev' => $page == 1 ? null : "{$url}/followers.json?page=".($page-1 <= 0 ? 1 : $page-1),
|
||||
'orderedItems' => $subs
|
||||
];
|
||||
|
||||
ActivityPubReturn::answer ($res);
|
||||
}
|
||||
|
||||
protected function pretty_sub ($sub_object)
|
||||
{
|
||||
return $sub_object->profileurl;
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,7 @@
|
||||
/**
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* Todo: Description
|
||||
*
|
||||
* PHP version 5
|
||||
* ActivityPubPlugin implementation for GNU Social
|
||||
*
|
||||
* LICENCE: This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
@ -23,87 +21,123 @@
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @copyright 2015 Free Software Foundaction, Inc.
|
||||
* @copyright 2018 Free Software Foundation http://fsf.org
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link https://gnu.io/social
|
||||
* @link https://www.gnu.org/software/social/
|
||||
*/
|
||||
if (!defined ('GNUSOCIAL')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
|
||||
/**
|
||||
* @category Plugin
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://www.gnu.org/software/social/
|
||||
*/
|
||||
class apActorLikedCollectionAction extends ManagedAction
|
||||
{
|
||||
protected $needLogin = false;
|
||||
protected $canPost = true;
|
||||
protected $needLogin = false;
|
||||
protected $canPost = true;
|
||||
|
||||
protected function handle()
|
||||
{
|
||||
$nickname = $this->trimmed('nickname');
|
||||
try {
|
||||
$user = User::getByNickname($nickname);
|
||||
$profile = $user->getProfile();
|
||||
$url = $profile->profileurl;
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error ('Invalid username');
|
||||
/**
|
||||
* Handle the Liked Collection request
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function handle () {
|
||||
$nickname = $this->trimmed ('nickname');
|
||||
try {
|
||||
$user = User::getByNickname ($nickname);
|
||||
$profile = $user->getProfile ();
|
||||
$url = $profile->profileurl;
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error ('Invalid username');
|
||||
}
|
||||
|
||||
$limit = intval ($this->trimmed ('limit'));
|
||||
$since_id = intval ($this->trimmed ('since_id'));
|
||||
$max_id = intval ($this->trimmed ('max_id'));
|
||||
|
||||
$limit = empty ($limit) ? 40 : $limit; // Default is 40
|
||||
$since_id = empty ($since_id) ? null : $since_id;
|
||||
$max_id = empty ($max_id) ? null : $max_id;
|
||||
|
||||
// Max is 80
|
||||
if ($limit > 80) {
|
||||
$limit = 80;
|
||||
}
|
||||
|
||||
$fave =
|
||||
$this->fetch_faves($user->getID(), $limit, $since_id, $max_id);
|
||||
|
||||
$faves = array();
|
||||
while ($fave->fetch ()) {
|
||||
$faves[] = $this->pretty_fave (clone ($fave));
|
||||
}
|
||||
|
||||
$res = [
|
||||
'@context' => [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
[
|
||||
"@language" => "en"
|
||||
]
|
||||
],
|
||||
'id' => "{$url}/liked.json",
|
||||
'type' => 'OrderedCollection',
|
||||
'totalItems' => Fave::countByProfile ($profile),
|
||||
'orderedItems' => $faves
|
||||
];
|
||||
|
||||
ActivityPubReturn::answer ($res);
|
||||
}
|
||||
|
||||
$limit = intval($this->trimmed('limit'));
|
||||
$since_id = intval($this->trimmed('since_id'));
|
||||
$max_id = intval($this->trimmed('max_id'));
|
||||
/**
|
||||
* Take a fave object and turns it in a pretty array to be used
|
||||
* as a plugin answer
|
||||
*
|
||||
* @param \Fave $fave_object
|
||||
* @return array pretty array representating a Fave
|
||||
*/
|
||||
protected function pretty_fave ($fave_object) {
|
||||
$res = array("uri" => $fave_object->uri,
|
||||
"created" => $fave_object->created,
|
||||
"object" => Activitypub_notice::noticeToObject (Notice::getByID ($fave_object->notice_id)));
|
||||
|
||||
$limit = empty ($limit) ? 40 : $limit; // Default is 40
|
||||
$since_id = empty ($since_id) ? null : $since_id;
|
||||
$max_id = empty ($max_id) ? null : $max_id;
|
||||
return $res;
|
||||
}
|
||||
|
||||
if ($limit > 80) $limit = 80; // Max is 80
|
||||
/**
|
||||
* Fetch faves
|
||||
*
|
||||
* @param int32 $user_id
|
||||
* @param int32 $limit
|
||||
* @param int32 $since_id
|
||||
* @param int32 $max_id
|
||||
* @return \Fave fetchable fave collection
|
||||
*/
|
||||
private static function fetch_faves ($user_id, $limit = 40, $since_id = null,
|
||||
$max_id = null) {
|
||||
$fav = new Fave ();
|
||||
|
||||
$fave = $this->fetch_faves ($user->getID(), $limit, $since_id, $max_id);
|
||||
$fav->user_id = $user_id;
|
||||
|
||||
$faves = [];
|
||||
while ($fave->fetch())
|
||||
$faves[] = $this->pretty_fave (clone($fave));
|
||||
$fav->orderBy ('modified DESC');
|
||||
|
||||
$res = [
|
||||
'@context' => [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
[
|
||||
"@language" => "en"
|
||||
]
|
||||
],
|
||||
'id' => "{$url}/liked.json",
|
||||
'type' => 'OrderedCollection',
|
||||
'totalItems' => Fave::countByProfile ($profile),
|
||||
'orderedItems' => $faves
|
||||
];
|
||||
if ($since_id != null) {
|
||||
$fav->whereAdd ("notice_id > {$since_id}");
|
||||
}
|
||||
|
||||
ActivityPubReturn::answer ($res);
|
||||
}
|
||||
if ($max_id != null) {
|
||||
$fav->whereAdd ("notice_id < {$max_id}");
|
||||
}
|
||||
|
||||
protected function pretty_fave ($fave_object)
|
||||
{
|
||||
$res = array ("uri" => $fave_object->uri,
|
||||
"created" => $fave_object->created,
|
||||
"object" => Activitypub_notice::noticeToObject(Notice::getByID($fave_object->notice_id)));
|
||||
$fav->limit ($limit);
|
||||
|
||||
return $res;
|
||||
}
|
||||
$fav->find ();
|
||||
|
||||
private static function fetch_faves ($user_id, $limit = 40, $since_id = null, $max_id = null)
|
||||
{
|
||||
$fav = new Fave();
|
||||
|
||||
$fav->user_id = $user_id;
|
||||
|
||||
$fav->orderBy('modified DESC');
|
||||
|
||||
if ($since_id != null)
|
||||
$fav->whereAdd("notice_id > {$since_id}");
|
||||
if ($max_id != null)
|
||||
$fav->whereAdd("notice_id < {$max_id}");
|
||||
|
||||
$fav->limit($limit);
|
||||
|
||||
$fav->find();
|
||||
|
||||
return $fav;
|
||||
}
|
||||
return $fav;
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,7 @@
|
||||
/**
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* Todo: Description
|
||||
*
|
||||
* PHP version 5
|
||||
* ActivityPubPlugin implementation for GNU Social
|
||||
*
|
||||
* LICENCE: This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
@ -23,30 +21,44 @@
|
||||
* @package GNUsocial
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @copyright 2015 Free Software Foundaction, Inc.
|
||||
* @copyright 2018 Free Software Foundation http://fsf.org
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link https://gnu.io/social
|
||||
* @link https://www.gnu.org/software/social/
|
||||
*/
|
||||
if (!defined ('GNUSOCIAL')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
|
||||
/**
|
||||
* @category Plugin
|
||||
* @package GNUsocial
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://www.gnu.org/software/social/
|
||||
*/
|
||||
class apActorProfileAction extends ManagedAction
|
||||
{
|
||||
protected $needLogin = false;
|
||||
protected $canPost = true;
|
||||
protected $needLogin = false;
|
||||
protected $canPost = true;
|
||||
|
||||
protected function handle()
|
||||
{
|
||||
$nickname = $this->trimmed('nickname');
|
||||
try {
|
||||
$user = User::getByNickname($nickname);
|
||||
$profile = $user->getProfile();
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error ('Invalid username', 404);
|
||||
/**
|
||||
* Handle the Actor Profile request
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function handle() {
|
||||
$nickname = $this->trimmed ('nickname');
|
||||
try {
|
||||
$user = User::getByNickname ($nickname);
|
||||
$profile = $user->getProfile ();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
ActivityPubReturn::error ('Invalid username', 404);
|
||||
}
|
||||
|
||||
$res = Activitypub_profile::profileToObject ($profile);
|
||||
|
||||
ActivityPubReturn::answer ($res);
|
||||
}
|
||||
|
||||
$res = Activitypub_profile::profileToObject($profile);
|
||||
|
||||
ActivityPubReturn::answer ($res);
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,8 @@
|
||||
/**
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* Todo: Description
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* ActivityPubPlugin implementation for GNU Social
|
||||
*
|
||||
* LICENCE: This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
@ -23,42 +21,55 @@
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @copyright 2015 Free Software Foundaction, Inc.
|
||||
* @copyright 2018 Free Software Foundation http://fsf.org
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link https://gnu.io/social
|
||||
* @link https://www.gnu.org/software/social/
|
||||
*/
|
||||
if (!defined ('GNUSOCIAL')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
|
||||
/**
|
||||
* @category Plugin
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://www.gnu.org/software/social/
|
||||
*/
|
||||
class Activitypub_attachment extends Managed_DataObject
|
||||
{
|
||||
/**
|
||||
* Generates a pretty array from an Attachment object
|
||||
*
|
||||
* @param \Attachment $attachment
|
||||
* @return pretty array to be used in a response
|
||||
*/
|
||||
public static function attachmentToObject ($attachment) {
|
||||
$res = [
|
||||
'@context' => [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
[
|
||||
"@language" => "en"
|
||||
]
|
||||
],
|
||||
'id' => $attachment->getID (),
|
||||
'mimetype' => $attachment->mimetype,
|
||||
'url' => $attachment->getUrl (),
|
||||
'size' => intval($attachment->size), // $attachment->getSize ()
|
||||
'title' => $attachment->getTitle (),
|
||||
'meta' => null
|
||||
];
|
||||
|
||||
public static function attachmentToObject($attachment)
|
||||
{
|
||||
$res = [
|
||||
'@context' => [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
[
|
||||
"@language" => "en"
|
||||
]
|
||||
],
|
||||
'id' => $attachment->getID (),
|
||||
'mimetype' => $attachment->mimetype,
|
||||
'url' => $attachment->getUrl (),
|
||||
'size' => intval($attachment->size), // $attachment->getSize ()
|
||||
'title' => $attachment->getTitle (),
|
||||
'meta' => null
|
||||
];
|
||||
|
||||
// Image
|
||||
if (substr($res["mimetype"], 0, 5) == "image")
|
||||
{
|
||||
$res["meta"]= [
|
||||
'width' => $attachment->width,
|
||||
'height' => $attachment->height
|
||||
];
|
||||
}
|
||||
// Image
|
||||
if (substr ($res["mimetype"], 0, 5) == "image")
|
||||
{
|
||||
$res["meta"]= [
|
||||
'width' => $attachment->width,
|
||||
'height' => $attachment->height
|
||||
];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,8 @@
|
||||
/**
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* Todo: Description
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* ActivityPubPlugin implementation for GNU Social
|
||||
*
|
||||
* LICENCE: This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
@ -23,21 +21,34 @@
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @copyright 2015 Free Software Foundaction, Inc.
|
||||
* @copyright 2018 Free Software Foundation http://fsf.org
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link https://gnu.io/social
|
||||
* @link https://www.gnu.org/software/social/
|
||||
*/
|
||||
if (!defined ('GNUSOCIAL')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
|
||||
/**
|
||||
* @category Plugin
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://www.gnu.org/software/social/
|
||||
*/
|
||||
class Activitypub_error extends Managed_DataObject
|
||||
{
|
||||
public static function errorMessageToObject($m)
|
||||
{
|
||||
$res = [
|
||||
'error'=> $m
|
||||
];
|
||||
|
||||
return $res;
|
||||
}
|
||||
/**
|
||||
* Generates a pretty error from a string
|
||||
*
|
||||
* @param string $m
|
||||
* @return pretty array to be used in a response
|
||||
*/
|
||||
public static function errorMessageToObject ($m) {
|
||||
$res = [
|
||||
'error'=> $m
|
||||
];
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,7 @@
|
||||
/**
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* Todo: Description
|
||||
*
|
||||
* PHP version 5
|
||||
* ActivityPubPlugin implementation for GNU Social
|
||||
*
|
||||
* LICENCE: This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
@ -23,55 +21,66 @@
|
||||
* @package GNUsocial
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @copyright 2015 Free Software Foundaction, Inc.
|
||||
* @copyright 2018 Free Software Foundation http://fsf.org
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link https://gnu.io/social
|
||||
* @link https://www.gnu.org/software/social/
|
||||
*/
|
||||
if (!defined ('GNUSOCIAL')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
|
||||
/**
|
||||
* @category Plugin
|
||||
* @package GNUsocial
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://www.gnu.org/software/social/
|
||||
*/
|
||||
class Activitypub_notice extends Managed_DataObject
|
||||
{
|
||||
/**
|
||||
* Generates a pretty notice from a Notice object
|
||||
*
|
||||
* @param \Notice $notice
|
||||
* @return pretty array to be used in a response
|
||||
*/
|
||||
public static function noticeToObject($notice) {
|
||||
$attachments = array ();
|
||||
foreach($notice->attachments()as $attachment) {
|
||||
$attachments[] = Activitypub_attachment::attachmentToObject ($attachment);
|
||||
}
|
||||
|
||||
public static function noticeToObject($notice)
|
||||
{
|
||||
$attachments = [];
|
||||
foreach ($notice->attachments () as $attachment)
|
||||
{
|
||||
$attachments[] = Activitypub_attachment::attachmentToObject ($attachment);
|
||||
}
|
||||
$tags = array ();
|
||||
foreach($notice->getTags()as $tag) {
|
||||
if ($tag != "") { // Hacky workaround to avoid stupid outputs
|
||||
$tags[] = Activitypub_tag::tagNameToObject($tag);
|
||||
}
|
||||
}
|
||||
|
||||
$tags = [];
|
||||
foreach ($notice->getTags () as $tag)
|
||||
{
|
||||
if ($tag != "") { // Hacky workaround to avoid stupid outputs
|
||||
$tags[] = Activitypub_tag::tagNameToObject ($tag);
|
||||
}
|
||||
}
|
||||
|
||||
$to = array ();
|
||||
foreach ($notice->getAttentionProfileIDs () as $to_id) {
|
||||
$to[] = Profile::getById ($to_id)->getUri ();
|
||||
}
|
||||
if (!is_null ($to)) {
|
||||
$to = array("https://www.w3.org/ns/activitystreams#Public");
|
||||
$to = array ();
|
||||
foreach ($notice->getAttentionProfileIDs()as $to_id) {
|
||||
$to[] = Profile::getById($to_id)->getUri();
|
||||
}
|
||||
if (!is_null($to)) {
|
||||
$to = array ("https://www.w3.org/ns/activitystreams#Public");
|
||||
}
|
||||
|
||||
$item = [
|
||||
'id' => $notice->getUrl (),
|
||||
'type' => 'Notice',
|
||||
'actor' => $notice->getProfile ()->getUrl (),
|
||||
'published' => $notice->getCreated (),
|
||||
'to' => $to,
|
||||
'content' => $notice->getContent (),
|
||||
'url' => $notice->getUrl (),
|
||||
'reply_to' => empty($notice->reply_to) ? null : Notice::getById($notice->reply_to)->getUrl (),
|
||||
'is_local' => $notice->isLocal (),
|
||||
'conversation' => intval ($notice->conversation),
|
||||
'attachment' => $attachments,
|
||||
'tag' => $tags
|
||||
];
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
$item = [
|
||||
'id' => $notice->getUrl (),
|
||||
'type' => 'Notice',
|
||||
'actor' => $notice->getProfile ()->getUrl (),
|
||||
'published' => $notice->getCreated (),
|
||||
'to' => $to,
|
||||
'content' => $notice->getContent (),
|
||||
'url' => $notice->getUrl (),
|
||||
'reply_to' => empty($notice->reply_to) ? null : Notice::getById($notice->reply_to)->getUrl (),
|
||||
'is_local' => $notice->isLocal (),
|
||||
'conversation' => intval ($notice->conversation),
|
||||
'attachment' => $attachments,
|
||||
'tag' => $tags
|
||||
];
|
||||
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,7 @@
|
||||
/**
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* Todo: Description
|
||||
*
|
||||
* PHP version 5
|
||||
* ActivityPubPlugin implementation for GNU Social
|
||||
*
|
||||
* LICENCE: This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
@ -23,48 +21,62 @@
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @copyright 2015 Free Software Foundaction, Inc.
|
||||
* @copyright 2018 Free Software Foundation http://fsf.org
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link https://gnu.io/social
|
||||
* @link https://www.gnu.org/software/social/
|
||||
*/
|
||||
if (!defined ('GNUSOCIAL')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
|
||||
/**
|
||||
* @category Plugin
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://www.gnu.org/software/social/
|
||||
*/
|
||||
class Activitypub_profile extends Managed_DataObject
|
||||
{
|
||||
|
||||
public static function profileToObject($profile)
|
||||
{
|
||||
$url = $profile->getURL ();
|
||||
$res = [
|
||||
'@context' => [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
[
|
||||
"@language" => "en"
|
||||
]
|
||||
],
|
||||
'id' => $profile->getID(),
|
||||
'type' => 'Person',
|
||||
'nickname' => $profile->getNickname (),
|
||||
'is_local' => $profile->isLocal(),
|
||||
'inbox' => "{$url}/inbox.json",
|
||||
'outbox' => "{$url}/outbox.json",
|
||||
'display_name' => $profile->getFullname(),
|
||||
'followers' => "{$url}/followers.json",
|
||||
'followers_count' => $profile->subscriberCount(),
|
||||
'following' => "{$url}/following.json",
|
||||
'following_count' => $profile->subscriptionCount(),
|
||||
'liked' => "{$url}/liked.json",
|
||||
'liked_count' => Fave::countByProfile ($profile),
|
||||
'summary' => $profile->getDescription(),
|
||||
'url' => $profile->getURL(),
|
||||
'avatar' => [
|
||||
'type' => 'Image',
|
||||
'width' => 96,
|
||||
'height' => 96,
|
||||
'url' => $profile->avatarUrl(AVATAR_PROFILE_SIZE)
|
||||
]
|
||||
];
|
||||
return $res;
|
||||
}
|
||||
/**
|
||||
* Generates a pretty profile from a Profile object
|
||||
*
|
||||
* @param \Profile $profile
|
||||
* @return pretty array to be used in a response
|
||||
*/
|
||||
public static function profileToObject($profile) {
|
||||
$url = $profile->getURL ();
|
||||
$res = [
|
||||
'@context' => [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
[
|
||||
"@language" => "en"
|
||||
]
|
||||
],
|
||||
'id' => $profile->getID (),
|
||||
'type' => 'Person',
|
||||
'nickname' => $profile->getNickname (),
|
||||
'is_local' => $profile->isLocal (),
|
||||
'inbox' => "{$url}/inbox.json",
|
||||
'sharedInbox' => common_root_url ()."inbox.json",
|
||||
'outbox' => "{$url}/outbox.json",
|
||||
'display_name' => $profile->getFullname (),
|
||||
'followers' => "{$url}/followers.json",
|
||||
'followers_count' => $profile->subscriberCount (),
|
||||
'following' => "{$url}/following.json",
|
||||
'following_count' => $profile->subscriptionCount (),
|
||||
'liked' => "{$url}/liked.json",
|
||||
'liked_count' => Fave::countByProfile ($profile),
|
||||
'summary' => $profile->getDescription (),
|
||||
'url' => $profile->getURL (),
|
||||
'avatar' => [
|
||||
'type' => 'Image',
|
||||
'width' => 96,
|
||||
'height' => 96,
|
||||
'url' => $profile->avatarUrl (AVATAR_PROFILE_SIZE)
|
||||
]
|
||||
];
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,7 @@
|
||||
/**
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* Todo: Description
|
||||
*
|
||||
* PHP version 5
|
||||
* ActivityPubPlugin implementation for GNU Social
|
||||
*
|
||||
* LICENCE: This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
@ -23,28 +21,42 @@
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @copyright 2015 Free Software Foundaction, Inc.
|
||||
* @copyright 2018 Free Software Foundation http://fsf.org
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link https://gnu.io/social
|
||||
* @link https://www.gnu.org/software/social/
|
||||
*/
|
||||
if (!defined ('GNUSOCIAL')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
|
||||
/**
|
||||
* @category Plugin
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://www.gnu.org/software/social/
|
||||
*/
|
||||
class Activitypub_tag extends Managed_DataObject
|
||||
{
|
||||
public static function tagNameToObject($tag)
|
||||
{
|
||||
$res = [
|
||||
'@context' => [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
[
|
||||
"@language" => "en"
|
||||
]
|
||||
],
|
||||
'name' => $tag,
|
||||
'url' => common_local_url('tag', array('tag' => $tag))
|
||||
];
|
||||
/**
|
||||
* Generates a pretty tag from a Tag object
|
||||
*
|
||||
* @param \Tag $tag
|
||||
* @return pretty array to be used in a response
|
||||
*/
|
||||
public static function tagNameToObject ($tag) {
|
||||
$res = [
|
||||
'@context' => [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
[
|
||||
"@language" => "en"
|
||||
]
|
||||
],
|
||||
'name' => $tag,
|
||||
'url' => common_local_url('tag', array('tag' => $tag))
|
||||
];
|
||||
|
||||
return $res;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user