Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like moduleModel often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use moduleModel, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 8 | class moduleModel extends module  | 
            ||
| 9 | { | 
            ||
| 10 | /**  | 
            ||
| 11 | * @brief Initialization  | 
            ||
| 12 | */  | 
            ||
| 13 | function init()  | 
            ||
| 16 | |||
| 17 | /**  | 
            ||
| 18 | * @brief Check if mid, vid are available  | 
            ||
| 19 | */  | 
            ||
| 20 | function isIDExists($id, $site_srl = 0)  | 
            ||
| 21 | 	{ | 
            ||
| 22 | 		if(!preg_match('/^[a-z]{1}([a-z0-9_]+)$/i',$id)) return true; | 
            ||
| 23 | // directory and rss/atom/api reserved checking, etc.  | 
            ||
| 24 | $dirs = FileHandler::readDir(_XE_PATH_);  | 
            ||
| 25 | $dirs[] = 'rss';  | 
            ||
| 26 | $dirs[] = 'atom';  | 
            ||
| 27 | $dirs[] = 'api';  | 
            ||
| 28 | if(in_array($id, $dirs)) return true;  | 
            ||
| 29 | // mid test  | 
            ||
| 30 | $args = new stdClass();  | 
            ||
| 31 | $args->mid = $id;  | 
            ||
| 32 | $args->site_srl = $site_srl;  | 
            ||
| 33 | 		$output = executeQuery('module.isExistsModuleName', $args); | 
            ||
| 34 | if($output->data->count) return true;  | 
            ||
| 35 | // vid test (check mid != vid if site_srl=0, which means it is not a virtual site)  | 
            ||
| 36 | if(!$site_srl)  | 
            ||
| 37 | 		{ | 
            ||
| 38 | $site_args = new stdClass();  | 
            ||
| 39 | $site_args->domain = $id;  | 
            ||
| 40 | 			$output = executeQuery('module.isExistsSiteDomain', $site_args); | 
            ||
| 41 | if($output->data->count) return true;  | 
            ||
| 42 | }  | 
            ||
| 43 | |||
| 44 | return false;  | 
            ||
| 45 | }  | 
            ||
| 46 | |||
| 47 | /**  | 
            ||
| 48 | * @brief Get site information  | 
            ||
| 49 | */  | 
            ||
| 50 | function getSiteInfo($site_srl, $columnList = array())  | 
            ||
| 51 | 	{ | 
            ||
| 52 | $args = new stdClass();  | 
            ||
| 53 | $args->site_srl = $site_srl;  | 
            ||
| 54 | 		$output = executeQuery('module.getSiteInfo', $args, $columnList); | 
            ||
| 55 | return $output->data;  | 
            ||
| 56 | }  | 
            ||
| 57 | |||
| 58 | function getSiteInfoByDomain($domain, $columnList = array())  | 
            ||
| 59 | 	{ | 
            ||
| 60 | $args = new stdClass();  | 
            ||
| 61 | $args->domain = $domain;  | 
            ||
| 62 | 		$output = executeQuery('module.getSiteInfoByDomain', $args, $columnList); | 
            ||
| 63 | return $output->data;  | 
            ||
| 64 | }  | 
            ||
| 65 | |||
| 66 | /**  | 
            ||
| 67 | * @brief Get module information with document_srl  | 
            ||
| 68 | * In this case, it is unable to use the cache file  | 
            ||
| 69 | */  | 
            ||
| 70 | function getModuleInfoByDocumentSrl($document_srl)  | 
            ||
| 71 | 	{ | 
            ||
| 72 | $args = new stdClass();  | 
            ||
| 73 | $args->document_srl = $document_srl;  | 
            ||
| 74 | 		$output = executeQuery('module.getModuleInfoByDocument', $args); | 
            ||
| 75 | $this->applyDefaultSkin($output->data);  | 
            ||
| 76 | return $this->addModuleExtraVars($output->data);  | 
            ||
| 77 | }  | 
            ||
| 78 | |||
| 79 | /**  | 
            ||
| 80 | * @brief Get the default mid according to the domain  | 
            ||
| 81 | */  | 
            ||
| 82 | function getDefaultMid()  | 
            ||
| 83 | 	{ | 
            ||
| 84 | $default_url = Context::getDefaultUrl();  | 
            ||
| 85 | if($default_url && substr_compare($default_url, '/', -1) === 0) $default_url = substr($default_url, 0, -1);  | 
            ||
| 86 | |||
| 87 | $request_url = Context::getRequestUri();  | 
            ||
| 88 | if($request_url && substr_compare($request_url, '/', -1) === 0) $request_url = substr($request_url, 0, -1);  | 
            ||
| 89 | |||
| 90 | $default_url_parse = parse_url($default_url);  | 
            ||
| 91 | $request_url_parse = parse_url($request_url);  | 
            ||
| 92 | 		$vid = Context::get('vid'); | 
            ||
| 93 | 		$mid = Context::get('mid'); | 
            ||
| 94 | |||
| 95 | // Set up  | 
            ||
| 96 | $domain = '';  | 
            ||
| 97 | $site_info = NULL;  | 
            ||
| 98 | if($default_url && $default_url_parse['host'] != $request_url_parse['host'])  | 
            ||
| 99 | 		{ | 
            ||
| 100 | $url_info = parse_url($request_url);  | 
            ||
| 101 | $hostname = $url_info['host'];  | 
            ||
| 102 | $path = $url_info['path'];  | 
            ||
| 103 | View Code Duplication | if(strlen($path) >= 1 && substr_compare($path, '/', -1) === 0) $path = substr($path, 0, -1);  | 
            |
| 104 | |||
| 105 | 			$domain = sprintf('%s%s%s', $hostname, $url_info['port']&&$url_info['port']!=80?':'.$url_info['port']:'',$path); | 
            ||
| 106 | }  | 
            ||
| 107 | |||
| 108 | if($domain === '')  | 
            ||
| 109 | 		{ | 
            ||
| 110 | if(!$vid) $vid = $mid;  | 
            ||
| 111 | if($vid)  | 
            ||
| 112 | 			{ | 
            ||
| 113 | $domain = $vid;  | 
            ||
| 114 | }  | 
            ||
| 115 | }  | 
            ||
| 116 | |||
| 117 | 		$oCacheHandler = CacheHandler::getInstance('object', null, true); | 
            ||
| 118 | // If domain is set, look for subsite  | 
            ||
| 119 | if($domain !== '')  | 
            ||
| 120 | 		{ | 
            ||
| 121 | $site_info = false;  | 
            ||
| 122 | if($oCacheHandler->isSupport())  | 
            ||
| 123 | 			{ | 
            ||
| 124 | $object_key = 'site_info:' . md5($domain);  | 
            ||
| 125 | 				$domain_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); | 
            ||
| 126 | $site_info = $oCacheHandler->get($domain_cache_key);  | 
            ||
| 127 | }  | 
            ||
| 128 | |||
| 129 | if($site_info === false)  | 
            ||
| 130 | 			{ | 
            ||
| 131 | $args = new stdClass();  | 
            ||
| 132 | $args->domain = $domain;  | 
            ||
| 133 | 				$output = executeQuery('module.getSiteInfoByDomain', $args); | 
            ||
| 134 | $site_info = $output->data;  | 
            ||
| 135 | |||
| 136 | if($oCacheHandler->isSupport()) $oCacheHandler->put($domain_cache_key, $site_info);  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 137 | }  | 
            ||
| 138 | |||
| 139 | if($site_info && $vid)  | 
            ||
| 140 | 			{ | 
            ||
| 141 | 				Context::set('vid', $site_info->domain, true); | 
            ||
| 142 | 				if(strtolower($mid)==strtolower($site_info->domain)) Context::set('mid', $site_info->mid,true); | 
            ||
| 143 | }  | 
            ||
| 144 | 			if(!$site_info || !$site_info->domain) { $domain = ''; unset($site_info); } | 
            ||
| 145 | }  | 
            ||
| 146 | |||
| 147 | // If no virtual website was found, get default website  | 
            ||
| 148 | if($domain === '')  | 
            ||
| 149 | 		{ | 
            ||
| 150 | $site_info = false;  | 
            ||
| 151 | if($oCacheHandler->isSupport())  | 
            ||
| 152 | 			{ | 
            ||
| 153 | $object_key = 'default_site';  | 
            ||
| 154 | 				$default_site_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); | 
            ||
| 155 | $site_info = $oCacheHandler->get($default_site_cache_key);  | 
            ||
| 156 | }  | 
            ||
| 157 | |||
| 158 | if($site_info === false)  | 
            ||
| 159 | 			{ | 
            ||
| 160 | $args = new stdClass();  | 
            ||
| 161 | $args->site_srl = 0;  | 
            ||
| 162 | 				$output = executeQuery('module.getSiteInfo', $args); | 
            ||
| 163 | // Update the related informaion if there is no default site info  | 
            ||
| 164 | if(!$output->data)  | 
            ||
| 165 | 				{ | 
            ||
| 166 | // Create a table if sites table doesn't exist  | 
            ||
| 167 | $oDB = &DB::getInstance();  | 
            ||
| 168 | 					if(!$oDB->isTableExists('sites')) $oDB->createTableByXmlFile(_XE_PATH_.'modules/module/schemas/sites.xml'); | 
            ||
| 169 | 					if(!$oDB->isTableExists('sites')) return; | 
            ||
| 170 | |||
| 171 | // Get mid, language  | 
            ||
| 172 | 					$mid_output = $oDB->executeQuery('module.getDefaultMidInfo', $args); | 
            ||
| 173 | $db_info = Context::getDBInfo();  | 
            ||
| 174 | $domain = Context::getDefaultUrl();  | 
            ||
| 175 | $url_info = parse_url($domain);  | 
            ||
| 176 | $domain = $url_info['host'].( (!empty($url_info['port'])&&$url_info['port']!=80)?':'.$url_info['port']:'').$url_info['path'];  | 
            ||
| 177 | |||
| 178 | $site_args = new stdClass;  | 
            ||
| 179 | $site_args->site_srl = 0;  | 
            ||
| 180 | $site_args->index_module_srl = $mid_output->data->module_srl;  | 
            ||
| 181 | $site_args->domain = $domain;  | 
            ||
| 182 | $site_args->default_language = $db_info->lang_type;  | 
            ||
| 183 | |||
| 184 | if($output->data && !$output->data->index_module_srl)  | 
            ||
| 185 | 					{ | 
            ||
| 186 | 						$output = executeQuery('module.updateSite', $site_args); | 
            ||
| 187 | }  | 
            ||
| 188 | else  | 
            ||
| 189 | 					{ | 
            ||
| 190 | 						$output = executeQuery('module.insertSite', $site_args); | 
            ||
| 191 | if(!$output->toBool()) return $output;  | 
            ||
| 192 | }  | 
            ||
| 193 | 					$output = executeQuery('module.getSiteInfo', $args); | 
            ||
| 194 | }  | 
            ||
| 195 | $site_info = $output->data;  | 
            ||
| 196 | if($oCacheHandler->isSupport()) $oCacheHandler->put($default_site_cache_key, $site_info);  | 
            ||
| 197 | }  | 
            ||
| 198 | }  | 
            ||
| 199 | |||
| 200 | if(!$site_info->module_srl) return $site_info;  | 
            ||
| 201 | if(is_array($site_info) && $site_info->data[0]) $site_info = $site_info[0];  | 
            ||
| 202 | return $this->addModuleExtraVars($site_info);  | 
            ||
| 203 | }  | 
            ||
| 204 | |||
| 205 | /**  | 
            ||
| 206 | * @brief Get module information by mid  | 
            ||
| 207 | */  | 
            ||
| 208 | function getModuleInfoByMid($mid, $site_srl = 0, $columnList = array())  | 
            ||
| 209 | 	{ | 
            ||
| 210 | 		if(!$mid || ($mid && !preg_match("/^[a-z][a-z0-9_]+$/i", $mid))) | 
            ||
| 211 | 		{ | 
            ||
| 212 | return;  | 
            ||
| 213 | }  | 
            ||
| 214 | |||
| 215 | $args = new stdClass();  | 
            ||
| 216 | $args->mid = $mid;  | 
            ||
| 217 | $args->site_srl = (int)$site_srl;  | 
            ||
| 218 | |||
| 219 | $module_srl = false;  | 
            ||
| 220 | $module_info = false;  | 
            ||
| 221 | |||
| 222 | 		$oCacheHandler = CacheHandler::getInstance('object', null, true); | 
            ||
| 223 | if($oCacheHandler->isSupport())  | 
            ||
| 224 | 		{ | 
            ||
| 225 | $object_key = 'module_srl:'.$mid.'_'.$site_srl;  | 
            ||
| 226 | 			$module_srl_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); | 
            ||
| 227 | $module_srl = $oCacheHandler->get($module_srl_cache_key);  | 
            ||
| 228 | View Code Duplication | if($module_srl)  | 
            |
| 229 | 			{ | 
            ||
| 230 | $object_key = 'mid_info:' . $module_srl;  | 
            ||
| 231 | 				$module_info_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); | 
            ||
| 232 | $module_info = $oCacheHandler->get($module_info_cache_key);  | 
            ||
| 233 | }  | 
            ||
| 234 | }  | 
            ||
| 235 | |||
| 236 | if($module_info === false)  | 
            ||
| 237 | 		{ | 
            ||
| 238 | 			$output = executeQuery('module.getMidInfo', $args); | 
            ||
| 239 | $module_info = $output->data;  | 
            ||
| 240 | if($oCacheHandler->isSupport())  | 
            ||
| 241 | 			{ | 
            ||
| 242 | $oCacheHandler->put($module_srl_cache_key, $module_info->module_srl);  | 
            ||
| 243 | |||
| 244 | $object_key = 'mid_info:' . $module_info->module_srl;  | 
            ||
| 245 | 				$module_info_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); | 
            ||
| 246 | $oCacheHandler->put($module_info_cache_key, $module_info);  | 
            ||
| 247 | }  | 
            ||
| 248 | }  | 
            ||
| 249 | |||
| 250 | $this->applyDefaultSkin($module_info);  | 
            ||
| 251 | if(!$module_info->module_srl && $module_info->data[0]) $module_info = $module_info->data[0];  | 
            ||
| 252 | return $this->addModuleExtraVars($module_info);  | 
            ||
| 253 | }  | 
            ||
| 254 | |||
| 255 | /**  | 
            ||
| 256 | * Get module info by menu_item_srl.  | 
            ||
| 257 | *  | 
            ||
| 258 | * @params int $menu_item_srl  | 
            ||
| 259 | *  | 
            ||
| 260 | * @return Object $moduleInfo  | 
            ||
| 261 | */  | 
            ||
| 262 | public function getModuleInfoByMenuItemSrl($menu_item_srl = 0)  | 
            ||
| 363 | |||
| 364 | /**  | 
            ||
| 365 | * @brief Get module information corresponding to module_srl  | 
            ||
| 366 | */  | 
            ||
| 367 | function getModuleInfoByModuleSrl($module_srl, $columnList = array())  | 
            ||
| 368 | 	{ | 
            ||
| 369 | $mid_info = false;  | 
            ||
| 370 | |||
| 371 | 		$oCacheHandler = CacheHandler::getInstance('object', null, true); | 
            ||
| 372 | if($oCacheHandler->isSupport())  | 
            ||
| 373 | 		{ | 
            ||
| 374 | $object_key = 'mid_info:' . $module_srl;  | 
            ||
| 375 | 			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); | 
            ||
| 376 | $mid_info = $oCacheHandler->get($cache_key);  | 
            ||
| 377 | }  | 
            ||
| 378 | |||
| 379 | View Code Duplication | if($mid_info === false)  | 
            |
| 380 | 		{ | 
            ||
| 381 | // Get data  | 
            ||
| 382 | $args = new stdClass();  | 
            ||
| 383 | $args->module_srl = $module_srl;  | 
            ||
| 384 | 			$output = executeQuery('module.getMidInfo', $args); | 
            ||
| 385 | if(!$output->toBool()) return;  | 
            ||
| 386 | |||
| 387 | $mid_info = $output->data;  | 
            ||
| 388 | $this->applyDefaultSkin($mid_info);  | 
            ||
| 389 | if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, $mid_info);  | 
            ||
| 390 | }  | 
            ||
| 391 | |||
| 392 | if($mid_info && count($columnList))  | 
            ||
| 393 | 		{ | 
            ||
| 394 | $module_info = new stdClass();  | 
            ||
| 395 | foreach($mid_info as $key => $item)  | 
            ||
| 396 | 			{ | 
            ||
| 397 | if(in_array($key, $columnList))  | 
            ||
| 398 | 				{ | 
            ||
| 399 | $module_info->$key = $item;  | 
            ||
| 400 | }  | 
            ||
| 401 | }  | 
            ||
| 402 | }  | 
            ||
| 403 | else $module_info = $mid_info;  | 
            ||
| 404 | |||
| 405 | 		$oModuleController = getController('module'); | 
            ||
| 406 | if(isset($module_info->browser_title)) $oModuleController->replaceDefinedLangCode($module_info->browser_title);  | 
            ||
| 407 | |||
| 408 | $this->applyDefaultSkin($module_info);  | 
            ||
| 409 | return $this->addModuleExtraVars($module_info);  | 
            ||
| 410 | }  | 
            ||
| 411 | |||
| 412 | /**  | 
            ||
| 413 | * Apply default skin info  | 
            ||
| 414 | *  | 
            ||
| 415 | * @param stdClass $moduleInfo Module information  | 
            ||
| 416 | */  | 
            ||
| 417 | private function applyDefaultSkin(&$moduleInfo)  | 
            ||
| 418 | 	{ | 
            ||
| 419 | if($moduleInfo->is_skin_fix == 'N')  | 
            ||
| 420 | 		{ | 
            ||
| 421 | $moduleInfo->skin = '/USE_DEFAULT/';  | 
            ||
| 422 | }  | 
            ||
| 423 | |||
| 424 | if($moduleInfo->is_mskin_fix == 'N')  | 
            ||
| 425 | 		{ | 
            ||
| 426 | $moduleInfo->mskin = '/USE_DEFAULT/';  | 
            ||
| 427 | }  | 
            ||
| 428 | }  | 
            ||
| 429 | /**  | 
            ||
| 430 | * @brief Get module information corresponding to layout_srl  | 
            ||
| 431 | */  | 
            ||
| 432 | function getModulesInfoByLayout($layout_srl, $columnList = array())  | 
            ||
| 433 | 	{ | 
            ||
| 434 | // Imported data  | 
            ||
| 435 | $args = new stdClass;  | 
            ||
| 436 | $args->layout_srl = $layout_srl;  | 
            ||
| 437 | 		$output = executeQueryArray('module.getModulesByLayout', $args, $columnList); | 
            ||
| 438 | |||
| 439 | $count = count($output->data);  | 
            ||
| 440 | |||
| 441 | $modules = array();  | 
            ||
| 442 | View Code Duplication | for($i=0;$i<$count;$i++)  | 
            |
| 443 | 		{ | 
            ||
| 444 | $modules[] = $output->data[$i];  | 
            ||
| 445 | }  | 
            ||
| 446 | return $this->addModuleExtraVars($modules);  | 
            ||
| 447 | }  | 
            ||
| 448 | |||
| 449 | /**  | 
            ||
| 450 | * @brief Get module information corresponding to multiple module_srls  | 
            ||
| 451 | */  | 
            ||
| 452 | function getModulesInfo($module_srls, $columnList = array())  | 
            ||
| 453 | 	{ | 
            ||
| 454 | 		if(is_array($module_srls)) $module_srls = implode(',',$module_srls); | 
            ||
| 455 | $args = new stdClass();  | 
            ||
| 456 | $args->module_srls = $module_srls;  | 
            ||
| 457 | 		$output = executeQueryArray('module.getModulesInfo', $args, $columnList); | 
            ||
| 458 | if(!$output->toBool()) return;  | 
            ||
| 459 | return $this->addModuleExtraVars($output->data);  | 
            ||
| 460 | }  | 
            ||
| 461 | |||
| 462 | /**  | 
            ||
| 463 | * @brief Add extra vars to the module basic information  | 
            ||
| 464 | */  | 
            ||
| 465 | function addModuleExtraVars($module_info)  | 
            ||
| 466 | 	{ | 
            ||
| 467 | // Process although one or more module informaion is requested  | 
            ||
| 468 | if(!is_array($module_info)) $target_module_info = array($module_info);  | 
            ||
| 469 | else $target_module_info = $module_info;  | 
            ||
| 470 | // Get module_srl  | 
            ||
| 471 | $module_srls = array();  | 
            ||
| 472 | foreach($target_module_info as $key => $val)  | 
            ||
| 473 | 		{ | 
            ||
| 474 | $module_srl = $val->module_srl;  | 
            ||
| 475 | if(!$module_srl) continue;  | 
            ||
| 476 | $module_srls[] = $val->module_srl;  | 
            ||
| 477 | }  | 
            ||
| 478 | // Extract extra information of the module and skin  | 
            ||
| 479 | $extra_vars = $this->getModuleExtraVars($module_srls);  | 
            ||
| 480 | if(!count($module_srls) || !count($extra_vars)) return $module_info;  | 
            ||
| 481 | |||
| 482 | foreach($target_module_info as $key => $val)  | 
            ||
| 483 | 		{ | 
            ||
| 484 | if(!$extra_vars[$val->module_srl] || !count($extra_vars[$val->module_srl])) continue;  | 
            ||
| 485 | foreach($extra_vars[$val->module_srl] as $k => $v)  | 
            ||
| 486 | 			{ | 
            ||
| 487 | 				if($target_module_info[$key]->{$k}) continue; | 
            ||
| 488 | 				$target_module_info[$key]->{$k} = $v; | 
            ||
| 489 | }  | 
            ||
| 490 | }  | 
            ||
| 491 | |||
| 492 | if(is_array($module_info)) return $target_module_info;  | 
            ||
| 493 | return $target_module_info[0];  | 
            ||
| 494 | }  | 
            ||
| 495 | |||
| 496 | /**  | 
            ||
| 497 | * @brief Get a complete list of mid, which is created in the DB  | 
            ||
| 498 | */  | 
            ||
| 499 | function getMidList($args = null, $columnList = array())  | 
            ||
| 500 | 	{ | 
            ||
| 501 | $list = false;  | 
            ||
| 502 | 		$oCacheHandler = CacheHandler::getInstance('object', null, true); | 
            ||
| 503 | if($oCacheHandler->isSupport())  | 
            ||
| 504 | 		{ | 
            ||
| 505 | if(count($args) === 1 && isset($args->site_srl))  | 
            ||
| 506 | 			{ | 
            ||
| 507 | $object_key = 'module:mid_list_' . $args->site_srl;  | 
            ||
| 508 | 				$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); | 
            ||
| 509 | $list = $oCacheHandler->get($cache_key);  | 
            ||
| 510 | }  | 
            ||
| 511 | }  | 
            ||
| 512 | |||
| 513 | if($list === false)  | 
            ||
| 514 | 		{ | 
            ||
| 515 | View Code Duplication | if($oCacheHandler->isSupport() && count($args) === 1 && isset($args->site_srl))  | 
            |
| 516 | 			{ | 
            ||
| 517 | $columnList = array();  | 
            ||
| 518 | }  | 
            ||
| 519 | |||
| 520 | 			$output = executeQuery('module.getMidList', $args, $columnList); | 
            ||
| 521 | if(!$output->toBool()) return $output;  | 
            ||
| 522 | $list = $output->data;  | 
            ||
| 523 | |||
| 524 | View Code Duplication | if($oCacheHandler->isSupport() && count($args) === 1 && isset($args->site_srl))  | 
            |
| 525 | 			{ | 
            ||
| 526 | $oCacheHandler->put($cache_key, $list);  | 
            ||
| 527 | }  | 
            ||
| 528 | }  | 
            ||
| 529 | if(!$list) return;  | 
            ||
| 530 | |||
| 531 | if(!is_array($list)) $list = array($list);  | 
            ||
| 532 | |||
| 533 | foreach($list as $val)  | 
            ||
| 534 | 		{ | 
            ||
| 535 | $mid_list[$val->mid] = $val;  | 
            ||
| 536 | }  | 
            ||
| 537 | |||
| 538 | return $mid_list;  | 
            ||
| 539 | }  | 
            ||
| 540 | |||
| 541 | /**  | 
            ||
| 542 | * @brief Get a complete list of module_srl, which is created in the DB  | 
            ||
| 543 | */  | 
            ||
| 544 | function getModuleSrlList($args = null, $columnList = array())  | 
            ||
| 545 | 	{ | 
            ||
| 546 | 		$output = executeQueryArray('module.getMidList', $args, $columnList); | 
            ||
| 547 | if(!$output->toBool()) return $output;  | 
            ||
| 548 | |||
| 549 | $list = $output->data;  | 
            ||
| 550 | if(!$list) return;  | 
            ||
| 551 | |||
| 552 | return $list;  | 
            ||
| 553 | }  | 
            ||
| 554 | |||
| 555 | /**  | 
            ||
| 556 | * @brief Return an array of module_srl corresponding to a mid list  | 
            ||
| 557 | */  | 
            ||
| 558 | function getModuleSrlByMid($mid)  | 
            ||
| 559 | 	{ | 
            ||
| 560 | 		if($mid && !is_array($mid)) $mid = explode(',',$mid); | 
            ||
| 561 | 		if(is_array($mid)) $mid = "'".implode("','",$mid)."'"; | 
            ||
| 562 | |||
| 563 | 		$site_module_info = Context::get('site_module_info'); | 
            ||
| 564 | |||
| 565 | $args = new stdClass;  | 
            ||
| 566 | $args->mid = $mid;  | 
            ||
| 567 | if($site_module_info) $args->site_srl = $site_module_info->site_srl;  | 
            ||
| 568 | 		$output = executeQuery('module.getModuleSrlByMid', $args); | 
            ||
| 569 | if(!$output->toBool()) return $output;  | 
            ||
| 570 | |||
| 571 | $list = $output->data;  | 
            ||
| 572 | if(!$list) return;  | 
            ||
| 573 | if(!is_array($list)) $list = array($list);  | 
            ||
| 574 | |||
| 575 | foreach($list as $key => $val)  | 
            ||
| 576 | 		{ | 
            ||
| 577 | $module_srl_list[] = $val->module_srl;  | 
            ||
| 578 | }  | 
            ||
| 579 | |||
| 580 | return $module_srl_list;  | 
            ||
| 581 | }  | 
            ||
| 582 | |||
| 583 | /**  | 
            ||
| 584 | * @brief Get forward value by the value of act  | 
            ||
| 585 | */  | 
            ||
| 586 | function getActionForward($act)  | 
            ||
| 587 | 	{ | 
            ||
| 588 | $action_forward = false;  | 
            ||
| 589 | // cache controll  | 
            ||
| 590 | 		$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE); | 
            ||
| 591 | if($oCacheHandler->isSupport())  | 
            ||
| 592 | 		{ | 
            ||
| 593 | $cache_key = 'action_forward';  | 
            ||
| 594 | $action_forward = $oCacheHandler->get($cache_key);  | 
            ||
| 595 | }  | 
            ||
| 596 | |||
| 597 | // retrieve and caching all registered action_forward  | 
            ||
| 598 | if($action_forward === false)  | 
            ||
| 599 | 		{ | 
            ||
| 600 | $args = new stdClass();  | 
            ||
| 601 | 			$output = executeQueryArray('module.getActionForward',$args); | 
            ||
| 602 | if(!$output->toBool()) return new stdClass;  | 
            ||
| 603 | if(!$output->data) $output->data = array();  | 
            ||
| 604 | |||
| 605 | $action_forward = array();  | 
            ||
| 606 | foreach($output->data as $item)  | 
            ||
| 607 | 			{ | 
            ||
| 608 | $action_forward[$item->act] = $item;  | 
            ||
| 609 | }  | 
            ||
| 610 | |||
| 611 | if($oCacheHandler->isSupport())  | 
            ||
| 612 | 			{ | 
            ||
| 613 | $oCacheHandler->put($cache_key, $action_forward);  | 
            ||
| 614 | }  | 
            ||
| 615 | }  | 
            ||
| 616 | |||
| 617 | if($action_forward[$act])  | 
            ||
| 618 | 		{ | 
            ||
| 619 | return $action_forward[$act];  | 
            ||
| 620 | }  | 
            ||
| 621 | else  | 
            ||
| 622 | 		{ | 
            ||
| 623 | return new stdClass();  | 
            ||
| 624 | }  | 
            ||
| 625 | }  | 
            ||
| 626 | |||
| 627 | /**  | 
            ||
| 628 | * @brief Get a list of all triggers on the trigger_name  | 
            ||
| 629 | */  | 
            ||
| 630 | function getTriggers($trigger_name, $called_position)  | 
            ||
| 631 | 	{ | 
            ||
| 632 | if(is_null($GLOBALS['__triggers__']))  | 
            ||
| 633 | 		{ | 
            ||
| 634 | $triggers = FALSE;  | 
            ||
| 635 | 			$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE); | 
            ||
| 636 | if($oCacheHandler->isSupport())  | 
            ||
| 637 | 			{ | 
            ||
| 638 | $cache_key = 'triggers';  | 
            ||
| 639 | $triggers = $oCacheHandler->get($cache_key);  | 
            ||
| 640 | }  | 
            ||
| 641 | if($triggers === FALSE)  | 
            ||
| 642 | 			{ | 
            ||
| 643 | 				$output = executeQueryArray('module.getTriggers'); | 
            ||
| 644 | $triggers = $output->data;  | 
            ||
| 645 | if($output->toBool() && $oCacheHandler->isSupport())  | 
            ||
| 646 | 				{ | 
            ||
| 647 | $oCacheHandler->put($cache_key, $triggers);  | 
            ||
| 648 | }  | 
            ||
| 649 | }  | 
            ||
| 650 | foreach($triggers as $item)  | 
            ||
| 651 | 			{ | 
            ||
| 652 | $GLOBALS['__triggers__'][$item->trigger_name][$item->called_position][] = $item;  | 
            ||
| 653 | }  | 
            ||
| 654 | }  | 
            ||
| 655 | |||
| 656 | return $GLOBALS['__triggers__'][$trigger_name][$called_position];  | 
            ||
| 657 | }  | 
            ||
| 658 | |||
| 659 | /**  | 
            ||
| 660 | * @brief Get specific triggers from the trigger_name  | 
            ||
| 661 | */  | 
            ||
| 662 | function getTrigger($trigger_name, $module, $type, $called_method, $called_position)  | 
            ||
| 663 | 	{ | 
            ||
| 664 | $triggers = $this->getTriggers($trigger_name, $called_position);  | 
            ||
| 665 | |||
| 666 | if($triggers && is_array($triggers))  | 
            ||
| 667 | 		{ | 
            ||
| 668 | foreach($triggers as $item)  | 
            ||
| 669 | 			{ | 
            ||
| 670 | if($item->module == $module && $item->type == $type && $item->called_method == $called_method)  | 
            ||
| 671 | 				{ | 
            ||
| 672 | return $item;  | 
            ||
| 673 | }  | 
            ||
| 674 | }  | 
            ||
| 675 | }  | 
            ||
| 676 | |||
| 677 | return NULL;  | 
            ||
| 678 | }  | 
            ||
| 679 | |||
| 680 | /**  | 
            ||
| 681 | * @brief Get module extend  | 
            ||
| 682 | */  | 
            ||
| 683 | function getModuleExtend($parent_module, $type, $kind='')  | 
            ||
| 684 | 	{ | 
            ||
| 685 | $key = $parent_module.'.'.$kind.'.'.$type;  | 
            ||
| 686 | |||
| 687 | $module_extend_info = $this->loadModuleExtends();  | 
            ||
| 688 | if(array_key_exists($key, $module_extend_info))  | 
            ||
| 689 | 		{ | 
            ||
| 690 | return $module_extend_info[$key];  | 
            ||
| 691 | }  | 
            ||
| 692 | |||
| 693 | return false;  | 
            ||
| 694 | }  | 
            ||
| 695 | |||
| 696 | /**  | 
            ||
| 697 | * @brief Get all the module extend  | 
            ||
| 698 | */  | 
            ||
| 699 | function loadModuleExtends()  | 
            ||
| 700 | 	{ | 
            ||
| 701 | $cache_file = './files/config/module_extend.php';  | 
            ||
| 702 | $cache_file = FileHandler::getRealPath($cache_file);  | 
            ||
| 703 | |||
| 704 | if(!isset($GLOBALS['__MODULE_EXTEND__']))  | 
            ||
| 705 | 		{ | 
            ||
| 706 | // check pre install  | 
            ||
| 707 | 			if(file_exists(FileHandler::getRealPath('./files')) && !file_exists($cache_file)) | 
            ||
| 708 | 			{ | 
            ||
| 709 | $arr = array();  | 
            ||
| 710 | 				$output = executeQueryArray('module.getModuleExtend'); | 
            ||
| 711 | if($output->data)  | 
            ||
| 712 | 				{ | 
            ||
| 713 | foreach($output->data as $v)  | 
            ||
| 714 | 					{ | 
            ||
| 715 | 						$arr[] = sprintf("'%s.%s.%s' => '%s'", $v->parent_module, $v->kind, $v->type, $v->extend_module); | 
            ||
| 716 | }  | 
            ||
| 717 | }  | 
            ||
| 718 | |||
| 719 | $str = '<?PHP return array(%s); ?>';  | 
            ||
| 720 | 				$str = sprintf($str, join(',',$arr)); | 
            ||
| 721 | |||
| 722 | FileHandler::writeFile($cache_file, $str);  | 
            ||
| 723 | }  | 
            ||
| 724 | |||
| 725 | |||
| 726 | if(file_exists($cache_file))  | 
            ||
| 727 | 			{ | 
            ||
| 728 | $GLOBALS['__MODULE_EXTEND__'] = include($cache_file);  | 
            ||
| 729 | }  | 
            ||
| 730 | else  | 
            ||
| 731 | 			{ | 
            ||
| 732 | $GLOBALS['__MODULE_EXTEND__'] = array();  | 
            ||
| 733 | }  | 
            ||
| 734 | }  | 
            ||
| 735 | |||
| 736 | return $GLOBALS['__MODULE_EXTEND__'];  | 
            ||
| 737 | }  | 
            ||
| 738 | |||
| 739 | /**  | 
            ||
| 740 | * @brief Get information from conf/info.xml  | 
            ||
| 741 | */  | 
            ||
| 742 | function getModuleInfoXml($module)  | 
            ||
| 743 | 	{ | 
            ||
| 744 | // Get a path of the requested module. Return if not exists.  | 
            ||
| 745 | $module_path = ModuleHandler::getModulePath($module);  | 
            ||
| 746 | if(!$module_path) return;  | 
            ||
| 747 | // Read the xml file for module skin information  | 
            ||
| 748 | 		$xml_file = sprintf("%s/conf/info.xml", $module_path); | 
            ||
| 749 | if(!file_exists($xml_file)) return;  | 
            ||
| 750 | |||
| 751 | $oXmlParser = new XmlParser();  | 
            ||
| 752 | $tmp_xml_obj = $oXmlParser->loadXmlFile($xml_file);  | 
            ||
| 753 | $xml_obj = $tmp_xml_obj->module;  | 
            ||
| 754 | |||
| 755 | if(!$xml_obj) return;  | 
            ||
| 756 | |||
| 757 | // Module Information  | 
            ||
| 758 | $module_info = new stdClass();  | 
            ||
| 759 | if($xml_obj->version && $xml_obj->attrs->version == '0.2')  | 
            ||
| 760 | 		{ | 
            ||
| 761 | // module format 0.2  | 
            ||
| 762 | $module_info->title = $xml_obj->title->body;  | 
            ||
| 763 | $module_info->description = $xml_obj->description->body;  | 
            ||
| 764 | $module_info->version = $xml_obj->version->body;  | 
            ||
| 765 | $module_info->homepage = $xml_obj->link->body;  | 
            ||
| 766 | $module_info->category = $xml_obj->category->body;  | 
            ||
| 767 | if(!$module_info->category) $module_info->category = 'service';  | 
            ||
| 768 | sscanf($xml_obj->date->body, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d);  | 
            ||
| 769 | 			$module_info->date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d); | 
            ||
| 770 | $module_info->license = $xml_obj->license->body;  | 
            ||
| 771 | $module_info->license_link = $xml_obj->license->attrs->link;  | 
            ||
| 772 | |||
| 773 | View Code Duplication | if(!is_array($xml_obj->author)) $author_list[] = $xml_obj->author;  | 
            |
| 774 | else $author_list = $xml_obj->author;  | 
            ||
| 775 | |||
| 776 | View Code Duplication | foreach($author_list as $author)  | 
            |
| 777 | 			{ | 
            ||
| 778 | $author_obj = new stdClass();  | 
            ||
| 779 | $author_obj->name = $author->name->body;  | 
            ||
| 780 | $author_obj->email_address = $author->attrs->email_address;  | 
            ||
| 781 | $author_obj->homepage = $author->attrs->link;  | 
            ||
| 782 | $module_info->author[] = $author_obj;  | 
            ||
| 783 | }  | 
            ||
| 784 | }  | 
            ||
| 785 | else  | 
            ||
| 786 | 		{ | 
            ||
| 787 | // module format 0.1  | 
            ||
| 788 | $module_info->title = $xml_obj->title->body;  | 
            ||
| 789 | $module_info->description = $xml_obj->author->description->body;  | 
            ||
| 790 | $module_info->version = $xml_obj->attrs->version;  | 
            ||
| 791 | $module_info->category = $xml_obj->attrs->category;  | 
            ||
| 792 | if(!$module_info->category) $module_info->category = 'service';  | 
            ||
| 793 | sscanf($xml_obj->author->attrs->date, '%d. %d. %d', $date_obj->y, $date_obj->m, $date_obj->d);  | 
            ||
| 794 | 			$module_info->date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d); | 
            ||
| 795 | $author_obj = new stdClass();  | 
            ||
| 796 | $author_obj->name = $xml_obj->author->name->body;  | 
            ||
| 797 | $author_obj->email_address = $xml_obj->author->attrs->email_address;  | 
            ||
| 798 | $author_obj->homepage = $xml_obj->author->attrs->link;  | 
            ||
| 799 | $module_info->author[] = $author_obj;  | 
            ||
| 800 | }  | 
            ||
| 801 | // Add admin_index by using action information  | 
            ||
| 802 | $action_info = $this->getModuleActionXml($module);  | 
            ||
| 803 | $module_info->admin_index_act = $action_info->admin_index_act;  | 
            ||
| 804 | $module_info->default_index_act = $action_info->default_index_act;  | 
            ||
| 805 | $module_info->setup_index_act = $action_info->setup_index_act;  | 
            ||
| 806 | $module_info->simple_setup_index_act = $action_info->simple_setup_index_act;  | 
            ||
| 807 | |||
| 808 | return $module_info;  | 
            ||
| 809 | }  | 
            ||
| 810 | |||
| 811 | /**  | 
            ||
| 812 | * @brief Return permisson and action data by conf/module.xml in the module  | 
            ||
| 813 | * Cache it because it takes too long to parse module.xml file  | 
            ||
| 814 | * When caching, add codes so to include it directly  | 
            ||
| 815 | * This is apparently good for performance, but not sure about its side-effects  | 
            ||
| 816 | */  | 
            ||
| 817 | function getModuleActionXml($module)  | 
            ||
| 818 | 	{ | 
            ||
| 819 | // Get a path of the requested module. Return if not exists.  | 
            ||
| 820 | $class_path = ModuleHandler::getModulePath($module);  | 
            ||
| 821 | if(!$class_path) return;  | 
            ||
| 822 | |||
| 823 | // Check if module.xml exists in the path. Return if not exist  | 
            ||
| 824 | 		$xml_file = sprintf("%sconf/module.xml", $class_path); | 
            ||
| 825 | if(!file_exists($xml_file)) return;  | 
            ||
| 826 | |||
| 827 | // Check if cached file exists  | 
            ||
| 828 | $cache_file = sprintf(_XE_PATH_ . "files/cache/module_info/%s.%s.%s.php", $module, Context::getLangType(), __XE_VERSION__);  | 
            ||
| 829 | |||
| 830 | // Update if no cache file exists or it is older than xml file  | 
            ||
| 831 | if(!file_exists($cache_file) || filemtime($cache_file) < filemtime($xml_file) || $re_cache)  | 
            ||
| 832 | 		{ | 
            ||
| 833 | $info = new stdClass();  | 
            ||
| 834 | $buff = array(); // /< Set buff variable to use in the cache file  | 
            ||
| 835 | 			$buff[] = '<?php if(!defined("__XE__")) exit();'; | 
            ||
| 836 | $buff[] = '$info = new stdClass;';  | 
            ||
| 837 | $buff['default_index_act'] = '$info->default_index_act = \'%s\';';  | 
            ||
| 838 | $buff['setup_index_act'] = '$info->setup_index_act=\'%s\';';  | 
            ||
| 839 | $buff['simple_setup_index_act'] = '$info->simple_setup_index_act=\'%s\';';  | 
            ||
| 840 | $buff['admin_index_act'] = '$info->admin_index_act = \'%s\';';  | 
            ||
| 841 | |||
| 842 | $xml_obj = XmlParser::loadXmlFile($xml_file); // /< Read xml file and convert it to xml object  | 
            ||
| 843 | |||
| 844 | if(!count($xml_obj->module)) return; // /< Error occurs if module tag doesn't included in the xml  | 
            ||
| 845 | |||
| 846 | $grants = $xml_obj->module->grants->grant; // /< Permission information  | 
            ||
| 847 | $permissions = $xml_obj->module->permissions->permission; // /< Acting permission  | 
            ||
| 848 | $menus = $xml_obj->module->menus->menu;  | 
            ||
| 849 | $actions = $xml_obj->module->actions->action; // /< Action list (required)  | 
            ||
| 850 | |||
| 851 | $default_index = $admin_index = '';  | 
            ||
| 852 | |||
| 853 | // Arrange permission information  | 
            ||
| 854 | if($grants)  | 
            ||
| 855 | 			{ | 
            ||
| 856 | if(is_array($grants)) $grant_list = $grants;  | 
            ||
| 857 | else $grant_list[] = $grants;  | 
            ||
| 858 | |||
| 859 | $info->grant = new stdClass();  | 
            ||
| 860 | $buff[] = '$info->grant = new stdClass;';  | 
            ||
| 861 | foreach($grant_list as $grant)  | 
            ||
| 862 | 				{ | 
            ||
| 863 | $name = $grant->attrs->name;  | 
            ||
| 864 | $default = $grant->attrs->default?$grant->attrs->default:'guest';  | 
            ||
| 865 | $title = $grant->title->body;  | 
            ||
| 866 | |||
| 867 | 					$info->grant->{$name} = new stdClass(); | 
            ||
| 868 | 					$info->grant->{$name}->title = $title; | 
            ||
| 869 | 					$info->grant->{$name}->default = $default; | 
            ||
| 870 | |||
| 871 | 					$buff[] = sprintf('$info->grant->%s = new stdClass;', $name); | 
            ||
| 872 | 					$buff[] = sprintf('$info->grant->%s->title=\'%s\';', $name, $title); | 
            ||
| 873 | 					$buff[] = sprintf('$info->grant->%s->default=\'%s\';', $name, $default); | 
            ||
| 874 | }  | 
            ||
| 875 | }  | 
            ||
| 876 | // Permissions to grant  | 
            ||
| 877 | if($permissions)  | 
            ||
| 878 | 			{ | 
            ||
| 879 | if(is_array($permissions)) $permission_list = $permissions;  | 
            ||
| 880 | else $permission_list[] = $permissions;  | 
            ||
| 881 | |||
| 882 | $buff[] = '$info->permission = new stdClass;';  | 
            ||
| 883 | |||
| 884 | $info->permission = new stdClass();  | 
            ||
| 885 | foreach($permission_list as $permission)  | 
            ||
| 886 | 				{ | 
            ||
| 887 | $action = $permission->attrs->action;  | 
            ||
| 888 | $target = $permission->attrs->target;  | 
            ||
| 889 | |||
| 890 | 					$info->permission->{$action} = $target; | 
            ||
| 891 | |||
| 892 | 					$buff[] = sprintf('$info->permission->%s = \'%s\';', $action, $target); | 
            ||
| 893 | }  | 
            ||
| 894 | }  | 
            ||
| 895 | // for admin menus  | 
            ||
| 896 | if($menus)  | 
            ||
| 897 | 			{ | 
            ||
| 898 | if(is_array($menus)) $menu_list = $menus;  | 
            ||
| 899 | else $menu_list[] = $menus;  | 
            ||
| 900 | |||
| 901 | $buff[] = '$info->menu = new stdClass;';  | 
            ||
| 902 | $info->menu = new stdClass();  | 
            ||
| 903 | foreach($menu_list as $menu)  | 
            ||
| 904 | 				{ | 
            ||
| 905 | $menu_name = $menu->attrs->name;  | 
            ||
| 906 | $menu_title = is_array($menu->title) ? $menu->title[0]->body : $menu->title->body;  | 
            ||
| 907 | $menu_type = $menu->attrs->type;  | 
            ||
| 908 | |||
| 909 | 					$info->menu->{$menu_name} = new stdClass(); | 
            ||
| 910 | 					$info->menu->{$menu_name}->title = $menu_title; | 
            ||
| 911 | 					$info->menu->{$menu_name}->acts = array(); | 
            ||
| 912 | 					$info->menu->{$menu_name}->type = $menu_type; | 
            ||
| 913 | |||
| 914 | 					$buff[] = sprintf('$info->menu->%s = new stdClass;', $menu_name); | 
            ||
| 915 | 					$buff[] = sprintf('$info->menu->%s->title=\'%s\';', $menu_name, $menu_title); | 
            ||
| 916 | 					$buff[] = sprintf('$info->menu->%s->type=\'%s\';', $menu_name, $menu_type); | 
            ||
| 917 | }  | 
            ||
| 918 | }  | 
            ||
| 919 | |||
| 920 | // actions  | 
            ||
| 921 | if($actions)  | 
            ||
| 922 | 			{ | 
            ||
| 923 | if(is_array($actions)) $action_list = $actions;  | 
            ||
| 924 | else $action_list[] = $actions;  | 
            ||
| 925 | |||
| 926 | $buff[] = '$info->action = new stdClass;';  | 
            ||
| 927 | $info->action = new stdClass();  | 
            ||
| 928 | foreach($action_list as $action)  | 
            ||
| 929 | 				{ | 
            ||
| 930 | $name = $action->attrs->name;  | 
            ||
| 931 | |||
| 932 | $type = $action->attrs->type;  | 
            ||
| 933 | $grant = $action->attrs->grant?$action->attrs->grant:'guest';  | 
            ||
| 934 | $standalone = $action->attrs->standalone=='false'?'false':'true';  | 
            ||
| 935 | $ruleset = $action->attrs->ruleset?$action->attrs->ruleset:'';  | 
            ||
| 936 | $method = $action->attrs->method?$action->attrs->method:'';  | 
            ||
| 937 | |||
| 938 | $index = $action->attrs->index;  | 
            ||
| 939 | $admin_index = $action->attrs->admin_index;  | 
            ||
| 940 | $setup_index = $action->attrs->setup_index;  | 
            ||
| 941 | $simple_setup_index = $action->attrs->simple_setup_index;  | 
            ||
| 942 | $menu_index = $action->attrs->menu_index;  | 
            ||
| 943 | |||
| 944 | 					$info->action->{$name} = new stdClass(); | 
            ||
| 945 | 					$info->action->{$name}->type = $type; | 
            ||
| 946 | 					$info->action->{$name}->grant = $grant; | 
            ||
| 947 | 					$info->action->{$name}->standalone = $standalone; | 
            ||
| 948 | 					$info->action->{$name}->ruleset = $ruleset; | 
            ||
| 949 | 					$info->action->{$name}->method = $method; | 
            ||
| 950 | if($action->attrs->menu_name)  | 
            ||
| 951 | 					{ | 
            ||
| 952 | if($menu_index == 'true')  | 
            ||
| 953 | 						{ | 
            ||
| 954 | 							$info->menu->{$action->attrs->menu_name}->index = $name; | 
            ||
| 955 | 							$buff[] = sprintf('$info->menu->%s->index=\'%s\';', $action->attrs->menu_name, $name); | 
            ||
| 956 | }  | 
            ||
| 957 | 						if(is_array($info->menu->{$action->attrs->menu_name}->acts)) | 
            ||
| 958 | 						{ | 
            ||
| 959 | 							$info->menu->{$action->attrs->menu_name}->acts[] = $name; | 
            ||
| 960 | 							$currentKey = array_search($name, $info->menu->{$action->attrs->menu_name}->acts); | 
            ||
| 961 | }  | 
            ||
| 962 | |||
| 963 | 						$buff[] = sprintf('$info->menu->%s->acts[%d]=\'%s\';', $action->attrs->menu_name, $currentKey, $name); | 
            ||
| 964 | $i++;  | 
            ||
| 965 | }  | 
            ||
| 966 | |||
| 967 | 					$buff[] = sprintf('$info->action->%s = new stdClass;', $name); | 
            ||
| 968 | 					$buff[] = sprintf('$info->action->%s->type=\'%s\';', $name, $type); | 
            ||
| 969 | 					$buff[] = sprintf('$info->action->%s->grant=\'%s\';', $name, $grant); | 
            ||
| 970 | 					$buff[] = sprintf('$info->action->%s->standalone=\'%s\';', $name, $standalone); | 
            ||
| 971 | 					$buff[] = sprintf('$info->action->%s->ruleset=\'%s\';', $name, $ruleset); | 
            ||
| 972 | 					$buff[] = sprintf('$info->action->%s->method=\'%s\';', $name, $method); | 
            ||
| 973 | |||
| 974 | if($index=='true')  | 
            ||
| 975 | 					{ | 
            ||
| 976 | $default_index_act = $name;  | 
            ||
| 977 | $info->default_index_act = $name;  | 
            ||
| 978 | }  | 
            ||
| 979 | if($admin_index=='true')  | 
            ||
| 980 | 					{ | 
            ||
| 981 | $admin_index_act = $name;  | 
            ||
| 982 | $info->admin_index_act = $name;  | 
            ||
| 983 | }  | 
            ||
| 984 | if($setup_index=='true')  | 
            ||
| 985 | 					{ | 
            ||
| 986 | $setup_index_act = $name;  | 
            ||
| 987 | $info->setup_index_act = $name;  | 
            ||
| 988 | }  | 
            ||
| 989 | if($simple_setup_index=='true')  | 
            ||
| 990 | 					{ | 
            ||
| 991 | $simple_setup_index_act = $name;  | 
            ||
| 992 | $info->simple_setup_index_act = $name;  | 
            ||
| 993 | }  | 
            ||
| 994 | }  | 
            ||
| 995 | }  | 
            ||
| 996 | $buff['default_index_act'] = sprintf($buff['default_index_act'], $default_index_act);  | 
            ||
| 997 | $buff['setup_index_act'] = sprintf($buff['setup_index_act'], $setup_index_act);  | 
            ||
| 998 | $buff['simple_setup_index_act'] = sprintf($buff['simple_setup_index_act'], $simple_setup_index_act);  | 
            ||
| 999 | $buff['admin_index_act'] = sprintf($buff['admin_index_act'], $admin_index_act);  | 
            ||
| 1000 | |||
| 1001 | $buff[] = 'return $info;';  | 
            ||
| 1002 | |||
| 1003 | $buff = implode(PHP_EOL, $buff);  | 
            ||
| 1004 | |||
| 1005 | FileHandler::writeFile($cache_file, $buff);  | 
            ||
| 1006 | |||
| 1007 | return $info;  | 
            ||
| 1008 | }  | 
            ||
| 1009 | |||
| 1010 | if(file_exists($cache_file)) return include($cache_file);  | 
            ||
| 1011 | }  | 
            ||
