From b3f6ba4d58a8e5aa97084629c91363bd534ec063 Mon Sep 17 00:00:00 2001 From: Shadez Date: Thu, 30 Dec 2010 01:03:06 +0800 Subject: [PATCH] [429] Use __ARMORYDIRECTORY__ constant in include()/require_once() functions --- includes/armory_loader.php | 64 +++++++++++++++++++++++-------- includes/classes/class.armory.php | 22 +++++------ includes/revision_nr.php | 4 +- tools/build_loot_tables.php | 9 ++--- tools/create_database_dump.php | 2 +- 5 files changed, 64 insertions(+), 37 deletions(-) diff --git a/includes/armory_loader.php b/includes/armory_loader.php index 7f477f738..bac48344a 100644 --- a/includes/armory_loader.php +++ b/includes/armory_loader.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 405 + * @revision 429 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -25,14 +25,21 @@ if(!defined('__ARMORY__')) { die('Direct access to this file not allowed!'); } +// Detect armory directory +define('__ARMORYDIRECTORY__', dirname(dirname(__FILE__))); +if(!defined('__ARMORYDIRECTORY__') || __ARMORYDIRECTORY__ == null) { + die('Fatal error: unable to detect armory directory!'); +} session_start(); -if(!@include('classes/class.armory.php')) { +if(!@include(__ARMORYDIRECTORY__ . '/includes/classes/class.armory.php')) { die('Error: unable to load Armory class!'); } -if(!@include('revision_nr.php')) { - die('Error: unable to load revision_nr.php!'); +if(!@include(__ARMORYDIRECTORY__ . '/includes/revision_nr.php')) { + die('Error: unable to load revision file!'); } +// Forgot what am I did here :( $_SESSION['last_url'] = str_replace('.php', '.xml', $_SERVER['PHP_SELF']) . '?' .str_replace('locale=', 'l=', $_SERVER['QUERY_STRING']); + $armory = new Armory(); /* Check DbVersion */ $dbVersion = $armory->aDB->selectCell("SELECT `version` FROM `ARMORYDBPREFIX_db_version`"); @@ -91,14 +98,14 @@ if($armory->armoryconfig['maintenance'] == true && !defined('MAINTENANCE_PAGE')) { header('Location: maintenance.xml'); } -if(!@include('UpdateFields.php')) { +if(!@include(__ARMORYDIRECTORY__ . '/includes/UpdateFields.php')) { die('Error: unable to load UpdateFields.php!'); } -if(!@include('defines.php')) { +if(!@include(__ARMORYDIRECTORY__ . '/includes/defines.php')) { die('Error: unable to load defines.php!'); } if(!defined('skip_utils_class')) { - if(!@include('classes/class.utils.php')) { + if(!@include(__ARMORYDIRECTORY__ . '/includes/classes/class.utils.php')) { die('Error: unable to load utils class!'); } $utils = new Utils($armory); @@ -109,6 +116,29 @@ $utils->CheckConfigRealmData(); // Check $_GET variable $utils->CheckVariablesForPage(); + /* + // Check sessions count + // May be not required? + //TODO: think about this feature + $sess_count = $utils->GetSessionsCount(); + if($sess_count >= $armory->armoryconfig['maxSessionCount'] && !$utils->IsCorrectSession() && !defined('LIMIT_PAGE')) { + header('Location: limit.xml'); + } + elseif($sess_count < $armory->armoryconfig['maxSessionCount'] && !$utils->IsCorrectSession()) { + // we can create session + $utils->CreateNewSession(); + if(defined('LIMIT_PAGE')) { + header('Location: index.xml'); + } + } + elseif($sess_count < $armory->armoryconfig['maxSessionCount'] && $utils->IsCorrectSession()) { + // just update + $utils->UpdateSession(); + if(defined('LIMIT_PAGE')) { + header('Location: index.xml'); + } + } + */ } /** Login **/ if(isset($_GET['login']) && $_GET['login'] == 1) { @@ -172,61 +202,61 @@ } $_locale = (isset($_SESSION['armoryLocale'])) ? $_SESSION['armoryLocale'] : $armory->GetLocale(); if(defined('load_characters_class')) { - if(!@include('classes/class.characters.php')) { + if(!@include(__ARMORYDIRECTORY__ . '/includes/classes/class.characters.php')) { die('Error: unable to load characters class!'); } $characters = new Characters($armory); } if(defined('load_guilds_class')) { - if(!@include('classes/class.guilds.php')) { + if(!@include(__ARMORYDIRECTORY__ . '/includes/classes/class.guilds.php')) { die('Error: unable to load guilds class!'); } $guilds = new Guilds($armory); } if(defined('load_achievements_class')) { - if(!@include('classes/class.achievements.php')) { + if(!@include(__ARMORYDIRECTORY__ . '/includes/classes/class.achievements.php')) { die('Error: unable to load achievements class!'); } // Do not create class instance here. It should be created in Characters::GetAchievementMgr(). } if(defined('load_items_class')) { - if(!@include('classes/class.items.php')) { + if(!@include(__ARMORYDIRECTORY__ . '/includes/classes/class.items.php')) { die('Error: unable to load items class!'); } $items = new Items($armory); } if(defined('load_mangos_class')) { - if(!@include('classes/class.mangos.php')) { + if(!@include(__ARMORYDIRECTORY__ . '/includes/classes/class.mangos.php')) { die('Error: unable to load Mangos class!'); } $mangos = new Mangos($armory); } if(defined('load_arenateams_class')) { - if(!@include('classes/class.arenateams.php')) { + if(!@include(__ARMORYDIRECTORY__ . '/includes/classes/class.arenateams.php')) { die('Error: unable to load arenateams class!'); } $arenateams = new Arenateams($armory); } if(defined('load_search_class')) { - if(!@include('classes/class.search.php')) { + if(!@include(__ARMORYDIRECTORY__ . '/includes/classes/class.search.php')) { die('Error: unable to load search engine class!'); } $search = new SearchMgr($armory); } if(defined('load_itemprototype_class')) { - if(!@include('classes/class.itemprototype.php')) { + if(!@include(__ARMORYDIRECTORY__ . '/includes/classes/class.itemprototype.php')) { die('Error: unable to load ItemPrototype Class!'); } // Do not create class instance here. It should be created in Characters or Items classes. } if(defined('load_item_class')) { - if(!@include('classes/class.item.php')) { + if(!@include(__ARMORYDIRECTORY__ . '/includes/classes/class.item.php')) { die('Error: unable to load Item Class!'); } // Do not create class instance here. It should be created in Characters or Items classes. } // Start XML parser -if(!@include('classes/class.xmlhandler.php')) { +if(!@include(__ARMORYDIRECTORY__ . '/includes/classes/class.xmlhandler.php')) { die('Error: unable to load XML handler class!'); } $xml = new XMLHandler($armory->GetLocale()); diff --git a/includes/classes/class.armory.php b/includes/classes/class.armory.php index f2b4a9533..3403eada6 100644 --- a/includes/classes/class.armory.php +++ b/includes/classes/class.armory.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 366 + * @revision 429 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -67,13 +67,13 @@ * @return bool **/ public function Armory() { - if(!@include('configuration.php')) { + if(!@include(__ARMORYDIRECTORY__ . '/includes/classes/configuration.php')) { die('Error: unable to load configuration file!'); } - if(!@require_once('class.dbhandler.php')) { + if(!@require_once(__ARMORYDIRECTORY__ . '/includes/classes/class.dbhandler.php')) { die('Error: unable to load database class!'); } - if(!@require_once('class.debug.php')) { + if(!@require_once(__ARMORYDIRECTORY__ . '/includes/classes/class.debug.php')) { die('Error: unable to load debug class!'); } $this->mysqlconfig = $ArmoryConfig['mysql']; @@ -84,7 +84,7 @@ public function Armory() { $this->rDB = new ArmoryDatabaseHandler($this->mysqlconfig['host_realmd'], $this->mysqlconfig['user_realmd'], $this->mysqlconfig['pass_realmd'], $this->mysqlconfig['name_realmd'], $this->mysqlconfig['charset_realmd'], $this->Log()); if(isset($_GET['r'])) { if(preg_match('/,/', $_GET['r'])) { - // Achievements/statistics comparison + // Achievements/statistics comparison cases $rData = explode(',', $_GET['r']); $realmName = urldecode($rData[0]); } @@ -150,7 +150,7 @@ public function Armory() { * Checks browser language from HTTP_ACCEPT_LANGUAGE * @category Armory class * @access public - * @return mixed + * @return string **/ private function IsAllowedLocale($locale) { switch($locale) { @@ -161,7 +161,7 @@ private function IsAllowedLocale($locale) { return 'en_gb'; break; case 'es': - return 'es_es'; + return 'es_es'; //es_mx? break; case 'fr': return 'fr_fr'; @@ -170,9 +170,9 @@ private function IsAllowedLocale($locale) { return 'ru_ru'; break; default: - return false; break; } + return null; } /** @@ -212,9 +212,6 @@ public function GetLocale() { * @return int **/ public function GetLoc() { - if($this->_loc == null) { - return 0; - } return $this->_loc; } @@ -222,11 +219,12 @@ public function GetLoc() { * Sets locale * @category Armory class * @access public - * @return int + * @return bool **/ public function SetLocale($locale, $locale_id) { $this->_locale = $locale; $this->_loc = $locale_id; + return true; } } ?> \ No newline at end of file diff --git a/includes/revision_nr.php b/includes/revision_nr.php index fa70e6bb7..5d650b424 100644 --- a/includes/revision_nr.php +++ b/includes/revision_nr.php @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/tools/build_loot_tables.php b/tools/build_loot_tables.php index 9b1e9cfd6..5dbca0b2f 100644 --- a/tools/build_loot_tables.php +++ b/tools/build_loot_tables.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 357 + * @revision 429 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -23,12 +23,11 @@ **/ define('__ARMORY__', true); -if(!@include('../includes/classes/class.armory.php')) { - die('Error: can not load Armory class!'); +define('__ARMORYDIRECTORY__', dirname(dirname(__FILE__))); +if(!@include(__ARMORYDIRECTORY__ . '/includes/classes/class.armory.php')) { + die('Error: unable to load Armory class!'); } - $update_type = 'echo'; // Change to 'echo' to show query in you browser. Or choose 'update' to execute all queries directly to DB. - $armory = new Armory(); echo 'World of Warcraft Armory'; $check_builded = $armory->aDB->selectCell("SELECT `loot_builded` FROM `ARMORYDBPREFIX_db_version`"); diff --git a/tools/create_database_dump.php b/tools/create_database_dump.php index 62372a2ec..1469e45df 100644 --- a/tools/create_database_dump.php +++ b/tools/create_database_dump.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 417 + * @revision 429 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License *