BxBaseStudioBuilderPage.php 75 KB

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