Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/14/head
Maxence Lange 2018-10-12 08:44:35 +02:00
rodzic 0ab2dcd522
commit 4c7c9cdfbe
21 zmienionych plików z 86 dodań i 480 usunięć

Wyświetl plik

@ -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();

Wyświetl plik

@ -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');

15
composer.json 100644
Wyświetl plik

@ -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"
}
}

51
composer.lock wygenerowano 100644
Wyświetl plik

@ -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": []
}

Wyświetl plik

@ -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;

Wyświetl plik

@ -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')

Wyświetl plik

@ -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(

Wyświetl plik

@ -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;

Wyświetl plik

@ -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;

Wyświetl plik

@ -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;

Wyświetl plik

@ -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;

Wyświetl plik

@ -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 {

Wyświetl plik

@ -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 {

Wyświetl plik

@ -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;

Wyświetl plik

@ -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;

Wyświetl plik

@ -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 {

Wyświetl plik

@ -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;

Wyświetl plik

@ -1,242 +0,0 @@
<?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 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()
];
}
}

Wyświetl plik

@ -1,122 +0,0 @@
<?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 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;
}
}

Wyświetl plik

@ -1,78 +0,0 @@
<?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 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);
}
}

Wyświetl plik

@ -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';