BxBaseStudioBuilderPage.php 63 KB

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