BxBaseStudioBuilderPage.php 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097
  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. define('BX_DOL_STUDIO_BUILDER_PAGE', 1);
  11. class BxBaseStudioBuilderPage extends BxDolStudioBuilderPage
  12. {
  13. protected $sParamsDivider = '#';
  14. protected $sSelectKeyPrefix = 'id-';
  15. protected $sActionPageCreate = 'page_create';
  16. protected $sActionPageDelete = 'page_delete';
  17. protected $sActionPageEdit = 'page_edit';
  18. protected $sActionBlockCreate = 'block_create';
  19. protected $sActionBlockEdit = 'block_edit';
  20. protected $sStorage;
  21. protected $sTranscoder;
  22. protected $aUploaders;
  23. protected $sTranscoderCover;
  24. protected $aUploadersCover;
  25. protected $sBaseUrl;
  26. protected $sTypeUrl;
  27. protected $sPageUrl;
  28. protected $aHtmlIds = array(
  29. 'add_popup_id' => 'adm-bp-add-popup',
  30. 'edit_popup_id' => 'adm-bp-edit-popup',
  31. 'uri_field_id' => 'adm-bp-field-uri',
  32. 'url_field_id' => 'adm-bp-field-url',
  33. 'settings_group_id' => 'adm-bp-settings-group-',
  34. 'settings_groups_id' => 'adm-bp-settings-groups',
  35. 'create_block_popup_id' => 'adm-bp-create-block-popup',
  36. 'edit_block_popup_id' => 'adm-bp-edit-block-popup',
  37. 'edit_block_editor_id' => 'adm-bp-edit-block-editor',
  38. 'edit_block_builder_id' => 'adm-bp-edit-block-builder',
  39. 'block_id' => 'adm-bpb-',
  40. 'block_list_id' => 'adm-bpl-',
  41. 'block_lists_id' => 'adm-bp-block-lists',
  42. 'layout_id' => 'adm-bpl-',
  43. );
  44. protected $aPageSettings = array(
  45. array('name' => 'options', 'title' => '_adm_bp_mi_page_options', 'active' => 1),
  46. array('name' => 'cover', 'title' => '_adm_bp_mi_page_cover', 'active' => 0),
  47. array('name' => 'layout', 'title' => '_adm_bp_mi_page_layout', 'active' => 0),
  48. array('name' => 'visibility', 'title' => '_adm_bp_mi_page_visibility', 'active' => 0),
  49. array('name' => 'cache', 'title' => '_adm_bp_mi_page_cache', 'active' => 0),
  50. array('name' => 'seo', 'title' => '_adm_bp_mi_page_seo', 'active' => 0),
  51. array('name' => 'injections', 'title' => '_adm_bp_mi_page_injections', 'active' => 0)
  52. );
  53. function __construct($sType = '', $sPage = '')
  54. {
  55. parent::__construct($sType, $sPage);
  56. $this->sStorage = BX_DOL_STORAGE_OBJ_IMAGES;
  57. $this->sTranscoder = 'sys_builder_page_preview';
  58. $this->aUploaders = array('sys_builder_page_html5');
  59. $this->sTranscoderCover = 'sys_cover_preview';
  60. $this->aUploadersCover = array('sys_std_crop_cover');
  61. $this->sBaseUrl = BX_DOL_URL_STUDIO . 'builder_page.php';
  62. $this->sTypeUrl = $this->sBaseUrl . '?type=%s';
  63. $this->sPageUrl = $this->sTypeUrl . '&page=%s';
  64. }
  65. function getPageCss()
  66. {
  67. $oTemplate = BxDolStudioTemplate::getInstance();
  68. $aUploaders = array_merge($this->aUploaders, $this->aUploadersCover);
  69. foreach($aUploaders as $sUploader) {
  70. $oUploader = BxDolUploader::getObjectInstance($sUploader, $this->sStorage, '', $oTemplate);
  71. if($oUploader)
  72. $oUploader->addCssJs();
  73. }
  74. return array_merge(parent::getPageCss(), array(
  75. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css',
  76. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'grapesjs/|grapes.min.css',
  77. 'page_layouts.css',
  78. 'builder_page.css'
  79. ));
  80. }
  81. function getPageJs()
  82. {
  83. return array_merge(parent::getPageJs(), array(
  84. 'codemirror/codemirror.min.js',
  85. 'grapesjs/grapes.min.js',
  86. 'grapesjs/grapesjs-blocks-basic.js',
  87. 'grapesjs/grapesjs-style-bg.js',
  88. 'grapesjs/grapesjs-preset-webpage.min.js',
  89. 'jquery-ui/jquery-ui.min.js',
  90. 'jquery.ui.touch-punch.min.js',
  91. 'jquery.easing.js',
  92. 'jquery.form.min.js',
  93. 'functions.js',
  94. 'builder_page.js'
  95. ));
  96. }
  97. function getPageJsObject()
  98. {
  99. return 'oBxDolStudioBuilderPage';
  100. }
  101. function getPageMenu($aMenu = [], $aMarkers = [])
  102. {
  103. $aMenuItems = [
  104. BX_DOL_STUDIO_MODULE_SYSTEM => [
  105. 'name' => BX_DOL_STUDIO_MODULE_SYSTEM,
  106. 'icon' => 'mi-bp-system.svg',
  107. 'icon_bg' => true,
  108. 'title' => '_adm_bp_cpt_type_' . BX_DOL_STUDIO_MODULE_SYSTEM,
  109. ],
  110. BX_DOL_STUDIO_MODULE_CUSTOM => [
  111. 'name' => BX_DOL_STUDIO_MODULE_CUSTOM,
  112. 'icon' => 'mi-bp-custom.svg',
  113. 'icon_bg' => true,
  114. 'title' => '_adm_bp_cpt_type_' . BX_DOL_STUDIO_MODULE_CUSTOM,
  115. ]
  116. ];
  117. $aModulesDb = $this->oDb->getPages(['type' => 'modules_with_pages']);
  118. foreach($aModulesDb as $aModuleDb) {
  119. $sName = $aModuleDb['name'];
  120. if($sName == BX_DOL_STUDIO_MODULE_SYSTEM)
  121. continue;
  122. $aMenuItems[] = [
  123. 'name' => $sName,
  124. 'icon' => BxDolStudioUtils::getModuleIcon($aModuleDb, 'menu', false),
  125. 'icon_bg' => false,
  126. 'title' => BxDolStudioUtils::getModuleTitle($sName)
  127. ];
  128. }
  129. $aMenu = [];
  130. foreach($aMenuItems as $aMenuItem)
  131. $aMenu[] = array_merge($aMenuItem, [
  132. 'link' => sprintf($this->sTypeUrl, $aMenuItem['name']),
  133. 'selected' => $aMenuItem['name'] == $this->sType
  134. ]);
  135. return parent::getPageMenu($aMenu);
  136. }
  137. function getPageCode($sPage = '', $bWrap = true)
  138. {
  139. $sResult = parent::getPageCode($sPage, $bWrap);
  140. if($sResult === false)
  141. return false;
  142. $oPage = BxTemplPage::getObjectInstance($this->sPage);
  143. $oTemplate = BxDolStudioTemplate::getInstance();
  144. $sJsObject = $this->getPageJsObject();
  145. $sTxtEmpty = _t('_sys_txt_empty');
  146. $sContent = "";
  147. if(($bPage = $this->sPage != '') === true) {
  148. /**
  149. * Reset (move to hidden sell) blocks which cannot be seen,
  150. * because of unsuitable cell number to currently selected layout.
  151. */
  152. $this->oDb->resetBlocksByPage($this->aPageRebuild['object'], $this->aPageRebuild['layout_cells_number']);
  153. $aTmplVars = array(
  154. 'page_id' => 'bx-page-' . $this->aPageRebuild['uri'],
  155. 'bx_if:show_layout_row_dump' => array(
  156. 'condition' => true,
  157. 'content' => array()
  158. )
  159. );
  160. for($i = 0; $i <= $this->aPageRebuild['layout_cells_number']; $i++) {
  161. $aBlocks = array();
  162. $this->oDb->getBlocks(array('type' => 'by_object_cell', 'object' => $this->aPageRebuild['object'], 'cell' => $i), $aBlocks, false);
  163. $aTmplVarsCell = array('id' => $i, 'bx_repeat:blocks' => array());
  164. foreach($aBlocks as $aBlock) {
  165. $sTitle = strip_tags(!empty($aBlock['title_system']) ? _t($aBlock['title_system']) : $oPage->getBlockTitle($aBlock));
  166. list($sIcon, $sIconUrl) = $this->getBlockIcon($aBlock);
  167. $aTmplVarsCell['bx_repeat:blocks'][] = array(
  168. 'html_id' => $this->aHtmlIds['block_id'] . $aBlock['id'],
  169. 'bx_if:is_inactive' => array(
  170. 'condition' => (int)$aBlock['active'] == 0,
  171. 'content' => array()
  172. ),
  173. 'bx_if:show_link' => array(
  174. 'condition' => true,
  175. 'content' => array(
  176. 'onclick' => $sJsObject . ".performAction('block_edit', {id: " . $aBlock['id'] . "})",
  177. 'title' => !empty($sTitle) ? $sTitle : $sTxtEmpty,
  178. )
  179. ),
  180. 'bx_if:show_text' => array(
  181. 'condition' => false,
  182. 'content' => array()
  183. ),
  184. 'bx_if:show_api' => [
  185. 'condition' => (int)$aBlock['active_api'] != 0,
  186. 'content' => []
  187. ],
  188. 'bx_if:image' => array (
  189. 'condition' => (bool)$sIconUrl,
  190. 'content' => array('icon_url' => $sIconUrl),
  191. ),
  192. 'bx_if:icon' => array (
  193. 'condition' => (bool)$sIcon,
  194. 'content' => array('icon' => $sIcon),
  195. ),
  196. 'module' => $this->getModuleTitle($aBlock['module']),
  197. 'visible_for' => _t('_adm_bp_txt_visible_for', BxDolStudioUtils::getVisibilityTitle($aBlock['visible_for_levels'])),
  198. 'bx_if:show_checkbox' => array(
  199. 'condition' => false,
  200. 'content' => array()
  201. ),
  202. 'bx_if:show_drag_handle' => array(
  203. 'condition' => true,
  204. 'content' => array()
  205. )
  206. );
  207. }
  208. $sCell = $oTemplate->parseHtmlByName('bp_cell.html', $aTmplVarsCell);
  209. if($i == 0)
  210. $aTmplVars['bx_if:show_layout_row_dump']['content']['cell_' . $i] = $sCell;
  211. else
  212. $aTmplVars['cell_' . $i] = $sCell;
  213. }
  214. $sContent = $oTemplate->parseHtmlByName($this->aPageRebuild['layout_template'], $aTmplVars);
  215. }
  216. $aLanguages = BxDolStudioLanguagesUtils::getInstance()->getLanguages();
  217. $aTmplVars = array(
  218. 'js_object' => $sJsObject,
  219. 'action_url' => $this->sBaseUrl,
  220. 'page_url' => sprintf($this->sPageUrl, '{0}', '{1}'),
  221. 'type' => $this->sType,
  222. 'page' => $this->sPage,
  223. 'html_ids' => json_encode($this->aHtmlIds),
  224. 'languahes' => json_encode($aLanguages),
  225. 'content' => $this->getBlockCode(array(
  226. 'items' => $sContent
  227. ))
  228. );
  229. $oTemplate->addJsTranslation(array(
  230. '_adm_bp_wrn_page_delete',
  231. '_adm_bp_wrn_page_block_delete'
  232. ));
  233. return $sResult . $oTemplate->parseHtmlByName('builder_page.html', $aTmplVars);
  234. }
  235. function getBlockPanelTop($aBlock)
  236. {
  237. return parent::getBlockPanelTop(
  238. array('panel_top' => BxDolStudioTemplate::getInstance()->parseHtmlByName('bp_block_panel_top.html', $this->_getTmplVarsBlockPanelTop()))
  239. );
  240. }
  241. protected function actionPageCreate()
  242. {
  243. $sJsObject = $this->getPageJsObject();
  244. $oTemplate = BxDolStudioTemplate::getInstance();
  245. $sModule = BX_DOL_STUDIO_MODULE_CUSTOM;
  246. $oForm = $this->_getPageCreateForm();
  247. $oForm->initChecker();
  248. if($oForm->isSubmittedAndValid()) {
  249. unset($oForm->aInputs['settings']);
  250. foreach($this->aPageSettings as $aSetting)
  251. $oForm->aInputs = array_merge($oForm->aInputs, $this->{'getSettings' . $this->getClassName($aSetting['name']) . 'Fields'}());
  252. $sLanguage = BxDolStudioLanguagesUtils::getInstance()->getCurrentLangName(false);
  253. $sObject = BxDolForm::getSubmittedValue('title-' . $sLanguage, $oForm->aFormAttrs['method']);
  254. $sObject = uriGenerate($sObject, 'sys_objects_page', 'object', ['empty' => 'object']);
  255. $sUri = $oForm->getCleanValue('uri');
  256. $aPage = $this->oDb->getPages(['type' => 'by_uri', 'value' => $sUri]);
  257. if(!empty($aPage) && is_array($aPage))
  258. return ['msg' => _t('_adm_bp_err_page_uri')];
  259. $iVisibleFor = BxDolStudioUtils::getVisibilityValue($oForm->getCleanValue('visible_for'), $oForm->getCleanValue('visible_for_levels'));
  260. BxDolForm::setSubmittedValue('visible_for_levels', $iVisibleFor, $oForm->aFormAttrs['method']);
  261. unset($oForm->aInputs['visible_for']);
  262. $aValsToAdd = [
  263. 'author' => bx_get_logged_profile_id(),
  264. 'object' => $sObject,
  265. 'url' => $this->sPageBaseUrl . $sUri,
  266. 'added' => time()
  267. ];
  268. $this->onSavePage($oForm, $aValsToAdd);
  269. $iId = (int)$oForm->insert($aValsToAdd);
  270. if($iId != 0) {
  271. $this->onPageChanged($oForm, $aValsToAdd);
  272. return ['eval' => $sJsObject . '.onCreatePage(\'' . $sModule . '\', \'' . $sObject . '\')'];
  273. } else {
  274. return ['msg' => _t('_adm_bp_err_page_create')];
  275. }
  276. }
  277. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['add_popup_id'], _t('_adm_bp_txt_create_popup'), $oTemplate->parseHtmlByName('bp_add_page.html', array(
  278. 'js_object' => $sJsObject,
  279. 'form_id' => $oForm->getId(),
  280. 'form' => $oForm->getCode(true)
  281. )));
  282. return array('popup' => $sContent);
  283. }
  284. protected function actionPageEdit()
  285. {
  286. $sJsObject = $this->getPageJsObject();
  287. $oTemplate = BxDolStudioTemplate::getInstance();
  288. $oForm = $this->_getPageEditForm();
  289. $oForm->initChecker();
  290. if($oForm->isSubmittedAndValid()) {
  291. unset($oForm->aInputs['settings']);
  292. foreach($this->aPageSettings as $aSetting)
  293. $oForm->aInputs = array_merge($oForm->aInputs, $this->{'getSettings' . $this->getClassName($aSetting['name']) . 'Fields'}($this->aPageRebuild, false));
  294. $mixedVisibleFor = $oForm->getCleanValue('visible_for');
  295. $mixedVisibleForLevels = $oForm->getCleanValue('visible_for_levels');
  296. if($mixedVisibleFor !== false && $mixedVisibleForLevels !== false) {
  297. $iVisibleFor = BxDolStudioUtils::getVisibilityValue($mixedVisibleFor, $mixedVisibleForLevels);
  298. BxDolForm::setSubmittedValue('visible_for_levels', $iVisibleFor, $oForm->aFormAttrs['method']);
  299. unset($oForm->aInputs['visible_for']);
  300. }
  301. $this->onSavePage($oForm, $this->aPageRebuild);
  302. if($oForm->update($this->aPageRebuild['id'])) {
  303. $this->onPageChanged($oForm, $this->aPageRebuild);
  304. $iLevelId = $oForm->getCleanValue('layout_id');
  305. if(!empty($iLevelId) && $iLevelId != $this->aPageRebuild['layout_id']) {
  306. $aLayoutOld = array();
  307. $this->oDb->getLayouts(array('type' => 'by_id', 'value' => $this->aPageRebuild['layout_id']), $aLayoutOld, false);
  308. $aLayoutNew = array();
  309. $this->oDb->getLayouts(array('type' => 'by_id', 'value' => $iLevelId), $aLayoutNew, false);
  310. if($aLayoutOld['cells_number'] > $aLayoutNew['cells_number'] && $this->oDb->resetBlocksByPage($this->sPage, $aLayoutNew['cells_number']) === false)
  311. return array('msg' => _t('_adm_bp_err_save'));
  312. return array('eval' => $sJsObject . '.onSaveSettingsLayout()');
  313. }
  314. return array();
  315. }
  316. else
  317. return array('msg' => _t('_adm_bp_err_save'));
  318. }
  319. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['edit_popup_id'], _t('_adm_bp_txt_settings_popup'), $oTemplate->parseHtmlByName('bp_edit_page.html', array(
  320. 'js_object' => $sJsObject,
  321. 'form_id' => $oForm->getId(),
  322. 'form' => $oForm->getCode(true)
  323. )));
  324. return array('popup' => $sContent);
  325. }
  326. protected function actionPageDelete()
  327. {
  328. if(empty($this->sPage) || empty($this->aPageRebuild) || !is_array($this->aPageRebuild))
  329. return array('msg' => _t('_adm_bp_err_page_delete'));
  330. $oLangauge = BxDolStudioLanguagesUtils::getInstance();
  331. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  332. $aBlocks = array();
  333. $this->oDb->getBlocks(array('type' => 'by_object', 'value' => $this->sPage), $aBlocks, false);
  334. if(is_array($aBlocks) && !empty($aBlocks)) {
  335. foreach($aBlocks as $aBlock)
  336. $this->onBlockDelete($aBlock);
  337. $this->oDb->deleteBlocks(array('type' => 'by_object', 'value' => $this->sPage));
  338. }
  339. if($this->oDb->deletePages(array('type' => 'by_object', 'value' => $this->sPage))) {
  340. $oLangauge->deleteLanguageString($this->aPageRebuild['title_system']);
  341. $oLangauge->deleteLanguageString($this->aPageRebuild['title']);
  342. $this->onPageChanged(null, $this->aPageRebuild);
  343. return array('eval' => 'window.parent.location.href = "' . sprintf($this->sTypeUrl, $this->sType) . '";');
  344. }
  345. return array('msg' => _t('_adm_bp_err_page_delete'));
  346. }
  347. protected function actionBlockList()
  348. {
  349. $sModule = BX_DOL_STUDIO_BP_TYPE_DEFAULT;
  350. if(bx_get('bp_module') !== false)
  351. $sModule = bx_process_input(bx_get('bp_module'));
  352. return array(
  353. 'content' => $this->getBlockList($sModule)
  354. );
  355. }
  356. protected function actionBlockCreate()
  357. {
  358. $sJsObject = $this->getPageJsObject();
  359. $oTemplate = BxDolStudioTemplate::getInstance();
  360. $sSelected = BX_DOL_STUDIO_BP_SKELETONS;
  361. $aForm = array(
  362. 'form_attrs' => array(
  363. 'id' => 'adm-bp-block-create',
  364. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionBlockCreate,
  365. 'method' => 'post'
  366. ),
  367. 'params' => array (
  368. 'db' => array(
  369. 'table' => 'sys_pages_blocks',
  370. 'key' => 'id',
  371. 'uri' => '',
  372. 'uri_title' => '',
  373. 'submit_name' => 'do_submit'
  374. ),
  375. ),
  376. 'inputs' => array (
  377. 'blocks' => array(
  378. 'type' => 'custom',
  379. 'name' => 'blocks',
  380. 'content' => '',
  381. 'db' => array (
  382. 'pass' => 'Int',
  383. ),
  384. ),
  385. )
  386. );
  387. $aMenu = [
  388. BX_DOL_STUDIO_BP_SKELETONS => [
  389. 'name' => BX_DOL_STUDIO_BP_SKELETONS,
  390. 'icon' => 'mi-qrcode.svg',
  391. 'icon_bg' => true,
  392. 'title' => '_sys_block_types_skeletons',
  393. 'selected' => $sSelected == BX_DOL_STUDIO_BP_SKELETONS,
  394. ],
  395. BX_DOL_STUDIO_MODULE_SYSTEM => [
  396. 'name' => BX_DOL_STUDIO_MODULE_SYSTEM,
  397. 'icon' => 'mi-cog.svg',
  398. 'icon_bg' => true,
  399. 'title' => '_sys_block_types_system',
  400. 'selected' => $sSelected == BX_DOL_STUDIO_MODULE_SYSTEM,
  401. ],
  402. BX_DOL_STUDIO_MODULE_CUSTOM => [
  403. 'name' => BX_DOL_STUDIO_MODULE_CUSTOM,
  404. 'icon' => 'mi-wrench.svg',
  405. 'icon_bg' => true,
  406. 'title' => '_sys_block_types_custom',
  407. 'selected' => $sSelected == BX_DOL_STUDIO_MODULE_CUSTOM,
  408. ]
  409. ];
  410. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(['type' => 'type', 'value' => [BX_DOL_MODULE_TYPE_MODULE, BX_DOL_MODULE_TYPE_TEMPLATE]]);
  411. $aModulesWithBlocks = $this->oDb->getModulesWithCopyableBlocks();
  412. foreach($aModules as $aModule) {
  413. $sName = $aModule['name'];
  414. if(!in_array($sName, $aModulesWithBlocks))
  415. continue;
  416. if(!empty($aMenu[$sName]))
  417. $aMenu[$sName] = array_merge($aMenu[$sName], $aModule);
  418. else
  419. $aMenu[$sName] = $aModule;
  420. if(empty($aMenu[$sName]['icon']))
  421. $aMenu[$sName]['icon'] = BxDolStudioUtils::getModuleIcon($aModule, 'menu', false);
  422. }
  423. foreach($aMenu as $sKey => $aItem)
  424. $aMenu[$sKey]['onclick'] = $sJsObject . '.onChangeModule(\'' . $aItem['name'] . '\', this);';
  425. $oMenu = new BxTemplStudioMenu(['template' => 'menu_side.html', 'menu_items' => $aMenu]);
  426. $aForm['inputs']['blocks']['content'] = $oTemplate->parseHtmlByName('bp_add_block_form.html', [
  427. 'menu' => $oMenu->getCode(),
  428. 'html_block_lists_id' => $this->aHtmlIds['block_lists_id'],
  429. 'blocks' => $this->getBlockList($sSelected)
  430. ]);
  431. $oForm = new BxTemplStudioFormView($aForm);
  432. $oForm->initChecker();
  433. if($oForm->isSubmittedAndValid()) {
  434. $aIds = $oForm->getCleanValue('blocks');
  435. $aBlocks = array();
  436. $this->oDb->getBlocks(array('type' => 'by_ids', 'value' => $aIds), $aBlocks, false);
  437. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  438. $oStorege = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  439. $bResult = true;
  440. foreach($aBlocks as $aBlock) {
  441. $sModule = $aBlock['module'];
  442. $sTitleKey = $this->getSystemName($aBlock['title'] . '_' . time());
  443. $aTitleValues = $oLanguage->getLanguageString($aBlock['title']);
  444. unset($aBlock['id']);
  445. $aBlock['object'] = $this->sPage;
  446. $aBlock['cell_id'] = 1;
  447. $aBlock['module'] = $this->getBlockModule($aBlock);
  448. $aBlock['title'] = $sTitleKey;
  449. $aBlock['copyable'] = $sModule == BX_DOL_STUDIO_BP_SKELETONS ? 1 : 0;
  450. $aBlock['deletable'] = 1;
  451. //--- Process Lang copy
  452. $sContentKey = $sContentValue = "";
  453. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && $aBlock['content'] != '') {
  454. $sContentKey = $this->getSystemName($aBlock['content'] . '_' . time());
  455. $sContentValue = _t($aBlock['content']);
  456. $aBlock['content'] = $sContentKey;
  457. $oLanguage->addLanguageString($sContentKey, $sContentValue);
  458. }
  459. //--- Process Image copy
  460. $iImageId = $sImageAlign = "";
  461. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && $aBlock['content'] != '') {
  462. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  463. $aBlock['content'] = "";
  464. if(is_numeric($iImageId) && (int)$iImageId != 0 && ($iImageId = $oStorege->storeFileFromStorage(array('id' => $iImageId))) !== false)
  465. $aBlock['content'] = implode($this->sParamsDivider, array($iImageId, $sImageAlign));
  466. }
  467. // add indexing data
  468. $aBlock = array_merge($aBlock, $this->getIndexingDataForBlock($aBlock['type'], $aBlock['content']));
  469. if(!$this->oDb->insertBlock($aBlock)) {
  470. if($sContentKey != "")
  471. $oLanguage->deleteLanguageString($sContentKey);
  472. if($iImageId != "")
  473. $oStorege->deleteFile((int)$iImageId, 0);
  474. $bResult = false;
  475. break;
  476. }
  477. //--- Process Title copy
  478. foreach($aTitleValues as $iLangId => $aTitleValue)
  479. $oLanguage->addLanguageString($sTitleKey, $aTitleValue['string'], $iLangId);
  480. }
  481. if($bResult)
  482. return array('eval' => $sJsObject . '.onCreateBlock(oData)');
  483. else
  484. return array('msg' => _t('_adm_bp_err_block_added'));
  485. }
  486. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['create_block_popup_id'], _t('_adm_bp_txt_new_block_popup'), $oTemplate->parseHtmlByName('bp_add_block.html', array(
  487. 'action' => 'create',
  488. 'form_id' => $aForm['form_attrs']['id'],
  489. 'form' => $oForm->getCode(true)
  490. )));
  491. return array('popup' => $sContent);
  492. }
  493. protected function actionBlockEdit()
  494. {
  495. $sJsObject = $this->getPageJsObject();
  496. $oTemplate = BxDolStudioTemplate::getInstance();
  497. $iId = (int)bx_get('id');
  498. if(!$iId)
  499. return array();
  500. $aBlock = array();
  501. $this->oDb->getBlocks(array('type' => 'by_id', 'value' => $iId), $aBlock, false);
  502. if(empty($aBlock) || !is_array($aBlock))
  503. return array('msg' => _t('_adm_bp_err_block_not_found'));
  504. bx_import('BxDolStudioUtils');
  505. $aForm = array(
  506. 'form_attrs' => array(
  507. 'id' => 'adm-bp-block-edit',
  508. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionBlockEdit,
  509. 'method' => 'post'
  510. ),
  511. 'params' => array (
  512. 'db' => array(
  513. 'table' => 'sys_pages_blocks',
  514. 'key' => 'id',
  515. 'uri' => '',
  516. 'uri_title' => '',
  517. 'submit_name' => 'do_submit'
  518. ),
  519. ),
  520. 'inputs' => array (
  521. 'id' => array(
  522. 'type' => 'hidden',
  523. 'name' => 'id',
  524. 'value' => $iId,
  525. 'db' => array (
  526. 'pass' => 'Int',
  527. ),
  528. ),
  529. 'title' => array(
  530. 'type' => 'text_translatable',
  531. 'name' => 'title',
  532. 'caption' => _t('_adm_bp_txt_block_title'),
  533. 'info' => _t('_adm_bp_dsc_block_title'),
  534. 'value' => $aBlock['title'],
  535. 'required' => '1',
  536. 'db' => array (
  537. 'pass' => 'Xss',
  538. ),
  539. 'checker' => array (
  540. 'func' => 'LengthTranslatable',
  541. 'params' => array(3, 100, 'title'),
  542. 'error' => _t('_adm_bp_err_block_title'),
  543. ),
  544. ),
  545. 'designbox_id' => array(
  546. 'type' => 'select',
  547. 'name' => 'designbox_id',
  548. 'caption' => _t('_adm_bp_txt_block_designbox'),
  549. 'info' => '',
  550. 'value' => $this->sSelectKeyPrefix . $aBlock['designbox_id'],
  551. 'values' => array(
  552. array('key' => '', 'value' => _t('_adm_bp_txt_block_designbox_empty')),
  553. ),
  554. 'required' => '1',
  555. 'db' => array (
  556. 'pass' => 'Xss',
  557. ),
  558. 'checker' => array (
  559. 'func' => 'avail',
  560. 'params' => array(),
  561. 'error' => _t('_adm_bp_err_block_designbox'),
  562. ),
  563. ),
  564. 'async' => array(
  565. 'type' => 'select',
  566. 'name' => 'async',
  567. 'caption' => _t('_adm_bp_txt_block_async'),
  568. 'info' => '',
  569. 'value' => isset($aBlock['async']) ? $aBlock['async'] : 0,
  570. 'required' => '0',
  571. 'db' => array (
  572. 'pass' => 'Int',
  573. ),
  574. ),
  575. 'submenu' => array(
  576. 'type' => 'select',
  577. 'name' => 'submenu',
  578. 'caption' => _t('_adm_bp_txt_block_submenu'),
  579. 'info' => '',
  580. 'value' => isset($aBlock['submenu']) ? $aBlock['submenu'] : '',
  581. 'required' => '0',
  582. 'db' => array (
  583. 'pass' => 'Xss',
  584. ),
  585. ),
  586. 'tabs' => array(
  587. 'type' => 'switcher',
  588. 'name' => 'tabs',
  589. 'caption' => _t('_adm_bp_txt_block_tabs'),
  590. 'info' => '',
  591. 'value' => '1',
  592. 'checked' => $aBlock['tabs'] == '1',
  593. 'db' => array (
  594. 'pass' => 'Int',
  595. )
  596. ),
  597. 'hidden_on' => array(
  598. 'type' => 'select_multiple',
  599. 'name' => 'hidden_on',
  600. 'caption' => _t('_adm_bp_txt_block_hidden_on'),
  601. 'info' => '',
  602. 'value' => (int)$aBlock['hidden_on'],
  603. 'values' => array(
  604. BX_DB_HIDDEN_PHONE => _t('_adm_bp_txt_block_hidden_on_phone'),
  605. BX_DB_HIDDEN_TABLET => _t('_adm_bp_txt_block_hidden_on_tablet'),
  606. BX_DB_HIDDEN_DESKTOP => _t('_adm_bp_txt_block_hidden_on_desktop'),
  607. BX_DB_HIDDEN_MOBILE => _t('_adm_bp_txt_block_hidden_on_mobile')
  608. ),
  609. 'db' => array (
  610. 'pass' => 'Set',
  611. )
  612. ),
  613. 'visible_for' => array(
  614. 'type' => 'select',
  615. 'name' => 'visible_for',
  616. 'caption' => _t('_adm_bp_txt_block_visible_for'),
  617. 'info' => '',
  618. 'value' => $aBlock['visible_for_levels'] == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
  619. 'values' => array(
  620. array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_bp_txt_block_visible_for_all')),
  621. array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_bp_txt_block_visible_for_selected')),
  622. ),
  623. 'required' => '0',
  624. 'attrs' => array(
  625. 'onchange' => $sJsObject . '.onChangeVisibleFor(this)'
  626. ),
  627. 'db' => array (
  628. 'pass' => 'Xss',
  629. )
  630. ),
  631. 'visible_for_levels' => array(
  632. 'type' => 'checkbox_set',
  633. 'name' => 'visible_for_levels',
  634. 'caption' => _t('_adm_bp_txt_block_visible_for_levels'),
  635. 'info' => _t('_adm_bp_dsc_block_visible_for_levels'),
  636. 'value' => array(),
  637. 'values' => array(),
  638. 'tr_attrs' => array(
  639. 'style' => $aBlock['visible_for_levels'] == BX_DOL_INT_MAX ? 'display:none' : ''
  640. ),
  641. 'db' => array (
  642. 'pass' => 'Int',
  643. )
  644. ),
  645. 'content_empty' => array(
  646. 'type' => 'text_translatable',
  647. 'name' => 'content_empty',
  648. 'caption' => _t('_adm_bp_txt_block_content_empty'),
  649. 'info' => _t('_adm_bp_dsc_block_content_empty'),
  650. 'value' => $aBlock['content_empty'],
  651. 'db' => array (
  652. 'pass' => 'Xss',
  653. ),
  654. ),
  655. 'help' => array(
  656. 'type' => 'textarea_translatable',
  657. 'name' => 'help',
  658. 'caption' => _t('_adm_bp_txt_block_help'),
  659. 'info' => '',
  660. 'value' => $aBlock['help'],
  661. 'required' => '0',
  662. 'html' => 2,
  663. 'db' => array (
  664. 'pass' => 'Xss',
  665. ),
  666. ),
  667. 'class' => array(
  668. 'type' => 'text',
  669. 'name' => 'class',
  670. 'caption' => _t('_adm_bp_txt_block_class'),
  671. 'info' => '',
  672. 'value' => $aBlock['class'],
  673. 'required' => '0',
  674. 'db' => array (
  675. 'pass' => 'Xss',
  676. ),
  677. ),
  678. 'cache_lifetime' => array(
  679. 'type' => 'text',
  680. 'name' => 'cache_lifetime',
  681. 'caption' => _t('_adm_bp_txt_block_cache_lifetime'),
  682. 'info' => '',
  683. 'value' => isset($aBlock['cache_lifetime']) ? $aBlock['cache_lifetime'] : 0,
  684. 'required' => '0',
  685. 'db' => array (
  686. 'pass' => 'Int',
  687. ),
  688. ),
  689. 'active' => array(
  690. 'type' => 'switcher',
  691. 'name' => 'active',
  692. 'caption' => _t('_adm_bp_txt_block_active'),
  693. 'info' => '',
  694. 'value' => '1',
  695. 'checked' => $aBlock['active'] == '1',
  696. 'db' => array (
  697. 'pass' => 'Int',
  698. )
  699. ),
  700. 'active_api' => array(
  701. 'type' => 'switcher',
  702. 'name' => 'active_api',
  703. 'caption' => _t('_adm_bp_txt_block_active_api'),
  704. 'info' => '',
  705. 'value' => '1',
  706. 'checked' => $aBlock['active_api'] == '1',
  707. 'db' => array (
  708. 'pass' => 'Int',
  709. )
  710. ),
  711. 'controls' => array(
  712. 'name' => 'controls',
  713. 'type' => 'input_set',
  714. array(
  715. 'type' => 'submit',
  716. 'name' => 'do_submit',
  717. 'value' => _t('_adm_bp_btn_block_save')
  718. ),
  719. array (
  720. 'type' => 'reset',
  721. 'name' => 'close',
  722. 'value' => _t('_adm_bp_btn_block_cancel'),
  723. 'attrs' => array(
  724. 'onclick' => $sJsObject . '.onEditBlockCancel(this)',
  725. 'class' => 'bx-def-margin-sec-left',
  726. ),
  727. )
  728. )
  729. )
  730. );
  731. $aDBoxes = array();
  732. $this->oDb->getDesignBoxes(array('type' => 'ordered'), $aDBoxes, false);
  733. foreach($aDBoxes as $aDBox)
  734. $aForm['inputs']['designbox_id']['values'][] = array('key' => $this->sSelectKeyPrefix . $aDBox['id'], 'value' => _t($aDBox['title']));
  735. $aContentPlaceholders = $this->oDb->getContentPlaceholders();
  736. $aForm['inputs']['async']['values'][] = array('key' => 0, 'value' => _t('_sys_no_async'));
  737. foreach ($aContentPlaceholders as $iKey => $sTitle)
  738. $aForm['inputs']['async']['values'][] = array('key' => $iKey, 'value' => _t($sTitle));
  739. $aSubmenus = $this->oDb->getBlockSubmenus();
  740. $aForm['inputs']['submenu']['values'][] = array('key' => '', 'value' => _t('_sys_menu_item_title_inherited'));
  741. $aForm['inputs']['submenu']['values'][] = array('key' => 'disabled', 'value' => _t('_sys_menu_item_title_disabled'));
  742. foreach ($aSubmenus as $sObject => $sTitle)
  743. $aForm['inputs']['submenu']['values'][] = array('key' => $sObject, 'value' => _t($sTitle));
  744. BxDolStudioUtils::getVisibilityValues($aBlock['visible_for_levels'], $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
  745. $aForm['inputs'] = $this->addInArray($aForm['inputs'], 'visible_for_levels', $this->getBlockContent($aBlock));
  746. if((int)$aBlock['deletable'] != 0)
  747. $aForm['inputs']['controls'][] = array (
  748. 'type' => 'reset',
  749. 'name' => 'close',
  750. 'value' => _t('_adm_bp_btn_block_delete'),
  751. 'attrs' => array(
  752. 'onclick' => $sJsObject . '.deleteBlock(' . $aBlock['id'] . ')',
  753. 'class' => 'bx-def-margin-sec-left',
  754. ),
  755. );
  756. $oForm = new BxTemplStudioFormView($aForm);
  757. $oForm->initChecker();
  758. if($oForm->isSubmittedAndValid()) {
  759. $this->onSaveBlock($oForm, $aBlock);
  760. // add indexing data
  761. $aBlockAddon = $this->getIndexingDataForBlock($aBlock['type'], $oForm->getCleanValue('content'));
  762. if($oForm->update($iId, $aBlockAddon) !== false)
  763. return array('eval' => $sJsObject . '.onEditBlock(oData)');
  764. else
  765. return array('msg' => _t('_adm_bp_err_block_edit'));
  766. }
  767. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['edit_block_popup_id'], _t('_adm_bp_txt_edit_block_popup', _t($aBlock['title_system'])), $oTemplate->parseHtmlByName('bp_add_block.html', array(
  768. 'action' => 'edit',
  769. 'form_id' => $aForm['form_attrs']['id'],
  770. 'form' => $oForm->getCode(true)
  771. )));
  772. return array('popup' => array('html' => $sContent, 'options' => array('onBeforeShow' => $sJsObject . '.onEditBlockBeforeShow($el)')));
  773. }
  774. protected function actionBlockDelete()
  775. {
  776. $sJsObject = $this->getPageJsObject();
  777. $iId = (int)bx_get('id');
  778. $aBlock = array();
  779. $this->oDb->getBlocks(array('type' => 'by_id', 'value' => $iId), $aBlock, false);
  780. if(empty($aBlock) || !is_array($aBlock))
  781. return array('msg' => _t('_adm_bp_err_block_not_found'));
  782. if((int)$aBlock['deletable'] == 0)
  783. return array('msg' => _t('_adm_bp_err_block_not_deletable'));
  784. if(!$this->oDb->deleteBlocks(array('type' => 'by_id', 'value' => $iId)))
  785. return array('msg' => _t('_adm_bp_err_block_delete'));
  786. $this->onBlockDelete($aBlock);
  787. return array('eval' => $sJsObject . '.onDeleteBlock(' . $iId . ', oData)');
  788. }
  789. protected function actionUriGet()
  790. {
  791. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  792. $aLanguages = $oLanguage->getLanguages();
  793. $sLanguageDef = $oLanguage->getDefaultLangName();
  794. $sLanguageCur = $oLanguage->getCurrentLangName(false);
  795. $aValues = array();
  796. foreach($aLanguages as $sName => $sTitle)
  797. if(($mixedValue = bx_get($sName)) !== false)
  798. $aValues[$sName] = bx_process_input($mixedValue);
  799. $sUri = "";
  800. if(($mixedValue = bx_get('uri')) !== false)
  801. $sUri = bx_process_input($mixedValue);
  802. else if(array_key_exists('en', $aValues) && $aValues['en'] != '')
  803. $sUri = $aValues['en'];
  804. else if(array_key_exists($sLanguageDef, $aValues) && $aValues[$sLanguageDef] != '')
  805. $sUri = $aValues[$sLanguageDef];
  806. else if(array_key_exists($sLanguageCur, $aValues) && $aValues[$sLanguageCur] != '')
  807. $sUri = $aValues[$sLanguageCur];
  808. else if(count($aValues) > 0)
  809. foreach($aValues as $sValue)
  810. if(!empty($sValue)) {
  811. $sUri = $sValue;
  812. break;
  813. }
  814. $sUri = $sUri != "" ? uriGenerate($sUri, 'sys_objects_page', 'uri') : "";
  815. $sUrl = BxDolPermalinks::getInstance()->permalink($this->sPageBaseUrl . $sUri);
  816. return array('eval' => $this->getPageJsObject() . '.onGetUri(oData)', 'uri' => $sUri, 'url' => $sUrl);
  817. }
  818. protected function getSettingsOptions($aPage = array(), $bCreate = true, $bInputsOnly = false)
  819. {
  820. $aForm = array(
  821. 'form_attrs' => array(
  822. 'id' => 'adm-bp-settings-options',
  823. ),
  824. 'params' => array (
  825. 'remove_form' => '1',
  826. 'csrf' => array(
  827. 'disable' => true
  828. )
  829. ),
  830. 'inputs' => array (
  831. 'title_system' => array(
  832. 'type' => 'text_translatable',
  833. 'name' => 'title_system',
  834. 'caption' => _t('_adm_bp_txt_page_title_system'),
  835. 'info' => _t('_adm_bp_dsc_page_title_system'),
  836. 'value' => isset($aPage['title_system']) ? $aPage['title_system'] : '',
  837. 'required' => '1',
  838. 'db' => array (
  839. 'pass' => 'Xss',
  840. ),
  841. 'checker' => array (
  842. 'func' => 'length',
  843. 'params' => array(3,100),
  844. 'error' => _t('_adm_bp_err_page_title_system'),
  845. ),
  846. ),
  847. 'title' => array(
  848. 'type' => 'text_translatable',
  849. 'name' => 'title',
  850. 'caption' => _t('_adm_bp_txt_page_title'),
  851. 'info' => _t('_adm_bp_dsc_page_title'),
  852. 'value' => isset($aPage['title']) ? $aPage['title'] : '',
  853. 'required' => '1',
  854. 'db' => array (
  855. 'pass' => 'Xss',
  856. ),
  857. 'checker' => array (
  858. 'func' => 'length',
  859. 'params' => array(3,100),
  860. 'error' => _t('_adm_bp_err_page_title'),
  861. ),
  862. ),
  863. 'url' => array(
  864. 'type' => 'text',
  865. 'name' => 'url',
  866. 'caption' => _t('_adm_bp_txt_page_url'),
  867. 'info' => _t('_adm_bp_dsc_page_url'),
  868. 'value' => isset($aPage['url']) ? BxDolPermalinks::getInstance()->permalink($aPage['url']) : '',
  869. 'required' => '0',
  870. 'attrs' => array(
  871. 'id' => $this->aHtmlIds['url_field_id'],
  872. 'disabled' => 'disabled'
  873. ),
  874. ),
  875. 'type_id' => array(
  876. 'type' => 'select',
  877. 'name' => 'type_id',
  878. 'caption' => _t('_adm_bp_txt_page_type_id'),
  879. 'info' => _t('_adm_bp_dsc_page_type_id'),
  880. 'value' => isset($aPage['type_id']) ? $aPage['type_id'] : '',
  881. 'required' => '1',
  882. 'db' => array (
  883. 'pass' => 'Int',
  884. ),
  885. ),
  886. 'submenu' => array(
  887. 'type' => 'select',
  888. 'name' => 'submenu',
  889. 'caption' => _t('_adm_bp_txt_page_submenu'),
  890. 'info' => _t('_adm_bp_dsc_page_submenu'),
  891. 'value' => isset($aPage['submenu']) ? $aPage['submenu'] : '',
  892. 'required' => '0',
  893. 'db' => array (
  894. 'pass' => 'Xss',
  895. ),
  896. ),
  897. 'sticky_columns' => array(
  898. 'type' => 'switcher',
  899. 'name' => 'sticky_columns',
  900. 'caption' => _t('_adm_bp_txt_page_sticky_columns'),
  901. 'info' => '',
  902. 'value' => '1',
  903. 'checked' => isset($aPage['sticky_columns']) && $aPage['sticky_columns'] == 1,
  904. 'db' => array (
  905. 'pass' => 'Int',
  906. )
  907. )
  908. )
  909. );
  910. $aTypes = array();
  911. $this->oDb->getTypes(array('type' => 'all'), $aTypes, false);
  912. foreach($aTypes as $aType)
  913. $aForm['inputs']['type_id']['values'][] = array('key' => $aType['id'], 'value' => _t($aType['title']));
  914. $aSubmenus = $this->oDb->getSubmenus();
  915. $aForm['inputs']['submenu']['values'][] = array('key' => '', 'value' => _t('_sys_menu_item_title_inherited'));
  916. $aForm['inputs']['submenu']['values'][] = array('key' => 'disabled', 'value' => _t('_sys_menu_item_title_disabled'));
  917. foreach ($aSubmenus as $sObject => $sTitle)
  918. $aForm['inputs']['submenu']['values'][] = array('key' => $sObject, 'value' => _t($sTitle));
  919. if($bCreate) {
  920. $sJsObject = $this->getPageJsObject();
  921. $aForm['inputs']['title']['attrs']['onblur'] = $sJsObject . '.getUri(this);';
  922. $aForm['inputs'] = bx_array_insert_before(array(
  923. 'uri' => array(
  924. 'type' => 'text',
  925. 'name' => 'uri',
  926. 'caption' => _t('_adm_bp_txt_page_uri'),
  927. 'info' => _t('_adm_bp_dsc_page_uri'),
  928. 'value' => '',
  929. 'required' => '1',
  930. 'attrs' => array(
  931. 'id' => $this->aHtmlIds['uri_field_id'],
  932. 'onblur' => $sJsObject . '.getUri(this);'
  933. ),
  934. 'db' => array (
  935. 'pass' => 'Xss',
  936. ),
  937. 'checker' => array (
  938. 'func' => 'length',
  939. 'params' => array(3,100),
  940. 'error' => _t('_adm_bp_err_page_uri'),
  941. ),
  942. )
  943. ), $aForm['inputs'], 'url');
  944. }
  945. if($bInputsOnly)
  946. return $aForm['inputs'];
  947. $oForm = new BxTemplStudioFormView($aForm);
  948. return $oForm->getCode();
  949. }
  950. protected function getSettingsOptionsFields($aPage = array(), $bCreate = true)
  951. {
  952. return $this->getSettingsOptions($aPage, $bCreate, true);
  953. }
  954. protected function getSettingsCover($aPage = array(), $bCreate = true, $bInputsOnly = false)
  955. {
  956. $aForm = array(
  957. 'form_attrs' => array(
  958. 'id' => 'adm-bp-settings-cover',
  959. ),
  960. 'params' => array (
  961. 'remove_form' => '1',
  962. 'csrf' => array(
  963. 'disable' => true
  964. )
  965. ),
  966. 'inputs' => array (
  967. 'cover' => array(
  968. 'type' => 'select',
  969. 'name' => 'cover',
  970. 'caption' => _t('_adm_bp_txt_page_cover'),
  971. 'info' => '',
  972. 'value' => isset($aPage['cover']) ? (int)$aPage['cover'] : '1',
  973. 'values' => array(
  974. array('key' => 0, 'value' => _t('_adm_bp_txt_page_cover_0')),
  975. array('key' => 1, 'value' => _t('_adm_bp_txt_page_cover_1')),
  976. array('key' => 2, 'value' => _t('_adm_bp_txt_page_cover_2')),
  977. array('key' => 3, 'value' => _t('_adm_bp_txt_page_cover_3'))
  978. ),
  979. 'db' => array (
  980. 'pass' => 'Int',
  981. )
  982. ),
  983. 'cover_image' => array(
  984. 'type' => 'files',
  985. 'name' => 'cover_image',
  986. 'storage_object' => $this->sStorage,
  987. 'images_transcoder' => $this->sTranscoderCover,
  988. 'uploaders' => $this->aUploadersCover,
  989. 'multiple' => false,
  990. 'content_id' => isset($aPage['id']) ? $aPage['id'] : 0,
  991. 'ghost_template' => BxTemplStudioFunctions::getInstance()->getDefaultGhostTemplate('cover_image'),
  992. 'caption' => _t('_adm_bp_txt_page_cover_image'),
  993. 'db' => array (
  994. 'pass' => 'Int',
  995. )
  996. ),
  997. 'cover_title' => array(
  998. 'type' => 'text_translatable',
  999. 'name' => 'cover_title',
  1000. 'caption' => _t('_adm_bp_txt_page_cover_title'),
  1001. 'info' => '',
  1002. 'value' => isset($aPage['cover_title']) ? $aPage['cover_title'] : '',
  1003. 'db' => array (
  1004. 'pass' => 'Xss',
  1005. )
  1006. ),
  1007. )
  1008. );
  1009. if($bInputsOnly)
  1010. return $aForm['inputs'];
  1011. $oForm = new BxTemplStudioFormView($aForm);
  1012. return $oForm->getCode();
  1013. }
  1014. protected function getSettingsCoverFields($aPage = array(), $bCreate = true)
  1015. {
  1016. return $this->getSettingsCover($aPage, $bCreate, true);
  1017. }
  1018. protected function getSettingsLayout($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1019. {
  1020. $sJsObject = $this->getPageJsObject();
  1021. $oTemplate = BxDolStudioTemplate::getInstance();
  1022. $iLayout = isset($aPage['layout_id']) ? (int)$aPage['layout_id'] : 5;
  1023. $aLayouts = array();
  1024. $this->oDb->getLayouts(array('type' => 'all'), $aLayouts, false);
  1025. $aTmplParams = array(
  1026. 'bx_repeat:layouts' => array(),
  1027. 'form' => ''
  1028. );
  1029. foreach($aLayouts as $aLayout)
  1030. $aTmplParams['bx_repeat:layouts'][] = array(
  1031. 'id' => $aLayout['id'],
  1032. 'html_id' => $this->aHtmlIds['layout_id'] . $aLayout['id'],
  1033. 'js_object' => $sJsObject,
  1034. 'bx_if:active' => array(
  1035. 'condition' => (int)$aLayout['id'] == $iLayout,
  1036. 'content' => array()
  1037. ),
  1038. 'icon' => $oTemplate->getImageUrl($aLayout['icon']),
  1039. 'title' => _t($aLayout['title']),
  1040. );
  1041. $aForm = array(
  1042. 'form_attrs' => array(
  1043. 'id' => 'adm-bp-settings-layout',
  1044. ),
  1045. 'params' => array (
  1046. 'remove_form' => '1',
  1047. 'csrf' => array(
  1048. 'disable' => true
  1049. )
  1050. ),
  1051. 'inputs' => array (
  1052. 'layout_id' => array(
  1053. 'type' => 'hidden',
  1054. 'name' => 'layout_id',
  1055. 'value' => $iLayout,
  1056. 'db' => array (
  1057. 'pass' => 'Int',
  1058. ),
  1059. )
  1060. )
  1061. );
  1062. if($bInputsOnly)
  1063. return $aForm['inputs'];
  1064. $oForm = new BxTemplStudioFormView($aForm);
  1065. $aTmplParams['form'] = $oForm->getCode();
  1066. return $oTemplate->parseHtmlByName('bp_layouts.html', $aTmplParams);
  1067. }
  1068. protected function getSettingsLayoutFields($aPage = array(), $bCreate = true)
  1069. {
  1070. return $this->getSettingsLayout($aPage, $bCreate, true);
  1071. }
  1072. protected function getSettingsVisibility($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1073. {
  1074. $iVisibleForLevels = isset($aPage['visible_for_levels']) ? (int)$aPage['visible_for_levels'] : BX_DOL_INT_MAX;
  1075. if(isset($aPage['visible_for_levels_editable']) && (int)$aPage['visible_for_levels_editable'] == 0)
  1076. $aInputs = array(
  1077. 'visible_for_levels' => array(
  1078. 'type' => 'custom',
  1079. 'name' => 'visible_for_levels',
  1080. 'content' => MsgBox(_t('_adm_bp_err_page_visible_for_levels'))
  1081. )
  1082. );
  1083. else {
  1084. bx_import('BxDolStudioUtils');
  1085. $aInputs = array(
  1086. 'visible_for' => array(
  1087. 'type' => 'select',
  1088. 'name' => 'visible_for',
  1089. 'caption' => _t('_adm_bp_txt_block_visible_for'),
  1090. 'info' => '',
  1091. 'value' => $iVisibleForLevels == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
  1092. 'values' => array(
  1093. array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_bp_txt_block_visible_for_all')),
  1094. array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_bp_txt_block_visible_for_selected')),
  1095. ),
  1096. 'required' => '0',
  1097. 'attrs' => array(
  1098. 'onchange' => $this->getPageJsObject() . '.onChangeVisibleFor(this)'
  1099. ),
  1100. 'db' => array (
  1101. 'pass' => 'Xss',
  1102. )
  1103. ),
  1104. 'visible_for_levels' => array(
  1105. 'type' => 'checkbox_set',
  1106. 'name' => 'visible_for_levels',
  1107. 'caption' => _t('_adm_bp_txt_page_visible_for_levels'),
  1108. 'info' => _t('_adm_bp_dsc_page_visible_for_levels'),
  1109. 'value' => array(),
  1110. 'values' => array(),
  1111. 'tr_attrs' => array(
  1112. 'style' => $iVisibleForLevels == BX_DOL_INT_MAX ? 'display:none' : ''
  1113. ),
  1114. 'db' => array (
  1115. 'pass' => 'Int',
  1116. )
  1117. )
  1118. );
  1119. }
  1120. $aForm = array(
  1121. 'form_attrs' => array(
  1122. 'id' => 'adm-bp-settings-visibility',
  1123. ),
  1124. 'params' => array (
  1125. 'remove_form' => '1',
  1126. 'csrf' => array(
  1127. 'disable' => true
  1128. )
  1129. ),
  1130. 'inputs' => $aInputs
  1131. );
  1132. BxDolStudioUtils::getVisibilityValues($iVisibleForLevels, $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
  1133. if($bInputsOnly)
  1134. return $aForm['inputs'];
  1135. $oForm = new BxTemplStudioFormView($aForm);
  1136. return $oForm->getCode();
  1137. }
  1138. protected function getSettingsVisibilityFields($aPage = array(), $bCreate = true)
  1139. {
  1140. return $this->getSettingsVisibility($aPage, $bCreate, true);
  1141. }
  1142. protected function getSettingsCache($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1143. {
  1144. $aForm = array(
  1145. 'form_attrs' => array(
  1146. 'id' => 'adm-bp-settings-cache',
  1147. ),
  1148. 'params' => array (
  1149. 'remove_form' => '1',
  1150. 'csrf' => array(
  1151. 'disable' => true
  1152. )
  1153. ),
  1154. 'inputs' => array (
  1155. 'cache_lifetime' => array(
  1156. 'type' => 'text',
  1157. 'name' => 'cache_lifetime',
  1158. 'caption' => _t('_adm_bp_txt_page_cache_lifetime'),
  1159. 'info' => _t('_adm_bp_dsc_page_cache_lifetime'),
  1160. 'value' => isset($aPage['cache_lifetime']) ? $aPage['cache_lifetime'] : 0,
  1161. 'required' => '',
  1162. 'attrs' => array(
  1163. 'disabled' => isset($aPage['cache_editable']) && (int)$aPage['cache_editable'] == 0 ? 'disabled' : ''
  1164. ),
  1165. 'db' => array (
  1166. 'pass' => 'Int',
  1167. )
  1168. ),
  1169. )
  1170. );
  1171. if($bInputsOnly)
  1172. return $aForm['inputs'];
  1173. $oForm = new BxTemplStudioFormView($aForm);
  1174. return $oForm->getCode();
  1175. }
  1176. protected function getSettingsCacheFields($aPage = array(), $bCreate = true)
  1177. {
  1178. return $this->getSettingsCache($aPage, $bCreate, true);
  1179. }
  1180. protected function getSettingsSeo($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1181. {
  1182. $aForm = array(
  1183. 'form_attrs' => array(
  1184. 'id' => 'adm-bp-settings-seo',
  1185. ),
  1186. 'params' => array (
  1187. 'remove_form' => '1',
  1188. 'csrf' => array(
  1189. 'disable' => true
  1190. )
  1191. ),
  1192. 'inputs' => array (
  1193. 'meta_title' => array(
  1194. 'type' => 'text',
  1195. 'name' => 'meta_title',
  1196. 'caption' => _t('_adm_bp_txt_page_meta_title'),
  1197. 'value' => isset($aPage['meta_title']) ? $aPage['meta_title'] : '',
  1198. 'db' => array (
  1199. 'pass' => 'Xss',
  1200. ),
  1201. ),
  1202. 'meta_description' => array(
  1203. 'type' => 'textarea',
  1204. 'name' => 'meta_description',
  1205. 'caption' => _t('_adm_bp_txt_page_meta_description'),
  1206. 'info' => _t('_adm_bp_dsc_page_meta_description'),
  1207. 'value' => isset($aPage['meta_description']) ? $aPage['meta_description'] : '',
  1208. 'db' => array (
  1209. 'pass' => 'Xss',
  1210. ),
  1211. ),
  1212. 'meta_keywords' => array(
  1213. 'type' => 'textarea',
  1214. 'name' => 'meta_keywords',
  1215. 'caption' => _t('_adm_bp_txt_page_meta_keywords'),
  1216. 'info' => _t('_adm_bp_dsc_page_meta_keywords'),
  1217. 'value' => isset($aPage['meta_keywords']) ? $aPage['meta_keywords'] : '',
  1218. 'db' => array (
  1219. 'pass' => 'Xss',
  1220. ),
  1221. ),
  1222. 'meta_robots' => array(
  1223. 'type' => 'text',
  1224. 'name' => 'meta_robots',
  1225. 'caption' => _t('_adm_bp_txt_page_meta_robots'),
  1226. 'info' => _t('_adm_bp_dsc_page_meta_robots'),
  1227. 'value' => isset($aPage['meta_robots']) ? $aPage['meta_robots'] : '',
  1228. 'required' => '0',
  1229. 'db' => array (
  1230. 'pass' => 'Xss',
  1231. )
  1232. )
  1233. )
  1234. );
  1235. if($bInputsOnly)
  1236. return $aForm['inputs'];
  1237. $oForm = new BxTemplStudioFormView($aForm);
  1238. return $oForm->getCode();
  1239. }
  1240. protected function getSettingsSeoFields($aPage = array(), $bCreate = true)
  1241. {
  1242. return $this->getSettingsSeo($aPage, $bCreate, true);
  1243. }
  1244. protected function getSettingsInjections($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1245. {
  1246. $aForm = array(
  1247. 'form_attrs' => array(
  1248. 'id' => 'adm-bp-injections-seo',
  1249. ),
  1250. 'params' => array (
  1251. 'remove_form' => '1',
  1252. 'csrf' => array(
  1253. 'disable' => true
  1254. )
  1255. ),
  1256. 'inputs' => array (
  1257. 'inj_head' => array(
  1258. 'type' => 'textarea',
  1259. 'name' => 'inj_head',
  1260. 'caption' => _t('_adm_bp_txt_page_inj_head'),
  1261. 'info' => _t('_adm_bp_dsc_page_inj_head'),
  1262. 'value' => isset($aPage['inj_head']) ? $aPage['inj_head'] : '',
  1263. 'code' => 1,
  1264. 'db' => array (
  1265. 'pass' => 'XssHtml',
  1266. ),
  1267. ),
  1268. 'inj_footer' => array(
  1269. 'type' => 'textarea',
  1270. 'name' => 'inj_footer',
  1271. 'caption' => _t('_adm_bp_txt_page_inj_footer'),
  1272. 'info' => _t('_adm_bp_dsc_page_inj_footer'),
  1273. 'value' => isset($aPage['inj_footer']) ? $aPage['inj_footer'] : '',
  1274. 'code' => 1,
  1275. 'db' => array (
  1276. 'pass' => 'XssHtml',
  1277. ),
  1278. )
  1279. )
  1280. );
  1281. if($bInputsOnly)
  1282. return $aForm['inputs'];
  1283. $oForm = new BxTemplStudioFormView($aForm);
  1284. return $oForm->getCode();
  1285. }
  1286. protected function getSettingsInjectionsFields($aPage = array(), $bCreate = true)
  1287. {
  1288. return $this->getSettingsInjections($aPage, $bCreate, true);
  1289. }
  1290. protected function getBlockIcon($aBlock)
  1291. {
  1292. $sIcon = $sIconUrl = "";
  1293. $sResult = '';
  1294. switch($aBlock['type']) {
  1295. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1296. $sResult = 'far file-alt';
  1297. break;
  1298. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1299. $sResult = 'code';
  1300. break;
  1301. case BX_DOL_STUDIO_BP_BLOCK_CREATIVE:
  1302. $sResult = 'object-group';
  1303. break;
  1304. case BX_DOL_STUDIO_BP_BLOCK_BENTO_GRID:
  1305. $sResult = 'fa-grip-horizontal';
  1306. break;
  1307. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1308. $sResult = 'rss';
  1309. break;
  1310. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1311. $sResult = 'far image';
  1312. break;
  1313. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1314. $sResult = 'globe';
  1315. break;
  1316. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1317. $sResult = 'list-alt';
  1318. break;
  1319. case BX_DOL_STUDIO_BP_BLOCK_WIKI:
  1320. $sResult = 'file-word';
  1321. break;
  1322. case BX_DOL_STUDIO_BP_BLOCK_CUSTOM:
  1323. $sResult = 'file';
  1324. break;
  1325. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1326. $sResult = $this->getModuleIcon($aBlock['module'], 'page');
  1327. break;
  1328. }
  1329. if(strpos($sResult, '.') === false)
  1330. $sIcon = $sResult;
  1331. else
  1332. $sIconUrl = $sResult;
  1333. return array($sIcon, $sIconUrl);
  1334. }
  1335. protected function getBlockModule($aBlock)
  1336. {
  1337. return $aBlock['module'] != BX_DOL_STUDIO_BP_SKELETONS ? $aBlock['module'] : BX_DOL_STUDIO_MODULE_CUSTOM;
  1338. }
  1339. protected function getBlockContent($aBlock)
  1340. {
  1341. $aFields = array();
  1342. switch($aBlock['type']) {
  1343. case BX_DOL_STUDIO_BP_BLOCK_CUSTOM:
  1344. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1345. case BX_DOL_STUDIO_BP_BLOCK_BENTO_GRID:
  1346. $aFields = [
  1347. 'content' => [
  1348. 'type' => 'textarea',
  1349. 'name' => 'content',
  1350. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1351. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1352. 'value' => $aBlock['content'],
  1353. 'required' => '0',
  1354. 'code' => 1,
  1355. 'attrs' => [
  1356. 'class' => 'bx-form-input-textarea-codemirror'
  1357. ],
  1358. 'db' => [
  1359. 'pass' => 'XssHtml',
  1360. ],
  1361. ],
  1362. ];
  1363. break;
  1364. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1365. $aFields = [
  1366. 'content' => [
  1367. 'type' => 'textarea',
  1368. 'name' => 'content',
  1369. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1370. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1371. 'value' => $aBlock['content'],
  1372. 'required' => '0',
  1373. 'html' => 2,
  1374. 'attrs' => [
  1375. 'id' => $this->aHtmlIds['edit_block_editor_id']
  1376. ],
  1377. 'db' => [
  1378. 'pass' => 'XssHtml',
  1379. ],
  1380. ],
  1381. 'attachments' => [
  1382. 'type' => 'files',
  1383. 'name' => 'attachments',
  1384. 'storage_object' => $this->sStorage,
  1385. 'images_transcoder' => $this->sTranscoder,
  1386. 'uploaders' => $this->aUploaders,
  1387. 'multiple' => true,
  1388. 'content_id' => $aBlock['id'],
  1389. 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('bp_fgt_attachments.html', [
  1390. 'js_object' => $this->getPageJsObject(),
  1391. 'name' => 'attachments',
  1392. 'editor_id' => $this->aHtmlIds['edit_block_editor_id'],
  1393. ]),
  1394. 'caption' => _t('_adm_bp_txt_block_content_attachments_html')
  1395. ]
  1396. ];
  1397. break;
  1398. case BX_DOL_STUDIO_BP_BLOCK_CREATIVE:
  1399. $oTemplate = BxDolStudioTemplate::getInstance();
  1400. $sContent = $oTemplate->parseHtmlByName('bp_block_skeleton_creative.html', [
  1401. 'html_id' => $this->aHtmlIds['edit_block_builder_id'],
  1402. 'content_html' => $aBlock['content'],
  1403. 'content_data' => json_encode([
  1404. 'pages' => [
  1405. ['component' => $aBlock['content']]
  1406. ]
  1407. ])
  1408. ]);
  1409. $aFields = [
  1410. 'content' => [
  1411. 'type' => 'custom',
  1412. 'name' => 'content',
  1413. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1414. 'content' => $sContent,
  1415. 'required' => '0',
  1416. 'db' => [
  1417. 'pass' => 'XssHtml',
  1418. ],
  1419. ],
  1420. ];
  1421. break;
  1422. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1423. $aFields = [
  1424. 'content' => [
  1425. 'type' => 'textarea_translatable',
  1426. 'name' => 'content',
  1427. 'caption' => _t('_adm_bp_txt_block_content_lang'),
  1428. 'info' => _t('_adm_bp_dsc_block_content_lang'),
  1429. 'value' => $aBlock['content'],
  1430. 'required' => '0',
  1431. 'html' => 2,
  1432. 'db' => [
  1433. 'pass' => 'XssHtml',
  1434. ],
  1435. ],
  1436. ];
  1437. break;
  1438. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1439. $iImageId = $sImageAlign = '';
  1440. if($aBlock['content'] != '')
  1441. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1442. $aFields = [
  1443. 'content' => [
  1444. 'type' => 'hidden',
  1445. 'name' => 'content',
  1446. 'value' => '',
  1447. 'db' => [
  1448. 'pass' => 'Xss',
  1449. ],
  1450. ],
  1451. 'image_file' => [
  1452. 'type' => 'files',
  1453. 'name' => 'image_file',
  1454. 'storage_object' => BX_DOL_STORAGE_OBJ_IMAGES,
  1455. 'images_transcoder' => 'sys_image_resize',
  1456. 'uploaders' => ['sys_html5'],
  1457. 'multiple' => false,
  1458. 'content_id' => $aBlock['id'],
  1459. 'ghost_template' => BxTemplStudioFunctions::getInstance()->getDefaultGhostTemplate('image_file'),
  1460. 'caption' => _t('_adm_bp_txt_block_content_image_file'),
  1461. ],
  1462. 'image_align' => [
  1463. 'type' => 'select',
  1464. 'name' => 'image_align',
  1465. 'caption' => _t('_adm_bp_txt_block_content_image_align'),
  1466. 'info' => '',
  1467. 'value' => $sImageAlign,
  1468. 'values' => [
  1469. ['key' => '', 'value' => _t('_adm_bp_txt_block_content_image_align_empty')],
  1470. ['key' => 'left', 'value' => _t('_adm_bp_txt_block_content_image_align_left')],
  1471. ['key' => 'center', 'value' => _t('_adm_bp_txt_block_content_image_align_center')],
  1472. ['key' => 'right', 'value' => _t('_adm_bp_txt_block_content_image_align_right')],
  1473. ],
  1474. 'required' => '0',
  1475. 'db' => [
  1476. 'pass' => 'Xss',
  1477. ],
  1478. ],
  1479. ];
  1480. break;
  1481. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1482. $sRssUrl = $sRssLength = '';
  1483. if($aBlock['content'] != '')
  1484. list($sRssUrl, $sRssLength) = explode($this->sParamsDivider, $aBlock['content']);
  1485. $aFields = [
  1486. 'content' => [
  1487. 'type' => 'hidden',
  1488. 'name' => 'content',
  1489. 'value' => '',
  1490. 'db' => [
  1491. 'pass' => 'Xss',
  1492. ],
  1493. ],
  1494. 'rss_url' => [
  1495. 'type' => 'text',
  1496. 'name' => 'rss_url',
  1497. 'caption' => _t('_adm_bp_txt_block_content_rss_url'),
  1498. 'info' => _t('_adm_bp_dsc_block_content_rss_url'),
  1499. 'value' => $sRssUrl,
  1500. 'required' => '0',
  1501. 'db' => [
  1502. 'pass' => 'Xss',
  1503. ],
  1504. ],
  1505. 'rss_length' => [
  1506. 'type' => 'text',
  1507. 'name' => 'rss_length',
  1508. 'caption' => _t('_adm_bp_txt_block_content_rss_length'),
  1509. 'info' => _t('_adm_bp_dsc_block_content_rss_length'),
  1510. 'value' => $sRssLength,
  1511. 'required' => '0',
  1512. 'db' => [
  1513. 'pass' => 'Int',
  1514. ],
  1515. ],
  1516. ];
  1517. break;
  1518. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1519. $aFields = [
  1520. 'content' => [
  1521. 'type' => 'select',
  1522. 'name' => 'content',
  1523. 'caption' => _t('_adm_bp_txt_block_content_menu'),
  1524. 'info' => '',
  1525. 'value' => $aBlock['content'],
  1526. 'values' => [],
  1527. 'required' => '0',
  1528. 'db' => [
  1529. 'pass' => 'Xss',
  1530. ],
  1531. ]
  1532. ];
  1533. $sGroup = '';
  1534. $aMenus = $this->oDb->getMenus(true);
  1535. foreach($aMenus as $sKey => $aMenu) {
  1536. if($sGroup != $aMenu['module']) {
  1537. if(!empty($sGroup))
  1538. $aFields['content']['values'][$sGroup . '_end'] = ['type' => 'group_end'];
  1539. $sGroup = $aMenu['module'];
  1540. $aFields['content']['values'][$sGroup . '_beg'] = ['type' => 'group_header', 'value' => BxDolStudioUtils::getModuleTitle($sGroup)];
  1541. }
  1542. $aFields['content']['values'][$sKey] = _t($aMenu['title']);
  1543. }
  1544. $aFields['content']['values'] = array_merge(['' => _t('_adm_bp_txt_block_content_menu_empty')], $aFields['content']['values']);
  1545. break;
  1546. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1547. $aService = ['module' => '', 'method' => ''];
  1548. if($aBlock['content'] != '')
  1549. $aService = unserialize($aBlock['content']);
  1550. $aFields = [
  1551. 'service_module' => [
  1552. 'type' => 'value',
  1553. 'name' => 'service_module',
  1554. 'caption' => _t('_adm_bp_txt_block_content_service_module'),
  1555. 'value' => $this->getModuleTitle($aService['module'])
  1556. ],
  1557. 'service_method' => [
  1558. 'type' => 'value',
  1559. 'name' => 'service_method',
  1560. 'caption' => _t('_adm_bp_txt_block_content_service_method'),
  1561. 'value' => $aService['method']
  1562. ]
  1563. ];
  1564. break;
  1565. }
  1566. return $aFields;
  1567. }
  1568. protected function getBlockList($sModule)
  1569. {
  1570. if(empty($sModule))
  1571. return '';
  1572. $sJsObject = $this->getPageJsObject();
  1573. $oTemplate = BxDolStudioTemplate::getInstance();
  1574. $oForm = new BxTemplStudioFormView(array());
  1575. $aInputCheckbox = [
  1576. 'type' => 'checkbox',
  1577. 'name' => 'blocks[]',
  1578. 'attrs' => [
  1579. 'onChange' => 'javascript:' . $sJsObject . '.onSelectBlock(this);'
  1580. ],
  1581. 'value' => ''
  1582. ];
  1583. $aTmplParams = [
  1584. 'html_block_list_id' => $this->aHtmlIds['block_list_id'] . $sModule,
  1585. 'bx_repeat:blocks' => []
  1586. ];
  1587. $aBlocks = $this->getBlocks($sModule);
  1588. foreach($aBlocks as $aBlock) {
  1589. list($sIcon, $sIconUrl) = $this->getBlockIcon($aBlock);
  1590. $aInputCheckbox['value'] = $aBlock['id'];
  1591. $aTmplParams['bx_repeat:blocks'][] = [
  1592. 'js_object' => $sJsObject,
  1593. 'html_id' => $this->aHtmlIds['block_id'] . $aBlock['id'],
  1594. 'bx_if:is_inactive' => array(
  1595. 'condition' => false,
  1596. 'content' => [true]
  1597. ),
  1598. 'bx_if:show_link' => [
  1599. 'condition' => false,
  1600. 'content' => [true]
  1601. ],
  1602. 'bx_if:show_text' => [
  1603. 'condition' => true,
  1604. 'content' => [
  1605. 'title' => _t(!empty($aBlock['title_system']) ? $aBlock['title_system'] : $aBlock['title']),
  1606. ]
  1607. ],
  1608. 'bx_if:show_api' => [
  1609. 'condition' => false,
  1610. 'content' => [true]
  1611. ],
  1612. 'bx_if:image' => [
  1613. 'condition' => (bool)$sIconUrl,
  1614. 'content' => array('icon_url' => $sIconUrl),
  1615. ],
  1616. 'bx_if:icon' => [
  1617. 'condition' => (bool)$sIcon,
  1618. 'content' => ['icon' => $sIcon],
  1619. ],
  1620. 'module' => $this->getModuleTitle($aBlock['module']),
  1621. 'visible_for' => _t('_adm_bp_txt_visible_for', BxDolStudioUtils::getVisibilityTitle($aBlock['visible_for_levels'])),
  1622. 'bx_if:show_checkbox' => [
  1623. 'condition' => true,
  1624. 'content' => [
  1625. 'content' => $oForm->genRow($aInputCheckbox)
  1626. ]
  1627. ],
  1628. 'bx_if:show_drag_handle' => [
  1629. 'condition' => false,
  1630. 'content' => []
  1631. ]
  1632. ];
  1633. }
  1634. return $oTemplate->parseHtmlByName('bp_blocks_list.html', $aTmplParams);
  1635. }
  1636. protected function onBlockDelete($aBlock)
  1637. {
  1638. if($aBlock['module'] != BX_DOL_STUDIO_MODULE_CUSTOM)
  1639. return;
  1640. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['title']);
  1641. //--- Process Lang block
  1642. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && $aBlock['content'] != '')
  1643. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['content']);
  1644. //--- Process Image block
  1645. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && $aBlock['content'] != '') {
  1646. $iImageId = $sImageAlign = '';
  1647. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1648. if(is_numeric($iImageId) && (int)$iImageId != 0)
  1649. BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$iImageId, 0);
  1650. }
  1651. }
  1652. protected function getBlocks($sModule)
  1653. {
  1654. $aBlocks = array();
  1655. $this->oDb->getBlocks(array('type' => 'by_module_to_copy', 'value' => $sModule), $aBlocks, false);
  1656. return $aBlocks;
  1657. }
  1658. protected function _getPageCreateForm()
  1659. {
  1660. $oTemplate = BxDolStudioTemplate::getInstance();
  1661. $sForm = 'adm-bp-page-create';
  1662. $aForm = array(
  1663. 'form_attrs' => array(
  1664. 'id' => $sForm,
  1665. 'name' => $sForm,
  1666. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionPageCreate,
  1667. 'method' => 'post'
  1668. ),
  1669. 'params' => array (
  1670. 'db' => array(
  1671. 'table' => 'sys_objects_page',
  1672. 'key' => 'id',
  1673. 'uri' => '',
  1674. 'uri_title' => '',
  1675. 'submit_name' => 'do_submit'
  1676. ),
  1677. 'display' => $sForm
  1678. ),
  1679. 'inputs' => array (
  1680. 'module' => array(
  1681. 'type' => 'hidden',
  1682. 'name' => 'module',
  1683. 'value' => BX_DOL_STUDIO_MODULE_CUSTOM,
  1684. 'db' => array (
  1685. 'pass' => 'Xss',
  1686. ),
  1687. ),
  1688. 'deletable' => array(
  1689. 'type' => 'hidden',
  1690. 'name' => 'deletable',
  1691. 'value' => 1,
  1692. 'db' => array (
  1693. 'pass' => 'Int',
  1694. ),
  1695. ),
  1696. 'settings' => array(
  1697. 'type' => 'custom',
  1698. 'name' => 'settings',
  1699. 'content' => $oTemplate->parseHtmlByName('bp_edit_page_form.html', $this->_getTmplVarsPageSettings()),
  1700. ),
  1701. )
  1702. );
  1703. return new BxTemplStudioFormView($aForm);
  1704. }
  1705. protected function _getPageEditForm()
  1706. {
  1707. $oTemplate = BxDolStudioTemplate::getInstance();
  1708. $sForm = 'adm-bp-page-edit';
  1709. $aForm = array(
  1710. 'form_attrs' => array(
  1711. 'id' => $sForm,
  1712. 'name' => $sForm,
  1713. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionPageEdit,
  1714. 'method' => 'post'
  1715. ),
  1716. 'params' => array (
  1717. 'db' => array(
  1718. 'table' => 'sys_objects_page',
  1719. 'key' => 'id',
  1720. 'uri' => '',
  1721. 'uri_title' => '',
  1722. 'submit_name' => 'do_submit'
  1723. ),
  1724. 'display' => $sForm
  1725. ),
  1726. 'inputs' => array (
  1727. 'settings' => array(
  1728. 'type' => 'custom',
  1729. 'name' => 'settings',
  1730. 'content' => $oTemplate->parseHtmlByName('bp_edit_page_form.html', $this->_getTmplVarsPageSettings($this->aPageRebuild, false)),
  1731. ),
  1732. )
  1733. );
  1734. return new BxTemplStudioFormView($aForm);
  1735. }
  1736. protected function _getTmplVarsBlockPanelTop()
  1737. {
  1738. $sJsObject = $this->getPageJsObject();
  1739. $oForm = new BxTemplStudioFormView(array());
  1740. $aPages = $this->oDb->getPages(array('type' => 'by_module', 'value' => $this->sType));
  1741. $aCounter = array();
  1742. $this->oDb->getBlocks(array('type' => 'counter_by_pages'), $aCounter, false);
  1743. $aInputPagesValues = [];
  1744. foreach($aPages as $aPage) {
  1745. $sTitle = _t($aPage['title_system']);
  1746. if(empty($sTitle))
  1747. $sTitle = _t($aPage['title']);
  1748. $aInputPagesValues[] = array(
  1749. 'key' => $aPage['object'],
  1750. 'value' => $sTitle . " (" . (isset($aCounter[$aPage['object']]) ? $aCounter[$aPage['object']] : "0") . ")"
  1751. );
  1752. }
  1753. usort($aInputPagesValues, function($aV1, $aV2) {
  1754. return strcmp($aV1['value'], $aV2['value']);
  1755. });
  1756. $aInputPages = array(
  1757. 'type' => 'select',
  1758. 'name' => 'page',
  1759. 'attrs' => array(
  1760. 'onChange' => 'javascript:' . $this->getPageJsObject() . '.onChangePage(this)'
  1761. ),
  1762. 'value' => $this->sPage,
  1763. 'values' => array_merge([[
  1764. 'key' => '',
  1765. 'value' => _t('_adm_bp_txt_select_page')]
  1766. ], $aInputPagesValues)
  1767. );
  1768. $aTmplVarsActions = array();
  1769. if(($this->sPage != '' && !empty($this->aPageRebuild)) !== false)
  1770. $aTmplVarsActions = $this->_getTmplVarsBlockPanelTopActions();
  1771. return array(
  1772. 'js_object' => $this->getPageJsObject(),
  1773. 'selector' => $oForm->genRow($aInputPages),
  1774. 'action_page_create' => $this->sActionPageCreate,
  1775. 'bx_if:show_actions' => array(
  1776. 'condition' => $this->sPage != '',
  1777. 'content' => $aTmplVarsActions
  1778. )
  1779. );
  1780. }
  1781. protected function _getTmplVarsBlockPanelTopActions()
  1782. {
  1783. $sJsObject = $this->getPageJsObject();
  1784. $oPermalinks = BxDolPermalinks::getInstance();
  1785. return [
  1786. 'js_object' => $sJsObject,
  1787. 'bx_if:can_view' => [
  1788. 'condition' => !empty($this->aPageRebuild['url']),
  1789. 'content' => [
  1790. 'url_view' => bx_absolute_url($oPermalinks->permalink($this->aPageRebuild['url'])),
  1791. ]
  1792. ],
  1793. 'action_page_edit' => $this->sActionPageEdit,
  1794. 'bx_if:can_delete' => [
  1795. 'condition' => (int)$this->aPageRebuild['deletable'] == 1,
  1796. 'content' => [
  1797. 'js_object' => $sJsObject
  1798. ]
  1799. ],
  1800. 'action_block_create' => $this->sActionBlockCreate,
  1801. ];
  1802. }
  1803. protected function _getTmplVarsPageSettings($aPage = array(), $bCreate = true)
  1804. {
  1805. $sJsObject = $this->getPageJsObject();
  1806. $aTmplParams = array(
  1807. 'js_object' => $sJsObject,
  1808. 'menu' => array(),
  1809. 'html_settings_groups_id' => $this->aHtmlIds['settings_groups_id'],
  1810. 'bx_repeat:settings_groups' => array(),
  1811. 'submit' => _t($bCreate ? '_adm_bp_btn_page_create' : '_adm_bp_btn_page_apply')
  1812. );
  1813. foreach($this->aPageSettings as $aSetting) {
  1814. //--- get menu items
  1815. $aTmplParams['menu'][$aSetting['name']] = array(
  1816. 'name' => $aSetting['name'],
  1817. 'icon' => '',
  1818. 'onclick' => $sJsObject . '.onChangeSettingGroup(\'' . $aSetting['name'] . '\', this);',
  1819. 'title' => $aSetting['title'],
  1820. 'selected' => isset($aSetting['active']) && (int)$aSetting['active'] == 1
  1821. );
  1822. //--- get settings
  1823. $aTmplParams['bx_repeat:settings_groups'][] = array(
  1824. 'html_settings_group_id' => $this->aHtmlIds['settings_group_id'] . $aSetting['name'],
  1825. 'bx_if:hidden' => array(
  1826. 'condition' => $aSetting['active'] != 1,
  1827. 'content' => array()
  1828. ),
  1829. 'content' => $this->{'getSettings' . $this->getClassName($aSetting['name'])}($aPage, $bCreate)
  1830. );
  1831. }
  1832. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aTmplParams['menu']));
  1833. $aTmplParams['menu'] = $oMenu->getCode();
  1834. return $aTmplParams;
  1835. }
  1836. protected function getIndexingDataForBlock($sType, $sContent)
  1837. {
  1838. $aBlock = array();
  1839. switch($sType) {
  1840. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1841. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1842. $aBlock['text'] = trim(strip_tags($sContent));
  1843. $aBlock['text_updated'] = time();
  1844. break;
  1845. }
  1846. return $aBlock;
  1847. }
  1848. protected function onPageChanged($oForm, $aPage)
  1849. {
  1850. $this->oDb->cleanCache('sys_pages_objects_data');
  1851. $this->oDb->cleanCache('sys_pages_uri_object_map');
  1852. $this->oDb->cleanCache('sys_pages_urirewrite_object_map');
  1853. }
  1854. }
  1855. /** @} */