Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

333 lines
8.4 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. <?php
  2. /**
  3. *
  4. * Friendika
  5. *
  6. */
  7. /**
  8. *
  9. * bootstrap the application
  10. *
  11. */
  12. require_once('boot.php');
  13. $a = new App;
  14. /**
  15. *
  16. * Load the configuration file which contains our DB credentials.
  17. * Ignore errors. If the file doesn't exist or is empty, we are running in installation mode.
  18. *
  19. */
  20. $install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false : true);
  21. @include(".htconfig.php");
  22. $lang = get_language();
  23. load_translation_table($lang);
  24. /**
  25. *
  26. * Try to open the database;
  27. *
  28. */
  29. require_once("dba.php");
  30. $db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
  31. unset($db_host, $db_user, $db_pass, $db_data);
  32. if(! $install) {
  33. /**
  34. * Load configs from db. Overwrite configs from .htconfig.php
  35. */
  36. load_config('config');
  37. load_config('system');
  38. require_once("session.php");
  39. load_hooks();
  40. call_hooks('init_1');
  41. }
  42. /**
  43. *
  44. * Important stuff we always need to do.
  45. * Initialise authentication and date and time.
  46. * Create the HTML head for the page, even if we may not use it (xml, etc.)
  47. * The order of these may be important so use caution if you think they're all
  48. * intertwingled with no logical order and decide to sort it out. Some of the
  49. * dependencies have changed, but at least at one time in the recent past - the
  50. * order was critical to everything working properly
  51. *
  52. */
  53. require_once("datetime.php");
  54. $a->timezone = (($default_timezone) ? $default_timezone : 'UTC');
  55. date_default_timezone_set($a->timezone);
  56. $a->init_pagehead();
  57. session_start();
  58. /**
  59. * Language was set earlier, but we can over-ride it in the session.
  60. * We have to do it here because the session was just now opened.
  61. */
  62. if(x($_POST,'system_language'))
  63. $_SESSION['language'] = $_POST['system_language'];
  64. if((x($_SESSION,'language')) && ($_SESSION['language'] !== $lang)) {
  65. $lang = $_SESSION['language'];
  66. load_translation_table($lang);
  67. }
  68. /**
  69. *
  70. * For Mozilla auth manager - still needs sorting, and this might conflict with LRDD header.
  71. * Apache/PHP lumps the Link: headers into one - and other services might not be able to parse it
  72. * this way. There's a PHP flag to link the headers because by default this will over-write any other
  73. * link header.
  74. *
  75. * What we really need to do is output the raw headers ourselves so we can keep them separate.
  76. *
  77. */
  78. // header('Link: <' . $a->get_baseurl() . '/amcd>; rel="acct-mgmt";');
  79. if((x($_SESSION,'authenticated')) || (x($_POST,'auth-params')) || ($a->module === 'login'))
  80. require("auth.php");
  81. if(! x($_SESSION,'authenticated'))
  82. header('X-Account-Management-Status: none');
  83. if(! x($_SESSION,'sysmsg'))
  84. $_SESSION['sysmsg'] = '';
  85. if(! x($_SESSION,'sysmsg_info'))
  86. $_SESSION['sysmsg_info'] = '';
  87. /*
  88. * check_config() is responsible for running update scripts. These automatically
  89. * update the DB schema whenever we push a new one out. It also checks to see if
  90. * any plugins have been added or removed and reacts accordingly.
  91. */
  92. if($install)
  93. $a->module = 'install';
  94. else
  95. check_config($a);
  96. $arr = array('app_menu' => $a->apps);
  97. call_hooks('app_menu', $arr);
  98. $a->apps = $arr['app_menu'];
  99. /**
  100. *
  101. * We have already parsed the server path into $a->argc and $a->argv
  102. *
  103. * $a->argv[0] is our module name. We will load the file mod/{$a->argv[0]}.php
  104. * and use it for handling our URL request.
  105. * The module file contains a few functions that we call in various circumstances
  106. * and in the following order:
  107. *
  108. * "module"_init
  109. * "module"_post (only called if there are $_POST variables)
  110. * "module"_afterpost
  111. * "module"_content - the string return of this function contains our page body
  112. *
  113. * Modules which emit other serialisations besides HTML (XML,JSON, etc.) should do
  114. * so within the module init and/or post functions and then invoke killme() to terminate
  115. * further processing.
  116. */
  117. if(strlen($a->module)) {
  118. /**
  119. *
  120. * We will always have a module name.
  121. * First see if we have a plugin which is masquerading as a module.
  122. *
  123. */
  124. if(is_array($a->plugins) && in_array($a->module,$a->plugins) && file_exists("addon/{$a->module}/{$a->module}.php")) {
  125. include_once("addon/{$a->module}/{$a->module}.php");
  126. if(function_exists($a->module . '_module'))
  127. $a->module_loaded = true;
  128. }
  129. /**
  130. * If not, next look for a 'standard' program module in the 'mod' directory
  131. */
  132. if((! $a->module_loaded) && (file_exists("mod/{$a->module}.php"))) {
  133. include_once("mod/{$a->module}.php");
  134. $a->module_loaded = true;
  135. }
  136. /**
  137. *
  138. * The URL provided does not resolve to a valid module.
  139. *
  140. * On Dreamhost sites, quite often things go wrong for no apparent reason and they send us to '/internal_error.html'.
  141. * We don't like doing this, but as it occasionally accounts for 10-20% or more of all site traffic -
  142. * we are going to trap this and redirect back to the requested page. As long as you don't have a critical error on your page
  143. * this will often succeed and eventually do the right thing.
  144. *
  145. * Otherwise we are going to emit a 404 not found.
  146. *
  147. */
  148. if(! $a->module_loaded) {
  149. // Stupid browser tried to pre-fetch our ACL img template. Don't log the event or return anything - just quietly exit.
  150. if((x($_SERVER,'QUERY_STRING')) && strpos($_SERVER['QUERY_STRING'],'{0}') !== false) {
  151. killme();
  152. }
  153. if((x($_SERVER,'QUERY_STRING')) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) {
  154. logger('index.php: dreamhost_error_hack invoked. Original URI =' . $_SERVER['REQUEST_URI']);
  155. goaway($a->get_baseurl() . $_SERVER['REQUEST_URI']);
  156. }
  157. logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] . ' ADDRESS: ' . $_SERVER['REMOTE_ADDR'] . ' QUERY: ' . $_SERVER['QUERY_STRING'], LOGGER_DEBUG);
  158. header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
  159. notice( t('Page not found.' ) . EOL);
  160. }
  161. }
  162. /* initialise content region */
  163. if(! x($a->page,'content'))
  164. $a->page['content'] = '';
  165. /**
  166. * Call module functions
  167. */
  168. if($a->module_loaded) {
  169. $a->page['page_title'] = $a->module;
  170. if(function_exists($a->module . '_init')) {
  171. $func = $a->module . '_init';
  172. $func($a);
  173. }
  174. if(($_SERVER['REQUEST_METHOD'] === 'POST') && (! $a->error)
  175. && (function_exists($a->module . '_post'))
  176. && (! x($_POST,'auth-params'))) {
  177. $func = $a->module . '_post';
  178. $func($a);
  179. }
  180. if((! $a->error) && (function_exists($a->module . '_afterpost'))) {
  181. $func = $a->module . '_afterpost';
  182. $func($a);
  183. }
  184. if((! $a->error) && (function_exists($a->module . '_content'))) {
  185. $func = $a->module . '_content';
  186. $a->page['content'] .= $func($a);
  187. }
  188. }
  189. // If you're just visiting, let javascript take you home
  190. if(x($_SESSION,'visitor_home'))
  191. $homebase = $_SESSION['visitor_home'];
  192. elseif(local_user())
  193. $homebase = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
  194. if(isset($homebase))
  195. $a->page['content'] .= '<script>var homebase="' . $homebase . '" ; </script>';
  196. // now that we've been through the module content, see if the page reported
  197. // a permission problem and if so, a 403 response would seem to be in order.
  198. if(stristr($_SESSION['sysmsg'], t('Permission denied'))) {
  199. header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . t('Permission denied.'));
  200. }
  201. /**
  202. *
  203. * Report anything which needs to be communicated in the notification area (before the main body)
  204. *
  205. */
  206. if(x($_SESSION,'sysmsg')) {
  207. $a->page['content'] = "<div id=\"sysmsg\" class=\"error-message\">{$_SESSION['sysmsg']}</div>\r\n"
  208. . ((x($a->page,'content')) ? $a->page['content'] : '');
  209. $_SESSION['sysmsg']="";
  210. unset($_SESSION['sysmsg']);
  211. }
  212. if(x($_SESSION,'sysmsg_info')) {
  213. $a->page['content'] = "<div id=\"sysmsg_info\" class=\"info-message\">{$_SESSION['sysmsg_info']}</div>\r\n"
  214. . ((x($a->page,'content')) ? $a->page['content'] : '');
  215. $_SESSION['sysmsg_info']="";
  216. unset($_SESSION['sysmsg_info']);
  217. }
  218. call_hooks('page_end', $a->page['content']);
  219. /**
  220. *
  221. * Add a place for the pause/resume Ajax indicator
  222. *
  223. */
  224. $a->page['content'] .= '<div id="pause"></div>';
  225. /**
  226. *
  227. * Add the navigation (menu) template
  228. *
  229. */
  230. if($a->module != 'install') {
  231. require_once('nav.php');
  232. nav($a);
  233. }
  234. /**
  235. * Build the page - now that we have all the components
  236. */
  237. $a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array('$stylesheet' => current_theme_url()));
  238. $page = $a->page;
  239. $profile = $a->profile;
  240. header("Content-type: text/html; charset=utf-8");
  241. $template = 'view/' . $lang . '/'
  242. . ((x($a->page,'template')) ? $a->page['template'] : 'default' ) . '.php';
  243. if(file_exists($template))
  244. require_once($template);
  245. else
  246. require_once(str_replace($lang . '/', '', $template));
  247. session_write_close();
  248. exit;