| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup UnaView UNA Studio Representation classes
- * @ingroup UnaStudio
- * @{
- */
- define('BX_DOL_STUDIO_BUILDER_PAGE', 1);
- class BxBaseStudioBuilderPage extends BxDolStudioBuilderPage
- {
- protected $sParamsDivider = '#';
- protected $sSelectKeyPrefix = 'id-';
- protected $sActionPageCreate = 'page_create';
- protected $sActionPageDelete = 'page_delete';
- protected $sActionPageEdit = 'page_edit';
- protected $sActionBlockCreate = 'block_create';
- protected $sActionBlockEdit = 'block_edit';
- protected $sStorage;
- protected $sTranscoder;
- protected $aUploaders;
-
- protected $sTranscoderCover;
- protected $aUploadersCover;
- protected $sBaseUrl;
- protected $sTypeUrl;
- protected $sPageUrl;
- protected $aHtmlIds = array(
- 'add_popup_id' => 'adm-bp-add-popup',
- 'edit_popup_id' => 'adm-bp-edit-popup',
- 'uri_field_id' => 'adm-bp-field-uri',
- 'url_field_id' => 'adm-bp-field-url',
- 'settings_group_id' => 'adm-bp-settings-group-',
- 'settings_groups_id' => 'adm-bp-settings-groups',
- 'create_block_popup_id' => 'adm-bp-create-block-popup',
- 'edit_block_popup_id' => 'adm-bp-edit-block-popup',
- 'edit_block_editor_id' => 'adm-bp-edit-block-editor',
- 'edit_block_builder_id' => 'adm-bp-edit-block-builder',
- 'block_id' => 'adm-bpb-',
- 'block_list_id' => 'adm-bpl-',
- 'block_lists_id' => 'adm-bp-block-lists',
- 'layout_id' => 'adm-bpl-',
- );
- protected $aPageSettings = array(
- array('name' => 'options', 'title' => '_adm_bp_mi_page_options', 'icon' => 'mi-bp-options.svg', 'active' => 1),
- array('name' => 'cover', 'title' => '_adm_bp_mi_page_cover', 'icon' => 'mi-bp-cover.svg', 'active' => 0),
- array('name' => 'layout', 'title' => '_adm_bp_mi_page_layout', 'icon' => 'mi-bp-layout.svg', 'active' => 0),
- array('name' => 'visibility', 'title' => '_adm_bp_mi_page_visibility', 'icon' => 'mi-bp-visibility.svg', 'active' => 0),
- array('name' => 'cache', 'title' => '_adm_bp_mi_page_cache', 'icon' => 'mi-bp-cache.svg', 'active' => 0),
- array('name' => 'seo', 'title' => '_adm_bp_mi_page_seo', 'icon' => 'mi-bp-seo.svg', 'active' => 0),
- array('name' => 'injections', 'title' => '_adm_bp_mi_page_injections', 'icon' => 'mi-bp-injections.svg', 'active' => 0)
- );
- function __construct($sType = '', $sPage = '')
- {
- parent::__construct($sType, $sPage);
- $this->sStorage = BX_DOL_STORAGE_OBJ_IMAGES;
- $this->sTranscoder = 'sys_builder_page_preview';
- $this->aUploaders = array('sys_builder_page_html5');
- $this->sTranscoderCover = 'sys_cover_preview';
- $this->aUploadersCover = array('sys_std_crop_cover');
- $this->sBaseUrl = BX_DOL_URL_STUDIO . 'builder_page.php';
- $this->sTypeUrl = $this->sBaseUrl . '?type=%s';
- $this->sPageUrl = $this->sTypeUrl . '&page=%s';
- }
- function getPageCss()
- {
- $oTemplate = BxDolStudioTemplate::getInstance();
- $aUploaders = array_merge($this->aUploaders, $this->aUploadersCover);
- foreach($aUploaders as $sUploader) {
- $oUploader = BxDolUploader::getObjectInstance($sUploader, $this->sStorage, '', $oTemplate);
- if($oUploader)
- $oUploader->addCssJs();
- }
- return array_merge(parent::getPageCss(), [
- BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css',
- BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'grapesjs/|grapes.min.css',
- BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'select2/css/|select2.min.css',
- 'page_layouts.css',
- 'builder_page.css'
- ]);
- }
- function getPageJs()
- {
- return array_merge(parent::getPageJs(), [
- 'codemirror/codemirror.min.js',
- 'grapesjs/grapes.min.js',
- 'grapesjs/grapesjs-blocks-basic.js',
- 'grapesjs/grapesjs-style-bg.js',
- 'grapesjs/grapesjs-preset-webpage.min.js',
- 'select2/js/select2.min.js',
- 'jquery-ui/jquery-ui.min.js',
- 'jquery.ui.touch-punch.min.js',
- 'jquery.easing.js',
- 'jquery.form.min.js',
- 'forms.js',
- 'functions.js',
- 'builder_page.js'
- ]);
- }
- function getPageJsObject()
- {
- return 'oBxDolStudioBuilderPage';
- }
- function getPageMenu($aMenu = [], $aMarkers = [])
- {
- $aMenuItems = [
- BX_DOL_STUDIO_BP_TYPE_SYSTEM => ['icon' => 'mi-bp-system.svg'],
- BX_DOL_STUDIO_BP_TYPE_CUSTOM => ['icon' => 'mi-bp-custom.svg'],
- BX_DOL_STUDIO_BP_TYPE_MODULES => ['icon' => 'mi-bp-modules.svg']
- ];
- $aMenu = [];
- foreach($aMenuItems as $sMenuItem => $aItem)
- $aMenu[] = [
- 'name' => $sMenuItem,
- 'icon' => $aItem['icon'],
- 'icon_bg' => true,
- 'link' => sprintf($this->sTypeUrl, $sMenuItem),
- 'title' => _t('_adm_bp_cpt_type_' . $sMenuItem),
- 'selected' => $sMenuItem == $this->sType || ($sMenuItem == BX_DOL_STUDIO_BP_TYPE_MODULES && !isset($aMenuItems[$this->sType]))
- ];
- return parent::getPageMenu($aMenu);
- }
- function getPageCode($sPage = '', $bWrap = true)
- {
- $sResult = parent::getPageCode($sPage, $bWrap);
- if($sResult === false)
- return false;
- $oPage = BxTemplPage::getObjectInstance($this->sPage);
- $oTemplate = BxDolStudioTemplate::getInstance();
- $sJsObject = $this->getPageJsObject();
- $sTxtEmpty = _t('_sys_txt_empty');
- $sContent = "";
- if(($bPage = $this->sPage != '') === true) {
- /**
- * Reset (move to hidden sell) blocks which cannot be seen,
- * because of unsuitable cell number to currently selected layout.
- */
- $this->oDb->resetBlocksByPage($this->aPageRebuild['object'], $this->aPageRebuild['layout_cells_number']);
- $aTmplVars = array(
- 'page_id' => 'bx-page-' . $this->aPageRebuild['uri'],
- 'bx_if:show_layout_row_dump' => array(
- 'condition' => true,
- 'content' => array()
- )
- );
- for($i = 0; $i <= $this->aPageRebuild['layout_cells_number']; $i++) {
- $aBlocks = array();
- $this->oDb->getBlocks(array('type' => 'by_object_cell', 'object' => $this->aPageRebuild['object'], 'cell' => $i), $aBlocks, false);
- $aTmplVarsCell = array('id' => $i, 'bx_repeat:blocks' => array());
- foreach($aBlocks as $aBlock) {
- $sTitle = strip_tags(!empty($aBlock['title_system']) ? _t($aBlock['title_system']) : $oPage->getBlockTitle($aBlock));
- list($sIcon, $sIconUrl) = $this->getBlockIcon($aBlock);
- $aTmplVarsCell['bx_repeat:blocks'][] = array(
- 'html_id' => $this->aHtmlIds['block_id'] . $aBlock['id'],
- 'bx_if:is_inactive' => array(
- 'condition' => (int)$aBlock['active'] == 0,
- 'content' => array()
- ),
- 'bx_if:show_link' => array(
- 'condition' => true,
- 'content' => array(
- 'onclick' => $sJsObject . ".performAction('block_edit', {id: " . $aBlock['id'] . "})",
- 'title' => !empty($sTitle) ? $sTitle : $sTxtEmpty,
- )
- ),
- 'bx_if:show_text' => array(
- 'condition' => false,
- 'content' => array()
- ),
- 'bx_if:show_api' => [
- 'condition' => (int)$aBlock['active_api'] != 0,
- 'content' => []
- ],
- 'bx_if:image' => array (
- 'condition' => (bool)$sIconUrl,
- 'content' => array('icon_url' => $sIconUrl),
- ),
- 'bx_if:icon' => array (
- 'condition' => (bool)$sIcon,
- 'content' => array('icon' => $sIcon),
- ),
- 'module' => $this->getModuleTitle($aBlock['module']),
- 'visible_for' => _t('_adm_bp_txt_visible_for', BxDolStudioUtils::getVisibilityTitle($aBlock['visible_for_levels'])),
- 'bx_if:show_checkbox' => array(
- 'condition' => false,
- 'content' => array()
- ),
- 'bx_if:show_drag_handle' => array(
- 'condition' => true,
- 'content' => array()
- )
- );
- }
- $sCell = $oTemplate->parseHtmlByName('bp_cell.html', $aTmplVarsCell);
- if($i == 0)
- $aTmplVars['bx_if:show_layout_row_dump']['content']['cell_' . $i] = $sCell;
- else
- $aTmplVars['cell_' . $i] = $sCell;
- }
- $sContent = $oTemplate->parseHtmlByName($this->aPageRebuild['layout_template'], $aTmplVars);
- }
- $aLanguages = BxDolStudioLanguagesUtils::getInstance()->getLanguages();
- $aTmplVars = array(
- 'js_object' => $sJsObject,
- 'action_url' => $this->sBaseUrl,
- 'page_url' => sprintf($this->sPageUrl, '{0}', '{1}'),
- 'type' => $this->sType,
- 'page' => $this->sPage,
- 'html_ids' => json_encode($this->aHtmlIds),
- 'languages' => json_encode($aLanguages),
- 'content' => $this->getBlockCode(array(
- 'items' => $sContent
- ))
- );
- $oTemplate->addJsTranslation([
- '_sys_not_available',
- '_adm_bp_wrn_page_delete',
- '_adm_bp_wrn_page_block_delete'
- ]);
- return $sResult . $oTemplate->parseHtmlByName('builder_page.html', $aTmplVars);
- }
- function getBlockPanelTop($aBlock)
- {
- return parent::getBlockPanelTop(
- array('panel_top' => BxDolStudioTemplate::getInstance()->parseHtmlByName('bp_block_panel_top.html', $this->_getTmplVarsBlockPanelTop()))
- );
- }
- protected function actionPageCreate()
- {
- $sJsObject = $this->getPageJsObject();
- $oTemplate = BxDolStudioTemplate::getInstance();
- $sModule = BX_DOL_STUDIO_MODULE_CUSTOM;
- $oForm = $this->_getPageCreateForm();
- $oForm->initChecker();
- if($oForm->isSubmittedAndValid()) {
- unset($oForm->aInputs['settings']);
- foreach($this->aPageSettings as $aSetting)
- $oForm->aInputs = array_merge($oForm->aInputs, $this->{'getSettings' . $this->getClassName($aSetting['name']) . 'Fields'}());
- $sLanguage = BxDolStudioLanguagesUtils::getInstance()->getCurrentLangName(false);
- $sObject = BxDolForm::getSubmittedValue('title-' . $sLanguage, $oForm->aFormAttrs['method']);
- $sObject = uriGenerate($sObject, 'sys_objects_page', 'object', ['empty' => 'object']);
- $sUri = $oForm->getCleanValue('uri');
-
- $aPage = $this->oDb->getPages(['type' => 'by_uri', 'value' => $sUri]);
- if(!empty($aPage) && is_array($aPage))
- return ['msg' => _t('_adm_bp_err_page_uri')];
- $iVisibleFor = BxDolStudioUtils::getVisibilityValue($oForm->getCleanValue('visible_for'), $oForm->getCleanValue('visible_for_levels'));
- BxDolForm::setSubmittedValue('visible_for_levels', $iVisibleFor, $oForm->aFormAttrs['method']);
- unset($oForm->aInputs['visible_for']);
- $aValsToAdd = [
- 'author' => bx_get_logged_profile_id(),
- 'object' => $sObject,
- 'url' => $this->sPageBaseUrl . $sUri,
- 'added' => time()
- ];
- $this->onSavePage($oForm, $aValsToAdd);
- $iId = (int)$oForm->insert($aValsToAdd);
- if($iId != 0) {
- $this->onPageChanged($oForm, $aValsToAdd);
- return ['eval' => $sJsObject . '.onCreatePage(\'' . $sModule . '\', \'' . $sObject . '\')'];
- } else {
- return ['msg' => _t('_adm_bp_err_page_create')];
- }
- }
- $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['add_popup_id'], _t('_adm_bp_txt_create_popup'), $oTemplate->parseHtmlByName('bp_add_page.html', array(
- 'js_object' => $sJsObject,
- 'form_id' => $oForm->getId(),
- 'form' => $oForm->getCode(true)
- )));
- return array('popup' => $sContent);
- }
- protected function actionPageEdit()
- {
- $sJsObject = $this->getPageJsObject();
- $oTemplate = BxDolStudioTemplate::getInstance();
- $oForm = $this->_getPageEditForm();
- $oForm->initChecker();
- if($oForm->isSubmittedAndValid()) {
- unset($oForm->aInputs['settings']);
- foreach($this->aPageSettings as $aSetting)
- $oForm->aInputs = array_merge($oForm->aInputs, $this->{'getSettings' . $this->getClassName($aSetting['name']) . 'Fields'}($this->aPageRebuild, false));
- $mixedVisibleFor = $oForm->getCleanValue('visible_for');
- $mixedVisibleForLevels = $oForm->getCleanValue('visible_for_levels');
- if($mixedVisibleFor !== false && $mixedVisibleForLevels !== false) {
- $iVisibleFor = BxDolStudioUtils::getVisibilityValue($mixedVisibleFor, $mixedVisibleForLevels);
- BxDolForm::setSubmittedValue('visible_for_levels', $iVisibleFor, $oForm->aFormAttrs['method']);
- unset($oForm->aInputs['visible_for']);
- }
- $this->onSavePage($oForm, $this->aPageRebuild);
- if($oForm->update($this->aPageRebuild['id'])) {
- $this->onPageChanged($oForm, $this->aPageRebuild);
- $iLevelId = $oForm->getCleanValue('layout_id');
- if(!empty($iLevelId) && $iLevelId != $this->aPageRebuild['layout_id']) {
- $aLayoutOld = array();
- $this->oDb->getLayouts(array('type' => 'by_id', 'value' => $this->aPageRebuild['layout_id']), $aLayoutOld, false);
- $aLayoutNew = array();
- $this->oDb->getLayouts(array('type' => 'by_id', 'value' => $iLevelId), $aLayoutNew, false);
- if($aLayoutOld['cells_number'] > $aLayoutNew['cells_number'] && $this->oDb->resetBlocksByPage($this->sPage, $aLayoutNew['cells_number']) === false)
- return array('msg' => _t('_adm_bp_err_save'));
- return array('eval' => $sJsObject . '.onSaveSettingsLayout()');
- }
- return array();
- }
- else
- return array('msg' => _t('_adm_bp_err_save'));
- }
- $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['edit_popup_id'], _t('_adm_bp_txt_settings_popup'), $oTemplate->parseHtmlByName('bp_edit_page.html', array(
- 'js_object' => $sJsObject,
- 'form_id' => $oForm->getId(),
- 'form' => $oForm->getCode(true)
- )));
- return array('popup' => $sContent);
- }
- protected function actionPageDelete()
- {
- if(empty($this->sPage) || empty($this->aPageRebuild) || !is_array($this->aPageRebuild))
- return array('msg' => _t('_adm_bp_err_page_delete'));
- $oLangauge = BxDolStudioLanguagesUtils::getInstance();
- $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
- $aBlocks = array();
- $this->oDb->getBlocks(array('type' => 'by_object', 'value' => $this->sPage), $aBlocks, false);
- if(is_array($aBlocks) && !empty($aBlocks)) {
- foreach($aBlocks as $aBlock)
- $this->onBlockDelete($aBlock);
- $this->oDb->deleteBlocks(array('type' => 'by_object', 'value' => $this->sPage));
- }
- if($this->oDb->deletePages(array('type' => 'by_object', 'value' => $this->sPage))) {
- $oLangauge->deleteLanguageString($this->aPageRebuild['title_system']);
- $oLangauge->deleteLanguageString($this->aPageRebuild['title']);
- $this->onPageChanged(null, $this->aPageRebuild);
- return array('eval' => 'window.parent.location.href = "' . sprintf($this->sTypeUrl, $this->sType) . '";');
- }
- return array('msg' => _t('_adm_bp_err_page_delete'));
- }
- protected function actionBlockList()
- {
- $sModule = BX_DOL_STUDIO_BP_TYPE_DEFAULT;
- if(bx_get('bp_module') !== false)
- $sModule = bx_process_input(bx_get('bp_module'));
- return array(
- 'content' => $this->getBlockList($sModule)
- );
- }
- protected function actionBlockCreate()
- {
- $sJsObject = $this->getPageJsObject();
- $oTemplate = BxDolStudioTemplate::getInstance();
- $sSelected = BX_DOL_STUDIO_BP_SKELETONS;
- $aForm = array(
- 'form_attrs' => array(
- 'id' => 'adm-bp-block-create',
- 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionBlockCreate,
- 'method' => 'post'
- ),
- 'params' => array (
- 'db' => array(
- 'table' => 'sys_pages_blocks',
- 'key' => 'id',
- 'uri' => '',
- 'uri_title' => '',
- 'submit_name' => 'do_submit'
- ),
- ),
- 'inputs' => array (
- 'blocks' => array(
- 'type' => 'custom',
- 'name' => 'blocks',
- 'content' => '',
- 'db' => array (
- 'pass' => 'Int',
- ),
- ),
- )
- );
- $aMenu = [
- BX_DOL_STUDIO_BP_SKELETONS => [
- 'name' => BX_DOL_STUDIO_BP_SKELETONS,
- 'icon' => 'mi-qrcode.svg',
- 'icon_bg' => true,
- 'title' => '_sys_block_types_skeletons',
- 'selected' => $sSelected == BX_DOL_STUDIO_BP_SKELETONS,
- ],
- BX_DOL_STUDIO_MODULE_SYSTEM => [
- 'name' => BX_DOL_STUDIO_MODULE_SYSTEM,
- 'icon' => 'mi-cog.svg',
- 'icon_bg' => true,
- 'title' => '_sys_block_types_system',
- 'selected' => $sSelected == BX_DOL_STUDIO_MODULE_SYSTEM,
- ],
- BX_DOL_STUDIO_MODULE_CUSTOM => [
- 'name' => BX_DOL_STUDIO_MODULE_CUSTOM,
- 'icon' => 'mi-wrench.svg',
- 'icon_bg' => true,
- 'title' => '_sys_block_types_custom',
- 'selected' => $sSelected == BX_DOL_STUDIO_MODULE_CUSTOM,
- ]
- ];
- $aModules = BxDolModuleQuery::getInstance()->getModulesBy(['type' => 'type', 'value' => [BX_DOL_MODULE_TYPE_MODULE, BX_DOL_MODULE_TYPE_TEMPLATE]]);
- $aModulesWithBlocks = $this->oDb->getModulesWithCopyableBlocks();
- foreach($aModules as $aModule) {
- $sName = $aModule['name'];
- if(!in_array($sName, $aModulesWithBlocks))
- continue;
- if(!empty($aMenu[$sName]))
- $aMenu[$sName] = array_merge($aMenu[$sName], $aModule);
- else
- $aMenu[$sName] = $aModule;
- if(empty($aMenu[$sName]['icon']))
- $aMenu[$sName]['icon'] = BxDolStudioUtils::getModuleIcon($aModule, 'menu', false);
- }
- foreach($aMenu as $sKey => $aItem)
- $aMenu[$sKey]['onclick'] = $sJsObject . '.onChangeModule(\'' . $aItem['name'] . '\', this);';
- $oMenu = new BxTemplStudioMenu(['template' => 'menu_side.html', 'menu_items' => $aMenu]);
- $aForm['inputs']['blocks']['content'] = $oTemplate->parseHtmlByName('bp_add_block_form.html', [
- 'menu' => $oMenu->getCode(),
- 'html_block_lists_id' => $this->aHtmlIds['block_lists_id'],
- 'blocks' => $this->getBlockList($sSelected)
- ]);
- $oForm = new BxTemplStudioFormView($aForm);
- $oForm->initChecker();
- if($oForm->isSubmittedAndValid()) {
- $aIds = $oForm->getCleanValue('blocks');
- $aBlocks = array();
- $this->oDb->getBlocks(array('type' => 'by_ids', 'value' => $aIds), $aBlocks, false);
- $oLanguage = BxDolStudioLanguagesUtils::getInstance();
- $oStorege = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
- $bResult = true;
- foreach($aBlocks as $aBlock) {
- $sModule = $aBlock['module'];
- $sTitleKey = $this->getSystemName($aBlock['title'] . '_' . time());
- $aTitleValues = $oLanguage->getLanguageString($aBlock['title']);
- unset($aBlock['id']);
- $aBlock['object'] = $this->sPage;
- $aBlock['cell_id'] = 1;
- $aBlock['module'] = $this->getBlockModule($aBlock);
- $aBlock['title'] = $sTitleKey;
- $aBlock['copyable'] = $sModule == BX_DOL_STUDIO_BP_SKELETONS ? 1 : 0;
- $aBlock['deletable'] = 1;
- //--- Process Lang copy
- $sContentKey = $sContentValue = "";
- if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && $aBlock['content'] != '') {
- $sContentKey = $this->getSystemName($aBlock['content'] . '_' . time());
- $sContentValue = _t($aBlock['content']);
- $aBlock['content'] = $sContentKey;
- $oLanguage->addLanguageString($sContentKey, $sContentValue);
- }
- //--- Process Image copy
- $iImageId = $sImageAlign = "";
- if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && $aBlock['content'] != '') {
- list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
- $aBlock['content'] = "";
- if(is_numeric($iImageId) && (int)$iImageId != 0 && ($iImageId = $oStorege->storeFileFromStorage(array('id' => $iImageId))) !== false)
- $aBlock['content'] = implode($this->sParamsDivider, array($iImageId, $sImageAlign));
- }
- // add indexing data
- $aBlock = array_merge($aBlock, $this->getIndexingDataForBlock($aBlock['type'], $aBlock['content']));
- if(!$this->oDb->insertBlock($aBlock)) {
- if($sContentKey != "")
- $oLanguage->deleteLanguageString($sContentKey);
- if($iImageId != "")
- $oStorege->deleteFile((int)$iImageId, 0);
- $bResult = false;
- break;
- }
- //--- Process Title copy
- foreach($aTitleValues as $iLangId => $aTitleValue)
- $oLanguage->addLanguageString($sTitleKey, $aTitleValue['string'], $iLangId);
- }
- if($bResult)
- return array('eval' => $sJsObject . '.onCreateBlock(oData)');
- else
- return array('msg' => _t('_adm_bp_err_block_added'));
- }
- $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['create_block_popup_id'], _t('_adm_bp_txt_new_block_popup'), $oTemplate->parseHtmlByName('bp_add_block.html', array(
- 'action' => 'create',
- 'form_id' => $aForm['form_attrs']['id'],
- 'form' => $oForm->getCode(true)
- )));
- return array('popup' => $sContent);
- }
- protected function actionBlockEdit()
- {
- $sJsObject = $this->getPageJsObject();
- $oTemplate = BxDolStudioTemplate::getInstance();
- $iId = (int)bx_get('id');
- if(!$iId)
- return array();
- $aBlock = array();
- $this->oDb->getBlocks(array('type' => 'by_id', 'value' => $iId), $aBlock, false);
- if(empty($aBlock) || !is_array($aBlock))
- return array('msg' => _t('_adm_bp_err_block_not_found'));
- bx_import('BxDolStudioUtils');
- $aForm = array(
- 'form_attrs' => array(
- 'id' => 'adm-bp-block-edit',
- 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionBlockEdit,
- 'method' => 'post'
- ),
- 'params' => array (
- 'db' => array(
- 'table' => 'sys_pages_blocks',
- 'key' => 'id',
- 'uri' => '',
- 'uri_title' => '',
- 'submit_name' => 'do_submit'
- ),
- ),
- 'inputs' => array (
- 'id' => array(
- 'type' => 'hidden',
- 'name' => 'id',
- 'value' => $iId,
- 'db' => array (
- 'pass' => 'Int',
- ),
- ),
- 'title' => array(
- 'type' => 'text_translatable',
- 'name' => 'title',
- 'caption' => _t('_adm_bp_txt_block_title'),
- 'info' => _t('_adm_bp_dsc_block_title'),
- 'value' => $aBlock['title'],
- 'required' => '1',
- 'db' => array (
- 'pass' => 'Xss',
- ),
- 'checker' => array (
- 'func' => 'LengthTranslatable',
- 'params' => array(3, 100, 'title'),
- 'error' => _t('_adm_bp_err_block_title'),
- ),
- ),
- 'description' => array(
- 'type' => 'text_translatable',
- 'name' => 'description',
- 'caption' => _t('_adm_bp_txt_block_description'),
- 'info' => _t('_adm_bp_dsc_block_description'),
- 'value' => $aBlock['description'],
- 'required' => '0',
- 'db' => array (
- 'pass' => 'Xss',
- ),
- ),
- 'icon' => array(
- 'type' => 'textarea',
- 'name' => 'icon',
- 'caption' => _t('_adm_bp_txt_block_icon'),
- 'info' => _t('_adm_bp_dsc_block_icon'),
- 'value' => $aBlock['icon'],
- 'code' => 1,
- 'required' => '0',
- 'db' => array (
- 'pass' => 'Xss',
- ),
- 'attrs' => array('class' => 'bx-form-input-textarea-small'),
- ),
- 'designbox_id' => array(
- 'type' => 'select',
- 'name' => 'designbox_id',
- 'caption' => _t('_adm_bp_txt_block_designbox'),
- 'info' => '',
- 'value' => $this->sSelectKeyPrefix . $aBlock['designbox_id'],
- 'values' => array(
- array('key' => '', 'value' => _t('_adm_bp_txt_block_designbox_empty')),
- ),
- 'required' => '1',
- 'db' => array (
- 'pass' => 'Xss',
- ),
- 'checker' => array (
- 'func' => 'avail',
- 'params' => array(),
- 'error' => _t('_adm_bp_err_block_designbox'),
- ),
- ),
- 'async' => array(
- 'type' => 'select',
- 'name' => 'async',
- 'caption' => _t('_adm_bp_txt_block_async'),
- 'info' => '',
- 'value' => isset($aBlock['async']) ? $aBlock['async'] : 0,
- 'required' => '0',
- 'db' => array (
- 'pass' => 'Int',
- ),
- ),
- 'submenu' => array(
- 'type' => 'select',
- 'name' => 'submenu',
- 'caption' => _t('_adm_bp_txt_block_submenu'),
- 'info' => '',
- 'value' => isset($aBlock['submenu']) ? $aBlock['submenu'] : '',
- 'required' => '0',
- 'db' => array (
- 'pass' => 'Xss',
- ),
- ),
- 'tabs' => array(
- 'type' => 'switcher',
- 'name' => 'tabs',
- 'caption' => _t('_adm_bp_txt_block_tabs'),
- 'info' => '',
- 'value' => '1',
- 'checked' => $aBlock['tabs'] == '1',
- 'db' => array (
- 'pass' => 'Int',
- )
- ),
- 'hidden_on' => array(
- 'type' => 'select_multiple',
- 'name' => 'hidden_on',
- 'caption' => _t('_adm_bp_txt_block_hidden_on'),
- 'info' => '',
- 'value' => (int)$aBlock['hidden_on'],
- 'values' => array(
- BX_DB_HIDDEN_PHONE => _t('_adm_bp_txt_block_hidden_on_phone'),
- BX_DB_HIDDEN_TABLET => _t('_adm_bp_txt_block_hidden_on_tablet'),
- BX_DB_HIDDEN_DESKTOP => _t('_adm_bp_txt_block_hidden_on_desktop'),
- BX_DB_HIDDEN_MOBILE => _t('_adm_bp_txt_block_hidden_on_mobile')
- ),
- 'db' => array (
- 'pass' => 'Set',
- )
- ),
- 'visible_for' => array(
- 'type' => 'select',
- 'name' => 'visible_for',
- 'caption' => _t('_adm_bp_txt_block_visible_for'),
- 'info' => '',
- 'value' => $aBlock['visible_for_levels'] == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
- 'values' => array(
- array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_bp_txt_block_visible_for_all')),
- array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_bp_txt_block_visible_for_selected')),
- ),
- 'required' => '0',
- 'attrs' => array(
- 'onchange' => $sJsObject . '.onChangeVisibleFor(this)'
- ),
- 'db' => array (
- 'pass' => 'Xss',
- )
- ),
- 'visible_for_levels' => array(
- 'type' => 'checkbox_set',
- 'name' => 'visible_for_levels',
- 'caption' => _t('_adm_bp_txt_block_visible_for_levels'),
- 'info' => _t('_adm_bp_dsc_block_visible_for_levels'),
- 'value' => array(),
- 'values' => array(),
- 'tr_attrs' => array(
- 'style' => $aBlock['visible_for_levels'] == BX_DOL_INT_MAX ? 'display:none' : ''
- ),
- 'db' => array (
- 'pass' => 'Int',
- )
- ),
- 'content_empty' => array(
- 'type' => 'text_translatable',
- 'name' => 'content_empty',
- 'caption' => _t('_adm_bp_txt_block_content_empty'),
- 'info' => _t('_adm_bp_dsc_block_content_empty'),
- 'value' => $aBlock['content_empty'],
- 'db' => array (
- 'pass' => 'Xss',
- ),
- ),
- 'help' => array(
- 'type' => 'textarea_translatable',
- 'name' => 'help',
- 'caption' => _t('_adm_bp_txt_block_help'),
- 'info' => '',
- 'value' => $aBlock['help'],
- 'required' => '0',
- 'html' => 2,
- 'db' => array (
- 'pass' => 'Xss',
- ),
- ),
- 'class' => array(
- 'type' => 'text',
- 'name' => 'class',
- 'caption' => _t('_adm_bp_txt_block_class'),
- 'info' => '',
- 'value' => $aBlock['class'],
- 'required' => '0',
- 'db' => array (
- 'pass' => 'Xss',
- ),
- ),
- 'cache_lifetime' => array(
- 'type' => 'text',
- 'name' => 'cache_lifetime',
- 'caption' => _t('_adm_bp_txt_block_cache_lifetime'),
- 'info' => '',
- 'value' => isset($aBlock['cache_lifetime']) ? $aBlock['cache_lifetime'] : 0,
- 'required' => '0',
- 'db' => array (
- 'pass' => 'Int',
- ),
- ),
- 'active' => array(
- 'type' => 'switcher',
- 'name' => 'active',
- 'caption' => _t('_adm_bp_txt_block_active'),
- 'info' => '',
- 'value' => '1',
- 'checked' => $aBlock['active'] == '1',
- 'db' => array (
- 'pass' => 'Int',
- )
- ),
- 'active_api' => array(
- 'type' => 'switcher',
- 'name' => 'active_api',
- 'caption' => _t('_adm_bp_txt_block_active_api'),
- 'info' => '',
- 'value' => '1',
- 'checked' => $aBlock['active_api'] == '1',
- 'db' => array (
- 'pass' => 'Int',
- )
- ),
- 'controls' => array(
- 'name' => 'controls',
- 'type' => 'input_set',
- array(
- 'type' => 'submit',
- 'name' => 'do_submit',
- 'value' => _t('_adm_bp_btn_block_save')
- ),
- array (
- 'type' => 'reset',
- 'name' => 'close',
- 'value' => _t('_adm_bp_btn_block_cancel'),
- 'attrs' => array(
- 'onclick' => $sJsObject . '.onEditBlockCancel(this)',
- 'class' => 'bx-def-margin-sec-left',
- ),
- )
- )
- )
- );
- $aDBoxes = array();
- $this->oDb->getDesignBoxes(array('type' => 'ordered'), $aDBoxes, false);
- foreach($aDBoxes as $aDBox)
- $aForm['inputs']['designbox_id']['values'][] = array('key' => $this->sSelectKeyPrefix . $aDBox['id'], 'value' => _t($aDBox['title']));
- $aContentPlaceholders = $this->oDb->getContentPlaceholders();
- $aForm['inputs']['async']['values'][] = array('key' => 0, 'value' => _t('_sys_no_async'));
- foreach ($aContentPlaceholders as $iKey => $sTitle)
- $aForm['inputs']['async']['values'][] = array('key' => $iKey, 'value' => _t($sTitle));
- $aSubmenus = $this->oDb->getBlockSubmenus();
- $aForm['inputs']['submenu']['values'][] = array('key' => '', 'value' => _t('_sys_menu_item_title_inherited'));
- $aForm['inputs']['submenu']['values'][] = array('key' => 'disabled', 'value' => _t('_sys_menu_item_title_disabled'));
- foreach ($aSubmenus as $sObject => $sTitle)
- $aForm['inputs']['submenu']['values'][] = array('key' => $sObject, 'value' => _t($sTitle));
- BxDolStudioUtils::getVisibilityValues($aBlock['visible_for_levels'], $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
- $aForm['inputs'] = $this->addInArray($aForm['inputs'], 'visible_for_levels', $this->getBlockContent($aBlock));
- if((int)$aBlock['deletable'] != 0)
- $aForm['inputs']['controls'][] = array (
- 'type' => 'reset',
- 'name' => 'close',
- 'value' => _t('_adm_bp_btn_block_delete'),
- 'attrs' => array(
- 'onclick' => $sJsObject . '.deleteBlock(' . $aBlock['id'] . ')',
- 'class' => 'bx-def-margin-sec-left',
- ),
- );
- $oForm = new BxTemplStudioFormView($aForm);
- $oForm->initChecker();
- if($oForm->isSubmittedAndValid()) {
- $this->onSaveBlock($oForm, $aBlock);
- // add indexing data
- $aBlockAddon = $this->getIndexingDataForBlock($aBlock['type'], $oForm->getCleanValue('content'));
- if($oForm->update($iId, $aBlockAddon) !== false)
- return array('eval' => $sJsObject . '.onEditBlock(oData)');
- else
- return array('msg' => _t('_adm_bp_err_block_edit'));
- }
- $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(
- 'action' => 'edit',
- 'form_id' => $aForm['form_attrs']['id'],
- 'form' => $oForm->getCode(true)
- )));
- return array('popup' => array('html' => $sContent, 'options' => array('onBeforeShow' => $sJsObject . '.onEditBlockBeforeShow($el)')));
- }
- protected function actionBlockDelete()
- {
- $sJsObject = $this->getPageJsObject();
- $iId = (int)bx_get('id');
- $aBlock = array();
- $this->oDb->getBlocks(array('type' => 'by_id', 'value' => $iId), $aBlock, false);
- if(empty($aBlock) || !is_array($aBlock))
- return array('msg' => _t('_adm_bp_err_block_not_found'));
- if((int)$aBlock['deletable'] == 0)
- return array('msg' => _t('_adm_bp_err_block_not_deletable'));
- if(!$this->oDb->deleteBlocks(array('type' => 'by_id', 'value' => $iId)))
- return array('msg' => _t('_adm_bp_err_block_delete'));
- $this->onBlockDelete($aBlock);
- return array('eval' => $sJsObject . '.onDeleteBlock(' . $iId . ', oData)');
- }
- protected function actionUriGet()
- {
- $oLanguage = BxDolStudioLanguagesUtils::getInstance();
- $aLanguages = $oLanguage->getLanguages();
- $sLanguageDef = $oLanguage->getDefaultLangName();
- $sLanguageCur = $oLanguage->getCurrentLangName(false);
- $aValues = array();
- foreach($aLanguages as $sName => $sTitle)
- if(($mixedValue = bx_get($sName)) !== false)
- $aValues[$sName] = bx_process_input($mixedValue);
- $sUri = "";
- if(($mixedValue = bx_get('uri')) !== false)
- $sUri = bx_process_input($mixedValue);
- else if(array_key_exists('en', $aValues) && $aValues['en'] != '')
- $sUri = $aValues['en'];
- else if(array_key_exists($sLanguageDef, $aValues) && $aValues[$sLanguageDef] != '')
- $sUri = $aValues[$sLanguageDef];
- else if(array_key_exists($sLanguageCur, $aValues) && $aValues[$sLanguageCur] != '')
- $sUri = $aValues[$sLanguageCur];
- else if(count($aValues) > 0)
- foreach($aValues as $sValue)
- if(!empty($sValue)) {
- $sUri = $sValue;
- break;
- }
- $sUri = $sUri != "" ? uriGenerate($sUri, 'sys_objects_page', 'uri') : "";
- $sUrl = BxDolPermalinks::getInstance()->permalink($this->sPageBaseUrl . $sUri);
- return array('eval' => $this->getPageJsObject() . '.onGetUri(oData)', 'uri' => $sUri, 'url' => $sUrl);
- }
- protected function getSettingsOptions($aPage = array(), $bCreate = true, $bInputsOnly = false)
- {
- $aForm = array(
- 'form_attrs' => array(
- 'id' => 'adm-bp-settings-options',
- ),
- 'params' => array (
- 'remove_form' => '1',
- 'csrf' => array(
- 'disable' => true
- )
- ),
- 'inputs' => array (
- 'title_system' => array(
- 'type' => 'text_translatable',
- 'name' => 'title_system',
- 'caption' => _t('_adm_bp_txt_page_title_system'),
- 'info' => _t('_adm_bp_dsc_page_title_system'),
- 'value' => isset($aPage['title_system']) ? $aPage['title_system'] : '',
- 'required' => '1',
- 'db' => array (
- 'pass' => 'Xss',
- ),
- 'checker' => array (
- 'func' => 'length',
- 'params' => array(3,100),
- 'error' => _t('_adm_bp_err_page_title_system'),
- ),
- ),
- 'title' => array(
- 'type' => 'text_translatable',
- 'name' => 'title',
- 'caption' => _t('_adm_bp_txt_page_title'),
- 'info' => _t('_adm_bp_dsc_page_title'),
- 'value' => isset($aPage['title']) ? $aPage['title'] : '',
- 'required' => '1',
- 'db' => array (
- 'pass' => 'Xss',
- ),
- 'checker' => array (
- 'func' => 'length',
- 'params' => array(3,100),
- 'error' => _t('_adm_bp_err_page_title'),
- ),
- ),
- 'url' => array(
- 'type' => 'text',
- 'name' => 'url',
- 'caption' => _t('_adm_bp_txt_page_url'),
- 'info' => _t('_adm_bp_dsc_page_url'),
- 'value' => isset($aPage['url']) ? BxDolPermalinks::getInstance()->permalink($aPage['url']) : '',
- 'required' => '0',
- 'attrs' => array(
- 'id' => $this->aHtmlIds['url_field_id'],
- 'disabled' => 'disabled'
- ),
- ),
- 'type_id' => array(
- 'type' => 'select',
- 'name' => 'type_id',
- 'caption' => _t('_adm_bp_txt_page_type_id'),
- 'info' => _t('_adm_bp_dsc_page_type_id'),
- 'value' => isset($aPage['type_id']) ? $aPage['type_id'] : '',
- 'required' => '1',
- 'db' => array (
- 'pass' => 'Int',
- ),
- ),
- 'submenu' => array(
- 'type' => 'select',
- 'name' => 'submenu',
- 'caption' => _t('_adm_bp_txt_page_submenu'),
- 'info' => _t('_adm_bp_dsc_page_submenu'),
- 'value' => isset($aPage['submenu']) ? $aPage['submenu'] : '',
- 'required' => '0',
- 'db' => array (
- 'pass' => 'Xss',
- ),
- ),
- 'sticky_columns' => array(
- 'type' => 'switcher',
- 'name' => 'sticky_columns',
- 'caption' => _t('_adm_bp_txt_page_sticky_columns'),
- 'info' => '',
- 'value' => '1',
- 'checked' => isset($aPage['sticky_columns']) && $aPage['sticky_columns'] == 1,
- 'db' => array (
- 'pass' => 'Int',
- )
- )
- )
- );
-
- $aTypes = array();
- $this->oDb->getTypes(array('type' => 'all'), $aTypes, false);
- foreach($aTypes as $aType)
- $aForm['inputs']['type_id']['values'][] = array('key' => $aType['id'], 'value' => _t($aType['title']));
- $aSubmenus = $this->oDb->getSubmenus();
- $aForm['inputs']['submenu']['values'][] = array('key' => '', 'value' => _t('_sys_menu_item_title_inherited'));
- $aForm['inputs']['submenu']['values'][] = array('key' => 'disabled', 'value' => _t('_sys_menu_item_title_disabled'));
- foreach ($aSubmenus as $sObject => $sTitle)
- $aForm['inputs']['submenu']['values'][] = array('key' => $sObject, 'value' => _t($sTitle));
- if($bCreate) {
- $sJsObject = $this->getPageJsObject();
- $aForm['inputs']['title']['attrs']['onblur'] = $sJsObject . '.getUri(this);';
- $aForm['inputs'] = bx_array_insert_before(array(
- 'uri' => array(
- 'type' => 'text',
- 'name' => 'uri',
- 'caption' => _t('_adm_bp_txt_page_uri'),
- 'info' => _t('_adm_bp_dsc_page_uri'),
- 'value' => '',
- 'required' => '1',
- 'attrs' => array(
- 'id' => $this->aHtmlIds['uri_field_id'],
- 'onblur' => $sJsObject . '.getUri(this);'
- ),
- 'db' => array (
- 'pass' => 'Xss',
- ),
- 'checker' => array (
- 'func' => 'length',
- 'params' => array(3,100),
- 'error' => _t('_adm_bp_err_page_uri'),
- ),
- )
- ), $aForm['inputs'], 'url');
- }
- if($bInputsOnly)
- return $aForm['inputs'];
- $oForm = new BxTemplStudioFormView($aForm);
- return $oForm->getCode();
- }
- protected function getSettingsOptionsFields($aPage = array(), $bCreate = true)
- {
- return $this->getSettingsOptions($aPage, $bCreate, true);
- }
- protected function getSettingsCover($aPage = array(), $bCreate = true, $bInputsOnly = false)
- {
- $aForm = array(
- 'form_attrs' => array(
- 'id' => 'adm-bp-settings-cover',
- ),
- 'params' => array (
- 'remove_form' => '1',
- 'csrf' => array(
- 'disable' => true
- )
- ),
- 'inputs' => array (
- 'cover' => array(
- 'type' => 'select',
- 'name' => 'cover',
- 'caption' => _t('_adm_bp_txt_page_cover'),
- 'info' => '',
- 'value' => isset($aPage['cover']) ? (int)$aPage['cover'] : '1',
- 'values' => array(
- array('key' => 0, 'value' => _t('_adm_bp_txt_page_cover_0')),
- array('key' => 1, 'value' => _t('_adm_bp_txt_page_cover_1')),
- array('key' => 2, 'value' => _t('_adm_bp_txt_page_cover_2')),
- array('key' => 3, 'value' => _t('_adm_bp_txt_page_cover_3'))
- ),
- 'db' => array (
- 'pass' => 'Int',
- )
- ),
- 'cover_image' => array(
- 'type' => 'files',
- 'name' => 'cover_image',
- 'storage_object' => $this->sStorage,
- 'images_transcoder' => $this->sTranscoderCover,
- 'uploaders' => $this->aUploadersCover,
- 'multiple' => false,
- 'content_id' => isset($aPage['id']) ? $aPage['id'] : 0,
- 'ghost_template' => BxTemplStudioFunctions::getInstance()->getDefaultGhostTemplate('cover_image'),
- 'caption' => _t('_adm_bp_txt_page_cover_image'),
- 'db' => array (
- 'pass' => 'Int',
- )
- ),
- 'cover_title' => array(
- 'type' => 'text_translatable',
- 'name' => 'cover_title',
- 'caption' => _t('_adm_bp_txt_page_cover_title'),
- 'info' => '',
- 'value' => isset($aPage['cover_title']) ? $aPage['cover_title'] : '',
- 'db' => array (
- 'pass' => 'Xss',
- )
- ),
- )
- );
- if($bInputsOnly)
- return $aForm['inputs'];
- $oForm = new BxTemplStudioFormView($aForm);
- return $oForm->getCode();
- }
- protected function getSettingsCoverFields($aPage = array(), $bCreate = true)
- {
- return $this->getSettingsCover($aPage, $bCreate, true);
- }
- protected function getSettingsLayout($aPage = array(), $bCreate = true, $bInputsOnly = false)
- {
- $sJsObject = $this->getPageJsObject();
- $oTemplate = BxDolStudioTemplate::getInstance();
- $iLayout = isset($aPage['layout_id']) ? (int)$aPage['layout_id'] : 5;
- $aLayouts = array();
- $this->oDb->getLayouts(array('type' => 'all'), $aLayouts, false);
- $aTmplParams = array(
- 'bx_repeat:layouts' => array(),
- 'form' => ''
- );
- foreach($aLayouts as $aLayout)
- $aTmplParams['bx_repeat:layouts'][] = array(
- 'id' => $aLayout['id'],
- 'html_id' => $this->aHtmlIds['layout_id'] . $aLayout['id'],
- 'js_object' => $sJsObject,
- 'bx_if:active' => array(
- 'condition' => (int)$aLayout['id'] == $iLayout,
- 'content' => array()
- ),
- 'icon' => $oTemplate->getImageUrl($aLayout['icon']),
- 'title' => _t($aLayout['title']),
- );
- $aForm = array(
- 'form_attrs' => array(
- 'id' => 'adm-bp-settings-layout',
- ),
- 'params' => array (
- 'remove_form' => '1',
- 'csrf' => array(
- 'disable' => true
- )
- ),
- 'inputs' => array (
- 'layout_id' => array(
- 'type' => 'hidden',
- 'name' => 'layout_id',
- 'value' => $iLayout,
- 'db' => array (
- 'pass' => 'Int',
- ),
- )
- )
- );
- if($bInputsOnly)
- return $aForm['inputs'];
- $oForm = new BxTemplStudioFormView($aForm);
- $aTmplParams['form'] = $oForm->getCode();
- return $oTemplate->parseHtmlByName('bp_layouts.html', $aTmplParams);
- }
- protected function getSettingsLayoutFields($aPage = array(), $bCreate = true)
- {
- return $this->getSettingsLayout($aPage, $bCreate, true);
- }
- protected function getSettingsVisibility($aPage = array(), $bCreate = true, $bInputsOnly = false)
- {
- $iVisibleForLevels = isset($aPage['visible_for_levels']) ? (int)$aPage['visible_for_levels'] : BX_DOL_INT_MAX;
- if(isset($aPage['visible_for_levels_editable']) && (int)$aPage['visible_for_levels_editable'] == 0)
- $aInputs = array(
- 'visible_for_levels' => array(
- 'type' => 'custom',
- 'name' => 'visible_for_levels',
- 'content' => MsgBox(_t('_adm_bp_err_page_visible_for_levels'))
- )
- );
- else {
- bx_import('BxDolStudioUtils');
- $aInputs = array(
- 'visible_for' => array(
- 'type' => 'select',
- 'name' => 'visible_for',
- 'caption' => _t('_adm_bp_txt_block_visible_for'),
- 'info' => '',
- 'value' => $iVisibleForLevels == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
- 'values' => array(
- array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_bp_txt_block_visible_for_all')),
- array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_bp_txt_block_visible_for_selected')),
- ),
- 'required' => '0',
- 'attrs' => array(
- 'onchange' => $this->getPageJsObject() . '.onChangeVisibleFor(this)'
- ),
- 'db' => array (
- 'pass' => 'Xss',
- )
- ),
- 'visible_for_levels' => array(
- 'type' => 'checkbox_set',
- 'name' => 'visible_for_levels',
- 'caption' => _t('_adm_bp_txt_page_visible_for_levels'),
- 'info' => _t('_adm_bp_dsc_page_visible_for_levels'),
- 'value' => array(),
- 'values' => array(),
- 'tr_attrs' => array(
- 'style' => $iVisibleForLevels == BX_DOL_INT_MAX ? 'display:none' : ''
- ),
- 'db' => array (
- 'pass' => 'Int',
- )
- )
- );
- }
- $aForm = array(
- 'form_attrs' => array(
- 'id' => 'adm-bp-settings-visibility',
- ),
- 'params' => array (
- 'remove_form' => '1',
- 'csrf' => array(
- 'disable' => true
- )
- ),
- 'inputs' => $aInputs
- );
- BxDolStudioUtils::getVisibilityValues($iVisibleForLevels, $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
- if($bInputsOnly)
- return $aForm['inputs'];
- $oForm = new BxTemplStudioFormView($aForm);
- return $oForm->getCode();
- }
- protected function getSettingsVisibilityFields($aPage = array(), $bCreate = true)
- {
- return $this->getSettingsVisibility($aPage, $bCreate, true);
- }
- protected function getSettingsCache($aPage = array(), $bCreate = true, $bInputsOnly = false)
- {
- $aForm = array(
- 'form_attrs' => array(
- 'id' => 'adm-bp-settings-cache',
- ),
- 'params' => array (
- 'remove_form' => '1',
- 'csrf' => array(
- 'disable' => true
- )
- ),
- 'inputs' => array (
- 'cache_lifetime' => array(
- 'type' => 'text',
- 'name' => 'cache_lifetime',
- 'caption' => _t('_adm_bp_txt_page_cache_lifetime'),
- 'info' => _t('_adm_bp_dsc_page_cache_lifetime'),
- 'value' => isset($aPage['cache_lifetime']) ? $aPage['cache_lifetime'] : 0,
- 'required' => '',
- 'attrs' => array(
- 'disabled' => isset($aPage['cache_editable']) && (int)$aPage['cache_editable'] == 0 ? 'disabled' : ''
- ),
- 'db' => array (
- 'pass' => 'Int',
- )
- ),
- )
- );
- if($bInputsOnly)
- return $aForm['inputs'];
- $oForm = new BxTemplStudioFormView($aForm);
- return $oForm->getCode();
- }
- protected function getSettingsCacheFields($aPage = array(), $bCreate = true)
- {
- return $this->getSettingsCache($aPage, $bCreate, true);
- }
- protected function getSettingsSeo($aPage = array(), $bCreate = true, $bInputsOnly = false)
- {
- $aForm = array(
- 'form_attrs' => array(
- 'id' => 'adm-bp-settings-seo',
- ),
- 'params' => array (
- 'remove_form' => '1',
- 'csrf' => array(
- 'disable' => true
- )
- ),
- 'inputs' => array (
- 'meta_title' => array(
- 'type' => 'text',
- 'name' => 'meta_title',
- 'caption' => _t('_adm_bp_txt_page_meta_title'),
- 'value' => isset($aPage['meta_title']) ? $aPage['meta_title'] : '',
- 'db' => array (
- 'pass' => 'Xss',
- ),
- ),
- 'meta_description' => array(
- 'type' => 'textarea',
- 'name' => 'meta_description',
- 'caption' => _t('_adm_bp_txt_page_meta_description'),
- 'info' => _t('_adm_bp_dsc_page_meta_description'),
- 'value' => isset($aPage['meta_description']) ? $aPage['meta_description'] : '',
- 'db' => array (
- 'pass' => 'Xss',
- ),
- ),
- 'meta_keywords' => array(
- 'type' => 'textarea',
- 'name' => 'meta_keywords',
- 'caption' => _t('_adm_bp_txt_page_meta_keywords'),
- 'info' => _t('_adm_bp_dsc_page_meta_keywords'),
- 'value' => isset($aPage['meta_keywords']) ? $aPage['meta_keywords'] : '',
- 'db' => array (
- 'pass' => 'Xss',
- ),
- ),
- 'meta_robots' => array(
- 'type' => 'text',
- 'name' => 'meta_robots',
- 'caption' => _t('_adm_bp_txt_page_meta_robots'),
- 'info' => _t('_adm_bp_dsc_page_meta_robots'),
- 'value' => isset($aPage['meta_robots']) ? $aPage['meta_robots'] : '',
- 'required' => '0',
- 'db' => array (
- 'pass' => 'Xss',
- )
- )
- )
- );
- if($bInputsOnly)
- return $aForm['inputs'];
- $oForm = new BxTemplStudioFormView($aForm);
- return $oForm->getCode();
- }
- protected function getSettingsSeoFields($aPage = array(), $bCreate = true)
- {
- return $this->getSettingsSeo($aPage, $bCreate, true);
- }
- protected function getSettingsInjections($aPage = array(), $bCreate = true, $bInputsOnly = false)
- {
- $aForm = array(
- 'form_attrs' => array(
- 'id' => 'adm-bp-injections-seo',
- ),
- 'params' => array (
- 'remove_form' => '1',
- 'csrf' => array(
- 'disable' => true
- )
- ),
- 'inputs' => array (
- 'inj_head' => array(
- 'type' => 'textarea',
- 'name' => 'inj_head',
- 'caption' => _t('_adm_bp_txt_page_inj_head'),
- 'info' => _t('_adm_bp_dsc_page_inj_head'),
- 'value' => isset($aPage['inj_head']) ? $aPage['inj_head'] : '',
- 'code' => 1,
- 'db' => array (
- 'pass' => 'XssHtml',
- ),
- ),
- 'inj_footer' => array(
- 'type' => 'textarea',
- 'name' => 'inj_footer',
- 'caption' => _t('_adm_bp_txt_page_inj_footer'),
- 'info' => _t('_adm_bp_dsc_page_inj_footer'),
- 'value' => isset($aPage['inj_footer']) ? $aPage['inj_footer'] : '',
- 'code' => 1,
- 'db' => array (
- 'pass' => 'XssHtml',
- ),
- )
- )
- );
- if($bInputsOnly)
- return $aForm['inputs'];
- $oForm = new BxTemplStudioFormView($aForm);
- return $oForm->getCode();
- }
- protected function getSettingsInjectionsFields($aPage = array(), $bCreate = true)
- {
- return $this->getSettingsInjections($aPage, $bCreate, true);
- }
- protected function getBlockIcon($aBlock)
- {
- $sIcon = $sIconUrl = "";
- $sResult = '';
- switch($aBlock['type']) {
- case BX_DOL_STUDIO_BP_BLOCK_RAW:
- $sResult = 'far file-alt';
- break;
- case BX_DOL_STUDIO_BP_BLOCK_HTML:
- $sResult = 'code';
- break;
-
- case BX_DOL_STUDIO_BP_BLOCK_CREATIVE:
- $sResult = 'object-group';
- break;
-
- case BX_DOL_STUDIO_BP_BLOCK_BENTO_GRID:
- $sResult = 'fa-grip-horizontal';
- break;
- case BX_DOL_STUDIO_BP_BLOCK_RSS:
- $sResult = 'rss';
- break;
- case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
- $sResult = 'far image';
- break;
- case BX_DOL_STUDIO_BP_BLOCK_LANG:
- $sResult = 'globe';
- break;
- case BX_DOL_STUDIO_BP_BLOCK_MENU:
- $sResult = 'list-alt';
- break;
- case BX_DOL_STUDIO_BP_BLOCK_WIKI:
- $sResult = 'file-word';
- break;
- case BX_DOL_STUDIO_BP_BLOCK_CUSTOM:
- $sResult = 'file';
- break;
- case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
- $sResult = $this->getModuleIcon($aBlock['module'], 'page');
- break;
- }
- if(strpos($sResult, '.') === false)
- $sIcon = $sResult;
- else
- $sIconUrl = $sResult;
- return array($sIcon, $sIconUrl);
- }
- protected function getBlockModule($aBlock)
- {
- return $aBlock['module'] != BX_DOL_STUDIO_BP_SKELETONS ? $aBlock['module'] : BX_DOL_STUDIO_MODULE_CUSTOM;
- }
- protected function getBlockContent($aBlock)
- {
- $aFields = array();
- switch($aBlock['type']) {
- case BX_DOL_STUDIO_BP_BLOCK_CUSTOM:
- case BX_DOL_STUDIO_BP_BLOCK_RAW:
- case BX_DOL_STUDIO_BP_BLOCK_BENTO_GRID:
- $aFields = [
- 'content' => [
- 'type' => 'textarea',
- 'name' => 'content',
- 'caption' => _t('_adm_bp_txt_block_content_raw'),
- 'info' => _t('_adm_bp_dsc_block_content_raw'),
- 'value' => $aBlock['content'],
- 'required' => '0',
- 'code' => 1,
- 'attrs' => [
- 'class' => 'bx-form-input-textarea-codemirror'
- ],
- 'db' => [
- 'pass' => 'XssHtml',
- ],
- ],
- ];
- break;
- case BX_DOL_STUDIO_BP_BLOCK_HTML:
- $aFields = [
- 'content' => [
- 'type' => 'textarea',
- 'name' => 'content',
- 'caption' => _t('_adm_bp_txt_block_content_raw'),
- 'info' => _t('_adm_bp_dsc_block_content_raw'),
- 'value' => $aBlock['content'],
- 'required' => '0',
- 'html' => 2,
- 'html_toggle' => true,
- 'attrs' => [
- 'id' => $this->aHtmlIds['edit_block_editor_id']
- ],
- 'db' => [
- 'pass' => 'XssHtml',
- ],
- ],
- 'attachments' => [
- 'type' => 'files',
- 'name' => 'attachments',
- 'storage_object' => $this->sStorage,
- 'images_transcoder' => $this->sTranscoder,
- 'uploaders' => $this->aUploaders,
- 'multiple' => true,
- 'content_id' => $aBlock['id'],
- 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('bp_fgt_attachments.html', [
- 'js_object' => $this->getPageJsObject(),
- 'name' => 'attachments',
- 'editor_id' => $this->aHtmlIds['edit_block_editor_id'],
- ]),
- 'caption' => _t('_adm_bp_txt_block_content_attachments_html')
- ]
- ];
- break;
-
- case BX_DOL_STUDIO_BP_BLOCK_CREATIVE:
- $oTemplate = BxDolStudioTemplate::getInstance();
- $sContent = $oTemplate->parseHtmlByName('bp_block_skeleton_creative.html', [
- 'html_id' => $this->aHtmlIds['edit_block_builder_id'],
- 'content_html' => $aBlock['content'],
- 'content_data' => json_encode([
- 'pages' => [
- ['component' => $aBlock['content']]
- ]
- ])
- ]);
- $aFields = [
- 'content' => [
- 'type' => 'custom',
- 'name' => 'content',
- 'caption' => _t('_adm_bp_txt_block_content_raw'),
- 'content' => $sContent,
- 'required' => '0',
- 'db' => [
- 'pass' => 'XssHtml',
- ],
- ],
- ];
- break;
- case BX_DOL_STUDIO_BP_BLOCK_LANG:
- $aFields = [
- 'content' => [
- 'type' => 'textarea_translatable',
- 'name' => 'content',
- 'caption' => _t('_adm_bp_txt_block_content_lang'),
- 'info' => _t('_adm_bp_dsc_block_content_lang'),
- 'value' => $aBlock['content'],
- 'required' => '0',
- 'html' => 2,
- 'html_toggle' => true,
- 'db' => [
- 'pass' => 'XssHtml',
- ],
- ],
- ];
- break;
- case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
- $iImageId = $sImageAlign = '';
- if($aBlock['content'] != '')
- list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
- $aFields = [
- 'content' => [
- 'type' => 'hidden',
- 'name' => 'content',
- 'value' => '',
- 'db' => [
- 'pass' => 'Xss',
- ],
- ],
- 'image_file' => [
- 'type' => 'files',
- 'name' => 'image_file',
- 'storage_object' => BX_DOL_STORAGE_OBJ_IMAGES,
- 'images_transcoder' => 'sys_image_resize',
- 'uploaders' => ['sys_html5'],
- 'multiple' => false,
- 'content_id' => $aBlock['id'],
- 'ghost_template' => BxTemplStudioFunctions::getInstance()->getDefaultGhostTemplate('image_file'),
- 'caption' => _t('_adm_bp_txt_block_content_image_file'),
- ],
- 'image_align' => [
- 'type' => 'select',
- 'name' => 'image_align',
- 'caption' => _t('_adm_bp_txt_block_content_image_align'),
- 'info' => '',
- 'value' => $sImageAlign,
- 'values' => [
- ['key' => '', 'value' => _t('_adm_bp_txt_block_content_image_align_empty')],
- ['key' => 'left', 'value' => _t('_adm_bp_txt_block_content_image_align_left')],
- ['key' => 'center', 'value' => _t('_adm_bp_txt_block_content_image_align_center')],
- ['key' => 'right', 'value' => _t('_adm_bp_txt_block_content_image_align_right')],
- ],
- 'required' => '0',
- 'db' => [
- 'pass' => 'Xss',
- ],
- ],
- ];
- break;
- case BX_DOL_STUDIO_BP_BLOCK_RSS:
- $sRssUrl = $sRssLength = '';
- if($aBlock['content'] != '')
- list($sRssUrl, $sRssLength) = explode($this->sParamsDivider, $aBlock['content']);
- $aFields = [
- 'content' => [
- 'type' => 'hidden',
- 'name' => 'content',
- 'value' => '',
- 'db' => [
- 'pass' => 'Xss',
- ],
- ],
- 'rss_url' => [
- 'type' => 'text',
- 'name' => 'rss_url',
- 'caption' => _t('_adm_bp_txt_block_content_rss_url'),
- 'info' => _t('_adm_bp_dsc_block_content_rss_url'),
- 'value' => $sRssUrl,
- 'required' => '0',
- 'db' => [
- 'pass' => 'Xss',
- ],
- ],
- 'rss_length' => [
- 'type' => 'text',
- 'name' => 'rss_length',
- 'caption' => _t('_adm_bp_txt_block_content_rss_length'),
- 'info' => _t('_adm_bp_dsc_block_content_rss_length'),
- 'value' => $sRssLength,
- 'required' => '0',
- 'db' => [
- 'pass' => 'Int',
- ],
- ],
- ];
- break;
- case BX_DOL_STUDIO_BP_BLOCK_MENU:
- $aFields = [
- 'content' => [
- 'type' => 'select',
- 'name' => 'content',
- 'caption' => _t('_adm_bp_txt_block_content_menu'),
- 'info' => '',
- 'value' => $aBlock['content'],
- 'values' => [],
- 'required' => '0',
- 'db' => [
- 'pass' => 'Xss',
- ],
- ]
- ];
- $sGroup = '';
- $aMenus = $this->oDb->getMenus(true);
- foreach($aMenus as $sKey => $aMenu) {
- if($sGroup != $aMenu['module']) {
- if(!empty($sGroup))
- $aFields['content']['values'][$sGroup . '_end'] = ['type' => 'group_end'];
- $sGroup = $aMenu['module'];
- $aFields['content']['values'][$sGroup . '_beg'] = ['type' => 'group_header', 'value' => BxDolStudioUtils::getModuleTitle($sGroup)];
- }
- $aFields['content']['values'][$sKey] = _t($aMenu['title']);
- }
- $aFields['content']['values'] = array_merge(['' => _t('_adm_bp_txt_block_content_menu_empty')], $aFields['content']['values']);
- break;
- case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
- $aService = ['module' => '', 'method' => ''];
- if($aBlock['content'] != '')
- $aService = unserialize($aBlock['content']);
- $aFields = [
- 'service_module' => [
- 'type' => 'value',
- 'name' => 'service_module',
- 'caption' => _t('_adm_bp_txt_block_content_service_module'),
- 'value' => $this->getModuleTitle($aService['module'])
- ],
- 'service_method' => [
- 'type' => 'value',
- 'name' => 'service_method',
- 'caption' => _t('_adm_bp_txt_block_content_service_method'),
- 'value' => $aService['method']
- ]
- ];
- break;
- }
- return $aFields;
- }
- protected function getBlockList($sModule)
- {
- if(empty($sModule))
- return '';
- $sJsObject = $this->getPageJsObject();
- $oTemplate = BxDolStudioTemplate::getInstance();
- $oForm = new BxTemplStudioFormView(array());
- $aInputCheckbox = [
- 'type' => 'checkbox',
- 'name' => 'blocks[]',
- 'attrs' => [
- 'onChange' => 'javascript:' . $sJsObject . '.onSelectBlock(this);'
- ],
- 'value' => ''
- ];
- $aTmplParams = [
- 'html_block_list_id' => $this->aHtmlIds['block_list_id'] . $sModule,
- 'bx_repeat:blocks' => []
- ];
- $aBlocks = $this->getBlocks($sModule);
- foreach($aBlocks as $aBlock) {
- list($sIcon, $sIconUrl) = $this->getBlockIcon($aBlock);
- $aInputCheckbox['value'] = $aBlock['id'];
- $aTmplParams['bx_repeat:blocks'][] = [
- 'js_object' => $sJsObject,
- 'html_id' => $this->aHtmlIds['block_id'] . $aBlock['id'],
- 'bx_if:is_inactive' => array(
- 'condition' => false,
- 'content' => [true]
- ),
- 'bx_if:show_link' => [
- 'condition' => false,
- 'content' => [true]
- ],
- 'bx_if:show_text' => [
- 'condition' => true,
- 'content' => [
- 'title' => _t(!empty($aBlock['title_system']) ? $aBlock['title_system'] : $aBlock['title']),
- ]
- ],
- 'bx_if:show_api' => [
- 'condition' => false,
- 'content' => [true]
- ],
- 'bx_if:image' => [
- 'condition' => (bool)$sIconUrl,
- 'content' => array('icon_url' => $sIconUrl),
- ],
- 'bx_if:icon' => [
- 'condition' => (bool)$sIcon,
- 'content' => ['icon' => $sIcon],
- ],
- 'module' => $this->getModuleTitle($aBlock['module']),
- 'visible_for' => _t('_adm_bp_txt_visible_for', BxDolStudioUtils::getVisibilityTitle($aBlock['visible_for_levels'])),
- 'bx_if:show_checkbox' => [
- 'condition' => true,
- 'content' => [
- 'content' => $oForm->genRow($aInputCheckbox)
- ]
- ],
- 'bx_if:show_drag_handle' => [
- 'condition' => false,
- 'content' => []
- ]
- ];
- }
- return $oTemplate->parseHtmlByName('bp_blocks_list.html', $aTmplParams);
- }
- protected function onBlockDelete($aBlock)
- {
- if($aBlock['module'] != BX_DOL_STUDIO_MODULE_CUSTOM)
- return;
- BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['title']);
- //--- Process Lang block
- if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && $aBlock['content'] != '')
- BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['content']);
- //--- Process Image block
- if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && $aBlock['content'] != '') {
- $iImageId = $sImageAlign = '';
- list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
- if(is_numeric($iImageId) && (int)$iImageId != 0)
- BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$iImageId, 0);
- }
- }
- protected function getBlocks($sModule)
- {
- $aBlocks = array();
- $this->oDb->getBlocks(array('type' => 'by_module_to_copy', 'value' => $sModule), $aBlocks, false);
- return $aBlocks;
- }
- protected function _getPageCreateForm()
- {
- $oTemplate = BxDolStudioTemplate::getInstance();
- $sForm = 'adm-bp-page-create';
- $aForm = array(
- 'form_attrs' => array(
- 'id' => $sForm,
- 'name' => $sForm,
- 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionPageCreate,
- 'method' => 'post'
- ),
- 'params' => array (
- 'db' => array(
- 'table' => 'sys_objects_page',
- 'key' => 'id',
- 'uri' => '',
- 'uri_title' => '',
- 'submit_name' => 'do_submit'
- ),
- 'display' => $sForm
- ),
- 'inputs' => array (
- 'module' => array(
- 'type' => 'hidden',
- 'name' => 'module',
- 'value' => BX_DOL_STUDIO_MODULE_CUSTOM,
- 'db' => array (
- 'pass' => 'Xss',
- ),
- ),
- 'deletable' => array(
- 'type' => 'hidden',
- 'name' => 'deletable',
- 'value' => 1,
- 'db' => array (
- 'pass' => 'Int',
- ),
- ),
- 'settings' => array(
- 'type' => 'custom',
- 'name' => 'settings',
- 'content' => $oTemplate->parseHtmlByName('bp_edit_page_form.html', $this->_getTmplVarsPageSettings()),
- ),
- )
- );
- return new BxTemplStudioFormView($aForm);
- }
- protected function _getPageEditForm()
- {
- $oTemplate = BxDolStudioTemplate::getInstance();
- $sForm = 'adm-bp-page-edit';
- $aForm = array(
- 'form_attrs' => array(
- 'id' => $sForm,
- 'name' => $sForm,
- 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionPageEdit,
- 'method' => 'post'
- ),
- 'params' => array (
- 'db' => array(
- 'table' => 'sys_objects_page',
- 'key' => 'id',
- 'uri' => '',
- 'uri_title' => '',
- 'submit_name' => 'do_submit'
- ),
- 'display' => $sForm
- ),
- 'inputs' => array (
- 'settings' => array(
- 'type' => 'custom',
- 'name' => 'settings',
- 'content' => $oTemplate->parseHtmlByName('bp_edit_page_form.html', $this->_getTmplVarsPageSettings($this->aPageRebuild, false)),
- ),
- )
- );
- return new BxTemplStudioFormView($aForm);
- }
- protected function _getTmplVarsBlockPanelTop()
- {
- $oPermalink = BxDolPermalinks::getInstance();
- $sJsObject = $this->getPageJsObject();
- $aInputTypes = [];
- if(!in_array($this->sType, [BX_DOL_STUDIO_BP_TYPE_SYSTEM, BX_DOL_STUDIO_BP_TYPE_CUSTOM])) {
- $aModulesDb = $this->oDb->getPages(['type' => 'modules_with_pages']);
- $aInputTypesValues = [[
- 'key' => '',
- 'value' => _t('_adm_txt_select_module')
- ]];
- foreach($aModulesDb as $aModuleDb) {
- $sName = $aModuleDb['name'];
- if($sName == BX_DOL_STUDIO_MODULE_SYSTEM)
- continue;
- $aInputTypesValues[] = [
- 'key' => $sName,
- 'value' => BxDolStudioUtils::getModuleTitle($sName)
- ];
- }
- $aInputTypes = [
- 'type' => 'select',
- 'name' => 'page',
- 'attrs' => [
- 'onChange' => 'javascript:' . $sJsObject . '.onChangeType(this)'
- ],
- 'value' => $this->sType,
- 'values' => $aInputTypesValues
- ];
- }
- $aPages = $this->oDb->getPages(['type' => 'by_module', 'value' => $this->sType]);
- $aCounter = [];
- $this->oDb->getBlocks(['type' => 'counter_by_pages'], $aCounter, false);
-
- $aInputPagesValues = [];
- foreach($aPages as $aPage) {
- $sTitle = _t($aPage['title_system']);
- if(empty($sTitle))
- $sTitle = _t($aPage['title']);
- $aInputPagesValues[] = [
- 'key' => $aPage['object'],
- 'value' => $sTitle,
- 'attrs' => [
- 'data-url' => $aPage['url'] ? $oPermalink->permalink($aPage['url']) : '',
- 'data-blocks' => $aCounter[$aPage['object']] ?? 0
- ]
- ];
- }
- usort($aInputPagesValues, function($aV1, $aV2) {
- return strcmp($aV1['value'], $aV2['value']);
- });
- $aInputPages = [
- 'type' => 'select',
- 'name' => 'page',
- 'attrs' => [
- 'onChange' => 'javascript:' . $sJsObject . '.onChangePage(this)'
- ],
- 'value' => $this->sPage,
- 'values' => array_merge([[
- 'key' => '',
- 'value' => _t('_adm_bp_txt_select_page')
- ]], $aInputPagesValues)
- ];
- $aTmplVarsActions = [];
- if(($this->sPage != '' && !empty($this->aPageRebuild)) !== false)
- $aTmplVarsActions = $this->_getTmplVarsBlockPanelTopActions();
- $oForm = new BxTemplStudioFormView([]);
- return [
- 'js_object' => $sJsObject,
- 'bx_if:show_selector_types' => [
- 'condition' => !empty($aInputTypes),
- 'content' => [
- 'selector_types' => $oForm->genRow($aInputTypes),
- ]
- ],
- 'selector_pages' => $oForm->genRow($aInputPages),
- 'action_page_create' => $this->sActionPageCreate,
- 'bx_if:show_actions' => [
- 'condition' => $this->sPage != '',
- 'content' => $aTmplVarsActions
- ]
- ];
- }
- protected function _getTmplVarsBlockPanelTopActions()
- {
- $sJsObject = $this->getPageJsObject();
- $oPermalinks = BxDolPermalinks::getInstance();
- return [
- 'js_object' => $sJsObject,
- 'bx_if:can_view' => [
- 'condition' => !empty($this->aPageRebuild['url']),
- 'content' => [
- 'url_view' => bx_absolute_url($oPermalinks->permalink($this->aPageRebuild['url'])),
- ]
- ],
- 'action_page_edit' => $this->sActionPageEdit,
- 'bx_if:can_delete' => [
- 'condition' => (int)$this->aPageRebuild['deletable'] == 1,
- 'content' => [
- 'js_object' => $sJsObject
- ]
- ],
- 'action_block_create' => $this->sActionBlockCreate,
- ];
- }
- protected function _getTmplVarsPageSettings($aPage = array(), $bCreate = true)
- {
- $sJsObject = $this->getPageJsObject();
- $aTmplParams = array(
- 'js_object' => $sJsObject,
- 'menu' => array(),
- 'html_settings_groups_id' => $this->aHtmlIds['settings_groups_id'],
- 'bx_repeat:settings_groups' => array(),
- 'submit' => _t($bCreate ? '_adm_bp_btn_page_create' : '_adm_bp_btn_page_apply')
- );
- foreach($this->aPageSettings as $aSetting) {
- //--- get menu items
- $aTmplParams['menu'][$aSetting['name']] = array(
- 'name' => $aSetting['name'],
- 'icon' => $aSetting['icon'] ?? '', // a Lucide glyph on the sidebar tile, like the app pages' side menus
- 'icon_bg' => true,
- 'onclick' => $sJsObject . '.onChangeSettingGroup(\'' . $aSetting['name'] . '\', this);',
- 'title' => $aSetting['title'],
- 'selected' => isset($aSetting['active']) && (int)$aSetting['active'] == 1
- );
- //--- get settings
- $aTmplParams['bx_repeat:settings_groups'][] = array(
- 'html_settings_group_id' => $this->aHtmlIds['settings_group_id'] . $aSetting['name'],
- 'bx_if:hidden' => array(
- 'condition' => $aSetting['active'] != 1,
- 'content' => array()
- ),
- 'content' => $this->{'getSettings' . $this->getClassName($aSetting['name'])}($aPage, $bCreate)
- );
- }
- $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aTmplParams['menu']));
- $aTmplParams['menu'] = $oMenu->getCode();
- return $aTmplParams;
- }
- protected function getIndexingDataForBlock($sType, $sContent)
- {
- $aBlock = array();
- switch($sType) {
- case BX_DOL_STUDIO_BP_BLOCK_HTML:
- case BX_DOL_STUDIO_BP_BLOCK_RAW:
- $aBlock['text'] = trim(strip_tags($sContent));
- $aBlock['text_updated'] = time();
- break;
- }
- return $aBlock;
- }
- protected function onPageChanged($oForm, $aPage)
- {
- $this->oDb->cleanCache('sys_pages_objects_data');
- $this->oDb->cleanCache('sys_pages_uri_object_map');
- $this->oDb->cleanCache('sys_pages_urirewrite_object_map');
- }
- }
- /** @} */
|