') {
list (, $value) = explode('', $line[0], 2);
$inifile = trim(strip_tags($value));
} else {
list (, $value) = explode(' => ', $line[0], 2);
$inifile = trim($value);
}
// Check the file actually exists
if (!file_exists($inifile)) {
user_error('ini_get_all() Unable to find php.ini', E_USER_WARNING);
return false;
}
// Check the file is readable
if (!is_readable($inifile)) {
user_error('ini_get_all() Unable to open php.ini', E_USER_WARNING);
return false;
}
// Parse the ini
if ($extension !== null) {
$ini_all = parse_ini_file($inifile, true);
// Lowercase extension keys
foreach ($ini_all as $key => $value) {
$ini_arr[strtolower($key)] = $value;
}
// Check the extension exists
if (isset($ini_arr[$extension])) {
$ini = $ini_arr[$extension];
} else {
user_error("ini_get_all() Unable to find extension '$extension'",
E_USER_WARNING);
return false;
}
} else {
$ini = parse_ini_file($inifile);
}
// Order
$ini_lc = array_map('strtolower', array_keys($ini));
array_multisort($ini_lc, SORT_ASC, SORT_STRING, $ini);
// Format
$info = array();
foreach ($ini as $key => $value) {
$info[$key] = array(
'global_value' => $value,
'local_value' => ini_get($key),
// No way to know this
'access' => -1
);
}
return $info;
}
// Define
if (!function_exists('ini_get_all')) {
function ini_get_all($extension = null)
{
return php_compat_ini_get_all($extension);
}
}
PHP_Compat-1.6.0a3/Compat/Function/is_a.php 100777 1750 1750 1512 100777 13427 , Arpad Ray
* @link http://php.net/function.is_a
* @author Aidan Lister
* @version $Revision: 269597 $
* @since PHP 4.2.0
* @require PHP 4.0.0 (user_error) (is_subclass_of)
*/
function php_compat_is_a($object, $class)
{
if (!is_object($object)) {
return false;
}
if (strtolower(get_class($object)) == strtolower($class)) {
return true;
} else {
return is_subclass_of($object, $class);
}
}
// Define
if (!function_exists('is_a')) {
function is_a($object, $class)
{
return php_compat_is_a($object, $class);
}
}
PHP_Compat-1.6.0a3/Compat/Function/is_callable.php 100777 1750 1750 3343 100777 14752 , Arpad Ray
* @link http://php.net/function.is_callable
* @author Gaetano Giunta
* @author Arpad Ray
* @version $Revision: 269597 $
* @since PHP 4.0.6
* @require PHP 4.0.0 (true, false, etc...)
* @todo add the 3rd parameter syntax...
*/
function php_compat_is_callable($var, $syntax_only = false)
{
if (!is_string($var)
&& !(is_array($var)
&& count($var) == 2
&& isset($var[0], $var[1])
&& is_string($var[1])
&& (is_string($var[0])
||
is_object($var[0])
)
)
) {
return false;
}
if ($syntax_only) {
return true;
}
if (is_string($var)) {
return function_exists($var);
} else if (is_array($var)) {
if (is_string($var[0])) {
$methods = get_class_methods($var[0]);
$method = strtolower($var[1]);
if ($methods) {
foreach ($methods as $classMethod) {
if (strtolower($classMethod) == $method) {
return true;
}
}
}
} else {
return method_exists($var[0], $var[1]);
}
}
return false;
}
// Define
if (!function_exists('is_callable')) {
function is_callable($var, $syntax_only)
{
return php_compat_is_callable($var, $syntax_only);
}
}
PHP_Compat-1.6.0a3/Compat/Function/is_scalar.php 100777 1750 1750 1251 100777 14454 , Arpad Ray
* @link http://php.net/function.is_scalar
* @author Gaetano Giunta
* @version $Revision: 269597 $
* @since PHP 4.0.5
* @require PHP 4 (is_bool)
*/
function php_compat_is_scalar($val)
{
// Check input
return (is_bool($val) || is_int($val) || is_float($val) || is_string($val));
}
// Define
if (!function_exists('is_scalar')) {
function is_scalar($val)
{
return php_compat_is_scalar($val);
}
}
PHP_Compat-1.6.0a3/Compat/Function/json_decode.php 100777 1750 1750 1322 100777 14767 , Arpad Ray , James Wade
* @link http://php.net/function.json_decode
* @author James Wade
* @version $Revision: 1.0 $
* @since 5.3.0
*/
//pear install Services_JSON-1.0.1
require_once 'Services/JSON.php';
if (!function_exists('json_decode')){
function json_decode($content, $assoc=false) {
$json = $assoc?new Services_JSON(SERVICES_JSON_LOOSE_TYPE):new Services_JSON;
return $json->decode($content);
}
} PHP_Compat-1.6.0a3/Compat/Function/json_encode.php 100777 1750 1750 1220 100777 14776 , Arpad Ray , James Wade
* @link http://php.net/function.json_encode
* @author James Wade
* @version $Revision: 1.0 $
* @since 5.3.0
*/
//pear install Services_JSON-1.0.1
require_once 'Services/JSON.php';
if (!function_exists('json_encode')){
function json_encode($content){
$json = new Services_JSON;
return $json->encode($content);
}
} PHP_Compat-1.6.0a3/Compat/Function/md5_file.php 100777 1750 1750 3342 100777 14203 , Arpad Ray
* @link http://php.net/md5_file
* @author Aidan Lister
* @version $Revision: 269597 $
* @since PHP 4.2.0
* @require PHP 4.0.0 (user_error)
*/
function php_compat_md5_file($filename, $raw_output = false)
{
// Sanity check
if (!is_scalar($filename)) {
user_error('md5_file() expects parameter 1 to be string, ' .
gettype($filename) . ' given', E_USER_WARNING);
return;
}
if (!is_scalar($raw_output)) {
user_error('md5_file() expects parameter 2 to be bool, ' .
gettype($raw_output) . ' given', E_USER_WARNING);
return;
}
if (!file_exists($filename)) {
user_error('md5_file() Unable to open file', E_USER_WARNING);
return false;
}
// Read the file
if (false === $fh = fopen($filename, 'rb')) {
user_error('md5_file() failed to open stream: No such file or directory',
E_USER_WARNING);
return false;
}
clearstatcache();
if ($fsize = @filesize($filename)) {
$data = fread($fh, $fsize);
} else {
$data = '';
while (!feof($fh)) {
$data .= fread($fh, 8192);
}
}
fclose($fh);
// Return
$data = md5($data);
if ($raw_output === true) {
$data = pack('H*', $data);
}
return $data;
}
// Define
if (!function_exists('md5_file')) {
function md5_file($filename, $raw_output = false)
{
return php_compat_md5_file($filename, $raw_output);
}
}
PHP_Compat-1.6.0a3/Compat/Function/mhash.php 100777 1750 1750 4120 100777 13612 , Arpad Ray
* @link http://php.net/function.mhash
* @author Aidan Lister
* @version $Revision: 269597 $
* @since PHP 4.1.0
* @require PHP 4.0.0 (user_error)
*/
function php_compat_mhash($hashtype, $data, $key = '')
{
switch ($hashtype) {
case MHASH_MD5:
$key = str_pad((strlen($key) > 64 ? pack("H*", md5($key)) : $key), 64, chr(0x00));
$k_opad = $key ^ (str_pad('', 64, chr(0x5c)));
$k_ipad = $key ^ (str_pad('', 64, chr(0x36)));
return pack("H*", md5($k_opad . pack("H*", md5($k_ipad . $data))));
default:
return false;
break;
}
}
// Define
if (!function_exists('mhash')) {
function mhash($hashtype, $data, $key = '')
{
return php_compat_mhash($hashtype, $data, $key = '');
}
}
PHP_Compat-1.6.0a3/Compat/Function/microtime.php 100777 1750 1750 2047 100777 14510 , Arpad Ray
* @link http://php.net/function.microtime
* @author Aidan Lister
* @author Arpad Ray
* @version $Revision: 269597 $
* @since PHP 5.0.0 (Added optional get_as_float parameter)
* @require PHP 4.0.0 (user_error)
*/
function php_compat_microtime($get_as_float = false)
{
if (!function_exists('gettimeofday')) {
$time = time();
return $get_as_float ? ($time * 1000000.0) : '0.00000000 ' . $time;
}
$gtod = gettimeofday();
$usec = $gtod['usec'] / 1000000.0;
return $get_as_float
? (float) ($gtod['sec'] + $usec)
: (sprintf('%.8f ', $usec) . $gtod['sec']);
}
// Define
if (!function_exists('microtime')) {
function microtime($get_as_float = false)
{
return php_compat_microtime($get_as_float);
}
}
PHP_Compat-1.6.0a3/Compat/Function/mime_content_type.php 100777 1750 1750 2460 100777 16241 , Arpad Ray
* @link http://php.net/function.mime_content_type
* @version $Revision: 269597 $
* @author Ian Eure
* @since PHP 4.3.0
* @require PHP 4.0.3 (escapeshellarg)
*/
function php_compat_mime_content_type($filename)
{
// Sanity check
if (!file_exists($filename)) {
return false;
}
$filename = escapeshellarg($filename);
$out = `file -iL $filename 2>/dev/null`;
if (empty($out)) {
return 'application/octet-stream';
}
// Strip off filename
$t = substr($out, strpos($out, ':') + 2);
if (strpos($t, ';') !== false) {
// Strip MIME parameters
$t = substr($t, 0, strpos($t, ';'));
}
// Strip any remaining whitespace
return trim($t);
}
// Define
if (!function_exists('mime_content_type')) {
function mime_content_type($filename)
{
return php_compat_mime_content_type($filename);
}
}
PHP_Compat-1.6.0a3/Compat/Function/mkdir.php 100777 1750 1750 3245 100777 13627 , Arpad Ray
* @link http://php.net/function.mkdir
* @author Arpad Ray
* @version $Revision: 269597 $
* @since PHP 5.0.0 (Added optional recursive and context parameters)
* @require PHP 4.0.0 (user_error)
*/
function php_compat_mkdir($pathname, $mode = 0777, $recursive = true, $context = null) {
if (version_compare(PHP_VERSION, '5.0.0', 'gte')) {
// revert to native function
return (func_num_args() > 3)
? mkdir($pathname, $mode, $recursive, $context)
: mkdir($pathname, $mode, $recursive);
}
if (!strlen($pathname)) {
user_error('No such file or directory', E_USER_WARNING);
return false;
}
if (is_dir($pathname)) {
if (func_num_args() == 5) {
// recursive call
return true;
}
user_error('File exists', E_USER_WARNING);
return false;
}
$parent_is_dir = php_compat_mkdir(dirname($pathname), $mode, $recursive, null, 0);
if ($parent_is_dir) {
return mkdir($pathname, $mode);
}
user_error('No such file or directory', E_USER_WARNING);
return false;
}
// Define
if (!function_exists('mkdir')) {
function mkdir($pathname, $mode, $recursive = false, $context = null)
{
return php_compat_mkdir($pathname, $mode, $recursive, $context);
}
}
?> PHP_Compat-1.6.0a3/Compat/Function/ob_clean.php 100777 1750 1750 1447 100777 14265 , Arpad Ray
* @link http://php.net/function.ob_clean
* @author Aidan Lister
* @author Thiemo Mättig (http://maettig.com/)
* @version $Revision: 269597 $
* @since PHP 4.2.0
* @require PHP 4.0.0 (user_error)
*/
function php_compat_ob_clean()
{
if (@ob_end_clean()) {
return ob_start();
}
user_error("ob_clean() failed to delete buffer. No buffer to delete.", E_USER_NOTICE);
return false;
}
// Define
if (!function_exists('ob_clean')) {
function ob_clean()
{
return php_compat_ob_clean();
}
}
PHP_Compat-1.6.0a3/Compat/Function/ob_flush.php 100777 1750 1750 1444 100777 14321 , Arpad Ray
* @link http://php.net/function.ob_flush
* @author Aidan Lister
* @author Thiemo Mättig (http://maettig.com/)
* @version $Revision: 269597 $
* @since PHP 4.2.0
* @require PHP 4.0.0 (user_error)
*/
function php_compat_ob_flush()
{
if (@ob_end_flush()) {
return ob_start();
}
user_error("ob_flush() Failed to flush buffer. No buffer to flush.", E_USER_NOTICE);
return false;
}
// Define
if (!function_exists('ob_flush')) {
function ob_flush()
{
return php_compat_ob_flush();
}
}
PHP_Compat-1.6.0a3/Compat/Function/ob_get_clean.php 100777 1750 1750 1413 100777 15115 , Arpad Ray
* @link http://php.net/function.ob_get_clean
* @author Aidan Lister
* @author Thiemo Mättig (http://maettig.com/)
* @version $Revision: 269597 $
* @since PHP 4.3.0
* @require PHP 4.0.0 (user_error)
*/
function php_compat_ob_get_clean()
{
$contents = ob_get_contents();
if ($contents !== false) {
ob_end_clean();
}
return $contents;
}
// Define
if (!function_exists('ob_get_clean')) {
function ob_get_clean()
{
return php_compat_ob_get_clean();
}
}
PHP_Compat-1.6.0a3/Compat/Function/ob_get_flush.php 100777 1750 1750 1413 100777 15154 , Arpad Ray
* @link http://php.net/function.ob_get_flush
* @author Aidan Lister
* @author Thiemo Mättig (http://maettig.com/)
* @version $Revision: 269597 $
* @since PHP 4.3.0
* @require PHP 4.0.0 (user_error)
*/
function php_compat_ob_get_flush()
{
$contents = ob_get_contents();
if ($contents !== false) {
ob_end_flush();
}
return $contents;
}
// Define
if (!function_exists('ob_get_flush')) {
function ob_get_flush()
{
return php_compat_ob_get_flush();
}
}
PHP_Compat-1.6.0a3/Compat/Function/pathinfo.php 100777 1750 1750 2641 100777 14330
* @copyright 2009 James Wade
* @license LGPL - http://www.gnu.org/licenses/lgpl.html
* @version $CVS: 1.0 $
* @link http://php.net/function.pathinfo
* @since PHP 5.2.0
* @require PHP 4.0.0 (user_error)
*/
if (!defined('PATHINFO_FILENAME')) {
define('PATHINFO_FILENAME', 8);
}
/**
* Returns information about a file path
*
* @param string $path The path being checked.
* @param int $options See @link
*
* @return array
*/
function php_compat_pathinfo($path = false, $options = false)
{
// Sanity check
if (!is_scalar($path)) {
user_error('pathinfo() expects parameter 1 to be string, '
. gettype($path) . ' given', E_USER_WARNING);
return;
}
if (version_compare(PHP_VERSION, '5.2.0', 'ge')) {
return pathinfo($path, $options);
}
if ($options & PATHINFO_FILENAME) {
//bug #15688
if (strpos($path, '.') !== false) {
$filename = substr($path, 0, strrpos($path, '.'));
}
if ($options === PATHINFO_FILENAME) {
return $filename;
}
$pathinfo = pathinfo($path, $options);
$pathinfo['filename'] = $filename;
return $pathinfo;
}
return pathinfo($path, $options);
}
PHP_Compat-1.6.0a3/Compat/Function/pg_affected_rows.php 100777 1750 1750 1233 100777 16015 , Arpad Ray
* @link http://php.net/function.pg_affectd_rows
* @author Ian Eure
* @version $Revision@
* @since PHP 4.2.0
* @require PHP 4.0.0
*/
function php_compat_pg_affected_rows($resource)
{
return pg_cmdtuples($resource);
}
// Define
if (!function_exists('pg_affected_rows')) {
function pg_affected_rows($resource)
{
return php_compat_pg_affected_rows($resource);
}
}
PHP_Compat-1.6.0a3/Compat/Function/pg_escape_bytea.php 100777 1750 1750 1347 100777 15634 , Arpad Ray
* @link http://php.net/function.pg_escape_bytea
* @author Ian Eure
* @version $Revision@
* @since PHP 4.2.0
* @require PHP 4.0.0
*/
function php_compat_pg_escape_bytea($data)
{
return str_replace(
array(chr(92), chr(0), chr(39)),
array('\\\134', '\\\000', '\\\047'),
$data);
}
// Define
if (!function_exists('pg_escape_bytea')) {
function pg_escape_bytea($data)
{
return php_compat_pg_escape_bytea($data);
}
}
PHP_Compat-1.6.0a3/Compat/Function/pg_unescape_bytea.php 100777 1750 1750 1324 100777 16172 , Arpad Ray
* @link http://php.net/function.pg_unescape_bytea
* @author Ian Eure
* @version $Revision@
* @since PHP 4.2.0
* @require PHP 4.0.0
*/
function php_compat_pg_unescape_bytea(&$data)
{
return str_replace(
array('$', '"'),
array('\\$', '\\"'),
$data);
}
// Define
if (!function_exists('pg_unescape_bytea')) {
function pg_unescape_bytea(&$data)
{
return php_compat_pg_unescape_bytea($data);
}
}
PHP_Compat-1.6.0a3/Compat/Function/php_ini_loaded_file.php 100777 1750 1750 2340 100777 16451 , Arpad Ray
* @link http://php.net/php_ini_loaded_file
* @author Aidan Lister
* @version $Revision: 269597 $
* @since PHP 5.1.0
* @require PHP 4.0.0 (ob_start)
*/
function php_compat_php_ini_loaded_file()
{
// Get the location of php.ini
ob_start();
phpinfo(INFO_GENERAL);
$info = ob_get_contents();
ob_clean();
$info = explode("\n", $info);
$line = array_values(preg_grep('#php\.ini#', $info));
// Plain vs HTML output
if (substr($line[0], 0, 4) === '') {
list (, $value) = explode('', $line[0], 2);
$inifile = trim(strip_tags($value));
} else {
list (, $value) = explode(' => ', $line[0], 2);
$inifile = trim($value);
}
// Check the file actually exists
if (!file_exists($inifile)) {
return false;
}
}
// Define
if (!function_exists('php_ini_loaded_file')) {
function php_ini_loaded_file()
{
return php_compat_php_ini_loaded_file();
}
}
PHP_Compat-1.6.0a3/Compat/Function/php_strip_whitespace.php 100777 1750 1750 4132 100777 16741 , Arpad Ray
* @link http://php.net/function.php_strip_whitespace
* @author Aidan Lister
* @version $Revision: 269597 $
* @since PHP 5
* @require PHP 4.0.0 (user_error) + Tokenizer extension
*/
function php_compat_php_strip_whitespace($file)
{
// Sanity check
if (!is_scalar($file)) {
user_error('php_strip_whitespace() expects parameter 1 to be string, ' .
gettype($file) . ' given', E_USER_WARNING);
return;
}
// Load file / tokens
$source = implode('', file($file));
$tokens = token_get_all($source);
// Init
$source = '';
$was_ws = false;
// Process
foreach ($tokens as $token) {
if (is_string($token)) {
// Single character tokens
$source .= $token;
} else {
list($id, $text) = $token;
switch ($id) {
// Skip all comments
case T_COMMENT:
case T_ML_COMMENT:
case T_DOC_COMMENT:
break;
// Remove whitespace
case T_WHITESPACE:
// We don't want more than one whitespace in a row replaced
if ($was_ws !== true) {
$source .= ' ';
}
$was_ws = true;
break;
default:
$was_ws = false;
$source .= $text;
break;
}
}
}
return $source;
}
// Define
if (!function_exists('php_strip_whitespace')) {
function php_strip_whitespace($file)
{
return php_compat_php_strip_whitespace($file);
}
}
PHP_Compat-1.6.0a3/Compat/Function/property_exists.php 100777 1750 1750 3402 100777 15777 , Arpad Ray
* @link http://php.net/property_exists
* @author Christian Stadler
* @version $Revision: 269597 $
* @since PHP 5.1.0
* @require PHP 4.0.0 (user_error)
*/
function php_compat_property_exists($class, $property)
{
if (!is_string($property)) {
user_error('property_exists() expects parameter 2 to be a string, ' .
gettype($property) . ' given', E_USER_WARNING);
return false;
}
if (is_object($class) || is_string($class)) {
if (is_string($class)) {
if (!class_exists($class)) {
return false;
}
$vars = get_class_vars($class);
} else {
$vars = get_object_vars($class);
}
// Bail out early if get_class_vars or get_object_vars didnt work
// or returned an empty array
if (!is_array($vars) || count($vars) <= 0) {
return false;
}
$property = strtolower($property);
foreach (array_keys($vars) AS $varname) {
if (strtolower($varname) == $property) {
return true;
}
}
return false;
}
user_error('property_exists() expects parameter 1 to be a string or ' .
'an object, ' . gettype($class) . ' given', E_USER_WARNING);
return false;
}
// Define
if (!function_exists('property_exists')) {
function property_exists($class, $property)
{
return php_compat_property_exists($class, $property);
}
}
PHP_Compat-1.6.0a3/Compat/Function/range.php 100777 1750 1750 2542 100777 13614 , Arpad Ray
* @link http://php.net/function.range
* @author Aidan Lister
* @version $Revision: 269597 $
* @since PHP 5.0.0 (The optional step parameter was added in 5.0.0)
* @require PHP 4.0.0 (user_error)
*/
function php_compat_range($low, $high, $step = 1)
{
$arr = array();
$step = (abs($step) > 0) ? abs($step) : 1;
$sign = ($low <= $high) ? 1 : -1;
// Numeric sequence
if (is_numeric($low) && is_numeric($high)) {
for ($i = (float)$low; $i*$sign <= $high*$sign; $i += $step*$sign)
$arr[] = $i;
// Character sequence
} else {
if (is_numeric($low)) {
return $this->range($low, 0, $step);
}
if (is_numeric($high)) {
return $this->range(0, $high, $step);
}
$low = ord($low);
$high = ord($high);
for ($i = $low; $i * $sign <= $high * $sign; $i += $step * $sign) {
$arr[] = chr($i);
}
}
return $arr;
}
// Define
if (!function_exists('range')) {
function range($low, $high, $step = 1)
{
return php_compat_range($low, $high, $step);
}
}
PHP_Compat-1.6.0a3/Compat/Function/restore_include_path.php 100777 1750 1750 1223 100777 16715 , Arpad Ray
* @link http://php.net/function.restore_include_path
* @author Stephan Schmidt
* @version $Revision: 269597 $
* @since PHP 4.3.0
*/
function php_compat_restore_include_path()
{
return ini_restore('include_path');
}
// Define
if (!function_exists('restore_include_path')) {
function restore_include_path()
{
return php_compat_restore_include_path();
}
}
PHP_Compat-1.6.0a3/Compat/Function/scandir.php 100777 1750 1750 2735 100777 14147 , Arpad Ray
* @link http://php.net/function.scandir
* @author Aidan Lister
* @version $Revision: 269597 $
* @since PHP 5
* @require PHP 4.0.0 (user_error)
*/
function php_compat_scandir($directory, $sorting_order = 0)
{
if (!is_string($directory)) {
user_error('scandir() expects parameter 1 to be string, ' .
gettype($directory) . ' given', E_USER_WARNING);
return;
}
if (!is_int($sorting_order) && !is_bool($sorting_order)) {
user_error('scandir() expects parameter 2 to be long, ' .
gettype($sorting_order) . ' given', E_USER_WARNING);
return;
}
if (!is_dir($directory) || (false === $fh = @opendir($directory))) {
user_error('scandir() failed to open dir: Invalid argument', E_USER_WARNING);
return false;
}
$files = array ();
while (false !== ($filename = readdir($fh))) {
$files[] = $filename;
}
closedir($fh);
if ($sorting_order == 1) {
rsort($files);
} else {
sort($files);
}
return $files;
}
// Define
if (!function_exists('scandir')) {
function scandir($directory, $sorting_order = 0)
{
return php_compat_scandir($directory, $sorting_order = 0);
}
}
PHP_Compat-1.6.0a3/Compat/Function/setcookie.php 100777 1750 1750 2053 100777 14502 , Arpad Ray
* @link http://php.net/function.setcookie
* @author Stefan Neufeind
* @version $Revision: 269597 $
* @since PHP 5.2 (Added optional httponly parameter)
* @require PHP 3 (setcookie)
*/
function php_compat_setcookie($name, $value, $expire, $path, $domain, $secure, $httponly)
{
// Following the idea on Matt Mecham's blog
// http://blog.mattmecham.com/archives/2006/09/http_only_cookies_without_php.html
$domain === ($httponly === true) ? $domain . '; HttpOnly' : $domain;
setcookie($name, $value, $expire, $path, $domain, $secure);
}
// Define
if (!function_exists('setcookie')) {
function setcookie($name, $value, $expire, $path, $domain, $secure, $httponly)
{
return php_compat_setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
}
} PHP_Compat-1.6.0a3/Compat/Function/setrawcookie.php 100777 1750 1750 2322 100777 15213 , Arpad Ray
* @link http://php.net/function.setrawcookie
* @author Stephan Schmidt
* @version $Revision: 279662 $
* @since PHP 5.2.0 (Added optional httponly parameter)
* @require PHP 3 (setcookie)
*/
function php_compat_setrawcookie($name, $value, $expire=0, $path=false, $domain=false, $secure=false, $httponly=false)
{
// Following the idea on Matt Mecham's blog
// http://blog.mattmecham.com/archives/2006/09/http_only_cookies_without_php.html
$domain = ($httponly === true) ? $domain . '; HttpOnly' : $domain;
// This should probably set a cookie using header() manually so we can avoid escaping
setcookie($name, $value, $expire, $path, $domain, $secure);
}
// Define
if (!function_exists('setrawcookie')) {
function setrawcookie($name, $value, $expire=0, $path=false, $domain=false, $secure=false, $httponly=false)
{
return php_compat_setrawcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
}
}
PHP_Compat-1.6.0a3/Compat/Function/set_include_path.php 100777 1750 1750 1275 100777 16034 , Arpad Ray
* @link http://php.net/function.set_include_path
* @author Stephan Schmidt
* @version $Revision: 269597 $
* @since PHP 4.3.0
*/
function php_compat_set_include_path($new_include_path)
{
return ini_set('include_path', $new_include_path);
}
// Define
if (!function_exists('set_include_path')) {
function set_include_path($new_include_path)
{
return php_compat_set_include_path($new_include_path);
}
}
PHP_Compat-1.6.0a3/Compat/Function/sinh.php 100777 1750 1750 1066 100777 13461 , Arpad Ray
* @link http://php.net/function.sinh
* @author Arpad Ray
* @version $Revision: 269597 $
* @since PHP 5
* @require PHP 3.0.0
*/
function php_compat_sinh($n)
{
return 0.5 * (exp($n) - exp(-$n));
}
if (!function_exists('sinh')) {
function sinh($n)
{
return php_compat_sinh($n);
}
}
PHP_Compat-1.6.0a3/Compat/Function/stripos.php 100777 1750 1750 3255 100777 14225 , Arpad Ray
* @link http://php.net/function.stripos
* @author Aidan Lister
* @version $Revision: 269597 $
* @since PHP 5
* @require PHP 4.0.0 (user_error)
*/
function php_compat_stripos($haystack, $needle, $offset = null)
{
if (!is_scalar($haystack)) {
user_error('stripos() expects parameter 1 to be string, ' .
gettype($haystack) . ' given', E_USER_WARNING);
return false;
}
if (!is_scalar($needle)) {
user_error('stripos() needle is not a string or an integer.', E_USER_WARNING);
return false;
}
if (!is_int($offset) && !is_bool($offset) && !is_null($offset)) {
user_error('stripos() expects parameter 3 to be long, ' .
gettype($offset) . ' given', E_USER_WARNING);
return false;
}
// Manipulate the string if there is an offset
$fix = 0;
if (!is_null($offset)) {
if ($offset > 0) {
$haystack = substr($haystack, $offset, strlen($haystack) - $offset);
$fix = $offset;
}
}
$segments = explode(strtolower($needle), strtolower($haystack), 2);
// Check there was a match
if (count($segments) === 1) {
return false;
}
$position = strlen($segments[0]) + $fix;
return $position;
}
// Define
if (!function_exists('stripos')) {
function stripos($haystack, $needle, $offset = null)
{
return php_compat_stripos($haystack, $needle, $offset);
}
}
PHP_Compat-1.6.0a3/Compat/Function/strpbrk.php 100777 1750 1750 2507 100777 14210 , Arpad Ray
* @link http://php.net/function.strpbrk
* @author Stephan Schmidt
* @version $Revision: 269597 $
* @since PHP 5
* @require PHP 4.0.0 (user_error)
*/
function php_compat_strpbrk($haystack, $char_list)
{
if (!is_scalar($haystack)) {
user_error('strpbrk() expects parameter 1 to be string, ' .
gettype($haystack) . ' given', E_USER_WARNING);
return false;
}
if (!is_scalar($char_list)) {
user_error('strpbrk() expects parameter 2 to be string, ' .
gettype($char_list) . ' given', E_USER_WARNING);
return false;
}
$haystack = (string) $haystack;
$char_list = (string) $char_list;
$len = strlen($haystack);
for ($i = 0; $i < $len; $i++) {
$char = substr($haystack, $i, 1);
if (strpos($char_list, $char) === false) {
continue;
}
return substr($haystack, $i);
}
return false;
}
// Define
if (!function_exists('strpbrk')) {
function strpbrk($haystack, $char_list)
{
return php_compat_strpbrk($haystack, $char_list);
}
}
PHP_Compat-1.6.0a3/Compat/Function/strripos.php 100777 1750 1750 3701 100777 14403 , Arpad Ray
* @link http://php.net/function.strripos
* @author Aidan Lister
* @version $Revision: 269597 $
* @since PHP 5
* @require PHP 4.0.0 (user_error)
*/
function php_compat_strripos($haystack, $needle, $offset = null)
{
// Sanity check
if (!is_scalar($haystack)) {
user_error('strripos() expects parameter 1 to be scalar, ' .
gettype($haystack) . ' given', E_USER_WARNING);
return false;
}
if (!is_scalar($needle)) {
user_error('strripos() expects parameter 2 to be scalar, ' .
gettype($needle) . ' given', E_USER_WARNING);
return false;
}
if (!is_int($offset) && !is_bool($offset) && !is_null($offset)) {
user_error('strripos() expects parameter 3 to be long, ' .
gettype($offset) . ' given', E_USER_WARNING);
return false;
}
// Initialise variables
$needle = strtolower($needle);
$haystack = strtolower($haystack);
$needle_fc = $needle{0};
$needle_len = strlen($needle);
$haystack_len = strlen($haystack);
$offset = (int) $offset;
$leftlimit = ($offset >= 0) ? $offset : 0;
$p = ($offset >= 0) ?
$haystack_len :
$haystack_len + $offset + 1;
// Reverse iterate haystack
while (--$p >= $leftlimit) {
if ($needle_fc === $haystack{$p} &&
substr($haystack, $p, $needle_len) === $needle) {
return $p;
}
}
return false;
}
// Define
if (!function_exists('strripos')) {
function strripos($haystack, $needle, $offset = null)
{
return php_compat_strripos($haystack, $needle, $offset);
}
}
PHP_Compat-1.6.0a3/Compat/Function/strstr.php 100777 1750 1750 1244 100777 14057 , Arpad Ray , James Wade
* @link http://php.net/function.strstr
* @author James Wade
* @version $Revision: 1.0 $
* @since PHP 5.3.0
* @require PHP 4.0.0 (strrev)
*/
function php_compat_strstr($haystack, $needle, $before_needle = false)
{
if ($before_needle) {
return strrev(array_pop(explode($n,strrev($h))));
} else {
return strstr($haystack, $needle);
}
}
PHP_Compat-1.6.0a3/Compat/Function/str_getcsv.php 100777 1750 1750 3235 100777 14703 , Arpad Ray
* @link http://php.net/function.str_getcsv
* @author HM2K
* @version $CVS: 1.0 $
* @since 5.3.0
* @require PHP 4.0.0 (fgetcsv)
*/
function php_compat_str_getcsv($input, $delimiter = ',', $enclosure = '"', $escape = '\\') {
$fh = tmpfile();
fwrite($fh, $input);
$data = array();
while (($row = php_compat_fgetcsv_wrap($fh, 1000, $delimiter, $enclosure, $escape)) !== FALSE) {
$data[] = $row;
}
fclose($fh);
return empty($data) ? false : $data;
}
/**
* Wraps fgetcsv() for the correct PHP version
*
* @link http://php.net/function.fgetcsv
*/
function php_compat_fgetcsv_wrap($fh, $length, $delimiter = ',', $enclosure = '"', $escape = '\\') {
// The escape parameter was added
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
return fgetcsv($fh, $length, $delimiter, $enclosure, $escape);
}
// The enclosure parameter was added
elseif (version_compare(PHP_VERSION, '4.3.0', '>=')) {
return fgetcsv($fh, $length, $delimiter, $enclosure);
} else {
return fgetcsv($fh, $length, $delimiter);
}
}
if (!function_exists('str_getcsv')) {
/**
* Backwards compatbility for str_getcsv()
*
* @link http://php.net/function.fgetcsv
*/
function str_getcsv($input, $delimiter = ',', $enclosure = '"', $escape = '\\') {
return php_compat_str_getcsv($input, $delimiter, $enclosure, $escape);
}
}
PHP_Compat-1.6.0a3/Compat/Function/str_ireplace.php 100777 1750 1750 3624 100777 15176 , Arpad Ray
* @link http://php.net/function.str_ireplace
* @author Aidan Lister
* @author Arpad Ray
* @version $Revision: 274076 $
* @since PHP 5
* @require PHP 4.0.0 (user_error)
*/
function php_compat_str_ireplace($search, $replace, $subject)
{
// Sanity check
if (is_string($search) && is_array($replace)) {
user_error('Array to string conversion', E_USER_NOTICE);
$replace = (string) $replace;
}
// If search isn't an array, make it one
$search = (array) $search;
$length_search = count($search);
// build the replace array
$replace = is_array($replace)
? array_pad($replace, $length_search, '')
: array_pad(array(), $length_search, $replace);
// If subject is not an array, make it one
$was_string = false;
if (is_string($subject)) {
$was_string = true;
$subject = array ($subject);
}
// Prepare the search array
foreach ($search as $search_key => $search_value) {
$search[$search_key] = '/' . preg_quote($search_value, '/') . '/i';
}
// Prepare the replace array (escape backreferences)
$replace = str_replace(array('\\', '$'), array('\\\\', '\$'), $replace);
$result = preg_replace($search, $replace, $subject);
return $was_string ? $result[0] : $result;
}
// Define
if (!function_exists('str_ireplace')) {
function str_ireplace($search, $replace, $subject)
{
return php_compat_str_ireplace($search, $replace, $subject);
}
}
PHP_Compat-1.6.0a3/Compat/Function/str_rot13.php 100777 1750 1750 1413 100777 14354 , Arpad Ray
* @link http://php.net/function.str_rot13
* @author Alan Morey
* @author Aidan Lister
* @version $Revision: 269597 $
* @since PHP 4.0.0
*/
function php_compat_str_rot13($str)
{
$from = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$to = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM';
return strtr($str, $from, $to);
}
// Define
if (!function_exists('str_rot13')) {
function str_rot13($str)
{
return php_compat_str_rot13($str);
}
}
PHP_Compat-1.6.0a3/Compat/Function/str_shuffle.php 100777 1750 1750 1607 100777 15045 , Arpad Ray
* @link http://php.net/function.str_shuffle
* @author Aidan Lister
* @version $Revision: 269597 $
* @since PHP 4.3.0
* @require PHP 4.0.0 (user_error)
*/
function php_compat_str_shuffle($str)
{
// Cast
$str = (string) $str;
// Swap random character from [0..$i] to position [$i].
for ($i = strlen($str) - 1; $i >= 0; $i--) {
$j = mt_rand(0, $i);
$tmp = $str[$i];
$str[$i] = $str[$j];
$str[$j] = $tmp;
}
return $str;
}
// Define
if (!function_exists('str_shuffle')) {
function str_shuffle($str)
{
return php_compat_str_shuffle($str);
}
}
PHP_Compat-1.6.0a3/Compat/Function/str_split.php 100777 1750 1750 3206 100777 14541 , Arpad Ray
* @link http://php.net/function.str_split
* @author Aidan Lister
* @version $Revision: 269597 $
* @since PHP 5
* @require PHP 4.0.0 (user_error)
*/
function php_compat_str_split($string, $split_length = 1)
{
if (!is_scalar($split_length)) {
user_error('str_split() expects parameter 2 to be long, ' .
gettype($split_length) . ' given', E_USER_WARNING);
return false;
}
$split_length = (int) $split_length;
if ($split_length < 1) {
user_error('str_split() The length of each segment must be greater than zero', E_USER_WARNING);
return false;
}
// Select split method
if ($split_length < 65536) {
// Faster, but only works for less than 2^16
preg_match_all('/.{1,' . $split_length . '}/s', $string, $matches);
return $matches[0];
} else {
// Required due to preg limitations
$arr = array();
$idx = 0;
$pos = 0;
$len = strlen($string);
while ($len > 0) {
$blk = ($len < $split_length) ? $len : $split_length;
$arr[$idx++] = substr($string, $pos, $blk);
$pos += $blk;
$len -= $blk;
}
return $arr;
}
}
// Define
if (!function_exists('str_split')) {
function str_split($string, $split_length = 1)
{
return php_compat_str_split($string, $split_length);
}
}
PHP_Compat-1.6.0a3/Compat/Function/str_word_count.php 100777 1750 1750 3051 100777 15567 , Arpad Ray | |