PageRenderTime 57ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/index.php

https://code.google.com/p/mangoswebv3/
PHP | 299 lines | 183 code | 38 blank | 78 comment | 27 complexity | 9644e74e72324dc31bf921df07a76496 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /****************************************************************************/
  3. /* < MangosWeb Enhanced v3 > */
  4. /* Copyright (C) <2009 - 2011> <Wilson212> */
  5. /* < http://keyswow.com > */
  6. /* */
  7. /* Original MangosWeb (C) 2007, Sasha, Nafe, TGM, Peec */
  8. /****************************************************************************/
  9. /***************************************************************
  10. * SET ERROR REPORTING
  11. ***************************************************************/
  12. error_reporting(E_ALL);
  13. ini_set('log_errors', TRUE);
  14. ini_set('html_errors', FALSE);
  15. ini_set('error_log', 'core/logs/error_log.txt');
  16. ini_set('display_errors', TRUE);
  17. /***************************************************************
  18. * Define INCLUDED so we can see if pages are included by this one
  19. ***************************************************************/
  20. define('INCLUDED', TRUE);
  21. /***************************************************************
  22. * Define page loading time start
  23. ***************************************************************/
  24. define('TIME_START', microtime(1));
  25. $_SERVER['REQUEST_TIME'] = time();
  26. /***************************************************************
  27. * Load the Core and Config Classes
  28. ***************************************************************/
  29. include('core/class.config.php');
  30. $Config = new Config;
  31. include('core/core.php');
  32. $Core = new Core;
  33. /***************************************************************
  34. * Show Site Notice if enabled in config, and user cookie not set
  35. ***************************************************************/
  36. if($Config->get('site_notice_enable') == 1 && !isset($_COOKIE['agreement_accepted']))
  37. {
  38. include('modules/notice/notice.php');
  39. exit();
  40. }
  41. /***************************************************************
  42. * See if the site is installed by checking config defualts
  43. ***************************************************************/
  44. if($Config->getDbInfo('db_username') == 'default')
  45. {
  46. header('location: install/');
  47. }
  48. /***************************************************************
  49. * Include the site functions and classes
  50. ***************************************************************/
  51. include('core/common.php'); // Holds most of the sites common functions
  52. include('core/class.template.php'); // Sets up the template system
  53. include('core/SDL/class.account.php'); // contains account related scripts and functions
  54. /***************************************************************
  55. * Set the site globals, selected realm, language etc etc
  56. ***************************************************************/
  57. $Core->setGlobals();
  58. // Load language file
  59. include('lang/' . $GLOBALS["user_cur_lang"] . '/common.php');
  60. /***************************************************************
  61. * Setup the Database class and Database connections
  62. ***************************************************************/
  63. require ('core/class.database.php');
  64. $DB = new Database(
  65. $Config->getDbInfo('db_host'),
  66. $Config->getDbInfo('db_port'),
  67. $Config->getDbInfo('db_username'),
  68. $Config->getDbInfo('db_password'),
  69. $Config->getDbInfo('db_name')
  70. );
  71. // Check the database status. 0 = cannot connect, 1 = success, 2 = DB doesnt exist
  72. if($DB->status() != 1)
  73. {
  74. echo "Cannot connect to the Realm database. Please make sure you have run the installer to properly set the DB info in the database.";
  75. die();
  76. }
  77. // Make an array from `dbinfo` column for the selected realm..
  78. $DB_info = $DB->selectRow("SELECT * FROM realmlist WHERE id='".$GLOBALS['cur_selected_realm']."'");
  79. $dbinfo = explode(';', $DB_info['dbinfo']);
  80. // DBinfo column: char_host;char_port;char_username;char_password;charDBname;
  81. // world_host;world_port;world_username;world_pass;worldDBname
  82. $Realm_DB_Info = array(
  83. 'char_db_host' => $dbinfo['0'], // char host
  84. 'char_db_port' => $dbinfo['1'], // char port
  85. 'char_db_username' => $dbinfo['2'], // char user
  86. 'char_db_password' => $dbinfo['3'], // char password
  87. 'char_db_name' => $dbinfo['4'], //char db name
  88. 'w_db_host' => $dbinfo['5'], // world host
  89. 'w_db_port' => $dbinfo['6'], // world port
  90. 'w_db_username' => $dbinfo['7'], // world user
  91. 'w_db_password' => $dbinfo['8'], // world password
  92. 'w_db_name' => $dbinfo['9'], // world db name
  93. );
  94. // Free up memory.
  95. unset($dbinfo, $DB_info);
  96. // === Establish the Character DB connection === //
  97. $CDB = new Database(
  98. $Realm_DB_Info['char_db_host'],
  99. $Realm_DB_Info['char_db_port'],
  100. $Realm_DB_Info['char_db_username'],
  101. $Realm_DB_Info['char_db_password'],
  102. $Realm_DB_Info['char_db_name']
  103. );
  104. // Check the CDB status. 0 = cannot connect, 1 = success, 2 = DB doesnt exist
  105. if($CDB->status() != 1)
  106. {
  107. echo "Cannot connect to the Character database. Please make sure you have this realm setup successfully in the Admin Panel.
  108. Delete your cookies to reset realm selection back to default";
  109. die();
  110. }
  111. // === Establish the World DB connection === //
  112. $WDB = new Database(
  113. $Realm_DB_Info['w_db_host'],
  114. $Realm_DB_Info['w_db_port'],
  115. $Realm_DB_Info['w_db_username'],
  116. $Realm_DB_Info['w_db_password'],
  117. $Realm_DB_Info['w_db_name']
  118. );
  119. // Check the CDB status. 0 = cannot connect, 1 = success, 2 = DB doesnt exist
  120. if($WDB->status() != 1)
  121. {
  122. echo "Cannot connect to the World database. Please make sure you have this realm setup successfully in the Admin Panel.
  123. Delete your cookies to reset realm selection back to default";
  124. die();
  125. }
  126. // Free up memory
  127. unset($Realm_DB_Info);
  128. /***************************************************************
  129. * Load the Account / Auth Class
  130. ***************************************************************/
  131. $Account = new Account();
  132. $user = $Account->user;
  133. $user['cur_selected_realm'] = $GLOBALS['cur_selected_realm'];
  134. /***************************************************************
  135. * Load the Template class and setup the template system
  136. ***************************************************************/
  137. $Template = new MangosTemplate;
  138. // Lets get the template information
  139. $Template = $Template->loadTemplateXML();
  140. if($Template == FALSE)
  141. {
  142. echo "Fetal Error: Template XML Not Found!";
  143. die();
  144. }
  145. /***************************************************************
  146. * Start of page loading
  147. ***************************************************************/
  148. // Start off by checking if the requested page is a module or not
  149. if(!isset($_GET['p']) && isset($_GET['module']))
  150. {
  151. // Scan the directory for installed modules to prevent XSS
  152. $Modulelist = scandir("modules/");
  153. if(in_array($_GET['module'], $Modulelist))
  154. {
  155. include("modules/".$_GET['module']."/module.php");
  156. }
  157. else
  158. {
  159. echo "No Module of that name found!";
  160. }
  161. }
  162. // If page is not a module, then lets load our template pages.
  163. else
  164. {
  165. // if empty page, then load default component(frontpage)
  166. $ext = (isset($_GET['p']) ? $_GET['p'] : (string)$Config->get('default_component'));
  167. // If url looks like so: ?p=account/login (This is a avalid url)
  168. if(strpos($ext, '/') !== FALSE)
  169. {
  170. list($ext, $sub) = explode('/', $ext);
  171. }
  172. else
  173. {
  174. // If empty sub page, load page.index.php
  175. $sub = (isset($_GET['sub']) ? $_GET['sub'] : 'index');
  176. }
  177. $script_file = 'inc/' . $ext . '/' . $ext . '.' . $sub . '.php';
  178. $template_file = $Template['script_path'] . '/' . $ext . '/' . $ext . '.' . $sub . '.php';
  179. // === Start Loading of the Page files === //
  180. // If the requested page is the admin Panel, then we load the admin template
  181. if($ext == 'admin')
  182. {
  183. if(file_exists('inc/admin/body_functions.php'))
  184. {
  185. include('inc/admin/body_functions.php');
  186. }
  187. @include('inc/admin/script_files/admin.' . $sub .'.php');
  188. ob_start();
  189. include('inc/admin/body_header.php');
  190. ob_end_flush();
  191. ob_start();
  192. include('inc/admin/template_files/admin.' . $sub .'.php');
  193. ob_end_flush();
  194. // Set our time end, so we can see how fast the page loaded.
  195. define('TIME_END', microtime(1));
  196. define('PAGE_LOAD_TIME', TIME_END - TIME_START);
  197. include('inc/admin/body_footer.php');
  198. }
  199. // Else, if requested page isnt the admin panel, then load the template
  200. else
  201. {
  202. // Start Loading Of Script Files
  203. @include($script_file);
  204. // If a body functions file exists, include it.
  205. if(file_exists($Template['functions']))
  206. {
  207. include($Template['functions']);
  208. }
  209. ob_start();
  210. include($Template['header']);
  211. ob_end_flush();
  212. // === Start the loading of the template cache === //
  213. // Lets check to see if the page is flagged to cache or not. defined in scriptfile of each page
  214. if(defined('CACHE_FILE'))
  215. {
  216. $CacheFile = CACHE_FILE;
  217. }
  218. else # Not defined
  219. {
  220. $CacheFile = FALSE;
  221. }
  222. // Check if admin has enabled caching, and CACHE_FILE is enabled
  223. if($Config->get('enable_cache') && $CacheFile == TRUE)
  224. {
  225. // If file is cached
  226. if($Core->isCached($Template['number']."_".$ext.".".$sub."_".$GLOBALS['user_cur_lang']))
  227. {
  228. $Contents = $Core->getCache($Template['number']."_".$ext.".".$sub."_".$GLOBALS['user_cur_lang']);
  229. echo $Contents;
  230. }
  231. // If not cached, then get contents of the page and cache them.
  232. else
  233. {
  234. ob_start();
  235. include($template_file);
  236. $Contents = ob_get_flush();
  237. $Core->writeCache($Template['number']."_".$ext.".".$sub."_".$GLOBALS['user_cur_lang'], $Contents);
  238. }
  239. unset($Contents);
  240. }
  241. else
  242. {
  243. ob_start();
  244. include($template_file);
  245. ob_end_flush();
  246. }
  247. // === End cache system, Load the footer === //
  248. // Set our time end, so we can see how fast the page loaded.
  249. define('TIME_END', microtime(1));
  250. define('PAGE_LOAD_TIME', TIME_END - TIME_START);
  251. include($Template['footer']);
  252. }
  253. }
  254. /***************************************************************
  255. * End Page Loading
  256. ***************************************************************/
  257. // Close all DB Connections
  258. $DB->__destruct();
  259. $CDB->__destruct();
  260. $WDB->__destruct();
  261. ?>