BxBaseStudioBuilderPage.php 77 KB

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