diff --git a/ActivityPubPlugin.php b/ActivityPubPlugin.php index 313d017..dc7dd05 100644 --- a/ActivityPubPlugin.php +++ b/ActivityPubPlugin.php @@ -22,6 +22,7 @@ * @category Plugin * @package GNUsocial * @author Daniel Supernault + * @author Diogo Cordeiro * @copyright 2014 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/ @@ -34,16 +35,16 @@ class ActivityPubPlugin extends Plugin public function onRouterInitialized(URLMapper $m) { - $m->connect('api/statuses/user_timeline/:id.ap', - ['action' => 'activitypubactor'], - ['id' => '[0-9]+']); + $m->connect(':nickname/profile.json', + ['action' => 'apActorProfile'], + ['nickname' => Nickname::DISPLAY_FMT]); } public function onPluginVersion(array &$versions) { $versions[] = [ 'name' => 'ActivityPub', 'version' => GNUSOCIAL_VERSION, - 'author' => 'Daniel Supernault', + 'author' => 'Daniel Supernault, Diogo Cordeiro', 'homepage' => 'https://www.gnu.org/software/social/', 'rawdescription' => // Todo: Translation diff --git a/README.md b/README.md index d62738b..aa9e657 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,2 @@ # ActivityPub GNU/Social Plugin - -Warning: This is still a work in progress, not every ActivityPub property is fully implemented yet. \ No newline at end of file +Warning: This is still a work in progress, not every ActivityPub property is fully implemented yet. diff --git a/actions/activitypubactor.php b/actions/apactorprofile.php similarity index 62% rename from actions/activitypubactor.php rename to actions/apactorprofile.php index e6b6467..28abcd6 100644 --- a/actions/activitypubactor.php +++ b/actions/apactorprofile.php @@ -22,6 +22,7 @@ * @category Plugin * @package GNUsocial * @author Daniel Supernault + * @author Diogo Cordeiro * @copyright 2015 Free Software Foundaction, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link https://gnu.io/social @@ -29,18 +30,23 @@ if (!defined('GNUSOCIAL')) { exit(1); } -class ActivityPubActorAction extends ManagedAction +class apActorProfileAction extends ManagedAction { protected $needLogin = false; protected $canPost = true; protected function handle() { - $user = User::getByID($this->trimmed('id')); - $profile = $user->getProfile(); - $url = $profile->profileurl; + $nickname = $this->trimmed('nickname'); + try { + $user = User::getByNickname($nickname); + $profile = $user->getProfile(); + $url = $profile->profileurl; + } catch (Exception $e) { + throw new \Exception('Invalid username'); + } - $avatar = $profile->avatarUrl(AVATAR_PROFILE_SIZE); + $avatar_url = $profile->avatarUrl(AVATAR_PROFILE_SIZE); $res = [ '@context' => [ @@ -49,27 +55,29 @@ class ActivityPubActorAction extends ManagedAction "@language" => "en" ] ], - 'id' => $url, + 'id' => $user->getID(), 'type' => 'Person', - 'following' => "{$url}/subscriptions", + 'username' => $user->nickname, + 'inbox' => "{$url}/inbox.json", + 'outbox' => "{$url}/outbox.json", + 'acct' => null, // TODO: Equals `username` for local users, includes `@domain` for remote ones + 'display_name' => $profile->fullname, 'followers' => "{$url}/subscribers", - 'inbox' => null, - 'outbox' => null, - 'liked' => "{$url}/favorites", - 'preferredUsername' => $user->nickname, - 'name' => $user->nickname, + 'following' => "{$url}/subscriptions", + 'liked' => "{$url}/liked.json", + 'liked_count' => Fave::countByProfile ($profile), 'summary' => $profile->bio, 'url' => $url, - 'icon' => [ + 'avatar' => [ 'type' => 'Image', 'width' => 96, 'height' => 96, - 'url' => $avatar + 'url' => $avatar_url ] ]; header('Content-Type: application/json'); - echo json_encode($res, JSON_PRETTY_PRINT); + echo json_encode($res, isset($_GET["pretty"]) ? JSON_PRETTY_PRINT : null); } } diff --git a/classes/Activitypub_notice.php b/classes/Activitypub_notice.php new file mode 100644 index 0000000..eb25b7d --- /dev/null +++ b/classes/Activitypub_notice.php @@ -0,0 +1,64 @@ +. + * + * @category Plugin + * @package GNUsocial + * @author Daniel Supernault + * @author Diogo Cordeiro + * @copyright 2015 Free Software Foundaction, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link https://gnu.io/social + */ + +if (!defined('GNUSOCIAL')) { exit(1); } + +class Activitypub_notice extends Managed_DataObject +{ + + public static function noticeToObject($notice) + { + // todo: fix timestamp formats + $item = [ + 'id' => $notice->getUrl(), + // TODO: handle other types + 'type' => 'Notice', + 'actor' => $notice->getProfile()->getUrl(), + 'published' => $notice->created, + 'to' => [ + // TODO: handle proper scope + 'https://www.w3.org/ns/activitystreams#Public' + ], + 'cc' => [ + // TODO: add cc's + "{$notice->getProfile()->getUrl()}/subscribers", + ], + 'content' => $notice->getContent(), + 'rendered' => $notice->getRendered(), + 'url' => $notice->getUrl(), + 'reply_to' => empty($notice->reply_to) ? null : Notice::getById($notice->reply_to)->getUrl(), + 'is_local' => $notice->is_local, + 'conversation' => $notice->conversation, + 'attachment' => [], + 'tag' => [] + ]; + return $item; + } +} \ No newline at end of file