1
0

BxDolStudioStore.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  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 DolphinStudio Dolphin Studio
  7. * @{
  8. */
  9. defined('BX_DOL') or die('hack attempt');
  10. bx_import('BxTemplStudioPage');
  11. bx_import('BxDolStudioStoreQuery');
  12. define('BX_DOL_STUDIO_STR_TYPE_DEFAULT', 'goodies');
  13. class BxDolStudioStore extends BxTemplStudioPage {
  14. protected $sPage;
  15. protected $aProducts;
  16. function BxDolStudioStore($sPage = "") {
  17. parent::BxTemplStudioPage('store');
  18. $this->oDb = new BxDolStudioStoreQuery();
  19. $this->sPage = BX_DOL_STUDIO_STR_TYPE_DEFAULT;
  20. if(is_string($sPage) && !empty($sPage))
  21. $this->sPage = $sPage;
  22. //--- Check actions ---//
  23. if(($sAction = bx_get('str_action')) !== false) {
  24. $sAction = bx_process_input($sAction);
  25. $aResult = array('code' => 1, 'message' => _t('_adm_mod_err_cannot_process_action'));
  26. switch($sAction) {
  27. case 'get-products-by-type':
  28. $sValue = bx_process_input(bx_get('str_value'));
  29. $sMethod = 'load' . ucfirst($sValue);
  30. if(method_exists($this, $sMethod)) {
  31. $this->sPage = $sValue;
  32. $this->aProducts = $this->$sMethod();
  33. $aResult = array('code' => 0, 'content' => $this->getPageCode());
  34. }
  35. else
  36. $aResult = array('code' => 1, 'message' => _t('_adm_act_err_failed_page_loading'));
  37. break;
  38. case 'install':
  39. $sValue = bx_process_input(bx_get('str_value'));
  40. if(empty($sValue))
  41. break;
  42. bx_import('BxDolStudioInstallerUtils');
  43. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($sValue, 'install');
  44. break;
  45. }
  46. if(!empty($aResult['message'])) {
  47. bx_import('BxDolStudioTemplate');
  48. $sContent = BxDolStudioTemplate::getInstance()->parseHtmlByName('mod_action_result.html', array('content' => $aResult['message']));
  49. bx_import('BxTemplStudioFunctions');
  50. $aResult['message'] = BxTemplStudioFunctions::getInstance()->transBox($sContent);
  51. }
  52. $oJson = new Services_JSON();
  53. echo $oJson->encode($aResult);
  54. exit;
  55. }
  56. }
  57. protected function loadGoodies() {
  58. $aProducts = array();
  59. $sJsObject = $this->getPageJsObject();
  60. // Load featured
  61. $aProducts[] = array(
  62. 'caption' => '_adm_block_cpt_last_featured',
  63. 'actions' => array(
  64. array('name' => 'featured', 'caption' => '_adm_action_cpt_see_all_featured', 'url' => 'javascript:void(0)', 'onclick' => $sJsObject . ".changePage('featured', this)")
  65. ),
  66. 'items' => array()
  67. );
  68. // Load modules
  69. $aProducts[] = array(
  70. 'caption' => '_adm_block_cpt_last_modules',
  71. 'actions' => array(
  72. array('name' => 'modules', 'caption' => '_adm_action_cpt_see_all_modules', 'url' => 'javascript:void(0)', 'onclick' => $sJsObject . ".changePage('modules', this)")
  73. ),
  74. 'items' => array()
  75. );
  76. // Load templates
  77. $aProducts[] = array(
  78. 'caption' => '_adm_block_cpt_last_templates',
  79. 'actions' => array(
  80. array('name' => 'templates', 'caption' => '_adm_action_cpt_see_all_templates', 'url' => 'javascript:void(0)', 'onclick' => $sJsObject . ".changePage('templates', this)")
  81. ),
  82. 'items' => array()
  83. );
  84. // Load languages
  85. $aProducts[] = array(
  86. 'caption' => '_adm_block_cpt_last_languages',
  87. 'actions' => array(
  88. array('name' => 'languages', 'caption' => '_adm_action_cpt_see_all_languages', 'url' => 'javascript:void(0)', 'onclick' => $sJsObject . ".changePage('languages', this)")
  89. ),
  90. 'items' => array()
  91. );
  92. return $aProducts;
  93. }
  94. protected function loadPurchases() {
  95. $aProducts = array();
  96. $oTemplate = BxDolStudioTemplate::getInstance();
  97. $aInstalled = $this->oDb->getModules();
  98. $aInstalledInfo = array();
  99. foreach($aInstalled as $aModule)
  100. $aInstalledInfo[$aModule['path']] = $aModule;
  101. $aInstalledPathes = array_keys($aInstalledInfo);
  102. $iOrder = 0;
  103. $sPath = BX_DIRECTORY_PATH_ROOT . 'modules/';
  104. if(($rHandleVendor = opendir($sPath)) !== false) {
  105. while(($sVendor = readdir($rHandleVendor)) !== false) {
  106. if(substr($sVendor, 0, 1) == '.' || !is_dir($sPath . $sVendor))
  107. continue;
  108. if(($rHandleModule = opendir($sPath . $sVendor)) !== false) {
  109. while(($sModule = readdir($rHandleModule)) !== false) {
  110. if(!is_dir($sPath . $sVendor . '/' . $sModule) || substr($sModule, 0, 1) == '.')
  111. continue;
  112. $sConfigPath = $sPath . $sVendor . '/' . $sModule . '/install/config.php';
  113. if(!file_exists($sConfigPath))
  114. continue;
  115. include($sConfigPath);
  116. $sModulePath = $aConfig['home_dir'];
  117. $sTitle = bx_process_output($aConfig['title']);
  118. $bInstalled = in_array($sModulePath, $aInstalledPathes);
  119. $bEnabled = $bInstalled && (int)$aInstalledInfo[$sModulePath]['enabled'] == 1;
  120. $sLinkMarket = '';
  121. if(isset($aConfig['product_url'])) {
  122. $aTmplVars = array(
  123. 'vendor' => $aConfig['vendor'],
  124. 'version' => $aConfig['version'],
  125. 'uri' => $aConfig['home_uri'],
  126. 'title' => $aConfig['title']
  127. );
  128. $sLinkMarket = $oTemplate->parseHtmlByContent(bx_html_attribute($aConfig['product_url']), $aTmplVars, array('{', '}'));
  129. }
  130. $aProducts[$sTitle] = array(
  131. 'name' => $aConfig['name'],
  132. 'title' => $sTitle,
  133. 'vendor' => $aConfig['vendor'],
  134. 'version' => $aConfig['version'],
  135. 'uri' => $aConfig['home_uri'],
  136. 'dir' => $aConfig['home_dir'],
  137. 'title' => $sTitle,
  138. 'note' => isset($aConfig['note']) ? bx_process_output($aConfig['note']) : '',
  139. 'link_market' => $sLinkMarket,
  140. 'installed' => $bInstalled,
  141. 'enabled' => $bInstalled && $bEnabled
  142. );
  143. }
  144. closedir($rHandleModule);
  145. }
  146. }
  147. closedir($rHandleVendor);
  148. }
  149. ksort($aProducts);
  150. return $aProducts;
  151. }
  152. }
  153. /** @} */