BxBaseStudioBuilderPage.php 77 KB

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