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/
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.
If you include this with the PHP auto_prepend_file ini setting you get the following benefits:
# 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 creates a global function for each common html tag. Those functions accept variable arguments, key=>value pairs are considered attributes.
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"), ), ), );
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.
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); }
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()
echo T('hello') . ' ' . Q($customer->name); echo ET('chainletter', 'name' => Q($customer->name));
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.
ED($foo, $bar); # echoes name and value of $foo and $bar EDC('verbose', $foo);
it.class provides various statically callable functions. The main groups are:
$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");
Helper functions dealing with URLs.
$filename = it_url::get_cache( 'url' => "http://static.php.net/www.php.net/images/php.gif", 'timeout' => 5, 'cachedir' => $_SERVER['DOCUMENT_ROOT'] . "/cache", );
This allows maintaining session cookies and authentication status for users. Not documented yet, check the source.
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.