1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class XoopsLoad
24: {
25: 26: 27: 28: 29:
30: protected static $map = array();
31:
32: 33: 34: 35: 36: 37: 38: 39:
40: public static function addMap(array $map)
41: {
42: XoopsLoad::$map = array_merge(XoopsLoad::$map, $map);
43:
44: return XoopsLoad::$map;
45: }
46:
47: 48: 49: 50: 51:
52: public static function getMap()
53: {
54: return XoopsLoad::$map;
55: }
56:
57: 58: 59: 60: 61: 62: 63: 64:
65: public static function load($name, $type = "core")
66: {
67: static $loaded;
68:
69: $lname = strtolower($name);
70:
71: $type = empty($type) ? 'core' : $type;
72: if (isset($loaded[$type][$lname])) {
73: return $loaded[$type][$lname];
74: }
75:
76: if (class_exists($lname, false)) {
77: $loaded[$type][$lname] = true;
78:
79: return true;
80: }
81: switch ($type) {
82: case 'framework':
83: $isloaded = self::loadFramework($lname);
84: break;
85: case 'class':
86: case 'core':
87: $type = 'core';
88: if ($isloaded = self::loadClass($name)) {
89: break;
90: }
91: $isloaded = self::loadCore($lname);
92: break;
93: default:
94: $isloaded = self::loadModule($lname, $type);
95: break;
96: }
97: $loaded[$type][$lname] = $isloaded;
98:
99: return $loaded[$type][$lname];
100: }
101:
102: 103: 104: 105: 106: 107: 108:
109: private static function loadCore($name)
110: {
111: $map = XoopsLoad::$map;
112: if (isset($map[$name])) {
113:
114: require $map[$name];
115: if (class_exists($name) && method_exists($name, '__autoload')) {
116: call_user_func(array($name, '__autoload'));
117: }
118:
119: return true;
120: } elseif (self::fileExists($file = \XoopsBaseConfig::get('root-path') . '/class/' . $name . '.php')) {
121:
122: include_once $file;
123: $class = 'Xoops' . ucfirst($name);
124: if (class_exists($class)) {
125: return $class;
126: } else {
127: trigger_error(
128: 'Class ' . $name . ' not found in file ' . __FILE__ . 'at line ' . __LINE__,
129: E_USER_WARNING
130: );
131: }
132: }
133:
134: return false;
135: }
136:
137: 138: 139: 140: 141: 142: 143:
144: private static function loadFramework($name)
145: {
146: if (!self::fileExists($file = \XoopsBaseConfig::get('root-path') . '/Frameworks/' . $name . '/xoops' . $name . '.php')) {
147: 148: 149: 150: 151: 152: 153:
154: return false;
155: }
156: include $file;
157: $class = 'Xoops' . ucfirst($name);
158: if (class_exists($class, false)) {
159: return $class;
160: }
161:
162: return false;
163: }
164:
165: 166: 167: 168: 169: 170: 171: 172:
173: private static function loadModule($name, $dirname = null)
174: {
175: if (empty($dirname)) {
176: return false;
177: }
178: if (self::fileExists($file = \XoopsBaseConfig::get('root-path') . '/modules/' . $dirname . '/class/' . $name . '.php')) {
179: include $file;
180: if (class_exists(ucfirst($dirname) . ucfirst($name))) {
181: return true;
182: }
183: }
184:
185: return false;
186: }
187:
188: 189: 190: 191: 192: 193:
194: public static function loadCoreConfig()
195: {
196: $xoops_root_path = \XoopsBaseConfig::get('root-path');
197: return array(
198: 'bloggerapi' => $xoops_root_path . '/class/xml/rpc/bloggerapi.php',
199: 'criteria' => $xoops_root_path . '/class/criteria.php',
200: 'criteriacompo' => $xoops_root_path . '/class/criteria.php',
201: 'criteriaelement' => $xoops_root_path . '/class/criteria.php',
202: 'formdhtmltextarea' => $xoops_root_path . '/class/xoopseditor/dhtmltextarea/dhtmltextarea.php',
203: 'formtextarea' => $xoops_root_path . '/class/xoopseditor/textarea/textarea.php',
204: 'htmlawed' => $xoops_root_path . '/class/vendor/htmLawed.php',
205: 'metaweblogapi' => $xoops_root_path . '/class/xml/rpc/metaweblogapi.php',
206: 'movabletypeapi' => $xoops_root_path . '/class/xml/rpc/movabletypeapi.php',
207: 'mytextsanitizer' => $xoops_root_path . '/class/module.textsanitizer.php',
208:
209:
210: 'rssauthorhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
211: 'rsscategoryhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
212: 'rsscommentshandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
213: 'rsscopyrighthandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
214: 'rssdescriptionhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
215: 'rssdocshandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
216: 'rssgeneratorhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
217: 'rssguidhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
218: 'rssheighthandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
219: 'rssimagehandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
220: 'rssitemhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
221: 'rsslanguagehandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
222: 'rsslastbuilddatehandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
223: 'rsslinkhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
224: 'rssmanagingeditorhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
225: 'rssnamehandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
226: 'rsspubdatehandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
227: 'rsssourcehandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
228: 'rsstextinputhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
229: 'rsstitlehandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
230: 'rssttlhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
231: 'rssurlhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
232: 'rsswebmasterhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
233: 'rsswidthhandler' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
234: 'saxparser' => $xoops_root_path . '/class/xml/saxparser.php',
235:
236: 'snoopy' => $xoops_root_path . '/class/vendor/snoopy.php',
237: 'sqlutility' => $xoops_root_path . '/class/database/sqlutility.php',
238: 'tar' => $xoops_root_path . '/class/class.tar.php',
239: 'xmltaghandler' => $xoops_root_path . '/class/xml/xmltaghandler.php',
240: 'xoopsadminthemefactory' => $xoops_root_path . '/class/theme.php',
241: 'xoopsapi' => $xoops_root_path . '/class/xml/rpc/xoopsapi.php',
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258: 'xoopscaptcha' => $xoops_root_path . '/class/captcha/xoopscaptcha.php',
259: 'xoopscaptchamethod' => $xoops_root_path . '/class/captcha/xoopscaptchamethod.php',
260: 'xoopscaptchaimage' => $xoops_root_path . '/class/captcha/image.php',
261: 'xoopscaptcharecaptcha' => $xoops_root_path . '/class/captcha/recaptcha.php',
262: 'xoopscaptchatext' => $xoops_root_path . '/class/captcha/text.php',
263: 'xoopscaptchaimagehandler' => $xoops_root_path . '/class/captcha/image/scripts/imageclass.php',
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274: 'xoopsdatabase' => $xoops_root_path . '/class/database/database.php',
275:
276:
277: 'xoopsdatabasefactory' => $xoops_root_path . '/class/database/databasefactory.php',
278: 'xoopsdatabasemanager' => $xoops_root_path . '/class/database/manager.php',
279: 'xoopsdownloader' => $xoops_root_path . '/class/downloader.php',
280: 'xoopsmysqldatabase' => $xoops_root_path . '/class/database/mysqldatabase.php',
281: 'xoopsmysqldatabaseproxy' => $xoops_root_path . '/class/database/mysqldatabaseproxy.php',
282: 'xoopsmysqldatabasesafe' => $xoops_root_path . '/class/database/mysqldatabasesafe.php',
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295: 'xoopslists' => $xoops_root_path . '/class/xoopslists.php',
296:
297:
298: 'xoopslogger' => $xoops_root_path . '/class/logger/xoopslogger.php',
299: 'xoopseditor' => $xoops_root_path . '/class/xoopseditor/xoopseditor.php',
300: 'xoopseditorhandler' => $xoops_root_path . '/class/xoopseditor/xoopseditor.php',
301: 'xoopsfile' => $xoops_root_path . '/class/file/xoopsfile.php',
302: 'xoopsfilehandler' => $xoops_root_path . '/class/file/file.php',
303: 'xoopsfilterinput' => $xoops_root_path . '/class/xoopsfilterinput.php',
304: 'xoopsfolderhandler' => $xoops_root_path . '/class/file/folder.php',
305: 'xoopsform' => $xoops_root_path . '/class/xoopsform/form.php',
306: 'xoopsformbutton' => $xoops_root_path . '/class/xoopsform/formbutton.php',
307: 'xoopsformbuttontray' => $xoops_root_path . '/class/xoopsform/formbuttontray.php',
308:
309: 'xoopsformcaptcha' => $xoops_root_path . '/class/xoopsform/formcaptcha.php',
310: 'xoopsformcheckbox' => $xoops_root_path . '/class/xoopsform/formcheckbox.php',
311: 'xoopsformcolorpicker' => $xoops_root_path . '/class/xoopsform/formcolorpicker.php',
312:
313: 'xoopsformdatetime' => $xoops_root_path . '/class/xoopsform/formdatetime.php',
314: 'xoopsformdhtmltextarea' => $xoops_root_path . '/class/xoopsform/formdhtmltextarea.php',
315: 'xoopsformeditor' => $xoops_root_path . '/class/xoopsform/formeditor.php',
316: 'xoopsformelement' => $xoops_root_path . '/class/xoopsform/formelement.php',
317: 'xoopsformelementtray' => $xoops_root_path . '/class/xoopsform/formelementtray.php',
318: 'xoopsformfile' => $xoops_root_path . '/class/xoopsform/formfile.php',
319: 'xoopsformhidden' => $xoops_root_path . '/class/xoopsform/formhidden.php',
320: 'xoopsformhiddentoken' => $xoops_root_path . '/class/xoopsform/formhiddentoken.php',
321: 'xoopsformlabel' => $xoops_root_path . '/class/xoopsform/formlabel.php',
322: 'xoopsformloader' => $xoops_root_path . '/class/xoopsformloader.php',
323: 'xoopsformpassword' => $xoops_root_path . '/class/xoopsform/formpassword.php',
324: 'xoopsformradio' => $xoops_root_path . '/class/xoopsform/formradio.php',
325: 'xoopsformradioyn' => $xoops_root_path . '/class/xoopsform/formradioyn.php',
326:
327: 'xoopsformselect' => $xoops_root_path . '/class/xoopsform/formselect.php',
328: 'xoopsformselectcheckgroup' => $xoops_root_path . '/class/xoopsform/formselectcheckgroup.php',
329: 'xoopsformselectcountry' => $xoops_root_path . '/class/xoopsform/formselectcountry.php',
330: 'xoopsformselecteditor' => $xoops_root_path . '/class/xoopsform/formselecteditor.php',
331: 'xoopsformselectgroup' => $xoops_root_path . '/class/xoopsform/formselectgroup.php',
332: 'xoopsformselectlang' => $xoops_root_path . '/class/xoopsform/formselectlang.php',
333:
334: 'xoopsformselectmatchoption' => $xoops_root_path . '/class/xoopsform/formselectmatchoption.php',
335: 'xoopsformselecttheme' => $xoops_root_path . '/class/xoopsform/formselecttheme.php',
336: 'xoopsformselecttimezone' => $xoops_root_path . '/class/xoopsform/formselecttimezone.php',
337: 'xoopsformselectuser' => $xoops_root_path . '/class/xoopsform/formselectuser.php',
338:
339:
340: 'xoopsformtext' => $xoops_root_path . '/class/xoopsform/formtext.php',
341: 'xoopsformtextarea' => $xoops_root_path . '/class/xoopsform/formtextarea.php',
342: 'xoopsformtextdateselect' => $xoops_root_path . '/class/xoopsform/formtextdateselect.php',
343:
344:
345: 'xoopsgroupformcheckbox' => $xoops_root_path . '/class/xoopsform/grouppermform.php',
346: 'xoopsgrouppermform' => $xoops_root_path . '/class/xoopsform/grouppermform.php',
347:
348: 'xoopsmailer' => $xoops_root_path . '/class/xoopsmailer.php',
349: 'xoopsmediauploader' => $xoops_root_path . '/class/uploader.php',
350:
351:
352:
353:
354:
355:
356:
357: 'xoopsmultimailer' => $xoops_root_path . '/class/xoopsmultimailer.php',
358:
359:
360:
361:
362: 'xoopsobjecttree' => $xoops_root_path . '/class/tree.php',
363:
364:
365: 'xoopspagenav' => $xoops_root_path . '/class/pagenav.php',
366:
367: 'xoopspreload' => $xoops_root_path . '/class/preload.php',
368: 'xoopspreloaditem' => $xoops_root_path . '/class/preload.php',
369:
370:
371:
372:
373:
374: 'xoopsrequest' => $xoops_root_path . '/class/xoopsrequest.php',
375:
376:
377: 'xoopssimpleform' => $xoops_root_path . '/class/xoopsform/simpleform.php',
378: 'xoopstableform' => $xoops_root_path . '/class/xoopsform/tableform.php',
379: 'xoopstardownloader' => $xoops_root_path . '/class/tardownloader.php',
380: 'xoopstheme' => $xoops_root_path . '/class/theme.php',
381: 'xoopsthemeblocksplugin' => $xoops_root_path . '/class/theme_blocks.php',
382: 'xoopsthemefactory' => $xoops_root_path . '/class/theme.php',
383: 'xoopsthemeform' => $xoops_root_path . '/class/xoopsform/themeform.php',
384: 'xoopsthemeplugin' => $xoops_root_path . '/class/theme.php',
385: 'xoopsthemesetparser' => $xoops_root_path . '/class/xml/themesetparser.php',
386:
387:
388:
389:
390:
391:
392:
393: 'xoopsuserutility' => $xoops_root_path . '/class/userutility.php',
394: 'xoopsutility' => $xoops_root_path . '/class/utility/xoopsutility.php',
395: 'xoopsxmlrpcapi' => $xoops_root_path . '/class/xml/rpc/xmlrpcapi.php',
396: 'xoopsxmlrpcarray' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
397: 'xoopsxmlrpcbase64'=> $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
398: 'xoopsxmlrpcboolean' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
399: 'xoopsxmlrpcdatetime' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
400: 'xoopsxmlrpcdocument' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
401: 'xoopsxmlrpcdouble' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
402: 'xoopsxmlrpcfault' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
403: 'xoopsxmlrpcint' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
404: 'xoopsxmlrpcparser' => $xoops_root_path . '/class/xml/rpc/xmlrpcparser.php',
405: 'xoopsxmlrpcrequest' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
406: 'xoopsxmlrpcresponse' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
407: 'xoopsxmlrpcstring' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
408: 'xoopsxmlrpcstruct' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
409: 'xoopsxmlrpctag' => $xoops_root_path . '/class/xml/rpc/xmlrpctag.php',
410: 'xoopsxmlrss2parser' => $xoops_root_path . '/class/xml/rss/xmlrss2parser.php',
411: 'xoopszipdownloader' => $xoops_root_path . '/class/zipdownloader.php',
412: 'zipfile' => $xoops_root_path . '/class/class.zipfile.php',
413: );
414: }
415:
416: 417: 418: 419: 420: 421: 422:
423: public static function loadConfig($data = null)
424: {
425: $xoops = Xoops::getInstance();
426: $configs = array();
427: if (is_array($data)) {
428: $configs = $data;
429: } else {
430: if (!empty($data)) {
431: $dirname = $data;
432: } elseif ($xoops->isModule()) {
433: $dirname = $xoops->module->getVar('dirname', 'n');
434: } else {
435: return false;
436: }
437: if (self::fileExists($file = \XoopsBaseConfig::get('root-path') . '/modules/' . $dirname . '/include/autoload.php')) {
438: if (!$configs = include $file) {
439: return false;
440: }
441: }
442: }
443:
444: return array_merge(XoopsLoad::loadCoreConfig(), $configs);
445: }
446:
447: 448: 449: 450: 451: 452: 453: 454:
455: public static function loadFile($file, $once = true)
456: {
457: self::securityCheck($file);
458: if (self::fileExists($file)) {
459: if ($once) {
460: include_once $file;
461: } else {
462: include $file;
463: }
464:
465: return true;
466: }
467:
468: return false;
469: }
470:
471: 472: 473: 474: 475: 476: 477:
478: public static function loadClass($class)
479: {
480: if (class_exists($class, false) || interface_exists($class, false)) {
481: return true;
482: }
483:
484: $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
485: if (!self::loadFile(\XoopsBaseConfig::get('lib-path') . DIRECTORY_SEPARATOR . $file)) {
486: return false;
487: }
488:
489: if (!class_exists($class, false) && !interface_exists($class, false)) {
490: return false;
491: }
492:
493: if (method_exists($class, '__autoload')) {
494: call_user_func(array($class, '__autoload'));
495: }
496:
497: return true;
498: }
499:
500: 501: 502: 503: 504: 505: 506:
507: public static function fileExists($file)
508: {
509: static $included = array();
510: if (!isset($included[$file])) {
511: $included[$file] = file_exists($file);
512: }
513:
514: return $included[$file];
515: }
516:
517: 518: 519: 520: 521: 522: 523:
524: protected static function securityCheck($filename)
525: {
526: 527: 528:
529: if (preg_match('/[^a-z0-9\\/\\\\_.:-]/i', $filename)) {
530: exit('Security check: Illegal character in filename');
531: }
532: }
533:
534: 535: 536: 537: 538: 539: 540:
541: public static function startAutoloader($path)
542: {
543: static $libPath = null;
544:
545: if ($libPath === null) {
546: $loaderPath = $path . '/vendor/autoload.php';
547: if (self::fileExists($loaderPath)) {
548: $libPath = $path;
549: include $loaderPath;
550: }
551: XoopsLoad::addMap(XoopsLoad::loadCoreConfig());
552: spl_autoload_register(array('XoopsLoad', 'load'));
553: }
554: }
555: }
556: