Add Feature inbox
This commit is contained in:
parent
08ec02561a
commit
15fab762b5
@ -45,7 +45,7 @@ class ActivityPubPlugin extends Plugin
|
||||
* @param URLMapper $m
|
||||
* @return void
|
||||
*/
|
||||
public function onRouterInitialized(URLMapper $m) {
|
||||
public function onRouterInitialized (URLMapper $m) {
|
||||
ActivityPubURLMapperOverwrite::overwrite_variable ($m, ':nickname',
|
||||
['action' => 'showstream'],
|
||||
['nickname' => Nickname::DISPLAY_FMT],
|
||||
@ -77,7 +77,7 @@ class ActivityPubPlugin extends Plugin
|
||||
* @param array $versions
|
||||
* @return boolean true
|
||||
*/
|
||||
public function onPluginVersion (array & $versions) {
|
||||
public function onPluginVersion (array &$versions) {
|
||||
$versions[] = [ 'name' => 'ActivityPub',
|
||||
'version' => GNUSOCIAL_VERSION,
|
||||
'author' => 'Daniel Supernault, Diogo Cordeiro',
|
||||
@ -90,32 +90,6 @@ class ActivityPubPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites variables in URL-mapping
|
||||
*/
|
||||
class ActivityPubURLMapperOverwrite extends URLMapper
|
||||
{
|
||||
static function overwrite_variable ($m, $path, $args, $paramPatterns, $newaction) {
|
||||
$mimes = [
|
||||
'application/activity+json',
|
||||
'application/ld+json',
|
||||
'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
|
||||
];
|
||||
|
||||
if (in_array ($_SERVER["HTTP_ACCEPT"], $mimes) == false) {
|
||||
return 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin return handler
|
||||
*/
|
||||
|
@ -57,7 +57,11 @@ class apActorFollowersAction extends ManagedAction
|
||||
ActivityPubReturn::error ('Invalid username');
|
||||
}
|
||||
|
||||
$page = intval ($this->trimmed ('page'));
|
||||
if (!isset ($_GET["page"])) {
|
||||
$page = 1;
|
||||
} else {
|
||||
$page = intval ($this->trimmed ('page'));
|
||||
}
|
||||
|
||||
if ($page <= 0) {
|
||||
ActivityPubReturn::error ('Invalid page number');
|
||||
|
@ -57,7 +57,11 @@ class apActorFollowingAction extends ManagedAction
|
||||
ActivityPubReturn::error ('Invalid username');
|
||||
}
|
||||
|
||||
$page = intval ($this->trimmed ('page'));
|
||||
if (!isset ($_GET["page"])) {
|
||||
$page = 1;
|
||||
} else {
|
||||
$page = intval ($this->trimmed ('page'));
|
||||
}
|
||||
|
||||
if ($page <= 0) {
|
||||
ActivityPubReturn::error ('Invalid page number');
|
||||
|
105
actions/apactorinbox.php
Normal file
105
actions/apactorinbox.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
require_once dirname (__DIR__) . DIRECTORY_SEPARATOR . "utils" . DIRECTORY_SEPARATOR . "discovery.php";
|
||||
use Activitypub_Discovery;
|
||||
|
||||
/**
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* Todo: Description
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @category Plugin
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @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 apActorInboxAction extends ManagedAction
|
||||
{
|
||||
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.");
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
ActivityPubReturn::error ("C2S not implemented just yet.");
|
||||
}
|
||||
|
||||
$data = json_decode (file_get_contents ('php://input'));
|
||||
|
||||
// Validate data
|
||||
if (!(isset($data->type))) {
|
||||
ActivityPubReturn::error ("Type was not specified.");
|
||||
}
|
||||
if (!isset($data->actor)) {
|
||||
ActivityPubReturn::error ("Actor was not specified.");
|
||||
}
|
||||
if (!isset($data->object)) {
|
||||
ActivityPubReturn::error ("Object was not specified.");
|
||||
}
|
||||
|
||||
// Get valid Actor object
|
||||
try {
|
||||
require_once dirname (__DIR__) . DIRECTORY_SEPARATOR . "utils" . DIRECTORY_SEPARATOR . "discovery.php";
|
||||
$actor_profile = new Activitypub_Discovery;
|
||||
$actor_profile = $actor_profile->lookup($data->actor);
|
||||
$actor_profile = $actor_profile[0];
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error ("Invalid Actor.", 404);
|
||||
}
|
||||
|
||||
$to_profiles = array ($user);
|
||||
|
||||
// Process request
|
||||
switch ($data->type) {
|
||||
case "Create":
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Create.php";
|
||||
break;
|
||||
case "Delete":
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Delete.php";
|
||||
break;
|
||||
case "Follow":
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Follow.php";
|
||||
break;
|
||||
case "Like":
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Like.php";
|
||||
break;
|
||||
case "Undo":
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Undo.php";
|
||||
break;
|
||||
case "Announce":
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Announce.php";
|
||||
break;
|
||||
default:
|
||||
ActivityPubReturn::error ("Invalid type value.");
|
||||
}
|
||||
}
|
||||
}
|
@ -70,8 +70,7 @@ class apActorLikedCollectionAction extends ManagedAction
|
||||
$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 = array();
|
||||
while ($fave->fetch ()) {
|
||||
|
122
actions/apsharedinbox.php
Normal file
122
actions/apsharedinbox.php
Normal file
@ -0,0 +1,122 @@
|
||||
<?php
|
||||
require_once dirname (__DIR__) . DIRECTORY_SEPARATOR . "utils" . DIRECTORY_SEPARATOR . "discovery.php";
|
||||
use Activitypub_Discovery;
|
||||
use ActivityPubReturn;
|
||||
use Activitypub_notice;
|
||||
|
||||
/**
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* Todo: Description
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @category Plugin
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @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 apSharedInboxAction extends ManagedAction
|
||||
{
|
||||
protected $needLogin = false;
|
||||
protected $canPost = true;
|
||||
|
||||
protected function handle ()
|
||||
{
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
ActivityPubReturn::error ("Only POST requests allowed.");
|
||||
}
|
||||
|
||||
$data = json_decode (file_get_contents ('php://input'));
|
||||
|
||||
// Validate data
|
||||
if (!(isset($data->type))) {
|
||||
ActivityPubReturn::error ("Type was not specified.");
|
||||
}
|
||||
if (!isset($data->actor)) {
|
||||
ActivityPubReturn::error ("Actor was not specified.");
|
||||
}
|
||||
if (!isset($data->to)) {
|
||||
ActivityPubReturn::error ("To was not specified.");
|
||||
}
|
||||
if (!isset($data->object)) {
|
||||
ActivityPubReturn::error ("Object was not specified.");
|
||||
}
|
||||
|
||||
$discovery = new Activitypub_Discovery;
|
||||
|
||||
// Get valid Actor object
|
||||
try {
|
||||
$actor_profile = $discovery->lookup ($data->actor);
|
||||
$actor_profile = $actor_profile[0];
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error ("Invalid Actor.", 404);
|
||||
}
|
||||
|
||||
// Public To:
|
||||
$public_to = array ("https://www.w3.org/ns/activitystreams#Public",
|
||||
"Public",
|
||||
"as:Public");
|
||||
|
||||
$to_profiles = array ();
|
||||
// Generate To objects
|
||||
if (is_array ($data->to)) {
|
||||
// Remove duplicates from To actors set
|
||||
array_unique ($data->to);
|
||||
foreach ($data->to as $to_url) {
|
||||
try {
|
||||
$to_profiles = array_merge ($to_profiles, $discovery->lookup ($to_url));
|
||||
} catch (Exception $e) {
|
||||
// XXX: Invalid actor found, not sure how we handle those
|
||||
}
|
||||
}
|
||||
} else if (empty ($data->to)
|
||||
|| in_array ($data->to, $public_to)) {
|
||||
// No need to do anything else at this point, let's just break out the if
|
||||
} else {
|
||||
try {
|
||||
$to_profiles[]= $discovery->lookup ($data->to);
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error ("Invalid Actor.", 404);
|
||||
}
|
||||
}
|
||||
unset ($discovery);
|
||||
|
||||
// Process request
|
||||
switch ($data->type) {
|
||||
case "Create":
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Create.php";
|
||||
break;
|
||||
case "Follow":
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Follow.php";
|
||||
break;
|
||||
case "Like":
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Like.php";
|
||||
break;
|
||||
case "Announce":
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Announce.php";
|
||||
break;
|
||||
default:
|
||||
ActivityPubReturn::error ("Invalid type value.");
|
||||
}
|
||||
}
|
||||
}
|
37
actions/inbox/Announce.php
Normal file
37
actions/inbox/Announce.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @category Plugin
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @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);
|
||||
}
|
||||
|
||||
try {
|
||||
Notice::getByUri ($data->object)->repeat ($actor_profile, "api");
|
||||
ActivityPubReturn::answer ("Notice repeated successfully.");
|
||||
} catch(Exception $ex) {
|
||||
ActivityPubReturn::error ($ex->getMessage (), 403);
|
||||
}
|
93
actions/inbox/Create.php
Normal file
93
actions/inbox/Create.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @category Plugin
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @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);
|
||||
}
|
||||
|
||||
$valid_object_types = array ("Note");
|
||||
|
||||
// Validate data
|
||||
if (! (isset($data->object->type) && in_array ($data->object->type, $valid_object_types))) {
|
||||
ActivityPubReturn::error ("Invalid Object type.");
|
||||
}
|
||||
if (!isset ($data->object->content)) {
|
||||
ActivityPubReturn::error ("Object content was not specified.");
|
||||
}
|
||||
|
||||
$content = $data->object->content;
|
||||
|
||||
$act = new Activity ();
|
||||
$act->verb = ActivityVerb::POST;
|
||||
$act->time = time ();
|
||||
$act->actor = $actor_profile->asActivityObject ();
|
||||
|
||||
$act->context = new ActivityContext ();
|
||||
|
||||
// Is this a reply?
|
||||
if (isset ($data->object->reply_to)) {
|
||||
$reply_to = Notice::getByUri ($data->object->reply_to);
|
||||
$act->context->replyToID = $reply_to->getUri ();
|
||||
$act->context->replyToUrl = $data->object->reply_to;
|
||||
} else {
|
||||
$reply_to = null;
|
||||
}
|
||||
|
||||
$act->context->attention = common_get_attentions($content, $actor_profile, $reply_to);
|
||||
|
||||
foreach ($to_profiles as $to)
|
||||
{
|
||||
$act->context->attention[$to->getUri()] = "http://activitystrea.ms/schema/1.0/person";
|
||||
}
|
||||
|
||||
// Reject notice if it is too long (without the HTML)
|
||||
// This is done after MediaFile::fromUpload etc. just to act the same as the ApiStatusesUpdateAction
|
||||
if (Notice::contentTooLong ($content)) {
|
||||
ActivityPubReturn::error ("That's too long. Maximum notice size is %d character.");
|
||||
}
|
||||
|
||||
$options = array('source' = >'web', 'uri' = >$data->id);
|
||||
// $options gets filled with possible scoping settings
|
||||
ToSelector::fillActivity ($this, $act, $options);
|
||||
|
||||
$actobj = new ActivityObject ();
|
||||
$actobj->type = ActivityObject::NOTE;
|
||||
$actobj->content = common_render_content ($content, $actor_profile, $reply_to);
|
||||
|
||||
// Finally add the activity object to our activity
|
||||
$act->objects[] = $actobj;
|
||||
|
||||
try {
|
||||
$res = array ("@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"id" => $data->id,
|
||||
"type" => "Create",
|
||||
"actor" => $data->actor,
|
||||
"object" => Activitypub_notice::noticeToObject (Notice::saveActivity ($act, $actor_profile, $options)));
|
||||
ActivityPubReturn::answer ($res);
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error ($e->getMessage ());
|
||||
}
|
37
actions/inbox/Delete.php
Normal file
37
actions/inbox/Delete.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @category Plugin
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @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);
|
||||
}
|
||||
|
||||
try {
|
||||
Activitypub_notice::getByUri ($data->object)->deleteAs ($actor_profile);
|
||||
ActivityPubReturn::answer ("Notice deleted successfully.");
|
||||
} catch(Exception $ex) {
|
||||
ActivityPubReturn::error ($ex->getMessage(), 403);
|
||||
}
|
49
actions/inbox/Follow.php
Normal file
49
actions/inbox/Follow.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @category Plugin
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @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);
|
||||
}
|
||||
|
||||
// Get valid Object profile
|
||||
try {
|
||||
$object_profile = new Activitypub_Discovery;
|
||||
$object_profile = $object_profile->lookup ($data->object);
|
||||
} catch(Exception $e) {
|
||||
ActivityPubReturn::error ("Invalid Object Actor URL.", 404);
|
||||
}
|
||||
|
||||
try {
|
||||
if (!Subscription::exists ($actor_profile, $object_profile)) {
|
||||
Subscription::start ($actor_profile, $object_profile);
|
||||
ActivityPubReturn::answer ("You are now following this person.");
|
||||
} else {
|
||||
ActivityPubReturn::error ("Already following.", 409);
|
||||
}
|
||||
} catch(Exception $ex) {
|
||||
ActivityPubReturn::error ("Invalid Object Actor URL.", 404);
|
||||
}
|
37
actions/inbox/Like.php
Normal file
37
actions/inbox/Like.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @category Plugin
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @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);
|
||||
}
|
||||
|
||||
try {
|
||||
Fave::addNew ($actor_profile, Notice::getByUri ($data->object));
|
||||
ActivityPubReturn::answer ("Notice favorited successfully.");
|
||||
} catch (Exception $ex) {
|
||||
ActivityPubReturn::error ($ex->getMessage (), 403);
|
||||
}
|
81
actions/inbox/Undo.php
Normal file
81
actions/inbox/Undo.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
use Activitypub_Discovery;
|
||||
|
||||
/**
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @category Plugin
|
||||
* @package GNUsocial
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||
* @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);
|
||||
}
|
||||
|
||||
// Validate data
|
||||
if (!isset ($data->type)) {
|
||||
ActivityPubReturn::error ("Type was not specified.");
|
||||
}
|
||||
|
||||
switch ($data->object->type) {
|
||||
case "Like":
|
||||
try {
|
||||
// Validate data
|
||||
if (!isset ($data->object->object)) {
|
||||
ActivityPubReturn::error ("Object Notice URL was not specified.");
|
||||
}
|
||||
|
||||
Fave::removeEntry ($actor_profile, Notice::getByUri($data->object->object));
|
||||
ActivityPubReturn::answer ("Notice disfavorited successfully.");
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error ($e->getMessage(), 403);
|
||||
}
|
||||
break;
|
||||
case "Follow":
|
||||
// Validate data
|
||||
if (!isset ($data->object->object)) {
|
||||
ActivityPubReturn::error ("Object Actor URL was not specified.");
|
||||
}
|
||||
// Get valid Object profile
|
||||
try {
|
||||
$object_profile = new Activitypub_Discovery;
|
||||
$object_profile = $object_profile->lookup ($data->object->object);
|
||||
} catch (Exception $e) {
|
||||
ActivityPubReturn::error ("Invalid Object Actor URL.", 404);
|
||||
}
|
||||
|
||||
try {
|
||||
if (Subscription::exists ($actor_profile, $object_profile)) {
|
||||
Subscription::cancel ($actor_profile, $object_profile);
|
||||
ActivityPubReturn::answer ("You are no longer following this person.");
|
||||
} else {
|
||||
ActivityPubReturn::error ("You are not following this person already.", 409);
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
ActivityPubReturn::error ("Invalid Object Actor URL.", 404);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ActivityPubReturn::error ("Invalid object type.");
|
||||
break;
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* 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
|
||||
@ -26,7 +26,7 @@
|
||||
* @link https://www.gnu.org/software/social/
|
||||
*/
|
||||
if (!defined ('GNUSOCIAL')) {
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,37 +39,37 @@ if (!defined ('GNUSOCIAL')) {
|
||||
*/
|
||||
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
|
||||
];
|
||||
/**
|
||||
* 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
|
||||
];
|
||||
|
||||
// Image
|
||||
if (substr ($res["mimetype"], 0, 5) == "image")
|
||||
{
|
||||
$res["meta"]= [
|
||||
// Image
|
||||
if (substr ($res["mimetype"], 0, 5) == "image")
|
||||
{
|
||||
$res["meta"]= [
|
||||
'width' => $attachment->width,
|
||||
'height' => $attachment->height
|
||||
];
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
* GNU social - a federating social network
|
||||
*
|
||||
* 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
|
||||
@ -45,10 +45,10 @@ class Activitypub_error extends Managed_DataObject
|
||||
* @param string $m
|
||||
* @return pretty array to be used in a response
|
||||
*/
|
||||
public static function errorMessageToObject ($m) {
|
||||
$res = [
|
||||
'error'=> $m
|
||||
];
|
||||
return $res;
|
||||
public static function errorMessageToObject ($m) {
|
||||
$res = [
|
||||
'error'=> $m
|
||||
];
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user