. */ unset($GLOBALS['IT_SYNTAXCONVERTER_DIR']); # Security measure for register_globals on #$debug_itclassloader = true; it_initialize(); function it_initialize() { static $it_initrecursion; if (!$it_initrecursion++) { $it_path = dirname(__FILE__); if ($webmode = $_SERVER['REMOTE_ADDR']) # Web? { $GLOBALS['ULTRAHOME'] = dirname($_SERVER['DOCUMENT_ROOT']); umask(0002); # Work around bugs.php.net/bug.php?id=28401 $_SERVER['HTTP_HOST'] = strtolower($_SERVER['HTTP_HOST']); } else # Shell $GLOBALS['ULTRAHOME'] = dirname(dirname(preg_match('|^/|', $argv[0]) ? $argv[0] : getcwd() . '/' . $argv[0])); $GLOBALS['IT_HOME'] = $GLOBALS['ULTRAHOME']; # IT_HOME is recommended variable name for applications $needsconvert = !@eval("return is_array(42=>69,);"); # Check if PHP is patched to support our syntax, see http://cschneid.com/php/ if ($needsconvert && !$GLOBALS['IT_SYNTAXCONVERTER_DIR']) { $GLOBALS['IT_SYNTAXCONVERTER_DIR'] = $GLOBALS['IT_HOME'] . "/tmp"; if (!is_writeable($GLOBALS['IT_SYNTAXCONVERTER_DIR']) || getmyuid() != fileowner($GLOBALS['IT_SYNTAXCONVERTER_DIR'])) die(($webmode ? "
" : "") . "Seems to be running in shared environment, manually set\n\$GLOBALS['IT_SYNTAXCONVERTER_DIR'] in $it_path/auto_prepend_local.php\nto either:\n a) FALSE (syntax conversion disabled) or\n b) the path to a writeable directory (NOTE: THIS IS UNSAFE!) or\n c) install the PHP patch from http://cschneid.com/php/\n" . ($webmode ? "" : "")); } else $needsconvert = false; $include_path = ini_get('include_path'); if ($autoloader = function_exists('spl_autoload_register') && spl_autoload_register('it_classloader')) { ini_set('include_path', "$it_path:$include_path"); require_once("$it_path/auto_prepend.php"); if (file_exists("$it_path/auto_prepend_local.php")) require_once("$it_path/auto_prepend_local.php"); } else { ini_set('include_path', "$it_path/..:$include_path"); require("itools.lib"); # PHP 4 fallback } @set_error_handler("it_errorhandler", E_USER_ERROR | E_RECOVERABLE_ERROR | E_WARNING | E_USER_WARNING | E_NOTICE | E_USER_NOTICE); ini_set('include_path', $GLOBALS['IT_SYNTAXCONVERTER_DIR'] . "/it_syntaxconverter:$it_path:$include_path"); $user_includes = explode(":", $include_path); # XXX Note: Comment this out if you want system wide include path converted and auto_prepend.php considered $user_includes = array_diff($user_includes, array_diff(explode(":", get_cfg_var('include_path')), array("."))); foreach (array_reverse($user_includes) as $include) { if ($include == ".") $include = dirname($_SERVER['SCRIPT_FILENAME']); if ($needsconvert) it_convert($include); if (file_exists($autoprepend = "$include/auto_prepend.php")) { if ($needsconvert && ($include != $it_path)) $autoprepend = it_convert($autoprepend); require_once($autoprepend); if (file_exists("$include/auto_prepend_local.php")) require_once("$include/auto_prepend_local.php"); } } if (!isset($GLOBALS['it_html'])) new it_html; if ($needsconvert) { # Convert syntax and start $converted = it_convert($_SERVER['SCRIPT_FILENAME']); /* XXX Disabled as DB not always there if (!$autoloader) # PHP 4 fallback it_dbi::createclasses(); */ require($converted); exit; } } } function it_convert($source) { if (is_dir($source) && !is_link($source)) { foreach (glob("$source/*") as $file) it_convert($file); } else if (is_readable($source)) { $converted = $GLOBALS['IT_SYNTAXCONVERTER_DIR'] . "/it_syntaxconverter/$source"; if (@filemtime($converted) < filemtime($source)) { $converter = new it_syntaxconverter(file_get_contents($source)); $parts = explode("/", dirname($converted)); for ($i = 1; $i <= count($parts); $i++) @mkdir(join("/", array_slice($parts, 0, $i)), 0700); if ($output = fopen($converted, "w")) { fputs($output, $converter->output); fclose($output); } clearstatcache(); } } return $converted; } function it_classloader($classname) { if ($file = @fopen("$classname.class", "r", true)) # Check for file in include path, do not use @include to get failures on inheritance { include("$classname.class"); fclose($file); } else it_dbi::createclass($classname); EDC('ultraclassloader', $classname, it_debug::backtrace()); } function it_errorhandler($errno, $errstr, $errfile, $errline, $errcontext) { if ($result = error_reporting() & $errno) # Is this error enabled? { static $it_errnames = array(); if (!$it_errnames) { foreach (get_defined_constants() as $name => $no) { if (preg_match('/^E_/', $name)) $it_errnames[$no] = "$name: "; } } $error = array( 'title' => $it_errnames[$errno] . $errstr, 'locals' => $errcontext, 'file' => $errfile, 'line' => $errline, 'backtraceskip' => 1, ); switch ($errno) { case E_USER_ERROR: case E_RECOVERABLE_ERROR: it::fatal($error); break; default: it::error($error); break; } } return $result; # True means do not execute standard PHP error handler }