[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/includes/ -> compat.php42x.php (source)

   1  <?php
   2  /**
   3   * PHP 4.2.x Compatibility functions
   4   */
   5  
   6  // no direct access
   7  defined( '_VALID_MOS' ) or die( 'Restricted access' );
   8  
   9  /**
  10   * Replace file_get_contents()
  11   *
  12   * @category    PHP
  13   * @package     PHP_Compat
  14   * @link        http://php.net/function.file_get_contents
  15   * @author      Aidan Lister <aidan@php.net>
  16   * @version     $Revision: 4988 $
  17   * @internal    resource_context is not supported
  18   * @since        PHP 5
  19   * @require     PHP 4.0.1 (trigger_error)
  20   */
  21  if (!function_exists('file_get_contents')) {
  22  	function file_get_contents($filename, $incpath = false, $resource_context = null)
  23      {
  24          if (false === $fh = fopen($filename, 'rb', $incpath)) {
  25              trigger_error('file_get_contents() failed to open stream: No such file or directory', E_USER_WARNING);
  26              return false;
  27          }
  28  
  29          clearstatcache();
  30          if ($fsize = @filesize($filename)) {
  31              $data = fread($fh, $fsize);
  32          } else {
  33              $data = '';
  34              while (!feof($fh)) {
  35                  $data .= fread($fh, 8192);
  36              }
  37          }
  38  
  39          fclose($fh);
  40          return $data;
  41      }
  42  }
  43  if (!defined('FILE_USE_INCLUDE_PATH')) {
  44      define('FILE_USE_INCLUDE_PATH', 1);
  45  }
  46  
  47  if (!defined('FILE_APPEND')) {
  48      define('FILE_APPEND', 8);
  49  }
  50  
  51  
  52  /**
  53   * Replace file_put_contents()
  54   *
  55   * @category    PHP
  56   * @package     PHP_Compat
  57   * @link        http://php.net/function.file_put_contents
  58   * @author      Aidan Lister <aidan@php.net>
  59   * @version     $Revision: 4988 $
  60   * @internal    resource_context is not supported
  61   * @since        PHP 5
  62   * @require     PHP 4.0.1 (trigger_error)
  63   */
  64  if (!function_exists('file_put_contents')) {
  65  	function file_put_contents($filename, $content, $flags = null, $resource_context = null)
  66      {
  67          // If $content is an array, convert it to a string
  68          if (is_array($content)) {
  69              $content = implode('', $content);
  70          }
  71  
  72          // If we don't have a string, throw an error
  73          if (!is_scalar($content)) {
  74              trigger_error('file_put_contents() The 2nd parameter should be either a string or an array', E_USER_WARNING);
  75              return false;
  76          }
  77  
  78          // Get the length of date to write
  79          $length = strlen($content);
  80  
  81          // Check what mode we are using
  82          $mode = ($flags & FILE_APPEND) ?
  83                      $mode = 'a' :
  84                      $mode = 'w';
  85  
  86          // Check if we're using the include path
  87          $use_inc_path = ($flags & FILE_USE_INCLUDE_PATH) ?
  88                      true :
  89                      false;
  90  
  91          // Open the file for writing
  92          if (($fh = @fopen($filename, $mode, $use_inc_path)) === false) {
  93              trigger_error('file_put_contents() failed to open stream: Permission denied', E_USER_WARNING);
  94              return false;
  95          }
  96  
  97          // Write to the file
  98          $bytes = 0;
  99          if (($bytes = @fwrite($fh, $content)) === false) {
 100              $errormsg = sprintf('file_put_contents() Failed to write %d bytes to %s',
 101                              $length,
 102                              $filename);
 103              trigger_error($errormsg, E_USER_WARNING);
 104              return false;
 105          }
 106  
 107          // Close the handle
 108          @fclose($fh);
 109  
 110          // Check all the data was written
 111          if ($bytes != $length) {
 112              $errormsg = sprintf('file_put_contents() Only %d of %d bytes written, possibly out of free disk space.',
 113                              $bytes,
 114                              $length);
 115              trigger_error($errormsg, E_USER_WARNING);
 116              return false;
 117          }
 118  
 119          // Return length
 120          return $bytes;
 121      }
 122  }
 123  /**
 124   * Add functionanlity of html_entity_decode() to PHP under 4.3
 125   *
 126   * @category    PHP
 127   * @package     PHP_Compat
 128   * @link        http://php.net/function.html_entity_decode
 129   * @since        PHP 4.3
 130   * @require     PHP 4.0.1 
 131   */
 132  if (!function_exists('html_entity_decode')) {
 133  	function html_entity_decode($string)
 134      {
 135             // Replace numeric
 136             $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
 137             $string = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $string);
 138             
 139             $trans_tbl = get_html_translation_table(HTML_ENTITIES);
 140             $trans_tbl = array_flip($trans_tbl);
 141             return strtr($string, $trans_tbl);
 142      }
 143  }
 144  ?>


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics