1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13: 14: 15:
16: class Legacy_Utils
17: {
18: 19: 20: 21: 22: 23: 24:
25: function checkSystemModules()
26: {
27: $root=&XCube_Root::getSingleton();
28: $systemModules = array_map('trim', explode(',', $root->getSiteConfig('Cube', 'SystemModules')));
29: $recommendedModules = array_map('trim', explode(',', $root->getSiteConfig('Cube', 'RecommendedModules')));
30: $moduleHandler =& xoops_gethandler('module');
31: $uninstalledModules = array();
32: $disabledModules = array();
33: foreach ($systemModules as $systemModule) {
34: if (!empty($systemModule)) {
35: if (!($moduleObject =& $moduleHandler->getByDirname($systemModule))) {
36: $uninstalledModules[] = $systemModule;
37: }
38: elseif (!$moduleObject->get('isactive')) {
39: $disabledModules[] = $systemModule;
40: }
41: }
42: }
43: if (count($uninstalledModules) == 0 && count($disabledModules) == 0) {
44: return true;
45: }
46: else {
47: return array('uninstalled' =>$uninstalledModules, 'disabled'=>$disabledModules, 'recommended'=>$recommendedModules);
48: }
49: }
50:
51: 52: 53: 54: 55: 56:
57: function &createModule($module, $loadConfig=true)
58: {
59: $instance = null;
60:
61:
62:
63:
64: XCube_DelegateUtils::call('Legacy_Utils.CreateModule', new XCube_Ref($instance), $module, $loadConfig);
65:
66: if (is_object($instance) && is_a($instance, 'Legacy_AbstractModule')) {
67: return $instance;
68: }
69:
70: $dirname = $module->get('dirname');
71:
72:
73:
74:
75: $className = ucfirst($dirname) . "_Module";
76: if (!XC_CLASS_EXISTS($className)) {
77: $filePath = XOOPS_ROOT_PATH . "/modules/${dirname}/class/Module.class.php";
78: if (file_exists($filePath)) {
79: require_once $filePath;
80: }
81: }
82:
83: if (XC_CLASS_EXISTS($className)) {
84: $instance = new $className($module, $loadConfig);
85: }
86: else {
87: $instance = new Legacy_ModuleAdapter($module, $loadConfig);
88: }
89:
90: return $instance;
91: }
92:
93: 94: 95: 96: 97: 98:
99: function &createBlockProcedure(&$block)
100: {
101:
102:
103:
104: $retBlock = null;
105:
106:
107:
108:
109: XCube_DelegateUtils::call('Legacy_Utils.CreateBlockProcedure', new XCube_Ref($retBlock), $block);
110:
111: if (is_object($retBlock) && is_a($retBlock, 'Legacy_AbstractBlockProcedure')) {
112: return $retBlock;
113: }
114:
115: $func = $block->get('show_func');
116: if (substr($func, 0, 4) == 'cl::') {
117: $className = ucfirst($block->get('dirname')) . '_' . substr($func, 4);
118: if (!XC_CLASS_EXISTS($className)) {
119: $filePath = XOOPS_ROOT_PATH . '/modules/' . $block->get('dirname') . '/blocks/' . $block->get('func_file');
120: if (!file_exists($filePath)) {
121: $retBlock = new Legacy_BlockProcedureAdapter($block);
122: return $retBlock;
123: }
124:
125: require_once $filePath;
126:
127: if (!XC_CLASS_EXISTS($className)) {
128: $retBlock = new Legacy_BlockProcedureAdapter($block);
129: return $retBlock;
130: }
131: }
132:
133: $retBlock = new $className($block);
134: }
135: else {
136: $retBlock = new Legacy_BlockProcedureAdapter($block);
137: }
138:
139: return $retBlock;
140: }
141:
142: 143: 144:
145: function raiseUserControlEvent()
146: {
147: $root =& XCube_Root::getSingleton();
148: foreach (array_keys($_REQUEST) as $key) {
149: if (strpos($key, 'Legacy_Event_User_') === 0) {
150: $eventName = substr($key, 18);
151: XCube_DelegateUtils::call('Legacy.Event.User.' . $eventName);
152: $root->mContext->mAttributes['userEvent'][$eventName] = true;
153: }
154: }
155: }
156:
157: 158: 159: 160: 161: 162:
163: function convertVersionFromModinfoToInt($version)
164: {
165: return round(100 * floatval($version));
166: }
167:
168: 169: 170: 171: 172:
173: function convertVersionIntToFloat($version)
174: {
175: return round(floatval(intval($version) / 100), 2);
176: }
177:
178: 179: 180: 181: 182: 183: 184:
185: public static function getUid()
186: {
187: $root = XCube_Root::getSingleton();
188: return ($root->mContext->mUser->isInRole('Site.RegisteredUser')) ? $root->mContext->mXoopsUser->get('uid') : 0;
189: }
190:
191: 192: 193: 194: 195: 196: 197:
198: public static function getUserName( $uid)
199: {
200: $name = null;
201: XCube_DelegateUtils::call('Legacy_User.GetUserName', new XCube_Ref($name), $uid);
202: if(! $name){
203: $handler =& xoops_gethandler('member');
204: $user =& $handler->getUser(intval($uid));
205: if($user){
206: $name = $user->getShow('uname');
207: }
208: }
209: return $name;
210: }
211:
212: 213: 214: 215: 216: 217: 218:
219: public static function getDirnameListByTrustDirname( $trustDirname)
220: {
221: $list = array();
222: $cri = new CriteriaCompo();
223: $cri->add(new Criteria('isactive',0,'>'));
224: $cri->add(new Criteria('trust_dirname', $trustDirname));
225: $cri->addSort('weight','ASC');
226: $cri->addSort('mid','ASC');
227: foreach(xoops_gethandler('module')->getObjects($cri) as $module)
228: {
229: $list[] = $module->get('dirname');
230: }
231: return $list;
232: }
233:
234: 235: 236: 237: 238: 239: 240:
241: public static function getTrustDirnameByDirname( $dirname)
242: {
243: $handler =& xoops_gethandler('module');
244: $module =& $handler->getByDirname($dirname);
245: if($module){
246: return $module->get('trust_dirname') ? $module->get('trust_dirname') : null;
247: }
248: }
249:
250: 251: 252: 253: 254: 255: 256: 257: 258:
259: public static function formatPagetitle( $modulename, $pagetitle, $action)
260: {
261: $handler = xoops_gethandler('config');
262: $configArr = $handler->getConfigsByDirname('legacyRender');
263:
264: $replace = array($modulename, $pagetitle, $action);
265: $search = array('{modulename}', '{pagetitle}', '{action}');
266: $ret = str_replace($search, $replace, $configArr['pagetitle']);
267:
268: $ret = (! $modulename) ? preg_replace("/\[modulename\](.*)\[\/modulename\]/U", "", $ret) : preg_replace("/\[modulename\](.*)\[\/modulename\]/U", '$1', $ret);
269: $ret = (! $pagetitle) ? preg_replace("/\[pagetitle\](.*)\[\/pagetitle\]/U", "", $ret) : preg_replace("/\[pagetitle\](.*)\[\/pagetitle\]/U", '$1', $ret);
270: $ret = (! $action) ? preg_replace("/\[action\](.*)\[\/action\]/U", "", $ret) : preg_replace("/\[action\](.*)\[\/action\]/U", '$1', $ret);
271:
272: return $ret;
273: }
274:
275: 276: 277: 278: 279: 280: 281: 282:
283: public static function getModuleHandler( $name, $dirname)
284: {
285: $trustDirname = self::getTrustDirnameByDirname($dirname);
286: if(isset($trustDirname)){
287: $path = XOOPS_TRUST_PATH. '/modules/'. $trustDirname .'/class/handler/' . ucfirst($name) . '.class.php';
288: $className = ucfirst($trustDirname) . '_' . ucfirst($name) . 'Handler';
289: self::_loadClassFile($path,$className);
290:
291: $root =& XCube_Root::getSingleton();
292: $instance = new $className($root->mController->getDB(),$dirname);
293: return $instance;
294: }
295: else{
296: return xoops_getmodulehandler($name, $dirname);
297: }
298: }
299:
300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310:
311: public static function renderUri( $dirname, $dataname=null, $data_id=0, $action=null, $query=null)
312: {
313: $uri = null;
314: if(XCube_Root::getSingleton()->mContext->getXoopsConfig('cool_uri')==true){
315: if(isset($dataname)){
316: if($data_id>0){
317: if(isset($action)){
318: $uri = sprintf('/%s/%s/%d/%s', $dirname, $dataname, $data_id, $action);
319: }
320: else{
321: $uri = sprintf('/%s/%s/%d', $dirname, $dataname, $data_id);
322: }
323: }
324: else{
325: if(isset($action)){
326: $uri = sprintf('/%s/%s/%s', $dirname, $dataname, $action);
327: }
328: else{
329: $uri = sprintf('/%s/%s', $dirname, $dataname);
330: }
331: }
332: }
333: else{
334: if($data_id>0){
335: if(isset($action)){
336: die();
337: }
338: else{
339: $uri = sprintf('/%s/%d', $dirname, $data_id);
340: }
341: }
342: else{
343: if(isset($action)){
344: die();
345: }
346: else{
347: $uri = '/'.$dirname;
348: }
349: }
350: }
351: $uri = (isset($query)) ? XOOPS_URL.$uri.'?'.$query : XOOPS_URL. $uri;
352: }
353: else{
354: XCube_DelegateUtils::call('Module.'.$dirname.'.Global.Event.GetNormalUri', new XCube_Ref($uri), $dirname, $dataname, $data_id, $action, $query);
355:
356: $uri = XOOPS_MODULE_URL. $uri;
357: }
358:
359: return $uri;
360: }
361:
362: 363: 364: 365: 366: 367: 368:
369: public static function getCommonModuleList( $role)
370: {
371: $list = array();
372: $cri = new CriteriaCompo();
373: $cri->add(new Criteria('isactive',0,'>'));
374: $cri->add(new Criteria('role', $role));
375: $cri->addSort('weight','ASC');
376: $cri->addSort('mid','ASC');
377: foreach(xoops_gethandler('module')->getObjects($cri) as $module)
378: {
379: $list[] = $module->get('dirname');
380: }
381: return $list;
382: }
383:
384: 385: 386: 387: 388: 389: 390: 391:
392: private static function _loadClassFile( $path, $class)
393: {
394: if(!file_exists($path))
395: {
396: return false;
397: }
398: require_once $path;
399:
400: return class_exists($class);
401: }
402: }
403:
404: ?>
405: