kopia lustrzana https://github.com/nextcloud/social
Merge pull request #114 from nextcloud-gmbh/validate-import
validate import on incoming requestpull/128/head
commit
ee6b6663f7
|
@ -192,11 +192,8 @@ class ActivityPubController extends Controller {
|
|||
|
||||
/**
|
||||
* Method is called when a remote ActivityPub server wants to POST in the INBOX of a USER
|
||||
*
|
||||
* Checking that the user exists, and that the header is properly signed.
|
||||
*
|
||||
* Does nothing. Should save data ($body) in database.
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class InvalidResourceEntryException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -35,12 +35,12 @@ use daita\MySmallPhpTools\Traits\TPathTools;
|
|||
use JsonSerializable;
|
||||
use OCA\Social\Exceptions\ActivityCantBeVerifiedException;
|
||||
use OCA\Social\Exceptions\InvalidOriginException;
|
||||
use OCA\Social\Exceptions\InvalidResourceEntryException;
|
||||
use OCA\Social\Exceptions\UrlCloudException;
|
||||
use OCA\Social\Model\InstancePath;
|
||||
use OCA\Social\Service\ActivityPub\ICoreService;
|
||||
|
||||
|
||||
abstract class ACore implements JsonSerializable {
|
||||
abstract class ACore extends Item implements JsonSerializable {
|
||||
|
||||
|
||||
use TArrayTools;
|
||||
|
@ -50,100 +50,33 @@ abstract class ACore implements JsonSerializable {
|
|||
const CONTEXT_ACTIVITYSTREAMS = 'https://www.w3.org/ns/activitystreams';
|
||||
const CONTEXT_SECURITY = 'https://w3id.org/security/v1';
|
||||
|
||||
const AS_ID = 1;
|
||||
const AS_TYPE = 2;
|
||||
const AS_URL = 3;
|
||||
const AS_DATE = 4;
|
||||
const AS_USERNAME = 5;
|
||||
const AS_ACCOUNT = 6;
|
||||
const AS_STRING = 7;
|
||||
|
||||
/** @var string */
|
||||
private $urlSocial = '';
|
||||
|
||||
/** @var string */
|
||||
private $urlCloud = '';
|
||||
|
||||
// /** @var bool */
|
||||
// private $isTopLevel = false;
|
||||
|
||||
/** @var array */
|
||||
private $meta = [];
|
||||
|
||||
/** @var string */
|
||||
private $address = '';
|
||||
|
||||
/** @var string */
|
||||
private $id = '';
|
||||
|
||||
/** @var string */
|
||||
private $type = '';
|
||||
|
||||
/** @var string */
|
||||
private $url = '';
|
||||
|
||||
/** @var string */
|
||||
private $summary = '';
|
||||
|
||||
/** @var InstancePath[] */
|
||||
private $instancePaths = [];
|
||||
|
||||
/** @var string */
|
||||
private $to = '';
|
||||
|
||||
/** @var array */
|
||||
private $toArray = [];
|
||||
|
||||
/** @var array */
|
||||
private $cc = [];
|
||||
|
||||
/** @var array */
|
||||
private $bcc = [];
|
||||
|
||||
/** @var string */
|
||||
private $published = '';
|
||||
|
||||
/** @var array */
|
||||
private $tags = [];
|
||||
/** @var null Item */
|
||||
private $parent = null;
|
||||
|
||||
/** @var array */
|
||||
private $entries = [];
|
||||
|
||||
/** @var Person */
|
||||
private $actor = null;
|
||||
|
||||
/** @var string */
|
||||
private $actorId = '';
|
||||
|
||||
/** @var Document */
|
||||
private $icon = null;
|
||||
|
||||
/** @var ACore */
|
||||
private $object = null;
|
||||
|
||||
/** @var string */
|
||||
private $objectId = '';
|
||||
|
||||
/** @var ICoreService */
|
||||
private $saveAs;
|
||||
|
||||
/** @var bool */
|
||||
private $completeDetails = false;
|
||||
|
||||
/** @var string */
|
||||
private $source = '';
|
||||
|
||||
/** @var null ACore */
|
||||
private $parent = null;
|
||||
|
||||
/** @var bool */
|
||||
private $local = false;
|
||||
|
||||
/** @var string */
|
||||
private $origin = '';
|
||||
|
||||
|
||||
/**
|
||||
* Core constructor.
|
||||
*
|
||||
* @param ACore $parent
|
||||
*/
|
||||
public function __construct($parent = null) {
|
||||
// $this->isTopLevel = $isTopLevel;
|
||||
|
||||
if ($parent instanceof ACore) {
|
||||
$this->setParent($parent);
|
||||
}
|
||||
|
@ -151,455 +84,21 @@ abstract class ACore implements JsonSerializable {
|
|||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param Item $parent
|
||||
*
|
||||
* @return ACore
|
||||
* @return Item
|
||||
*/
|
||||
public function setId(string $id): ACore {
|
||||
$this->id = $id;
|
||||
public function setParent(Item $parent): ACore {
|
||||
$this->parent = $parent;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $base
|
||||
*
|
||||
* @throws UrlCloudException
|
||||
* @return Item
|
||||
*/
|
||||
public function generateUniqueId(string $base = '') {
|
||||
if ($this->getUrlCloud() === '') {
|
||||
throw new UrlCloudException();
|
||||
}
|
||||
|
||||
if ($base !== '') {
|
||||
$base = $this->withoutEndSlash($this->withBeginSlash($base));
|
||||
}
|
||||
|
||||
$uuid = sprintf(
|
||||
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
||||
mt_rand(0, 0xffff), mt_rand(0, 0xfff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000,
|
||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
||||
);
|
||||
|
||||
$this->setId($this->getUrlCloud() . $base . '/' . $uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function setType(string $type): ACore {
|
||||
// if ($type !== '') {
|
||||
$this->type = $type;
|
||||
|
||||
// }
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl(): string {
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function setUrl(string $url): ACore {
|
||||
$this->url = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param InstancePath $instancePath
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function addInstancePath(InstancePath $instancePath): ACore {
|
||||
if ($instancePath->getUri() !== '') {
|
||||
$this->instancePaths[] = $instancePath;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param InstancePath[] $path
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function addInstancePaths(array $path): ACore {
|
||||
$this->instancePaths = array_merge($this->instancePaths, $path);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return InstancePath[]
|
||||
*/
|
||||
public function getInstancePaths(): array {
|
||||
return $this->instancePaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InstancePath[] $instancePaths
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function setInstancePaths(array $instancePaths): ACore {
|
||||
$this->instancePaths = $instancePaths;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSummary(): string {
|
||||
return $this->summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $summary
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function setSummary(string $summary): ACore {
|
||||
$this->summary = $summary;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Person
|
||||
*/
|
||||
public function getActor(): Person {
|
||||
return $this->actor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Person $actor
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function setActor(Person $actor): ACore {
|
||||
$this->actor = $actor;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function gotActor(): bool {
|
||||
if ($this->actor === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $actorId
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function setActorId(string $actorId): ACore {
|
||||
$this->actorId = $actorId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getActorId(): string {
|
||||
return $this->actorId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUrlSocial(): string {
|
||||
return $this->urlSocial;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function setUrlSocial(string $path): ACore {
|
||||
$this->urlSocial = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUrlCloud(): string {
|
||||
return $this->urlCloud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function setUrlCloud(string $path): ACore {
|
||||
$this->urlCloud = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAddress(): string {
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $address
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function setAddress(string $address) {
|
||||
$this->address = $address;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTo(): string {
|
||||
return $this->to;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $to
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function setTo(string $to): ACore {
|
||||
$this->to = $to;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getToArray(): array {
|
||||
return $this->toArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $to
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function addToArray(string $to): ACore {
|
||||
$this->toArray[] = $to;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $toArray
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function setToArray(array $toArray): ACore {
|
||||
$this->toArray = $toArray;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function addCc(string $cc): Acore {
|
||||
$this->cc[] = $cc;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCcArray(): array {
|
||||
return $this->cc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $cc
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function setCcArray(array $cc): ACore {
|
||||
$this->cc = $cc;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getBccArray(): array {
|
||||
return $this->bcc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $bcc
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function setBccArray(array $bcc): ACore {
|
||||
$this->bcc = $bcc;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getOrigin(): string {
|
||||
return $this->origin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $origin
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function setOrigin(string $origin): ACore {
|
||||
$this->origin = $origin;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
*
|
||||
* @throws InvalidOriginException
|
||||
*/
|
||||
public function checkOrigin($id) {
|
||||
|
||||
$host = parse_url($id, PHP_URL_HOST);
|
||||
if ($this->getRoot()
|
||||
->getOrigin() === $host) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new InvalidOriginException();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* @param string $url
|
||||
*
|
||||
* @throws ActivityCantBeVerifiedException
|
||||
*/
|
||||
public function verify(string $url) {
|
||||
// TODO - Compare this with checkOrigin()
|
||||
$url1 = parse_url($this->getId());
|
||||
$url2 = parse_url($url);
|
||||
|
||||
if ($this->get('host', $url1, '1') !== $this->get('host', $url2, '2')) {
|
||||
throw new ActivityCantBeVerifiedException('activity cannot be verified');
|
||||
}
|
||||
|
||||
if ($this->get('scheme', $url1, '1') !== $this->get('scheme', $url2, '2')) {
|
||||
throw new ActivityCantBeVerifiedException('activity cannot be verified');
|
||||
}
|
||||
|
||||
if ($this->getInt('port', $url1, 1) !== $this->getInt('port', $url2, 1)) {
|
||||
throw new ActivityCantBeVerifiedException('activity cannot be verified');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $published
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function setPublished(string $published): ACore {
|
||||
$this->published = $published;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPublished(): string {
|
||||
return $this->published;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $tag
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function addTag(array $tag): ACore {
|
||||
$this->tags[] = $tag;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTags(): array {
|
||||
return $this->tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $tag
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function setTags(array $tag): ACore {
|
||||
$this->tags = $tag;
|
||||
|
||||
return $this;
|
||||
public function getParent(): ACore {
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
|
||||
|
@ -632,92 +131,86 @@ abstract class ACore implements JsonSerializable {
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @param ICoreService $class
|
||||
*/
|
||||
public function getObjectId(): string {
|
||||
return $this->objectId;
|
||||
public function saveAs(ICoreService $class) {
|
||||
$this->saveAs = $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $objectId
|
||||
* @return ICoreService
|
||||
*/
|
||||
public function savingAs() {
|
||||
return $this->saveAs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $base
|
||||
*
|
||||
* @return ACore
|
||||
* @throws UrlCloudException
|
||||
*/
|
||||
public function setObjectId(string $objectId): ACore {
|
||||
$this->objectId = $objectId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function gotIcon(): bool {
|
||||
if ($this->icon === null) {
|
||||
return false;
|
||||
public function generateUniqueId(string $base = '') {
|
||||
if ($this->getUrlCloud() === '') {
|
||||
throw new UrlCloudException();
|
||||
}
|
||||
|
||||
return true;
|
||||
if ($base !== '') {
|
||||
$base = $this->withoutEndSlash($this->withBeginSlash($base));
|
||||
}
|
||||
|
||||
$uuid = sprintf(
|
||||
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
||||
mt_rand(0, 0xffff), mt_rand(0, 0xfff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000,
|
||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
||||
);
|
||||
|
||||
$this->setId($this->getUrlCloud() . $base . '/' . $uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Document
|
||||
*/
|
||||
public function getIcon(): Document {
|
||||
return $this->icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Document $icon
|
||||
* @param $id
|
||||
*
|
||||
* @return ACore
|
||||
* @throws InvalidOriginException
|
||||
*/
|
||||
public function setIcon(Document $icon): ACore {
|
||||
$this->icon = $icon;
|
||||
public function checkOrigin($id) {
|
||||
$host = parse_url($id, PHP_URL_HOST);
|
||||
if ($this->getRoot()
|
||||
->getOrigin() === $host) {
|
||||
return;
|
||||
}
|
||||
|
||||
return $this;
|
||||
throw new InvalidOriginException();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isLocal(): bool {
|
||||
return $this->local;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $local
|
||||
* @deprecated
|
||||
*
|
||||
* @return Person
|
||||
*/
|
||||
public function setLocal(bool $local): ACore {
|
||||
$this->local = $local;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ACore $parent
|
||||
* @param string $url
|
||||
*
|
||||
* @return ACore
|
||||
* @throws ActivityCantBeVerifiedException
|
||||
*/
|
||||
public function setParent(ACore $parent): ACore {
|
||||
$this->parent = $parent;
|
||||
public function verify(string $url) {
|
||||
// TODO - Compare this with checkOrigin() - and delete this method.
|
||||
$url1 = parse_url($this->getId());
|
||||
$url2 = parse_url($url);
|
||||
|
||||
return $this;
|
||||
if ($this->get('host', $url1, '1') !== $this->get('host', $url2, '2')) {
|
||||
throw new ActivityCantBeVerifiedException('activity cannot be verified');
|
||||
}
|
||||
|
||||
if ($this->get('scheme', $url1, '1') !== $this->get('scheme', $url2, '2')) {
|
||||
throw new ActivityCantBeVerifiedException('activity cannot be verified');
|
||||
}
|
||||
|
||||
if ($this->getInt('port', $url1, 1) !== $this->getInt('port', $url2, 1)) {
|
||||
throw new ActivityCantBeVerifiedException('activity cannot be verified');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ACore
|
||||
*/
|
||||
public function getParent(): ACore {
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
|
@ -849,71 +342,100 @@ abstract class ACore implements JsonSerializable {
|
|||
|
||||
|
||||
/**
|
||||
* @param ICoreService $class
|
||||
*/
|
||||
public function saveAs(ICoreService $class) {
|
||||
$this->saveAs = $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ICoreService
|
||||
*/
|
||||
public function savingAs() {
|
||||
return $this->saveAs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isCompleteDetails(): bool {
|
||||
return $this->completeDetails;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $completeDetails
|
||||
* @param int $as
|
||||
* @param string $k
|
||||
* @param array $arr
|
||||
* @param string $default
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function setCompleteDetails(bool $completeDetails): ACore {
|
||||
$this->completeDetails = $completeDetails;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws InvalidResourceEntryException
|
||||
*/
|
||||
public function getSource(): string {
|
||||
return $this->source;
|
||||
public function validate(int $as, string $k, array $arr, string $default = ''): string {
|
||||
$value = $this->validateEntryString($as, $this->get($k, $arr, $default));
|
||||
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source
|
||||
*
|
||||
* @return ACore
|
||||
*/
|
||||
public function setSource(string $source): ACore {
|
||||
$this->source = $source;
|
||||
|
||||
return $this;
|
||||
/**
|
||||
* @param int $as
|
||||
* @param string $k
|
||||
* @param array $arr
|
||||
* @param array $default
|
||||
*
|
||||
* @return array
|
||||
* @throws InvalidResourceEntryException
|
||||
*/
|
||||
public function validateArray(int $as, string $k, array $arr, array $default = []): array {
|
||||
$values = $this->getArray($k, $arr, $default);
|
||||
|
||||
$result = [];
|
||||
foreach ($values as $value) {
|
||||
$result[] = $this->validateEntryString($as, $value);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* // TODO - better checks
|
||||
*
|
||||
* @param $as
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
* @throws InvalidResourceEntryException
|
||||
*/
|
||||
public function validateEntryString(int $as, string $value): string {
|
||||
switch ($as) {
|
||||
case self::AS_ID:
|
||||
if (parse_url($value) !== false) {
|
||||
return $value;
|
||||
}
|
||||
break;
|
||||
|
||||
case self::AS_TYPE:
|
||||
return $value;
|
||||
|
||||
case self::AS_URL:
|
||||
if (parse_url($value) !== false) {
|
||||
return $value;
|
||||
}
|
||||
break;
|
||||
|
||||
case self::AS_DATE:
|
||||
return $value;
|
||||
|
||||
case self::AS_STRING:
|
||||
$value = strip_tags($value);
|
||||
|
||||
return $value;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
throw new InvalidResourceEntryException($as . ' ' . $value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @throws InvalidResourceEntryException
|
||||
*/
|
||||
public function import(array $data) {
|
||||
$this->setId($this->get('id', $data, ''));
|
||||
$this->setType($this->get('type', $data, ''));
|
||||
$this->setUrl($this->get('url', $data, ''));
|
||||
$this->setSummary($this->get('summary', $data, ''));
|
||||
$this->setToArray($this->getArray('to', $data, []));
|
||||
$this->setCcArray($this->getArray('cc', $data, []));
|
||||
$this->setPublished($this->get('published', $data, ''));
|
||||
$this->setActorId($this->get('actor', $data, ''));
|
||||
$this->setObjectId($this->get('object', $data, ''));
|
||||
$this->setId($this->validate(self::AS_ID, 'id', $data, ''));
|
||||
$this->setType($this->validate(self::AS_TYPE, 'type', $data, ''));
|
||||
$this->setUrl($this->validate(self::AS_URL, 'url', $data, ''));
|
||||
$this->setSummary($this->validate(self::AS_STRING, 'summary', $data, ''));
|
||||
$this->setToArray($this->validateArray(self::AS_ID, 'to', $data, []));
|
||||
$this->setCcArray($this->validateArray(self::AS_ID, 'cc', $data, []));
|
||||
$this->setPublished($this->validate(self::AS_DATE, 'published', $data, ''));
|
||||
$this->setActorId($this->validate(self::AS_ID, 'actor', $data, ''));
|
||||
$this->setObjectId($this->validate(self::AS_ID, 'object', $data, ''));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ class Create extends ACore implements JsonSerializable {
|
|||
*/
|
||||
public function import(array $data) {
|
||||
parent::import($data);
|
||||
$this->setActorId($this->get('actor', $data, ''));
|
||||
$this->setActorId($this->validate(ACore::AS_ID, 'actor', $data, ''));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ class Delete extends ACore implements JsonSerializable {
|
|||
*/
|
||||
public function import(array $data) {
|
||||
parent::import($data);
|
||||
$this->setActorId($this->get('actor', $data, ''));
|
||||
$this->setActorId($this->validate(ACore::AS_ID, 'actor', $data, ''));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -46,7 +46,6 @@ class Undo extends ACore implements JsonSerializable {
|
|||
const TYPE = 'Undo';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Undo constructor.
|
||||
*
|
||||
|
|
|
@ -200,7 +200,7 @@ class Document extends ACore implements JsonSerializable {
|
|||
public function import(array $data) {
|
||||
parent::import($data);
|
||||
|
||||
$this->setMediaType($this->get('mediaType', $data, ''));
|
||||
$this->setMediaType($this->validate(ACore::AS_STRING, 'mediaType', $data, ''));
|
||||
|
||||
if ($this->getId() === '') {
|
||||
$this->generateUniqueId('/documents/g');
|
||||
|
|
|
@ -0,0 +1,603 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Model\ActivityPub;
|
||||
|
||||
|
||||
use OCA\Social\Model\InstancePath;
|
||||
|
||||
|
||||
class Item {
|
||||
|
||||
|
||||
/** @var string */
|
||||
private $urlSocial = '';
|
||||
|
||||
/** @var string */
|
||||
private $urlCloud = '';
|
||||
|
||||
/** @var string */
|
||||
private $address = '';
|
||||
|
||||
/** @var string */
|
||||
private $id = '';
|
||||
|
||||
/** @var string */
|
||||
private $type = '';
|
||||
|
||||
/** @var string */
|
||||
private $url = '';
|
||||
|
||||
/** @var string */
|
||||
private $summary = '';
|
||||
|
||||
/** @var InstancePath[] */
|
||||
private $instancePaths = [];
|
||||
|
||||
/** @var string */
|
||||
private $to = '';
|
||||
|
||||
/** @var array */
|
||||
private $toArray = [];
|
||||
|
||||
/** @var array */
|
||||
private $cc = [];
|
||||
|
||||
/** @var array */
|
||||
private $bcc = [];
|
||||
|
||||
/** @var string */
|
||||
private $published = '';
|
||||
|
||||
/** @var array */
|
||||
private $tags = [];
|
||||
|
||||
/** @var Person */
|
||||
private $actor = null;
|
||||
|
||||
/** @var string */
|
||||
private $actorId = '';
|
||||
|
||||
/** @var Document */
|
||||
private $icon = null;
|
||||
|
||||
/** @var string */
|
||||
private $objectId = '';
|
||||
|
||||
/** @var bool */
|
||||
private $completeDetails = false;
|
||||
|
||||
/** @var string */
|
||||
private $source = '';
|
||||
|
||||
/** @var bool */
|
||||
private $local = false;
|
||||
|
||||
/** @var string */
|
||||
private $origin = '';
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setId(string $id): Item {
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setType(string $type): Item {
|
||||
// if ($type !== '') {
|
||||
$this->type = $type;
|
||||
|
||||
// }
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl(): string {
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setUrl(string $url): Item {
|
||||
$this->url = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param InstancePath $instancePath
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function addInstancePath(InstancePath $instancePath): Item {
|
||||
if ($instancePath->getUri() !== '') {
|
||||
$this->instancePaths[] = $instancePath;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param InstancePath[] $path
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function addInstancePaths(array $path): Item {
|
||||
$this->instancePaths = array_merge($this->instancePaths, $path);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return InstancePath[]
|
||||
*/
|
||||
public function getInstancePaths(): array {
|
||||
return $this->instancePaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InstancePath[] $instancePaths
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setInstancePaths(array $instancePaths): Item {
|
||||
$this->instancePaths = $instancePaths;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSummary(): string {
|
||||
return $this->summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $summary
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setSummary(string $summary): Item {
|
||||
$this->summary = $summary;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Person
|
||||
*/
|
||||
public function getActor(): Person {
|
||||
return $this->actor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Person $actor
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setActor(Person $actor): Item {
|
||||
$this->actor = $actor;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function gotActor(): bool {
|
||||
if ($this->actor === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $actorId
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setActorId(string $actorId): Item {
|
||||
$this->actorId = $actorId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getActorId(): string {
|
||||
return $this->actorId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUrlSocial(): string {
|
||||
return $this->urlSocial;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setUrlSocial(string $path): Item {
|
||||
$this->urlSocial = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUrlCloud(): string {
|
||||
return $this->urlCloud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setUrlCloud(string $path): Item {
|
||||
$this->urlCloud = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAddress(): string {
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $address
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setAddress(string $address) {
|
||||
$this->address = $address;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTo(): string {
|
||||
return $this->to;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $to
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setTo(string $to): Item {
|
||||
$this->to = $to;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getToArray(): array {
|
||||
return $this->toArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $to
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function addToArray(string $to): Item {
|
||||
$this->toArray[] = $to;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $toArray
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setToArray(array $toArray): Item {
|
||||
$this->toArray = $toArray;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function addCc(string $cc): Item {
|
||||
$this->cc[] = $cc;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCcArray(): array {
|
||||
return $this->cc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $cc
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setCcArray(array $cc): Item {
|
||||
$this->cc = $cc;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getBccArray(): array {
|
||||
return $this->bcc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $bcc
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setBccArray(array $bcc): Item {
|
||||
$this->bcc = $bcc;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getOrigin(): string {
|
||||
return $this->origin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $origin
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setOrigin(string $origin): Item {
|
||||
$this->origin = $origin;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $published
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setPublished(string $published): Item {
|
||||
$this->published = $published;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPublished(): string {
|
||||
return $this->published;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $tag
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function addTag(array $tag): Item {
|
||||
$this->tags[] = $tag;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTags(): array {
|
||||
return $this->tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $tag
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setTags(array $tag): Item {
|
||||
$this->tags = $tag;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getObjectId(): string {
|
||||
return $this->objectId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $objectId
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setObjectId(string $objectId): Item {
|
||||
$this->objectId = $objectId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function gotIcon(): bool {
|
||||
if ($this->icon === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Document
|
||||
*/
|
||||
public function getIcon(): Document {
|
||||
return $this->icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Document $icon
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setIcon(Document $icon): Item {
|
||||
$this->icon = $icon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isLocal(): bool {
|
||||
return $this->local;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $local
|
||||
*
|
||||
* @return Person
|
||||
*/
|
||||
public function setLocal(bool $local): Item {
|
||||
$this->local = $local;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isCompleteDetails(): bool {
|
||||
return $this->completeDetails;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $completeDetails
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setCompleteDetails(bool $completeDetails): Item {
|
||||
$this->completeDetails = $completeDetails;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSource(): string {
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function setSource(string $source): Item {
|
||||
$this->source = $source;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -199,11 +199,11 @@ class Note extends ACore implements JsonSerializable {
|
|||
public function import(array $data) {
|
||||
parent::import($data);
|
||||
|
||||
$this->setInReplyTo($this->get('inReplyTo', $data, ''));
|
||||
$this->setAttributedTo($this->get('attributedTo', $data, ''));
|
||||
$this->setInReplyTo($this->validate(ACore::AS_ID, 'inReplyTo', $data, ''));
|
||||
$this->setAttributedTo($this->validate(ACore::AS_ID, 'attributedTo', $data, ''));
|
||||
$this->setSensitive($this->getBool('sensitive', $data, false));
|
||||
$this->setConversation($this->get('conversation', $data, ''));
|
||||
$this->setContent($this->get('content', $data, ''));
|
||||
$this->setConversation($this->validate(ACore::AS_ID, 'conversation', $data, ''));
|
||||
$this->setContent($this->validate(ACore::AS_STRING, 'content', $data, ''));
|
||||
$this->convertPublished();
|
||||
}
|
||||
|
||||
|
|
|
@ -417,16 +417,18 @@ class Person extends ACore implements JsonSerializable {
|
|||
*/
|
||||
public function import(array $data) {
|
||||
parent::import($data);
|
||||
$this->setPreferredUsername($this->get('preferredUsername', $data, ''))
|
||||
$this->setPreferredUsername(
|
||||
$this->validate(ACore::AS_USERNAME, 'preferredUsername', $data, '')
|
||||
)
|
||||
->setPublicKey($this->get('publicKey.publicKeyPem', $data))
|
||||
->setSharedInbox($this->get('endpoints.sharedInbox', $data))
|
||||
->setName($this->get('name', $data, ''))
|
||||
->setAccount($this->get('account', $data, ''))
|
||||
->setInbox($this->get('inbox', $data, ''))
|
||||
->setOutbox($this->get('outbox', $data, ''))
|
||||
->setFollowers($this->get('followers', $data, ''))
|
||||
->setFollowing($this->get('following', $data, ''))
|
||||
->setFeatured($this->get('featured', $data, ''));
|
||||
->setSharedInbox($this->validate(ACore::AS_URL, 'endpoints.sharedInbox', $data))
|
||||
->setName($this->validate(ACore::AS_USERNAME, 'name', $data, ''))
|
||||
->setAccount($this->validate(ACore::AS_ACCOUNT, 'account', $data, ''))
|
||||
->setInbox($this->validate(ACore::AS_URL, 'inbox', $data, ''))
|
||||
->setOutbox($this->validate(ACore::AS_URL, 'outbox', $data, ''))
|
||||
->setFollowers($this->validate(ACore::AS_URL, 'followers', $data, ''))
|
||||
->setFollowing($this->validate(ACore::AS_URL, 'following', $data, ''))
|
||||
->setFeatured($this->validate(ACore::AS_URL, 'featured', $data, ''));
|
||||
|
||||
$icon = new Image($this);
|
||||
$icon->setUrlCloud($this->getUrlCloud());
|
||||
|
|
|
@ -27,13 +27,13 @@ declare(strict_types=1);
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
namespace OCA\Social\Service\ActivityPub;
|
||||
|
||||
|
||||
use Exception;
|
||||
use OC\User\NoUserException;
|
||||
use OCA\Social\Db\NotesRequest;
|
||||
use OCA\Social\Exceptions\ActivityCantBeVerifiedException;
|
||||
use OCA\Social\Exceptions\ActorDoesNotExistException;
|
||||
use OCA\Social\Exceptions\InvalidOriginException;
|
||||
use OCA\Social\Exceptions\NoteNotFoundException;
|
||||
|
@ -50,6 +50,7 @@ use OCA\Social\Service\ConfigService;
|
|||
use OCA\Social\Service\CurlService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
|
||||
|
||||
class NoteService implements ICoreService {
|
||||
|
||||
|
||||
|
@ -94,8 +95,7 @@ class NoteService implements ICoreService {
|
|||
*/
|
||||
public function __construct(
|
||||
NotesRequest $notesRequest, ActivityService $activityService, ActorService $actorService,
|
||||
PersonService $personService,
|
||||
CurlService $curlService, ConfigService $configService,
|
||||
PersonService $personService, CurlService $curlService, ConfigService $configService,
|
||||
MiscService $miscService
|
||||
) {
|
||||
$this->notesRequest = $notesRequest;
|
||||
|
|
Ładowanie…
Reference in New Issue