BxBaseStudioBuilderPage.php 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749
  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' => 'type', 'value' => array(BX_DOL_MODULE_TYPE_MODULE, BX_DOL_MODULE_TYPE_TEMPLATE)));
  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. 'type_id' => array(
  813. 'type' => 'select',
  814. 'name' => 'type_id',
  815. 'caption' => _t('_adm_bp_txt_page_type_id'),
  816. 'info' => _t('_adm_bp_dsc_page_type_id'),
  817. 'value' => isset($aPage['type_id']) ? $aPage['type_id'] : '',
  818. 'required' => '1',
  819. 'db' => array (
  820. 'pass' => 'Int',
  821. ),
  822. ),
  823. )
  824. );
  825. $aTypes = array();
  826. $this->oDb->getTypes(array('type' => 'all'), $aTypes, false);
  827. foreach($aTypes as $aType)
  828. $aForm['inputs']['type_id']['values'][] = array('key' => $aType['id'], 'value' => _t($aType['title']));
  829. if($bCreate) {
  830. $sJsObject = $this->getPageJsObject();
  831. $aForm['inputs']['title']['attrs']['onblur'] = $sJsObject . '.getUri(this);';
  832. $aForm['inputs'] = bx_array_insert_before(array(
  833. 'uri' => array(
  834. 'type' => 'text',
  835. 'name' => 'uri',
  836. 'caption' => _t('_adm_bp_txt_page_uri'),
  837. 'info' => _t('_adm_bp_dsc_page_uri'),
  838. 'value' => '',
  839. 'required' => '1',
  840. 'attrs' => array(
  841. 'id' => $this->aHtmlIds['uri_field_id'],
  842. 'onblur' => $sJsObject . '.getUri(this);'
  843. ),
  844. 'db' => array (
  845. 'pass' => 'Xss',
  846. ),
  847. 'checker' => array (
  848. 'func' => 'length',
  849. 'params' => array(3,100),
  850. 'error' => _t('_adm_bp_err_page_uri'),
  851. ),
  852. )
  853. ), $aForm['inputs'], 'url');
  854. }
  855. if($bInputsOnly)
  856. return $aForm['inputs'];
  857. $oForm = new BxTemplStudioFormView($aForm);
  858. return $oForm->getCode();
  859. }
  860. protected function getSettingsOptionsFields($aPage = array(), $bCreate = true)
  861. {
  862. return $this->getSettingsOptions($aPage, $bCreate, true);
  863. }
  864. protected function getSettingsCover($aPage = array(), $bCreate = true, $bInputsOnly = false)
  865. {
  866. $aForm = array(
  867. 'form_attrs' => array(
  868. 'id' => 'adm-bp-settings-cover',
  869. ),
  870. 'params' => array (
  871. 'remove_form' => '1',
  872. 'csrf' => array(
  873. 'disable' => true
  874. )
  875. ),
  876. 'inputs' => array (
  877. 'cover' => array(
  878. 'type' => 'switcher',
  879. 'name' => 'cover',
  880. 'caption' => _t('_adm_bp_txt_page_cover'),
  881. 'info' => '',
  882. 'value' => '1',
  883. 'checked' => isset($aPage['cover']) && $aPage['cover'] == '1',
  884. 'db' => array (
  885. 'pass' => 'Int',
  886. )
  887. ),
  888. 'cover_image' => array(
  889. 'type' => 'files',
  890. 'name' => 'cover_image',
  891. 'storage_object' => $this->sStorage,
  892. 'images_transcoder' => $this->sTranscoderCover,
  893. 'uploaders' => $this->aUploadersCover,
  894. 'multiple' => false,
  895. 'content_id' => isset($aPage['id']) ? $aPage['id'] : 0,
  896. 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('uploader_fgt_cover.html', array(
  897. 'name' => 'cover_image',
  898. )),
  899. 'caption' => _t('_adm_bp_txt_page_cover_image'),
  900. 'db' => array (
  901. 'pass' => 'Int',
  902. )
  903. )
  904. )
  905. );
  906. if($bInputsOnly)
  907. return $aForm['inputs'];
  908. $oForm = new BxTemplStudioFormView($aForm);
  909. return $oForm->getCode();
  910. }
  911. protected function getSettingsCoverFields($aPage = array(), $bCreate = true)
  912. {
  913. return $this->getSettingsCover($aPage, $bCreate, true);
  914. }
  915. protected function getSettingsLayout($aPage = array(), $bCreate = true, $bInputsOnly = false)
  916. {
  917. $sJsObject = $this->getPageJsObject();
  918. $oTemplate = BxDolStudioTemplate::getInstance();
  919. $iLayout = isset($aPage['layout_id']) ? (int)$aPage['layout_id'] : 5;
  920. $aLayouts = array();
  921. $this->oDb->getLayouts(array('type' => 'all'), $aLayouts, false);
  922. $aTmplParams = array(
  923. 'bx_repeat:layouts' => array(),
  924. 'form' => ''
  925. );
  926. foreach($aLayouts as $aLayout)
  927. $aTmplParams['bx_repeat:layouts'][] = array(
  928. 'id' => $aLayout['id'],
  929. 'html_id' => $this->aHtmlIds['layout_id'] . $aLayout['id'],
  930. 'js_object' => $sJsObject,
  931. 'bx_if:active' => array(
  932. 'condition' => (int)$aLayout['id'] == $iLayout,
  933. 'content' => array()
  934. ),
  935. 'icon' => $oTemplate->getImageUrl($aLayout['icon']),
  936. 'title' => _t($aLayout['title']),
  937. );
  938. $aForm = array(
  939. 'form_attrs' => array(
  940. 'id' => 'adm-bp-settings-layout',
  941. ),
  942. 'params' => array (
  943. 'remove_form' => '1',
  944. 'csrf' => array(
  945. 'disable' => true
  946. )
  947. ),
  948. 'inputs' => array (
  949. 'layout_id' => array(
  950. 'type' => 'hidden',
  951. 'name' => 'layout_id',
  952. 'value' => $iLayout,
  953. 'db' => array (
  954. 'pass' => 'Int',
  955. ),
  956. )
  957. )
  958. );
  959. if($bInputsOnly)
  960. return $aForm['inputs'];
  961. $oForm = new BxTemplStudioFormView($aForm);
  962. $aTmplParams['form'] = $oForm->getCode();
  963. return $oTemplate->parseHtmlByName('bp_layouts.html', $aTmplParams);
  964. }
  965. protected function getSettingsLayoutFields($aPage = array(), $bCreate = true)
  966. {
  967. return $this->getSettingsLayout($aPage, $bCreate, true);
  968. }
  969. protected function getSettingsVisibility($aPage = array(), $bCreate = true, $bInputsOnly = false)
  970. {
  971. $iVisibleForLevels = isset($aPage['visible_for_levels']) ? (int)$aPage['visible_for_levels'] : BX_DOL_INT_MAX;
  972. if(isset($aPage['visible_for_levels_editable']) && (int)$aPage['visible_for_levels_editable'] == 0)
  973. $aInputs = array(
  974. 'visible_for_levels' => array(
  975. 'type' => 'custom',
  976. 'name' => 'visible_for_levels',
  977. 'content' => MsgBox(_t('_adm_bp_err_page_visible_for_levels'))
  978. )
  979. );
  980. else {
  981. bx_import('BxDolStudioUtils');
  982. $aInputs = array(
  983. 'visible_for' => array(
  984. 'type' => 'select',
  985. 'name' => 'visible_for',
  986. 'caption' => _t('_adm_bp_txt_block_visible_for'),
  987. 'info' => '',
  988. 'value' => $iVisibleForLevels == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
  989. 'values' => array(
  990. array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_bp_txt_block_visible_for_all')),
  991. array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_bp_txt_block_visible_for_selected')),
  992. ),
  993. 'required' => '0',
  994. 'attrs' => array(
  995. 'onchange' => $this->getPageJsObject() . '.onChangeVisibleFor(this)'
  996. ),
  997. 'db' => array (
  998. 'pass' => 'Xss',
  999. )
  1000. ),
  1001. 'visible_for_levels' => array(
  1002. 'type' => 'checkbox_set',
  1003. 'name' => 'visible_for_levels',
  1004. 'caption' => _t('_adm_bp_txt_page_visible_for_levels'),
  1005. 'info' => _t('_adm_bp_dsc_page_visible_for_levels'),
  1006. 'value' => array(),
  1007. 'values' => array(),
  1008. 'tr_attrs' => array(
  1009. 'style' => $iVisibleForLevels == BX_DOL_INT_MAX ? 'display:none' : ''
  1010. ),
  1011. 'db' => array (
  1012. 'pass' => 'Int',
  1013. )
  1014. )
  1015. );
  1016. }
  1017. $aForm = array(
  1018. 'form_attrs' => array(
  1019. 'id' => 'adm-bp-settings-visibility',
  1020. ),
  1021. 'params' => array (
  1022. 'remove_form' => '1',
  1023. 'csrf' => array(
  1024. 'disable' => true
  1025. )
  1026. ),
  1027. 'inputs' => $aInputs
  1028. );
  1029. BxDolStudioUtils::getVisibilityValues($iVisibleForLevels, $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
  1030. if($bInputsOnly)
  1031. return $aForm['inputs'];
  1032. $oForm = new BxTemplStudioFormView($aForm);
  1033. return $oForm->getCode();
  1034. }
  1035. protected function getSettingsVisibilityFields($aPage = array(), $bCreate = true)
  1036. {
  1037. return $this->getSettingsVisibility($aPage, $bCreate, true);
  1038. }
  1039. protected function getSettingsCache($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1040. {
  1041. $aForm = array(
  1042. 'form_attrs' => array(
  1043. 'id' => 'adm-bp-settings-cache',
  1044. ),
  1045. 'params' => array (
  1046. 'remove_form' => '1',
  1047. 'csrf' => array(
  1048. 'disable' => true
  1049. )
  1050. ),
  1051. 'inputs' => array (
  1052. 'cache_lifetime' => array(
  1053. 'type' => 'text',
  1054. 'name' => 'cache_lifetime',
  1055. 'caption' => _t('_adm_bp_txt_page_cache_lifetime'),
  1056. 'info' => _t('_adm_bp_dsc_page_cache_lifetime'),
  1057. 'value' => isset($aPage['cache_lifetime']) ? $aPage['cache_lifetime'] : 0,
  1058. 'required' => '',
  1059. 'attrs' => array(
  1060. 'disabled' => isset($aPage['cache_editable']) && (int)$aPage['cache_editable'] == 0 ? 'disabled' : ''
  1061. ),
  1062. 'db' => array (
  1063. 'pass' => 'Int',
  1064. )
  1065. ),
  1066. )
  1067. );
  1068. if($bInputsOnly)
  1069. return $aForm['inputs'];
  1070. $oForm = new BxTemplStudioFormView($aForm);
  1071. return $oForm->getCode();
  1072. }
  1073. protected function getSettingsCacheFields($aPage = array(), $bCreate = true)
  1074. {
  1075. return $this->getSettingsCache($aPage, $bCreate, true);
  1076. }
  1077. protected function getSettingsSeo($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1078. {
  1079. $aForm = array(
  1080. 'form_attrs' => array(
  1081. 'id' => 'adm-bp-settings-seo',
  1082. ),
  1083. 'params' => array (
  1084. 'remove_form' => '1',
  1085. 'csrf' => array(
  1086. 'disable' => true
  1087. )
  1088. ),
  1089. 'inputs' => array (
  1090. 'meta_description' => array(
  1091. 'type' => 'textarea',
  1092. 'name' => 'meta_description',
  1093. 'caption' => _t('_adm_bp_txt_page_meta_description'),
  1094. 'info' => _t('_adm_bp_dsc_page_meta_description'),
  1095. 'value' => isset($aPage['meta_description']) ? $aPage['meta_description'] : '',
  1096. 'db' => array (
  1097. 'pass' => 'Xss',
  1098. ),
  1099. ),
  1100. 'meta_keywords' => array(
  1101. 'type' => 'textarea',
  1102. 'name' => 'meta_keywords',
  1103. 'caption' => _t('_adm_bp_txt_page_meta_keywords'),
  1104. 'info' => _t('_adm_bp_dsc_page_meta_keywords'),
  1105. 'value' => isset($aPage['meta_keywords']) ? $aPage['meta_keywords'] : '',
  1106. 'db' => array (
  1107. 'pass' => 'Xss',
  1108. ),
  1109. ),
  1110. 'meta_robots' => array(
  1111. 'type' => 'text',
  1112. 'name' => 'meta_robots',
  1113. 'caption' => _t('_adm_bp_txt_page_meta_robots'),
  1114. 'info' => _t('_adm_bp_dsc_page_meta_robots'),
  1115. 'value' => isset($aPage['meta_robots']) ? $aPage['meta_robots'] : '',
  1116. 'required' => '0',
  1117. 'db' => array (
  1118. 'pass' => 'Xss',
  1119. )
  1120. )
  1121. )
  1122. );
  1123. if($bInputsOnly)
  1124. return $aForm['inputs'];
  1125. $oForm = new BxTemplStudioFormView($aForm);
  1126. return $oForm->getCode();
  1127. }
  1128. protected function getSettingsSeoFields($aPage = array(), $bCreate = true)
  1129. {
  1130. return $this->getSettingsSeo($aPage, $bCreate, true);
  1131. }
  1132. protected function getBlockIcon($aBlock)
  1133. {
  1134. $sIcon = $sIconUrl = "";
  1135. $sResult = '';
  1136. switch($aBlock['type']) {
  1137. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1138. $sResult = 'far file-alt';
  1139. break;
  1140. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1141. $sResult = 'code';
  1142. break;
  1143. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1144. $sResult = 'rss';
  1145. break;
  1146. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1147. $sResult = 'far image';
  1148. break;
  1149. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1150. $sResult = 'globe';
  1151. break;
  1152. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1153. $sResult = 'list-alt';
  1154. break;
  1155. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1156. $sResult = $this->getModuleIcon($aBlock['module'], 'page');
  1157. break;
  1158. }
  1159. if(strpos($sResult, '.') === false)
  1160. $sIcon = $sResult;
  1161. else
  1162. $sIconUrl = $sResult;
  1163. return array($sIcon, $sIconUrl);
  1164. }
  1165. protected function getBlockModule($aBlock)
  1166. {
  1167. return $aBlock['module'] != BX_DOL_STUDIO_BP_SKELETONS ? $aBlock['module'] : BX_DOL_STUDIO_MODULE_CUSTOM;
  1168. }
  1169. protected function getBlockContent($aBlock)
  1170. {
  1171. $aFields = array();
  1172. switch($aBlock['type']) {
  1173. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1174. $aFields = array(
  1175. 'content' => array(
  1176. 'type' => 'textarea',
  1177. 'name' => 'content',
  1178. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1179. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1180. 'value' => $aBlock['content'],
  1181. 'required' => '0',
  1182. 'code' => 1,
  1183. 'attrs' => array('class' => 'bx-form-input-textarea-codemirror'),
  1184. 'db' => array (
  1185. 'pass' => 'XssHtml',
  1186. ),
  1187. ),
  1188. );
  1189. break;
  1190. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1191. $aFields = array(
  1192. 'content' => array(
  1193. 'type' => 'textarea',
  1194. 'name' => 'content',
  1195. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1196. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1197. 'value' => $aBlock['content'],
  1198. 'required' => '0',
  1199. 'html' => 2,
  1200. 'attrs' => array('id' => $this->aHtmlIds['edit_block_editor_id']),
  1201. 'db' => array (
  1202. 'pass' => 'XssHtml',
  1203. ),
  1204. ),
  1205. 'attachments' => array(
  1206. 'type' => 'files',
  1207. 'name' => 'attachments',
  1208. 'storage_object' => $this->sStorage,
  1209. 'images_transcoder' => $this->sTranscoder,
  1210. 'uploaders' => $this->aUploaders,
  1211. 'multiple' => true,
  1212. 'content_id' => $aBlock['id'],
  1213. 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('bp_fgt_attachments.html', array(
  1214. 'js_object' => $this->getPageJsObject(),
  1215. 'name' => 'attachments',
  1216. 'editor_id' => $this->aHtmlIds['edit_block_editor_id'],
  1217. )),
  1218. 'caption' => _t('_adm_bp_txt_block_content_attachments_html')
  1219. )
  1220. );
  1221. break;
  1222. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1223. $aFields = array(
  1224. 'content' => array(
  1225. 'type' => 'textarea_translatable',
  1226. 'name' => 'content',
  1227. 'caption' => _t('_adm_bp_txt_block_content_lang'),
  1228. 'info' => _t('_adm_bp_dsc_block_content_lang'),
  1229. 'value' => $aBlock['content'],
  1230. 'required' => '0',
  1231. 'html' => 0,
  1232. 'code' => 1,
  1233. 'db' => array (
  1234. 'pass' => 'XssHtml',
  1235. ),
  1236. ),
  1237. );
  1238. break;
  1239. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1240. $iImageId = $sImageAlign = '';
  1241. if($aBlock['content'] != '')
  1242. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1243. $aFields = array(
  1244. 'content' => array(
  1245. 'type' => 'hidden',
  1246. 'name' => 'content',
  1247. 'value' => '',
  1248. 'db' => array (
  1249. 'pass' => 'Xss',
  1250. ),
  1251. ),
  1252. 'image_file' => array(
  1253. 'type' => 'image_uploader',
  1254. 'name' => 'image_file',
  1255. 'caption' => _t('_adm_bp_txt_block_content_image_file'),
  1256. 'caption_preview' => _t('_adm_bp_txt_block_content_image_preview'),
  1257. 'info' => _t('_adm_bp_dsc_block_content_image_file'),
  1258. 'ajax_action_delete' => $this->getPageJsObject() . '.deleteBlockImage(' . $aBlock['id'] . ')',
  1259. 'value' => (int)$iImageId
  1260. ),
  1261. 'image_align' => array(
  1262. 'type' => 'select',
  1263. 'name' => 'image_align',
  1264. 'caption' => _t('_adm_bp_txt_block_content_image_align'),
  1265. 'info' => '',
  1266. 'value' => $sImageAlign,
  1267. 'values' => array(
  1268. array('key' => '', 'value' => _t('_adm_bp_txt_block_content_image_align_empty')),
  1269. array('key' => 'left', 'value' => _t('_adm_bp_txt_block_content_image_align_left')),
  1270. array('key' => 'center', 'value' => _t('_adm_bp_txt_block_content_image_align_center')),
  1271. array('key' => 'right', 'value' => _t('_adm_bp_txt_block_content_image_align_right')),
  1272. ),
  1273. 'required' => '0',
  1274. 'db' => array (
  1275. 'pass' => 'Xss',
  1276. ),
  1277. ),
  1278. );
  1279. break;
  1280. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1281. $sRssUrl = $sRssLength = '';
  1282. if($aBlock['content'] != '')
  1283. list($sRssUrl, $sRssLength) = explode($this->sParamsDivider, $aBlock['content']);
  1284. $aFields = array(
  1285. 'content' => array(
  1286. 'type' => 'hidden',
  1287. 'name' => 'content',
  1288. 'value' => '',
  1289. 'db' => array (
  1290. 'pass' => 'Xss',
  1291. ),
  1292. ),
  1293. 'rss_url' => array(
  1294. 'type' => 'text',
  1295. 'name' => 'rss_url',
  1296. 'caption' => _t('_adm_bp_txt_block_content_rss_url'),
  1297. 'info' => _t('_adm_bp_dsc_block_content_rss_url'),
  1298. 'value' => $sRssUrl,
  1299. 'required' => '0',
  1300. 'db' => array (
  1301. 'pass' => 'Xss',
  1302. ),
  1303. ),
  1304. 'rss_length' => array(
  1305. 'type' => 'text',
  1306. 'name' => 'rss_length',
  1307. 'caption' => _t('_adm_bp_txt_block_content_rss_length'),
  1308. 'info' => _t('_adm_bp_dsc_block_content_rss_length'),
  1309. 'value' => $sRssLength,
  1310. 'required' => '0',
  1311. 'db' => array (
  1312. 'pass' => 'Int',
  1313. ),
  1314. ),
  1315. );
  1316. break;
  1317. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1318. $aFields = array(
  1319. 'content' => array(
  1320. 'type' => 'select',
  1321. 'name' => 'content',
  1322. 'caption' => _t('_adm_bp_txt_block_content_menu'),
  1323. 'info' => '',
  1324. 'value' => $aBlock['content'],
  1325. 'values' => array(),
  1326. 'required' => '0',
  1327. 'db' => array (
  1328. 'pass' => 'Xss',
  1329. ),
  1330. )
  1331. );
  1332. $aMenus = $this->oDb->getMenus();
  1333. foreach($aMenus as $sKey => $sValue)
  1334. $aFields['content']['values'][$sKey] = _t($sValue);
  1335. asort($aFields['content']['values']);
  1336. $aFields['content']['values'] = array_merge(array('' => _t('_adm_bp_txt_block_content_menu_empty')), $aFields['content']['values']);
  1337. break;
  1338. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1339. $aService = array('module' => '', 'method' => '');
  1340. if($aBlock['content'] != '')
  1341. $aService = unserialize($aBlock['content']);
  1342. $aFields = array(
  1343. 'service_module' => array(
  1344. 'type' => 'value',
  1345. 'name' => 'service_module',
  1346. 'caption' => _t('_adm_bp_txt_block_content_service_module'),
  1347. 'value' => $this->getModuleTitle($aService['module'])
  1348. ),
  1349. 'service_method' => array(
  1350. 'type' => 'value',
  1351. 'name' => 'service_method',
  1352. 'caption' => _t('_adm_bp_txt_block_content_service_method'),
  1353. 'value' => $aService['method']
  1354. )
  1355. );
  1356. break;
  1357. }
  1358. return $aFields;
  1359. }
  1360. protected function getBlockList($sModule)
  1361. {
  1362. if(empty($sModule))
  1363. return '';
  1364. $sJsObject = $this->getPageJsObject();
  1365. $oTemplate = BxDolStudioTemplate::getInstance();
  1366. $oForm = new BxTemplStudioFormView(array());
  1367. $aInputCheckbox = array(
  1368. 'type' => 'checkbox',
  1369. 'name' => 'blocks[]',
  1370. 'attrs' => array(
  1371. 'onChange' => 'javascript:' . $sJsObject . '.onSelectBlock(this);'
  1372. ),
  1373. 'value' => ''
  1374. );
  1375. $aTmplParams = array(
  1376. 'html_block_list_id' => $this->aHtmlIds['block_list_id'] . $sModule,
  1377. 'bx_repeat:blocks' => array()
  1378. );
  1379. $aBlocks = $this->getBlocks($sModule);
  1380. foreach($aBlocks as $aBlock) {
  1381. list($sIcon, $sIconUrl) = $this->getBlockIcon($aBlock);
  1382. $aInputCheckbox['value'] = $aBlock['id'];
  1383. $aTmplParams['bx_repeat:blocks'][] = array(
  1384. 'js_object' => $sJsObject,
  1385. 'html_id' => $this->aHtmlIds['block_id'] . $aBlock['id'],
  1386. 'bx_if:is_inactive' => array(
  1387. 'condition' => false,
  1388. 'content' => array()
  1389. ),
  1390. 'bx_if:show_link' => array(
  1391. 'condition' => false,
  1392. 'content' => array()
  1393. ),
  1394. 'bx_if:show_text' => array(
  1395. 'condition' => true,
  1396. 'content' => array(
  1397. 'title' => _t(!empty($aBlock['title_system']) ? $aBlock['title_system'] : $aBlock['title']),
  1398. )
  1399. ),
  1400. 'bx_if:image' => array (
  1401. 'condition' => (bool)$sIconUrl,
  1402. 'content' => array('icon_url' => $sIconUrl),
  1403. ),
  1404. 'bx_if:icon' => array (
  1405. 'condition' => (bool)$sIcon,
  1406. 'content' => array('icon' => $sIcon),
  1407. ),
  1408. 'module' => $this->getModuleTitle($aBlock['module']),
  1409. 'visible_for' => _t('_adm_bp_txt_visible_for', BxDolStudioUtils::getVisibilityTitle($aBlock['visible_for_levels'])),
  1410. 'bx_if:show_checkbox' => array(
  1411. 'condition' => true,
  1412. 'content' => array(
  1413. 'content' => $oForm->genRow($aInputCheckbox)
  1414. )
  1415. ),
  1416. 'bx_if:show_drag_handle' => array(
  1417. 'condition' => false,
  1418. 'content' => array()
  1419. )
  1420. );
  1421. }
  1422. return $oTemplate->parseHtmlByName('bp_blocks_list.html', $aTmplParams);
  1423. }
  1424. protected function onBlockDelete($aBlock)
  1425. {
  1426. if($aBlock['module'] != BX_DOL_STUDIO_MODULE_CUSTOM)
  1427. return;
  1428. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['title']);
  1429. //--- Process Lang block
  1430. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && $aBlock['content'] != '')
  1431. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['content']);
  1432. //--- Process Image block
  1433. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && $aBlock['content'] != '') {
  1434. $iImageId = $sImageAlign = '';
  1435. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1436. if(is_numeric($iImageId) && (int)$iImageId != 0)
  1437. BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$iImageId, 0);
  1438. }
  1439. }
  1440. protected function getBlocks($sModule)
  1441. {
  1442. $aBlocks = array();
  1443. $this->oDb->getBlocks(array('type' => 'by_module_to_copy', 'value' => $sModule), $aBlocks, false);
  1444. return $aBlocks;
  1445. }
  1446. protected function _getTmplVarsBlockPanelTop()
  1447. {
  1448. $sJsObject = $this->getPageJsObject();
  1449. $oForm = new BxTemplStudioFormView(array());
  1450. $aInputPages = array(
  1451. 'type' => 'select',
  1452. 'name' => 'page',
  1453. 'attrs' => array(
  1454. 'onChange' => 'javascript:' . $this->getPageJsObject() . '.onChangePage(this)'
  1455. ),
  1456. 'value' => $this->sPage,
  1457. 'values' => array(
  1458. array('key' => '', 'value' => _t('_adm_bp_txt_select_page'))
  1459. )
  1460. );
  1461. $aPages = $aCounter = array();
  1462. $this->oDb->getPages(array('type' => 'by_module', 'value' => $this->sType), $aPages, false);
  1463. $this->oDb->getBlocks(array('type' => 'counter_by_pages'), $aCounter, false);
  1464. foreach($aPages as $aPage)
  1465. $aInputPages['values'][] = array('key' => $aPage['object'], 'value' => _t($aPage['title_system']) . " (" . (isset($aCounter[$aPage['object']]) ? $aCounter[$aPage['object']] : "0") . ")");
  1466. $aTmplVarsActions = array();
  1467. if(($this->sPage != '' && !empty($this->aPageRebuild)) !== false)
  1468. $aTmplVarsActions = $this->_getTmplVarsBlockPanelTopActions();
  1469. return array(
  1470. 'js_object' => $this->getPageJsObject(),
  1471. 'selector' => $oForm->genRow($aInputPages),
  1472. 'action_page_create' => $this->sActionPageCreate,
  1473. 'bx_if:show_actions' => array(
  1474. 'condition' => $this->sPage != '',
  1475. 'content' => $aTmplVarsActions
  1476. )
  1477. );
  1478. }
  1479. protected function _getTmplVarsBlockPanelTopActions()
  1480. {
  1481. $sJsObject = $this->getPageJsObject();
  1482. $oPermalinks = BxDolPermalinks::getInstance();
  1483. return array(
  1484. 'js_object' => $sJsObject,
  1485. 'url_view' => BX_DOL_URL_ROOT . $oPermalinks->permalink($this->aPageRebuild['url']),
  1486. 'action_page_edit' => $this->sActionPageEdit,
  1487. 'bx_if:can_delete' => array(
  1488. 'condition' => (int)$this->aPageRebuild['deletable'] == 1,
  1489. 'content' => array(
  1490. 'js_object' => $sJsObject
  1491. )
  1492. ),
  1493. 'action_block_create' => $this->sActionBlockCreate,
  1494. );
  1495. }
  1496. protected function _getTmplVarsPageSettings($aPage = array(), $bCreate = true)
  1497. {
  1498. $sJsObject = $this->getPageJsObject();
  1499. $aTmplParams = array(
  1500. 'js_object' => $sJsObject,
  1501. 'menu' => array(),
  1502. 'html_settings_groups_id' => $this->aHtmlIds['settings_groups_id'],
  1503. 'bx_repeat:settings_groups' => array(),
  1504. 'submit' => _t($bCreate ? '_adm_bp_btn_page_create' : '_adm_bp_btn_page_apply')
  1505. );
  1506. foreach($this->aPageSettings as $aSetting) {
  1507. //--- get menu items
  1508. $aTmplParams['menu'][$aSetting['name']] = array(
  1509. 'name' => $aSetting['name'],
  1510. 'icon' => '',
  1511. 'onclick' => $sJsObject . '.onChangeSettingGroup(\'' . $aSetting['name'] . '\', this);',
  1512. 'title' => $aSetting['title'],
  1513. 'selected' => isset($aSetting['active']) && (int)$aSetting['active'] == 1
  1514. );
  1515. //--- get settings
  1516. $aTmplParams['bx_repeat:settings_groups'][] = array(
  1517. 'html_settings_group_id' => $this->aHtmlIds['settings_group_id'] . $aSetting['name'],
  1518. 'bx_if:hidden' => array(
  1519. 'condition' => $aSetting['active'] != 1,
  1520. 'content' => array()
  1521. ),
  1522. 'content' => $this->{'getSettings' . $this->getClassName($aSetting['name'])}($aPage, $bCreate)
  1523. );
  1524. }
  1525. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aTmplParams['menu']));
  1526. $aTmplParams['menu'] = $oMenu->getCode();
  1527. return $aTmplParams;
  1528. }
  1529. }
  1530. /** @} */