BxDolInstallModulesTools.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php defined('BX_DOL_INSTALL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentInstall Trident Install
  7. * @{
  8. */
  9. class BxDolInstallModulesTools
  10. {
  11. public function __construct()
  12. {
  13. }
  14. public function getModules ($sType = null)
  15. {
  16. $aModules = array();
  17. $sPath = BX_INSTALL_DIR_MODULES;
  18. if (($rHandleVendor = opendir($sPath)) !== false) {
  19. while (($sVendor = readdir($rHandleVendor)) !== false) {
  20. if (substr($sVendor, 0, 1) == '.' || !is_dir($sPath . $sVendor))
  21. continue;
  22. if (($rHandleModule = opendir($sPath . $sVendor)) !== false) {
  23. while(($sModule = readdir($rHandleModule)) !== false) {
  24. if(!is_dir($sPath . $sVendor . '/' . $sModule) || substr($sModule, 0, 1) == '.')
  25. continue;
  26. $sConfigPath = $sPath . $sVendor . '/' . $sModule . '/install/config.php';
  27. $aModuleConfig = $this->getModuleConfigByConfigPath($sConfigPath);
  28. if (empty($aModuleConfig) || ($sType && $sType != $aModuleConfig['type']))
  29. continue;
  30. $aModules[$aModuleConfig['name']] = $aModuleConfig;
  31. }
  32. closedir($rHandleModule);
  33. }
  34. }
  35. closedir($rHandleVendor);
  36. }
  37. ksort($aModules);
  38. return $aModules;
  39. }
  40. public function getModuleConfigByUri ($sUri, $aModules)
  41. {
  42. foreach ($aModules as $aModuleConfig)
  43. if ($sUri == $aModuleConfig['home_uri'])
  44. return $aModuleConfig;
  45. return null;
  46. }
  47. public function readLanguage ($aModuleConfig)
  48. {
  49. $sPath = BX_INSTALL_DIR_MODULES . $aModuleConfig['home_dir'] . 'data/langs/system/' . $aModuleConfig['home_uri'] . '.xml';
  50. if(!file_exists($sPath))
  51. return array();
  52. $oXmlParser = BxDolXmlParser::getInstance();
  53. $sXmlContent = file_get_contents($sPath);
  54. return $oXmlParser->getValues($sXmlContent, 'string');
  55. }
  56. protected function getModuleConfigByConfigPath ($sConfigPath)
  57. {
  58. if (!file_exists($sConfigPath))
  59. return array();
  60. include($sConfigPath);
  61. return $aConfig;
  62. }
  63. }
  64. /** @} */