| 1012 | |||
| 1013 | /**  | 
            ||
| 1014 | * Get a skin list for js API.  | 
            ||
| 1015 | * return void  | 
            ||
| 1016 | */  | 
            ||
| 1017 | public function getModuleSkinInfoList()  | 
            ||
| 1018 | 	{ | 
            ||
| 1019 | 		$module = Context::get('module_type'); | 
            ||
| 1020 | |||
| 1021 | if($module == 'ARTICLE')  | 
            ||
| 1022 | 		{ | 
            ||
| 1023 | $module = 'page';  | 
            ||
| 1024 | }  | 
            ||
| 1025 | |||
| 1026 | 		$skinType = Context::get('skin_type'); | 
            ||
| 1027 | |||
| 1028 | $path = ModuleHandler::getModulePath($module);  | 
            ||
| 1029 | $dir = ($skinType == 'M') ? 'm.skins' : 'skins';  | 
            ||
| 1030 | $skin_list = $this->getSkins($path, $dir);  | 
            ||
| 1031 | |||
| 1032 | 		$this->add('skin_info_list', $skin_list); | 
            ||
| 1033 | }  | 
            ||
| 1034 | |||
| 1035 | /**  | 
            ||
| 1036 | * @brief Get a list of skins for the module  | 
            ||
| 1037 | * Return file analysis of skin and skin.xml  | 
            ||
| 1038 | */  | 
            ||
| 1039 | function getSkins($path, $dir = 'skins')  | 
            ||
| 1040 | 	{ | 
            ||
| 1041 | if(substr($path, -1) == '/')  | 
            ||
| 1042 | 		{ | 
            ||
| 1043 | $path = substr($path, 0, -1);  | 
            ||
| 1044 | }  | 
            ||
| 1045 | |||
| 1046 | 		$skin_path = sprintf("%s/%s/", $path, $dir); | 
            ||
| 1047 | $list = FileHandler::readDir($skin_path);  | 
            ||
| 1048 | if(!count($list)) return;  | 
            ||
| 1049 | |||
| 1050 | natcasesort($list);  | 
            ||
| 1051 | |||
| 1052 | foreach($list as $skin_name)  | 
            ||
| 1053 | 		{ | 
            ||
| 1054 | if(!is_dir($skin_path . $skin_name))  | 
            ||
| 1055 | 			{ | 
            ||
| 1056 | continue;  | 
            ||
| 1057 | }  | 
            ||
| 1058 | unset($skin_info);  | 
            ||
| 1059 | $skin_info = $this->loadSkinInfo($path, $skin_name, $dir);  | 
            ||
| 1060 | if(!$skin_info)  | 
            ||
| 1061 | 			{ | 
            ||
| 1062 | $skin_info = new stdClass();  | 
            ||
| 1063 | $skin_info->title = $skin_name;  | 
            ||
| 1064 | }  | 
            ||
| 1065 | |||
| 1066 | $skin_list[$skin_name] = $skin_info;  | 
            ||
| 1067 | }  | 
            ||
| 1068 | |||
| 1069 | 		$tmpPath = strtr($path, array('/' => ' ')); | 
            ||
| 1070 | $tmpPath = trim($tmpPath);  | 
            ||
| 1071 | 		$module = array_pop(explode(' ', $tmpPath)); | 
            ||
| 1072 | |||
| 1073 | if($dir == 'skins')  | 
            ||
| 1074 | 		{ | 
            ||
| 1075 | 			$oAdminModel = getAdminModel('admin'); | 
            ||
| 1076 | $themesInfo = $oAdminModel->getThemeList();  | 
            ||
| 1077 | |||
| 1078 | foreach($themesInfo as $themeName => $info)  | 
            ||
| 1079 | 			{ | 
            ||
| 1080 | $skinInfos = $info->skin_infos;  | 
            ||
| 1081 | if(isset($skinInfos[$module]) && $skinInfos[$module]->is_theme)  | 
            ||
| 1082 | 				{ | 
            ||
| 1083 | $themeSkinInfo = $GLOBALS['__ThemeModuleSkin__'][$module]['skins'][$skinInfos[$module]->name];  | 
            ||
| 1084 | $skin_list[$skinInfos[$module]->name] = $themeSkinInfo;  | 
            ||
| 1085 | }  | 
            ||
| 1086 | }  | 
            ||
| 1087 | }  | 
            ||
| 1088 | |||
| 1089 | 		$siteInfo = Context::get('site_module_info'); | 
            ||
| 1090 | 		$oMenuAdminModel = getAdminModel('menu'); | 
            ||
| 1091 | $installedMenuTypes = $oMenuAdminModel->getModuleListInSitemap($siteInfo->site_srl);  | 
            ||
| 1092 | $moduleName = $module;  | 
            ||
| 1093 | if($moduleName === 'page')  | 
            ||
| 1094 | 		{ | 
            ||
| 1095 | $moduleName = 'ARTICLE';  | 
            ||
| 1096 | }  | 
            ||
| 1097 | if(array_key_exists($moduleName, $installedMenuTypes))  | 
            ||
| 1098 | 		{ | 
            ||
| 1099 | if($dir == 'skins')  | 
            ||
| 1100 | 			{ | 
            ||
| 1101 | $type = 'P';  | 
            ||
| 1102 | }  | 
            ||
| 1103 | else  | 
            ||
| 1104 | 			{ | 
            ||
| 1105 | $type = 'M';  | 
            ||
| 1106 | }  | 
            ||
| 1107 | $defaultSkinName = $this->getModuleDefaultSkin($module, $type, $site_info->site_srl);  | 
            ||
| 1108 | |||
| 1109 | if(isset($defaultSkinName))  | 
            ||
| 1110 | 			{ | 
            ||
| 1111 | $defaultSkinInfo = $this->loadSkinInfo($path, $defaultSkinName, $dir);  | 
            ||
| 1112 | |||
| 1113 | $useDefault = new stdClass();  | 
            ||
| 1114 | 				$useDefault->title = Context::getLang('use_site_default_skin') . ' (' . $defaultSkinInfo->title . ')'; | 
            ||
| 1115 | |||
| 1116 | $useDefaultList['/USE_DEFAULT/'] = $useDefault;  | 
            ||
| 1117 | |||
| 1118 | $skin_list = array_merge($useDefaultList, $skin_list);  | 
            ||
| 1119 | }  | 
            ||
| 1120 | }  | 
            ||
| 1121 | |||
| 1122 | return $skin_list;  | 
            ||
| 1123 | }  | 
            ||
| 1124 | |||
| 1125 | /**  | 
            ||
| 1126 | * @brief Get skin information on a specific location  | 
            ||
| 1127 | */  | 
            ||
| 1128 | function loadSkinInfo($path, $skin, $dir = 'skins')  | 
            ||
| 1346 | |||
| 1347 | /**  | 
            ||
| 1348 | * @brief Return the number of modules which are registered on a virtual site  | 
            ||
| 1349 | */  | 
            ||
| 1350 | function getModuleCount($site_srl, $module = null)  | 
            ||
| 1351 | 	{ | 
            ||
| 1352 | $args = new stdClass;  | 
            ||
| 1353 | $args->site_srl = $site_srl;  | 
            ||
| 1354 | if(!is_null($module)) $args->module = $module;  | 
            ||
| 1355 | 		$output = executeQuery('module.getModuleCount', $args); | 
            ||
| 1356 | return $output->data->count;  | 
            ||
| 1357 | }  | 
            ||
| 1358 | |||
| 1359 | /**  | 
            ||
| 1360 | * @brief Return module configurations  | 
            ||
| 1361 | * Global configuration is used to manage board, member and others  | 
            ||
| 1362 | */  | 
            ||
| 1363 | View Code Duplication | function getModuleConfig($module, $site_srl = 0)  | 
            |
| 1364 | 	{ | 
            ||
| 1365 | $config = false;  | 
            ||
| 1366 | // cache controll  | 
            ||
| 1367 | 		$oCacheHandler = CacheHandler::getInstance('object', null, true); | 
            ||
| 1368 | if($oCacheHandler->isSupport())  | 
            ||
| 1369 | 		{ | 
            ||
| 1370 | $object_key = 'module_config:' . $module . '_' . $site_srl;  | 
            ||
| 1371 | 			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); | 
            ||
| 1372 | $config = $oCacheHandler->get($cache_key);  | 
            ||
| 1373 | }  | 
            ||
| 1374 | |||
| 1375 | if($config === false)  | 
            ||
| 1376 | 		{ | 
            ||
| 1377 | if(!$GLOBALS['__ModuleConfig__'][$site_srl][$module])  | 
            ||
| 1378 | 			{ | 
            ||
| 1379 | $args = new stdClass();  | 
            ||
| 1380 | $args->module = $module;  | 
            ||
| 1381 | $args->site_srl = $site_srl;  | 
            ||
| 1382 | 				$output = executeQuery('module.getModuleConfig', $args); | 
            ||
| 1383 | if($output->data->config) $config = unserialize($output->data->config);  | 
            ||
| 1384 | else $config = null;  | 
            ||
| 1385 | |||
| 1386 | //insert in cache  | 
            ||
| 1387 | if($oCacheHandler->isSupport())  | 
            ||
| 1388 | 				{ | 
            ||
| 1389 | $oCacheHandler->put($cache_key, $config);  | 
            ||
| 1390 | }  | 
            ||
| 1391 | $GLOBALS['__ModuleConfig__'][$site_srl][$module] = $config;  | 
            ||
| 1392 | }  | 
            ||
| 1393 | return $GLOBALS['__ModuleConfig__'][$site_srl][$module];  | 
            ||
| 1394 | }  | 
            ||
| 1395 | |||
| 1396 | return $config;  | 
            ||
| 1397 | }  | 
            ||
| 1398 | |||
| 1399 | /**  | 
            ||
| 1400 | * @brief Return the module configuration of mid  | 
            ||
| 1401 | * Manage mid configurations which depend on module  | 
            ||
| 1402 | */  | 
            ||
| 1403 | View Code Duplication | function getModulePartConfig($module, $module_srl)  | 
            |
| 1404 | 	{ | 
            ||
| 1405 | $config = false;  | 
            ||
| 1406 | // cache controll  | 
            ||
| 1407 | 		$oCacheHandler = CacheHandler::getInstance('object', null, true); | 
            ||
| 1408 | if($oCacheHandler->isSupport())  | 
            ||
| 1409 | 		{ | 
            ||
| 1410 | $object_key = 'module_part_config:'.$module.'_'.$module_srl;  | 
            ||
| 1411 | 			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); | 
            ||
| 1412 | $config = $oCacheHandler->get($cache_key);  | 
            ||
| 1413 | }  | 
            ||
| 1414 | |||
| 1415 | if($config === false)  | 
            ||
| 1416 | 		{ | 
            ||
| 1417 | if(!isset($GLOBALS['__ModulePartConfig__'][$module][$module_srl]))  | 
            ||
| 1418 | 			{ | 
            ||
| 1419 | $args = new stdClass();  | 
            ||
| 1420 | $args->module = $module;  | 
            ||
| 1421 | $args->module_srl = $module_srl;  | 
            ||
| 1422 | 				$output = executeQuery('module.getModulePartConfig', $args); | 
            ||
| 1423 | if($output->data->config) $config = unserialize($output->data->config);  | 
            ||
| 1424 | else $config = null;  | 
            ||
| 1425 | |||
| 1426 | //insert in cache  | 
            ||
| 1427 | if($oCacheHandler->isSupport())  | 
            ||
| 1428 | 				{ | 
            ||
| 1429 | $oCacheHandler->put($cache_key, $config);  | 
            ||
| 1430 | }  | 
            ||
| 1431 | $GLOBALS['__ModulePartConfig__'][$module][$module_srl] = $config;  | 
            ||
| 1432 | }  | 
            ||
| 1433 | return $GLOBALS['__ModulePartConfig__'][$module][$module_srl];  | 
            ||
| 1434 | }  | 
            ||
| 1435 | |||
| 1436 | return $config;  | 
            ||
| 1437 | }  | 
            ||
| 1438 | |||
| 1439 | /**  | 
            ||
| 1440 | * @brief Get all of module configurations for each mid  | 
            ||
| 1441 | */  | 
            ||
