From a5a19fd672bc0b8113d620669b557f17dccd343a Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Thu, 26 Oct 2006 13:35:12 +0000 Subject: Moved itools to live branch --- itjs.class | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 itjs.class (limited to 'itjs.class') diff --git a/itjs.class b/itjs.class new file mode 100644 index 0000000..ac56032 --- /dev/null +++ b/itjs.class @@ -0,0 +1,131 @@ +$callback("; + $footer = "," . intval($_REQUEST['itjs_callid']) . ")"; + } + + return $header . itjs::encode($values) . $footer; +} + +/* + * Encode the result into a javascript array to transfer and eval() in client + */ +function encode($values) +{ + $texts = ($values === array_values($values)) ? "[]0" : "{}1"; # Numerical or associative array + + $result = $texts{0}; + + foreach ($values as $key => $value) + { + $result .= $separator; + + if ($texts{2}) + { + if (!preg_match('/^[a-z_]\w*$/i', $key)) + $key = "'$key'"; + + $result .= "$key:"; + } + + if (!is_array($value)) + { + $quote = (strval(intval($value)) == strval($value)) ? "" : '"'; + $result .= $quote . strtr($value, array("\0" => '\\0', '"' => '\\"', ""<\\/", "\n" => '\\n', "\r" => '\\r', "\t" => '\\t', "\\" => '\\\\')) . $quote; + } + else + $result .= itjs::encode($value); + + $separator = ",\n"; + } + + $result .= $texts{1}; + + return $result; +} + +function filenames($filelist) +{ + $result = array(); + + $files = array_flip(explode(",", $filelist)); + $itools = array_flip(array("it.js", "loader.js", "state.js", "timer.js")); + $plainfiles = array_flip(array("boot.js", "state.html", "error.gif")); + + if (isset($files['itools'])) + { + unset($files['itools']); + $files = $itools + $files; # Order is important! + } + + foreach (array_keys($files) as $file) + { + if (isset($itools[$file]) || isset($plainfiles[$file])) + $result[] = "/www/server/phpinclude/itools/itjs/$file"; + else + $result[] = $GLOBALS['ULTRAHOME'] . "/itjs/$file"; + } + + return $result; +} + +/** + * Strip comments and trim lines + * @param $code String containing javascript code to be stripped + * @return Naked code + */ +function strip($code) +{ + if (!preg_match("/^devel/", $GLOBALS['ULTRASERVERTYPE'])) + $code = preg_replace(array('|\s//.*$|m', '|/\*.*?\*/|s', '|^\s+|m'), array(), $code); + + return $code; +} + +/** + * Compute checksum for list of files + * @param $files Array of filenames to calculate checksum for + * @return Checksum for given files + */ +function checksum($files = array()) +{ + foreach (array_merge($files, array('itjs.php', 'itjs.class')) as $file) + { + if (!preg_match("/^devel/", $GLOBALS['ULTRASERVERTYPE'])) + $result += @filesize($file); + else + $result = md5($result . @file_get_contents($file)); + } + + return $result; +} + +} + +?> -- cgit v1.2.3