[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

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


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