1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: |
|
19: | defined('XOOPS_ROOT_PATH') || exit('Restricted access');
|
20: |
|
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: |
|
28: | class XoopsFile
|
29: | {
|
30: | |
31: | |
32: |
|
33: | public function __construct()
|
34: | {
|
35: | }
|
36: |
|
37: | |
38: | |
39: | |
40: | |
41: |
|
42: | public function getInstance()
|
43: | {
|
44: | static $instance;
|
45: | if (!isset($instance)) {
|
46: | $class = __CLASS__;
|
47: | $instance = new $class();
|
48: | }
|
49: |
|
50: | return $instance;
|
51: | }
|
52: |
|
53: | |
54: | |
55: | |
56: | |
57: | |
58: | |
59: |
|
60: | public static function load($name = 'file')
|
61: | {
|
62: | switch ($name) {
|
63: | case 'folder':
|
64: | if (!class_exists('XoopsFolderHandler')) {
|
65: | if (file_exists($folder = __DIR__ . '/folder.php')) {
|
66: | include $folder;
|
67: | } else {
|
68: | trigger_error('Require Item : ' . str_replace(XOOPS_ROOT_PATH, '', $folder) . ' In File ' . __FILE__ . ' at Line ' . __LINE__, E_USER_WARNING);
|
69: |
|
70: | return false;
|
71: | }
|
72: | }
|
73: | break;
|
74: | case 'file':
|
75: | default:
|
76: | if (!class_exists('XoopsFileHandler')) {
|
77: | if (file_exists($file = __DIR__ . '/file.php')) {
|
78: | include $file;
|
79: | } else {
|
80: | trigger_error('Require File : ' . str_replace(XOOPS_ROOT_PATH, '', $file) . ' In File ' . __FILE__ . ' at Line ' . __LINE__, E_USER_WARNING);
|
81: |
|
82: | return false;
|
83: | }
|
84: | }
|
85: | break;
|
86: | }
|
87: |
|
88: | return true;
|
89: | }
|
90: |
|
91: | |
92: | |
93: | |
94: | |
95: | |
96: | |
97: | |
98: | |
99: |
|
100: | public static function getHandler($name = 'file', $path = false, $create = false, $mode = null)
|
101: | {
|
102: | $handler = null;
|
103: | XoopsFile::load($name);
|
104: | $class = 'Xoops' . ucfirst($name) . 'Handler';
|
105: | if (class_exists($class)) {
|
106: | $handler = new $class($path, $create, $mode);
|
107: | } else {
|
108: | trigger_error('Class ' . $class . ' not exist in File ' . __FILE__ . ' at Line ' . __LINE__, E_USER_WARNING);
|
109: | }
|
110: |
|
111: | return $handler;
|
112: | }
|
113: | }
|
114: | |