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.

375 lines
9.8 KiB

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