diff --git a/admin/includes/settings_menus.php b/admin/includes/settings_menus.php
index 2ce784fc..e612a888 100644
--- a/admin/includes/settings_menus.php
+++ b/admin/includes/settings_menus.php
@@ -1,5 +1,7 @@
array('Fist fighting', 'fist'),
diff --git a/admin/pages/plugins.php b/admin/pages/plugins.php
index 6eb0862e..f130a15c 100644
--- a/admin/pages/plugins.php
+++ b/admin/pages/plugins.php
@@ -7,6 +7,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
+
+use MyAAC\Plugins;
+
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Plugin manager';
@@ -14,8 +17,6 @@ csrfProtect();
$use_datatable = true;
-require_once LIBS . 'plugins.php';
-
if (!getBoolean(setting('core.admin_plugins_manage_enable'))) {
warning('Plugin installation and management is disabled in Settings.
If you wish to enable, go to Settings and enable Enable Plugins Manage.');
}
diff --git a/admin/pages/settings.php b/admin/pages/settings.php
index 5b354c99..4533b33b 100644
--- a/admin/pages/settings.php
+++ b/admin/pages/settings.php
@@ -7,6 +7,10 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
+
+use MyAAC\Plugins;
+use MyAAC\Settings;
+
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Settings';
diff --git a/admin/pages/visitors.php b/admin/pages/visitors.php
index 8ab78521..9e83d339 100644
--- a/admin/pages/visitors.php
+++ b/admin/pages/visitors.php
@@ -12,6 +12,7 @@ defined('MYAAC') or die('Direct access not allowed!');
use DeviceDetector\DeviceDetector;
use DeviceDetector\Parser\Client\Browser;
use DeviceDetector\Parser\OperatingSystem;
+use MyAAC\Visitors;
$title = 'Visitors';
$use_datatable = true;
@@ -24,7 +25,6 @@ if (!setting('core.visitors_counter')): ?>
return;
endif;
-require SYSTEM . 'libs/visitors.php';
$visitors = new Visitors(setting('core.visitors_counter_ttl'));
function compare($a, $b): int {
diff --git a/admin/tools/reload_data.php b/admin/tools/reload_data.php
index 79740d31..cb0a1cec 100644
--- a/admin/tools/reload_data.php
+++ b/admin/tools/reload_data.php
@@ -22,6 +22,9 @@
* @copyright 2020 MyAAC
* @link https://my-aac.org
*/
+
+use MyAAC\DataLoader;
+
define('MYAAC_ADMIN', true);
require '../../common.php';
@@ -37,8 +40,6 @@ ob_implicit_flush();
ob_end_flush();
header('X-Accel-Buffering: no');
-require LIBS . 'DataLoader.php';
-
require LOCALE . 'en/main.php';
require LOCALE . 'en/install.php';
diff --git a/admin/tools/settings_save.php b/admin/tools/settings_save.php
index 500c83bb..7ed43093 100644
--- a/admin/tools/settings_save.php
+++ b/admin/tools/settings_save.php
@@ -1,4 +1,8 @@
load();
diff --git a/composer.json b/composer.json
index f022369e..ee65ddbe 100644
--- a/composer.json
+++ b/composer.json
@@ -24,6 +24,7 @@
"autoload": {
"psr-4": {
"MyAAC\\": "system/src"
- }
+ },
+ "files": ["system/src/global.php"]
}
}
diff --git a/index.php b/index.php
index 39f457cb..56237bfd 100644
--- a/index.php
+++ b/index.php
@@ -24,6 +24,9 @@
* @link https://my-aac.org
*/
+use MyAAC\UsageStatistics;
+use MyAAC\Visitors;
+
require_once 'common.php';
require_once SYSTEM . 'functions.php';
@@ -146,8 +149,7 @@ if(setting('core.anonymous_usage_statistics')) {
}
if($should_report) {
- require_once LIBS . 'usage_statistics.php';
- Usage_Statistics::report();
+ UsageStatistics::report();
updateDatabaseConfig('last_usage_report', time());
if($cache->enabled()) {
@@ -160,7 +162,6 @@ if(setting('core.views_counter'))
require_once SYSTEM . 'counter.php';
if(setting('core.visitors_counter')) {
- require_once SYSTEM . 'libs/visitors.php';
$visitors = new Visitors(setting('core.visitors_counter_ttl'));
}
diff --git a/install/index.php b/install/index.php
index 9c2e5048..d6043d42 100644
--- a/install/index.php
+++ b/install/index.php
@@ -12,7 +12,6 @@ require SYSTEM . 'functions.php';
require BASE . 'install/includes/functions.php';
require BASE . 'install/includes/locale.php';
require SYSTEM . 'clients.conf.php';
-require LIBS . 'Settings.php';
// ignore undefined index from Twig autoloader
$config['env'] = 'prod';
diff --git a/install/steps/5-database.php b/install/steps/5-database.php
index b75608fc..6ee7d031 100644
--- a/install/steps/5-database.php
+++ b/install/steps/5-database.php
@@ -1,4 +1,7 @@
'What is this?',
diff --git a/system/compat/base.php b/system/compat/base.php
index 40d2617e..1a606be3 100644
--- a/system/compat/base.php
+++ b/system/compat/base.php
@@ -9,10 +9,12 @@
*/
defined('MYAAC') or die('Direct access not allowed!');
+class Validator extends \MyAAC\Validator {}
+
function check_name($name, &$errors = '') {
if(Validator::characterName($name))
return true;
-
+
$errors = Validator::getLastError();
return false;
}
@@ -20,7 +22,7 @@ function check_name($name, &$errors = '') {
function check_account_id($id, &$errors = '') {
if(Validator::accountId($id))
return true;
-
+
$errors = Validator::getLastError();
return false;
}
@@ -28,7 +30,7 @@ function check_account_id($id, &$errors = '') {
function check_account_name($name, &$errors = '') {
if(Validator::accountName($name))
return true;
-
+
$errors = Validator::getLastError();
return false;
}
@@ -36,7 +38,7 @@ function check_account_name($name, &$errors = '') {
function check_name_new_char($name, &$errors = '') {
if(Validator::newCharacterName($name))
return true;
-
+
$errors = Validator::getLastError();
return false;
}
@@ -44,7 +46,7 @@ function check_name_new_char($name, &$errors = '') {
function check_rank_name($name, &$errors = '') {
if(Validator::rankName($name))
return true;
-
+
$errors = Validator::getLastError();
return false;
}
@@ -52,7 +54,7 @@ function check_rank_name($name, &$errors = '') {
function check_guild_name($name, &$errors = '') {
if(Validator::guildName($name))
return true;
-
+
$errors = Validator::getLastError();
return false;
}
@@ -72,4 +74,4 @@ function fieldExist($field, $table)
global $db;
return $db->hasColumn($table, $field);
}
-?>
\ No newline at end of file
+?>
diff --git a/system/counter.php b/system/counter.php
index 63905ba2..2c2512d3 100644
--- a/system/counter.php
+++ b/system/counter.php
@@ -7,6 +7,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
+
+use MyAAC\Cache\Cache;
+
defined('MYAAC') or die('Direct access not allowed!');
define('COUNTER_SYNC', 10); // how often counter is synchronized with database (each x site refreshes)
diff --git a/system/exception.php b/system/exception.php
index 077d0f3f..94b60c47 100644
--- a/system/exception.php
+++ b/system/exception.php
@@ -8,6 +8,8 @@
* @link https://my-aac.org
*/
+use MyAAC\Exceptions\SensitiveException;
+
if (class_exists(\Whoops\Run::class)) {
$whoops = new \Whoops\Run;
if(IS_CLI) {
@@ -21,8 +23,6 @@ if (class_exists(\Whoops\Run::class)) {
return;
}
-require LIBS . 'SensitiveException.php';
-
/**
* @param Exception $exception
*/
diff --git a/system/functions.php b/system/functions.php
index 5c18b67c..df619acf 100644
--- a/system/functions.php
+++ b/system/functions.php
@@ -9,12 +9,17 @@
*/
defined('MYAAC') or die('Direct access not allowed!');
+use MyAAC\Cache\Cache;
use MyAAC\CsrfToken;
+use MyAAC\Items;
use MyAAC\Models\Config;
use MyAAC\Models\Guild;
use MyAAC\Models\House;
use MyAAC\Models\Pages;
use MyAAC\Models\Player;
+use MyAAC\News;
+use MyAAC\Plugins;
+use MyAAC\Settings;
use PHPMailer\PHPMailer\PHPMailer;
use Twig\Loader\ArrayLoader as Twig_ArrayLoader;
@@ -137,7 +142,6 @@ function getGuildLink($name, $generate = true): string
}
function getItemNameById($id) {
- require_once LIBS . 'items.php';
$item = Items::get($id);
return !empty($item['name']) ? $item['name'] : '';
}
@@ -1195,7 +1199,6 @@ function setting($key)
function clearCache()
{
- require_once LIBS . 'news.php';
News::clearCache();
$cache = Cache::getInstance();
@@ -1689,7 +1692,6 @@ function makeLinksClickable($text, $blank = true) {
}
// validator functions
-require_once LIBS . 'validator.php';
require_once SYSTEM . 'compat/base.php';
// custom functions
diff --git a/system/init.php b/system/init.php
index 0bf55c24..d4867a91 100644
--- a/system/init.php
+++ b/system/init.php
@@ -8,7 +8,12 @@
* @link https://my-aac.org
*/
+use DebugBar\StandardDebugBar;
+use MyAAC\Cache\Cache;
use MyAAC\CsrfToken;
+use MyAAC\Hooks;
+use MyAAC\Settings;
+use MyAAC\Towns;
defined('MYAAC') or die('Direct access not allowed!');
@@ -16,8 +21,6 @@ if(!isset($config['installed']) || !$config['installed']) {
throw new RuntimeException('MyAAC has not been installed yet or there was error during installation. Please install again.');
}
-use DebugBar\StandardDebugBar;
-
if(config('env') === 'dev') {
require SYSTEM . 'exception.php';
}
@@ -39,11 +42,9 @@ if(isset($config['gzip_output']) && $config['gzip_output'] && isset($_SERVER['HT
ob_start('ob_gzhandler');
// cache
-require_once SYSTEM . 'libs/cache.php';
$cache = Cache::getInstance();
// event system
-require_once SYSTEM . 'hooks.php';
$hooks = new Hooks();
$hooks->load();
@@ -145,7 +146,6 @@ require_once SYSTEM . 'database.php';
require SYSTEM . 'migrate.php';
// settings
-require_once LIBS . 'Settings.php';
$settings = Settings::getInstance();
$settings->load();
@@ -176,5 +176,4 @@ define('USE_ACCOUNT_NAME', $db->hasColumn('accounts', 'name'));
define('USE_ACCOUNT_NUMBER', $db->hasColumn('accounts', 'number'));
define('USE_ACCOUNT_SALT', $db->hasColumn('accounts', 'salt'));
-require LIBS . 'Towns.php';
Towns::load();
diff --git a/system/libs/SensitiveException.php b/system/libs/SensitiveException.php
deleted file mode 100644
index 58978198..00000000
--- a/system/libs/SensitiveException.php
+++ /dev/null
@@ -1,3 +0,0 @@
-enabled()) {
+ if(class_exists('MyAAC\Cache\Cache') && ($cache = Cache::getInstance()) && $cache->enabled()) {
$tmp = null;
$need_revalidation = true;
if($cache->fetch('database_checksum', $tmp) && $tmp) {
@@ -145,7 +147,7 @@ class OTS_DB_MySQL extends OTS_Base_DB
{
global $config;
- if(class_exists('Cache') && ($cache = Cache::getInstance()) && $cache->enabled()) {
+ if(class_exists('MyAAC\Cache\Cache') && ($cache = Cache::getInstance()) && $cache->enabled()) {
$cache->set('database_tables', serialize($this->has_table_cache), 3600);
$cache->set('database_columns', serialize($this->has_column_cache), 3600);
$cache->set('database_checksum', serialize(sha1($config['database_host'] . '.' . $config['database_name'])), 3600);
diff --git a/system/libs/pot/OTS_Groups_List.php b/system/libs/pot/OTS_Groups_List.php
index 868180dd..af4df170 100644
--- a/system/libs/pot/OTS_Groups_List.php
+++ b/system/libs/pot/OTS_Groups_List.php
@@ -8,6 +8,8 @@
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public License, Version 3
*/
+use MyAAC\Cache\Cache;
+
/**
* List of groups.
*
diff --git a/system/migrations/17.php b/system/migrations/17.php
index 8c7cf8a0..73e3828c 100644
--- a/system/migrations/17.php
+++ b/system/migrations/17.php
@@ -1,5 +1,7 @@
hasTable('myaac_menu')) {
$db->query("
CREATE TABLE `myaac_menu`
@@ -16,7 +18,6 @@ CREATE TABLE `myaac_menu`
");
}
-require_once LIBS . 'plugins.php';
Plugins::installMenus('kathrine', require TEMPLATES . 'kathrine/menus.php');
Plugins::installMenus('tibiacom', require TEMPLATES . 'tibiacom/menus.php');
diff --git a/system/migrations/20.php b/system/migrations/20.php
index 45dc582d..e7b5ee0a 100644
--- a/system/migrations/20.php
+++ b/system/migrations/20.php
@@ -1,6 +1,6 @@
query("SELECT `id` FROM `players` WHERE (`name` = " . $db->quote("Rook Sample") . " OR `name` = " . $db->quote("Sorcerer Sample") . " OR `name` = " . $db->quote("Druid Sample") . " OR `name` = " . $db->quote("Paladin Sample") . " OR `name` = " . $db->quote("Knight Sample") . " OR `name` = " . $db->quote("Account Manager") . ") ORDER BY `id`;");
diff --git a/system/migrations/28.php b/system/migrations/28.php
index fd6943cf..d06487c8 100644
--- a/system/migrations/28.php
+++ b/system/migrations/28.php
@@ -1,8 +1,10 @@
exec('DROP TABLE IF EXISTS `' . TABLE_PREFIX . 'hooks`;');
$cache = Cache::getInstance();
if($cache->enabled()) {
$cache->delete('hooks');
-}
\ No newline at end of file
+}
diff --git a/system/pages/account/create.php b/system/pages/account/create.php
index 0f190bb6..58e72356 100644
--- a/system/pages/account/create.php
+++ b/system/pages/account/create.php
@@ -8,6 +8,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
+
+use MyAAC\CreateCharacter;
+
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Create Account';
@@ -21,7 +24,6 @@ if($logged)
}
if(setting('core.account_create_character_create')) {
- require_once LIBS . 'CreateCharacter.php';
$createCharacter = new CreateCharacter();
}
diff --git a/system/pages/account/create_character.php b/system/pages/account/create_character.php
index 3216a71a..e68c8773 100644
--- a/system/pages/account/create_character.php
+++ b/system/pages/account/create_character.php
@@ -8,6 +8,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
+
+use MyAAC\CreateCharacter;
+
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Create Character';
@@ -30,7 +33,6 @@ $character_created = false;
$save = isset($_POST['save']) && $_POST['save'] == 1;
$errors = array();
if($save) {
- require_once LIBS . 'CreateCharacter.php';
$createCharacter = new CreateCharacter();
$character_created = $createCharacter->doCreate($character_name, $character_sex, $character_vocation, $character_town, $account_logged, $errors);
diff --git a/system/pages/forum.php b/system/pages/forum.php
index e5b68ed0..c00b7f4b 100644
--- a/system/pages/forum.php
+++ b/system/pages/forum.php
@@ -8,6 +8,9 @@
* @copyright 2021 MyAAC
* @link https://my-aac.org
*/
+
+use MyAAC\Forum;
+
defined('MYAAC') or exit;
$ret = require __DIR__ . '/forum/base.php';
diff --git a/system/pages/forum/admin.php b/system/pages/forum/admin.php
index e9aa18b2..046452b2 100644
--- a/system/pages/forum/admin.php
+++ b/system/pages/forum/admin.php
@@ -8,6 +8,9 @@
* @copyright 2021 MyAAC
* @link https://my-aac.org
*/
+
+use MyAAC\Forum;
+
defined('MYAAC') or exit('Direct access not allowed!');
$canEdit = Forum::isModerator();
diff --git a/system/pages/forum/base.php b/system/pages/forum/base.php
index de449692..2ede7f2e 100644
--- a/system/pages/forum/base.php
+++ b/system/pages/forum/base.php
@@ -11,7 +11,7 @@
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Forum';
-require_once LIBS . 'forum.php';
+class_exists('MyAAC\Forum');
$forumSetting = setting('core.forum');
if(strtolower($forumSetting) != 'site') {
diff --git a/system/pages/forum/edit_post.php b/system/pages/forum/edit_post.php
index eec5b43f..042081de 100644
--- a/system/pages/forum/edit_post.php
+++ b/system/pages/forum/edit_post.php
@@ -8,6 +8,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
+
+use MyAAC\Forum;
+
defined('MYAAC') or die('Direct access not allowed!');
$ret = require __DIR__ . '/base.php';
diff --git a/system/pages/forum/move_thread.php b/system/pages/forum/move_thread.php
index 45d14683..a66ddfce 100644
--- a/system/pages/forum/move_thread.php
+++ b/system/pages/forum/move_thread.php
@@ -8,6 +8,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
+
+use MyAAC\Forum;
+
defined('MYAAC') or die('Direct access not allowed!');
$ret = require __DIR__ . '/base.php';
diff --git a/system/pages/forum/new_post.php b/system/pages/forum/new_post.php
index 49db8af0..9be11343 100644
--- a/system/pages/forum/new_post.php
+++ b/system/pages/forum/new_post.php
@@ -8,6 +8,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
+
+use MyAAC\Forum;
+
defined('MYAAC') or die('Direct access not allowed!');
$ret = require __DIR__ . '/base.php';
diff --git a/system/pages/forum/new_thread.php b/system/pages/forum/new_thread.php
index 3882f895..0ce1270b 100644
--- a/system/pages/forum/new_thread.php
+++ b/system/pages/forum/new_thread.php
@@ -8,6 +8,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
+
+use MyAAC\Forum;
+
defined('MYAAC') or die('Direct access not allowed!');
$ret = require __DIR__ . '/base.php';
diff --git a/system/pages/forum/remove_post.php b/system/pages/forum/remove_post.php
index c3f2d46f..73535eae 100644
--- a/system/pages/forum/remove_post.php
+++ b/system/pages/forum/remove_post.php
@@ -8,6 +8,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
+
+use MyAAC\Forum;
+
defined('MYAAC') or die('Direct access not allowed!');
$ret = require __DIR__ . '/base.php';
diff --git a/system/pages/forum/show_board.php b/system/pages/forum/show_board.php
index 4e37984c..710a0f05 100644
--- a/system/pages/forum/show_board.php
+++ b/system/pages/forum/show_board.php
@@ -8,6 +8,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
+
+use MyAAC\Forum;
+
defined('MYAAC') or die('Direct access not allowed!');
$ret = require __DIR__ . '/base.php';
diff --git a/system/pages/forum/show_thread.php b/system/pages/forum/show_thread.php
index 124928bc..51dcd096 100644
--- a/system/pages/forum/show_thread.php
+++ b/system/pages/forum/show_thread.php
@@ -8,6 +8,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
+
+use MyAAC\Forum;
+
defined('MYAAC') or die('Direct access not allowed!');
$ret = require __DIR__ . '/base.php';
diff --git a/system/pages/gallery.php b/system/pages/gallery.php
index 69ad2194..f44bd91f 100644
--- a/system/pages/gallery.php
+++ b/system/pages/gallery.php
@@ -8,6 +8,7 @@
* @link https://my-aac.org
*/
+use MyAAC\Cache\Cache;
use MyAAC\Models\Gallery as ModelsGallery;
defined('MYAAC') or die('Direct access not allowed!');
diff --git a/system/pages/highscores.php b/system/pages/highscores.php
index e42e10dd..ff2fbd40 100644
--- a/system/pages/highscores.php
+++ b/system/pages/highscores.php
@@ -9,6 +9,7 @@
* @link https://my-aac.org
*/
+use MyAAC\Cache\Cache;
use MyAAC\Models\Player;
use MyAAC\Models\PlayerDeath;
use MyAAC\Models\PlayerKillers;
diff --git a/system/pages/news.php b/system/pages/news.php
index cd39e89f..7dbd3f3c 100644
--- a/system/pages/news.php
+++ b/system/pages/news.php
@@ -8,10 +8,11 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
-defined('MYAAC') or die('Direct access not allowed!');
-require_once LIBS . 'forum.php';
-require_once LIBS . 'news.php';
+use MyAAC\Cache\Cache;
+use MyAAC\News;
+
+defined('MYAAC') or die('Direct access not allowed!');
$canEdit = hasFlag(FLAG_CONTENT_NEWS) || superAdmin();
if(isset($_GET['archive']))
diff --git a/system/router.php b/system/router.php
index 99a07f91..0f90071d 100644
--- a/system/router.php
+++ b/system/router.php
@@ -9,6 +9,7 @@
*/
use MyAAC\Models\Pages;
+use MyAAC\Plugins;
defined('MYAAC') or die('Direct access not allowed!');
diff --git a/system/settings.php b/system/settings.php
index ee779316..2d54a37e 100644
--- a/system/settings.php
+++ b/system/settings.php
@@ -10,6 +10,9 @@
* Additional options
* - for number: min, max, step
*/
+
+use MyAAC\Settings;
+
return [
'name' => 'MyAAC',
'settings' =>
diff --git a/system/libs/cache_apc.php b/system/src/Cache/APC.php
similarity index 76%
rename from system/libs/cache_apc.php
rename to system/src/Cache/APC.php
index a997e6e5..b831a5d3 100644
--- a/system/libs/cache_apc.php
+++ b/system/src/Cache/APC.php
@@ -8,9 +8,10 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
-defined('MYAAC') or die('Direct access not allowed!');
-class Cache_APC
+namespace MyAAC\Cache;
+
+class APC
{
private $prefix;
private $enabled;
@@ -31,22 +32,25 @@ class Cache_APC
public function get($key)
{
$tmp = '';
- if($this->fetch($this->prefix . $key, $tmp)) {
+ if ($this->fetch($this->prefix . $key, $tmp)) {
return $tmp;
}
return '';
}
- public function fetch($key, &$var) {
+ public function fetch($key, &$var)
+ {
return ($var = apc_fetch($this->prefix . $key)) !== false;
}
- public function delete($key) {
+ public function delete($key)
+ {
apc_delete($this->prefix . $key);
}
- public function enabled() {
+ public function enabled()
+ {
return $this->enabled;
}
-}
\ No newline at end of file
+}
diff --git a/system/libs/cache_apcu.php b/system/src/Cache/APCu.php
similarity index 77%
rename from system/libs/cache_apcu.php
rename to system/src/Cache/APCu.php
index d4979f23..7f6500bf 100644
--- a/system/libs/cache_apcu.php
+++ b/system/src/Cache/APCu.php
@@ -8,9 +8,10 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
-defined('MYAAC') or die('Direct access not allowed!');
-class Cache_APCu
+namespace MyAAC\Cache;
+
+class APCu
{
private $prefix;
private $enabled;
@@ -31,22 +32,25 @@ class Cache_APCu
public function get($key)
{
$tmp = '';
- if($this->fetch($this->prefix . $key, $tmp)) {
+ if ($this->fetch($this->prefix . $key, $tmp)) {
return $tmp;
}
return '';
}
- public function fetch($key, &$var) {
+ public function fetch($key, &$var)
+ {
return ($var = apcu_fetch($this->prefix . $key)) !== false;
}
- public function delete($key) {
+ public function delete($key)
+ {
apcu_delete($this->prefix . $key);
}
- public function enabled() {
+ public function enabled()
+ {
return $this->enabled;
}
}
diff --git a/system/libs/cache.php b/system/src/Cache/Cache.php
similarity index 64%
rename from system/libs/cache.php
rename to system/src/Cache/Cache.php
index 55c17a17..b9981dce 100644
--- a/system/libs/cache.php
+++ b/system/src/Cache/Cache.php
@@ -8,7 +8,8 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
-defined('MYAAC') or die('Direct access not allowed!');
+
+namespace MyAAC\Cache;
/**
* Class Cache
@@ -41,40 +42,34 @@ class Cache
*/
public static function generateInstance($engine = '', $prefix = '')
{
- if(config('env') === 'dev') {
+ if (config('env') === 'dev') {
self::$instance = new self();
return self::$instance;
}
- switch(strtolower($engine)) {
+ switch (strtolower($engine)) {
case 'apc':
- require 'cache_apc.php';
- self::$instance = new Cache_APC($prefix);
+ self::$instance = new APC($prefix);
break;
case 'apcu':
- require 'cache_apcu.php';
- self::$instance = new Cache_APCu($prefix);
+ self::$instance = new APCu($prefix);
break;
case 'eaccelerator':
- require 'cache_eaccelerator.php';
- self::$instance = new Cache_eAccelerator($prefix);
+ self::$instance = new eAccelerator($prefix);
break;
case 'xcache':
- require 'cache_xcache.php';
- self::$instance = new Cache_XCache($prefix);
+ self::$instance = new XCache($prefix);
break;
case 'file':
- require 'cache_file.php';
- self::$instance = new Cache_File($prefix, CACHE);
+ self::$instance = new File($prefix, CACHE);
break;
case 'php':
- require 'cache_php.php';
- self::$instance = new Cache_PHP($prefix, CACHE);
+ self::$instance = new PHP($prefix, CACHE);
break;
case 'auto':
@@ -94,13 +89,13 @@ class Cache
*/
public static function detect()
{
- if(function_exists('apc_fetch'))
+ if (function_exists('apc_fetch'))
return 'apc';
- else if(function_exists('apcu_fetch'))
+ else if (function_exists('apcu_fetch'))
return 'apcu';
- else if(function_exists('eaccelerator_get'))
+ else if (function_exists('eaccelerator_get'))
return 'eaccelerator';
- else if(function_exists('xcache_get') && ini_get('xcache.var_size'))
+ else if (function_exists('xcache_get') && ini_get('xcache.var_size'))
return 'xcache';
return 'file';
@@ -109,12 +104,15 @@ class Cache
/**
* @return bool
*/
- public function enabled() {return false;}
+ public function enabled()
+ {
+ return false;
+ }
public static function remember($key, $ttl, $callback)
{
$cache = self::getInstance();
- if(!$cache->enabled()) {
+ if (!$cache->enabled()) {
return $callback();
}
@@ -124,7 +122,7 @@ class Cache
}
$value = $callback();
- $cache->set($key, serialize($value),$ttl);
+ $cache->set($key, serialize($value), $ttl);
return $value;
}
}
diff --git a/system/libs/cache_eaccelerator.php b/system/src/Cache/EAccelerator.php
similarity index 72%
rename from system/libs/cache_eaccelerator.php
rename to system/src/Cache/EAccelerator.php
index e5285a64..58adc6d3 100644
--- a/system/libs/cache_eaccelerator.php
+++ b/system/src/Cache/EAccelerator.php
@@ -8,14 +8,16 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
-defined('MYAAC') or die('Direct access not allowed!');
-class Cache_eAccelerator
+namespace MyAAC\Cache;
+
+class EAccelerator
{
private $prefix;
private $enabled;
- public function __construct($prefix = '') {
+ public function __construct($prefix = '')
+ {
$this->prefix = $prefix;
$this->enabled = function_exists('eaccelerator_get');
}
@@ -30,22 +32,25 @@ class Cache_eAccelerator
public function get($key)
{
$tmp = '';
- if($this->fetch($this->prefix . $key, $tmp)) {
+ if ($this->fetch($this->prefix . $key, $tmp)) {
return $tmp;
}
return '';
}
- public function fetch($key, &$var) {
+ public function fetch($key, &$var)
+ {
return ($var = eaccelerator_get($this->prefix . $key)) !== null;
}
- public function delete($key) {
+ public function delete($key)
+ {
eaccelerator_rm($this->prefix . $key);
}
- public function enabled() {
+ public function enabled()
+ {
return $this->enabled;
}
}
diff --git a/system/libs/cache_file.php b/system/src/Cache/File.php
similarity index 76%
rename from system/libs/cache_file.php
rename to system/src/Cache/File.php
index a4c897c8..8d93d495 100644
--- a/system/libs/cache_file.php
+++ b/system/src/Cache/File.php
@@ -7,15 +7,17 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
-defined('MYAAC') or die('Direct access not allowed!');
-class Cache_File
+namespace MyAAC\Cache;
+
+class File
{
private $prefix;
private $dir;
private $enabled;
- public function __construct($prefix = '', $dir = '') {
+ public function __construct($prefix = '', $dir = '')
+ {
$this->prefix = $prefix;
$this->dir = $dir;
$this->enabled = (file_exists($this->dir) && is_dir($this->dir) && is_writable($this->dir));
@@ -36,7 +38,7 @@ class Cache_File
public function get($key)
{
$tmp = '';
- if($this->fetch($key, $tmp)) {
+ if ($this->fetch($key, $tmp)) {
return $tmp;
}
@@ -46,7 +48,7 @@ class Cache_File
public function fetch($key, &$var)
{
$file = $this->_name($key);
- if(!file_exists($file) || filemtime($file) < time()) {
+ if (!file_exists($file) || filemtime($file) < time()) {
return false;
}
@@ -57,16 +59,18 @@ class Cache_File
public function delete($key)
{
$file = $this->_name($key);
- if(file_exists($file)) {
+ if (file_exists($file)) {
unlink($file);
}
}
- public function enabled() {
+ public function enabled()
+ {
return $this->enabled;
}
- private function _name($key) {
+ private function _name($key)
+ {
return sprintf('%s%s%s', $this->dir, $this->prefix, sha1($key));
}
-}
\ No newline at end of file
+}
diff --git a/system/libs/cache_php.php b/system/src/Cache/PHP.php
similarity index 79%
rename from system/libs/cache_php.php
rename to system/src/Cache/PHP.php
index 5d35ceef..e42bd928 100644
--- a/system/libs/cache_php.php
+++ b/system/src/Cache/PHP.php
@@ -7,15 +7,17 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
-defined('MYAAC') or die('Direct access not allowed!');
-class Cache_PHP
+namespace MyAAC\Cache;
+
+class PHP
{
private $prefix;
private $dir;
private $enabled;
- public function __construct($prefix = '', $dir = '') {
+ public function __construct($prefix = '', $dir = '')
+ {
$this->prefix = $prefix;
$this->dir = $dir;
$this->enabled = (file_exists($this->dir) && is_dir($this->dir) && is_writable($this->dir));
@@ -42,7 +44,7 @@ class Cache_PHP
public function get($key)
{
$tmp = '';
- if($this->fetch($key, $tmp)) {
+ if ($this->fetch($key, $tmp)) {
return $tmp;
}
@@ -52,7 +54,7 @@ class Cache_PHP
public function fetch($key, &$var)
{
$file = $this->_name($key);
- if(!file_exists($file) || filemtime($file) < time()) {
+ if (!file_exists($file) || filemtime($file) < time()) {
return false;
}
@@ -64,16 +66,18 @@ class Cache_PHP
public function delete($key)
{
$file = $this->_name($key);
- if(file_exists($file)) {
+ if (file_exists($file)) {
unlink($file);
}
}
- public function enabled() {
+ public function enabled()
+ {
return $this->enabled;
}
- private function _name($key) {
+ private function _name($key)
+ {
return sprintf('%s%s%s', $this->dir, $this->prefix, sha1($key) . '.php');
}
-}
\ No newline at end of file
+}
diff --git a/system/libs/cache_xcache.php b/system/src/Cache/XCache.php
similarity index 75%
rename from system/libs/cache_xcache.php
rename to system/src/Cache/XCache.php
index bb1c054c..0bcf05d6 100644
--- a/system/libs/cache_xcache.php
+++ b/system/src/Cache/XCache.php
@@ -8,14 +8,16 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
-defined('MYAAC') or die('Direct access not allowed!');
-class Cache_XCache
+namespace MyAAC\Cache;
+
+class XCache
{
private $prefix;
private $enabled;
- public function __construct($prefix = '') {
+ public function __construct($prefix = '')
+ {
$this->prefix = $prefix;
$this->enabled = function_exists('xcache_get') && ini_get('xcache.var_size');
}
@@ -30,7 +32,7 @@ class Cache_XCache
public function get($key)
{
$tmp = '';
- if($this->fetch($this->prefix . $key, $tmp)) {
+ if ($this->fetch($this->prefix . $key, $tmp)) {
return $tmp;
}
@@ -40,7 +42,7 @@ class Cache_XCache
public function fetch($key, &$var)
{
$key = $this->prefix . $key;
- if(!xcache_isset($key)) {
+ if (!xcache_isset($key)) {
return false;
}
@@ -48,11 +50,13 @@ class Cache_XCache
return true;
}
- public function delete($key) {
+ public function delete($key)
+ {
xcache_unset($this->prefix . $key);
}
- public function enabled() {
+ public function enabled()
+ {
return $this->enabled;
}
}
diff --git a/system/libs/changelog.php b/system/src/Changelog.php
similarity index 98%
rename from system/libs/changelog.php
rename to system/src/Changelog.php
index f6d2011b..c2827451 100644
--- a/system/libs/changelog.php
+++ b/system/src/Changelog.php
@@ -1,5 +1,8 @@
find($char_to_copy_name);
if(!$char_to_copy->isLoaded())
$errors[] = 'Wrong characters configuration. Try again or contact with admin. ADMIN: Go to Admin Panel -> Settings -> Create Character and set valid characters to copy names. Character to copy: '.$char_to_copy_name.' doesn\'t exist.';
@@ -162,7 +164,7 @@ class CreateCharacter
if($sex == "0")
$char_to_copy->setLookType(136);
- $player = new OTS_Player();
+ $player = new \OTS_Player();
$player->setName($name);
$player->setAccount($account);
$player->setGroupId(1);
@@ -194,7 +196,7 @@ class CreateCharacter
$player->setManaSpent($char_to_copy->getManaSpent());
$player->setSoul($char_to_copy->getSoul());
- for($skill = POT::SKILL_FIRST; $skill <= POT::SKILL_LAST; $skill++) {
+ for($skill = \POT::SKILL_FIRST; $skill <= \POT::SKILL_LAST; $skill++) {
$value = 10;
if (setting('core.use_character_sample_skills')) {
$value = $char_to_copy->getSkill($skill);
@@ -231,7 +233,7 @@ class CreateCharacter
$player->save();
$player->setCustomField('created', time());
- $player = new OTS_Player();
+ $player = new \OTS_Player();
$player->find($name);
if(!$player->isLoaded()) {
@@ -240,7 +242,7 @@ class CreateCharacter
}
if($db->hasTable('player_skills')) {
- for($skill = POT::SKILL_FIRST; $skill <= POT::SKILL_LAST; $skill++) {
+ for($skill = \POT::SKILL_FIRST; $skill <= \POT::SKILL_LAST; $skill++) {
$value = 10;
if (setting('core.use_character_sample_skills')) {
$value = $char_to_copy->getSkill($skill);
diff --git a/system/libs/creatures.php b/system/src/Creatures.php
similarity index 93%
rename from system/libs/creatures.php
rename to system/src/Creatures.php
index 42be67ad..0e888eab 100644
--- a/system/libs/creatures.php
+++ b/system/src/Creatures.php
@@ -9,14 +9,13 @@
* @link https://my-aac.org
*/
+namespace MyAAC;
+
use MyAAC\Models\Monster;
-defined('MYAAC') or die('Direct access not allowed!');
-
-require_once LIBS . 'items.php';
class Creatures {
/**
- * @var OTS_MonstersList
+ * @var \OTS_MonstersList
*/
private static $monstersList;
private static $lastError = '';
@@ -24,7 +23,7 @@ class Creatures {
public static function loadFromXML($show = false) {
try {
Monster::query()->delete();
- } catch(Exception $error) {}
+ } catch(\Exception $error) {}
if($show) {
echo '