BxBaseStudioBuilderPage.php 81 KB

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