FreshRSS.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. // Enable extensions for the current user.
  27. $ext_list = FreshRSS_Context::$conf->extensions_enabled;
  28. Minz_ExtensionManager::enable_by_list($ext_list);
  29. // Init i18n.
  30. Minz_Session::_param('language', FreshRSS_Context::$conf->language);
  31. Minz_Translate::init();
  32. $this->loadStylesAndScripts();
  33. $this->loadNotifications();
  34. }
  35. private function loadStylesAndScripts() {
  36. $theme = FreshRSS_Themes::load(FreshRSS_Context::$conf->theme);
  37. if ($theme) {
  38. foreach($theme['files'] as $file) {
  39. if ($file[0] === '_') {
  40. $theme_id = 'base-theme';
  41. $filename = substr($file, 1);
  42. } else {
  43. $theme_id = $theme['id'];
  44. $filename = $file;
  45. }
  46. $filetime = @filemtime(PUBLIC_PATH . '/themes/' . $theme_id . '/' . $filename);
  47. Minz_View::appendStyle(Minz_Url::display(
  48. '/themes/' . $theme_id . '/' . $filename . '?' . $filetime
  49. ));
  50. }
  51. }
  52. Minz_View::appendScript(Minz_Url::display('/scripts/jquery.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.min.js')));
  53. Minz_View::appendScript(Minz_Url::display('/scripts/shortcut.js?' . @filemtime(PUBLIC_PATH . '/scripts/shortcut.js')));
  54. Minz_View::appendScript(Minz_Url::display('/scripts/main.js?' . @filemtime(PUBLIC_PATH . '/scripts/main.js')));
  55. if (Minz_Configuration::authType() === 'persona') {
  56. // TODO move it in a plugin
  57. // Needed for login AND logout with Persona.
  58. Minz_View::appendScript('https://login.persona.org/include.js');
  59. $file_mtime = @filemtime(PUBLIC_PATH . '/scripts/persona.js');
  60. Minz_View::appendScript(Minz_Url::display('/scripts/persona.js?' . $file_mtime));
  61. }
  62. }
  63. private function loadNotifications() {
  64. $notif = Minz_Session::param('notification');
  65. if ($notif) {
  66. Minz_View::_param('notification', $notif);
  67. Minz_Session::_param('notification');
  68. }
  69. }
  70. }