| 1442 | function getModulePartConfigs($module, $site_srl = 0)  | 
            ||
| 1443 | 	{ | 
            ||
| 1444 | $args = new stdClass();  | 
            ||
| 1445 | $args->module = $module;  | 
            ||
| 1446 | if($site_srl) $args->site_srl = $site_srl;  | 
            ||
| 1447 | 		$output = executeQueryArray('module.getModulePartConfigs', $args); | 
            ||
| 1448 | if(!$output->toBool() || !$output->data) return array();  | 
            ||
| 1449 | |||
| 1450 | foreach($output->data as $key => $val)  | 
            ||
| 1451 | 		{ | 
            ||
| 1452 | $result[$val->module_srl] = unserialize($val->config);  | 
            ||
| 1453 | }  | 
            ||
| 1454 | return $result;  | 
            ||
| 1455 | }  | 
            ||
| 1456 | |||
| 1457 | /**  | 
            ||
| 1458 | * @brief Get a list of module category  | 
            ||
| 1459 | */  | 
            ||
| 1460 | function getModuleCategories($moduleCategorySrl = array())  | 
            ||
| 1461 | 	{ | 
            ||
| 1462 | $args = new stdClass();  | 
            ||
| 1463 | $args->moduleCategorySrl = $moduleCategorySrl;  | 
            ||
| 1464 | // Get data from the DB  | 
            ||
| 1465 | 		$output = executeQuery('module.getModuleCategories', $args); | 
            ||
| 1466 | if(!$output->toBool()) return $output;  | 
            ||
| 1467 | $list = $output->data;  | 
            ||
| 1468 | if(!$list) return;  | 
            ||
| 1469 | if(!is_array($list)) $list = array($list);  | 
            ||
| 1470 | |||
| 1471 | foreach($list as $val)  | 
            ||
| 1472 | 		{ | 
            ||
| 1473 | $category_list[$val->module_category_srl] = $val;  | 
            ||
| 1474 | }  | 
            ||
| 1475 | return $category_list;  | 
            ||
| 1476 | }  | 
            ||
| 1477 | |||
| 1478 | /**  | 
            ||
| 1479 | * @brief Get content from the module category  | 
            ||
| 1480 | */  | 
            ||
| 1481 | function getModuleCategory($module_category_srl)  | 
            ||
| 1482 | 	{ | 
            ||
| 1483 | // Get data from the DB  | 
            ||
| 1484 | $args = new stdClass;  | 
            ||
| 1485 | $args->module_category_srl = $module_category_srl;  | 
            ||
| 1486 | 		$output = executeQuery('module.getModuleCategory', $args); | 
            ||
| 1487 | if(!$output->toBool()) return $output;  | 
            ||
| 1488 | return $output->data;  | 
            ||
| 1489 | }  | 
            ||
| 1490 | |||
| 1491 | /**  | 
            ||
| 1492 | * @brief Get xml information of the module  | 
            ||
| 1493 | */  | 
            ||
| 1494 | function getModulesXmlInfo()  | 
            ||
| 1495 | 	{ | 
            ||
| 1496 | // Get a list of downloaded and installed modules  | 
            ||
| 1497 | 		$searched_list = FileHandler::readDir('./modules'); | 
            ||
| 1498 | $searched_count = count($searched_list);  | 
            ||
| 1499 | if(!$searched_count) return;  | 
            ||
| 1500 | sort($searched_list);  | 
            ||
| 1501 | |||
| 1502 | for($i=0;$i<$searched_count;$i++)  | 
            ||
| 1503 | 		{ | 
            ||
| 1504 | // Module name  | 
            ||
| 1505 | $module_name = $searched_list[$i];  | 
            ||
| 1506 | |||
| 1507 | $path = ModuleHandler::getModulePath($module_name);  | 
            ||
| 1508 | // Get information of the module  | 
            ||
| 1509 | $info = $this->getModuleInfoXml($module_name);  | 
            ||
| 1510 | unset($obj);  | 
            ||
| 1511 | |||
| 1512 | if(!isset($info)) continue;  | 
            ||
| 1513 | $info->module = $module_name;  | 
            ||
| 1514 | $info->created_table_count = $created_table_count;  | 
            ||
| 1515 | $info->table_count = $table_count;  | 
            ||
| 1516 | $info->path = $path;  | 
            ||
| 1517 | $info->admin_index_act = $info->admin_index_act;  | 
            ||
| 1518 | $list[] = $info;  | 
            ||
| 1519 | }  | 
            ||
| 1520 | return $list;  | 
            ||
| 1521 | }  | 
            ||
| 1522 | |||
| 1523 | function checkNeedInstall($module_name)  | 
            ||
| 1524 | 	{ | 
            ||
| 1525 | $oDB = &DB::getInstance();  | 
            ||
| 1526 | $info = null;  | 
            ||
| 1527 | |||
| 1528 | $moduledir = ModuleHandler::getModulePath($module_name);  | 
            ||
| 1529 | if(file_exists(FileHandler::getRealPath($moduledir."schemas")))  | 
            ||
| 1530 | 		{ | 
            ||
| 1531 | $tmp_files = FileHandler::readDir($moduledir."schemas", '/(\.xml)$/');  | 
            ||
| 1532 | $table_count = count($tmp_files);  | 
            ||
| 1533 | // Check if the table is created  | 
            ||
| 1534 | $created_table_count = 0;  | 
            ||
| 1535 | View Code Duplication | for($j=0;$j<count($tmp_files);$j++)  | 
            |
| 1536 | 			{ | 
            ||
| 1537 | 				list($table_name) = explode(".",$tmp_files[$j]); | 
            ||
| 1538 | if($oDB->isTableExists($table_name)) $created_table_count ++;  | 
            ||
| 1539 | }  | 
            ||
| 1540 | // Check if DB is installed  | 
            ||
| 1541 | if($table_count > $created_table_count) return true;  | 
            ||
| 1542 | else return false;  | 
            ||
| 1543 | }  | 
            ||
| 1544 | return false;  | 
            ||
| 1545 | }  | 
            ||
| 1546 | |||
| 1547 | function checkNeedUpdate($module_name)  | 
            ||
| 1548 | 	{ | 
            ||
| 1549 | // Check if it is upgraded to module.class.php on each module  | 
            ||
| 1550 | $oDummy = getModule($module_name, 'class');  | 
            ||
| 1551 | if($oDummy && method_exists($oDummy, "checkUpdate"))  | 
            ||
| 1552 | 		{ | 
            ||
| 1553 | return $oDummy->checkUpdate();  | 
            ||
| 1554 | }  | 
            ||
| 1555 | return false;  | 
            ||
| 1556 | }  | 
            ||
| 1557 | |||
| 1558 | /**  | 
            ||
| 1559 | * @brief Get a type and information of the module  | 
            ||
| 1560 | */  | 
            ||
| 1561 | function getModuleList()  | 
            ||
| 1562 | 	{ | 
            ||
| 1563 | // Create DB Object  | 
            ||
| 1564 | $oDB = &DB::getInstance();  | 
            ||
| 1565 | // Get a list of downloaded and installed modules  | 
            ||
| 1566 | 		$searched_list = FileHandler::readDir('./modules', '/^([a-zA-Z0-9_-]+)$/'); | 
            ||
| 1567 | sort($searched_list);  | 
            ||
| 1568 | |||
| 1569 | $searched_count = count($searched_list);  | 
            ||
| 1570 | if(!$searched_count) return;  | 
            ||
| 1571 | |||
| 1572 | for($i=0;$i<$searched_count;$i++)  | 
            ||
| 1573 | 		{ | 
            ||
| 1574 | // module name  | 
            ||
| 1575 | $module_name = $searched_list[$i];  | 
            ||
| 1576 | |||
| 1577 | $path = ModuleHandler::getModulePath($module_name);  | 
            ||
| 1578 | if(!is_dir(FileHandler::getRealPath($path))) continue;  | 
            ||
| 1579 | |||
| 1580 | // Get the number of xml files to create a table in schemas  | 
            ||
| 1581 | $tmp_files = FileHandler::readDir($path.'schemas', '/(\.xml)$/');  | 
            ||
| 1582 | $table_count = count($tmp_files);  | 
            ||
| 1583 | // Check if the table is created  | 
            ||
| 1584 | $created_table_count = 0;  | 
            ||
| 1585 | View Code Duplication | for($j=0;$j<$table_count;$j++)  | 
            |
| 1586 | 			{ | 
            ||
| 1587 | 				list($table_name) = explode('.',$tmp_files[$j]); | 
            ||
| 1588 | if($oDB->isTableExists($table_name)) $created_table_count ++;  | 
            ||
| 1589 | }  | 
            ||
| 1590 | // Get information of the module  | 
            ||
| 1591 | $info = NULL;  | 
            ||
| 1592 | $info = $this->getModuleInfoXml($module_name);  | 
            ||
| 1593 | |||
| 1594 | if(!$info) continue;  | 
            ||
| 1595 | |||
| 1596 | $info->module = $module_name;  | 
            ||
| 1597 | $info->category = $info->category;  | 
            ||
| 1598 | $info->created_table_count = $created_table_count;  | 
            ||
| 1599 | $info->table_count = $table_count;  | 
            ||
| 1600 | $info->path = $path;  | 
            ||
| 1601 | $info->admin_index_act = $info->admin_index_act;  | 
            ||
| 1602 | // Check if DB is installed  | 
            ||
| 1603 | if($table_count > $created_table_count) $info->need_install = true;  | 
            ||
| 1604 | else $info->need_install = false;  | 
            ||
| 1605 | // Check if it is upgraded to module.class.php on each module  | 
            ||
| 1606 | $oDummy = null;  | 
            ||
| 1607 | $oDummy = getModule($module_name, 'class');  | 
            ||
| 1608 | if($oDummy && method_exists($oDummy, "checkUpdate"))  | 
            ||
| 1609 | 			{ | 
            ||
| 1610 | $info->need_update = $oDummy->checkUpdate();  | 
            ||
| 1611 | }  | 
            ||
| 1612 | else  | 
            ||
| 1613 | 			{ | 
            ||
| 1614 | continue;  | 
            ||
| 1615 | }  | 
            ||
| 1616 | |||
| 1617 | $list[] = $info;  | 
            ||
| 1618 | }  | 
            ||
| 1619 | return $list;  | 
            ||
| 1620 | }  | 
            ||
| 1621 | |||
| 1622 | /**  | 
            ||
| 1623 | * @brief Combine module_srls with domain of sites  | 
            ||
| 1624 | * Because XE DBHandler doesn't support left outer join,  | 
            ||
| 1625 | * it should be as same as $Output->data[]->module_srl.  | 
            ||
| 1626 | */  | 
            ||
| 1627 | function syncModuleToSite(&$data)  | 
            ||
| 1628 | 	{ | 
            ||
| 1629 | if(!$data) return;  | 
            ||
| 1630 | |||
| 1631 | if(is_array($data))  | 
            ||
| 1632 | 		{ | 
            ||
| 1633 | foreach($data as $key => $val)  | 
            ||
| 1634 | 			{ | 
            ||
| 1635 | $module_srls[] = $val->module_srl;  | 
            ||
| 1636 | }  | 
            ||
| 1637 | if(!count($module_srls)) return;  | 
            ||
| 1638 | }  | 
            ||
| 1639 | else  | 
            ||
| 1640 | 		{ | 
            ||
| 1641 | $module_srls[] = $data->module_srl;  | 
            ||
| 1642 | }  | 
            ||
| 1643 | |||
| 1644 | $args = new stdClass();  | 
            ||
| 1645 | 		$args->module_srls = implode(',',$module_srls); | 
            ||
| 1646 | 		$output = executeQueryArray('module.getModuleSites', $args); | 
            ||
| 1647 | if(!$output->data) return array();  | 
            ||
| 1648 | foreach($output->data as $key => $val)  | 
            ||
| 1649 | 		{ | 
            ||
| 1650 | $modules[$val->module_srl] = $val;  | 
            ||
| 1651 | }  | 
            ||
| 1652 | |||
| 1653 | if(is_array($data))  | 
            ||
| 1654 | 		{ | 
            ||
| 1655 | foreach($data as $key => $val)  | 
            ||
| 1656 | 			{ | 
            ||
| 1657 | $data[$key]->domain = $modules[$val->module_srl]->domain;  | 
            ||
| 1658 | }  | 
            ||
| 1659 | }  | 
            ||
| 1660 | else  | 
            ||
| 1661 | 		{ | 
            ||
| 1662 | $data->domain = $modules[$data->module_srl]->domain;  | 
            ||
| 1663 | }  | 
            ||
| 1664 | }  | 
            ||
| 1665 | |||
| 1666 | /**  | 
            ||
| 1667 | * @brief Check if it is an administrator of site_module_info  | 
            ||
| 1668 | */  | 
            ||
| 1669 | function isSiteAdmin($member_info, $site_srl = null)  | 
            ||
