FreshRSS.php 2.9 KB

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