BxBaseStudioBuilderPage.php 63 KB

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