Skip to content

Commit

Permalink
Rename system folder to core and replace \Aurora\System namespace wit…
Browse files Browse the repository at this point in the history
…h \Aurora\Core
  • Loading branch information
Usbac committed Sep 7, 2024
1 parent a442406 commit 8e4dc15
Show file tree
Hide file tree
Showing 63 changed files with 165 additions and 165 deletions.
4 changes: 2 additions & 2 deletions app/bootstrap/config.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

$db_folder = \Aurora\System\Helper::getPath('app/database');
$db_folder = \Aurora\Core\Helper::getPath('app/database');
$db_file = "$db_folder/db.sqlite";
$db_exists = file_exists($db_file);
if (!$db_exists) {
file_put_contents($db_file, '');
}

$db = new \Aurora\System\DB("sqlite:$db_file");
$db = new \Aurora\Core\DB("sqlite:$db_file");

if (!$db_exists) {
(new \Aurora\App\Migration($db))->import(json_decode(file_get_contents("$db_folder/fixtures.json"), true)['tables']);
Expand Down
14 changes: 7 additions & 7 deletions app/bootstrap/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function e($val): string
if (!function_exists('t')) {
function t(?string $key = null, bool $escape = true)
{
$text = \Aurora\System\Container::get('language')->get($key);
$text = \Aurora\Core\Container::get('language')->get($key);
return $key && $escape ? e($text) : $text;
}
}
Expand All @@ -29,25 +29,25 @@ function setting(?string $key = null): mixed
}
}

