BxBaseStudioBuilderPage.php 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729
  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. 'block_id' => 'adm-bpb-',
  38. 'block_list_id' => 'adm-bpl-',
  39. 'block_lists_id' => 'adm-bp-block-lists',
  40. 'layout_id' => 'adm-bpl-',
  41. );
  42. protected $aPageSettings = array(
  43. array('name' => 'options', 'title' => '_adm_bp_mi_page_options', 'active' => 1),
  44. array('name' => 'cover', 'title' => '_adm_bp_mi_page_cover', 'active' => 0),
  45. array('name' => 'layout', 'title' => '_adm_bp_mi_page_layout', 'active' => 0),
  46. array('name' => 'visibility', 'title' => '_adm_bp_mi_page_visibility', 'active' => 0),
  47. array('name' => 'cache', 'title' => '_adm_bp_mi_page_cache', 'active' => 0),
  48. array('name' => 'seo', 'title' => '_adm_bp_mi_page_seo', 'active' => 0)
  49. );
  50. function __construct($sType = '', $sPage = '')
  51. {
  52. parent::__construct($sType, $sPage);
  53. $this->sStorage = BX_DOL_STORAGE_OBJ_IMAGES;
  54. $this->sTranscoder = 'sys_builder_page_preview';
  55. $this->aUploaders = array('sys_builder_page_simple', 'sys_builder_page_html5');
  56. $this->sTranscoderCover = 'sys_cover_preview';
  57. $this->aUploadersCover = array('sys_std_crop_cover');
  58. $this->sBaseUrl = BX_DOL_URL_STUDIO . 'builder_page.php';
  59. $this->sTypeUrl = $this->sBaseUrl . '?type=%s';
  60. $this->sPageUrl = $this->sTypeUrl . '&page=%s';
  61. }
  62. function getPageCss()
  63. {
  64. $oTemplate = BxDolStudioTemplate::getInstance();
  65. $aUploaders = array_merge($this->aUploaders, $this->aUploadersCover);
  66. foreach($aUploaders as $sUploader) {
  67. $oUploader = BxDolUploader::getObjectInstance($sUploader, $this->sStorage, '', $oTemplate);
  68. if($oUploader)
  69. $oUploader->addCssJs();
  70. }
  71. return array_merge(parent::getPageCss(), array(
  72. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css',
  73. 'page_layouts.css',
  74. 'builder_page.css'
  75. ));
  76. }
  77. function getPageJs()
  78. {
  79. return array_merge(parent::getPageJs(), array(
  80. 'codemirror/codemirror.min.js',
  81. 'jquery-ui/jquery.ui.core.min.js',
  82. 'jquery-ui/jquery.ui.widget.min.js',
  83. 'jquery-ui/jquery.ui.mouse.min.js',
  84. 'jquery-ui/jquery.ui.sortable.min.js',
  85. 'jquery.ui.touch-punch.min.js',
  86. 'jquery.easing.js',
  87. 'jquery.form.min.js',
  88. 'functions.js',
  89. 'builder_page.js'
  90. ));
  91. }
  92. function getPageJsObject()
  93. {
  94. return 'oBxDolStudioBuilderPage';
  95. }
  96. function getPageMenu($aMenu = array(), $aMarkers = array())
  97. {
  98. $aMenuItems = array(
  99. BX_DOL_STUDIO_MODULE_SYSTEM => array(
  100. 'name' => BX_DOL_STUDIO_MODULE_SYSTEM,
  101. 'icon' => 'cog',
  102. ),
  103. BX_DOL_STUDIO_MODULE_CUSTOM => array(
  104. 'name' => BX_DOL_STUDIO_MODULE_CUSTOM,
  105. 'icon' => 'wrench',
  106. 'title' => '_adm_bp_cpt_type_' . BX_DOL_STUDIO_MODULE_CUSTOM,
  107. )
  108. );
  109. $aModulesDb = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules'));
  110. foreach($aModulesDb as $aModuleDb) {
  111. $sName = $aModuleDb['name'];
  112. if(!empty($aMenuItems[$sName]))
  113. $aMenuItems[$sName] = array_merge($aMenuItems[$sName], $aModuleDb);
  114. else
  115. $aMenuItems[$sName] = $aModuleDb;
  116. $aMenuItems[$sName]['title'] = BxDolStudioUtils::getModuleTitle($sName);
  117. if(empty($aMenuItems[$sName]['icon']))
  118. $aMenuItems[$sName]['icon'] = BxDolStudioUtils::getModuleIcon($aModuleDb, 'menu', false);
  119. }
  120. $aMenu = array();
  121. foreach($aMenuItems as $aMenuItem)
  122. $aMenu[] = array(
  123. 'name' => $aMenuItem['name'],
  124. 'icon' => $aMenuItem['icon'],
  125. 'link' => sprintf($this->sTypeUrl, $aMenuItem['name']),
  126. 'title' => $aMenuItem['title'],
  127. 'selected' => $aMenuItem['name'] == $this->sType
  128. );
  129. return parent::getPageMenu($aMenu);
  130. }
  131. function getPageCode($bHidden = false)
  132. {
  133. $oPage = BxTemplPage::getObjectInstance($this->sPage);
  134. $oTemplate = BxDolStudioTemplate::getInstance();
  135. $sJsObject = $this->getPageJsObject();
  136. $sTxtEmpty = _t('_sys_txt_empty');
  137. $sContent = "";
  138. if(($bPage = $this->sPage != '') === true) {
  139. $aTmplVars = array();
  140. for($i = 1; $i <= $this->aPageRebuild['layout_cells_number']; $i++) {
  141. $aBlocks = array();
  142. $this->oDb->getBlocks(array('type' => 'by_object_cell', 'object' => $this->aPageRebuild['object'], 'cell' => $i), $aBlocks, false);
  143. $aTmplVarsCell = array('id' => $i, 'bx_repeat:blocks' => array());
  144. foreach($aBlocks as $aBlock) {
  145. $sTitle = !empty($aBlock['title_system']) ? _t($aBlock['title_system']) : $oPage->getBlockTitle($aBlock);
  146. list($sIcon, $sIconUrl) = $this->getBlockIcon($aBlock);
  147. $aTmplVarsCell['bx_repeat:blocks'][] = array(
  148. 'html_id' => $this->aHtmlIds['block_id'] . $aBlock['id'],
  149. 'bx_if:is_inactive' => array(
  150. 'condition' => (int)$aBlock['active'] == 0,
  151. 'content' => array()
  152. ),
  153. 'bx_if:show_link' => array(
  154. 'condition' => true,
  155. 'content' => array(
  156. 'onclick' => $sJsObject . ".performAction('block_edit', {id: " . $aBlock['id'] . "})",
  157. 'title' => !empty($sTitle) ? $sTitle : $sTxtEmpty,
  158. )
  159. ),
  160. 'bx_if:show_text' => array(
  161. 'condition' => false,
  162. 'content' => array()
  163. ),
  164. 'bx_if:image' => array (
  165. 'condition' => (bool)$sIconUrl,
  166. 'content' => array('icon_url' => $sIconUrl),
  167. ),
  168. 'bx_if:icon' => array (
  169. 'condition' => (bool)$sIcon,
  170. 'content' => array('icon' => $sIcon),
  171. ),
  172. 'module' => $this->getModuleTitle($aBlock['module']),
  173. 'visible_for' => _t('_adm_bp_txt_visible_for', BxDolStudioUtils::getVisibilityTitle($aBlock['visible_for_levels'])),
  174. 'bx_if:show_checkbox' => array(
  175. 'condition' => false,
  176. 'content' => array()
  177. ),
  178. 'bx_if:show_drag_handle' => array(
  179. 'condition' => true,
  180. 'content' => array()
  181. )
  182. );
  183. }
  184. $aTmplVars['cell_' . $i] = $oTemplate->parseHtmlByName('bp_cell.html', $aTmplVarsCell);
  185. }
  186. $sContent = $oTemplate->parseHtmlByName($this->aPageRebuild['layout_template'], $aTmplVars);
  187. }
  188. $aLanguages = BxDolStudioLanguagesUtils::getInstance()->getLanguages();
  189. $aTmplVars = array(
  190. 'js_object' => $sJsObject,
  191. 'action_url' => $this->sBaseUrl,
  192. 'page_url' => sprintf($this->sPageUrl, '{0}', '{1}'),
  193. 'type' => $this->sType,
  194. 'page' => $this->sPage,
  195. 'html_ids' => json_encode($this->aHtmlIds),
  196. 'languahes' => json_encode($aLanguages),
  197. 'content' => $this->getBlockCode(array(
  198. 'items' => $sContent
  199. ))
  200. );
  201. $oTemplate->addJsTranslation(array(
  202. '_adm_bp_wrn_page_delete',
  203. '_adm_bp_wrn_page_block_delete'
  204. ));
  205. return $oTemplate->parseHtmlByName('builder_page.html', $aTmplVars);
  206. }
  207. function getBlockPanelTop($aBlock)
  208. {
  209. return parent::getBlockPanelTop(
  210. array('panel_top' => BxDolStudioTemplate::getInstance()->parseHtmlByName('bp_block_panel_top.html', $this->_getTmplVarsBlockPanelTop()))
  211. );
  212. }
  213. protected function actionPageCreate()
  214. {
  215. $sJsObject = $this->getPageJsObject();
  216. $oTemplate = BxDolStudioTemplate::getInstance();
  217. $sModule = BX_DOL_STUDIO_MODULE_CUSTOM;
  218. $aForm = array(
  219. 'form_attrs' => array(
  220. 'id' => 'adm-bp-page-create',
  221. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionPageCreate,
  222. 'method' => 'post'
  223. ),
  224. 'params' => array (
  225. 'db' => array(
  226. 'table' => 'sys_objects_page',
  227. 'key' => 'id',
  228. 'uri' => '',
  229. 'uri_title' => '',
  230. 'submit_name' => 'do_submit'
  231. ),
  232. ),
  233. 'inputs' => array (
  234. 'module' => array(
  235. 'type' => 'hidden',
  236. 'name' => 'module',
  237. 'value' => $sModule,
  238. 'db' => array (
  239. 'pass' => 'Xss',
  240. ),
  241. ),
  242. 'deletable' => array(
  243. 'type' => 'hidden',
  244. 'name' => 'deletable',
  245. 'value' => 1,
  246. 'db' => array (
  247. 'pass' => 'Int',
  248. ),
  249. ),
  250. 'settings' => array(
  251. 'type' => 'custom',
  252. 'name' => 'settings',
  253. 'content' => $oTemplate->parseHtmlByName('bp_edit_page_form.html', $this->_getTmplVarsPageSettings()),
  254. ),
  255. )
  256. );
  257. $oForm = new BxTemplStudioFormView($aForm);
  258. $oForm->initChecker();
  259. if($oForm->isSubmittedAndValid()) {
  260. unset($oForm->aInputs['settings']);
  261. foreach($this->aPageSettings as $aSetting)
  262. $oForm->aInputs = array_merge($oForm->aInputs, $this->{'getSettings' . $this->getClassName($aSetting['name']) . 'Fields'}());
  263. $sLanguage = BxDolStudioLanguagesUtils::getInstance()->getCurrentLangName(false);
  264. $sObject = BxDolForm::getSubmittedValue('title-' . $sLanguage, $aForm['form_attrs']['method']);
  265. $sObject = uriGenerate($sObject, 'sys_objects_page', 'object', 'object');
  266. $sUri = $oForm->getCleanValue('uri');
  267. $aPage = array();
  268. $this->oDb->getPages(array('type' => 'by_uri', 'value' => $sUri), $aPage, false);
  269. if(!empty($aPage) && is_array($aPage))
  270. return array('msg' => _t('_adm_bp_err_page_uri'));
  271. $iVisibleFor = BxDolStudioUtils::getVisibilityValue($oForm->getCleanValue('visible_for'), $oForm->getCleanValue('visible_for_levels'));
  272. BxDolForm::setSubmittedValue('visible_for_levels', $iVisibleFor, $aForm['form_attrs']['method']);
  273. unset($oForm->aInputs['visible_for']);
  274. $iId = (int)$oForm->insert(array('object' => $sObject, 'url' => $this->sPageBaseUrl . $sUri));
  275. if($iId != 0)
  276. return array('eval' => $sJsObject . '.onCreatePage(\'' . $sModule . '\', \'' . $sObject . '\')');
  277. else
  278. return array('msg' => _t('_adm_bp_err_page_create'));
  279. }
  280. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['add_popup_id'], _t('_adm_bp_txt_create_popup'), $oTemplate->parseHtmlByName('bp_add_page.html', array(
  281. 'js_object' => $sJsObject,
  282. 'form_id' => $aForm['form_attrs']['id'],
  283. 'form' => $oForm->getCode(true)
  284. )));
  285. return array('popup' => $sContent);
  286. }
  287. protected function actionPageEdit()
  288. {
  289. $sJsObject = $this->getPageJsObject();
  290. $oTemplate = BxDolStudioTemplate::getInstance();
  291. $aForm = array(
  292. 'form_attrs' => array(
  293. 'id' => 'adm-bp-page-edit',
  294. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionPageEdit,
  295. 'method' => 'post'
  296. ),
  297. 'params' => array (
  298. 'db' => array(
  299. 'table' => 'sys_objects_page',
  300. 'key' => 'id',
  301. 'uri' => '',
  302. 'uri_title' => '',
  303. 'submit_name' => 'do_submit'
  304. ),
  305. ),
  306. 'inputs' => array (
  307. 'settings' => array(
  308. 'type' => 'custom',
  309. 'name' => 'settings',
  310. 'content' => $oTemplate->parseHtmlByName('bp_edit_page_form.html', $this->_getTmplVarsPageSettings($this->aPageRebuild, false)),
  311. ),
  312. )
  313. );
  314. $oForm = new BxTemplStudioFormView($aForm);
  315. $oForm->initChecker();
  316. if($oForm->isSubmittedAndValid()) {
  317. unset($oForm->aInputs['settings']);
  318. foreach($this->aPageSettings as $aSetting)
  319. $oForm->aInputs = array_merge($oForm->aInputs, $this->{'getSettings' . $this->getClassName($aSetting['name']) . 'Fields'}($this->aPageRebuild, false));
  320. $iVisibleFor = BxDolStudioUtils::getVisibilityValue($oForm->getCleanValue('visible_for'), $oForm->getCleanValue('visible_for_levels'));
  321. BxDolForm::setSubmittedValue('visible_for_levels', $iVisibleFor, $aForm['form_attrs']['method']);
  322. unset($oForm->aInputs['visible_for']);
  323. if($oForm->update($this->aPageRebuild['id'])) {
  324. $iLevelId = $oForm->getCleanValue('layout_id');
  325. if(!empty($iLevelId) && $iLevelId != $this->aPageRebuild['layout_id']) {
  326. $aLayoutOld = array();
  327. $this->oDb->getLayouts(array('type' => 'by_id', 'value' => $this->aPageRebuild['layout_id']), $aLayoutOld, false);
  328. $aLayoutNew = array();
  329. $this->oDb->getLayouts(array('type' => 'by_id', 'value' => $iLevelId), $aLayoutNew, false);
  330. if($aLayoutOld['cells_number'] > $aLayoutNew['cells_number'] && $this->oDb->resetBlocksByPage($this->sPage, $aLayoutNew['cells_number']) === false)
  331. return array('msg' => _t('_adm_bp_err_save'));
  332. return array('eval' => $sJsObject . '.onSaveSettingsLayout()');
  333. }
  334. return array();
  335. }
  336. else
  337. return array('msg' => _t('_adm_bp_err_save'));
  338. }
  339. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['edit_popup_id'], _t('_adm_bp_txt_settings_popup'), $oTemplate->parseHtmlByName('bp_edit_page.html', array(
  340. 'js_object' => $sJsObject,
  341. 'form_id' => $aForm['form_attrs']['id'],
  342. 'form' => $oForm->getCode(true)
  343. )));
  344. return array('popup' => $sContent);
  345. }
  346. protected function actionPageDelete()
  347. {
  348. if(empty($this->sPage) || empty($this->aPageRebuild) || !is_array($this->aPageRebuild))
  349. return array('msg' => _t('_adm_bp_err_page_delete'));
  350. $oLangauge = BxDolStudioLanguagesUtils::getInstance();
  351. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  352. $aBlocks = array();
  353. $this->oDb->getBlocks(array('type' => 'by_object', 'value' => $this->sPage), $aBlocks, false);
  354. if(is_array($aBlocks) && !empty($aBlocks)) {
  355. foreach($aBlocks as $aBlock)
  356. $this->onBlockDelete($aBlock);
  357. $this->oDb->deleteBlocks(array('type' => 'by_object', 'value' => $this->sPage));
  358. }
  359. if($this->oDb->deletePages(array('type' => 'by_object', 'value' => $this->sPage))) {
  360. $oLangauge->deleteLanguageString($this->aPageRebuild['title_system']);
  361. $oLangauge->deleteLanguageString($this->aPageRebuild['title']);
  362. return array('eval' => 'window.parent.location.href = "' . sprintf($this->sTypeUrl, $this->sType) . '";');
  363. }
  364. return array('msg' => _t('_adm_bp_err_page_delete'));
  365. }
  366. protected function actionBlockList()
  367. {
  368. $sModule = BX_DOL_STUDIO_BP_TYPE_DEFAULT;
  369. if(bx_get('bp_module') !== false)
  370. $sModule = bx_process_input(bx_get('bp_module'));
  371. return array(
  372. 'content' => $this->getBlockList($sModule)
  373. );
  374. }
  375. protected function actionBlockCreate()
  376. {
  377. $sJsObject = $this->getPageJsObject();
  378. $oTemplate = BxDolStudioTemplate::getInstance();
  379. $sSelected = BX_DOL_STUDIO_BP_SKELETONS;
  380. $aForm = array(
  381. 'form_attrs' => array(
  382. 'id' => 'adm-bp-block-create',
  383. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionBlockCreate,
  384. 'method' => 'post'
  385. ),
  386. 'params' => array (
  387. 'db' => array(
  388. 'table' => 'sys_pages_blocks',
  389. 'key' => 'id',
  390. 'uri' => '',
  391. 'uri_title' => '',
  392. 'submit_name' => 'do_submit'
  393. ),
  394. ),
  395. 'inputs' => array (
  396. 'blocks' => array(
  397. 'type' => 'custom',
  398. 'name' => 'blocks',
  399. 'content' => '',
  400. 'db' => array (
  401. 'pass' => 'Int',
  402. ),
  403. ),
  404. )
  405. );
  406. $aMenu = array(
  407. BX_DOL_STUDIO_BP_SKELETONS => array(
  408. 'name' => BX_DOL_STUDIO_BP_SKELETONS,
  409. 'icon' => 'qrcode',
  410. 'title' => '_sys_block_types_skeletons',
  411. 'selected' => $sSelected == BX_DOL_STUDIO_BP_SKELETONS,
  412. ),
  413. BX_DOL_STUDIO_MODULE_SYSTEM => array(
  414. 'name' => BX_DOL_STUDIO_MODULE_SYSTEM,
  415. 'icon' => 'cog',
  416. 'title' => '_sys_block_types_system',
  417. 'selected' => $sSelected == BX_DOL_STUDIO_MODULE_SYSTEM,
  418. ),
  419. BX_DOL_STUDIO_MODULE_CUSTOM => array(
  420. 'name' => BX_DOL_STUDIO_MODULE_CUSTOM,
  421. 'icon' => 'wrench',
  422. 'title' => '_sys_block_types_custom',
  423. 'selected' => $sSelected == BX_DOL_STUDIO_MODULE_CUSTOM,
  424. )
  425. );
  426. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules'));
  427. $aModulesWithBlocks = $this->oDb->getModulesWithCopyableBlocks();
  428. foreach($aModules as $aModule) {
  429. $sName = $aModule['name'];
  430. if(!in_array($sName, $aModulesWithBlocks))
  431. continue;
  432. if(!empty($aMenu[$sName]))
  433. $aMenu[$sName] = array_merge($aMenu[$sName], $aModule);
  434. else
  435. $aMenu[$sName] = $aModule;
  436. if(empty($aMenu[$sName]['icon']))
  437. $aMenu[$sName]['icon'] = BxDolStudioUtils::getModuleIcon($aModule, 'menu', false);
  438. }
  439. foreach($aMenu as $sKey => $aItem)
  440. $aMenu[$sKey]['onclick'] = $sJsObject . '.onChangeModule(\'' . $aItem['name'] . '\', this);';
  441. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aMenu));
  442. $aTmplParams = array(
  443. 'menu' => $oMenu->getCode(),
  444. 'html_block_lists_id' => $this->aHtmlIds['block_lists_id'],
  445. 'blocks' => $this->getBlockList($sSelected)
  446. );
  447. $aForm['inputs']['blocks']['content'] = $oTemplate->parseHtmlByName('bp_add_block_form.html', $aTmplParams);
  448. $oForm = new BxTemplStudioFormView($aForm);
  449. $oForm->initChecker();
  450. if($oForm->isSubmittedAndValid()) {
  451. $aIds = $oForm->getCleanValue('blocks');
  452. $aBlocks = array();
  453. $this->oDb->getBlocks(array('type' => 'by_ids', 'value' => $aIds), $aBlocks, false);
  454. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  455. $oStorege = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  456. $bResult = true;
  457. foreach($aBlocks as $aBlock) {
  458. $sModule = $aBlock['module'];
  459. $sTitleKey = $this->getSystemName($aBlock['title'] . '_' . time());
  460. $aTitleValues = $oLanguage->getLanguageString($aBlock['title']);
  461. unset($aBlock['id']);
  462. $aBlock['object'] = $this->sPage;
  463. $aBlock['cell_id'] = 1;
  464. $aBlock['module'] = $this->getBlockModule($aBlock);
  465. $aBlock['title'] = $sTitleKey;
  466. $aBlock['copyable'] = $sModule == BX_DOL_STUDIO_BP_SKELETONS ? 1 : 0;
  467. $aBlock['deletable'] = 1;
  468. //--- Process Lang copy
  469. $sContentKey = $sContentValue = "";
  470. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && $aBlock['content'] != '') {
  471. $sContentKey = $this->getSystemName($aBlock['content'] . '_' . time());
  472. $sContentValue = _t($aBlock['content']);
  473. $aBlock['content'] = $sContentKey;
  474. $oLanguage->addLanguageString($sContentKey, $sContentValue);
  475. }
  476. //--- Process Image copy
  477. $iImageId = $sImageAlign = "";
  478. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && $aBlock['content'] != '') {
  479. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  480. $aBlock['content'] = "";
  481. if(is_numeric($iImageId) && (int)$iImageId != 0 && ($iImageId = $oStorege->storeFileFromStorage(array('id' => $iImageId))) !== false)
  482. $aBlock['content'] = implode($this->sParamsDivider, array($iImageId, $sImageAlign));
  483. }
  484. if(!$this->oDb->insertBlock($aBlock)) {
  485. if($sContentKey != "")
  486. $oLanguage->deleteLanguageString($sContentKey);
  487. if($iImageId != "")
  488. $oStorege->deleteFile((int)$iImageId, 0);
  489. $bResult = false;
  490. break;
  491. }
  492. //--- Process Title copy
  493. foreach($aTitleValues as $iLangId => $aTitleValue)
  494. $oLanguage->addLanguageString($sTitleKey, $aTitleValue['string'], $iLangId);
  495. }
  496. if($bResult)
  497. return array('eval' => $sJsObject . '.onCreateBlock(oData)');
  498. else
  499. return array('msg' => _t('_adm_bp_err_block_added'));
  500. }
  501. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['create_block_popup_id'], _t('_adm_bp_txt_new_block_popup'), $oTemplate->parseHtmlByName('bp_add_block.html', array(
  502. 'action' => 'create',
  503. 'form_id' => $aForm['form_attrs']['id'],
  504. 'form' => $oForm->getCode(true)
  505. )));
  506. return array('popup' => $sContent);
  507. }
  508. protected function actionBlockEdit()
  509. {
  510. $sJsObject = $this->getPageJsObject();
  511. $oTemplate = BxDolStudioTemplate::getInstance();
  512. $iId = (int)bx_get('id');
  513. if(!$iId)
  514. return array();
  515. $aBlock = array();
  516. $this->oDb->getBlocks(array('type' => 'by_id', 'value' => $iId), $aBlock, false);
  517. if(empty($aBlock) || !is_array($aBlock))
  518. return array('msg' => _t('_adm_bp_err_block_not_found'));
  519. bx_import('BxDolStudioUtils');
  520. $aForm = array(
  521. 'form_attrs' => array(
  522. 'id' => 'adm-bp-block-edit',
  523. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionBlockEdit,
  524. 'method' => 'post'
  525. ),
  526. 'params' => array (
  527. 'db' => array(
  528. 'table' => 'sys_pages_blocks',
  529. 'key' => 'id',
  530. 'uri' => '',
  531. 'uri_title' => '',
  532. 'submit_name' => 'do_submit'
  533. ),
  534. ),
  535. 'inputs' => array (
  536. 'id' => array(
  537. 'type' => 'hidden',
  538. 'name' => 'id',
  539. 'value' => $iId,
  540. 'db' => array (
  541. 'pass' => 'Int',
  542. ),
  543. ),
  544. 'title' => array(
  545. 'type' => 'text_translatable',
  546. 'name' => 'title',
  547. 'caption' => _t('_adm_bp_txt_block_title'),
  548. 'info' => _t('_adm_bp_dsc_block_title'),
  549. 'value' => $aBlock['title'],
  550. 'required' => '1',
  551. 'db' => array (
  552. 'pass' => 'Xss',
  553. ),
  554. 'checker' => array (
  555. 'func' => 'length',
  556. 'params' => array(3,100),
  557. 'error' => _t('_adm_bp_err_block_title'),
  558. ),
  559. ),
  560. 'designbox_id' => array(
  561. 'type' => 'select',
  562. 'name' => 'designbox_id',
  563. 'caption' => _t('_adm_bp_txt_block_designbox'),
  564. 'info' => '',
  565. 'value' => $this->sSelectKeyPrefix . $aBlock['designbox_id'],
  566. 'values' => array(
  567. array('key' => '', 'value' => _t('_adm_bp_txt_block_designbox_empty')),
  568. ),
  569. 'required' => '1',
  570. 'db' => array (
  571. 'pass' => 'Xss',
  572. ),
  573. 'checker' => array (
  574. 'func' => 'avail',
  575. 'params' => array(),
  576. 'error' => _t('_adm_bp_err_block_designbox'),
  577. ),
  578. ),
  579. 'hidden_on' => array(
  580. 'type' => 'select_multiple',
  581. 'name' => 'hidden_on',
  582. 'caption' => _t('_adm_bp_txt_block_hidden_on'),
  583. 'info' => '',
  584. 'value' => (int)$aBlock['hidden_on'],
  585. 'values' => array(
  586. BX_DB_HIDDEN_PHONE => _t('_adm_bp_txt_block_hidden_on_phone'),
  587. BX_DB_HIDDEN_TABLET => _t('_adm_bp_txt_block_hidden_on_tablet'),
  588. BX_DB_HIDDEN_DESKTOP => _t('_adm_bp_txt_block_hidden_on_desktop')
  589. ),
  590. 'db' => array (
  591. 'pass' => 'Set',
  592. )
  593. ),
  594. 'visible_for' => array(
  595. 'type' => 'select',
  596. 'name' => 'visible_for',
  597. 'caption' => _t('_adm_bp_txt_block_visible_for'),
  598. 'info' => '',
  599. 'value' => $aBlock['visible_for_levels'] == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
  600. 'values' => array(
  601. array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_bp_txt_block_visible_for_all')),
  602. array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_bp_txt_block_visible_for_selected')),
  603. ),
  604. 'required' => '0',
  605. 'attrs' => array(
  606. 'onchange' => $sJsObject . '.onChangeVisibleFor(this)'
  607. ),
  608. 'db' => array (
  609. 'pass' => 'Xss',
  610. )
  611. ),
  612. 'visible_for_levels' => array(
  613. 'type' => 'checkbox_set',
  614. 'name' => 'visible_for_levels',
  615. 'caption' => _t('_adm_bp_txt_block_visible_for_levels'),
  616. 'info' => _t('_adm_bp_dsc_block_visible_for_levels'),
  617. 'value' => array(),
  618. 'values' => array(),
  619. 'tr_attrs' => array(
  620. 'style' => $aBlock['visible_for_levels'] == BX_DOL_INT_MAX ? 'display:none' : ''
  621. ),
  622. 'db' => array (
  623. 'pass' => 'Int',
  624. )
  625. ),
  626. 'active' => array(
  627. 'type' => 'switcher',
  628. 'name' => 'active',
  629. 'caption' => _t('_adm_bp_txt_block_active'),
  630. 'info' => '',
  631. 'value' => '1',
  632. 'checked' => $aBlock['active'] == '1',
  633. 'db' => array (
  634. 'pass' => 'Int',
  635. )
  636. ),
  637. 'controls' => array(
  638. 'name' => 'controls',
  639. 'type' => 'input_set',
  640. array(
  641. 'type' => 'submit',
  642. 'name' => 'do_submit',
  643. 'value' => _t('_adm_bp_btn_block_save')
  644. ),
  645. array (
  646. 'type' => 'reset',
  647. 'name' => 'close',
  648. 'value' => _t('_adm_bp_btn_block_cancel'),
  649. 'attrs' => array(
  650. 'onclick' => $sJsObject . '.onEditBlockCancel(this)',
  651. 'class' => 'bx-def-margin-sec-left',
  652. ),
  653. )
  654. )
  655. )
  656. );
  657. $aDBoxes = array();
  658. $this->oDb->getDesignBoxes(array('type' => 'ordered'), $aDBoxes, false);
  659. foreach($aDBoxes as $aDBox)
  660. $aForm['inputs']['designbox_id']['values'][] = array('key' => $this->sSelectKeyPrefix . $aDBox['id'], 'value' => _t($aDBox['title']));
  661. BxDolStudioUtils::getVisibilityValues($aBlock['visible_for_levels'], $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
  662. $aForm['inputs'] = $this->addInArray($aForm['inputs'], 'visible_for_levels', $this->getBlockContent($aBlock));
  663. if((int)$aBlock['deletable'] != 0)
  664. $aForm['inputs']['controls'][] = array (
  665. 'type' => 'reset',
  666. 'name' => 'close',
  667. 'value' => _t('_adm_bp_btn_block_delete'),
  668. 'attrs' => array(
  669. 'onclick' => $sJsObject . '.deleteBlock(' . $aBlock['id'] . ')',
  670. 'class' => 'bx-def-margin-sec-left',
  671. ),
  672. );
  673. $oForm = new BxTemplStudioFormView($aForm);
  674. $oForm->initChecker();
  675. if($oForm->isSubmittedAndValid()) {
  676. $this->onSaveBlock($oForm, $aBlock);
  677. if($oForm->update($iId) !== false)
  678. return array('eval' => $sJsObject . '.onEditBlock(oData)');
  679. else
  680. return array('msg' => _t('_adm_bp_err_block_edit'));
  681. }
  682. $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(
  683. 'action' => 'edit',
  684. 'form_id' => $aForm['form_attrs']['id'],
  685. 'form' => $oForm->getCode(true)
  686. )));
  687. return array('popup' => array('html' => $sContent, 'options' => array('onBeforeShow' => $sJsObject . '.onEditBlockBeforeShow($el)')));
  688. }
  689. protected function actionBlockDelete()
  690. {
  691. $sJsObject = $this->getPageJsObject();
  692. $iId = (int)bx_get('id');
  693. $aBlock = array();
  694. $this->oDb->getBlocks(array('type' => 'by_id', 'value' => $iId), $aBlock, false);
  695. if(empty($aBlock) || !is_array($aBlock))
  696. return array('msg' => _t('_adm_bp_err_block_not_found'));
  697. if((int)$aBlock['deletable'] == 0)
  698. return array('msg' => _t('_adm_bp_err_block_not_deletable'));
  699. if(!$this->oDb->deleteBlocks(array('type' => 'by_id', 'value' => $iId)))
  700. return array('msg' => _t('_adm_bp_err_block_delete'));
  701. $this->onBlockDelete($aBlock);
  702. return array('eval' => $sJsObject . '.onDeleteBlock(' . $iId . ', oData)');
  703. }
  704. protected function actionImageDelete()
  705. {
  706. $sJsObject = $this->getPageJsObject();
  707. $iId = (int)bx_get('id');
  708. $aBlock = array();
  709. $this->oDb->getBlocks(array('type' => 'by_id', 'value' => $iId), $aBlock, false);
  710. if(empty($aBlock) || !is_array($aBlock))
  711. return array('msg' => _t('_adm_bp_err_block_not_found'));
  712. $iImageId = $sImageAlign = '';
  713. if($aBlock['content'] != '')
  714. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  715. if(is_numeric($iImageId) && (int)$iImageId != 0) {
  716. if(!BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$iImageId, 0))
  717. return array('msg' => _t('_adm_bp_err_block_content_image_preview_delete'));
  718. $this->oDb->updateBlock($iId, array('content' => ''));
  719. }
  720. return $this->actionBlockEdit();
  721. }
  722. protected function actionUriGet()
  723. {
  724. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  725. $aLanguages = $oLanguage->getLanguages();
  726. $sLanguageDef = $oLanguage->getDefaultLangName();
  727. $sLanguageCur = $oLanguage->getCurrentLangName(false);
  728. $aValues = array();
  729. foreach($aLanguages as $sName => $sTitle)
  730. if(($mixedValue = bx_get($sName)) !== false)
  731. $aValues[$sName] = bx_process_input($mixedValue);
  732. $sUri = "";
  733. if(($mixedValue = bx_get('uri')) !== false)
  734. $sUri = bx_process_input($mixedValue);
  735. else if(array_key_exists('en', $aValues) && $aValues['en'] != '')
  736. $sUri = $aValues['en'];
  737. else if(array_key_exists($sLanguageDef, $aValues) && $aValues[$sLanguageDef] != '')
  738. $sUri = $aValues[$sLanguageDef];
  739. else if(array_key_exists($sLanguageCur, $aValues) && $aValues[$sLanguageCur] != '')
  740. $sUri = $aValues[$sLanguageCur];
  741. else if(count($aValues) > 0)
  742. foreach($aValues as $sValue)
  743. if(!empty($sValue)) {
  744. $sUri = $sValue;
  745. break;
  746. }
  747. $sUri = $sUri != "" ? uriGenerate($sUri, 'sys_objects_page', 'uri') : "";
  748. $sUrl = BxDolPermalinks::getInstance()->permalink($this->sPageBaseUrl . $sUri);
  749. return array('eval' => $this->getPageJsObject() . '.onGetUri(oData)', 'uri' => $sUri, 'url' => $sUrl);
  750. }
  751. protected function getSettingsOptions($aPage = array(), $bCreate = true, $bInputsOnly = false)
  752. {
  753. $aForm = array(
  754. 'form_attrs' => array(
  755. 'id' => 'adm-bp-settings-options',
  756. ),
  757. 'params' => array (
  758. 'remove_form' => '1',
  759. 'csrf' => array(
  760. 'disable' => true
  761. )
  762. ),
  763. 'inputs' => array (
  764. 'title_system' => array(
  765. 'type' => 'text_translatable',
  766. 'name' => 'title_system',
  767. 'caption' => _t('_adm_bp_txt_page_title_system'),
  768. 'info' => _t('_adm_bp_dsc_page_title_system'),
  769. 'value' => isset($aPage['title_system']) ? $aPage['title_system'] : '',
  770. 'required' => '1',
  771. 'db' => array (
  772. 'pass' => 'Xss',
  773. ),
  774. 'checker' => array (
  775. 'func' => 'length',
  776. 'params' => array(3,100),
  777. 'error' => _t('_adm_bp_err_page_title_system'),
  778. ),
  779. ),
  780. 'title' => array(
  781. 'type' => 'text_translatable',
  782. 'name' => 'title',
  783. 'caption' => _t('_adm_bp_txt_page_title'),
  784. 'info' => _t('_adm_bp_dsc_page_title'),
  785. 'value' => isset($aPage['title']) ? $aPage['title'] : '',
  786. 'required' => '1',
  787. 'db' => array (
  788. 'pass' => 'Xss',
  789. ),
  790. 'checker' => array (
  791. 'func' => 'length',
  792. 'params' => array(3,100),
  793. 'error' => _t('_adm_bp_err_page_title'),
  794. ),
  795. ),
  796. 'url' => array(
  797. 'type' => 'text',
  798. 'name' => 'url',
  799. 'caption' => _t('_adm_bp_txt_page_url'),
  800. 'info' => _t('_adm_bp_dsc_page_url'),
  801. 'value' => isset($aPage['url']) ? BxDolPermalinks::getInstance()->permalink($aPage['url']) : '',
  802. 'required' => '0',
  803. 'attrs' => array(
  804. 'id' => $this->aHtmlIds['url_field_id'],
  805. 'disabled' => 'disabled'
  806. ),
  807. ),
  808. )
  809. );
  810. if($bCreate) {
  811. $sJsObject = $this->getPageJsObject();
  812. $aForm['inputs']['title']['attrs']['onblur'] = $sJsObject . '.getUri(this);';
  813. $aForm['inputs'] = bx_array_insert_before(array(
  814. 'uri' => array(
  815. 'type' => 'text',
  816. 'name' => 'uri',
  817. 'caption' => _t('_adm_bp_txt_page_uri'),
  818. 'info' => _t('_adm_bp_dsc_page_uri'),
  819. 'value' => '',
  820. 'required' => '1',
  821. 'attrs' => array(
  822. 'id' => $this->aHtmlIds['uri_field_id'],
  823. 'onblur' => $sJsObject . '.getUri(this);'
  824. ),
  825. 'db' => array (
  826. 'pass' => 'Xss',
  827. ),
  828. 'checker' => array (
  829. 'func' => 'length',
  830. 'params' => array(3,100),
  831. 'error' => _t('_adm_bp_err_page_uri'),
  832. ),
  833. )
  834. ), $aForm['inputs'], 'url');
  835. }
  836. if($bInputsOnly)
  837. return $aForm['inputs'];
  838. $oForm = new BxTemplStudioFormView($aForm);
  839. return $oForm->getCode();
  840. }
  841. protected function getSettingsOptionsFields($aPage = array(), $bCreate = true)
  842. {
  843. return $this->getSettingsOptions($aPage, $bCreate, true);
  844. }
  845. protected function getSettingsCover($aPage = array(), $bCreate = true, $bInputsOnly = false)
  846. {
  847. $aForm = array(
  848. 'form_attrs' => array(
  849. 'id' => 'adm-bp-settings-cover',
  850. ),
  851. 'params' => array (
  852. 'remove_form' => '1',
  853. 'csrf' => array(
  854. 'disable' => true
  855. )
  856. ),
  857. 'inputs' => array (
  858. 'cover' => array(
  859. 'type' => 'switcher',
  860. 'name' => 'cover',
  861. 'caption' => _t('_adm_bp_txt_page_cover'),
  862. 'info' => '',
  863. 'value' => '1',
  864. 'checked' => isset($aPage['cover']) && $aPage['cover'] == '1',
  865. 'db' => array (
  866. 'pass' => 'Int',
  867. )
  868. ),
  869. 'cover_image' => array(
  870. 'type' => 'files',
  871. 'name' => 'cover_image',
  872. 'storage_object' => $this->sStorage,
  873. 'images_transcoder' => $this->sTranscoderCover,
  874. 'uploaders' => $this->aUploadersCover,
  875. 'multiple' => false,
  876. 'content_id' => isset($aPage['id']) ? $aPage['id'] : 0,
  877. 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('uploader_fgt_cover.html', array(
  878. 'name' => 'cover_image',
  879. )),
  880. 'caption' => _t('_adm_bp_txt_page_cover_image'),
  881. 'db' => array (
  882. 'pass' => 'Int',
  883. )
  884. )
  885. )
  886. );
  887. if($bInputsOnly)
  888. return $aForm['inputs'];
  889. $oForm = new BxTemplStudioFormView($aForm);
  890. return $oForm->getCode();
  891. }
  892. protected function getSettingsCoverFields($aPage = array(), $bCreate = true)
  893. {
  894. return $this->getSettingsCover($aPage, $bCreate, true);
  895. }
  896. protected function getSettingsLayout($aPage = array(), $bCreate = true, $bInputsOnly = false)
  897. {
  898. $sJsObject = $this->getPageJsObject();
  899. $oTemplate = BxDolStudioTemplate::getInstance();
  900. $iLayout = isset($aPage['layout_id']) ? (int)$aPage['layout_id'] : 5;
  901. $aLayouts = array();
  902. $this->oDb->getLayouts(array('type' => 'all'), $aLayouts, false);
  903. $aTmplParams = array(
  904. 'bx_repeat:layouts' => array(),
  905. 'form' => ''
  906. );
  907. foreach($aLayouts as $aLayout)
  908. $aTmplParams['bx_repeat:layouts'][] = array(
  909. 'id' => $aLayout['id'],
  910. 'html_id' => $this->aHtmlIds['layout_id'] . $aLayout['id'],
  911. 'js_object' => $sJsObject,
  912. 'bx_if:active' => array(
  913. 'condition' => (int)$aLayout['id'] == $iLayout,
  914. 'content' => array()
  915. ),
  916. 'icon' => $oTemplate->getImageUrl($aLayout['icon']),
  917. 'title' => _t($aLayout['title']),
  918. );
  919. $aForm = array(
  920. 'form_attrs' => array(
  921. 'id' => 'adm-bp-settings-layout',
  922. ),
  923. 'params' => array (
  924. 'remove_form' => '1',
  925. 'csrf' => array(
  926. 'disable' => true
  927. )
  928. ),
  929. 'inputs' => array (
  930. 'layout_id' => array(
  931. 'type' => 'hidden',
  932. 'name' => 'layout_id',
  933. 'value' => $iLayout,
  934. 'db' => array (
  935. 'pass' => 'Int',
  936. ),
  937. )
  938. )
  939. );
  940. if($bInputsOnly)
  941. return $aForm['inputs'];
  942. $oForm = new BxTemplStudioFormView($aForm);
  943. $aTmplParams['form'] = $oForm->getCode();
  944. return $oTemplate->parseHtmlByName('bp_layouts.html', $aTmplParams);
  945. }
  946. protected function getSettingsLayoutFields($aPage = array(), $bCreate = true)
  947. {
  948. return $this->getSettingsLayout($aPage, $bCreate, true);
  949. }
  950. protected function getSettingsVisibility($aPage = array(), $bCreate = true, $bInputsOnly = false)
  951. {
  952. $iVisibleForLevels = isset($aPage['visible_for_levels']) ? (int)$aPage['visible_for_levels'] : BX_DOL_INT_MAX;
  953. if(isset($aPage['visible_for_levels_editable']) && (int)$aPage['visible_for_levels_editable'] == 0)
  954. $aInputs = array(
  955. 'visible_for_levels' => array(
  956. 'type' => 'custom',
  957. 'name' => 'visible_for_levels',
  958. 'content' => MsgBox(_t('_adm_bp_err_page_visible_for_levels'))
  959. )
  960. );
  961. else {
  962. bx_import('BxDolStudioUtils');
  963. $aInputs = array(
  964. 'visible_for' => array(
  965. 'type' => 'select',
  966. 'name' => 'visible_for',
  967. 'caption' => _t('_adm_bp_txt_block_visible_for'),
  968. 'info' => '',
  969. 'value' => $iVisibleForLevels == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
  970. 'values' => array(
  971. array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_bp_txt_block_visible_for_all')),
  972. array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_bp_txt_block_visible_for_selected')),
  973. ),
  974. 'required' => '0',
  975. 'attrs' => array(
  976. 'onchange' => $this->getPageJsObject() . '.onChangeVisibleFor(this)'
  977. ),
  978. 'db' => array (
  979. 'pass' => 'Xss',
  980. )
  981. ),
  982. 'visible_for_levels' => array(
  983. 'type' => 'checkbox_set',
  984. 'name' => 'visible_for_levels',
  985. 'caption' => _t('_adm_bp_txt_page_visible_for_levels'),
  986. 'info' => _t('_adm_bp_dsc_page_visible_for_levels'),
  987. 'value' => array(),
  988. 'values' => array(),
  989. 'tr_attrs' => array(
  990. 'style' => $iVisibleForLevels == BX_DOL_INT_MAX ? 'display:none' : ''
  991. ),
  992. 'db' => array (
  993. 'pass' => 'Int',
  994. )
  995. )
  996. );
  997. }
  998. $aForm = array(
  999. 'form_attrs' => array(
  1000. 'id' => 'adm-bp-settings-visibility',
  1001. ),
  1002. 'params' => array (
  1003. 'remove_form' => '1',
  1004. 'csrf' => array(
  1005. 'disable' => true
  1006. )
  1007. ),
  1008. 'inputs' => $aInputs
  1009. );
  1010. BxDolStudioUtils::getVisibilityValues($iVisibleForLevels, $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
  1011. if($bInputsOnly)
  1012. return $aForm['inputs'];
  1013. $oForm = new BxTemplStudioFormView($aForm);
  1014. return $oForm->getCode();
  1015. }
  1016. protected function getSettingsVisibilityFields($aPage = array(), $bCreate = true)
  1017. {
  1018. return $this->getSettingsVisibility($aPage = array(), $bCreate, true);
  1019. }
  1020. protected function getSettingsCache($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1021. {
  1022. $aForm = array(
  1023. 'form_attrs' => array(
  1024. 'id' => 'adm-bp-settings-cache',
  1025. ),
  1026. 'params' => array (
  1027. 'remove_form' => '1',
  1028. 'csrf' => array(
  1029. 'disable' => true
  1030. )
  1031. ),
  1032. 'inputs' => array (
  1033. 'cache_lifetime' => array(
  1034. 'type' => 'text',
  1035. 'name' => 'cache_lifetime',
  1036. 'caption' => _t('_adm_bp_txt_page_cache_lifetime'),
  1037. 'info' => _t('_adm_bp_dsc_page_cache_lifetime'),
  1038. 'value' => isset($aPage['cache_lifetime']) ? $aPage['cache_lifetime'] : 0,
  1039. 'required' => '',
  1040. 'attrs' => array(
  1041. 'disabled' => isset($aPage['cache_editable']) && (int)$aPage['cache_editable'] == 0 ? 'disabled' : ''
  1042. ),
  1043. 'db' => array (
  1044. 'pass' => 'Int',
  1045. )
  1046. ),
  1047. )
  1048. );
  1049. if($bInputsOnly)
  1050. return $aForm['inputs'];
  1051. $oForm = new BxTemplStudioFormView($aForm);
  1052. return $oForm->getCode();
  1053. }
  1054. protected function getSettingsCacheFields($aPage = array(), $bCreate = true)
  1055. {
  1056. return $this->getSettingsCache($aPage, $bCreate, true);
  1057. }
  1058. protected function getSettingsSeo($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1059. {
  1060. $aForm = array(
  1061. 'form_attrs' => array(
  1062. 'id' => 'adm-bp-settings-seo',
  1063. ),
  1064. 'params' => array (
  1065. 'remove_form' => '1',
  1066. 'csrf' => array(
  1067. 'disable' => true
  1068. )
  1069. ),
  1070. 'inputs' => array (
  1071. 'meta_description' => array(
  1072. 'type' => 'textarea',
  1073. 'name' => 'meta_description',
  1074. 'caption' => _t('_adm_bp_txt_page_meta_description'),
  1075. 'info' => _t('_adm_bp_dsc_page_meta_description'),
  1076. 'value' => isset($aPage['meta_description']) ? $aPage['meta_description'] : '',
  1077. 'db' => array (
  1078. 'pass' => 'Xss',
  1079. ),
  1080. ),
  1081. 'meta_keywords' => array(
  1082. 'type' => 'textarea',
  1083. 'name' => 'meta_keywords',
  1084. 'caption' => _t('_adm_bp_txt_page_meta_keywords'),
  1085. 'info' => _t('_adm_bp_dsc_page_meta_keywords'),
  1086. 'value' => isset($aPage['meta_keywords']) ? $aPage['meta_keywords'] : '',
  1087. 'db' => array (
  1088. 'pass' => 'Xss',
  1089. ),
  1090. ),
  1091. 'meta_robots' => array(
  1092. 'type' => 'text',
  1093. 'name' => 'meta_robots',
  1094. 'caption' => _t('_adm_bp_txt_page_meta_robots'),
  1095. 'info' => _t('_adm_bp_dsc_page_meta_robots'),
  1096. 'value' => isset($aPage['meta_robots']) ? $aPage['meta_robots'] : '',
  1097. 'required' => '0',
  1098. 'db' => array (
  1099. 'pass' => 'Xss',
  1100. )
  1101. )
  1102. )
  1103. );
  1104. if($bInputsOnly)
  1105. return $aForm['inputs'];
  1106. $oForm = new BxTemplStudioFormView($aForm);
  1107. return $oForm->getCode();
  1108. }
  1109. protected function getSettingsSeoFields($aPage = array(), $bCreate = true)
  1110. {
  1111. return $this->getSettingsSeo($aPage, $bCreate, true);
  1112. }
  1113. protected function getBlockIcon($aBlock)
  1114. {
  1115. $sIcon = $sIconUrl = "";
  1116. $sResult = '';
  1117. switch($aBlock['type']) {
  1118. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1119. $sResult = 'file-text-o';
  1120. break;
  1121. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1122. $sResult = 'code';
  1123. break;
  1124. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1125. $sResult = 'rss';
  1126. break;
  1127. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1128. $sResult = 'picture-o';
  1129. break;
  1130. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1131. $sResult = 'globe';
  1132. break;
  1133. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1134. $sResult = 'list-alt';
  1135. break;
  1136. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1137. $sResult = $this->getModuleIcon($aBlock['module'], 'page');
  1138. break;
  1139. }
  1140. if(strpos($sResult, '.') === false)
  1141. $sIcon = $sResult;
  1142. else
  1143. $sIconUrl = $sResult;
  1144. return array($sIcon, $sIconUrl);
  1145. }
  1146. protected function getBlockModule($aBlock)
  1147. {
  1148. return $aBlock['module'] != BX_DOL_STUDIO_BP_SKELETONS ? $aBlock['module'] : BX_DOL_STUDIO_MODULE_CUSTOM;
  1149. }
  1150. protected function getBlockContent($aBlock)
  1151. {
  1152. $aFields = array();
  1153. switch($aBlock['type']) {
  1154. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1155. $aFields = array(
  1156. 'content' => array(
  1157. 'type' => 'textarea',
  1158. 'name' => 'content',
  1159. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1160. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1161. 'value' => $aBlock['content'],
  1162. 'required' => '0',
  1163. 'code' => 1,
  1164. 'attrs' => array('class' => 'bx-form-input-textarea-codemirror'),
  1165. 'db' => array (
  1166. 'pass' => 'XssHtml',
  1167. ),
  1168. ),
  1169. );
  1170. break;
  1171. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1172. $aFields = array(
  1173. 'content' => array(
  1174. 'type' => 'textarea',
  1175. 'name' => 'content',
  1176. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1177. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1178. 'value' => $aBlock['content'],
  1179. 'required' => '0',
  1180. 'html' => 1,
  1181. 'attrs' => array('id' => $this->aHtmlIds['edit_block_editor_id']),
  1182. 'db' => array (
  1183. 'pass' => 'XssHtml',
  1184. ),
  1185. ),
  1186. 'attachments' => array(
  1187. 'type' => 'files',
  1188. 'name' => 'attachments',
  1189. 'storage_object' => $this->sStorage,
  1190. 'images_transcoder' => $this->sTranscoder,
  1191. 'uploaders' => $this->aUploaders,
  1192. 'multiple' => true,
  1193. 'content_id' => $aBlock['id'],
  1194. 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('bp_fgt_attachments.html', array(
  1195. 'js_object' => $this->getPageJsObject(),
  1196. 'name' => 'attachments',
  1197. 'editor_id' => $this->aHtmlIds['edit_block_editor_id'],
  1198. )),
  1199. 'caption' => _t('_adm_bp_txt_block_content_attachments_html')
  1200. )
  1201. );
  1202. break;
  1203. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1204. $aFields = array(
  1205. 'content' => array(
  1206. 'type' => 'textarea_translatable',
  1207. 'name' => 'content',
  1208. 'caption' => _t('_adm_bp_txt_block_content_lang'),
  1209. 'info' => _t('_adm_bp_dsc_block_content_lang'),
  1210. 'value' => $aBlock['content'],
  1211. 'required' => '0',
  1212. 'html' => 0,
  1213. 'code' => 1,
  1214. 'db' => array (
  1215. 'pass' => 'XssHtml',
  1216. ),
  1217. ),
  1218. );
  1219. break;
  1220. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1221. $iImageId = $sImageAlign = '';
  1222. if($aBlock['content'] != '')
  1223. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1224. $aFields = array(
  1225. 'content' => array(
  1226. 'type' => 'hidden',
  1227. 'name' => 'content',
  1228. 'value' => '',
  1229. 'db' => array (
  1230. 'pass' => 'Xss',
  1231. ),
  1232. ),
  1233. 'image_file' => array(
  1234. 'type' => 'image_uploader',
  1235. 'name' => 'image_file',
  1236. 'caption' => _t('_adm_bp_txt_block_content_image_file'),
  1237. 'caption_preview' => _t('_adm_bp_txt_block_content_image_preview'),
  1238. 'info' => _t('_adm_bp_dsc_block_content_image_file'),
  1239. 'ajax_action_delete' => $this->getPageJsObject() . '.deleteBlockImage(' . $aBlock['id'] . ')',
  1240. 'value' => (int)$iImageId
  1241. ),
  1242. 'image_align' => array(
  1243. 'type' => 'select',
  1244. 'name' => 'image_align',
  1245. 'caption' => _t('_adm_bp_txt_block_content_image_align'),
  1246. 'info' => '',
  1247. 'value' => $sImageAlign,
  1248. 'values' => array(
  1249. array('key' => '', 'value' => _t('_adm_bp_txt_block_content_image_align_empty')),
  1250. array('key' => 'left', 'value' => _t('_adm_bp_txt_block_content_image_align_left')),
  1251. array('key' => 'center', 'value' => _t('_adm_bp_txt_block_content_image_align_center')),
  1252. array('key' => 'right', 'value' => _t('_adm_bp_txt_block_content_image_align_right')),
  1253. ),
  1254. 'required' => '0',
  1255. 'db' => array (
  1256. 'pass' => 'Xss',
  1257. ),
  1258. ),
  1259. );
  1260. break;
  1261. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1262. $sRssUrl = $sRssLength = '';
  1263. if($aBlock['content'] != '')
  1264. list($sRssUrl, $sRssLength) = explode($this->sParamsDivider, $aBlock['content']);
  1265. $aFields = array(
  1266. 'content' => array(
  1267. 'type' => 'hidden',
  1268. 'name' => 'content',
  1269. 'value' => '',
  1270. 'db' => array (
  1271. 'pass' => 'Xss',
  1272. ),
  1273. ),
  1274. 'rss_url' => array(
  1275. 'type' => 'text',
  1276. 'name' => 'rss_url',
  1277. 'caption' => _t('_adm_bp_txt_block_content_rss_url'),
  1278. 'info' => _t('_adm_bp_dsc_block_content_rss_url'),
  1279. 'value' => $sRssUrl,
  1280. 'required' => '0',
  1281. 'db' => array (
  1282. 'pass' => 'Xss',
  1283. ),
  1284. ),
  1285. 'rss_length' => array(
  1286. 'type' => 'text',
  1287. 'name' => 'rss_length',
  1288. 'caption' => _t('_adm_bp_txt_block_content_rss_length'),
  1289. 'info' => _t('_adm_bp_dsc_block_content_rss_length'),
  1290. 'value' => $sRssLength,
  1291. 'required' => '0',
  1292. 'db' => array (
  1293. 'pass' => 'Int',
  1294. ),
  1295. ),
  1296. );
  1297. break;
  1298. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1299. $aFields = array(
  1300. 'content' => array(
  1301. 'type' => 'select',
  1302. 'name' => 'content',
  1303. 'caption' => _t('_adm_bp_txt_block_content_menu'),
  1304. 'info' => '',
  1305. 'value' => $aBlock['content'],
  1306. 'values' => array(),
  1307. 'required' => '0',
  1308. 'db' => array (
  1309. 'pass' => 'Xss',
  1310. ),
  1311. )
  1312. );
  1313. $aMenus = $this->oDb->getMenus();
  1314. foreach($aMenus as $sKey => $sValue)
  1315. $aFields['content']['values'][$sKey] = _t($sValue);
  1316. asort($aFields['content']['values']);
  1317. $aFields['content']['values'] = array_merge(array('' => _t('_adm_bp_txt_block_content_menu_empty')), $aFields['content']['values']);
  1318. break;
  1319. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1320. $aService = array('module' => '', 'method' => '');
  1321. if($aBlock['content'] != '')
  1322. $aService = unserialize($aBlock['content']);
  1323. $aFields = array(
  1324. 'service_module' => array(
  1325. 'type' => 'value',
  1326. 'name' => 'service_module',
  1327. 'caption' => _t('_adm_bp_txt_block_content_service_module'),
  1328. 'value' => $this->getModuleTitle($aService['module'])
  1329. ),
  1330. 'service_method' => array(
  1331. 'type' => 'value',
  1332. 'name' => 'service_method',
  1333. 'caption' => _t('_adm_bp_txt_block_content_service_method'),
  1334. 'value' => $aService['method']
  1335. )
  1336. );
  1337. break;
  1338. }
  1339. return $aFields;
  1340. }
  1341. protected function getBlockList($sModule)
  1342. {
  1343. if(empty($sModule))
  1344. return '';
  1345. $sJsObject = $this->getPageJsObject();
  1346. $oTemplate = BxDolStudioTemplate::getInstance();
  1347. $oForm = new BxTemplStudioFormView(array());
  1348. $aInputCheckbox = array(
  1349. 'type' => 'checkbox',
  1350. 'name' => 'blocks[]',
  1351. 'attrs' => array(
  1352. 'onChange' => 'javascript:' . $sJsObject . '.onSelectBlock(this);'
  1353. ),
  1354. 'value' => ''
  1355. );
  1356. $aTmplParams = array(
  1357. 'html_block_list_id' => $this->aHtmlIds['block_list_id'] . $sModule,
  1358. 'bx_repeat:blocks' => array()
  1359. );
  1360. $aBlocks = $this->getBlocks($sModule);
  1361. foreach($aBlocks as $aBlock) {
  1362. list($sIcon, $sIconUrl) = $this->getBlockIcon($aBlock);
  1363. $aInputCheckbox['value'] = $aBlock['id'];
  1364. $aTmplParams['bx_repeat:blocks'][] = array(
  1365. 'js_object' => $sJsObject,
  1366. 'html_id' => $this->aHtmlIds['block_id'] . $aBlock['id'],
  1367. 'bx_if:is_inactive' => array(
  1368. 'condition' => false,
  1369. 'content' => array()
  1370. ),
  1371. 'bx_if:show_link' => array(
  1372. 'condition' => false,
  1373. 'content' => array()
  1374. ),
  1375. 'bx_if:show_text' => array(
  1376. 'condition' => true,
  1377. 'content' => array(
  1378. 'title' => _t(!empty($aBlock['title_system']) ? $aBlock['title_system'] : $aBlock['title']),
  1379. )
  1380. ),
  1381. 'bx_if:image' => array (
  1382. 'condition' => (bool)$sIconUrl,
  1383. 'content' => array('icon_url' => $sIconUrl),
  1384. ),
  1385. 'bx_if:icon' => array (
  1386. 'condition' => (bool)$sIcon,
  1387. 'content' => array('icon' => $sIcon),
  1388. ),
  1389. 'module' => $this->getModuleTitle($aBlock['module']),
  1390. 'visible_for' => _t('_adm_bp_txt_visible_for', BxDolStudioUtils::getVisibilityTitle($aBlock['visible_for_levels'])),
  1391. 'bx_if:show_checkbox' => array(
  1392. 'condition' => true,
  1393. 'content' => array(
  1394. 'content' => $oForm->genRow($aInputCheckbox)
  1395. )
  1396. ),
  1397. 'bx_if:show_drag_handle' => array(
  1398. 'condition' => false,
  1399. 'content' => array()
  1400. )
  1401. );
  1402. }
  1403. return $oTemplate->parseHtmlByName('bp_blocks_list.html', $aTmplParams);
  1404. }
  1405. protected function onBlockDelete($aBlock)
  1406. {
  1407. if($aBlock['module'] != BX_DOL_STUDIO_MODULE_CUSTOM)
  1408. return;
  1409. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['title']);
  1410. //--- Process Lang block
  1411. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && $aBlock['content'] != '')
  1412. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['content']);
  1413. //--- Process Image block
  1414. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && $aBlock['content'] != '') {
  1415. $iImageId = $sImageAlign = '';
  1416. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1417. if(is_numeric($iImageId) && (int)$iImageId != 0)
  1418. BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$iImageId, 0);
  1419. }
  1420. }
  1421. protected function getBlocks($sModule)
  1422. {
  1423. $aBlocks = array();
  1424. $this->oDb->getBlocks(array('type' => 'by_module_to_copy', 'value' => $sModule), $aBlocks, false);
  1425. return $aBlocks;
  1426. }
  1427. protected function _getTmplVarsBlockPanelTop()
  1428. {
  1429. $sJsObject = $this->getPageJsObject();
  1430. $oForm = new BxTemplStudioFormView(array());
  1431. $aInputPages = array(
  1432. 'type' => 'select',
  1433. 'name' => 'page',
  1434. 'attrs' => array(
  1435. 'onChange' => 'javascript:' . $this->getPageJsObject() . '.onChangePage(this)'
  1436. ),
  1437. 'value' => $this->sPage,
  1438. 'values' => array(
  1439. array('key' => '', 'value' => _t('_adm_bp_txt_select_page'))
  1440. )
  1441. );
  1442. $aPages = $aCounter = array();
  1443. $this->oDb->getPages(array('type' => 'by_module', 'value' => $this->sType), $aPages, false);
  1444. $this->oDb->getBlocks(array('type' => 'counter_by_pages'), $aCounter, false);
  1445. foreach($aPages as $aPage)
  1446. $aInputPages['values'][] = array('key' => $aPage['object'], 'value' => _t($aPage['title_system']) . " (" . (isset($aCounter[$aPage['object']]) ? $aCounter[$aPage['object']] : "0") . ")");
  1447. $aTmplVarsActions = array();
  1448. if(($this->sPage != '' && !empty($this->aPageRebuild)) !== false)
  1449. $aTmplVarsActions = $this->_getTmplVarsBlockPanelTopActions();
  1450. return array(
  1451. 'js_object' => $this->getPageJsObject(),
  1452. 'selector' => $oForm->genRow($aInputPages),
  1453. 'action_page_create' => $this->sActionPageCreate,
  1454. 'bx_if:show_actions' => array(
  1455. 'condition' => $this->sPage != '',
  1456. 'content' => $aTmplVarsActions
  1457. )
  1458. );
  1459. }
  1460. protected function _getTmplVarsBlockPanelTopActions()
  1461. {
  1462. $sJsObject = $this->getPageJsObject();
  1463. $oPermalinks = BxDolPermalinks::getInstance();
  1464. return array(
  1465. 'js_object' => $sJsObject,
  1466. 'url_view' => BX_DOL_URL_ROOT . $oPermalinks->permalink($this->aPageRebuild['url']),
  1467. 'action_page_edit' => $this->sActionPageEdit,
  1468. 'bx_if:can_delete' => array(
  1469. 'condition' => (int)$this->aPageRebuild['deletable'] == 1,
  1470. 'content' => array(
  1471. 'js_object' => $sJsObject
  1472. )
  1473. ),
  1474. 'action_block_create' => $this->sActionBlockCreate,
  1475. );
  1476. }
  1477. protected function _getTmplVarsPageSettings($aPage = array(), $bCreate = true)
  1478. {
  1479. $sJsObject = $this->getPageJsObject();
  1480. $aTmplParams = array(
  1481. 'js_object' => $sJsObject,
  1482. 'menu' => array(),
  1483. 'html_settings_groups_id' => $this->aHtmlIds['settings_groups_id'],
  1484. 'bx_repeat:settings_groups' => array(),
  1485. 'submit' => _t($bCreate ? '_adm_bp_btn_page_create' : '_adm_bp_btn_page_apply')
  1486. );
  1487. foreach($this->aPageSettings as $aSetting) {
  1488. //--- get menu items
  1489. $aTmplParams['menu'][$aSetting['name']] = array(
  1490. 'name' => $aSetting['name'],
  1491. 'icon' => '',
  1492. 'onclick' => $sJsObject . '.onChangeSettingGroup(\'' . $aSetting['name'] . '\', this);',
  1493. 'title' => $aSetting['title'],
  1494. 'selected' => isset($aSetting['active']) && (int)$aSetting['active'] == 1
  1495. );
  1496. //--- get settings
  1497. $aTmplParams['bx_repeat:settings_groups'][] = array(
  1498. 'html_settings_group_id' => $this->aHtmlIds['settings_group_id'] . $aSetting['name'],
  1499. 'bx_if:hidden' => array(
  1500. 'condition' => $aSetting['active'] != 1,
  1501. 'content' => array()
  1502. ),
  1503. 'content' => $this->{'getSettings' . $this->getClassName($aSetting['name'])}($aPage, $bCreate)
  1504. );
  1505. }
  1506. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aTmplParams['menu']));
  1507. $aTmplParams['menu'] = $oMenu->getCode();
  1508. return $aTmplParams;
  1509. }
  1510. }
  1511. /** @} */