Refactoring classes into src/ folder, so they will be auto-loaded by composer

This commit is contained in:
slawkens 2024-01-27 00:36:49 +01:00
parent 410d75c882
commit 1a6fb8bee2
78 changed files with 439 additions and 341 deletions

View File

@ -1,5 +1,7 @@
<?php
use MyAAC\Plugins;
$order = 10;
$settingsMenu = [];

View File

@ -9,6 +9,7 @@
* @link https://my-aac.org
*/
use MyAAC\Changelog;
use MyAAC\Models\Changelog as ModelsChangelog;
defined('MYAAC') or die('Direct access not allowed!');
@ -26,7 +27,6 @@ $use_datatable = true;
const CL_LIMIT = 600; // maximum changelog body length
$id = $_GET['id'] ?? 0;
require_once LIBS . 'changelog.php';
if(!empty($action))
{

View File

@ -8,6 +8,7 @@
* @link https://my-aac.org
*/
use MyAAC\Cache\Cache;
use MyAAC\Models\Menu;
defined('MYAAC') or die('Direct access not allowed!');

View File

@ -7,6 +7,10 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
use MyAAC\Forum;
use MyAAC\News;
defined('MYAAC') or die('Direct access not allowed!');
$title = 'News Panel';
@ -15,9 +19,6 @@ csrfProtect();
$use_datatable = true;
require_once LIBS . 'forum.php';
require_once LIBS . 'news.php';
if (!hasFlag(FLAG_CONTENT_PAGES) && !superAdmin()) {
echo 'Access denied.';
return;

View File

@ -8,6 +8,7 @@
* @link https://my-aac.org
*/
use MyAAC\Forum;
use MyAAC\Models\Player;
defined('MYAAC') or die('Direct access not allowed!');
@ -19,7 +20,6 @@ csrfProtect();
$player_base = ADMIN_URL . '?p=players';
$use_datatable = true;
require_once LIBS . 'forum.php';
$skills = array(
POT::SKILL_FIST => array('Fist fighting', 'fist'),

View File

@ -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.<br/>If you wish to enable, go to Settings and enable <strong>Enable Plugins Manage</strong>.');
}

View File

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

View File

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

View File

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

View File

@ -1,4 +1,8 @@
<?php
use MyAAC\Hooks;
use MyAAC\Settings;
const MYAAC_ADMIN = true;
require '../../common.php';
@ -7,7 +11,6 @@ require SYSTEM . 'init.php';
require SYSTEM . 'login.php';
// event system
require_once SYSTEM . 'hooks.php';
$hooks = new Hooks();
$hooks->load();

View File

@ -24,6 +24,7 @@
"autoload": {
"psr-4": {
"MyAAC\\": "system/src"
}
},
"files": ["system/src/global.php"]
}
}

View File

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

View File

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

View File

@ -1,4 +1,7 @@
<?php
use MyAAC\Settings;
defined('MYAAC') or die('Direct access not allowed!');
//ini_set('display_errors', false);

View File

@ -1,4 +1,7 @@
<?php
use MyAAC\Settings;
defined('MYAAC') or die('Direct access not allowed!');
ini_set('max_execution_time', 300);

View File

