00001 <?php
00002
00015
00016
00017
00023 function import($class) {
00024 require_once(str_replace('.', '/', $class) . '.inc.php');
00025 }
00026
00032 function pageRequiresInstall() {
00033 $page = Request::getRequestedPage();
00034 return ($page != 'install' && $page != 'help');
00035 }
00036
00041 function initSystem() {
00042 $microTime = Core::microtime();
00043
00044 Registry::set('system.debug.startTime', $microTime);
00045 $notes = array();
00046 Registry::set('system.debug.notes', $notes);
00047
00048 if (Config::getVar('general', 'installed')) {
00049
00050 $conn = &DBConnection::getInstance();
00051
00052 if (!$conn->isConnected()) {
00053 if (Config::getVar('database', 'debug')) {
00054 $dbconn = &$conn->getDBConn();
00055 fatalError('Database connection failed: ' . $dbconn->errorMsg());
00056
00057 } else {
00058 fatalError('Database connection failed!');
00059 }
00060 }
00061 }
00062 }
00063
00064 if (!function_exists('file_get_contents')) {
00065
00066 function file_get_contents($file) {
00067 return join('', file($file));
00068 }
00069 }
00070
00074 function fatalError($reason) {
00075
00076
00077 static $isErrorCondition = null;
00078 static $showStackTrace = false;
00079
00080 if ($isErrorCondition === null) {
00081 $isErrorCondition = true;
00082 $showStackTrace = Config::getVar('debug', 'show_stacktrace');
00083 $isErrorCondition = false;
00084 }
00085
00086 echo "<h1>$reason</h1>";
00087
00088 if ($showStackTrace && checkPhpVersion('4.3.0')) {
00089 echo "<h4>Stack Trace:</h4>\n";
00090 $trace = debug_backtrace();
00091
00092
00093 array_shift($trace);
00094
00095
00096
00097
00098
00099
00100
00101 foreach ($trace as $bt) {
00102 $args = '';
00103 if (isset($bt['args'])) foreach ($bt['args'] as $a) {
00104 if (!empty($args)) {
00105 $args .= ', ';
00106 }
00107 switch (gettype($a)) {
00108 case 'integer':
00109 case 'double':
00110 $args .= $a;
00111 break;
00112 case 'string':
00113 $a = htmlspecialchars(substr($a, 0, 64)).((strlen($a) > 64) ? '...' : '');
00114 $args .= "\"$a\"";
00115 break;
00116 case 'array':
00117 $args .= 'Array('.count($a).')';
00118 break;
00119 case 'object':
00120 $args .= 'Object('.get_class($a).')';
00121 break;
00122 case 'resource':
00123 $args .= 'Resource('.strstr($a, '#').')';
00124 break;
00125 case 'boolean':
00126 $args .= $a ? 'True' : 'False';
00127 break;
00128 case 'NULL':
00129 $args .= 'Null';
00130 break;
00131 default:
00132 $args .= 'Unknown';
00133 }
00134 }
00135 $class = isset($bt['class'])?$bt['class']:'';
00136 $type = isset($bt['type'])?$bt['type']:'';
00137 $function = isset($bt['function'])?$bt['function']:'';
00138 $file = isset($bt['file'])?$bt['file']:'(unknown)';
00139 $line = isset($bt['line'])?$bt['line']:'(unknown)';
00140
00141 echo "<strong>File:</strong> {$file} line {$line}<br />\n";
00142 echo "<strong>Function:</strong> {$class}{$type}{$function}($args)<br />\n";
00143 echo "<br/>\n";
00144 }
00145 }
00146
00147 error_log("OJS: $reason");
00148 die();
00149 }
00150
00156 function checkPhpVersion($version) {
00157 return (version_compare(PHP_VERSION, $version) !== -1);
00158 }
00159
00160 ?>