Fix last merge issues

This commit is contained in:
Diogo Cordeiro 2018-07-10 01:47:52 +01:00
parent ecb812d5e6
commit 295d4a254d
19 changed files with 226 additions and 189 deletions

View File

@ -26,7 +26,7 @@
* @link https://www.gnu.org/software/social/ * @link https://www.gnu.org/software/social/
*/ */
if (!defined ('GNUSOCIAL')) { if (!defined ('GNUSOCIAL')) {
exit(1); exit (1);
} }
/** /**
@ -90,6 +90,32 @@ 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 * Plugin return handler
*/ */

View File

@ -26,14 +26,13 @@
* @link https://www.gnu.org/software/social/ * @link https://www.gnu.org/software/social/
*/ */
if (!defined ('GNUSOCIAL')) { if (!defined ('GNUSOCIAL')) {
exit(1); exit (1);
} }
/** /**
* @category Plugin * @category Plugin
* @package GNUsocial * @package GNUsocial
* @author Diogo Cordeiro <diogo@fc.up.pt> * @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 * @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/ * @link http://www.gnu.org/software/social/
*/ */

View File

@ -26,14 +26,13 @@
* @link https://www.gnu.org/software/social/ * @link https://www.gnu.org/software/social/
*/ */
if (!defined ('GNUSOCIAL')) { if (!defined ('GNUSOCIAL')) {
exit(1); exit (1);
} }
/** /**
* @category Plugin * @category Plugin
* @package GNUsocial * @package GNUsocial
* @author Diogo Cordeiro <diogo@fc.up.pt> * @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 * @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/ * @link http://www.gnu.org/software/social/
*/ */

View File

@ -1,13 +1,8 @@
<?php <?php
require_once dirname (__DIR__) . DIRECTORY_SEPARATOR . "utils" . DIRECTORY_SEPARATOR . "discovery.php";
use Activitypub_Discovery;
/** /**
* 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
@ -26,18 +21,31 @@ use Activitypub_Discovery;
* @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>
* @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 apActorInboxAction extends ManagedAction class apActorInboxAction extends ManagedAction
{ {
protected $needLogin = false; protected $needLogin = false;
protected $canPost = true; protected $canPost = true;
/**
* Handle the Actor Inbox request
*
* @return void
*/
protected function handle () protected function handle ()
{ {
$nickname = $this->trimmed ('nickname'); $nickname = $this->trimmed ('nickname');
@ -70,7 +78,7 @@ class apActorInboxAction extends ManagedAction
try { try {
require_once dirname (__DIR__) . DIRECTORY_SEPARATOR . "utils" . DIRECTORY_SEPARATOR . "discovery.php"; require_once dirname (__DIR__) . DIRECTORY_SEPARATOR . "utils" . DIRECTORY_SEPARATOR . "discovery.php";
$actor_profile = new Activitypub_Discovery; $actor_profile = new Activitypub_Discovery;
$actor_profile = $actor_profile->lookup($data->actor); $actor_profile = $actor_profile->lookup ($data->actor);
$actor_profile = $actor_profile[0]; $actor_profile = $actor_profile[0];
} catch (Exception $e) { } catch (Exception $e) {
ActivityPubReturn::error ("Invalid Actor.", 404); ActivityPubReturn::error ("Invalid Actor.", 404);

View File

@ -26,14 +26,13 @@
* @link https://www.gnu.org/software/social/ * @link https://www.gnu.org/software/social/
*/ */
if (!defined ('GNUSOCIAL')) { if (!defined ('GNUSOCIAL')) {
exit(1); exit (1);
} }
/** /**
* @category Plugin * @category Plugin
* @package GNUsocial * @package GNUsocial
* @author Diogo Cordeiro <diogo@fc.up.pt> * @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 * @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/ * @link http://www.gnu.org/software/social/
*/ */

View File

@ -26,7 +26,7 @@
* @link https://www.gnu.org/software/social/ * @link https://www.gnu.org/software/social/
*/ */
if (!defined ('GNUSOCIAL')) { if (!defined ('GNUSOCIAL')) {
exit(1); exit (1);
} }
/** /**

View File

@ -1,4 +1,5 @@
<?php <?php
require_once dirname (__DIR__) . DIRECTORY_SEPARATOR . "utils" . DIRECTORY_SEPARATOR . "discovery.php"; require_once dirname (__DIR__) . DIRECTORY_SEPARATOR . "utils" . DIRECTORY_SEPARATOR . "discovery.php";
use Activitypub_Discovery; use Activitypub_Discovery;
use ActivityPubReturn; use ActivityPubReturn;
@ -7,9 +8,7 @@ use Activitypub_notice;
/** /**
* 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
@ -28,18 +27,31 @@ use Activitypub_notice;
* @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>
* @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 apSharedInboxAction extends ManagedAction class apSharedInboxAction extends ManagedAction
{ {
protected $needLogin = false; protected $needLogin = false;
protected $canPost = true; protected $canPost = true;
/**
* Handle the Shared Inbox request
*
* @return void
*/
protected function handle () protected function handle ()
{ {
if ($_SERVER['REQUEST_METHOD'] !== 'POST') { if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
@ -49,7 +61,7 @@ class apSharedInboxAction extends ManagedAction
$data = json_decode (file_get_contents ('php://input')); $data = json_decode (file_get_contents ('php://input'));
// Validate data // Validate data
if (!(isset($data->type))) { if (!isset($data->type)) {
ActivityPubReturn::error ("Type was not specified."); ActivityPubReturn::error ("Type was not specified.");
} }
if (!isset($data->actor)) { if (!isset($data->actor)) {
@ -89,8 +101,7 @@ class apSharedInboxAction extends ManagedAction
// XXX: Invalid actor found, not sure how we handle those // XXX: Invalid actor found, not sure how we handle those
} }
} }
} else if (empty ($data->to) } else if (empty ($data->to) || in_array ($data->to, $public_to)) {
|| in_array ($data->to, $public_to)) {
// No need to do anything else at this point, let's just break out the if // No need to do anything else at this point, let's just break out the if
} else { } else {
try { try {

View File

@ -26,7 +26,7 @@
* @link https://www.gnu.org/software/social/ * @link https://www.gnu.org/software/social/
*/ */
if (!defined ('GNUSOCIAL')) { if (!defined ('GNUSOCIAL')) {
exit(1); exit (1);
} }
try { try {

View File

@ -26,7 +26,7 @@
* @link https://www.gnu.org/software/social/ * @link https://www.gnu.org/software/social/
*/ */
if (!defined ('GNUSOCIAL')) { if (!defined ('GNUSOCIAL')) {
exit(1); exit (1);
} }
$valid_object_types = array ("Note"); $valid_object_types = array ("Note");
@ -70,7 +70,7 @@ if (Notice::contentTooLong ($content)) {
ActivityPubReturn::error ("That's too long. Maximum notice size is %d character."); ActivityPubReturn::error ("That's too long. Maximum notice size is %d character.");
} }
$options = array('source' = >'web', 'uri' = >$data->id); $options = array ('source' => 'web', 'uri' => $data->id);
// $options gets filled with possible scoping settings // $options gets filled with possible scoping settings
ToSelector::fillActivity ($this, $act, $options); ToSelector::fillActivity ($this, $act, $options);

View File

@ -26,12 +26,12 @@
* @link https://www.gnu.org/software/social/ * @link https://www.gnu.org/software/social/
*/ */
if (!defined ('GNUSOCIAL')) { if (!defined ('GNUSOCIAL')) {
exit(1); exit (1);
} }
try { try {
Activitypub_notice::getByUri ($data->object)->deleteAs ($actor_profile); Activitypub_notice::getByUri ($data->object)->deleteAs ($actor_profile);
ActivityPubReturn::answer ("Notice deleted successfully."); ActivityPubReturn::answer ("Notice deleted successfully.");
} catch(Exception $ex) { } catch(Exception $ex) {
ActivityPubReturn::error ($ex->getMessage(), 403); ActivityPubReturn::error ($ex->getMessage (), 403);
} }

View File

@ -26,7 +26,7 @@
* @link https://www.gnu.org/software/social/ * @link https://www.gnu.org/software/social/
*/ */
if (!defined ('GNUSOCIAL')) { if (!defined ('GNUSOCIAL')) {
exit(1); exit (1);
} }
// Get valid Object profile // Get valid Object profile
@ -44,6 +44,6 @@ try {
} else { } else {
ActivityPubReturn::error ("Already following.", 409); ActivityPubReturn::error ("Already following.", 409);
} }
} catch(Exception $ex) { } catch (Exception $ex) {
ActivityPubReturn::error ("Invalid Object Actor URL.", 404); ActivityPubReturn::error ("Invalid Object Actor URL.", 404);
} }

View File

@ -26,7 +26,7 @@
* @link https://www.gnu.org/software/social/ * @link https://www.gnu.org/software/social/
*/ */
if (!defined ('GNUSOCIAL')) { if (!defined ('GNUSOCIAL')) {
exit(1); exit (1);
} }
try { try {

View File

@ -29,7 +29,7 @@ use Activitypub_Discovery;
* @link https://www.gnu.org/software/social/ * @link https://www.gnu.org/software/social/
*/ */
if (!defined ('GNUSOCIAL')) { if (!defined ('GNUSOCIAL')) {
exit(1); exit (1);
} }
// Validate data // Validate data

View File

@ -26,14 +26,13 @@
* @link https://www.gnu.org/software/social/ * @link https://www.gnu.org/software/social/
*/ */
if (!defined ('GNUSOCIAL')) { if (!defined ('GNUSOCIAL')) {
exit(1); exit (1);
} }
/** /**
* @category Plugin * @category Plugin
* @package GNUsocial * @package GNUsocial
* @author Diogo Cordeiro <diogo@fc.up.pt> * @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 * @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/ * @link http://www.gnu.org/software/social/
*/ */

View File

@ -26,14 +26,13 @@
* @link https://www.gnu.org/software/social/ * @link https://www.gnu.org/software/social/
*/ */
if (!defined ('GNUSOCIAL')) { if (!defined ('GNUSOCIAL')) {
exit(1); exit (1);
} }
/** /**
* @category Plugin * @category Plugin
* @package GNUsocial * @package GNUsocial
* @author Diogo Cordeiro <diogo@fc.up.pt> * @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 * @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/ * @link http://www.gnu.org/software/social/
*/ */

View File

@ -26,7 +26,7 @@
* @link https://www.gnu.org/software/social/ * @link https://www.gnu.org/software/social/
*/ */
if (!defined ('GNUSOCIAL')) { if (!defined ('GNUSOCIAL')) {
exit(1); exit (1);
} }
/** /**
@ -45,22 +45,22 @@ class Activitypub_notice extends Managed_DataObject
* @param \Notice $notice * @param \Notice $notice
* @return pretty array to be used in a response * @return pretty array to be used in a response
*/ */
public static function noticeToObject($notice) { public static function noticeToObject ($notice) {
$attachments = array (); $attachments = array ();
foreach($notice->attachments()as $attachment) { foreach($notice->attachments () as $attachment) {
$attachments[] = Activitypub_attachment::attachmentToObject ($attachment); $attachments[] = Activitypub_attachment::attachmentToObject ($attachment);
} }
$tags = array (); $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");

View File

@ -26,7 +26,7 @@
* @link https://www.gnu.org/software/social/ * @link https://www.gnu.org/software/social/
*/ */
if (!defined ('GNUSOCIAL')) { if (!defined ('GNUSOCIAL')) {
exit(1); exit (1);
} }
/** /**

View File

@ -26,14 +26,13 @@
* @link https://www.gnu.org/software/social/ * @link https://www.gnu.org/software/social/
*/ */
if (!defined ('GNUSOCIAL')) { if (!defined ('GNUSOCIAL')) {
exit(1); exit (1);
} }
/** /**
* @category Plugin * @category Plugin
* @package GNUsocial * @package GNUsocial
* @author Diogo Cordeiro <diogo@fc.up.pt> * @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 * @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/ * @link http://www.gnu.org/software/social/
*/ */
@ -54,7 +53,7 @@ class Activitypub_tag extends Managed_DataObject
] ]
], ],
'name' => $tag, 'name' => $tag,
'url' => common_local_url('tag', array('tag' => $tag)) 'url' => common_local_url ('tag', array('tag' => $tag))
]; ];
return $res; return $res;

View File

@ -22,25 +22,23 @@ use Profile;
* *
* @category Plugin * @category Plugin
* @package GNUsocial * @package GNUsocial
* @author Daniel Supernault <danielsupernault@gmail.com>
* @author Diogo Cordeiro <diogo@fc.up.pt> * @author Diogo Cordeiro <diogo@fc.up.pt>
* @author Daniel Supernault <danielsupernault@gmail.com>
* @copyright 2018 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')) { if (!defined ('GNUSOCIAL')) {
exit(1); exit (1);
} }
/** /**
* @category Plugin * @category Plugin
* @package GNUsocial * @package GNUsocial
* @author Daniel Supernault <danielsupernault@gmail.com>
* @author Diogo Cordeiro <diogo@fc.up.pt> * @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 * @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/ * @link http://www.gnu.org/software/social/
*/ */
class Activitypub_Discovery class Activitypub_Discovery
{ {
private $discovered_actor_profiles = array (); private $discovered_actor_profiles = array ();