diff --git a/appinfo/database.xml b/appinfo/database.xml
index 5778099a..21f239a2 100644
--- a/appinfo/database.xml
+++ b/appinfo/database.xml
@@ -428,6 +428,12 @@
true
+
+ public
+ boolean
+ true
+
+
creation
timestamp
diff --git a/appinfo/info.xml b/appinfo/info.xml
index 1ac0da72..55a16624 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -5,7 +5,7 @@
Social
🎉 Nextcloud becomes part of the federated social networks!
- 0.0.41
+ 0.0.42
agpl
Maxence Lange
Julius Härtl
diff --git a/lib/Model/ActivityPub/Document.php b/lib/Model/ActivityPub/Document.php
index fa14dda3..317917f1 100644
--- a/lib/Model/ActivityPub/Document.php
+++ b/lib/Model/ActivityPub/Document.php
@@ -58,6 +58,9 @@ class Document extends ACore implements JsonSerializable {
/** @var string */
private $caching = '';
+ /** @var bool */
+ private $public = false;
+
/**
* Document constructor.
@@ -128,6 +131,25 @@ class Document extends ACore implements JsonSerializable {
}
+ /**
+ * @return bool
+ */
+ public function isPublic(): bool {
+ return $this->public;
+ }
+
+ /**
+ * @param bool $public
+ *
+ * @return Document
+ */
+ public function setPublic(bool $public): Document {
+ $this->public = $public;
+
+ return $this;
+ }
+
+
/**
* @return string
*/
@@ -169,6 +191,8 @@ class Document extends ACore implements JsonSerializable {
public function importFromDatabase(array $data) {
parent::importFromDatabase($data);
+ $this->setPublic(($this->getInt('public', $data, 0) === 1) ? true : false);
+ $this->setLocalCopy($this->get('local_copy', $data, ''));
$this->setMediaType($this->get('media_type', $data, ''));
$this->setMimeType($this->get('mime_type', $data, ''));
$this->setCaching($this->get('caching', $data, ''));
diff --git a/lib/Service/CacheService.php b/lib/Service/CacheService.php
new file mode 100644
index 00000000..a2cdef98
--- /dev/null
+++ b/lib/Service/CacheService.php
@@ -0,0 +1,199 @@
+
+ * @copyright 2018, Maxence Lange
+ * @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 .
+ *
+ */
+
+namespace OCA\Social\Service;
+
+
+use daita\MySmallPhpTools\Model\Request;
+use OCA\Social\Exceptions\RequestException;
+
+class CurlService {
+
+
+ /** @var MiscService */
+ private $miscService;
+
+
+ /**
+ * CurlService constructor.
+ *
+ * @param MiscService $miscService
+ */
+ public function __construct(MiscService $miscService) {
+ $this->miscService = $miscService;
+ }
+
+
+ /**
+ * @param Request $request
+ *
+ * @return array
+ * @throws RequestException
+ */
+ public function request(Request $request): array {
+ $curl = $this->initRequest($request);
+
+ $this->initRequestPost($curl, $request);
+ $this->initRequestPut($curl, $request);
+ $this->initRequestDelete($curl, $request);
+
+ $result = curl_exec($curl);
+ $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
+
+ $this->parseRequestResultCode301($code);
+// $this->parseRequestResultCode401($code);
+ $this->parseRequestResultCode404($code, $request);
+// $this->parseRequestResultCode503($code);
+// $this->parseRequestResultCode500($code);
+// $this->parseRequestResult($result);
+
+ $ret = json_decode((string)$result, true);
+// if ($ret === null) {
+// throw new RequestException('500 Internal server error - could not parse JSON response');
+// }
+ if (!is_array($ret)) {
+ $ret = ['_result' => $result];
+ }
+
+ $ret['_address'] = $request->getAddress();
+ $ret['_path'] = $request->getUrl();
+ $ret['_code'] = $code;
+
+ return $ret;
+ }
+
+
+ /**
+ * @param Request $request
+ *
+ * @return resource
+ */
+ private function initRequest(Request $request) {
+
+ $curl = $this->generateCurlRequest($request);
+ $headers = $request->getHeaders();
+
+ $headers[] = 'Accept: application/ld+json; profile="https://www.w3.org/ns/activitystreams"';
+
+ curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
+ curl_setopt($curl, CURLOPT_TIMEOUT, 20);
+
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
+
+ return $curl;
+ }
+
+
+ /**
+ * @param Request $request
+ *
+ * @return resource
+ */
+ private function generateCurlRequest(Request $request) {
+ $url = 'https://' . $request->getAddress() . $request->getParsedUrl();
+ if ($request->getType() !== Request::TYPE_GET) {
+ $curl = curl_init($url);
+ } else {
+ $curl = curl_init($url . '?' . $request->getUrlData());
+ }
+
+ return $curl;
+ }
+
+
+ /**
+ * @param resource $curl
+ * @param Request $request
+ */
+ private function initRequestPost($curl, Request $request) {
+ if ($request->getType() !== Request::TYPE_POST) {
+ return;
+ }
+
+ curl_setopt($curl, CURLOPT_POST, true);
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getDataBody());
+ }
+
+
+ /**
+ * @param resource $curl
+ * @param Request $request
+ */
+ private function initRequestPut($curl, Request $request) {
+ if ($request->getType() !== Request::TYPE_PUT) {
+ return;
+ }
+
+ curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getDataBody());
+ }
+
+
+ /**
+ * @param resource $curl
+ * @param Request $request
+ */
+ private function initRequestDelete($curl, Request $request) {
+ if ($request->getType() !== Request::TYPE_DELETE) {
+ return;
+ }
+
+ curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getDataBody());
+ }
+
+
+ /**
+ * @param int $code
+ *
+ * @throws RequestException
+ */
+ private function parseRequestResultCode301($code) {
+ if ($code === 301) {
+ throw new RequestException('301 Moved Permanently');
+ }
+ }
+
+
+ /**
+ * @param int $code
+ *
+ * @param Request $request
+ *
+ * @throws RequestException
+ */
+ private function parseRequestResultCode404(int $code, Request $request) {
+ if ($code === 404) {
+ throw new RequestException('404 Not Found - ' . json_encode($request));
+ }
+ }
+
+
+}