BxBaseStudioBuilderPage.php 80 KB

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