Add and fix some code documentation

This commit is contained in:
Diogo Cordeiro 2018-07-09 23:43:34 +01:00
parent 80b9d1873c
commit fc5b344864
10 changed files with 615 additions and 456 deletions

View File

@ -2,9 +2,7 @@
/** /**
* GNU social - a federating social network * GNU social - a federating social network
* *
* Plugin that handles ActivityPub * ActivityPubPlugin implementation for GNU Social
*
* PHP version 5
* *
* LICENCE: This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU Affero General Public License as published by
@ -23,18 +21,31 @@
* @package GNUsocial * @package GNUsocial
* @author Daniel Supernault <danielsupernault@gmail.com> * @author Daniel Supernault <danielsupernault@gmail.com>
* @author Diogo Cordeiro <diogo@fc.up.pt> * @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 * @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/ * @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 class ActivityPubPlugin extends Plugin
{ {
/**
public function onRouterInitialized(URLMapper $m) * Route/Reroute urls
{ *
* @param URLMapper $m
* @return void
*/
public function onRouterInitialized(URLMapper $m) {
ActivityPubURLMapperOverwrite::overwrite_variable ($m, ':nickname', ActivityPubURLMapperOverwrite::overwrite_variable ($m, ':nickname',
['action' => 'showstream'], ['action' => 'showstream'],
['nickname' => Nickname::DISPLAY_FMT], ['nickname' => Nickname::DISPLAY_FMT],
@ -51,10 +62,22 @@ class ActivityPubPlugin extends Plugin
$m->connect (':nickname/following.json', $m->connect (':nickname/following.json',
['action' => 'apActorFollowing'], ['action' => 'apActorFollowing'],
['nickname' => Nickname::DISPLAY_FMT]); ['nickname' => Nickname::DISPLAY_FMT]);
$m->connect (':nickname/inbox.json',
['action' => 'apActorInbox'],
['nickname' => Nickname::DISPLAY_FMT]);
$m->connect ('inbox.json',
array('action' => 'apSharedInbox'));
} }
public function onPluginVersion(array &$versions) /**
{ * Plugin version information
*
* @param array $versions
* @return boolean true
*/
public function onPluginVersion (array & $versions) {
$versions[] = [ 'name' => 'ActivityPub', $versions[] = [ 'name' => 'ActivityPub',
'version' => GNUSOCIAL_VERSION, 'version' => GNUSOCIAL_VERSION,
'author' => 'Daniel Supernault, Diogo Cordeiro', 'author' => 'Daniel Supernault, Diogo Cordeiro',
@ -62,18 +85,17 @@ class ActivityPubPlugin extends Plugin
'rawdescription' => 'rawdescription' =>
// Todo: Translation // Todo: Translation
'Adds ActivityPub Support']; 'Adds ActivityPub Support'];
return true; return true;
} }
} }
/** /**
* Overwrites variables in URL-mapping * Overwrites variables in URL-mapping
*
*/ */
class ActivityPubURLMapperOverwrite extends URLMapper class ActivityPubURLMapperOverwrite extends URLMapper
{ {
static function overwrite_variable($m, $path, $args, $paramPatterns, $newaction) static function overwrite_variable ($m, $path, $args, $paramPatterns, $newaction) {
{
$mimes = [ $mimes = [
'application/activity+json', 'application/activity+json',
'application/ld+json', 'application/ld+json',
@ -94,16 +116,31 @@ class ActivityPubURLMapperOverwrite extends URLMapper
} }
} }
/**
* Plugin return handler
*/
class ActivityPubReturn class ActivityPubReturn
{ {
static function answer ($res) /**
{ * Return a valid answer
*
* @param array $res
* @return void
*/
static function answer ($res) {
header ('Content-Type: application/activity+json'); header ('Content-Type: application/activity+json');
echo json_encode ($res, JSON_UNESCAPED_SLASHES | (isset ($_GET["pretty"]) ? JSON_PRETTY_PRINT : null)); echo json_encode ($res, JSON_UNESCAPED_SLASHES | (isset ($_GET["pretty"]) ? JSON_PRETTY_PRINT : null));
exit; exit;
} }
static function error ($m, $code=500)
{ /**
* Return an error
*
* @param string $m
* @param int32 $code
* @return void
*/
static function error ($m, $code = 500) {
http_response_code ($code); http_response_code ($code);
header ('Content-Type: application/activity+json'); header ('Content-Type: application/activity+json');
$res[] = Activitypub_error::errorMessageToObject ($m); $res[] = Activitypub_error::errorMessageToObject ($m);

View File

@ -2,9 +2,7 @@
/** /**
* GNU social - a federating social network * GNU social - a federating social network
* *
* Todo: Description * ActivityPubPlugin implementation for GNU Social
*
* PHP version 5
* *
* LICENCE: This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU Affero General Public License as published by
@ -23,20 +21,33 @@
* @package GNUsocial * @package GNUsocial
* @author Diogo Cordeiro <diogo@fc.up.pt> * @author Diogo Cordeiro <diogo@fc.up.pt>
* @author Daniel Supernault <danielsupernault@gmail.com> * @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 * @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 class apActorFollowersAction extends ManagedAction
{ {
protected $needLogin = false; protected $needLogin = false;
protected $canPost = true; protected $canPost = true;
protected function handle() /**
{ * Handle the Followers Collection request
*
* @return void
*/
protected function handle () {
$nickname = $this->trimmed ('nickname'); $nickname = $this->trimmed ('nickname');
try { try {
$user = User::getByNickname ($nickname); $user = User::getByNickname ($nickname);
@ -48,15 +59,17 @@ class apActorFollowersAction extends ManagedAction
$page = intval ($this->trimmed ('page')); $page = intval ($this->trimmed ('page'));
if ($page <= 0) if ($page <= 0) {
ActivityPubReturn::error ('Invalid page number'); ActivityPubReturn::error ('Invalid page number');
}
/* Fetch Followers */ /* Fetch Followers */
try { try {
$since = ($page - 1) * PROFILES_PER_MINILIST; $since = ($page - 1) * PROFILES_PER_MINILIST;
$limit = (($page - 1) == 0 ? 1 : $page) * PROFILES_PER_MINILIST; $limit = (($page - 1) == 0 ? 1 : $page) * PROFILES_PER_MINILIST;
$sub = $profile->getSubscribers ($since, $limit); $sub = $profile->getSubscribers ($since, $limit);
} catch (NoResultException $e) { }
catch(NoResultException $e) {
ActivityPubReturn::error ('This user has no followers'); ActivityPubReturn::error ('This user has no followers');
} }
@ -64,16 +77,19 @@ class apActorFollowersAction extends ManagedAction
$total_subs = $profile->subscriberCount (); $total_subs = $profile->subscriberCount ();
$total_pages = ceil ($total_subs / PROFILES_PER_MINILIST); $total_pages = ceil ($total_subs / PROFILES_PER_MINILIST);
if ($total_pages == 0) if ($total_pages == 0) {
ActivityPubReturn::error ('This user has no followers'); ActivityPubReturn::error ('This user has no followers');
}
if ($page > $total_pages) if ($page > $total_pages) {
ActivityPubReturn::error ("There are only {$total_pages} pages"); ActivityPubReturn::error ("There are only {$total_pages} pages");
}
/* Get followers' URLs */ /* Get followers' URLs */
$subs = []; $subs = array ();
while ($sub->fetch()) while ($sub->fetch ()) {
$subs[] = $this->pretty_sub (clone($sub)); $subs[] = $sub->profileurl;
}
$res = [ $res = [
'@context' => [ '@context' => [
@ -90,9 +106,4 @@ class apActorFollowersAction extends ManagedAction
ActivityPubReturn::answer ($res); ActivityPubReturn::answer ($res);
} }
protected function pretty_sub ($sub_object)
{
return $sub_object->profileurl;
}
} }

View File

@ -2,9 +2,7 @@
/** /**
* GNU social - a federating social network * GNU social - a federating social network
* *
* Todo: Description * ActivityPubPlugin implementation for GNU Social
*
* PHP version 5
* *
* LICENCE: This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU Affero General Public License as published by
@ -23,20 +21,33 @@
* @package GNUsocial * @package GNUsocial
* @author Diogo Cordeiro <diogo@fc.up.pt> * @author Diogo Cordeiro <diogo@fc.up.pt>
* @author Daniel Supernault <danielsupernault@gmail.com> * @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 * @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 class apActorFollowingAction extends ManagedAction
{ {
protected $needLogin = false; protected $needLogin = false;
protected $canPost = true; protected $canPost = true;
protected function handle() /**
{ * Handle the Following Collection request
*
* @return void
*/
protected function handle () {
$nickname = $this->trimmed ('nickname'); $nickname = $this->trimmed ('nickname');
try { try {
$user = User::getByNickname ($nickname); $user = User::getByNickname ($nickname);
@ -48,8 +59,9 @@ class apActorFollowingAction extends ManagedAction
$page = intval ($this->trimmed ('page')); $page = intval ($this->trimmed ('page'));
if ($page <= 0) if ($page <= 0) {
ActivityPubReturn::error ('Invalid page number'); ActivityPubReturn::error ('Invalid page number');
}
/* Fetch Following */ /* Fetch Following */
try { try {
@ -64,16 +76,19 @@ class apActorFollowingAction extends ManagedAction
$total_subs = $profile->subscriptionCount(); $total_subs = $profile->subscriptionCount();
$total_pages = ceil ($total_subs / PROFILES_PER_MINILIST); $total_pages = ceil ($total_subs / PROFILES_PER_MINILIST);
if ($total_pages == 0) if ($total_pages == 0) {
ActivityPubReturn::error ('This user has no followers'); ActivityPubReturn::error ('This user has no followers');
}
if ($page > $total_pages) if ($page > $total_pages) {
ActivityPubReturn::error ("There are only {$total_pages} pages"); ActivityPubReturn::error ("There are only {$total_pages} pages");
}
/* Get followed' URLs */ /* Get followed' URLs */
$subs = []; $subs = array ();
while ($sub->fetch()) while ($sub->fetch ()) {
$subs[] = $this->pretty_sub (clone($sub)); $subs[] = $sub->profileurl;
}
$res = [ $res = [
'@context' => [ '@context' => [
@ -90,9 +105,4 @@ class apActorFollowingAction extends ManagedAction
ActivityPubReturn::answer ($res); ActivityPubReturn::answer ($res);
} }
protected function pretty_sub ($sub_object)
{
return $sub_object->profileurl;
}
} }

View File

@ -2,9 +2,7 @@
/** /**
* GNU social - a federating social network * GNU social - a federating social network
* *
* Todo: Description * ActivityPubPlugin implementation for GNU Social
*
* PHP version 5
* *
* LICENCE: This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU Affero General Public License as published by
@ -23,20 +21,33 @@
* @package GNUsocial * @package GNUsocial
* @author Diogo Cordeiro <diogo@fc.up.pt> * @author Diogo Cordeiro <diogo@fc.up.pt>
* @author Daniel Supernault <danielsupernault@gmail.com> * @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 * @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 class apActorLikedCollectionAction extends ManagedAction
{ {
protected $needLogin = false; protected $needLogin = false;
protected $canPost = true; protected $canPost = true;
protected function handle() /**
{ * Handle the Liked Collection request
*
* @return void
*/
protected function handle () {
$nickname = $this->trimmed ('nickname'); $nickname = $this->trimmed ('nickname');
try { try {
$user = User::getByNickname ($nickname); $user = User::getByNickname ($nickname);
@ -54,13 +65,18 @@ class apActorLikedCollectionAction extends ManagedAction
$since_id = empty ($since_id) ? null : $since_id; $since_id = empty ($since_id) ? null : $since_id;
$max_id = empty ($max_id) ? null : $max_id; $max_id = empty ($max_id) ? null : $max_id;
if ($limit > 80) $limit = 80; // Max is 80 // Max is 80
if ($limit > 80) {
$limit = 80;
}
$fave = $this->fetch_faves ($user->getID(), $limit, $since_id, $max_id); $fave =
$this->fetch_faves($user->getID(), $limit, $since_id, $max_id);
$faves = []; $faves = array();
while ($fave->fetch()) while ($fave->fetch ()) {
$faves[] = $this->pretty_fave (clone ($fave)); $faves[] = $this->pretty_fave (clone ($fave));
}
$res = [ $res = [
'@context' => [ '@context' => [
@ -78,8 +94,14 @@ class apActorLikedCollectionAction extends ManagedAction
ActivityPubReturn::answer ($res); ActivityPubReturn::answer ($res);
} }
protected function pretty_fave ($fave_object) /**
{ * 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, $res = array("uri" => $fave_object->uri,
"created" => $fave_object->created, "created" => $fave_object->created,
"object" => Activitypub_notice::noticeToObject (Notice::getByID ($fave_object->notice_id))); "object" => Activitypub_notice::noticeToObject (Notice::getByID ($fave_object->notice_id)));
@ -87,18 +109,30 @@ class apActorLikedCollectionAction extends ManagedAction
return $res; return $res;
} }
private static function fetch_faves ($user_id, $limit = 40, $since_id = null, $max_id = null) /**
{ * 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 (); $fav = new Fave ();
$fav->user_id = $user_id; $fav->user_id = $user_id;
$fav->orderBy ('modified DESC'); $fav->orderBy ('modified DESC');
if ($since_id != null) if ($since_id != null) {
$fav->whereAdd ("notice_id > {$since_id}"); $fav->whereAdd ("notice_id > {$since_id}");
if ($max_id != null) }
if ($max_id != null) {
$fav->whereAdd ("notice_id < {$max_id}"); $fav->whereAdd ("notice_id < {$max_id}");
}
$fav->limit ($limit); $fav->limit ($limit);

View File

@ -2,9 +2,7 @@
/** /**
* GNU social - a federating social network * GNU social - a federating social network
* *
* Todo: Description * ActivityPubPlugin implementation for GNU Social
*
* PHP version 5
* *
* LICENCE: This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU Affero General Public License as published by
@ -23,25 +21,39 @@
* @package GNUsocial * @package GNUsocial
* @author Daniel Supernault <danielsupernault@gmail.com> * @author Daniel Supernault <danielsupernault@gmail.com>
* @author Diogo Cordeiro <diogo@fc.up.pt> * @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 * @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 class apActorProfileAction extends ManagedAction
{ {
protected $needLogin = false; protected $needLogin = false;
protected $canPost = true; protected $canPost = true;
protected function handle() /**
{ * Handle the Actor Profile request
*
* @return void
*/
protected function handle() {
$nickname = $this->trimmed ('nickname'); $nickname = $this->trimmed ('nickname');
try { try {
$user = User::getByNickname ($nickname); $user = User::getByNickname ($nickname);
$profile = $user->getProfile (); $profile = $user->getProfile ();
} catch (Exception $e) { }
catch (Exception $e) {
ActivityPubReturn::error ('Invalid username', 404); ActivityPubReturn::error ('Invalid username', 404);
} }

View File

@ -2,9 +2,7 @@
/** /**
* GNU social - a federating social network * GNU social - a federating social network
* *
* Todo: Description * ActivityPubPlugin implementation for GNU Social
*
* PHP version 5
* *
* LICENCE: This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU Affero General Public License as published by
@ -23,18 +21,31 @@
* @package GNUsocial * @package GNUsocial
* @author Diogo Cordeiro <diogo@fc.up.pt> * @author Diogo Cordeiro <diogo@fc.up.pt>
* @author Daniel Supernault <danielsupernault@gmail.com> * @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 * @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 class Activitypub_attachment extends Managed_DataObject
{ {
/**
public static function attachmentToObject($attachment) * 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 = [ $res = [
'@context' => [ '@context' => [
"https://www.w3.org/ns/activitystreams", "https://www.w3.org/ns/activitystreams",

View File

@ -2,9 +2,7 @@
/** /**
* GNU social - a federating social network * GNU social - a federating social network
* *
* Todo: Description * ActivityPubPlugin implementation for GNU Social
*
* PHP version 5
* *
* LICENCE: This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU Affero General Public License as published by
@ -23,21 +21,34 @@
* @package GNUsocial * @package GNUsocial
* @author Diogo Cordeiro <diogo@fc.up.pt> * @author Diogo Cordeiro <diogo@fc.up.pt>
* @author Daniel Supernault <danielsupernault@gmail.com> * @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 * @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 class Activitypub_error extends Managed_DataObject
{ {
public static function errorMessageToObject($m) /**
{ * 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 = [ $res = [
'error'=> $m 'error'=> $m
]; ];
return $res; return $res;
} }
} }

View File

@ -2,9 +2,7 @@
/** /**
* GNU social - a federating social network * GNU social - a federating social network
* *
* Todo: Description * ActivityPubPlugin implementation for GNU Social
*
* PHP version 5
* *
* LICENCE: This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU Affero General Public License as published by
@ -23,27 +21,38 @@
* @package GNUsocial * @package GNUsocial
* @author Daniel Supernault <danielsupernault@gmail.com> * @author Daniel Supernault <danielsupernault@gmail.com>
* @author Diogo Cordeiro <diogo@fc.up.pt> * @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 * @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 class Activitypub_notice extends Managed_DataObject
{ {
/**
public static function noticeToObject($notice) * Generates a pretty notice from a Notice object
{ *
$attachments = []; * @param \Notice $notice
foreach ($notice->attachments () as $attachment) * @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); $attachments[] = Activitypub_attachment::attachmentToObject ($attachment);
} }
$tags = []; $tags = array ();
foreach ($notice->getTags () as $tag) foreach($notice->getTags()as $tag) {
{
if ($tag != "") { // Hacky workaround to avoid stupid outputs if ($tag != "") { // Hacky workaround to avoid stupid outputs
$tags[] = Activitypub_tag::tagNameToObject($tag); $tags[] = Activitypub_tag::tagNameToObject($tag);
} }

View File

@ -2,9 +2,7 @@
/** /**
* GNU social - a federating social network * GNU social - a federating social network
* *
* Todo: Description * ActivityPubPlugin implementation for GNU Social
*
* PHP version 5
* *
* LICENCE: This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU Affero General Public License as published by
@ -23,18 +21,31 @@
* @package GNUsocial * @package GNUsocial
* @author Diogo Cordeiro <diogo@fc.up.pt> * @author Diogo Cordeiro <diogo@fc.up.pt>
* @author Daniel Supernault <danielsupernault@gmail.com> * @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 * @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 class Activitypub_profile extends Managed_DataObject
{ {
/**
public static function profileToObject($profile) * 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 (); $url = $profile->getURL ();
$res = [ $res = [
'@context' => [ '@context' => [
@ -48,6 +59,7 @@ class Activitypub_profile extends Managed_DataObject
'nickname' => $profile->getNickname (), 'nickname' => $profile->getNickname (),
'is_local' => $profile->isLocal (), 'is_local' => $profile->isLocal (),
'inbox' => "{$url}/inbox.json", 'inbox' => "{$url}/inbox.json",
'sharedInbox' => common_root_url ()."inbox.json",
'outbox' => "{$url}/outbox.json", 'outbox' => "{$url}/outbox.json",
'display_name' => $profile->getFullname (), 'display_name' => $profile->getFullname (),
'followers' => "{$url}/followers.json", 'followers' => "{$url}/followers.json",

View File

@ -2,9 +2,7 @@
/** /**
* GNU social - a federating social network * GNU social - a federating social network
* *
* Todo: Description * ActivityPubPlugin implementation for GNU Social
*
* PHP version 5
* *
* LICENCE: This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU Affero General Public License as published by
@ -23,17 +21,31 @@
* @package GNUsocial * @package GNUsocial
* @author Diogo Cordeiro <diogo@fc.up.pt> * @author Diogo Cordeiro <diogo@fc.up.pt>
* @author Daniel Supernault <danielsupernault@gmail.com> * @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 * @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 class Activitypub_tag extends Managed_DataObject
{ {
public static function tagNameToObject($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 = [ $res = [
'@context' => [ '@context' => [
"https://www.w3.org/ns/activitystreams", "https://www.w3.org/ns/activitystreams",