[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/include/ -> compat.inc.php (source)

   1  <?php # $Id: compat.inc.php 1707 2007-06-01 15:31:54Z garvinhicking $
   2  # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
   3  # All rights reserved.  See LICENSE file for licensing details
   4  
   5  if (IN_serendipity !== true) {
   6      die ("Don't hack!");
   7  }
   8  
   9  if (defined('S9Y_FRAMEWORK_COMPAT')) {
  10      return;
  11  }
  12  @define('S9Y_FRAMEWORK_COMPAT', true);
  13  
  14  $serendipity = array();
  15  @ini_set('magic_quotes_runtime', 'off');
  16  
  17  if (!defined('PATH_SEPARATOR')) {
  18      if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  19          define('PATH_SEPARATOR', ';');
  20      } else {
  21          define('PATH_SEPARATOR', ':');
  22      }
  23  }
  24  
  25  if (!defined('DIRECTORY_SEPARATOR')) {
  26      if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  27          define('DIRECTORY_SEPARATOR', '\\');
  28      } else {
  29          define('DIRECTORY_SEPARATOR', '/');
  30      }
  31  }
  32  
  33  /**
  34   * Create a snapshot of the current memory usage
  35   *
  36   * This functions makes use of static function properties to store the last used memory and the intermediate snapshots.
  37   * @access public
  38   * @param  string   A label for debugging output
  39   * @return boolean  Return whether the snapshot could be evaluated
  40   */
  41  function memSnap($tshow = '') {
  42      static $avail    = null;
  43      static $show     = true;
  44      static $memUsage = 0;
  45  
  46      if (!$show) {
  47          return false;
  48      }
  49  
  50      if ($avail === false) {
  51          return true;
  52      } elseif ($avail === null) {
  53          if (function_exists('memory_get_usage')) {
  54              $avail = memory_get_usage();
  55          } else {
  56              $avail = false;
  57              return false;
  58          }
  59      }
  60  
  61      if ($memUsage === 0) {
  62          $memUsage = $avail;
  63      }
  64  
  65      $current = memory_get_usage();
  66      echo '[' . date('d.m.Y H:i') . '] ' . number_format($current - $memUsage, 2, ',', '.') . ' label "' . $tshow . '", totalling ' . number_format($current, 2, ',', '.') . '<br />' . "\n";
  67      $memUsage = $current;
  68  }
  69  
  70  if (!function_exists('file_get_contents')) {
  71      function file_get_contents($filename, $use_include_path = 0) {
  72          $file = fopen($filename, 'rb', $use_include_path);
  73          $data = '';
  74          if ($file) {
  75              while (!feof($file)) {
  76                  $data .= fread($file, 4096);
  77              }
  78              fclose($file);
  79          }
  80  
  81          return $data;
  82      }
  83  }
  84  
  85  if (!isset($_REQUEST)) {
  86      $_REQUEST = &$HTTP_REQUEST_VARS;
  87  }
  88  if (!isset($_POST)) {
  89      $_POST = &$HTTP_POST_VARS;
  90  }
  91  
  92  if (!isset($_GET)) {
  93      $_GET = &$HTTP_GET_VARS;
  94  }
  95  
  96  if (!isset($_SESSION)) {
  97      $_SESSION = &$HTTP_SESSION_VARS;
  98  }
  99  
 100  if (!isset($_COOKIE)) {
 101      $_COOKIE = &$HTTP_COOKIE_VARS;
 102  }
 103  
 104  if (!isset($_SERVER)) {
 105      $_SERVER = &$HTTP_SERVER_VARS;
 106  }
 107  
 108  if (extension_loaded('filter') && function_exists('input_name_to_filter') && input_name_to_filter(ini_get('filter.default')) !== FILTER_UNSAFE_RAW) {
 109      foreach ($_POST as $key => $value) {
 110          $_POST[$key] = input_get(INPUT_POST, $key, FILTER_UNSAFE_RAW);
 111      }
 112      foreach ($_GET as $key => $value) {
 113          $_GET[$key] = input_get(INPUT_GET, $key, FILTER_UNSAFE_RAW);
 114      }
 115      foreach ($_COOKIE as $key => $value) {
 116          $_COOKIE[$key] = input_get(INPUT_COOKIE, $key, FILTER_UNSAFE_RAW);
 117      }
 118      // NOT YET IMPLEMENTED IN PHP:
 119      /*
 120      foreach ($_SESSION as $key => $value) {
 121          $_SESSION[$key] = input_get(INPUT_SESSION, $key, FILTER_UNSAFE_RAW);
 122      }
 123      */
 124  }
 125  
 126  if (extension_loaded('filter') && function_exists('filter_id') && function_exists('filter_input') && filter_id(ini_get('filter.default')) !== FILTER_UNSAFE_RAW) {
 127      foreach ($_POST as $key => $value) {
 128          $_POST[$key] = filter_input(INPUT_POST, $key, FILTER_UNSAFE_RAW);
 129      }
 130      foreach ($_GET as $key => $value) {
 131          $_GET[$key] = filter_input(INPUT_GET, $key, FILTER_UNSAFE_RAW);
 132      }
 133      foreach ($_COOKIE as $key => $value) {
 134          $_COOKIE[$key] = filter_input(INPUT_COOKIE, $key, FILTER_UNSAFE_RAW);
 135      }
 136  
 137      // NOT YET IMPLEMENTED IN PHP:
 138      /*
 139      foreach ($_SESSION as $key => $value) {
 140          $_SESSION[$key] = filter_input(INPUT_SESSION, $key, FILTER_UNSAFE_RAW);
 141      }
 142      */
 143  }
 144  
 145  /*
 146   *  Avoid magic_quotes_gpc issues
 147   *  courtesy of iliaa@php.net
 148   */
 149  function serendipity_strip_quotes(&$var)
 150  {
 151      if (is_array($var)) {
 152          foreach ($var as $k => $v) {
 153              if (is_array($v)) {
 154                  array_walk($var[$k], 'serendipity_strip_quotes');
 155              } else {
 156                  $var[$k] = stripslashes($v);
 157              }
 158          }
 159      } else {
 160          $var = stripslashes($var);
 161      }
 162  }
 163  
 164  if (ini_get('magic_quotes_gpc')) {
 165      if (@count($_REQUEST)) {
 166          array_walk($_REQUEST, 'serendipity_strip_quotes');
 167      }
 168  
 169      if (@count($_GET)) {
 170          array_walk($_GET,     'serendipity_strip_quotes');
 171      }
 172  
 173      if (@count($_POST)) {
 174          array_walk($_POST,    'serendipity_strip_quotes');
 175      }
 176  
 177      if (@count($_COOKIE)) {
 178          array_walk($_COOKIE, 'serendipity_strip_quotes');
 179      }
 180  
 181      if (@count($_FILES) && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
 182          array_walk($_FILES,   'serendipity_strip_quotes');
 183      }
 184  }
 185  
 186  
 187  // Merge get and post into the serendipity array
 188  $serendipity['GET']    = &$_GET['serendipity'];
 189  $serendipity['POST']   = &$_POST['serendipity'];
 190  $serendipity['COOKIE'] = &$_COOKIE['serendipity'];
 191  
 192  // Attempt to fix IIS compatibility
 193  if (empty($_SERVER['REQUEST_URI'])) {
 194      $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . '?' . (!empty($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '');
 195  }
 196  
 197  // Some security issues
 198  if (isset($serendipity['GET']['searchTerm'])) {
 199      $serendipity['GET']['searchTerm'] = htmlspecialchars(strip_tags($serendipity['GET']['searchTerm']));
 200  }
 201  
 202  /**
 203   * Translate values coming from the Database into native PHP variables to detect boolean values.
 204   *
 205   * @access public
 206   * @param   string      input value
 207   * @return  boolean     boolean output value
 208   */
 209  function serendipity_get_bool($item) {
 210      static $translation = array('true'  => true,
 211                                  'false' => false);
 212  
 213      if (isset($translation[$item])) {
 214          return $translation[$item];
 215      } else {
 216          return $item;
 217      }
 218  }
 219  
 220  /**
 221   * Get the current charset
 222   *
 223   * @return  string      Empty string or "UTF-8/".
 224   */
 225  function serendipity_getCharset() {
 226      global $serendipity;
 227  
 228      $charset = $serendipity['charset'];
 229      if (!empty($_POST['charset'])) {
 230          if ($_POST['charset'] == 'UTF-8/') {
 231              $charset = 'UTF-8/';
 232          } else {
 233              $charset = '';
 234          }
 235      }
 236  
 237      if (!empty($serendipity['POST']['charset'])) {
 238          if ($serendipity['POST']['charset'] == 'UTF-8/') {
 239              $charset = 'UTF-8/';
 240          } else {
 241              $charset = '';
 242          }
 243      }
 244      return $charset;
 245  }
 246  
 247  /**
 248   * Detect the language of the User Agent/Visitor
 249   *
 250   * This function needs to be included at this point so that it is globally available, also
 251   * during installation.
 252   *
 253   * @access public
 254   * @param   boolean     Toggle whether to include the language that has been autodetected.
 255   * @return  string      Return the detected language name
 256   */
 257  function serendipity_detectLang($use_include = false) {
 258      global $serendipity;
 259  
 260      $supported_languages = array_keys($serendipity['languages']);
 261      $possible_languages = explode(',', (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : ''));
 262      if (is_array($possible_languages)) {
 263          $charset = serendipity_getCharset();
 264  
 265          foreach($possible_languages as $index => $lang) {
 266              $preferred_language = strtolower(preg_replace('@^([^\-_;]*)_?.*$@', '\1', $lang));
 267              if (in_array($preferred_language, $supported_languages)) {
 268                  if ($use_include) {
 269                      @include(S9Y_INCLUDE_PATH . 'lang/' . $charset . 'serendipity_lang_' . $preferred_language . '.inc.php');
 270                      $serendipity['autolang'] = $preferred_language;
 271                  }
 272                  return $preferred_language;
 273              } // endif
 274          } // endforeach
 275      } // endif
 276  
 277      return $serendipity['lang'];
 278  }
 279  
 280  /**
 281   * Get the current serendipity version, minus the "-alpha", "-beta" or whatever tags
 282   *
 283   * @access public
 284   * @param  string   Serendipity version
 285   * @return string   Serendipity version, stripped of unneeded parts
 286   */
 287  function serendipity_getCoreVersion($version) {
 288      return preg_replace('@^([0-9\.]+).*$@', '\1', $version);
 289  }
 290  
 291  /**
 292   * Make Serendipity emit an error message and terminate the script
 293   *
 294   * @access public
 295   * @param   string  HTML code to die with
 296   * @return null
 297   */
 298  function serendipity_die($html) {
 299      die(
 300          '<html>
 301              <head>
 302                  <meta http-equiv="Content-Type" content="text/html; charset=' . LANG_CHARSET . '">
 303              </head>
 304              <body>' . $html . '</body>
 305          </html>');
 306  }
 307  
 308  /*
 309   *  Some defaults for our config vars.
 310   *  They are likely to be overwritten later in the code
 311   */
 312  $serendipity['templatePath'] = 'templates/';
 313  if (!isset($serendipity['serendipityPath'])) {
 314      $serendipity['serendipityPath'] = (defined('S9Y_INCLUDE_PATH') ? S9Y_INCLUDE_PATH : './');
 315  }
 316  
 317  $serendipity['indexFile'] = 'index.php';
 318  
 319  /* vim: set sts=4 ts=4 expandtab : */


Généré le : Sat Nov 24 09:00:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics