BxBaseStudioBuilderPage.php 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentView Trident Studio Representation classes
  7. * @ingroup TridentStudio
  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 $sBaseUrl;
  20. protected $sTypeUrl;
  21. protected $sPageUrl;
  22. protected $aHtmlIds = array(
  23. 'add_popup_id' => 'adm-bp-add-popup',
  24. 'edit_popup_id' => 'adm-bp-edit-popup',
  25. 'uri_field_id' => 'adm-bp-field-uri',
  26. 'url_field_id' => 'adm-bp-field-url',
  27. 'settings_group_id' => 'adm-bp-settings-group-',
  28. 'settings_groups_id' => 'adm-bp-settings-groups',
  29. 'create_block_popup_id' => 'adm-bp-create-block-popup',
  30. 'edit_block_popup_id' => 'adm-bp-edit-block-popup',
  31. 'block_id' => 'adm-bpb-',
  32. 'block_list_id' => 'adm-bpl-',
  33. 'block_lists_id' => 'adm-bp-block-lists',
  34. 'layout_id' => 'adm-bpl-',
  35. );
  36. protected $aPageSettings = array(
  37. array('name' => 'options', 'title' => '_adm_bp_mi_page_options', 'active' => 1),
  38. array('name' => 'layout', 'title' => '_adm_bp_mi_page_layout', 'active' => 0),
  39. array('name' => 'visibility', 'title' => '_adm_bp_mi_page_visibility', 'active' => 0),
  40. array('name' => 'cache', 'title' => '_adm_bp_mi_page_cache', 'active' => 0),
  41. array('name' => 'seo', 'title' => '_adm_bp_mi_page_seo', 'active' => 0)
  42. );
  43. function __construct($sType = '', $sPage = '')
  44. {
  45. parent::__construct($sType, $sPage);
  46. $this->sBaseUrl = BX_DOL_URL_STUDIO . 'builder_page.php';
  47. $this->sTypeUrl = $this->sBaseUrl . '?type=%s';
  48. $this->sPageUrl = $this->sTypeUrl . '&page=%s';
  49. }
  50. function getPageCss()
  51. {
  52. return array_merge(parent::getPageCss(), array('page_layouts.css', 'builder_page.css'));
  53. }
  54. function getPageJs()
  55. {
  56. return array_merge(parent::getPageJs(), array(
  57. 'jquery-ui/jquery.ui.core.min.js',
  58. 'jquery-ui/jquery.ui.widget.min.js',
  59. 'jquery-ui/jquery.ui.mouse.min.js',
  60. 'jquery-ui/jquery.ui.sortable.min.js',
  61. 'jquery.ui.touch-punch.min.js',
  62. 'jquery.easing.js',
  63. 'jquery.form.min.js',
  64. 'functions.js',
  65. 'builder_page.js'
  66. ));
  67. }
  68. function getPageJsObject()
  69. {
  70. return 'oBxDolStudioBuilderPage';
  71. }
  72. function getPageMenu($aMenu = array(), $aMarkers = array())
  73. {
  74. $aMenuItems = array(
  75. BX_DOL_STUDIO_MODULE_SYSTEM => array(
  76. 'name' => BX_DOL_STUDIO_MODULE_SYSTEM,
  77. 'icon' => 'cog',
  78. ),
  79. BX_DOL_STUDIO_MODULE_CUSTOM => array(
  80. 'name' => BX_DOL_STUDIO_MODULE_CUSTOM,
  81. 'icon' => 'wrench',
  82. 'title' => '_adm_bp_cpt_type_' . BX_DOL_STUDIO_MODULE_CUSTOM,
  83. )
  84. );
  85. $aModulesDb = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules'));
  86. foreach($aModulesDb as $aModuleDb) {
  87. $sName = $aModuleDb['name'];
  88. if(!empty($aMenuItems[$sName]))
  89. $aMenuItems[$sName] = array_merge($aMenuItems[$sName], $aModuleDb);
  90. else
  91. $aMenuItems[$sName] = $aModuleDb;
  92. if(empty($aMenuItems[$sName]['icon']))
  93. $aMenuItems[$sName]['icon'] = BxDolStudioUtils::getModuleIcon($aModuleDb, 'menu', false);
  94. }
  95. $aMenu = array();
  96. foreach($aMenuItems as $aMenuItem)
  97. $aMenu[] = array(
  98. 'name' => $aMenuItem['name'],
  99. 'icon' => $aMenuItem['icon'],
  100. 'link' => sprintf($this->sTypeUrl, $aMenuItem['name']),
  101. 'title' => $aMenuItem['title'],
  102. 'selected' => $aMenuItem['name'] == $this->sType
  103. );
  104. return parent::getPageMenu($aMenu);
  105. }
  106. function getPageCode($bHidden = false)
  107. {
  108. $oPage = BxTemplPage::getObjectInstance($this->sPage);
  109. $oTemplate = BxDolStudioTemplate::getInstance();
  110. $sJsObject = $this->getPageJsObject();
  111. $sTxtEmpty = _t('_sys_txt_empty');
  112. $sContent = "";
  113. if(($bPage = $this->sPage != '') === true) {
  114. $aTmplVars = array();
  115. for($i = 1; $i <= $this->aPageRebuild['layout_cells_number']; $i++) {
  116. $aBlocks = array();
  117. $this->oDb->getBlocks(array('type' => 'by_object_cell', 'object' => $this->aPageRebuild['object'], 'cell' => $i), $aBlocks, false);
  118. $aTmplVarsCell = array('id' => $i, 'bx_repeat:blocks' => array());
  119. foreach($aBlocks as $aBlock) {
  120. $sTitle = !empty($aBlock['title_system']) ? _t($aBlock['title_system']) : $oPage->getBlockTitle($aBlock);
  121. list($sIcon, $sIconUrl) = $this->getBlockIcon($aBlock);
  122. $aTmplVarsCell['bx_repeat:blocks'][] = array(
  123. 'html_id' => $this->aHtmlIds['block_id'] . $aBlock['id'],
  124. 'bx_if:is_inactive' => array(
  125. 'condition' => (int)$aBlock['active'] == 0,
  126. 'content' => array()
  127. ),
  128. 'bx_if:show_link' => array(
  129. 'condition' => true,
  130. 'content' => array(
  131. 'onclick' => $sJsObject . ".performAction('block_edit', {id: " . $aBlock['id'] . "})",
  132. 'title' => !empty($sTitle) ? $sTitle : $sTxtEmpty,
  133. )
  134. ),
  135. 'bx_if:show_text' => array(
  136. 'condition' => false,
  137. 'content' => array()
  138. ),
  139. 'bx_if:image' => array (
  140. 'condition' => (bool)$sIconUrl,
  141. 'content' => array('icon_url' => $sIconUrl),
  142. ),
  143. 'bx_if:icon' => array (
  144. 'condition' => (bool)$sIcon,
  145. 'content' => array('icon' => $sIcon),
  146. ),
  147. 'module' => $this->getModuleTitle($aBlock['module']),
  148. 'visible_for' => _t('_adm_bp_txt_visible_for', BxDolStudioUtils::getVisibilityTitle($aBlock['visible_for_levels'])),
  149. 'bx_if:show_checkbox' => array(
  150. 'condition' => false,
  151. 'content' => array()
  152. ),
  153. 'bx_if:show_drag_handle' => array(
  154. 'condition' => true,
  155. 'content' => array()
  156. )
  157. );
  158. }
  159. $aTmplVars['cell_' . $i] = $oTemplate->parseHtmlByName('bp_cell.html', $aTmplVarsCell);
  160. }
  161. $sContent = $oTemplate->parseHtmlByName($this->aPageRebuild['layout_template'], $aTmplVars);
  162. }
  163. $aLanguages = BxDolStudioLanguagesUtils::getInstance()->getLanguages();
  164. $aTmplVars = array(
  165. 'js_object' => $sJsObject,
  166. 'action_url' => $this->sBaseUrl,
  167. 'page_url' => sprintf($this->sPageUrl, '{0}', '{1}'),
  168. 'type' => $this->sType,
  169. 'page' => $this->sPage,
  170. 'html_ids' => json_encode($this->aHtmlIds),
  171. 'languahes' => json_encode($aLanguages),
  172. 'bx_repeat:blocks' => array(
  173. array(
  174. 'caption' => '',
  175. 'panel_top' => $this->getBlockPanelTop(),
  176. 'items' => $sContent,
  177. 'panel_bottom' => ''
  178. )
  179. )
  180. );
  181. $oTemplate->addJsTranslation(array(
  182. '_adm_bp_wrn_page_delete',
  183. '_adm_bp_wrn_page_block_delete'
  184. ));
  185. return $oTemplate->parseHtmlByName('builder_page.html', $aTmplVars);
  186. }
  187. function getBlockPanelTop($aParams = array())
  188. {
  189. $oTemplate = BxDolStudioTemplate::getInstance();
  190. return parent::getBlockPanelTop(
  191. array('panel_top' => $oTemplate->parseHtmlByName('bp_block_panel_top.html', $this->_getTmplVarsBlockPanelTop()))
  192. );
  193. }
  194. protected function actionPageCreate()
  195. {
  196. $oTemplate = BxDolStudioTemplate::getInstance();
  197. $sModule = BX_DOL_STUDIO_MODULE_CUSTOM;
  198. $aForm = array(
  199. 'form_attrs' => array(
  200. 'id' => 'adm-bp-page-create',
  201. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionPageCreate,
  202. 'method' => 'post'
  203. ),
  204. 'params' => array (
  205. 'db' => array(
  206. 'table' => 'sys_objects_page',
  207. 'key' => 'id',
  208. 'uri' => '',
  209. 'uri_title' => '',
  210. 'submit_name' => 'do_submit'
  211. ),
  212. ),
  213. 'inputs' => array (
  214. 'module' => array(
  215. 'type' => 'hidden',
  216. 'name' => 'module',
  217. 'value' => $sModule,
  218. 'db' => array (
  219. 'pass' => 'Xss',
  220. ),
  221. ),
  222. 'deletable' => array(
  223. 'type' => 'hidden',
  224. 'name' => 'deletable',
  225. 'value' => 1,
  226. 'db' => array (
  227. 'pass' => 'Int',
  228. ),
  229. ),
  230. 'settings' => array(
  231. 'type' => 'custom',
  232. 'name' => 'settings',
  233. 'content' => $oTemplate->parseHtmlByName('bp_edit_page_form.html', $this->_getTmplVarsPageSettings()),
  234. ),
  235. )
  236. );
  237. $oForm = new BxTemplStudioFormView($aForm);
  238. $oForm->initChecker();
  239. if($oForm->isSubmittedAndValid()) {
  240. unset($oForm->aInputs['settings']);
  241. foreach($this->aPageSettings as $aSetting)
  242. $oForm->aInputs = array_merge($oForm->aInputs, $this->{'getSettings' . $this->getClassName($aSetting['name']) . 'Fields'}());
  243. $sLanguage = BxDolStudioLanguagesUtils::getInstance()->getCurrentLangName(false);
  244. $sObject = BxDolForm::getSubmittedValue('title-' . $sLanguage, $aForm['form_attrs']['method']);
  245. $sObject = uriGenerate($sObject, 'sys_objects_page', 'object', 'object');
  246. $sUri = $oForm->getCleanValue('uri');
  247. $iVisibleFor = BxDolStudioUtils::getVisibilityValue($oForm->getCleanValue('visible_for'), $oForm->getCleanValue('visible_for_levels'));
  248. BxDolForm::setSubmittedValue('visible_for_levels', $iVisibleFor, $aForm['form_attrs']['method']);
  249. unset($oForm->aInputs['visible_for']);
  250. $iId = (int)$oForm->insert(array('object' => $sObject, 'url' => $this->sPageBaseUrl . $sUri));
  251. if($iId != 0)
  252. return array('eval' => $this->getPageJsObject() . '.onCreatePage(\'' . $sModule . '\', \'' . $sObject . '\')');
  253. else
  254. return array('msg' => _t('_adm_bp_err_page_create'));
  255. }
  256. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['add_popup_id'], _t('_adm_bp_txt_create_popup'), $oTemplate->parseHtmlByName('bp_add_page.html', array(
  257. 'form_id' => $aForm['form_attrs']['id'],
  258. 'form' => $oForm->getCode(true)
  259. )));
  260. return array('popup' => $sContent);
  261. }
  262. protected function actionPageEdit()
  263. {
  264. $sJsObject = $this->getPageJsObject();
  265. $oTemplate = BxDolStudioTemplate::getInstance();
  266. $aForm = array(
  267. 'form_attrs' => array(
  268. 'id' => 'adm-bp-page-edit',
  269. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionPageEdit,
  270. 'method' => 'post'
  271. ),
  272. 'params' => array (
  273. 'db' => array(
  274. 'table' => 'sys_objects_page',
  275. 'key' => 'id',
  276. 'uri' => '',
  277. 'uri_title' => '',
  278. 'submit_name' => 'do_submit'
  279. ),
  280. ),
  281. 'inputs' => array (
  282. 'settings' => array(
  283. 'type' => 'custom',
  284. 'name' => 'settings',
  285. 'content' => $oTemplate->parseHtmlByName('bp_edit_page_form.html', $this->_getTmplVarsPageSettings($this->aPageRebuild, false)),
  286. ),
  287. )
  288. );
  289. $oForm = new BxTemplStudioFormView($aForm);
  290. $oForm->initChecker();
  291. if($oForm->isSubmittedAndValid()) {
  292. unset($oForm->aInputs['settings']);
  293. foreach($this->aPageSettings as $aSetting)
  294. $oForm->aInputs = array_merge($oForm->aInputs, $this->{'getSettings' . $this->getClassName($aSetting['name']) . 'Fields'}($this->aPageRebuild, false));
  295. $iVisibleFor = BxDolStudioUtils::getVisibilityValue($oForm->getCleanValue('visible_for'), $oForm->getCleanValue('visible_for_levels'));
  296. BxDolForm::setSubmittedValue('visible_for_levels', $iVisibleFor, $aForm['form_attrs']['method']);
  297. unset($oForm->aInputs['visible_for']);
  298. if($oForm->update($this->aPageRebuild['id'])) {
  299. $iLevelId = $oForm->getCleanValue('layout_id');
  300. if(!empty($iLevelId) && $iLevelId != $this->aPageRebuild['layout_id']) {
  301. $aLayoutOld = array();
  302. $this->oDb->getLayouts(array('type' => 'by_id', 'value' => $this->aPageRebuild['layout_id']), $aLayoutOld, false);
  303. $aLayoutNew = array();
  304. $this->oDb->getLayouts(array('type' => 'by_id', 'value' => $iLevelId), $aLayoutNew, false);
  305. if($aLayoutOld['cells_number'] > $aLayoutNew['cells_number'] && $this->oDb->resetBlocksByPage($this->sPage, $aLayoutNew['cells_number']) === false)
  306. return array('msg' => _t('_adm_bp_err_save'));
  307. return array('eval' => $sJsObject . '.onSaveSettings()');
  308. }
  309. return array();
  310. } else
  311. return array('msg' => _t('_adm_bp_err_save'));
  312. }
  313. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['edit_popup_id'], _t('_adm_bp_txt_settings_popup'), $oTemplate->parseHtmlByName('bp_edit_page.html', array(
  314. 'form_id' => $aForm['form_attrs']['id'],
  315. 'form' => $oForm->getCode(true)
  316. )));
  317. return array('popup' => $sContent);
  318. }
  319. protected function actionPageDelete()
  320. {
  321. if(empty($this->sPage) || empty($this->aPageRebuild) || !is_array($this->aPageRebuild))
  322. return array('msg' => _t('_adm_bp_err_page_delete'));
  323. $oLangauge = BxDolStudioLanguagesUtils::getInstance();
  324. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  325. $aBlocks = array();
  326. $this->oDb->getBlocks(array('type' => 'by_object', 'value' => $this->sPage), $aBlocks, false);
  327. if(is_array($aBlocks) && !empty($aBlocks)) {
  328. foreach($aBlocks as $aBlock)
  329. $this->onBlockDelete($aBlock);
  330. $this->oDb->deleteBlocks(array('type' => 'by_object', 'value' => $this->sPage));
  331. }
  332. if($this->oDb->deletePages(array('type' => 'by_object', 'value' => $this->sPage))) {
  333. $oLangauge->deleteLanguageString($this->aPageRebuild['title_system']);
  334. $oLangauge->deleteLanguageString($this->aPageRebuild['title']);
  335. return array('eval' => 'window.parent.location.href = "' . sprintf($this->sTypeUrl, $this->sType) . '";');
  336. }
  337. return array('msg' => _t('_adm_bp_err_page_delete'));
  338. }
  339. protected function actionBlockList()
  340. {
  341. $sModule = BX_DOL_STUDIO_BP_TYPE_DEFAULT;
  342. if(bx_get('bp_module') !== false)
  343. $sModule = bx_process_input(bx_get('bp_module'));
  344. return array(
  345. 'content' => $this->getBlockList($sModule)
  346. );
  347. }
  348. protected function actionBlockCreate()
  349. {
  350. $sJsObject = $this->getPageJsObject();
  351. $oTemplate = BxDolStudioTemplate::getInstance();
  352. $sSelected = BX_DOL_STUDIO_BP_SKELETONS;
  353. $aForm = array(
  354. 'form_attrs' => array(
  355. 'id' => 'adm-bp-block-create',
  356. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionBlockCreate,
  357. 'method' => 'post'
  358. ),
  359. 'params' => array (
  360. 'db' => array(
  361. 'table' => 'sys_pages_blocks',
  362. 'key' => 'id',
  363. 'uri' => '',
  364. 'uri_title' => '',
  365. 'submit_name' => 'do_submit'
  366. ),
  367. ),
  368. 'inputs' => array (
  369. 'blocks' => array(
  370. 'type' => 'custom',
  371. 'name' => 'blocks',
  372. 'content' => '',
  373. 'db' => array (
  374. 'pass' => 'Int',
  375. ),
  376. ),
  377. )
  378. );
  379. $aMenu = array(
  380. BX_DOL_STUDIO_BP_SKELETONS => array(
  381. 'name' => BX_DOL_STUDIO_BP_SKELETONS,
  382. 'icon' => 'qrcode',
  383. 'title' => '_sys_block_types_skeletons',
  384. 'selected' => $sSelected == BX_DOL_STUDIO_BP_SKELETONS,
  385. ),
  386. BX_DOL_STUDIO_MODULE_SYSTEM => array(
  387. 'name' => BX_DOL_STUDIO_MODULE_SYSTEM,
  388. 'icon' => 'cog',
  389. 'title' => '_sys_block_types_system',
  390. 'selected' => $sSelected == BX_DOL_STUDIO_MODULE_SYSTEM,
  391. ),
  392. BX_DOL_STUDIO_MODULE_CUSTOM => array(
  393. 'name' => BX_DOL_STUDIO_MODULE_CUSTOM,
  394. 'icon' => 'wrench',
  395. 'title' => '_sys_block_types_custom',
  396. 'selected' => $sSelected == BX_DOL_STUDIO_MODULE_CUSTOM,
  397. )
  398. );
  399. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules'));
  400. $aModulesWithBlocks = $this->oDb->getModulesWithCopyableBlocks();
  401. foreach($aModules as $aModule) {
  402. $sName = $aModule['name'];
  403. if(!in_array($sName, $aModulesWithBlocks))
  404. continue;
  405. if(!empty($aMenu[$sName]))
  406. $aMenu[$sName] = array_merge($aMenu[$sName], $aModule);
  407. else
  408. $aMenu[$sName] = $aModule;
  409. if(empty($aMenu[$sName]['icon']))
  410. $aMenu[$sName]['icon'] = BxDolStudioUtils::getModuleIcon($aModule, 'menu', false);
  411. }
  412. foreach($aMenu as $sKey => $aItem)
  413. $aMenu[$sKey]['onclick'] = $sJsObject . '.onChangeModule(\'' . $aItem['name'] . '\', this);';
  414. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aMenu));
  415. $aTmplParams = array(
  416. 'menu' => $oMenu->getCode(),
  417. 'html_block_lists_id' => $this->aHtmlIds['block_lists_id'],
  418. 'blocks' => $this->getBlockList($sSelected)
  419. );
  420. $aForm['inputs']['blocks']['content'] = $oTemplate->parseHtmlByName('bp_add_block_form.html', $aTmplParams);
  421. $oForm = new BxTemplStudioFormView($aForm);
  422. $oForm->initChecker();
  423. if($oForm->isSubmittedAndValid()) {
  424. $aIds = $oForm->getCleanValue('blocks');
  425. $aBlocks = array();
  426. $this->oDb->getBlocks(array('type' => 'by_ids', 'value' => $aIds), $aBlocks, false);
  427. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  428. $oStorege = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  429. $bResult = true;
  430. foreach($aBlocks as $aBlock) {
  431. $sTitleKey = $this->getSystemName($aBlock['title'] . '_' . time());
  432. $sTitleValue = _t($aBlock['title']);
  433. unset($aBlock['id']);
  434. $aBlock['object'] = $this->sPage;
  435. $aBlock['cell_id'] = 1;
  436. $aBlock['module'] = $this->getBlockModule($aBlock);
  437. $aBlock['title'] = $sTitleKey;
  438. $aBlock['copyable'] = 0;
  439. $aBlock['deletable'] = 1;
  440. //--- Process Lang copy
  441. $sContentKey = $sContentValue = "";
  442. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && $aBlock['content'] != '') {
  443. $sContentKey = $this->getSystemName($aBlock['content'] . '_' . time());
  444. $sContentValue = _t($aBlock['content']);
  445. $aBlock['content'] = $sContentKey;
  446. $oLanguage->addLanguageString($sContentKey, $sContentValue);
  447. }
  448. //--- Process Image copy
  449. $iImageId = $sImageAlign = "";
  450. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && $aBlock['content'] != '') {
  451. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  452. $aBlock['content'] = "";
  453. if(is_numeric($iImageId) && (int)$iImageId != 0 && ($iImageId = $oStorege->storeFileFromStorage(array('id' => $iImageId))) !== false)
  454. $aBlock['content'] = implode($this->sParamsDivider, array($iImageId, $sImageAlign));
  455. }
  456. if(!$this->oDb->insertBlock($aBlock)) {
  457. if($sContentKey != "")
  458. $oLanguage->deleteLanguageString($sContentKey);
  459. if($iImageId != "")
  460. $oStorege->deleteFile((int)$iImageId, 0);
  461. $bResult = false;
  462. break;
  463. }
  464. $oLanguage->addLanguageString($sTitleKey, $sTitleValue);
  465. }
  466. if($bResult)
  467. return array('eval' => $sJsObject . '.onCreateBlock(oData)');
  468. else
  469. return array('msg' => _t('_adm_bp_err_block_added'));
  470. }
  471. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->aHtmlIds['create_block_popup_id'], _t('_adm_bp_txt_new_block_popup'), $oTemplate->parseHtmlByName('bp_add_block.html', array(
  472. 'action' => 'create',
  473. 'form_id' => $aForm['form_attrs']['id'],
  474. 'form' => $oForm->getCode(true)
  475. )));
  476. return array('popup' => $sContent);
  477. }
  478. protected function actionBlockEdit()
  479. {
  480. $sJsObject = $this->getPageJsObject();
  481. $oTemplate = BxDolStudioTemplate::getInstance();
  482. $iId = (int)bx_get('id');
  483. if(!$iId)
  484. return array();
  485. $aBlock = array();
  486. $this->oDb->getBlocks(array('type' => 'by_id', 'value' => $iId), $aBlock, false);
  487. if(empty($aBlock) || !is_array($aBlock))
  488. return array('msg' => _t('_adm_bp_err_block_not_found'));
  489. $aForm = array(
  490. 'form_attrs' => array(
  491. 'id' => 'adm-bp-block-edit',
  492. 'action' => sprintf($this->sPageUrl, $this->sType, $this->sPage) . '&bp_action=' . $this->sActionBlockEdit,
  493. 'method' => 'post'
  494. ),
  495. 'params' => array (
  496. 'db' => array(
  497. 'table' => 'sys_pages_blocks',
  498. 'key' => 'id',
  499. 'uri' => '',
  500. 'uri_title' => '',
  501. 'submit_name' => 'do_submit'
  502. ),
  503. ),
  504. 'inputs' => array (
  505. 'id' => array(
  506. 'type' => 'hidden',
  507. 'name' => 'id',
  508. 'value' => $iId,
  509. 'db' => array (
  510. 'pass' => 'Int',
  511. ),
  512. ),
  513. 'title' => array(
  514. 'type' => 'text_translatable',
  515. 'name' => 'title',
  516. 'caption' => _t('_adm_bp_txt_block_title'),
  517. 'info' => _t('_adm_bp_dsc_block_title'),
  518. 'value' => $aBlock['title'],
  519. 'required' => '1',
  520. 'db' => array (
  521. 'pass' => 'Xss',
  522. ),
  523. 'checker' => array (
  524. 'func' => 'length',
  525. 'params' => array(3,100),
  526. 'error' => _t('_adm_bp_err_block_title'),
  527. ),
  528. ),
  529. 'designbox_id' => array(
  530. 'type' => 'select',
  531. 'name' => 'designbox_id',
  532. 'caption' => _t('_adm_bp_txt_block_designbox'),
  533. 'info' => '',
  534. 'value' => $this->sSelectKeyPrefix . $aBlock['designbox_id'],
  535. 'values' => array(
  536. array('key' => '', 'value' => _t('_adm_bp_txt_block_designbox_empty')),
  537. ),
  538. 'required' => '1',
  539. 'db' => array (
  540. 'pass' => 'Xss',
  541. ),
  542. 'checker' => array (
  543. 'func' => 'avail',
  544. 'params' => array(),
  545. 'error' => _t('_adm_bp_err_block_designbox'),
  546. ),
  547. ),
  548. 'visible_for' => array(
  549. 'type' => 'select',
  550. 'name' => 'visible_for',
  551. 'caption' => _t('_adm_bp_txt_block_visible_for'),
  552. 'info' => '',
  553. 'value' => $aBlock['visible_for_levels'] == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
  554. 'values' => array(
  555. array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_bp_txt_block_visible_for_all')),
  556. array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_bp_txt_block_visible_for_selected')),
  557. ),
  558. 'required' => '0',
  559. 'attrs' => array(
  560. 'onchange' => $this->getPageJsObject() . '.onChangeVisibleFor(this)'
  561. ),
  562. 'db' => array (
  563. 'pass' => 'Xss',
  564. )
  565. ),
  566. 'visible_for_levels' => array(
  567. 'type' => 'checkbox_set',
  568. 'name' => 'visible_for_levels',
  569. 'caption' => _t('_adm_bp_txt_block_visible_for_levels'),
  570. 'info' => _t('_adm_bp_dsc_block_visible_for_levels'),
  571. 'value' => array(),
  572. 'values' => array(),
  573. 'tr_attrs' => array(
  574. 'style' => $aBlock['visible_for_levels'] == BX_DOL_INT_MAX ? 'display:none' : ''
  575. ),
  576. 'db' => array (
  577. 'pass' => 'Int',
  578. )
  579. ),
  580. 'active' => array(
  581. 'type' => 'switcher',
  582. 'name' => 'active',
  583. 'caption' => _t('_adm_bp_txt_block_active'),
  584. 'info' => '',
  585. 'value' => '1',
  586. 'checked' => $aBlock['active'] == '1',
  587. 'db' => array (
  588. 'pass' => 'Int',
  589. )
  590. ),
  591. 'controls' => array(
  592. 'name' => 'controls',
  593. 'type' => 'input_set',
  594. array(
  595. 'type' => 'submit',
  596. 'name' => 'do_submit',
  597. 'value' => _t('_adm_bp_btn_block_save'),
  598. ),
  599. array (
  600. 'type' => 'reset',
  601. 'name' => 'close',
  602. 'value' => _t('_adm_bp_btn_block_cancel'),
  603. 'attrs' => array(
  604. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  605. 'class' => 'bx-def-margin-sec-left',
  606. ),
  607. )
  608. )
  609. )
  610. );
  611. $aDBoxes = array();
  612. $this->oDb->getDesignBoxes(array('type' => 'ordered'), $aDBoxes, false);
  613. foreach($aDBoxes as $aDBox)
  614. $aForm['inputs']['designbox_id']['values'][] = array('key' => $this->sSelectKeyPrefix . $aDBox['id'], 'value' => _t($aDBox['title']));
  615. BxDolStudioUtils::getVisibilityValues($aBlock['visible_for_levels'], $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
  616. $aForm['inputs'] = $this->addInArray($aForm['inputs'], 'visible_for_levels', $this->getBlockContent($aBlock));
  617. if((int)$aBlock['deletable'] != 0)
  618. $aForm['inputs']['controls'][] = array (
  619. 'type' => 'reset',
  620. 'name' => 'close',
  621. 'value' => _t('_adm_bp_btn_block_delete'),
  622. 'attrs' => array(
  623. 'onclick' => $this->getPageJsObject() . ".deleteBlock(" . $aBlock['id'] . ")",
  624. 'class' => 'bx-def-margin-sec-left',
  625. ),
  626. );
  627. $oForm = new BxTemplStudioFormView($aForm);
  628. $oForm->initChecker();
  629. if($oForm->isSubmittedAndValid()) {
  630. $this->onSaveBlock($oForm, $aBlock);
  631. if($oForm->update($iId) !== false)
  632. return array('eval' => $sJsObject . '.onEditBlock(oData)');
  633. else
  634. return array('msg' => _t('_adm_bp_err_block_edit'));
  635. }
  636. $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(
  637. 'action' => 'edit',
  638. 'form_id' => $aForm['form_attrs']['id'],
  639. 'form' => $oForm->getCode(true)
  640. )));
  641. return array('popup' => $sContent);
  642. }
  643. protected function actionBlockDelete()
  644. {
  645. $sJsObject = $this->getPageJsObject();
  646. $iId = (int)bx_get('id');
  647. $aBlock = array();
  648. $this->oDb->getBlocks(array('type' => 'by_id', 'value' => $iId), $aBlock, false);
  649. if(empty($aBlock) || !is_array($aBlock))
  650. return array('msg' => _t('_adm_bp_err_block_not_found'));
  651. if((int)$aBlock['deletable'] == 0)
  652. return array('msg' => _t('_adm_bp_err_block_not_deletable'));
  653. if(!$this->oDb->deleteBlocks(array('type' => 'by_id', 'value' => $iId)))
  654. return array('msg' => _t('_adm_bp_err_block_delete'));
  655. $this->onBlockDelete($aBlock);
  656. return array('eval' => $sJsObject . '.onDeleteBlock(' . $iId . ', oData)');
  657. }
  658. protected function actionImageDelete()
  659. {
  660. $sJsObject = $this->getPageJsObject();
  661. $iId = (int)bx_get('id');
  662. $aBlock = array();
  663. $this->oDb->getBlocks(array('type' => 'by_id', 'value' => $iId), $aBlock, false);
  664. if(empty($aBlock) || !is_array($aBlock))
  665. return array('msg' => _t('_adm_bp_err_block_not_found'));
  666. $iImageId = $sImageAlign = '';
  667. if($aBlock['content'] != '')
  668. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  669. if(is_numeric($iImageId) && (int)$iImageId != 0) {
  670. if(!BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$iImageId, 0))
  671. return array('msg' => _t('_adm_bp_err_block_content_image_preview_delete'));
  672. $this->oDb->updateBlock($iId, array('content' => ''));
  673. }
  674. return $this->actionBlockEdit();
  675. }
  676. protected function actionUriGet()
  677. {
  678. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  679. $aLanguages = $oLanguage->getLanguages();
  680. $sLanguageDef = $oLanguage->getDefaultLangName();
  681. $sLanguageCur = $oLanguage->getCurrentLangName(false);
  682. $aValues = array();
  683. foreach($aLanguages as $sName => $sTitle)
  684. if(($mixedValue = bx_get($sName)) !== false)
  685. $aValues[$sName] = bx_process_input($mixedValue);
  686. $sUri = "";
  687. if(($mixedValue = bx_get('uri')) !== false)
  688. $sUri = bx_process_input($mixedValue);
  689. else if(array_key_exists('en', $aValues) && $aValues['en'] != '')
  690. $sUri = $aValues['en'];
  691. else if(array_key_exists($sLanguageDef, $aValues) && $aValues[$sLanguageDef] != '')
  692. $sUri = $aValues[$sLanguageDef];
  693. else if(array_key_exists($sLanguageCur, $aValues) && $aValues[$sLanguageCur] != '')
  694. $sUri = $aValues[$sLanguageCur];
  695. else if(count($aValues) > 0)
  696. foreach($aValues as $sValue)
  697. if(!empty($sValue)) {
  698. $sUri = $sValue;
  699. break;
  700. }
  701. $sUri = $sUri != "" ? uriGenerate($sUri, 'sys_objects_page', 'uri') : "";
  702. $sUrl = BxDolPermalinks::getInstance()->permalink($this->sPageBaseUrl . $sUri);
  703. return array('eval' => $this->getPageJsObject() . '.onGetUri(oData)', 'uri' => $sUri, 'url' => $sUrl);
  704. }
  705. protected function getSettingsOptions($aPage = array(), $bCreate = true, $bInputsOnly = false)
  706. {
  707. $aForm = array(
  708. 'form_attrs' => array(
  709. 'id' => 'adm-bp-settings-seo',
  710. ),
  711. 'params' => array (
  712. 'remove_form' => '1',
  713. 'csrf' => array(
  714. 'disable' => true
  715. )
  716. ),
  717. 'inputs' => array (
  718. 'title_system' => array(
  719. 'type' => 'text_translatable',
  720. 'name' => 'title_system',
  721. 'caption' => _t('_adm_bp_txt_page_title_system'),
  722. 'info' => _t('_adm_bp_dsc_page_title_system'),
  723. 'value' => isset($aPage['title_system']) ? $aPage['title_system'] : '',
  724. 'required' => '1',
  725. 'db' => array (
  726. 'pass' => 'Xss',
  727. ),
  728. 'checker' => array (
  729. 'func' => 'length',
  730. 'params' => array(3,100),
  731. 'error' => _t('_adm_bp_err_page_title_system'),
  732. ),
  733. ),
  734. 'title' => array(
  735. 'type' => 'text_translatable',
  736. 'name' => 'title',
  737. 'caption' => _t('_adm_bp_txt_page_title'),
  738. 'info' => _t('_adm_bp_dsc_page_title'),
  739. 'value' => isset($aPage['title']) ? $aPage['title'] : '',
  740. 'required' => '1',
  741. 'db' => array (
  742. 'pass' => 'Xss',
  743. ),
  744. 'checker' => array (
  745. 'func' => 'length',
  746. 'params' => array(3,100),
  747. 'error' => _t('_adm_bp_err_page_title'),
  748. ),
  749. ),
  750. 'url' => array(
  751. 'type' => 'text',
  752. 'name' => 'url',
  753. 'caption' => _t('_adm_bp_txt_page_url'),
  754. 'info' => _t('_adm_bp_dsc_page_url'),
  755. 'value' => isset($aPage['url']) ? BxDolPermalinks::getInstance()->permalink($aPage['url']) : '',
  756. 'required' => '0',
  757. 'attrs' => array(
  758. 'id' => $this->aHtmlIds['url_field_id'],
  759. 'disabled' => 'disabled'
  760. ),
  761. )
  762. )
  763. );
  764. if($bCreate) {
  765. $sJsObject = $this->getPageJsObject();
  766. $aForm['inputs']['title']['attrs']['onblur'] = $sJsObject . '.getUri(this);';
  767. $aForm['inputs'] = bx_array_insert_before(array(
  768. 'uri' => array(
  769. 'type' => 'text',
  770. 'name' => 'uri',
  771. 'caption' => _t('_adm_bp_txt_page_uri'),
  772. 'info' => _t('_adm_bp_dsc_page_uri'),
  773. 'value' => '',
  774. 'required' => '1',
  775. 'attrs' => array(
  776. 'id' => $this->aHtmlIds['uri_field_id'],
  777. 'onblur' => $sJsObject . '.getUri(this);'
  778. ),
  779. 'db' => array (
  780. 'pass' => 'Xss',
  781. ),
  782. 'checker' => array (
  783. 'func' => 'length',
  784. 'params' => array(3,100),
  785. 'error' => _t('_adm_bp_err_page_uri'),
  786. ),
  787. )
  788. ), $aForm['inputs'], 'url');
  789. }
  790. if($bInputsOnly)
  791. return $aForm['inputs'];
  792. $oForm = new BxTemplStudioFormView($aForm);
  793. return $oForm->getCode();
  794. }
  795. protected function getSettingsOptionsFields($aPage = array(), $bCreate = true, $bInputsOnly = false)
  796. {
  797. return $this->getSettingsOptions($aPage, $bCreate, true);
  798. }
  799. protected function getSettingsLayout($aPage = array(), $bCreate = true, $bInputsOnly = false)
  800. {
  801. $sJsObject = $this->getPageJsObject();
  802. $oTemplate = BxDolStudioTemplate::getInstance();
  803. $iLayout = isset($aPage['layout_id']) ? (int)$aPage['layout_id'] : 5;
  804. $aLayouts = array();
  805. $this->oDb->getLayouts(array('type' => 'all'), $aLayouts, false);
  806. $aTmplParams = array(
  807. 'bx_repeat:layouts' => array(),
  808. 'form' => ''
  809. );
  810. foreach($aLayouts as $aLayout)
  811. $aTmplParams['bx_repeat:layouts'][] = array(
  812. 'id' => $aLayout['id'],
  813. 'html_id' => $this->aHtmlIds['layout_id'] . $aLayout['id'],
  814. 'js_object' => $sJsObject,
  815. 'bx_if:active' => array(
  816. 'condition' => (int)$aLayout['id'] == $iLayout,
  817. 'content' => array()
  818. ),
  819. 'icon' => $oTemplate->getImageUrl($aLayout['icon']),
  820. 'title' => _t($aLayout['title']),
  821. );
  822. $aForm = array(
  823. 'form_attrs' => array(
  824. 'id' => 'adm-bp-settings-seo',
  825. ),
  826. 'params' => array (
  827. 'remove_form' => '1',
  828. 'csrf' => array(
  829. 'disable' => true
  830. )
  831. ),
  832. 'inputs' => array (
  833. 'layout_id' => array(
  834. 'type' => 'hidden',
  835. 'name' => 'layout_id',
  836. 'value' => $iLayout,
  837. 'db' => array (
  838. 'pass' => 'Int',
  839. ),
  840. )
  841. )
  842. );
  843. if($bInputsOnly)
  844. return $aForm['inputs'];
  845. $oForm = new BxTemplStudioFormView($aForm);
  846. $aTmplParams['form'] = $oForm->getCode();
  847. return $oTemplate->parseHtmlByName('bp_layouts.html', $aTmplParams);
  848. }
  849. protected function getSettingsLayoutFields($aPage = array(), $bCreate = true)
  850. {
  851. return $this->getSettingsLayout($aPage, $bCreate, true);
  852. }
  853. protected function getSettingsVisibility($aPage = array(), $bCreate = true, $bInputsOnly = false)
  854. {
  855. $iVisibleForLevels = isset($aPage['visible_for_levels']) ? (int)$aPage['visible_for_levels'] : BX_DOL_INT_MAX;
  856. if(isset($aPage['visible_for_levels_editable']) && (int)$aPage['visible_for_levels_editable'] == 0)
  857. $aInputs = array(
  858. 'visible_for_levels' => array(
  859. 'type' => 'custom',
  860. 'name' => 'visible_for_levels',
  861. 'content' => MsgBox(_t('_adm_bp_err_page_visible_for_levels'))
  862. )
  863. );
  864. else
  865. $aInputs = array(
  866. 'visible_for' => array(
  867. 'type' => 'select',
  868. 'name' => 'visible_for',
  869. 'caption' => _t('_adm_bp_txt_block_visible_for'),
  870. 'info' => '',
  871. 'value' => $iVisibleForLevels == BX_DOL_INT_MAX ? BX_DOL_STUDIO_VISIBLE_ALL : BX_DOL_STUDIO_VISIBLE_SELECTED,
  872. 'values' => array(
  873. array('key' => BX_DOL_STUDIO_VISIBLE_ALL, 'value' => _t('_adm_bp_txt_block_visible_for_all')),
  874. array('key' => BX_DOL_STUDIO_VISIBLE_SELECTED, 'value' => _t('_adm_bp_txt_block_visible_for_selected')),
  875. ),
  876. 'required' => '0',
  877. 'attrs' => array(
  878. 'onchange' => $this->getPageJsObject() . '.onChangeVisibleFor(this)'
  879. ),
  880. 'db' => array (
  881. 'pass' => 'Xss',
  882. )
  883. ),
  884. 'visible_for_levels' => array(
  885. 'type' => 'checkbox_set',
  886. 'name' => 'visible_for_levels',
  887. 'caption' => _t('_adm_bp_txt_page_visible_for_levels'),
  888. 'info' => _t('_adm_bp_dsc_page_visible_for_levels'),
  889. 'value' => '',
  890. 'values' => array(),
  891. 'tr_attrs' => array(
  892. 'style' => $iVisibleForLevels == BX_DOL_INT_MAX ? 'display:none' : ''
  893. ),
  894. 'db' => array (
  895. 'pass' => 'Int',
  896. )
  897. )
  898. );
  899. $aForm = array(
  900. 'form_attrs' => array(
  901. 'id' => 'adm-bp-settings-visibility',
  902. ),
  903. 'params' => array (
  904. 'remove_form' => '1',
  905. 'csrf' => array(
  906. 'disable' => true
  907. )
  908. ),
  909. 'inputs' => $aInputs
  910. );
  911. BxDolStudioUtils::getVisibilityValues($iVisibleForLevels, $aForm['inputs']['visible_for_levels']['values'], $aForm['inputs']['visible_for_levels']['value']);
  912. if($bInputsOnly)
  913. return $aForm['inputs'];
  914. $oForm = new BxTemplStudioFormView($aForm);
  915. return $oForm->getCode();
  916. }
  917. protected function getSettingsVisibilityFields($aPage = array(), $bCreate = true)
  918. {
  919. return $this->getSettingsVisibility($aPage = array(), $bCreate, true);
  920. }
  921. protected function getSettingsCache($aPage = array(), $bCreate = true, $bInputsOnly = false)
  922. {
  923. $aForm = array(
  924. 'form_attrs' => array(
  925. 'id' => 'adm-bp-settings-cache',
  926. ),
  927. 'params' => array (
  928. 'remove_form' => '1',
  929. 'csrf' => array(
  930. 'disable' => true
  931. )
  932. ),
  933. 'inputs' => array (
  934. 'cache_lifetime' => array(
  935. 'type' => 'text',
  936. 'name' => 'cache_lifetime',
  937. 'caption' => _t('_adm_bp_txt_page_cache_lifetime'),
  938. 'info' => _t('_adm_bp_dsc_page_cache_lifetime'),
  939. 'value' => isset($aPage['cache_lifetime']) ? $aPage['cache_lifetime'] : 0,
  940. 'required' => '',
  941. 'attrs' => array(
  942. 'disabled' => isset($aPage['cache_editable']) && (int)$aPage['cache_editable'] == 0 ? 'disabled' : ''
  943. ),
  944. 'db' => array (
  945. 'pass' => 'Int',
  946. )
  947. ),
  948. )
  949. );
  950. if($bInputsOnly)
  951. return $aForm['inputs'];
  952. $oForm = new BxTemplStudioFormView($aForm);
  953. return $oForm->getCode();
  954. }
  955. protected function getSettingsCacheFields($aPage = array(), $bCreate = true)
  956. {
  957. return $this->getSettingsCache($aPage, $bCreate, true);
  958. }
  959. protected function getSettingsSeo($aPage = array(), $bCreate = true, $bInputsOnly = false)
  960. {
  961. $aForm = array(
  962. 'form_attrs' => array(
  963. 'id' => 'adm-bp-settings-seo',
  964. ),
  965. 'params' => array (
  966. 'remove_form' => '1',
  967. 'csrf' => array(
  968. 'disable' => true
  969. )
  970. ),
  971. 'inputs' => array (
  972. 'meta_description' => array(
  973. 'type' => 'textarea',
  974. 'name' => 'meta_description',
  975. 'caption' => _t('_adm_bp_txt_page_meta_description'),
  976. 'info' => _t('_adm_bp_dsc_page_meta_description'),
  977. 'value' => isset($aPage['meta_description']) ? $aPage['meta_description'] : '',
  978. 'db' => array (
  979. 'pass' => 'Xss',
  980. ),
  981. ),
  982. 'meta_keywords' => array(
  983. 'type' => 'textarea',
  984. 'name' => 'meta_keywords',
  985. 'caption' => _t('_adm_bp_txt_page_meta_keywords'),
  986. 'info' => _t('_adm_bp_dsc_page_meta_keywords'),
  987. 'value' => isset($aPage['meta_keywords']) ? $aPage['meta_keywords'] : '',
  988. 'db' => array (
  989. 'pass' => 'Xss',
  990. ),
  991. ),
  992. 'meta_robots' => array(
  993. 'type' => 'text',
  994. 'name' => 'meta_robots',
  995. 'caption' => _t('_adm_bp_txt_page_meta_robots'),
  996. 'info' => _t('_adm_bp_dsc_page_meta_robots'),
  997. 'value' => isset($aPage['meta_robots']) ? $aPage['meta_robots'] : '',
  998. 'required' => '0',
  999. 'db' => array (
  1000. 'pass' => 'Xss',
  1001. )
  1002. )
  1003. )
  1004. );
  1005. if($bInputsOnly)
  1006. return $aForm['inputs'];
  1007. $oForm = new BxTemplStudioFormView($aForm);
  1008. return $oForm->getCode();
  1009. }
  1010. protected function getSettingsSeoFields($aPage = array(), $bCreate = true)
  1011. {
  1012. return $this->getSettingsSeo($aPage, $bCreate, true);
  1013. }
  1014. protected function getBlockIcon($aBlock)
  1015. {
  1016. $sIcon = $sIconUrl = "";
  1017. $sResult = '';
  1018. switch($aBlock['type']) {
  1019. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1020. $sResult = 'file-text-o';
  1021. break;
  1022. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1023. $sResult = 'code';
  1024. break;
  1025. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1026. $sResult = 'rss';
  1027. break;
  1028. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1029. $sResult = 'picture-o';
  1030. break;
  1031. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1032. $sResult = 'globe';
  1033. break;
  1034. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1035. $sResult = 'list-alt';
  1036. break;
  1037. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1038. $sResult = $this->getModuleIcon($aBlock['module'], 'page');
  1039. break;
  1040. }
  1041. if(strpos($sResult, '.') === false)
  1042. $sIcon = $sResult;
  1043. else
  1044. $sIconUrl = $sResult;
  1045. return array($sIcon, $sIconUrl);
  1046. }
  1047. protected function getBlockModule($aBlock)
  1048. {
  1049. return $aBlock['module'] != BX_DOL_STUDIO_BP_SKELETONS ? $aBlock['module'] : BX_DOL_STUDIO_MODULE_CUSTOM;
  1050. }
  1051. protected function getBlockContent($aBlock)
  1052. {
  1053. $aFields = array();
  1054. switch($aBlock['type']) {
  1055. case BX_DOL_STUDIO_BP_BLOCK_RAW:
  1056. $aFields = array(
  1057. 'content' => array(
  1058. 'type' => 'textarea',
  1059. 'name' => 'content',
  1060. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1061. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1062. 'value' => $aBlock['content'],
  1063. 'required' => '0',
  1064. 'db' => array (
  1065. 'pass' => 'Xss',
  1066. ),
  1067. ),
  1068. );
  1069. break;
  1070. case BX_DOL_STUDIO_BP_BLOCK_HTML:
  1071. $aFields = array(
  1072. 'content' => array(
  1073. 'type' => 'textarea',
  1074. 'name' => 'content',
  1075. 'caption' => _t('_adm_bp_txt_block_content_raw'),
  1076. 'info' => _t('_adm_bp_dsc_block_content_raw'),
  1077. 'value' => $aBlock['content'],
  1078. 'required' => '0',
  1079. 'html' => 1,
  1080. 'db' => array (
  1081. 'pass' => 'XssHtml',
  1082. ),
  1083. ),
  1084. );
  1085. break;
  1086. case BX_DOL_STUDIO_BP_BLOCK_LANG:
  1087. $aFields = array(
  1088. 'content' => array(
  1089. 'type' => 'textarea',
  1090. 'name' => 'content',
  1091. 'caption' => _t('_adm_bp_txt_block_content_lang'),
  1092. 'info' => _t('_adm_bp_dsc_block_content_lang'),
  1093. 'value' => $aBlock['content'] != '' ? _t($aBlock['content']) : '',
  1094. 'required' => '0',
  1095. 'html' => 3,
  1096. 'db' => array (
  1097. 'pass' => 'XssHtml',
  1098. ),
  1099. ),
  1100. );
  1101. break;
  1102. case BX_DOL_STUDIO_BP_BLOCK_IMAGE:
  1103. $iImageId = $sImageAlign = '';
  1104. if($aBlock['content'] != '')
  1105. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1106. $aFields = array(
  1107. 'content' => array(
  1108. 'type' => 'hidden',
  1109. 'name' => 'content',
  1110. 'value' => '',
  1111. 'db' => array (
  1112. 'pass' => 'Xss',
  1113. ),
  1114. ),
  1115. 'image_file' => array(
  1116. 'type' => 'image_uploader',
  1117. 'name' => 'image_file',
  1118. 'caption' => _t('_adm_bp_txt_block_content_image_file'),
  1119. 'caption_preview' => _t('_adm_bp_txt_block_content_image_preview'),
  1120. 'info' => _t('_adm_bp_dsc_block_content_image_file'),
  1121. 'ajax_action_delete' => $this->getPageJsObject() . '.deleteBlockImage(' . $aBlock['id'] . ')',
  1122. 'value' => (int)$iImageId
  1123. ),
  1124. 'image_align' => array(
  1125. 'type' => 'select',
  1126. 'name' => 'image_align',
  1127. 'caption' => _t('_adm_bp_txt_block_content_image_align'),
  1128. 'info' => '',
  1129. 'value' => $sImageAlign,
  1130. 'values' => array(
  1131. array('key' => '', 'value' => _t('_adm_bp_txt_block_content_image_align_empty')),
  1132. array('key' => 'left', 'value' => _t('_adm_bp_txt_block_content_image_align_left')),
  1133. array('key' => 'center', 'value' => _t('_adm_bp_txt_block_content_image_align_center')),
  1134. array('key' => 'right', 'value' => _t('_adm_bp_txt_block_content_image_align_right')),
  1135. ),
  1136. 'required' => '0',
  1137. 'db' => array (
  1138. 'pass' => 'Xss',
  1139. ),
  1140. ),
  1141. );
  1142. break;
  1143. case BX_DOL_STUDIO_BP_BLOCK_RSS:
  1144. $sRssUrl = $sRssLength = '';
  1145. if($aBlock['content'] != '')
  1146. list($sRssUrl, $sRssLength) = explode($this->sParamsDivider, $aBlock['content']);
  1147. $aFields = array(
  1148. 'content' => array(
  1149. 'type' => 'hidden',
  1150. 'name' => 'content',
  1151. 'value' => '',
  1152. 'db' => array (
  1153. 'pass' => 'Xss',
  1154. ),
  1155. ),
  1156. 'rss_url' => array(
  1157. 'type' => 'text',
  1158. 'name' => 'rss_url',
  1159. 'caption' => _t('_adm_bp_txt_block_content_rss_url'),
  1160. 'info' => _t('_adm_bp_dsc_block_content_rss_url'),
  1161. 'value' => $sRssUrl,
  1162. 'required' => '0',
  1163. 'db' => array (
  1164. 'pass' => 'Xss',
  1165. ),
  1166. ),
  1167. 'rss_length' => array(
  1168. 'type' => 'text',
  1169. 'name' => 'rss_length',
  1170. 'caption' => _t('_adm_bp_txt_block_content_rss_length'),
  1171. 'info' => _t('_adm_bp_dsc_block_content_rss_length'),
  1172. 'value' => $sRssLength,
  1173. 'required' => '0',
  1174. 'db' => array (
  1175. 'pass' => 'Int',
  1176. ),
  1177. ),
  1178. );
  1179. break;
  1180. case BX_DOL_STUDIO_BP_BLOCK_MENU:
  1181. $aFields = array(
  1182. 'content' => array(
  1183. 'type' => 'select',
  1184. 'name' => 'content',
  1185. 'caption' => _t('_adm_bp_txt_block_content_menu'),
  1186. 'info' => '',
  1187. 'value' => $aBlock['content'],
  1188. 'values' => array(),
  1189. 'required' => '0',
  1190. 'db' => array (
  1191. 'pass' => 'Xss',
  1192. ),
  1193. )
  1194. );
  1195. $aMenus = $this->oDb->getMenus();
  1196. foreach($aMenus as $sKey => $sValue)
  1197. $aFields['content']['values'][$sKey] = _t($sValue);
  1198. asort($aFields['content']['values']);
  1199. $aFields['content']['values'] = array_merge(array('' => _t('_adm_bp_txt_block_content_menu_empty')), $aFields['content']['values']);
  1200. break;
  1201. case BX_DOL_STUDIO_BP_BLOCK_SERVICE:
  1202. $aService = array('module' => '', 'method' => '');
  1203. if($aBlock['content'] != '')
  1204. $aService = unserialize($aBlock['content']);
  1205. $aFields = array(
  1206. 'service_module' => array(
  1207. 'type' => 'value',
  1208. 'name' => 'service_module',
  1209. 'caption' => _t('_adm_bp_txt_block_content_service_module'),
  1210. 'value' => $this->getModuleTitle($aService['module'])
  1211. ),
  1212. 'service_method' => array(
  1213. 'type' => 'value',
  1214. 'name' => 'service_method',
  1215. 'caption' => _t('_adm_bp_txt_block_content_service_method'),
  1216. 'value' => $aService['method']
  1217. )
  1218. );
  1219. break;
  1220. }
  1221. return $aFields;
  1222. }
  1223. protected function getBlockList($sModule)
  1224. {
  1225. if(empty($sModule))
  1226. return '';
  1227. $sJsObject = $this->getPageJsObject();
  1228. $oTemplate = BxDolStudioTemplate::getInstance();
  1229. $oForm = new BxTemplStudioFormView(array());
  1230. $aInputCheckbox = array(
  1231. 'type' => 'checkbox',
  1232. 'name' => 'blocks[]',
  1233. 'attrs' => array(
  1234. 'onChange' => 'javascript:' . $sJsObject . '.onSelectBlock(this);'
  1235. ),
  1236. 'value' => ''
  1237. );
  1238. $aTmplParams = array(
  1239. 'html_block_list_id' => $this->aHtmlIds['block_list_id'] . $sModule,
  1240. 'bx_repeat:blocks' => array()
  1241. );
  1242. $aBlocks = $this->getBlocks($sModule);
  1243. foreach($aBlocks as $aBlock) {
  1244. list($sIcon, $sIconUrl) = $this->getBlockIcon($aBlock);
  1245. $aInputCheckbox['value'] = $aBlock['id'];
  1246. $aTmplParams['bx_repeat:blocks'][] = array(
  1247. 'js_object' => $sJsObject,
  1248. 'html_id' => $this->aHtmlIds['block_id'] . $aBlock['id'],
  1249. 'bx_if:is_inactive' => array(
  1250. 'condition' => false,
  1251. 'content' => array()
  1252. ),
  1253. 'bx_if:show_link' => array(
  1254. 'condition' => false,
  1255. 'content' => array()
  1256. ),
  1257. 'bx_if:show_text' => array(
  1258. 'condition' => true,
  1259. 'content' => array(
  1260. 'title' => _t(!empty($aBlock['title_system']) ? $aBlock['title_system'] : $aBlock['title']),
  1261. )
  1262. ),
  1263. 'bx_if:image' => array (
  1264. 'condition' => (bool)$sIconUrl,
  1265. 'content' => array('icon_url' => $sIconUrl),
  1266. ),
  1267. 'bx_if:icon' => array (
  1268. 'condition' => (bool)$sIcon,
  1269. 'content' => array('icon' => $sIcon),
  1270. ),
  1271. 'module' => $this->getModuleTitle($aBlock['module']),
  1272. 'visible_for' => _t('_adm_bp_txt_visible_for', BxDolStudioUtils::getVisibilityTitle($aBlock['visible_for_levels'])),
  1273. 'bx_if:show_checkbox' => array(
  1274. 'condition' => true,
  1275. 'content' => array(
  1276. 'content' => $oForm->genRow($aInputCheckbox)
  1277. )
  1278. ),
  1279. 'bx_if:show_drag_handle' => array(
  1280. 'condition' => false,
  1281. 'content' => array()
  1282. )
  1283. );
  1284. }
  1285. return $oTemplate->parseHtmlByName('bp_blocks_list.html', $aTmplParams);
  1286. }
  1287. protected function onBlockDelete($aBlock)
  1288. {
  1289. if($aBlock['module'] != BX_DOL_STUDIO_MODULE_CUSTOM)
  1290. return;
  1291. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['title']);
  1292. //--- Process Lang block
  1293. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_LANG && $aBlock['content'] != '')
  1294. BxDolStudioLanguagesUtils::getInstance()->deleteLanguageString($aBlock['content']);
  1295. //--- Process Image block
  1296. if($aBlock['type'] == BX_DOL_STUDIO_BP_BLOCK_IMAGE && $aBlock['content'] != '') {
  1297. $iImageId = $sImageAlign = '';
  1298. list($iImageId, $sImageAlign) = explode($this->sParamsDivider, $aBlock['content']);
  1299. if(is_numeric($iImageId) && (int)$iImageId != 0)
  1300. BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->deleteFile((int)$iImageId, 0);
  1301. }
  1302. }
  1303. protected function getBlocks($sModule)
  1304. {
  1305. $aBlocks = array();
  1306. $this->oDb->getBlocks(array('type' => 'by_module_to_copy', 'value' => $sModule), $aBlocks, false);
  1307. return $aBlocks;
  1308. }
  1309. protected function _getTmplVarsBlockPanelTop()
  1310. {
  1311. $sJsObject = $this->getPageJsObject();
  1312. $oForm = new BxTemplStudioFormView(array());
  1313. $aInputPages = array(
  1314. 'type' => 'select',
  1315. 'name' => 'page',
  1316. 'attrs' => array(
  1317. 'onChange' => 'javascript:' . $this->getPageJsObject() . '.onChangePage(this)'
  1318. ),
  1319. 'value' => $this->sPage,
  1320. 'values' => array(
  1321. array('key' => '', 'value' => _t('_adm_bp_txt_select_page'))
  1322. )
  1323. );
  1324. $aPages = $aCounter = array();
  1325. $this->oDb->getPages(array('type' => 'by_module', 'value' => $this->sType), $aPages, false);
  1326. $this->oDb->getBlocks(array('type' => 'counter_by_pages'), $aCounter, false);
  1327. foreach($aPages as $aPage)
  1328. $aInputPages['values'][] = array('key' => $aPage['object'], 'value' => _t($aPage['title_system']) . " (" . (isset($aCounter[$aPage['object']]) ? $aCounter[$aPage['object']] : "0") . ")");
  1329. $aTmplVarsActions = array();
  1330. if(($this->sPage != '' && !empty($this->aPageRebuild)) !== false)
  1331. $aTmplVarsActions = $this->_getTmplVarsBlockPanelTopActions();
  1332. return array(
  1333. 'js_object' => $this->getPageJsObject(),
  1334. 'selector' => $oForm->genRow($aInputPages),
  1335. 'action_page_create' => $this->sActionPageCreate,
  1336. 'bx_if:show_actions' => array(
  1337. 'condition' => $this->sPage != '',
  1338. 'content' => $aTmplVarsActions
  1339. )
  1340. );
  1341. }
  1342. protected function _getTmplVarsBlockPanelTopActions()
  1343. {
  1344. $sJsObject = $this->getPageJsObject();
  1345. $oPermalinks = BxDolPermalinks::getInstance();
  1346. return array(
  1347. 'js_object' => $sJsObject,
  1348. 'url_view' => BX_DOL_URL_ROOT . $oPermalinks->permalink($this->aPageRebuild['url']),
  1349. 'action_page_edit' => $this->sActionPageEdit,
  1350. 'bx_if:can_delete' => array(
  1351. 'condition' => (int)$this->aPageRebuild['deletable'] == 1,
  1352. 'content' => array(
  1353. 'js_object' => $sJsObject
  1354. )
  1355. ),
  1356. 'action_block_create' => $this->sActionBlockCreate,
  1357. );
  1358. }
  1359. protected function _getTmplVarsPageSettings($aPage = array(), $bCreate = true)
  1360. {
  1361. $sJsObject = $this->getPageJsObject();
  1362. $aTmplParams = array(
  1363. 'menu' => array(),
  1364. 'html_settings_groups_id' => $this->aHtmlIds['settings_groups_id'],
  1365. 'bx_repeat:settings_groups' => array(),
  1366. 'submit' => _t($bCreate ? '_adm_bp_btn_page_create' : '_adm_bp_btn_page_apply')
  1367. );
  1368. foreach($this->aPageSettings as $aSetting) {
  1369. //--- get menu items
  1370. $aTmplParams['menu'][$aSetting['name']] = array(
  1371. 'name' => $aSetting['name'],
  1372. 'icon' => '',
  1373. 'onclick' => $sJsObject . '.onChangeSettingGroup(\'' . $aSetting['name'] . '\', this);',
  1374. 'title' => $aSetting['title'],
  1375. 'selected' => isset($aSetting['active']) && (int)$aSetting['active'] == 1
  1376. );
  1377. //--- get settings
  1378. $aTmplParams['bx_repeat:settings_groups'][] = array(
  1379. 'html_settings_group_id' => $this->aHtmlIds['settings_group_id'] . $aSetting['name'],
  1380. 'bx_if:hidden' => array(
  1381. 'condition' => $aSetting['active'] != 1,
  1382. 'content' => array()
  1383. ),
  1384. 'content' => $this->{'getSettings' . $this->getClassName($aSetting['name'])}($aPage, $bCreate)
  1385. );
  1386. }
  1387. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_side.html', 'menu_items' => $aTmplParams['menu']));
  1388. $aTmplParams['menu'] = $oMenu->getCode();
  1389. return $aTmplParams;
  1390. }
  1391. }
  1392. /** @} */