[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/libraries/joomla/utilities/compat/ -> php50x.php (source)

   1  <?php
   2  /**
   3  * @version        $Id:php50x.php 6961 2007-03-15 16:06:53Z tcp $
   4  * @package        Joomla.Framework
   5  * @subpackage    Compatibility
   6  * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7  * @license        GNU/GPL, see LICENSE.php
   8  * Joomla! is free software. This version may have been modified pursuant
   9  * to the GNU General Public License, and as distributed it includes or
  10  * is derivative of works licensed under the GNU General Public License or
  11  * other free or open source software licenses.
  12  * See COPYRIGHT.php for copyright notices and details.
  13  */
  14  
  15   /**
  16   * PHP 5.0.x Compatibility functions
  17   *
  18   * @since        1.5
  19   */
  20  
  21  // Check to ensure this file is within the rest of the framework
  22  defined('JPATH_BASE') or die('Restricted access');
  23  
  24  if (!defined('FILE_USE_INCLUDE_PATH')) {
  25      define('FILE_USE_INCLUDE_PATH', 1);
  26  }
  27  
  28  if (!defined('FILE_APPEND')) {
  29      define('FILE_APPEND', 8);
  30  }
  31  
  32  /**
  33   * Replace file_put_contents()
  34   *
  35   * @link        http://php.net/function.file_put_contents
  36   * @author        Aidan Lister <aidan@php.net>
  37   * @version         $Revision: 47 $
  38   * @internal    resource_context is not supported
  39   * @since        PHP 5
  40   */
  41  if (!function_exists('file_put_contents')) {
  42  	function file_put_contents($filename, $content, $flags = null, $resource_context = null)
  43      {
  44          // If $content is an array, convert it to a string
  45          if (is_array($content)) {
  46              $content = implode('', $content);
  47          }
  48  
  49          // If we don't have a string, throw an error
  50          if (!is_scalar($content)) {
  51              trigger_error('file_put_contents() The 2nd parameter should be either a string or an array', E_USER_WARNING);
  52              return false;
  53          }
  54  
  55          // Get the length of date to write
  56          $length = strlen($content);
  57  
  58          // Check what mode we are using
  59          $mode = ($flags & FILE_APPEND) ?
  60                      $mode = 'a' :
  61                      $mode = 'w';
  62  
  63          // Check if we're using the include path
  64          $use_inc_path = ($flags & FILE_USE_INCLUDE_PATH) ?
  65                      true :
  66                      false;
  67  
  68          // Open the file for writing
  69          if (($fh = @fopen($filename, $mode, $use_inc_path)) === false) {
  70              trigger_error('file_put_contents() failed to open stream: Permission denied', E_USER_WARNING);
  71              return false;
  72          }
  73  
  74          // Write to the file
  75          $bytes = 0;
  76          if (($bytes = @fwrite($fh, $content)) === false) {
  77              $errormsg = sprintf('file_put_contents() Failed to write %d bytes to %s',
  78                              $length,
  79                              $filename);
  80              trigger_error($errormsg, E_USER_WARNING);
  81              return false;
  82          }
  83  
  84          // Close the handle
  85          @fclose($fh);
  86  
  87          // Check all the data was written
  88          if ($bytes != $length) {
  89              $errormsg = sprintf('file_put_contents() Only %d of %d bytes written, possibly out of free disk space.',
  90                              $bytes,
  91                              $length);
  92              trigger_error($errormsg, E_USER_WARNING);
  93              return false;
  94          }
  95  
  96          // Return length
  97          return $bytes;
  98      }
  99  }
 100  
 101  /**
 102   * Ported PHP5 function to PHP4 for forward compatibility
 103   */
 104  
 105  if (version_compare(phpversion(), '5.0') < 0) {
 106      eval('
 107      function clone($object) {
 108        return unserialize(serialize($object));
 109      }
 110      ');
 111    }
 112  
 113  if(!function_exists('stripos')) {
 114   function stripos($haystack, $needle, $offset = 0) {
 115    return strpos(strtolower($haystack), strtolower($needle), $offset);
 116   }
 117  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1