diff --git a/admin/index.php b/admin/index.php index 5293d374..5102e634 100644 --- a/admin/index.php +++ b/admin/index.php @@ -1,7 +1,7 @@ load(); -require(SYSTEM . 'status.php'); -require(SYSTEM . 'login.php'); -require(ADMIN . 'includes/functions.php'); +require SYSTEM . 'status.php'; +require SYSTEM . 'login.php'; +require ADMIN . 'includes/functions.php'; $twig->addGlobal('config', $config); $twig->addGlobal('status', $status); @@ -41,7 +41,7 @@ if(!$logged || !admin()) { $page = 'login'; } -// include our page +// include our page $file = SYSTEM . 'pages/admin/' . $page . '.php'; if(!@file_exists($file)) { $page = '404'; @@ -56,5 +56,5 @@ ob_end_clean(); // template $template_path = 'template/'; -require(ADMIN . $template_path . 'template.php'); +require ADMIN . $template_path . 'template.php'; ?> diff --git a/admin/tools/phpinfo.php b/admin/tools/phpinfo.php index 0ebd694b..5b791d07 100644 --- a/admin/tools/phpinfo.php +++ b/admin/tools/phpinfo.php @@ -1,8 +1,8 @@ - * @copyright 2017 MyAAC - * @link http://my-aac.org - */ - -// uncomment if your php.ini have display_errors disabled and you want to see errors -// ini_set('display_errors', 1); -// ini_set('display_startup_errors', 1); -// error_reporting(E_ALL); - -require_once 'common.php'; -require_once SYSTEM . 'functions.php'; - -$uri = $_SERVER['REQUEST_URI']; - -$tmp = BASE_DIR; -if(!empty($tmp)) - $uri = str_replace(BASE_DIR . '/', '', $uri); -else - $uri = str_replace_first('/', '', $uri); - -$uri = str_replace(array('index.php/', '?'), '', $uri); -define('URI', $uri); - -if(preg_match("/^[A-Za-z0-9-_%\'+]+\.png$/i", $uri)) { - $tmp = explode('.', $uri); - $_REQUEST['name'] = urldecode($tmp[0]); - - chdir(TOOLS . 'signature'); - include TOOLS . 'signature/index.php'; - exit(); -} -else if(preg_match("/^(.*)\.(gif|jpg|png|jpeg|tiff|bmp|css|js|less|map|html|php|zip|rar|gz|ttf|woff|ico)$/i", $_SERVER['REQUEST_URI'])) { - header("HTTP/1.0 404 Not Found"); - exit; -} - -if(file_exists(BASE . 'config.local.php')) - require_once BASE . 'config.local.php'; - -if(file_exists(BASE . 'install') && (!isset($config['installed']) || !$config['installed'])) -{ - header('Location: ' . BASE_URL . 'install/'); - die('Setup detected that install/ directory exists. Please visit this url to start MyAAC Installation.
Delete install/ directory if you already installed MyAAC.
Remember to REFRESH this page when you\'re done!'); -} - -$found = false; -if(empty($uri) || isset($_REQUEST['template'])) { - $_REQUEST['p'] = 'news'; - $found = true; -} -else { - $tmp = strtolower($uri); - if(!preg_match('/[^A-z0-9_\-]/', $uri) && file_exists(SYSTEM . 'pages/' . $tmp . '.php')) { - $_REQUEST['p'] = $uri; - $found = true; - } - else { - $rules = array( - '/^account\/manage\/?$/' => array('subtopic' => 'accountmanagement'), - '/^account\/create\/?$/' => array('subtopic' => 'createaccount'), - '/^account\/lost\/?$/' => array('subtopic' => 'lostaccount'), - '/^account\/logout\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'logout'), - '/^account\/password\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_password'), - '/^account\/register\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'register'), - '/^account\/register\/new\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'register_new'), - '/^account\/email\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_email'), - '/^account\/info\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_info'), - '/^account\/character\/create\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'create_character'), - '/^account\/character\/name\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_name'), - '/^account\/character\/sex\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_sex'), - '/^account\/character\/delete\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'delete_character'), - '/^account\/character\/comment\/[A-Za-z0-9-_%+\']+\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_comment', 'name' => '$3'), - '/^account\/character\/comment\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_comment'), - '/^account\/confirm_email\/[A-Za-z0-9-_]+\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'confirm_email', 'v' => '$2'), - '/^characters\/[A-Za-z0-9-_%+\']+$/' => array('subtopic' => 'characters', 'name' => '$1'), - '/^changelog\/[0-9]+\/?$/' => array('subtopic' => 'changelog', 'page' => '$1'), - '/^commands\/add\/?$/' => array('subtopic' => 'commands', 'action' => 'add'), - '/^commands\/edit\/?$/' => array('subtopic' => 'commands', 'action' => 'edit'), - '/^faq\/add\/?$/' => array('subtopic' => 'faq', 'action' => 'add'), - '/^faq\/edit\/?$/' => array('subtopic' => 'faq', 'action' => 'edit'), - '/^forum\/add_board\/?$/' => array('subtopic' => 'forum', 'action' => 'add_board'),# - '/^forum\/edit_board\/?$/' => array('subtopic' => 'forum', 'action' => 'edit_board'), - '/^forum\/board\/[0-9]+\/?$/' => array('subtopic' => 'forum', 'action' => 'show_board', 'id' => '$2'), - '/^forum\/board\/[0-9]+\/[0-9]+\/?$/' => array('subtopic' => 'forum', 'action' => 'show_board', 'id' => '$2', 'page' => '$3'), - '/^forum\/thread\/[0-9]+\/?$/' => array('subtopic' => 'forum', 'action' => 'show_thread', 'id' => '$2'), - '/^forum\/thread\/[0-9]+\/[0-9]+\/?$/' => array('subtopic' => 'forum', 'action' => 'show_thread', 'id' => '$2', 'page' => '$3'), - '/^gallery\/add\/?$/' => array('subtopic' => 'gallery', 'action' => 'add'), - '/^gallery\/edit\/?$/' => array('subtopic' => 'gallery', 'action' => 'edit'), - '/^gallery\/[0-9]+\/?$/' => array('subtopic' => 'gallery', 'image' => '$1'), - '/^gifts\/history\/?$/' => array('subtopic' => 'gifts', 'action' => 'show_history'), - '/^guilds\/[A-Za-z0-9-_%+\']+$/' => array('subtopic' => 'guilds', 'action' => 'show', 'guild' => '$1'), - '/^highscores\/[A-Za-z0-9-_]+\/[A-Za-z0-9-_]+\/[0-9]+\/?$/' => array('subtopic' => 'highscores', 'list' => '$1', 'vocation' => '$2', 'page' => '$3'), - '/^highscores\/[A-Za-z0-9-_]+\/[0-9]+\/?$/' => array('subtopic' => 'highscores', 'list' => '$1', 'page' => '$2'), - '/^highscores\/[A-Za-z0-9-_]+\/[A-Za-z0-9-_]+\/?$/' => array('subtopic' => 'highscores', 'list' => '$1', 'vocation' => '$2'), - '/^highscores\/[A-Za-z0-9-_\']+\/?$/' => array('subtopic' => 'highscores', 'list' => '$1'), - '/^news\/add\/?$/' => array('subtopic' => 'news', 'action' => 'add'), - '/^news\/edit\/?$/' => array('subtopic' => 'news', 'action' => 'edit'), - '/^news\/archive\/?$/' => array('subtopic' => 'newsarchive'), - '/^news\/archive\/[0-9]+\/?$/' => array('subtopic' => 'newsarchive', 'id' => '$2'), - '/^polls\/[0-9]+\/?$/' => array('subtopic' => 'polls', 'id' => '$1'), - '/^spells\/[A-Za-z0-9-_%]+\/[A-Za-z0-9-_]+\/?$/' => array('subtopic' => 'spells', 'vocation' => '$1', 'order' => '$2') - ); - - foreach($rules as $rule => $redirect) { - if (preg_match($rule, $uri)) { - $tmp = explode('/', $uri); - foreach($redirect as $key => $value) { - - if(strpos($value, '$') !== false) { - $value = str_replace('$' . $value[1], $tmp[$value[1]], $value); - } - - $_REQUEST[$key] = $value; - $_GET[$key] = $value; - } - - $found = true; - break; - } - } - } -} - -// define page visited, so it can be used within events system -$page = isset($_REQUEST['subtopic']) ? $_REQUEST['subtopic'] : (isset($_REQUEST['p']) ? $_REQUEST['p'] : ''); -if(empty($page) || !preg_match('/^[A-z0-9\_\-]+$/', $page)) { - $tmp = URI; - if(!empty($tmp)) { - $page = $tmp; - } - else { - if(!$found) - $page = '404'; - else - $page = 'news'; - } -} - -$page = strtolower($page); -define('PAGE', $page); - -$template_place_holders = array(); - -require_once SYSTEM . 'init.php'; - -// event system -require_once SYSTEM . 'hooks.php'; -$hooks = new Hooks(); -$hooks->load(); -require_once SYSTEM . 'template.php'; -require_once SYSTEM . 'login.php'; -require_once SYSTEM . 'status.php'; - -$twig->addGlobal('config', $config); -$twig->addGlobal('status', $status); - -// database migrations -$tmp = ''; -if(fetchDatabaseConfig('database_version', $tmp)) { // we got version - $tmp = (int)$tmp; - if($tmp < DATABASE_VERSION) { // import if older - $db->revalidateCache(); - for($i = $tmp + 1; $i <= DATABASE_VERSION; $i++) { - require(SYSTEM . 'migrations/' . $i . '.php'); - updateDatabaseConfig('database_version', $i); - } - } -} -else { // register first version - registerDatabaseConfig('database_version', 0); - $db->revalidateCache(); - for($i = 1; $i <= DATABASE_VERSION; $i++) { - require(SYSTEM . 'migrations/' . $i . '.php'); - updateDatabaseConfig('database_version', $i); - } -} - -$hooks->trigger(HOOK_STARTUP); - -// anonymous usage statistics -// sent only when user agrees -if(isset($config['anonymous_usage_statistics']) && $config['anonymous_usage_statistics']) { - $report_time = 30 * 24 * 60 * 60; // report one time per 30 days - $should_report = true; - - $value = ''; - if($cache->enabled() && $cache->fetch('last_usage_report', $value)) { - $should_report = time() > (int)$value + $report_time; - } - else { - $value = ''; - if(fetchDatabaseConfig('last_usage_report', $value)) { - $should_report = time() > (int)$value + $report_time; - if($cache->enabled()) { - $cache->set('last_usage_report', $value); - } - } - else { - registerDatabaseConfig('last_usage_report', time() - ($report_time - (7 * 24 * 60 * 60))); // first report after a week - $should_report = false; - } - } - - if($should_report) { - require_once(LIBS . 'usage_statistics.php'); - Usage_Statistics::report(); - - updateDatabaseConfig('last_usage_report', time()); - if($cache->enabled()) { - $cache->set('last_usage_report', time()); - } - } -} - -if($config['views_counter']) - require_once SYSTEM . 'counter.php'; - -if($config['visitors_counter']) -{ - require_once SYSTEM . 'libs/visitors.php'; - $visitors = new Visitors($config['visitors_counter_ttl']); -} - -// page content loading -if(!isset($content[0])) - $content = ''; -$load_it = true; - -// check if site has been closed -$site_closed = false; -if(fetchDatabaseConfig('site_closed', $site_closed)) { - $site_closed = ($site_closed == 1); - if($site_closed) { - if(!admin()) - { - $title = getDatabaseConfig('site_closed_title'); - $content .= '

' . getDatabaseConfig('site_closed_message') . '


'; - $load_it = false; - } - - if(!$logged) - { - ob_start(); - require SYSTEM . 'pages/accountmanagement.php'; - $content .= ob_get_contents(); - ob_end_clean(); - $load_it = false; - } - } -} -define('SITE_CLOSED', $site_closed); - -// backward support for gesior -if($config['backward_support']) { - define('INITIALIZED', true); - $SQL = $db; - $layout_header = template_header(); - $layout_name = $template_path; - $news_content = ''; - $tickers_content = ''; - $subtopic = PAGE; - $main_content = ''; - - $config['access_admin_panel'] = 2; - $group_id_of_acc_logged = 0; - if($logged && $account_logged) - $group_id_of_acc_logged = $account_logged->getGroupId(); - - $config['site'] = &$config; - $config['server'] = &$config['lua']; - $config['site']['shop_system'] = $config['gifts_system']; - - if(!isset($config['vdarkborder'])) - $config['vdarkborder'] = '#505050'; - if(!isset($config['darkborder'])) - $config['darkborder'] = '#D4C0A1'; - if(!isset($config['lightborder'])) - $config['lightborder'] = '#F1E0C6'; - - $config['site']['download_page'] = true; - $config['site']['serverinfo_page'] = true; - $config['site']['screenshot_page'] = true; - - if($config['forum'] != '') - $config['forum_link'] = (strtolower($config['forum']) === 'site' ? getLink('forum') : $config['forum']); - - foreach($status as $key => $value) - $config['status']['serverStatus_' . $key] = $value; -} - -if($load_it) -{ - if(SITE_CLOSED && admin()) - $content .= '

Site is under maintenance (closed mode). Only privileged users can see it.

'; - - if($config['backward_support']) - require SYSTEM . 'compat_pages.php'; - - $ignore = false; - - $logged_access = 1; - if($logged && $account_logged && $account_logged->isLoaded()) { - $logged_access = $account_logged->getAccess(); - } - - $query = - $db->query( - 'SELECT `id`, `title`, `body`, `php`, `hidden`' . - ' FROM `' . TABLE_PREFIX . 'pages`' . - ' WHERE `name` LIKE ' . $db->quote($page) . ' AND `hidden` != 1 AND `access` <= ' . $db->quote($logged_access)); - if($query->rowCount() > 0) // found page - { - $ignore = true; - $query = $query->fetch(); - $title = $query['title']; - - if($query['php'] == '1') // execute it as php code - { - $tmp = substr($query['body'], 0, 10); - if(($pos = strpos($tmp, ' $errno, 'errstr' => $errstr); - } - set_error_handler('error_handler'); - - ob_start(); - eval($tmp); - $content .= ob_get_contents(); - ob_end_clean(); - - restore_error_handler(); - if(isset($php_errors[0]) && superAdmin()) { - var_dump($php_errors); - } - } - else - $content .= $query['body']; // plain html - - if(hasFlag(FLAG_CONTENT_PAGES) || superAdmin()) { - $content = $twig->render('admin.pages.links.html.twig', array( - 'page' => array('id' => $query['id'], 'hidden' => $query['hidden']) - )) . $content; - } - } - else - { - $file = SYSTEM . 'pages/' . $page . '.php'; - if(!@file_exists($file)) - { - $page = '404'; - $file = SYSTEM . 'pages/404.php'; - } - } - - ob_start(); - if($hooks->trigger(HOOK_BEFORE_PAGE)) { - if(!$ignore) - require $file; - } - - if($config['backward_support'] && isset($main_content[0])) - $content .= $main_content; - - $content .= ob_get_contents(); - ob_end_clean(); - $hooks->trigger(HOOK_AFTER_PAGE); -} - -if($config['backward_support']) { - $main_content = $content; - if(!isset($title)) - $title = ucfirst($page); - - $topic = $title; -} - -$title_full = (isset($title) ? $title . $config['title_separator'] : '') . $config['lua']['serverName']; -if(file_exists($template_path . '/index.php')) - require($template_path . '/index.php'); -else if(file_exists($template_path . '/template.php')) // deprecated - require($template_path . '/template.php'); -else if($config['backward_support'] && file_exists($template_path . '/layout.php')) -{ - require($template_path . '/layout.php'); -} -else -{ - // TODO: save more info to log file - die('ERROR: Cannot load template.'); -} - -echo base64_decode('PCEtLSBQb3dlcmVkIGJ5IE15QUFDIDo6IGh0dHBzOi8vd3d3Lm15LWFhYy5vcmcvIC0tPg==') . PHP_EOL; -if(superAdmin()) { - echo ''; - echo PHP_EOL . ''; - if(function_exists('memory_get_peak_usage')) { - echo PHP_EOL . ''; - } - - if($config['database_log']) { - echo PHP_EOL . ''; - } -} - -$hooks->trigger(HOOK_FINISH); -?> + + * @copyright 2017 MyAAC + * @link http://my-aac.org + */ + +// uncomment if your php.ini have display_errors disabled and you want to see errors +// ini_set('display_errors', 1); +// ini_set('display_startup_errors', 1); +// error_reporting(E_ALL); + +require_once 'common.php'; +require_once SYSTEM . 'functions.php'; + +$uri = $_SERVER['REQUEST_URI']; + +$tmp = BASE_DIR; +if(!empty($tmp)) + $uri = str_replace(BASE_DIR . '/', '', $uri); +else + $uri = str_replace_first('/', '', $uri); + +$uri = str_replace(array('index.php/', '?'), '', $uri); +define('URI', $uri); + +if(preg_match("/^[A-Za-z0-9-_%\'+]+\.png$/i", $uri)) { + $tmp = explode('.', $uri); + $_REQUEST['name'] = urldecode($tmp[0]); + + chdir(TOOLS . 'signature'); + include TOOLS . 'signature/index.php'; + exit(); +} +else if(preg_match("/^(.*)\.(gif|jpg|png|jpeg|tiff|bmp|css|js|less|map|html|php|zip|rar|gz|ttf|woff|ico)$/i", $_SERVER['REQUEST_URI'])) { + header("HTTP/1.0 404 Not Found"); + exit; +} + +if(file_exists(BASE . 'config.local.php')) + require_once BASE . 'config.local.php'; + +if(file_exists(BASE . 'install') && (!isset($config['installed']) || !$config['installed'])) +{ + header('Location: ' . BASE_URL . 'install/'); + die('Setup detected that install/ directory exists. Please visit this url to start MyAAC Installation.
Delete install/ directory if you already installed MyAAC.
Remember to REFRESH this page when you\'re done!'); +} + +$found = false; +if(empty($uri) || isset($_REQUEST['template'])) { + $_REQUEST['p'] = 'news'; + $found = true; +} +else { + $tmp = strtolower($uri); + if(!preg_match('/[^A-z0-9_\-]/', $uri) && file_exists(SYSTEM . 'pages/' . $tmp . '.php')) { + $_REQUEST['p'] = $uri; + $found = true; + } + else { + $rules = array( + '/^account\/manage\/?$/' => array('subtopic' => 'accountmanagement'), + '/^account\/create\/?$/' => array('subtopic' => 'createaccount'), + '/^account\/lost\/?$/' => array('subtopic' => 'lostaccount'), + '/^account\/logout\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'logout'), + '/^account\/password\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_password'), + '/^account\/register\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'register'), + '/^account\/register\/new\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'register_new'), + '/^account\/email\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_email'), + '/^account\/info\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_info'), + '/^account\/character\/create\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'create_character'), + '/^account\/character\/name\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_name'), + '/^account\/character\/sex\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_sex'), + '/^account\/character\/delete\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'delete_character'), + '/^account\/character\/comment\/[A-Za-z0-9-_%+\']+\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_comment', 'name' => '$3'), + '/^account\/character\/comment\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_comment'), + '/^account\/confirm_email\/[A-Za-z0-9-_]+\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'confirm_email', 'v' => '$2'), + '/^characters\/[A-Za-z0-9-_%+\']+$/' => array('subtopic' => 'characters', 'name' => '$1'), + '/^changelog\/[0-9]+\/?$/' => array('subtopic' => 'changelog', 'page' => '$1'), + '/^commands\/add\/?$/' => array('subtopic' => 'commands', 'action' => 'add'), + '/^commands\/edit\/?$/' => array('subtopic' => 'commands', 'action' => 'edit'), + '/^faq\/add\/?$/' => array('subtopic' => 'faq', 'action' => 'add'), + '/^faq\/edit\/?$/' => array('subtopic' => 'faq', 'action' => 'edit'), + '/^forum\/add_board\/?$/' => array('subtopic' => 'forum', 'action' => 'add_board'),# + '/^forum\/edit_board\/?$/' => array('subtopic' => 'forum', 'action' => 'edit_board'), + '/^forum\/board\/[0-9]+\/?$/' => array('subtopic' => 'forum', 'action' => 'show_board', 'id' => '$2'), + '/^forum\/board\/[0-9]+\/[0-9]+\/?$/' => array('subtopic' => 'forum', 'action' => 'show_board', 'id' => '$2', 'page' => '$3'), + '/^forum\/thread\/[0-9]+\/?$/' => array('subtopic' => 'forum', 'action' => 'show_thread', 'id' => '$2'), + '/^forum\/thread\/[0-9]+\/[0-9]+\/?$/' => array('subtopic' => 'forum', 'action' => 'show_thread', 'id' => '$2', 'page' => '$3'), + '/^gallery\/add\/?$/' => array('subtopic' => 'gallery', 'action' => 'add'), + '/^gallery\/edit\/?$/' => array('subtopic' => 'gallery', 'action' => 'edit'), + '/^gallery\/[0-9]+\/?$/' => array('subtopic' => 'gallery', 'image' => '$1'), + '/^gifts\/history\/?$/' => array('subtopic' => 'gifts', 'action' => 'show_history'), + '/^guilds\/[A-Za-z0-9-_%+\']+$/' => array('subtopic' => 'guilds', 'action' => 'show', 'guild' => '$1'), + '/^highscores\/[A-Za-z0-9-_]+\/[A-Za-z0-9-_]+\/[0-9]+\/?$/' => array('subtopic' => 'highscores', 'list' => '$1', 'vocation' => '$2', 'page' => '$3'), + '/^highscores\/[A-Za-z0-9-_]+\/[0-9]+\/?$/' => array('subtopic' => 'highscores', 'list' => '$1', 'page' => '$2'), + '/^highscores\/[A-Za-z0-9-_]+\/[A-Za-z0-9-_]+\/?$/' => array('subtopic' => 'highscores', 'list' => '$1', 'vocation' => '$2'), + '/^highscores\/[A-Za-z0-9-_\']+\/?$/' => array('subtopic' => 'highscores', 'list' => '$1'), + '/^news\/add\/?$/' => array('subtopic' => 'news', 'action' => 'add'), + '/^news\/edit\/?$/' => array('subtopic' => 'news', 'action' => 'edit'), + '/^news\/archive\/?$/' => array('subtopic' => 'newsarchive'), + '/^news\/archive\/[0-9]+\/?$/' => array('subtopic' => 'newsarchive', 'id' => '$2'), + '/^polls\/[0-9]+\/?$/' => array('subtopic' => 'polls', 'id' => '$1'), + '/^spells\/[A-Za-z0-9-_%]+\/[A-Za-z0-9-_]+\/?$/' => array('subtopic' => 'spells', 'vocation' => '$1', 'order' => '$2') + ); + + foreach($rules as $rule => $redirect) { + if (preg_match($rule, $uri)) { + $tmp = explode('/', $uri); + foreach($redirect as $key => $value) { + + if(strpos($value, '$') !== false) { + $value = str_replace('$' . $value[1], $tmp[$value[1]], $value); + } + + $_REQUEST[$key] = $value; + $_GET[$key] = $value; + } + + $found = true; + break; + } + } + } +} + +// define page visited, so it can be used within events system +$page = isset($_REQUEST['subtopic']) ? $_REQUEST['subtopic'] : (isset($_REQUEST['p']) ? $_REQUEST['p'] : ''); +if(empty($page) || !preg_match('/^[A-z0-9\_\-]+$/', $page)) { + $tmp = URI; + if(!empty($tmp)) { + $page = $tmp; + } + else { + if(!$found) + $page = '404'; + else + $page = 'news'; + } +} + +$page = strtolower($page); +define('PAGE', $page); + +$template_place_holders = array(); + +require_once SYSTEM . 'init.php'; + +// event system +require_once SYSTEM . 'hooks.php'; +$hooks = new Hooks(); +$hooks->load(); +require_once SYSTEM . 'template.php'; +require_once SYSTEM . 'login.php'; +require_once SYSTEM . 'status.php'; + +$twig->addGlobal('config', $config); +$twig->addGlobal('status', $status); + +// database migrations +$tmp = ''; +if(fetchDatabaseConfig('database_version', $tmp)) { // we got version + $tmp = (int)$tmp; + if($tmp < DATABASE_VERSION) { // import if older + $db->revalidateCache(); + for($i = $tmp + 1; $i <= DATABASE_VERSION; $i++) { + require SYSTEM . 'migrations/' . $i . '.php'; + updateDatabaseConfig('database_version', $i); + } + } +} +else { // register first version + registerDatabaseConfig('database_version', 0); + $db->revalidateCache(); + for($i = 1; $i <= DATABASE_VERSION; $i++) { + require SYSTEM . 'migrations/' . $i . '.php'; + updateDatabaseConfig('database_version', $i); + } +} + +$hooks->trigger(HOOK_STARTUP); + +// anonymous usage statistics +// sent only when user agrees +if(isset($config['anonymous_usage_statistics']) && $config['anonymous_usage_statistics']) { + $report_time = 30 * 24 * 60 * 60; // report one time per 30 days + $should_report = true; + + $value = ''; + if($cache->enabled() && $cache->fetch('last_usage_report', $value)) { + $should_report = time() > (int)$value + $report_time; + } + else { + $value = ''; + if(fetchDatabaseConfig('last_usage_report', $value)) { + $should_report = time() > (int)$value + $report_time; + if($cache->enabled()) { + $cache->set('last_usage_report', $value); + } + } + else { + registerDatabaseConfig('last_usage_report', time() - ($report_time - (7 * 24 * 60 * 60))); // first report after a week + $should_report = false; + } + } + + if($should_report) { + require_once(LIBS . 'usage_statistics.php'); + Usage_Statistics::report(); + + updateDatabaseConfig('last_usage_report', time()); + if($cache->enabled()) { + $cache->set('last_usage_report', time()); + } + } +} + +if($config['views_counter']) + require_once SYSTEM . 'counter.php'; + +if($config['visitors_counter']) +{ + require_once SYSTEM . 'libs/visitors.php'; + $visitors = new Visitors($config['visitors_counter_ttl']); +} + +// page content loading +if(!isset($content[0])) + $content = ''; +$load_it = true; + +// check if site has been closed +$site_closed = false; +if(fetchDatabaseConfig('site_closed', $site_closed)) { + $site_closed = ($site_closed == 1); + if($site_closed) { + if(!admin()) + { + $title = getDatabaseConfig('site_closed_title'); + $content .= '

' . getDatabaseConfig('site_closed_message') . '


'; + $load_it = false; + } + + if(!$logged) + { + ob_start(); + require SYSTEM . 'pages/accountmanagement.php'; + $content .= ob_get_contents(); + ob_end_clean(); + $load_it = false; + } + } +} +define('SITE_CLOSED', $site_closed); + +// backward support for gesior +if($config['backward_support']) { + define('INITIALIZED', true); + $SQL = $db; + $layout_header = template_header(); + $layout_name = $template_path; + $news_content = ''; + $tickers_content = ''; + $subtopic = PAGE; + $main_content = ''; + + $config['access_admin_panel'] = 2; + $group_id_of_acc_logged = 0; + if($logged && $account_logged) + $group_id_of_acc_logged = $account_logged->getGroupId(); + + $config['site'] = &$config; + $config['server'] = &$config['lua']; + $config['site']['shop_system'] = $config['gifts_system']; + + if(!isset($config['vdarkborder'])) + $config['vdarkborder'] = '#505050'; + if(!isset($config['darkborder'])) + $config['darkborder'] = '#D4C0A1'; + if(!isset($config['lightborder'])) + $config['lightborder'] = '#F1E0C6'; + + $config['site']['download_page'] = true; + $config['site']['serverinfo_page'] = true; + $config['site']['screenshot_page'] = true; + + if($config['forum'] != '') + $config['forum_link'] = (strtolower($config['forum']) === 'site' ? getLink('forum') : $config['forum']); + + foreach($status as $key => $value) + $config['status']['serverStatus_' . $key] = $value; +} + +if($load_it) +{ + if(SITE_CLOSED && admin()) + $content .= '

Site is under maintenance (closed mode). Only privileged users can see it.

'; + + if($config['backward_support']) + require SYSTEM . 'compat_pages.php'; + + $ignore = false; + + $logged_access = 1; + if($logged && $account_logged && $account_logged->isLoaded()) { + $logged_access = $account_logged->getAccess(); + } + + $query = + $db->query( + 'SELECT `id`, `title`, `body`, `php`, `hidden`' . + ' FROM `' . TABLE_PREFIX . 'pages`' . + ' WHERE `name` LIKE ' . $db->quote($page) . ' AND `hidden` != 1 AND `access` <= ' . $db->quote($logged_access)); + if($query->rowCount() > 0) // found page + { + $ignore = true; + $query = $query->fetch(); + $title = $query['title']; + + if($query['php'] == '1') // execute it as php code + { + $tmp = substr($query['body'], 0, 10); + if(($pos = strpos($tmp, ' $errno, 'errstr' => $errstr); + } + set_error_handler('error_handler'); + + ob_start(); + eval($tmp); + $content .= ob_get_contents(); + ob_end_clean(); + + restore_error_handler(); + if(isset($php_errors[0]) && superAdmin()) { + var_dump($php_errors); + } + } + else + $content .= $query['body']; // plain html + + if(hasFlag(FLAG_CONTENT_PAGES) || superAdmin()) { + $content = $twig->render('admin.pages.links.html.twig', array( + 'page' => array('id' => $query['id'], 'hidden' => $query['hidden']) + )) . $content; + } + } + else + { + $file = SYSTEM . 'pages/' . $page . '.php'; + if(!@file_exists($file)) + { + $page = '404'; + $file = SYSTEM . 'pages/404.php'; + } + } + + ob_start(); + if($hooks->trigger(HOOK_BEFORE_PAGE)) { + if(!$ignore) + require $file; + } + + if($config['backward_support'] && isset($main_content[0])) + $content .= $main_content; + + $content .= ob_get_contents(); + ob_end_clean(); + $hooks->trigger(HOOK_AFTER_PAGE); +} + +if($config['backward_support']) { + $main_content = $content; + if(!isset($title)) + $title = ucfirst($page); + + $topic = $title; +} + +$title_full = (isset($title) ? $title . $config['title_separator'] : '') . $config['lua']['serverName']; +if(file_exists($template_path . '/index.php')) + require $template_path . '/index.php'; +else if(file_exists($template_path . '/template.php')) // deprecated + require $template_path . '/template.php'; +else if($config['backward_support'] && file_exists($template_path . '/layout.php')) +{ + require $template_path . '/layout.php'; +} +else +{ + // TODO: save more info to log file + die('ERROR: Cannot load template.'); +} + +echo base64_decode('PCEtLSBQb3dlcmVkIGJ5IE15QUFDIDo6IGh0dHBzOi8vd3d3Lm15LWFhYy5vcmcvIC0tPg==') . PHP_EOL; +if(superAdmin()) { + echo ''; + echo PHP_EOL . ''; + if(function_exists('memory_get_peak_usage')) { + echo PHP_EOL . ''; + } + + if($config['database_log']) { + echo PHP_EOL . ''; + } +} + +$hooks->trigger(HOOK_FINISH); +?> diff --git a/install/includes/database.php b/install/includes/database.php index e7e1575d..0b051301 100644 --- a/install/includes/database.php +++ b/install/includes/database.php @@ -1,9 +1,9 @@ ' . diff --git a/install/includes/locale.php b/install/includes/locale.php index 19dad6ca..079e47d7 100644 --- a/install/includes/locale.php +++ b/install/includes/locale.php @@ -31,13 +31,13 @@ else } } } - + if(!isset($locale_)) $locale_ = 'en'; } -require(LOCALE . 'en/main.php'); -require(LOCALE . 'en/install.php'); +require LOCALE . 'en/main.php'; +require LOCALE . 'en/install.php'; $file_main = LOCALE . $locale_ . '/main.php'; if(!file_exists($file_main)) @@ -47,6 +47,6 @@ $file_install = LOCALE . $locale_ . '/install.php'; if(!file_exists($file_install)) $file_install = LOCALE . 'en/install.php'; -require($file_main); -require($file_install); +require $file_main; +require $file_install; ?> \ No newline at end of file diff --git a/install/index.php b/install/index.php index 06eb6d63..f40ca5cd 100644 --- a/install/index.php +++ b/install/index.php @@ -1,16 +1,16 @@ $tmp_locale, 'name' => $locale['name']); } } diff --git a/install/steps/5-database.php b/install/steps/5-database.php index fac8b263..c4512731 100644 --- a/install/steps/5-database.php +++ b/install/steps/5-database.php @@ -40,13 +40,13 @@ if(!$error) { } } } - - require(BASE . 'install/includes/config.php'); - + + require BASE . 'install/includes/config.php'; + if(!$error) { success($locale['step_database_importing']); - require(BASE . 'install/includes/database.php'); - + require BASE . 'install/includes/database.php'; + if(isset($database_error)) { // we failed connect to the database error($database_error); } diff --git a/install/steps/6-admin.php b/install/steps/6-admin.php index 46c58288..3dfdbb8f 100644 --- a/install/steps/6-admin.php +++ b/install/steps/6-admin.php @@ -1,10 +1,10 @@ hasColumn('players', 'deletion')) @@ -42,19 +42,19 @@ if($success) { success($locale['step_database_imported_players']); } -require(LIBS . 'items.php'); +require LIBS . 'items.php'; if(Items::loadFromXML()) success($locale['step_database_loaded_items']); else error(Items::getError()); -require(LIBS . 'weapons.php'); +require LIBS . 'weapons.php'; if(Weapons::loadFromXML()) success($locale['step_database_loaded_weapons']); else error(Weapons::getError()); -require(LIBS . 'creatures.php'); +require LIBS . 'creatures.php'; if(Creatures::loadFromXML()) { success($locale['step_database_loaded_monsters']); @@ -67,7 +67,7 @@ else { error(Creatures::getLastError()); } -require(LIBS . 'spells.php'); +require LIBS . 'spells.php'; if(Spells::loadFromXML()) { success($locale['step_database_loaded_spells']); } @@ -76,7 +76,7 @@ else { } // update config.highscores_ids_hidden -require_once(SYSTEM . 'migrations/20.php'); +require_once SYSTEM . 'migrations/20.php'; $database_migration_20 = true; $content = ''; if(!databaseMigration20($content)) { @@ -86,7 +86,7 @@ if(!databaseMigration20($content)) { } // add z_polls tables -require_once(SYSTEM . 'migrations/22.php'); +require_once SYSTEM . 'migrations/22.php'; $locale['step_finish_desc'] = str_replace('$ADMIN_PANEL$', generateLink(str_replace('tools/', '',ADMIN_URL), $locale['step_finish_admin_panel'], true), $locale['step_finish_desc']); $locale['step_finish_desc'] = str_replace('$HOMEPAGE$', generateLink(str_replace('tools/', '', BASE_URL), $locale['step_finish_homepage'], true), $locale['step_finish_desc']); diff --git a/system/bin/install_plugin.php b/system/bin/install_plugin.php index 75ed16b2..21c267b6 100644 --- a/system/bin/install_plugin.php +++ b/system/bin/install_plugin.php @@ -4,11 +4,11 @@ if(php_sapi_name() != "cli") { die('This script can be run only in command line mode.'); } -require_once('../../common.php'); -require_once(SYSTEM . 'functions.php'); -require_once(SYSTEM . 'init.php'); -require_once(SYSTEM . 'hooks.php'); -require_once(LIBS . 'plugins.php'); +require_once '../../common.php'; +require_once SYSTEM . 'functions.php'; +require_once SYSTEM . 'init.php'; +require_once SYSTEM . 'hooks.php'; +require_once LIBS . 'plugins.php'; if($argc != 2) { exit('This command expects one parameter: zip file name (plugin)' . PHP_EOL); diff --git a/system/hooks.php b/system/hooks.php index 91efd2f5..0f3c565f 100644 --- a/system/hooks.php +++ b/system/hooks.php @@ -47,7 +47,7 @@ class Hook global $db, $config, $template_path, $ots, $content, $twig; if(file_exists(BASE . $this->_file)) { - $ret = require(BASE . $this->_file); + $ret = require BASE . $this->_file; } return $ret === null || $ret == 1 || $ret; diff --git a/system/init.php b/system/init.php index e108efa6..1d06b1f2 100644 --- a/system/init.php +++ b/system/init.php @@ -120,9 +120,9 @@ if(!isset($config['highscores_ids_hidden']) || count($config['highscores_ids_hid } // POT -require_once(SYSTEM . 'libs/pot/OTS.php'); +require_once SYSTEM . 'libs/pot/OTS.php'; $ots = POT::getInstance(); -require_once(SYSTEM . 'database.php'); +require_once SYSTEM . 'database.php'; define('USE_ACCOUNT_NAME', $db->hasColumn('accounts', 'name')); // load vocation names diff --git a/system/item.php b/system/item.php index 0178e6b8..8930f94b 100644 --- a/system/item.php +++ b/system/item.php @@ -8,7 +8,7 @@ * @link http://my-aac.org */ defined('MYAAC') or die('Direct access not allowed!'); -require_once(SYSTEM . 'libs/items_images.php'); +require_once SYSTEM . 'libs/items_images.php'; Items_Images::$files = array( 'otb' => SYSTEM . 'data/items.otb', diff --git a/system/libs/cache.php b/system/libs/cache.php index 10e01fca..a766ab69 100644 --- a/system/libs/cache.php +++ b/system/libs/cache.php @@ -19,27 +19,27 @@ class Cache if(!self::$instance) { switch(strtolower($engine)) { case 'apc': - require('cache_apc.php'); + require 'cache_apc.php'; self::$instance = new Cache_APC($prefix); break; case 'apcu': - require('cache_apcu.php'); + require 'cache_apcu.php'; self::$instance = new Cache_APCu($prefix); break; case 'eaccelerator': - require('cache_eaccelerator.php'); + require 'cache_eaccelerator.php'; self::$instance = new Cache_eAccelerator($prefix); break; case 'xcache': - require('cache_xcache.php'); + require 'cache_xcache.php'; self::$instance = new Cache_XCache($prefix); break; case 'file': - require('cache_file.php'); + require 'cache_file.php'; self::$instance = new Cache_File($prefix, CACHE); break; diff --git a/system/libs/plugins.php b/system/libs/plugins.php index c39a3076..78bb56ff 100644 --- a/system/libs/plugins.php +++ b/system/libs/plugins.php @@ -236,7 +236,7 @@ class Plugins { if (isset($plugin['install'])) { if (file_exists(BASE . $plugin['install'])) { $db->revalidateCache(); - require(BASE . $plugin['install']); + require BASE . $plugin['install']; $db->revalidateCache(); } else diff --git a/system/pages/account.php b/system/pages/account.php index f7d5c135..881acc82 100644 --- a/system/pages/account.php +++ b/system/pages/account.php @@ -11,6 +11,6 @@ defined('MYAAC') or die('Direct access not allowed!'); if($action == 'confirm_email') { - require_once(PAGES . 'account/confirm_email.php'); + require_once PAGES . 'account/confirm_email.php'; } ?> diff --git a/system/pages/accountmanagement.php b/system/pages/accountmanagement.php index f0ca51d8..e653b6b3 100644 --- a/system/pages/accountmanagement.php +++ b/system/pages/accountmanagement.php @@ -12,7 +12,7 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Account Management'; if($config['account_country']) - require(SYSTEM . 'countries.conf.php'); + require SYSTEM . 'countries.conf.php'; $groups = new OTS_Groups_List(); @@ -30,7 +30,7 @@ if(ACTION == "logout" && !isset($_REQUEST['account_login'])) { if(!$logged) { if(ACTION == 'confirm_email') { - require(PAGES . 'account/' . ACTION . '.php'); + require PAGES . 'account/' . ACTION . '.php'; return; } @@ -137,7 +137,7 @@ $errors = array(); error('Error: Action contains illegal characters.'); } else if(file_exists(PAGES . 'account/' . $action . '.php')) { - require(PAGES . 'account/' . $action . '.php'); + require PAGES . 'account/' . $action . '.php'; } else { error('This page does not exists.'); diff --git a/system/pages/admin/items.php b/system/pages/admin/items.php index 1d0d8269..fa88e132 100644 --- a/system/pages/admin/items.php +++ b/system/pages/admin/items.php @@ -10,8 +10,8 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Load items.xml'; -require(LIBS . 'items.php'); -require(LIBS . 'weapons.php'); +require LIBS . 'items.php'; +require LIBS . 'weapons.php'; echo $twig->render('admin.items.html.twig'); diff --git a/system/pages/admin/menus.php b/system/pages/admin/menus.php index 9511ebd3..d176c215 100644 --- a/system/pages/admin/menus.php +++ b/system/pages/admin/menus.php @@ -49,7 +49,7 @@ if(isset($_REQUEST['template'])) { $file = TEMPLATES . $template . '/config.php'; if(file_exists($file)) { - require_once($file); + require_once $file; } else { echo 'Cannot find template config.php file.'; diff --git a/system/pages/admin/plugins.php b/system/pages/admin/plugins.php index 416ab27f..7db83cc5 100644 --- a/system/pages/admin/plugins.php +++ b/system/pages/admin/plugins.php @@ -10,7 +10,7 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Plugin manager'; -require(LIBS . 'plugins.php'); +require LIBS . 'plugins.php'; echo $twig->render('admin.plugins.form.html.twig'); diff --git a/system/pages/admin/tools.php b/system/pages/admin/tools.php index 235eac33..572f14d7 100644 --- a/system/pages/admin/tools.php +++ b/system/pages/admin/tools.php @@ -25,5 +25,5 @@ if(preg_match("/[^A-z0-9_\-]/", $tool)) $file = BASE . 'admin/pages/tools/' . $tool . '.php'; if(!@file_exists($file)) - require($file); + require $file; ?> diff --git a/system/pages/admin/visitors.php b/system/pages/admin/visitors.php index b5cf9de8..ca3c739a 100644 --- a/system/pages/admin/visitors.php +++ b/system/pages/admin/visitors.php @@ -18,7 +18,7 @@ You can enable it by editing this configurable in config.local.php file:< return; endif; -require(SYSTEM . 'libs/visitors.php'); +require SYSTEM . 'libs/visitors.php'; $visitors = new Visitors($config['visitors_counter_ttl']); function compare($a, $b) { diff --git a/system/pages/characters.php b/system/pages/characters.php index b66e0820..ef4f6201 100644 --- a/system/pages/characters.php +++ b/system/pages/characters.php @@ -11,7 +11,7 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Characters'; -require_once(SYSTEM . 'item.php'); +require_once SYSTEM . 'item.php'; $groups = new OTS_Groups_List(); function generate_search_form($autofocus = false) diff --git a/system/pages/createaccount.php b/system/pages/createaccount.php index 59dd7ac6..ccdba296 100644 --- a/system/pages/createaccount.php +++ b/system/pages/createaccount.php @@ -12,7 +12,7 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Create Account'; if($config['account_country']) - require(SYSTEM . 'countries.conf.php'); + require SYSTEM . 'countries.conf.php'; if($logged) { diff --git a/system/pages/forum.php b/system/pages/forum.php index 8696ece4..8f0771de 100644 --- a/system/pages/forum.php +++ b/system/pages/forum.php @@ -26,7 +26,7 @@ if(strtolower($config['forum']) != 'site') if(!$logged) echo 'You are not logged in. Log in to post on the forum.

