diff --git a/appinfo/app.php b/appinfo/app.php index b871207c..b667d7e5 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -29,7 +29,7 @@ declare(strict_types=1); namespace OCA\Social\AppInfo; -require_once(__DIR__ . '/../lib/autoload.php'); +require_once __DIR__ . '/autoload.php'; //$app = new Application(); //$app->registerNavigation(); diff --git a/lib/autoload.php b/appinfo/autoload.php similarity index 70% rename from lib/autoload.php rename to appinfo/autoload.php index d990fe69..3427325f 100644 --- a/lib/autoload.php +++ b/appinfo/autoload.php @@ -27,30 +27,11 @@ declare(strict_types=1); * */ +namespace OCA\Social\AppInfo; -/** - * @param $dir - */ -function loadPHPFiles($dir) { - try { - $files = scandir($dir); - } catch (Exception $e) { - return; - } +$composerDir = __DIR__ . '/../vendor/'; - foreach ($files as $file) { - if (substr($file, 0, 1) === '.' || $file === 'autoload.php') { - continue; - } - - $path = $dir . '/' . $file; - if (is_dir($path)) { - loadPHPFiles($path); - } else { - require_once($path); - } - } +if (is_dir($composerDir) && file_exists($composerDir . 'autoload.php')) { + require_once $composerDir . 'autoload.php'; } -loadPHPFiles(__DIR__ . '/Tools'); -//loadPHPFiles(__DIR__ . '/Authentication'); diff --git a/composer.json b/composer.json new file mode 100644 index 00000000..3bf0a3c8 --- /dev/null +++ b/composer.json @@ -0,0 +1,15 @@ +{ + "name": "nextcloud/social", + "description": "Social app", + "minimum-stability": "stable", + "license": "AGPL-3.0-or-later", + "authors": [ + { + "name": "Maxence Lange", + "email": "maxence@artificial-owl.com" + } + ], + "require": { + "daita/my-small-php-tools": "dev-master" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 00000000..60088b49 --- /dev/null +++ b/composer.lock @@ -0,0 +1,51 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "02220c2a6087d409a5e53060ee20c47e", + "packages": [ + { + "name": "daita/my-small-php-tools", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/daita/my-small-php-tools.git", + "reference": "f13fb739ffc13c6843e34628dcd3a251a619ee02" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/f13fb739ffc13c6843e34628dcd3a251a619ee02", + "reference": "f13fb739ffc13c6843e34628dcd3a251a619ee02", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "AGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Maxence Lange", + "email": "maxence@artificial-owl.com" + } + ], + "description": "My small PHP Tools", + "time": "2018-10-11T14:02:16+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": { + "daita/my-small-php-tools": 20 + }, + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 75fba6f2..2488116d 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -29,7 +29,7 @@ declare(strict_types=1); namespace OCA\Social\Controller; -use daita\Traits\TNCDataResponse; +use daita\MySmallPhpTools\Traits\TNCDataResponse; use Exception; use OCA\Social\AppInfo\Application; use OCA\Social\Service\ActorService; diff --git a/lib/Controller/ActivityPubController.php b/lib/Controller/ActivityPubController.php index 5d7be96d..c3fad8b3 100644 --- a/lib/Controller/ActivityPubController.php +++ b/lib/Controller/ActivityPubController.php @@ -30,7 +30,7 @@ declare(strict_types=1); namespace OCA\Social\Controller; -use daita\Traits\TNCDataResponse; +use daita\MySmallPhpTools\Traits\TNCDataResponse; use Exception; use OCA\Social\AppInfo\Application; use OCA\Social\Service\ActivityPubService; @@ -269,7 +269,7 @@ class ActivityPubController extends Controller { */ private function checkSourceActivityStreams(): bool { - // comment this line to display the result that would be return to an ActivityPub service (TEST) + // uncomment this line to display the result that would be return to an ActivityPub service (TEST) return true; if ($this->request->getHeader('Accept') diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php index b3cbc543..bf584ab7 100644 --- a/lib/Controller/NavigationController.php +++ b/lib/Controller/NavigationController.php @@ -66,6 +66,7 @@ class NavigationController extends Controller { * @param string $userId * @param IConfig $config * @param IURLGenerator $urlGenerator + * @param ActorService $actorService * @param MiscService $miscService */ public function __construct( diff --git a/lib/Controller/SocialPubController.php b/lib/Controller/SocialPubController.php index b3cfc011..51ee6f09 100644 --- a/lib/Controller/SocialPubController.php +++ b/lib/Controller/SocialPubController.php @@ -30,7 +30,7 @@ declare(strict_types=1); namespace OCA\Social\Controller; -use daita\Traits\TNCDataResponse; +use daita\MySmallPhpTools\Traits\TNCDataResponse; use OCA\Social\AppInfo\Application; use OCA\Social\Service\ActivityPubService; use OCA\Social\Service\ActorService; diff --git a/lib/Db/ActorsRequestBuilder.php b/lib/Db/ActorsRequestBuilder.php index 746c5c19..4f480817 100644 --- a/lib/Db/ActorsRequestBuilder.php +++ b/lib/Db/ActorsRequestBuilder.php @@ -30,7 +30,7 @@ declare(strict_types=1); namespace OCA\Social\Db; -use daita\Traits\TArrayTools; +use daita\MySmallPhpTools\Traits\TArrayTools; use OCA\Social\Model\ActivityPub\Actor; use OCP\DB\QueryBuilder\IQueryBuilder; diff --git a/lib/Db/CacheActorsRequestBuilder.php b/lib/Db/CacheActorsRequestBuilder.php index 99d5f448..29e7b80b 100644 --- a/lib/Db/CacheActorsRequestBuilder.php +++ b/lib/Db/CacheActorsRequestBuilder.php @@ -30,7 +30,7 @@ declare(strict_types=1); namespace OCA\Social\Db; -use daita\Traits\TArrayTools; +use daita\MySmallPhpTools\Traits\TArrayTools; use OCA\Social\Model\ActivityPub\Cache\CacheActor; use OCP\DB\QueryBuilder\IQueryBuilder; diff --git a/lib/Db/NotesRequestBuilder.php b/lib/Db/NotesRequestBuilder.php index 246dd7f6..a4de22a6 100644 --- a/lib/Db/NotesRequestBuilder.php +++ b/lib/Db/NotesRequestBuilder.php @@ -30,7 +30,7 @@ declare(strict_types=1); namespace OCA\Social\Db; -use daita\Traits\TArrayTools; +use daita\MySmallPhpTools\Traits\TArrayTools; use OCA\Social\Model\ActivityPub\Note; use OCP\DB\QueryBuilder\IQueryBuilder; diff --git a/lib/Model/Instance.php b/lib/Model/Instance.php index 600d6547..a1ab08d6 100644 --- a/lib/Model/Instance.php +++ b/lib/Model/Instance.php @@ -30,7 +30,7 @@ declare(strict_types=1); namespace OCA\Social\Model; -use daita\Traits\TArrayTools; +use daita\MySmallPhpTools\Traits\TArrayTools; use JsonSerializable; class Instance implements JsonSerializable { diff --git a/lib/Model/InstancePath.php b/lib/Model/InstancePath.php index 36cd6231..885f7ca1 100644 --- a/lib/Model/InstancePath.php +++ b/lib/Model/InstancePath.php @@ -30,7 +30,7 @@ declare(strict_types=1); namespace OCA\Social\Model; -use daita\Traits\TArrayTools; +use daita\MySmallPhpTools\Traits\TArrayTools; use JsonSerializable; class InstancePath implements JsonSerializable { diff --git a/lib/Service/ActivityPubService.php b/lib/Service/ActivityPubService.php index 0d7ff0e0..b2d65423 100644 --- a/lib/Service/ActivityPubService.php +++ b/lib/Service/ActivityPubService.php @@ -30,7 +30,7 @@ declare(strict_types=1); namespace OCA\Social\Service; -use daita\Model\Request; +use daita\MySmallPhpTools\Model\Request; use DateTime; use Exception; use OC\User\NoUserException; diff --git a/lib/Service/ActorService.php b/lib/Service/ActorService.php index f0de418b..b7d3cecb 100644 --- a/lib/Service/ActorService.php +++ b/lib/Service/ActorService.php @@ -30,7 +30,7 @@ declare(strict_types=1); namespace OCA\Social\Service; -use daita\Traits\TArrayTools; +use daita\MySmallPhpTools\Traits\TArrayTools; use Exception; use OC\User\NoUserException; use OCA\Social\Db\ActorsRequest; diff --git a/lib/Service/CurlService.php b/lib/Service/CurlService.php index e167176e..c485dd76 100644 --- a/lib/Service/CurlService.php +++ b/lib/Service/CurlService.php @@ -30,7 +30,7 @@ declare(strict_types=1); namespace OCA\Social\Service; -use daita\Model\Request; +use daita\MySmallPhpTools\Model\Request; use OCA\Social\Exceptions\RequestException; class CurlService { diff --git a/lib/Service/InstanceService.php b/lib/Service/InstanceService.php index 3544b608..777866e5 100644 --- a/lib/Service/InstanceService.php +++ b/lib/Service/InstanceService.php @@ -30,7 +30,7 @@ declare(strict_types=1); namespace OCA\Social\Service; -use daita\Model\Request; +use daita\MySmallPhpTools\Model\Request; use OCA\Social\Exceptions\RequestException; use OCA\Social\Model\ActivityPub\Core; use OCA\Social\Model\Instance; diff --git a/lib/Tools/Model/Request.php b/lib/Tools/Model/Request.php deleted file mode 100644 index 72bf9419..00000000 --- a/lib/Tools/Model/Request.php +++ /dev/null @@ -1,242 +0,0 @@ - - * @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 daita\Model; - -use JsonSerializable; - -class Request implements \JsonSerializable { - - const TYPE_GET = 0; - const TYPE_POST = 1; - const TYPE_PUT = 2; - const TYPE_DELETE = 3; - - /** @var string */ - private $address; - - /** @var int */ - private $url; - - /** @var int */ - private $type; - - /** @var array */ - private $headers = []; - - /** @var array */ - private $data = []; - - - /** - * Request constructor. - * - * @param string $url - * @param int $type - */ - public function __construct($url, $type = 0) { - $this->url = $url; - $this->type = $type; - } - - - /** - * @return string - */ - public function getAddress(): string { - return $this->address; - } - - /** - * @param string $address - * - * @return Request - */ - public function setAddress(string $address): Request { - $this->address = $address; - - return $this; - } - - /** - * @return string - */ - public function getParsedUrl(): string { - $url = $this->getUrl(); - $ak = array_keys($this->getData()); - foreach ($ak as $k) { - if (!is_string($this->data[$k])) { - continue; - } - - $url = str_replace(':' . $k, $this->data[$k], $url); - } - - return $url; - } - - - /** - * @return string - */ - public function getUrl(): string { - return $this->url; - } - - - /** - * @return int - */ - public function getType(): int { - return $this->type; - } - - - public function addHeader($header): Request { - $this->headers[] = $header; - - return $this; - } - - - /** - * @return array - */ - public function getHeaders(): array { - return $this->headers; - } - - /** - * @param array $headers - * - * @return Request - */ - public function setHeaders(array $headers): Request { - $this->headers = $headers; - - return $this; - } - - - /** - * @return array - */ - public function getData(): array { - return $this->data; - } - - - /** - * @param array $data - * - * @return Request - */ - public function setData(array $data): Request { - $this->data = $data; - - return $this; - } - - - /** - * @param string $data - * - * @return Request - */ - public function setDataJson(string $data): Request { - $this->setData(json_decode($data, true)); - - return $this; - } - - - /** - * @param JsonSerializable $data - * - * @return Request - */ - public function setDataSerialize(JsonSerializable $data): Request { - $this->setDataJson(json_encode($data)); - - return $this; - } - - - /** - * @param string $k - * @param string $v - * - * @return Request - */ - public function addData(string $k, string $v): Request { - $this->data[$k] = $v; - - return $this; - } - - - /** - * @param string $k - * @param int $v - * - * @return Request - */ - public function addDataInt(string $k, int $v): Request { - $this->data[$k] = $v; - - return $this; - } - - - /** - * @return string - */ - public function getDataBody() { - return json_encode($this->getData()); -// if ($this->getData() === []) { -// return ''; -// } -// -// return preg_replace( -// '/([(%5B)]{1})[0-9]+([(%5D)]{1})/', '$1$2', http_build_query($this->getData()) -// ); - } - - - /** - * @return array - */ - public function jsonSerialize(): array { - return [ - 'url' => $this->getUrl(), - 'type' => $this->getType(), - 'data' => $this->getData() - ]; - } -} diff --git a/lib/Tools/Traits/TArrayTools.php b/lib/Tools/Traits/TArrayTools.php deleted file mode 100644 index df80a374..00000000 --- a/lib/Tools/Traits/TArrayTools.php +++ /dev/null @@ -1,122 +0,0 @@ - - * @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 daita\Traits; - - -trait TArrayTools { - - - /** - * @param string $k - * @param array $arr - * @param string $default - * - * @return string - */ - private function get(string $k, array $arr, string $default = ''): string { - if ($arr === null) { - return $default; - } - - if (!key_exists($k, $arr) || $arr[$k] === null) { - return $default; - } - - return $arr[$k]; - } - - - /** - * @param string $k - * @param array $arr - * @param int $default - * - * @return int - */ - private function getInt(string $k, array $arr, int $default = 0): int { - if ($arr === null) { - return $default; - } - - if (!key_exists($k, $arr) || $arr[$k] === null) { - return $default; - } - - return intval($arr[$k]); - } - - - /** - * @param string $k - * @param array $arr - * @param bool $default - * - * @return bool - */ - private function getBool(string $k, array $arr, bool $default = false): bool { - if ($arr === null) { - return $default; - } - - if (!key_exists($k, $arr)) { - return $default; - } - - return $arr[$k]; - } - - - /** - * @param string $k - * @param array $arr - * @param array $default - * - * @return array - */ - private function getArray(string $k, array $arr, array $default = []): array { - if ($arr === null) { - return $default; - } - - if (!key_exists($k, $arr)) { - return $default; - } - - $r = $arr[$k]; - if ($r === null || !is_array($r)) { - return $default; - } - - return $r; - } - - -} - diff --git a/lib/Tools/Traits/TNCDataResponse.php b/lib/Tools/Traits/TNCDataResponse.php deleted file mode 100644 index 12ef036d..00000000 --- a/lib/Tools/Traits/TNCDataResponse.php +++ /dev/null @@ -1,78 +0,0 @@ - - * @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 daita\Traits; - - -use JsonSerializable; -use OCP\AppFramework\Http; -use OCP\AppFramework\Http\DataResponse; - -trait TNCDataResponse { - - - /** - * @param string $message - * - * @return DataResponse - */ - private function fail(string $message = ''): DataResponse { - return new DataResponse( - ['status' => -1, 'message' => $message], Http::STATUS_NON_AUTHORATIVE_INFORMATION - ); - } - - - /** - * @param array $result - * - * @return DataResponse - */ - private function success(array $result): DataResponse { - $data = - [ - 'result' => $result, - 'status' => 1 - ]; - - return new DataResponse($data, Http::STATUS_OK); - } - - - /** - * @param JsonSerializable $result - * - * @return DataResponse - */ - private function directSuccess(JsonSerializable $result): DataResponse { - return new DataResponse($result, Http::STATUS_OK); - } - -} - diff --git a/lib/webfinger.php b/lib/webfinger.php index 93b7586e..3e921ddc 100644 --- a/lib/webfinger.php +++ b/lib/webfinger.php @@ -28,7 +28,7 @@ declare(strict_types=1); namespace OCA\Social; -require_once(__DIR__ . '/../lib/autoload.php'); +require_once(__DIR__ . '/../appinfo/autoload.php'); if (!array_key_exists('resource', $_GET)) { echo 'missing resource';