BxBaseStudioBuilderPage.php 77 KB

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