'; -require_once(LIBS . 'forum.php'); +require_once LIBS . 'forum.php'; $canEdit = Forum::isModerator(); if($canEdit) diff --git a/system/pages/guilds.php b/system/pages/guilds.php index 13a9ea20..19b5cbba 100644 --- a/system/pages/guilds.php +++ b/system/pages/guilds.php @@ -20,14 +20,14 @@ define('MOTD_EXISTS', $db->hasColumn('guilds', 'motd')); //show list of guilds if(empty($action)) { - require(PAGES . 'guilds/list_of_guilds.php'); + require PAGES . 'guilds/list_of_guilds.php'; } else { if(!ctype_alnum(str_replace(array('-', '_'), '', $action))) { error('Error: Action contains illegal characters.'); } else if(file_exists(PAGES . 'guilds/' . $action . '.php')) { - require(PAGES . 'guilds/' . $action . '.php'); + require PAGES . 'guilds/' . $action . '.php'; } else { error('This page does not exists.'); diff --git a/system/pages/highscores.php b/system/pages/highscores.php index df8c98fb..77538c51 100644 --- a/system/pages/highscores.php +++ b/system/pages/highscores.php @@ -12,7 +12,7 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Highscores'; if($config['account_country'] && $config['highscores_country_box']) - require(SYSTEM . 'countries.conf.php'); + require SYSTEM . 'countries.conf.php'; $list = isset($_GET['list']) ? $_GET['list'] : ''; $_page = isset($_GET['page']) ? $_GET['page'] : 0; diff --git a/system/pages/news.php b/system/pages/news.php index dd249852..c746adc8 100644 --- a/system/pages/news.php +++ b/system/pages/news.php @@ -10,7 +10,7 @@ */ defined('MYAAC') or die('Direct access not allowed!'); -require_once(LIBS . 'forum.php'); +require_once LIBS . 'forum.php'; if(isset($_GET['archive'])) { diff --git a/system/pages/newsarchive.php b/system/pages/newsarchive.php index 91d0f6a3..a32dce31 100644 --- a/system/pages/newsarchive.php +++ b/system/pages/newsarchive.php @@ -9,5 +9,5 @@ * @link http://my-aac.org */ $_GET['archive'] = true; -require('news.php'); +require 'news.php'; ?> diff --git a/system/pages/online.php b/system/pages/online.php index 8373572c..286fe046 100644 --- a/system/pages/online.php +++ b/system/pages/online.php @@ -12,7 +12,7 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Who is online?'; if($config['account_country']) - require(SYSTEM . 'countries.conf.php'); + require SYSTEM . 'countries.conf.php'; $promotion = ''; if($db->hasColumn('players', 'promotion')) diff --git a/system/pages/team.php b/system/pages/team.php index 0b9f75d6..5bab28c9 100644 --- a/system/pages/team.php +++ b/system/pages/team.php @@ -12,7 +12,7 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Gamemasters List'; if($config['account_country']) - require(SYSTEM . 'countries.conf.php'); + require SYSTEM . 'countries.conf.php'; $groups = new OTS_Groups_List(); if(!$groups->count()) diff --git a/templates/tibiacom/headline.php b/templates/tibiacom/headline.php index 71ebcaff..bacef45b 100644 --- a/templates/tibiacom/headline.php +++ b/templates/tibiacom/headline.php @@ -1,5 +1,5 @@ 7 ) ); /** Get experience points for a certain level **/ diff --git a/tools/status.php b/tools/status.php index 10277889..ae0ee49d 100644 --- a/tools/status.php +++ b/tools/status.php @@ -1,9 +1,9 @@