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.

381 lines
10 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
9 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. /**
  93. * Build the page ending -- this is stuff that goes right before
  94. * the closing </body> tag
  95. */
  96. $a->init_page_end();
  97. if(! x($_SESSION,'sysmsg'))
  98. $_SESSION['sysmsg'] = array();
  99. if(! x($_SESSION,'sysmsg_info'))
  100. $_SESSION['sysmsg_info'] = array();
  101. /*
  102. * check_config() is responsible for running update scripts. These automatically
  103. * update the DB schema whenever we push a new one out. It also checks to see if
  104. * any plugins have been added or removed and reacts accordingly.
  105. */
  106. if($install)
  107. $a->module = 'install';
  108. else
  109. check_config($a);
  110. nav_set_selected('nothing');
  111. $arr = array('app_menu' => $a->apps);
  112. call_hooks('app_menu', $arr);
  113. $a->apps = $arr['app_menu'];
  114. /**
  115. *
  116. * We have already parsed the server path into $a->argc and $a->argv
  117. *
  118. * $a->argv[0] is our module name. We will load the file mod/{$a->argv[0]}.php
  119. * and use it for handling our URL request.
  120. * The module file contains a few functions that we call in various circumstances
  121. * and in the following order:
  122. *
  123. * "module"_init
  124. * "module"_post (only called if there are $_POST variables)
  125. * "module"_afterpost
  126. * "module"_content - the string return of this function contains our page body
  127. *
  128. * Modules which emit other serialisations besides HTML (XML,JSON, etc.) should do
  129. * so within the module init and/or post functions and then invoke killme() to terminate
  130. * further processing.
  131. */
  132. if(strlen($a->module)) {
  133. /**
  134. *
  135. * We will always have a module name.
  136. * First see if we have a plugin which is masquerading as a module.
  137. *
  138. */
  139. if(is_array($a->plugins) && in_array($a->module,$a->plugins) && file_exists("addon/{$a->module}/{$a->module}.php")) {
  140. include_once("addon/{$a->module}/{$a->module}.php");
  141. if(function_exists($a->module . '_module'))
  142. $a->module_loaded = true;
  143. }
  144. /**
  145. * If not, next look for a 'standard' program module in the 'mod' directory
  146. */
  147. if((! $a->module_loaded) && (file_exists("mod/{$a->module}.php"))) {
  148. include_once("mod/{$a->module}.php");
  149. $a->module_loaded = true;
  150. }
  151. /**
  152. *
  153. * The URL provided does not resolve to a valid module.
  154. *
  155. * On Dreamhost sites, quite often things go wrong for no apparent reason and they send us to '/internal_error.html'.
  156. * We don't like doing this, but as it occasionally accounts for 10-20% or more of all site traffic -
  157. * 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
  158. * this will often succeed and eventually do the right thing.
  159. *
  160. * Otherwise we are going to emit a 404 not found.
  161. *
  162. */
  163. if(! $a->module_loaded) {
  164. // Stupid browser tried to pre-fetch our Javascript img template. Don't log the event or return anything - just quietly exit.
  165. if((x($_SERVER,'QUERY_STRING')) && preg_match('/{[0-9]}/',$_SERVER['QUERY_STRING']) !== 0) {
  166. killme();
  167. }
  168. if((x($_SERVER,'QUERY_STRING')) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) {
  169. logger('index.php: dreamhost_error_hack invoked. Original URI =' . $_SERVER['REQUEST_URI']);
  170. goaway($a->get_baseurl() . $_SERVER['REQUEST_URI']);
  171. }
  172. logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] . ' ADDRESS: ' . $_SERVER['REMOTE_ADDR'] . ' QUERY: ' . $_SERVER['QUERY_STRING'], LOGGER_DEBUG);
  173. header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
  174. $tpl = get_markup_template("404.tpl");
  175. $a->page['content'] = replace_macros($tpl, array(
  176. '$message' => t('Page not found.' )
  177. ));
  178. }
  179. }
  180. /**
  181. * load current theme info
  182. */
  183. $theme_info_file = "view/theme/".current_theme()."/theme.php";
  184. if (file_exists($theme_info_file)){
  185. require_once($theme_info_file);
  186. }
  187. /* initialise content region */
  188. if(! x($a->page,'content'))
  189. $a->page['content'] = '';
  190. if(! $install)
  191. call_hooks('page_content_top',$a->page['content']);
  192. /**
  193. * Call module functions
  194. */
  195. if($a->module_loaded) {
  196. $a->page['page_title'] = $a->module;
  197. $placeholder = '';
  198. if(function_exists($a->module . '_init')) {
  199. call_hooks($a->module . '_mod_init', $placeholder);
  200. $func = $a->module . '_init';
  201. $func($a);
  202. }
  203. if(function_exists(str_replace('-','_',current_theme()) . '_init')) {
  204. $func = str_replace('-','_',current_theme()) . '_init';
  205. $func($a);
  206. }
  207. // elseif (x($a->theme_info,"extends") && file_exists("view/theme/".$a->theme_info["extends"]."/theme.php")) {
  208. // require_once("view/theme/".$a->theme_info["extends"]."/theme.php");
  209. // if(function_exists(str_replace('-','_',$a->theme_info["extends"]) . '_init')) {
  210. // $func = str_replace('-','_',$a->theme_info["extends"]) . '_init';
  211. // $func($a);
  212. // }
  213. // }
  214. if(($_SERVER['REQUEST_METHOD'] === 'POST') && (! $a->error)
  215. && (function_exists($a->module . '_post'))
  216. && (! x($_POST,'auth-params'))) {
  217. call_hooks($a->module . '_mod_post', $_POST);
  218. $func = $a->module . '_post';
  219. $func($a);
  220. }
  221. if((! $a->error) && (function_exists($a->module . '_afterpost'))) {
  222. call_hooks($a->module . '_mod_afterpost',$placeholder);
  223. $func = $a->module . '_afterpost';
  224. $func($a);
  225. }
  226. if((! $a->error) && (function_exists($a->module . '_content'))) {
  227. $arr = array('content' => $a->page['content']);
  228. call_hooks($a->module . '_mod_content', $arr);
  229. $a->page['content'] = $arr['content'];
  230. $func = $a->module . '_content';
  231. $arr = array('content' => $func($a));
  232. call_hooks($a->module . '_mod_aftercontent', $arr);
  233. $a->page['content'] .= $arr['content'];
  234. }
  235. }
  236. // If you're just visiting, let javascript take you home
  237. if(x($_SESSION,'visitor_home'))
  238. $homebase = $_SESSION['visitor_home'];
  239. elseif(local_user())
  240. $homebase = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
  241. if(isset($homebase))
  242. $a->page['content'] .= '<script>var homebase="' . $homebase . '" ; </script>';
  243. // now that we've been through the module content, see if the page reported
  244. // a permission problem and if so, a 403 response would seem to be in order.
  245. if(stristr( implode("",$_SESSION['sysmsg']), t('Permission denied'))) {
  246. header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . t('Permission denied.'));
  247. }
  248. /**
  249. *
  250. * Report anything which needs to be communicated in the notification area (before the main body)
  251. *
  252. */
  253. /*if(x($_SESSION,'sysmsg')) {
  254. $a->page['content'] = "<div id=\"sysmsg\" class=\"error-message\">{$_SESSION['sysmsg']}</div>\r\n"
  255. . ((x($a->page,'content')) ? $a->page['content'] : '');
  256. $_SESSION['sysmsg']="";
  257. unset($_SESSION['sysmsg']);
  258. }
  259. if(x($_SESSION,'sysmsg_info')) {
  260. $a->page['content'] = "<div id=\"sysmsg_info\" class=\"info-message\">{$_SESSION['sysmsg_info']}</div>\r\n"
  261. . ((x($a->page,'content')) ? $a->page['content'] : '');
  262. $_SESSION['sysmsg_info']="";
  263. unset($_SESSION['sysmsg_info']);
  264. }*/
  265. call_hooks('page_end', $a->page['content']);
  266. /**
  267. *
  268. * Add a place for the pause/resume Ajax indicator
  269. *
  270. */
  271. $a->page['content'] .= '<div id="pause"></div>';
  272. /**
  273. *
  274. * Add the navigation (menu) template
  275. *
  276. */
  277. if($a->module != 'install') {
  278. nav($a);
  279. }
  280. /**
  281. * Build the page - now that we have all the components
  282. */
  283. $a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array('$stylesheet' => current_theme_url()));
  284. $page = $a->page;
  285. $profile = $a->profile;
  286. header("Content-type: text/html; charset=utf-8");
  287. $template = 'view/theme/' . current_theme() . '/'
  288. . ((x($a->page,'template')) ? $a->page['template'] : 'default' ) . '.php';
  289. if(file_exists($template))
  290. require_once($template);
  291. else
  292. require_once(str_replace('theme/' . current_theme() . '/', '', $template));
  293. session_write_close();
  294. exit;