BxBaseStudioBuilderPage.php 68 KB

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