BxBaseStudioBuilderPage.php 82 KB

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