Skip to content

Commit

Permalink
PUSH
Browse files Browse the repository at this point in the history
-> Rewrite of the storage engine
  • Loading branch information
NaysKutzu committed Aug 19, 2024
1 parent 88592e1 commit f33d57e
Show file tree
Hide file tree
Showing 110 changed files with 4,948 additions and 368 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ composer.phar
/caches/*/
caches/last_settings_migrate_run
.php-cs-fixer.cache
/storage/caches/*.json
/storage/caches/*.txt
/storage/caches/*.log
/storage/caches/*/
/storage/logs/*.log
32 changes: 30 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
{
"php.version": "8.3",
"cSpell.words": [
"tailwindcss"
]
"acaches",
"asuccessful",
"asuccessfully",
"autoloader",
"ccaches",
"dbconfigure",
"ealready",
"ERRMODE",
"fklmnor",
"Inno",
"jsyaml",
"Kutzu",
"mythicalcore",
"mythicalframework",
"rfiles",
"Swal",
"tailwindcss",
"unban",
"unic",
"unverification",
"unverify"
],
"cSpell.useGitignore": true,
"cSpell.ignorePaths": [
"settings.json",
"composer-lock.json",
],
"window.title": "${appName}",
"window.autoDetectColorScheme": true,
"editor.minimap.enabled": true,
}
20 changes: 18 additions & 2 deletions .vscode/vscode.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,26 @@
},
"Get translation": {
"prefix": "S_GetLang",
"scope": "php",
"scope": "twig",
"body": [
"\\$lang['$1']"
"{{ lang('$1') }}"
],
"description": "Get a specific value from the language file!"
},
"Get setting": {
"prefix": "S_GetSetting",
"scope": "twig",
"body": [
"{{ setting('$1', '$2') }}"
],
"description": "Get a specific value from the settings table!"
},
"Get Config": {
"prefix": "S_GetConfig",
"scope": "twig",
"body": [
"{{ cfg('$1', '$2') }}"
],
"description": "Get a specific value from the config file!"
},
}
38 changes: 38 additions & 0 deletions api/System/getTranslationKey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use MythicalSystems\Api\Api as api;
use MythicalSystemsFramework\Managers\LanguageManager;

api::init();
api::allowOnlyGET();

if (isset($_GET['key']) && !$_GET['key'] == '') {
if (isset($_GET['orElse']) && !$_GET['orElse'] == '') {
$key = $_GET['key'];
$orElse = $_GET['orElse'];
if (isset($_GET['plain'])) {
$plain = true;
} else {
$plain = false;
}

$translation = LanguageManager::getLang();
$translation = $translation[$key] ?? $orElse;

if ($translation == $orElse) {
$error = 'The translation does not exist!';
} else {
$error = null;
}

if ($plain) {
exit($translation);
} else {
api::OK('The translation exists!', ['RESULT' => $translation, 'result' => $translation, 'text' => $translation, 'message' => $translation, 'error' => $error]);
}
} else {
api::BadRequest('You are missing the GET field for orElse!', []);
}
} else {
api::BadRequest('You are missing the GET field for key!', []);
}
53 changes: 44 additions & 9 deletions api/User/infoalreadyexists.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,57 @@

use MythicalSystems\Api\Api as api;
use MythicalSystemsFramework\User\UserHelper;
use MythicalSystemsFramework\Kernel\Encryption;

api::init();
api::allowOnlyGET();
if (isset($_GET['info']) && !$_GET['info'] == '') {
if (isset($_GET['value']) && !$_GET['value'] == '') {
$info = $_GET['info'];
$value = $_GET['value'];
$user = UserHelper::doesInfoAboutExist($info, $value);
if ($user == 'INFO_EXISTS') {
api::OK('The info exists!', ['RESULT' => $user]);
} elseif ($user == 'INFO_NOT_FOUND') {
api::BadRequest('The info does not exist!', ['RESULT' => $user]);
if (isset($_GET['isEncrypted']) && !$_GET['isEncrypted'] == '') {
$isEncrypted = $_GET['isEncrypted'];
$info = $_GET['info'];
$value = $_GET['value'];

if (isset($_GET['inVerted']) && !$_GET['inVerted'] == '') {
if ($_GET['inVerted'] == 'true') {
$inVerted = true;
} else {
$inVerted = false;
}
} else {
$inVerted = false;
}

if ($isEncrypted == 'true') {
$value = Encryption::encrypt($value);
$user = UserHelper::doesInfoAboutExist($info, $value);
} else {
$user = UserHelper::doesInfoAboutExist($info, $value);
}

if ($user == 'INFO_EXISTS') {
if ($inVerted == true) {
api::BadRequest('The info exists!', ['RESULT' => $user]);
} else {
api::OK('The info exists!', ['RESULT' => $user]);
}
} elseif ($user == 'INFO_NOT_FOUND') {
if ($inVerted == true) {
api::OK('The info does not exist!', ['RESULT' => $user]);
} else {
api::BadRequest('The info does not exist!', ['RESULT' => $user]);
}
} elseif ($user == 'ERROR_DATABASE_SELECT_FAILED') {
api::BadRequest('Failed to select the info from the database!', ['RESULT' => $user]);
} else {
api::BadRequest('An unknown error occurred!', ['RESULT' => $user]);
}
} else {
api::BadRequest('You are missing the GET field for isEncrypted!', []);
}
} else {
api::BadRequest('You are missing the post field for value!', []);
api::BadRequest('You are missing the GET field for value!', []);
}
} else {
api::BadRequest('You are missing the post field for info!', []);
api::BadRequest('You are missing the GET field for info!', []);
}
12 changes: 9 additions & 3 deletions api/User/register.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

use MythicalSystemsFramework\Kernel\Logger;
use MythicalSystemsFramework\Api\Api as api;
use MythicalSystemsFramework\Kernel\Debugger;
use MythicalSystemsFramework\Mail\MailService;
use MythicalSystemsFramework\Kernel\LoggerTypes;
use MythicalSystemsFramework\Kernel\LoggerLevels;
use MythicalSystemsFramework\User\UserHelper as user;
use MythicalSystemsFramework\Handlers\ActivityHandler;

Expand Down Expand Up @@ -51,15 +54,18 @@
} elseif ($user == 'ERROR_DATABASE_INSERT_FAILED') {
api::BadRequest('Failed to insert the user into the database!', ['RESULT' => $user]);
} else {
$user_id = user::getSpecificUserData($user, 'uuid', false);
$user_id = user::getSpecificUserData($user, 'uuid', true);
if (MailService::isEnabled() == true) {
// TODO: Add a verify system
} else {
user::updateSpecificUserData($user, 'verified', 'true');
ActivityHandler::addActivity($user_id, user::getSpecificUserData($user, 'username', false), 'User created an account!', MythicalSystems\CloudFlare\CloudFlare::getRealUserIP(), 'USER_CREATED');
ActivityHandler::addActivity($user_id, user::getSpecificUserData($user, 'username', false), 'User verified his account!', MythicalSystems\CloudFlare\CloudFlare::getRealUserIP(), 'USER_VERIFIED');

ActivityHandler::addActivity($user_id, user::getSpecificUserData($user, 'username', true), 'User created an account!', MythicalSystems\CloudFlare\CloudFlare::getRealUserIP(), 'USER_CREATED');
ActivityHandler::addActivity($user_id, user::getSpecificUserData($user, 'username', true), 'User verified his account!', MythicalSystems\CloudFlare\CloudFlare::getRealUserIP(), 'USER_VERIFIED');
}
api::OK('The user has been created!', ['TOKEN' => $user]);
}
} catch (Exception $e) {
api::InternalServerError('An error occurred!', ['ERROR' => $e->getMessage()]);
Logger::log(LoggerTypes::CORE, LoggerLevels::CRITICAL, '(Api/User/register.php) An error occurred in the register.php file!');
}
13 changes: 6 additions & 7 deletions app/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
class App extends \MythicalSystems\Main
{
/**
* Convert a string to a bool.
* Call the garbage collector.
*/
public static function convertStringToBool(string $value): bool
public static function callGarbageCollector(): void
{
if ($value == 'true') {
return true;
} else {
return false;
}
gc_enable();
gc_mem_caches();
gc_collect_cycles();
gc_disable();
}
}
16 changes: 16 additions & 0 deletions app/Cli/CommandBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace MythicalSystemsFramework\Cli;

