BxBaseStudioBuilderPage.php 62 KB

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