PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/textpattern/index.php

http://textpattern.googlecode.com/
PHP | 232 lines | 144 code | 49 blank | 39 comment | 32 complexity | bb919a46134affeac1ec31d1a55d1bb7 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0
  1. <?php
  2. /*
  3. * Textpattern Content Management System
  4. * http://textpattern.com
  5. *
  6. * Copyright (C) 2005 Dean Allen
  7. * Copyright (C) 2014 The Textpattern Development Team
  8. *
  9. * This file is part of Textpattern.
  10. *
  11. * Textpattern is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation, version 2.
  14. *
  15. * Textpattern is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with Textpattern. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. if (@ini_get('register_globals')) {
  24. if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {
  25. die('GLOBALS overwrite attempt detected. Please consider turning register_globals off.');
  26. }
  27. // Collect and unset all registered variables from globals.
  28. $_txpg = array_merge(
  29. isset($_SESSION) ? (array) $_SESSION : array(),
  30. (array) $_ENV,
  31. (array) $_GET,
  32. (array) $_POST,
  33. (array) $_COOKIE,
  34. (array) $_FILES,
  35. (array) $_SERVER);
  36. // As the deliberately awkward-named local variable $_txpfoo MUST NOT be unset to avoid notices further
  37. // down, we must remove any potentially identical-named global from the list of global names here.
  38. unset($_txpg['_txpfoo']);
  39. foreach ($_txpg as $_txpfoo => $value) {
  40. if (!in_array($_txpfoo, array(
  41. 'GLOBALS',
  42. '_SERVER',
  43. '_GET',
  44. '_POST',
  45. '_FILES',
  46. '_COOKIE',
  47. '_SESSION',
  48. '_REQUEST',
  49. '_ENV',
  50. ))) {
  51. unset($GLOBALS[$_txpfoo], $$_txpfoo);
  52. }
  53. }
  54. }
  55. if (!defined('txpath')) {
  56. define("txpath", dirname(__FILE__));
  57. }
  58. define("txpinterface", "admin");
  59. $thisversion = '4.6-dev';
  60. $txp_using_svn = true; // Set false for releases.
  61. ob_start(NULL, 2048);
  62. if (!isset($txpcfg['table_prefix']) && !@include './config.php') {
  63. ob_end_clean();
  64. header('HTTP/1.1 503 Service Unavailable');
  65. exit('config.php is missing or corrupt. To install Textpattern, visit <a href="./setup/">setup</a>.');
  66. } else {
  67. ob_end_clean();
  68. }
  69. header("Content-type: text/html; charset=utf-8");
  70. error_reporting(E_ALL | E_STRICT);
  71. @ini_set("display_errors","1");
  72. include txpath.'/vendors/Textpattern/Loader.php';
  73. $loader = new Textpattern_Loader(txpath.'/vendors');
  74. $loader->register();
  75. $loader = new Textpattern_Loader(txpath.'/lib');
  76. $loader->register();
  77. include_once txpath.'/lib/constants.php';
  78. include txpath.'/lib/txplib_misc.php';
  79. include txpath.'/lib/txplib_db.php';
  80. include txpath.'/lib/txplib_forms.php';
  81. include txpath.'/lib/txplib_html.php';
  82. include txpath.'/lib/txplib_theme.php';
  83. include txpath.'/lib/txplib_validator.php';
  84. include txpath.'/lib/admin_config.php';
  85. set_error_handler('adminErrorHandler', error_reporting());
  86. $microstart = getmicrotime();
  87. if ($connected && safe_query("describe `".PFX."textpattern`")) {
  88. $dbversion = safe_field('val', 'txp_prefs', "name = 'version'");
  89. // Global site preferences.
  90. $prefs = get_prefs();
  91. extract($prefs);
  92. if (empty($siteurl)) {
  93. $httphost = preg_replace('/[^-_a-zA-Z0-9.:]/', '', $_SERVER['HTTP_HOST']);
  94. $prefs['siteurl'] = $siteurl = $httphost . rtrim(dirname(dirname($_SERVER['SCRIPT_NAME'])), '/');
  95. }
  96. if (empty($path_to_site)) {
  97. updateSitePath(dirname(dirname(__FILE__)));
  98. }
  99. define("LANG",$language);
  100. // i18n: define("LANG","en-gb");
  101. define('txp_version', $thisversion);
  102. if (!defined('PROTOCOL')) {
  103. switch (serverSet('HTTPS')) {
  104. case '' :
  105. case 'off' : // ISAPI with IIS.
  106. define('PROTOCOL', 'http://');
  107. break;
  108. default :
  109. define('PROTOCOL', 'https://');
  110. break;
  111. }
  112. }
  113. define('hu', PROTOCOL.$siteurl.'/');
  114. // Relative URL global.
  115. define('rhu', preg_replace('|^https?://[^/]+|', '', hu));
  116. // HTTP address of the site serving images.
  117. if (!defined('ihu')) {
  118. define('ihu', hu);
  119. }
  120. if (!empty($locale)) {
  121. setlocale(LC_ALL, $locale);
  122. }
  123. $textarray = load_lang(LANG);
  124. // Initialise global theme.
  125. $theme = theme::init();
  126. include txpath.'/include/txp_auth.php';
  127. doAuth();
  128. // Once more for global plus private preferences.
  129. $prefs = get_prefs();
  130. extract($prefs);
  131. /**
  132. * @ignore
  133. */
  134. define('SITE_HOST', (string) @parse_url(hu, PHP_URL_HOST));
  135. /**
  136. * @ignore
  137. */
  138. define('IMPATH', $path_to_site.DS.$img_dir.DS);
  139. $event = (gps('event') ? trim(gps('event')) : (!empty($default_event) && has_privs($default_event) ? $default_event : 'article'));
  140. $step = trim(gps('step'));
  141. $app_mode = trim(gps('app_mode'));
  142. if (!$dbversion or ($dbversion != $thisversion) or $txp_using_svn) {
  143. define('TXP_UPDATE', 1);
  144. include txpath.'/update/_update.php';
  145. }
  146. janitor();
  147. // Article or form preview.
  148. if (isset($_POST['form_preview']) || isset($_GET['txpreview'])) {
  149. include txpath.'/publish.php';
  150. textpattern();
  151. exit;
  152. }
  153. if (!empty($admin_side_plugins) and gps('event') != 'plugin') {
  154. load_plugins(1);
  155. }
  156. // Plugins may have altered privilege settings.
  157. if (!defined('TXP_UPDATE_DONE') && !gps('event') && !empty($default_event) && has_privs($default_event)) {
  158. $event = $default_event;
  159. }
  160. // Initialise private theme.
  161. $theme = theme::init();
  162. include txpath.'/lib/txplib_head.php';
  163. require_privs($event);
  164. callback_event($event, $step, 1);
  165. $inc = txpath . '/include/txp_'.$event.'.php';
  166. if (is_readable($inc)) {
  167. include($inc);
  168. }
  169. callback_event($event, $step, 0);
  170. end_page();
  171. $microdiff = substr(getmicrotime() - $microstart, 0, 6);
  172. $memory_peak = is_callable('memory_get_peak_usage') ? ceil(memory_get_peak_usage(true) / 1024) : '-';
  173. if ($app_mode != 'async') {
  174. echo n.comment(gTxt('runtime').': '.$microdiff);
  175. echo n.comment(sprintf('Memory: %sKb', $memory_peak));
  176. } else {
  177. header("X-Textpattern-Runtime: $microdiff");
  178. header("X-Textpattern-Memory: $memory_peak");
  179. }
  180. } else {
  181. txp_die('DB-Connect was successful, but the textpattern-table was not found.',
  182. '503 Service Unavailable');
  183. }