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. ),
  594. 'db' => array (
  595. 'pass' => 'Set',
  596. )
  597. ),
  598. 'visible_for' => array(
  599. 'type' => 'select',
  600. 'name' => 'visible_for',
  601. 'caption' => _t('_adm_bp_txt_block_visible_for'),
  602. 'info' => '',
  603. 'value' => $aBlock['visible_for_levels'] == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
  604. 'values' => array(
  605. array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_bp_txt_block_visible_for_all')),
  606. array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_bp_txt_block_visible_for_selected')),
  607. ),
  608. 'required' => '0',
  609. 'attrs' => array(
  610. 'onchange' => $sJsObject . '.onChangeVisibleFor(this)'
  611. ),
  612. 'db' => array (
  613. 'pass' => 'Xss',
  614. )
  615. ),
  616. 'visible_for_levels' => array(
  617. 'type' => 'checkbox_set',
  618. 'name' => 'visible_for_levels',
  619. 'caption' => _t('_adm_bp_txt_block_visible_for_levels'),
  620. 'info' => _t('_adm_bp_dsc_block_visible_for_levels'),
  621. 'value' => array(),
  622. 'values' => array(),
  623. 'tr_attrs' => array(
  624. 'style' => $aBlock['visible_for_levels'] == BX_DOL_INT_MAX ? 'display:none' : ''
  625. ),
  626. 'db' => array (
  627. 'pass' => 'Int',
  628. )
  629. ),
  630. 'active' => array(
  631. 'type' => 'switcher',
  632. 'name' => 'active',
  633. 'caption' => _t('_adm_bp_txt_block_active'),
  634. 'info' => '',
  635. 'value' => '1',
  636. 'checked' => $aBlock['active'] == '1',
  637. 'db' => array (
  638. 'pass' => 'Int',
  639. )
  640. ),
  641. 'controls' => array(
  642. 'name' => 'controls',
  643. 'type' => 'input_set',
  644. array(
  645. 'type' => 'submit',
  646. 'name' => 'do_submit',
  647. 'value' => _t('_adm_bp_btn_block_save')
  648. ),
  649. array (
  650. 'type' => 'reset',
  651. 'name' => 'close',
  652. 'value' => _t('_adm_bp_btn_block_cancel'),
  653. 'attrs' => array(
  654. 'onclick' => $sJsObject . '.onEditBlockCancel(this)',
  655. 'class' => 'bx-def-margin-sec-left',
  656. ),
  657. )
  658. )
  659. )
  660. );
  661. $aDBoxes = array();
  662. $this->oDb->getDesignBoxes(array('type' => 'ordered'), $aDBoxes, false);
  663. foreach($aDBoxes as $aDBox)
  664. $aForm['inputs']['designbox_id']['values'][] = array('key' => $this->sSelectKeyPrefix . $aDBox['id'], 'value' => _t($aDBox['title']));
  665. BxDolStudioUtils::getVisibilityValues($aBlock['visible_for_levels'], $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
  666. $aForm['inputs'] = $this->addInArray($aForm['inputs'], 'visible_for_levels', $this->getBlockContent($aBlock));
  667. if((int)$aBlock['deletable'] != 0)
  668. $aForm['inputs']['controls'][] = array (
  669. 'type' => 'reset',
  670. 'name' => 'close',
  671. 'value' => _t('_adm_bp_btn_block_delete'),
  672. 'attrs' => array(
  673. 'onclick' => $sJsObject . '.deleteBlock(' . $aBlock['id'] . ')',
  674. 'class' => 'bx-def-margin-sec-left',
  675. ),
  676. );
  677. $oForm = new BxTemplStudioFormView($aForm);
  678. $oForm->initChecker();
  679. if($oForm->isSubmittedAndValid()) {
  680. $this->onSaveBlock($oForm, $aBlock);
  681. if($oForm->update($iId) !== false)
  682. return array('eval' => $sJsObject . '.onEditBlock(oData)');
  683. else
  684. return array('msg' => _t('_adm_bp_err_block_edit'));
  685. }
  686. $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(
  687. 'action' => 'edit',
  688. 'form_id' => $aForm['form_attrs']['id'],
  689. 'form' => $oForm->getCode(true)
  690. )));
  691. return array('popup' => array('html' => $sContent, 'options' => array('onBeforeShow' => $sJsObject . '.onEditBlockBeforeShow($el)')));
  692. }
  693. protected function actionBlockDelete()
  694. {
  695. $sJsObject = $this->getPageJsObject();
  696. $iId = (int)bx_get('id');
  697. $aBlock = array();
  698. $this->oDb->getBlocks(array('type' => 'by_id', 'value' => $iId), $aBlock, false);
  699. if(empty($aBlock) || !is_array($aBlock))
  700. return array('msg' => _t('_adm_bp_err_block_not_found'));
  701. if((int)$aBlock['deletable'] == 0)
  702. return array('msg' => _t('_adm_bp_err_block_not_deletable'));
  703. if(!$this->oDb->deleteBlocks(array('type' => 'by_id', 'value' => $iId)))
  704. return array('msg' => _t('_adm_bp_err_block_delete'));
  705. $this->onBlockDelete($aBlock);
  706. return array('eval' => $sJsObject . '.onDeleteBlock(' . $iId . ', oData)');
  707. }
  708. protected function actionImageDelete()
  709. {
  710. $sJsObject = $this->getPageJsObject();
  711. $iId = (int)bx_get('id');
  712. $aBlock = array();
  713. $this->oDb->getBlocks(array('type' => 'by_id', 'value' => $iId), $aBlock, false);
  714. if(empty($aBlock) || !is_array($aBlock))
  715. return array('msg' => _t('_adm_bp_err_block_not_found'));
  716. $iImageId = $sImageAlign = '';
  717. if($aBlock['content'] != '')
  718. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  719. if(is_numeric($iImageId) && (int)$iImageId != 0) {
  720. if(!BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$iImageId, 0))
  721. return array('msg' => _t('_adm_bp_err_block_content_image_preview_delete'));
  722. $this->oDb->updateBlock($iId, array('content' => ''));
  723. }
  724. return $this->actionBlockEdit();
  725. }
  726. protected function actionUriGet()
  727. {
  728. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  729. $aLanguages = $oLanguage->getLanguages();
  730. $sLanguageDef = $oLanguage->getDefaultLangName();
  731. $sLanguageCur = $oLanguage->getCurrentLangName(false);
  732. $aValues = array();
  733. foreach($aLanguages as $sName => $sTitle)
  734. if(($mixedValue = bx_get($sName)) !== false)
  735. $aValues[$sName] = bx_process_input($mixedValue);
  736. $sUri = "";
  737. if(($mixedValue = bx_get('uri')) !== false)
  738. $sUri = bx_process_input($mixedValue);
  739. else if(array_key_exists('en', $aValues) && $aValues['en'] != '')
  740. $sUri = $aValues['en'];
  741. else if(array_key_exists($sLanguageDef, $aValues) && $aValues[$sLanguageDef] != '')
  742. $sUri = $aValues[$sLanguageDef];
  743. else if(array_key_exists($sLanguageCur, $aValues) && $aValues[$sLanguageCur] != '')
  744. $sUri = $aValues[$sLanguageCur];
  745. else if(count($aValues) > 0)
  746. foreach($aValues as $sValue)
  747. if(!empty($sValue)) {
  748. $sUri = $sValue;
  749. break;
  750. }
  751. $sUri = $sUri != "" ? uriGenerate($sUri, 'sys_objects_page', 'uri') : "";
  752. $sUrl = BxDolPermalinks::getInstance()->permalink($this->sPageBaseUrl . $sUri);
  753. return array('eval' => $this->getPageJsObject() . '.onGetUri(oData)', 'uri' => $sUri, 'url' => $sUrl);
  754. }
  755. protected function getSettingsOptions($aPage = array(), $bCreate = true, $bInputsOnly = false)
  756. {
  757. $aForm = array(
  758. 'form_attrs' => array(
  759. 'id' => 'adm-bp-settings-options',
  760. ),
  761. 'params' => array (
  762. 'remove_form' => '1',
  763. 'csrf' => array(
  764. 'disable' => true
  765. )
  766. ),
  767. 'inputs' => array (
  768. 'title_system' => array(
  769. 'type' => 'text_translatable',
  770. 'name' => 'title_system',
  771. 'caption' => _t('_adm_bp_txt_page_title_system'),
  772. 'info' => _t('_adm_bp_dsc_page_title_system'),
  773. 'value' => isset($aPage['title_system']) ? $aPage['title_system'] : '',
  774. 'required' => '1',
  775. 'db' => array (
  776. 'pass' => 'Xss',
  777. ),
  778. 'checker' => array (
  779. 'func' => 'length',
  780. 'params' => array(3,100),
  781. 'error' => _t('_adm_bp_err_page_title_system'),
  782. ),
  783. ),
  784. 'title' => array(
  785. 'type' => 'text_translatable',
  786. 'name' => 'title',
  787. 'caption' => _t('_adm_bp_txt_page_title'),
  788. 'info' => _t('_adm_bp_dsc_page_title'),
  789. 'value' => isset($aPage['title']) ? $aPage['title'] : '',
  790. 'required' => '1',
  791. 'db' => array (
  792. 'pass' => 'Xss',
  793. ),
  794. 'checker' => array (
  795. 'func' => 'length',
  796. 'params' => array(3,100),
  797. 'error' => _t('_adm_bp_err_page_title'),
  798. ),
  799. ),
  800. 'url' => array(
  801. 'type' => 'text',
  802. 'name' => 'url',
  803. 'caption' => _t('_adm_bp_txt_page_url'),
  804. 'info' => _t('_adm_bp_dsc_page_url'),
  805. 'value' => isset($aPage['url']) ? BxDolPermalinks::getInstance()->permalink($aPage['url']) : '',
  806. 'required' => '0',
  807. 'attrs' => array(
  808. 'id' => $this->aHtmlIds['url_field_id'],
  809. 'disabled' => 'disabled'
  810. ),
  811. ),
  812. 'type_id' => array(
  813. 'type' => 'select',
  814. 'name' => 'type_id',
  815. 'caption' => _t('_adm_bp_txt_page_type_id'),
  816. 'info' => _t('_adm_bp_dsc_page_type_id'),
  817. 'value' => isset($aPage['type_id']) ? $aPage['type_id'] : '',
  818. 'required' => '1',
  819. 'db' => array (
  820. 'pass' => 'Int',
  821. ),
  822. ),
  823. 'submenu' => array(
  824. 'type' => 'select',
  825. 'name' => 'submenu',
  826. 'caption' => _t('_adm_bp_txt_page_submenu'),
  827. 'info' => _t('_adm_bp_dsc_page_submenu'),
  828. 'value' => isset($aPage['submenu']) ? $aPage['submenu'] : '',
  829. 'required' => '0',
  830. 'db' => array (
  831. 'pass' => 'Xss',
  832. ),
  833. ),
  834. )
  835. );
  836. $aTypes = array();
  837. $this->oDb->getTypes(array('type' => 'all'), $aTypes, false);
  838. foreach($aTypes as $aType)
  839. $aForm['inputs']['type_id']['values'][] = array('key' => $aType['id'], 'value' => _t($aType['title']));
  840. $aSubmenus = $this->oDb->getSubmenus();
  841. $aForm['inputs']['submenu']['values'][] = array('key' => '', 'value' => _t('_sys_please_select'));
  842. foreach ($aSubmenus as $sObject => $sTitle)
  843. $aForm['inputs']['submenu']['values'][] = array('key' => $sObject, 'value' => _t($sTitle));
  844. if($bCreate) {
  845. $sJsObject = $this->getPageJsObject();
  846. $aForm['inputs']['title']['attrs']['onblur'] = $sJsObject . '.getUri(this);';
  847. $aForm['inputs'] = bx_array_insert_before(array(
  848. 'uri' => array(
  849. 'type' => 'text',
  850. 'name' => 'uri',
  851. 'caption' => _t('_adm_bp_txt_page_uri'),
  852. 'info' => _t('_adm_bp_dsc_page_uri'),
  853. 'value' => '',
  854. 'required' => '1',
  855. 'attrs' => array(
  856. 'id' => $this->aHtmlIds['uri_field_id'],
  857. 'onblur' => $sJsObject . '.getUri(this);'
  858. ),
  859. 'db' => array (
  860. 'pass' => 'Xss',
  861. ),
  862. 'checker' => array (
  863. 'func' => 'length',
  864. 'params' => array(3,100),
  865. 'error' => _t('_adm_bp_err_page_uri'),
  866. ),
  867. )
  868. ), $aForm['inputs'], 'url');
  869. }
  870. if($bInputsOnly)
  871. return $aForm['inputs'];
  872. $oForm = new BxTemplStudioFormView($aForm);
  873. return $oForm->getCode();
  874. }
  875. protected function getSettingsOptionsFields($aPage = array(), $bCreate = true)
  876. {
  877. return $this->getSettingsOptions($aPage, $bCreate, true);
  878. }
  879. protected function getSettingsCover($aPage = array(), $bCreate = true, $bInputsOnly = false)
  880. {
  881. $aForm = array(
  882. 'form_attrs' => array(
  883. 'id' => 'adm-bp-settings-cover',
  884. ),
  885. 'params' => array (
  886. 'remove_form' => '1',
  887. 'csrf' => array(
  888. 'disable' => true
  889. )
  890. ),
  891. 'inputs' => array (
  892. 'cover' => array(
  893. 'type' => 'switcher',
  894. 'name' => 'cover',
  895. 'caption' => _t('_adm_bp_txt_page_cover'),
  896. 'info' => '',
  897. 'value' => '1',
  898. 'checked' => isset($aPage['cover']) && $aPage['cover'] == '1',
  899. 'db' => array (
  900. 'pass' => 'Int',
  901. )
  902. ),
  903. 'cover_image' => array(
  904. 'type' => 'files',
  905. 'name' => 'cover_image',
  906. 'storage_object' => $this->sStorage,
  907. 'images_transcoder' => $this->sTranscoderCover,
  908. 'uploaders' => $this->aUploadersCover,
  909. 'multiple' => false,
  910. 'content_id' => isset($aPage['id']) ? $aPage['id'] : 0,
  911. 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('uploader_fgt_cover.html', array(
  912. 'name' => 'cover_image',
  913. )),
  914. 'caption' => _t('_adm_bp_txt_page_cover_image'),
  915. 'db' => array (
  916. 'pass' => 'Int',
  917. )
  918. )
  919. )
  920. );
  921. if($bInputsOnly)
  922. return $aForm['inputs'];
  923. $oForm = new BxTemplStudioFormView($aForm);
  924. return $oForm->getCode();
  925. }
  926. protected function getSettingsCoverFields($aPage = array(), $bCreate = true)
  927. {
  928. return $this->getSettingsCover($aPage, $bCreate, true);
  929. }
  930. protected function getSettingsLayout($aPage = array(), $bCreate = true, $bInputsOnly = false)
  931. {
  932. $sJsObject = $this->getPageJsObject();
  933. $oTemplate = BxDolStudioTemplate::getInstance();
  934. $iLayout = isset($aPage['layout_id']) ? (int)$aPage['layout_id'] : 5;
  935. $aLayouts = array();
  936. $this->oDb->getLayouts(array('type' => 'all'), $aLayouts, false);
  937. $aTmplParams = array(
  938. 'bx_repeat:layouts' => array(),
  939. 'form' => ''
  940. );
  941. foreach($aLayouts as $aLayout)
  942. $aTmplParams['bx_repeat:layouts'][] = array(
  943. 'id' => $aLayout['id'],
  944. 'html_id' => $this->aHtmlIds['layout_id'] . $aLayout['id'],
  945. 'js_object' => $sJsObject,
  946. 'bx_if:active' => array(
  947. 'condition' => (int)$aLayout['id'] == $iLayout,
  948. 'content' => array()
  949. ),
  950. 'icon' => $oTemplate->getImageUrl($aLayout['icon']),
  951. 'title' => _t($aLayout['title']),
  952. );
  953. $aForm = array(
  954. 'form_attrs' => array(
  955. 'id' => 'adm-bp-settings-layout',
  956. ),
  957. 'params' => array (
  958. 'remove_form' => '1',
  959. 'csrf' => array(
  960. 'disable' => true
  961. )
  962. ),
  963. 'inputs' => array (
  964. 'layout_id' => array(
  965. 'type' => 'hidden',
  966. 'name' => 'layout_id',
  967. 'value' => $iLayout,
  968. 'db' => array (
  969. 'pass' => 'Int',
  970. ),
  971. )
  972. )
  973. );
  974. if($bInputsOnly)
  975. return $aForm['inputs'];
  976. $oForm = new BxTemplStudioFormView($aForm);
  977. $aTmplParams['form'] = $oForm->getCode();
  978. return $oTemplate->parseHtmlByName('bp_layouts.html', $aTmplParams);
  979. }
  980. protected function getSettingsLayoutFields($aPage = array(), $bCreate = true)
  981. {
  982. return $this->getSettingsLayout($aPage, $bCreate, true);
  983. }
  984. protected function getSettingsVisibility($aPage = array(), $bCreate = true, $bInputsOnly = false)
  985. {
  986. $iVisibleForLevels = isset($aPage['visible_for_levels']) ? (int)$aPage['visible_for_levels'] : BX_DOL_INT_MAX;
  987. if(isset($aPage['visible_for_levels_editable']) && (int)$aPage['visible_for_levels_editable'] == 0)
  988. $aInputs = array(
  989. 'visible_for_levels' => array(
  990. 'type' => 'custom',
  991. 'name' => 'visible_for_levels',
  992. 'content' => MsgBox(_t('_adm_bp_err_page_visible_for_levels'))
  993. )
  994. );
  995. else {
  996. bx_import('BxDolStudioUtils');
  997. $aInputs = array(
  998. 'visible_for' => array(
  999. 'type' => 'select',
  1000. 'name' => 'visible_for',
  1001. 'caption' => _t('_adm_bp_txt_block_visible_for'),
  1002. 'info' => '',
  1003. 'value' => $iVisibleForLevels == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
  1004. 'values' => array(
  1005. array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_bp_txt_block_visible_for_all')),
  1006. array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_bp_txt_block_visible_for_selected')),
  1007. ),
  1008. 'required' => '0',
  1009. 'attrs' => array(
  1010. 'onchange' => $this->getPageJsObject() . '.onChangeVisibleFor(this)'
  1011. ),
  1012. 'db' => array (
  1013. 'pass' => 'Xss',
  1014. )
  1015. ),
  1016. 'visible_for_levels' => array(
  1017. 'type' => 'checkbox_set',
  1018. 'name' => 'visible_for_levels',
  1019. 'caption' => _t('_adm_bp_txt_page_visible_for_levels'),
  1020. 'info' => _t('_adm_bp_dsc_page_visible_for_levels'),
  1021. 'value' => array(),
  1022. 'values' => array(),
  1023. 'tr_attrs' => array(
  1024. 'style' => $iVisibleForLevels == BX_DOL_INT_MAX ? 'display:none' : ''
  1025. ),
  1026. 'db' => array (
  1027. 'pass' => 'Int',
  1028. )
  1029. )
  1030. );
  1031. }
  1032. $aForm = array(
  1033. 'form_attrs' => array(
  1034. 'id' => 'adm-bp-settings-visibility',
  1035. ),
  1036. 'params' => array (
  1037. 'remove_form' => '1',
  1038. 'csrf' => array(
  1039. 'disable' => true
  1040. )
  1041. ),
  1042. 'inputs' => $aInputs
  1043. );
  1044. BxDolStudioUtils::getVisibilityValues($iVisibleForLevels, $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
  1045. if($bInputsOnly)
  1046. return $aForm['inputs'];
  1047. $oForm = new BxTemplStudioFormView($aForm);
  1048. return $oForm->getCode();
  1049. }
  1050. protected function getSettingsVisibilityFields($aPage = array(), $bCreate = true)
  1051. {
  1052. return $this->getSettingsVisibility($aPage, $bCreate, true);
  1053. }
  1054. protected function getSettingsCache($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1055. {
  1056. $aForm = array(
  1057. 'form_attrs' => array(
  1058. 'id' => 'adm-bp-settings-cache',
  1059. ),
  1060. 'params' => array (
  1061. 'remove_form' => '1',
  1062. 'csrf' => array(
  1063. 'disable' => true
  1064. )
  1065. ),
  1066. 'inputs' => array (
  1067. 'cache_lifetime' => array(
  1068. 'type' => 'text',
  1069. 'name' => 'cache_lifetime',
  1070. 'caption' => _t('_adm_bp_txt_page_cache_lifetime'),
  1071. 'info' => _t('_adm_bp_dsc_page_cache_lifetime'),
  1072. 'value' => isset($aPage['cache_lifetime']) ? $aPage['cache_lifetime'] : 0,
  1073. 'required' => '',
  1074. 'attrs' => array(
  1075. 'disabled' => isset($aPage['cache_editable']) && (int)$aPage['cache_editable'] == 0 ? 'disabled' : ''
  1076. ),
  1077. 'db' => array (
  1078. 'pass' => 'Int',
  1079. )
  1080. ),
  1081. )
  1082. );
  1083. if($bInputsOnly)
  1084. return $aForm['inputs'];
  1085. $oForm = new BxTemplStudioFormView($aForm);
  1086. return $oForm->getCode();
  1087. }
  1088. protected function getSettingsCacheFields($aPage = array(), $bCreate = true)
  1089. {
  1090. return $this->getSettingsCache($aPage, $bCreate, true);
  1091. }
  1092. protected function getSettingsSeo($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1093. {
  1094. $aForm = array(
  1095. 'form_attrs' => array(
  1096. 'id' => 'adm-bp-settings-seo',
  1097. ),
  1098. 'params' => array (
  1099. 'remove_form' => '1',
  1100. 'csrf' => array(
  1101. 'disable' => true
  1102. )
  1103. ),
  1104. 'inputs' => array (
  1105. 'meta_description' => array(
  1106. 'type' => 'textarea',
  1107. 'name' => 'meta_description',
  1108. 'caption' => _t('_adm_bp_txt_page_meta_description'),
  1109. 'info' => _t('_adm_bp_dsc_page_meta_description'),
  1110. 'value' => isset($aPage['meta_description']) ? $aPage['meta_description'] : '',
  1111. 'db' => array (
  1112. 'pass' => 'Xss',
  1113. ),
  1114. ),
  1115. 'meta_keywords' => array(
  1116. 'type' => 'textarea',
  1117. 'name' => 'meta_keywords',
  1118. 'caption' => _t('_adm_bp_txt_page_meta_keywords'),
  1119. 'info' => _t('_adm_bp_dsc_page_meta_keywords'),
  1120. 'value' => isset($aPage['meta_keywords']) ? $aPage['meta_keywords'] : '',
  1121. 'db' => array (
  1122. 'pass' => 'Xss',
  1123. ),
  1124. ),
  1125. 'meta_robots' => array(
  1126. 'type' => 'text',
  1127. 'name' => 'meta_robots',
  1128. 'caption' => _t('_adm_bp_txt_page_meta_robots'),
  1129. 'info' => _t('_adm_bp_dsc_page_meta_robots'),
  1130. 'value' => isset($aPage['meta_robots']) ? $aPage['meta_robots'] : '',
  1131. 'required' => '0',
  1132. 'db' => array (
  1133. 'pass' => 'Xss',
  1134. )
  1135. )
  1136. )
  1137. );
  1138. if($bInputsOnly)
  1139. return $aForm['inputs'];
  1140. $oForm = new BxTemplStudioFormView($aForm);
  1141. return $oForm->getCode();
  1142. }
  1143. protected function getSettingsSeoFields($aPage = array(), $bCreate = true)
  1144. {
  1145. return $this->getSettingsSeo($aPage, $bCreate, true);
  1146. }
  1147. protected function getBlockIcon($aBlock)
  1148. {
  1149. $sIcon = $sIconUrl = "";
  1150. $sResult = '';
  1151. switch($aBlock['type']) {
  1152. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1153. $sResult = 'far file-alt';
  1154. break;
  1155. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1156. $sResult = 'code';
  1157. break;
  1158. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1159. $sResult = 'rss';
  1160. break;
  1161. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1162. $sResult = 'far image';
  1163. break;
  1164. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1165. $sResult = 'globe';
  1166. break;
  1167. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1168. $sResult = 'list-alt';
  1169. break;
  1170. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1171. $sResult = $this->getModuleIcon($aBlock['module'], 'page');
  1172. break;
  1173. }
  1174. if(strpos($sResult, '.') === false)
  1175. $sIcon = $sResult;
  1176. else
  1177. $sIconUrl = $sResult;
  1178. return array($sIcon, $sIconUrl);
  1179. }
  1180. protected function getBlockModule($aBlock)
  1181. {
  1182. return $aBlock['module'] != BX_DOL_STUDIO_BP_SKELETONS ? $aBlock['module'] : BX_DOL_STUDIO_MODULE_CUSTOM;
  1183. }
  1184. protected function getBlockContent($aBlock)
  1185. {
  1186. $aFields = array();
  1187. switch($aBlock['type']) {
  1188. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1189. $aFields = array(
  1190. 'content' => array(
  1191. 'type' => 'textarea',
  1192. 'name' => 'content',
  1193. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1194. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1195. 'value' => $aBlock['content'],
  1196. 'required' => '0',
  1197. 'code' => 1,
  1198. 'attrs' => array('class' => 'bx-form-input-textarea-codemirror'),
  1199. 'db' => array (
  1200. 'pass' => 'XssHtml',
  1201. ),
  1202. ),
  1203. );
  1204. break;
  1205. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1206. $aFields = array(
  1207. 'content' => array(
  1208. 'type' => 'textarea',
  1209. 'name' => 'content',
  1210. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1211. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1212. 'value' => $aBlock['content'],
  1213. 'required' => '0',
  1214. 'html' => 2,
  1215. 'attrs' => array('id' => $this->aHtmlIds['edit_block_editor_id']),
  1216. 'db' => array (
  1217. 'pass' => 'XssHtml',
  1218. ),
  1219. ),
  1220. 'attachments' => array(
  1221. 'type' => 'files',
  1222. 'name' => 'attachments',
  1223. 'storage_object' => $this->sStorage,
  1224. 'images_transcoder' => $this->sTranscoder,
  1225. 'uploaders' => $this->aUploaders,
  1226. 'multiple' => true,
  1227. 'content_id' => $aBlock['id'],
  1228. 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('bp_fgt_attachments.html', array(
  1229. 'js_object' => $this->getPageJsObject(),
  1230. 'name' => 'attachments',
  1231. 'editor_id' => $this->aHtmlIds['edit_block_editor_id'],
  1232. )),
  1233. 'caption' => _t('_adm_bp_txt_block_content_attachments_html')
  1234. )
  1235. );
  1236. break;
  1237. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1238. $aFields = array(
  1239. 'content' => array(
  1240. 'type' => 'textarea_translatable',
  1241. 'name' => 'content',
  1242. 'caption' => _t('_adm_bp_txt_block_content_lang'),
  1243. 'info' => _t('_adm_bp_dsc_block_content_lang'),
  1244. 'value' => $aBlock['content'],
  1245. 'required' => '0',
  1246. 'html' => 0,
  1247. 'code' => 1,
  1248. 'db' => array (
  1249. 'pass' => 'XssHtml',
  1250. ),
  1251. ),
  1252. );
  1253. break;
  1254. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1255. $iImageId = $sImageAlign = '';
  1256. if($aBlock['content'] != '')
  1257. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1258. $aFields = array(
  1259. 'content' => array(
  1260. 'type' => 'hidden',
  1261. 'name' => 'content',
  1262. 'value' => '',
  1263. 'db' => array (
  1264. 'pass' => 'Xss',
  1265. ),
  1266. ),
  1267. 'image_file' => array(
  1268. 'type' => 'image_uploader',
  1269. 'name' => 'image_file',
  1270. 'caption' => _t('_adm_bp_txt_block_content_image_file'),
  1271. 'caption_preview' => _t('_adm_bp_txt_block_content_image_preview'),
  1272. 'info' => _t('_adm_bp_dsc_block_content_image_file'),
  1273. 'ajax_action_delete' => $this->getPageJsObject() . '.deleteBlockImage(' . $aBlock['id'] . ')',
  1274. 'value' => (int)$iImageId
  1275. ),
  1276. 'image_align' => array(
  1277. 'type' => 'select',
  1278. 'name' => 'image_align',
  1279. 'caption' => _t('_adm_bp_txt_block_content_image_align'),
  1280. 'info' => '',
  1281. 'value' => $sImageAlign,
  1282. 'values' => array(
  1283. array('key' => '', 'value' => _t('_adm_bp_txt_block_content_image_align_empty')),
  1284. array('key' => 'left', 'value' => _t('_adm_bp_txt_block_content_image_align_left')),
  1285. array('key' => 'center', 'value' => _t('_adm_bp_txt_block_content_image_align_center')),
  1286. array('key' => 'right', 'value' => _t('_adm_bp_txt_block_content_image_align_right')),
  1287. ),
  1288. 'required' => '0',
  1289. 'db' => array (
  1290. 'pass' => 'Xss',
  1291. ),
  1292. ),
  1293. );
  1294. break;
  1295. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1296. $sRssUrl = $sRssLength = '';
  1297. if($aBlock['content'] != '')
  1298. list($sRssUrl, $sRssLength) = explode($this->sParamsDivider, $aBlock['content']);
  1299. $aFields = array(
  1300. 'content' => array(
  1301. 'type' => 'hidden',
  1302. 'name' => 'content',
  1303. 'value' => '',
  1304. 'db' => array (
  1305. 'pass' => 'Xss',
  1306. ),
  1307. ),
  1308. 'rss_url' => array(
  1309. 'type' => 'text',
  1310. 'name' => 'rss_url',
  1311. 'caption' => _t('_adm_bp_txt_block_content_rss_url'),
  1312. 'info' => _t('_adm_bp_dsc_block_content_rss_url'),
  1313. 'value' => $sRssUrl,
  1314. 'required' => '0',
  1315. 'db' => array (
  1316. 'pass' => 'Xss',
  1317. ),
  1318. ),
  1319. 'rss_length' => array(
  1320. 'type' => 'text',
  1321. 'name' => 'rss_length',
  1322. 'caption' => _t('_adm_bp_txt_block_content_rss_length'),
  1323. 'info' => _t('_adm_bp_dsc_block_content_rss_length'),
  1324. 'value' => $sRssLength,
  1325. 'required' => '0',
  1326. 'db' => array (
  1327. 'pass' => 'Int',
  1328. ),
  1329. ),
  1330. );
  1331. break;
  1332. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1333. $aFields = array(
  1334. 'content' => array(
  1335. 'type' => 'select',
  1336. 'name' => 'content',
  1337. 'caption' => _t('_adm_bp_txt_block_content_menu'),
  1338. 'info' => '',
  1339. 'value' => $aBlock['content'],
  1340. 'values' => array(),
  1341. 'required' => '0',
  1342. 'db' => array (
  1343. 'pass' => 'Xss',
  1344. ),
  1345. )
  1346. );
  1347. $aMenus = $this->oDb->getMenus();
  1348. foreach($aMenus as $sKey => $sValue)
  1349. $aFields['content']['values'][$sKey] = _t($sValue);
  1350. asort($aFields['content']['values']);
  1351. $aFields['content']['values'] = array_merge(array('' => _t('_adm_bp_txt_block_content_menu_empty')), $aFields['content']['values']);
  1352. break;
  1353. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1354. $aService = array('module' => '', 'method' => '');
  1355. if($aBlock['content'] != '')
  1356. $aService = unserialize($aBlock['content']);
  1357. $aFields = array(
  1358. 'service_module' => array(
  1359. 'type' => 'value',
  1360. 'name' => 'service_module',
  1361. 'caption' => _t('_adm_bp_txt_block_content_service_module'),
  1362. 'value' => $this->getModuleTitle($aService['module'])
  1363. ),
  1364. 'service_method' => array(
  1365. 'type' => 'value',
  1366. 'name' => 'service_method',
  1367. 'caption' => _t('_adm_bp_txt_block_content_service_method'),
  1368. 'value' => $aService['method']
  1369. )
  1370. );
  1371. break;
  1372. }
  1373. return $aFields;
  1374. }
  1375. protected function getBlockList($sModule)
  1376. {
  1377. if(empty($sModule))
  1378. return '';
  1379. $sJsObject = $this->getPageJsObject();
  1380. $oTemplate = BxDolStudioTemplate::getInstance();
  1381. $oForm = new BxTemplStudioFormView(array());
  1382. $aInputCheckbox = array(
  1383. 'type' => 'checkbox',
  1384. 'name' => 'blocks[]',
  1385. 'attrs' => array(
  1386. 'onChange' => 'javascript:' . $sJsObject . '.onSelectBlock(this);'
  1387. ),
  1388. 'value' => ''
  1389. );
  1390. $aTmplParams = array(
  1391. 'html_block_list_id' => $this->aHtmlIds['block_list_id'] . $sModule,
  1392. 'bx_repeat:blocks' => array()
  1393. );
  1394. $aBlocks = $this->getBlocks($sModule);
  1395. foreach($aBlocks as $aBlock) {
  1396. list($sIcon, $sIconUrl) = $this->getBlockIcon($aBlock);
  1397. $aInputCheckbox['value'] = $aBlock['id'];
  1398. $aTmplParams['bx_repeat:blocks'][] = array(
  1399. 'js_object' => $sJsObject,
  1400. 'html_id' => $this->aHtmlIds['block_id'] . $aBlock['id'],
  1401. 'bx_if:is_inactive' => array(
  1402. 'condition' => false,
  1403. 'content' => array()
  1404. ),
  1405. 'bx_if:show_link' => array(
  1406. 'condition' => false,
  1407. 'content' => array()
  1408. ),
  1409. 'bx_if:show_text' => array(
  1410. 'condition' => true,
  1411. 'content' => array(
  1412. 'title' => _t(!empty($aBlock['title_system']) ? $aBlock['title_system'] : $aBlock['title']),
  1413. )
  1414. ),
  1415. 'bx_if:image' => array (
  1416. 'condition' => (bool)$sIconUrl,
  1417. 'content' => array('icon_url' => $sIconUrl),
  1418. ),
  1419. 'bx_if:icon' => array (
  1420. 'condition' => (bool)$sIcon,
  1421. 'content' => array('icon' => $sIcon),
  1422. ),
  1423. 'module' => $this->getModuleTitle($aBlock['module']),
  1424. 'visible_for' => _t('_adm_bp_txt_visible_for', BxDolStudioUtils::getVisibilityTitle($aBlock['visible_for_levels'])),
  1425. 'bx_if:show_checkbox' => array(
  1426. 'condition' => true,
  1427. 'content' => array(
  1428. 'content' => $oForm->genRow($aInputCheckbox)
  1429. )
  1430. ),
  1431. 'bx_if:show_drag_handle' => array(
  1432. 'condition' => false,
  1433. 'content' => array()
  1434. )
  1435. );
  1436. }
  1437. return $oTemplate->parseHtmlByName('bp_blocks_list.html', $aTmplParams);
  1438. }
  1439. protected function onBlockDelete($aBlock)
  1440. {
  1441. if($aBlock['module'] != BX_DOL_STUDIO_MODULE_CUSTOM)
  1442. return;
  1443. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['title']);
  1444. //--- Process Lang block
  1445. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && $aBlock['content'] != '')
  1446. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['content']);
  1447. //--- Process Image block
  1448. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && $aBlock['content'] != '') {
  1449. $iImageId = $sImageAlign = '';
  1450. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1451. if(is_numeric($iImageId) && (int)$iImageId != 0)
  1452. BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$iImageId, 0);
  1453. }
  1454. }
  1455. protected function getBlocks($sModule)
  1456. {
  1457. $aBlocks = array();
  1458. $this->oDb->getBlocks(array('type' => 'by_module_to_copy', 'value' => $sModule), $aBlocks, false);
  1459. return $aBlocks;
  1460. }
  1461. protected function _getTmplVarsBlockPanelTop()
  1462. {
  1463. $sJsObject = $this->getPageJsObject();
  1464. $oForm = new BxTemplStudioFormView(array());
  1465. $aInputPages = array(
  1466. 'type' => 'select',
  1467. 'name' => 'page',
  1468. 'attrs' => array(
  1469. 'onChange' => 'javascript:' . $this->getPageJsObject() . '.onChangePage(this)'
  1470. ),
  1471. 'value' => $this->sPage,
  1472. 'values' => array(
  1473. array('key' => '', 'value' => _t('_adm_bp_txt_select_page'))
  1474. )
  1475. );
  1476. $aPages = $aCounter = array();
  1477. $this->oDb->getPages(array('type' => 'by_module', 'value' => $this->sType), $aPages, false);
  1478. $this->oDb->getBlocks(array('type' => 'counter_by_pages'), $aCounter, false);
  1479. foreach($aPages as $aPage)
  1480. $aInputPages['values'][] = array('key' => $aPage['object'], 'value' => _t($aPage['title_system']) . " (" . (isset($aCounter[$aPage['object']]) ? $aCounter[$aPage['object']] : "0") . ")");
  1481. $aTmplVarsActions = array();
  1482. if(($this->sPage != '' && !empty($this->aPageRebuild)) !== false)
  1483. $aTmplVarsActions = $this->_getTmplVarsBlockPanelTopActions();
  1484. return array(
  1485. 'js_object' => $this->getPageJsObject(),
  1486. 'selector' => $oForm->genRow($aInputPages),
  1487. 'action_page_create' => $this->sActionPageCreate,
  1488. 'bx_if:show_actions' => array(
  1489. 'condition' => $this->sPage != '',
  1490. 'content' => $aTmplVarsActions
  1491. )
  1492. );
  1493. }
  1494. protected function _getTmplVarsBlockPanelTopActions()
  1495. {
  1496. $sJsObject = $this->getPageJsObject();
  1497. $oPermalinks = BxDolPermalinks::getInstance();
  1498. return array(
  1499. 'js_object' => $sJsObject,
  1500. 'url_view' => BX_DOL_URL_ROOT . $oPermalinks->permalink($this->aPageRebuild['url']),
  1501. 'action_page_edit' => $this->sActionPageEdit,
  1502. 'bx_if:can_delete' => array(
  1503. 'condition' => (int)$this->aPageRebuild['deletable'] == 1,
  1504. 'content' => array(
  1505. 'js_object' => $sJsObject
  1506. )
  1507. ),
  1508. 'action_block_create' => $this->sActionBlockCreate,
  1509. );
  1510. }
  1511. protected function _getTmplVarsPageSettings($aPage = array(), $bCreate = true)
  1512. {
  1513. $sJsObject = $this->getPageJsObject();
  1514. $aTmplParams = array(
  1515. 'js_object' => $sJsObject,
  1516. 'menu' => array(),
  1517. 'html_settings_groups_id' => $this->aHtmlIds['settings_groups_id'],
  1518. 'bx_repeat:settings_groups' => array(),
  1519. 'submit' => _t($bCreate ? '_adm_bp_btn_page_create' : '_adm_bp_btn_page_apply')
  1520. );
  1521. foreach($this->aPageSettings as $aSetting) {
  1522. //--- get menu items
  1523. $aTmplParams['menu'][$aSetting['name']] = array(
  1524. 'name' => $aSetting['name'],
  1525. 'icon' => '',
  1526. 'onclick' => $sJsObject . '.onChangeSettingGroup(\'' . $aSetting['name'] . '\', this);',
  1527. 'title' => $aSetting['title'],
  1528. 'selected' => isset($aSetting['active']) && (int)$aSetting['active'] == 1
  1529. );
  1530. //--- get settings
  1531. $aTmplParams['bx_repeat:settings_groups'][] = array(
  1532. 'html_settings_group_id' => $this->aHtmlIds['settings_group_id'] . $aSetting['name'],
  1533. 'bx_if:hidden' => array(
  1534. 'condition' => $aSetting['active'] != 1,
  1535. 'content' => array()
  1536. ),
  1537. 'content' => $this->{'getSettings' . $this->getClassName($aSetting['name'])}($aPage, $bCreate)
  1538. );
  1539. }
  1540. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aTmplParams['menu']));
  1541. $aTmplParams['menu'] = $oMenu->getCode();
  1542. return $aTmplParams;
  1543. }
  1544. }
  1545. /** @} */