BxDolStudioBuilderPage.php 6.2 KB

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