FreshRSS.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. class FreshRSS extends Minz_FrontController {
  3. public function init() {
  4. if (!isset($_SESSION)) {
  5. Minz_Session::init('FreshRSS');
  6. }
  7. $this->accessControl(Minz_Session::param('currentUser', ''));
  8. $this->loadParamsView();
  9. $this->loadStylesAndScripts();
  10. $this->loadNotifications();
  11. }
  12. private function accessControl($currentUser) {
  13. if ($currentUser == '') {
  14. switch (Minz_Configuration::authType()) {
  15. case 'http_auth':
  16. $currentUser = httpAuthUser();
  17. $loginOk = $currentUser != '';
  18. break;
  19. case 'persona':
  20. $currentUser = Minz_Configuration::defaultUser(); //TODO: Make Persona compatible with multi-user
  21. $loginOk = Minz_Session::param('mail') != '';
  22. break;
  23. case 'none':
  24. $currentUser = Minz_Configuration::defaultUser();
  25. $loginOk = true;
  26. break;
  27. default:
  28. $currentUser = Minz_Configuration::defaultUser();
  29. $loginOk = false;
  30. break;
  31. }
  32. } else {
  33. $loginOk = true;
  34. }
  35. if (!ctype_alnum($currentUser)) {
  36. Minz_Session::_param('currentUser', '');
  37. die('Invalid username [' . $currentUser . ']!');
  38. }
  39. try {
  40. $this->conf = new FreshRSS_Configuration($currentUser);
  41. } catch (Minz_Exception $e) {
  42. Minz_Session::_param('currentUser', '');
  43. die('Invalid configuration for user [' . $currentUser . ']! ' . $e->getMessage()); //Permission denied or conf file does not exist
  44. }
  45. Minz_View::_param ('conf', $this->conf);
  46. Minz_Session::_param('currentUser', $currentUser);
  47. if ($loginOk) {
  48. switch (Minz_Configuration::authType()) {
  49. case 'http_auth':
  50. $loginOk = $currentUser === httpAuthUser();
  51. break;
  52. case 'persona':
  53. $loginOk = Minz_Session::param('mail') === $this->conf->mail_login;
  54. break;
  55. case 'none':
  56. $loginOk = true;
  57. break;
  58. default:
  59. $loginOk = false;
  60. break;
  61. }
  62. if ((!$loginOk) && (PHP_SAPI === 'cli') && (Minz_Request::actionName() === 'actualize')) { //Command line
  63. Minz_Configuration::_authType('none');
  64. $loginOk = true;
  65. }
  66. }
  67. Minz_View::_param ('loginOk', $loginOk);
  68. }
  69. private function loadParamsView () {
  70. Minz_Session::_param ('language', $this->conf->language);
  71. Minz_Translate::init();
  72. $output = Minz_Request::param ('output');
  73. if (!$output) {
  74. $output = $this->conf->view_mode;
  75. Minz_Request::_param ('output', $output);
  76. }
  77. }
  78. private function loadStylesAndScripts () {
  79. $theme = FreshRSS_Themes::get_infos($this->conf->theme);
  80. if ($theme) {
  81. foreach($theme['files'] as $file) {
  82. Minz_View::appendStyle (Minz_Url::display ('/themes/' . $theme['path'] . '/' . $file . '?' . @filemtime(PUBLIC_PATH . '/themes/' . $theme['path'] . '/' . $file)));
  83. }
  84. }
  85. if (Minz_Configuration::authType() === 'persona') {
  86. Minz_View::appendScript ('https://login.persona.org/include.js');
  87. }
  88. $includeLazyLoad = $this->conf->lazyload && ($this->conf->display_posts || Minz_Request::param ('output') === 'reader');
  89. Minz_View::appendScript (Minz_Url::display ('/scripts/jquery.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.min.js')), false, !$includeLazyLoad, !$includeLazyLoad);
  90. if ($includeLazyLoad) {
  91. Minz_View::appendScript (Minz_Url::display ('/scripts/jquery.lazyload.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.lazyload.min.js')));
  92. }
  93. Minz_View::appendScript (Minz_Url::display ('/scripts/main.js?' . @filemtime(PUBLIC_PATH . '/scripts/main.js')));
  94. }
  95. private function loadNotifications () {
  96. $notif = Minz_Session::param ('notification');
  97. if ($notif) {
  98. Minz_View::_param ('notification', $notif);
  99. Minz_Session::_param ('notification');
  100. }
  101. }
  102. }