BxBaseStudioBuilderPage.php 77 KB

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