| 1670 | 	{ | 
            ||
| 1671 | if(!$member_info->member_srl) return false;  | 
            ||
| 1672 | if($member_info->is_admin == 'Y') return true;  | 
            ||
| 1673 | |||
| 1674 | $args = new stdClass();  | 
            ||
| 1675 | View Code Duplication | if(!isset($site_srl))  | 
            |
| 1676 | 		{ | 
            ||
| 1677 | 			$site_module_info = Context::get('site_module_info'); | 
            ||
| 1678 | if(!$site_module_info) return;  | 
            ||
| 1679 | $args->site_srl = $site_module_info->site_srl;  | 
            ||
| 1680 | }  | 
            ||
| 1681 | else  | 
            ||
| 1682 | 		{ | 
            ||
| 1683 | $args->site_srl = $site_srl;  | 
            ||
| 1684 | }  | 
            ||
| 1685 | |||
| 1686 | $args->member_srl = $member_info->member_srl;  | 
            ||
| 1687 | 		$output = executeQuery('module.isSiteAdmin', $args); | 
            ||
| 1688 | if($output->data->member_srl == $args->member_srl) return true;  | 
            ||
| 1689 | return false;  | 
            ||
| 1690 | }  | 
            ||
| 1691 | |||
| 1692 | /**  | 
            ||
| 1693 | * @brief Get admin information of the site  | 
            ||
| 1694 | */  | 
            ||
| 1695 | function getSiteAdmin($site_srl)  | 
            ||
| 1696 | 	{ | 
            ||
| 1697 | $args = new stdClass;  | 
            ||
| 1698 | $args->site_srl = $site_srl;  | 
            ||
| 1699 | 		$output = executeQueryArray('module.getSiteAdmin', $args); | 
            ||
| 1700 | return $output->data;  | 
            ||
| 1701 | }  | 
            ||
| 1702 | |||
| 1703 | /**  | 
            ||
| 1704 | * @brief Get admin ID of the module  | 
            ||
| 1705 | */  | 
            ||
| 1706 | function getAdminId($module_srl)  | 
            ||
| 1707 | 	{ | 
            ||
| 1708 | $obj = new stdClass();  | 
            ||
| 1709 | $obj->module_srl = $module_srl;  | 
            ||
| 1710 | 		$output = executeQueryArray('module.getAdminID', $obj); | 
            ||
| 1711 | if(!$output->toBool() || !$output->data) return;  | 
            ||
| 1712 | |||
| 1713 | return $output->data;  | 
            ||
| 1714 | }  | 
            ||
| 1715 | |||
| 1716 | /**  | 
            ||
| 1717 | * @brief Get extra vars of the module  | 
            ||
| 1718 | * Extra information, not in the modules table  | 
            ||
| 1719 | */  | 
            ||
| 1720 | function getModuleExtraVars($list_module_srl)  | 
            ||
| 1721 | 	{ | 
            ||
| 1722 | $extra_vars = array();  | 
            ||
| 1723 | $get_module_srls = array();  | 
            ||
| 1724 | if(!is_array($list_module_srl)) $list_module_srl = array($list_module_srl);  | 
            ||
| 1725 | |||
| 1726 | $vars = false;  | 
            ||
| 1727 | // cache controll  | 
            ||
| 1728 | 		$oCacheHandler = CacheHandler::getInstance('object', null, true); | 
            ||
| 1729 | if($oCacheHandler->isSupport())  | 
            ||
| 1730 | 		{ | 
            ||
| 1731 | foreach($list_module_srl as $module_srl)  | 
            ||
| 1732 | 			{ | 
            ||
| 1733 | $object_key = 'module_extra_vars:'.$module_srl;  | 
            ||
| 1734 | 				$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); | 
            ||
| 1735 | $vars = $oCacheHandler->get($cache_key);  | 
            ||
| 1736 | |||
| 1737 | if($vars)  | 
            ||
| 1738 | 				{ | 
            ||
| 1739 | $extra_vars[$module_srl] = $vars;  | 
            ||
| 1740 | }  | 
            ||
| 1741 | else  | 
            ||
| 1742 | 				{ | 
            ||
| 1743 | $get_module_srls[] = $module_srl;  | 
            ||
| 1744 | }  | 
            ||
| 1745 | }  | 
            ||
| 1746 | }  | 
            ||
| 1747 | else  | 
            ||
| 1748 | 		{ | 
            ||
| 1749 | $get_module_srls = $list_module_srl;  | 
            ||
| 1750 | }  | 
            ||
| 1751 | |||
| 1752 | if(count($get_module_srls) > 0)  | 
            ||
| 1753 | 		{ | 
            ||
| 1754 | $args = new stdClass();  | 
            ||
| 1755 | 			$args->module_srl = implode(',', $get_module_srls); | 
            ||
| 1756 | 			$output = executeQueryArray('module.getModuleExtraVars', $args); | 
            ||
| 1757 | |||
| 1758 | if(!$output->toBool())  | 
            ||
| 1759 | 			{ | 
            ||
| 1760 | return;  | 
            ||
| 1761 | }  | 
            ||
| 1762 | |||
| 1763 | if(!$output->data)  | 
            ||
| 1764 | 			{ | 
            ||
| 1765 | foreach($get_module_srls as $module_srl)  | 
            ||
| 1766 | 				{ | 
            ||
| 1767 | $extra_vars[$module_srl] = new stdClass;  | 
            ||
| 1768 | }  | 
            ||
| 1769 | }  | 
            ||
| 1770 | foreach($output->data as $key => $val)  | 
            ||
| 1771 | 			{ | 
            ||
| 1772 | 				if(in_array($val->name, array('mid','module')) || $val->value == 'Array') continue; | 
            ||
| 1773 | |||
| 1774 | if(!isset($extra_vars[$val->module_srl]))  | 
            ||
| 1775 | 				{ | 
            ||
| 1776 | $extra_vars[$val->module_srl] = new stdClass();  | 
            ||
| 1777 | }  | 
            ||
| 1778 | 				$extra_vars[$val->module_srl]->{$val->name} = $val->value; | 
            ||
| 1779 | |||
| 1780 | View Code Duplication | if($oCacheHandler->isSupport())  | 
            |
| 1781 | 				{ | 
            ||
| 1782 | $object_key = 'module_extra_vars:'.$val->module_srl;  | 
            ||
| 1783 | 					$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); | 
            ||
| 1784 | $oCacheHandler->put($cache_key, $extra_vars[$val->module_srl]);  | 
            ||
| 1785 | }  | 
            ||
| 1786 | }  | 
            ||
| 1787 | }  | 
            ||
| 1788 | |||
| 1789 | return $extra_vars;  | 
            ||
| 1790 | }  | 
            ||
| 1791 | |||
| 1792 | /**  | 
            ||
| 1793 | * @brief Get skin information of the module  | 
            ||
| 1794 | */  | 
            ||
| 1795 | View Code Duplication | function getModuleSkinVars($module_srl)  | 
            |
| 1796 | 	{ | 
            ||
| 1797 | $skin_vars = false;  | 
            ||
| 1798 | 		$oCacheHandler = CacheHandler::getInstance('object', null, true); | 
            ||
| 1799 | if($oCacheHandler->isSupport())  | 
            ||
| 1800 | 		{ | 
            ||
| 1801 | $object_key = 'module_skin_vars:'.$module_srl;  | 
            ||
| 1802 | 			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); | 
            ||
| 1803 | $skin_vars = $oCacheHandler->get($cache_key);  | 
            ||
| 1804 | }  | 
            ||
| 1805 | |||
| 1806 | if($skin_vars === false)  | 
            ||
| 1807 | 		{ | 
            ||
| 1808 | $args = new stdClass();  | 
            ||
| 1809 | $args->module_srl = $module_srl;  | 
            ||
| 1810 | 			$output = executeQueryArray('module.getModuleSkinVars',$args); | 
            ||
| 1811 | if(!$output->toBool()) return;  | 
            ||
| 1812 | |||
| 1813 | $skin_vars = array();  | 
            ||
| 1814 | foreach($output->data as $vars)  | 
            ||
| 1815 | 			{ | 
            ||
| 1816 | $skin_vars[$vars->name] = $vars;  | 
            ||
| 1817 | }  | 
            ||
| 1818 | |||
| 1819 | if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, $skin_vars);  | 
            ||
| 1820 | }  | 
            ||
| 1821 | |||
| 1822 | return $skin_vars;  | 
            ||
| 1823 | }  | 
            ||
| 1824 | |||
| 1825 | /**  | 
            ||
| 1826 | * Get default skin name  | 
            ||
| 1827 | */  | 
            ||
| 1828 | function getModuleDefaultSkin($module_name, $skin_type = 'P', $site_srl = 0, $updateCache = true)  | 
            ||
| 1829 | 	{ | 
            ||
| 1830 | $target = ($skin_type == 'M') ? 'mskin' : 'skin';  | 
            ||
| 1831 | if(!$site_srl) $site_srl = 0;  | 
            ||
| 1832 | |||
| 1833 | $designInfoFile = sprintf(_XE_PATH_.'files/site_design/design_%s.php', $site_srl);  | 
            ||
| 1834 | if(is_readable($designInfoFile))  | 
            ||
| 1835 | 		{ | 
            ||
| 1836 | include($designInfoFile);  | 
            ||
| 1837 | |||
| 1838 | 			$skinName = $designInfo->module->{$module_name}->{$target}; | 
            ||
| 1839 | }  | 
            ||
| 1840 | if(!$skinName)  | 
            ||
| 1841 | 		{ | 
            ||
| 1842 | $dir = ($skin_type == 'M') ? 'm.skins/' : 'skins/';  | 
            ||
| 1843 | $moduleSkinPath = ModuleHandler::getModulePath($module_name).$dir;  | 
            ||
| 1844 | |||
| 1845 | if(is_dir($moduleSkinPath.'default'))  | 
            ||
| 1846 | 			{ | 
            ||
| 1847 | $skinName = 'default';  | 
            ||
| 1848 | }  | 
            ||
| 1849 | else if(is_dir($moduleSkinPath.'xe_default'))  | 
            ||
| 1850 | 			{ | 
            ||
| 1851 | $skinName = 'xe_default';  | 
            ||
| 1852 | }  | 
            ||
| 1853 | else  | 
            ||
| 1854 | 			{ | 
            ||
| 1855 | $skins = FileHandler::readDir($moduleSkinPath);  | 
            ||
| 1856 | if(count($skins) > 0)  | 
            ||
| 1857 | 				{ | 
            ||
| 1858 | $skinName = $skins[0];  | 
            ||
| 1859 | }  | 
            ||
| 1860 | else  | 
            ||
| 1861 | 				{ | 
            ||
| 1862 | $skinName = NULL;  | 
            ||
| 1863 | }  | 
            ||
| 1864 | }  | 
            ||
| 1865 | |||
| 1866 | if($updateCache && $skinName)  | 
            ||
| 1867 | 			{ | 
            ||
| 1868 | 				if(!isset($designInfo->module->{$module_name})) $designInfo->module->{$module_name} = new stdClass(); | 
            ||
| 1869 | 				$designInfo->module->{$module_name}->{$target} = $skinName; | 
            ||
| 1870 | |||
| 1871 | 				$oAdminController = getAdminController('admin'); | 
            ||
| 1872 | $oAdminController->makeDefaultDesignFile($designInfo, $site_srl);  | 
            ||
| 1873 | }  | 
            ||
| 1874 | }  | 
            ||
| 1875 | |||
| 1876 | return $skinName;  | 
            ||
| 1877 | }  | 
            ||
| 1878 | |||
| 1879 | /**  | 
            ||
| 1880 | * @brief Combine skin information with module information  | 
            ||
| 1881 | */  | 
            ||
| 1882 | function syncSkinInfoToModuleInfo(&$module_info)  | 
            ||
| 1883 | 	{ | 
            ||
| 1884 | if(!$module_info->module_srl) return;  | 
            ||
| 1885 | |||
| 1886 | 		$oCacheHandler = CacheHandler::getInstance('object', null, true); | 
            ||
| 1887 | if(Mobile::isFromMobilePhone())  | 
            ||
| 1888 | 		{ | 
            ||
| 1889 | $skin_vars = $this->getModuleMobileSkinVars($module_info->module_srl);  | 
            ||
| 1890 | }  | 
            ||
| 1891 | else  | 
            ||
| 1892 | 		{ | 
            ||
| 1893 | $skin_vars = $this->getModuleSkinVars($module_info->module_srl);  | 
            ||
| 1894 | }  | 
            ||
| 1895 | |||
| 1896 | if(!$skin_vars) return;  | 
            ||
| 1897 | |||
| 1898 | foreach($skin_vars as $name => $val)  | 
            ||
| 1899 | 		{ | 
            ||
| 1900 | 			if(isset($module_info->{$name})) continue; | 
            ||
| 1901 | 			$module_info->{$name} = $val->value; | 
            ||
| 1902 | }  | 
            ||
| 1903 | }  | 
            ||
