FreshRSS.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. $loginOk = false;
  21. $email = filter_var(Minz_Session::param('mail'), FILTER_VALIDATE_EMAIL);
  22. if ($email != '') { //TODO: Remove redundancy with indexController
  23. $personaFile = DATA_PATH . '/persona/' . $email . '.txt';
  24. if (($currentUser = @file_get_contents($personaFile)) !== false) {
  25. $currentUser = trim($currentUser);
  26. $loginOk = true;
  27. }
  28. }
  29. if (!$loginOk) {
  30. $currentUser = Minz_Configuration::defaultUser();
  31. }
  32. break;
  33. case 'none':
  34. $currentUser = Minz_Configuration::defaultUser();
  35. $loginOk = true;
  36. break;
  37. default:
  38. $currentUser = Minz_Configuration::defaultUser();
  39. $loginOk = false;
  40. break;
  41. }
  42. } else {
  43. $loginOk = true;
  44. }
  45. if (!ctype_alnum($currentUser)) {
  46. Minz_Session::_param('currentUser', '');
  47. die('Invalid username [' . $currentUser . ']!');
  48. }
  49. try {
  50. $this->conf = new FreshRSS_Configuration($currentUser);
  51. } catch (Minz_Exception $e) {
  52. Minz_Session::_param('currentUser', '');
  53. die('Invalid configuration for user [' . $currentUser . ']! ' . $e->getMessage()); //Permission denied or conf file does not exist
  54. }
  55. Minz_View::_param ('conf', $this->conf);
  56. Minz_Session::_param('currentUser', $currentUser);
  57. if ($loginOk) {
  58. switch (Minz_Configuration::authType()) {
  59. case 'http_auth':
  60. $loginOk = strcasecmp($currentUser, httpAuthUser()) === 0;
  61. break;
  62. case 'persona':
  63. $loginOk = strcasecmp(Minz_Session::param('mail'), $this->conf->mail_login) === 0;
  64. break;
  65. case 'none':
  66. $loginOk = true;
  67. break;
  68. default:
  69. $loginOk = false;
  70. break;
  71. }
  72. if ((!$loginOk) && (PHP_SAPI === 'cli') && (Minz_Request::actionName() === 'actualize')) { //Command line
  73. Minz_Configuration::_authType('none');
  74. $loginOk = true;
  75. }
  76. }
  77. Minz_View::_param ('loginOk', $loginOk);
  78. }
  79. private function loadParamsView () {
  80. Minz_Session::_param ('language', $this->conf->language);
  81. Minz_Translate::init();
  82. $output = Minz_Request::param ('output');
  83. if (!$output) {
  84. $output = $this->conf->view_mode;
  85. Minz_Request::_param ('output', $output);
  86. }
  87. }
  88. private function loadStylesAndScripts () {
  89. $theme = FreshRSS_Themes::get_infos($this->conf->theme);
  90. if ($theme) {
  91. foreach($theme['files'] as $file) {
  92. Minz_View::appendStyle (Minz_Url::display ('/themes/' . $theme['path'] . '/' . $file . '?' . @filemtime(PUBLIC_PATH . '/themes/' . $theme['path'] . '/' . $file)));
  93. }
  94. }
  95. if (Minz_Configuration::authType() === 'persona') {
  96. Minz_View::appendScript ('https://login.persona.org/include.js');
  97. }
  98. $includeLazyLoad = $this->conf->lazyload && ($this->conf->display_posts || Minz_Request::param ('output') === 'reader');
  99. Minz_View::appendScript (Minz_Url::display ('/scripts/jquery.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.min.js')), false, !$includeLazyLoad, !$includeLazyLoad);
  100. if ($includeLazyLoad) {
  101. Minz_View::appendScript (Minz_Url::display ('/scripts/jquery.lazyload.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.lazyload.min.js')));
  102. }
  103. Minz_View::appendScript (Minz_Url::display ('/scripts/main.js?' . @filemtime(PUBLIC_PATH . '/scripts/main.js')));
  104. }
  105. private function loadNotifications () {
  106. $notif = Minz_Session::param ('notification');
  107. if ($notif) {
  108. Minz_View::_param ('notification', $notif);
  109. Minz_Session::_param ('notification');
  110. }
  111. }
  112. }