BxDolStudioBuilderPage.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaStudio UNA Studio
  7. * @{
  8. */
  9. bx_import('BxDolStudioUtils');
  10. define('BX_DOL_STUDIO_BP_SKELETONS', 'skeletons');
  11. define('BX_DOL_STUDIO_BP_TYPE_DEFAULT', BX_DOL_STUDIO_MODULE_SYSTEM);
  12. define('BX_DOL_STUDIO_BP_BLOCK_RAW', 'raw');
  13. define('BX_DOL_STUDIO_BP_BLOCK_HTML', 'html');
  14. define('BX_DOL_STUDIO_BP_BLOCK_RSS', 'rss');
  15. define('BX_DOL_STUDIO_BP_BLOCK_IMAGE', 'image');
  16. define('BX_DOL_STUDIO_BP_BLOCK_LANG', 'lang');
  17. define('BX_DOL_STUDIO_BP_BLOCK_MENU', 'menu');
  18. define('BX_DOL_STUDIO_BP_BLOCK_WIKI', 'wiki');
  19. define('BX_DOL_STUDIO_BP_BLOCK_CUSTOM', 'custom');
  20. define('BX_DOL_STUDIO_BP_BLOCK_SERVICE', 'service');
  21. class BxDolStudioBuilderPage extends BxTemplStudioWidget
  22. {
  23. protected $sType;
  24. protected $sPage;
  25. protected $sPageBaseUrl;
  26. protected $aPageRebuild;
  27. function __construct($sType = '', $sPage = '')
  28. {
  29. parent::__construct('builder_pages');
  30. $this->oDb = new BxDolStudioBuilderPageQuery();
  31. $this->sType = BX_DOL_STUDIO_BP_TYPE_DEFAULT;
  32. if(is_string($sType) && !empty($sType))
  33. $this->sType = $sType;
  34. $this->sPage = '';
  35. $this->sPageBaseUrl = 'page.php?i=';
  36. $this->aPageRebuild = array();
  37. if(is_string($sPage) && !empty($sPage)) {
  38. $this->sPage = $sPage;
  39. $this->aPageRebuild = $this->oDb->getPages(array('type' => 'by_object_full', 'value' => $this->sPage));
  40. if(empty($this->aPageRebuild) || !is_array($this->aPageRebuild)) {
  41. $this->sPage = '';
  42. $this->aPageRebuild = array();
  43. }
  44. }
  45. }
  46. public function checkAction()
  47. {
  48. $sAction = bx_get('bp_action');
  49. if($sAction === false)
  50. return false;
  51. $sAction = bx_process_input($sAction);
  52. $aResult = array('code' => 1, 'message' => _t('_adm_bp_err_cannot_process_action'));
  53. switch($sAction) {
  54. case 'reorder':
  55. if(empty($this->aPageRebuild) || !is_array($this->aPageRebuild))
  56. break;
  57. $bResult = false;
  58. for($i = 0; $i <= $this->aPageRebuild['layout_cells_number']; $i++) {
  59. $aItems = bx_get('bp_items_' . $i);
  60. $iItems = count($aItems);
  61. for($j = 0; $j < $iItems; $j++)
  62. $bResult |= $this->oDb->updateBlock((int)$aItems[$j], array(
  63. 'cell_id' => $i,
  64. 'order' => $j
  65. ));
  66. }
  67. $aResult = $bResult ? array('code' => 0, 'message' => _t('_adm_bp_scs_save')) : array('code' => 1, 'message' => _t('_adm_bp_err_nothing_changed'));
  68. break;
  69. default:
  70. $sMethod = 'action' . $this->getClassName($sAction);
  71. if(method_exists($this, $sMethod))
  72. $aResult = $this->$sMethod();
  73. }
  74. return $aResult;
  75. }
  76. function processAction($sAction)
  77. {
  78. $sMethod = 'action' . $this->getClassName($sAction);
  79. if (method_exists($this, $sMethod))
  80. return $this->$sMethod();
  81. else
  82. return array('code' => 1, 'message' => _t('_adm_bp_err_cannot_process_action'));
  83. }
  84. protected function onSaveBlock(&$oForm, &$aBlock)
  85. {
  86. $iDesignboxId = (int)str_replace($this->sSelectKeyPrefix, '', $oForm->getCleanValue('designbox_id'));
  87. BxDolForm::setSubmittedValue('designbox_id', $iDesignboxId, $oForm->aFormAttrs['method']);
  88. $iVisibleFor = BxDolStudioUtils::getVisibilityValue($oForm->getCleanValue('visible_for'), $oForm->getCleanValue('visible_for_levels'));
  89. BxDolForm::setSubmittedValue('visible_for_levels', $iVisibleFor, $oForm->aFormAttrs['method']);
  90. unset($oForm->aInputs['visible_for']);
  91. //--- Process Lang fields
  92. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && isset($oForm->aInputs['content']))
  93. $this->onSaveBlockLang($oForm, $aBlock);
  94. //--- Process Image fields
  95. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && isset($oForm->aInputs['image_file'], $oForm->aInputs['image_align']))
  96. $this->onSaveBlockImage($oForm, $aBlock);
  97. //--- Process RSS fields
  98. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_RSS && isset($oForm->aInputs['rss_url'], $oForm->aInputs['rss_length']))
  99. $this->onSaveBlockRss($oForm, $aBlock);
  100. }
  101. protected function onSaveBlockLang(&$oForm, &$aBlock)
  102. {
  103. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  104. $sContentKey = '';
  105. $sContentValue = $oForm->getCleanValue('content');
  106. if($aBlock['content'] == '') {
  107. $sContentKey = '_sys_bpb_content_' . $aBlock['id'];
  108. $oLanguage->addLanguageString($sContentKey, $sContentValue);
  109. } else {
  110. $sContentKey = $aBlock['content'];
  111. $oLanguage->updateLanguageString($sContentKey, $sContentValue);
  112. }
  113. BxDolForm::setSubmittedValue('content', $sContentKey, $oForm->aFormAttrs['method']);
  114. }
  115. protected function onSaveBlockImage(&$oForm, &$aBlock)
  116. {
  117. $iImageId = 0;
  118. if($aBlock['content'] != '')
  119. list($iImageId) = explode($this->sParamsDivider, $aBlock['content']);
  120. $iImageId = $oForm->processImageUploaderSave('image_file', $iImageId);
  121. if(is_string($iImageId) && !is_numeric($iImageId))
  122. return array('msg' => $iImageId);
  123. $sImageAlign = $oForm->getCleanValue('image_align');
  124. unset($oForm->aInputs['image_file'], $oForm->aInputs['image_align']);
  125. BxDolForm::setSubmittedValue('content', implode($this->sParamsDivider, array($iImageId, $sImageAlign)), $oForm->aFormAttrs['method']);
  126. }
  127. protected function onSaveBlockRss(&$oForm, &$aBlock)
  128. {
  129. $aRss = array(
  130. trim($oForm->getCleanValue('rss_url')),
  131. $oForm->getCleanValue('rss_length')
  132. );
  133. unset($oForm->aInputs['rss_url'], $oForm->aInputs['rss_length']);
  134. BxDolForm::setSubmittedValue('content', implode($this->sParamsDivider, $aRss), $oForm->aFormAttrs['method']);
  135. }
  136. protected function addInArray($aInput, $sKey, $aValues)
  137. {
  138. return BxDolStudioUtils::addInArray($aInput, $sKey, $aValues);
  139. }
  140. protected function getModuleIcon($sName, $sType = 'menu', $bReturnAsUrl = true)
  141. {
  142. $sResult = '';
  143. switch($sName) {
  144. case BX_DOL_STUDIO_MODULE_SYSTEM:
  145. $sResult = 'cog';
  146. break;
  147. case BX_DOL_STUDIO_MODULE_CUSTOM:
  148. $sResult = 'wrench';
  149. break;
  150. case BX_DOL_STUDIO_BP_SKELETONS:
  151. $sResult = 'qrcode';
  152. break;
  153. default:
  154. $sResult = parent::getModuleIcon($sName, $sType, $bReturnAsUrl);
  155. }
  156. return $sResult;
  157. }
  158. }
  159. /** @} */