| 1904 | |||
| 1905 | /**  | 
            ||
| 1906 | * Get mobile skin information of the module  | 
            ||
| 1907 | * @param $module_srl Sequence of module  | 
            ||
| 1908 | * @return array  | 
            ||
| 1909 | */  | 
            ||
| 1910 | View Code Duplication | function getModuleMobileSkinVars($module_srl)  | 
            |
| 1911 | 	{ | 
            ||
| 1912 | $skin_vars = false;  | 
            ||
| 1913 | 		$oCacheHandler = CacheHandler::getInstance('object', null, true); | 
            ||
| 1914 | if($oCacheHandler->isSupport())  | 
            ||
| 1915 | 		{ | 
            ||
| 1916 | $object_key = 'module_mobile_skin_vars:'.$module_srl;  | 
            ||
| 1917 | 			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); | 
            ||
| 1918 | $skin_vars = $oCacheHandler->get($cache_key);  | 
            ||
| 1919 | }  | 
            ||
| 1920 | |||
| 1921 | if($skin_vars === false)  | 
            ||
| 1922 | 		{ | 
            ||
| 1923 | $args = new stdClass();  | 
            ||
| 1924 | $args->module_srl = $module_srl;  | 
            ||
| 1925 | 			$output = executeQueryArray('module.getModuleMobileSkinVars',$args); | 
            ||
| 1926 | if(!$output->toBool() || !$output->data) return;  | 
            ||
| 1927 | |||
| 1928 | $skin_vars = array();  | 
            ||
| 1929 | foreach($output->data as $vars)  | 
            ||
| 1930 | 			{ | 
            ||
| 1931 | $skin_vars[$vars->name] = $vars;  | 
            ||
| 1932 | }  | 
            ||
| 1933 | |||
| 1934 | if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, $skin_vars);  | 
            ||
| 1935 | }  | 
            ||
| 1936 | |||
| 1937 | return $skin_vars;  | 
            ||
| 1938 | }  | 
            ||
| 1939 | |||
| 1940 | /**  | 
            ||
| 1941 | * Combine skin information with module information  | 
            ||
| 1942 | * @param $module_info Module information  | 
            ||
| 1943 | */  | 
            ||
| 1944 | function syncMobileSkinInfoToModuleInfo(&$module_info)  | 
            ||
| 1945 | 	{ | 
            ||
| 1946 | if(!$module_info->module_srl) return;  | 
            ||
| 1947 | $skin_vars = false;  | 
            ||
| 1948 | // cache controll  | 
            ||
| 1949 | 		$oCacheHandler = CacheHandler::getInstance('object', null, true); | 
            ||
| 1950 | View Code Duplication | if($oCacheHandler->isSupport())  | 
            |
| 1951 | 		{ | 
            ||
| 1952 | $object_key = 'module_mobile_skin_vars:'.$module_info->module_srl;  | 
            ||
| 1953 | 			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); | 
            ||
| 1954 | $skin_vars = $oCacheHandler->get($cache_key);  | 
            ||
| 1955 | }  | 
            ||
| 1956 | View Code Duplication | if($skin_vars === false)  | 
            |
| 1957 | 		{ | 
            ||
| 1958 | $args = new stdClass;  | 
            ||
| 1959 | $args->module_srl = $module_info->module_srl;  | 
            ||
| 1960 | 			$output = executeQueryArray('module.getModuleMobileSkinVars',$args); | 
            ||
| 1961 | if(!$output->toBool()) return;  | 
            ||
| 1962 | $skin_vars = $output->data;  | 
            ||
| 1963 | |||
| 1964 | //insert in cache  | 
            ||
| 1965 | if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, $skin_vars);  | 
            ||
| 1966 | }  | 
            ||
| 1967 | if(!$skin_vars) return;  | 
            ||
| 1968 | |||
| 1969 | foreach($output->data as $val)  | 
            ||
| 1970 | 		{ | 
            ||
| 1971 | 			if(isset($module_info->{$val->name})) continue; | 
            ||
| 1972 | 			$module_info->{$val->name} = $val->value; | 
            ||
| 1973 | }  | 
            ||
| 1974 | }  | 
            ||
| 1975 | |||
| 1976 | /**  | 
            ||
| 1977 | * @brief Return permission by using module info, xml info and member info  | 
            ||
| 1978 | */  | 
            ||
| 1979 | function getGrant($module_info, $member_info, $xml_info = '')  | 
            ||
| 2135 | |||
| 2136 | function getModuleFileBox($module_filebox_srl)  | 
            ||
| 2137 | 	{ | 
            ||
| 2138 | $args = new stdClass();  | 
            ||
| 2139 | $args->module_filebox_srl = $module_filebox_srl;  | 
            ||
| 2140 | 		return executeQuery('module.getModuleFileBox', $args); | 
            ||
| 2141 | }  | 
            ||
| 2142 | |||
| 2143 | function getModuleFileBoxList()  | 
            ||
| 2144 | 	{ | 
            ||
| 2145 | 		$oModuleModel = getModel('module'); | 
            ||
| 2146 | |||
| 2147 | $args = new stdClass();  | 
            ||
| 2148 | 		$args->page = Context::get('page'); | 
            ||
| 2149 | $args->list_count = 5;  | 
            ||
| 2150 | $args->page_count = 5;  | 
            ||
| 2151 | 		$output = executeQuery('module.getModuleFileBoxList', $args); | 
            ||
| 2152 | $output = $oModuleModel->unserializeAttributes($output);  | 
            ||
| 2153 | return $output;  | 
            ||
| 2154 | }  | 
            ||
| 2155 | |||
| 2156 | function unserializeAttributes($module_filebox_list)  | 
            ||
| 2157 | 	{ | 
            ||
| 2158 | if(is_array($module_filebox_list->data))  | 
            ||
| 2159 | 		{ | 
            ||
| 2160 | foreach($module_filebox_list->data as &$item)  | 
            ||
| 2161 | 			{ | 
            ||
| 2162 | if(empty($item->comment))  | 
            ||
| 2163 | 				{ | 
            ||
| 2164 | continue;  | 
            ||
| 2165 | }  | 
            ||
| 2166 | |||
| 2167 | 				$attributes = explode(';', $item->comment); | 
            ||
| 2168 | foreach($attributes as $attribute)  | 
            ||
| 2169 | 				{ | 
            ||
| 2170 | 					$values = explode(':', $attribute); | 
            ||
| 2171 | if((count($values) % 2) ==1)  | 
            ||
| 2172 | 					{ | 
            ||
| 2173 | for($i=2;$i<count($values);$i++)  | 
            ||
| 2174 | 						{ | 
            ||
| 2175 | $values[1].=":".$values[$i];  | 
            ||
| 2176 | }  | 
            ||
| 2177 | }  | 
            ||
| 2178 | $atts[$values[0]]=$values[1];  | 
            ||
| 2179 | }  | 
            ||
| 2180 | $item->attributes = $atts;  | 
            ||
| 2181 | unset($atts);  | 
            ||
| 2182 | }  | 
            ||
| 2183 | }  | 
            ||
| 2184 | return $module_filebox_list;  | 
            ||
| 2185 | }  | 
            ||
| 2186 | |||
| 2187 | function getFileBoxListHtml()  | 
            ||
| 2188 | 	{ | 
            ||
| 2189 | 		$logged_info = Context::get('logged_info'); | 
            ||
| 2190 | if($logged_info->is_admin !='Y' && !$logged_info->is_site_admin) return new Object(-1, 'msg_not_permitted');  | 
            ||
| 2191 | $link = parse_url($_SERVER["HTTP_REFERER"]);  | 
            ||
| 2192 | 		$link_params = explode('&',$link['query']); | 
            ||
| 2193 | foreach ($link_params as $param)  | 
            ||
| 2194 | 		{ | 
            ||
| 2195 | 			$param = explode("=",$param); | 
            ||
| 2196 | if($param[0] == 'selected_widget') $selected_widget = $param[1];  | 
            ||
| 2197 | }  | 
            ||
| 2198 | 		$oWidgetModel = getModel('widget'); | 
            ||
| 2199 | if($selected_widget) $widget_info = $oWidgetModel->getWidgetInfo($selected_widget);  | 
            ||
| 2200 | 		Context::set('allow_multiple', $widget_info->extra_var->images->allow_multiple); | 
            ||
| 2201 | |||
| 2202 | 		$oModuleModel = getModel('module'); | 
            ||
| 2203 | $output = $oModuleModel->getModuleFileBoxList();  | 
            ||
| 2204 | 		Context::set('filebox_list', $output->data); | 
            ||
| 2205 | |||
| 2206 | 		$page = Context::get('page'); | 
            ||
| 2207 | if (!$page) $page = 1;  | 
            ||
| 2208 | 		Context::set('page', $page); | 
            ||
| 2209 | 		Context::set('page_navigation', $output->page_navigation); | 
            ||
| 2210 | |||
| 2211 | $security = new Security();  | 
            ||
| 2212 | 		$security->encodeHTML('filebox_list..comment', 'filebox_list..attributes.'); | 
            ||
| 2213 | |||
| 2214 | $oTemplate = &TemplateHandler::getInstance();  | 
            ||
| 2215 | $html = $oTemplate->compile(_XE_PATH_ . 'modules/module/tpl/', 'filebox_list_html');  | 
            ||
| 2216 | |||
| 2217 | 		$this->add('html', $html); | 
            ||
| 2218 | }  | 
            ||
| 2219 | |||
| 2220 | function getModuleFileBoxPath($module_filebox_srl)  | 
            ||
| 2224 | |||
| 2225 | /**  | 
            ||
| 2226 | * @brief Return ruleset cache file path  | 
            ||
| 2227 | * @param module, act  | 
            ||
| 2228 | */  | 
            ||
| 2229 | function getValidatorFilePath($module, $ruleset, $mid=null)  | 
            ||
| 2230 | 	{ | 
            ||
| 2231 | // load dynamic ruleset xml file  | 
            ||
| 2232 | if(strpos($ruleset, '@') !== false)  | 
            ||
| 2233 | 		{ | 
            ||
| 2234 | 			$rulsetFile = str_replace('@', '', $ruleset); | 
            ||
| 2235 | 			$xml_file = sprintf('./files/ruleset/%s.xml', $rulsetFile); | 
            ||
| 2236 | return FileHandler::getRealPath($xml_file);  | 
            ||
| 2237 | }  | 
            ||
| 2238 | else if (strpos($ruleset, '#') !== false)  | 
            ||
| 2239 | 		{ | 
            ||
| 2240 | 			$rulsetFile = str_replace('#', '', $ruleset).'.'.$mid; | 
            ||
| 2241 | 			$xml_file = sprintf('./files/ruleset/%s.xml', $rulsetFile); | 
            ||
| 2242 | if(is_readable($xml_file))  | 
            ||
| 2243 | return FileHandler::getRealPath($xml_file);  | 
            ||
| 2244 | 			else{ | 
            ||
| 2245 | 				$ruleset = str_replace('#', '', $ruleset); | 
            ||
| 2246 | }  | 
            ||
| 2247 | |||
| 2248 | }  | 
            ||
| 2249 | // Get a path of the requested module. Return if not exists.  | 
            ||
| 2250 | $class_path = ModuleHandler::getModulePath($module);  | 
            ||
| 2251 | if(!$class_path) return;  | 
            ||
| 2252 | |||
| 2253 | // Check if module.xml exists in the path. Return if not exist  | 
            ||
| 2254 | 		$xml_file = sprintf("%sruleset/%s.xml", $class_path, $ruleset); | 
            ||
| 2255 | if(!file_exists($xml_file)) return;  | 
            ||
| 2256 | |||
| 2257 | return $xml_file;  | 
            ||
| 2258 | }  | 
            ||
| 2259 | |||
| 2260 | function getLangListByLangcodeForAutoComplete()  | 
            ||
| 2261 | 	{ | 
            ||
| 2262 | 		$keyword = Context::get('search_keyword'); | 
            ||
| 2263 | |||
| 2264 | $requestVars = Context::getRequestVars();  | 
            ||
| 2265 | |||
| 2266 | $args = new stdClass;  | 
            ||
| 2267 | $args->site_srl = (int)$requestVars->site_srl;  | 
            ||
| 2268 | $args->page = 1; // /< Page  | 
            ||
| 2269 | $args->list_count = 100; // /< the number of posts to display on a single page  | 
            ||
| 2270 | $args->page_count = 5; // /< the number of pages that appear in the page navigation  | 
            ||
| 2271 | $args->sort_index = 'name';  | 
            ||
| 2272 | $args->order_type = 'asc';  | 
            ||
| 2290 | |||
| 2291 | /**  | 
            ||
| 2292 | * @brief already instance created module list  | 
            ||
| 2293 | */  | 
            ||
| 2294 | function getModuleListByInstance($site_srl = 0, $columnList = array())  | 
            ||
| 2301 | |||
| 2302 | function getLangByLangcode()  | 
            ||
| 2312 | }  | 
            ||
| 2313 | /* End of file module.model.php */  | 
            ||
| 2315 | 
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: