Textpattern PHP Cross Reference Content Management Systems

Source: /textpattern/index.php - 195 lines - 5424 bytes - Text - Print

   1  <?php
   2  
   3  /*
   4      This is Textpattern
   5  
   6      Copyright 2005 by Dean Allen
   7      www.textpattern.com
   8      All rights reserved
   9  
  10      Use of this software indicates acceptance of the Textpattern license agreement
  11  
  12  $HeadURL: https://textpattern.googlecode.com/svn/releases/4.5.4/source/textpattern/index.php $
  13  $LastChangedRevision: 4916 $
  14  
  15  */
  16  
  17      if (@ini_get('register_globals')) {
  18          if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {
  19              die('GLOBALS overwrite attempt detected. Please consider turning register_globals off.');
  20          }
  21  
  22          // Collect and unset all registered variables from globals
  23          $_txpg = array_merge(
  24              isset($_SESSION) ? (array) $_SESSION : array(),
  25              (array) $_ENV,
  26              (array) $_GET,
  27              (array) $_POST,
  28              (array) $_COOKIE,
  29              (array) $_FILES,
  30              (array) $_SERVER);
  31  
  32          // As the deliberately awkward-named local variable $_txpfoo MUST NOT be unset to avoid notices further down
  33          // we must remove any potentially identical-named global from the list of global names here.
  34          unset($_txpg['_txpfoo']);
  35          foreach ($_txpg as $_txpfoo => $value) {
  36              if (!in_array($_txpfoo, array(
  37                  'GLOBALS',
  38                  '_SERVER',
  39                  '_GET',
  40                  '_POST',
  41                  '_FILES',
  42                  '_COOKIE',
  43                  '_SESSION',
  44                  '_REQUEST',
  45                  '_ENV',
  46              ))) {
  47                  unset($GLOBALS[$_txpfoo], $$_txpfoo);
  48              }
  49          }
  50      }
  51  
  52      if (!defined('txpath'))
  53      {
  54          define("txpath", dirname(__FILE__));
  55      }
  56  
  57      define("txpinterface", "admin");
  58  
  59      $thisversion = '4.5.4';
  60      $txp_using_svn = false; // set false for releases
  61  
  62      ob_start(NULL, 2048);
  63      if (!isset($txpcfg['table_prefix']) && !@include './config.php') {
  64          ob_end_clean();
  65          header('HTTP/1.1 503 Service Unavailable');
  66          exit('config.php is missing or corrupt.  To install Textpattern, visit <a href="./setup/">setup</a>.');
  67      } else ob_end_clean();
  68  
  69      header("Content-type: text/html; charset=utf-8");
  70  
  71      // We need to violate/disable E_STRICT for PHP 4.x compatibility
  72      // E_STRICT bitmask calculation stems from the variations for E_ALL in PHP 4.x, 5.3, and 5.4
  73      error_reporting(E_ALL & ~(defined('E_STRICT') ? E_STRICT : 0));
  74      @ini_set("display_errors","1");
  75  
  76      include_once txpath.'/lib/constants.php';
  77      include txpath.'/lib/txplib_misc.php';
  78      include txpath.'/lib/txplib_db.php';
  79      include txpath.'/lib/txplib_forms.php';
  80      include txpath.'/lib/txplib_html.php';
  81      include txpath.'/lib/txplib_theme.php';
  82      include txpath.'/lib/txplib_validator.php';
  83      include txpath.'/lib/admin_config.php';
  84  
  85      set_error_handler('adminErrorHandler', error_reporting());
  86      $microstart = getmicrotime();
  87  
  88       if ($connected && safe_query("describe `".PFX."textpattern`")) {
  89  
  90          $dbversion = safe_field('val','txp_prefs',"name = 'version'");
  91  
  92          // global site prefs
  93          $prefs = get_prefs();
  94          extract($prefs);
  95  
  96          if (empty($siteurl)) {
  97              $httphost = preg_replace('/[^-_a-zA-Z0-9.:]/', '', $_SERVER['HTTP_HOST']);
  98              $prefs['siteurl'] = $siteurl = $httphost . rtrim(dirname(dirname($_SERVER['SCRIPT_NAME'])), '/');
  99          }
 100          if (empty($path_to_site))
 101              updateSitePath(dirname(dirname(__FILE__)));
 102  
 103          define("LANG",$language);
 104          //i18n: define("LANG","en-gb");
 105          define('txp_version', $thisversion);
 106  
 107          if (!defined('PROTOCOL')) {
 108              switch (serverSet('HTTPS')) {
 109                  case '':
 110                  case 'off': // ISAPI with IIS
 111                      define('PROTOCOL', 'http://');
 112                  break;
 113  
 114                  default:
 115                      define('PROTOCOL', 'https://');
 116                  break;
 117              }
 118          }
 119  
 120          define('hu', PROTOCOL.$siteurl.'/');
 121          // relative url global
 122          define('rhu', preg_replace('|^https?://[^/]+|', '', hu));
 123          // http address of the site serving images
 124          if (!defined('ihu')) define('ihu', hu);
 125  
 126          if (!empty($locale)) setlocale(LC_ALL, $locale);
 127          $textarray = load_lang(LANG);
 128  
 129          // init global theme
 130          $theme = theme::init();
 131  
 132          include txpath.'/include/txp_auth.php';
 133          doAuth();
 134  
 135          // once more for global plus private prefs
 136          $prefs = get_prefs();
 137          extract($prefs);
 138  
 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  
 143          if (!$dbversion or ($dbversion != $thisversion) or $txp_using_svn)
 144          {
 145              define('TXP_UPDATE', 1);
 146              include txpath.'/update/_update.php';
 147          }
 148  
 149          janitor();
 150  
 151          // article or form preview
 152          if (isset($_POST['form_preview']) || isset($_GET['txpreview'])) {
 153              include txpath.'/publish.php';
 154              textpattern();
 155              exit;
 156          }
 157  
 158          if (!empty($admin_side_plugins) and gps('event') != 'plugin')
 159              load_plugins(1);
 160  
 161          // plugins may have altered privilege settings
 162          if (!defined('TXP_UPDATE_DONE') && !gps('event') && !empty($default_event) && has_privs($default_event))
 163          {
 164               $event = $default_event;
 165          }
 166  
 167          // init private theme
 168          $theme = theme::init();
 169  
 170          include txpath.'/lib/txplib_head.php';
 171  
 172          require_privs($event);
 173          callback_event($event, $step, 1);
 174          $inc = txpath . '/include/txp_'.$event.'.php';
 175          if (is_readable($inc))
 176              include($inc);
 177          callback_event($event, $step, 0);
 178  
 179          end_page();
 180  
 181          $microdiff = substr(getmicrotime() - $microstart,0,6);
 182          $memory_peak = is_callable('memory_get_peak_usage') ? ceil(memory_get_peak_usage(true)/1024) : '-';
 183  
 184          if ($app_mode != 'async') {
 185              echo n.comment(gTxt('runtime').': '.$microdiff);
 186              echo n.comment(sprintf('Memory: %sKb', $memory_peak));
 187          } else {
 188              header("X-Textpattern-Runtime: $microdiff");
 189              header("X-Textpattern-Memory: $memory_peak");
 190          }
 191      } else {
 192          txp_die('DB-Connect was successful, but the textpattern-table was not found.',
 193                  '503 Service Unavailable');
 194      }
 195  ?>

title

Description

title

Description

title

Description

title

title

Body