BxBaseStudioBuilderPage.php 62 KB

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