Index: branches/5.2.x/core/units/helpers/modules_helper.php =================================================================== diff -u -N -r14628 -r14699 --- branches/5.2.x/core/units/helpers/modules_helper.php (.../modules_helper.php) (revision 14628) +++ branches/5.2.x/core/units/helpers/modules_helper.php (.../modules_helper.php) (revision 14699) @@ -1,6 +1,6 @@ Application->recallObject('Session'); /* @var $session Session */ - + return $session->CookiesEnabled; } @@ -204,33 +219,14 @@ */ protected function _getFreeModules($vars) { - $skip_modules = Array ('.', '..'); $domain = $this->_GetDomain($vars); + $modules = array_map('strtolower', $this->getModules()); if ( !$this->_IsLocalSite($domain) ) { - array_push($skip_modules, 'in-commerce', 'in-auction'); + return array_diff($modules, Array ('in-commerce', 'in-auction')); } - $ret = Array (); - $folder = dir(MODULES_PATH); - - if ( $folder === false ) { - return Array (); - } - - while ( ($entry = $folder->read()) !== false ) { - $entry_lowercased = strtolower($entry); - - if ( !is_dir($folder->path . '/' . $entry) || in_array($entry_lowercased, $skip_modules) ) { - continue; - } - - $ret[] = $entry_lowercased; - } - - $folder->close(); - - return $ret; + return $modules; } /** @@ -248,6 +244,7 @@ /** * Returns domain from licences (and direct in case of install script) * + * @param Array $vars * @return string */ function _GetDomain($vars) @@ -368,6 +365,8 @@ if ($i > 20) return 99; if ($i > 10) return '.'.($this->_GetObscureValue(6.5)+1); if ($i == 'a') return 0xa; + + return 0; } function _Chr($val) @@ -431,16 +430,69 @@ { static $modules = null; - if (is_null($modules)) { + if ( is_null($modules) ) { $sql = 'SELECT LOWER(Name) FROM ' . $this->Application->getUnitOption('mod', 'TableName'); $modules = $this->Conn->GetCol($sql); } - if ($module_name == 'kernel') { + if ( $module_name == 'kernel' ) { $module_name = 'in-portal'; } return in_array(strtolower($module_name), $modules); } + + /** + * Returns list of matching modules + * + * @param int $module_type + * @return Array + * @access public + */ + public function getModules($module_type = self::ANY) + { + $modules = Array (); + + $iterator = new DirectoryIterator(MODULES_PATH); + /* @var $file_info DirectoryIterator */ + + foreach ($iterator as $file_info) { + $file_path = $file_info->getPathname(); + + if ( $file_info->isDir() && !$file_info->isDot() && $this->isInPortalModule($file_path) ) { + $install_order = trim( file_get_contents($file_path . '/install/install_order.txt') ); + $modules[$install_order] = $file_info->getFilename(); + } + } + + // allows to control module install order + ksort($modules, SORT_NUMERIC); + + if ( $module_type == self::ANY ) { + return $modules; + } + + foreach ($modules as $install_order => $module_name) { + $installed = $this->moduleInstalled($module_name); + + if ( ($module_type == self::INSTALLED && !$installed) || ($module_type == self::NOT_INSTALLED && $installed) ) { + unset($modules[$install_order]); + } + } + + return $modules; + } + + /** + * Checks, that given folder is In-Portal module's root folder + * + * @param string $folder_path + * @return bool + * @access public + */ + public static function isInPortalModule($folder_path) + { + return file_exists($folder_path . '/install.php') && file_exists($folder_path . '/install/install_schema.sql'); + } } \ No newline at end of file