* @package MCMS\System\Service */ class ModuleSvc extends ModuleSvcBase { private static $cache; private static function checkCache() { if(empty(self::$cache)) self::$cache = new SimpleCache(); // TODO: optimize } public static function findModules($basepath, DB &$db, $pathhead = false) { if (!$pathhead) $pathhead = $basepath; $modules = array(); if (file_exists($basepath.__DS__.'_info_.php')) { $info = array(); $info['id'] = str_replace(__DS__,'.',substr($basepath,strlen($pathhead)+1)); $info['uid'] = NULL; $info['title'] = 'Unnamed'; $info['version'] = false; $info["autor"] = false; $info["home"] = false; $info["update"] = false; $info['class'] = false; $info['dir'] = $basepath; $info['urlpath'] = str_replace(__DS__,'/',substr($basepath,strlen( _BASEPATH_))); $info['icon'] = file_exists($basepath.__DS__.'_admin_'.__DS__.'images'.__DS__.'icon16.png') ? $info['urlpath'].'/_admin_/images/icon16.png': false; $info['acl'] = []; $info["needs"] = []; $info["entries"] = []; $info = array_merge($info, array_from_file($basepath.__DS__.'_info_.php','info')); $info['abstract'] = (isset($info['abstract'])) && $info['abstract'] == true; $info['noinstall'] = isset($info['noinstall']) && $info['noinstall'] === true; $info['setup'] = isset($info['setup']) ? $info['setup'] : NULL; $info['setupi'] = isset($info['setupi']) ? $info['setupi'] : NULL; $modules[] = $info; } $files = scandir($basepath); foreach($files as $file) { if (is_dir($basepath.__DS__.$file) && preg_match('#^[a-zA-Z][a-zA-Z0-9_-]*$#',$file)) $modules = array_merge($modules, self::findModules($basepath.__DS__.$file, $db, $pathhead)); } return $modules; } public static function getInstalledModuleVersion($module) { $db = System::getInstance()->getDB(); $info = $db->table('installinfos')->getObject([ 'type' => 'module', 'key' => $module ]); return !empty($info) ? $info->version : NULL; } public static function isModuleInstalled($module) { $v = self::getInstalledModuleVersion($module); return !empty($v); } }