Textpattern PHP Cross Reference Content Management Systems

Source: /rpc/index.php - 184 lines - 5218 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /*
   4   * Textpattern Content Management System
   5   * http://textpattern.com
   6   *
   7   * XML-RPC Server for Textpattern 4.0.x
   8   * http://web.archive.org/web/20150119065246/http://txp.kusor.com/rpc-api
   9   *
  10   * Copyright (C) 2005-2006, 2016 The Textpattern Development Team
  11   * Author: Pedro Palazón
  12   *
  13   * This file is part of Textpattern.
  14   *
  15   * Textpattern is free software; you can redistribute it and/or
  16   * modify it under the terms of the GNU General Public License
  17   * as published by the Free Software Foundation, version 2.
  18   *
  19   * Textpattern is distributed in the hope that it will be useful,
  20   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22   * GNU General Public License for more details.
  23   *
  24   * You should have received a copy of the GNU General Public License
  25   * along with Textpattern. If not, see <http://www.gnu.org/licenses/>.
  26   */
  27  
  28  // TODO: change error reporting to E_ALL, including E_NOTICE to detect subtle bugs?
  29  error_reporting(E_ALL & ~E_NOTICE);
  30  
  31  // TODO: if display_errors is set to 0... who will ever see errors?
  32  ini_set("display_errors", "0");
  33  
  34  if (@ini_get('register_globals')) {
  35      if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {
  36          die('GLOBALS overwrite attempt detected. Please consider turning register_globals off.');
  37      }
  38  
  39      // Collect and unset all registered variables from globals.
  40      $_txpg = array_merge(
  41          isset($_SESSION) ? (array) $_SESSION : array(),
  42          (array) $_ENV,
  43          (array) $_GET,
  44          (array) $_POST,
  45          (array) $_COOKIE,
  46          (array) $_FILES,
  47          (array) $_SERVER);
  48  
  49      // As the deliberate awkwardly-named local variable $_txpfoo MUST NOT be
  50      // unset to avoid notices further down, we must remove any potential
  51      // identically-named global from the list of global names here.
  52      unset($_txpg['_txpfoo']);
  53  
  54      foreach ($_txpg as $_txpfoo => $value) {
  55          if (!in_array($_txpfoo, array(
  56              'GLOBALS',
  57              '_SERVER',
  58              '_GET',
  59              '_POST',
  60              '_FILES',
  61              '_COOKIE',
  62              '_SESSION',
  63              '_REQUEST',
  64              '_ENV',
  65          ))) {
  66              unset($GLOBALS[$_txpfoo], $$_txpfoo);
  67          }
  68      }
  69  }
  70  
  71  define('txpath', dirname(dirname(__FILE__)).'/textpattern');
  72  define('txpinterface', 'xmlrpc');
  73  
  74  require_once txpath.'/config.php';
  75  require_once txpath.'/lib/txplib_db.php';
  76  require_once txpath.'/lib/txplib_misc.php';
  77  require_once txpath.'/lib/admin_config.php';
  78  require_once txpath.'/lib/IXRClass.php';
  79  require_once txpath.'/lib/class.trace.php';
  80  
  81  $trace = new Trace();
  82  
  83  require_once txpath.'/vendors/Textpattern/Loader.php';
  84  
  85  $loader = new \Textpattern\Loader(txpath.'/vendors');
  86  $loader->register();
  87  
  88  $loader = new \Textpattern\Loader(txpath.'/lib');
  89  $loader->register();
  90  
  91  
  92  if ($connected && numRows(safe_query("show tables like '".PFX."textpattern'"))) {
  93      // TODO: where is dbversion used?
  94      $dbversion = safe_field('val', 'txp_prefs', "name = 'version'");
  95  
  96      // Hold it globally, instead of do several calls to the function.
  97      $prefs = get_prefs();
  98      extract($prefs);
  99  
 100      if (!defined('LANG')) {
 101          define("LANG", $language);
 102      }
 103  
 104      if (!defined('hu')) {
 105          define("hu", 'http://'.$siteurl.'/');
 106      }
 107  
 108      if (!defined('txrpcpath')) {
 109          define('txrpcpath', hu.'rpc/');
 110      }
 111  
 112      if (!empty($locale)) {
 113          setlocale(LC_ALL, $locale);
 114      }
 115  
 116      $textarray = load_lang(LANG);
 117  
 118  // TODO: include txplib_html instead of duplicating?
 119      // From txplib_html.php.
 120      if (!defined('t')) {
 121          define("t", "\t");
 122      }
 123  
 124      if (!defined('n')) {
 125          define("n", "\n");
 126      }
 127  
 128      if (!defined('br')) {
 129          define("br", "<br />");
 130      }
 131  
 132      if (!defined('sp')) {
 133          define("sp", "&#160;");
 134      }
 135  
 136      if (!defined('a')) {
 137          define("a", "&#38;");
 138      }
 139  }
 140  
 141  require_once txpath.'/lib/txplib_wrapper.php';
 142  require_once  'TXP_RPCServer.php';
 143  
 144  // Run the XML-RPC server.
 145  $server = new TXP_RPCServer();
 146  $server->serve();
 147  
 148  // TODO: remove before official release?
 149  // Save some debug logs.
 150  function write_log()
 151  {
 152      global $HTTP_RAW_POST_DATA;
 153  
 154      if (!defined('txpdmpfile')) {
 155          define('txpdmpfile', 'txpxmlrpc.txt');
 156      }
 157  
 158      $fp = @fopen(dirname(__FILE__).DIRECTORY_SEPARATOR.'xmlrpclog', 'a');
 159  
 160      if ($fp) {
 161          $lnsep = "\n================================\n";
 162          fwrite($fp, "\n$lnsep".strftime("%Y-%m-%d %H:%M:%S"));
 163          fwrite($fp, '[USER_AGENT] '.$_SERVER['HTTP_USER_AGENT']);
 164          fwrite($fp, $lnsep);
 165          fwrite($fp, '[ACCEPT_ENCODING] '.$_SERVER['HTTP_ACCEPT_ENCODING']);
 166  
 167          if (strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'apache') !== false && is_callable('getallheaders')) {
 168              fwrite($fp, $lnsep);
 169              fwrite($fp, "Apache Request Headers:\n");
 170              fwrite($fp, $lnsep);
 171              $headers = getallheaders();
 172  
 173              foreach ($headers as $header => $value) {
 174                  fwrite($fp, "$header: $value \n");
 175              }
 176          }
 177  
 178          fwrite($fp, $lnsep);
 179          fwrite($fp, "Incoming data, usually utf-8 encoded:\n");
 180          fwrite($fp, $lnsep);
 181          fwrite($fp, $HTTP_RAW_POST_DATA);
 182          fclose($fp);
 183      }
 184  }

title

Description

title

Description

title

Description

title

title

Body