BxBaseStudioBuilderPage.php 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973
  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_simple', '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 actionImageDelete()
  806. {
  807. $sJsObject = $this->getPageJsObject();
  808. $iId = (int)bx_get('id');
  809. $aBlock = array();
  810. $this->oDb->getBlocks(array('type' => 'by_id', 'value' => $iId), $aBlock, false);
  811. if(empty($aBlock) || !is_array($aBlock))
  812. return array('msg' => _t('_adm_bp_err_block_not_found'));
  813. $iImageId = $sImageAlign = '';
  814. if($aBlock['content'] != '')
  815. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  816. if(is_numeric($iImageId) && (int)$iImageId != 0) {
  817. if(!BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$iImageId, 0))
  818. return array('msg' => _t('_adm_bp_err_block_content_image_preview_delete'));
  819. $this->oDb->updateBlock($iId, array('content' => ''));
  820. }
  821. return $this->actionBlockEdit();
  822. }
  823. protected function actionUriGet()
  824. {
  825. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  826. $aLanguages = $oLanguage->getLanguages();
  827. $sLanguageDef = $oLanguage->getDefaultLangName();
  828. $sLanguageCur = $oLanguage->getCurrentLangName(false);
  829. $aValues = array();
  830. foreach($aLanguages as $sName => $sTitle)
  831. if(($mixedValue = bx_get($sName)) !== false)
  832. $aValues[$sName] = bx_process_input($mixedValue);
  833. $sUri = "";
  834. if(($mixedValue = bx_get('uri')) !== false)
  835. $sUri = bx_process_input($mixedValue);
  836. else if(array_key_exists('en', $aValues) && $aValues['en'] != '')
  837. $sUri = $aValues['en'];
  838. else if(array_key_exists($sLanguageDef, $aValues) && $aValues[$sLanguageDef] != '')
  839. $sUri = $aValues[$sLanguageDef];
  840. else if(array_key_exists($sLanguageCur, $aValues) && $aValues[$sLanguageCur] != '')
  841. $sUri = $aValues[$sLanguageCur];
  842. else if(count($aValues) > 0)
  843. foreach($aValues as $sValue)
  844. if(!empty($sValue)) {
  845. $sUri = $sValue;
  846. break;
  847. }
  848. $sUri = $sUri != "" ? uriGenerate($sUri, 'sys_objects_page', 'uri') : "";
  849. $sUrl = BxDolPermalinks::getInstance()->permalink($this->sPageBaseUrl . $sUri);
  850. return array('eval' => $this->getPageJsObject() . '.onGetUri(oData)', 'uri' => $sUri, 'url' => $sUrl);
  851. }
  852. protected function getSettingsOptions($aPage = array(), $bCreate = true, $bInputsOnly = false)
  853. {
  854. $aForm = array(
  855. 'form_attrs' => array(
  856. 'id' => 'adm-bp-settings-options',
  857. ),
  858. 'params' => array (
  859. 'remove_form' => '1',
  860. 'csrf' => array(
  861. 'disable' => true
  862. )
  863. ),
  864. 'inputs' => array (
  865. 'title_system' => array(
  866. 'type' => 'text_translatable',
  867. 'name' => 'title_system',
  868. 'caption' => _t('_adm_bp_txt_page_title_system'),
  869. 'info' => _t('_adm_bp_dsc_page_title_system'),
  870. 'value' => isset($aPage['title_system']) ? $aPage['title_system'] : '',
  871. 'required' => '1',
  872. 'db' => array (
  873. 'pass' => 'Xss',
  874. ),
  875. 'checker' => array (
  876. 'func' => 'length',
  877. 'params' => array(3,100),
  878. 'error' => _t('_adm_bp_err_page_title_system'),
  879. ),
  880. ),
  881. 'title' => array(
  882. 'type' => 'text_translatable',
  883. 'name' => 'title',
  884. 'caption' => _t('_adm_bp_txt_page_title'),
  885. 'info' => _t('_adm_bp_dsc_page_title'),
  886. 'value' => isset($aPage['title']) ? $aPage['title'] : '',
  887. 'required' => '1',
  888. 'db' => array (
  889. 'pass' => 'Xss',
  890. ),
  891. 'checker' => array (
  892. 'func' => 'length',
  893. 'params' => array(3,100),
  894. 'error' => _t('_adm_bp_err_page_title'),
  895. ),
  896. ),
  897. 'url' => array(
  898. 'type' => 'text',
  899. 'name' => 'url',
  900. 'caption' => _t('_adm_bp_txt_page_url'),
  901. 'info' => _t('_adm_bp_dsc_page_url'),
  902. 'value' => isset($aPage['url']) ? BxDolPermalinks::getInstance()->permalink($aPage['url']) : '',
  903. 'required' => '0',
  904. 'attrs' => array(
  905. 'id' => $this->aHtmlIds['url_field_id'],
  906. 'disabled' => 'disabled'
  907. ),
  908. ),
  909. 'type_id' => array(
  910. 'type' => 'select',
  911. 'name' => 'type_id',
  912. 'caption' => _t('_adm_bp_txt_page_type_id'),
  913. 'info' => _t('_adm_bp_dsc_page_type_id'),
  914. 'value' => isset($aPage['type_id']) ? $aPage['type_id'] : '',
  915. 'required' => '1',
  916. 'db' => array (
  917. 'pass' => 'Int',
  918. ),
  919. ),
  920. 'submenu' => array(
  921. 'type' => 'select',
  922. 'name' => 'submenu',
  923. 'caption' => _t('_adm_bp_txt_page_submenu'),
  924. 'info' => _t('_adm_bp_dsc_page_submenu'),
  925. 'value' => isset($aPage['submenu']) ? $aPage['submenu'] : '',
  926. 'required' => '0',
  927. 'db' => array (
  928. 'pass' => 'Xss',
  929. ),
  930. ),
  931. 'sticky_columns' => array(
  932. 'type' => 'switcher',
  933. 'name' => 'sticky_columns',
  934. 'caption' => _t('_adm_bp_txt_page_sticky_columns'),
  935. 'info' => '',
  936. 'value' => '1',
  937. 'checked' => isset($aPage['sticky_columns']) && $aPage['sticky_columns'] == 1,
  938. 'db' => array (
  939. 'pass' => 'Int',
  940. )
  941. )
  942. )
  943. );
  944. $aTypes = array();
  945. $this->oDb->getTypes(array('type' => 'all'), $aTypes, false);
  946. foreach($aTypes as $aType)
  947. $aForm['inputs']['type_id']['values'][] = array('key' => $aType['id'], 'value' => _t($aType['title']));
  948. $aSubmenus = $this->oDb->getSubmenus();
  949. $aForm['inputs']['submenu']['values'][] = array('key' => '', 'value' => _t('_sys_menu_item_title_inherited'));
  950. $aForm['inputs']['submenu']['values'][] = array('key' => 'disabled', 'value' => _t('_sys_menu_item_title_disabled'));
  951. foreach ($aSubmenus as $sObject => $sTitle)
  952. $aForm['inputs']['submenu']['values'][] = array('key' => $sObject, 'value' => _t($sTitle));
  953. if($bCreate) {
  954. $sJsObject = $this->getPageJsObject();
  955. $aForm['inputs']['title']['attrs']['onblur'] = $sJsObject . '.getUri(this);';
  956. $aForm['inputs'] = bx_array_insert_before(array(
  957. 'uri' => array(
  958. 'type' => 'text',
  959. 'name' => 'uri',
  960. 'caption' => _t('_adm_bp_txt_page_uri'),
  961. 'info' => _t('_adm_bp_dsc_page_uri'),
  962. 'value' => '',
  963. 'required' => '1',
  964. 'attrs' => array(
  965. 'id' => $this->aHtmlIds['uri_field_id'],
  966. 'onblur' => $sJsObject . '.getUri(this);'
  967. ),
  968. 'db' => array (
  969. 'pass' => 'Xss',
  970. ),
  971. 'checker' => array (
  972. 'func' => 'length',
  973. 'params' => array(3,100),
  974. 'error' => _t('_adm_bp_err_page_uri'),
  975. ),
  976. )
  977. ), $aForm['inputs'], 'url');
  978. }
  979. if($bInputsOnly)
  980. return $aForm['inputs'];
  981. $oForm = new BxTemplStudioFormView($aForm);
  982. return $oForm->getCode();
  983. }
  984. protected function getSettingsOptionsFields($aPage = array(), $bCreate = true)
  985. {
  986. return $this->getSettingsOptions($aPage, $bCreate, true);
  987. }
  988. protected function getSettingsCover($aPage = array(), $bCreate = true, $bInputsOnly = false)
  989. {
  990. $aForm = array(
  991. 'form_attrs' => array(
  992. 'id' => 'adm-bp-settings-cover',
  993. ),
  994. 'params' => array (
  995. 'remove_form' => '1',
  996. 'csrf' => array(
  997. 'disable' => true
  998. )
  999. ),
  1000. 'inputs' => array (
  1001. 'cover' => array(
  1002. 'type' => 'select',
  1003. 'name' => 'cover',
  1004. 'caption' => _t('_adm_bp_txt_page_cover'),
  1005. 'info' => '',
  1006. 'value' => isset($aPage['cover']) ? (int)$aPage['cover'] : '1',
  1007. 'values' => array(
  1008. array('key' => 0, 'value' => _t('_adm_bp_txt_page_cover_0')),
  1009. array('key' => 1, 'value' => _t('_adm_bp_txt_page_cover_1')),
  1010. array('key' => 2, 'value' => _t('_adm_bp_txt_page_cover_2')),
  1011. array('key' => 3, 'value' => _t('_adm_bp_txt_page_cover_3'))
  1012. ),
  1013. 'db' => array (
  1014. 'pass' => 'Int',
  1015. )
  1016. ),
  1017. 'cover_image' => array(
  1018. 'type' => 'files',
  1019. 'name' => 'cover_image',
  1020. 'storage_object' => $this->sStorage,
  1021. 'images_transcoder' => $this->sTranscoderCover,
  1022. 'uploaders' => $this->aUploadersCover,
  1023. 'multiple' => false,
  1024. 'content_id' => isset($aPage['id']) ? $aPage['id'] : 0,
  1025. 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('uploader_fgt_cover.html', array(
  1026. 'name' => 'cover_image',
  1027. )),
  1028. 'caption' => _t('_adm_bp_txt_page_cover_image'),
  1029. 'db' => array (
  1030. 'pass' => 'Int',
  1031. )
  1032. )
  1033. )
  1034. );
  1035. if($bInputsOnly)
  1036. return $aForm['inputs'];
  1037. $oForm = new BxTemplStudioFormView($aForm);
  1038. return $oForm->getCode();
  1039. }
  1040. protected function getSettingsCoverFields($aPage = array(), $bCreate = true)
  1041. {
  1042. return $this->getSettingsCover($aPage, $bCreate, true);
  1043. }
  1044. protected function getSettingsLayout($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1045. {
  1046. $sJsObject = $this->getPageJsObject();
  1047. $oTemplate = BxDolStudioTemplate::getInstance();
  1048. $iLayout = isset($aPage['layout_id']) ? (int)$aPage['layout_id'] : 5;
  1049. $aLayouts = array();
  1050. $this->oDb->getLayouts(array('type' => 'all'), $aLayouts, false);
  1051. $aTmplParams = array(
  1052. 'bx_repeat:layouts' => array(),
  1053. 'form' => ''
  1054. );
  1055. foreach($aLayouts as $aLayout)
  1056. $aTmplParams['bx_repeat:layouts'][] = array(
  1057. 'id' => $aLayout['id'],
  1058. 'html_id' => $this->aHtmlIds['layout_id'] . $aLayout['id'],
  1059. 'js_object' => $sJsObject,
  1060. 'bx_if:active' => array(
  1061. 'condition' => (int)$aLayout['id'] == $iLayout,
  1062. 'content' => array()
  1063. ),
  1064. 'icon' => $oTemplate->getImageUrl($aLayout['icon']),
  1065. 'title' => _t($aLayout['title']),
  1066. );
  1067. $aForm = array(
  1068. 'form_attrs' => array(
  1069. 'id' => 'adm-bp-settings-layout',
  1070. ),
  1071. 'params' => array (
  1072. 'remove_form' => '1',
  1073. 'csrf' => array(
  1074. 'disable' => true
  1075. )
  1076. ),
  1077. 'inputs' => array (
  1078. 'layout_id' => array(
  1079. 'type' => 'hidden',
  1080. 'name' => 'layout_id',
  1081. 'value' => $iLayout,
  1082. 'db' => array (
  1083. 'pass' => 'Int',
  1084. ),
  1085. )
  1086. )
  1087. );
  1088. if($bInputsOnly)
  1089. return $aForm['inputs'];
  1090. $oForm = new BxTemplStudioFormView($aForm);
  1091. $aTmplParams['form'] = $oForm->getCode();
  1092. return $oTemplate->parseHtmlByName('bp_layouts.html', $aTmplParams);
  1093. }
  1094. protected function getSettingsLayoutFields($aPage = array(), $bCreate = true)
  1095. {
  1096. return $this->getSettingsLayout($aPage, $bCreate, true);
  1097. }
  1098. protected function getSettingsVisibility($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1099. {
  1100. $iVisibleForLevels = isset($aPage['visible_for_levels']) ? (int)$aPage['visible_for_levels'] : BX_DOL_INT_MAX;
  1101. if(isset($aPage['visible_for_levels_editable']) && (int)$aPage['visible_for_levels_editable'] == 0)
  1102. $aInputs = array(
  1103. 'visible_for_levels' => array(
  1104. 'type' => 'custom',
  1105. 'name' => 'visible_for_levels',
  1106. 'content' => MsgBox(_t('_adm_bp_err_page_visible_for_levels'))
  1107. )
  1108. );
  1109. else {
  1110. bx_import('BxDolStudioUtils');
  1111. $aInputs = array(
  1112. 'visible_for' => array(
  1113. 'type' => 'select',
  1114. 'name' => 'visible_for',
  1115. 'caption' => _t('_adm_bp_txt_block_visible_for'),
  1116. 'info' => '',
  1117. 'value' => $iVisibleForLevels == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
  1118. 'values' => array(
  1119. array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_bp_txt_block_visible_for_all')),
  1120. array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_bp_txt_block_visible_for_selected')),
  1121. ),
  1122. 'required' => '0',
  1123. 'attrs' => array(
  1124. 'onchange' => $this->getPageJsObject() . '.onChangeVisibleFor(this)'
  1125. ),
  1126. 'db' => array (
  1127. 'pass' => 'Xss',
  1128. )
  1129. ),
  1130. 'visible_for_levels' => array(
  1131. 'type' => 'checkbox_set',
  1132. 'name' => 'visible_for_levels',
  1133. 'caption' => _t('_adm_bp_txt_page_visible_for_levels'),
  1134. 'info' => _t('_adm_bp_dsc_page_visible_for_levels'),
  1135. 'value' => array(),
  1136. 'values' => array(),
  1137. 'tr_attrs' => array(
  1138. 'style' => $iVisibleForLevels == BX_DOL_INT_MAX ? 'display:none' : ''
  1139. ),
  1140. 'db' => array (
  1141. 'pass' => 'Int',
  1142. )
  1143. )
  1144. );
  1145. }
  1146. $aForm = array(
  1147. 'form_attrs' => array(
  1148. 'id' => 'adm-bp-settings-visibility',
  1149. ),
  1150. 'params' => array (
  1151. 'remove_form' => '1',
  1152. 'csrf' => array(
  1153. 'disable' => true
  1154. )
  1155. ),
  1156. 'inputs' => $aInputs
  1157. );
  1158. BxDolStudioUtils::getVisibilityValues($iVisibleForLevels, $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
  1159. if($bInputsOnly)
  1160. return $aForm['inputs'];
  1161. $oForm = new BxTemplStudioFormView($aForm);
  1162. return $oForm->getCode();
  1163. }
  1164. protected function getSettingsVisibilityFields($aPage = array(), $bCreate = true)
  1165. {
  1166. return $this->getSettingsVisibility($aPage, $bCreate, true);
  1167. }
  1168. protected function getSettingsCache($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1169. {
  1170. $aForm = array(
  1171. 'form_attrs' => array(
  1172. 'id' => 'adm-bp-settings-cache',
  1173. ),
  1174. 'params' => array (
  1175. 'remove_form' => '1',
  1176. 'csrf' => array(
  1177. 'disable' => true
  1178. )
  1179. ),
  1180. 'inputs' => array (
  1181. 'cache_lifetime' => array(
  1182. 'type' => 'text',
  1183. 'name' => 'cache_lifetime',
  1184. 'caption' => _t('_adm_bp_txt_page_cache_lifetime'),
  1185. 'info' => _t('_adm_bp_dsc_page_cache_lifetime'),
  1186. 'value' => isset($aPage['cache_lifetime']) ? $aPage['cache_lifetime'] : 0,
  1187. 'required' => '',
  1188. 'attrs' => array(
  1189. 'disabled' => isset($aPage['cache_editable']) && (int)$aPage['cache_editable'] == 0 ? 'disabled' : ''
  1190. ),
  1191. 'db' => array (
  1192. 'pass' => 'Int',
  1193. )
  1194. ),
  1195. )
  1196. );
  1197. if($bInputsOnly)
  1198. return $aForm['inputs'];
  1199. $oForm = new BxTemplStudioFormView($aForm);
  1200. return $oForm->getCode();
  1201. }
  1202. protected function getSettingsCacheFields($aPage = array(), $bCreate = true)
  1203. {
  1204. return $this->getSettingsCache($aPage, $bCreate, true);
  1205. }
  1206. protected function getSettingsSeo($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1207. {
  1208. $aForm = array(
  1209. 'form_attrs' => array(
  1210. 'id' => 'adm-bp-settings-seo',
  1211. ),
  1212. 'params' => array (
  1213. 'remove_form' => '1',
  1214. 'csrf' => array(
  1215. 'disable' => true
  1216. )
  1217. ),
  1218. 'inputs' => array (
  1219. 'meta_description' => array(
  1220. 'type' => 'textarea',
  1221. 'name' => 'meta_description',
  1222. 'caption' => _t('_adm_bp_txt_page_meta_description'),
  1223. 'info' => _t('_adm_bp_dsc_page_meta_description'),
  1224. 'value' => isset($aPage['meta_description']) ? $aPage['meta_description'] : '',
  1225. 'db' => array (
  1226. 'pass' => 'Xss',
  1227. ),
  1228. ),
  1229. 'meta_keywords' => array(
  1230. 'type' => 'textarea',
  1231. 'name' => 'meta_keywords',
  1232. 'caption' => _t('_adm_bp_txt_page_meta_keywords'),
  1233. 'info' => _t('_adm_bp_dsc_page_meta_keywords'),
  1234. 'value' => isset($aPage['meta_keywords']) ? $aPage['meta_keywords'] : '',
  1235. 'db' => array (
  1236. 'pass' => 'Xss',
  1237. ),
  1238. ),
  1239. 'meta_robots' => array(
  1240. 'type' => 'text',
  1241. 'name' => 'meta_robots',
  1242. 'caption' => _t('_adm_bp_txt_page_meta_robots'),
  1243. 'info' => _t('_adm_bp_dsc_page_meta_robots'),
  1244. 'value' => isset($aPage['meta_robots']) ? $aPage['meta_robots'] : '',
  1245. 'required' => '0',
  1246. 'db' => array (
  1247. 'pass' => 'Xss',
  1248. )
  1249. )
  1250. )
  1251. );
  1252. if($bInputsOnly)
  1253. return $aForm['inputs'];
  1254. $oForm = new BxTemplStudioFormView($aForm);
  1255. return $oForm->getCode();
  1256. }
  1257. protected function getSettingsSeoFields($aPage = array(), $bCreate = true)
  1258. {
  1259. return $this->getSettingsSeo($aPage, $bCreate, true);
  1260. }
  1261. protected function getSettingsInjections($aPage = array(), $bCreate = true, $bInputsOnly = false)
  1262. {
  1263. $aForm = array(
  1264. 'form_attrs' => array(
  1265. 'id' => 'adm-bp-injections-seo',
  1266. ),
  1267. 'params' => array (
  1268. 'remove_form' => '1',
  1269. 'csrf' => array(
  1270. 'disable' => true
  1271. )
  1272. ),
  1273. 'inputs' => array (
  1274. 'inj_head' => array(
  1275. 'type' => 'textarea',
  1276. 'name' => 'inj_head',
  1277. 'caption' => _t('_adm_bp_txt_page_inj_head'),
  1278. 'info' => _t('_adm_bp_dsc_page_inj_head'),
  1279. 'value' => isset($aPage['inj_head']) ? $aPage['inj_head'] : '',
  1280. 'code' => 1,
  1281. 'db' => array (
  1282. 'pass' => 'XssHtml',
  1283. ),
  1284. ),
  1285. 'inj_footer' => array(
  1286. 'type' => 'textarea',
  1287. 'name' => 'inj_footer',
  1288. 'caption' => _t('_adm_bp_txt_page_inj_footer'),
  1289. 'info' => _t('_adm_bp_dsc_page_inj_footer'),
  1290. 'value' => isset($aPage['inj_footer']) ? $aPage['inj_footer'] : '',
  1291. 'code' => 1,
  1292. 'db' => array (
  1293. 'pass' => 'XssHtml',
  1294. ),
  1295. )
  1296. )
  1297. );
  1298. if($bInputsOnly)
  1299. return $aForm['inputs'];
  1300. $oForm = new BxTemplStudioFormView($aForm);
  1301. return $oForm->getCode();
  1302. }
  1303. protected function getSettingsInjectionsFields($aPage = array(), $bCreate = true)
  1304. {
  1305. return $this->getSettingsInjections($aPage, $bCreate, true);
  1306. }
  1307. protected function getBlockIcon($aBlock)
  1308. {
  1309. $sIcon = $sIconUrl = "";
  1310. $sResult = '';
  1311. switch($aBlock['type']) {
  1312. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1313. $sResult = 'far file-alt';
  1314. break;
  1315. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1316. $sResult = 'code';
  1317. break;
  1318. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1319. $sResult = 'rss';
  1320. break;
  1321. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1322. $sResult = 'far image';
  1323. break;
  1324. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1325. $sResult = 'globe';
  1326. break;
  1327. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1328. $sResult = 'list-alt';
  1329. break;
  1330. case BX_DOL_STUDIO_BP_BLOCK_WIKI:
  1331. $sResult = 'file-word';
  1332. break;
  1333. case BX_DOL_STUDIO_BP_BLOCK_CUSTOM:
  1334. $sResult = 'file';
  1335. break;
  1336. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1337. $sResult = $this->getModuleIcon($aBlock['module'], 'page');
  1338. break;
  1339. }
  1340. if(strpos($sResult, '.') === false)
  1341. $sIcon = $sResult;
  1342. else
  1343. $sIconUrl = $sResult;
  1344. return array($sIcon, $sIconUrl);
  1345. }
  1346. protected function getBlockModule($aBlock)
  1347. {
  1348. return $aBlock['module'] != BX_DOL_STUDIO_BP_SKELETONS ? $aBlock['module'] : BX_DOL_STUDIO_MODULE_CUSTOM;
  1349. }
  1350. protected function getBlockContent($aBlock)
  1351. {
  1352. $aFields = array();
  1353. switch($aBlock['type']) {
  1354. case BX_DOL_STUDIO_BP_BLOCK_CUSTOM:
  1355. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1356. $aFields = array(
  1357. 'content' => array(
  1358. 'type' => 'textarea',
  1359. 'name' => 'content',
  1360. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1361. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1362. 'value' => $aBlock['content'],
  1363. 'required' => '0',
  1364. 'code' => 1,
  1365. 'attrs' => array('class' => 'bx-form-input-textarea-codemirror'),
  1366. 'db' => array (
  1367. 'pass' => 'XssHtml',
  1368. ),
  1369. ),
  1370. );
  1371. break;
  1372. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1373. $aFields = array(
  1374. 'content' => array(
  1375. 'type' => 'textarea',
  1376. 'name' => 'content',
  1377. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1378. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1379. 'value' => $aBlock['content'],
  1380. 'required' => '0',
  1381. 'html' => 2,
  1382. 'attrs' => array('id' => $this->aHtmlIds['edit_block_editor_id']),
  1383. 'db' => array (
  1384. 'pass' => 'XssHtml',
  1385. ),
  1386. ),
  1387. 'attachments' => array(
  1388. 'type' => 'files',
  1389. 'name' => 'attachments',
  1390. 'storage_object' => $this->sStorage,
  1391. 'images_transcoder' => $this->sTranscoder,
  1392. 'uploaders' => $this->aUploaders,
  1393. 'multiple' => true,
  1394. 'content_id' => $aBlock['id'],
  1395. 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('bp_fgt_attachments.html', array(
  1396. 'js_object' => $this->getPageJsObject(),
  1397. 'name' => 'attachments',
  1398. 'editor_id' => $this->aHtmlIds['edit_block_editor_id'],
  1399. )),
  1400. 'caption' => _t('_adm_bp_txt_block_content_attachments_html')
  1401. )
  1402. );
  1403. break;
  1404. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1405. $aFields = array(
  1406. 'content' => array(
  1407. 'type' => 'textarea_translatable',
  1408. 'name' => 'content',
  1409. 'caption' => _t('_adm_bp_txt_block_content_lang'),
  1410. 'info' => _t('_adm_bp_dsc_block_content_lang'),
  1411. 'value' => $aBlock['content'],
  1412. 'required' => '0',
  1413. 'html' => 2,
  1414. 'db' => array (
  1415. 'pass' => 'XssHtml',
  1416. ),
  1417. ),
  1418. );
  1419. break;
  1420. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1421. $iImageId = $sImageAlign = '';
  1422. if($aBlock['content'] != '')
  1423. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1424. $aFields = array(
  1425. 'content' => array(
  1426. 'type' => 'hidden',
  1427. 'name' => 'content',
  1428. 'value' => '',
  1429. 'db' => array (
  1430. 'pass' => 'Xss',
  1431. ),
  1432. ),
  1433. 'image_file' => array(
  1434. 'type' => 'image_uploader',
  1435. 'name' => 'image_file',
  1436. 'caption' => _t('_adm_bp_txt_block_content_image_file'),
  1437. 'caption_preview' => _t('_adm_bp_txt_block_content_image_preview'),
  1438. 'info' => _t('_adm_bp_dsc_block_content_image_file'),
  1439. 'ajax_action_delete' => $this->getPageJsObject() . '.deleteBlockImage(' . $aBlock['id'] . ')',
  1440. 'value' => (int)$iImageId
  1441. ),
  1442. 'image_align' => array(
  1443. 'type' => 'select',
  1444. 'name' => 'image_align',
  1445. 'caption' => _t('_adm_bp_txt_block_content_image_align'),
  1446. 'info' => '',
  1447. 'value' => $sImageAlign,
  1448. 'values' => array(
  1449. array('key' => '', 'value' => _t('_adm_bp_txt_block_content_image_align_empty')),
  1450. array('key' => 'left', 'value' => _t('_adm_bp_txt_block_content_image_align_left')),
  1451. array('key' => 'center', 'value' => _t('_adm_bp_txt_block_content_image_align_center')),
  1452. array('key' => 'right', 'value' => _t('_adm_bp_txt_block_content_image_align_right')),
  1453. ),
  1454. 'required' => '0',
  1455. 'db' => array (
  1456. 'pass' => 'Xss',
  1457. ),
  1458. ),
  1459. );
  1460. break;
  1461. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1462. $sRssUrl = $sRssLength = '';
  1463. if($aBlock['content'] != '')
  1464. list($sRssUrl, $sRssLength) = explode($this->sParamsDivider, $aBlock['content']);
  1465. $aFields = array(
  1466. 'content' => array(
  1467. 'type' => 'hidden',
  1468. 'name' => 'content',
  1469. 'value' => '',
  1470. 'db' => array (
  1471. 'pass' => 'Xss',
  1472. ),
  1473. ),
  1474. 'rss_url' => array(
  1475. 'type' => 'text',
  1476. 'name' => 'rss_url',
  1477. 'caption' => _t('_adm_bp_txt_block_content_rss_url'),
  1478. 'info' => _t('_adm_bp_dsc_block_content_rss_url'),
  1479. 'value' => $sRssUrl,
  1480. 'required' => '0',
  1481. 'db' => array (
  1482. 'pass' => 'Xss',
  1483. ),
  1484. ),
  1485. 'rss_length' => array(
  1486. 'type' => 'text',
  1487. 'name' => 'rss_length',
  1488. 'caption' => _t('_adm_bp_txt_block_content_rss_length'),
  1489. 'info' => _t('_adm_bp_dsc_block_content_rss_length'),
  1490. 'value' => $sRssLength,
  1491. 'required' => '0',
  1492. 'db' => array (
  1493. 'pass' => 'Int',
  1494. ),
  1495. ),
  1496. );
  1497. break;
  1498. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1499. $aFields = array(
  1500. 'content' => array(
  1501. 'type' => 'select',
  1502. 'name' => 'content',
  1503. 'caption' => _t('_adm_bp_txt_block_content_menu'),
  1504. 'info' => '',
  1505. 'value' => $aBlock['content'],
  1506. 'values' => array(),
  1507. 'required' => '0',
  1508. 'db' => array (
  1509. 'pass' => 'Xss',
  1510. ),
  1511. )
  1512. );
  1513. $sGroup = '';
  1514. $aMenus = $this->oDb->getMenus(true);
  1515. foreach($aMenus as $sKey => $aMenu) {
  1516. if($sGroup != $aMenu['module']) {
  1517. if(!empty($sGroup))
  1518. $aFields['content']['values'][$sGroup . '_end'] = array('type' => 'group_end');
  1519. $sGroup = $aMenu['module'];
  1520. $aFields['content']['values'][$sGroup . '_beg'] = array('type' => 'group_header', 'value' => BxDolStudioUtils::getModuleTitle($sGroup));
  1521. }
  1522. $aFields['content']['values'][$sKey] = _t($aMenu['title']);
  1523. }
  1524. $aFields['content']['values'] = array_merge(array('' => _t('_adm_bp_txt_block_content_menu_empty')), $aFields['content']['values']);
  1525. break;
  1526. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1527. $aService = array('module' => '', 'method' => '');
  1528. if($aBlock['content'] != '')
  1529. $aService = unserialize($aBlock['content']);
  1530. $aFields = array(
  1531. 'service_module' => array(
  1532. 'type' => 'value',
  1533. 'name' => 'service_module',
  1534. 'caption' => _t('_adm_bp_txt_block_content_service_module'),
  1535. 'value' => $this->getModuleTitle($aService['module'])
  1536. ),
  1537. 'service_method' => array(
  1538. 'type' => 'value',
  1539. 'name' => 'service_method',
  1540. 'caption' => _t('_adm_bp_txt_block_content_service_method'),
  1541. 'value' => $aService['method']
  1542. )
  1543. );
  1544. break;
  1545. }
  1546. return $aFields;
  1547. }
  1548. protected function getBlockList($sModule)
  1549. {
  1550. if(empty($sModule))
  1551. return '';
  1552. $sJsObject = $this->getPageJsObject();
  1553. $oTemplate = BxDolStudioTemplate::getInstance();
  1554. $oForm = new BxTemplStudioFormView(array());
  1555. $aInputCheckbox = array(
  1556. 'type' => 'checkbox',
  1557. 'name' => 'blocks[]',
  1558. 'attrs' => array(
  1559. 'onChange' => 'javascript:' . $sJsObject . '.onSelectBlock(this);'
  1560. ),
  1561. 'value' => ''
  1562. );
  1563. $aTmplParams = array(
  1564. 'html_block_list_id' => $this->aHtmlIds['block_list_id'] . $sModule,
  1565. 'bx_repeat:blocks' => array()
  1566. );
  1567. $aBlocks = $this->getBlocks($sModule);
  1568. foreach($aBlocks as $aBlock) {
  1569. list($sIcon, $sIconUrl) = $this->getBlockIcon($aBlock);
  1570. $aInputCheckbox['value'] = $aBlock['id'];
  1571. $aTmplParams['bx_repeat:blocks'][] = array(
  1572. 'js_object' => $sJsObject,
  1573. 'html_id' => $this->aHtmlIds['block_id'] . $aBlock['id'],
  1574. 'bx_if:is_inactive' => array(
  1575. 'condition' => false,
  1576. 'content' => array()
  1577. ),
  1578. 'bx_if:show_link' => array(
  1579. 'condition' => false,
  1580. 'content' => array()
  1581. ),
  1582. 'bx_if:show_text' => array(
  1583. 'condition' => true,
  1584. 'content' => array(
  1585. 'title' => _t(!empty($aBlock['title_system']) ? $aBlock['title_system'] : $aBlock['title']),
  1586. )
  1587. ),
  1588. 'bx_if:image' => array (
  1589. 'condition' => (bool)$sIconUrl,
  1590. 'content' => array('icon_url' => $sIconUrl),
  1591. ),
  1592. 'bx_if:icon' => array (
  1593. 'condition' => (bool)$sIcon,
  1594. 'content' => array('icon' => $sIcon),
  1595. ),
  1596. 'module' => $this->getModuleTitle($aBlock['module']),
  1597. 'visible_for' => _t('_adm_bp_txt_visible_for', BxDolStudioUtils::getVisibilityTitle($aBlock['visible_for_levels'])),
  1598. 'bx_if:show_checkbox' => array(
  1599. 'condition' => true,
  1600. 'content' => array(
  1601. 'content' => $oForm->genRow($aInputCheckbox)
  1602. )
  1603. ),
  1604. 'bx_if:show_drag_handle' => array(
  1605. 'condition' => false,
  1606. 'content' => array()
  1607. )
  1608. );
  1609. }
  1610. return $oTemplate->parseHtmlByName('bp_blocks_list.html', $aTmplParams);
  1611. }
  1612. protected function onBlockDelete($aBlock)
  1613. {
  1614. if($aBlock['module'] != BX_DOL_STUDIO_MODULE_CUSTOM)
  1615. return;
  1616. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['title']);
  1617. //--- Process Lang block
  1618. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && $aBlock['content'] != '')
  1619. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['content']);
  1620. //--- Process Image block
  1621. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && $aBlock['content'] != '') {
  1622. $iImageId = $sImageAlign = '';
  1623. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1624. if(is_numeric($iImageId) && (int)$iImageId != 0)
  1625. BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$iImageId, 0);
  1626. }
  1627. }
  1628. protected function getBlocks($sModule)
  1629. {
  1630. $aBlocks = array();
  1631. $this->oDb->getBlocks(array('type' => 'by_module_to_copy', 'value' => $sModule), $aBlocks, false);
  1632. return $aBlocks;
  1633. }
  1634. protected function _getTmplVarsBlockPanelTop()
  1635. {
  1636. $sJsObject = $this->getPageJsObject();
  1637. $oForm = new BxTemplStudioFormView(array());
  1638. $aInputPages = array(
  1639. 'type' => 'select',
  1640. 'name' => 'page',
  1641. 'attrs' => array(
  1642. 'onChange' => 'javascript:' . $this->getPageJsObject() . '.onChangePage(this)'
  1643. ),
  1644. 'value' => $this->sPage,
  1645. 'values' => array(
  1646. array('key' => '', 'value' => _t('_adm_bp_txt_select_page'))
  1647. )
  1648. );
  1649. $aPages = $this->oDb->getPages(array('type' => 'by_module', 'value' => $this->sType));
  1650. $aCounter = array();
  1651. $this->oDb->getBlocks(array('type' => 'counter_by_pages'), $aCounter, false);
  1652. foreach($aPages as $aPage) {
  1653. $sTitle = _t($aPage['title_system']);
  1654. if(empty($sTitle))
  1655. $sTitle = _t($aPage['title']);
  1656. $aInputPages['values'][] = array(
  1657. 'key' => $aPage['object'],
  1658. 'value' => $sTitle . " (" . (isset($aCounter[$aPage['object']]) ? $aCounter[$aPage['object']] : "0") . ")"
  1659. );
  1660. }
  1661. $aTmplVarsActions = array();
  1662. if(($this->sPage != '' && !empty($this->aPageRebuild)) !== false)
  1663. $aTmplVarsActions = $this->_getTmplVarsBlockPanelTopActions();
  1664. return array(
  1665. 'js_object' => $this->getPageJsObject(),
  1666. 'selector' => $oForm->genRow($aInputPages),
  1667. 'action_page_create' => $this->sActionPageCreate,
  1668. 'bx_if:show_actions' => array(
  1669. 'condition' => $this->sPage != '',
  1670. 'content' => $aTmplVarsActions
  1671. )
  1672. );
  1673. }
  1674. protected function _getTmplVarsBlockPanelTopActions()
  1675. {
  1676. $sJsObject = $this->getPageJsObject();
  1677. $oPermalinks = BxDolPermalinks::getInstance();
  1678. return array(
  1679. 'js_object' => $sJsObject,
  1680. 'url_view' => bx_absolute_url($oPermalinks->permalink($this->aPageRebuild['url'])),
  1681. 'action_page_edit' => $this->sActionPageEdit,
  1682. 'bx_if:can_delete' => array(
  1683. 'condition' => (int)$this->aPageRebuild['deletable'] == 1,
  1684. 'content' => array(
  1685. 'js_object' => $sJsObject
  1686. )
  1687. ),
  1688. 'action_block_create' => $this->sActionBlockCreate,
  1689. );
  1690. }
  1691. protected function _getTmplVarsPageSettings($aPage = array(), $bCreate = true)
  1692. {
  1693. $sJsObject = $this->getPageJsObject();
  1694. $aTmplParams = array(
  1695. 'js_object' => $sJsObject,
  1696. 'menu' => array(),
  1697. 'html_settings_groups_id' => $this->aHtmlIds['settings_groups_id'],
  1698. 'bx_repeat:settings_groups' => array(),
  1699. 'submit' => _t($bCreate ? '_adm_bp_btn_page_create' : '_adm_bp_btn_page_apply')
  1700. );
  1701. foreach($this->aPageSettings as $aSetting) {
  1702. //--- get menu items
  1703. $aTmplParams['menu'][$aSetting['name']] = array(
  1704. 'name' => $aSetting['name'],
  1705. 'icon' => '',
  1706. 'onclick' => $sJsObject . '.onChangeSettingGroup(\'' . $aSetting['name'] . '\', this);',
  1707. 'title' => $aSetting['title'],
  1708. 'selected' => isset($aSetting['active']) && (int)$aSetting['active'] == 1
  1709. );
  1710. //--- get settings
  1711. $aTmplParams['bx_repeat:settings_groups'][] = array(
  1712. 'html_settings_group_id' => $this->aHtmlIds['settings_group_id'] . $aSetting['name'],
  1713. 'bx_if:hidden' => array(
  1714. 'condition' => $aSetting['active'] != 1,
  1715. 'content' => array()
  1716. ),
  1717. 'content' => $this->{'getSettings' . $this->getClassName($aSetting['name'])}($aPage, $bCreate)
  1718. );
  1719. }
  1720. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aTmplParams['menu']));
  1721. $aTmplParams['menu'] = $oMenu->getCode();
  1722. return $aTmplParams;
  1723. }
  1724. protected function getIndexingDataForBlock($sType, $sContent)
  1725. {
  1726. $aBlock = array();
  1727. switch($sType) {
  1728. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1729. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1730. $aBlock['text'] = trim(strip_tags($sContent));
  1731. $aBlock['text_updated'] = time();
  1732. break;
  1733. }
  1734. return $aBlock;
  1735. }
  1736. }
  1737. /** @} */