BxBaseStudioBuilderPage.php 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099
  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. 'html_toggle' => true,
  1375. 'attrs' => [
  1376. 'id' => $this->aHtmlIds['edit_block_editor_id']
  1377. ],
  1378. 'db' => [
  1379. 'pass' => 'XssHtml',
  1380. ],
  1381. ],
  1382. 'attachments' => [
  1383. 'type' => 'files',
  1384. 'name' => 'attachments',
  1385. 'storage_object' => $this->sStorage,
  1386. 'images_transcoder' => $this->sTranscoder,
  1387. 'uploaders' => $this->aUploaders,
  1388. 'multiple' => true,
  1389. 'content_id' => $aBlock['id'],
  1390. 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('bp_fgt_attachments.html', [
  1391. 'js_object' => $this->getPageJsObject(),
  1392. 'name' => 'attachments',
  1393. 'editor_id' => $this->aHtmlIds['edit_block_editor_id'],
  1394. ]),
  1395. 'caption' => _t('_adm_bp_txt_block_content_attachments_html')
  1396. ]
  1397. ];
  1398. break;
  1399. case BX_DOL_STUDIO_BP_BLOCK_CREATIVE:
  1400. $oTemplate = BxDolStudioTemplate::getInstance();
  1401. $sContent = $oTemplate->parseHtmlByName('bp_block_skeleton_creative.html', [
  1402. 'html_id' => $this->aHtmlIds['edit_block_builder_id'],
  1403. 'content_html' => $aBlock['content'],
  1404. 'content_data' => json_encode([
  1405. 'pages' => [
  1406. ['component' => $aBlock['content']]
  1407. ]
  1408. ])
  1409. ]);
  1410. $aFields = [
  1411. 'content' => [
  1412. 'type' => 'custom',
  1413. 'name' => 'content',
  1414. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1415. 'content' => $sContent,
  1416. 'required' => '0',
  1417. 'db' => [
  1418. 'pass' => 'XssHtml',
  1419. ],
  1420. ],
  1421. ];
  1422. break;
  1423. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1424. $aFields = [
  1425. 'content' => [
  1426. 'type' => 'textarea_translatable',
  1427. 'name' => 'content',
  1428. 'caption' => _t('_adm_bp_txt_block_content_lang'),
  1429. 'info' => _t('_adm_bp_dsc_block_content_lang'),
  1430. 'value' => $aBlock['content'],
  1431. 'required' => '0',
  1432. 'html' => 2,
  1433. 'html_toggle' => true,
  1434. 'db' => [
  1435. 'pass' => 'XssHtml',
  1436. ],
  1437. ],
  1438. ];
  1439. break;
  1440. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1441. $iImageId = $sImageAlign = '';
  1442. if($aBlock['content'] != '')
  1443. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1444. $aFields = [
  1445. 'content' => [
  1446. 'type' => 'hidden',
  1447. 'name' => 'content',
  1448. 'value' => '',
  1449. 'db' => [
  1450. 'pass' => 'Xss',
  1451. ],
  1452. ],
  1453. 'image_file' => [
  1454. 'type' => 'files',
  1455. 'name' => 'image_file',
  1456. 'storage_object' => BX_DOL_STORAGE_OBJ_IMAGES,
  1457. 'images_transcoder' => 'sys_image_resize',
  1458. 'uploaders' => ['sys_html5'],
  1459. 'multiple' => false,
  1460. 'content_id' => $aBlock['id'],
  1461. 'ghost_template' => BxTemplStudioFunctions::getInstance()->getDefaultGhostTemplate('image_file'),
  1462. 'caption' => _t('_adm_bp_txt_block_content_image_file'),
  1463. ],
  1464. 'image_align' => [
  1465. 'type' => 'select',
  1466. 'name' => 'image_align',
  1467. 'caption' => _t('_adm_bp_txt_block_content_image_align'),
  1468. 'info' => '',
  1469. 'value' => $sImageAlign,
  1470. 'values' => [
  1471. ['key' => '', 'value' => _t('_adm_bp_txt_block_content_image_align_empty')],
  1472. ['key' => 'left', 'value' => _t('_adm_bp_txt_block_content_image_align_left')],
  1473. ['key' => 'center', 'value' => _t('_adm_bp_txt_block_content_image_align_center')],
  1474. ['key' => 'right', 'value' => _t('_adm_bp_txt_block_content_image_align_right')],
  1475. ],
  1476. 'required' => '0',
  1477. 'db' => [
  1478. 'pass' => 'Xss',
  1479. ],
  1480. ],
  1481. ];
  1482. break;
  1483. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1484. $sRssUrl = $sRssLength = '';
  1485. if($aBlock['content'] != '')
  1486. list($sRssUrl, $sRssLength) = explode($this->sParamsDivider, $aBlock['content']);
  1487. $aFields = [
  1488. 'content' => [
  1489. 'type' => 'hidden',
  1490. 'name' => 'content',
  1491. 'value' => '',
  1492. 'db' => [
  1493. 'pass' => 'Xss',
  1494. ],
  1495. ],
  1496. 'rss_url' => [
  1497. 'type' => 'text',
  1498. 'name' => 'rss_url',
  1499. 'caption' => _t('_adm_bp_txt_block_content_rss_url'),
  1500. 'info' => _t('_adm_bp_dsc_block_content_rss_url'),
  1501. 'value' => $sRssUrl,
  1502. 'required' => '0',
  1503. 'db' => [
  1504. 'pass' => 'Xss',
  1505. ],
  1506. ],
  1507. 'rss_length' => [
  1508. 'type' => 'text',
  1509. 'name' => 'rss_length',
  1510. 'caption' => _t('_adm_bp_txt_block_content_rss_length'),
  1511. 'info' => _t('_adm_bp_dsc_block_content_rss_length'),
  1512. 'value' => $sRssLength,
  1513. 'required' => '0',
  1514. 'db' => [
  1515. 'pass' => 'Int',
  1516. ],
  1517. ],
  1518. ];
  1519. break;
  1520. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1521. $aFields = [
  1522. 'content' => [
  1523. 'type' => 'select',
  1524. 'name' => 'content',
  1525. 'caption' => _t('_adm_bp_txt_block_content_menu'),
  1526. 'info' => '',
  1527. 'value' => $aBlock['content'],
  1528. 'values' => [],
  1529. 'required' => '0',
  1530. 'db' => [
  1531. 'pass' => 'Xss',
  1532. ],
  1533. ]
  1534. ];
  1535. $sGroup = '';
  1536. $aMenus = $this->oDb->getMenus(true);
  1537. foreach($aMenus as $sKey => $aMenu) {
  1538. if($sGroup != $aMenu['module']) {
  1539. if(!empty($sGroup))
  1540. $aFields['content']['values'][$sGroup . '_end'] = ['type' => 'group_end'];
  1541. $sGroup = $aMenu['module'];
  1542. $aFields['content']['values'][$sGroup . '_beg'] = ['type' => 'group_header', 'value' => BxDolStudioUtils::getModuleTitle($sGroup)];
  1543. }
  1544. $aFields['content']['values'][$sKey] = _t($aMenu['title']);
  1545. }
  1546. $aFields['content']['values'] = array_merge(['' => _t('_adm_bp_txt_block_content_menu_empty')], $aFields['content']['values']);
  1547. break;
  1548. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1549. $aService = ['module' => '', 'method' => ''];
  1550. if($aBlock['content'] != '')
  1551. $aService = unserialize($aBlock['content']);
  1552. $aFields = [
  1553. 'service_module' => [
  1554. 'type' => 'value',
  1555. 'name' => 'service_module',
  1556. 'caption' => _t('_adm_bp_txt_block_content_service_module'),
  1557. 'value' => $this->getModuleTitle($aService['module'])
  1558. ],
  1559. 'service_method' => [
  1560. 'type' => 'value',
  1561. 'name' => 'service_method',
  1562. 'caption' => _t('_adm_bp_txt_block_content_service_method'),
  1563. 'value' => $aService['method']
  1564. ]
  1565. ];
  1566. break;
  1567. }
  1568. return $aFields;
  1569. }
  1570. protected function getBlockList($sModule)
  1571. {
  1572. if(empty($sModule))
  1573. return '';
  1574. $sJsObject = $this->getPageJsObject();
  1575. $oTemplate = BxDolStudioTemplate::getInstance();
  1576. $oForm = new BxTemplStudioFormView(array());
  1577. $aInputCheckbox = [
  1578. 'type' => 'checkbox',
  1579. 'name' => 'blocks[]',
  1580. 'attrs' => [
  1581. 'onChange' => 'javascript:' . $sJsObject . '.onSelectBlock(this);'
  1582. ],
  1583. 'value' => ''
  1584. ];
  1585. $aTmplParams = [
  1586. 'html_block_list_id' => $this->aHtmlIds['block_list_id'] . $sModule,
  1587. 'bx_repeat:blocks' => []
  1588. ];
  1589. $aBlocks = $this->getBlocks($sModule);
  1590. foreach($aBlocks as $aBlock) {
  1591. list($sIcon, $sIconUrl) = $this->getBlockIcon($aBlock);
  1592. $aInputCheckbox['value'] = $aBlock['id'];
  1593. $aTmplParams['bx_repeat:blocks'][] = [
  1594. 'js_object' => $sJsObject,
  1595. 'html_id' => $this->aHtmlIds['block_id'] . $aBlock['id'],
  1596. 'bx_if:is_inactive' => array(
  1597. 'condition' => false,
  1598. 'content' => [true]
  1599. ),
  1600. 'bx_if:show_link' => [
  1601. 'condition' => false,
  1602. 'content' => [true]
  1603. ],
  1604. 'bx_if:show_text' => [
  1605. 'condition' => true,
  1606. 'content' => [
  1607. 'title' => _t(!empty($aBlock['title_system']) ? $aBlock['title_system'] : $aBlock['title']),
  1608. ]
  1609. ],
  1610. 'bx_if:show_api' => [
  1611. 'condition' => false,
  1612. 'content' => [true]
  1613. ],
  1614. 'bx_if:image' => [
  1615. 'condition' => (bool)$sIconUrl,
  1616. 'content' => array('icon_url' => $sIconUrl),
  1617. ],
  1618. 'bx_if:icon' => [
  1619. 'condition' => (bool)$sIcon,
  1620. 'content' => ['icon' => $sIcon],
  1621. ],
  1622. 'module' => $this->getModuleTitle($aBlock['module']),
  1623. 'visible_for' => _t('_adm_bp_txt_visible_for', BxDolStudioUtils::getVisibilityTitle($aBlock['visible_for_levels'])),
  1624. 'bx_if:show_checkbox' => [
  1625. 'condition' => true,
  1626. 'content' => [
  1627. 'content' => $oForm->genRow($aInputCheckbox)
  1628. ]
  1629. ],
  1630. 'bx_if:show_drag_handle' => [
  1631. 'condition' => false,
  1632. 'content' => []
  1633. ]
  1634. ];
  1635. }
  1636. return $oTemplate->parseHtmlByName('bp_blocks_list.html', $aTmplParams);
  1637. }
  1638. protected function onBlockDelete($aBlock)
  1639. {
  1640. if($aBlock['module'] != BX_DOL_STUDIO_MODULE_CUSTOM)
  1641. return;
  1642. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['title']);
  1643. //--- Process Lang block
  1644. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && $aBlock['content'] != '')
  1645. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['content']);
  1646. //--- Process Image block
  1647. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && $aBlock['content'] != '') {
  1648. $iImageId = $sImageAlign = '';
  1649. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1650. if(is_numeric($iImageId) && (int)$iImageId != 0)
  1651. BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$iImageId, 0);
  1652. }
  1653. }
  1654. protected function getBlocks($sModule)
  1655. {
  1656. $aBlocks = array();
  1657. $this->oDb->getBlocks(array('type' => 'by_module_to_copy', 'value' => $sModule), $aBlocks, false);
  1658. return $aBlocks;
  1659. }
  1660. protected function _getPageCreateForm()
  1661. {
  1662. $oTemplate = BxDolStudioTemplate::getInstance();
  1663. $sForm = 'adm-bp-page-create';
  1664. $aForm = array(
  1665. 'form_attrs' => array(
  1666. 'id' => $sForm,
  1667. 'name' => $sForm,
  1668. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionPageCreate,
  1669. 'method' => 'post'
  1670. ),
  1671. 'params' => array (
  1672. 'db' => array(
  1673. 'table' => 'sys_objects_page',
  1674. 'key' => 'id',
  1675. 'uri' => '',
  1676. 'uri_title' => '',
  1677. 'submit_name' => 'do_submit'
  1678. ),
  1679. 'display' => $sForm
  1680. ),
  1681. 'inputs' => array (
  1682. 'module' => array(
  1683. 'type' => 'hidden',
  1684. 'name' => 'module',
  1685. 'value' => BX_DOL_STUDIO_MODULE_CUSTOM,
  1686. 'db' => array (
  1687. 'pass' => 'Xss',
  1688. ),
  1689. ),
  1690. 'deletable' => array(
  1691. 'type' => 'hidden',
  1692. 'name' => 'deletable',
  1693. 'value' => 1,
  1694. 'db' => array (
  1695. 'pass' => 'Int',
  1696. ),
  1697. ),
  1698. 'settings' => array(
  1699. 'type' => 'custom',
  1700. 'name' => 'settings',
  1701. 'content' => $oTemplate->parseHtmlByName('bp_edit_page_form.html', $this->_getTmplVarsPageSettings()),
  1702. ),
  1703. )
  1704. );
  1705. return new BxTemplStudioFormView($aForm);
  1706. }
  1707. protected function _getPageEditForm()
  1708. {
  1709. $oTemplate = BxDolStudioTemplate::getInstance();
  1710. $sForm = 'adm-bp-page-edit';
  1711. $aForm = array(
  1712. 'form_attrs' => array(
  1713. 'id' => $sForm,
  1714. 'name' => $sForm,
  1715. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionPageEdit,
  1716. 'method' => 'post'
  1717. ),
  1718. 'params' => array (
  1719. 'db' => array(
  1720. 'table' => 'sys_objects_page',
  1721. 'key' => 'id',
  1722. 'uri' => '',
  1723. 'uri_title' => '',
  1724. 'submit_name' => 'do_submit'
  1725. ),
  1726. 'display' => $sForm
  1727. ),
  1728. 'inputs' => array (
  1729. 'settings' => array(
  1730. 'type' => 'custom',
  1731. 'name' => 'settings',
  1732. 'content' => $oTemplate->parseHtmlByName('bp_edit_page_form.html', $this->_getTmplVarsPageSettings($this->aPageRebuild, false)),
  1733. ),
  1734. )
  1735. );
  1736. return new BxTemplStudioFormView($aForm);
  1737. }
  1738. protected function _getTmplVarsBlockPanelTop()
  1739. {
  1740. $sJsObject = $this->getPageJsObject();
  1741. $oForm = new BxTemplStudioFormView(array());
  1742. $aPages = $this->oDb->getPages(array('type' => 'by_module', 'value' => $this->sType));
  1743. $aCounter = array();
  1744. $this->oDb->getBlocks(array('type' => 'counter_by_pages'), $aCounter, false);
  1745. $aInputPagesValues = [];
  1746. foreach($aPages as $aPage) {
  1747. $sTitle = _t($aPage['title_system']);
  1748. if(empty($sTitle))
  1749. $sTitle = _t($aPage['title']);
  1750. $aInputPagesValues[] = array(
  1751. 'key' => $aPage['object'],
  1752. 'value' => $sTitle . " (" . (isset($aCounter[$aPage['object']]) ? $aCounter[$aPage['object']] : "0") . ")"
  1753. );
  1754. }
  1755. usort($aInputPagesValues, function($aV1, $aV2) {
  1756. return strcmp($aV1['value'], $aV2['value']);
  1757. });
  1758. $aInputPages = array(
  1759. 'type' => 'select',
  1760. 'name' => 'page',
  1761. 'attrs' => array(
  1762. 'onChange' => 'javascript:' . $this->getPageJsObject() . '.onChangePage(this)'
  1763. ),
  1764. 'value' => $this->sPage,
  1765. 'values' => array_merge([[
  1766. 'key' => '',
  1767. 'value' => _t('_adm_bp_txt_select_page')]
  1768. ], $aInputPagesValues)
  1769. );
  1770. $aTmplVarsActions = array();
  1771. if(($this->sPage != '' && !empty($this->aPageRebuild)) !== false)
  1772. $aTmplVarsActions = $this->_getTmplVarsBlockPanelTopActions();
  1773. return array(
  1774. 'js_object' => $this->getPageJsObject(),
  1775. 'selector' => $oForm->genRow($aInputPages),
  1776. 'action_page_create' => $this->sActionPageCreate,
  1777. 'bx_if:show_actions' => array(
  1778. 'condition' => $this->sPage != '',
  1779. 'content' => $aTmplVarsActions
  1780. )
  1781. );
  1782. }
  1783. protected function _getTmplVarsBlockPanelTopActions()
  1784. {
  1785. $sJsObject = $this->getPageJsObject();
  1786. $oPermalinks = BxDolPermalinks::getInstance();
  1787. return [
  1788. 'js_object' => $sJsObject,
  1789. 'bx_if:can_view' => [
  1790. 'condition' => !empty($this->aPageRebuild['url']),
  1791. 'content' => [
  1792. 'url_view' => bx_absolute_url($oPermalinks->permalink($this->aPageRebuild['url'])),
  1793. ]
  1794. ],
  1795. 'action_page_edit' => $this->sActionPageEdit,
  1796. 'bx_if:can_delete' => [
  1797. 'condition' => (int)$this->aPageRebuild['deletable'] == 1,
  1798. 'content' => [
  1799. 'js_object' => $sJsObject
  1800. ]
  1801. ],
  1802. 'action_block_create' => $this->sActionBlockCreate,
  1803. ];
  1804. }
  1805. protected function _getTmplVarsPageSettings($aPage = array(), $bCreate = true)
  1806. {
  1807. $sJsObject = $this->getPageJsObject();
  1808. $aTmplParams = array(
  1809. 'js_object' => $sJsObject,
  1810. 'menu' => array(),
  1811. 'html_settings_groups_id' => $this->aHtmlIds['settings_groups_id'],
  1812. 'bx_repeat:settings_groups' => array(),
  1813. 'submit' => _t($bCreate ? '_adm_bp_btn_page_create' : '_adm_bp_btn_page_apply')
  1814. );
  1815. foreach($this->aPageSettings as $aSetting) {
  1816. //--- get menu items
  1817. $aTmplParams['menu'][$aSetting['name']] = array(
  1818. 'name' => $aSetting['name'],
  1819. 'icon' => '',
  1820. 'onclick' => $sJsObject . '.onChangeSettingGroup(\'' . $aSetting['name'] . '\', this);',
  1821. 'title' => $aSetting['title'],
  1822. 'selected' => isset($aSetting['active']) && (int)$aSetting['active'] == 1
  1823. );
  1824. //--- get settings
  1825. $aTmplParams['bx_repeat:settings_groups'][] = array(
  1826. 'html_settings_group_id' => $this->aHtmlIds['settings_group_id'] . $aSetting['name'],
  1827. 'bx_if:hidden' => array(
  1828. 'condition' => $aSetting['active'] != 1,
  1829. 'content' => array()
  1830. ),
  1831. 'content' => $this->{'getSettings' . $this->getClassName($aSetting['name'])}($aPage, $bCreate)
  1832. );
  1833. }
  1834. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aTmplParams['menu']));
  1835. $aTmplParams['menu'] = $oMenu->getCode();
  1836. return $aTmplParams;
  1837. }
  1838. protected function getIndexingDataForBlock($sType, $sContent)
  1839. {
  1840. $aBlock = array();
  1841. switch($sType) {
  1842. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1843. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1844. $aBlock['text'] = trim(strip_tags($sContent));
  1845. $aBlock['text_updated'] = time();
  1846. break;
  1847. }
  1848. return $aBlock;
  1849. }
  1850. protected function onPageChanged($oForm, $aPage)
  1851. {
  1852. $this->oDb->cleanCache('sys_pages_objects_data');
  1853. $this->oDb->cleanCache('sys_pages_uri_object_map');
  1854. $this->oDb->cleanCache('sys_pages_urirewrite_object_map');
  1855. }
  1856. }
  1857. /** @} */