BxBaseStudioBuilderPage.php 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812
  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. // add indexing data
  491. $aBlock = array_merge($aBlock, $this->getIndexingDataForBlock($aBlock['type'], $aBlock['content']));
  492. if(!$this->oDb->insertBlock($aBlock)) {
  493. if($sContentKey != "")
  494. $oLanguage->deleteLanguageString($sContentKey);
  495. if($iImageId != "")
  496. $oStorege->deleteFile((int)$iImageId, 0);
  497. $bResult = false;
  498. break;
  499. }
  500. //--- Process Title copy
  501. foreach($aTitleValues as $iLangId => $aTitleValue)
  502. $oLanguage->addLanguageString($sTitleKey, $aTitleValue['string'], $iLangId);
  503. }
  504. if($bResult)
  505. return array('eval' => $sJsObject . '.onCreateBlock(oData)');
  506. else
  507. return array('msg' => _t('_adm_bp_err_block_added'));
  508. }
  509. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['create_block_popup_id'], _t('_adm_bp_txt_new_block_popup'), $oTemplate->parseHtmlByName('bp_add_block.html', array(
  510. 'action' => 'create',
  511. 'form_id' => $aForm['form_attrs']['id'],
  512. 'form' => $oForm->getCode(true)
  513. )));
  514. return array('popup' => $sContent);
  515. }
  516. protected function actionBlockEdit()
  517. {
  518. $sJsObject = $this->getPageJsObject();
  519. $oTemplate = BxDolStudioTemplate::getInstance();
  520. $iId = (int)bx_get('id');
  521. if(!$iId)
  522. return array();
  523. $aBlock = array();
  524. $this->oDb->getBlocks(array('type' => 'by_id', 'value' => $iId), $aBlock, false);
  525. if(empty($aBlock) || !is_array($aBlock))
  526. return array('msg' => _t('_adm_bp_err_block_not_found'));
  527. bx_import('BxDolStudioUtils');
  528. $aForm = array(
  529. 'form_attrs' => array(
  530. 'id' => 'adm-bp-block-edit',
  531. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionBlockEdit,
  532. 'method' => 'post'
  533. ),
  534. 'params' => array (
  535. 'db' => array(
  536. 'table' => 'sys_pages_blocks',
  537. 'key' => 'id',
  538. 'uri' => '',
  539. 'uri_title' => '',
  540. 'submit_name' => 'do_submit'
  541. ),
  542. ),
  543. 'inputs' => array (
  544. 'id' => array(
  545. 'type' => 'hidden',
  546. 'name' => 'id',
  547. 'value' => $iId,
  548. 'db' => array (
  549. 'pass' => 'Int',
  550. ),
  551. ),
  552. 'title' => array(
  553. 'type' => 'text_translatable',
  554. 'name' => 'title',
  555. 'caption' => _t('_adm_bp_txt_block_title'),
  556. 'info' => _t('_adm_bp_dsc_block_title'),
  557. 'value' => $aBlock['title'],
  558. 'required' => '1',
  559. 'db' => array (
  560. 'pass' => 'Xss',
  561. ),
  562. 'checker' => array (
  563. 'func' => 'LengthTranslatable',
  564. 'params' => array(3, 100, 'title'),
  565. 'error' => _t('_adm_bp_err_block_title'),
  566. ),
  567. ),
  568. 'designbox_id' => array(
  569. 'type' => 'select',
  570. 'name' => 'designbox_id',
  571. 'caption' => _t('_adm_bp_txt_block_designbox'),
  572. 'info' => '',
  573. 'value' => $this->sSelectKeyPrefix . $aBlock['designbox_id'],
  574. 'values' => array(
  575. array('key' => '', 'value' => _t('_adm_bp_txt_block_designbox_empty')),
  576. ),
  577. 'required' => '1',
  578. 'db' => array (
  579. 'pass' => 'Xss',
  580. ),
  581. 'checker' => array (
  582. 'func' => 'avail',
  583. 'params' => array(),
  584. 'error' => _t('_adm_bp_err_block_designbox'),
  585. ),
  586. ),
  587. 'hidden_on' => array(
  588. 'type' => 'select_multiple',
  589. 'name' => 'hidden_on',
  590. 'caption' => _t('_adm_bp_txt_block_hidden_on'),
  591. 'info' => '',
  592. 'value' => (int)$aBlock['hidden_on'],
  593. 'values' => array(
  594. BX_DB_HIDDEN_PHONE => _t('_adm_bp_txt_block_hidden_on_phone'),
  595. BX_DB_HIDDEN_TABLET => _t('_adm_bp_txt_block_hidden_on_tablet'),
  596. BX_DB_HIDDEN_DESKTOP => _t('_adm_bp_txt_block_hidden_on_desktop'),
  597. BX_DB_HIDDEN_MOBILE => _t('_adm_bp_txt_block_hidden_on_mobile')
  598. ),
  599. 'db' => array (
  600. 'pass' => 'Set',
  601. )
  602. ),
  603. 'visible_for' => array(
  604. 'type' => 'select',
  605. 'name' => 'visible_for',
  606. 'caption' => _t('_adm_bp_txt_block_visible_for'),
  607. 'info' => '',
  608. 'value' => $aBlock['visible_for_levels'] == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
  609. 'values' => array(
  610. array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_bp_txt_block_visible_for_all')),
  611. array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_bp_txt_block_visible_for_selected')),
  612. ),
  613. 'required' => '0',
  614. 'attrs' => array(
  615. 'onchange' => $sJsObject . '.onChangeVisibleFor(this)'
  616. ),
  617. 'db' => array (
  618. 'pass' => 'Xss',
  619. )
  620. ),
  621. 'visible_for_levels' => array(
  622. 'type' => 'checkbox_set',
  623. 'name' => 'visible_for_levels',
  624. 'caption' => _t('_adm_bp_txt_block_visible_for_levels'),
  625. 'info' => _t('_adm_bp_dsc_block_visible_for_levels'),
  626. 'value' => array(),
  627. 'values' => array(),
  628. 'tr_attrs' => array(
  629. 'style' => $aBlock['visible_for_levels'] == BX_DOL_INT_MAX ? 'display:none' : ''
  630. ),
  631. 'db' => array (
  632. 'pass' => 'Int',
  633. )
  634. ),
  635. 'active' => array(
  636. 'type' => 'switcher',
  637. 'name' => 'active',
  638. 'caption' => _t('_adm_bp_txt_block_active'),
  639. 'info' => '',
  640. 'value' => '1',
  641. 'checked' => $aBlock['active'] == '1',
  642. 'db' => array (
  643. 'pass' => 'Int',
  644. )
  645. ),
  646. 'controls' => array(
  647. 'name' => 'controls',
  648. 'type' => 'input_set',
  649. array(
  650. 'type' => 'submit',
  651. 'name' => 'do_submit',
  652. 'value' => _t('_adm_bp_btn_block_save')
  653. ),
  654. array (
  655. 'type' => 'reset',
  656. 'name' => 'close',
  657. 'value' => _t('_adm_bp_btn_block_cancel'),
  658. 'attrs' => array(
  659. 'onclick' => $sJsObject . '.onEditBlockCancel(this)',
  660. 'class' => 'bx-def-margin-sec-left',
  661. ),
  662. )
  663. )
  664. )
  665. );
  666. $aDBoxes = array();
  667. $this->oDb->getDesignBoxes(array('type' => 'ordered'), $aDBoxes, false);
  668. foreach($aDBoxes as $aDBox)
  669. $aForm['inputs']['designbox_id']['values'][] = array('key' => $this->sSelectKeyPrefix . $aDBox['id'], 'value' => _t($aDBox['title']));
  670. BxDolStudioUtils::getVisibilityValues($aBlock['visible_for_levels'], $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
  671. $aForm['inputs'] = $this->addInArray($aForm['inputs'], 'visible_for_levels', $this->getBlockContent($aBlock));
  672. if((int)$aBlock['deletable'] != 0)
  673. $aForm['inputs']['controls'][] = array (
  674. 'type' => 'reset',
  675. 'name' => 'close',
  676. 'value' => _t('_adm_bp_btn_block_delete'),
  677. 'attrs' => array(
  678. 'onclick' => $sJsObject . '.deleteBlock(' . $aBlock['id'] . ')',
  679. 'class' => 'bx-def-margin-sec-left',
  680. ),
  681. );
  682. $oForm = new BxTemplStudioFormView($aForm);
  683. $oForm->initChecker();
  684. if($oForm->isSubmittedAndValid()) {
  685. $this->onSaveBlock($oForm, $aBlock);
  686. // add indexing data
  687. $aBlockAddon = $this->getIndexingDataForBlock($aBlock['type'], $oForm->getCleanValue('content'));
  688. if($oForm->update($iId, $aBlockAddon) !== false)
  689. return array('eval' => $sJsObject . '.onEditBlock(oData)');
  690. else
  691. return array('msg' => _t('_adm_bp_err_block_edit'));
  692. }
  693. $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(
  694. 'action' => 'edit',
  695. 'form_id' => $aForm['form_attrs']['id'],
  696. 'form' => $oForm->getCode(true)
  697. )));
  698. return array('popup' => array('html' => $sContent, 'options' => array('onBeforeShow' => $sJsObject . '.onEditBlockBeforeShow($el)')));
  699. }
  700. protected function actionBlockDelete()
  701. {
  702. $sJsObject = $this->getPageJsObject();
  703. $iId = (int)bx_get('id');
  704. $aBlock = array();
  705. $this->oDb->getBlocks(array('type' => 'by_id', 'value' => $iId), $aBlock, false);
  706. if(empty($aBlock) || !is_array($aBlock))
  707. return array('msg' => _t('_adm_bp_err_block_not_found'));
  708. if((int)$aBlock['deletable'] == 0)
  709. return array('msg' => _t('_adm_bp_err_block_not_deletable'));
  710. if(!$this->oDb->deleteBlocks(array('type' => 'by_id', 'value' => $iId)))
  711. return array('msg' => _t('_adm_bp_err_block_delete'));
  712. $this->onBlockDelete($aBlock);
  713. return array('eval' => $sJsObject . '.onDeleteBlock(' . $iId . ', oData)');
  714. }
  715. protected function actionImageDelete()
  716. {
  717. $sJsObject = $this->getPageJsObject();
  718. $iId = (int)bx_get('id');
  719. $aBlock = array();
  720. $this->oDb->getBlocks(array('type' => 'by_id', 'value' => $iId), $aBlock, false);
  721. if(empty($aBlock) || !is_array($aBlock))
  722. return array('msg' => _t('_adm_bp_err_block_not_found'));
  723. $iImageId = $sImageAlign = '';
  724. if($aBlock['content'] != '')
  725. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  726. if(is_numeric($iImageId) && (int)$iImageId != 0) {
  727. if(!BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$iImageId, 0))
  728. return array('msg' => _t('_adm_bp_err_block_content_image_preview_delete'));
  729. $this->oDb->updateBlock($iId, array('content' => ''));
  730. }
  731. return $this->actionBlockEdit();
  732. }
  733. protected function actionUriGet()
  734. {
  735. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  736. $aLanguages = $oLanguage->getLanguages();
  737. $sLanguageDef = $oLanguage->getDefaultLangName();
  738. $sLanguageCur = $oLanguage->getCurrentLangName(false);
  739. $aValues = array();
  740. foreach($aLanguages as $sName => $sTitle)
  741. if(($mixedValue = bx_get($sName)) !== false)
  742. $aValues[$sName] = bx_process_input($mixedValue);
  743. $sUri = "";
  744. if(($mixedValue = bx_get('uri')) !== false)
  745. $sUri = bx_process_input($mixedValue);
  746. else if(array_key_exists('en', $aValues) && $aValues['en'] != '')
  747. $sUri = $aValues['en'];
  748. else if(array_key_exists($sLanguageDef, $aValues) && $aValues[$sLanguageDef] != '')
  749. $sUri = $aValues[$sLanguageDef];
  750. else if(array_key_exists($sLanguageCur, $aValues) && $aValues[$sLanguageCur] != '')
  751. $sUri = $aValues[$sLanguageCur];
  752. else if(count($aValues) > 0)
  753. foreach($aValues as $sValue)
  754. if(!empty($sValue)) {
  755. $sUri = $sValue;
  756. break;
  757. }
  758. $sUri = $sUri != "" ? uriGenerate($sUri, 'sys_objects_page', 'uri') : "";
  759. $sUrl = BxDolPermalinks::getInstance()->permalink($this->sPageBaseUrl . $sUri);
  760. return array('eval' => $this->getPageJsObject() . '.onGetUri(oData)', 'uri' => $sUri, 'url' => $sUrl);
  761. }
  762. protected function getSettingsOptions($aPage = array(), $bCreate = true, $bInputsOnly = false)
  763. {
  764. $aForm = array(
  765. 'form_attrs' => array(
  766. 'id' => 'adm-bp-settings-options',
  767. ),
  768. 'params' => array (
  769. 'remove_form' => '1',
  770. 'csrf' => array(
  771. 'disable' => true
  772. )
  773. ),
  774. 'inputs' => array (
  775. 'title_system' => array(
  776. 'type' => 'text_translatable',
  777. 'name' => 'title_system',
  778. 'caption' => _t('_adm_bp_txt_page_title_system'),
  779. 'info' => _t('_adm_bp_dsc_page_title_system'),
  780. 'value' => isset($aPage['title_system']) ? $aPage['title_system'] : '',
  781. 'required' => '1',
  782. 'db' => array (
  783. 'pass' => 'Xss',
  784. ),
  785. 'checker' => array (
  786. 'func' => 'length',
  787. 'params' => array(3,100),
  788. 'error' => _t('_adm_bp_err_page_title_system'),
  789. ),
  790. ),
  791. 'title' => array(
  792. 'type' => 'text_translatable',
  793. 'name' => 'title',
  794. 'caption' => _t('_adm_bp_txt_page_title'),
  795. 'info' => _t('_adm_bp_dsc_page_title'),
  796. 'value' => isset($aPage['title']) ? $aPage['title'] : '',
  797. 'required' => '1',
  798. 'db' => array (
  799. 'pass' => 'Xss',
  800. ),
  801. 'checker' => array (
  802. 'func' => 'length',
  803. 'params' => array(3,100),
  804. 'error' => _t('_adm_bp_err_page_title'),
  805. ),
  806. ),
  807. 'url' => array(
  808. 'type' => 'text',
  809. 'name' => 'url',
  810. 'caption' => _t('_adm_bp_txt_page_url'),
  811. 'info' => _t('_adm_bp_dsc_page_url'),
  812. 'value' => isset($aPage['url']) ? BxDolPermalinks::getInstance()->permalink($aPage['url']) : '',
  813. 'required' => '0',
  814. 'attrs' => array(
  815. 'id' => $this->aHtmlIds['url_field_id'],
  816. 'disabled' => 'disabled'
  817. ),
  818. ),
  819. 'type_id' => array(
  820. 'type' => 'select',
  821. 'name' => 'type_id',
  822. 'caption' => _t('_adm_bp_txt_page_type_id'),
  823. 'info' => _t('_adm_bp_dsc_page_type_id'),
  824. 'value' => isset($aPage['type_id']) ? $aPage['type_id'] : '',
  825. 'required' => '1',
  826. 'db' => array (
  827. 'pass' => 'Int',
  828. ),
  829. ),
  830. 'submenu' => array(
  831. 'type' => 'select',
  832. 'name' => 'submenu',
  833. 'caption' => _t('_adm_bp_txt_page_submenu'),
  834. 'info' => _t('_adm_bp_dsc_page_submenu'),
  835. 'value' => isset($aPage['submenu']) ? $aPage['submenu'] : '',
  836. 'required' => '0',
  837. 'db' => array (
  838. 'pass' => 'Xss',
  839. ),
  840. ),
  841. )
  842. );
  843. $aTypes = array();
  844. $this->oDb->getTypes(array('type' => 'all'), $aTypes, false);
  845. foreach($aTypes as $aType)
  846. $aForm['inputs']['type_id']['values'][] = array('key' => $aType['id'], 'value' => _t($aType['title']));
  847. $aSubmenus = $this->oDb->getSubmenus();
  848. $aForm['inputs']['submenu']['values'][] = array('key' => '', 'value' => _t('_sys_please_select'));
  849. foreach ($aSubmenus as $sObject => $sTitle)
  850. $aForm['inputs']['submenu']['values'][] = array('key' => $sObject, 'value' => _t($sTitle));
  851. if($bCreate) {
  852. $sJsObject = $this->getPageJsObject();
  853. $aForm['inputs']['title']['attrs']['onblur'] = $sJsObject . '.getUri(this);';
  854. $aForm['inputs'] = bx_array_insert_before(array(
  855. 'uri' => array(
  856. 'type' => 'text',
  857. 'name' => 'uri',
  858. 'caption' => _t('_adm_bp_txt_page_uri'),
  859. 'info' => _t('_adm_bp_dsc_page_uri'),
  860. 'value' => '',
  861. 'required' => '1',
  862. 'attrs' => array(
  863. 'id' => $this->aHtmlIds['uri_field_id'],
  864. 'onblur' => $sJsObject . '.getUri(this);'
  865. ),
  866. 'db' => array (
  867. 'pass' => 'Xss',
  868. ),
  869. 'checker' => array (
  870. 'func' => 'length',
  871. 'params' => array(3,100),
  872. 'error' => _t('_adm_bp_err_page_uri'),
  873. ),
  874. )
  875. ), $aForm['inputs'], 'url');
  876. }
  877. if($bInputsOnly)
  878. return $aForm['inputs'];
  879. $oForm = new BxTemplStudioFormView($aForm);
  880. return $oForm->getCode();
  881. }
  882. protected function getSettingsOptionsFields($aPage = array(), $bCreate = true)
  883. {
  884. return $this->getSettingsOptions($aPage, $bCreate, true);
  885. }
  886. protected function getSettingsCover($aPage = array(), $bCreate = true, $bInputsOnly = false)
  887. {
  888. $aForm = array(
  889. 'form_attrs' => array(
  890. 'id' => 'adm-bp-settings-cover',
  891. ),
  892. 'params' => array (
  893. 'remove_form' => '1',
  894. 'csrf' => array(
  895. 'disable' => true
  896. )
  897. ),
  898. 'inputs' => array (
  899. 'cover' => array(
  900. 'type' => 'select',
  901. 'name' => 'cover',
  902. 'caption' => _t('_adm_bp_txt_page_cover'),
  903. 'info' => '',
  904. 'value' => isset($aPage['cover']) ? (int)$aPage['cover'] : '1',
  905. 'values' => array(
  906. array('key' => 0, 'value' => _t('_adm_bp_txt_page_cover_0')),
  907. array('key' => 1, 'value' => _t('_adm_bp_txt_page_cover_1')),
  908. array('key' => 2, 'value' => _t('_adm_bp_txt_page_cover_2')),
  909. array('key' => 3, 'value' => _t('_adm_bp_txt_page_cover_3'))
  910. ),
  911. 'db' => array (
  912. 'pass' => 'Int',
  913. )
  914. ),
  915. 'cover_image' => array(
  916. 'type' => 'files',
  917. 'name' => 'cover_image',
  918. 'storage_object' => $this->sStorage,
  919. 'images_transcoder' => $this->sTranscoderCover,
  920. 'uploaders' => $this->aUploadersCover,
  921. 'multiple' => false,
  922. 'content_id' => isset($aPage['id']) ? $aPage['id'] : 0,
  923. 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('uploader_fgt_cover.html', array(
  924. 'name' => 'cover_image',
  925. )),
  926. 'caption' => _t('_adm_bp_txt_page_cover_image'),
  927. 'db' => array (
  928. 'pass' => 'Int',
  929. )
  930. )
  931. )
  932. );
  933. if($bInputsOnly)
  934. return $aForm['inputs'];
  935. $oForm = new BxTemplStudioFormView($aForm);
  936. return $oForm->getCode();
  937. }
  938. protected function getSettingsCoverFields($aPage = array(), $bCreate = true)
  939. {
  940. return $this->getSettingsCover($aPage, $bCreate, true);
  941. }
  942. protected function getSettingsLayout($aPage = array(), $bCreate = true, $bInputsOnly = false)
  943. {
  944. $sJsObject = $this->getPageJsObject();
  945. $oTemplate = BxDolStudioTemplate::getInstance();
  946. $iLayout = isset($aPage['layout_id']) ? (int)$aPage['layout_id'] : 5;
  947. $aLayouts = array();
  948. $this->oDb->getLayouts(array('type' => 'all'), $aLayouts, false);
  949. $aTmplParams = array(
  950. 'bx_repeat:layouts' => array(),
  951. 'form' => ''
  952. );
  953. foreach($aLayouts as $aLayout)
  954. $aTmplParams['bx_repeat:layouts'][] = array(
  955. 'id' => $aLayout['id'],
  956. 'html_id' => $this->aHtmlIds['layout_id'] . $aLayout['id'],
  957. 'js_object' => $sJsObject,
  958. 'bx_if:active' => array(
  959. 'condition' => (int)$aLayout['id'] == $iLayout,
  960. 'content' => array()
  961. ),
  962. 'icon' => $oTemplate->getImageUrl($aLayout['icon']),
  963. 'title' => _t($aLayout['title']),
  964. );
  965. $aForm = array(
  966. 'form_attrs' => array(
  967. 'id' => 'adm-bp-settings-layout',
  968. ),
  969. 'params' => array (
  970. 'remove_form' => '1',
  971. 'csrf' => array(
  972. 'disable' => true
  973. )
  974. ),
  975. 'inputs' => array (
  976. 'layout_id' => array(
  977. 'type' => 'hidden',
  978. 'name' => 'layout_id',
  979. 'value' => $iLayout,
  980. 'db' => array (
  981. 'pass' => 'Int',
  982. ),
  983. )
  984. )
  985. );
  986. if($bInputsOnly)
  987. return $aForm['inputs'];
  988. $oForm = new BxTemplStudioFormView($aForm);
  989. $aTmplParams['form'] = $oForm->getCode();
  990. return $oTemplate->parseHtmlByName('bp_layouts.html', $aTmplParams);
  991. }
  992. protected function getSettingsLayoutFields($aPage = array(), $bCreate = true)
  993. {
  994. return $this->getSettingsLayout($aPage, $bCreate, true);
  995. }
  996. protected function getSettingsVisibility($aPage = array(), $bCreate = true, $bInputsOnly = false)
  997. {
  998. $iVisibleForLevels = isset($aPage['visible_for_levels']) ? (int)$aPage['visible_for_levels'] : BX_DOL_INT_MAX;
  999. if(isset($aPage['visible_for_levels_editable']) && (int)$aPage['visible_for_levels_editable'] == 0)
  1000. $aInputs = array(
  1001. 'visible_for_levels' => array(
  1002. 'type' => 'custom',
  1003. 'name' => 'visible_for_levels',
  1004. 'content' => MsgBox(_t('_adm_bp_err_page_visible_for_levels'))
  1005. )
  1006. );
  1007. else {
  1008. bx_import('BxDolStudioUtils');
  1009. $aInputs = array(
  1010. 'visible_for' => array(
  1011. 'type' => 'select',
  1012. 'name' => 'visible_for',
  1013. 'caption' => _t('_adm_bp_txt_block_visible_for'),
  1014. 'info' => '',
  1015. 'value' => $iVisibleForLevels == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
  1016. 'values' => array(
  1017. array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_bp_txt_block_visible_for_all')),
  1018. array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_bp_txt_block_visible_for_selected')),
  1019. ),
  1020. 'required' => '0',
  1021. 'attrs' => array(
  1022. 'onchange' => $this->getPageJsObject() . '.onChangeVisibleFor(this)'
  1023. ),
  1024. 'db' => array (
  1025. 'pass' => 'Xss',
  1026. )
  1027. ),
  1028. 'visible_for_levels' => array(
  1029. 'type' => 'checkbox_set',
  1030. 'name' => 'visible_for_levels',
  1031. 'caption' => _t('_adm_bp_txt_page_visible_for_levels'),
  1032. 'info' => _t('_adm_bp_dsc_page_visible_for_levels'),
  1033. 'value' => array(),
  1034. 'values' => array(),
  1035. 'tr_attrs' => array(
  1036. 'style' => $iVisibleForLevels == BX_DOL_INT_MAX ? 'display:none' : ''
  1037. ),
  1038. 'db' => array (
  1039. 'pass' => 'Int',
  1040. )
  1041. )
  1042. );
  1043. }
  1044. $aForm = array(
  1045. 'form_attrs' => array(
  1046. 'id' => 'adm-bp-settings-visibility',
  1047. ),
  1048. 'params' => array (
  1049. 'remove_form' => '1',
  1050. 'csrf' => array(
  1051. 'disable' => true
  1052. )
  1053. ),
  1054. 'inputs' => $aInputs
  1055. );
  1056. BxDolStudioUtils::getVisibilityValues($iVisibleForLevels, $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
  1057. if($bInputsOnly)
  1058. return $aForm['inputs'];
  1059. $oForm = new BxTemplStudioFormView($aForm);
  1060. return $oForm->getCode();
  1061. }
  1062. protected function getSettingsVisibilityFields($aPage = array(), $bCreate = true)
  1063. {
  1064. return $this->getSettingsVisibility($aPage, $bCreate, true);
  1065. }
  1066. protected function getSettingsCache($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1067. {
  1068. $aForm = array(
  1069. 'form_attrs' => array(
  1070. 'id' => 'adm-bp-settings-cache',
  1071. ),
  1072. 'params' => array (
  1073. 'remove_form' => '1',
  1074. 'csrf' => array(
  1075. 'disable' => true
  1076. )
  1077. ),
  1078. 'inputs' => array (
  1079. 'cache_lifetime' => array(
  1080. 'type' => 'text',
  1081. 'name' => 'cache_lifetime',
  1082. 'caption' => _t('_adm_bp_txt_page_cache_lifetime'),
  1083. 'info' => _t('_adm_bp_dsc_page_cache_lifetime'),
  1084. 'value' => isset($aPage['cache_lifetime']) ? $aPage['cache_lifetime'] : 0,
  1085. 'required' => '',
  1086. 'attrs' => array(
  1087. 'disabled' => isset($aPage['cache_editable']) && (int)$aPage['cache_editable'] == 0 ? 'disabled' : ''
  1088. ),
  1089. 'db' => array (
  1090. 'pass' => 'Int',
  1091. )
  1092. ),
  1093. )
  1094. );
  1095. if($bInputsOnly)
  1096. return $aForm['inputs'];
  1097. $oForm = new BxTemplStudioFormView($aForm);
  1098. return $oForm->getCode();
  1099. }
  1100. protected function getSettingsCacheFields($aPage = array(), $bCreate = true)
  1101. {
  1102. return $this->getSettingsCache($aPage, $bCreate, true);
  1103. }
  1104. protected function getSettingsSeo($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1105. {
  1106. $aForm = array(
  1107. 'form_attrs' => array(
  1108. 'id' => 'adm-bp-settings-seo',
  1109. ),
  1110. 'params' => array (
  1111. 'remove_form' => '1',
  1112. 'csrf' => array(
  1113. 'disable' => true
  1114. )
  1115. ),
  1116. 'inputs' => array (
  1117. 'meta_description' => array(
  1118. 'type' => 'textarea',
  1119. 'name' => 'meta_description',
  1120. 'caption' => _t('_adm_bp_txt_page_meta_description'),
  1121. 'info' => _t('_adm_bp_dsc_page_meta_description'),
  1122. 'value' => isset($aPage['meta_description']) ? $aPage['meta_description'] : '',
  1123. 'db' => array (
  1124. 'pass' => 'Xss',
  1125. ),
  1126. ),
  1127. 'meta_keywords' => array(
  1128. 'type' => 'textarea',
  1129. 'name' => 'meta_keywords',
  1130. 'caption' => _t('_adm_bp_txt_page_meta_keywords'),
  1131. 'info' => _t('_adm_bp_dsc_page_meta_keywords'),
  1132. 'value' => isset($aPage['meta_keywords']) ? $aPage['meta_keywords'] : '',
  1133. 'db' => array (
  1134. 'pass' => 'Xss',
  1135. ),
  1136. ),
  1137. 'meta_robots' => array(
  1138. 'type' => 'text',
  1139. 'name' => 'meta_robots',
  1140. 'caption' => _t('_adm_bp_txt_page_meta_robots'),
  1141. 'info' => _t('_adm_bp_dsc_page_meta_robots'),
  1142. 'value' => isset($aPage['meta_robots']) ? $aPage['meta_robots'] : '',
  1143. 'required' => '0',
  1144. 'db' => array (
  1145. 'pass' => 'Xss',
  1146. )
  1147. )
  1148. )
  1149. );
  1150. if($bInputsOnly)
  1151. return $aForm['inputs'];
  1152. $oForm = new BxTemplStudioFormView($aForm);
  1153. return $oForm->getCode();
  1154. }
  1155. protected function getSettingsSeoFields($aPage = array(), $bCreate = true)
  1156. {
  1157. return $this->getSettingsSeo($aPage, $bCreate, true);
  1158. }
  1159. protected function getBlockIcon($aBlock)
  1160. {
  1161. $sIcon = $sIconUrl = "";
  1162. $sResult = '';
  1163. switch($aBlock['type']) {
  1164. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1165. $sResult = 'far file-alt';
  1166. break;
  1167. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1168. $sResult = 'code';
  1169. break;
  1170. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1171. $sResult = 'rss';
  1172. break;
  1173. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1174. $sResult = 'far image';
  1175. break;
  1176. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1177. $sResult = 'globe';
  1178. break;
  1179. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1180. $sResult = 'list-alt';
  1181. break;
  1182. case BX_DOL_STUDIO_BP_BLOCK_WIKI:
  1183. $sResult = 'file-word';
  1184. break;
  1185. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1186. $sResult = $this->getModuleIcon($aBlock['module'], 'page');
  1187. break;
  1188. }
  1189. if(strpos($sResult, '.') === false)
  1190. $sIcon = $sResult;
  1191. else
  1192. $sIconUrl = $sResult;
  1193. return array($sIcon, $sIconUrl);
  1194. }
  1195. protected function getBlockModule($aBlock)
  1196. {
  1197. return $aBlock['module'] != BX_DOL_STUDIO_BP_SKELETONS ? $aBlock['module'] : BX_DOL_STUDIO_MODULE_CUSTOM;
  1198. }
  1199. protected function getBlockContent($aBlock)
  1200. {
  1201. $aFields = array();
  1202. switch($aBlock['type']) {
  1203. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1204. $aFields = array(
  1205. 'content' => array(
  1206. 'type' => 'textarea',
  1207. 'name' => 'content',
  1208. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1209. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1210. 'value' => $aBlock['content'],
  1211. 'required' => '0',
  1212. 'code' => 1,
  1213. 'attrs' => array('class' => 'bx-form-input-textarea-codemirror'),
  1214. 'db' => array (
  1215. 'pass' => 'XssHtml',
  1216. ),
  1217. ),
  1218. );
  1219. break;
  1220. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1221. $aFields = array(
  1222. 'content' => array(
  1223. 'type' => 'textarea',
  1224. 'name' => 'content',
  1225. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1226. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1227. 'value' => $aBlock['content'],
  1228. 'required' => '0',
  1229. 'html' => 2,
  1230. 'attrs' => array('id' => $this->aHtmlIds['edit_block_editor_id']),
  1231. 'db' => array (
  1232. 'pass' => 'XssHtml',
  1233. ),
  1234. ),
  1235. 'attachments' => array(
  1236. 'type' => 'files',
  1237. 'name' => 'attachments',
  1238. 'storage_object' => $this->sStorage,
  1239. 'images_transcoder' => $this->sTranscoder,
  1240. 'uploaders' => $this->aUploaders,
  1241. 'multiple' => true,
  1242. 'content_id' => $aBlock['id'],
  1243. 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('bp_fgt_attachments.html', array(
  1244. 'js_object' => $this->getPageJsObject(),
  1245. 'name' => 'attachments',
  1246. 'editor_id' => $this->aHtmlIds['edit_block_editor_id'],
  1247. )),
  1248. 'caption' => _t('_adm_bp_txt_block_content_attachments_html')
  1249. )
  1250. );
  1251. break;
  1252. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1253. $aFields = array(
  1254. 'content' => array(
  1255. 'type' => 'textarea_translatable',
  1256. 'name' => 'content',
  1257. 'caption' => _t('_adm_bp_txt_block_content_lang'),
  1258. 'info' => _t('_adm_bp_dsc_block_content_lang'),
  1259. 'value' => $aBlock['content'],
  1260. 'required' => '0',
  1261. 'html' => 0,
  1262. 'code' => 1,
  1263. 'db' => array (
  1264. 'pass' => 'XssHtml',
  1265. ),
  1266. ),
  1267. );
  1268. break;
  1269. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1270. $iImageId = $sImageAlign = '';
  1271. if($aBlock['content'] != '')
  1272. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1273. $aFields = array(
  1274. 'content' => array(
  1275. 'type' => 'hidden',
  1276. 'name' => 'content',
  1277. 'value' => '',
  1278. 'db' => array (
  1279. 'pass' => 'Xss',
  1280. ),
  1281. ),
  1282. 'image_file' => array(
  1283. 'type' => 'image_uploader',
  1284. 'name' => 'image_file',
  1285. 'caption' => _t('_adm_bp_txt_block_content_image_file'),
  1286. 'caption_preview' => _t('_adm_bp_txt_block_content_image_preview'),
  1287. 'info' => _t('_adm_bp_dsc_block_content_image_file'),
  1288. 'ajax_action_delete' => $this->getPageJsObject() . '.deleteBlockImage(' . $aBlock['id'] . ')',
  1289. 'value' => (int)$iImageId
  1290. ),
  1291. 'image_align' => array(
  1292. 'type' => 'select',
  1293. 'name' => 'image_align',
  1294. 'caption' => _t('_adm_bp_txt_block_content_image_align'),
  1295. 'info' => '',
  1296. 'value' => $sImageAlign,
  1297. 'values' => array(
  1298. array('key' => '', 'value' => _t('_adm_bp_txt_block_content_image_align_empty')),
  1299. array('key' => 'left', 'value' => _t('_adm_bp_txt_block_content_image_align_left')),
  1300. array('key' => 'center', 'value' => _t('_adm_bp_txt_block_content_image_align_center')),
  1301. array('key' => 'right', 'value' => _t('_adm_bp_txt_block_content_image_align_right')),
  1302. ),
  1303. 'required' => '0',
  1304. 'db' => array (
  1305. 'pass' => 'Xss',
  1306. ),
  1307. ),
  1308. );
  1309. break;
  1310. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1311. $sRssUrl = $sRssLength = '';
  1312. if($aBlock['content'] != '')
  1313. list($sRssUrl, $sRssLength) = explode($this->sParamsDivider, $aBlock['content']);
  1314. $aFields = array(
  1315. 'content' => array(
  1316. 'type' => 'hidden',
  1317. 'name' => 'content',
  1318. 'value' => '',
  1319. 'db' => array (
  1320. 'pass' => 'Xss',
  1321. ),
  1322. ),
  1323. 'rss_url' => array(
  1324. 'type' => 'text',
  1325. 'name' => 'rss_url',
  1326. 'caption' => _t('_adm_bp_txt_block_content_rss_url'),
  1327. 'info' => _t('_adm_bp_dsc_block_content_rss_url'),
  1328. 'value' => $sRssUrl,
  1329. 'required' => '0',
  1330. 'db' => array (
  1331. 'pass' => 'Xss',
  1332. ),
  1333. ),
  1334. 'rss_length' => array(
  1335. 'type' => 'text',
  1336. 'name' => 'rss_length',
  1337. 'caption' => _t('_adm_bp_txt_block_content_rss_length'),
  1338. 'info' => _t('_adm_bp_dsc_block_content_rss_length'),
  1339. 'value' => $sRssLength,
  1340. 'required' => '0',
  1341. 'db' => array (
  1342. 'pass' => 'Int',
  1343. ),
  1344. ),
  1345. );
  1346. break;
  1347. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1348. $aFields = array(
  1349. 'content' => array(
  1350. 'type' => 'select',
  1351. 'name' => 'content',
  1352. 'caption' => _t('_adm_bp_txt_block_content_menu'),
  1353. 'info' => '',
  1354. 'value' => $aBlock['content'],
  1355. 'values' => array(),
  1356. 'required' => '0',
  1357. 'db' => array (
  1358. 'pass' => 'Xss',
  1359. ),
  1360. )
  1361. );
  1362. $sGroup = '';
  1363. $aMenus = $this->oDb->getMenus(true);
  1364. foreach($aMenus as $sKey => $aMenu) {
  1365. if($sGroup != $aMenu['module']) {
  1366. if(!empty($sGroup))
  1367. $aFields['content']['values'][$sGroup . '_end'] = array('type' => 'group_end');
  1368. $sGroup = $aMenu['module'];
  1369. $aFields['content']['values'][$sGroup . '_beg'] = array('type' => 'group_header', 'value' => BxDolStudioUtils::getModuleTitle($sGroup));
  1370. }
  1371. $aFields['content']['values'][$sKey] = _t($aMenu['title']);
  1372. }
  1373. $aFields['content']['values'] = array_merge(array('' => _t('_adm_bp_txt_block_content_menu_empty')), $aFields['content']['values']);
  1374. break;
  1375. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1376. $aService = array('module' => '', 'method' => '');
  1377. if($aBlock['content'] != '')
  1378. $aService = unserialize($aBlock['content']);
  1379. $aFields = array(
  1380. 'service_module' => array(
  1381. 'type' => 'value',
  1382. 'name' => 'service_module',
  1383. 'caption' => _t('_adm_bp_txt_block_content_service_module'),
  1384. 'value' => $this->getModuleTitle($aService['module'])
  1385. ),
  1386. 'service_method' => array(
  1387. 'type' => 'value',
  1388. 'name' => 'service_method',
  1389. 'caption' => _t('_adm_bp_txt_block_content_service_method'),
  1390. 'value' => $aService['method']
  1391. )
  1392. );
  1393. break;
  1394. }
  1395. return $aFields;
  1396. }
  1397. protected function getBlockList($sModule)
  1398. {
  1399. if(empty($sModule))
  1400. return '';
  1401. $sJsObject = $this->getPageJsObject();
  1402. $oTemplate = BxDolStudioTemplate::getInstance();
  1403. $oForm = new BxTemplStudioFormView(array());
  1404. $aInputCheckbox = array(
  1405. 'type' => 'checkbox',
  1406. 'name' => 'blocks[]',
  1407. 'attrs' => array(
  1408. 'onChange' => 'javascript:' . $sJsObject . '.onSelectBlock(this);'
  1409. ),
  1410. 'value' => ''
  1411. );
  1412. $aTmplParams = array(
  1413. 'html_block_list_id' => $this->aHtmlIds['block_list_id'] . $sModule,
  1414. 'bx_repeat:blocks' => array()
  1415. );
  1416. $aBlocks = $this->getBlocks($sModule);
  1417. foreach($aBlocks as $aBlock) {
  1418. list($sIcon, $sIconUrl) = $this->getBlockIcon($aBlock);
  1419. $aInputCheckbox['value'] = $aBlock['id'];
  1420. $aTmplParams['bx_repeat:blocks'][] = array(
  1421. 'js_object' => $sJsObject,
  1422. 'html_id' => $this->aHtmlIds['block_id'] . $aBlock['id'],
  1423. 'bx_if:is_inactive' => array(
  1424. 'condition' => false,
  1425. 'content' => array()
  1426. ),
  1427. 'bx_if:show_link' => array(
  1428. 'condition' => false,
  1429. 'content' => array()
  1430. ),
  1431. 'bx_if:show_text' => array(
  1432. 'condition' => true,
  1433. 'content' => array(
  1434. 'title' => _t(!empty($aBlock['title_system']) ? $aBlock['title_system'] : $aBlock['title']),
  1435. )
  1436. ),
  1437. 'bx_if:image' => array (
  1438. 'condition' => (bool)$sIconUrl,
  1439. 'content' => array('icon_url' => $sIconUrl),
  1440. ),
  1441. 'bx_if:icon' => array (
  1442. 'condition' => (bool)$sIcon,
  1443. 'content' => array('icon' => $sIcon),
  1444. ),
  1445. 'module' => $this->getModuleTitle($aBlock['module']),
  1446. 'visible_for' => _t('_adm_bp_txt_visible_for', BxDolStudioUtils::getVisibilityTitle($aBlock['visible_for_levels'])),
  1447. 'bx_if:show_checkbox' => array(
  1448. 'condition' => true,
  1449. 'content' => array(
  1450. 'content' => $oForm->genRow($aInputCheckbox)
  1451. )
  1452. ),
  1453. 'bx_if:show_drag_handle' => array(
  1454. 'condition' => false,
  1455. 'content' => array()
  1456. )
  1457. );
  1458. }
  1459. return $oTemplate->parseHtmlByName('bp_blocks_list.html', $aTmplParams);
  1460. }
  1461. protected function onBlockDelete($aBlock)
  1462. {
  1463. if($aBlock['module'] != BX_DOL_STUDIO_MODULE_CUSTOM)
  1464. return;
  1465. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['title']);
  1466. //--- Process Lang block
  1467. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && $aBlock['content'] != '')
  1468. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['content']);
  1469. //--- Process Image block
  1470. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && $aBlock['content'] != '') {
  1471. $iImageId = $sImageAlign = '';
  1472. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1473. if(is_numeric($iImageId) && (int)$iImageId != 0)
  1474. BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$iImageId, 0);
  1475. }
  1476. }
  1477. protected function getBlocks($sModule)
  1478. {
  1479. $aBlocks = array();
  1480. $this->oDb->getBlocks(array('type' => 'by_module_to_copy', 'value' => $sModule), $aBlocks, false);
  1481. return $aBlocks;
  1482. }
  1483. protected function _getTmplVarsBlockPanelTop()
  1484. {
  1485. $sJsObject = $this->getPageJsObject();
  1486. $oForm = new BxTemplStudioFormView(array());
  1487. $aInputPages = array(
  1488. 'type' => 'select',
  1489. 'name' => 'page',
  1490. 'attrs' => array(
  1491. 'onChange' => 'javascript:' . $this->getPageJsObject() . '.onChangePage(this)'
  1492. ),
  1493. 'value' => $this->sPage,
  1494. 'values' => array(
  1495. array('key' => '', 'value' => _t('_adm_bp_txt_select_page'))
  1496. )
  1497. );
  1498. $aPages = $aCounter = array();
  1499. $this->oDb->getPages(array('type' => 'by_module', 'value' => $this->sType), $aPages, false);
  1500. $this->oDb->getBlocks(array('type' => 'counter_by_pages'), $aCounter, false);
  1501. foreach($aPages as $aPage) {
  1502. $sTitle = _t($aPage['title_system']);
  1503. if(empty($sTitle))
  1504. $sTitle = _t($aPage['title']);
  1505. $aInputPages['values'][] = array(
  1506. 'key' => $aPage['object'],
  1507. 'value' => $sTitle . " (" . (isset($aCounter[$aPage['object']]) ? $aCounter[$aPage['object']] : "0") . ")"
  1508. );
  1509. }
  1510. $aTmplVarsActions = array();
  1511. if(($this->sPage != '' && !empty($this->aPageRebuild)) !== false)
  1512. $aTmplVarsActions = $this->_getTmplVarsBlockPanelTopActions();
  1513. return array(
  1514. 'js_object' => $this->getPageJsObject(),
  1515. 'selector' => $oForm->genRow($aInputPages),
  1516. 'action_page_create' => $this->sActionPageCreate,
  1517. 'bx_if:show_actions' => array(
  1518. 'condition' => $this->sPage != '',
  1519. 'content' => $aTmplVarsActions
  1520. )
  1521. );
  1522. }
  1523. protected function _getTmplVarsBlockPanelTopActions()
  1524. {
  1525. $sJsObject = $this->getPageJsObject();
  1526. $oPermalinks = BxDolPermalinks::getInstance();
  1527. return array(
  1528. 'js_object' => $sJsObject,
  1529. 'url_view' => BX_DOL_URL_ROOT . $oPermalinks->permalink($this->aPageRebuild['url']),
  1530. 'action_page_edit' => $this->sActionPageEdit,
  1531. 'bx_if:can_delete' => array(
  1532. 'condition' => (int)$this->aPageRebuild['deletable'] == 1,
  1533. 'content' => array(
  1534. 'js_object' => $sJsObject
  1535. )
  1536. ),
  1537. 'action_block_create' => $this->sActionBlockCreate,
  1538. );
  1539. }
  1540. protected function _getTmplVarsPageSettings($aPage = array(), $bCreate = true)
  1541. {
  1542. $sJsObject = $this->getPageJsObject();
  1543. $aTmplParams = array(
  1544. 'js_object' => $sJsObject,
  1545. 'menu' => array(),
  1546. 'html_settings_groups_id' => $this->aHtmlIds['settings_groups_id'],
  1547. 'bx_repeat:settings_groups' => array(),
  1548. 'submit' => _t($bCreate ? '_adm_bp_btn_page_create' : '_adm_bp_btn_page_apply')
  1549. );
  1550. foreach($this->aPageSettings as $aSetting) {
  1551. //--- get menu items
  1552. $aTmplParams['menu'][$aSetting['name']] = array(
  1553. 'name' => $aSetting['name'],
  1554. 'icon' => '',
  1555. 'onclick' => $sJsObject . '.onChangeSettingGroup(\'' . $aSetting['name'] . '\', this);',
  1556. 'title' => $aSetting['title'],
  1557. 'selected' => isset($aSetting['active']) && (int)$aSetting['active'] == 1
  1558. );
  1559. //--- get settings
  1560. $aTmplParams['bx_repeat:settings_groups'][] = array(
  1561. 'html_settings_group_id' => $this->aHtmlIds['settings_group_id'] . $aSetting['name'],
  1562. 'bx_if:hidden' => array(
  1563. 'condition' => $aSetting['active'] != 1,
  1564. 'content' => array()
  1565. ),
  1566. 'content' => $this->{'getSettings' . $this->getClassName($aSetting['name'])}($aPage, $bCreate)
  1567. );
  1568. }
  1569. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aTmplParams['menu']));
  1570. $aTmplParams['menu'] = $oMenu->getCode();
  1571. return $aTmplParams;
  1572. }
  1573. protected function getIndexingDataForBlock($sType, $sContent)
  1574. {
  1575. $aBlock = array();
  1576. switch($sType) {
  1577. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1578. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1579. $aBlock['text'] = trim(strip_tags($sContent));
  1580. $aBlock['text_updated'] = time();
  1581. break;
  1582. }
  1583. return $aBlock;
  1584. }
  1585. }
  1586. /** @} */