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.
 
 
 
 
 
 

428 lines
11 KiB

  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("include/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("include/session.php");
  41. load_hooks();
  42. call_hooks('init_1');
  43. }
  44. $maintenance = get_config('system', 'maintenance');
  45. /**
  46. *
  47. * Important stuff we always need to do.
  48. *
  49. * The order of these may be important so use caution if you think they're all
  50. * intertwingled with no logical order and decide to sort it out. Some of the
  51. * dependencies have changed, but at least at one time in the recent past - the
  52. * order was critical to everything working properly
  53. *
  54. */
  55. session_start();
  56. /**
  57. * Language was set earlier, but we can over-ride it in the session.
  58. * We have to do it here because the session was just now opened.
  59. */
  60. if(array_key_exists('system_language',$_POST)) {
  61. if(strlen($_POST['system_language']))
  62. $_SESSION['language'] = $_POST['system_language'];
  63. else
  64. unset($_SESSION['language']);
  65. }
  66. if((x($_SESSION,'language')) && ($_SESSION['language'] !== $lang)) {
  67. $lang = $_SESSION['language'];
  68. load_translation_table($lang);
  69. }
  70. if((x($_GET,'zrl')) && (!$install && !$maintenance)) {
  71. $_SESSION['my_url'] = $_GET['zrl'];
  72. $a->query_string = preg_replace('/[\?&]zrl=(.*?)([\?&]|$)/is','',$a->query_string);
  73. zrl_init($a);
  74. }
  75. /**
  76. *
  77. * For Mozilla auth manager - still needs sorting, and this might conflict with LRDD header.
  78. * Apache/PHP lumps the Link: headers into one - and other services might not be able to parse it
  79. * this way. There's a PHP flag to link the headers because by default this will over-write any other
  80. * link header.
  81. *
  82. * What we really need to do is output the raw headers ourselves so we can keep them separate.
  83. *
  84. */
  85. // header('Link: <' . $a->get_baseurl() . '/amcd>; rel="acct-mgmt";');
  86. if((x($_SESSION,'authenticated')) || (x($_POST,'auth-params')) || ($a->module === 'login'))
  87. require("include/auth.php");
  88. if(! x($_SESSION,'authenticated'))
  89. header('X-Account-Management-Status: none');
  90. /* set up page['htmlhead'] and page['end'] for the modules to use */
  91. $a->page['htmlhead'] = '';
  92. $a->page['end'] = '';
  93. if(! x($_SESSION,'sysmsg'))
  94. $_SESSION['sysmsg'] = array();
  95. if(! x($_SESSION,'sysmsg_info'))
  96. $_SESSION['sysmsg_info'] = array();
  97. /*
  98. * check_config() is responsible for running update scripts. These automatically
  99. * update the DB schema whenever we push a new one out. It also checks to see if
  100. * any plugins have been added or removed and reacts accordingly.
  101. */
  102. if($install)
  103. $a->module = 'install';
  104. elseif($maintenance)
  105. $a->module = 'maintenance';
  106. else {
  107. proc_run('php', 'include/dbupdate.php');
  108. check_plugins($a);
  109. }
  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 && !$maintenance)
  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. if(function_exists(str_replace('-','_',current_theme()) . '_content_loaded')) {
  236. $func = str_replace('-','_',current_theme()) . '_content_loaded';
  237. $func($a);
  238. }
  239. }
  240. /*
  241. * Create the page head after setting the language
  242. * and getting any auth credentials
  243. *
  244. * Moved init_pagehead() and init_page_end() to after
  245. * all the module functions have executed so that all
  246. * theme choices made by the modules can take effect
  247. */
  248. $a->init_pagehead();
  249. /**
  250. * Build the page ending -- this is stuff that goes right before
  251. * the closing </body> tag
  252. */
  253. $a->init_page_end();
  254. // If you're just visiting, let javascript take you home
  255. if(x($_SESSION,'visitor_home'))
  256. $homebase = $_SESSION['visitor_home'];
  257. elseif(local_user())
  258. $homebase = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
  259. if(isset($homebase))
  260. $a->page['content'] .= '<script>var homebase="' . $homebase . '" ; </script>';
  261. // now that we've been through the module content, see if the page reported
  262. // a permission problem and if so, a 403 response would seem to be in order.
  263. if(stristr( implode("",$_SESSION['sysmsg']), t('Permission denied'))) {
  264. header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . t('Permission denied.'));
  265. }
  266. /**
  267. *
  268. * Report anything which needs to be communicated in the notification area (before the main body)
  269. *
  270. */
  271. /*if(x($_SESSION,'sysmsg')) {
  272. $a->page['content'] = "<div id=\"sysmsg\" class=\"error-message\">{$_SESSION['sysmsg']}</div>\r\n"
  273. . ((x($a->page,'content')) ? $a->page['content'] : '');
  274. $_SESSION['sysmsg']="";
  275. unset($_SESSION['sysmsg']);
  276. }
  277. if(x($_SESSION,'sysmsg_info')) {
  278. $a->page['content'] = "<div id=\"sysmsg_info\" class=\"info-message\">{$_SESSION['sysmsg_info']}</div>\r\n"
  279. . ((x($a->page,'content')) ? $a->page['content'] : '');
  280. $_SESSION['sysmsg_info']="";
  281. unset($_SESSION['sysmsg_info']);
  282. }*/
  283. call_hooks('page_end', $a->page['content']);
  284. /**
  285. *
  286. * Add a place for the pause/resume Ajax indicator
  287. *
  288. */
  289. $a->page['content'] .= '<div id="pause"></div>';
  290. /**
  291. *
  292. * Add the navigation (menu) template
  293. *
  294. */
  295. if($a->module != 'install' && $a->module != 'maintenance') {
  296. nav($a);
  297. }
  298. /**
  299. * Add a "toggle mobile" link if we're using a mobile device
  300. */
  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. /**
  314. * Build the page - now that we have all the components
  315. */
  316. if(!$a->theme['stylesheet'])
  317. $stylesheet = current_theme_url();
  318. else
  319. $stylesheet = $a->theme['stylesheet'];
  320. $a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array('$stylesheet' => $stylesheet));
  321. $page = $a->page;
  322. $profile = $a->profile;
  323. header("Content-type: text/html; charset=utf-8");
  324. $template = 'view/theme/' . current_theme() . '/'
  325. . ((x($a->page,'template')) ? $a->page['template'] : 'default' ) . '.php';
  326. if(file_exists($template))
  327. require_once($template);
  328. else
  329. require_once(str_replace('theme/' . current_theme() . '/', '', $template));
  330. session_write_close();
  331. exit;