Textpattern PHP Cross Reference Content Management Systems

Source: /textpattern/index.php - 253 lines - 7228 bytes - Text - Print

   1  <?php
   2  
   3  /*
   4   * Textpattern Content Management System
   5   * https://textpattern.com/
   6   *
   7   * Copyright (C) 2020 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 <https://www.gnu.org/licenses/>.
  22   */
  23  
  24  if (!defined('txpath')) {
  25      define("txpath", dirname(__FILE__));
  26  }
  27  
  28  define("txpinterface", "admin");
  29  
  30  $thisversion = '4.8.4';
  31  // $txp_using_svn deprecated in 4.7.0.
  32  $txp_using_svn = $txp_is_dev = false; // Set false for releases.
  33  
  34  ob_start(null, 2048);
  35  
  36  if (!isset($txpcfg['table_prefix']) && !@include './config.php') {
  37      ob_end_clean();
  38      header('HTTP/1.1 503 Service Unavailable');
  39      exit('<p>config.php is missing or corrupt. To install Textpattern, visit <a href="./setup/">setup</a>.</p>');
  40  } else {
  41      ob_end_clean();
  42  }
  43  
  44  header("Content-Type: text/html; charset=utf-8");
  45  
  46  error_reporting(E_ALL | E_STRICT);
  47  @ini_set("display_errors", "1");
  48  include txpath.'/lib/class.trace.php';
  49  $trace = new Trace();
  50  $trace->start('[PHP includes]');
  51  include_once txpath.'/lib/constants.php';
  52  include txpath.'/lib/txplib_misc.php';
  53  include txpath.'/lib/txplib_admin.php';
  54  
  55  include txpath.'/vendors/Textpattern/Loader.php';
  56  
  57  $loader = new \Textpattern\Loader(txpath.'/vendors');
  58  $loader->register();
  59  
  60  $loader = new \Textpattern\Loader(txpath.'/lib');
  61  $loader->register();
  62  
  63  include txpath.'/lib/txplib_db.php';
  64  include txpath.'/lib/txplib_forms.php';
  65  include txpath.'/lib/txplib_html.php';
  66  include txpath.'/lib/admin_config.php';
  67  $trace->stop();
  68  
  69  set_error_handler('adminErrorHandler', error_reporting());
  70  
  71  if ($connected && numRows(safe_query("SHOW TABLES LIKE '".PFX."textpattern'"))) {
  72      // Global site preferences.
  73      $prefs = get_prefs();
  74      extract($prefs);
  75  
  76      if (empty($siteurl)) {
  77          $httphost = preg_replace('/[^-_a-zA-Z0-9.:]/', '', $_SERVER['HTTP_HOST']);
  78          $prefs['siteurl'] = $siteurl = $httphost.rtrim(dirname(dirname($_SERVER['SCRIPT_NAME'])), DS);
  79      }
  80  
  81      if (empty($path_to_site)) {
  82          updateSitePath(dirname(dirname(__FILE__)));
  83      }
  84  
  85      define('TXP_PATTERN', get_pref('enable_short_tags', false) ? 'txp|[a-z]+:' : 'txp:?');
  86      define("LANG", $language);
  87      define('txp_version', $thisversion);
  88  
  89      if (!defined('PROTOCOL')) {
  90          switch (serverSet('HTTPS')) {
  91              case '':
  92              case 'off': // ISAPI with IIS.
  93                  define('PROTOCOL', 'http://');
  94                  break;
  95              default:
  96                  define('PROTOCOL', 'https://');
  97                  break;
  98          }
  99      }
 100  
 101      define('hu', PROTOCOL.$siteurl.'/');
 102  
 103      // Relative URL global.
 104      define('rhu', preg_replace('|^https?://[^/]+|', '', hu));
 105  
 106      // HTTP address of the site serving images.
 107      if (!defined('ihu')) {
 108          define('ihu', hu);
 109      }
 110  
 111      // HTTP address of Textpattern admin URL.
 112      if (!defined('ahu')) {
 113          if (empty($txpcfg['admin_url'])) {
 114              $adminurl = hu.'textpattern/';
 115          } else {
 116              $adminurl = PROTOCOL.rtrim(preg_replace('|^https?://|', '', $txpcfg['admin_url']), '/').'/';
 117          }
 118  
 119          define('ahu', $adminurl);
 120      }
 121  
 122      // Shared admin and public cookie_domain when using multisite admin URL (use main domain if not set).
 123      if (!defined('cookie_domain')) {
 124          if (!isset($txpcfg['cookie_domain'])) {
 125              if (empty($txpcfg['admin_url'])) {
 126                  $txpcfg['cookie_domain'] = '';
 127              } else {
 128                  $txpcfg['cookie_domain'] = rtrim(substr($txpcfg['admin_url'], strpos($txpcfg['admin_url'], '.') + 1), '/');
 129              }
 130          }
 131  
 132          define('cookie_domain', $txpcfg['cookie_domain']);
 133      }
 134  
 135      if (!empty($locale)) {
 136          setlocale(LC_ALL, $locale);
 137      }
 138  
 139      // For backwards-compatibility (sort of) with plugins that expect the
 140      // $textarray global to be present.
 141      // Will remove in future.
 142      $textarray = array();
 143  
 144      load_lang(LANG, 'admin');
 145  
 146      // Initialise global theme.
 147      $theme = \Textpattern\Admin\Theme::init();
 148  
 149      include txpath.'/include/txp_auth.php';
 150      doAuth();
 151  
 152      // Add private preferences.
 153      $prefs += get_prefs($txp_user);
 154      plug_privs();
 155      extract($prefs);
 156  
 157      $dbversion = $version;
 158  
 159      $event = (gps('event') ? trim(gps('event')) : (!empty($default_event) && has_privs($default_event) ? $default_event : 'article'));
 160      $step = trim(gps('step'));
 161      $app_mode = trim(gps('app_mode'));
 162  
 163      /**
 164       * @ignore
 165       */
 166  
 167      define('SITE_HOST', (string) @parse_url(hu, PHP_URL_HOST));
 168  
 169      /**
 170       * @ignore
 171       */
 172  
 173      define('IMPATH', $path_to_site.DS.$img_dir.DS);
 174  
 175      if (!$dbversion || ($dbversion != $thisversion) || $txp_is_dev) {
 176          define('TXP_UPDATE', 1);
 177          include txpath.'/update/_update.php';
 178      }
 179  
 180      janitor();
 181  
 182      // Article or form preview.
 183      if (isset($_GET['txpreview'])) {
 184          load_lang(LANG, 'public');
 185          include txpath.'/publish.php';
 186          textpattern();
 187          echo $trace->summary();
 188  
 189          if ($production_status === 'debug') {
 190              echo $trace->result();
 191          }
 192  
 193          exit;
 194      }
 195  
 196      $txp_sections = safe_column(array('name'), 'txp_section', '1 ORDER BY title, name');
 197  
 198      // Reload string pack using per-user language.
 199      $lang_ui = (empty($language_ui)) ? $language : $language_ui;
 200      load_lang($lang_ui, $event);
 201  
 202      if ($lang_ui != $language) {
 203          Txp::get('\Textpattern\L10n\Locale')->setLocale(LC_ALL, $lang_ui);
 204      }
 205  
 206      // Register modules
 207      register_callback('\Textpattern\Module\Help\HelpAdmin::init', 'help');
 208  
 209      if (!empty($admin_side_plugins) and gps('event') != 'plugin') {
 210          load_plugins(1);
 211      }
 212  
 213      // Plugins may have altered privilege settings.
 214      if (!defined('TXP_UPDATE_DONE') && !gps('event') && !empty($default_event) && has_privs($default_event)) {
 215          $event = $default_event;
 216      }
 217  
 218      // Initialise private theme.
 219      $theme = \Textpattern\Admin\Theme::init();
 220  
 221      include txpath.'/lib/txplib_head.php';
 222  
 223      require_privs($event);
 224      callback_event($event, $step, 1);
 225      $inc = txpath.'/include/txp_'.$event.'.php';
 226  
 227      if (is_readable($inc)) {
 228          include($inc);
 229      }
 230  
 231      callback_event($event, $step, 0);
 232  
 233      end_page();
 234  
 235      if ($production_status !== 'live') {
 236          if ($app_mode != 'async') {
 237              echo $trace->summary();
 238  
 239              if ($production_status === 'debug') {
 240                  echo $trace->result();
 241              }
 242          } else {
 243              foreach ($trace->summary(true) as $key => $value) {
 244                  header('X-Textpattern-'.preg_replace('/[^\w]+/', '', $key).': '.$value);
 245              }
 246          }
 247      }
 248  } else {
 249      txp_die(
 250          'Database connection was successful, but the <code>textpattern</code> table was not found.',
 251          '503 Service Unavailable'
 252      );
 253  }

title

Description

title

Description

title

Description

title

title

Body