interface CommandBuilder
{
/**
* Execute the command.
*
* @param bool $isFrameworkCommand Is it a framework command?
* @param array $args the arguments passed to the command
*
* @return void it should return nothing as it is a void function
*/
public static function execute(bool $isFrameworkCommand, array $args): void;
}
15 changes: 15 additions & 0 deletions app/Cli/Commands/Backup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace MythicalSystemsFramework\Cli\Commands;

use MythicalSystemsFramework\Cli\CommandBuilder;

class Backup extends Command implements CommandBuilder
{
public static string $description = 'A command to backup the application.';

public static function execute(bool $isFrameworkCommand, array $args): void
{
echo self::log_info('Backing up the application...');
}
}
5 changes: 3 additions & 2 deletions app/Cli/Commands/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace MythicalSystemsFramework\Cli\Commands;

use MythicalSystemsFramework\Cli\CommandBuilder;
use MythicalSystemsFramework\Database\MySQLCache;
use MythicalSystemsFramework\Handlers\CacheHandler as CacheWorker;

class Cache extends Command
class Cache extends Command implements CommandBuilder
{
public static string $description = 'A command that can help if you want to cache the database or the config!';

public static function execute(bool $isFrameworkCommand = false): void
public static function execute(bool $isFrameworkCommand, array $args): void
{
echo self::log_info('');
echo self::log_info('&c1.&7 Flush the caches!');
Expand Down
6 changes: 4 additions & 2 deletions app/Cli/Commands/Colors.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace MythicalSystemsFramework\Cli\Commands;

class Colors extends Command
use MythicalSystemsFramework\Cli\CommandBuilder;

class Colors extends Command implements CommandBuilder
{
public static string $description = 'A command to display the supported colors!';

public static function execute(bool $isFrameworkCommand = false): void
public static function execute(bool $isFrameworkCommand, array $args): void
{
$colors = 'Colors: &0Black&r, &1Dark Blue&r, &2Dark Green&r, &3Dark Aqua&r, &4Dark Red&r, &5Dark Purple&r, &6Gold&r, &7Gray&r, &8Dark Gray&r, &9Blue&r, &aGreen&r, &bAqua&r, &cRed&r, &dLight Purple&r, &eYellow&r, &rWhite&r, &rReset&r, &lBold&r, &nUnderline&r, &mStrikethrough&r';
echo self::translateColorsCode($colors);
Expand Down
19 changes: 17 additions & 2 deletions app/Cli/Commands/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
namespace MythicalSystemsFramework\Cli\Commands;

use MythicalSystemsFramework\Cli\Kernel;
use MythicalSystemsFramework\Cli\CommandBuilder;

class Command extends Kernel
class Command extends Kernel implements CommandBuilder
{
public static string $description = 'A example command :)';

public static function execute(bool $isFrameworkCommand = false): void
public static function execute(bool $isFrameworkCommand, array $args): void
{
/*
* This method should be overridden in the child class.
Expand Down Expand Up @@ -63,4 +64,18 @@ public static function log_info(string $message): void
{
echo self::translateColorsCode("&7$message&r&o");
}

/**
* Arguments start from 1 including one.
*
* @return mixed
*/
public static function getArgument(array $args, int $index): ?string
{
try {
return $args[$index + 1];
} catch (\Exception $e) {
return null;
}
}
}
19 changes: 14 additions & 5 deletions app/Cli/Commands/Configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
namespace MythicalSystemsFramework\Cli\Commands;

use MythicalSystemsFramework\Database\MySQL;
use MythicalSystemsFramework\Cli\CommandBuilder;
use MythicalSystemsFramework\Encryption\XChaCha20;
use MythicalSystemsFramework\Managers\ConfigManager as cfg;

class Configure extends Command
class Configure extends Command implements CommandBuilder
{
public static string $description = 'A command that can help if you want to configure the app!';

public static function execute(bool $isFrameworkCommand = false): void
public static function execute(bool $isFrameworkCommand, array $args): void
{
echo self::log_info('');
echo self::log_info('&c1.&7 Configure the database');
Expand Down Expand Up @@ -86,8 +88,8 @@ public static function dbconfigure(): void
cfg::set('database', 'password', $password);
cfg::set('database', 'name', $database);
echo self::translateColorsCode('&rGenerating an encryption key for database...!&o');
$key = 'mythicalcore_' . bin2hex(random_bytes(64 * 128));
cfg::set('encryption', 'key', $key);
echo self::translateColorsCode('&rPlease wait...&o');
echo self::translateColorsCode('&rWe generated a key for you: &e' . XChaCha20::generateKey() . '&o');
echo self::translateColorsCode('&rKey generated &asuccessfully&r!&o');
echo self::translateColorsCode('&rConfiguration saved &asuccessfully&r!&o');
} else {
Expand All @@ -97,6 +99,13 @@ public static function dbconfigure(): void

public static function configure(): void
{
self::exit('This feature is not implemented yet.');
echo self::translateColorsCode('Enter the name of the application &8[&eMythicalFramework&8]&r: ');
$app_name = readline() ?: 'MythicalFramework';
echo self::translateColorsCode('Enter the logo of the application &8[&ehttps://avatars.githubusercontent.com/u/117385445&8]&r: ');
$app_logo = readline() ?: 'https://avatars.githubusercontent.com/u/117385445';
echo self::translateColorsCode('Enter the timezone of the application &8[&eEurope/Vienna&8]&r: ');
$app_timezone = readline() ?: 'Europe/Vienna';

// SAVE IT SOMEWHERE I THINK:::
}
}
Loading

0 comments on commit f33d57e

Please sign in to comment.