BxBaseStudioBuilderPage.php 69 KB

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