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.

416 lines
11 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
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. require_once('object/BaseObject.php');
  14. $a = new App;
  15. BaseObject::set_app($a);
  16. /**
  17. *
  18. * Load the configuration file which contains our DB credentials.
  19. * Ignore errors. If the file doesn't exist or is empty, we are running in installation mode.
  20. *
  21. */
  22. $install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false : true);
  23. @include(".htconfig.php");
  24. $lang = get_browser_language();
  25. load_translation_table($lang);
  26. /**
  27. *
  28. * Try to open the database;
  29. *
  30. */
  31. require_once("dba.php");
  32. if(! $install) {
  33. $db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
  34. unset($db_host, $db_user, $db_pass, $db_data);
  35. /**
  36. * Load configs from db. Overwrite configs from .htconfig.php
  37. */
  38. load_config('config');
  39. load_config('system');
  40. require_once("session.php");
  41. load_hooks();
  42. call_hooks('init_1');
  43. }
  44. /**
  45. *
  46. * Important stuff we always need to do.
  47. *
  48. * The order of these may be important so use caution if you think they're all
  49. * intertwingled with no logical order and decide to sort it out. Some of the
  50. * dependencies have changed, but at least at one time in the recent past - the
  51. * order was critical to everything working properly
  52. *
  53. */
  54. session_start();
  55. /**
  56. * Language was set earlier, but we can over-ride it in the session.
  57. * We have to do it here because the session was just now opened.
  58. */
  59. if(array_key_exists('system_language',$_POST)) {
  60. if(strlen($_POST['system_language']))
  61. $_SESSION['language'] = $_POST['system_language'];
  62. else
  63. unset($_SESSION['language']);
  64. }
  65. if((x($_SESSION,'language')) && ($_SESSION['language'] !== $lang)) {
  66. $lang = $_SESSION['language'];
  67. load_translation_table($lang);
  68. }
  69. if((x($_GET,'zrl')) && (! $install)) {
  70. $_SESSION['my_url'] = $_GET['zrl'];
  71. $a->query_string = preg_replace('/[\?&]zrl=(.*?)([\?&]|$)/is','',$a->query_string);
  72. zrl_init($a);
  73. }
  74. /**
  75. *
  76. * For Mozilla auth manager - still needs sorting, and this might conflict with LRDD header.
  77. * Apache/PHP lumps the Link: headers into one - and other services might not be able to parse it
  78. * this way. There's a PHP flag to link the headers because by default this will over-write any other
  79. * link header.
  80. *
  81. * What we really need to do is output the raw headers ourselves so we can keep them separate.
  82. *
  83. */
  84. // header('Link: <' . $a->get_baseurl() . '/amcd>; rel="acct-mgmt";');
  85. if((x($_SESSION,'authenticated')) || (x($_POST,'auth-params')) || ($a->module === 'login'))
  86. require("auth.php");
  87. if(! x($_SESSION,'authenticated'))
  88. header('X-Account-Management-Status: none');
  89. /* set up page['htmlhead'] and page['end'] for the modules to use */
  90. $a->page['htmlhead'] = '';
  91. $a->page['end'] = '';
  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. if(function_exists(str_replace('-','_',current_theme()) . '_content_loaded')) {
  231. $func = str_replace('-','_',current_theme()) . '_content_loaded';
  232. $func($a);
  233. }
  234. }
  235. /*
  236. * Create the page head after setting the language
  237. * and getting any auth credentials
  238. *
  239. * Moved init_pagehead() and init_page_end() to after
  240. * all the module functions have executed so that all
  241. * theme choices made by the modules can take effect
  242. */
  243. $a->init_pagehead();
  244. /**
  245. * Build the page ending -- this is stuff that goes right before
  246. * the closing </body> tag
  247. */
  248. $a->init_page_end();
  249. // If you're just visiting, let javascript take you home
  250. if(x($_SESSION,'visitor_home'))
  251. $homebase = $_SESSION['visitor_home'];
  252. elseif(local_user())
  253. $homebase = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
  254. if(isset($homebase))
  255. $a->page['content'] .= '<script>var homebase="' . $homebase . '" ; </script>';
  256. // now that we've been through the module content, see if the page reported
  257. // a permission problem and if so, a 403 response would seem to be in order.
  258. if(stristr( implode("",$_SESSION['sysmsg']), t('Permission denied'))) {
  259. header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . t('Permission denied.'));
  260. }
  261. /**
  262. *
  263. * Report anything which needs to be communicated in the notification area (before the main body)
  264. *
  265. */
  266. /*if(x($_SESSION,'sysmsg')) {
  267. $a->page['content'] = "<div id=\"sysmsg\" class=\"error-message\">{$_SESSION['sysmsg']}</div>\r\n"
  268. . ((x($a->page,'content')) ? $a->page['content'] : '');
  269. $_SESSION['sysmsg']="";
  270. unset($_SESSION['sysmsg']);
  271. }
  272. if(x($_SESSION,'sysmsg_info')) {
  273. $a->page['content'] = "<div id=\"sysmsg_info\" class=\"info-message\">{$_SESSION['sysmsg_info']}</div>\r\n"
  274. . ((x($a->page,'content')) ? $a->page['content'] : '');
  275. $_SESSION['sysmsg_info']="";
  276. unset($_SESSION['sysmsg_info']);
  277. }*/
  278. call_hooks('page_end', $a->page['content']);
  279. /**
  280. *
  281. * Add a place for the pause/resume Ajax indicator
  282. *
  283. */
  284. $a->page['content'] .= '<div id="pause"></div>';
  285. /**
  286. *
  287. * Add the navigation (menu) template
  288. *
  289. */
  290. if($a->module != 'install') {
  291. nav($a);
  292. }
  293. /**
  294. * Build the page - now that we have all the components
  295. */
  296. if(!$a->theme['stylesheet'])
  297. $stylesheet = current_theme_url();
  298. else
  299. $stylesheet = $a->theme['stylesheet'];
  300. $a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array('$stylesheet' => $stylesheet));
  301. if($a->is_mobile || $a->is_tablet) {
  302. if(isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) {
  303. $link = $a->get_baseurl() . '/toggle_mobile?address=' . curPageURL();
  304. }
  305. else {
  306. $link = $a->get_baseurl() . '/toggle_mobile?off=1&address=' . curPageURL();
  307. }
  308. $a->page['footer'] = replace_macros(get_markup_template("toggle_mobile_footer.tpl"), array(
  309. '$toggle_link' => $link,
  310. '$toggle_text' => t('toggle mobile')
  311. ));
  312. }
  313. $page = $a->page;
  314. $profile = $a->profile;
  315. header("Content-type: text/html; charset=utf-8");
  316. $template = 'view/theme/' . current_theme() . '/'
  317. . ((x($a->page,'template')) ? $a->page['template'] : 'default' ) . '.php';
  318. if(file_exists($template))
  319. require_once($template);
  320. else
  321. require_once(str_replace('theme/' . current_theme() . '/', '', $template));
  322. session_write_close();
  323. exit;