FreshRSS.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. class FreshRSS extends Minz_FrontController {
  3. public function init() {
  4. if (!isset($_SESSION)) {
  5. Minz_Session::init('FreshRSS');
  6. }
  7. // Load list of extensions and enable the "system" ones.
  8. Minz_ExtensionManager::init();
  9. // Need to be called just after session init because it initializes
  10. // current user.
  11. FreshRSS_Auth::init();
  12. if (Minz_Request::isPost() && !is_referer_from_same_domain()) {
  13. // Basic protection against XSRF attacks
  14. FreshRSS_Auth::removeAccess();
  15. $http_referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
  16. Minz_Error::error(
  17. 403,
  18. array('error' => array(
  19. _t('access_denied'),
  20. ' [HTTP_REFERER=' . htmlspecialchars($http_referer) . ']'
  21. ))
  22. );
  23. }
  24. // Load context and configuration.
  25. FreshRSS_Context::init();
  26. // Init i18n.
  27. Minz_Session::_param('language', FreshRSS_Context::$conf->language);
  28. Minz_Translate::init();
  29. $this->loadStylesAndScripts();
  30. $this->loadNotifications();
  31. // Enable extensions for the current (logged) user.
  32. if (FreshRSS_Auth::hasAccess()) {
  33. $ext_list = FreshRSS_Context::$conf->extensions_enabled;
  34. Minz_ExtensionManager::enable_by_list($ext_list);
  35. }
  36. }
  37. private function loadStylesAndScripts() {
  38. $theme = FreshRSS_Themes::load(FreshRSS_Context::$conf->theme);
  39. if ($theme) {
  40. foreach($theme['files'] as $file) {
  41. if ($file[0] === '_') {
  42. $theme_id = 'base-theme';
  43. $filename = substr($file, 1);
  44. } else {
  45. $theme_id = $theme['id'];
  46. $filename = $file;
  47. }
  48. $filetime = @filemtime(PUBLIC_PATH . '/themes/' . $theme_id . '/' . $filename);
  49. Minz_View::appendStyle(Minz_Url::display(
  50. '/themes/' . $theme_id . '/' . $filename . '?' . $filetime
  51. ));
  52. }
  53. }
  54. Minz_View::appendScript(Minz_Url::display('/scripts/jquery.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.min.js')));
  55. Minz_View::appendScript(Minz_Url::display('/scripts/shortcut.js?' . @filemtime(PUBLIC_PATH . '/scripts/shortcut.js')));
  56. Minz_View::appendScript(Minz_Url::display('/scripts/main.js?' . @filemtime(PUBLIC_PATH . '/scripts/main.js')));
  57. if (Minz_Configuration::authType() === 'persona') {
  58. // TODO move it in a plugin
  59. // Needed for login AND logout with Persona.
  60. Minz_View::appendScript('https://login.persona.org/include.js');
  61. $file_mtime = @filemtime(PUBLIC_PATH . '/scripts/persona.js');
  62. Minz_View::appendScript(Minz_Url::display('/scripts/persona.js?' . $file_mtime));
  63. }
  64. }
  65. private function loadNotifications() {
  66. $notif = Minz_Session::param('notification');
  67. if ($notif) {
  68. Minz_View::_param('notification', $notif);
  69. Minz_Session::_param('notification');
  70. }
  71. }
  72. }