BxBaseStudioBuilderPage.php 62 KB

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