BxBaseStudioBuilderPage.php 62 KB

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