00001 <?php
00013 abstract class SAutoLoad
00014 {
00015 protected static $COMMON_ROOT;
00016 protected static $searchPath = array();
00017 protected static $modules = array();
00018
00024 public static function initialize() {
00025 SAutoLoad::$COMMON_ROOT = dirname(__FILE__);
00026 SAutoLoad::addSearchPath(SAutoLoad::$COMMON_ROOT);
00027 SAutoLoad::addSearchPath(SAutoLoad::$COMMON_ROOT . '/helpers');
00028 SAutoLoad::addSearchPath(SAutoLoad::$COMMON_ROOT . '/content');
00029 }
00030
00038 public static function addSearchPath($path) {
00039 if (!in_array($path, SAutoLoad::$searchPath)) {
00040 array_push(SAutoLoad::$searchPath, $path);
00041 }
00042 }
00043
00048 public static function getSearchPath() {
00049 return SAutoLoad::$searchPath;
00050 }
00051
00056 public static function getModules() {
00057 return SAutoLoad::$modules;
00058 }
00059
00068 public static function isModuleUsed($name) {
00069 return in_array($name, SAutoLoad::$modules);
00070 }
00071
00089 public static function addModule($name) {
00090 $COMMON = SAutoLoad::$COMMON_ROOT;
00091
00092
00093
00094 if (in_array($name, SAutoLoad::$modules)){
00095 return;
00096 }
00097
00098 array_push(SAutoLoad::$modules, $name);
00099
00100 # Switch on the name of the module to decide what to load
00101 switch($name) {
00102 case 'pr2':
00103 $PR2_ROOT = "$COMMON/pr2";
00104 SAutoLoad::addSearchPath("$PR2_ROOT");
00105 SAutoLoad::addSearchPath("$PR2_ROOT/translate");
00106 SAutoLoad::addSearchPath("$PR2_ROOT/template");
00107 SAutoLoad::addSearchPath("$PR2_ROOT/layout");
00108 break;
00109 case 'xforms':
00110 SAutoLoad::addSearchPath("$COMMON/XForms");
00111 SAutoLoad::addSearchPath("$COMMON/XForms/group");
00112 SAutoLoad::addSearchPath("$COMMON/XForms/control");
00113 SAutoLoad::addModule('tk2');
00114 break;
00115 case 'swat':
00116 SAutoLoad::addSearchPath("$COMMON/SWAT");
00117 SAutoLoad::addSearchPath("$COMMON/SWAT/event");
00118 SAutoLoad::addSearchPath("$COMMON/SWAT/session");
00119 SAutoLoad::addSearchPath("$COMMON/SWAT/authDB");
00120 SAutoLoad::addSearchPath("$COMMON/SWAT/auth");
00121 SAutoLoad::addSearchPath("$COMMON/SWAT/questionnaire");
00122 SAutoLoad::addSearchPath("$COMMON/SWAT/model");
00123 SAutoLoad::addSearchPath("$COMMON/SWAT/model2");
00124 SAutoLoad::addModule('tk2');
00125 break;
00126 case 'snap2':
00127 SAutoLoad::addSearchPath("$COMMON/snap2");
00128 SAutoLoad::addSearchPath("$COMMON/snap2/core");
00129 SAutoLoad::addSearchPath("$COMMON/snap2/perm");
00130 SAutoLoad::addSearchPath("$COMMON/snap2/util");
00131 SAutoLoad::addSearchPath("$COMMON/snap2/objects");
00132 SAutoLoad::addSearchPath("$COMMON/snap2/content");
00133 SAutoLoad::addSearchPath("$COMMON/snap2/tk2");
00134 SAutoLoad::addSearchPath("$COMMON/snap2/tk2/previews");
00135 SAutoLoad::addSearchPath("$COMMON/snap2/tk2/editors");
00136 break;
00137 case 'tk2':
00138 SAutoLoad::addSearchPath("$COMMON/tk2");
00139 SAutoLoad::addSearchPath("$COMMON/tk2/actions");
00140 SAutoLoad::addSearchPath("$COMMON/tk2/containers");
00141 SAutoLoad::addSearchPath("$COMMON/tk2/forms");
00142 SAutoLoad::addSearchPath("$COMMON/tk2/components");
00143 SAutoLoad::addSearchPath("$COMMON/tk2/themes");
00144 break;
00145 case 'tsd':
00146 SAutoLoad::addModule('sdr');
00147 SAutoLoad::addModule('sdrservice');
00148 SAutoLoad::addSearchPath("$COMMON/tsd");
00149 break;
00150 case 'sdr':
00151 case 'sdrservice':
00152 SAutoLoad::addSearchPath("$COMMON/sdr/search");
00153 SAutoLoad::addSearchPath("$COMMON/sdr/search/model");
00154 SAutoLoad::addSearchPath("$COMMON/sdr/update");
00155 SAutoLoad::addSearchPath("$COMMON/sdr/update/model");
00156 break;
00157 case 'sdr-ui':
00158 SAutoLoad::addSearchPath("$COMMON/sdr/ui");
00159 SAutoLoad::addSearchPath("$COMMON/sdr/ui/tk");
00160 SAutoLoad::addSearchPath("$COMMON/sdr/ui/translate");
00161 SDRService::init();
00162 break;
00163 case 'models':
00164 SAutoLoad::addSearchPath("$COMMON/models");
00165 SAutoLoad::addSearchPath("$COMMON/models/CSERDmodel");
00166 break;
00167 case 'tcpdf':
00168 require_once("$COMMON/tcpdf/config/lang/eng.php");
00169 require_once("$COMMON/tcpdf/tcpdf.php");
00170 break;
00171 default:
00172 if (SConfig::getOption('common.DISPLAY_WARNINGS')){
00173 SErrorManager::setWarning("No known module named $name");
00174 }
00175 break;
00176 }
00177 }
00178 }
00179
00180
00181 include_once("SErrorManager.php5");
00182 include_once("SCacheManager.php5");
00183
00184 if(isset($_REQUEST['scache'])) {
00185 $clauses = explode(';', $_REQUEST['scache']);
00186 foreach($clauses as $clause) {
00187 preg_match('/(include|page|apc):([a-zA-Z0-9_]+)/', $clause, $matches);
00188 $cache = $matches[1];
00189 $cmd = $matches[2];
00190 if($cache == 'include') {
00191 switch($cmd) {
00192 case 'disable':
00193 print "<!-- Include Cache Disabled -->\n";
00194 SConfig::setDefault('includeCache.enable', false);
00195 break;
00196 case 'clear':
00197 print "<!-- Include Cache Cleared -->\n";
00198 SCacheManager::clearIncludeCache();
00199 break;
00200 }
00201 }
00202 else if($cache == 'apc') {
00203 switch($cmd) {
00204 case 'clear':
00205 print "<!-- APC Cache Cleared -->\n";
00206 apc_clear_cache('system');
00207 break;
00208 case 'stats':
00209 $enabled = (function_exists('apc_cache_info') ? 'enabled' : 'disabled');
00210
00211 print <<<END_HTML
00212 <html>
00213 <head>
00214 <title>APC Info</title>
00215 </head>
00216 <body>
00217 <h1>APC Information</h1>
00218 <p>Status: <b>$enabled</b></p>
00219 <table border="1" cellpadding="2" cellspacing="2">
00220 <tr>
00221 <th>File Name</th>
00222 <th>Hits</th>
00223 <th>Created</th>
00224 <th>Last Access</th>
00225 </tr>
00226 END_HTML;
00227 if($enabled == 'enabled') {
00228 $info = apc_cache_info('system');
00229 foreach($info['cache_list'] as $entry) {
00230 print "<tr><td>$entry[filename]</td><td>$entry[num_hits]</td><td>"
00231 . strftime('%c', $entry['creation_time']) . '</td><td>'
00232 . strftime('%c', $entry['access_time']) . '</td></tr>';
00233 }
00234 }
00235 print '</table></body></html>';
00236 STimer::enable(false);
00237 exit;
00238 }
00239 }
00240 }
00241 }
00242
00243 SCacheManager::loadIncludeCache();
00244
00245
00246
00247
00248
00249
00258 function __autoload($classname) {
00259 $COMMON_SEARCH_PATH = SAutoLoad::getSearchPath();
00260 $DISPLAY_ERRORS = SConfig::getOption('common.DISPLAY_ERRORS');
00261 global $fCache;
00262
00263 if($classname == "")
00264 return true;
00265
00266
00267 foreach($COMMON_SEARCH_PATH as $path) {
00268 $classpath = $path . "/$classname.php5";
00269
00270 if (file_exists($classpath)) {
00271
00272 require($classpath);
00273
00274 SCacheManager::addToIncludeCache($classpath);
00275 return true;
00276 }
00277 }
00278
00279
00280
00281
00282 if (isset($_GET['runTestSuite'])) {
00283 STestReporter::register('SAutoLoad.errorCount', 1);
00284 STestReporter::register('SAutoLoad.error', 'Class ' . $classname . ' not found');
00285 STestReporter::registerStatus(STestReporter::STATUS_ERROR);
00286 }
00287
00288 if ($DISPLAY_ERRORS && (SConfig::getOption('common.ignoreClassLoadErrors') != true)) {
00289
00290 print "<html><head><title>Class Not Found</title><style type=\"text/css\">
00291 .backtrace td { padding: 4px; border: 1px solid black }
00292 .backtrace th { padding: 4px; padding-bottom: 1px}
00293 </style></head><body>";
00294 print("<h1>ShERPA: Class Not Found</h1>"
00295 . "<h3>The class $classname was not found in any of these common search paths:<br />");
00296 foreach($COMMON_SEARCH_PATH as $path) {
00297 print ($path . "<br />");
00298 }
00299 print "<br />";
00300 $fnName = "";
00301 print printBacktrace($fnName);
00302
00303 if (count(SConfig::getNotFound()) > 0) {
00304 print 'Additionally, attempts to look up the following SConfig options failed:<br />';
00305 foreach(SConfig::getNotFound() as $nf) {
00306 print("$nf<br />\n");
00307 }
00308 print("<br />");
00309 }
00310 print "</body></html>";
00311 exit();
00312 } else if (SConfig::getOption('common.ignoreClassLoadErrors') != true){
00313
00314 print("<hr /><h3>This site is temporarily down for maintenance. "
00315 . "Thank you for your patience.</h3><hr />");
00316 exit();
00317 }
00318 }
00319
00320
00329 function printBacktrace(&$place) {
00330 $bt = debug_backtrace();
00331 $collect = "<table style=\"border-collapse: collapse\" class=\"backtrace\"><tr><th>Function</th><th>Line</th><th>File</th></tr>";
00332 for($i = 1; $i < count($bt); $i++) {
00333 $fn = $bt[$i];
00334 if(!isset($fn['file']))
00335 $file = "<none>";
00336 else
00337 $file = $fn['file'];
00338 if($i < count($bt) - 1) {
00339 if(!isset($bt[$i+1]['class']))
00340 $fnName = $bt[$i+1]['function'] . "()";
00341 else
00342 $fnName = $bt[$i+1]['class']."::".$bt[$i+1]['function'] . "()";
00343 }
00344 else {
00345 $fnName = "<global>";
00346 }
00347 if($i == 1)
00348 $place = $fnName;
00349 if(!isset($fn['line']))
00350 $fn['line'] = "???";
00351 $collect .= "<tr><td>$fnName</td><td>$fn[line]</td><td>$file</td></tr>";
00352 }
00353 return $collect;
00354 }
00355
00356
00357
00358 SAutoLoad::initialize();
00359
00360 if(isset($_GET['runTestSuite']))
00361 STestReporter::init();
00362
00363 ?>