PageRenderTime 55ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/common.php

https://gitlab.com/phpbb3_ppkbb3cker_edition/phpbb3_ppkbb3cker_edition
PHP | 308 lines | 221 code | 46 blank | 41 comment | 55 complexity | 3cf085851dc990f4296cf04c442f64ae MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package phpBB3
  5. * @version $Id$
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. * Minimum Requirement: PHP 4.3.3
  10. */
  11. /**
  12. */
  13. if (!defined('IN_PHPBB'))
  14. {
  15. exit;
  16. }
  17. require($phpbb_root_path . 'includes/startup.' . $phpEx);
  18. if (file_exists($phpbb_root_path . 'config.' . $phpEx))
  19. {
  20. require($phpbb_root_path . 'config.' . $phpEx);
  21. }
  22. if (!defined('PHPBB_INSTALLED'))
  23. {
  24. // Redirect the user to the installer
  25. require($phpbb_root_path . 'includes/functions.' . $phpEx);
  26. // We have to generate a full HTTP/1.1 header here since we can't guarantee to have any of the information
  27. // available as used by the redirect function
  28. $server_name = (!empty($_SERVER['HTTP_HOST'])) ? strtolower($_SERVER['HTTP_HOST']) : ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME'));
  29. $server_port = (!empty($_SERVER['SERVER_PORT'])) ? (int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT');
  30. $secure = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 1 : 0;
  31. $script_name = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF');
  32. if (!$script_name)
  33. {
  34. $script_name = (!empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI');
  35. }
  36. // $phpbb_root_path accounts for redirects from e.g. /adm
  37. $script_path = trim(dirname($script_name)) . '/' . $phpbb_root_path . 'install/index.' . $phpEx;
  38. // Replace any number of consecutive backslashes and/or slashes with a single slash
  39. // (could happen on some proxy setups and/or Windows servers)
  40. $script_path = preg_replace('#[\\\\/]{2,}#', '/', $script_path);
  41. // Eliminate . and .. from the path
  42. $script_path = phpbb_clean_path($script_path);
  43. $url = (($secure) ? 'https://' : 'http://') . $server_name;
  44. if ($server_port && (($secure && $server_port <> 443) || (!$secure && $server_port <> 80)))
  45. {
  46. // HTTP HOST can carry a port number...
  47. if (strpos($server_name, ':') === false)
  48. {
  49. $url .= ':' . $server_port;
  50. }
  51. }
  52. $url .= $script_path;
  53. header('Location: ' . $url);
  54. exit;
  55. }
  56. if (defined('DEBUG_EXTRA'))
  57. {
  58. $base_memory_usage = 0;
  59. if (function_exists('memory_get_usage'))
  60. {
  61. $base_memory_usage = memory_get_usage();
  62. }
  63. }
  64. // Load Extensions
  65. // dl() is deprecated and disabled by default as of PHP 5.3.
  66. if (!empty($load_extensions) && function_exists('dl'))
  67. {
  68. $load_extensions = explode(',', $load_extensions);
  69. foreach ($load_extensions as $extension)
  70. {
  71. @dl(trim($extension));
  72. }
  73. }
  74. if(@file_exists($phpbb_root_path.'cache/data_cgp_extreme.'.$phpEx) && !isset($_GET['style']) && !isset($_GET['ap']) && !isset($_GET['np']))
  75. {
  76. $cgp_configs=@file($phpbb_root_path.'cache/data_cgp_extreme.'.$phpEx);
  77. if(isset($cgp_configs[3]))
  78. {
  79. $cgp_configs=unserialize($cgp_configs[3]);
  80. $current_page=basename($_SERVER['SCRIPT_NAME']);
  81. $cgp_pages=array("portal.{$phpEx}", "index.{$phpEx}", "viewforum.{$phpEx}", "viewtopic.{$phpEx}");
  82. $cgp_pages_alias=array("portal.{$phpEx}"=>'portal', "index.{$phpEx}"=>'index', "viewforum.{$phpEx}"=>'vf', "viewtopic.{$phpEx}"=>'vt');
  83. $cgp_places=explode(' ', $cgp_configs['cgp_places']);
  84. $cgp_place_num=array('portal' => 0, 'index' => 1, 'vf' => 2, 'vt' => 3);
  85. if(in_array($current_page, $cgp_pages) && !$cgp_places[$cgp_place_num[$cgp_pages_alias[$current_page]]])
  86. {
  87. if(isset($_GET['sid']))
  88. {
  89. $cgp_user='user';
  90. }
  91. else if(isset($_COOKIE[$cgp_configs['cookie_name'].'_u']))
  92. {
  93. if($_COOKIE[$cgp_configs['cookie_name'].'_u']==1)
  94. {
  95. $cgp_user='guest';
  96. }
  97. else
  98. {
  99. $cgp_user='user';
  100. }
  101. }
  102. else
  103. {
  104. $cookietime=time() + 86400*30;
  105. $name_data = rawurlencode($cgp_configs['cookie_name'].'_u') . '=' . rawurlencode(1);
  106. $expire = gmdate('D, d-M-Y H:i:s \\G\\M\\T', $cookietime);
  107. $domain = (!$cgp_configs['cookie_domain'] || $cgp_configs['cookie_domain'] == 'localhost' || $cgp_configs['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $cgp_configs['cookie_domain'];
  108. header('Set-Cookie: ' . $name_data . (($cookietime) ? '; expires=' . $expire : '') . '; path=' . $cgp_configs['cookie_path'] . $domain . ((!$cgp_configs['cookie_secure']) ? '' : '; secure') . '; HttpOnly', false);
  109. $cgp_user='bot';
  110. }
  111. if(in_array($cgp_user, array('guest', 'bot')))
  112. {
  113. $cgp_start=isset($_GET['start']) ? intval($_GET['start']) : 0;
  114. $cgp_forum=isset($_GET['f']) ? intval($_GET['f']) : 0;
  115. $cgp_topic=isset($_GET['t']) ? intval($_GET['t']) : 0;
  116. if($cgp_configs['cgp_multi_styles'])
  117. {
  118. $cgp_style=isset($_COOKIE[$cgp_configs['cookie_name'].'_style']) ? intval($_COOKIE[$cgp_configs['cookie_name'].'_style']) : $cgp_configs['default_style'];
  119. }
  120. else
  121. {
  122. $cgp_style=0;
  123. }
  124. switch($cgp_pages_alias[$current_page])
  125. {
  126. case 'portal':
  127. $cgp_page="data_portal_".($cgp_style ? "st{$cgp_style}_" : '')."{$cgp_user}.{$phpEx}";
  128. break;
  129. case 'index':
  130. $cgp_page="data_index_".($cgp_style ? "st{$cgp_style}_" : '')."{$cgp_user}.{$phpEx}";
  131. break;
  132. case 'vf':
  133. $cgp_page="data_vf_f{$cgp_forum}_s{$cgp_start}_".($cgp_style ? "st{$cgp_style}_" : '')."{$cgp_user}.{$phpEx}";
  134. break;
  135. case 'vt':
  136. $cgp_page="data_vt_t{$cgp_topic}_s{$cgp_start}_".($cgp_style ? "st{$cgp_style}_" : '')."{$cgp_user}.{$phpEx}";
  137. break;
  138. }
  139. if(@file_exists("{$phpbb_root_path}cache/{$cgp_page}"))
  140. {
  141. $file="{$phpbb_root_path}cache/{$cgp_page}";
  142. if (!($handle = @fopen($file, 'rb')))
  143. {
  144. return false;
  145. }
  146. // Skip the PHP header
  147. fgets($handle);
  148. $data = false;
  149. $line = 0;
  150. while (($buffer = fgets($handle)) && !feof($handle))
  151. {
  152. $buffer = substr($buffer, 0, -1); // Remove the LF
  153. // $buffer is only used to read integers
  154. // if it is non numeric we have an invalid
  155. // cache file, which we will now remove.
  156. if (!is_numeric($buffer))
  157. {
  158. break;
  159. }
  160. if ($line == 0)
  161. {
  162. $expires = (int) $buffer;
  163. if (time() >= $expires)
  164. {
  165. break;
  166. }
  167. }
  168. else if ($line == 1)
  169. {
  170. $bytes = (int) $buffer;
  171. // Never should have 0 bytes
  172. if (!$bytes)
  173. {
  174. break;
  175. }
  176. // Grab the serialized data
  177. $data = fread($handle, $bytes);
  178. // Read 1 byte, to trigger EOF
  179. fread($handle, 1);
  180. if (!feof($handle))
  181. {
  182. // Somebody tampered with our data
  183. $data = false;
  184. }
  185. break;
  186. }
  187. else
  188. {
  189. // Something went wrong
  190. break;
  191. }
  192. $line++;
  193. }
  194. fclose($handle);
  195. if($data!==false)
  196. {
  197. // unserialize if we got some data
  198. $data = @unserialize($data);
  199. if (defined('DEBUG'))
  200. {
  201. $mtime = explode(' ', microtime());
  202. $totaltime = $mtime[0] + $mtime[1] - $starttime;
  203. $debug_output = sprintf('<br />CGP [Extreme] output time : %.5fs | 0 Queries | GZIP : ' . (($cgp_configs['gzip_compress'] && @extension_loaded('zlib')) ? 'On' : 'Off'), $totaltime);
  204. $data = str_replace('<!-- CGP DEBUG OUTPUT -->', $debug_output, $data);
  205. }
  206. header('Content-type: text/html; charset=UTF-8');
  207. header('Cache-Control: public, no-cache="set-cookie"');
  208. header('Pragma: public');
  209. header('ETag: ' . $expires);
  210. // gzip_compression (copied from page_header() )
  211. if ($cgp_configs['gzip_compress'])
  212. {
  213. if (@extension_loaded('zlib') && !headers_sent() && ob_get_level() <= 1 && ob_get_length() == 0)
  214. {
  215. ob_start('ob_gzhandler');
  216. }
  217. }
  218. echo $data;
  219. (ob_get_level() > 0) ? @ob_flush() : @flush();
  220. exit();
  221. }
  222. }
  223. }
  224. }
  225. }
  226. //include_once($phpbb_root_path.'tracker/include/cgp_extreme.'.$phpEx);
  227. }
  228. // Include files
  229. require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.' . $phpEx);
  230. require($phpbb_root_path . 'includes/cache.' . $phpEx);
  231. require($phpbb_root_path . 'includes/template.' . $phpEx);
  232. require($phpbb_root_path . 'includes/session.' . $phpEx);
  233. require($phpbb_root_path . 'includes/auth.' . $phpEx);
  234. require($phpbb_root_path . 'includes/functions.' . $phpEx);
  235. require($phpbb_root_path . 'includes/functions_content.' . $phpEx);
  236. require($phpbb_root_path . 'includes/constants.' . $phpEx);
  237. require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
  238. require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
  239. // Set PHP error handler to ours
  240. set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler');
  241. // Instantiate some basic classes
  242. $user = new user();
  243. $auth = new auth();
  244. $template = new template();
  245. $cache = new cache();
  246. $db = new $sql_db();
  247. // Connect to DB
  248. $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, defined('PHPBB_DB_NEW_LINK') ? PHPBB_DB_NEW_LINK : false);
  249. // We do not need this any longer, unset for safety purposes
  250. unset($dbpasswd);
  251. // Grab global variables, re-cache if necessary
  252. $config = $cache->obtain_config();
  253. //$db->sql_query("SET sql_mode='NO_UNSIGNED_SUBTRACTION'");
  254. obtain_tracker_config();
  255. // Add own hook handler
  256. require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
  257. $phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display')));
  258. foreach ($cache->obtain_hooks() as $hook)
  259. {
  260. @include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx);
  261. }
  262. ?>