1: <?php
2: 3: 4: 5: 6:
7:
8: if (!defined('XOOPS_ROOT_PATH')) exit();
9:
10: class Profile_AssetManager
11: {
12: var $mDirname = "profile";
13: var $mAssetList = array();
14: var $_mCache = array();
15:
16: 17: 18:
19: function Profile_AssetManager()
20: {
21: }
22:
23: 24: 25:
26: function &getSingleton()
27: {
28: static $instance;
29:
30: if (!is_object($instance)) {
31: $instance = new Profile_AssetManager();
32: }
33:
34: return $instance;
35: }
36:
37: 38: 39:
40: function &create($type, $name)
41: {
42: $instance = null;
43:
44:
45:
46:
47: if ($instance === null) {
48: $instance =& $this->_fallbackCreate($type, $name);
49: }
50:
51: $this->_mCache[$type][$name] =& $instance;
52:
53: return $instance;
54: }
55:
56: 57: 58:
59: function &_fallbackCreate($type, $name)
60: {
61: if (isset($this->mAssetList[$type][$name])) {
62: $className = $this->mAssetList[$type][$name]['class'];
63: if (isset($this->mAssetList[$type][$name]['absPath'])) {
64: $filePath = $this->mAssetList[$type][$name]['absPath'];
65: }
66: else {
67: $filePath = XOOPS_MODULE_PATH . "/" . $this->mDirname . "/" . $this->mAssetList[$type][$name]['path'];
68: }
69:
70: $instance =& $this->_createInstance($className, $filePath);
71: }
72: else {
73: switch ($type) {
74: case "filter":
75: $instance =& $this->_createFilter($name);
76: break;
77: case "form":
78: $instance =& $this->_createActionForm($name);
79: break;
80: case "handler":
81: $instance =& $this->_createHandler($name);
82: break;
83: }
84: }
85:
86: return $instance;
87: }
88:
89: 90: 91:
92: function &load($type, $name)
93: {
94: if (isset($this->_mCache[$type][$name])) {
95: return $this->_mCache[$type][$name];
96: }
97:
98: return $this->create($type, $name);
99: }
100:
101: 102: 103:
104: function &_createHandler($name)
105: {
106: return xoops_getmodulehandler($name, $this->mDirname);
107: }
108:
109: 110: 111:
112: function &_createFilter($name)
113: {
114: $entity = $name;
115: $isAdmin = false;
116: $adminToken = "";
117:
118: if (preg_match("/^admin\.([a-z\_]+)$/i", $name, $matches)) {
119: $entity = $matches[1];
120: $isAdmin = true;
121: $adminToken = "Admin_";
122: }
123:
124: $filePath = $this->_getBasePath($isAdmin) . "/forms/" . ucfirst($entity) . "FilterForm.class.php";
125: $className = ucfirst($this->mDirname) . "_${adminToken}" . ucfirst($entity) . "FilterForm";
126:
127: $instance =& $this->_createInstance($className, $filePath);
128:
129: return $instance;
130: }
131:
132: 133: 134:
135: function &_createActionForm($name)
136: {
137: $mode = "";
138: $entity = $name;
139: $isAdmin = false;
140: $adminToken = "";
141:
142: if (preg_match("/^admin\.([a-z\_]+)$/i", $name, $matches)) {
143: $entity = $matches[1];
144: $isAdmin = true;
145: $adminToken = "Admin_";
146: }
147:
148: if (preg_match("/^([^\_]+)\_(.+)$/", $entity, $matches)) {
149: $mode = $matches[1];
150: $entity = $matches[2];
151: }
152:
153: $className = ucfirst($this->mDirname) . "_${adminToken}" . ucfirst($entity) . ucfirst($mode) . "Form";
154: $filePath = $this->_getBasePath($isAdmin) . "/forms/" . ucfirst($entity) . ucfirst($mode) . "Form.class.php";
155:
156: $instance =& $this->_createInstance($className, $filePath);
157:
158: return $instance;
159: }
160:
161: 162: 163:
164: function &_createInstance($className, $filePath)
165: {
166: $instance = null;
167:
168: if (class_exists($className)) {
169: $instance =new $className();
170: return $instance;
171: }
172:
173: if (!file_exists($filePath)) {
174: return $instance;
175: }
176:
177: require_once $filePath;
178:
179: if (class_exists($className)) {
180: $instance =new $className();
181: }
182:
183: return $instance;
184: }
185:
186: 187: 188:
189: function _getBasePath($isAdmin = false)
190: {
191: $filePath = XOOPS_MODULE_PATH . "/" . $this->mDirname;
192: if ($isAdmin) {
193: $filePath .= "/admin";
194: }
195:
196: return $filePath;
197: }
198: }
199:
200: ?>
201: