PageRenderTime 63ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/index.php

https://code.google.com/p/mwenhanced/
PHP | 421 lines | 302 code | 48 blank | 71 comment | 68 complexity | 019a2d1a6fa22869bee55e309c5b29c2 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0, AGPL-1.0, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /****************************************************************************/
  3. /* < MangosWeb is a Web-Fonted for Mangos (mangosproject.org) > */
  4. /* Copyright (C) <2007> <Sasha,TGM,Peec,Nafe> */
  5. /* */
  6. /* MangosWeb Enhanced made by <Wilson212,Ionstorm66> <2009-2010> */
  7. /* < http://code.google.com/p/mwenhanced/ > */
  8. /* */
  9. /* This program is free software: you can redistribute it and/or modify */
  10. /* it under the terms of the GNU General Public License as published by */
  11. /* the Free Software Foundation, either version 2 of the License, or */
  12. /* (at your option) any later version. */
  13. /* */
  14. /* This program is distributed in the hope that it will be useful, */
  15. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  16. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  17. /* GNU General Public License for more details. */
  18. /* */
  19. /* You should have received a copy of the GNU General Public License */
  20. /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
  21. /* */
  22. /* $Rev$ */
  23. /****************************************************************************/
  24. // Current Revision format is: version.revision
  25. $rev = "2.11";
  26. // Set error reporting to only a few things.
  27. ini_set('error_reporting', E_ERROR ^ E_NOTICE ^ E_WARNING);
  28. error_reporting(E_ERROR ^ E_NOTICE ^ E_WARNING);
  29. ini_set('log_errors',TRUE);
  30. ini_set('html_errors',FALSE);
  31. ini_set('error_log','core/logs/error_log.txt');
  32. ini_set('display_errors',FALSE);
  33. // Define INCLUDED so that we can check other pages if they are included by this file
  34. define( 'INCLUDED', true ) ;
  35. // Start a variable that shows how fast page loaded.
  36. $time_start = microtime( 1 ) ;
  37. $_SERVER['REQUEST_TIME'] = time() ;
  38. // Initialize config files and set sites super global.
  39. include ( 'core/class.mangosweb.php' ) ;
  40. $MW = new mangosweb ; // Super global.
  41. // Get current emulator project
  42. $project = $MW->getEmu;
  43. // Site functions & classes ...
  44. include ( 'core/common.php' ) ; // Holds most of the sites functions
  45. include ( 'core/mangos.class.php' ) ; // Constructs player info, zone info, and also holds donate, and guid functions
  46. include ( 'core/class.auth.php' ) ; // contains account related scripts and functions
  47. require_once ( 'core/dbsimple/Generic.php' ) ; // sets up DB simple
  48. require ( 'core/class.captcha.php' ) ; // Contains image verification scripts
  49. include ( 'core/cache_class/safeIO.php' ) ; // Part of the cache system
  50. include ( 'core/cache_class/gCache.php' ) ; // Also part of the cache system
  51. //Site notice cookie
  52. if ( file_exists( "ToS.html" ) && ! isset( $_COOKIE['agreement_accepted'] ) )
  53. {
  54. include ( 'notice.php' ) ;
  55. exit() ;
  56. }
  57. // Inizialize difrent variables.
  58. global $MW, $mangos ;
  59. // Super-Global variables.
  60. $GLOBALS['users_online'] = array() ;
  61. $GLOBALS['guests_online'] = 0 ;
  62. $GLOBALS['messages'] = '' ;
  63. $GLOBALS['redirect'] = '' ;
  64. $GLOBALS['sidebarmessages'] = '' ;
  65. $GLOBALS['context_menu'] = array() ;
  66. $GLOBALS['user_cur_lang'] = ( string )$MW->getConfig->generic->default_lang ;
  67. // Inzizalize Cache class
  68. $cache = new gCache ;
  69. $cache->folder = './core/cache/sites' ;
  70. $cache->timeout = $MW->getConfig->generic->cache_expiretime ;
  71. // Assign a connect variable to class call.
  72. // DB layer documentation at http://en.dklab.ru/lib/DbSimple/
  73. $DB = dbsimple_Generic::connect( "" . $MW->getDbInfo['db_type'] . "://" . $MW->getDbInfo['db_username'] .
  74. ":" . $MW->getDbInfo['db_password'] . "@" . $MW->getDbInfo['db_host'] . ":" . $MW->getDbInfo['db_port'] .
  75. "/" . $MW->getDbInfo['db_name'] . "" ) ;
  76. // Set error handler for $DB.
  77. $DB->setErrorHandler( 'databaseErrorHandler' ) ;
  78. // Also set to default encoding for $DB
  79. $DB->query( "SET NAMES " . $MW->getDbInfo['db_encoding'] ) ;
  80. // Play arround for IIS lake on $_SERVER['REQUEST_URI']
  81. if ( $_SERVER['REQUEST_URI'] == "" )
  82. {
  83. if ( $_SERVER['QUERY_STRING'] != "" )
  84. {
  85. $__SERVER['REQUEST_URI'] = $_SERVER["SCRIPT_NAME"] . "?" . $_SERVER['QUERY_STRING'] ;
  86. } else
  87. {
  88. $__SERVER['REQUEST_URI'] = $_SERVER["SCRIPT_NAME"] ;
  89. }
  90. } else
  91. {
  92. $__SERVER['REQUEST_URI'] = $_SERVER['REQUEST_URI'] ;
  93. }
  94. // Build path vars //
  95. $MW->add_temp_confs( array( 'site_href' => str_replace( '//', '/', str_replace( '\\',
  96. '/', dirname( $_SERVER['SCRIPT_NAME'] ) . '/' ) ) ) ) ;
  97. $MW->add_temp_confs( array( 'site_domain' => $_SERVER['HTTP_HOST'], 'email_href' =>
  98. $_SERVER['HTTP_HOST'] ) ) ;
  99. $MW->add_temp_confs( array( 'base_href' => 'http://' . $MW->getConfig->temp->email_href .
  100. '' . $MW->getConfig->temp->site_href, ) ) ;
  101. // Check lang ======================================
  102. if ( isset( $_COOKIE['Language'] ) )
  103. $GLOBALS['user_cur_lang'] = $_COOKIE['Language'] ;
  104. loadLanguages() ;
  105. // ================================================
  106. // Load auth system //
  107. $auth = new AUTH( $DB, $MW->getConfig ) ;
  108. $user = $auth->user ;
  109. // ================== //
  110. //Determine Current Template
  111. if ( $user['id'] == -1 ) {
  112. $currtmp = "templates/".( string ) $MW->getConfig->generic->default_template;
  113. }else{
  114. $currtmp = $DB->selectCell( "SELECT theme FROM `account_extend` WHERE account_id=?d",
  115. $user['id'] ) ;
  116. foreach ( $MW->getConfig->templates->template as $template ) {
  117. $currtmp2[] = $template ;
  118. }
  119. $currtmp = "templates/" . $currtmp2[$currtmp] ;
  120. // If persons current template is no longer available, this resets his template to default
  121. if($currtmp == "templates/"){
  122. $currtmp = "templates/".( string ) $MW->getConfig->generic->default_template;
  123. $DB->query( "UPDATE `account_extend` SET `theme`='0' WHERE `account_id`=?d",$user['id'] );
  124. }
  125. }
  126. // Load page files for the new Advanced Template System if enabled
  127. if ((int)$MW->getConfig->template_system->enable == 1){
  128. include('' . $currtmp . '/include.php');
  129. if(!$pagefiles) {
  130. echo "This template does not have the required \"include.php\" in the \"" . $currtmp . " /\" root folder. In order to continue,
  131. read the avanced_template_readme.txt";
  132. exit;
  133. }else{
  134. $offtmp = "templates/" . $pagefiles;
  135. }
  136. }else{
  137. $offtmp = "templates/" . ( string ) $MW->getConfig->generic->template;
  138. }
  139. // Load Permissions and aviable sites.
  140. include ( 'core/default_components.php' ) ;
  141. // Start of context menu. ( Only make an array for later output )
  142. $GLOBALS['context_menu'][] = array( 'title' => $lang['mainpage'], 'link' =>
  143. 'index.php' ) ;
  144. if ( $user['id'] <= 0 )
  145. {
  146. $GLOBALS['context_menu'][] = array( 'title' => $lang['register'], 'link' =>
  147. mw_url( 'account', 'register' ) ) ;
  148. }
  149. $GLOBALS['context_menu'][] = array( 'title' => 'Forum', 'link' =>
  150. 'index.php?n=forum' ) ;
  151. $GLOBALS['context_menu'][] = array( 'title' => $lang['players_online'], 'link' =>
  152. mw_url( 'server', 'playersonline' ) ) ;
  153. if ( ( isset( $user['g_is_admin'] ) || isset( $user['g_is_supadmin'] ) ) && ( $user['g_is_admin'] ==
  154. 1 || $user['g_is_supadmin'] == 1 ) )
  155. {
  156. $allowed_ext[] = 'admin' ;
  157. $GLOBALS['context_menu'][] = array( 'title' => '------------------', 'link' =>
  158. '#' ) ;
  159. $GLOBALS['context_menu'][] = array( 'title' => $lang['admin_panel'], 'link' =>
  160. 'index.php?n=admin' ) ;
  161. }
  162. // for mod_rewrite query_string fix //
  163. global $_GETVARS ;
  164. $req_vars = parse_url( $__SERVER['REQUEST_URI'] ) ;
  165. if ( isset( $req_vars['query'] ) )
  166. {
  167. parse_str( $req_vars['query'], $req_arr ) ;
  168. $_GETVARS = $req_arr ;
  169. }
  170. unset( $req_arr, $req_vars ) ;
  171. // ======================================================= //
  172. // Finds out what realm we are viewing.
  173. if ( ( int )$MW->getConfig->generic_values->realm_info->multirealm && isset( $_REQUEST['changerealm_to'] ) )
  174. {
  175. setcookie( "cur_selected_realmd", intval( $_REQUEST['changerealm_to'] ), time() +
  176. ( 3600 * 24 ) ) ; // expire in 24 hour
  177. $user['cur_selected_realmd'] = intval( $_REQUEST['changerealm_to'] ) ;
  178. } elseif ( ( int )$MW->getConfig->generic_values->realm_info->multirealm && isset
  179. ( $_COOKIE['cur_selected_realmd'] ) )
  180. {
  181. $user['cur_selected_realmd'] = intval( $_COOKIE['cur_selected_realmd'] ) ;
  182. } else
  183. {
  184. $user['cur_selected_realmd'] = ( int )$MW->getConfig->generic_values->realm_info->default_realm_id ;
  185. setcookie( "cur_selected_realmd", $user['cur_selected_realmd'], time() + ( 3600 *
  186. 24 ) ) ;
  187. }
  188. // Make an array from `dbinfo` column for the selected realm..
  189. $mangos_info = $DB->selectCell( "SELECT dbinfo FROM `realmlist` WHERE id=?d", $user['cur_selected_realmd'] ) ;
  190. $dbinfo_mangos = explode( ';', $mangos_info ) ;
  191. //DBinfo column: username;password;port;host;WorldDBname;CharDBname
  192. $mangos = array( 'db_type' => 'mysql', 'db_host' => $dbinfo_mangos['3'],
  193. //ip of db world
  194. 'db_port' => $dbinfo_mangos['2'], //port
  195. 'db_username' => $dbinfo_mangos['0'], //world user
  196. 'db_password' => $dbinfo_mangos['1'], //world password
  197. 'db_name' => $dbinfo_mangos['4'], //world db name
  198. 'db_char' => $dbinfo_mangos['5'], //character db name
  199. 'db_encoding' => 'utf8', // don't change
  200. ) ;
  201. unset( $dbinfo_mangos, $mangos_info ) ; // Free up memory.
  202. if ( ( int )$MW->getConfig->generic->use_alternate_mangosdb_port )
  203. {
  204. $mangos['db_port'] = ( int )$MW->getConfig->generic->use_alternate_mangosdb_port ;
  205. }
  206. // Connects to WORLD DB
  207. $WSDB = DbSimple_Generic::connect( "" . $mangos['db_type'] . "://" . $mangos['db_username'] .
  208. ":" . $mangos['db_password'] . "@" . $mangos['db_host'] . ":" . $mangos['db_port'] .
  209. "/" . $mangos['db_name'] . "" ) ;
  210. if ( $WSDB )
  211. $WSDB->setErrorHandler( 'databaseErrorHandler' ) ;
  212. if ( $WSDB )
  213. $WSDB->query( "SET NAMES " . $mangos['db_encoding'] ) ;
  214. // Connects to CHARACTERS DB
  215. $CHDB = DbSimple_Generic::connect( "" . $mangos['db_type'] . "://" . $mangos['db_username'] .
  216. ":" . $mangos['db_password'] . "@" . $mangos['db_host'] . ":" . $mangos['db_port'] .
  217. "/" . $mangos['db_char'] . "" ) ;
  218. if ( $CHDB )
  219. $CHDB->setErrorHandler( 'databaseErrorHandler' ) ;
  220. if ( $CHDB )
  221. $CHDB->query( "SET NAMES " . $mangos['db_encoding'] ) ;
  222. //Load characters list
  223. if ( isset( $user['id'] ) && $user['id'] > 0 )
  224. {
  225. $characters = $CHDB->select( 'SELECT guid,name FROM `characters` WHERE account=?d',
  226. $user['id'] ) ;
  227. if ( isset( $_COOKIE['cur_selected_character'] ) )
  228. {
  229. foreach ( $characters as $character )
  230. {
  231. if ( $character['guid'] == $_COOKIE['cur_selected_character'] )
  232. {
  233. $DB->query( 'UPDATE account_extend SET character_id=?d,character_name=? WHERE account_id=?d',
  234. $character['guid'], $character['name'], $user['id'] ) ;
  235. }
  236. }
  237. }
  238. } else
  239. {
  240. $characters = array() ;
  241. }
  242. if ( empty( $_GET['p'] ) or $_GET['p'] < 1 )
  243. $p = 1 ;
  244. else
  245. $p = $_GET['p'] ;
  246. $ext = ( isset( $_REQUEST['n'] ) ? $_REQUEST['n'] : ( string )$MW->getConfig->generic->default_component ) ;
  247. if ( strpos( $ext, '/' ) !== false )
  248. list( $ext, $sub ) = explode( '/', $ext ) ;
  249. else
  250. $sub = ( isset( $_REQUEST['sub'] ) ? $_REQUEST['sub'] : 'index' ) ;
  251. $req_tpl = false ;
  252. //initialize modules
  253. //if installing a new module, please delete the cache file
  254. include ( 'components/modules/initialize.php' ) ;
  255. if ( in_array( $ext, $allowed_ext ) )
  256. {
  257. // load component
  258. //set defaults here to be loaded -- these can be changed via the main.php or whatnot
  259. //this is used especially in the case of the module system
  260. $script_file = 'components/' . $ext . '/' . $ext . '.' . $sub . '.php' ;
  261. $template_file = '' . $offtmp .
  262. '/' . $ext . '/' . $ext . '.' . $sub . '.php' ;
  263. require ( 'components/' . $ext . '/' . 'main.php' ) ;
  264. $group_privilege = $com_content[$ext][$sub][0] ;
  265. $expectation = ( substr( $group_privilege, 0, 1 ) == '!' ) ? 0 : 1 ;
  266. if ( $expectation == 0 )
  267. $group_privilege = substr( $group_privilege, 1 ) ;
  268. if ( $group_privilege && $user[$group_privilege] != $expectation )
  269. exit( '<h2>Forbidden</h2><meta http-equiv=refresh content="3;url=\'./\'">' ) ;
  270. // ==================== //
  271. if ( isset( $_REQUEST['n'] ) && isset( $lang[$com_content[$ext]['index'][1]] ) )
  272. $pathway_info[] = array( 'title' => $lang[$com_content[$ext]['index'][1]],
  273. 'link' => $com_content[$ext]['index'][2] ) ;
  274. // ==================== //
  275. foreach ( $com_content[( string )$ext] as $sub_name => $sub_conf )
  276. {
  277. if ( $sub_conf[4] == 1 )
  278. {
  279. if ( $sub_conf[0] )
  280. {
  281. if ( $user[$sub_conf[0]] == 1 )
  282. {
  283. $GLOBALS['context_menu'][] = array( 'title' => ( isset( $lang[$sub_conf[1]] ) ?
  284. $lang[$sub_conf[1]] : '??title??' ), 'link' => ( isset( $sub_conf[2] ) ? $sub_conf[2] :
  285. '?link?' ) ) ;
  286. }
  287. } else
  288. {
  289. if ( isset( $lang[$sub_conf[1]] ) )
  290. $GLOBALS['context_menu'][] = array( 'title' => $lang[$sub_conf[1]], 'link' => $sub_conf[2] ) ;
  291. }
  292. }
  293. }
  294. if ( $sub )
  295. {
  296. if ( $com_content[$ext][$sub] )
  297. {
  298. if ( $com_content[$ext][$sub][0] )
  299. {
  300. if ( $user[$com_content[$ext][$sub][0]] == 1 )
  301. {
  302. $req_tpl = true ;
  303. @include ( $script_file ) ;
  304. }
  305. } else
  306. {
  307. $req_tpl = true ;
  308. @include ( $script_file ) ;
  309. }
  310. }
  311. }
  312. if ( empty( $_GET['nobody'] ) )
  313. {
  314. // DEBUG //
  315. if ( ( int )$MW->getConfig->generic->debuginfo )
  316. {
  317. output_message( 'debug', 'DEBUG://' . $DB->_statistics['count'] ) ;
  318. output_message( 'debug', '<pre>' . print_r( $_SERVER, true ) . '</pre>' ) ;
  319. }
  320. // =======//
  321. // Start Loading Of Template Files
  322. include ( '' . $offtmp . '/body_functions.php' );
  323. ob_start() ;
  324. include ( '' . $offtmp . '/body_header.php' );
  325. ob_end_flush() ;
  326. if ( $req_tpl )
  327. {
  328. if ( file_exists( $template_file ) )
  329. {
  330. // Only cache if user is not logged in.
  331. if ( $user['id'] < 0 && ( int )$MW->getConfig->generic->cache_expiretime != 0 )
  332. {
  333. // Start caching process But we want to exclude some cases.
  334. if ( isset( $_REQUEST['n'] ) && $_REQUEST['n'] != 'account' )
  335. {
  336. $cache->contentId = md5( 'CONTENT' . $_SERVER['REQUEST_URI'] ) ;
  337. if ( $cache->Valid() )
  338. {
  339. echo $cache->content ;
  340. } else
  341. {
  342. $cache->capture() ;
  343. include ( $template_file ) ;
  344. $cache->endcapture() ;
  345. }
  346. } else
  347. {
  348. include ( $template_file ) ;
  349. }
  350. } else
  351. {
  352. // Create output buffer
  353. ob_start() ;
  354. include ( $template_file ) ;
  355. ob_end_flush() ;
  356. }
  357. }
  358. }
  359. $time_end = microtime( 1 ) ;
  360. $exec_time = $time_end - $time_start ;
  361. include ( '' . $offtmp . '/body_footer.php' ) ;
  362. //include ( 'templates/' . $templatefiles . '/body_footer.php' ) ; NOTE: for future template system
  363. } else
  364. {
  365. if ( file_exists( $template_file ) )
  366. {
  367. include ( $template_file ) ;
  368. }
  369. }
  370. }else{
  371. echo '<h2>Forbidden</h2><meta http-equiv=refresh content="3;url=\'./\'">' ;
  372. }
  373. ?>