BxBaseStudioBuilderPage.php 70 KB

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