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 <?php
use MyAAC\Plugins;
$order = 10; $order = 10;
$settingsMenu = []; $settingsMenu = [];

View File

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

View File

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

View File

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

View File

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

View File

@ -7,6 +7,9 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
use MyAAC\Plugins;
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
$title = 'Plugin manager'; $title = 'Plugin manager';
@ -14,8 +17,6 @@ csrfProtect();
$use_datatable = true; $use_datatable = true;
require_once LIBS . 'plugins.php';
if (!getBoolean(setting('core.admin_plugins_manage_enable'))) { 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>.'); 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 * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
use MyAAC\Plugins;
use MyAAC\Settings;
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
$title = 'Settings'; $title = 'Settings';

View File

@ -12,6 +12,7 @@ defined('MYAAC') or die('Direct access not allowed!');
use DeviceDetector\DeviceDetector; use DeviceDetector\DeviceDetector;
use DeviceDetector\Parser\Client\Browser; use DeviceDetector\Parser\Client\Browser;
use DeviceDetector\Parser\OperatingSystem; use DeviceDetector\Parser\OperatingSystem;
use MyAAC\Visitors;
$title = 'Visitors'; $title = 'Visitors';
$use_datatable = true; $use_datatable = true;
@ -24,7 +25,6 @@ if (!setting('core.visitors_counter')): ?>
return; return;
endif; endif;
require SYSTEM . 'libs/visitors.php';
$visitors = new Visitors(setting('core.visitors_counter_ttl')); $visitors = new Visitors(setting('core.visitors_counter_ttl'));
function compare($a, $b): int { function compare($a, $b): int {

View File

@ -22,6 +22,9 @@
* @copyright 2020 MyAAC * @copyright 2020 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
use MyAAC\DataLoader;
define('MYAAC_ADMIN', true); define('MYAAC_ADMIN', true);
require '../../common.php'; require '../../common.php';
@ -37,8 +40,6 @@ ob_implicit_flush();
ob_end_flush(); ob_end_flush();
header('X-Accel-Buffering: no'); header('X-Accel-Buffering: no');
require LIBS . 'DataLoader.php';
require LOCALE . 'en/main.php'; require LOCALE . 'en/main.php';
require LOCALE . 'en/install.php'; require LOCALE . 'en/install.php';

View File

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

View File

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

View File

@ -24,6 +24,9 @@
* @link https://my-aac.org * @link https://my-aac.org
*/ */
use MyAAC\UsageStatistics;
use MyAAC\Visitors;
require_once 'common.php'; require_once 'common.php';
require_once SYSTEM . 'functions.php'; require_once SYSTEM . 'functions.php';
@ -146,8 +149,7 @@ if(setting('core.anonymous_usage_statistics')) {
} }
if($should_report) { if($should_report) {
require_once LIBS . 'usage_statistics.php'; UsageStatistics::report();
Usage_Statistics::report();
updateDatabaseConfig('last_usage_report', time()); updateDatabaseConfig('last_usage_report', time());
if($cache->enabled()) { if($cache->enabled()) {
@ -160,7 +162,6 @@ if(setting('core.views_counter'))
require_once SYSTEM . 'counter.php'; require_once SYSTEM . 'counter.php';
if(setting('core.visitors_counter')) { if(setting('core.visitors_counter')) {
require_once SYSTEM . 'libs/visitors.php';
$visitors = new Visitors(setting('core.visitors_counter_ttl')); $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/functions.php';
require BASE . 'install/includes/locale.php'; require BASE . 'install/includes/locale.php';
require SYSTEM . 'clients.conf.php'; require SYSTEM . 'clients.conf.php';
require LIBS . 'Settings.php';
// ignore undefined index from Twig autoloader // ignore undefined index from Twig autoloader
$config['env'] = 'prod'; $config['env'] = 'prod';

View File

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

View File

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

View File

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

View File

@ -9,6 +9,8 @@
*/ */
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
class Validator extends \MyAAC\Validator {}
function check_name($name, &$errors = '') { function check_name($name, &$errors = '') {
if(Validator::characterName($name)) if(Validator::characterName($name))
return true; return true;

View File

@ -7,6 +7,9 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
use MyAAC\Cache\Cache;
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
define('COUNTER_SYNC', 10); // how often counter is synchronized with database (each x site refreshes) 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 * @link https://my-aac.org
*/ */
use MyAAC\Exceptions\SensitiveException;
if (class_exists(\Whoops\Run::class)) { if (class_exists(\Whoops\Run::class)) {
$whoops = new \Whoops\Run; $whoops = new \Whoops\Run;
if(IS_CLI) { if(IS_CLI) {
@ -21,8 +23,6 @@ if (class_exists(\Whoops\Run::class)) {
return; return;
} }
require LIBS . 'SensitiveException.php';
/** /**
* @param Exception $exception * @param Exception $exception
*/ */

View File

@ -9,12 +9,17 @@
*/ */
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
use MyAAC\Cache\Cache;
use MyAAC\CsrfToken; use MyAAC\CsrfToken;
use MyAAC\Items;
use MyAAC\Models\Config; use MyAAC\Models\Config;
use MyAAC\Models\Guild; use MyAAC\Models\Guild;
use MyAAC\Models\House; use MyAAC\Models\House;
use MyAAC\Models\Pages; use MyAAC\Models\Pages;
use MyAAC\Models\Player; use MyAAC\Models\Player;
use MyAAC\News;
use MyAAC\Plugins;
use MyAAC\Settings;
use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\PHPMailer;
use Twig\Loader\ArrayLoader as Twig_ArrayLoader; use Twig\Loader\ArrayLoader as Twig_ArrayLoader;
@ -137,7 +142,6 @@ function getGuildLink($name, $generate = true): string
} }
function getItemNameById($id) { function getItemNameById($id) {
require_once LIBS . 'items.php';
$item = Items::get($id); $item = Items::get($id);
return !empty($item['name']) ? $item['name'] : ''; return !empty($item['name']) ? $item['name'] : '';
} }
@ -1195,7 +1199,6 @@ function setting($key)
function clearCache() function clearCache()
{ {
require_once LIBS . 'news.php';
News::clearCache(); News::clearCache();
$cache = Cache::getInstance(); $cache = Cache::getInstance();
@ -1689,7 +1692,6 @@ function makeLinksClickable($text, $blank = true) {
} }
// validator functions // validator functions
require_once LIBS . 'validator.php';
require_once SYSTEM . 'compat/base.php'; require_once SYSTEM . 'compat/base.php';
// custom functions // custom functions

View File

@ -8,7 +8,12 @@
* @link https://my-aac.org * @link https://my-aac.org
*/ */
use DebugBar\StandardDebugBar;
use MyAAC\Cache\Cache;
use MyAAC\CsrfToken; use MyAAC\CsrfToken;
use MyAAC\Hooks;
use MyAAC\Settings;
use MyAAC\Towns;
defined('MYAAC') or die('Direct access not allowed!'); 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.'); 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') { if(config('env') === 'dev') {
require SYSTEM . 'exception.php'; require SYSTEM . 'exception.php';
} }
@ -39,11 +42,9 @@ if(isset($config['gzip_output']) && $config['gzip_output'] && isset($_SERVER['HT
ob_start('ob_gzhandler'); ob_start('ob_gzhandler');
// cache // cache
require_once SYSTEM . 'libs/cache.php';
$cache = Cache::getInstance(); $cache = Cache::getInstance();
// event system // event system
require_once SYSTEM . 'hooks.php';
$hooks = new Hooks(); $hooks = new Hooks();
$hooks->load(); $hooks->load();
@ -145,7 +146,6 @@ require_once SYSTEM . 'database.php';
require SYSTEM . 'migrate.php'; require SYSTEM . 'migrate.php';
// settings // settings
require_once LIBS . 'Settings.php';
$settings = Settings::getInstance(); $settings = Settings::getInstance();
$settings->load(); $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_NUMBER', $db->hasColumn('accounts', 'number'));
define('USE_ACCOUNT_SALT', $db->hasColumn('accounts', 'salt')); define('USE_ACCOUNT_SALT', $db->hasColumn('accounts', 'salt'));
require LIBS . 'Towns.php';
Towns::load(); 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 * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public License, Version 3
*/ */
use MyAAC\Cache\Cache;
/** /**
* MySQL connection interface. * MySQL connection interface.
* *
@ -94,7 +96,7 @@ class OTS_DB_MySQL extends OTS_Base_DB
} }
global $config; global $config;
if(class_exists('Cache') && ($cache = Cache::getInstance()) && $cache->enabled()) { if(class_exists('MyAAC\Cache\Cache') && ($cache = Cache::getInstance()) && $cache->enabled()) {
$tmp = null; $tmp = null;
$need_revalidation = true; $need_revalidation = true;
if($cache->fetch('database_checksum', $tmp) && $tmp) { if($cache->fetch('database_checksum', $tmp) && $tmp) {
@ -145,7 +147,7 @@ class OTS_DB_MySQL extends OTS_Base_DB
{ {
global $config; 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_tables', serialize($this->has_table_cache), 3600);
$cache->set('database_columns', serialize($this->has_column_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); $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 * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public License, Version 3
*/ */
use MyAAC\Cache\Cache;
/** /**
* List of groups. * List of groups.
* *

View File

@ -1,5 +1,7 @@
<?php <?php
use MyAAC\Plugins;
if(!$db->hasTable('myaac_menu')) { if(!$db->hasTable('myaac_menu')) {
$db->query(" $db->query("
CREATE TABLE `myaac_menu` 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('kathrine', require TEMPLATES . 'kathrine/menus.php');
Plugins::installMenus('tibiacom', require TEMPLATES . 'tibiacom/menus.php'); Plugins::installMenus('tibiacom', require TEMPLATES . 'tibiacom/menus.php');

View File

@ -1,6 +1,6 @@
<?php <?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`;"); $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,5 +1,7 @@
<?php <?php
use MyAAC\Cache\Cache;
$db->exec('DROP TABLE IF EXISTS `' . TABLE_PREFIX . 'hooks`;'); $db->exec('DROP TABLE IF EXISTS `' . TABLE_PREFIX . 'hooks`;');
$cache = Cache::getInstance(); $cache = Cache::getInstance();

View File

@ -8,6 +8,9 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
use MyAAC\CreateCharacter;
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
$title = 'Create Account'; $title = 'Create Account';
@ -21,7 +24,6 @@ if($logged)
} }
if(setting('core.account_create_character_create')) { if(setting('core.account_create_character_create')) {
require_once LIBS . 'CreateCharacter.php';
$createCharacter = new CreateCharacter(); $createCharacter = new CreateCharacter();
} }

View File

@ -8,6 +8,9 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
use MyAAC\CreateCharacter;
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
$title = 'Create Character'; $title = 'Create Character';
@ -30,7 +33,6 @@ $character_created = false;
$save = isset($_POST['save']) && $_POST['save'] == 1; $save = isset($_POST['save']) && $_POST['save'] == 1;
$errors = array(); $errors = array();
if($save) { if($save) {
require_once LIBS . 'CreateCharacter.php';
$createCharacter = new CreateCharacter(); $createCharacter = new CreateCharacter();
$character_created = $createCharacter->doCreate($character_name, $character_sex, $character_vocation, $character_town, $account_logged, $errors); $character_created = $createCharacter->doCreate($character_name, $character_sex, $character_vocation, $character_town, $account_logged, $errors);

View File

@ -8,6 +8,9 @@
* @copyright 2021 MyAAC * @copyright 2021 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
use MyAAC\Forum;
defined('MYAAC') or exit; defined('MYAAC') or exit;
$ret = require __DIR__ . '/forum/base.php'; $ret = require __DIR__ . '/forum/base.php';

View File

@ -8,6 +8,9 @@
* @copyright 2021 MyAAC * @copyright 2021 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
use MyAAC\Forum;
defined('MYAAC') or exit('Direct access not allowed!'); defined('MYAAC') or exit('Direct access not allowed!');
$canEdit = Forum::isModerator(); $canEdit = Forum::isModerator();

View File

@ -11,7 +11,7 @@
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
$title = 'Forum'; $title = 'Forum';
require_once LIBS . 'forum.php'; class_exists('MyAAC\Forum');
$forumSetting = setting('core.forum'); $forumSetting = setting('core.forum');
if(strtolower($forumSetting) != 'site') { if(strtolower($forumSetting) != 'site') {

View File

@ -8,6 +8,9 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
use MyAAC\Forum;
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
$ret = require __DIR__ . '/base.php'; $ret = require __DIR__ . '/base.php';

View File

@ -8,6 +8,9 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
use MyAAC\Forum;
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
$ret = require __DIR__ . '/base.php'; $ret = require __DIR__ . '/base.php';

View File

@ -8,6 +8,9 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
use MyAAC\Forum;
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
$ret = require __DIR__ . '/base.php'; $ret = require __DIR__ . '/base.php';

View File

@ -8,6 +8,9 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
use MyAAC\Forum;
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
$ret = require __DIR__ . '/base.php'; $ret = require __DIR__ . '/base.php';

View File

@ -8,6 +8,9 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
use MyAAC\Forum;
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
$ret = require __DIR__ . '/base.php'; $ret = require __DIR__ . '/base.php';

View File

@ -8,6 +8,9 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
use MyAAC\Forum;
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
$ret = require __DIR__ . '/base.php'; $ret = require __DIR__ . '/base.php';

View File

@ -8,6 +8,9 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
use MyAAC\Forum;
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
$ret = require __DIR__ . '/base.php'; $ret = require __DIR__ . '/base.php';

View File

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

View File

@ -9,6 +9,7 @@
* @link https://my-aac.org * @link https://my-aac.org
*/ */
use MyAAC\Cache\Cache;
use MyAAC\Models\Player; use MyAAC\Models\Player;
use MyAAC\Models\PlayerDeath; use MyAAC\Models\PlayerDeath;
use MyAAC\Models\PlayerKillers; use MyAAC\Models\PlayerKillers;

View File

@ -8,10 +8,11 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
defined('MYAAC') or die('Direct access not allowed!');
require_once LIBS . 'forum.php'; use MyAAC\Cache\Cache;
require_once LIBS . 'news.php'; use MyAAC\News;
defined('MYAAC') or die('Direct access not allowed!');
$canEdit = hasFlag(FLAG_CONTENT_NEWS) || superAdmin(); $canEdit = hasFlag(FLAG_CONTENT_NEWS) || superAdmin();
if(isset($_GET['archive'])) if(isset($_GET['archive']))

View File

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

View File

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

View File

@ -8,9 +8,10 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
defined('MYAAC') or die('Direct access not allowed!');
class Cache_APC namespace MyAAC\Cache;
class APC
{ {
private $prefix; private $prefix;
private $enabled; private $enabled;
@ -38,15 +39,18 @@ class Cache_APC
return ''; return '';
} }
public function fetch($key, &$var) { public function fetch($key, &$var)
{
return ($var = apc_fetch($this->prefix . $key)) !== false; return ($var = apc_fetch($this->prefix . $key)) !== false;
} }
public function delete($key) { public function delete($key)
{
apc_delete($this->prefix . $key); apc_delete($this->prefix . $key);
} }
public function enabled() { public function enabled()
{
return $this->enabled; return $this->enabled;
} }
} }

View File

@ -8,9 +8,10 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
defined('MYAAC') or die('Direct access not allowed!');
class Cache_APCu namespace MyAAC\Cache;
class APCu
{ {
private $prefix; private $prefix;
private $enabled; private $enabled;
@ -38,15 +39,18 @@ class Cache_APCu
return ''; return '';
} }
public function fetch($key, &$var) { public function fetch($key, &$var)
{
return ($var = apcu_fetch($this->prefix . $key)) !== false; return ($var = apcu_fetch($this->prefix . $key)) !== false;
} }
public function delete($key) { public function delete($key)
{
apcu_delete($this->prefix . $key); apcu_delete($this->prefix . $key);
} }
public function enabled() { public function enabled()
{
return $this->enabled; return $this->enabled;
} }
} }

View File

@ -8,7 +8,8 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
defined('MYAAC') or die('Direct access not allowed!');
namespace MyAAC\Cache;
/** /**
* Class Cache * Class Cache
@ -48,33 +49,27 @@ class Cache
switch (strtolower($engine)) { switch (strtolower($engine)) {
case 'apc': case 'apc':
require 'cache_apc.php'; self::$instance = new APC($prefix);
self::$instance = new Cache_APC($prefix);
break; break;
case 'apcu': case 'apcu':
require 'cache_apcu.php'; self::$instance = new APCu($prefix);
self::$instance = new Cache_APCu($prefix);
break; break;
case 'eaccelerator': case 'eaccelerator':
require 'cache_eaccelerator.php'; self::$instance = new eAccelerator($prefix);
self::$instance = new Cache_eAccelerator($prefix);
break; break;
case 'xcache': case 'xcache':
require 'cache_xcache.php'; self::$instance = new XCache($prefix);
self::$instance = new Cache_XCache($prefix);
break; break;
case 'file': case 'file':
require 'cache_file.php'; self::$instance = new File($prefix, CACHE);
self::$instance = new Cache_File($prefix, CACHE);
break; break;
case 'php': case 'php':
require 'cache_php.php'; self::$instance = new PHP($prefix, CACHE);
self::$instance = new Cache_PHP($prefix, CACHE);
break; break;
case 'auto': case 'auto':
@ -109,7 +104,10 @@ class Cache
/** /**
* @return bool * @return bool
*/ */
public function enabled() {return false;} public function enabled()
{
return false;
}
public static function remember($key, $ttl, $callback) public static function remember($key, $ttl, $callback)
{ {

View File

@ -8,14 +8,16 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
defined('MYAAC') or die('Direct access not allowed!');
class Cache_eAccelerator namespace MyAAC\Cache;
class EAccelerator
{ {
private $prefix; private $prefix;
private $enabled; private $enabled;
public function __construct($prefix = '') { public function __construct($prefix = '')
{
$this->prefix = $prefix; $this->prefix = $prefix;
$this->enabled = function_exists('eaccelerator_get'); $this->enabled = function_exists('eaccelerator_get');
} }
@ -37,15 +39,18 @@ class Cache_eAccelerator
return ''; return '';
} }
public function fetch($key, &$var) { public function fetch($key, &$var)
{
return ($var = eaccelerator_get($this->prefix . $key)) !== null; return ($var = eaccelerator_get($this->prefix . $key)) !== null;
} }
public function delete($key) { public function delete($key)
{
eaccelerator_rm($this->prefix . $key); eaccelerator_rm($this->prefix . $key);
} }
public function enabled() { public function enabled()
{
return $this->enabled; return $this->enabled;
} }
} }

View File

@ -7,15 +7,17 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
defined('MYAAC') or die('Direct access not allowed!');
class Cache_File namespace MyAAC\Cache;
class File
{ {
private $prefix; private $prefix;
private $dir; private $dir;
private $enabled; private $enabled;
public function __construct($prefix = '', $dir = '') { public function __construct($prefix = '', $dir = '')
{
$this->prefix = $prefix; $this->prefix = $prefix;
$this->dir = $dir; $this->dir = $dir;
$this->enabled = (file_exists($this->dir) && is_dir($this->dir) && is_writable($this->dir)); $this->enabled = (file_exists($this->dir) && is_dir($this->dir) && is_writable($this->dir));
@ -62,11 +64,13 @@ class Cache_File
} }
} }
public function enabled() { public function enabled()
{
return $this->enabled; return $this->enabled;
} }
private function _name($key) { private function _name($key)
{
return sprintf('%s%s%s', $this->dir, $this->prefix, sha1($key)); return sprintf('%s%s%s', $this->dir, $this->prefix, sha1($key));
} }
} }

View File

@ -7,15 +7,17 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
defined('MYAAC') or die('Direct access not allowed!');
class Cache_PHP namespace MyAAC\Cache;
class PHP
{ {
private $prefix; private $prefix;
private $dir; private $dir;
private $enabled; private $enabled;
public function __construct($prefix = '', $dir = '') { public function __construct($prefix = '', $dir = '')
{
$this->prefix = $prefix; $this->prefix = $prefix;
$this->dir = $dir; $this->dir = $dir;
$this->enabled = (file_exists($this->dir) && is_dir($this->dir) && is_writable($this->dir)); $this->enabled = (file_exists($this->dir) && is_dir($this->dir) && is_writable($this->dir));
@ -69,11 +71,13 @@ class Cache_PHP
} }
} }
public function enabled() { public function enabled()
{
return $this->enabled; return $this->enabled;
} }
private function _name($key) { private function _name($key)
{
return sprintf('%s%s%s', $this->dir, $this->prefix, sha1($key) . '.php'); return sprintf('%s%s%s', $this->dir, $this->prefix, sha1($key) . '.php');
} }
} }

View File

@ -8,14 +8,16 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
defined('MYAAC') or die('Direct access not allowed!');
class Cache_XCache namespace MyAAC\Cache;
class XCache
{ {
private $prefix; private $prefix;
private $enabled; private $enabled;
public function __construct($prefix = '') { public function __construct($prefix = '')
{
$this->prefix = $prefix; $this->prefix = $prefix;
$this->enabled = function_exists('xcache_get') && ini_get('xcache.var_size'); $this->enabled = function_exists('xcache_get') && ini_get('xcache.var_size');
} }
@ -48,11 +50,13 @@ class Cache_XCache
return true; return true;
} }
public function delete($key) { public function delete($key)
{
xcache_unset($this->prefix . $key); xcache_unset($this->prefix . $key);
} }
public function enabled() { public function enabled()
{
return $this->enabled; return $this->enabled;
} }
} }

View File

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

View File

@ -1,5 +1,7 @@
<?php <?php
namespace MyAAC;
use MyAAC\Models\Player; use MyAAC\Models\Player;
/** /**
@ -50,8 +52,8 @@ class CreateCharacter
return false; return false;
} }
if(!admin() && !Validator::newCharacterName($name)) { if(!admin() && !\Validator::newCharacterName($name)) {
$errors['name'] = Validator::getLastError(); $errors['name'] = \Validator::getLastError();
return false; return false;
} }
@ -123,13 +125,13 @@ class CreateCharacter
* @param int $sex * @param int $sex
* @param int $vocation * @param int $vocation
* @param int $town * @param int $town
* @param OTS_Account $account * @param \OTS_Account $account
* @param array $errors * @param array $errors
* @return bool * @return bool
* @throws E_OTS_NotLoaded * @throws \E_OTS_NotLoaded
* @throws Twig_Error_Loader * @throws \Twig_Error_Loader
* @throws Twig_Error_Runtime * @throws \Twig_Error_Runtime
* @throws Twig_Error_Syntax * @throws \Twig_Error_Syntax
*/ */
public function doCreate($name, $sex, $vocation, $town, $account, &$errors) public function doCreate($name, $sex, $vocation, $town, $account, &$errors)
{ {
@ -147,7 +149,7 @@ class CreateCharacter
if(empty($errors)) if(empty($errors))
{ {
$char_to_copy_name = config('character_samples')[$vocation]; $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); $char_to_copy->find($char_to_copy_name);
if(!$char_to_copy->isLoaded()) 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.'; $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") if($sex == "0")
$char_to_copy->setLookType(136); $char_to_copy->setLookType(136);
$player = new OTS_Player(); $player = new \OTS_Player();
$player->setName($name); $player->setName($name);
$player->setAccount($account); $player->setAccount($account);
$player->setGroupId(1); $player->setGroupId(1);
@ -194,7 +196,7 @@ class CreateCharacter
$player->setManaSpent($char_to_copy->getManaSpent()); $player->setManaSpent($char_to_copy->getManaSpent());
$player->setSoul($char_to_copy->getSoul()); $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; $value = 10;
if (setting('core.use_character_sample_skills')) { if (setting('core.use_character_sample_skills')) {
$value = $char_to_copy->getSkill($skill); $value = $char_to_copy->getSkill($skill);
@ -231,7 +233,7 @@ class CreateCharacter
$player->save(); $player->save();
$player->setCustomField('created', time()); $player->setCustomField('created', time());
$player = new OTS_Player(); $player = new \OTS_Player();
$player->find($name); $player->find($name);
if(!$player->isLoaded()) { if(!$player->isLoaded()) {
@ -240,7 +242,7 @@ class CreateCharacter
} }
if($db->hasTable('player_skills')) { 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; $value = 10;
if (setting('core.use_character_sample_skills')) { if (setting('core.use_character_sample_skills')) {
$value = $char_to_copy->getSkill($skill); $value = $char_to_copy->getSkill($skill);

View File

@ -9,14 +9,13 @@
* @link https://my-aac.org * @link https://my-aac.org
*/ */
namespace MyAAC;
use MyAAC\Models\Monster; use MyAAC\Models\Monster;
defined('MYAAC') or die('Direct access not allowed!');
require_once LIBS . 'items.php';
class Creatures { class Creatures {
/** /**
* @var OTS_MonstersList * @var \OTS_MonstersList
*/ */
private static $monstersList; private static $monstersList;
private static $lastError = ''; private static $lastError = '';
@ -24,7 +23,7 @@ class Creatures {
public static function loadFromXML($show = false) { public static function loadFromXML($show = false) {
try { try {
Monster::query()->delete(); Monster::query()->delete();
} catch(Exception $error) {} } catch(\Exception $error) {}
if($show) { if($show) {
echo '<h2>Reload monsters.</h2>'; echo '<h2>Reload monsters.</h2>';
@ -32,9 +31,9 @@ class Creatures {
} }
try { 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(); self::$lastError = $e->getMessage();
return false; return false;
} }
@ -119,7 +118,7 @@ class Creatures {
$summons = $monster->getSummons(); $summons = $monster->getSummons();
$loot = $monster->getLoot(); $loot = $monster->getLoot();
foreach($loot as &$item) { foreach($loot as &$item) {
if(!Validator::number($item['id'])) { if(!\Validator::number($item['id'])) {
if(isset($items[$item['id']])) { if(isset($items[$item['id']])) {
$item['id'] = $items[$item['id']]; $item['id'] = $items[$item['id']];
} }
@ -161,7 +160,7 @@ class Creatures {
success('Added: ' . $name . '<br/>'); success('Added: ' . $name . '<br/>');
} }
} }
catch(Exception $error) { catch(\Exception $error) {
if($show) { if($show) {
warning('Error while adding monster (' . $name . '): ' . $error->getMessage()); warning('Error while adding monster (' . $name . '): ' . $error->getMessage());
} }

View File

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

View File

@ -23,9 +23,8 @@
* @link https://my-aac.org * @link https://my-aac.org
*/ */
/** namespace MyAAC;
* Class DataLoader
*/
class DataLoader class DataLoader
{ {
private static $locale; private static $locale;
@ -38,7 +37,6 @@ class DataLoader
{ {
self::$startTime = microtime(true); self::$startTime = microtime(true);
require_once LIBS . 'items.php';
if(Items::loadFromXML()) { if(Items::loadFromXML()) {
success(self::$locale['step_database_loaded_items'] . self::getLoadedTime()); success(self::$locale['step_database_loaded_items'] . self::getLoadedTime());
} }
@ -48,7 +46,6 @@ class DataLoader
self::$startTime = microtime(true); self::$startTime = microtime(true);
require LIBS . 'creatures.php';
if(Creatures::loadFromXML()) { if(Creatures::loadFromXML()) {
success(self::$locale['step_database_loaded_monsters'] . self::getLoadedTime()); success(self::$locale['step_database_loaded_monsters'] . self::getLoadedTime());
@ -63,7 +60,6 @@ class DataLoader
self::$startTime = microtime(true); self::$startTime = microtime(true);
require_once LIBS . 'npc.php';
if(NPCs::loadFromXML()) { if(NPCs::loadFromXML()) {
success(self::$locale['step_database_loaded_npcs'] . self::getLoadedTime()); success(self::$locale['step_database_loaded_npcs'] . self::getLoadedTime());
} }
@ -73,7 +69,6 @@ class DataLoader
self::$startTime = microtime(true); self::$startTime = microtime(true);
require LIBS . 'spells.php';
if(Spells::loadFromXML()) { if(Spells::loadFromXML()) {
success(self::$locale['step_database_loaded_spells'] . self::getLoadedTime()); success(self::$locale['step_database_loaded_spells'] . self::getLoadedTime());
} }
@ -92,7 +87,6 @@ class DataLoader
self::$startTime = microtime(true); self::$startTime = microtime(true);
require LIBS . 'weapons.php';
if(Weapons::loadFromXML()) { if(Weapons::loadFromXML()) {
success(self::$locale['step_database_loaded_weapons'] . self::getLoadedTime()); 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 * @copyright 2019 MyAAC
* @link https://my-aac.org * @link https://my-aac.org
*/ */
defined('MYAAC') or die('Direct access not allowed!');
namespace MyAAC;
$settingForumTablePrefix = setting('core.forum_table_prefix'); $settingForumTablePrefix = setting('core.forum_table_prefix');
if(null !== $settingForumTablePrefix && !empty(trim($settingForumTablePrefix))) { if(null !== $settingForumTablePrefix && !empty(trim($settingForumTablePrefix))) {
if(!in_array($settingForumTablePrefix, array('myaac_', 'z_'))) { 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); define('FORUM_TABLE_PREFIX', $settingForumTablePrefix);
@ -30,9 +31,9 @@ else {
class Forum class Forum
{ {
/** /**
* @param OTS_Account $account * @param \OTS_Account $account
* @return bool * @return bool
* @throws E_OTS_NotLoaded * @throws \E_OTS_NotLoaded
*/ */
public static function canPost($account) public static function canPost($account)
{ {
@ -294,7 +295,7 @@ class Forum
$section = $sections[$board_id]; $section = $sections[$board_id];
if($section['guild'] > 0) { if($section['guild'] > 0) {
if($logged) { if($logged) {
$guild = new OTS_Guild(); $guild = new \OTS_Guild();
$guild->load($section['guild']); $guild->load($section['guild']);
$status = false; $status = false;
if($guild->isLoaded()) { if($guild->isLoaded()) {
@ -322,4 +323,3 @@ class Forum
return $hasAccess; 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 * @copyright 2019 MyAAC
* @link https://my-aac.org * @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 class Items
{ {
@ -23,7 +27,7 @@ class Items
return false; return false;
} }
$xml = new DOMDocument; $xml = new \DOMDocument;
$xml->load($file_path); $xml->load($file_path);
$items = array(); $items = array();
@ -39,8 +43,7 @@ class Items
} }
} }
require_once LIBS . 'cache_php.php'; $cache_php = new CachePHP(config('cache_prefix'), CACHE . 'persistent/');
$cache_php = new Cache_PHP(config('cache_prefix'), CACHE . 'persistent/');
$cache_php->set('items', $items, 5 * 365 * 24 * 60 * 60); $cache_php->set('items', $items, 5 * 365 * 24 * 60 * 60);
return true; return true;
} }
@ -67,8 +70,7 @@ class Items
return; return;
} }
require_once LIBS . 'cache_php.php'; $cache_php = new CachePHP(config('cache_prefix'), CACHE . 'persistent/');
$cache_php = new Cache_PHP(config('cache_prefix'), CACHE . 'persistent/');
self::$items = $cache_php->get('items'); self::$items = $cache_php->get('items');
} }
@ -110,7 +112,7 @@ class Items
$s .= 'an item of type ' . $item['id']; $s .= 'an item of type ' . $item['id'];
if(isset($attr['type']) && strtolower($attr['type']) == 'rune') { 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) {
if($item->level > 0 && $item->maglevel > 0) { if($item->level > 0 && $item->maglevel > 0) {
$s .= '. ' . ($count > 1 ? "They" : "It") . ' can only be used by '; $s .= '. ' . ($count > 1 ? "They" : "It") . ' can only be used by ';

View File

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

View File

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

View File

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

View File

@ -1,44 +1,9 @@
<?php <?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) { namespace MyAAC;
//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;
}
use Composer\Semver\Semver; use Composer\Semver\Semver;
use MyAAC\Cache\Cache;
use MyAAC\Models\Menu; use MyAAC\Models\Menu;
class Plugins { class Plugins {
@ -312,11 +277,11 @@ class Plugins {
{ {
global $db; global $db;
if(!\class_exists('ZipArchive')) { if(!\class_exists('\ZipArchive')) {
throw new RuntimeException('Please install PHP zip extension. Plugins upload disabled until then.'); throw new \RuntimeException('Please install PHP zip extension. Plugins upload disabled until then.');
} }
$zip = new ZipArchive(); $zip = new \ZipArchive();
if($zip->open($file) !== true) { if($zip->open($file) !== true) {
self::$error = 'There was a problem with opening zip archive.'; self::$error = 'There was a problem with opening zip archive.';
return false; return false;

View File

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

View File

@ -9,9 +9,9 @@
* @link https://my-aac.org * @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 { class Spells {
private static $spellsList = null; private static $spellsList = null;
@ -38,7 +38,7 @@ class Spells {
try { try {
Spell::query()->delete(); Spell::query()->delete();
} catch(Exception $error) {} } catch(\Exception $error) {}
if($show) { if($show) {
echo '<h2>Reload spells.</h2>'; echo '<h2>Reload spells.</h2>';
@ -46,9 +46,9 @@ class Spells {
} }
try { 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(); self::$lastError = $e->getMessage();
return false; return false;
} }
@ -88,7 +88,7 @@ class Spells {
success('Added: ' . $name . '<br/>'); success('Added: ' . $name . '<br/>');
} }
} }
catch(PDOException $error) { catch(\PDOException $error) {
if($show) { if($show) {
warning('Error while adding spell (' . $name . '): ' . $error->getMessage()); warning('Error while adding spell (' . $name . '): ' . $error->getMessage());
} }
@ -128,7 +128,7 @@ class Spells {
success('Added: ' . $name . '<br/>'); success('Added: ' . $name . '<br/>');
} }
} }
catch(PDOException $error) { catch(\PDOException $error) {
if($show) { if($show) {
warning('Error while adding spell (' . $name . '): ' . $error->getMessage()); warning('Error while adding spell (' . $name . '): ' . $error->getMessage());
} }
@ -166,7 +166,7 @@ class Spells {
success('Added: ' . $name . '<br/>'); success('Added: ' . $name . '<br/>');
} }
} }
catch(PDOException $error) { catch(\PDOException $error) {
if($show) { if($show) {
warning('Error while adding spell (' . $name . '): ' . $error->getMessage()); warning('Error while adding spell (' . $name . '): ' . $error->getMessage());
} }

View File

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

View File

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

View File

@ -19,8 +19,10 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 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 class TownsReader
{ {

View File

@ -7,9 +7,12 @@
* @copyright 2019 MyAAC * @copyright 2019 MyAAC
* @link https://my-aac.org * @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'; private static $report_url = 'https://my-aac.org/report_usage.php';
public static function report() { public static function report() {

View File

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

View File

@ -8,9 +8,10 @@
* @link https://my-aac.org * @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 class Visitors
{ {

View File

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

View File

@ -1,15 +1,7 @@
<?php <?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; $i = 0;
define('HOOK_STARTUP', ++$i); define('HOOK_STARTUP', ++$i);
define('HOOK_BEFORE_PAGE', ++$i); define('HOOK_BEFORE_PAGE', ++$i);
define('HOOK_AFTER_PAGE', ++$i); define('HOOK_AFTER_PAGE', ++$i);
@ -82,83 +74,30 @@ define('HOOK_TWIG', ++$i);
const HOOK_FIRST = HOOK_STARTUP; const HOOK_FIRST = HOOK_STARTUP;
define('HOOK_LAST', $i); define('HOOK_LAST', $i);
require_once LIBS . 'plugins.php'; function is_sub_dir($path = NULL, $parent_folder = BASE): bool|string
class Hook
{ {
private $_name, $_type, $_file; //Get directory path minus last folder
$dir = dirname($path);
$folder = substr($path, strlen($dir));
public function __construct($name, $type, $file) { //Check the base dir is valid
$this->_name = $name; $dir = realpath($dir);
$this->_type = $type;
$this->_file = $file; //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) //Rebuild path
{ $path = $dir. '/' . $folder;
global $db, $config, $template_path, $ots, $content, $twig;
if(is_callable($this->_file)) //If this path is higher than the parent folder
{ if( strcasecmp($path, $parent_folder) > 0 ) {
$params['db'] = $db; return $path;
$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; return false;
}
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();
}
} }

View File

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

View File

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

View File

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