.
diff --git a/devel-utf8/README b/devel-utf8/README
new file mode 100644
index 0000000..62a2564
--- /dev/null
+++ b/devel-utf8/README
@@ -0,0 +1,200 @@
+ITools - A simple support library for PHP
+=========================================
+Home: http://itools.search.ch/
+License: http://itools.search.ch/itools/live/COPYING
+Installing: svn co http://itools.search.ch/itools/live itools
+Reference: http://itools.search.ch/(function | class | class/function)
+Tutorial video: http://itools.search.ch/2007-11-14-itools-demo.mov
+
+ITools is a collection of PHP functions and classes which make a few common
+tasks in PHP easier. It works in PHP 5 and up.
+
+Our examples omit array() around function parameters and use dangling commas.
+To get that, you can either use our just-in-time syntax converter or use
+our patch for PHP (see http://cschneid.com/php/ for info). To use the syntax
+converter, see the chapter about it_auto_prepend.php below.
+
+it_auto_prepend.php - ITools environment (optional)
+---------------------------------------------------
+If you include this with the PHP auto_prepend_file ini setting you get the
+following benefits:
+a) Includes all the ITools functionality
+b) auto_prepend.php is included for each directory in the include path.
+c) Automatic syntax conversion is enabled if you have a vanilla PHP without
+our syntax patch installed.
+NOTE: This may need manual configuration on shared hosting
+d) An autoloader for classes is installed, you don't need to require any files
+it looks for foo.class if you access class foo).
+e) $GLOBALS['IT_HOME'] is set to one level above the DOCUMENT_ROOT in web
+mode, one level above the script for CLI mode: This allows access to data
+directories from web and CLI mode alike.
+
+Example:
+ # Put this line in .htaccess or httpd.conf to set up ITools environment
+ php_value auto_prepend_file YOUR_PATH_TO_ITOOLS/it_auto_prepend.php
+
+
+it_html - HTML output generation
+--------------------------------
+it_html creates a global function for each common html tag. Those functions
+accept variable arguments, key=>value pairs are considered attributes.
+
+Example:
+ new it_html; # Not necessary if using it_auto_prepend.php
+ echo html(
+ head('title' => "welcome earth"),
+ body(
+ p('style' => "margin:1em",
+ a('href' => U("http://google.com/search", 'q' => "Hello World"), "Hello World"),
+ ),
+ ),
+ );
+
+Functions:
+ new it_html($config) -- create global functions, choose (x)html style
+ div($attributes, $content) -- return a with attributes and content
+ html($params, $content) -- return a but adds correct doctype
+ head($params, $content) -- return a but needs special params
+ select($tags, $options, $selected) -- build a html select from an array
+ tag($tag, $content) -- create arbitrary <$tag>
+ Q($str) -- html encode a value, roughly like htmlentities
+ U($arr) -- create a valid url from strings and key=>value
+ it_html::sanitize($html) -- remove dangerous tags from html code
+
+
+
+it_dbi - Database access
+------------------------
+The dbi object is a simple mysql interface. For each table in your database,
+a class is created automatically. Queries are encoded as arrays which ensures
+correct quoting, see select(). Errors are by default reported within dbi.
+
+Example:
+ it_dbi::createclasses(); # Not necessary if using it_auto_prepend.php
+ $record = new T_Customers('ID' => 'mueller');
+ $record->update('email' => "mueller@spam.com");
+ $response = "Email added for $record->name";
+ # Using Iterators (PHP 5+ only):
+ foreach (new T_Customers as $customer) { ... } # Iterate all customers
+ foreach (new T_Customers('age' => 42) as $customer) { ... }
+ foreach (new T_Customers as $id => $customer) { ... } # $id = $customer->_key
+ # ... you can iterate over any query (also multiple times):
+ $customers->select('age' => 42);
+ foreach ($customers as $customer) { foo($customer); }
+ foreach ($customers as $customer) { bar($customer); }
+
+Functions:
+ it_dbi::createclasses($config) -- create database objects for each table name
+ $t = new Tablename($query) -- return a dbi object, executes optional select
+ $t->select($query) -- read first result of (encoded) query into t.
+ $t->iterate() -- advance to next result
+ $t->update($fields) -- update selected record from key=>value pairs
+ $t->insert($fields) -- insert a new record from key=>value pairs
+ $t->replace($fields) -- replace a new record from key=>value pairs
+ $t->delete($query) -- delete current record or those found by query
+ $t->query($sqlquery) -- execute a raw SQL query on db connection
+
+
+
+it_text - Translation support
+-----------------------------
+it_text finds the best language to use from browser and override settings. It
+then reads texts.php in the format documented in the constructor. You can then
+use T() to translate a label. Unknown labels are reported using it::error()
+
+Example:
+ echo T('hello') . ' ' . Q($customer->name);
+ echo ET('chainletter', 'name' => Q($customer->name));
+
+Functions:
+ new it_text($config) -- read texts. usually called implicitly
+ T($label) -- return translated $label
+ ET($label, $values) -- return translated $label w/ values replaced
+ T_lang() -- returns current language
+ T_set_language($language) -- sets a new language
+ T_exists($label) -- returns whether a label is defined
+
+
+
+it_debug - Debug support
+------------------------
+it_debug is used for debugging. The function ED($foo, $bar) echoes the
+values of $foo and $bar AND prepends it with the names of the variables. EDX()
+does the same and exits. EDC('verbose', $foo) only echoes if
+$GLOBALS['debug_verbose'] is set. it_debug::backtrace() outputs a compact
+stackdump.
+
+Example:
+ ED($foo, $bar); # echoes name and value of $foo and $bar
+ EDC('verbose', $foo);
+
+Functions:
+ ED($args...) -- echoes names and values of all args
+ EDX($args...) -- echoes names and values of all args and exits
+ EDC('foo', $var...) -- echoes only if $GLOBALS['debug_foo'] is set
+ D($args...) -- returns formatted names and values of params
+ it_debug::backtrace($skip) -- prints short backtrace, skipping $skip levels
+
+
+
+it.class - Tool functions
+-------------------------
+it.class provides various statically callable functions. The main groups are:
+a) Much simpler perl regex matching (no delimiters, matches returned directly
+as scalar or array, case insensitive, locale support) and a multi-pattern
+replacement function.
+b) Better error functions: stack and variable dumps added to error messages,
+error messages mailed if display_errors is off. Extra parameter allow the
+filtering of sporadic errors.
+c) Better shell support, specifically a command line parser and an exec
+function that handles quoting.
+
+Example:
+ $from = it::match('From: (.*)', $mail);
+ $page = it::replace('<.*?>' => '', ' +' => ' ', $page);
+ it::error('title'=>"cannot connect", 'id'=>"db"); # suppress sporadic errors
+ it::fatal("internal error");
+ $diff = it::exec("diff -wu {old} {new}", 'old' => $old, 'new' => $new);
+ it::imageconvert('in' => "src.jpg", 'out' => "dst.jpg", 'size' => "80x80");
+
+Functions:
+ it::match($pattern, $subject, $opts) -- find pattern in subject using opts; return matches
+ it::replace($replace, $subject, $opts) -- replace patterns in subject; return result
+ it::error($info) -- print or mail error message
+ it::fatal($info) -- print or mail error message, then exit
+ it::bail($message) -- print message to stderr, exit with errcode
+ it::exec($command, $values) -- execute command, return output
+ it::getopt($usage) -- parse (or print) usage, return options,
+ it::gets() -- fetch next line from stdin or named arg
+ it::imageconvert($params) -- Convert image using ImageMagick convert
+ it::log($fn, $data, $data...) -- Append data (separated by tabs) to log/$fn-$date
+ it::map($expr, $array) -- Apply php expression to array members & return
+
+
+
+it_url - URL handling
+---------------------
+Helper functions dealing with URLs.
+
+Example:
+ $filename = it_url::get_cache(
+ 'url' => "http://static.php.net/www.php.net/images/php.gif",
+ 'timeout' => 5,
+ 'cachedir' => $_SERVER['DOCUMENT_ROOT'] . "/cache",
+ );
+
+Functions:
+ it_url::get($params) -- performs GET/POST requests to web servers
+ it_url::get_cache($params) -- performs GET/POST and caches the result
+
+
+it_user - Session handling
+--------------------------
+This allows maintaining session cookies and authentication status for users.
+Not documented yet, check the source.
+
+it_xml - XML parser
+-------------------
+This will parse an XML string and returns a tree of PHP objects; similar to
+simplexml, supports a streaming mode for huge XML files. Not documented yet,
+check the source.
diff --git a/devel-utf8/auto_prepend.php b/devel-utf8/auto_prepend.php
new file mode 100644
index 0000000..b71acb7
--- /dev/null
+++ b/devel-utf8/auto_prepend.php
@@ -0,0 +1,232 @@
+etext($label, array_map(array("it_html", "Q"), $values), $language) : $GLOBALS['it_text']->text($label, $language);
+}
+
+/**
+ * Return a text in the selected language
+ * Replaces variables of the form {var} with value from argument $values
+ * @param $label Label of text to return
+ * @param $values Associative array containing values to fill in
+ * @param $language Optional language to return text in.
+ * @return Localized text string with variables replaced by their values
+ */
+function ET($label, $values = null, $language = null)
+{
+ it_text::init();
+ return $GLOBALS['it_text']->etext($label, $values, $language);
+}
+
+/**
+ * Change language
+ * @param $language New language to set
+ */
+function T_set_language($language)
+{
+ it_text::init();
+ return $GLOBALS['it_text']->set_language($language);
+}
+
+/**
+ * Get active language
+ * @return currently active language
+ */
+function T_lang()
+{
+ it_text::init();
+ return $GLOBALS['it_text']->get_language();
+}
+
+/**
+ * Get active language
+ * @return default language of browser
+ */
+function T_defaultlang()
+{
+ it_text::init();
+ return $GLOBALS['it_text']->get_defaultlanguage();
+}
+
+/**
+ * Get available languages
+ * @return available languages as langcode => langname
+ */
+function T_languages()
+{
+ it_text::init();
+ return $GLOBALS['it_text']->languages;
+}
+
+/**
+ * Check if a text entry for a specific label exists
+ * @param $label Label to check
+ * @return true if text exists in actual (or supplied) language, false otherwise.
+ */
+function T_exists($label, $language = null)
+{
+ it_text::init();
+ return $GLOBALS['it_text']->text_exists($label, $language);
+}
+
+/**
+ * Return "db4" or "db2" depending on availability
+ */
+function db_version()
+{
+ return in_array("db4", dba_handlers()) ? "db4" : "db2";
+}
+
+
+
+
+/****************** functions for class it_text **********************/
+
+/**
+ * Build an url
+ */
+function U(/* ... */)
+{
+ $args = func_get_args();
+ return call_user_func_array(array('it_html', 'U'), $args);
+}
+
+
+
+
+/************************** other functions ***************************/
+
+/**
+ * Print an error message and end page
+ */
+function fail($text)
+{
+ trigger_error($text, E_USER_ERROR);
+ it::fatal($text);
+}
+
+/**
+ * Global shortcut for $it_debug::debug()
+ * @see it_debug::debug()
+ */
+function debug($text, $level=0)
+{
+ if (isset($GLOBALS['it_debug']))
+ $GLOBALS['it_debug']->debug($text, $level);
+}
+
+/**
+ * Convert a htmlentities-encoded string back to normal
+ */
+function it_htmlentities_decode($string)
+{
+ return strtr($string, array_flip(get_html_translation_table(HTML_ENTITIES)));
+}
+
+/**
+ * Clone an object and return copy, works for all PHP versions
+ */
+function &it_clone(&$object)
+{
+ $result = (is_object($object) && version_compare(zend_version(), 2, '>=')) ? clone($object) : $object;
+ return $result; # PHP internals need a tmp var to return by ref
+}
+
+/**
+ * Experimental PHP taint support, see ftp://ftp.porcupine.org/pub/php/
+ */
+if (function_exists("taint"))
+{
+ function it_untaint($value, $marks = TC_HTML) { untaint($value, $marks); return $value; }
+ function it_taintcheck($value, $marks = TC_HTML) { if (istainted($value) & $marks) { untaint($value, $marks); it::error(it_untaint("it_taintcheck($value, $marks) failed")); } return $value; }
+}
+else
+{
+ define('TC_HTML', 0);
+ define('TC_SHELL', 0);
+ define('TC_MYSQL', 0);
+ define('TC_MYSQLI', 0);
+ define('TC_SELF', 0);
+ define('TC_ALL', 0);
+ define('TC_NONE', 0);
+ function it_untaint($value, $dummy_marks = 0) { return $value; }
+ function it_taintcheck($value, $dummy_marks = 0) { return $value; }
+}
+
+# ULTRAHOME is generated in a safe way
+$GLOBALS['ULTRAHOME'] = it_untaint($GLOBALS['ULTRAHOME'], TC_ALL);
+
+?>
diff --git a/devel-utf8/convertsyntax.php b/devel-utf8/convertsyntax.php
new file mode 100755
index 0000000..282b774
--- /dev/null
+++ b/devel-utf8/convertsyntax.php
@@ -0,0 +1,43 @@
+#!/usr/bin/env php
+changes)
+ {
+ if ($opts['verbose'])
+ echo "$file contains $converter->changes new syntax elements\n";
+
+ $result++;
+ }
+ }
+ else
+ {
+ echo $converter->output;
+
+ if ($opts['verbose'] && $converter->changes)
+ fputs(fopen("php://stderr", "w"), "$converter->changes changes made to $file\n");
+ }
+}
+
+exit($result);
diff --git a/devel-utf8/it.class b/devel-utf8/it.class
new file mode 100644
index 0000000..624f601
--- /dev/null
+++ b/devel-utf8/it.class
@@ -0,0 +1,846 @@
+.
+**
+** it.class - static functions
+*/
+
+class it
+{
+/**
+ * Create config class with static members initialized (e.g. $home).
+ * NOTE: PHP5 ONLY
+ * @param $p Static members to be generated in newly created class
+ * service: Class name of created class (default: from caller path)
+ * home: Home directory of application (default: from caller path)
+ * site: Domain name of application (default: from caller path)
+ * db: Database of application (default: from caller path)
+ */
+static function createconfig($p = array())
+{
+ $stack = debug_backtrace();
+ $filename = $stack[0]['file'];
+ preg_match('!/www/((\w+)[^/]+)!', $filename, $parts);
+
+ $p += array(
+ 'home' => $parts[0],
+ 'site' => $parts[1],
+ 'db' => strtr($parts[1], ".-", "__"),
+ 'service' => $parts[2],
+ );
+
+ if (class_exists($p['service'] . "_tools"))
+ $extends = "extends {$p['service']}_tools ";
+
+ $code = array("class {$p['service']} $extends{");
+
+ foreach ($p as $name => $value)
+ $code[] = "static \$$name = " . var_export($value, true) . ";";
+
+ $code[] = "}";
+ eval(join("\n", $code));
+}
+
+
+/**
+ * Clone an object and return copy, works for all PHP versions
+ */
+static function &cloneobj(&$object)
+{
+ $result = (is_object($object) && version_compare(zend_version(), 2, '>=')) ? clone($object) : $object;
+
+ return $result; # PHP internals need a tmp var to return by ref
+}
+
+
+/**
+ * Append all arguments to a logfile (tab separated). Date will be added to filename and line
+ * @param $name Name of logfile. Will be in log/ of service unless it starts with /
+ * @param $line1 Line to append (varargs)
+ */
+static function log($name /* ... */)
+{
+ $args = func_get_args();
+ $line = date("Y-m-d H:i:s") . "\t" . implode("\t", array_slice($args, 1)) . "\n";
+ $basefn = substr($name, 0, 1) == "/" ? $name : $GLOBALS['ULTRAHOME'] . "/log/$name";
+ $fullfn = $basefn . "-" . date('Ymd');
+
+ if (substr($fullfn, 0, 1) == "/")
+ {
+ if (!file_exists($fullfn))
+ {
+ $tmp = getmypid();
+ @touch("$fullfn.$tmp");
+ @chgrp("$fullfn.$tmp", "www");
+ @rename("$fullfn.$tmp", $fullfn);
+ @unlink($basefn);
+ @symlink($fullfn, $basefn);
+ }
+
+ file_put_contents($fullfn, $line, FILE_APPEND);
+ }
+}
+
+
+/**
+ * Store timings for appending to log/timer_log-* in auto_append.php
+ */
+static function timerlog($label = '')
+{
+ if ($GLOBALS['debug_timerlog'])
+ {
+ $s = $GLOBALS['ULTRATIME'];
+ $e = gettimeofday();
+ $msec= ($e['sec'] - $s['sec']) * 1000 + ($e['usec'] - $s['usec']) / 1000;
+ $GLOBALS['ULTRATIMERLOG'] .= sprintf(" %s:%d", $label, $msec);
+ }
+}
+
+
+/**
+ * Send verbose error report to browser or (if display_errors is off) by email to .diffnotice gods, file owner or SERVER_ADMIN
+ * All params optional. Single string parameter means 'title'.
+ * @param $p['title'] error title, one line
+ * @param $p['body'] error body, multiline
+ * @param $p['to'] comma separated recipient list
+ * @param $p['id'] identifier of error. if given, only subsequent errors of same id will trigger message
+ * @param $p['graceperiod'] number of seconds within which additional errors are ignored if id is set
+ * @param $p['timewindow'] number of seconds after graceperiod within which the second error must occur if id is set
+ * @param $p['backtraceskip'] number of stack levels to drop
+ * @param $p['blockmail'] number of seconds to block mails after having sent a mail [3600]
+ * @param $p['blockmailid'] block mail for $p['blockmail'] seconds with same id. Default: $p['to']
+ * @param $p['omitdebuginfo'] Do not add stack dump, locals and environment to output [false]
+ */
+static function error($p = array(), $body = null, $to = null) # $body and $to deprecated
+{
+ if (!is_array($p))
+ $p = array('title' => $p, 'body' => $body, 'to' => $to);
+
+ if ($_SERVER['REMOTE_ADDR'])
+ $url = ($_SERVER['HTTPS'] ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
+ else
+ $url = $_SERVER['SCRIPT_NAME'];
+
+ $gods = strtr(trim(@file_get_contents($GLOBALS['ULTRAHOME'] . "/.diffnotice")), array("\n"=>', '));
+ if (!$p['to'])
+ unset($p['to']); # allow defaults to kick in
+ $p += array(
+ 'title' => "it::error",
+ 'to' => $gods ? $gods : (get_current_user() ? get_current_user() : $_SERVER['SERVER_ADMIN']),
+ 'graceperiod' => 60,
+ 'timewindow' => 25*3600,
+ 'backtraceskip' => 0,
+ 'blockmail' => 3600,
+ 'omitdebuginfo' => false,
+ );
+ $p += array('blockmailid' => md5($p['to']));
+
+ @mkdir("/tmp/alertdata");
+ @chmod("/tmp/alertdata", 0777);
+
+ $toscreen = ini_get('display_errors') || (defined("STDOUT") && posix_isatty(STDOUT)) || EDC('astwin') || EDC('asdevel');
+ @fseek(STDOUT, 0, SEEK_END); # Work around PHP bug 49819: posix_isatty seeks to start
+
+ if ($toscreen && !it::is_live())
+ $GLOBALS['debug_noredir'] = 1;
+
+ if (!$toscreen) # this error can only be sent by mail: find out if we want to suppress it
+ {
+ if (!$p['id'])
+ $sendmail = true;
+ else
+ {
+ $errstampfn = "/tmp/alertdata/errstamp_" . urlencode($p['id']);
+ $errstampage = time() - @filemtime($errstampfn);
+ $sendmail = $errstampage >= $p['graceperiod'] && $errstampage <= $p['graceperiod'] + $p['timewindow'];
+ if ($errstampage > $p['graceperiod'])
+ {
+ @unlink($errstampfn);
+ @touch($errstampfn);
+ }
+ }
+
+ if ($sendmail)
+ {
+ $lastsentfn = "/tmp/alertdata/lastsent_" . getmyuid() . "." . $p['blockmailid'];
+ $now = time();
+ clearstatcache();
+ $lastsenttime = @filemtime($lastsentfn);