PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/Upload/archive/global.php

https://gitlab.com/Conors99/ppm-1.8
PHP | 229 lines | 180 code | 23 blank | 26 comment | 36 complexity | ef9e07417ef0ee7a87d289525032f579 MD5 | raw file
  1. <?php
  2. /**
  3. * MyBB 1.8
  4. * Copyright 2014 MyBB Group, All Rights Reserved
  5. *
  6. * Website: http://www.mybb.com
  7. * License: http://www.mybb.com/about/license
  8. *
  9. */
  10. // If archive mode does not work, uncomment the line below and try again
  11. // define("ARCHIVE_QUERY_STRINGS", 1);
  12. // Lets pretend we're a level higher
  13. chdir('./../');
  14. require_once dirname(dirname(__FILE__))."/inc/init.php";
  15. require_once MYBB_ROOT."inc/functions_archive.php";
  16. require_once MYBB_ROOT."inc/class_session.php";
  17. require_once MYBB_ROOT."inc/class_parser.php";
  18. $parser = new postParser;
  19. $shutdown_queries = $shutdown_functions = array();
  20. $groupscache = $cache->read("usergroups");
  21. if(!is_array($groupscache))
  22. {
  23. $cache->update_usergroups();
  24. $groupscache = $cache->read("usergroups");
  25. }
  26. $fpermissioncache = $cache->read("forumpermissions");
  27. // Send headers before anything else.
  28. send_page_headers();
  29. // If the installer has not been removed and no lock exists, die.
  30. if(is_dir(MYBB_ROOT."install") && !file_exists(MYBB_ROOT."install/lock"))
  31. {
  32. echo "Please remove the install directory from your server, or create a file called 'lock' in the install directory. Until you do so, your board will remain unaccessable";
  33. exit;
  34. }
  35. // If the server OS is not Windows and not Apache or the PHP is running as a CGI or we have defined ARCHIVE_QUERY_STRINGS, use query strings - DIRECTORY_SEPARATOR checks if running windows
  36. //if((DIRECTORY_SEPARATOR != '\\' && stripos($_SERVER['SERVER_SOFTWARE'], 'apache') == false) || stripos(SAPI_NAME, 'cgi') !== false || defined("ARCHIVE_QUERY_STRINGS"))
  37. // http://dev.mybb.com/issues/1489 - remove automatic detection and rely on users to set the right option here
  38. if($mybb->settings['seourls_archive'] == 1)
  39. {
  40. if($_SERVER['REQUEST_URI'])
  41. {
  42. $url = $_SERVER['REQUEST_URI'];
  43. }
  44. elseif($_SERVER['REDIRECT_URL'])
  45. {
  46. $url = $_SERVER['REDIRECT_URL'];
  47. }
  48. elseif($_SERVER['PATH_INFO'])
  49. {
  50. $url = $_SERVER['PATH_INFO'];
  51. }
  52. else
  53. {
  54. $url = $_SERVER['PHP_SELF'];
  55. }
  56. $base_url = $mybb->settings['bburl']."/archive/index.php/";
  57. $endpart = my_substr(strrchr($url, "/"), 1);
  58. }
  59. else
  60. {
  61. $url = $_SERVER['QUERY_STRING'];
  62. $base_url = $mybb->settings['bburl']."/archive/index.php?";
  63. $endpart = $url;
  64. }
  65. $action = "index";
  66. // This seems to work the same as the block below except without the css bugs O_o
  67. $archiveurl = $mybb->settings['bburl'].'/archive';
  68. if($endpart != "index.php")
  69. {
  70. $endpart = str_replace(".html", "", $endpart);
  71. $todo = explode("-", $endpart, 3);
  72. if($todo[0])
  73. {
  74. $action = $action2 = $todo[0];
  75. }
  76. if(!empty($todo[2]))
  77. {
  78. $page = (int)$todo[2];
  79. }
  80. else
  81. {
  82. $page = 1;
  83. }
  84. if(!empty($todo[1]))
  85. {
  86. $id = (int)$todo[1];
  87. }
  88. else
  89. {
  90. $id = 0;
  91. }
  92. // Get the thread, announcement or forum information.
  93. if($action == "announcement")
  94. {
  95. $time = TIME_NOW;
  96. $query = $db->query("
  97. SELECT a.*, u.username
  98. FROM ".TABLE_PREFIX."announcements a
  99. LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=a.uid)
  100. WHERE a.aid='{$id}' AND startdate < '{$time}' AND (enddate > '{$time}' OR enddate = 0)
  101. ");
  102. $announcement = $db->fetch_array($query);
  103. if(!$announcement['aid'])
  104. {
  105. $action = "404";
  106. }
  107. }
  108. elseif($action == "thread")
  109. {
  110. $query = $db->simple_select("threads", "*", "tid='{$id}' AND closed NOT LIKE 'moved|%'");
  111. $thread = $db->fetch_array($query);
  112. if(!$thread['tid'])
  113. {
  114. $action = "404";
  115. }
  116. }
  117. elseif($action == "forum")
  118. {
  119. $query = $db->simple_select("forums", "*", "fid='{$id}' AND active!=0 AND password=''");
  120. $forum = $db->fetch_array($query);
  121. if(!$forum['fid'])
  122. {
  123. $action = "404";
  124. }
  125. }
  126. elseif($action != 'index')
  127. {
  128. $action = "404";
  129. }
  130. }
  131. // Define the full MyBB version location of this page.
  132. if($action == "thread")
  133. {
  134. define('MYBB_LOCATION', get_thread_link($id));
  135. }
  136. elseif($action == "forum")
  137. {
  138. define('MYBB_LOCATION', get_forum_link($id));
  139. }
  140. elseif($action == "announcement")
  141. {
  142. define('MYBB_LOCATION', get_announcement_link($id));
  143. }
  144. else
  145. {
  146. define('MYBB_LOCATION', INDEX_URL);
  147. }
  148. // Initialise session
  149. $session = new session;
  150. $session->init();
  151. if(!$mybb->settings['bblanguage'])
  152. {
  153. $mybb->settings['bblanguage'] = "english";
  154. }
  155. $lang->set_language($mybb->settings['bblanguage']);
  156. // Load global language phrases
  157. $lang->load("global");
  158. $lang->load("messages");
  159. $lang->load("archive");
  160. // Draw up the basic part of our naviagation
  161. $navbits[0]['name'] = $mybb->settings['bbname_orig'];
  162. $navbits[0]['url'] = $mybb->settings['bburl']."/archive/index.php";
  163. // Check banned ip addresses
  164. if(is_banned_ip($session->ipaddress))
  165. {
  166. archive_error($lang->error_banned);
  167. }
  168. // If our board is closed..
  169. if($mybb->settings['boardclosed'] == 1)
  170. {
  171. if($mybb->usergroup['canviewboardclosed'] != 1)
  172. {
  173. if(!$mybb->settings['boardclosed_reason'])
  174. {
  175. $mybb->settings['boardclosed_reason'] = $lang->boardclosed_reason;
  176. }
  177. $lang->error_boardclosed .= "<blockquote>".$mybb->settings['boardclosed_reason']."</blockquote>";
  178. archive_error($lang->error_boardclosed);
  179. }
  180. }
  181. // Do we require users to login?
  182. if($mybb->settings['forcelogin'] == 1)
  183. {
  184. if($mybb->user['uid'] == 0)
  185. {
  186. archive_error($lang->error_mustlogin);
  187. }
  188. }
  189. // Load Limiting - DIRECTORY_SEPARATOR checks if running windows
  190. if(DIRECTORY_SEPARATOR != '\\')
  191. {
  192. if($uptime = @exec('uptime'))
  193. {
  194. preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/", $uptime, $regs);
  195. $load = $regs[1];
  196. if($mybb->usergroup['cancp'] != 1 && $load > $mybb->settings['load'] && $mybb->settings['load'] > 0)
  197. {
  198. archive_error($lang->error_loadlimit);
  199. }
  200. }
  201. }
  202. if($mybb->usergroup['canview'] == 0)
  203. {
  204. archive_error_no_permission();
  205. }