BxDolStudioBuilderPage.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php defined('BX_DOL') 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 DolphinStudio Dolphin Studio
  7. * @{
  8. */
  9. bx_import('BxTemplStudioPage');
  10. bx_import('BxDolStudioBuilderPageQuery');
  11. define('BX_DOL_STUDIO_BP_SKELETONS', 'skeletons');
  12. define('BX_DOL_STUDIO_BP_TYPE_DEFAULT', BX_DOL_STUDIO_MODULE_SYSTEM);
  13. define('BX_DOL_STUDIO_BP_BLOCK_RAW', 'raw');
  14. define('BX_DOL_STUDIO_BP_BLOCK_HTML', 'html');
  15. define('BX_DOL_STUDIO_BP_BLOCK_RSS', 'rss');
  16. define('BX_DOL_STUDIO_BP_BLOCK_IMAGE', 'image');
  17. define('BX_DOL_STUDIO_BP_BLOCK_LANG', 'lang');
  18. define('BX_DOL_STUDIO_BP_BLOCK_MENU', 'menu');
  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. //--- Check actions ---//
  49. if(($sAction = bx_get('bp_action')) !== false) {
  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. }
  77. protected function onSaveBlock(&$oForm, &$aBlock)
  78. {
  79. $iDesignboxId = (int)str_replace($this->sSelectKeyPrefix, '', $oForm->getCleanValue('designbox_id'));
  80. BxDolForm::setSubmittedValue('designbox_id', $iDesignboxId, $oForm->aFormAttrs['method']);
  81. $iVisibleFor = BxDolStudioUtils::getVisibilityValue($oForm->getCleanValue('visible_for'), $oForm->getCleanValue('visible_for_levels'));
  82. BxDolForm::setSubmittedValue('visible_for_levels', $iVisibleFor, $oForm->aFormAttrs['method']);
  83. unset($oForm->aInputs['visible_for']);
  84. //--- Process Lang fields
  85. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && isset($oForm->aInputs['content'])) {
  86. bx_import('BxDolStudioLanguagesUtils');
  87. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  88. $sContentKey = '';
  89. $sContentValue = $oForm->getCleanValue('content');
  90. if($aBlock['content'] == '') {
  91. $sContentKey = '_sys_bpb_content_' . $aBlock['id'];
  92. $oLanguage->addLanguageString($sContentKey, $sContentValue);
  93. } else {
  94. $sContentKey = $aBlock['content'];
  95. $oLanguage->updateLanguageString($sContentKey, $sContentValue);
  96. }
  97. BxDolForm::setSubmittedValue('content', $sContentKey, $oForm->aFormAttrs['method']);
  98. }
  99. //--- Process Image fields
  100. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && isset($oForm->aInputs['image_file'], $oForm->aInputs['image_align'])) {
  101. $iImageId = 0;
  102. if($aBlock['content'] != '')
  103. list($iImageId) = explode($this->sParamsDivider, $aBlock['content']);
  104. $iImageId = $oForm->processImageUploaderSave('image_file', $iImageId);
  105. if(is_string($iImageId) && !is_numeric($iImageId))
  106. return array('msg' => $iImageId);
  107. $sImageAlign = $oForm->getCleanValue('image_align');
  108. unset($oForm->aInputs['image_file'], $oForm->aInputs['image_align']);
  109. BxDolForm::setSubmittedValue('content', implode($this->sParamsDivider, array($iImageId, $sImageAlign)), $oForm->aFormAttrs['method']);
  110. }
  111. //--- Process RSS fields
  112. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_RSS && isset($oForm->aInputs['rss_url'], $oForm->aInputs['rss_length'])) {
  113. $aRss = array(
  114. trim($oForm->getCleanValue('rss_url')),
  115. $oForm->getCleanValue('rss_length')
  116. );
  117. unset($oForm->aInputs['rss_url'], $oForm->aInputs['rss_length']);
  118. BxDolForm::setSubmittedValue('content', implode($this->sParamsDivider, $aRss), $oForm->aFormAttrs['method']);
  119. }
  120. }
  121. protected function addInArray($aInput, $sKey, $aValues)
  122. {
  123. bx_import('BxDolStudioUtils');
  124. return BxDolStudioUtils::addInArray($aInput, $sKey, $aValues);
  125. }
  126. protected function getModuleIcon($sName, $sType = 'menu', $bReturnAsUrl = true)
  127. {
  128. $sResult = '';
  129. switch($sName) {
  130. case BX_DOL_STUDIO_MODULE_SYSTEM:
  131. $sResult = 'cog';
  132. break;
  133. case BX_DOL_STUDIO_MODULE_CUSTOM:
  134. $sResult = 'wrench';
  135. break;
  136. case BX_DOL_STUDIO_BP_SKELETONS:
  137. $sResult = 'qrcode';
  138. break;
  139. default:
  140. $sResult = parent::getModuleIcon($sName, $sType, $bReturnAsUrl);
  141. }
  142. return $sResult;
  143. }
  144. }
  145. /** @} */