From 7ec6e84231999ddf4cef5928a0530682265432f9 Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Wed, 19 Sep 2007 14:07:27 +0000 Subject: Make it.class PHP4 compatible again --- it.class | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/it.class b/it.class index 95bb2f7..226a88d 100644 --- a/it.class +++ b/it.class @@ -23,11 +23,6 @@ class it { - static $stdin_args = array(); - static $stdin = null; - static $stdin_filename = ""; - static $stdin_line = 0; - /** * Clone an object and return copy, works for all PHP versions */ @@ -52,7 +47,7 @@ function log($name /* ... */) $existed = file_exists($fn); - if ($fh = fopen($fn, "a")) + if (isset($GLOBALS['ULTRAHOME']) && ($fh = fopen($fn, "a"))) { fputs($fh, $line); fclose($fh); @@ -385,7 +380,15 @@ function _exec_quotevalue($value) function imageconvert($p) { $result = false; - $type = it::replace(array("jpeg" => "jpg", "tiff" => "tif"), image_type_to_extension(@exif_imagetype($p['in']), false)); + $imagetype = @exif_imagetype($p['in']); + + if (!function_exists("image_type_to_extension") || !($type = it::replace(array("jpeg" => "jpg", "tiff" => "tif"), image_type_to_extension($imagetype, false)))) + { + # Fallback for PHP4 + $knowntypes = array(IMAGETYPE_GIF => "gif", IMAGETYPE_JPEG => "jpg", IMAGETYPE_PNG => "png", IMAGETYPE_BMP => "bmp"); + $type = $knowntypes[$imagetype]; + } + $p += array('type' => $type, 'types' => "gif,jpg,png,bmp,tif,jp2"); if (it::match(",$type,", ",{$p['types']},")) # Valid type? @@ -408,10 +411,17 @@ function imageconvert($p) */ function getopt($helplines) { + $GLOBALS['it_stdin'] = array( + 'fd' => null, + 'args' => array(), + 'filename' => "", + 'line' => 0, + ); + $result = array('args' => array()); if ($indentation = it::match('^\s+', $helplines)) - $helplines = it::replace($indentation => "\n", $helplines); + $helplines = it::replace(array($indentation => "\n"), $helplines); foreach(explode("\n", trim($helplines)) as $helpline) { @@ -435,7 +445,7 @@ function getopt($helplines) } $mandatoryargs = array(); - if ($tmp = trim(it::replace("\n.*" => "", "^\S+\s+\S+\s*" => "", "\[.*?\]\s*" => "", trim($helplines)))) + if ($tmp = trim(it::replace(array("\n.*" => "", "^\S+\s+\S+\s*" => "", "\[.*?\]\s*" => ""), trim($helplines)))) $mandatoryargs = preg_split('/\s+/', $tmp); foreach (array_slice($_SERVER['argv'], 1) as $arg) @@ -459,7 +469,7 @@ function getopt($helplines) } else if ($letters = it::match('^-(\w+)', $arg)) { - foreach (str_split($letters, 1) as $letter) + foreach (explode("\n", trim(chunk_split($letters, 1, "\n"))) as $letter) { $optname = $alias[$letter] ? $alias[$letter] : $letter; if ($witharg[$optname]) @@ -482,7 +492,7 @@ function getopt($helplines) exit(1); } - it::$stdin_args = $result['args'] ? $result['args'] : array("-"); + $GLOBALS['it_stdin']['args'] = $result['args'] ? $result['args'] : array("-"); it::_stdin_next(); return $result; @@ -490,11 +500,11 @@ function getopt($helplines) function _stdin_next() { - if ($result = it::$stdin_args) + if ($result = $GLOBALS['it_stdin']['args']) { - it::$stdin_filename = array_shift(it::$stdin_args); - it::$stdin = (it::$stdin_filename == "-") ? STDIN : @fopen(it::$stdin_filename, "r"); - it::$stdin_line = 0; + $GLOBALS['it_stdin']['filename'] = array_shift($GLOBALS['it_stdin']['args']); + $GLOBALS['it_stdin']['fd'] = ($GLOBALS['it_stdin']['filename'] == "-") ? STDIN : @fopen($GLOBALS['it_stdin']['filename'], "r"); + $GLOBALS['it_stdin']['line'] = 0; } return $result; @@ -508,10 +518,10 @@ function _stdin_next() function gets() { do { - $result = fgets(it::$stdin); + $result = fgets($GLOBALS['it_stdin']['fd']); } while (($result === false) && it::_stdin_next()); - it::$stdin_line++; + $GLOBALS['it_stdin']['line']++; return $result; } -- cgit v1.2.3