BxBaseStudioBuilderPage.php 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047
  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 = array(), $aMarkers = array())
  101. {
  102. $aMenuItems = array(
  103. BX_DOL_STUDIO_MODULE_SYSTEM => array(
  104. 'name' => BX_DOL_STUDIO_MODULE_SYSTEM,
  105. 'icon' => 'mi-cog.svg',
  106. 'icon_bg' => true
  107. ),
  108. BX_DOL_STUDIO_MODULE_CUSTOM => array(
  109. 'name' => BX_DOL_STUDIO_MODULE_CUSTOM,
  110. 'icon' => 'mi-wrench.svg',
  111. 'icon_bg' => true,
  112. 'title' => '_adm_bp_cpt_type_' . BX_DOL_STUDIO_MODULE_CUSTOM,
  113. )
  114. );
  115. $aModulesDb = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'type', 'value' => array(BX_DOL_MODULE_TYPE_MODULE, BX_DOL_MODULE_TYPE_TEMPLATE)));
  116. foreach($aModulesDb as $aModuleDb) {
  117. $sName = $aModuleDb['name'];
  118. if(!empty($aMenuItems[$sName]))
  119. $aMenuItems[$sName] = array_merge($aMenuItems[$sName], $aModuleDb);
  120. else
  121. $aMenuItems[$sName] = $aModuleDb;
  122. $aMenuItems[$sName]['title'] = BxDolStudioUtils::getModuleTitle($sName);
  123. if(empty($aMenuItems[$sName]['icon']))
  124. $aMenuItems[$sName]['icon'] = BxDolStudioUtils::getModuleIcon($aModuleDb, 'menu', false);
  125. }
  126. $aMenu = [];
  127. foreach($aMenuItems as $aMenuItem)
  128. $aMenu[] = array_merge($aMenuItem, [
  129. 'link' => sprintf($this->sTypeUrl, $aMenuItem['name']),
  130. 'selected' => $aMenuItem['name'] == $this->sType
  131. ]);
  132. return parent::getPageMenu($aMenu);
  133. }
  134. function getPageCode($sPage = '', $bWrap = true)
  135. {
  136. $sResult = parent::getPageCode($sPage, $bWrap);
  137. if($sResult === false)
  138. return false;
  139. $oPage = BxTemplPage::getObjectInstance($this->sPage);
  140. $oTemplate = BxDolStudioTemplate::getInstance();
  141. $sJsObject = $this->getPageJsObject();
  142. $sTxtEmpty = _t('_sys_txt_empty');
  143. $sContent = "";
  144. if(($bPage = $this->sPage != '') === true) {
  145. /**
  146. * Reset (move to hidden sell) blocks which cannot be seen,
  147. * because of unsuitable cell number to currently selected layout.
  148. */
  149. $this->oDb->resetBlocksByPage($this->aPageRebuild['object'], $this->aPageRebuild['layout_cells_number']);
  150. $aTmplVars = array(
  151. 'page_id' => 'bx-page-' . $this->aPageRebuild['uri'],
  152. 'bx_if:show_layout_row_dump' => array(
  153. 'condition' => true,
  154. 'content' => array()
  155. )
  156. );
  157. for($i = 0; $i <= $this->aPageRebuild['layout_cells_number']; $i++) {
  158. $aBlocks = array();
  159. $this->oDb->getBlocks(array('type' => 'by_object_cell', 'object' => $this->aPageRebuild['object'], 'cell' => $i), $aBlocks, false);
  160. $aTmplVarsCell = array('id' => $i, 'bx_repeat:blocks' => array());
  161. foreach($aBlocks as $aBlock) {
  162. $sTitle = !empty($aBlock['title_system']) ? _t($aBlock['title_system']) : $oPage->getBlockTitle($aBlock);
  163. list($sIcon, $sIconUrl) = $this->getBlockIcon($aBlock);
  164. $aTmplVarsCell['bx_repeat:blocks'][] = array(
  165. 'html_id' => $this->aHtmlIds['block_id'] . $aBlock['id'],
  166. 'bx_if:is_inactive' => array(
  167. 'condition' => (int)$aBlock['active'] == 0,
  168. 'content' => array()
  169. ),
  170. 'bx_if:show_link' => array(
  171. 'condition' => true,
  172. 'content' => array(
  173. 'onclick' => $sJsObject . ".performAction('block_edit', {id: " . $aBlock['id'] . "})",
  174. 'title' => !empty($sTitle) ? $sTitle : $sTxtEmpty,
  175. )
  176. ),
  177. 'bx_if:show_text' => array(
  178. 'condition' => false,
  179. 'content' => array()
  180. ),
  181. 'bx_if:show_api' => [
  182. 'condition' => (int)$aBlock['active_api'] != 0,
  183. 'content' => []
  184. ],
  185. 'bx_if:image' => array (
  186. 'condition' => (bool)$sIconUrl,
  187. 'content' => array('icon_url' => $sIconUrl),
  188. ),
  189. 'bx_if:icon' => array (
  190. 'condition' => (bool)$sIcon,
  191. 'content' => array('icon' => $sIcon),
  192. ),
  193. 'module' => $this->getModuleTitle($aBlock['module']),
  194. 'visible_for' => _t('_adm_bp_txt_visible_for', BxDolStudioUtils::getVisibilityTitle($aBlock['visible_for_levels'])),
  195. 'bx_if:show_checkbox' => array(
  196. 'condition' => false,
  197. 'content' => array()
  198. ),
  199. 'bx_if:show_drag_handle' => array(
  200. 'condition' => true,
  201. 'content' => array()
  202. )
  203. );
  204. }
  205. $sCell = $oTemplate->parseHtmlByName('bp_cell.html', $aTmplVarsCell);
  206. if($i == 0)
  207. $aTmplVars['bx_if:show_layout_row_dump']['content']['cell_' . $i] = $sCell;
  208. else
  209. $aTmplVars['cell_' . $i] = $sCell;
  210. }
  211. $sContent = $oTemplate->parseHtmlByName($this->aPageRebuild['layout_template'], $aTmplVars);
  212. }
  213. $aLanguages = BxDolStudioLanguagesUtils::getInstance()->getLanguages();
  214. $aTmplVars = array(
  215. 'js_object' => $sJsObject,
  216. 'action_url' => $this->sBaseUrl,
  217. 'page_url' => sprintf($this->sPageUrl, '{0}', '{1}'),
  218. 'type' => $this->sType,
  219. 'page' => $this->sPage,
  220. 'html_ids' => json_encode($this->aHtmlIds),
  221. 'languahes' => json_encode($aLanguages),
  222. 'content' => $this->getBlockCode(array(
  223. 'items' => $sContent
  224. ))
  225. );
  226. $oTemplate->addJsTranslation(array(
  227. '_adm_bp_wrn_page_delete',
  228. '_adm_bp_wrn_page_block_delete'
  229. ));
  230. return $sResult . $oTemplate->parseHtmlByName('builder_page.html', $aTmplVars);
  231. }
  232. function getBlockPanelTop($aBlock)
  233. {
  234. return parent::getBlockPanelTop(
  235. array('panel_top' => BxDolStudioTemplate::getInstance()->parseHtmlByName('bp_block_panel_top.html', $this->_getTmplVarsBlockPanelTop()))
  236. );
  237. }
  238. protected function actionPageCreate()
  239. {
  240. $sJsObject = $this->getPageJsObject();
  241. $oTemplate = BxDolStudioTemplate::getInstance();
  242. $sModule = BX_DOL_STUDIO_MODULE_CUSTOM;
  243. $aForm = array(
  244. 'form_attrs' => array(
  245. 'id' => 'adm-bp-page-create',
  246. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionPageCreate,
  247. 'method' => 'post'
  248. ),
  249. 'params' => array (
  250. 'db' => array(
  251. 'table' => 'sys_objects_page',
  252. 'key' => 'id',
  253. 'uri' => '',
  254. 'uri_title' => '',
  255. 'submit_name' => 'do_submit'
  256. ),
  257. ),
  258. 'inputs' => array (
  259. 'module' => array(
  260. 'type' => 'hidden',
  261. 'name' => 'module',
  262. 'value' => $sModule,
  263. 'db' => array (
  264. 'pass' => 'Xss',
  265. ),
  266. ),
  267. 'deletable' => array(
  268. 'type' => 'hidden',
  269. 'name' => 'deletable',
  270. 'value' => 1,
  271. 'db' => array (
  272. 'pass' => 'Int',
  273. ),
  274. ),
  275. 'settings' => array(
  276. 'type' => 'custom',
  277. 'name' => 'settings',
  278. 'content' => $oTemplate->parseHtmlByName('bp_edit_page_form.html', $this->_getTmplVarsPageSettings()),
  279. ),
  280. )
  281. );
  282. $oForm = new BxTemplStudioFormView($aForm);
  283. $oForm->initChecker();
  284. if($oForm->isSubmittedAndValid()) {
  285. unset($oForm->aInputs['settings']);
  286. foreach($this->aPageSettings as $aSetting)
  287. $oForm->aInputs = array_merge($oForm->aInputs, $this->{'getSettings' . $this->getClassName($aSetting['name']) . 'Fields'}());
  288. $sLanguage = BxDolStudioLanguagesUtils::getInstance()->getCurrentLangName(false);
  289. $sObject = BxDolForm::getSubmittedValue('title-' . $sLanguage, $aForm['form_attrs']['method']);
  290. $sObject = uriGenerate($sObject, 'sys_objects_page', 'object', ['empty' => 'object']);
  291. $sUri = $oForm->getCleanValue('uri');
  292. $aPage = $this->oDb->getPages(array('type' => 'by_uri', 'value' => $sUri));
  293. if(!empty($aPage) && is_array($aPage))
  294. return array('msg' => _t('_adm_bp_err_page_uri'));
  295. $iVisibleFor = BxDolStudioUtils::getVisibilityValue($oForm->getCleanValue('visible_for'), $oForm->getCleanValue('visible_for_levels'));
  296. BxDolForm::setSubmittedValue('visible_for_levels', $iVisibleFor, $aForm['form_attrs']['method']);
  297. unset($oForm->aInputs['visible_for']);
  298. $iId = (int)$oForm->insert(array('author' => bx_get_logged_profile_id(), 'added' => time(), 'object' => $sObject, 'url' => $this->sPageBaseUrl . $sUri));
  299. if($iId != 0)
  300. return array('eval' => $sJsObject . '.onCreatePage(\'' . $sModule . '\', \'' . $sObject . '\')');
  301. else
  302. return array('msg' => _t('_adm_bp_err_page_create'));
  303. }
  304. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['add_popup_id'], _t('_adm_bp_txt_create_popup'), $oTemplate->parseHtmlByName('bp_add_page.html', array(
  305. 'js_object' => $sJsObject,
  306. 'form_id' => $aForm['form_attrs']['id'],
  307. 'form' => $oForm->getCode(true)
  308. )));
  309. return array('popup' => $sContent);
  310. }
  311. protected function actionPageEdit()
  312. {
  313. $sJsObject = $this->getPageJsObject();
  314. $oTemplate = BxDolStudioTemplate::getInstance();
  315. $aForm = array(
  316. 'form_attrs' => array(
  317. 'id' => 'adm-bp-page-edit',
  318. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionPageEdit,
  319. 'method' => 'post'
  320. ),
  321. 'params' => array (
  322. 'db' => array(
  323. 'table' => 'sys_objects_page',
  324. 'key' => 'id',
  325. 'uri' => '',
  326. 'uri_title' => '',
  327. 'submit_name' => 'do_submit'
  328. ),
  329. ),
  330. 'inputs' => array (
  331. 'settings' => array(
  332. 'type' => 'custom',
  333. 'name' => 'settings',
  334. 'content' => $oTemplate->parseHtmlByName('bp_edit_page_form.html', $this->_getTmplVarsPageSettings($this->aPageRebuild, false)),
  335. ),
  336. )
  337. );
  338. $oForm = new BxTemplStudioFormView($aForm);
  339. $oForm->initChecker();
  340. if($oForm->isSubmittedAndValid()) {
  341. unset($oForm->aInputs['settings']);
  342. foreach($this->aPageSettings as $aSetting)
  343. $oForm->aInputs = array_merge($oForm->aInputs, $this->{'getSettings' . $this->getClassName($aSetting['name']) . 'Fields'}($this->aPageRebuild, false));
  344. $mixedVisibleFor = $oForm->getCleanValue('visible_for');
  345. $mixedVisibleForLevels = $oForm->getCleanValue('visible_for_levels');
  346. if($mixedVisibleFor !== false && $mixedVisibleForLevels !== false) {
  347. $iVisibleFor = BxDolStudioUtils::getVisibilityValue($mixedVisibleFor, $mixedVisibleForLevels);
  348. BxDolForm::setSubmittedValue('visible_for_levels', $iVisibleFor, $aForm['form_attrs']['method']);
  349. unset($oForm->aInputs['visible_for']);
  350. }
  351. if($oForm->update($this->aPageRebuild['id'])) {
  352. $iLevelId = $oForm->getCleanValue('layout_id');
  353. if(!empty($iLevelId) && $iLevelId != $this->aPageRebuild['layout_id']) {
  354. $aLayoutOld = array();
  355. $this->oDb->getLayouts(array('type' => 'by_id', 'value' => $this->aPageRebuild['layout_id']), $aLayoutOld, false);
  356. $aLayoutNew = array();
  357. $this->oDb->getLayouts(array('type' => 'by_id', 'value' => $iLevelId), $aLayoutNew, false);
  358. if($aLayoutOld['cells_number'] > $aLayoutNew['cells_number'] && $this->oDb->resetBlocksByPage($this->sPage, $aLayoutNew['cells_number']) === false)
  359. return array('msg' => _t('_adm_bp_err_save'));
  360. return array('eval' => $sJsObject . '.onSaveSettingsLayout()');
  361. }
  362. return array();
  363. }
  364. else
  365. return array('msg' => _t('_adm_bp_err_save'));
  366. }
  367. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['edit_popup_id'], _t('_adm_bp_txt_settings_popup'), $oTemplate->parseHtmlByName('bp_edit_page.html', array(
  368. 'js_object' => $sJsObject,
  369. 'form_id' => $aForm['form_attrs']['id'],
  370. 'form' => $oForm->getCode(true)
  371. )));
  372. return array('popup' => $sContent);
  373. }
  374. protected function actionPageDelete()
  375. {
  376. if(empty($this->sPage) || empty($this->aPageRebuild) || !is_array($this->aPageRebuild))
  377. return array('msg' => _t('_adm_bp_err_page_delete'));
  378. $oLangauge = BxDolStudioLanguagesUtils::getInstance();
  379. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  380. $aBlocks = array();
  381. $this->oDb->getBlocks(array('type' => 'by_object', 'value' => $this->sPage), $aBlocks, false);
  382. if(is_array($aBlocks) && !empty($aBlocks)) {
  383. foreach($aBlocks as $aBlock)
  384. $this->onBlockDelete($aBlock);
  385. $this->oDb->deleteBlocks(array('type' => 'by_object', 'value' => $this->sPage));
  386. }
  387. if($this->oDb->deletePages(array('type' => 'by_object', 'value' => $this->sPage))) {
  388. $oLangauge->deleteLanguageString($this->aPageRebuild['title_system']);
  389. $oLangauge->deleteLanguageString($this->aPageRebuild['title']);
  390. return array('eval' => 'window.parent.location.href = "' . sprintf($this->sTypeUrl, $this->sType) . '";');
  391. }
  392. return array('msg' => _t('_adm_bp_err_page_delete'));
  393. }
  394. protected function actionBlockList()
  395. {
  396. $sModule = BX_DOL_STUDIO_BP_TYPE_DEFAULT;
  397. if(bx_get('bp_module') !== false)
  398. $sModule = bx_process_input(bx_get('bp_module'));
  399. return array(
  400. 'content' => $this->getBlockList($sModule)
  401. );
  402. }
  403. protected function actionBlockCreate()
  404. {
  405. $sJsObject = $this->getPageJsObject();
  406. $oTemplate = BxDolStudioTemplate::getInstance();
  407. $sSelected = BX_DOL_STUDIO_BP_SKELETONS;
  408. $aForm = array(
  409. 'form_attrs' => array(
  410. 'id' => 'adm-bp-block-create',
  411. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionBlockCreate,
  412. 'method' => 'post'
  413. ),
  414. 'params' => array (
  415. 'db' => array(
  416. 'table' => 'sys_pages_blocks',
  417. 'key' => 'id',
  418. 'uri' => '',
  419. 'uri_title' => '',
  420. 'submit_name' => 'do_submit'
  421. ),
  422. ),
  423. 'inputs' => array (
  424. 'blocks' => array(
  425. 'type' => 'custom',
  426. 'name' => 'blocks',
  427. 'content' => '',
  428. 'db' => array (
  429. 'pass' => 'Int',
  430. ),
  431. ),
  432. )
  433. );
  434. $aMenu = array(
  435. BX_DOL_STUDIO_BP_SKELETONS => array(
  436. 'name' => BX_DOL_STUDIO_BP_SKELETONS,
  437. 'icon' => 'mi-qrcode.svg',
  438. 'icon_bg' => true,
  439. 'title' => '_sys_block_types_skeletons',
  440. 'selected' => $sSelected == BX_DOL_STUDIO_BP_SKELETONS,
  441. ),
  442. BX_DOL_STUDIO_MODULE_SYSTEM => array(
  443. 'name' => BX_DOL_STUDIO_MODULE_SYSTEM,
  444. 'icon' => 'mi-cog.svg',
  445. 'icon_bg' => true,
  446. 'title' => '_sys_block_types_system',
  447. 'selected' => $sSelected == BX_DOL_STUDIO_MODULE_SYSTEM,
  448. ),
  449. BX_DOL_STUDIO_MODULE_CUSTOM => array(
  450. 'name' => BX_DOL_STUDIO_MODULE_CUSTOM,
  451. 'icon' => 'mi-wrench.svg',
  452. 'icon_bg' => true,
  453. 'title' => '_sys_block_types_custom',
  454. 'selected' => $sSelected == BX_DOL_STUDIO_MODULE_CUSTOM,
  455. )
  456. );
  457. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(['type' => 'type', 'value' => [BX_DOL_MODULE_TYPE_MODULE, BX_DOL_MODULE_TYPE_TEMPLATE]]);
  458. $aModulesWithBlocks = $this->oDb->getModulesWithCopyableBlocks();
  459. foreach($aModules as $aModule) {
  460. $sName = $aModule['name'];
  461. if(!in_array($sName, $aModulesWithBlocks))
  462. continue;
  463. if(!empty($aMenu[$sName]))
  464. $aMenu[$sName] = array_merge($aMenu[$sName], $aModule);
  465. else
  466. $aMenu[$sName] = $aModule;
  467. if(empty($aMenu[$sName]['icon']))
  468. $aMenu[$sName]['icon'] = BxDolStudioUtils::getModuleIcon($aModule, 'menu', false);
  469. }
  470. foreach($aMenu as $sKey => $aItem)
  471. $aMenu[$sKey]['onclick'] = $sJsObject . '.onChangeModule(\'' . $aItem['name'] . '\', this);';
  472. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aMenu));
  473. $oMenu->setInlineIcons(false);
  474. $aTmplParams = array(
  475. 'menu' => $oMenu->getCode(),
  476. 'html_block_lists_id' => $this->aHtmlIds['block_lists_id'],
  477. 'blocks' => $this->getBlockList($sSelected)
  478. );
  479. $aForm['inputs']['blocks']['content'] = $oTemplate->parseHtmlByName('bp_add_block_form.html', $aTmplParams);
  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'])), $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_RSS:
  1354. $sResult = 'rss';
  1355. break;
  1356. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1357. $sResult = 'far image';
  1358. break;
  1359. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1360. $sResult = 'globe';
  1361. break;
  1362. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1363. $sResult = 'list-alt';
  1364. break;
  1365. case BX_DOL_STUDIO_BP_BLOCK_WIKI:
  1366. $sResult = 'file-word';
  1367. break;
  1368. case BX_DOL_STUDIO_BP_BLOCK_CUSTOM:
  1369. $sResult = 'file';
  1370. break;
  1371. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1372. $sResult = $this->getModuleIcon($aBlock['module'], 'page');
  1373. break;
  1374. }
  1375. if(strpos($sResult, '.') === false)
  1376. $sIcon = $sResult;
  1377. else
  1378. $sIconUrl = $sResult;
  1379. return array($sIcon, $sIconUrl);
  1380. }
  1381. protected function getBlockModule($aBlock)
  1382. {
  1383. return $aBlock['module'] != BX_DOL_STUDIO_BP_SKELETONS ? $aBlock['module'] : BX_DOL_STUDIO_MODULE_CUSTOM;
  1384. }
  1385. protected function getBlockContent($aBlock)
  1386. {
  1387. $aFields = array();
  1388. switch($aBlock['type']) {
  1389. case BX_DOL_STUDIO_BP_BLOCK_CUSTOM:
  1390. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1391. $aFields = [
  1392. 'content' => [
  1393. 'type' => 'textarea',
  1394. 'name' => 'content',
  1395. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1396. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1397. 'value' => $aBlock['content'],
  1398. 'required' => '0',
  1399. 'code' => 1,
  1400. 'attrs' => [
  1401. 'class' => 'bx-form-input-textarea-codemirror'
  1402. ],
  1403. 'db' => [
  1404. 'pass' => 'XssHtml',
  1405. ],
  1406. ],
  1407. ];
  1408. break;
  1409. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1410. $aFields = [
  1411. 'content' => [
  1412. 'type' => 'textarea',
  1413. 'name' => 'content',
  1414. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1415. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1416. 'value' => $aBlock['content'],
  1417. 'required' => '0',
  1418. 'html' => 2,
  1419. 'attrs' => [
  1420. 'id' => $this->aHtmlIds['edit_block_editor_id']
  1421. ],
  1422. 'db' => [
  1423. 'pass' => 'XssHtml',
  1424. ],
  1425. ],
  1426. 'attachments' => [
  1427. 'type' => 'files',
  1428. 'name' => 'attachments',
  1429. 'storage_object' => $this->sStorage,
  1430. 'images_transcoder' => $this->sTranscoder,
  1431. 'uploaders' => $this->aUploaders,
  1432. 'multiple' => true,
  1433. 'content_id' => $aBlock['id'],
  1434. 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('bp_fgt_attachments.html', [
  1435. 'js_object' => $this->getPageJsObject(),
  1436. 'name' => 'attachments',
  1437. 'editor_id' => $this->aHtmlIds['edit_block_editor_id'],
  1438. ]),
  1439. 'caption' => _t('_adm_bp_txt_block_content_attachments_html')
  1440. ]
  1441. ];
  1442. break;
  1443. case BX_DOL_STUDIO_BP_BLOCK_CREATIVE:
  1444. $oTemplate = BxDolStudioTemplate::getInstance();
  1445. $sContent = $oTemplate->parseHtmlByName('bp_block_skeleton_creative.html', [
  1446. 'html_id' => $this->aHtmlIds['edit_block_builder_id'],
  1447. 'content_html' => $aBlock['content'],
  1448. 'content_data' => json_encode([
  1449. 'pages' => [
  1450. ['component' => $aBlock['content']]
  1451. ]
  1452. ])
  1453. ]);
  1454. $aFields = [
  1455. 'content' => [
  1456. 'type' => 'custom',
  1457. 'name' => 'content',
  1458. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1459. 'content' => $sContent,
  1460. 'required' => '0',
  1461. 'db' => [
  1462. 'pass' => 'XssHtml',
  1463. ],
  1464. ],
  1465. ];
  1466. break;
  1467. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1468. $aFields = [
  1469. 'content' => [
  1470. 'type' => 'textarea_translatable',
  1471. 'name' => 'content',
  1472. 'caption' => _t('_adm_bp_txt_block_content_lang'),
  1473. 'info' => _t('_adm_bp_dsc_block_content_lang'),
  1474. 'value' => $aBlock['content'],
  1475. 'required' => '0',
  1476. 'html' => 2,
  1477. 'db' => [
  1478. 'pass' => 'XssHtml',
  1479. ],
  1480. ],
  1481. ];
  1482. break;
  1483. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1484. $iImageId = $sImageAlign = '';
  1485. if($aBlock['content'] != '')
  1486. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1487. $aFields = [
  1488. 'content' => [
  1489. 'type' => 'hidden',
  1490. 'name' => 'content',
  1491. 'value' => '',
  1492. 'db' => [
  1493. 'pass' => 'Xss',
  1494. ],
  1495. ],
  1496. 'image_file' => [
  1497. 'type' => 'files',
  1498. 'name' => 'image_file',
  1499. 'storage_object' => BX_DOL_STORAGE_OBJ_IMAGES,
  1500. 'images_transcoder' => 'sys_image_resize',
  1501. 'uploaders' => ['sys_html5'],
  1502. 'multiple' => false,
  1503. 'content_id' => $aBlock['id'],
  1504. 'ghost_template' => BxTemplStudioFunctions::getInstance()->getDefaultGhostTemplate('image_file'),
  1505. 'caption' => _t('_adm_bp_txt_block_content_image_file'),
  1506. ],
  1507. 'image_align' => [
  1508. 'type' => 'select',
  1509. 'name' => 'image_align',
  1510. 'caption' => _t('_adm_bp_txt_block_content_image_align'),
  1511. 'info' => '',
  1512. 'value' => $sImageAlign,
  1513. 'values' => [
  1514. ['key' => '', 'value' => _t('_adm_bp_txt_block_content_image_align_empty')],
  1515. ['key' => 'left', 'value' => _t('_adm_bp_txt_block_content_image_align_left')],
  1516. ['key' => 'center', 'value' => _t('_adm_bp_txt_block_content_image_align_center')],
  1517. ['key' => 'right', 'value' => _t('_adm_bp_txt_block_content_image_align_right')],
  1518. ],
  1519. 'required' => '0',
  1520. 'db' => [
  1521. 'pass' => 'Xss',
  1522. ],
  1523. ],
  1524. ];
  1525. break;
  1526. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1527. $sRssUrl = $sRssLength = '';
  1528. if($aBlock['content'] != '')
  1529. list($sRssUrl, $sRssLength) = explode($this->sParamsDivider, $aBlock['content']);
  1530. $aFields = [
  1531. 'content' => [
  1532. 'type' => 'hidden',
  1533. 'name' => 'content',
  1534. 'value' => '',
  1535. 'db' => [
  1536. 'pass' => 'Xss',
  1537. ],
  1538. ],
  1539. 'rss_url' => [
  1540. 'type' => 'text',
  1541. 'name' => 'rss_url',
  1542. 'caption' => _t('_adm_bp_txt_block_content_rss_url'),
  1543. 'info' => _t('_adm_bp_dsc_block_content_rss_url'),
  1544. 'value' => $sRssUrl,
  1545. 'required' => '0',
  1546. 'db' => [
  1547. 'pass' => 'Xss',
  1548. ],
  1549. ],
  1550. 'rss_length' => [
  1551. 'type' => 'text',
  1552. 'name' => 'rss_length',
  1553. 'caption' => _t('_adm_bp_txt_block_content_rss_length'),
  1554. 'info' => _t('_adm_bp_dsc_block_content_rss_length'),
  1555. 'value' => $sRssLength,
  1556. 'required' => '0',
  1557. 'db' => [
  1558. 'pass' => 'Int',
  1559. ],
  1560. ],
  1561. ];
  1562. break;
  1563. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1564. $aFields = [
  1565. 'content' => [
  1566. 'type' => 'select',
  1567. 'name' => 'content',
  1568. 'caption' => _t('_adm_bp_txt_block_content_menu'),
  1569. 'info' => '',
  1570. 'value' => $aBlock['content'],
  1571. 'values' => [],
  1572. 'required' => '0',
  1573. 'db' => [
  1574. 'pass' => 'Xss',
  1575. ],
  1576. ]
  1577. ];
  1578. $sGroup = '';
  1579. $aMenus = $this->oDb->getMenus(true);
  1580. foreach($aMenus as $sKey => $aMenu) {
  1581. if($sGroup != $aMenu['module']) {
  1582. if(!empty($sGroup))
  1583. $aFields['content']['values'][$sGroup . '_end'] = ['type' => 'group_end'];
  1584. $sGroup = $aMenu['module'];
  1585. $aFields['content']['values'][$sGroup . '_beg'] = ['type' => 'group_header', 'value' => BxDolStudioUtils::getModuleTitle($sGroup)];
  1586. }
  1587. $aFields['content']['values'][$sKey] = _t($aMenu['title']);
  1588. }
  1589. $aFields['content']['values'] = array_merge(['' => _t('_adm_bp_txt_block_content_menu_empty')], $aFields['content']['values']);
  1590. break;
  1591. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1592. $aService = ['module' => '', 'method' => ''];
  1593. if($aBlock['content'] != '')
  1594. $aService = unserialize($aBlock['content']);
  1595. $aFields = [
  1596. 'service_module' => [
  1597. 'type' => 'value',
  1598. 'name' => 'service_module',
  1599. 'caption' => _t('_adm_bp_txt_block_content_service_module'),
  1600. 'value' => $this->getModuleTitle($aService['module'])
  1601. ],
  1602. 'service_method' => [
  1603. 'type' => 'value',
  1604. 'name' => 'service_method',
  1605. 'caption' => _t('_adm_bp_txt_block_content_service_method'),
  1606. 'value' => $aService['method']
  1607. ]
  1608. ];
  1609. break;
  1610. }
  1611. return $aFields;
  1612. }
  1613. protected function getBlockList($sModule)
  1614. {
  1615. if(empty($sModule))
  1616. return '';
  1617. $sJsObject = $this->getPageJsObject();
  1618. $oTemplate = BxDolStudioTemplate::getInstance();
  1619. $oForm = new BxTemplStudioFormView(array());
  1620. $aInputCheckbox = array(
  1621. 'type' => 'checkbox',
  1622. 'name' => 'blocks[]',
  1623. 'attrs' => array(
  1624. 'onChange' => 'javascript:' . $sJsObject . '.onSelectBlock(this);'
  1625. ),
  1626. 'value' => ''
  1627. );
  1628. $aTmplParams = array(
  1629. 'html_block_list_id' => $this->aHtmlIds['block_list_id'] . $sModule,
  1630. 'bx_repeat:blocks' => array()
  1631. );
  1632. $aBlocks = $this->getBlocks($sModule);
  1633. foreach($aBlocks as $aBlock) {
  1634. list($sIcon, $sIconUrl) = $this->getBlockIcon($aBlock);
  1635. $aInputCheckbox['value'] = $aBlock['id'];
  1636. $aTmplParams['bx_repeat:blocks'][] = array(
  1637. 'js_object' => $sJsObject,
  1638. 'html_id' => $this->aHtmlIds['block_id'] . $aBlock['id'],
  1639. 'bx_if:is_inactive' => array(
  1640. 'condition' => false,
  1641. 'content' => array()
  1642. ),
  1643. 'bx_if:show_link' => array(
  1644. 'condition' => false,
  1645. 'content' => array()
  1646. ),
  1647. 'bx_if:show_text' => array(
  1648. 'condition' => true,
  1649. 'content' => array(
  1650. 'title' => _t(!empty($aBlock['title_system']) ? $aBlock['title_system'] : $aBlock['title']),
  1651. )
  1652. ),
  1653. 'bx_if:image' => array (
  1654. 'condition' => (bool)$sIconUrl,
  1655. 'content' => array('icon_url' => $sIconUrl),
  1656. ),
  1657. 'bx_if:icon' => array (
  1658. 'condition' => (bool)$sIcon,
  1659. 'content' => array('icon' => $sIcon),
  1660. ),
  1661. 'module' => $this->getModuleTitle($aBlock['module']),
  1662. 'visible_for' => _t('_adm_bp_txt_visible_for', BxDolStudioUtils::getVisibilityTitle($aBlock['visible_for_levels'])),
  1663. 'bx_if:show_checkbox' => array(
  1664. 'condition' => true,
  1665. 'content' => array(
  1666. 'content' => $oForm->genRow($aInputCheckbox)
  1667. )
  1668. ),
  1669. 'bx_if:show_drag_handle' => array(
  1670. 'condition' => false,
  1671. 'content' => array()
  1672. )
  1673. );
  1674. }
  1675. return $oTemplate->parseHtmlByName('bp_blocks_list.html', $aTmplParams);
  1676. }
  1677. protected function onBlockDelete($aBlock)
  1678. {
  1679. if($aBlock['module'] != BX_DOL_STUDIO_MODULE_CUSTOM)
  1680. return;
  1681. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['title']);
  1682. //--- Process Lang block
  1683. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && $aBlock['content'] != '')
  1684. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['content']);
  1685. //--- Process Image block
  1686. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && $aBlock['content'] != '') {
  1687. $iImageId = $sImageAlign = '';
  1688. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1689. if(is_numeric($iImageId) && (int)$iImageId != 0)
  1690. BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$iImageId, 0);
  1691. }
  1692. }
  1693. protected function getBlocks($sModule)
  1694. {
  1695. $aBlocks = array();
  1696. $this->oDb->getBlocks(array('type' => 'by_module_to_copy', 'value' => $sModule), $aBlocks, false);
  1697. return $aBlocks;
  1698. }
  1699. protected function _getTmplVarsBlockPanelTop()
  1700. {
  1701. $sJsObject = $this->getPageJsObject();
  1702. $oForm = new BxTemplStudioFormView(array());
  1703. $aPages = $this->oDb->getPages(array('type' => 'by_module', 'value' => $this->sType));
  1704. $aCounter = array();
  1705. $this->oDb->getBlocks(array('type' => 'counter_by_pages'), $aCounter, false);
  1706. $aInputPagesValues = [];
  1707. foreach($aPages as $aPage) {
  1708. $sTitle = _t($aPage['title_system']);
  1709. if(empty($sTitle))
  1710. $sTitle = _t($aPage['title']);
  1711. $aInputPagesValues[] = array(
  1712. 'key' => $aPage['object'],
  1713. 'value' => $sTitle . " (" . (isset($aCounter[$aPage['object']]) ? $aCounter[$aPage['object']] : "0") . ")"
  1714. );
  1715. }
  1716. usort($aInputPagesValues, function($aV1, $aV2) {
  1717. return strcmp($aV1['value'], $aV2['value']);
  1718. });
  1719. $aInputPages = array(
  1720. 'type' => 'select',
  1721. 'name' => 'page',
  1722. 'attrs' => array(
  1723. 'onChange' => 'javascript:' . $this->getPageJsObject() . '.onChangePage(this)'
  1724. ),
  1725. 'value' => $this->sPage,
  1726. 'values' => array_merge([[
  1727. 'key' => '',
  1728. 'value' => _t('_adm_bp_txt_select_page')]
  1729. ], $aInputPagesValues)
  1730. );
  1731. $aTmplVarsActions = array();
  1732. if(($this->sPage != '' && !empty($this->aPageRebuild)) !== false)
  1733. $aTmplVarsActions = $this->_getTmplVarsBlockPanelTopActions();
  1734. return array(
  1735. 'js_object' => $this->getPageJsObject(),
  1736. 'selector' => $oForm->genRow($aInputPages),
  1737. 'action_page_create' => $this->sActionPageCreate,
  1738. 'bx_if:show_actions' => array(
  1739. 'condition' => $this->sPage != '',
  1740. 'content' => $aTmplVarsActions
  1741. )
  1742. );
  1743. }
  1744. protected function _getTmplVarsBlockPanelTopActions()
  1745. {
  1746. $sJsObject = $this->getPageJsObject();
  1747. $oPermalinks = BxDolPermalinks::getInstance();
  1748. return [
  1749. 'js_object' => $sJsObject,
  1750. 'bx_if:can_view' => [
  1751. 'condition' => !empty($this->aPageRebuild['url']),
  1752. 'content' => [
  1753. 'url_view' => bx_absolute_url($oPermalinks->permalink($this->aPageRebuild['url'])),
  1754. ]
  1755. ],
  1756. 'action_page_edit' => $this->sActionPageEdit,
  1757. 'bx_if:can_delete' => [
  1758. 'condition' => (int)$this->aPageRebuild['deletable'] == 1,
  1759. 'content' => [
  1760. 'js_object' => $sJsObject
  1761. ]
  1762. ],
  1763. 'action_block_create' => $this->sActionBlockCreate,
  1764. ];
  1765. }
  1766. protected function _getTmplVarsPageSettings($aPage = array(), $bCreate = true)
  1767. {
  1768. $sJsObject = $this->getPageJsObject();
  1769. $aTmplParams = array(
  1770. 'js_object' => $sJsObject,
  1771. 'menu' => array(),
  1772. 'html_settings_groups_id' => $this->aHtmlIds['settings_groups_id'],
  1773. 'bx_repeat:settings_groups' => array(),
  1774. 'submit' => _t($bCreate ? '_adm_bp_btn_page_create' : '_adm_bp_btn_page_apply')
  1775. );
  1776. foreach($this->aPageSettings as $aSetting) {
  1777. //--- get menu items
  1778. $aTmplParams['menu'][$aSetting['name']] = array(
  1779. 'name' => $aSetting['name'],
  1780. 'icon' => '',
  1781. 'onclick' => $sJsObject . '.onChangeSettingGroup(\'' . $aSetting['name'] . '\', this);',
  1782. 'title' => $aSetting['title'],
  1783. 'selected' => isset($aSetting['active']) && (int)$aSetting['active'] == 1
  1784. );
  1785. //--- get settings
  1786. $aTmplParams['bx_repeat:settings_groups'][] = array(
  1787. 'html_settings_group_id' => $this->aHtmlIds['settings_group_id'] . $aSetting['name'],
  1788. 'bx_if:hidden' => array(
  1789. 'condition' => $aSetting['active'] != 1,
  1790. 'content' => array()
  1791. ),
  1792. 'content' => $this->{'getSettings' . $this->getClassName($aSetting['name'])}($aPage, $bCreate)
  1793. );
  1794. }
  1795. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aTmplParams['menu']));
  1796. $aTmplParams['menu'] = $oMenu->getCode();
  1797. return $aTmplParams;
  1798. }
  1799. protected function getIndexingDataForBlock($sType, $sContent)
  1800. {
  1801. $aBlock = array();
  1802. switch($sType) {
  1803. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1804. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1805. $aBlock['text'] = trim(strip_tags($sContent));
  1806. $aBlock['text_updated'] = time();
  1807. break;
  1808. }
  1809. return $aBlock;
  1810. }
  1811. }
  1812. /** @} */