BxBaseStudioBuilderPage.php 63 KB

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