BxBaseStudioBuilderPage.php 67 KB

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