BxBaseStudioBuilderPage.php 66 KB

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