@ -47,11 +47,9 @@ if($success) {
success($locale['step_database_imported_players']);
}
require_once LIBS . 'plugins.php';
Plugins::installMenus('kathrine', require TEMPLATES . 'kathrine/menus.php');
Plugins::installMenus('tibiacom', require TEMPLATES . 'tibiacom/menus.php');
require LIBS . 'DataLoader.php';
DataLoader::setLocale($locale);
DataLoader::load();
@ -65,7 +63,10 @@ require_once SYSTEM . 'migrations/22.php';
require_once SYSTEM . 'migrations/27.php';
require_once SYSTEM . 'migrations/30.php';
use MyAAC\DataLoader;
use MyAAC\Models\FAQ as ModelsFAQ;
use MyAAC\Plugins;
if(ModelsFAQ::count() == 0) {
ModelsFAQ::create([
'question' => 'What is this?',

View File

@ -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);
}
?>
?>

View File

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

View File

@ -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
*/

View File

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

View File

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

View File

@ -1,3 +0,0 @@
<?php
class SensitiveException extends Exception {}

View File

@ -12,6 +12,8 @@
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public License, Version 3
*/
use MyAAC\Cache\Cache;
/**
* MySQL connection interface.
*
@ -94,7 +96,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()) {
$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);

View File

@ -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.
*

View File

@ -1,5 +1,7 @@
<?php
use MyAAC\Plugins;
if(!$db->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');

View File

@ -1,6 +1,6 @@
<?php
require_once LIBS . 'Settings.php';
use MyAAC\Settings;
$query = $db->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`;");

View File

@ -1,8 +1,10 @@
<?php
use MyAAC\Cache\Cache;
$db->exec('DROP TABLE IF EXISTS `' . TABLE_PREFIX . 'hooks`;');
$cache = Cache::getInstance();
if($cache->enabled()) {
$cache->delete('hooks');
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,6 +9,7 @@
*/
use MyAAC\Models\Pages;
use MyAAC\Plugins;
defined('MYAAC') or die('Direct access not allowed!');

View File

@ -10,6 +10,9 @@
* Additional options
* - for number: min, max, step
*/
use MyAAC\Settings;
return [
'name' => 'MyAAC',
'settings' =>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,8 @@
<?php
namespace MyAAC;
use MyAAC\Cache\Cache;
use MyAAC\Models\Changelog as ModelsChangelog;
class Changelog

View File

@ -1,5 +1,7 @@
<?php
namespace MyAAC;
use MyAAC\Models\Player;
/**
@ -50,8 +52,8 @@ class CreateCharacter
return false;
}
if(!admin() && !Validator::newCharacterName($name)) {
$errors['name'] = Validator::getLastError();
if(!admin() && !\Validator::newCharacterName($name)) {
$errors['name'] = \Validator::getLastError();
return false;
}
@ -123,13 +125,13 @@ class CreateCharacter
* @param int $sex
* @param int $vocation
* @param int $town
* @param OTS_Account $account
* @param \OTS_Account $account
* @param array $errors
* @return bool
* @throws E_OTS_NotLoaded
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \E_OTS_NotLoaded
* @throws \Twig_Error_Loader
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
*/
public function doCreate($name, $sex, $vocation, $town, $account, &$errors)
{
@ -147,7 +149,7 @@ class CreateCharacter
if(empty($errors))
{
$char_to_copy_name = config('character_samples')[$vocation];
$char_to_copy = new OTS_Player();
$char_to_copy = new \OTS_Player();
$char_to_copy->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: <b>'.$char_to_copy_name.'</b> 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);

View File

@ -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 '<h2>Reload monsters.</h2>';
@ -32,9 +31,9 @@ class Creatures {
}
try {
self::$monstersList = new OTS_MonstersList(config('data_path') . 'monster/');
self::$monstersList = new \OTS_MonstersList(config('data_path') . 'monster/');
}
catch(Exception $e) {
catch(\Exception $e) {
self::$lastError = $e->getMessage();
return false;
}
@ -119,7 +118,7 @@ class Creatures {
$summons = $monster->getSummons();
$loot = $monster->getLoot();
foreach($loot as &$item) {
if(!Validator::number($item['id'])) {
if(!\Validator::number($item['id'])) {
if(isset($items[$item['id']])) {
$item['id'] = $items[$item['id']];
}
@ -161,7 +160,7 @@ class Creatures {
success('Added: ' . $name . '<br/>');
}
}
catch(Exception $error) {
catch(\Exception $error) {
if($show) {
warning('Error while adding monster (' . $name . '): ' . $error->getMessage());
}

View File

@ -7,7 +7,8 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
defined('MYAAC') or die('Direct access not allowed!');
namespace MyAAC;
class Data
{

View File

@ -23,9 +23,8 @@
* @link https://my-aac.org
*/
/**
* Class DataLoader
*/
namespace MyAAC;
class DataLoader
{
private static $locale;
@ -38,7 +37,6 @@ class DataLoader
{
self::$startTime = microtime(true);
require_once LIBS . 'items.php';
if(Items::loadFromXML()) {
success(self::$locale['step_database_loaded_items'] . self::getLoadedTime());
}
@ -48,7 +46,6 @@ class DataLoader
self::$startTime = microtime(true);
require LIBS . 'creatures.php';
if(Creatures::loadFromXML()) {
success(self::$locale['step_database_loaded_monsters'] . self::getLoadedTime());
@ -63,7 +60,6 @@ class DataLoader
self::$startTime = microtime(true);
require_once LIBS . 'npc.php';
if(NPCs::loadFromXML()) {
success(self::$locale['step_database_loaded_npcs'] . self::getLoadedTime());
}
@ -73,7 +69,6 @@ class DataLoader
self::$startTime = microtime(true);
require LIBS . 'spells.php';
if(Spells::loadFromXML()) {
success(self::$locale['step_database_loaded_spells'] . self::getLoadedTime());
}
@ -92,7 +87,6 @@ class DataLoader
self::$startTime = microtime(true);
require LIBS . 'weapons.php';
if(Weapons::loadFromXML()) {
success(self::$locale['step_database_loaded_weapons'] . self::getLoadedTime());
}

View File

@ -0,0 +1,7 @@
<?php
namespace MyAAC\Exceptions;
class SensitiveException extends \Exception
{
}

View File

@ -8,12 +8,13 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
defined('MYAAC') or die('Direct access not allowed!');
namespace MyAAC;
$settingForumTablePrefix = setting('core.forum_table_prefix');
if(null !== $settingForumTablePrefix && !empty(trim($settingForumTablePrefix))) {
if(!in_array($settingForumTablePrefix, array('myaac_', 'z_'))) {
throw new RuntimeException('Invalid value for forum_table_prefix in config.php. Can be only: "myaac_" or "z_".');
throw new \RuntimeException('Invalid value for forum_table_prefix in config.php. Can be only: "myaac_" or "z_".');
}
define('FORUM_TABLE_PREFIX', $settingForumTablePrefix);
@ -30,9 +31,9 @@ else {
class Forum
{
/**
* @param OTS_Account $account
* @param \OTS_Account $account
* @return bool
* @throws E_OTS_NotLoaded
* @throws \E_OTS_NotLoaded
*/
public static function canPost($account)
{
@ -294,7 +295,7 @@ class Forum
$section = $sections[$board_id];
if($section['guild'] > 0) {
if($logged) {
$guild = new OTS_Guild();
$guild = new \OTS_Guild();
$guild->load($section['guild']);
$status = false;
if($guild->isLoaded()) {
@ -322,4 +323,3 @@ class Forum
return $hasAccess;
}
}
?>

42
system/src/Hook.php Normal file
View File

@ -0,0 +1,42 @@
<?php
namespace MyAAC;
class Hook
{
private $_name, $_type, $_file;
public function __construct($name, $type, $file) {
$this->_name = $name;
$this->_type = $type;
$this->_file = $file;
}
public function execute($params)
{
global $db, $config, $template_path, $ots, $content, $twig;
if(is_callable($this->_file))
{
$params['db'] = $db;
$params['config'] = $config;
$params['template_path'] = $template_path;
$params['ots'] = $ots;
$params['content'] = $content;
$params['twig'] = $twig;
$tmp = $this->_file;
$ret = $tmp($params);
}
else {
extract($params);
$ret = include BASE . $this->_file;
}
return !isset($ret) || $ret == 1 || $ret;
}
public function name() {return $this->_name;}
public function type() {return $this->_type;}
}

44
system/src/Hooks.php Normal file
View File

@ -0,0 +1,44 @@
<?php
namespace MyAAC;
class Hooks
{
private static $_hooks = array();
public function register($hook, $type = '', $file = null) {
if(!($hook instanceof Hook))
$hook = new Hook($hook, $type, $file);
self::$_hooks[$hook->type()][] = $hook;
}
public function trigger($type, $params = array())
{
$ret = true;
if(isset(self::$_hooks[$type]))
{
foreach(self::$_hooks[$type] as $name => $hook) {
/** @var $hook Hook */
if (!$hook->execute($params)) {
$ret = false;
}
}
}
return $ret;
}
public function exist($type) {
return isset(self::$_hooks[$type]);
}
public function load()
{
foreach(Plugins::getHooks() as $hook) {
$this->register($hook['name'], $hook['type'], $hook['file']);
}
Plugins::clearWarnings();
}
}

View File

@ -8,7 +8,11 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
defined('MYAAC') or die('Direct access not allowed!');
namespace MyAAC;
use MyAAC\Cache\PHP as CachePHP;
use MyAAC\Models\Spell;
class Items
{
@ -23,7 +27,7 @@ class Items
return false;
}
$xml = new DOMDocument;
$xml = new \DOMDocument;
$xml->load($file_path);
$items = array();
@ -39,8 +43,7 @@ class Items
}
}
require_once LIBS . 'cache_php.php';
$cache_php = new Cache_PHP(config('cache_prefix'), CACHE . 'persistent/');
$cache_php = new CachePHP(config('cache_prefix'), CACHE . 'persistent/');
$cache_php->set('items', $items, 5 * 365 * 24 * 60 * 60);
return true;
}
@ -67,8 +70,7 @@ class Items
return;
}
require_once LIBS . 'cache_php.php';
$cache_php = new Cache_PHP(config('cache_prefix'), CACHE . 'persistent/');
$cache_php = new CachePHP(config('cache_prefix'), CACHE . 'persistent/');
self::$items = $cache_php->get('items');
}
@ -110,7 +112,7 @@ class Items
$s .= 'an item of type ' . $item['id'];
if(isset($attr['type']) && strtolower($attr['type']) == 'rune') {
$item = Spells::where('item_id', $id)->first();
$item = Spell::where('item_id', $id)->first();
if($item) {
if($item->level > 0 && $item->maglevel > 0) {
$s .= '. ' . ($count > 1 ? "They" : "It") . ' can only be used by ';

View File

@ -1,6 +1,7 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class AccountVipList extends Model {

View File

@ -9,7 +9,10 @@
* @copyright 2021 MyAAC
* @link https://my-aac.org
*/
defined('MYAAC') or die('Direct access not allowed!');
namespace MyAAC;
use MyAAC\Cache\PHP as CachePHP;
class NPCs
{
@ -22,7 +25,7 @@ class NPCs
return false;
$npcs = [];
$xml = new DOMDocument();
$xml = new \DOMDocument();
foreach (preg_grep('~\.(xml)$~i', scandir($npc_path)) as $npc) {
$xml->load($npc_path . $npc);
if ($xml) {
@ -40,8 +43,7 @@ class NPCs
return false;
}
require_once LIBS . 'cache_php.php';
$cache_php = new Cache_PHP(config('cache_prefix'), CACHE . 'persistent/');
$cache_php = new CachePHP(config('cache_prefix'), CACHE . 'persistent/');
$cache_php->set('npcs', $npcs, 5 * 365 * 24 * 60 * 60);
return true;
}
@ -52,8 +54,7 @@ class NPCs
return;
}
require_once LIBS . 'cache_php.php';
$cache_php = new Cache_PHP(config('cache_prefix'), CACHE . 'persistent/');
$cache_php = new CachePHP(config('cache_prefix'), CACHE . 'persistent/');
self::$npcs = $cache_php->get('npcs');
}
}

View File

@ -1,5 +1,8 @@
<?php
namespace MyAAC;
use MyAAC\Cache\Cache;
use MyAAC\Models\News as ModelsNews;
class News

View File

@ -1,44 +1,9 @@
<?php
/**
* Plugins class
*
* @package MyAAC
* @author Gesior <jerzyskalski@wp.pl>
* @author Slawkens <slawkens@gmail.com>
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
defined('MYAAC') or die('Direct access not allowed!');
function is_sub_dir($path = NULL, $parent_folder = BASE) {
//Get directory path minus last folder
$dir = dirname($path);
$folder = substr($path, strlen($dir));
//Check the the base dir is valid
$dir = realpath($dir);
//Only allow valid filename characters
$folder = preg_replace('/[^a-z0-9\.\-_]/i', '', $folder);
//If this is a bad path or a bad end folder name
if( !$dir OR !$folder OR $folder === '.') {
return FALSE;
}
//Rebuild path
$path = $dir. '/' . $folder;
//If this path is higher than the parent folder
if( strcasecmp($path, $parent_folder) > 0 ) {
return $path;
}
return FALSE;
}
namespace MyAAC;
use Composer\Semver\Semver;
use MyAAC\Cache\Cache;
use MyAAC\Models\Menu;
class Plugins {
@ -123,17 +88,17 @@ class Plugins {
}
}
}
/*
usort($routes, function ($a, $b)
{
// key 3 is priority
if ($a[3] == $b[3]) {
return 0;
}
/*
usort($routes, function ($a, $b)
{
// key 3 is priority
if ($a[3] == $b[3]) {
return 0;
}
return ($a[3] > $b[3]) ? -1 : 1;
});
*/
return ($a[3] > $b[3]) ? -1 : 1;
});
*/
// cleanup before passing back
// priority is not needed anymore
foreach ($routes as &$route) {
@ -312,11 +277,11 @@ class Plugins {
{
global $db;
if(!\class_exists('ZipArchive')) {
throw new RuntimeException('Please install PHP zip extension. Plugins upload disabled until then.');
if(!\class_exists('\ZipArchive')) {
throw new \RuntimeException('Please install PHP zip extension. Plugins upload disabled until then.');
}
$zip = new ZipArchive();
$zip = new \ZipArchive();
if($zip->open($file) !== true) {
self::$error = 'There was a problem with opening zip archive.';
return false;

View File

@ -1,17 +1,11 @@
<?php
namespace MyAAC;
use MyAAC\Cache\Cache;
use MyAAC\Models\Settings as ModelsSettings;
/**
* CreateCharacter
*
* @package MyAAC
* @author Slawkens <slawkens@gmail.com>
* @copyright 2020 MyAAC
* @link https://my-aac.org
*/
class Settings implements ArrayAccess
class Settings implements \ArrayAccess
{
static private $instance;
private $settingsFile = [];
@ -59,7 +53,7 @@ class Settings implements ArrayAccess
$this->loadPlugin($pluginName);
if (!isset($this->settingsFile[$pluginName])) {
throw new RuntimeException("Error on save settings: plugin $pluginName does not exist");
throw new \RuntimeException("Error on save settings: plugin $pluginName does not exist");
}
$settings = $this->settingsFile[$pluginName];
@ -94,7 +88,7 @@ class Settings implements ArrayAccess
'key' => $key,
'value' => $value
]);
} catch (PDOException $error) {
} catch (\PDOException $error) {
$this->errors[] = 'Error while saving setting (' . $pluginName . ' - ' . $key . '): ' . $error->getMessage();
}
}
@ -296,7 +290,7 @@ class Settings implements ArrayAccess
}
else if ($setting['options'] == '$timezones') {
$timezones = [];
foreach (DateTimeZone::listIdentifiers() as $value) {
foreach (\DateTimeZone::listIdentifiers() as $value) {
$timezones[$value] = $value;
}
@ -455,7 +449,7 @@ class Settings implements ArrayAccess
// return specified plugin settings (all)
if(!isset($key)) {
if (!isset($this->settingsFile[$pluginKeyName]['settings'])) {
throw new RuntimeException('Unknown plugin settings: ' . $pluginKeyName);
throw new \RuntimeException('Unknown plugin settings: ' . $pluginKeyName);
}
return $this->settingsFile[$pluginKeyName]['settings'];
}
@ -595,10 +589,10 @@ class Settings implements ArrayAccess
}
try {
$connectionTest = new PDO('mysql:' . implode(';', $dns), $user, $password);
$connectionTest->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$connectionTest = new \PDO('mysql:' . implode(';', $dns), $user, $password);
$connectionTest->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $error) {
catch(\PDOException $error) {
error('MySQL connection failed. Settings has been reverted.');
error($error->getMessage());
return false;

View File

@ -9,9 +9,9 @@
* @link https://my-aac.org
*/
use MyAAC\Models\Spell;
namespace MyAAC;
defined('MYAAC') or die('Direct access not allowed!');
use MyAAC\Models\Spell;
class Spells {
private static $spellsList = null;
@ -38,7 +38,7 @@ class Spells {
try {
Spell::query()->delete();
} catch(Exception $error) {}
} catch(\Exception $error) {}
if($show) {
echo '<h2>Reload spells.</h2>';
@ -46,9 +46,9 @@ class Spells {
}
try {
self::$spellsList = new OTS_SpellsList($config['data_path'].'spells/spells.xml');
self::$spellsList = new \OTS_SpellsList($config['data_path'].'spells/spells.xml');
}
catch(Exception $e) {
catch(\Exception $e) {
self::$lastError = $e->getMessage();
return false;
}
@ -88,7 +88,7 @@ class Spells {
success('Added: ' . $name . '<br/>');
}
}
catch(PDOException $error) {
catch(\PDOException $error) {
if($show) {
warning('Error while adding spell (' . $name . '): ' . $error->getMessage());
}
@ -128,7 +128,7 @@ class Spells {
success('Added: ' . $name . '<br/>');
}
}
catch(PDOException $error) {
catch(\PDOException $error) {
if($show) {
warning('Error while adding spell (' . $name . '): ' . $error->getMessage());
}
@ -166,7 +166,7 @@ class Spells {
success('Added: ' . $name . '<br/>');
}
}
catch(PDOException $error) {
catch(\PDOException $error) {
if($show) {
warning('Error while adding spell (' . $name . '): ' . $error->getMessage());
}

View File

@ -7,7 +7,8 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
defined('MYAAC') or die('Direct access not allowed!');
namespace MyAAC;
class Timer
{

View File

@ -23,11 +23,10 @@
* @link https://my-aac.org
*/
namespace MyAAC;
use MyAAC\Models\Town;
/**
* Class Towns
*/
class Towns
{
/**
@ -109,7 +108,6 @@ class Towns
if (file_exists($mapFile)) {
ini_set('memory_limit', '-1');
require LIBS . 'TownsReader.php';
$townsReader = new TownsReader($mapFile);
$townsReader->load();

View File

@ -19,8 +19,10 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
namespace MyAAC;
/*
This code bases on oryginal OTServ code for .otbm files - file iomapotbm.cpp rev.2141
This code bases on original OTServ code for .otbm files - file iomapotbm.cpp rev.2141
*/
class TownsReader
{
@ -79,4 +81,4 @@ class TownsReader
public function get() {
return $this->towns;
}
}
}

View File

@ -7,9 +7,12 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
defined('MYAAC') or die('Direct access not allowed!');
class Usage_Statistics {
namespace MyAAC;
use MyAAC\Cache\Cache;
class UsageStatistics {
private static $report_url = 'https://my-aac.org/report_usage.php';
public static function report() {

View File

@ -8,11 +8,11 @@
* @link https://my-aac.org
*/
namespace MyAAC;
use MyAAC\Models\Monster;
use MyAAC\Models\Spell;
defined('MYAAC') or die('Direct access not allowed!');
class Validator
{
private static $lastError = '';
@ -332,9 +332,8 @@ class Validator
$npcCheck = setting('core.create_character_name_npc_check');
if ($npcCheck) {
require_once LIBS . 'npc.php';
NPCS::load();
if(NPCS::$npcs) {
NPCs::load();
if(NPCs::$npcs) {
foreach (NPCs::$npcs as $npc) {
if(strpos($name_lower, $npc) !== false) {
self::$lastError = 'Your name cannot contains NPC name.';

View File

@ -8,9 +8,10 @@
* @link https://my-aac.org
*/
use MyAAC\Models\Visitor;
namespace MyAAC;
defined('MYAAC') or die('Direct access not allowed!');
use MyAAC\Cache\Cache;
use MyAAC\Models\Visitor;
class Visitors
{

View File

@ -9,6 +9,8 @@
* @link https://my-aac.org
*/
namespace MyAAC;
use MyAAC\Models\Weapon;
defined('MYAAC') or die('Direct access not allowed!');
@ -22,7 +24,7 @@ class Weapons {
try {
Weapon::query()->delete();
} catch (PDOException $error) {
} catch (\PDOException $error) {
}
$file_path = $config['data_path'] . 'weapons/weapons.xml';
@ -31,7 +33,7 @@ class Weapons {
return false;
}
$xml = new DOMDocument;
$xml = new \DOMDocument;
$xml->load($file_path);
foreach ($xml->getElementsByTagName('wand') as $weapon) {

View File

@ -1,15 +1,7 @@
<?php
/**
* Events system
*
* @package MyAAC
* @author Slawkens <slawkens@gmail.com>
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
defined('MYAAC') or die('Direct access not allowed!');
$i = 0;
define('HOOK_STARTUP', ++$i);
define('HOOK_BEFORE_PAGE', ++$i);
define('HOOK_AFTER_PAGE', ++$i);
@ -82,83 +74,30 @@ define('HOOK_TWIG', ++$i);
const HOOK_FIRST = HOOK_STARTUP;
define('HOOK_LAST', $i);
require_once LIBS . 'plugins.php';
class Hook
function is_sub_dir($path = NULL, $parent_folder = BASE): bool|string
{
private $_name, $_type, $_file;
//Get directory path minus last folder
$dir = dirname($path);
$folder = substr($path, strlen($dir));
public function __construct($name, $type, $file) {
$this->_name = $name;
$this->_type = $type;
$this->_file = $file;
//Check the base dir is valid
$dir = realpath($dir);
//Only allow valid filename characters
$folder = preg_replace('/[^a-z0-9\.\-_]/i', '', $folder);
//If this is a bad path or a bad end folder name
if( !$dir OR !$folder OR $folder === '.') {
return false;
}
public function execute($params)
{
global $db, $config, $template_path, $ots, $content, $twig;
//Rebuild path
$path = $dir. '/' . $folder;
if(is_callable($this->_file))
{
$params['db'] = $db;
$params['config'] = $config;
$params['template_path'] = $template_path;
$params['ots'] = $ots;
$params['content'] = $content;
$params['twig'] = $twig;
$tmp = $this->_file;
$ret = $tmp($params);
}
else {
extract($params);
$ret = include BASE . $this->_file;
}
return !isset($ret) || $ret == 1 || $ret;
//If this path is higher than the parent folder
if( strcasecmp($path, $parent_folder) > 0 ) {
return $path;
}
public function name() {return $this->_name;}
public function type() {return $this->_type;}
}
class Hooks
{
private static $_hooks = array();
public function register($hook, $type = '', $file = null) {
if(!($hook instanceof Hook))
$hook = new Hook($hook, $type, $file);
self::$_hooks[$hook->type()][] = $hook;
}
public function trigger($type, $params = array())
{
$ret = true;
if(isset(self::$_hooks[$type]))
{
foreach(self::$_hooks[$type] as $name => $hook) {
/** @var $hook Hook */
if (!$hook->execute($params)) {
$ret = false;
}
}
}
return $ret;
}
public function exist($type) {
return isset(self::$_hooks[$type]);
}
public function load()
{
foreach(Plugins::getHooks() as $hook) {
$this->register($hook['name'], $hook['type'], $hook['file']);
}
Plugins::clearWarnings();
}
return false;
}

View File

@ -8,6 +8,7 @@
* @link https://my-aac.org
*/
use MyAAC\Cache\Cache;
use MyAAC\Models\Config;
use MyAAC\Models\PlayerOnline;

View File

@ -8,7 +8,9 @@
* @link https://my-aac.org
*/
use MyAAC\Cache\Cache;
use MyAAC\Models\Menu;
use MyAAC\Plugins;
defined('MYAAC') or die('Direct access not allowed!');

View File

@ -9,6 +9,7 @@
* @link https://my-aac.org
*/
use MyAAC\CreateCharacter;
use MyAAC\Models\Account;
// we need some functions
@ -67,7 +68,6 @@ else if(isset($_GET['name']))
if(!admin() && !Validator::newCharacterName($name))
error_(Validator::getLastError());
require_once LIBS . 'CreateCharacter.php';
$createCharacter = new CreateCharacter();
if (!$createCharacter->checkName($name, $errors)) {
error_($errors['name']);