BxBaseStudioBuilderPage.php 64 KB

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