welcome.class.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. /**
  11. * Loads the welcome page
  12. *
  13. * @package modx
  14. * @subpackage manager.controllers
  15. */
  16. class WelcomeManagerController extends modManagerController {
  17. /**
  18. * Whether or not to show the welcome screen
  19. * @var boolean $showWelcomeScreen
  20. */
  21. public $showWelcomeScreen = false;
  22. /**
  23. * The current, active dashboard for the user
  24. * @var null|modDashboard $dashboard
  25. */
  26. public $dashboard = null;
  27. /**
  28. * Check for any permissions or requirements to load page
  29. * @return bool
  30. */
  31. public function checkPermissions() {
  32. return $this->modx->hasPermission('home');
  33. }
  34. /**
  35. * Register custom CSS/JS for the page
  36. * @return void
  37. */
  38. public function loadCustomCssJs() {
  39. $this->addJavascript($this->modx->getOption('manager_url').'assets/modext/widgets/modx.panel.welcome.js');
  40. $this->addJavascript($this->modx->getOption('manager_url').'assets/modext/sections/welcome.js');
  41. $this->addHtml('<script type="text/javascript">
  42. Ext.onReady(function() {
  43. MODx.load({
  44. xtype: "modx-page-welcome"
  45. ,dashboard: '.$this->modx->toJSON($this->dashboard->toArray()).'
  46. });
  47. });
  48. </script>');
  49. if ($this->showWelcomeScreen) {
  50. $url = $this->modx->getOption('welcome_screen_url',null,'http://misc.modx.com/revolution/welcome.20.html');
  51. $this->addHtml('<script type="text/javascript">
  52. // <![CDATA[
  53. Ext.onReady(function() { MODx.loadWelcomePanel("'.$url.'"); });
  54. // ]]></script>');
  55. }
  56. }
  57. /**
  58. * Custom logic code here for setting placeholders, etc
  59. * @param array $scriptProperties
  60. * @return array
  61. */
  62. public function process(array $scriptProperties = array()) {
  63. $placeholders = array();
  64. $this->checkForWelcomeScreen();
  65. $this->dashboard = $this->modx->user->getDashboard();
  66. $placeholders['dashboard'] = $this->dashboard->render($this);
  67. return $placeholders;
  68. }
  69. /**
  70. * Check to show if we need to show the Welcome Screen for the user
  71. * @return void
  72. */
  73. public function checkForWelcomeScreen() {
  74. if ($this->modx->getOption('welcome_screen',null,false)) {
  75. $this->showWelcomeScreen = true;
  76. /** @var modSystemSetting $setting */
  77. $setting = $this->modx->getObject('modSystemSetting','welcome_screen');
  78. if ($setting) {
  79. $setting->set('value',false);
  80. $setting->save();
  81. }
  82. /** @var modUserSetting $setting */
  83. $setting = $this->modx->getObject('modUserSetting',array(
  84. 'key' => 'welcome_screen',
  85. 'user' => $this->modx->user->get('id'),
  86. ));
  87. if ($setting) {
  88. $setting->set('value',false);
  89. $setting->save();
  90. }
  91. $this->modx->reloadConfig();
  92. }
  93. }
  94. /**
  95. * Return the pagetitle
  96. *
  97. * @return string
  98. */
  99. public function getPageTitle() {
  100. return $this->modx->lexicon('dashboard');
  101. }
  102. /**
  103. * Return the location of the template file
  104. * @return string
  105. */
  106. public function getTemplateFile() {
  107. return 'welcome.tpl';
  108. }
  109. /**
  110. * Specify the language topics to load
  111. * @return array
  112. */
  113. public function getLanguageTopics() {
  114. return array('welcome','configcheck');
  115. }
  116. }