FreshRSS.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. $this->initConfiguration();
  10. $this->initAuth();
  11. FreshRSS_Context::init();
  12. $this->initI18n();
  13. FreshRSS_Share::load(join_path(DATA_PATH, 'shares.php'));
  14. $this->loadStylesAndScripts();
  15. $this->loadNotifications();
  16. // Enable extensions for the current (logged) user.
  17. if (FreshRSS_Auth::hasAccess()) {
  18. $ext_list = FreshRSS_Context::$user_conf->extensions_enabled;
  19. Minz_ExtensionManager::enable_by_list($ext_list);
  20. }
  21. }
  22. private function initConfiguration() {
  23. $configuration_setter = new FreshRSS_ConfigurationSetter();
  24. $current_user = Minz_Session::param('currentUser', '_');
  25. Minz_Configuration::register('user',
  26. join_path(USERS_PATH, $current_user, 'config.php'),
  27. join_path(USERS_PATH, '_', 'config.default.php'),
  28. $configuration_setter);
  29. $system_conf = Minz_Configuration::get('system');
  30. $system_conf->_configurationSetter($configuration_setter);
  31. }
  32. private function initAuth() {
  33. FreshRSS_Auth::init();
  34. if (Minz_Request::isPost() && !is_referer_from_same_domain()) {
  35. // Basic protection against XSRF attacks
  36. FreshRSS_Auth::removeAccess();
  37. $http_referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
  38. Minz_Error::error(
  39. 403,
  40. array('error' => array(
  41. _t('access_denied'),
  42. ' [HTTP_REFERER=' . htmlspecialchars($http_referer) . ']'
  43. ))
  44. );
  45. }
  46. }
  47. private function initI18n() {
  48. Minz_Session::_param('language', FreshRSS_Context::$user_conf->language);
  49. Minz_Translate::init(FreshRSS_Context::$user_conf->language);
  50. }
  51. private function loadStylesAndScripts() {
  52. $theme = FreshRSS_Themes::load(FreshRSS_Context::$user_conf->theme);
  53. if ($theme) {
  54. foreach($theme['files'] as $file) {
  55. if ($file[0] === '_') {
  56. $theme_id = 'base-theme';
  57. $filename = substr($file, 1);
  58. } else {
  59. $theme_id = $theme['id'];
  60. $filename = $file;
  61. }
  62. $filetime = @filemtime(PUBLIC_PATH . '/themes/' . $theme_id . '/' . $filename);
  63. Minz_View::appendStyle(Minz_Url::display(
  64. '/themes/' . $theme_id . '/' . $filename . '?' . $filetime
  65. ));
  66. }
  67. }
  68. Minz_View::appendScript(Minz_Url::display('/scripts/jquery.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.min.js')));
  69. Minz_View::appendScript(Minz_Url::display('/scripts/shortcut.js?' . @filemtime(PUBLIC_PATH . '/scripts/shortcut.js')));
  70. Minz_View::appendScript(Minz_Url::display('/scripts/main.js?' . @filemtime(PUBLIC_PATH . '/scripts/main.js')));
  71. if (FreshRSS_Context::$system_conf->auth_type === 'persona') {
  72. // TODO move it in a plugin
  73. // Needed for login AND logout with Persona.
  74. Minz_View::appendScript('https://login.persona.org/include.js');
  75. $file_mtime = @filemtime(PUBLIC_PATH . '/scripts/persona.js');
  76. Minz_View::appendScript(Minz_Url::display('/scripts/persona.js?' . $file_mtime));
  77. }
  78. }
  79. private function loadNotifications() {
  80. $notif = Minz_Session::param('notification');
  81. if ($notif) {
  82. Minz_View::_param('notification', $notif);
  83. Minz_Session::_param('notification');
  84. }
  85. }
  86. }