return function (\Aurora\System\Kernel $kernel) {
return function (\Aurora\Core\Kernel $kernel) {
$languages = [];
foreach (glob(\Aurora\System\Helper::getPath('app/languages/*.php')) as $file) {
foreach (glob(\Aurora\Core\Helper::getPath('app/languages/*.php')) as $file) {
$languages[pathinfo($file, PATHINFO_FILENAME)] = require_once($file);
}

$db = $kernel->config('db');
$lang = new \Aurora\System\Language($languages);
$view = new \Aurora\System\View(\Aurora\System\Helper::getPath(\Aurora\System\Kernel::config('views')), new \Aurora\App\ViewHelper());
$lang = new \Aurora\Core\Language($languages);
$view = new \Aurora\Core\View(\Aurora\Core\Helper::getPath(\Aurora\Core\Kernel::config('views')), new \Aurora\App\ViewHelper());
$settings = $db->query('SELECT `key`, value FROM settings')->fetchAll(\PDO::FETCH_KEY_PAIR);
$permissions = $db->query('SELECT permission, role_level FROM roles_permissions ORDER BY permission')->fetchAll(\PDO::FETCH_KEY_PAIR);

$lang->setCode($settings['language']);

\Aurora\System\Container::set('language', $lang);
\Aurora\Core\Container::set('language', $lang);
\Aurora\App\Permission::set($permissions, $_SESSION['user']['role'] ?? 0);
\Aurora\App\Permission::addMethod('impersonate', fn($user) => ($user['status'] ?? false) && $user['role'] <= ($_SESSION['user']['role'] ?? 0) && \Aurora\App\Permission::can('impersonate'));
\Aurora\App\Setting::set($settings);
\Aurora\App\Media::setDirectory(\Aurora\System\Kernel::config('content'));
\Aurora\App\Media::setDirectory(\Aurora\Core\Kernel::config('content'));

(require('routes.php'))($kernel->router, $db, $view, $lang);
};
30 changes: 15 additions & 15 deletions app/bootstrap/routes.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Aurora\System\{DB, Helper, Kernel, Language, Route, View};
use Aurora\Core\{DB, Helper, Kernel, Language, Route, View};

const ITEMS_PER_PAGE = 20;

Expand All @@ -15,14 +15,14 @@
$theme_dir = 'themes/' . \Aurora\App\Setting::get('theme');

$router->middleware('*', function() use ($db) {
if (\Aurora\System\Helper::isValidId($_SESSION['user']['id'] ?? false)) {
if (\Aurora\Core\Helper::isValidId($_SESSION['user']['id'] ?? false)) {
$_SESSION['user'] = $db->query('SELECT * FROM users WHERE id = ? AND status', $_SESSION['user']['id'])
->fetch();
}
});

$router->middleware('*', function() use ($view, $lang, $theme_dir) {
if (\Aurora\App\Setting::get('maintenance') && !str_starts_with(Helper::getCurrentPath(), 'admin') && !\Aurora\System\Helper::isValidId($_SESSION['user']['id'] ?? false)) {
if (\Aurora\App\Setting::get('maintenance') && !str_starts_with(Helper::getCurrentPath(), 'admin') && !\Aurora\Core\Helper::isValidId($_SESSION['user']['id'] ?? false)) {
echo $view->get("$theme_dir/information.php", [
'description' => $lang->get('under_maintenance'),
'subdescription' => $lang->get('come_back_soon'),
Expand All @@ -32,7 +32,7 @@
});

$router->middleware('*', function() {
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !\Aurora\System\Helper::isCsrfTokenValid($_POST['csrf'] ?? '')) {
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !\Aurora\Core\Helper::isCsrfTokenValid($_POST['csrf'] ?? '')) {
echo json_encode([ 'reload' => true ]);
exit;
}
Expand All @@ -51,19 +51,19 @@
*/

$router->middleware('admin/*', function() use ($db) {
if ((!\Aurora\System\Helper::isValidId($_SESSION['user']['id'] ?? false) || !($_SESSION['user']['status'] ?? false)) &&
if ((!\Aurora\Core\Helper::isValidId($_SESSION['user']['id'] ?? false) || !($_SESSION['user']['status'] ?? false)) &&
!in_array(Helper::getCurrentPath(), [ 'admin', 'admin/login', 'admin/send_password_restore', 'admin/new_password', 'admin/password_restore' ])) {
header('Location: /admin');
exit;
}

if (\Aurora\System\Helper::isValidId($_SESSION['user']['id'] ?? false)) {
if (\Aurora\Core\Helper::isValidId($_SESSION['user']['id'] ?? false)) {
$db->update('users', [ 'last_active' => time() ], $_SESSION['user']['id']);
}
});

$router->get('admin', function() use ($view) {
if (\Aurora\System\Helper::isValidId($_SESSION['user']['id'] ?? false)) {
if (\Aurora\Core\Helper::isValidId($_SESSION['user']['id'] ?? false)) {
header('Location: /admin/dashboard');
}

Expand Down Expand Up @@ -162,7 +162,7 @@
});

$router->get('admin/pages/edit', function() use ($view, $link_mod, $page_mod, $theme_dir) {
$page = \Aurora\System\Helper::isValidId($_GET['id'] ?? false) ? $page_mod->get([ 'id' => $_GET['id'] ]) : [];
$page = \Aurora\Core\Helper::isValidId($_GET['id'] ?? false) ? $page_mod->get([ 'id' => $_GET['id'] ]) : [];
if (!$page && isset($_GET['id'])) {
http_response_code(404);
return;
Expand Down Expand Up @@ -259,7 +259,7 @@
});

$router->get('admin/posts/edit', function() use ($view, $user_mod, $tag_mod, $post_mod) {
$post = \Aurora\System\Helper::isValidId($_GET['id'] ?? false) ? $post_mod->get([ 'id' => $_GET['id'] ]) : [];
$post = \Aurora\Core\Helper::isValidId($_GET['id'] ?? false) ? $post_mod->get([ 'id' => $_GET['id'] ]) : [];
if (!$post && isset($_GET['id'])) {
http_response_code(404);
return;
Expand Down Expand Up @@ -353,7 +353,7 @@
});

$router->get('admin/users/edit', function() use ($db, $view, $user_mod) {
$user = \Aurora\System\Helper::isValidId($_GET['id'] ?? false) ? $user_mod->get([ 'id' => $_GET['id'] ]) : [];
$user = \Aurora\Core\Helper::isValidId($_GET['id'] ?? false) ? $user_mod->get([ 'id' => $_GET['id'] ]) : [];
if (!$user && isset($_GET['id'])) {
http_response_code(404);
return;
Expand Down Expand Up @@ -443,7 +443,7 @@
});

$router->get('admin/links/edit', function() use ($view, $link_mod) {
$link = \Aurora\System\Helper::isValidId($_GET['id'] ?? false) ? $link_mod->get([ 'id' => $_GET['id'] ]) : [];
$link = \Aurora\Core\Helper::isValidId($_GET['id'] ?? false) ? $link_mod->get([ 'id' => $_GET['id'] ]) : [];
if (!$link && isset($_GET['id'])) {
http_response_code(404);
return;
Expand Down Expand Up @@ -507,7 +507,7 @@
});

$router->get('admin/tags/edit', function() use ($view, $tag_mod) {
$tag = \Aurora\System\Helper::isValidId($_GET['id'] ?? false) ? $tag_mod->get([ 'id' => $_GET['id'] ]) : [];
$tag = \Aurora\Core\Helper::isValidId($_GET['id'] ?? false) ? $tag_mod->get([ 'id' => $_GET['id'] ]) : [];
if (!$tag && isset($_GET['id'])) {
http_response_code(404);
return;
Expand Down Expand Up @@ -551,7 +551,7 @@
$root_dir = Helper::getPath();
$content_dir = Helper::getPath(Kernel::config('content'));
$path = $_GET['path'] ?? Kernel::config('content');
$absolute_path = \Aurora\System\Helper::getPath($path);
$absolute_path = \Aurora\Core\Helper::getPath($path);

if ($path == Kernel::config('content') && !file_exists($absolute_path)) {
mkdir($absolute_path, \Aurora\App\Media::FOLDER_PERMISSION);
Expand Down Expand Up @@ -845,7 +845,7 @@
]);
}

$success = \Aurora\System\Helper::isValidId($id)
$success = \Aurora\Core\Helper::isValidId($id)
? $mod->save($id, $_POST)
: ($id = $mod->add($_POST)) !== false;

Expand All @@ -866,7 +866,7 @@
return json_encode([
'meta' => [
'created' => date('Y-m-d H:i:s'),
'version' => \Aurora\System\Kernel::VERSION,
'version' => \Aurora\Core\Kernel::VERSION,
],
'tables' => (new \Aurora\App\Migration($db))->export(),
]);
Expand Down
26 changes: 13 additions & 13 deletions app/controllers/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public static function setDirectory(string $directory): void
*/
public static function getFiles(string $path, string $search = '', string $order = 'name'): array
{
$path = \Aurora\System\Helper::getPath($path);
$path = \Aurora\Core\Helper::getPath($path);

if (!self::isValidPath($path)) {
throw new \InvalidArgumentException("Path '$path' is not a valid path within " . self::$directory);
}

$content_path_length = mb_strlen(\Aurora\System\Helper::getPath(self::$directory));
$content_path_length = mb_strlen(\Aurora\Core\Helper::getPath(self::$directory));

$files = array_map(function($file) use ($content_path_length) {
$mime = mime_content_type($file);
Expand Down Expand Up @@ -77,7 +77,7 @@ public static function getFiles(string $path, string $search = '', string $order
*/
public static function addFolder(string $path, string $name): bool
{
$path = \Aurora\System\Helper::getPath($path);
$path = \Aurora\Core\Helper::getPath($path);

if (empty(trim($name))) {
throw new \InvalidArgumentException('Folder name is empty');
Expand All @@ -98,7 +98,7 @@ public static function addFolder(string $path, string $name): bool
*/
public static function remove(string $path): bool
{
$path = \Aurora\System\Helper::getPath($path);
$path = \Aurora\Core\Helper::getPath($path);

if (!self::isValidPath($path)) {
throw new \InvalidArgumentException("Path '$path' is not a valid path within " . self::$directory);
Expand All @@ -116,7 +116,7 @@ public static function remove(string $path): bool
*/
public static function rename(string $path, string $name): bool
{
$path = \Aurora\System\Helper::getPath($path);
$path = \Aurora\Core\Helper::getPath($path);

if (!self::isValidPath($path)) {
throw new \InvalidArgumentException("Path '$path' is not a valid path within " . self::$directory);
Expand All @@ -134,8 +134,8 @@ public static function rename(string $path, string $name): bool
*/
public static function move(string $path, string $folder): bool
{
$path = \Aurora\System\Helper::getPath($path);
$folder = \Aurora\System\Helper::getPath($folder);
$path = \Aurora\Core\Helper::getPath($path);
$folder = \Aurora\Core\Helper::getPath($folder);

if (!self::isValidPath($path)) {
throw new \InvalidArgumentException("Path '$path' is not a valid path within " . self::$directory);
Expand All @@ -157,7 +157,7 @@ public static function move(string $path, string $folder): bool
*/
public static function duplicate(string $path, string $name): bool
{
$source = \Aurora\System\Helper::getPath($path);
$source = \Aurora\Core\Helper::getPath($path);
$destination = dirname($source) . "/$name";

if (!self::isValidPath($source)) {
Expand All @@ -169,10 +169,10 @@ public static function duplicate(string $path, string $name): bool
}

if ($source === $destination) {
$destination = \Aurora\System\Helper::getNewFilename($destination);
$destination = \Aurora\Core\Helper::getNewFilename($destination);
}

return \Aurora\System\Helper::copy($source, $destination);
return \Aurora\Core\Helper::copy($source, $destination);
}

/**
Expand All @@ -182,7 +182,7 @@ public static function duplicate(string $path, string $name): bool
*/
public static function isValidPath(string $path): bool
{
$content_dir = \Aurora\System\Helper::getPath(self::$directory);
$content_dir = \Aurora\Core\Helper::getPath(self::$directory);

return $path !== '' && strncmp($path, $content_dir, strlen($content_dir)) === 0;
}
Expand All @@ -195,7 +195,7 @@ public static function isValidPath(string $path): bool
*/
public static function uploadFile($file, string $path): bool
{
$path = \Aurora\System\Helper::getPath($path);
$path = \Aurora\Core\Helper::getPath($path);
$container_path = mb_substr($path, 0, mb_strrpos($path, '/') + 1);

if (!$file) {
Expand All @@ -219,7 +219,7 @@ public static function uploadFile($file, string $path): bool
*/
public static function getMaxUploadFileSize(): mixed
{
return min(array_map(fn($key) => \Aurora\System\Helper::getPhpSize(ini_get($key)), [ 'post_max_size', 'upload_max_filesize' ]));
return min(array_map(fn($key) => \Aurora\Core\Helper::getPhpSize(ini_get($key)), [ 'post_max_size', 'upload_max_filesize' ]));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function run(string $zip): int|bool
}

foreach (self::UPDATE_DIRECTORIES as $dir) {
if (!\Aurora\System\Helper::copy("$new_version_dir/$dir", \Aurora\System\Helper::getPath("/$dir"))) {
if (!\Aurora\Core\Helper::copy("$new_version_dir/$dir", \Aurora\Core\Helper::getPath("/$dir"))) {
return self::ERROR_COPY;
}
}
Expand All @@ -73,7 +73,7 @@ public function getLatestRelease(): array|bool|int
return self::ERROR_CONNECTION;
}

$current_version = explode('.', \Aurora\System\Kernel::VERSION);
$current_version = explode('.', \Aurora\Core\Kernel::VERSION);
$latest_release = [];

foreach (json_decode($releases, true) as $release) {
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/ViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class ViewHelper
*/
public function getFileQuery(string $filename): string
{
return "$filename?v=" . filemtime(\Aurora\System\Helper::getPath($filename));
return "$filename?v=" . filemtime(\Aurora\Core\Helper::getPath($filename));
}

/**
Expand All @@ -37,7 +37,7 @@ public function getContentUrl(mixed $url): string

return $host && $host !== $_SERVER['HTTP_HOST']
? $url
: \Aurora\System\Helper::getUrl(\Aurora\System\Kernel::config('content') . '/' . trim($url, '/'));
: \Aurora\Core\Helper::getUrl(\Aurora\Core\Kernel::config('content') . '/' . trim($url, '/'));
}

/**
Expand All @@ -50,19 +50,19 @@ public function dateFormat(mixed $tstamp): string
static $formatter = null;

if ($formatter === null) {
$formatter = new \IntlDateFormatter(\Aurora\System\Container::get('language')->getCode(), 0, 0);
$formatter = new \IntlDateFormatter(\Aurora\Core\Container::get('language')->getCode(), 0, 0);
}

$formatter->setPattern(\Aurora\App\Setting::get('date_format') ?? '');
return $formatter->format($tstamp);
}

/**
* @see \Aurora\System\Helper::getUrl
* @see \Aurora\Core\Helper::getUrl
*/
public function url(string $path = ''): string
{
return \Aurora\System\Helper::getUrl($path);
return \Aurora\Core\Helper::getUrl($path);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/modules/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function checkFields(array $data, $id): array
$errors['slug'] = $this->language->get('repeated_slug');
}

if (!empty($data['slug']) && !\Aurora\System\Helper::isSlugValid($data['slug'])) {
if (!empty($data['slug']) && !\Aurora\Core\Helper::isSlugValid($data['slug'])) {
$errors['slug'] = $this->language->get('invalid_slug');
}

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/modules/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function checkFields(array $data, $id): array
$errors['slug'] = $this->language->get('repeated_slug');
}

if (empty($data['slug']) || !\Aurora\System\Helper::isSlugValid($data['slug'])) {
if (empty($data['slug']) || !\Aurora\Core\Helper::isSlugValid($data['slug'])) {
$errors['slug'] = $this->language->get('invalid_slug');
}

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/modules/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function checkFields(array $data, $id): array
$errors['slug'] = $this->language->get('repeated_slug');
}

if (empty($data['slug']) || !\Aurora\System\Helper::isSlugValid($data['slug'])) {
if (empty($data['slug']) || !\Aurora\Core\Helper::isSlugValid($data['slug'])) {
$errors['slug'] = $this->language->get('invalid_slug');
}

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/modules/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function requestPasswordRestore(string $email, string $hash, string $mess
'created_at' => time(),
]);

if (!\Aurora\System\Kernel::config('mail')($email, $this->language->get('restore_your_password'), $message)) {
if (!\Aurora\Core\Kernel::config('mail')($email, $this->language->get('restore_your_password'), $message)) {
$errors['email'] = $this->language->get('error_sending_email');
}
}
Expand Down Expand Up @@ -178,7 +178,7 @@ public function checkFields(array $data, $id): array
$errors['slug'] = $this->language->get('repeated_slug');
}

if (empty($data['slug']) || !\Aurora\System\Helper::isSlugValid($data['slug'])) {
if (empty($data['slug']) || !\Aurora\Core\Helper::isSlugValid($data['slug'])) {
$errors['slug'] = $this->language->get('invalid_slug');
}

Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/base.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="<?= e(\Aurora\System\Container::get('language')->getCode()) ?>">
<html lang="<?= e(\Aurora\Core\Container::get('language')->getCode()) ?>">
<head>
<title>
<?php $this->sectionStart('title') ?><?php $this->sectionEnd() ?> - <?= e(setting('title')) ?>
Expand Down
Loading

0 comments on commit 8e4dc15

Please sign in to comment.