BxBaseStudioBuilderPage.php 66 KB

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