BxBaseStudioBuilderPage.php 66 KB

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