BxBaseStudioBuilderPage.php 84 KB

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