1
0

BxDolStudioBuilderPage.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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_SERVICE', 'service');
  19. class BxDolStudioBuilderPage extends BxTemplStudioPage
  20. {
  21. protected $sType;
  22. protected $sPage;
  23. protected $sPageBaseUrl;
  24. protected $aPageRebuild;
  25. function __construct($sType = '', $sPage = '')
  26. {
  27. parent::__construct('builder_pages');
  28. $this->oDb = new BxDolStudioBuilderPageQuery();
  29. $this->sType = BX_DOL_STUDIO_BP_TYPE_DEFAULT;
  30. if(is_string($sType) && !empty($sType))
  31. $this->sType = $sType;
  32. $this->sPage = '';
  33. $this->sPageBaseUrl = 'page.php?i=';
  34. $this->aPageRebuild = array();
  35. if(is_string($sPage) && !empty($sPage)) {
  36. $this->sPage = $sPage;
  37. $this->aPageRebuild = array();
  38. $this->oDb->getPages(array('type' => 'by_object_full', 'value' => $this->sPage), $this->aPageRebuild, false);
  39. if(empty($this->aPageRebuild) || !is_array($this->aPageRebuild)) {
  40. $this->sPage = '';
  41. $this->aPageRebuild = array();
  42. }
  43. }
  44. }
  45. function init()
  46. {
  47. if(($sAction = bx_get('bp_action')) === false)
  48. return;
  49. $sAction = bx_process_input($sAction);
  50. $aResult = array('code' => 1, 'message' => _t('_adm_bp_err_cannot_process_action'));
  51. switch($sAction) {
  52. case 'reorder':
  53. if(empty($this->aPageRebuild) || !is_array($this->aPageRebuild))
  54. break;
  55. $bResult = false;
  56. for($i = 1; $i <= $this->aPageRebuild['layout_cells_number']; $i++) {
  57. $aItems = bx_get('bp_items_' . $i);
  58. $iItems = count($aItems);
  59. for($j = 0; $j < $iItems; $j++)
  60. $bResult |= $this->oDb->updateBlock((int)$aItems[$j], array(
  61. 'cell_id' => $i,
  62. 'order' => $j
  63. ));
  64. }
  65. $aResult = $bResult ? array('code' => 0, 'message' => _t('_adm_bp_scs_save')) : array('code' => 1, 'message' => _t('_adm_bp_err_nothing_changed'));
  66. break;
  67. default:
  68. $sMethod = 'action' . $this->getClassName($sAction);
  69. if(method_exists($this, $sMethod))
  70. $aResult = $this->$sMethod();
  71. }
  72. echo json_encode($aResult);
  73. exit;
  74. }
  75. protected function onSaveBlock(&$oForm, &$aBlock)
  76. {
  77. $iDesignboxId = (int)str_replace($this->sSelectKeyPrefix, '', $oForm->getCleanValue('designbox_id'));
  78. BxDolForm::setSubmittedValue('designbox_id', $iDesignboxId, $oForm->aFormAttrs['method']);
  79. $iVisibleFor = BxDolStudioUtils::getVisibilityValue($oForm->getCleanValue('visible_for'), $oForm->getCleanValue('visible_for_levels'));
  80. BxDolForm::setSubmittedValue('visible_for_levels', $iVisibleFor, $oForm->aFormAttrs['method']);
  81. unset($oForm->aInputs['visible_for']);
  82. //--- Process Lang fields
  83. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && isset($oForm->aInputs['content']))
  84. $this->onSaveBlockLang($oForm, $aBlock);
  85. //--- Process Image fields
  86. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && isset($oForm->aInputs['image_file'], $oForm->aInputs['image_align']))
  87. $this->onSaveBlockImage($oForm, $aBlock);
  88. //--- Process RSS fields
  89. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_RSS && isset($oForm->aInputs['rss_url'], $oForm->aInputs['rss_length']))
  90. $this->onSaveBlockRss($oForm, $aBlock);
  91. }
  92. protected function onSaveBlockLang(&$oForm, &$aBlock)
  93. {
  94. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  95. $sContentKey = '';
  96. $sContentValue = $oForm->getCleanValue('content');
  97. if($aBlock['content'] == '') {
  98. $sContentKey = '_sys_bpb_content_' . $aBlock['id'];
  99. $oLanguage->addLanguageString($sContentKey, $sContentValue);
  100. } else {
  101. $sContentKey = $aBlock['content'];
  102. $oLanguage->updateLanguageString($sContentKey, $sContentValue);
  103. }
  104. BxDolForm::setSubmittedValue('content', $sContentKey, $oForm->aFormAttrs['method']);
  105. }
  106. protected function onSaveBlockImage(&$oForm, &$aBlock)
  107. {
  108. $iImageId = 0;
  109. if($aBlock['content'] != '')
  110. list($iImageId) = explode($this->sParamsDivider, $aBlock['content']);
  111. $iImageId = $oForm->processImageUploaderSave('image_file', $iImageId);
  112. if(is_string($iImageId) && !is_numeric($iImageId))
  113. return array('msg' => $iImageId);
  114. $sImageAlign = $oForm->getCleanValue('image_align');
  115. unset($oForm->aInputs['image_file'], $oForm->aInputs['image_align']);
  116. BxDolForm::setSubmittedValue('content', implode($this->sParamsDivider, array($iImageId, $sImageAlign)), $oForm->aFormAttrs['method']);
  117. }
  118. protected function onSaveBlockRss(&$oForm, &$aBlock)
  119. {
  120. $aRss = array(
  121. trim($oForm->getCleanValue('rss_url')),
  122. $oForm->getCleanValue('rss_length')
  123. );
  124. unset($oForm->aInputs['rss_url'], $oForm->aInputs['rss_length']);
  125. BxDolForm::setSubmittedValue('content', implode($this->sParamsDivider, $aRss), $oForm->aFormAttrs['method']);
  126. }
  127. protected function addInArray($aInput, $sKey, $aValues)
  128. {
  129. return BxDolStudioUtils::addInArray($aInput, $sKey, $aValues);
  130. }
  131. protected function getModuleIcon($sName, $sType = 'menu', $bReturnAsUrl = true)
  132. {
  133. $sResult = '';
  134. switch($sName) {
  135. case BX_DOL_STUDIO_MODULE_SYSTEM:
  136. $sResult = 'cog';
  137. break;
  138. case BX_DOL_STUDIO_MODULE_CUSTOM:
  139. $sResult = 'wrench';
  140. break;
  141. case BX_DOL_STUDIO_BP_SKELETONS:
  142. $sResult = 'qrcode';
  143. break;
  144. default:
  145. $sResult = parent::getModuleIcon($sName, $sType, $bReturnAsUrl);
  146. }
  147. return $sResult;
  148. }
  149. }
  150. /** @} */