BxBaseStudioBuilderPage.php 76 KB

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