BxBaseStudioBuilderPage.php 62 KB

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