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,38 +21,63 @@
* @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
{ *
ActivityPubURLMapperOverwrite::overwrite_variable($m, ':nickname', * @param URLMapper $m
* @return void
*/
public function onRouterInitialized(URLMapper $m) {
ActivityPubURLMapperOverwrite::overwrite_variable ($m, ':nickname',
['action' => 'showstream'], ['action' => 'showstream'],
['nickname' => Nickname::DISPLAY_FMT], ['nickname' => Nickname::DISPLAY_FMT],
'apactorprofile'); 'apactorprofile');
$m->connect(':nickname/liked.json', $m->connect (':nickname/liked.json',
['action' => 'apActorLikedCollection'], ['action' => 'apActorLikedCollection'],
['nickname' => Nickname::DISPLAY_FMT]); ['nickname' => Nickname::DISPLAY_FMT]);
$m->connect(':nickname/followers.json', $m->connect (':nickname/followers.json',
['action' => 'apActorFollowers'], ['action' => 'apActorFollowers'],
['nickname' => Nickname::DISPLAY_FMT]); ['nickname' => Nickname::DISPLAY_FMT]);
$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',
@ -84,7 +106,7 @@ class ActivityPubURLMapperOverwrite extends URLMapper
return true; return true;
} }
$m->connect($path, array('action' => $newaction), $paramPatterns); $m->connect ($path, array('action' => $newaction), $paramPatterns);
$regex = self::makeRegex($path, $paramPatterns); $regex = self::makeRegex($path, $paramPatterns);
foreach ($m->variables as $n => $v) { foreach ($m->variables as $n => $v) {
if ($v[1] == $regex) { if ($v[1] == $regex) {
@ -94,20 +116,35 @@ class ActivityPubURLMapperOverwrite extends URLMapper
} }
} }
/**
* Plugin return handler
*/
class ActivityPubReturn class ActivityPubReturn
{ {
static function answer ($res) /**
{ * Return a valid answer
header('Content-Type: application/activity+json'); *
echo json_encode($res, JSON_UNESCAPED_SLASHES | (isset($_GET["pretty"]) ? JSON_PRETTY_PRINT : null)); * @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; 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);
echo json_encode($res, JSON_UNESCAPED_SLASHES); echo json_encode ($res, JSON_UNESCAPED_SLASHES);
exit; exit;
} }
} }

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,57 +21,75 @@
* @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
$nickname = $this->trimmed('nickname'); *
* @return void
*/
protected function handle () {
$nickname = $this->trimmed ('nickname');
try { try {
$user = User::getByNickname($nickname); $user = User::getByNickname ($nickname);
$profile = $user->getProfile(); $profile = $user->getProfile ();
$url = $profile->profileurl; $url = $profile->profileurl;
} catch (Exception $e) { } catch (Exception $e) {
ActivityPubReturn::error ('Invalid username'); ActivityPubReturn::error ('Invalid username');
} }
$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');
} }
/* Calculate total items */ /* Calculate total items */
$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,57 +21,74 @@
* @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
$nickname = $this->trimmed('nickname'); *
* @return void
*/
protected function handle () {
$nickname = $this->trimmed ('nickname');
try { try {
$user = User::getByNickname($nickname); $user = User::getByNickname ($nickname);
$profile = $user->getProfile(); $profile = $user->getProfile ();
$url = $profile->profileurl; $url = $profile->profileurl;
} catch (Exception $e) { } catch (Exception $e) {
ActivityPubReturn::error ('Invalid username'); ActivityPubReturn::error ('Invalid username');
} }
$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 {
$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->getSubscribed($since, $limit); $sub = $profile->getSubscribed($since, $limit);
} catch (NoResultException $e) { } catch(NoResultException $e) {
ActivityPubReturn::error ('This user is not following anyone'); ActivityPubReturn::error ('This user is not following anyone');
} }
/* Calculate total items */ /* Calculate total items */
$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,44 +21,62 @@
* @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
$nickname = $this->trimmed('nickname'); *
* @return void
*/
protected function handle () {
$nickname = $this->trimmed ('nickname');
try { try {
$user = User::getByNickname($nickname); $user = User::getByNickname ($nickname);
$profile = $user->getProfile(); $profile = $user->getProfile ();
$url = $profile->profileurl; $url = $profile->profileurl;
} catch (Exception $e) { } catch (Exception $e) {
ActivityPubReturn::error ('Invalid username'); ActivityPubReturn::error ('Invalid username');
} }
$limit = intval($this->trimmed('limit')); $limit = intval ($this->trimmed ('limit'));
$since_id = intval($this->trimmed('since_id')); $since_id = intval ($this->trimmed ('since_id'));
$max_id = intval($this->trimmed('max_id')); $max_id = intval ($this->trimmed ('max_id'));
$limit = empty ($limit) ? 40 : $limit; // Default is 40 $limit = empty ($limit) ? 40 : $limit; // Default is 40
$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,31 +94,49 @@ 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
$res = array ("uri" => $fave_object->uri, * 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, "created" => $fave_object->created,
"object" => Activitypub_notice::noticeToObject(Notice::getByID($fave_object->notice_id))); "object" => Activitypub_notice::noticeToObject (Notice::getByID ($fave_object->notice_id)));
return $res; return $res;
} }
private static function fetch_faves ($user_id, $limit = 40, $since_id = null, $max_id = null) /**
{ * Fetch faves
$fav = new Fave(); *
* @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->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) }
$fav->whereAdd("notice_id < {$max_id}");
$fav->limit($limit); if ($max_id != null) {
$fav->whereAdd ("notice_id < {$max_id}");
}
$fav->find(); $fav->limit ($limit);
$fav->find ();
return $fav; return $fav;
} }

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,29 +21,43 @@
* @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
$nickname = $this->trimmed('nickname'); *
* @return void
*/
protected function handle() {
$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);
} }
$res = Activitypub_profile::profileToObject($profile); $res = Activitypub_profile::profileToObject ($profile);
ActivityPubReturn::answer ($res); ActivityPubReturn::answer ($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,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",
@ -51,7 +62,7 @@ class Activitypub_attachment extends Managed_DataObject
]; ];
// Image // Image
if (substr($res["mimetype"], 0, 5) == "image") if (substr ($res["mimetype"], 0, 5) == "image")
{ {
$res["meta"]= [ $res["meta"]= [
'width' => $attachment->width, 'width' => $attachment->width,

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,38 +21,49 @@
* @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);
} }
} }
$to = array (); $to = array ();
foreach ($notice->getAttentionProfileIDs () as $to_id) { foreach ($notice->getAttentionProfileIDs()as $to_id) {
$to[] = Profile::getById ($to_id)->getUri (); $to[] = Profile::getById($to_id)->getUri();
} }
if (!is_null ($to)) { if (!is_null($to)) {
$to = array("https://www.w3.org/ns/activitystreams#Public"); $to = array ("https://www.w3.org/ns/activitystreams#Public");
} }
$item = [ $item = [

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' => [
@ -43,26 +54,27 @@ class Activitypub_profile extends Managed_DataObject
"@language" => "en" "@language" => "en"
] ]
], ],
'id' => $profile->getID(), 'id' => $profile->getID (),
'type' => 'Person', 'type' => 'Person',
'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",
'followers_count' => $profile->subscriberCount(), 'followers_count' => $profile->subscriberCount (),
'following' => "{$url}/following.json", 'following' => "{$url}/following.json",
'following_count' => $profile->subscriptionCount(), 'following_count' => $profile->subscriptionCount (),
'liked' => "{$url}/liked.json", 'liked' => "{$url}/liked.json",
'liked_count' => Fave::countByProfile ($profile), 'liked_count' => Fave::countByProfile ($profile),
'summary' => $profile->getDescription(), 'summary' => $profile->getDescription (),
'url' => $profile->getURL(), 'url' => $profile->getURL (),
'avatar' => [ 'avatar' => [
'type' => 'Image', 'type' => 'Image',
'width' => 96, 'width' => 96,
'height' => 96, 'height' => 96,
'url' => $profile->avatarUrl(AVATAR_PROFILE_SIZE) 'url' => $profile->avatarUrl (AVATAR_PROFILE_SIZE)
] ]
]; ];
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,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",