BxBaseStudioBuilderPage.php 80 KB

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