diff --git a/app/Controllers/AdminController.php b/app/Controllers/AdminController.php index d1fdf8c..dae2164 100644 --- a/app/Controllers/AdminController.php +++ b/app/Controllers/AdminController.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Controllers; use League\Flysystem\FileNotFoundException; @@ -34,7 +54,7 @@ class AdminController extends Controller $totalSize += $filesystem->getSize($media->storage_path); } - return view()->render($response, 'dashboard/system.twig', [ + return view()->render($response, 'dashboard/system.twig', array( 'usersCount' => $usersCount, 'mediasCount' => $mediasCount, 'orphanFilesCount' => $orphanFilesCount, @@ -43,7 +63,7 @@ class AdminController extends Controller 'upload_max_filesize' => ini_get('upload_max_filesize'), 'installed_lang' => $this->lang->getList(), 'forced_lang' => $request->getAttribute('forced_lang'), - ]); + )); } /** @@ -69,7 +89,7 @@ class AdminController extends Controller $this->database->query('DELETE FROM `uploads` WHERE `user_id` IS NULL'); - $this->session->alert(lang('deleted_orphans', [$deleted])); + $this->session->alert(lang('deleted_orphans', array($deleted))); return redirect($response, route('system')); } @@ -92,7 +112,7 @@ class AdminController extends Controller $this->database->query('DELETE FROM `settings` WHERE `key` = \'lang\''); } - $this->session->alert(lang('lang_set', [param($request, 'lang')])); + $this->session->alert(lang('lang_set', array(param($request, 'lang')))); return redirect($response, route('system')); } diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 18e9d4e..9ef1351 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Controllers; use Psr\Http\Message\ResponseInterface as Response; @@ -29,19 +49,19 @@ class ClientController extends Controller return redirect($response, $request->getHeaderLine('Referer')); } - $json = [ + $json = array( 'DestinationType' => 'ImageUploader, TextUploader, FileUploader', 'RequestURL' => route('upload'), 'FileFormName' => 'upload', - 'Arguments' => [ + 'Arguments' => array( 'file' => '$filename$', 'text' => '$input$', 'token' => $user->token, - ], + ), 'URL' => '$json:url$', 'ThumbnailURL' => '$json:url$/raw', 'DeletionURL' => '$json:url$/delete/'.$user->token, - ]; + ); return json($response, $json, 200, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) ->withHeader('Content-Disposition', 'attachment;filename="'.$user->username.'-ShareX.sxcu"'); @@ -72,11 +92,11 @@ class ClientController extends Controller return view()->render($response->withHeader('Content-Disposition', 'attachment;filename="xbackbone_uploader_'.$user->username.'.sh"'), 'scripts/xbackbone_uploader.sh.twig', - [ + array( 'username' => $user->username, 'upload_url' => route('upload'), 'token' => $user->token, - ] + ) ); } } diff --git a/app/Controllers/Controller.php b/app/Controllers/Controller.php index e9c67c1..827e0e5 100644 --- a/app/Controllers/Controller.php +++ b/app/Controllers/Controller.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Controllers; use App\Database\DB; @@ -66,7 +86,7 @@ abstract class Controller try { $totalSize += $filesystem->getSize($media->storage_path); } catch (FileNotFoundException $e) { - $this->logger->error('Error calculating file size', ['exception' => $e]); + $this->logger->error('Error calculating file size', array('exception' => $e)); } } diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index 47bcb00..937e16e 100644 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Controllers; use App\Database\Queries\MediaQuery; @@ -63,12 +83,12 @@ class DashboardController extends Controller return view()->render( $response, ($this->session->get('admin', false) && $this->session->get('gallery_view', true)) ? 'dashboard/list.twig' : 'dashboard/grid.twig', - [ + array( 'medias' => $query->getMedia(), 'next' => $page < floor($query->getPages()), 'previous' => $page >= 1, 'current_page' => ++$page, - ] + ) ); } diff --git a/app/Controllers/LoginController.php b/app/Controllers/LoginController.php index 487aa98..4126207 100644 --- a/app/Controllers/LoginController.php +++ b/app/Controllers/LoginController.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Controllers; use Psr\Http\Message\ResponseInterface as Response; @@ -36,7 +56,7 @@ class LoginController extends Controller public function login(Request $request, Response $response): Response { $username = param($request, 'username'); - $result = $this->database->query('SELECT `id`, `email`, `username`, `password`,`is_admin`, `active` FROM `users` WHERE `username` = ? OR `email` = ? LIMIT 1', [$username, $username])->fetch(); + $result = $this->database->query('SELECT `id`, `email`, `username`, `password`,`is_admin`, `active` FROM `users` WHERE `username` = ? OR `email` = ? LIMIT 1', array($username, $username))->fetch(); if (!$result || !password_verify(param($request, 'password'), $result->password)) { $this->session->alert(lang('bad_login'), 'danger'); @@ -62,7 +82,7 @@ class LoginController extends Controller $this->session->set('admin', $result->is_admin); $this->session->set('used_space', humanFileSize($this->getUsedSpaceByUser($result->id))); - $this->session->alert(lang('welcome', [$result->username]), 'info'); + $this->session->alert(lang('welcome', array($result->username)), 'info'); $this->logger->info("User $result->username logged in."); if (param($request, 'remember') === 'on') { @@ -70,22 +90,22 @@ class LoginController extends Controller $token = bin2hex(random_bytes(32)); $expire = time() + 604800; // a week - $this->database->query('UPDATE `users` SET `remember_selector`=?, `remember_token`=?, `remember_expire`=? WHERE `id`=?', [ + $this->database->query('UPDATE `users` SET `remember_selector`=?, `remember_token`=?, `remember_expire`=? WHERE `id`=?', array( $selector, password_hash($token, PASSWORD_DEFAULT), date('Y-m-d\TH:i:s', $expire), $result->id, - ]); + )); // Workaround for php <= 7.3 if (PHP_VERSION_ID < 70300) { setcookie('remember', "{$selector}:{$token}", $expire, '; SameSite=Lax', '', false, true); } else { - setcookie('remember', "{$selector}:{$token}", [ + setcookie('remember', "{$selector}:{$token}", array( 'expires' => $expire, 'httponly' => true, 'samesite' => 'Lax', - ]); + )); } } diff --git a/app/Controllers/MediaController.php b/app/Controllers/MediaController.php index b93ba3d..68c5ed1 100644 --- a/app/Controllers/MediaController.php +++ b/app/Controllers/MediaController.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Controllers; use GuzzleHttp\Psr7\Stream; @@ -66,12 +86,12 @@ class MediaController extends Controller throw new HttpNotFoundException($request); } - return view()->render($response, 'upload/public.twig', [ + return view()->render($response, 'upload/public.twig', array( 'delete_token' => $token, 'media' => $media, 'type' => $type, 'url' => urlFor("/{$userCode}/{$mediaCode}"), - ]); + )); } /** @@ -159,14 +179,14 @@ class MediaController extends Controller if ($this->session->get('admin')) { $media = $this->database->query('SELECT * FROM `uploads` WHERE `id` = ? LIMIT 1', $id)->fetch(); } else { - $media = $this->database->query('SELECT * FROM `uploads` WHERE `id` = ? AND `user_id` = ? LIMIT 1', [$id, $this->session->get('user_id')])->fetch(); + $media = $this->database->query('SELECT * FROM `uploads` WHERE `id` = ? AND `user_id` = ? LIMIT 1', array($id, $this->session->get('user_id')))->fetch(); } if (!$media) { throw new HttpNotFoundException($request); } - $this->database->query('UPDATE `uploads` SET `published`=? WHERE `id`=?', [$media->published ? 0 : 1, $media->id]); + $this->database->query('UPDATE `uploads` SET `published`=? WHERE `id`=?', array($media->published ? 0 : 1, $media->id)); return $response; } @@ -191,7 +211,7 @@ class MediaController extends Controller if ($this->session->get('admin', false) || $media->user_id === $this->session->get('user_id')) { $this->deleteMedia($request, $media->storage_path, $id); - $this->logger->info('User '.$this->session->get('username').' deleted a media.', [$id]); + $this->logger->info('User '.$this->session->get('username').' deleted a media.', array($id)); $this->session->set('used_space', humanFileSize($this->getUsedSpaceByUser($this->session->get('user_id')))); } else { throw new HttpUnauthorizedException($request); @@ -240,7 +260,7 @@ class MediaController extends Controller if ($this->session->get('admin', false) || $user->id === $media->user_id) { $this->deleteMedia($request, $media->storage_path, $media->mediaId); - $this->logger->info('User '.$user->username.' deleted a media via token.', [$media->mediaId]); + $this->logger->info('User '.$user->username.' deleted a media via token.', array($media->mediaId)); } else { throw new HttpUnauthorizedException($request); } @@ -276,10 +296,10 @@ class MediaController extends Controller { $mediaCode = pathinfo($mediaCode)['filename']; - $media = $this->database->query('SELECT `uploads`.*, `users`.*, `users`.`id` AS `userId`, `uploads`.`id` AS `mediaId` FROM `uploads` INNER JOIN `users` ON `uploads`.`user_id` = `users`.`id` WHERE `user_code` = ? AND `uploads`.`code` = ? LIMIT 1', [ + $media = $this->database->query('SELECT `uploads`.*, `users`.*, `users`.`id` AS `userId`, `uploads`.`id` AS `mediaId` FROM `uploads` INNER JOIN `users` ON `uploads`.`user_id` = `users`.`id` WHERE `user_code` = ? AND `uploads`.`code` = ? LIMIT 1', array( $userCode, $mediaCode, - ])->fetch(); + ))->fetch(); return $media; } @@ -305,7 +325,7 @@ class MediaController extends Controller } else { $stream = new Stream($storage->readStream($media->storage_path)); - if (!in_array(explode('/', $mime)[0], ['image', 'video', 'audio']) || $disposition === 'attachment') { + if (!in_array(explode('/', $mime)[0], array('image', 'video', 'audio')) || $disposition === 'attachment') { return $response->withHeader('Content-Type', $mime) ->withHeader('Content-Disposition', $disposition.'; filename="'.$media->filename.'"') ->withHeader('Content-Length', $stream->getSize()) diff --git a/app/Controllers/ThemeController.php b/app/Controllers/ThemeController.php index 59fe547..fc83f26 100644 --- a/app/Controllers/ThemeController.php +++ b/app/Controllers/ThemeController.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Controllers; use Psr\Http\Message\ResponseInterface as Response; @@ -16,7 +36,7 @@ class ThemeController extends Controller { $apiJson = json_decode(file_get_contents('https://bootswatch.com/api/4.json')); - $out = []; + $out = array(); $out['Default - Bootstrap 4 default theme'] = 'https://bootswatch.com/_vendor/bootstrap/dist/css/bootstrap.min.css'; foreach ($apiJson->themes as $theme) { diff --git a/app/Controllers/UpgradeController.php b/app/Controllers/UpgradeController.php index 91f338c..f3d9e81 100644 --- a/app/Controllers/UpgradeController.php +++ b/app/Controllers/UpgradeController.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Controllers; use Psr\Http\Message\ResponseInterface as Response; @@ -100,11 +120,11 @@ class UpgradeController extends Controller */ public function checkForUpdates(Request $request, Response $response): Response { - $jsonResponse = [ + $jsonResponse = array( 'status' => null, 'message' => null, 'upgrade' => false, - ]; + ); $acceptPrerelease = param($request, 'prerelease', 'false') === 'true'; @@ -135,15 +155,15 @@ class UpgradeController extends Controller protected function getApiJson() { - $opts = [ - 'http' => [ + $opts = array( + 'http' => array( 'method' => 'GET', - 'header' => [ + 'header' => array( 'User-Agent: XBackBone-App', 'Accept: application/vnd.github.v3+json', - ], - ], - ]; + ), + ), + ); $data = @file_get_contents(self::GITHUB_SOURCE_API, false, stream_context_create($opts)); diff --git a/app/Controllers/UploadController.php b/app/Controllers/UploadController.php index d9d365c..227e29a 100644 --- a/app/Controllers/UploadController.php +++ b/app/Controllers/UploadController.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Controllers; use League\Flysystem\FileExistsException; @@ -28,9 +48,9 @@ class UploadController extends Controller return redirect($response, $request->getHeaderLine('Referer')); } - return view()->render($response, 'upload/web.twig', [ + return view()->render($response, 'upload/web.twig', array( 'user' => $user, - ]); + )); } /** @@ -43,10 +63,10 @@ class UploadController extends Controller */ public function upload(Request $request, Response $response): Response { - $json = [ + $json = array( 'message' => null, 'version' => PLATFORM_VERSION, - ]; + ); if ($this->config['maintenance']) { $json['message'] = 'Endpoint under maintenance.'; @@ -105,17 +125,17 @@ class UploadController extends Controller $this->storage->writeStream($storagePath, $file->getStream()->detach()); - $this->database->query('INSERT INTO `uploads`(`user_id`, `code`, `filename`, `storage_path`) VALUES (?, ?, ?, ?)', [ + $this->database->query('INSERT INTO `uploads`(`user_id`, `code`, `filename`, `storage_path`) VALUES (?, ?, ?, ?)', array( $user->id, $code, $file->getClientFilename(), $storagePath, - ]); + )); $json['message'] = 'OK.'; $json['url'] = urlFor("/{$user->user_code}/{$code}.{$fileInfo['extension']}"); - $this->logger->info("User $user->username uploaded new media.", [$this->database->getPdo()->lastInsertId()]); + $this->logger->info("User $user->username uploaded new media.", array($this->database->getPdo()->lastInsertId())); return json($response, $json, 201); } diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index 4f778f4..0db877c 100644 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Controllers; use Psr\Http\Message\ResponseInterface as Response; @@ -25,18 +45,18 @@ class UserController extends Controller { $page = max(0, --$page); - $users = $this->database->query('SELECT * FROM `users` LIMIT ? OFFSET ?', [self::PER_PAGE, $page * self::PER_PAGE])->fetchAll(); + $users = $this->database->query('SELECT * FROM `users` LIMIT ? OFFSET ?', array(self::PER_PAGE, $page * self::PER_PAGE))->fetchAll(); $pages = $this->database->query('SELECT COUNT(*) AS `count` FROM `users`')->fetch()->count / self::PER_PAGE; return view()->render($response, 'user/index.twig', - [ + array( 'users' => $users, 'next' => $page < floor($pages), 'previous' => $page >= 1, 'current_page' => ++$page, - ] + ) ); } @@ -98,7 +118,7 @@ class UserController extends Controller $token = $this->generateNewToken(); - $this->database->query('INSERT INTO `users`(`email`, `username`, `password`, `is_admin`, `active`, `user_code`, `token`) VALUES (?, ?, ?, ?, ?, ?, ?)', [ + $this->database->query('INSERT INTO `users`(`email`, `username`, `password`, `is_admin`, `active`, `user_code`, `token`) VALUES (?, ?, ?, ?, ?, ?, ?)', array( param($request, 'email'), param($request, 'username'), password_hash(param($request, 'password'), PASSWORD_DEFAULT), @@ -106,10 +126,10 @@ class UserController extends Controller param($request, 'is_active') !== null ? 1 : 0, $userCode, $token, - ]); + )); - $this->session->alert(lang('user_created', [param($request, 'username')]), 'success'); - $this->logger->info('User '.$this->session->get('username').' created a new user.', [array_diff_key($request->getParsedBody(), array_flip(['password']))]); + $this->session->alert(lang('user_created', array(param($request, 'username'))), 'success'); + $this->logger->info('User '.$this->session->get('username').' created a new user.', array(array_diff_key($request->getParsedBody(), array_flip(array('password'))))); return redirect($response, route('user.index')); } @@ -131,10 +151,10 @@ class UserController extends Controller { $user = $this->getUser($request, $id, false); - return view()->render($response, 'user/edit.twig', [ + return view()->render($response, 'user/edit.twig', array( 'profile' => false, 'user' => $user, - ]); + )); } /** @@ -154,57 +174,57 @@ class UserController extends Controller if (param($request, 'email') === null) { $this->session->alert(lang('email_required'), 'danger'); - return redirect($response, route('user.edit', ['id' => $id])); + return redirect($response, route('user.edit', array('id' => $id))); } - if ($this->database->query('SELECT COUNT(*) AS `count` FROM `users` WHERE `email` = ? AND `email` <> ?', [param($request, 'email'), $user->email])->fetch()->count > 0) { + if ($this->database->query('SELECT COUNT(*) AS `count` FROM `users` WHERE `email` = ? AND `email` <> ?', array(param($request, 'email'), $user->email))->fetch()->count > 0) { $this->session->alert(lang('email_taken'), 'danger'); - return redirect($response, route('user.edit', ['id' => $id])); + return redirect($response, route('user.edit', array('id' => $id))); } if (param($request, 'username') === null) { $this->session->alert(lang('username_required'), 'danger'); - return redirect($response, route('user.edit', ['id' => $id])); + return redirect($response, route('user.edit', array('id' => $id))); } - if ($this->database->query('SELECT COUNT(*) AS `count` FROM `users` WHERE `username` = ? AND `username` <> ?', [param($request, 'username'), $user->username])->fetch()->count > 0) { + if ($this->database->query('SELECT COUNT(*) AS `count` FROM `users` WHERE `username` = ? AND `username` <> ?', array(param($request, 'username'), $user->username))->fetch()->count > 0) { $this->session->alert(lang('username_taken'), 'danger'); - return redirect($response, route('user.edit', ['id' => $id])); + return redirect($response, route('user.edit', array('id' => $id))); } if ($user->id === $this->session->get('user_id') && param($request, 'is_admin') === null) { $this->session->alert(lang('cannot_demote'), 'danger'); - return redirect($response, route('user.edit', ['id' => $id])); + return redirect($response, route('user.edit', array('id' => $id))); } if (param($request, 'password') !== null && !empty(param($request, 'password'))) { - $this->database->query('UPDATE `users` SET `email`=?, `username`=?, `password`=?, `is_admin`=?, `active`=? WHERE `id` = ?', [ + $this->database->query('UPDATE `users` SET `email`=?, `username`=?, `password`=?, `is_admin`=?, `active`=? WHERE `id` = ?', array( param($request, 'email'), param($request, 'username'), password_hash(param($request, 'password'), PASSWORD_DEFAULT), param($request, 'is_admin') !== null ? 1 : 0, param($request, 'is_active') !== null ? 1 : 0, $user->id, - ]); + )); } else { - $this->database->query('UPDATE `users` SET `email`=?, `username`=?, `is_admin`=?, `active`=? WHERE `id` = ?', [ + $this->database->query('UPDATE `users` SET `email`=?, `username`=?, `is_admin`=?, `active`=? WHERE `id` = ?', array( param($request, 'email'), param($request, 'username'), param($request, 'is_admin') !== null ? 1 : 0, param($request, 'is_active') !== null ? 1 : 0, $user->id, - ]); + )); } - $this->session->alert(lang('user_updated', [param($request, 'username')]), 'success'); - $this->logger->info('User '.$this->session->get('username')." updated $user->id.", [ - array_diff_key((array) $user, array_flip(['password'])), - array_diff_key($request->getParsedBody(), array_flip(['password'])), - ]); + $this->session->alert(lang('user_updated', array(param($request, 'username'))), 'success'); + $this->logger->info('User '.$this->session->get('username')." updated $user->id.", array( + array_diff_key((array) $user, array_flip(array('password'))), + array_diff_key($request->getParsedBody(), array_flip(array('password'))), + )); return redirect($response, route('user.index')); } @@ -253,10 +273,10 @@ class UserController extends Controller { $user = $this->getUser($request, $this->session->get('user_id'), true); - return view()->render($response, 'user/edit.twig', [ + return view()->render($response, 'user/edit.twig', array( 'profile' => true, 'user' => $user, - ]); + )); } /** @@ -279,23 +299,23 @@ class UserController extends Controller $user = $this->getUser($request, $id, true); - if ($this->database->query('SELECT COUNT(*) AS `count` FROM `users` WHERE `email` = ? AND `email` <> ?', [param($request, 'email'), $user->email])->fetch()->count > 0) { + if ($this->database->query('SELECT COUNT(*) AS `count` FROM `users` WHERE `email` = ? AND `email` <> ?', array(param($request, 'email'), $user->email))->fetch()->count > 0) { $this->session->alert(lang('email_taken'), 'danger'); return redirect($response, route('profile')); } if (param($request, 'password') !== null && !empty(param($request, 'password'))) { - $this->database->query('UPDATE `users` SET `email`=?, `password`=? WHERE `id` = ?', [ + $this->database->query('UPDATE `users` SET `email`=?, `password`=? WHERE `id` = ?', array( param($request, 'email'), password_hash(param($request, 'password'), PASSWORD_DEFAULT), $user->id, - ]); + )); } else { - $this->database->query('UPDATE `users` SET `email`=? WHERE `id` = ?', [ + $this->database->query('UPDATE `users` SET `email`=? WHERE `id` = ?', array( param($request, 'email'), $user->id, - ]); + )); } $this->session->alert(lang('profile_updated'), 'success'); @@ -320,10 +340,10 @@ class UserController extends Controller $token = $this->generateNewToken(); - $this->database->query('UPDATE `users` SET `token`=? WHERE `id` = ?', [ + $this->database->query('UPDATE `users` SET `token`=? WHERE `id` = ?', array( $token, $user->id, - ]); + )); $this->logger->info('User '.$this->session->get('username')." refreshed token of user $user->id."); diff --git a/app/Database/DB.php b/app/Database/DB.php index 396e7e4..bcf46b2 100644 --- a/app/Database/DB.php +++ b/app/Database/DB.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Database; use PDO; @@ -27,10 +47,10 @@ class DB } } - public function query(string $query, $parameters = []) + public function query(string $query, $parameters = array()) { if (!is_array($parameters)) { - $parameters = [$parameters]; + $parameters = array($parameters); } $query = $this->pdo->prepare($query); diff --git a/app/Database/Migrator.php b/app/Database/Migrator.php index 0c38562..1b3c04c 100644 --- a/app/Database/Migrator.php +++ b/app/Database/Migrator.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Database; use PDOException; @@ -79,13 +99,13 @@ class Migrator try { $this->db->getPdo()->exec($sql); if (!$exists) { - $this->db->query('INSERT INTO `migrations` VALUES (?,?)', [basename($file), 1]); + $this->db->query('INSERT INTO `migrations` VALUES (?,?)', array(basename($file), 1)); } else { - $this->db->query('UPDATE `migrations` SET `migrated`=? WHERE `name`=?', [1, basename($file)]); + $this->db->query('UPDATE `migrations` SET `migrated`=? WHERE `name`=?', array(1, basename($file))); } } catch (PDOException $exception) { if (!$exists) { - $this->db->query('INSERT INTO `migrations` VALUES (?,?)', [basename($file), 0]); + $this->db->query('INSERT INTO `migrations` VALUES (?,?)', array(basename($file), 0)); } throw $exception; diff --git a/app/Database/Queries/MediaQuery.php b/app/Database/Queries/MediaQuery.php index 5829b8f..0d16bce 100644 --- a/app/Database/Queries/MediaQuery.php +++ b/app/Database/Queries/MediaQuery.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Database\Queries; use App\Database\DB; @@ -112,7 +132,7 @@ class MediaQuery } $orderAndSearch = ''; - $params = []; + $params = array(); if ($this->text !== null) { $orderAndSearch = $this->isAdmin ? 'WHERE `uploads`.`filename` LIKE ? ' : 'AND `uploads`.`filename` LIKE ? '; @@ -133,11 +153,11 @@ class MediaQuery $queryMedia = sprintf($queryMedia, $orderAndSearch); if ($this->isAdmin) { - $this->media = $this->db->query($queryMedia, array_merge($params, [self::PER_PAGE_ADMIN, $page * self::PER_PAGE_ADMIN]))->fetchAll(); + $this->media = $this->db->query($queryMedia, array_merge($params, array(self::PER_PAGE_ADMIN, $page * self::PER_PAGE_ADMIN)))->fetchAll(); $this->pages = $this->db->query($queryPages, $params)->fetch()->count / self::PER_PAGE_ADMIN; } else { - $this->media = $this->db->query($queryMedia, array_merge([$this->userId], $params, [self::PER_PAGE, $page * self::PER_PAGE]))->fetchAll(); - $this->pages = $this->db->query($queryPages, array_merge([$this->userId], $params))->fetch()->count / self::PER_PAGE; + $this->media = $this->db->query($queryMedia, array_merge(array($this->userId), $params, array(self::PER_PAGE, $page * self::PER_PAGE)))->fetchAll(); + $this->pages = $this->db->query($queryPages, array_merge(array($this->userId), $params))->fetch()->count / self::PER_PAGE; } foreach ($this->media as $media) { @@ -166,7 +186,7 @@ class MediaQuery $offset = $page * self::PER_PAGE_ADMIN; $limit = self::PER_PAGE_ADMIN; } else { - $userCode = $this->db->query('SELECT `user_code` FROM `users` WHERE `id` = ?', [$this->userId])->fetch()->user_code; + $userCode = $this->db->query('SELECT `user_code` FROM `users` WHERE `id` = ?', array($this->userId))->fetch()->user_code; $files = $this->storage->listFiles($userCode); $this->pages = count($files) / self::PER_PAGE; @@ -178,9 +198,9 @@ class MediaQuery if ($this->text !== null) { if ($this->isAdmin) { - $medias = $this->db->query('SELECT `uploads`.*, `users`.`user_code`, `users`.`username` FROM `uploads` LEFT JOIN `users` ON `uploads`.`user_id` = `users`.`id` WHERE `uploads`.`filename` LIKE ? ', ['%'.htmlentities($this->text).'%'])->fetchAll(); + $medias = $this->db->query('SELECT `uploads`.*, `users`.`user_code`, `users`.`username` FROM `uploads` LEFT JOIN `users` ON `uploads`.`user_id` = `users`.`id` WHERE `uploads`.`filename` LIKE ? ', array('%'.htmlentities($this->text).'%'))->fetchAll(); } else { - $medias = $this->db->query('SELECT `uploads`.*, `users`.`user_code`, `users`.`username` FROM `uploads` LEFT JOIN `users` ON `uploads`.`user_id` = `users`.`id` WHERE `user_id` = ? AND `uploads`.`filename` LIKE ? ', [$this->userId, '%'.htmlentities($this->text).'%'])->fetchAll(); + $medias = $this->db->query('SELECT `uploads`.*, `users`.`user_code`, `users`.`username` FROM `uploads` LEFT JOIN `users` ON `uploads`.`user_id` = `users`.`id` WHERE `user_id` = ? AND `uploads`.`filename` LIKE ? ', array($this->userId, '%'.htmlentities($this->text).'%'))->fetchAll(); } $paths = array_column($files, 'path'); @@ -196,7 +216,7 @@ class MediaQuery $paths[$media->storage_path] = $media; } - $this->media = []; + $this->media = array(); foreach ($files as $file) { $media = $paths[$file['path']]; if (!is_object($media)) { diff --git a/app/Exceptions/Handlers/AppErrorHandler.php b/app/Exceptions/Handlers/AppErrorHandler.php index 323e4a7..5e46e34 100644 --- a/app/Exceptions/Handlers/AppErrorHandler.php +++ b/app/Exceptions/Handlers/AppErrorHandler.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Exception\Handlers; use Slim\Handlers\ErrorHandler; diff --git a/app/Exceptions/Handlers/Renderers/HtmlErrorRenderer.php b/app/Exceptions/Handlers/Renderers/HtmlErrorRenderer.php index e1987fc..2731fb2 100644 --- a/app/Exceptions/Handlers/Renderers/HtmlErrorRenderer.php +++ b/app/Exceptions/Handlers/Renderers/HtmlErrorRenderer.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Exception\Handlers\Renderers; use App\Exceptions\UnderMaintenanceException; @@ -45,6 +65,6 @@ class HtmlErrorRenderer implements ErrorRendererInterface return view()->string('errors/400.twig'); } - return view()->string('errors/500.twig', ['exception' => $displayErrorDetails ? $exception : null]); + return view()->string('errors/500.twig', array('exception' => $displayErrorDetails ? $exception : null)); } } diff --git a/app/Exceptions/UnderMaintenanceException.php b/app/Exceptions/UnderMaintenanceException.php index 741178d..86d4a8b 100644 --- a/app/Exceptions/UnderMaintenanceException.php +++ b/app/Exceptions/UnderMaintenanceException.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Exceptions; use Slim\Exception\HttpSpecializedException; diff --git a/app/Factories/ViewFactory.php b/app/Factories/ViewFactory.php index 2298819..b45b5fb 100644 --- a/app/Factories/ViewFactory.php +++ b/app/Factories/ViewFactory.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Factories; use App\Web\View; @@ -16,12 +36,12 @@ class ViewFactory $config = $container->get('config'); $loader = new FilesystemLoader(BASE_DIR.'resources/templates'); - $twig = new Environment($loader, [ + $twig = new Environment($loader, array( 'cache' => BASE_DIR.'resources/cache/twig', 'autoescape' => 'html', 'debug' => $config['debug'], 'auto_reload' => $config['debug'], - ]); + )); $request = ServerRequestCreatorFactory::determineServerRequestCreator()->createServerRequestFromGlobals(); @@ -47,14 +67,14 @@ class ViewFactory public static function createInstallerInstance(Container $container) { $config = $container->get('config'); - $loader = new FilesystemLoader([BASE_DIR.'install/templates', BASE_DIR.'resources/templates']); + $loader = new FilesystemLoader(array(BASE_DIR.'install/templates', BASE_DIR.'resources/templates')); - $twig = new Environment($loader, [ + $twig = new Environment($loader, array( 'cache' => false, 'autoescape' => 'html', 'debug' => $config['debug'], 'auto_reload' => $config['debug'], - ]); + )); $request = ServerRequestCreatorFactory::determineServerRequestCreator()->createServerRequestFromGlobals(); diff --git a/app/Middleware/AdminMiddleware.php b/app/Middleware/AdminMiddleware.php index 7ae07c1..cd24cc2 100644 --- a/app/Middleware/AdminMiddleware.php +++ b/app/Middleware/AdminMiddleware.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Middleware; use GuzzleHttp\Psr7\Response; @@ -20,7 +40,7 @@ class AdminMiddleware extends Middleware */ public function __invoke(Request $request, RequestHandler $handler): ResponseInterface { - if (!$this->database->query('SELECT `id`, `is_admin` FROM `users` WHERE `id` = ? LIMIT 1', [$this->session->get('user_id')])->fetch()->is_admin) { + if (!$this->database->query('SELECT `id`, `is_admin` FROM `users` WHERE `id` = ? LIMIT 1', array($this->session->get('user_id')))->fetch()->is_admin) { $this->session->set('admin', false); throw new HttpUnauthorizedException($request); diff --git a/app/Middleware/AuthMiddleware.php b/app/Middleware/AuthMiddleware.php index 36ff679..0a037ef 100644 --- a/app/Middleware/AuthMiddleware.php +++ b/app/Middleware/AuthMiddleware.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Middleware; use GuzzleHttp\Psr7\Response; @@ -23,7 +43,7 @@ class AuthMiddleware extends Middleware return redirect(new Response(), route('login.show')); } - if (!$this->database->query('SELECT `id`, `active` FROM `users` WHERE `id` = ? LIMIT 1', [$this->session->get('user_id')])->fetch()->active) { + if (!$this->database->query('SELECT `id`, `active` FROM `users` WHERE `id` = ? LIMIT 1', array($this->session->get('user_id')))->fetch()->active) { $this->session->alert(lang('account_disabled'), 'danger'); $this->session->set('logged', false); diff --git a/app/Middleware/CheckForMaintenanceMiddleware.php b/app/Middleware/CheckForMaintenanceMiddleware.php index dfd2eb1..8075ded 100644 --- a/app/Middleware/CheckForMaintenanceMiddleware.php +++ b/app/Middleware/CheckForMaintenanceMiddleware.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Middleware; use App\Exceptions\UnderMaintenanceException; @@ -19,7 +39,7 @@ class CheckForMaintenanceMiddleware extends Middleware */ public function __invoke(Request $request, RequestHandler $handler): Response { - if (isset($this->config['maintenance']) && $this->config['maintenance'] && !$this->database->query('SELECT `id`, `is_admin` FROM `users` WHERE `id` = ? LIMIT 1', [$this->session->get('user_id')])->fetch()->is_admin) { + if (isset($this->config['maintenance']) && $this->config['maintenance'] && !$this->database->query('SELECT `id`, `is_admin` FROM `users` WHERE `id` = ? LIMIT 1', array($this->session->get('user_id')))->fetch()->is_admin) { throw new UnderMaintenanceException($request); } diff --git a/app/Middleware/InjectMiddleware.php b/app/Middleware/InjectMiddleware.php index 8252054..5c0bf43 100644 --- a/app/Middleware/InjectMiddleware.php +++ b/app/Middleware/InjectMiddleware.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Middleware; use Psr\Http\Message\ResponseInterface as Response; diff --git a/app/Middleware/LangMiddleware.php b/app/Middleware/LangMiddleware.php index c62d03d..0350f95 100644 --- a/app/Middleware/LangMiddleware.php +++ b/app/Middleware/LangMiddleware.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Middleware; use Psr\Http\Message\ResponseInterface as Response; diff --git a/app/Middleware/Middleware.php b/app/Middleware/Middleware.php index fde94ab..621f110 100644 --- a/app/Middleware/Middleware.php +++ b/app/Middleware/Middleware.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Middleware; use App\Controllers\Controller; diff --git a/app/Middleware/RememberMiddleware.php b/app/Middleware/RememberMiddleware.php index e4fd8b6..bd4d3f6 100644 --- a/app/Middleware/RememberMiddleware.php +++ b/app/Middleware/RememberMiddleware.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Middleware; use Psr\Http\Message\ResponseInterface as Response; @@ -20,7 +40,7 @@ class RememberMiddleware extends Middleware list($selector, $token) = explode(':', $request->getCookieParams()['remember']); $result = $this->database->query('SELECT `id`, `email`, `username`,`is_admin`, `active`, `remember_token` FROM `users` WHERE `remember_selector` = ? AND `remember_expire` > ? LIMIT 1', - [$selector, date('Y-m-d\TH:i:s', time())] + array($selector, date('Y-m-d\TH:i:s', time())) )->fetch(); if ($result && password_verify($token, $result->remember_token) && $result->active) { diff --git a/app/Web/Lang.php b/app/Web/Lang.php index c4e4664..4eef88e 100644 --- a/app/Web/Lang.php +++ b/app/Web/Lang.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Web; class Lang @@ -17,7 +37,7 @@ class Lang protected static $instance; /** @var array */ - protected $cache = []; + protected $cache = array(); /** * @return Lang @@ -85,7 +105,7 @@ class Lang */ public static function getList() { - $languages = []; + $languages = array(); $default = count(include self::$langPath.self::DEFAULT_LANG.'.lang.php') - 1; @@ -111,7 +131,7 @@ class Lang * * @return string */ - public function get($key, $args = []): string + public function get($key, $args = array()): string { return $this->getString($key, self::$lang, $args); } @@ -138,7 +158,7 @@ class Lang $transDict = include self::$langPath.$redLang.'.lang.php'; $this->cache[$lang] = $transDict; } else { - $transDict = []; + $transDict = array(); } } } diff --git a/app/Web/Session.php b/app/Web/Session.php index 697ce08..a9adbd9 100644 --- a/app/Web/Session.php +++ b/app/Web/Session.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Web; use Exception; @@ -33,13 +53,13 @@ class Session ); } - $started = @session_start([ + $started = @session_start(array( 'name' => $name, 'save_path' => $path, 'cookie_httponly' => true, 'gc_probability' => 25, 'cookie_samesite' => 'Lax', // works only for php >= 7.3 - ]); + )); if (!$started) { throw new Exception("Cannot start the HTTP session. That the session path '{$path}' is writable and your PHP settings."); @@ -70,7 +90,7 @@ class Session */ public function clear(): void { - $_SESSION = []; + $_SESSION = array(); } /** @@ -127,7 +147,7 @@ class Session */ public function alert($message, string $type = 'info'): void { - $_SESSION['_flash'][] = [$type => $message]; + $_SESSION['_flash'][] = array($type => $message); } /** @@ -138,7 +158,7 @@ class Session public function getAlert(): ?array { $flash = self::get('_flash'); - self::set('_flash', []); + self::set('_flash', array()); return $flash; } diff --git a/app/Web/View.php b/app/Web/View.php index 42c7a9b..f219250 100644 --- a/app/Web/View.php +++ b/app/Web/View.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + namespace App\Web; use Psr\Http\Message\ResponseInterface as Response; @@ -36,7 +56,7 @@ class View * * @return Response */ - public function render(Response $response, string $view, ?array $parameters = []) + public function render(Response $response, string $view, ?array $parameters = array()) { $body = $this->twig->render($view, $parameters); $response->getBody()->write($body); @@ -54,7 +74,7 @@ class View * * @return string */ - public function string(string $view, ?array $parameters = []) + public function string(string $view, ?array $parameters = array()) { return $this->twig->render($view, $parameters); } diff --git a/app/helpers.php b/app/helpers.php index dd150b8..daae622 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Factory\ServerRequestCreatorFactory; @@ -22,7 +42,7 @@ if (!function_exists('humanFileSize')) { for ($i = 0; ($size / 1024) > 0.9; $i++, $size /= 1024) { } - return round($size, $precision).' '.['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'][$i]; + return round($size, $precision).' '.array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB')[$i]; } } @@ -55,7 +75,7 @@ if (!function_exists('isDisplayableImage')) { */ function isDisplayableImage(string $mime): bool { - return in_array($mime, [ + return in_array($mime, array( 'image/apng', 'image/bmp', 'image/gif', @@ -66,7 +86,7 @@ if (!function_exists('isDisplayableImage')) { 'image/svg+xml', 'image/tiff', 'image/webp', - ]); + )); } } @@ -221,7 +241,7 @@ if (!function_exists('route')) { * * @return string */ - function route(string $path, array $args = [], string $append = ''): string + function route(string $path, array $args = array(), string $append = ''): string { global $app; $uri = $app->getRouteCollector()->getRouteParser()->relativeUrlFor($path, $args); @@ -284,7 +304,7 @@ if (!function_exists('lang')) { * * @return string */ - function lang(string $key, $args = []): string + function lang(string $key, $args = array()): string { return resolve('lang')->get($key, $args); } @@ -298,7 +318,7 @@ if (!function_exists('isBot')) { */ function isBot(string $userAgent) { - $bots = [ + $bots = array( 'TelegramBot', 'facebookexternalhit/', 'Discordbot/', @@ -306,7 +326,7 @@ if (!function_exists('isBot')) { 'Facebot', 'curl/', 'wget/', - ]; + ); foreach ($bots as $bot) { if (stripos($userAgent, $bot) !== false) { @@ -328,7 +348,7 @@ if (!function_exists('mime2font')) { */ function mime2font($mime) { - $classes = [ + $classes = array( 'image' => 'fa-file-image', 'audio' => 'fa-file-audio', 'video' => 'fa-file-video', @@ -350,7 +370,7 @@ if (!function_exists('mime2font')) { 'application/gzip' => 'fa-file-archive', 'application/zip' => 'fa-file-archive', 'application/octet-stream' => 'fa-file-alt', - ]; + ); foreach ($classes as $fullMime => $class) { if (strpos($mime, $fullMime) === 0) { @@ -385,7 +405,7 @@ if (!function_exists('queryParams')) { * * @return string */ - function queryParams(array $replace = []) + function queryParams(array $replace = array()) { $request = ServerRequestCreatorFactory::determineServerRequestCreator()->createServerRequestFromGlobals(); diff --git a/app/routes.php b/app/routes.php index c7cae2e..f185378 100644 --- a/app/routes.php +++ b/app/routes.php @@ -1,6 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + use App\Controllers\AdminController; use App\Controllers\ClientController; use App\Controllers\DashboardController; @@ -17,58 +36,58 @@ use Slim\Routing\RouteCollectorProxy; global $app; $app->group('', function (RouteCollectorProxy $group) { - $group->get('/home[/page/{page}]', [DashboardController::class, 'home'])->setName('home'); - $group->get('/upload', [UploadController::class, 'webUpload'])->setName('upload.web'); + $group->get('/home[/page/{page}]', array(DashboardController::class, 'home'))->setName('home'); + $group->get('/upload', array(UploadController::class, 'webUpload'))->setName('upload.web'); $group->group('', function (RouteCollectorProxy $group) { - $group->get('/home/switchView', [DashboardController::class, 'switchView'])->setName('switchView'); + $group->get('/home/switchView', array(DashboardController::class, 'switchView'))->setName('switchView'); - $group->get('/system/deleteOrphanFiles', [AdminController::class, 'deleteOrphanFiles'])->setName('system.deleteOrphanFiles'); + $group->get('/system/deleteOrphanFiles', array(AdminController::class, 'deleteOrphanFiles'))->setName('system.deleteOrphanFiles'); - $group->get('/system/themes', [ThemeController::class, 'getThemes'])->setName('theme'); - $group->post('/system/theme/apply', [ThemeController::class, 'applyTheme'])->setName('theme.apply'); + $group->get('/system/themes', array(ThemeController::class, 'getThemes'))->setName('theme'); + $group->post('/system/theme/apply', array(ThemeController::class, 'applyTheme'))->setName('theme.apply'); - $group->post('/system/lang/apply', [AdminController::class, 'applyLang'])->setName('lang.apply'); + $group->post('/system/lang/apply', array(AdminController::class, 'applyLang'))->setName('lang.apply'); - $group->post('/system/customHead', [AdminController::class, 'applyCustomHead'])->setName('customHead.apply'); + $group->post('/system/customHead', array(AdminController::class, 'applyCustomHead'))->setName('customHead.apply'); - $group->post('/system/upgrade', [UpgradeController::class, 'upgrade'])->setName('system.upgrade'); - $group->get('/system/checkForUpdates', [UpgradeController::class, 'checkForUpdates'])->setName('system.checkForUpdates'); + $group->post('/system/upgrade', array(UpgradeController::class, 'upgrade'))->setName('system.upgrade'); + $group->get('/system/checkForUpdates', array(UpgradeController::class, 'checkForUpdates'))->setName('system.checkForUpdates'); - $group->get('/system', [AdminController::class, 'system'])->setName('system'); + $group->get('/system', array(AdminController::class, 'system'))->setName('system'); - $group->get('/users[/page/{page}]', [UserController::class, 'index'])->setName('user.index'); + $group->get('/users[/page/{page}]', array(UserController::class, 'index'))->setName('user.index'); })->add(AdminMiddleware::class); $group->group('/user', function (RouteCollectorProxy $group) { - $group->get('/create', [UserController::class, 'create'])->setName('user.create'); - $group->post('/create', [UserController::class, 'store'])->setName('user.store'); - $group->get('/{id}/edit', [UserController::class, 'edit'])->setName('user.edit'); - $group->post('/{id}', [UserController::class, 'update'])->setName('user.update'); - $group->get('/{id}/delete', [UserController::class, 'delete'])->setName('user.delete'); + $group->get('/create', array(UserController::class, 'create'))->setName('user.create'); + $group->post('/create', array(UserController::class, 'store'))->setName('user.store'); + $group->get('/{id}/edit', array(UserController::class, 'edit'))->setName('user.edit'); + $group->post('/{id}', array(UserController::class, 'update'))->setName('user.update'); + $group->get('/{id}/delete', array(UserController::class, 'delete'))->setName('user.delete'); })->add(AdminMiddleware::class); - $group->get('/profile', [UserController::class, 'profile'])->setName('profile'); - $group->post('/profile/{id}', [UserController::class, 'profileEdit'])->setName('profile.update'); - $group->post('/user/{id}/refreshToken', [UserController::class, 'refreshToken'])->setName('refreshToken'); - $group->get('/user/{id}/config/sharex', [ClientController::class, 'getShareXConfig'])->setName('config.sharex'); - $group->get('/user/{id}/config/script', [ClientController::class, 'getBashScript'])->setName('config.script'); + $group->get('/profile', array(UserController::class, 'profile'))->setName('profile'); + $group->post('/profile/{id}', array(UserController::class, 'profileEdit'))->setName('profile.update'); + $group->post('/user/{id}/refreshToken', array(UserController::class, 'refreshToken'))->setName('refreshToken'); + $group->get('/user/{id}/config/sharex', array(ClientController::class, 'getShareXConfig'))->setName('config.sharex'); + $group->get('/user/{id}/config/script', array(ClientController::class, 'getBashScript'))->setName('config.script'); - $group->post('/upload/{id}/publish', [MediaController::class, 'togglePublish'])->setName('upload.publish'); - $group->post('/upload/{id}/unpublish', [MediaController::class, 'togglePublish'])->setName('upload.unpublish'); - $group->get('/upload/{id}/raw', [MediaController::class, 'getRawById'])->add(AdminMiddleware::class)->setName('upload.raw'); - $group->map(['GET', 'POST'], '/upload/{id}/delete', [MediaController::class, 'delete'])->setName('upload.delete'); + $group->post('/upload/{id}/publish', array(MediaController::class, 'togglePublish'))->setName('upload.publish'); + $group->post('/upload/{id}/unpublish', array(MediaController::class, 'togglePublish'))->setName('upload.unpublish'); + $group->get('/upload/{id}/raw', array(MediaController::class, 'getRawById'))->add(AdminMiddleware::class)->setName('upload.raw'); + $group->map(array('GET', 'POST'), '/upload/{id}/delete', array(MediaController::class, 'delete'))->setName('upload.delete'); })->add(App\Middleware\CheckForMaintenanceMiddleware::class)->add(AuthMiddleware::class); -$app->get('/', [DashboardController::class, 'redirects'])->setName('root'); -$app->get('/login', [LoginController::class, 'show'])->setName('login.show'); -$app->post('/login', [LoginController::class, 'login'])->setName('login'); -$app->map(['GET', 'POST'], '/logout', [LoginController::class, 'logout'])->setName('logout'); +$app->get('/', array(DashboardController::class, 'redirects'))->setName('root'); +$app->get('/login', array(LoginController::class, 'show'))->setName('login.show'); +$app->post('/login', array(LoginController::class, 'login'))->setName('login'); +$app->map(array('GET', 'POST'), '/logout', array(LoginController::class, 'logout'))->setName('logout'); -$app->post('/upload', [UploadController::class, 'upload'])->setName('upload'); +$app->post('/upload', array(UploadController::class, 'upload'))->setName('upload'); -$app->get('/{userCode}/{mediaCode}', [MediaController::class, 'show'])->setName('public'); -$app->get('/{userCode}/{mediaCode}/delete/{token}', [MediaController::class, 'show'])->setName('public.delete.show')->add(CheckForMaintenanceMiddleware::class); -$app->post('/{userCode}/{mediaCode}/delete/{token}', [MediaController::class, 'deleteByToken'])->setName('public.delete')->add(CheckForMaintenanceMiddleware::class); -$app->get('/{userCode}/{mediaCode}/raw[.{ext}]', [MediaController::class, 'getRaw'])->setName('public.raw'); -$app->get('/{userCode}/{mediaCode}/download', [MediaController::class, 'download'])->setName('public.download'); +$app->get('/{userCode}/{mediaCode}', array(MediaController::class, 'show'))->setName('public'); +$app->get('/{userCode}/{mediaCode}/delete/{token}', array(MediaController::class, 'show'))->setName('public.delete.show')->add(CheckForMaintenanceMiddleware::class); +$app->post('/{userCode}/{mediaCode}/delete/{token}', array(MediaController::class, 'deleteByToken'))->setName('public.delete')->add(CheckForMaintenanceMiddleware::class); +$app->get('/{userCode}/{mediaCode}/raw[.{ext}]', array(MediaController::class, 'getRaw'))->setName('public.raw'); +$app->get('/{userCode}/{mediaCode}/download', array(MediaController::class, 'download'))->setName('public.download'); diff --git a/bootstrap/app.php b/bootstrap/app.php index b45f96a..86cda78 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + use App\Exception\Handlers\AppErrorHandler; use App\Exception\Handlers\Renderers\HtmlErrorRenderer; use App\Factories\ViewFactory; @@ -26,22 +46,22 @@ if (!file_exists('config.php') && is_dir('install/')) { } // Load the config -$config = array_replace_recursive([ +$config = array_replace_recursive(array( 'app_name' => 'XBackBone', 'base_url' => isset($_SERVER['HTTPS']) ? 'https://'.$_SERVER['HTTP_HOST'] : 'http://'.$_SERVER['HTTP_HOST'], 'debug' => false, 'maintenance' => false, - 'db' => [ + 'db' => array( 'connection' => 'sqlite', 'dsn' => BASE_DIR.'resources/database/xbackbone.db', 'username' => null, 'password' => null, - ], - 'storage' => [ + ), + 'storage' => array( 'driver' => 'local', 'path' => realpath(__DIR__.'/').DIRECTORY_SEPARATOR.'storage', - ], -], require BASE_DIR.'config.php'); + ), +), require BASE_DIR.'config.php'); $builder = new ContainerBuilder(); @@ -50,13 +70,13 @@ if (!$config['debug']) { $builder->writeProxiesToFile(true, BASE_DIR.'/resources/cache/proxies'); } -$builder->addDefinitions([ +$builder->addDefinitions(array( 'config' => value($config), View::class => factory(function (Container $container) { return ViewFactory::createAppInstance($container); }), 'view' => get(View::class), -]); +)); $builder->addDefinitions(__DIR__.'/container.php'); diff --git a/bootstrap/container.php b/bootstrap/container.php index fd23552..8936a65 100644 --- a/bootstrap/container.php +++ b/bootstrap/container.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + use App\Database\DB; use App\Web\Lang; use App\Web\Session; @@ -19,7 +39,7 @@ use Spatie\Dropbox\Client as DropboxClient; use Spatie\FlysystemDropbox\DropboxAdapter; use Superbalist\Flysystem\GoogleStorage\GoogleStorageAdapter; -return [ +return array( Logger::class => factory(function () { $logger = new Logger('app'); @@ -54,22 +74,22 @@ return [ case 'local': return new Filesystem(new Local($config['storage']['path'])); case 's3': - $client = new S3Client([ - 'credentials' => [ + $client = new S3Client(array( + 'credentials' => array( 'key' => $config['storage']['key'], 'secret' => $config['storage']['secret'], - ], + ), 'region' => $config['storage']['region'], 'version' => 'latest', - ]); + )); return new Filesystem(new AwsS3Adapter($client, $config['storage']['bucket'], $config['storage']['path'])); case 'dropbox': $client = new DropboxClient($config['storage']['token']); - return new Filesystem(new DropboxAdapter($client), ['case_sensitive' => false]); + return new Filesystem(new DropboxAdapter($client), array('case_sensitive' => false)); case 'ftp': - return new Filesystem(new FtpAdapter([ + return new Filesystem(new FtpAdapter(array( 'host' => $config['storage']['host'], 'username' => $config['storage']['username'], 'password' => $config['storage']['password'], @@ -78,12 +98,12 @@ return [ 'passive' => $config['storage']['passive'], 'ssl' => $config['storage']['ssl'], 'timeout' => 30, - ])); + ))); case 'google-cloud': - $client = new StorageClient([ + $client = new StorageClient(array( 'projectId' => $config['storage']['project_id'], 'keyFilePath' => $config['storage']['key_path'], - ]); + )); return new Filesystem(new GoogleStorageAdapter($client, $client->bucket($config['storage']['bucket']))); default: @@ -96,4 +116,4 @@ return [ return Lang::build(Lang::recognize(), BASE_DIR.'resources/lang/'); }), 'lang' => get(Lang::class), -]; +); diff --git a/config.example.php b/config.example.php index d9e4667..d7c3e6e 100644 --- a/config.example.php +++ b/config.example.php @@ -1,15 +1,35 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + +return array( 'base_url' => 'https://localhost', // no trailing slash - 'db' => [ + 'db' => array( 'connection' => 'sqlite', 'dsn' => 'resources/database/xbackbone.db', 'username' => null, 'password' => null, - ], - 'storage' => [ + ), + 'storage' => array( 'driver' => 'local', 'path' => './storage', - ], -]; + ), +); diff --git a/index.php b/index.php index 6427241..f9bf202 100644 --- a/index.php +++ b/index.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + (PHP_MAJOR_VERSION >= 7 && PHP_MINOR_VERSION >= 1) ?: die('Sorry, PHP 7.1 or above is required to run XBackBone.'); require __DIR__.'/vendor/autoload.php'; diff --git a/install/index.php b/install/index.php index 60420fa..f85fd9f 100644 --- a/install/index.php +++ b/install/index.php @@ -1,5 +1,25 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + (PHP_MAJOR_VERSION >= 7 && PHP_MINOR_VERSION >= 1) ?: die('Sorry, PHP 7.1 or above is required to run XBackBone.'); require __DIR__.'/../vendor/autoload.php'; @@ -23,20 +43,20 @@ define('PLATFORM_VERSION', json_decode(file_get_contents(__DIR__.'/../composer.j define('BASE_DIR', realpath(__DIR__.'/../').DIRECTORY_SEPARATOR); // default config -$config = [ +$config = array( 'base_url' => str_replace('/install/', '', (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http')."://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"), 'debug' => true, - 'db' => [ + 'db' => array( 'connection' => 'sqlite', - 'dsn' => realpath(__DIR__.'/../').implode(DIRECTORY_SEPARATOR, ['resources', 'database', 'xbackbone.db']), + 'dsn' => realpath(__DIR__.'/../').implode(DIRECTORY_SEPARATOR, array('resources', 'database', 'xbackbone.db')), 'username' => null, 'password' => null, - ], - 'storage' => [ + ), + 'storage' => array( 'driver' => 'local', 'path' => realpath(__DIR__.'/../').DIRECTORY_SEPARATOR.'storage', - ], -]; + ), +); if (file_exists(__DIR__.'/../config.php')) { $config = array_replace_recursive($config, require __DIR__.'/../config.php'); @@ -44,13 +64,13 @@ if (file_exists(__DIR__.'/../config.php')) { $builder = new ContainerBuilder(); -$builder->addDefinitions([ +$builder->addDefinitions(array( 'config' => value($config), View::class => factory(function (Container $container) { return ViewFactory::createInstallerInstance($container); }), 'view' => get(View::class), -]); +)); $builder->addDefinitions(__DIR__.'/../bootstrap/container.php'); $app = Bridge::create($builder->build()); @@ -88,9 +108,9 @@ $app->get('/', function (Response $response, View $view, Session $session) use ( $installed = file_exists(__DIR__.'/../config.php'); - return $view->render($response, 'install.twig', [ + return $view->render($response, 'install.twig', array( 'installed' => $installed, - ]); + )); })->setName('install'); $app->post('/', function (Request $request, Response $response, Filesystem $storage, Session $session) use (&$config) { @@ -195,7 +215,7 @@ $app->post('/', function (Request $request, Response $response, Filesystem $stor // if not installed, create the default admin account if (!$installed) { - $db->query("INSERT INTO `users` (`email`, `username`, `password`, `is_admin`, `user_code`) VALUES (?, 'admin', ?, 1, ?)", [param($request, 'email'), password_hash(param($request, 'password'), PASSWORD_DEFAULT), humanRandomString(5)]); + $db->query("INSERT INTO `users` (`email`, `username`, `password`, `is_admin`, `user_code`) VALUES (?, 'admin', ?, 1, ?)", array(param($request, 'email'), password_hash(param($request, 'password'), PASSWORD_DEFAULT), humanRandomString(5))); } // post install cleanup diff --git a/resources/lang/bg.lang.php b/resources/lang/bg.lang.php index d07601a..7a74340 100644 --- a/resources/lang/bg.lang.php +++ b/resources/lang/bg.lang.php @@ -1,6 +1,26 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + +return array( 'lang' => 'Bulgarian', 'enforce_language' => 'Изберете език', 'yes' => 'Да', @@ -70,4 +90,4 @@ return [ 'user_deleted' => 'Потребителят бе изтрит.', 'cannot_delete' => 'Не можете да изтриете себе си.', 'gallery' => 'Галерия', -]; +); diff --git a/resources/lang/da.lang.php b/resources/lang/da.lang.php index 9c7ed17..a32b7e5 100644 --- a/resources/lang/da.lang.php +++ b/resources/lang/da.lang.php @@ -1,6 +1,26 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + +return array( 'lang' => 'Danish', 'yes' => 'Ja', 'no' => 'Nej', @@ -44,4 +64,4 @@ return [ 'is_active' => 'Er aktiv', 'is_admin' => 'Er administrator', 'your_profile' => 'Din Profil', -]; +); diff --git a/resources/lang/de.lang.php b/resources/lang/de.lang.php index 07cab5a..b7a5ec4 100644 --- a/resources/lang/de.lang.php +++ b/resources/lang/de.lang.php @@ -1,6 +1,26 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + +return array( 'lang' => 'German', 'yes' => 'Ja', 'no' => 'Nein', @@ -114,4 +134,4 @@ return [ 'remember_me' => 'Erinnere mich daran', 'please_wait' => 'Bitte warten…', 'dont_close' => 'Schließen Sie diesen Tab erst, wenn Sie fertig sind.', -]; +); diff --git a/resources/lang/en.lang.php b/resources/lang/en.lang.php index d00164a..6f2d20d 100644 --- a/resources/lang/en.lang.php +++ b/resources/lang/en.lang.php @@ -1,6 +1,26 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + +return array( 'lang' => 'English', 'enforce_language' => 'Enforce language', 'yes' => 'Yes', @@ -111,4 +131,4 @@ return [ 'remember_me' => 'Remember me', 'please_wait' => 'Please wait…', 'dont_close' => 'Do not close this tab until completion.', -]; +); diff --git a/resources/lang/es.lang.php b/resources/lang/es.lang.php index 204da9d..6f096b0 100644 --- a/resources/lang/es.lang.php +++ b/resources/lang/es.lang.php @@ -1,6 +1,26 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + +return array( 'lang' => 'Spanish', 'yes' => 'Si', 'no' => 'No', @@ -100,4 +120,4 @@ return [ 'lang_name' => 'nombre del lenguaje', 'default_lang_behavior' => 'XBackBone tratará de coincidir con el lenguaje predeterminado del navegador (recurrimos al Inglés automáticamente).', 'lang_set' => 'Lenguaje del sistema impuesto a "%s"', -]; +); diff --git a/resources/lang/fr.lang.php b/resources/lang/fr.lang.php index 4484a0e..13fc5a8 100644 --- a/resources/lang/fr.lang.php +++ b/resources/lang/fr.lang.php @@ -1,6 +1,26 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + +return array( 'lang' => 'French', 'yes' => 'Oui', 'no' => 'Non', @@ -93,4 +113,4 @@ return [ 'remember_me' => 'Se souvenir de moi', 'please_wait' => 'Veuillez patienter…', 'dont_close' => 'Ne fermez pas cette fenêtre jusqu\'à complétion.', -]; +); diff --git a/resources/lang/it.lang.php b/resources/lang/it.lang.php index 561c0fb..0ab0835 100644 --- a/resources/lang/it.lang.php +++ b/resources/lang/it.lang.php @@ -1,5 +1,26 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + +return array( 'lang' => 'Italian', 'yes' => 'Sì', 'no' => 'No', @@ -110,4 +131,4 @@ return [ 'remember_me' => 'Ricordami', 'please_wait' => 'Attendere prego…', 'dont_close' => 'Non chiudere questa scheda fino al completamento.', -]; +); diff --git a/resources/lang/nb_NO.lang.php b/resources/lang/nb_NO.lang.php index ff3b4fb..70ed5d9 100644 --- a/resources/lang/nb_NO.lang.php +++ b/resources/lang/nb_NO.lang.php @@ -1,6 +1,26 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + +return array( 'theme' => 'Drakt', 'username_taken' => 'Brukernavnet er i bruk.', 'file_size_no_match' => 'Nedlastet fil samsvarer ikke med riktig filstørrelse.', @@ -110,4 +130,4 @@ return [ 'custom_head_set' => 'Egendefinert HTML-hode lagt til.', 'remember_me' => 'Husk meg', 'please_wait' => 'Vent…', -]; +); diff --git a/resources/lang/nl.lang.php b/resources/lang/nl.lang.php index 7967baf..e95680b 100644 --- a/resources/lang/nl.lang.php +++ b/resources/lang/nl.lang.php @@ -1,6 +1,26 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + +return array( 'lang' => 'Dutch', 'yes' => 'Ja', 'no' => 'Nee', @@ -102,4 +122,4 @@ return [ 'lang_name' => 'Taal', 'default_lang_behavior' => 'XBackBone probeert standaard de taal van de browser te matchen (fallback is Engels).', 'lang_set' => 'Systeemtaal "%s" afgedwongen', -]; +); diff --git a/resources/lang/pt.lang.php b/resources/lang/pt.lang.php index eed3945..83ef70b 100644 --- a/resources/lang/pt.lang.php +++ b/resources/lang/pt.lang.php @@ -1,6 +1,26 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + +return array( 'lang' => 'Portuguese', 'yes' => 'Sim', 'no' => 'Não', @@ -44,4 +64,4 @@ return [ 'your_profile' => 'O teu perfil', 'token' => 'Token', 'copy' => 'Copiar', -]; +); diff --git a/resources/lang/ru.lang.php b/resources/lang/ru.lang.php index 9fdf19c..9f7e02a 100644 --- a/resources/lang/ru.lang.php +++ b/resources/lang/ru.lang.php @@ -1,6 +1,26 @@ + * + * @author Sergio Brighenti + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + */ + +return array( 'lang' => 'Russian', 'yes' => 'Да', 'no' => 'Нет', @@ -102,4 +122,4 @@ return [ 'lang_name' => 'язык', 'default_lang_behavior' => 'XBackBone попробует выбрать язык вашего браузера по умолчанию, иначе будет выбран Английский.', 'lang_set' => 'Выбран следующий язык: "%s"', -]; +);