BxBaseStudioBuilderPage.php 63 KB

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