BxBaseStudioBuilderPage.php 62 KB

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