BxBaseStudioBuilderPage.php 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123
  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. 'description' => array(
  546. 'type' => 'text_translatable',
  547. 'name' => 'description',
  548. 'caption' => _t('_adm_bp_txt_block_description'),
  549. 'info' => _t('_adm_bp_dsc_block_description'),
  550. 'value' => $aBlock['description'],
  551. 'required' => '0',
  552. 'db' => array (
  553. 'pass' => 'Xss',
  554. ),
  555. ),
  556. 'icon' => array(
  557. 'type' => 'textarea',
  558. 'name' => 'icon',
  559. 'caption' => _t('_adm_bp_txt_block_icon'),
  560. 'info' => _t('_adm_bp_dsc_block_icon'),
  561. 'value' => $aBlock['icon'],
  562. 'code' => 1,
  563. 'required' => '0',
  564. 'db' => array (
  565. 'pass' => 'Xss',
  566. ),
  567. 'attrs' => array('class' => 'bx-form-input-textarea-small'),
  568. ),
  569. 'designbox_id' => array(
  570. 'type' => 'select',
  571. 'name' => 'designbox_id',
  572. 'caption' => _t('_adm_bp_txt_block_designbox'),
  573. 'info' => '',
  574. 'value' => $this->sSelectKeyPrefix . $aBlock['designbox_id'],
  575. 'values' => array(
  576. array('key' => '', 'value' => _t('_adm_bp_txt_block_designbox_empty')),
  577. ),
  578. 'required' => '1',
  579. 'db' => array (
  580. 'pass' => 'Xss',
  581. ),
  582. 'checker' => array (
  583. 'func' => 'avail',
  584. 'params' => array(),
  585. 'error' => _t('_adm_bp_err_block_designbox'),
  586. ),
  587. ),
  588. 'async' => array(
  589. 'type' => 'select',
  590. 'name' => 'async',
  591. 'caption' => _t('_adm_bp_txt_block_async'),
  592. 'info' => '',
  593. 'value' => isset($aBlock['async']) ? $aBlock['async'] : 0,
  594. 'required' => '0',
  595. 'db' => array (
  596. 'pass' => 'Int',
  597. ),
  598. ),
  599. 'submenu' => array(
  600. 'type' => 'select',
  601. 'name' => 'submenu',
  602. 'caption' => _t('_adm_bp_txt_block_submenu'),
  603. 'info' => '',
  604. 'value' => isset($aBlock['submenu']) ? $aBlock['submenu'] : '',
  605. 'required' => '0',
  606. 'db' => array (
  607. 'pass' => 'Xss',
  608. ),
  609. ),
  610. 'tabs' => array(
  611. 'type' => 'switcher',
  612. 'name' => 'tabs',
  613. 'caption' => _t('_adm_bp_txt_block_tabs'),
  614. 'info' => '',
  615. 'value' => '1',
  616. 'checked' => $aBlock['tabs'] == '1',
  617. 'db' => array (
  618. 'pass' => 'Int',
  619. )
  620. ),
  621. 'hidden_on' => array(
  622. 'type' => 'select_multiple',
  623. 'name' => 'hidden_on',
  624. 'caption' => _t('_adm_bp_txt_block_hidden_on'),
  625. 'info' => '',
  626. 'value' => (int)$aBlock['hidden_on'],
  627. 'values' => array(
  628. BX_DB_HIDDEN_PHONE => _t('_adm_bp_txt_block_hidden_on_phone'),
  629. BX_DB_HIDDEN_TABLET => _t('_adm_bp_txt_block_hidden_on_tablet'),
  630. BX_DB_HIDDEN_DESKTOP => _t('_adm_bp_txt_block_hidden_on_desktop'),
  631. BX_DB_HIDDEN_MOBILE => _t('_adm_bp_txt_block_hidden_on_mobile')
  632. ),
  633. 'db' => array (
  634. 'pass' => 'Set',
  635. )
  636. ),
  637. 'visible_for' => array(
  638. 'type' => 'select',
  639. 'name' => 'visible_for',
  640. 'caption' => _t('_adm_bp_txt_block_visible_for'),
  641. 'info' => '',
  642. 'value' => $aBlock['visible_for_levels'] == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
  643. 'values' => array(
  644. array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_bp_txt_block_visible_for_all')),
  645. array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_bp_txt_block_visible_for_selected')),
  646. ),
  647. 'required' => '0',
  648. 'attrs' => array(
  649. 'onchange' => $sJsObject . '.onChangeVisibleFor(this)'
  650. ),
  651. 'db' => array (
  652. 'pass' => 'Xss',
  653. )
  654. ),
  655. 'visible_for_levels' => array(
  656. 'type' => 'checkbox_set',
  657. 'name' => 'visible_for_levels',
  658. 'caption' => _t('_adm_bp_txt_block_visible_for_levels'),
  659. 'info' => _t('_adm_bp_dsc_block_visible_for_levels'),
  660. 'value' => array(),
  661. 'values' => array(),
  662. 'tr_attrs' => array(
  663. 'style' => $aBlock['visible_for_levels'] == BX_DOL_INT_MAX ? 'display:none' : ''
  664. ),
  665. 'db' => array (
  666. 'pass' => 'Int',
  667. )
  668. ),
  669. 'content_empty' => array(
  670. 'type' => 'text_translatable',
  671. 'name' => 'content_empty',
  672. 'caption' => _t('_adm_bp_txt_block_content_empty'),
  673. 'info' => _t('_adm_bp_dsc_block_content_empty'),
  674. 'value' => $aBlock['content_empty'],
  675. 'db' => array (
  676. 'pass' => 'Xss',
  677. ),
  678. ),
  679. 'help' => array(
  680. 'type' => 'textarea_translatable',
  681. 'name' => 'help',
  682. 'caption' => _t('_adm_bp_txt_block_help'),
  683. 'info' => '',
  684. 'value' => $aBlock['help'],
  685. 'required' => '0',
  686. 'html' => 2,
  687. 'db' => array (
  688. 'pass' => 'Xss',
  689. ),
  690. ),
  691. 'class' => array(
  692. 'type' => 'text',
  693. 'name' => 'class',
  694. 'caption' => _t('_adm_bp_txt_block_class'),
  695. 'info' => '',
  696. 'value' => $aBlock['class'],
  697. 'required' => '0',
  698. 'db' => array (
  699. 'pass' => 'Xss',
  700. ),
  701. ),
  702. 'cache_lifetime' => array(
  703. 'type' => 'text',
  704. 'name' => 'cache_lifetime',
  705. 'caption' => _t('_adm_bp_txt_block_cache_lifetime'),
  706. 'info' => '',
  707. 'value' => isset($aBlock['cache_lifetime']) ? $aBlock['cache_lifetime'] : 0,
  708. 'required' => '0',
  709. 'db' => array (
  710. 'pass' => 'Int',
  711. ),
  712. ),
  713. 'active' => array(
  714. 'type' => 'switcher',
  715. 'name' => 'active',
  716. 'caption' => _t('_adm_bp_txt_block_active'),
  717. 'info' => '',
  718. 'value' => '1',
  719. 'checked' => $aBlock['active'] == '1',
  720. 'db' => array (
  721. 'pass' => 'Int',
  722. )
  723. ),
  724. 'active_api' => array(
  725. 'type' => 'switcher',
  726. 'name' => 'active_api',
  727. 'caption' => _t('_adm_bp_txt_block_active_api'),
  728. 'info' => '',
  729. 'value' => '1',
  730. 'checked' => $aBlock['active_api'] == '1',
  731. 'db' => array (
  732. 'pass' => 'Int',
  733. )
  734. ),
  735. 'controls' => array(
  736. 'name' => 'controls',
  737. 'type' => 'input_set',
  738. array(
  739. 'type' => 'submit',
  740. 'name' => 'do_submit',
  741. 'value' => _t('_adm_bp_btn_block_save')
  742. ),
  743. array (
  744. 'type' => 'reset',
  745. 'name' => 'close',
  746. 'value' => _t('_adm_bp_btn_block_cancel'),
  747. 'attrs' => array(
  748. 'onclick' => $sJsObject . '.onEditBlockCancel(this)',
  749. 'class' => 'bx-def-margin-sec-left',
  750. ),
  751. )
  752. )
  753. )
  754. );
  755. $aDBoxes = array();
  756. $this->oDb->getDesignBoxes(array('type' => 'ordered'), $aDBoxes, false);
  757. foreach($aDBoxes as $aDBox)
  758. $aForm['inputs']['designbox_id']['values'][] = array('key' => $this->sSelectKeyPrefix . $aDBox['id'], 'value' => _t($aDBox['title']));
  759. $aContentPlaceholders = $this->oDb->getContentPlaceholders();
  760. $aForm['inputs']['async']['values'][] = array('key' => 0, 'value' => _t('_sys_no_async'));
  761. foreach ($aContentPlaceholders as $iKey => $sTitle)
  762. $aForm['inputs']['async']['values'][] = array('key' => $iKey, 'value' => _t($sTitle));
  763. $aSubmenus = $this->oDb->getBlockSubmenus();
  764. $aForm['inputs']['submenu']['values'][] = array('key' => '', 'value' => _t('_sys_menu_item_title_inherited'));
  765. $aForm['inputs']['submenu']['values'][] = array('key' => 'disabled', 'value' => _t('_sys_menu_item_title_disabled'));
  766. foreach ($aSubmenus as $sObject => $sTitle)
  767. $aForm['inputs']['submenu']['values'][] = array('key' => $sObject, 'value' => _t($sTitle));
  768. BxDolStudioUtils::getVisibilityValues($aBlock['visible_for_levels'], $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
  769. $aForm['inputs'] = $this->addInArray($aForm['inputs'], 'visible_for_levels', $this->getBlockContent($aBlock));
  770. if((int)$aBlock['deletable'] != 0)
  771. $aForm['inputs']['controls'][] = array (
  772. 'type' => 'reset',
  773. 'name' => 'close',
  774. 'value' => _t('_adm_bp_btn_block_delete'),
  775. 'attrs' => array(
  776. 'onclick' => $sJsObject . '.deleteBlock(' . $aBlock['id'] . ')',
  777. 'class' => 'bx-def-margin-sec-left',
  778. ),
  779. );
  780. $oForm = new BxTemplStudioFormView($aForm);
  781. $oForm->initChecker();
  782. if($oForm->isSubmittedAndValid()) {
  783. $this->onSaveBlock($oForm, $aBlock);
  784. // add indexing data
  785. $aBlockAddon = $this->getIndexingDataForBlock($aBlock['type'], $oForm->getCleanValue('content'));
  786. if($oForm->update($iId, $aBlockAddon) !== false)
  787. return array('eval' => $sJsObject . '.onEditBlock(oData)');
  788. else
  789. return array('msg' => _t('_adm_bp_err_block_edit'));
  790. }
  791. $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(
  792. 'action' => 'edit',
  793. 'form_id' => $aForm['form_attrs']['id'],
  794. 'form' => $oForm->getCode(true)
  795. )));
  796. return array('popup' => array('html' => $sContent, 'options' => array('onBeforeShow' => $sJsObject . '.onEditBlockBeforeShow($el)')));
  797. }
  798. protected function actionBlockDelete()
  799. {
  800. $sJsObject = $this->getPageJsObject();
  801. $iId = (int)bx_get('id');
  802. $aBlock = array();
  803. $this->oDb->getBlocks(array('type' => 'by_id', 'value' => $iId), $aBlock, false);
  804. if(empty($aBlock) || !is_array($aBlock))
  805. return array('msg' => _t('_adm_bp_err_block_not_found'));
  806. if((int)$aBlock['deletable'] == 0)
  807. return array('msg' => _t('_adm_bp_err_block_not_deletable'));
  808. if(!$this->oDb->deleteBlocks(array('type' => 'by_id', 'value' => $iId)))
  809. return array('msg' => _t('_adm_bp_err_block_delete'));
  810. $this->onBlockDelete($aBlock);
  811. return array('eval' => $sJsObject . '.onDeleteBlock(' . $iId . ', oData)');
  812. }
  813. protected function actionUriGet()
  814. {
  815. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  816. $aLanguages = $oLanguage->getLanguages();
  817. $sLanguageDef = $oLanguage->getDefaultLangName();
  818. $sLanguageCur = $oLanguage->getCurrentLangName(false);
  819. $aValues = array();
  820. foreach($aLanguages as $sName => $sTitle)
  821. if(($mixedValue = bx_get($sName)) !== false)
  822. $aValues[$sName] = bx_process_input($mixedValue);
  823. $sUri = "";
  824. if(($mixedValue = bx_get('uri')) !== false)
  825. $sUri = bx_process_input($mixedValue);
  826. else if(array_key_exists('en', $aValues) && $aValues['en'] != '')
  827. $sUri = $aValues['en'];
  828. else if(array_key_exists($sLanguageDef, $aValues) && $aValues[$sLanguageDef] != '')
  829. $sUri = $aValues[$sLanguageDef];
  830. else if(array_key_exists($sLanguageCur, $aValues) && $aValues[$sLanguageCur] != '')
  831. $sUri = $aValues[$sLanguageCur];
  832. else if(count($aValues) > 0)
  833. foreach($aValues as $sValue)
  834. if(!empty($sValue)) {
  835. $sUri = $sValue;
  836. break;
  837. }
  838. $sUri = $sUri != "" ? uriGenerate($sUri, 'sys_objects_page', 'uri') : "";
  839. $sUrl = BxDolPermalinks::getInstance()->permalink($this->sPageBaseUrl . $sUri);
  840. return array('eval' => $this->getPageJsObject() . '.onGetUri(oData)', 'uri' => $sUri, 'url' => $sUrl);
  841. }
  842. protected function getSettingsOptions($aPage = array(), $bCreate = true, $bInputsOnly = false)
  843. {
  844. $aForm = array(
  845. 'form_attrs' => array(
  846. 'id' => 'adm-bp-settings-options',
  847. ),
  848. 'params' => array (
  849. 'remove_form' => '1',
  850. 'csrf' => array(
  851. 'disable' => true
  852. )
  853. ),
  854. 'inputs' => array (
  855. 'title_system' => array(
  856. 'type' => 'text_translatable',
  857. 'name' => 'title_system',
  858. 'caption' => _t('_adm_bp_txt_page_title_system'),
  859. 'info' => _t('_adm_bp_dsc_page_title_system'),
  860. 'value' => isset($aPage['title_system']) ? $aPage['title_system'] : '',
  861. 'required' => '1',
  862. 'db' => array (
  863. 'pass' => 'Xss',
  864. ),
  865. 'checker' => array (
  866. 'func' => 'length',
  867. 'params' => array(3,100),
  868. 'error' => _t('_adm_bp_err_page_title_system'),
  869. ),
  870. ),
  871. 'title' => array(
  872. 'type' => 'text_translatable',
  873. 'name' => 'title',
  874. 'caption' => _t('_adm_bp_txt_page_title'),
  875. 'info' => _t('_adm_bp_dsc_page_title'),
  876. 'value' => isset($aPage['title']) ? $aPage['title'] : '',
  877. 'required' => '1',
  878. 'db' => array (
  879. 'pass' => 'Xss',
  880. ),
  881. 'checker' => array (
  882. 'func' => 'length',
  883. 'params' => array(3,100),
  884. 'error' => _t('_adm_bp_err_page_title'),
  885. ),
  886. ),
  887. 'url' => array(
  888. 'type' => 'text',
  889. 'name' => 'url',
  890. 'caption' => _t('_adm_bp_txt_page_url'),
  891. 'info' => _t('_adm_bp_dsc_page_url'),
  892. 'value' => isset($aPage['url']) ? BxDolPermalinks::getInstance()->permalink($aPage['url']) : '',
  893. 'required' => '0',
  894. 'attrs' => array(
  895. 'id' => $this->aHtmlIds['url_field_id'],
  896. 'disabled' => 'disabled'
  897. ),
  898. ),
  899. 'type_id' => array(
  900. 'type' => 'select',
  901. 'name' => 'type_id',
  902. 'caption' => _t('_adm_bp_txt_page_type_id'),
  903. 'info' => _t('_adm_bp_dsc_page_type_id'),
  904. 'value' => isset($aPage['type_id']) ? $aPage['type_id'] : '',
  905. 'required' => '1',
  906. 'db' => array (
  907. 'pass' => 'Int',
  908. ),
  909. ),
  910. 'submenu' => array(
  911. 'type' => 'select',
  912. 'name' => 'submenu',
  913. 'caption' => _t('_adm_bp_txt_page_submenu'),
  914. 'info' => _t('_adm_bp_dsc_page_submenu'),
  915. 'value' => isset($aPage['submenu']) ? $aPage['submenu'] : '',
  916. 'required' => '0',
  917. 'db' => array (
  918. 'pass' => 'Xss',
  919. ),
  920. ),
  921. 'sticky_columns' => array(
  922. 'type' => 'switcher',
  923. 'name' => 'sticky_columns',
  924. 'caption' => _t('_adm_bp_txt_page_sticky_columns'),
  925. 'info' => '',
  926. 'value' => '1',
  927. 'checked' => isset($aPage['sticky_columns']) && $aPage['sticky_columns'] == 1,
  928. 'db' => array (
  929. 'pass' => 'Int',
  930. )
  931. )
  932. )
  933. );
  934. $aTypes = array();
  935. $this->oDb->getTypes(array('type' => 'all'), $aTypes, false);
  936. foreach($aTypes as $aType)
  937. $aForm['inputs']['type_id']['values'][] = array('key' => $aType['id'], 'value' => _t($aType['title']));
  938. $aSubmenus = $this->oDb->getSubmenus();
  939. $aForm['inputs']['submenu']['values'][] = array('key' => '', 'value' => _t('_sys_menu_item_title_inherited'));
  940. $aForm['inputs']['submenu']['values'][] = array('key' => 'disabled', 'value' => _t('_sys_menu_item_title_disabled'));
  941. foreach ($aSubmenus as $sObject => $sTitle)
  942. $aForm['inputs']['submenu']['values'][] = array('key' => $sObject, 'value' => _t($sTitle));
  943. if($bCreate) {
  944. $sJsObject = $this->getPageJsObject();
  945. $aForm['inputs']['title']['attrs']['onblur'] = $sJsObject . '.getUri(this);';
  946. $aForm['inputs'] = bx_array_insert_before(array(
  947. 'uri' => array(
  948. 'type' => 'text',
  949. 'name' => 'uri',
  950. 'caption' => _t('_adm_bp_txt_page_uri'),
  951. 'info' => _t('_adm_bp_dsc_page_uri'),
  952. 'value' => '',
  953. 'required' => '1',
  954. 'attrs' => array(
  955. 'id' => $this->aHtmlIds['uri_field_id'],
  956. 'onblur' => $sJsObject . '.getUri(this);'
  957. ),
  958. 'db' => array (
  959. 'pass' => 'Xss',
  960. ),
  961. 'checker' => array (
  962. 'func' => 'length',
  963. 'params' => array(3,100),
  964. 'error' => _t('_adm_bp_err_page_uri'),
  965. ),
  966. )
  967. ), $aForm['inputs'], 'url');
  968. }
  969. if($bInputsOnly)
  970. return $aForm['inputs'];
  971. $oForm = new BxTemplStudioFormView($aForm);
  972. return $oForm->getCode();
  973. }
  974. protected function getSettingsOptionsFields($aPage = array(), $bCreate = true)
  975. {
  976. return $this->getSettingsOptions($aPage, $bCreate, true);
  977. }
  978. protected function getSettingsCover($aPage = array(), $bCreate = true, $bInputsOnly = false)
  979. {
  980. $aForm = array(
  981. 'form_attrs' => array(
  982. 'id' => 'adm-bp-settings-cover',
  983. ),
  984. 'params' => array (
  985. 'remove_form' => '1',
  986. 'csrf' => array(
  987. 'disable' => true
  988. )
  989. ),
  990. 'inputs' => array (
  991. 'cover' => array(
  992. 'type' => 'select',
  993. 'name' => 'cover',
  994. 'caption' => _t('_adm_bp_txt_page_cover'),
  995. 'info' => '',
  996. 'value' => isset($aPage['cover']) ? (int)$aPage['cover'] : '1',
  997. 'values' => array(
  998. array('key' => 0, 'value' => _t('_adm_bp_txt_page_cover_0')),
  999. array('key' => 1, 'value' => _t('_adm_bp_txt_page_cover_1')),
  1000. array('key' => 2, 'value' => _t('_adm_bp_txt_page_cover_2')),
  1001. array('key' => 3, 'value' => _t('_adm_bp_txt_page_cover_3'))
  1002. ),
  1003. 'db' => array (
  1004. 'pass' => 'Int',
  1005. )
  1006. ),
  1007. 'cover_image' => array(
  1008. 'type' => 'files',
  1009. 'name' => 'cover_image',
  1010. 'storage_object' => $this->sStorage,
  1011. 'images_transcoder' => $this->sTranscoderCover,
  1012. 'uploaders' => $this->aUploadersCover,
  1013. 'multiple' => false,
  1014. 'content_id' => isset($aPage['id']) ? $aPage['id'] : 0,
  1015. 'ghost_template' => BxTemplStudioFunctions::getInstance()->getDefaultGhostTemplate('cover_image'),
  1016. 'caption' => _t('_adm_bp_txt_page_cover_image'),
  1017. 'db' => array (
  1018. 'pass' => 'Int',
  1019. )
  1020. ),
  1021. 'cover_title' => array(
  1022. 'type' => 'text_translatable',
  1023. 'name' => 'cover_title',
  1024. 'caption' => _t('_adm_bp_txt_page_cover_title'),
  1025. 'info' => '',
  1026. 'value' => isset($aPage['cover_title']) ? $aPage['cover_title'] : '',
  1027. 'db' => array (
  1028. 'pass' => 'Xss',
  1029. )
  1030. ),
  1031. )
  1032. );
  1033. if($bInputsOnly)
  1034. return $aForm['inputs'];
  1035. $oForm = new BxTemplStudioFormView($aForm);
  1036. return $oForm->getCode();
  1037. }
  1038. protected function getSettingsCoverFields($aPage = array(), $bCreate = true)
  1039. {
  1040. return $this->getSettingsCover($aPage, $bCreate, true);
  1041. }
  1042. protected function getSettingsLayout($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1043. {
  1044. $sJsObject = $this->getPageJsObject();
  1045. $oTemplate = BxDolStudioTemplate::getInstance();
  1046. $iLayout = isset($aPage['layout_id']) ? (int)$aPage['layout_id'] : 5;
  1047. $aLayouts = array();
  1048. $this->oDb->getLayouts(array('type' => 'all'), $aLayouts, false);
  1049. $aTmplParams = array(
  1050. 'bx_repeat:layouts' => array(),
  1051. 'form' => ''
  1052. );
  1053. foreach($aLayouts as $aLayout)
  1054. $aTmplParams['bx_repeat:layouts'][] = array(
  1055. 'id' => $aLayout['id'],
  1056. 'html_id' => $this->aHtmlIds['layout_id'] . $aLayout['id'],
  1057. 'js_object' => $sJsObject,
  1058. 'bx_if:active' => array(
  1059. 'condition' => (int)$aLayout['id'] == $iLayout,
  1060. 'content' => array()
  1061. ),
  1062. 'icon' => $oTemplate->getImageUrl($aLayout['icon']),
  1063. 'title' => _t($aLayout['title']),
  1064. );
  1065. $aForm = array(
  1066. 'form_attrs' => array(
  1067. 'id' => 'adm-bp-settings-layout',
  1068. ),
  1069. 'params' => array (
  1070. 'remove_form' => '1',
  1071. 'csrf' => array(
  1072. 'disable' => true
  1073. )
  1074. ),
  1075. 'inputs' => array (
  1076. 'layout_id' => array(
  1077. 'type' => 'hidden',
  1078. 'name' => 'layout_id',
  1079. 'value' => $iLayout,
  1080. 'db' => array (
  1081. 'pass' => 'Int',
  1082. ),
  1083. )
  1084. )
  1085. );
  1086. if($bInputsOnly)
  1087. return $aForm['inputs'];
  1088. $oForm = new BxTemplStudioFormView($aForm);
  1089. $aTmplParams['form'] = $oForm->getCode();
  1090. return $oTemplate->parseHtmlByName('bp_layouts.html', $aTmplParams);
  1091. }
  1092. protected function getSettingsLayoutFields($aPage = array(), $bCreate = true)
  1093. {
  1094. return $this->getSettingsLayout($aPage, $bCreate, true);
  1095. }
  1096. protected function getSettingsVisibility($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1097. {
  1098. $iVisibleForLevels = isset($aPage['visible_for_levels']) ? (int)$aPage['visible_for_levels'] : BX_DOL_INT_MAX;
  1099. if(isset($aPage['visible_for_levels_editable']) && (int)$aPage['visible_for_levels_editable'] == 0)
  1100. $aInputs = array(
  1101. 'visible_for_levels' => array(
  1102. 'type' => 'custom',
  1103. 'name' => 'visible_for_levels',
  1104. 'content' => MsgBox(_t('_adm_bp_err_page_visible_for_levels'))
  1105. )
  1106. );
  1107. else {
  1108. bx_import('BxDolStudioUtils');
  1109. $aInputs = array(
  1110. 'visible_for' => array(
  1111. 'type' => 'select',
  1112. 'name' => 'visible_for',
  1113. 'caption' => _t('_adm_bp_txt_block_visible_for'),
  1114. 'info' => '',
  1115. 'value' => $iVisibleForLevels == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
  1116. 'values' => array(
  1117. array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_bp_txt_block_visible_for_all')),
  1118. array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_bp_txt_block_visible_for_selected')),
  1119. ),
  1120. 'required' => '0',
  1121. 'attrs' => array(
  1122. 'onchange' => $this->getPageJsObject() . '.onChangeVisibleFor(this)'
  1123. ),
  1124. 'db' => array (
  1125. 'pass' => 'Xss',
  1126. )
  1127. ),
  1128. 'visible_for_levels' => array(
  1129. 'type' => 'checkbox_set',
  1130. 'name' => 'visible_for_levels',
  1131. 'caption' => _t('_adm_bp_txt_page_visible_for_levels'),
  1132. 'info' => _t('_adm_bp_dsc_page_visible_for_levels'),
  1133. 'value' => array(),
  1134. 'values' => array(),
  1135. 'tr_attrs' => array(
  1136. 'style' => $iVisibleForLevels == BX_DOL_INT_MAX ? 'display:none' : ''
  1137. ),
  1138. 'db' => array (
  1139. 'pass' => 'Int',
  1140. )
  1141. )
  1142. );
  1143. }
  1144. $aForm = array(
  1145. 'form_attrs' => array(
  1146. 'id' => 'adm-bp-settings-visibility',
  1147. ),
  1148. 'params' => array (
  1149. 'remove_form' => '1',
  1150. 'csrf' => array(
  1151. 'disable' => true
  1152. )
  1153. ),
  1154. 'inputs' => $aInputs
  1155. );
  1156. BxDolStudioUtils::getVisibilityValues($iVisibleForLevels, $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
  1157. if($bInputsOnly)
  1158. return $aForm['inputs'];
  1159. $oForm = new BxTemplStudioFormView($aForm);
  1160. return $oForm->getCode();
  1161. }
  1162. protected function getSettingsVisibilityFields($aPage = array(), $bCreate = true)
  1163. {
  1164. return $this->getSettingsVisibility($aPage, $bCreate, true);
  1165. }
  1166. protected function getSettingsCache($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1167. {
  1168. $aForm = array(
  1169. 'form_attrs' => array(
  1170. 'id' => 'adm-bp-settings-cache',
  1171. ),
  1172. 'params' => array (
  1173. 'remove_form' => '1',
  1174. 'csrf' => array(
  1175. 'disable' => true
  1176. )
  1177. ),
  1178. 'inputs' => array (
  1179. 'cache_lifetime' => array(
  1180. 'type' => 'text',
  1181. 'name' => 'cache_lifetime',
  1182. 'caption' => _t('_adm_bp_txt_page_cache_lifetime'),
  1183. 'info' => _t('_adm_bp_dsc_page_cache_lifetime'),
  1184. 'value' => isset($aPage['cache_lifetime']) ? $aPage['cache_lifetime'] : 0,
  1185. 'required' => '',
  1186. 'attrs' => array(
  1187. 'disabled' => isset($aPage['cache_editable']) && (int)$aPage['cache_editable'] == 0 ? 'disabled' : ''
  1188. ),
  1189. 'db' => array (
  1190. 'pass' => 'Int',
  1191. )
  1192. ),
  1193. )
  1194. );
  1195. if($bInputsOnly)
  1196. return $aForm['inputs'];
  1197. $oForm = new BxTemplStudioFormView($aForm);
  1198. return $oForm->getCode();
  1199. }
  1200. protected function getSettingsCacheFields($aPage = array(), $bCreate = true)
  1201. {
  1202. return $this->getSettingsCache($aPage, $bCreate, true);
  1203. }
  1204. protected function getSettingsSeo($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1205. {
  1206. $aForm = array(
  1207. 'form_attrs' => array(
  1208. 'id' => 'adm-bp-settings-seo',
  1209. ),
  1210. 'params' => array (
  1211. 'remove_form' => '1',
  1212. 'csrf' => array(
  1213. 'disable' => true
  1214. )
  1215. ),
  1216. 'inputs' => array (
  1217. 'meta_title' => array(
  1218. 'type' => 'text',
  1219. 'name' => 'meta_title',
  1220. 'caption' => _t('_adm_bp_txt_page_meta_title'),
  1221. 'value' => isset($aPage['meta_title']) ? $aPage['meta_title'] : '',
  1222. 'db' => array (
  1223. 'pass' => 'Xss',
  1224. ),
  1225. ),
  1226. 'meta_description' => array(
  1227. 'type' => 'textarea',
  1228. 'name' => 'meta_description',
  1229. 'caption' => _t('_adm_bp_txt_page_meta_description'),
  1230. 'info' => _t('_adm_bp_dsc_page_meta_description'),
  1231. 'value' => isset($aPage['meta_description']) ? $aPage['meta_description'] : '',
  1232. 'db' => array (
  1233. 'pass' => 'Xss',
  1234. ),
  1235. ),
  1236. 'meta_keywords' => array(
  1237. 'type' => 'textarea',
  1238. 'name' => 'meta_keywords',
  1239. 'caption' => _t('_adm_bp_txt_page_meta_keywords'),
  1240. 'info' => _t('_adm_bp_dsc_page_meta_keywords'),
  1241. 'value' => isset($aPage['meta_keywords']) ? $aPage['meta_keywords'] : '',
  1242. 'db' => array (
  1243. 'pass' => 'Xss',
  1244. ),
  1245. ),
  1246. 'meta_robots' => array(
  1247. 'type' => 'text',
  1248. 'name' => 'meta_robots',
  1249. 'caption' => _t('_adm_bp_txt_page_meta_robots'),
  1250. 'info' => _t('_adm_bp_dsc_page_meta_robots'),
  1251. 'value' => isset($aPage['meta_robots']) ? $aPage['meta_robots'] : '',
  1252. 'required' => '0',
  1253. 'db' => array (
  1254. 'pass' => 'Xss',
  1255. )
  1256. )
  1257. )
  1258. );
  1259. if($bInputsOnly)
  1260. return $aForm['inputs'];
  1261. $oForm = new BxTemplStudioFormView($aForm);
  1262. return $oForm->getCode();
  1263. }
  1264. protected function getSettingsSeoFields($aPage = array(), $bCreate = true)
  1265. {
  1266. return $this->getSettingsSeo($aPage, $bCreate, true);
  1267. }
  1268. protected function getSettingsInjections($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1269. {
  1270. $aForm = array(
  1271. 'form_attrs' => array(
  1272. 'id' => 'adm-bp-injections-seo',
  1273. ),
  1274. 'params' => array (
  1275. 'remove_form' => '1',
  1276. 'csrf' => array(
  1277. 'disable' => true
  1278. )
  1279. ),
  1280. 'inputs' => array (
  1281. 'inj_head' => array(
  1282. 'type' => 'textarea',
  1283. 'name' => 'inj_head',
  1284. 'caption' => _t('_adm_bp_txt_page_inj_head'),
  1285. 'info' => _t('_adm_bp_dsc_page_inj_head'),
  1286. 'value' => isset($aPage['inj_head']) ? $aPage['inj_head'] : '',
  1287. 'code' => 1,
  1288. 'db' => array (
  1289. 'pass' => 'XssHtml',
  1290. ),
  1291. ),
  1292. 'inj_footer' => array(
  1293. 'type' => 'textarea',
  1294. 'name' => 'inj_footer',
  1295. 'caption' => _t('_adm_bp_txt_page_inj_footer'),
  1296. 'info' => _t('_adm_bp_dsc_page_inj_footer'),
  1297. 'value' => isset($aPage['inj_footer']) ? $aPage['inj_footer'] : '',
  1298. 'code' => 1,
  1299. 'db' => array (
  1300. 'pass' => 'XssHtml',
  1301. ),
  1302. )
  1303. )
  1304. );
  1305. if($bInputsOnly)
  1306. return $aForm['inputs'];
  1307. $oForm = new BxTemplStudioFormView($aForm);
  1308. return $oForm->getCode();
  1309. }
  1310. protected function getSettingsInjectionsFields($aPage = array(), $bCreate = true)
  1311. {
  1312. return $this->getSettingsInjections($aPage, $bCreate, true);
  1313. }
  1314. protected function getBlockIcon($aBlock)
  1315. {
  1316. $sIcon = $sIconUrl = "";
  1317. $sResult = '';
  1318. switch($aBlock['type']) {
  1319. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1320. $sResult = 'far file-alt';
  1321. break;
  1322. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1323. $sResult = 'code';
  1324. break;
  1325. case BX_DOL_STUDIO_BP_BLOCK_CREATIVE:
  1326. $sResult = 'object-group';
  1327. break;
  1328. case BX_DOL_STUDIO_BP_BLOCK_BENTO_GRID:
  1329. $sResult = 'fa-grip-horizontal';
  1330. break;
  1331. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1332. $sResult = 'rss';
  1333. break;
  1334. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1335. $sResult = 'far image';
  1336. break;
  1337. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1338. $sResult = 'globe';
  1339. break;
  1340. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1341. $sResult = 'list-alt';
  1342. break;
  1343. case BX_DOL_STUDIO_BP_BLOCK_WIKI:
  1344. $sResult = 'file-word';
  1345. break;
  1346. case BX_DOL_STUDIO_BP_BLOCK_CUSTOM:
  1347. $sResult = 'file';
  1348. break;
  1349. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1350. $sResult = $this->getModuleIcon($aBlock['module'], 'page');
  1351. break;
  1352. }
  1353. if(strpos($sResult, '.') === false)
  1354. $sIcon = $sResult;
  1355. else
  1356. $sIconUrl = $sResult;
  1357. return array($sIcon, $sIconUrl);
  1358. }
  1359. protected function getBlockModule($aBlock)
  1360. {
  1361. return $aBlock['module'] != BX_DOL_STUDIO_BP_SKELETONS ? $aBlock['module'] : BX_DOL_STUDIO_MODULE_CUSTOM;
  1362. }
  1363. protected function getBlockContent($aBlock)
  1364. {
  1365. $aFields = array();
  1366. switch($aBlock['type']) {
  1367. case BX_DOL_STUDIO_BP_BLOCK_CUSTOM:
  1368. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1369. case BX_DOL_STUDIO_BP_BLOCK_BENTO_GRID:
  1370. $aFields = [
  1371. 'content' => [
  1372. 'type' => 'textarea',
  1373. 'name' => 'content',
  1374. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1375. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1376. 'value' => $aBlock['content'],
  1377. 'required' => '0',
  1378. 'code' => 1,
  1379. 'attrs' => [
  1380. 'class' => 'bx-form-input-textarea-codemirror'
  1381. ],
  1382. 'db' => [
  1383. 'pass' => 'XssHtml',
  1384. ],
  1385. ],
  1386. ];
  1387. break;
  1388. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1389. $aFields = [
  1390. 'content' => [
  1391. 'type' => 'textarea',
  1392. 'name' => 'content',
  1393. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1394. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1395. 'value' => $aBlock['content'],
  1396. 'required' => '0',
  1397. 'html' => 2,
  1398. 'html_toggle' => true,
  1399. 'attrs' => [
  1400. 'id' => $this->aHtmlIds['edit_block_editor_id']
  1401. ],
  1402. 'db' => [
  1403. 'pass' => 'XssHtml',
  1404. ],
  1405. ],
  1406. 'attachments' => [
  1407. 'type' => 'files',
  1408. 'name' => 'attachments',
  1409. 'storage_object' => $this->sStorage,
  1410. 'images_transcoder' => $this->sTranscoder,
  1411. 'uploaders' => $this->aUploaders,
  1412. 'multiple' => true,
  1413. 'content_id' => $aBlock['id'],
  1414. 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('bp_fgt_attachments.html', [
  1415. 'js_object' => $this->getPageJsObject(),
  1416. 'name' => 'attachments',
  1417. 'editor_id' => $this->aHtmlIds['edit_block_editor_id'],
  1418. ]),
  1419. 'caption' => _t('_adm_bp_txt_block_content_attachments_html')
  1420. ]
  1421. ];
  1422. break;
  1423. case BX_DOL_STUDIO_BP_BLOCK_CREATIVE:
  1424. $oTemplate = BxDolStudioTemplate::getInstance();
  1425. $sContent = $oTemplate->parseHtmlByName('bp_block_skeleton_creative.html', [
  1426. 'html_id' => $this->aHtmlIds['edit_block_builder_id'],
  1427. 'content_html' => $aBlock['content'],
  1428. 'content_data' => json_encode([
  1429. 'pages' => [
  1430. ['component' => $aBlock['content']]
  1431. ]
  1432. ])
  1433. ]);
  1434. $aFields = [
  1435. 'content' => [
  1436. 'type' => 'custom',
  1437. 'name' => 'content',
  1438. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1439. 'content' => $sContent,
  1440. 'required' => '0',
  1441. 'db' => [
  1442. 'pass' => 'XssHtml',
  1443. ],
  1444. ],
  1445. ];
  1446. break;
  1447. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1448. $aFields = [
  1449. 'content' => [
  1450. 'type' => 'textarea_translatable',
  1451. 'name' => 'content',
  1452. 'caption' => _t('_adm_bp_txt_block_content_lang'),
  1453. 'info' => _t('_adm_bp_dsc_block_content_lang'),
  1454. 'value' => $aBlock['content'],
  1455. 'required' => '0',
  1456. 'html' => 2,
  1457. 'html_toggle' => true,
  1458. 'db' => [
  1459. 'pass' => 'XssHtml',
  1460. ],
  1461. ],
  1462. ];
  1463. break;
  1464. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1465. $iImageId = $sImageAlign = '';
  1466. if($aBlock['content'] != '')
  1467. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1468. $aFields = [
  1469. 'content' => [
  1470. 'type' => 'hidden',
  1471. 'name' => 'content',
  1472. 'value' => '',
  1473. 'db' => [
  1474. 'pass' => 'Xss',
  1475. ],
  1476. ],
  1477. 'image_file' => [
  1478. 'type' => 'files',
  1479. 'name' => 'image_file',
  1480. 'storage_object' => BX_DOL_STORAGE_OBJ_IMAGES,
  1481. 'images_transcoder' => 'sys_image_resize',
  1482. 'uploaders' => ['sys_html5'],
  1483. 'multiple' => false,
  1484. 'content_id' => $aBlock['id'],
  1485. 'ghost_template' => BxTemplStudioFunctions::getInstance()->getDefaultGhostTemplate('image_file'),
  1486. 'caption' => _t('_adm_bp_txt_block_content_image_file'),
  1487. ],
  1488. 'image_align' => [
  1489. 'type' => 'select',
  1490. 'name' => 'image_align',
  1491. 'caption' => _t('_adm_bp_txt_block_content_image_align'),
  1492. 'info' => '',
  1493. 'value' => $sImageAlign,
  1494. 'values' => [
  1495. ['key' => '', 'value' => _t('_adm_bp_txt_block_content_image_align_empty')],
  1496. ['key' => 'left', 'value' => _t('_adm_bp_txt_block_content_image_align_left')],
  1497. ['key' => 'center', 'value' => _t('_adm_bp_txt_block_content_image_align_center')],
  1498. ['key' => 'right', 'value' => _t('_adm_bp_txt_block_content_image_align_right')],
  1499. ],
  1500. 'required' => '0',
  1501. 'db' => [
  1502. 'pass' => 'Xss',
  1503. ],
  1504. ],
  1505. ];
  1506. break;
  1507. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1508. $sRssUrl = $sRssLength = '';
  1509. if($aBlock['content'] != '')
  1510. list($sRssUrl, $sRssLength) = explode($this->sParamsDivider, $aBlock['content']);
  1511. $aFields = [
  1512. 'content' => [
  1513. 'type' => 'hidden',
  1514. 'name' => 'content',
  1515. 'value' => '',
  1516. 'db' => [
  1517. 'pass' => 'Xss',
  1518. ],
  1519. ],
  1520. 'rss_url' => [
  1521. 'type' => 'text',
  1522. 'name' => 'rss_url',
  1523. 'caption' => _t('_adm_bp_txt_block_content_rss_url'),
  1524. 'info' => _t('_adm_bp_dsc_block_content_rss_url'),
  1525. 'value' => $sRssUrl,
  1526. 'required' => '0',
  1527. 'db' => [
  1528. 'pass' => 'Xss',
  1529. ],
  1530. ],
  1531. 'rss_length' => [
  1532. 'type' => 'text',
  1533. 'name' => 'rss_length',
  1534. 'caption' => _t('_adm_bp_txt_block_content_rss_length'),
  1535. 'info' => _t('_adm_bp_dsc_block_content_rss_length'),
  1536. 'value' => $sRssLength,
  1537. 'required' => '0',
  1538. 'db' => [
  1539. 'pass' => 'Int',
  1540. ],
  1541. ],
  1542. ];
  1543. break;
  1544. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1545. $aFields = [
  1546. 'content' => [
  1547. 'type' => 'select',
  1548. 'name' => 'content',
  1549. 'caption' => _t('_adm_bp_txt_block_content_menu'),
  1550. 'info' => '',
  1551. 'value' => $aBlock['content'],
  1552. 'values' => [],
  1553. 'required' => '0',
  1554. 'db' => [
  1555. 'pass' => 'Xss',
  1556. ],
  1557. ]
  1558. ];
  1559. $sGroup = '';
  1560. $aMenus = $this->oDb->getMenus(true);
  1561. foreach($aMenus as $sKey => $aMenu) {
  1562. if($sGroup != $aMenu['module']) {
  1563. if(!empty($sGroup))
  1564. $aFields['content']['values'][$sGroup . '_end'] = ['type' => 'group_end'];
  1565. $sGroup = $aMenu['module'];
  1566. $aFields['content']['values'][$sGroup . '_beg'] = ['type' => 'group_header', 'value' => BxDolStudioUtils::getModuleTitle($sGroup)];
  1567. }
  1568. $aFields['content']['values'][$sKey] = _t($aMenu['title']);
  1569. }
  1570. $aFields['content']['values'] = array_merge(['' => _t('_adm_bp_txt_block_content_menu_empty')], $aFields['content']['values']);
  1571. break;
  1572. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1573. $aService = ['module' => '', 'method' => ''];
  1574. if($aBlock['content'] != '')
  1575. $aService = unserialize($aBlock['content']);
  1576. $aFields = [
  1577. 'service_module' => [
  1578. 'type' => 'value',
  1579. 'name' => 'service_module',
  1580. 'caption' => _t('_adm_bp_txt_block_content_service_module'),
  1581. 'value' => $this->getModuleTitle($aService['module'])
  1582. ],
  1583. 'service_method' => [
  1584. 'type' => 'value',
  1585. 'name' => 'service_method',
  1586. 'caption' => _t('_adm_bp_txt_block_content_service_method'),
  1587. 'value' => $aService['method']
  1588. ]
  1589. ];
  1590. break;
  1591. }
  1592. return $aFields;
  1593. }
  1594. protected function getBlockList($sModule)
  1595. {
  1596. if(empty($sModule))
  1597. return '';
  1598. $sJsObject = $this->getPageJsObject();
  1599. $oTemplate = BxDolStudioTemplate::getInstance();
  1600. $oForm = new BxTemplStudioFormView(array());
  1601. $aInputCheckbox = [
  1602. 'type' => 'checkbox',
  1603. 'name' => 'blocks[]',
  1604. 'attrs' => [
  1605. 'onChange' => 'javascript:' . $sJsObject . '.onSelectBlock(this);'
  1606. ],
  1607. 'value' => ''
  1608. ];
  1609. $aTmplParams = [
  1610. 'html_block_list_id' => $this->aHtmlIds['block_list_id'] . $sModule,
  1611. 'bx_repeat:blocks' => []
  1612. ];
  1613. $aBlocks = $this->getBlocks($sModule);
  1614. foreach($aBlocks as $aBlock) {
  1615. list($sIcon, $sIconUrl) = $this->getBlockIcon($aBlock);
  1616. $aInputCheckbox['value'] = $aBlock['id'];
  1617. $aTmplParams['bx_repeat:blocks'][] = [
  1618. 'js_object' => $sJsObject,
  1619. 'html_id' => $this->aHtmlIds['block_id'] . $aBlock['id'],
  1620. 'bx_if:is_inactive' => array(
  1621. 'condition' => false,
  1622. 'content' => [true]
  1623. ),
  1624. 'bx_if:show_link' => [
  1625. 'condition' => false,
  1626. 'content' => [true]
  1627. ],
  1628. 'bx_if:show_text' => [
  1629. 'condition' => true,
  1630. 'content' => [
  1631. 'title' => _t(!empty($aBlock['title_system']) ? $aBlock['title_system'] : $aBlock['title']),
  1632. ]
  1633. ],
  1634. 'bx_if:show_api' => [
  1635. 'condition' => false,
  1636. 'content' => [true]
  1637. ],
  1638. 'bx_if:image' => [
  1639. 'condition' => (bool)$sIconUrl,
  1640. 'content' => array('icon_url' => $sIconUrl),
  1641. ],
  1642. 'bx_if:icon' => [
  1643. 'condition' => (bool)$sIcon,
  1644. 'content' => ['icon' => $sIcon],
  1645. ],
  1646. 'module' => $this->getModuleTitle($aBlock['module']),
  1647. 'visible_for' => _t('_adm_bp_txt_visible_for', BxDolStudioUtils::getVisibilityTitle($aBlock['visible_for_levels'])),
  1648. 'bx_if:show_checkbox' => [
  1649. 'condition' => true,
  1650. 'content' => [
  1651. 'content' => $oForm->genRow($aInputCheckbox)
  1652. ]
  1653. ],
  1654. 'bx_if:show_drag_handle' => [
  1655. 'condition' => false,
  1656. 'content' => []
  1657. ]
  1658. ];
  1659. }
  1660. return $oTemplate->parseHtmlByName('bp_blocks_list.html', $aTmplParams);
  1661. }
  1662. protected function onBlockDelete($aBlock)
  1663. {
  1664. if($aBlock['module'] != BX_DOL_STUDIO_MODULE_CUSTOM)
  1665. return;
  1666. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['title']);
  1667. //--- Process Lang block
  1668. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && $aBlock['content'] != '')
  1669. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['content']);
  1670. //--- Process Image block
  1671. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && $aBlock['content'] != '') {
  1672. $iImageId = $sImageAlign = '';
  1673. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1674. if(is_numeric($iImageId) && (int)$iImageId != 0)
  1675. BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$iImageId, 0);
  1676. }
  1677. }
  1678. protected function getBlocks($sModule)
  1679. {
  1680. $aBlocks = array();
  1681. $this->oDb->getBlocks(array('type' => 'by_module_to_copy', 'value' => $sModule), $aBlocks, false);
  1682. return $aBlocks;
  1683. }
  1684. protected function _getPageCreateForm()
  1685. {
  1686. $oTemplate = BxDolStudioTemplate::getInstance();
  1687. $sForm = 'adm-bp-page-create';
  1688. $aForm = array(
  1689. 'form_attrs' => array(
  1690. 'id' => $sForm,
  1691. 'name' => $sForm,
  1692. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionPageCreate,
  1693. 'method' => 'post'
  1694. ),
  1695. 'params' => array (
  1696. 'db' => array(
  1697. 'table' => 'sys_objects_page',
  1698. 'key' => 'id',
  1699. 'uri' => '',
  1700. 'uri_title' => '',
  1701. 'submit_name' => 'do_submit'
  1702. ),
  1703. 'display' => $sForm
  1704. ),
  1705. 'inputs' => array (
  1706. 'module' => array(
  1707. 'type' => 'hidden',
  1708. 'name' => 'module',
  1709. 'value' => BX_DOL_STUDIO_MODULE_CUSTOM,
  1710. 'db' => array (
  1711. 'pass' => 'Xss',
  1712. ),
  1713. ),
  1714. 'deletable' => array(
  1715. 'type' => 'hidden',
  1716. 'name' => 'deletable',
  1717. 'value' => 1,
  1718. 'db' => array (
  1719. 'pass' => 'Int',
  1720. ),
  1721. ),
  1722. 'settings' => array(
  1723. 'type' => 'custom',
  1724. 'name' => 'settings',
  1725. 'content' => $oTemplate->parseHtmlByName('bp_edit_page_form.html', $this->_getTmplVarsPageSettings()),
  1726. ),
  1727. )
  1728. );
  1729. return new BxTemplStudioFormView($aForm);
  1730. }
  1731. protected function _getPageEditForm()
  1732. {
  1733. $oTemplate = BxDolStudioTemplate::getInstance();
  1734. $sForm = 'adm-bp-page-edit';
  1735. $aForm = array(
  1736. 'form_attrs' => array(
  1737. 'id' => $sForm,
  1738. 'name' => $sForm,
  1739. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionPageEdit,
  1740. 'method' => 'post'
  1741. ),
  1742. 'params' => array (
  1743. 'db' => array(
  1744. 'table' => 'sys_objects_page',
  1745. 'key' => 'id',
  1746. 'uri' => '',
  1747. 'uri_title' => '',
  1748. 'submit_name' => 'do_submit'
  1749. ),
  1750. 'display' => $sForm
  1751. ),
  1752. 'inputs' => array (
  1753. 'settings' => array(
  1754. 'type' => 'custom',
  1755. 'name' => 'settings',
  1756. 'content' => $oTemplate->parseHtmlByName('bp_edit_page_form.html', $this->_getTmplVarsPageSettings($this->aPageRebuild, false)),
  1757. ),
  1758. )
  1759. );
  1760. return new BxTemplStudioFormView($aForm);
  1761. }
  1762. protected function _getTmplVarsBlockPanelTop()
  1763. {
  1764. $sJsObject = $this->getPageJsObject();
  1765. $oForm = new BxTemplStudioFormView(array());
  1766. $aPages = $this->oDb->getPages(array('type' => 'by_module', 'value' => $this->sType));
  1767. $aCounter = array();
  1768. $this->oDb->getBlocks(array('type' => 'counter_by_pages'), $aCounter, false);
  1769. $aInputPagesValues = [];
  1770. foreach($aPages as $aPage) {
  1771. $sTitle = _t($aPage['title_system']);
  1772. if(empty($sTitle))
  1773. $sTitle = _t($aPage['title']);
  1774. $aInputPagesValues[] = array(
  1775. 'key' => $aPage['object'],
  1776. 'value' => $sTitle . " (" . (isset($aCounter[$aPage['object']]) ? $aCounter[$aPage['object']] : "0") . ")"
  1777. );
  1778. }
  1779. usort($aInputPagesValues, function($aV1, $aV2) {
  1780. return strcmp($aV1['value'], $aV2['value']);
  1781. });
  1782. $aInputPages = array(
  1783. 'type' => 'select',
  1784. 'name' => 'page',
  1785. 'attrs' => array(
  1786. 'onChange' => 'javascript:' . $this->getPageJsObject() . '.onChangePage(this)'
  1787. ),
  1788. 'value' => $this->sPage,
  1789. 'values' => array_merge([[
  1790. 'key' => '',
  1791. 'value' => _t('_adm_bp_txt_select_page')]
  1792. ], $aInputPagesValues)
  1793. );
  1794. $aTmplVarsActions = array();
  1795. if(($this->sPage != '' && !empty($this->aPageRebuild)) !== false)
  1796. $aTmplVarsActions = $this->_getTmplVarsBlockPanelTopActions();
  1797. return array(
  1798. 'js_object' => $this->getPageJsObject(),
  1799. 'selector' => $oForm->genRow($aInputPages),
  1800. 'action_page_create' => $this->sActionPageCreate,
  1801. 'bx_if:show_actions' => array(
  1802. 'condition' => $this->sPage != '',
  1803. 'content' => $aTmplVarsActions
  1804. )
  1805. );
  1806. }
  1807. protected function _getTmplVarsBlockPanelTopActions()
  1808. {
  1809. $sJsObject = $this->getPageJsObject();
  1810. $oPermalinks = BxDolPermalinks::getInstance();
  1811. return [
  1812. 'js_object' => $sJsObject,
  1813. 'bx_if:can_view' => [
  1814. 'condition' => !empty($this->aPageRebuild['url']),
  1815. 'content' => [
  1816. 'url_view' => bx_absolute_url($oPermalinks->permalink($this->aPageRebuild['url'])),
  1817. ]
  1818. ],
  1819. 'action_page_edit' => $this->sActionPageEdit,
  1820. 'bx_if:can_delete' => [
  1821. 'condition' => (int)$this->aPageRebuild['deletable'] == 1,
  1822. 'content' => [
  1823. 'js_object' => $sJsObject
  1824. ]
  1825. ],
  1826. 'action_block_create' => $this->sActionBlockCreate,
  1827. ];
  1828. }
  1829. protected function _getTmplVarsPageSettings($aPage = array(), $bCreate = true)
  1830. {
  1831. $sJsObject = $this->getPageJsObject();
  1832. $aTmplParams = array(
  1833. 'js_object' => $sJsObject,
  1834. 'menu' => array(),
  1835. 'html_settings_groups_id' => $this->aHtmlIds['settings_groups_id'],
  1836. 'bx_repeat:settings_groups' => array(),
  1837. 'submit' => _t($bCreate ? '_adm_bp_btn_page_create' : '_adm_bp_btn_page_apply')
  1838. );
  1839. foreach($this->aPageSettings as $aSetting) {
  1840. //--- get menu items
  1841. $aTmplParams['menu'][$aSetting['name']] = array(
  1842. 'name' => $aSetting['name'],
  1843. 'icon' => '',
  1844. 'onclick' => $sJsObject . '.onChangeSettingGroup(\'' . $aSetting['name'] . '\', this);',
  1845. 'title' => $aSetting['title'],
  1846. 'selected' => isset($aSetting['active']) && (int)$aSetting['active'] == 1
  1847. );
  1848. //--- get settings
  1849. $aTmplParams['bx_repeat:settings_groups'][] = array(
  1850. 'html_settings_group_id' => $this->aHtmlIds['settings_group_id'] . $aSetting['name'],
  1851. 'bx_if:hidden' => array(
  1852. 'condition' => $aSetting['active'] != 1,
  1853. 'content' => array()
  1854. ),
  1855. 'content' => $this->{'getSettings' . $this->getClassName($aSetting['name'])}($aPage, $bCreate)
  1856. );
  1857. }
  1858. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aTmplParams['menu']));
  1859. $aTmplParams['menu'] = $oMenu->getCode();
  1860. return $aTmplParams;
  1861. }
  1862. protected function getIndexingDataForBlock($sType, $sContent)
  1863. {
  1864. $aBlock = array();
  1865. switch($sType) {
  1866. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1867. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1868. $aBlock['text'] = trim(strip_tags($sContent));
  1869. $aBlock['text_updated'] = time();
  1870. break;
  1871. }
  1872. return $aBlock;
  1873. }
  1874. protected function onPageChanged($oForm, $aPage)
  1875. {
  1876. $this->oDb->cleanCache('sys_pages_objects_data');
  1877. $this->oDb->cleanCache('sys_pages_uri_object_map');
  1878. $this->oDb->cleanCache('sys_pages_urirewrite_object_map');
  1879. }
  1880. }
  1881. /** @} */