PageRenderTime 47ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/textpattern/index.php

https://github.com/textpattern/textpattern
PHP | 256 lines | 156 code | 57 blank | 43 comment | 41 complexity | aee28aaf1b3598f767ffc661a21c2fb0 MD5 | raw file
  1. <?php
  2. /*
  3. * Textpattern Content Management System
  4. * https://textpattern.com/
  5. *
  6. * Copyright (C) 2022 The Textpattern Development Team
  7. *
  8. * This file is part of Textpattern.
  9. *
  10. * Textpattern is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation, version 2.
  13. *
  14. * Textpattern is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with Textpattern. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. if (!defined('txpath')) {
  23. define("txpath", dirname(__FILE__));
  24. }
  25. define("txpinterface", "admin");
  26. $thisversion = '4.9.0-dev';
  27. // $txp_using_svn deprecated in 4.7.0.
  28. $txp_using_svn = $txp_is_dev = true; // Set false for releases.
  29. ob_start(null, 2048);
  30. if (!isset($txpcfg['table_prefix']) && !@include './config.php') {
  31. ob_end_clean();
  32. header('HTTP/1.1 503 Service Unavailable');
  33. exit('<p>config.php is missing or corrupt. To install Textpattern, visit <a href="./setup/">setup</a>.</p>');
  34. } else {
  35. ob_end_clean();
  36. }
  37. header("Content-Type: text/html; charset=utf-8");
  38. error_reporting(E_ALL | E_STRICT);
  39. @ini_set("display_errors", "1");
  40. include txpath.'/lib/class.trace.php';
  41. $trace = new Trace();
  42. $trace->start('[PHP includes]');
  43. include_once txpath.'/lib/constants.php';
  44. include txpath.'/lib/txplib_misc.php';
  45. include txpath.'/lib/txplib_admin.php';
  46. include txpath.'/vendors/Textpattern/Loader.php';
  47. $loader = new \Textpattern\Loader(txpath.'/vendors');
  48. $loader->register();
  49. $loader = new \Textpattern\Loader(txpath.'/lib');
  50. $loader->register();
  51. include txpath.'/lib/txplib_db.php';
  52. include txpath.'/lib/txplib_forms.php';
  53. include txpath.'/lib/txplib_html.php';
  54. include txpath.'/lib/admin_config.php';
  55. $trace->stop();
  56. set_error_handler('adminErrorHandler', error_reporting());
  57. if ($connected && numRows(safe_query("SHOW TABLES LIKE '".PFX."textpattern'"))) {
  58. // Global site preferences.
  59. $prefs = get_prefs();
  60. extract($prefs);
  61. if (empty($siteurl)) {
  62. $httphost = preg_replace('/[^-_a-zA-Z0-9.:]/', '', $_SERVER['HTTP_HOST']);
  63. $prefs['siteurl'] = $siteurl = $httphost.rtrim(dirname(dirname($_SERVER['SCRIPT_NAME'])), DS);
  64. }
  65. if (empty($path_to_site)) {
  66. updateSitePath(dirname(dirname(__FILE__)));
  67. }
  68. define('TXP_PATTERN', get_pref('enable_short_tags', false) ? 'txp|[a-z]+:' : 'txp:?');
  69. define("LANG", $language);
  70. define('txp_version', $thisversion);
  71. if (!defined('PROTOCOL')) {
  72. switch (serverSet('HTTPS')) {
  73. case '':
  74. case 'off': // ISAPI with IIS.
  75. define('PROTOCOL', 'http://');
  76. break;
  77. default:
  78. define('PROTOCOL', 'https://');
  79. break;
  80. }
  81. }
  82. define('hu', PROTOCOL.$siteurl.'/');
  83. // Relative URL global.
  84. define('rhu', preg_replace('|^https?://[^/]+|', '', hu));
  85. // HTTP address of the site serving images.
  86. if (!defined('ihu')) {
  87. define('ihu', hu);
  88. }
  89. // HTTP address of Textpattern admin URL.
  90. if (!defined('ahu')) {
  91. if (empty($txpcfg['admin_url'])) {
  92. $adminurl = hu.'textpattern/';
  93. } else {
  94. $adminurl = PROTOCOL.rtrim(preg_replace('|^https?://|', '', $txpcfg['admin_url']), '/').'/';
  95. }
  96. define('ahu', $adminurl);
  97. }
  98. // Shared admin and public cookie_domain when using multisite admin URL (use main domain if not set).
  99. if (!defined('cookie_domain')) {
  100. if (!isset($txpcfg['cookie_domain'])) {
  101. if (empty($txpcfg['admin_url'])) {
  102. $txpcfg['cookie_domain'] = '';
  103. } else {
  104. $txpcfg['cookie_domain'] = rtrim(substr($txpcfg['admin_url'], strpos($txpcfg['admin_url'], '.') + 1), '/');
  105. }
  106. }
  107. define('cookie_domain', $txpcfg['cookie_domain']);
  108. }
  109. if (!empty($locale)) {
  110. setlocale(LC_ALL, $locale);
  111. }
  112. // For backwards-compatibility (sort of) with plugins that expect the
  113. // $textarray global to be present.
  114. // Will remove in future.
  115. $textarray = array();
  116. //load_lang(LANG, 'admin');
  117. // Initialise global theme.
  118. $theme = \Textpattern\Admin\Theme::init();
  119. include txpath.'/include/txp_auth.php';
  120. doAuth();
  121. // Add private preferences.
  122. $prefs += get_prefs($txp_user);
  123. plug_privs();
  124. extract($prefs);
  125. $dbversion = $version;
  126. $event = (gps('event') ? trim(gps('event')) : (!empty($default_event) && has_privs($default_event) ? $default_event : 'article'));
  127. $step = trim(gps('step'));
  128. $app_mode = trim(gps('app_mode'));
  129. /**
  130. * @ignore
  131. */
  132. define('SITE_HOST', (string) @parse_url(hu, PHP_URL_HOST));
  133. /**
  134. * @ignore
  135. */
  136. define('IMPATH', $path_to_site.DS.$img_dir.DS);
  137. if (!$dbversion || ($dbversion != $thisversion) || $txp_is_dev) {
  138. define('TXP_UPDATE', 1);
  139. include txpath.'/update/_update.php';
  140. }
  141. janitor();
  142. // Article or form preview.
  143. if (isset($_GET['txpreview'])) {
  144. load_lang(LANG, 'public');
  145. include txpath.'/publish.php';
  146. textpattern();
  147. echo $trace->summary();
  148. if ($production_status === 'debug') {
  149. echo $trace->result();
  150. }
  151. exit;
  152. }
  153. $txp_sections = safe_column(array('name'), 'txp_section', '1 ORDER BY title, name');
  154. $timezone_key = get_pref('timezone_key', date_default_timezone_get()) or $timezone_key = 'UTC';
  155. date_default_timezone_set($timezone_key);
  156. // Reload string pack using per-user language.
  157. $lang_ui = (empty($language_ui)) ? $language : $language_ui;
  158. load_lang($lang_ui, $event);
  159. if ($lang_ui != $language) {
  160. Txp::get('\Textpattern\L10n\Locale')->setLocale(LC_ALL, $lang_ui);
  161. }
  162. // Register modules
  163. register_callback('\Textpattern\Module\Help\HelpAdmin::init', 'help');
  164. if (!empty($admin_side_plugins) and gps('event') != 'plugin') {
  165. load_plugins(1);
  166. }
  167. // Plugins may have altered privilege settings.
  168. if (!defined('TXP_UPDATE_DONE') && !gps('event') && !empty($default_event) && has_privs($default_event)) {
  169. $event = $default_event;
  170. }
  171. // Initialise private theme.
  172. $theme = \Textpattern\Admin\Theme::init();
  173. include txpath.'/lib/txplib_head.php';
  174. require_privs($event);
  175. callback_event($event, $step, 1);
  176. $inc = txpath.'/include/txp_'.$event.'.php';
  177. if (is_readable($inc)) {
  178. include($inc);
  179. }
  180. callback_event($event, $step, 0);
  181. end_page();
  182. if ($production_status !== 'live') {
  183. if ($app_mode != 'async') {
  184. echo $trace->summary();
  185. if ($production_status === 'debug') {
  186. echo $trace->result();
  187. }
  188. } else {
  189. foreach ($trace->summary(true) as $key => $value) {
  190. header('X-Textpattern-'.preg_replace('/[^\w]+/', '', $key).': '.$value);
  191. }
  192. }
  193. }
  194. } else {
  195. txp_die(
  196. 'Database connection was successful, but the <code>textpattern</code> table was not found.',
  197. '503 Service Unavailable'
  198. );
  199. }