diff options
author | Christian Schneider | 2007-09-19 14:07:27 +0000 |
---|---|---|
committer | Christian Schneider | 2007-09-19 14:07:27 +0000 |
commit | 7ec6e84231999ddf4cef5928a0530682265432f9 (patch) | |
tree | ebb80f58876c737009b44694353c6678d195f33c /it.class | |
parent | c41569f1acccb73322daaf7ef27afa90343a7484 (diff) | |
download | itools-7ec6e84231999ddf4cef5928a0530682265432f9.tar.gz itools-7ec6e84231999ddf4cef5928a0530682265432f9.tar.bz2 itools-7ec6e84231999ddf4cef5928a0530682265432f9.zip |
Make it.class PHP4 compatible again
Diffstat (limited to 'it.class')
-rw-r--r-- | it.class | 44 |
1 files changed, 27 insertions, 17 deletions
@@ -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; } |