BxBaseStudioBuilderPage.php 63 KB

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