1
0

BxBaseStudioBuilderPage.php 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150
  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 UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  8. * @{
  9. */
  10. define('BX_DOL_STUDIO_BUILDER_PAGE', 1);
  11. class BxBaseStudioBuilderPage extends BxDolStudioBuilderPage
  12. {
  13. protected $sParamsDivider = '#';
  14. protected $sSelectKeyPrefix = 'id-';
  15. protected $sActionPageCreate = 'page_create';
  16. protected $sActionPageDelete = 'page_delete';
  17. protected $sActionPageEdit = 'page_edit';
  18. protected $sActionBlockCreate = 'block_create';
  19. protected $sActionBlockEdit = 'block_edit';
  20. protected $sStorage;
  21. protected $sTranscoder;
  22. protected $aUploaders;
  23. protected $sTranscoderCover;
  24. protected $aUploadersCover;
  25. protected $sBaseUrl;
  26. protected $sTypeUrl;
  27. protected $sPageUrl;
  28. protected $aHtmlIds = array(
  29. 'add_popup_id' => 'adm-bp-add-popup',
  30. 'edit_popup_id' => 'adm-bp-edit-popup',
  31. 'uri_field_id' => 'adm-bp-field-uri',
  32. 'url_field_id' => 'adm-bp-field-url',
  33. 'settings_group_id' => 'adm-bp-settings-group-',
  34. 'settings_groups_id' => 'adm-bp-settings-groups',
  35. 'create_block_popup_id' => 'adm-bp-create-block-popup',
  36. 'edit_block_popup_id' => 'adm-bp-edit-block-popup',
  37. 'edit_block_editor_id' => 'adm-bp-edit-block-editor',
  38. 'edit_block_builder_id' => 'adm-bp-edit-block-builder',
  39. 'block_id' => 'adm-bpb-',
  40. 'block_list_id' => 'adm-bpl-',
  41. 'block_lists_id' => 'adm-bp-block-lists',
  42. 'layout_id' => 'adm-bpl-',
  43. );
  44. protected $aPageSettings = array(
  45. array('name' => 'options', 'title' => '_adm_bp_mi_page_options', 'icon' => 'mi-bp-options.svg', 'active' => 1),
  46. array('name' => 'cover', 'title' => '_adm_bp_mi_page_cover', 'icon' => 'mi-bp-cover.svg', 'active' => 0),
  47. array('name' => 'layout', 'title' => '_adm_bp_mi_page_layout', 'icon' => 'mi-bp-layout.svg', 'active' => 0),
  48. array('name' => 'visibility', 'title' => '_adm_bp_mi_page_visibility', 'icon' => 'mi-bp-visibility.svg', 'active' => 0),
  49. array('name' => 'cache', 'title' => '_adm_bp_mi_page_cache', 'icon' => 'mi-bp-cache.svg', 'active' => 0),
  50. array('name' => 'seo', 'title' => '_adm_bp_mi_page_seo', 'icon' => 'mi-bp-seo.svg', 'active' => 0),
  51. array('name' => 'injections', 'title' => '_adm_bp_mi_page_injections', 'icon' => 'mi-bp-injections.svg', 'active' => 0)
  52. );
  53. function __construct($sType = '', $sPage = '')
  54. {
  55. parent::__construct($sType, $sPage);
  56. $this->sStorage = BX_DOL_STORAGE_OBJ_IMAGES;
  57. $this->sTranscoder = 'sys_builder_page_preview';
  58. $this->aUploaders = array('sys_builder_page_html5');
  59. $this->sTranscoderCover = 'sys_cover_preview';
  60. $this->aUploadersCover = array('sys_std_crop_cover');
  61. $this->sBaseUrl = BX_DOL_URL_STUDIO . 'builder_page.php';
  62. $this->sTypeUrl = $this->sBaseUrl . '?type=%s';
  63. $this->sPageUrl = $this->sTypeUrl . '&page=%s';
  64. }
  65. function getPageCss()
  66. {
  67. $oTemplate = BxDolStudioTemplate::getInstance();
  68. $aUploaders = array_merge($this->aUploaders, $this->aUploadersCover);
  69. foreach($aUploaders as $sUploader) {
  70. $oUploader = BxDolUploader::getObjectInstance($sUploader, $this->sStorage, '', $oTemplate);
  71. if($oUploader)
  72. $oUploader->addCssJs();
  73. }
  74. return array_merge(parent::getPageCss(), [
  75. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css',
  76. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'grapesjs/|grapes.min.css',
  77. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'select2/css/|select2.min.css',
  78. 'page_layouts.css',
  79. 'builder_page.css'
  80. ]);
  81. }
  82. function getPageJs()
  83. {
  84. return array_merge(parent::getPageJs(), [
  85. 'codemirror/codemirror.min.js',
  86. 'grapesjs/grapes.min.js',
  87. 'grapesjs/grapesjs-blocks-basic.js',
  88. 'grapesjs/grapesjs-style-bg.js',
  89. 'grapesjs/grapesjs-preset-webpage.min.js',
  90. 'select2/js/select2.min.js',
  91. 'jquery-ui/jquery-ui.min.js',
  92. 'jquery.ui.touch-punch.min.js',
  93. 'jquery.easing.js',
  94. 'jquery.form.min.js',
  95. 'forms.js',
  96. 'functions.js',
  97. 'builder_page.js'
  98. ]);
  99. }
  100. function getPageJsObject()
  101. {
  102. return 'oBxDolStudioBuilderPage';
  103. }
  104. function getPageMenu($aMenu = [], $aMarkers = [])
  105. {
  106. $aMenuItems = [
  107. BX_DOL_STUDIO_BP_TYPE_SYSTEM => ['icon' => 'mi-bp-system.svg'],
  108. BX_DOL_STUDIO_BP_TYPE_CUSTOM => ['icon' => 'mi-bp-custom.svg'],
  109. BX_DOL_STUDIO_BP_TYPE_MODULES => ['icon' => 'mi-bp-modules.svg']
  110. ];
  111. $aMenu = [];
  112. foreach($aMenuItems as $sMenuItem => $aItem)
  113. $aMenu[] = [
  114. 'name' => $sMenuItem,
  115. 'icon' => $aItem['icon'],
  116. 'icon_bg' => true,
  117. 'link' => sprintf($this->sTypeUrl, $sMenuItem),
  118. 'title' => _t('_adm_bp_cpt_type_' . $sMenuItem),
  119. 'selected' => $sMenuItem == $this->sType || ($sMenuItem == BX_DOL_STUDIO_BP_TYPE_MODULES && !isset($aMenuItems[$this->sType]))
  120. ];
  121. return parent::getPageMenu($aMenu);
  122. }
  123. function getPageCode($sPage = '', $bWrap = true)
  124. {
  125. $sResult = parent::getPageCode($sPage, $bWrap);
  126. if($sResult === false)
  127. return false;
  128. $oPage = BxTemplPage::getObjectInstance($this->sPage);
  129. $oTemplate = BxDolStudioTemplate::getInstance();
  130. $sJsObject = $this->getPageJsObject();
  131. $sTxtEmpty = _t('_sys_txt_empty');
  132. $sContent = "";
  133. if(($bPage = $this->sPage != '') === true) {
  134. /**
  135. * Reset (move to hidden sell) blocks which cannot be seen,
  136. * because of unsuitable cell number to currently selected layout.
  137. */
  138. $this->oDb->resetBlocksByPage($this->aPageRebuild['object'], $this->aPageRebuild['layout_cells_number']);
  139. $aTmplVars = array(
  140. 'page_id' => 'bx-page-' . $this->aPageRebuild['uri'],
  141. 'bx_if:show_layout_row_dump' => array(
  142. 'condition' => true,
  143. 'content' => array()
  144. )
  145. );
  146. for($i = 0; $i <= $this->aPageRebuild['layout_cells_number']; $i++) {
  147. $aBlocks = array();
  148. $this->oDb->getBlocks(array('type' => 'by_object_cell', 'object' => $this->aPageRebuild['object'], 'cell' => $i), $aBlocks, false);
  149. $aTmplVarsCell = array('id' => $i, 'bx_repeat:blocks' => array());
  150. foreach($aBlocks as $aBlock) {
  151. $sTitle = strip_tags(!empty($aBlock['title_system']) ? _t($aBlock['title_system']) : $oPage->getBlockTitle($aBlock));
  152. list($sIcon, $sIconUrl) = $this->getBlockIcon($aBlock);
  153. $aTmplVarsCell['bx_repeat:blocks'][] = array(
  154. 'html_id' => $this->aHtmlIds['block_id'] . $aBlock['id'],
  155. 'bx_if:is_inactive' => array(
  156. 'condition' => (int)$aBlock['active'] == 0,
  157. 'content' => array()
  158. ),
  159. 'bx_if:show_link' => array(
  160. 'condition' => true,
  161. 'content' => array(
  162. 'onclick' => $sJsObject . ".performAction('block_edit', {id: " . $aBlock['id'] . "})",
  163. 'title' => !empty($sTitle) ? $sTitle : $sTxtEmpty,
  164. )
  165. ),
  166. 'bx_if:show_text' => array(
  167. 'condition' => false,
  168. 'content' => array()
  169. ),
  170. 'bx_if:show_api' => [
  171. 'condition' => (int)$aBlock['active_api'] != 0,
  172. 'content' => []
  173. ],
  174. 'bx_if:image' => array (
  175. 'condition' => (bool)$sIconUrl,
  176. 'content' => array('icon_url' => $sIconUrl),
  177. ),
  178. 'bx_if:icon' => array (
  179. 'condition' => (bool)$sIcon,
  180. 'content' => array('icon' => $sIcon),
  181. ),
  182. 'module' => $this->getModuleTitle($aBlock['module']),
  183. 'visible_for' => _t('_adm_bp_txt_visible_for', BxDolStudioUtils::getVisibilityTitle($aBlock['visible_for_levels'])),
  184. 'bx_if:show_checkbox' => array(
  185. 'condition' => false,
  186. 'content' => array()
  187. ),
  188. 'bx_if:show_drag_handle' => array(
  189. 'condition' => true,
  190. 'content' => array()
  191. )
  192. );
  193. }
  194. $sCell = $oTemplate->parseHtmlByName('bp_cell.html', $aTmplVarsCell);
  195. if($i == 0)
  196. $aTmplVars['bx_if:show_layout_row_dump']['content']['cell_' . $i] = $sCell;
  197. else
  198. $aTmplVars['cell_' . $i] = $sCell;
  199. }
  200. $sContent = $oTemplate->parseHtmlByName($this->aPageRebuild['layout_template'], $aTmplVars);
  201. }
  202. $aLanguages = BxDolStudioLanguagesUtils::getInstance()->getLanguages();
  203. $aTmplVars = array(
  204. 'js_object' => $sJsObject,
  205. 'action_url' => $this->sBaseUrl,
  206. 'page_url' => sprintf($this->sPageUrl, '{0}', '{1}'),
  207. 'type' => $this->sType,
  208. 'page' => $this->sPage,
  209. 'html_ids' => json_encode($this->aHtmlIds),
  210. 'languages' => json_encode($aLanguages),
  211. 'content' => $this->getBlockCode(array(
  212. 'items' => $sContent
  213. ))
  214. );
  215. $oTemplate->addJsTranslation([
  216. '_sys_not_available',
  217. '_adm_bp_wrn_page_delete',
  218. '_adm_bp_wrn_page_block_delete'
  219. ]);
  220. return $sResult . $oTemplate->parseHtmlByName('builder_page.html', $aTmplVars);
  221. }
  222. function getBlockPanelTop($aBlock)
  223. {
  224. return parent::getBlockPanelTop(
  225. array('panel_top' => BxDolStudioTemplate::getInstance()->parseHtmlByName('bp_block_panel_top.html', $this->_getTmplVarsBlockPanelTop()))
  226. );
  227. }
  228. protected function actionPageCreate()
  229. {
  230. $sJsObject = $this->getPageJsObject();
  231. $oTemplate = BxDolStudioTemplate::getInstance();
  232. $sModule = BX_DOL_STUDIO_MODULE_CUSTOM;
  233. $oForm = $this->_getPageCreateForm();
  234. $oForm->initChecker();
  235. if($oForm->isSubmittedAndValid()) {
  236. unset($oForm->aInputs['settings']);
  237. foreach($this->aPageSettings as $aSetting)
  238. $oForm->aInputs = array_merge($oForm->aInputs, $this->{'getSettings' . $this->getClassName($aSetting['name']) . 'Fields'}());
  239. $sLanguage = BxDolStudioLanguagesUtils::getInstance()->getCurrentLangName(false);
  240. $sObject = BxDolForm::getSubmittedValue('title-' . $sLanguage, $oForm->aFormAttrs['method']);
  241. $sObject = uriGenerate($sObject, 'sys_objects_page', 'object', ['empty' => 'object']);
  242. $sUri = $oForm->getCleanValue('uri');
  243. $aPage = $this->oDb->getPages(['type' => 'by_uri', 'value' => $sUri]);
  244. if(!empty($aPage) && is_array($aPage))
  245. return ['msg' => _t('_adm_bp_err_page_uri')];
  246. $iVisibleFor = BxDolStudioUtils::getVisibilityValue($oForm->getCleanValue('visible_for'), $oForm->getCleanValue('visible_for_levels'));
  247. BxDolForm::setSubmittedValue('visible_for_levels', $iVisibleFor, $oForm->aFormAttrs['method']);
  248. unset($oForm->aInputs['visible_for']);
  249. $aValsToAdd = [
  250. 'author' => bx_get_logged_profile_id(),
  251. 'object' => $sObject,
  252. 'url' => $this->sPageBaseUrl . $sUri,
  253. 'added' => time()
  254. ];
  255. $this->onSavePage($oForm, $aValsToAdd);
  256. $iId = (int)$oForm->insert($aValsToAdd);
  257. if($iId != 0) {
  258. $this->onPageChanged($oForm, $aValsToAdd);
  259. return ['eval' => $sJsObject . '.onCreatePage(\'' . $sModule . '\', \'' . $sObject . '\')'];
  260. } else {
  261. return ['msg' => _t('_adm_bp_err_page_create')];
  262. }
  263. }
  264. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['add_popup_id'], _t('_adm_bp_txt_create_popup'), $oTemplate->parseHtmlByName('bp_add_page.html', array(
  265. 'js_object' => $sJsObject,
  266. 'form_id' => $oForm->getId(),
  267. 'form' => $oForm->getCode(true)
  268. )));
  269. return array('popup' => $sContent);
  270. }
  271. protected function actionPageEdit()
  272. {
  273. $sJsObject = $this->getPageJsObject();
  274. $oTemplate = BxDolStudioTemplate::getInstance();
  275. $oForm = $this->_getPageEditForm();
  276. $oForm->initChecker();
  277. if($oForm->isSubmittedAndValid()) {
  278. unset($oForm->aInputs['settings']);
  279. foreach($this->aPageSettings as $aSetting)
  280. $oForm->aInputs = array_merge($oForm->aInputs, $this->{'getSettings' . $this->getClassName($aSetting['name']) . 'Fields'}($this->aPageRebuild, false));
  281. $mixedVisibleFor = $oForm->getCleanValue('visible_for');
  282. $mixedVisibleForLevels = $oForm->getCleanValue('visible_for_levels');
  283. if($mixedVisibleFor !== false && $mixedVisibleForLevels !== false) {
  284. $iVisibleFor = BxDolStudioUtils::getVisibilityValue($mixedVisibleFor, $mixedVisibleForLevels);
  285. BxDolForm::setSubmittedValue('visible_for_levels', $iVisibleFor, $oForm->aFormAttrs['method']);
  286. unset($oForm->aInputs['visible_for']);
  287. }
  288. $this->onSavePage($oForm, $this->aPageRebuild);
  289. if($oForm->update($this->aPageRebuild['id'])) {
  290. $this->onPageChanged($oForm, $this->aPageRebuild);
  291. $iLevelId = $oForm->getCleanValue('layout_id');
  292. if(!empty($iLevelId) && $iLevelId != $this->aPageRebuild['layout_id']) {
  293. $aLayoutOld = array();
  294. $this->oDb->getLayouts(array('type' => 'by_id', 'value' => $this->aPageRebuild['layout_id']), $aLayoutOld, false);
  295. $aLayoutNew = array();
  296. $this->oDb->getLayouts(array('type' => 'by_id', 'value' => $iLevelId), $aLayoutNew, false);
  297. if($aLayoutOld['cells_number'] > $aLayoutNew['cells_number'] && $this->oDb->resetBlocksByPage($this->sPage, $aLayoutNew['cells_number']) === false)
  298. return array('msg' => _t('_adm_bp_err_save'));
  299. return array('eval' => $sJsObject . '.onSaveSettingsLayout()');
  300. }
  301. return array();
  302. }
  303. else
  304. return array('msg' => _t('_adm_bp_err_save'));
  305. }
  306. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['edit_popup_id'], _t('_adm_bp_txt_settings_popup'), $oTemplate->parseHtmlByName('bp_edit_page.html', array(
  307. 'js_object' => $sJsObject,
  308. 'form_id' => $oForm->getId(),
  309. 'form' => $oForm->getCode(true)
  310. )));
  311. return array('popup' => $sContent);
  312. }
  313. protected function actionPageDelete()
  314. {
  315. if(empty($this->sPage) || empty($this->aPageRebuild) || !is_array($this->aPageRebuild))
  316. return array('msg' => _t('_adm_bp_err_page_delete'));
  317. $oLangauge = BxDolStudioLanguagesUtils::getInstance();
  318. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  319. $aBlocks = array();
  320. $this->oDb->getBlocks(array('type' => 'by_object', 'value' => $this->sPage), $aBlocks, false);
  321. if(is_array($aBlocks) && !empty($aBlocks)) {
  322. foreach($aBlocks as $aBlock)
  323. $this->onBlockDelete($aBlock);
  324. $this->oDb->deleteBlocks(array('type' => 'by_object', 'value' => $this->sPage));
  325. }
  326. if($this->oDb->deletePages(array('type' => 'by_object', 'value' => $this->sPage))) {
  327. $oLangauge->deleteLanguageString($this->aPageRebuild['title_system']);
  328. $oLangauge->deleteLanguageString($this->aPageRebuild['title']);
  329. $this->onPageChanged(null, $this->aPageRebuild);
  330. return array('eval' => 'window.parent.location.href = "' . sprintf($this->sTypeUrl, $this->sType) . '";');
  331. }
  332. return array('msg' => _t('_adm_bp_err_page_delete'));
  333. }
  334. protected function actionBlockList()
  335. {
  336. $sModule = BX_DOL_STUDIO_BP_TYPE_DEFAULT;
  337. if(bx_get('bp_module') !== false)
  338. $sModule = bx_process_input(bx_get('bp_module'));
  339. return array(
  340. 'content' => $this->getBlockList($sModule)
  341. );
  342. }
  343. protected function actionBlockCreate()
  344. {
  345. $sJsObject = $this->getPageJsObject();
  346. $oTemplate = BxDolStudioTemplate::getInstance();
  347. $sSelected = BX_DOL_STUDIO_BP_SKELETONS;
  348. $aForm = array(
  349. 'form_attrs' => array(
  350. 'id' => 'adm-bp-block-create',
  351. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionBlockCreate,
  352. 'method' => 'post'
  353. ),
  354. 'params' => array (
  355. 'db' => array(
  356. 'table' => 'sys_pages_blocks',
  357. 'key' => 'id',
  358. 'uri' => '',
  359. 'uri_title' => '',
  360. 'submit_name' => 'do_submit'
  361. ),
  362. ),
  363. 'inputs' => array (
  364. 'blocks' => array(
  365. 'type' => 'custom',
  366. 'name' => 'blocks',
  367. 'content' => '',
  368. 'db' => array (
  369. 'pass' => 'Int',
  370. ),
  371. ),
  372. )
  373. );
  374. $aMenu = [
  375. BX_DOL_STUDIO_BP_SKELETONS => [
  376. 'name' => BX_DOL_STUDIO_BP_SKELETONS,
  377. 'icon' => 'mi-qrcode.svg',
  378. 'icon_bg' => true,
  379. 'title' => '_sys_block_types_skeletons',
  380. 'selected' => $sSelected == BX_DOL_STUDIO_BP_SKELETONS,
  381. ],
  382. BX_DOL_STUDIO_MODULE_SYSTEM => [
  383. 'name' => BX_DOL_STUDIO_MODULE_SYSTEM,
  384. 'icon' => 'mi-cog.svg',
  385. 'icon_bg' => true,
  386. 'title' => '_sys_block_types_system',
  387. 'selected' => $sSelected == BX_DOL_STUDIO_MODULE_SYSTEM,
  388. ],
  389. BX_DOL_STUDIO_MODULE_CUSTOM => [
  390. 'name' => BX_DOL_STUDIO_MODULE_CUSTOM,
  391. 'icon' => 'mi-wrench.svg',
  392. 'icon_bg' => true,
  393. 'title' => '_sys_block_types_custom',
  394. 'selected' => $sSelected == BX_DOL_STUDIO_MODULE_CUSTOM,
  395. ]
  396. ];
  397. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(['type' => 'type', 'value' => [BX_DOL_MODULE_TYPE_MODULE, BX_DOL_MODULE_TYPE_TEMPLATE]]);
  398. $aModulesWithBlocks = $this->oDb->getModulesWithCopyableBlocks();
  399. foreach($aModules as $aModule) {
  400. $sName = $aModule['name'];
  401. if(!in_array($sName, $aModulesWithBlocks))
  402. continue;
  403. if(!empty($aMenu[$sName]))
  404. $aMenu[$sName] = array_merge($aMenu[$sName], $aModule);
  405. else
  406. $aMenu[$sName] = $aModule;
  407. if(empty($aMenu[$sName]['icon']))
  408. $aMenu[$sName]['icon'] = BxDolStudioUtils::getModuleIcon($aModule, 'menu', false);
  409. }
  410. foreach($aMenu as $sKey => $aItem)
  411. $aMenu[$sKey]['onclick'] = $sJsObject . '.onChangeModule(\'' . $aItem['name'] . '\', this);';
  412. $oMenu = new BxTemplStudioMenu(['template' => 'menu_side.html', 'menu_items' => $aMenu]);
  413. $aForm['inputs']['blocks']['content'] = $oTemplate->parseHtmlByName('bp_add_block_form.html', [
  414. 'menu' => $oMenu->getCode(),
  415. 'html_block_lists_id' => $this->aHtmlIds['block_lists_id'],
  416. 'blocks' => $this->getBlockList($sSelected)
  417. ]);
  418. $oForm = new BxTemplStudioFormView($aForm);
  419. $oForm->initChecker();
  420. if($oForm->isSubmittedAndValid()) {
  421. $aIds = $oForm->getCleanValue('blocks');
  422. $aBlocks = array();
  423. $this->oDb->getBlocks(array('type' => 'by_ids', 'value' => $aIds), $aBlocks, false);
  424. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  425. $oStorege = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  426. $bResult = true;
  427. foreach($aBlocks as $aBlock) {
  428. $sModule = $aBlock['module'];
  429. $sTitleKey = $this->getSystemName($aBlock['title'] . '_' . time());
  430. $aTitleValues = $oLanguage->getLanguageString($aBlock['title']);
  431. unset($aBlock['id']);
  432. $aBlock['object'] = $this->sPage;
  433. $aBlock['cell_id'] = 1;
  434. $aBlock['module'] = $this->getBlockModule($aBlock);
  435. $aBlock['title'] = $sTitleKey;
  436. $aBlock['copyable'] = $sModule == BX_DOL_STUDIO_BP_SKELETONS ? 1 : 0;
  437. $aBlock['deletable'] = 1;
  438. //--- Process Lang copy
  439. $sContentKey = $sContentValue = "";
  440. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && $aBlock['content'] != '') {
  441. $sContentKey = $this->getSystemName($aBlock['content'] . '_' . time());
  442. $sContentValue = _t($aBlock['content']);
  443. $aBlock['content'] = $sContentKey;
  444. $oLanguage->addLanguageString($sContentKey, $sContentValue);
  445. }
  446. //--- Process Image copy
  447. $iImageId = $sImageAlign = "";
  448. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && $aBlock['content'] != '') {
  449. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  450. $aBlock['content'] = "";
  451. if(is_numeric($iImageId) && (int)$iImageId != 0 && ($iImageId = $oStorege->storeFileFromStorage(array('id' => $iImageId))) !== false)
  452. $aBlock['content'] = implode($this->sParamsDivider, array($iImageId, $sImageAlign));
  453. }
  454. // add indexing data
  455. $aBlock = array_merge($aBlock, $this->getIndexingDataForBlock($aBlock['type'], $aBlock['content']));
  456. if(!$this->oDb->insertBlock($aBlock)) {
  457. if($sContentKey != "")
  458. $oLanguage->deleteLanguageString($sContentKey);
  459. if($iImageId != "")
  460. $oStorege->deleteFile((int)$iImageId, 0);
  461. $bResult = false;
  462. break;
  463. }
  464. //--- Process Title copy
  465. foreach($aTitleValues as $iLangId => $aTitleValue)
  466. $oLanguage->addLanguageString($sTitleKey, $aTitleValue['string'], $iLangId);
  467. }
  468. if($bResult)
  469. return array('eval' => $sJsObject . '.onCreateBlock(oData)');
  470. else
  471. return array('msg' => _t('_adm_bp_err_block_added'));
  472. }
  473. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['create_block_popup_id'], _t('_adm_bp_txt_new_block_popup'), $oTemplate->parseHtmlByName('bp_add_block.html', array(
  474. 'action' => 'create',
  475. 'form_id' => $aForm['form_attrs']['id'],
  476. 'form' => $oForm->getCode(true)
  477. )));
  478. return array('popup' => $sContent);
  479. }
  480. protected function actionBlockEdit()
  481. {
  482. $sJsObject = $this->getPageJsObject();
  483. $oTemplate = BxDolStudioTemplate::getInstance();
  484. $iId = (int)bx_get('id');
  485. if(!$iId)
  486. return array();
  487. $aBlock = array();
  488. $this->oDb->getBlocks(array('type' => 'by_id', 'value' => $iId), $aBlock, false);
  489. if(empty($aBlock) || !is_array($aBlock))
  490. return array('msg' => _t('_adm_bp_err_block_not_found'));
  491. bx_import('BxDolStudioUtils');
  492. $aForm = array(
  493. 'form_attrs' => array(
  494. 'id' => 'adm-bp-block-edit',
  495. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionBlockEdit,
  496. 'method' => 'post'
  497. ),
  498. 'params' => array (
  499. 'db' => array(
  500. 'table' => 'sys_pages_blocks',
  501. 'key' => 'id',
  502. 'uri' => '',
  503. 'uri_title' => '',
  504. 'submit_name' => 'do_submit'
  505. ),
  506. ),
  507. 'inputs' => array (
  508. 'id' => array(
  509. 'type' => 'hidden',
  510. 'name' => 'id',
  511. 'value' => $iId,
  512. 'db' => array (
  513. 'pass' => 'Int',
  514. ),
  515. ),
  516. 'title' => array(
  517. 'type' => 'text_translatable',
  518. 'name' => 'title',
  519. 'caption' => _t('_adm_bp_txt_block_title'),
  520. 'info' => _t('_adm_bp_dsc_block_title'),
  521. 'value' => $aBlock['title'],
  522. 'required' => '1',
  523. 'db' => array (
  524. 'pass' => 'Xss',
  525. ),
  526. 'checker' => array (
  527. 'func' => 'LengthTranslatable',
  528. 'params' => array(3, 100, 'title'),
  529. 'error' => _t('_adm_bp_err_block_title'),
  530. ),
  531. ),
  532. 'description' => array(
  533. 'type' => 'text_translatable',
  534. 'name' => 'description',
  535. 'caption' => _t('_adm_bp_txt_block_description'),
  536. 'info' => _t('_adm_bp_dsc_block_description'),
  537. 'value' => $aBlock['description'],
  538. 'required' => '0',
  539. 'db' => array (
  540. 'pass' => 'Xss',
  541. ),
  542. ),
  543. 'icon' => array(
  544. 'type' => 'textarea',
  545. 'name' => 'icon',
  546. 'caption' => _t('_adm_bp_txt_block_icon'),
  547. 'info' => _t('_adm_bp_dsc_block_icon'),
  548. 'value' => $aBlock['icon'],
  549. 'code' => 1,
  550. 'required' => '0',
  551. 'db' => array (
  552. 'pass' => 'Xss',
  553. ),
  554. 'attrs' => array('class' => 'bx-form-input-textarea-small'),
  555. ),
  556. 'designbox_id' => array(
  557. 'type' => 'select',
  558. 'name' => 'designbox_id',
  559. 'caption' => _t('_adm_bp_txt_block_designbox'),
  560. 'info' => '',
  561. 'value' => $this->sSelectKeyPrefix . $aBlock['designbox_id'],
  562. 'values' => array(
  563. array('key' => '', 'value' => _t('_adm_bp_txt_block_designbox_empty')),
  564. ),
  565. 'required' => '1',
  566. 'db' => array (
  567. 'pass' => 'Xss',
  568. ),
  569. 'checker' => array (
  570. 'func' => 'avail',
  571. 'params' => array(),
  572. 'error' => _t('_adm_bp_err_block_designbox'),
  573. ),
  574. ),
  575. 'async' => array(
  576. 'type' => 'select',
  577. 'name' => 'async',
  578. 'caption' => _t('_adm_bp_txt_block_async'),
  579. 'info' => '',
  580. 'value' => isset($aBlock['async']) ? $aBlock['async'] : 0,
  581. 'required' => '0',
  582. 'db' => array (
  583. 'pass' => 'Int',
  584. ),
  585. ),
  586. 'submenu' => array(
  587. 'type' => 'select',
  588. 'name' => 'submenu',
  589. 'caption' => _t('_adm_bp_txt_block_submenu'),
  590. 'info' => '',
  591. 'value' => isset($aBlock['submenu']) ? $aBlock['submenu'] : '',
  592. 'required' => '0',
  593. 'db' => array (
  594. 'pass' => 'Xss',
  595. ),
  596. ),
  597. 'tabs' => array(
  598. 'type' => 'switcher',
  599. 'name' => 'tabs',
  600. 'caption' => _t('_adm_bp_txt_block_tabs'),
  601. 'info' => '',
  602. 'value' => '1',
  603. 'checked' => $aBlock['tabs'] == '1',
  604. 'db' => array (
  605. 'pass' => 'Int',
  606. )
  607. ),
  608. 'hidden_on' => array(
  609. 'type' => 'select_multiple',
  610. 'name' => 'hidden_on',
  611. 'caption' => _t('_adm_bp_txt_block_hidden_on'),
  612. 'info' => '',
  613. 'value' => (int)$aBlock['hidden_on'],
  614. 'values' => array(
  615. BX_DB_HIDDEN_PHONE => _t('_adm_bp_txt_block_hidden_on_phone'),
  616. BX_DB_HIDDEN_TABLET => _t('_adm_bp_txt_block_hidden_on_tablet'),
  617. BX_DB_HIDDEN_DESKTOP => _t('_adm_bp_txt_block_hidden_on_desktop'),
  618. BX_DB_HIDDEN_MOBILE => _t('_adm_bp_txt_block_hidden_on_mobile')
  619. ),
  620. 'db' => array (
  621. 'pass' => 'Set',
  622. )
  623. ),
  624. 'visible_for' => array(
  625. 'type' => 'select',
  626. 'name' => 'visible_for',
  627. 'caption' => _t('_adm_bp_txt_block_visible_for'),
  628. 'info' => '',
  629. 'value' => $aBlock['visible_for_levels'] == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
  630. 'values' => array(
  631. array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_bp_txt_block_visible_for_all')),
  632. array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_bp_txt_block_visible_for_selected')),
  633. ),
  634. 'required' => '0',
  635. 'attrs' => array(
  636. 'onchange' => $sJsObject . '.onChangeVisibleFor(this)'
  637. ),
  638. 'db' => array (
  639. 'pass' => 'Xss',
  640. )
  641. ),
  642. 'visible_for_levels' => array(
  643. 'type' => 'checkbox_set',
  644. 'name' => 'visible_for_levels',
  645. 'caption' => _t('_adm_bp_txt_block_visible_for_levels'),
  646. 'info' => _t('_adm_bp_dsc_block_visible_for_levels'),
  647. 'value' => array(),
  648. 'values' => array(),
  649. 'tr_attrs' => array(
  650. 'style' => $aBlock['visible_for_levels'] == BX_DOL_INT_MAX ? 'display:none' : ''
  651. ),
  652. 'db' => array (
  653. 'pass' => 'Int',
  654. )
  655. ),
  656. 'content_empty' => array(
  657. 'type' => 'text_translatable',
  658. 'name' => 'content_empty',
  659. 'caption' => _t('_adm_bp_txt_block_content_empty'),
  660. 'info' => _t('_adm_bp_dsc_block_content_empty'),
  661. 'value' => $aBlock['content_empty'],
  662. 'db' => array (
  663. 'pass' => 'Xss',
  664. ),
  665. ),
  666. 'help' => array(
  667. 'type' => 'textarea_translatable',
  668. 'name' => 'help',
  669. 'caption' => _t('_adm_bp_txt_block_help'),
  670. 'info' => '',
  671. 'value' => $aBlock['help'],
  672. 'required' => '0',
  673. 'html' => 2,
  674. 'db' => array (
  675. 'pass' => 'Xss',
  676. ),
  677. ),
  678. 'class' => array(
  679. 'type' => 'text',
  680. 'name' => 'class',
  681. 'caption' => _t('_adm_bp_txt_block_class'),
  682. 'info' => '',
  683. 'value' => $aBlock['class'],
  684. 'required' => '0',
  685. 'db' => array (
  686. 'pass' => 'Xss',
  687. ),
  688. ),
  689. 'cache_lifetime' => array(
  690. 'type' => 'text',
  691. 'name' => 'cache_lifetime',
  692. 'caption' => _t('_adm_bp_txt_block_cache_lifetime'),
  693. 'info' => '',
  694. 'value' => isset($aBlock['cache_lifetime']) ? $aBlock['cache_lifetime'] : 0,
  695. 'required' => '0',
  696. 'db' => array (
  697. 'pass' => 'Int',
  698. ),
  699. ),
  700. 'active' => array(
  701. 'type' => 'switcher',
  702. 'name' => 'active',
  703. 'caption' => _t('_adm_bp_txt_block_active'),
  704. 'info' => '',
  705. 'value' => '1',
  706. 'checked' => $aBlock['active'] == '1',
  707. 'db' => array (
  708. 'pass' => 'Int',
  709. )
  710. ),
  711. 'active_api' => array(
  712. 'type' => 'switcher',
  713. 'name' => 'active_api',
  714. 'caption' => _t('_adm_bp_txt_block_active_api'),
  715. 'info' => '',
  716. 'value' => '1',
  717. 'checked' => $aBlock['active_api'] == '1',
  718. 'db' => array (
  719. 'pass' => 'Int',
  720. )
  721. ),
  722. 'controls' => array(
  723. 'name' => 'controls',
  724. 'type' => 'input_set',
  725. array(
  726. 'type' => 'submit',
  727. 'name' => 'do_submit',
  728. 'value' => _t('_adm_bp_btn_block_save')
  729. ),
  730. array (
  731. 'type' => 'reset',
  732. 'name' => 'close',
  733. 'value' => _t('_adm_bp_btn_block_cancel'),
  734. 'attrs' => array(
  735. 'onclick' => $sJsObject . '.onEditBlockCancel(this)',
  736. 'class' => 'bx-def-margin-sec-left',
  737. ),
  738. )
  739. )
  740. )
  741. );
  742. $aDBoxes = array();
  743. $this->oDb->getDesignBoxes(array('type' => 'ordered'), $aDBoxes, false);
  744. foreach($aDBoxes as $aDBox)
  745. $aForm['inputs']['designbox_id']['values'][] = array('key' => $this->sSelectKeyPrefix . $aDBox['id'], 'value' => _t($aDBox['title']));
  746. $aContentPlaceholders = $this->oDb->getContentPlaceholders();
  747. $aForm['inputs']['async']['values'][] = array('key' => 0, 'value' => _t('_sys_no_async'));
  748. foreach ($aContentPlaceholders as $iKey => $sTitle)
  749. $aForm['inputs']['async']['values'][] = array('key' => $iKey, 'value' => _t($sTitle));
  750. $aSubmenus = $this->oDb->getBlockSubmenus();
  751. $aForm['inputs']['submenu']['values'][] = array('key' => '', 'value' => _t('_sys_menu_item_title_inherited'));
  752. $aForm['inputs']['submenu']['values'][] = array('key' => 'disabled', 'value' => _t('_sys_menu_item_title_disabled'));
  753. foreach ($aSubmenus as $sObject => $sTitle)
  754. $aForm['inputs']['submenu']['values'][] = array('key' => $sObject, 'value' => _t($sTitle));
  755. BxDolStudioUtils::getVisibilityValues($aBlock['visible_for_levels'], $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
  756. $aForm['inputs'] = $this->addInArray($aForm['inputs'], 'visible_for_levels', $this->getBlockContent($aBlock));
  757. if((int)$aBlock['deletable'] != 0)
  758. $aForm['inputs']['controls'][] = array (
  759. 'type' => 'reset',
  760. 'name' => 'close',
  761. 'value' => _t('_adm_bp_btn_block_delete'),
  762. 'attrs' => array(
  763. 'onclick' => $sJsObject . '.deleteBlock(' . $aBlock['id'] . ')',
  764. 'class' => 'bx-def-margin-sec-left',
  765. ),
  766. );
  767. $oForm = new BxTemplStudioFormView($aForm);
  768. $oForm->initChecker();
  769. if($oForm->isSubmittedAndValid()) {
  770. $this->onSaveBlock($oForm, $aBlock);
  771. // add indexing data
  772. $aBlockAddon = $this->getIndexingDataForBlock($aBlock['type'], $oForm->getCleanValue('content'));
  773. if($oForm->update($iId, $aBlockAddon) !== false)
  774. return array('eval' => $sJsObject . '.onEditBlock(oData)');
  775. else
  776. return array('msg' => _t('_adm_bp_err_block_edit'));
  777. }
  778. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['edit_block_popup_id'], _t('_adm_bp_txt_edit_block_popup', _t($aBlock['title_system'])), $oTemplate->parseHtmlByName('bp_add_block.html', array(
  779. 'action' => 'edit',
  780. 'form_id' => $aForm['form_attrs']['id'],
  781. 'form' => $oForm->getCode(true)
  782. )));
  783. return array('popup' => array('html' => $sContent, 'options' => array('onBeforeShow' => $sJsObject . '.onEditBlockBeforeShow($el)')));
  784. }
  785. protected function actionBlockDelete()
  786. {
  787. $sJsObject = $this->getPageJsObject();
  788. $iId = (int)bx_get('id');
  789. $aBlock = array();
  790. $this->oDb->getBlocks(array('type' => 'by_id', 'value' => $iId), $aBlock, false);
  791. if(empty($aBlock) || !is_array($aBlock))
  792. return array('msg' => _t('_adm_bp_err_block_not_found'));
  793. if((int)$aBlock['deletable'] == 0)
  794. return array('msg' => _t('_adm_bp_err_block_not_deletable'));
  795. if(!$this->oDb->deleteBlocks(array('type' => 'by_id', 'value' => $iId)))
  796. return array('msg' => _t('_adm_bp_err_block_delete'));
  797. $this->onBlockDelete($aBlock);
  798. return array('eval' => $sJsObject . '.onDeleteBlock(' . $iId . ', oData)');
  799. }
  800. protected function actionUriGet()
  801. {
  802. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  803. $aLanguages = $oLanguage->getLanguages();
  804. $sLanguageDef = $oLanguage->getDefaultLangName();
  805. $sLanguageCur = $oLanguage->getCurrentLangName(false);
  806. $aValues = array();
  807. foreach($aLanguages as $sName => $sTitle)
  808. if(($mixedValue = bx_get($sName)) !== false)
  809. $aValues[$sName] = bx_process_input($mixedValue);
  810. $sUri = "";
  811. if(($mixedValue = bx_get('uri')) !== false)
  812. $sUri = bx_process_input($mixedValue);
  813. else if(array_key_exists('en', $aValues) && $aValues['en'] != '')
  814. $sUri = $aValues['en'];
  815. else if(array_key_exists($sLanguageDef, $aValues) && $aValues[$sLanguageDef] != '')
  816. $sUri = $aValues[$sLanguageDef];
  817. else if(array_key_exists($sLanguageCur, $aValues) && $aValues[$sLanguageCur] != '')
  818. $sUri = $aValues[$sLanguageCur];
  819. else if(count($aValues) > 0)
  820. foreach($aValues as $sValue)
  821. if(!empty($sValue)) {
  822. $sUri = $sValue;
  823. break;
  824. }
  825. $sUri = $sUri != "" ? uriGenerate($sUri, 'sys_objects_page', 'uri') : "";
  826. $sUrl = BxDolPermalinks::getInstance()->permalink($this->sPageBaseUrl . $sUri);
  827. return array('eval' => $this->getPageJsObject() . '.onGetUri(oData)', 'uri' => $sUri, 'url' => $sUrl);
  828. }
  829. protected function getSettingsOptions($aPage = array(), $bCreate = true, $bInputsOnly = false)
  830. {
  831. $aForm = array(
  832. 'form_attrs' => array(
  833. 'id' => 'adm-bp-settings-options',
  834. ),
  835. 'params' => array (
  836. 'remove_form' => '1',
  837. 'csrf' => array(
  838. 'disable' => true
  839. )
  840. ),
  841. 'inputs' => array (
  842. 'title_system' => array(
  843. 'type' => 'text_translatable',
  844. 'name' => 'title_system',
  845. 'caption' => _t('_adm_bp_txt_page_title_system'),
  846. 'info' => _t('_adm_bp_dsc_page_title_system'),
  847. 'value' => isset($aPage['title_system']) ? $aPage['title_system'] : '',
  848. 'required' => '1',
  849. 'db' => array (
  850. 'pass' => 'Xss',
  851. ),
  852. 'checker' => array (
  853. 'func' => 'length',
  854. 'params' => array(3,100),
  855. 'error' => _t('_adm_bp_err_page_title_system'),
  856. ),
  857. ),
  858. 'title' => array(
  859. 'type' => 'text_translatable',
  860. 'name' => 'title',
  861. 'caption' => _t('_adm_bp_txt_page_title'),
  862. 'info' => _t('_adm_bp_dsc_page_title'),
  863. 'value' => isset($aPage['title']) ? $aPage['title'] : '',
  864. 'required' => '1',
  865. 'db' => array (
  866. 'pass' => 'Xss',
  867. ),
  868. 'checker' => array (
  869. 'func' => 'length',
  870. 'params' => array(3,100),
  871. 'error' => _t('_adm_bp_err_page_title'),
  872. ),
  873. ),
  874. 'url' => array(
  875. 'type' => 'text',
  876. 'name' => 'url',
  877. 'caption' => _t('_adm_bp_txt_page_url'),
  878. 'info' => _t('_adm_bp_dsc_page_url'),
  879. 'value' => isset($aPage['url']) ? BxDolPermalinks::getInstance()->permalink($aPage['url']) : '',
  880. 'required' => '0',
  881. 'attrs' => array(
  882. 'id' => $this->aHtmlIds['url_field_id'],
  883. 'disabled' => 'disabled'
  884. ),
  885. ),
  886. 'type_id' => array(
  887. 'type' => 'select',
  888. 'name' => 'type_id',
  889. 'caption' => _t('_adm_bp_txt_page_type_id'),
  890. 'info' => _t('_adm_bp_dsc_page_type_id'),
  891. 'value' => isset($aPage['type_id']) ? $aPage['type_id'] : '',
  892. 'required' => '1',
  893. 'db' => array (
  894. 'pass' => 'Int',
  895. ),
  896. ),
  897. 'submenu' => array(
  898. 'type' => 'select',
  899. 'name' => 'submenu',
  900. 'caption' => _t('_adm_bp_txt_page_submenu'),
  901. 'info' => _t('_adm_bp_dsc_page_submenu'),
  902. 'value' => isset($aPage['submenu']) ? $aPage['submenu'] : '',
  903. 'required' => '0',
  904. 'db' => array (
  905. 'pass' => 'Xss',
  906. ),
  907. ),
  908. 'sticky_columns' => array(
  909. 'type' => 'switcher',
  910. 'name' => 'sticky_columns',
  911. 'caption' => _t('_adm_bp_txt_page_sticky_columns'),
  912. 'info' => '',
  913. 'value' => '1',
  914. 'checked' => isset($aPage['sticky_columns']) && $aPage['sticky_columns'] == 1,
  915. 'db' => array (
  916. 'pass' => 'Int',
  917. )
  918. )
  919. )
  920. );
  921. $aTypes = array();
  922. $this->oDb->getTypes(array('type' => 'all'), $aTypes, false);
  923. foreach($aTypes as $aType)
  924. $aForm['inputs']['type_id']['values'][] = array('key' => $aType['id'], 'value' => _t($aType['title']));
  925. $aSubmenus = $this->oDb->getSubmenus();
  926. $aForm['inputs']['submenu']['values'][] = array('key' => '', 'value' => _t('_sys_menu_item_title_inherited'));
  927. $aForm['inputs']['submenu']['values'][] = array('key' => 'disabled', 'value' => _t('_sys_menu_item_title_disabled'));
  928. foreach ($aSubmenus as $sObject => $sTitle)
  929. $aForm['inputs']['submenu']['values'][] = array('key' => $sObject, 'value' => _t($sTitle));
  930. if($bCreate) {
  931. $sJsObject = $this->getPageJsObject();
  932. $aForm['inputs']['title']['attrs']['onblur'] = $sJsObject . '.getUri(this);';
  933. $aForm['inputs'] = bx_array_insert_before(array(
  934. 'uri' => array(
  935. 'type' => 'text',
  936. 'name' => 'uri',
  937. 'caption' => _t('_adm_bp_txt_page_uri'),
  938. 'info' => _t('_adm_bp_dsc_page_uri'),
  939. 'value' => '',
  940. 'required' => '1',
  941. 'attrs' => array(
  942. 'id' => $this->aHtmlIds['uri_field_id'],
  943. 'onblur' => $sJsObject . '.getUri(this);'
  944. ),
  945. 'db' => array (
  946. 'pass' => 'Xss',
  947. ),
  948. 'checker' => array (
  949. 'func' => 'length',
  950. 'params' => array(3,100),
  951. 'error' => _t('_adm_bp_err_page_uri'),
  952. ),
  953. )
  954. ), $aForm['inputs'], 'url');
  955. }
  956. if($bInputsOnly)
  957. return $aForm['inputs'];
  958. $oForm = new BxTemplStudioFormView($aForm);
  959. return $oForm->getCode();
  960. }
  961. protected function getSettingsOptionsFields($aPage = array(), $bCreate = true)
  962. {
  963. return $this->getSettingsOptions($aPage, $bCreate, true);
  964. }
  965. protected function getSettingsCover($aPage = array(), $bCreate = true, $bInputsOnly = false)
  966. {
  967. $aForm = array(
  968. 'form_attrs' => array(
  969. 'id' => 'adm-bp-settings-cover',
  970. ),
  971. 'params' => array (
  972. 'remove_form' => '1',
  973. 'csrf' => array(
  974. 'disable' => true
  975. )
  976. ),
  977. 'inputs' => array (
  978. 'cover' => array(
  979. 'type' => 'select',
  980. 'name' => 'cover',
  981. 'caption' => _t('_adm_bp_txt_page_cover'),
  982. 'info' => '',
  983. 'value' => isset($aPage['cover']) ? (int)$aPage['cover'] : '1',
  984. 'values' => array(
  985. array('key' => 0, 'value' => _t('_adm_bp_txt_page_cover_0')),
  986. array('key' => 1, 'value' => _t('_adm_bp_txt_page_cover_1')),
  987. array('key' => 2, 'value' => _t('_adm_bp_txt_page_cover_2')),
  988. array('key' => 3, 'value' => _t('_adm_bp_txt_page_cover_3'))
  989. ),
  990. 'db' => array (
  991. 'pass' => 'Int',
  992. )
  993. ),
  994. 'cover_image' => array(
  995. 'type' => 'files',
  996. 'name' => 'cover_image',
  997. 'storage_object' => $this->sStorage,
  998. 'images_transcoder' => $this->sTranscoderCover,
  999. 'uploaders' => $this->aUploadersCover,
  1000. 'multiple' => false,
  1001. 'content_id' => isset($aPage['id']) ? $aPage['id'] : 0,
  1002. 'ghost_template' => BxTemplStudioFunctions::getInstance()->getDefaultGhostTemplate('cover_image'),
  1003. 'caption' => _t('_adm_bp_txt_page_cover_image'),
  1004. 'db' => array (
  1005. 'pass' => 'Int',
  1006. )
  1007. ),
  1008. 'cover_title' => array(
  1009. 'type' => 'text_translatable',
  1010. 'name' => 'cover_title',
  1011. 'caption' => _t('_adm_bp_txt_page_cover_title'),
  1012. 'info' => '',
  1013. 'value' => isset($aPage['cover_title']) ? $aPage['cover_title'] : '',
  1014. 'db' => array (
  1015. 'pass' => 'Xss',
  1016. )
  1017. ),
  1018. )
  1019. );
  1020. if($bInputsOnly)
  1021. return $aForm['inputs'];
  1022. $oForm = new BxTemplStudioFormView($aForm);
  1023. return $oForm->getCode();
  1024. }
  1025. protected function getSettingsCoverFields($aPage = array(), $bCreate = true)
  1026. {
  1027. return $this->getSettingsCover($aPage, $bCreate, true);
  1028. }
  1029. protected function getSettingsLayout($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1030. {
  1031. $sJsObject = $this->getPageJsObject();
  1032. $oTemplate = BxDolStudioTemplate::getInstance();
  1033. $iLayout = isset($aPage['layout_id']) ? (int)$aPage['layout_id'] : 5;
  1034. $aLayouts = array();
  1035. $this->oDb->getLayouts(array('type' => 'all'), $aLayouts, false);
  1036. $aTmplParams = array(
  1037. 'bx_repeat:layouts' => array(),
  1038. 'form' => ''
  1039. );
  1040. foreach($aLayouts as $aLayout)
  1041. $aTmplParams['bx_repeat:layouts'][] = array(
  1042. 'id' => $aLayout['id'],
  1043. 'html_id' => $this->aHtmlIds['layout_id'] . $aLayout['id'],
  1044. 'js_object' => $sJsObject,
  1045. 'bx_if:active' => array(
  1046. 'condition' => (int)$aLayout['id'] == $iLayout,
  1047. 'content' => array()
  1048. ),
  1049. 'icon' => $oTemplate->getImageUrl($aLayout['icon']),
  1050. 'title' => _t($aLayout['title']),
  1051. );
  1052. $aForm = array(
  1053. 'form_attrs' => array(
  1054. 'id' => 'adm-bp-settings-layout',
  1055. ),
  1056. 'params' => array (
  1057. 'remove_form' => '1',
  1058. 'csrf' => array(
  1059. 'disable' => true
  1060. )
  1061. ),
  1062. 'inputs' => array (
  1063. 'layout_id' => array(
  1064. 'type' => 'hidden',
  1065. 'name' => 'layout_id',
  1066. 'value' => $iLayout,
  1067. 'db' => array (
  1068. 'pass' => 'Int',
  1069. ),
  1070. )
  1071. )
  1072. );
  1073. if($bInputsOnly)
  1074. return $aForm['inputs'];
  1075. $oForm = new BxTemplStudioFormView($aForm);
  1076. $aTmplParams['form'] = $oForm->getCode();
  1077. return $oTemplate->parseHtmlByName('bp_layouts.html', $aTmplParams);
  1078. }
  1079. protected function getSettingsLayoutFields($aPage = array(), $bCreate = true)
  1080. {
  1081. return $this->getSettingsLayout($aPage, $bCreate, true);
  1082. }
  1083. protected function getSettingsVisibility($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1084. {
  1085. $iVisibleForLevels = isset($aPage['visible_for_levels']) ? (int)$aPage['visible_for_levels'] : BX_DOL_INT_MAX;
  1086. if(isset($aPage['visible_for_levels_editable']) && (int)$aPage['visible_for_levels_editable'] == 0)
  1087. $aInputs = array(
  1088. 'visible_for_levels' => array(
  1089. 'type' => 'custom',
  1090. 'name' => 'visible_for_levels',
  1091. 'content' => MsgBox(_t('_adm_bp_err_page_visible_for_levels'))
  1092. )
  1093. );
  1094. else {
  1095. bx_import('BxDolStudioUtils');
  1096. $aInputs = array(
  1097. 'visible_for' => array(
  1098. 'type' => 'select',
  1099. 'name' => 'visible_for',
  1100. 'caption' => _t('_adm_bp_txt_block_visible_for'),
  1101. 'info' => '',
  1102. 'value' => $iVisibleForLevels == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
  1103. 'values' => array(
  1104. array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_bp_txt_block_visible_for_all')),
  1105. array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_bp_txt_block_visible_for_selected')),
  1106. ),
  1107. 'required' => '0',
  1108. 'attrs' => array(
  1109. 'onchange' => $this->getPageJsObject() . '.onChangeVisibleFor(this)'
  1110. ),
  1111. 'db' => array (
  1112. 'pass' => 'Xss',
  1113. )
  1114. ),
  1115. 'visible_for_levels' => array(
  1116. 'type' => 'checkbox_set',
  1117. 'name' => 'visible_for_levels',
  1118. 'caption' => _t('_adm_bp_txt_page_visible_for_levels'),
  1119. 'info' => _t('_adm_bp_dsc_page_visible_for_levels'),
  1120. 'value' => array(),
  1121. 'values' => array(),
  1122. 'tr_attrs' => array(
  1123. 'style' => $iVisibleForLevels == BX_DOL_INT_MAX ? 'display:none' : ''
  1124. ),
  1125. 'db' => array (
  1126. 'pass' => 'Int',
  1127. )
  1128. )
  1129. );
  1130. }
  1131. $aForm = array(
  1132. 'form_attrs' => array(
  1133. 'id' => 'adm-bp-settings-visibility',
  1134. ),
  1135. 'params' => array (
  1136. 'remove_form' => '1',
  1137. 'csrf' => array(
  1138. 'disable' => true
  1139. )
  1140. ),
  1141. 'inputs' => $aInputs
  1142. );
  1143. BxDolStudioUtils::getVisibilityValues($iVisibleForLevels, $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
  1144. if($bInputsOnly)
  1145. return $aForm['inputs'];
  1146. $oForm = new BxTemplStudioFormView($aForm);
  1147. return $oForm->getCode();
  1148. }
  1149. protected function getSettingsVisibilityFields($aPage = array(), $bCreate = true)
  1150. {
  1151. return $this->getSettingsVisibility($aPage, $bCreate, true);
  1152. }
  1153. protected function getSettingsCache($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1154. {
  1155. $aForm = array(
  1156. 'form_attrs' => array(
  1157. 'id' => 'adm-bp-settings-cache',
  1158. ),
  1159. 'params' => array (
  1160. 'remove_form' => '1',
  1161. 'csrf' => array(
  1162. 'disable' => true
  1163. )
  1164. ),
  1165. 'inputs' => array (
  1166. 'cache_lifetime' => array(
  1167. 'type' => 'text',
  1168. 'name' => 'cache_lifetime',
  1169. 'caption' => _t('_adm_bp_txt_page_cache_lifetime'),
  1170. 'info' => _t('_adm_bp_dsc_page_cache_lifetime'),
  1171. 'value' => isset($aPage['cache_lifetime']) ? $aPage['cache_lifetime'] : 0,
  1172. 'required' => '',
  1173. 'attrs' => array(
  1174. 'disabled' => isset($aPage['cache_editable']) && (int)$aPage['cache_editable'] == 0 ? 'disabled' : ''
  1175. ),
  1176. 'db' => array (
  1177. 'pass' => 'Int',
  1178. )
  1179. ),
  1180. )
  1181. );
  1182. if($bInputsOnly)
  1183. return $aForm['inputs'];
  1184. $oForm = new BxTemplStudioFormView($aForm);
  1185. return $oForm->getCode();
  1186. }
  1187. protected function getSettingsCacheFields($aPage = array(), $bCreate = true)
  1188. {
  1189. return $this->getSettingsCache($aPage, $bCreate, true);
  1190. }
  1191. protected function getSettingsSeo($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1192. {
  1193. $aForm = array(
  1194. 'form_attrs' => array(
  1195. 'id' => 'adm-bp-settings-seo',
  1196. ),
  1197. 'params' => array (
  1198. 'remove_form' => '1',
  1199. 'csrf' => array(
  1200. 'disable' => true
  1201. )
  1202. ),
  1203. 'inputs' => array (
  1204. 'meta_title' => array(
  1205. 'type' => 'text',
  1206. 'name' => 'meta_title',
  1207. 'caption' => _t('_adm_bp_txt_page_meta_title'),
  1208. 'value' => isset($aPage['meta_title']) ? $aPage['meta_title'] : '',
  1209. 'db' => array (
  1210. 'pass' => 'Xss',
  1211. ),
  1212. ),
  1213. 'meta_description' => array(
  1214. 'type' => 'textarea',
  1215. 'name' => 'meta_description',
  1216. 'caption' => _t('_adm_bp_txt_page_meta_description'),
  1217. 'info' => _t('_adm_bp_dsc_page_meta_description'),
  1218. 'value' => isset($aPage['meta_description']) ? $aPage['meta_description'] : '',
  1219. 'db' => array (
  1220. 'pass' => 'Xss',
  1221. ),
  1222. ),
  1223. 'meta_keywords' => array(
  1224. 'type' => 'textarea',
  1225. 'name' => 'meta_keywords',
  1226. 'caption' => _t('_adm_bp_txt_page_meta_keywords'),
  1227. 'info' => _t('_adm_bp_dsc_page_meta_keywords'),
  1228. 'value' => isset($aPage['meta_keywords']) ? $aPage['meta_keywords'] : '',
  1229. 'db' => array (
  1230. 'pass' => 'Xss',
  1231. ),
  1232. ),
  1233. 'meta_robots' => array(
  1234. 'type' => 'text',
  1235. 'name' => 'meta_robots',
  1236. 'caption' => _t('_adm_bp_txt_page_meta_robots'),
  1237. 'info' => _t('_adm_bp_dsc_page_meta_robots'),
  1238. 'value' => isset($aPage['meta_robots']) ? $aPage['meta_robots'] : '',
  1239. 'required' => '0',
  1240. 'db' => array (
  1241. 'pass' => 'Xss',
  1242. )
  1243. )
  1244. )
  1245. );
  1246. if($bInputsOnly)
  1247. return $aForm['inputs'];
  1248. $oForm = new BxTemplStudioFormView($aForm);
  1249. return $oForm->getCode();
  1250. }
  1251. protected function getSettingsSeoFields($aPage = array(), $bCreate = true)
  1252. {
  1253. return $this->getSettingsSeo($aPage, $bCreate, true);
  1254. }
  1255. protected function getSettingsInjections($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1256. {
  1257. $aForm = array(
  1258. 'form_attrs' => array(
  1259. 'id' => 'adm-bp-injections-seo',
  1260. ),
  1261. 'params' => array (
  1262. 'remove_form' => '1',
  1263. 'csrf' => array(
  1264. 'disable' => true
  1265. )
  1266. ),
  1267. 'inputs' => array (
  1268. 'inj_head' => array(
  1269. 'type' => 'textarea',
  1270. 'name' => 'inj_head',
  1271. 'caption' => _t('_adm_bp_txt_page_inj_head'),
  1272. 'info' => _t('_adm_bp_dsc_page_inj_head'),
  1273. 'value' => isset($aPage['inj_head']) ? $aPage['inj_head'] : '',
  1274. 'code' => 1,
  1275. 'db' => array (
  1276. 'pass' => 'XssHtml',
  1277. ),
  1278. ),
  1279. 'inj_footer' => array(
  1280. 'type' => 'textarea',
  1281. 'name' => 'inj_footer',
  1282. 'caption' => _t('_adm_bp_txt_page_inj_footer'),
  1283. 'info' => _t('_adm_bp_dsc_page_inj_footer'),
  1284. 'value' => isset($aPage['inj_footer']) ? $aPage['inj_footer'] : '',
  1285. 'code' => 1,
  1286. 'db' => array (
  1287. 'pass' => 'XssHtml',
  1288. ),
  1289. )
  1290. )
  1291. );
  1292. if($bInputsOnly)
  1293. return $aForm['inputs'];
  1294. $oForm = new BxTemplStudioFormView($aForm);
  1295. return $oForm->getCode();
  1296. }
  1297. protected function getSettingsInjectionsFields($aPage = array(), $bCreate = true)
  1298. {
  1299. return $this->getSettingsInjections($aPage, $bCreate, true);
  1300. }
  1301. protected function getBlockIcon($aBlock)
  1302. {
  1303. $sIcon = $sIconUrl = "";
  1304. $sResult = '';
  1305. switch($aBlock['type']) {
  1306. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1307. $sResult = 'far file-alt';
  1308. break;
  1309. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1310. $sResult = 'code';
  1311. break;
  1312. case BX_DOL_STUDIO_BP_BLOCK_CREATIVE:
  1313. $sResult = 'object-group';
  1314. break;
  1315. case BX_DOL_STUDIO_BP_BLOCK_BENTO_GRID:
  1316. $sResult = 'fa-grip-horizontal';
  1317. break;
  1318. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1319. $sResult = 'rss';
  1320. break;
  1321. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1322. $sResult = 'far image';
  1323. break;
  1324. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1325. $sResult = 'globe';
  1326. break;
  1327. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1328. $sResult = 'list-alt';
  1329. break;
  1330. case BX_DOL_STUDIO_BP_BLOCK_WIKI:
  1331. $sResult = 'file-word';
  1332. break;
  1333. case BX_DOL_STUDIO_BP_BLOCK_CUSTOM:
  1334. $sResult = 'file';
  1335. break;
  1336. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1337. $sResult = $this->getModuleIcon($aBlock['module'], 'page');
  1338. break;
  1339. }
  1340. if(strpos($sResult, '.') === false)
  1341. $sIcon = $sResult;
  1342. else
  1343. $sIconUrl = $sResult;
  1344. return array($sIcon, $sIconUrl);
  1345. }
  1346. protected function getBlockModule($aBlock)
  1347. {
  1348. return $aBlock['module'] != BX_DOL_STUDIO_BP_SKELETONS ? $aBlock['module'] : BX_DOL_STUDIO_MODULE_CUSTOM;
  1349. }
  1350. protected function getBlockContent($aBlock)
  1351. {
  1352. $aFields = array();
  1353. switch($aBlock['type']) {
  1354. case BX_DOL_STUDIO_BP_BLOCK_CUSTOM:
  1355. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1356. case BX_DOL_STUDIO_BP_BLOCK_BENTO_GRID:
  1357. $aFields = [
  1358. 'content' => [
  1359. 'type' => 'textarea',
  1360. 'name' => 'content',
  1361. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1362. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1363. 'value' => $aBlock['content'],
  1364. 'required' => '0',
  1365. 'code' => 1,
  1366. 'attrs' => [
  1367. 'class' => 'bx-form-input-textarea-codemirror'
  1368. ],
  1369. 'db' => [
  1370. 'pass' => 'XssHtml',
  1371. ],
  1372. ],
  1373. ];
  1374. break;
  1375. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1376. $aFields = [
  1377. 'content' => [
  1378. 'type' => 'textarea',
  1379. 'name' => 'content',
  1380. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1381. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1382. 'value' => $aBlock['content'],
  1383. 'required' => '0',
  1384. 'html' => 2,
  1385. 'html_toggle' => true,
  1386. 'attrs' => [
  1387. 'id' => $this->aHtmlIds['edit_block_editor_id']
  1388. ],
  1389. 'db' => [
  1390. 'pass' => 'XssHtml',
  1391. ],
  1392. ],
  1393. 'attachments' => [
  1394. 'type' => 'files',
  1395. 'name' => 'attachments',
  1396. 'storage_object' => $this->sStorage,
  1397. 'images_transcoder' => $this->sTranscoder,
  1398. 'uploaders' => $this->aUploaders,
  1399. 'multiple' => true,
  1400. 'content_id' => $aBlock['id'],
  1401. 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('bp_fgt_attachments.html', [
  1402. 'js_object' => $this->getPageJsObject(),
  1403. 'name' => 'attachments',
  1404. 'editor_id' => $this->aHtmlIds['edit_block_editor_id'],
  1405. ]),
  1406. 'caption' => _t('_adm_bp_txt_block_content_attachments_html')
  1407. ]
  1408. ];
  1409. break;
  1410. case BX_DOL_STUDIO_BP_BLOCK_CREATIVE:
  1411. $oTemplate = BxDolStudioTemplate::getInstance();
  1412. $sContent = $oTemplate->parseHtmlByName('bp_block_skeleton_creative.html', [
  1413. 'html_id' => $this->aHtmlIds['edit_block_builder_id'],
  1414. 'content_html' => $aBlock['content'],
  1415. 'content_data' => json_encode([
  1416. 'pages' => [
  1417. ['component' => $aBlock['content']]
  1418. ]
  1419. ])
  1420. ]);
  1421. $aFields = [
  1422. 'content' => [
  1423. 'type' => 'custom',
  1424. 'name' => 'content',
  1425. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1426. 'content' => $sContent,
  1427. 'required' => '0',
  1428. 'db' => [
  1429. 'pass' => 'XssHtml',
  1430. ],
  1431. ],
  1432. ];
  1433. break;
  1434. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1435. $aFields = [
  1436. 'content' => [
  1437. 'type' => 'textarea_translatable',
  1438. 'name' => 'content',
  1439. 'caption' => _t('_adm_bp_txt_block_content_lang'),
  1440. 'info' => _t('_adm_bp_dsc_block_content_lang'),
  1441. 'value' => $aBlock['content'],
  1442. 'required' => '0',
  1443. 'html' => 2,
  1444. 'html_toggle' => true,
  1445. 'db' => [
  1446. 'pass' => 'XssHtml',
  1447. ],
  1448. ],
  1449. ];
  1450. break;
  1451. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1452. $iImageId = $sImageAlign = '';
  1453. if($aBlock['content'] != '')
  1454. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1455. $aFields = [
  1456. 'content' => [
  1457. 'type' => 'hidden',
  1458. 'name' => 'content',
  1459. 'value' => '',
  1460. 'db' => [
  1461. 'pass' => 'Xss',
  1462. ],
  1463. ],
  1464. 'image_file' => [
  1465. 'type' => 'files',
  1466. 'name' => 'image_file',
  1467. 'storage_object' => BX_DOL_STORAGE_OBJ_IMAGES,
  1468. 'images_transcoder' => 'sys_image_resize',
  1469. 'uploaders' => ['sys_html5'],
  1470. 'multiple' => false,
  1471. 'content_id' => $aBlock['id'],
  1472. 'ghost_template' => BxTemplStudioFunctions::getInstance()->getDefaultGhostTemplate('image_file'),
  1473. 'caption' => _t('_adm_bp_txt_block_content_image_file'),
  1474. ],
  1475. 'image_align' => [
  1476. 'type' => 'select',
  1477. 'name' => 'image_align',
  1478. 'caption' => _t('_adm_bp_txt_block_content_image_align'),
  1479. 'info' => '',
  1480. 'value' => $sImageAlign,
  1481. 'values' => [
  1482. ['key' => '', 'value' => _t('_adm_bp_txt_block_content_image_align_empty')],
  1483. ['key' => 'left', 'value' => _t('_adm_bp_txt_block_content_image_align_left')],
  1484. ['key' => 'center', 'value' => _t('_adm_bp_txt_block_content_image_align_center')],
  1485. ['key' => 'right', 'value' => _t('_adm_bp_txt_block_content_image_align_right')],
  1486. ],
  1487. 'required' => '0',
  1488. 'db' => [
  1489. 'pass' => 'Xss',
  1490. ],
  1491. ],
  1492. ];
  1493. break;
  1494. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1495. $sRssUrl = $sRssLength = '';
  1496. if($aBlock['content'] != '')
  1497. list($sRssUrl, $sRssLength) = explode($this->sParamsDivider, $aBlock['content']);
  1498. $aFields = [
  1499. 'content' => [
  1500. 'type' => 'hidden',
  1501. 'name' => 'content',
  1502. 'value' => '',
  1503. 'db' => [
  1504. 'pass' => 'Xss',
  1505. ],
  1506. ],
  1507. 'rss_url' => [
  1508. 'type' => 'text',
  1509. 'name' => 'rss_url',
  1510. 'caption' => _t('_adm_bp_txt_block_content_rss_url'),
  1511. 'info' => _t('_adm_bp_dsc_block_content_rss_url'),
  1512. 'value' => $sRssUrl,
  1513. 'required' => '0',
  1514. 'db' => [
  1515. 'pass' => 'Xss',
  1516. ],
  1517. ],
  1518. 'rss_length' => [
  1519. 'type' => 'text',
  1520. 'name' => 'rss_length',
  1521. 'caption' => _t('_adm_bp_txt_block_content_rss_length'),
  1522. 'info' => _t('_adm_bp_dsc_block_content_rss_length'),
  1523. 'value' => $sRssLength,
  1524. 'required' => '0',
  1525. 'db' => [
  1526. 'pass' => 'Int',
  1527. ],
  1528. ],
  1529. ];
  1530. break;
  1531. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1532. $aFields = [
  1533. 'content' => [
  1534. 'type' => 'select',
  1535. 'name' => 'content',
  1536. 'caption' => _t('_adm_bp_txt_block_content_menu'),
  1537. 'info' => '',
  1538. 'value' => $aBlock['content'],
  1539. 'values' => [],
  1540. 'required' => '0',
  1541. 'db' => [
  1542. 'pass' => 'Xss',
  1543. ],
  1544. ]
  1545. ];
  1546. $sGroup = '';
  1547. $aMenus = $this->oDb->getMenus(true);
  1548. foreach($aMenus as $sKey => $aMenu) {
  1549. if($sGroup != $aMenu['module']) {
  1550. if(!empty($sGroup))
  1551. $aFields['content']['values'][$sGroup . '_end'] = ['type' => 'group_end'];
  1552. $sGroup = $aMenu['module'];
  1553. $aFields['content']['values'][$sGroup . '_beg'] = ['type' => 'group_header', 'value' => BxDolStudioUtils::getModuleTitle($sGroup)];
  1554. }
  1555. $aFields['content']['values'][$sKey] = _t($aMenu['title']);
  1556. }
  1557. $aFields['content']['values'] = array_merge(['' => _t('_adm_bp_txt_block_content_menu_empty')], $aFields['content']['values']);
  1558. break;
  1559. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1560. $aService = ['module' => '', 'method' => ''];
  1561. if($aBlock['content'] != '')
  1562. $aService = unserialize($aBlock['content']);
  1563. $aFields = [
  1564. 'service_module' => [
  1565. 'type' => 'value',
  1566. 'name' => 'service_module',
  1567. 'caption' => _t('_adm_bp_txt_block_content_service_module'),
  1568. 'value' => $this->getModuleTitle($aService['module'])
  1569. ],
  1570. 'service_method' => [
  1571. 'type' => 'value',
  1572. 'name' => 'service_method',
  1573. 'caption' => _t('_adm_bp_txt_block_content_service_method'),
  1574. 'value' => $aService['method']
  1575. ]
  1576. ];
  1577. break;
  1578. }
  1579. return $aFields;
  1580. }
  1581. protected function getBlockList($sModule)
  1582. {
  1583. if(empty($sModule))
  1584. return '';
  1585. $sJsObject = $this->getPageJsObject();
  1586. $oTemplate = BxDolStudioTemplate::getInstance();
  1587. $oForm = new BxTemplStudioFormView(array());
  1588. $aInputCheckbox = [
  1589. 'type' => 'checkbox',
  1590. 'name' => 'blocks[]',
  1591. 'attrs' => [
  1592. 'onChange' => 'javascript:' . $sJsObject . '.onSelectBlock(this);'
  1593. ],
  1594. 'value' => ''
  1595. ];
  1596. $aTmplParams = [
  1597. 'html_block_list_id' => $this->aHtmlIds['block_list_id'] . $sModule,
  1598. 'bx_repeat:blocks' => []
  1599. ];
  1600. $aBlocks = $this->getBlocks($sModule);
  1601. foreach($aBlocks as $aBlock) {
  1602. list($sIcon, $sIconUrl) = $this->getBlockIcon($aBlock);
  1603. $aInputCheckbox['value'] = $aBlock['id'];
  1604. $aTmplParams['bx_repeat:blocks'][] = [
  1605. 'js_object' => $sJsObject,
  1606. 'html_id' => $this->aHtmlIds['block_id'] . $aBlock['id'],
  1607. 'bx_if:is_inactive' => array(
  1608. 'condition' => false,
  1609. 'content' => [true]
  1610. ),
  1611. 'bx_if:show_link' => [
  1612. 'condition' => false,
  1613. 'content' => [true]
  1614. ],
  1615. 'bx_if:show_text' => [
  1616. 'condition' => true,
  1617. 'content' => [
  1618. 'title' => _t(!empty($aBlock['title_system']) ? $aBlock['title_system'] : $aBlock['title']),
  1619. ]
  1620. ],
  1621. 'bx_if:show_api' => [
  1622. 'condition' => false,
  1623. 'content' => [true]
  1624. ],
  1625. 'bx_if:image' => [
  1626. 'condition' => (bool)$sIconUrl,
  1627. 'content' => array('icon_url' => $sIconUrl),
  1628. ],
  1629. 'bx_if:icon' => [
  1630. 'condition' => (bool)$sIcon,
  1631. 'content' => ['icon' => $sIcon],
  1632. ],
  1633. 'module' => $this->getModuleTitle($aBlock['module']),
  1634. 'visible_for' => _t('_adm_bp_txt_visible_for', BxDolStudioUtils::getVisibilityTitle($aBlock['visible_for_levels'])),
  1635. 'bx_if:show_checkbox' => [
  1636. 'condition' => true,
  1637. 'content' => [
  1638. 'content' => $oForm->genRow($aInputCheckbox)
  1639. ]
  1640. ],
  1641. 'bx_if:show_drag_handle' => [
  1642. 'condition' => false,
  1643. 'content' => []
  1644. ]
  1645. ];
  1646. }
  1647. return $oTemplate->parseHtmlByName('bp_blocks_list.html', $aTmplParams);
  1648. }
  1649. protected function onBlockDelete($aBlock)
  1650. {
  1651. if($aBlock['module'] != BX_DOL_STUDIO_MODULE_CUSTOM)
  1652. return;
  1653. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['title']);
  1654. //--- Process Lang block
  1655. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && $aBlock['content'] != '')
  1656. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['content']);
  1657. //--- Process Image block
  1658. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && $aBlock['content'] != '') {
  1659. $iImageId = $sImageAlign = '';
  1660. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1661. if(is_numeric($iImageId) && (int)$iImageId != 0)
  1662. BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$iImageId, 0);
  1663. }
  1664. }
  1665. protected function getBlocks($sModule)
  1666. {
  1667. $aBlocks = array();
  1668. $this->oDb->getBlocks(array('type' => 'by_module_to_copy', 'value' => $sModule), $aBlocks, false);
  1669. return $aBlocks;
  1670. }
  1671. protected function _getPageCreateForm()
  1672. {
  1673. $oTemplate = BxDolStudioTemplate::getInstance();
  1674. $sForm = 'adm-bp-page-create';
  1675. $aForm = array(
  1676. 'form_attrs' => array(
  1677. 'id' => $sForm,
  1678. 'name' => $sForm,
  1679. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionPageCreate,
  1680. 'method' => 'post'
  1681. ),
  1682. 'params' => array (
  1683. 'db' => array(
  1684. 'table' => 'sys_objects_page',
  1685. 'key' => 'id',
  1686. 'uri' => '',
  1687. 'uri_title' => '',
  1688. 'submit_name' => 'do_submit'
  1689. ),
  1690. 'display' => $sForm
  1691. ),
  1692. 'inputs' => array (
  1693. 'module' => array(
  1694. 'type' => 'hidden',
  1695. 'name' => 'module',
  1696. 'value' => BX_DOL_STUDIO_MODULE_CUSTOM,
  1697. 'db' => array (
  1698. 'pass' => 'Xss',
  1699. ),
  1700. ),
  1701. 'deletable' => array(
  1702. 'type' => 'hidden',
  1703. 'name' => 'deletable',
  1704. 'value' => 1,
  1705. 'db' => array (
  1706. 'pass' => 'Int',
  1707. ),
  1708. ),
  1709. 'settings' => array(
  1710. 'type' => 'custom',
  1711. 'name' => 'settings',
  1712. 'content' => $oTemplate->parseHtmlByName('bp_edit_page_form.html', $this->_getTmplVarsPageSettings()),
  1713. ),
  1714. )
  1715. );
  1716. return new BxTemplStudioFormView($aForm);
  1717. }
  1718. protected function _getPageEditForm()
  1719. {
  1720. $oTemplate = BxDolStudioTemplate::getInstance();
  1721. $sForm = 'adm-bp-page-edit';
  1722. $aForm = array(
  1723. 'form_attrs' => array(
  1724. 'id' => $sForm,
  1725. 'name' => $sForm,
  1726. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionPageEdit,
  1727. 'method' => 'post'
  1728. ),
  1729. 'params' => array (
  1730. 'db' => array(
  1731. 'table' => 'sys_objects_page',
  1732. 'key' => 'id',
  1733. 'uri' => '',
  1734. 'uri_title' => '',
  1735. 'submit_name' => 'do_submit'
  1736. ),
  1737. 'display' => $sForm
  1738. ),
  1739. 'inputs' => array (
  1740. 'settings' => array(
  1741. 'type' => 'custom',
  1742. 'name' => 'settings',
  1743. 'content' => $oTemplate->parseHtmlByName('bp_edit_page_form.html', $this->_getTmplVarsPageSettings($this->aPageRebuild, false)),
  1744. ),
  1745. )
  1746. );
  1747. return new BxTemplStudioFormView($aForm);
  1748. }
  1749. protected function _getTmplVarsBlockPanelTop()
  1750. {
  1751. $oPermalink = BxDolPermalinks::getInstance();
  1752. $sJsObject = $this->getPageJsObject();
  1753. $aInputTypes = [];
  1754. if(!in_array($this->sType, [BX_DOL_STUDIO_BP_TYPE_SYSTEM, BX_DOL_STUDIO_BP_TYPE_CUSTOM])) {
  1755. $aModulesDb = $this->oDb->getPages(['type' => 'modules_with_pages']);
  1756. $aInputTypesValues = [[
  1757. 'key' => '',
  1758. 'value' => _t('_adm_txt_select_module')
  1759. ]];
  1760. foreach($aModulesDb as $aModuleDb) {
  1761. $sName = $aModuleDb['name'];
  1762. if($sName == BX_DOL_STUDIO_MODULE_SYSTEM)
  1763. continue;
  1764. $aInputTypesValues[] = [
  1765. 'key' => $sName,
  1766. 'value' => BxDolStudioUtils::getModuleTitle($sName)
  1767. ];
  1768. }
  1769. $aInputTypes = [
  1770. 'type' => 'select',
  1771. 'name' => 'page',
  1772. 'attrs' => [
  1773. 'onChange' => 'javascript:' . $sJsObject . '.onChangeType(this)'
  1774. ],
  1775. 'value' => $this->sType,
  1776. 'values' => $aInputTypesValues
  1777. ];
  1778. }
  1779. $aPages = $this->oDb->getPages(['type' => 'by_module', 'value' => $this->sType]);
  1780. $aCounter = [];
  1781. $this->oDb->getBlocks(['type' => 'counter_by_pages'], $aCounter, false);
  1782. $aInputPagesValues = [];
  1783. foreach($aPages as $aPage) {
  1784. $sTitle = _t($aPage['title_system']);
  1785. if(empty($sTitle))
  1786. $sTitle = _t($aPage['title']);
  1787. $aInputPagesValues[] = [
  1788. 'key' => $aPage['object'],
  1789. 'value' => $sTitle,
  1790. 'attrs' => [
  1791. 'data-url' => $aPage['url'] ? $oPermalink->permalink($aPage['url']) : '',
  1792. 'data-blocks' => $aCounter[$aPage['object']] ?? 0
  1793. ]
  1794. ];
  1795. }
  1796. usort($aInputPagesValues, function($aV1, $aV2) {
  1797. return strcmp($aV1['value'], $aV2['value']);
  1798. });
  1799. $aInputPages = [
  1800. 'type' => 'select',
  1801. 'name' => 'page',
  1802. 'attrs' => [
  1803. 'onChange' => 'javascript:' . $sJsObject . '.onChangePage(this)'
  1804. ],
  1805. 'value' => $this->sPage,
  1806. 'values' => array_merge([[
  1807. 'key' => '',
  1808. 'value' => _t('_adm_bp_txt_select_page')
  1809. ]], $aInputPagesValues)
  1810. ];
  1811. $aTmplVarsActions = [];
  1812. if(($this->sPage != '' && !empty($this->aPageRebuild)) !== false)
  1813. $aTmplVarsActions = $this->_getTmplVarsBlockPanelTopActions();
  1814. $oForm = new BxTemplStudioFormView([]);
  1815. return [
  1816. 'js_object' => $sJsObject,
  1817. 'bx_if:show_selector_types' => [
  1818. 'condition' => !empty($aInputTypes),
  1819. 'content' => [
  1820. 'selector_types' => $oForm->genRow($aInputTypes),
  1821. ]
  1822. ],
  1823. 'selector_pages' => $oForm->genRow($aInputPages),
  1824. 'action_page_create' => $this->sActionPageCreate,
  1825. 'bx_if:show_actions' => [
  1826. 'condition' => $this->sPage != '',
  1827. 'content' => $aTmplVarsActions
  1828. ]
  1829. ];
  1830. }
  1831. protected function _getTmplVarsBlockPanelTopActions()
  1832. {
  1833. $sJsObject = $this->getPageJsObject();
  1834. $oPermalinks = BxDolPermalinks::getInstance();
  1835. return [
  1836. 'js_object' => $sJsObject,
  1837. 'bx_if:can_view' => [
  1838. 'condition' => !empty($this->aPageRebuild['url']),
  1839. 'content' => [
  1840. 'url_view' => bx_absolute_url($oPermalinks->permalink($this->aPageRebuild['url'])),
  1841. ]
  1842. ],
  1843. 'action_page_edit' => $this->sActionPageEdit,
  1844. 'bx_if:can_delete' => [
  1845. 'condition' => (int)$this->aPageRebuild['deletable'] == 1,
  1846. 'content' => [
  1847. 'js_object' => $sJsObject
  1848. ]
  1849. ],
  1850. 'action_block_create' => $this->sActionBlockCreate,
  1851. ];
  1852. }
  1853. protected function _getTmplVarsPageSettings($aPage = array(), $bCreate = true)
  1854. {
  1855. $sJsObject = $this->getPageJsObject();
  1856. $aTmplParams = array(
  1857. 'js_object' => $sJsObject,
  1858. 'menu' => array(),
  1859. 'html_settings_groups_id' => $this->aHtmlIds['settings_groups_id'],
  1860. 'bx_repeat:settings_groups' => array(),
  1861. 'submit' => _t($bCreate ? '_adm_bp_btn_page_create' : '_adm_bp_btn_page_apply')
  1862. );
  1863. foreach($this->aPageSettings as $aSetting) {
  1864. //--- get menu items
  1865. $aTmplParams['menu'][$aSetting['name']] = array(
  1866. 'name' => $aSetting['name'],
  1867. 'icon' => $aSetting['icon'] ?? '', // a Lucide glyph on the sidebar tile, like the app pages' side menus
  1868. 'icon_bg' => true,
  1869. 'onclick' => $sJsObject . '.onChangeSettingGroup(\'' . $aSetting['name'] . '\', this);',
  1870. 'title' => $aSetting['title'],
  1871. 'selected' => isset($aSetting['active']) && (int)$aSetting['active'] == 1
  1872. );
  1873. //--- get settings
  1874. $aTmplParams['bx_repeat:settings_groups'][] = array(
  1875. 'html_settings_group_id' => $this->aHtmlIds['settings_group_id'] . $aSetting['name'],
  1876. 'bx_if:hidden' => array(
  1877. 'condition' => $aSetting['active'] != 1,
  1878. 'content' => array()
  1879. ),
  1880. 'content' => $this->{'getSettings' . $this->getClassName($aSetting['name'])}($aPage, $bCreate)
  1881. );
  1882. }
  1883. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aTmplParams['menu']));
  1884. $aTmplParams['menu'] = $oMenu->getCode();
  1885. return $aTmplParams;
  1886. }
  1887. protected function getIndexingDataForBlock($sType, $sContent)
  1888. {
  1889. $aBlock = array();
  1890. switch($sType) {
  1891. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1892. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1893. $aBlock['text'] = trim(strip_tags($sContent));
  1894. $aBlock['text_updated'] = time();
  1895. break;
  1896. }
  1897. return $aBlock;
  1898. }
  1899. protected function onPageChanged($oForm, $aPage)
  1900. {
  1901. $this->oDb->cleanCache('sys_pages_objects_data');
  1902. $this->oDb->cleanCache('sys_pages_uri_object_map');
  1903. $this->oDb->cleanCache('sys_pages_urirewrite_object_map');
  1904. }
  1905. }
  1906. /** @} */