You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.9 KiB

  1. <?php
  2. class BaseController {
  3. public $name = 'main'; // The name of the current page
  4. protected $session_only = false;// The page is protected by a session ?
  5. protected $raw = false; // Display only the content ?
  6. protected $page;
  7. function __construct() {
  8. $this->load_language();
  9. $this->page = new TplPageBuilder();
  10. $this->page->addScript('movim_hash.js');
  11. $this->page->addScript('movim_utils.js');
  12. $this->page->addScript('movim_base.js');
  13. $this->page->addScript('movim_tpl.js');
  14. //$this->page->addScript('movim_session.js');
  15. $this->page->addScript('movim_rpc.js');
  16. }
  17. /**
  18. * Loads up the language, either from the User or default.
  19. */
  20. function load_language() {
  21. $user = new User();
  22. if($user->isLogged()) {
  23. try{
  24. $lang = $user->getConfig('language');
  25. load_language($lang);
  26. }
  27. catch(MovimException $e) {
  28. // Load default language.
  29. load_language(\system\Conf::getServerConfElement('defLang'));
  30. }
  31. }
  32. else if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  33. load_language_auto();
  34. }
  35. else {
  36. load_language(\system\Conf::getServerConfElement('defLang'));
  37. }
  38. }
  39. /**
  40. * Returns the value of a $_GET variable. Mainly used to avoid getting
  41. * notices from PHP when attempting to fetch an empty variable.
  42. * @param name is the desired variable's name.
  43. * @return the value of the requested variable, or FALSE.
  44. */
  45. protected function fetch_get($name)
  46. {
  47. if(isset($_GET[$name])) {
  48. return htmlentities($_GET[$name]);
  49. } else {
  50. return false;
  51. }
  52. }
  53. /**
  54. * Returns the value of a $_POST variable. Mainly used to avoid getting
  55. * notices from PHP when attempting to fetch an empty variable.
  56. * @param name is the desired variable's name.
  57. * @return the value of the requested variable, or FALSE.
  58. */
  59. protected function fetch_post($name)
  60. {
  61. if(isset($_POST[$name])) {
  62. return htmlentities($_POST[$name]);
  63. } else {
  64. return false;
  65. }
  66. }
  67. function check_session() {
  68. if($this->session_only) {
  69. $user = new User();
  70. if(!$user->isLogged()) {
  71. $this->name = 'login';
  72. }
  73. }
  74. }
  75. function display() {
  76. if($this->session_only) {
  77. $user = new User();
  78. $content = new TplPageBuilder($user);
  79. } else {
  80. $content = new TplPageBuilder();
  81. }
  82. if($this->raw) {
  83. echo $content->build($this->name.'.tpl');
  84. exit;
  85. } else {
  86. $built = $content->build($this->name.'.tpl');
  87. $this->page->setContent($built);
  88. echo $this->page->build('page.tpl');
  89. }
  90. }
  91. }