BxBaseStudioBuilderPage.php 76 KB

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