FreshRSS.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. class FreshRSS extends Minz_FrontController {
  3. public function init() {
  4. if (!isset($_SESSION)) {
  5. Minz_Session::init('FreshRSS');
  6. }
  7. FreshRSS_Auth::init();
  8. $this->loadConfiguration();
  9. $this->loadParamsView();
  10. if (Minz_Request::isPost() && !is_referer_from_same_domain()) {
  11. //Basic protection against XSRF attacks
  12. FreshRSS_Auth::removeAccess();
  13. Minz_Error::error(
  14. 403,
  15. array('error' => array(_t('access_denied') . ' [HTTP_REFERER=' .
  16. htmlspecialchars(empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']) . ']'))
  17. );
  18. }
  19. $this->loadStylesAndScripts();
  20. $this->loadNotifications();
  21. $this->loadExtensions();
  22. }
  23. private function loadConfiguration() {
  24. $current_user = Minz_Session::param('currentUser');
  25. try {
  26. $this->conf = new FreshRSS_Configuration($current_user);
  27. Minz_View::_param('conf', $this->conf);
  28. } catch(Minz_Exception $e) {
  29. Minz_Log::error('Cannot load configuration file of user `' . $current_user . '`');
  30. die($e->getMessage());
  31. }
  32. }
  33. private function loadParamsView() {
  34. Minz_Session::_param('language', $this->conf->language);
  35. Minz_Translate::init();
  36. $output = Minz_Request::param('output', '');
  37. if (($output === '') || ($output !== 'normal' && $output !== 'rss' && $output !== 'reader' && $output !== 'global')) {
  38. $output = $this->conf->view_mode;
  39. Minz_Request::_param('output', $output);
  40. }
  41. }
  42. private function loadStylesAndScripts() {
  43. $theme = FreshRSS_Themes::load($this->conf->theme);
  44. if ($theme) {
  45. foreach($theme['files'] as $file) {
  46. if ($file[0] === '_') {
  47. $theme_id = 'base-theme';
  48. $filename = substr($file, 1);
  49. } else {
  50. $theme_id = $theme['id'];
  51. $filename = $file;
  52. }
  53. $filetime = @filemtime(PUBLIC_PATH . '/themes/' . $theme_id . '/' . $filename);
  54. Minz_View::appendStyle(Minz_Url::display(
  55. '/themes/' . $theme_id . '/' . $filename . '?' . $filetime
  56. ));
  57. }
  58. }
  59. Minz_View::appendScript(Minz_Url::display('/scripts/jquery.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.min.js')));
  60. Minz_View::appendScript(Minz_Url::display('/scripts/shortcut.js?' . @filemtime(PUBLIC_PATH . '/scripts/shortcut.js')));
  61. Minz_View::appendScript(Minz_Url::display('/scripts/main.js?' . @filemtime(PUBLIC_PATH . '/scripts/main.js')));
  62. if (Minz_Configuration::authType() === 'persona') {
  63. // TODO move it in a plugin
  64. // Needed for login AND logout with Persona.
  65. Minz_View::appendScript('https://login.persona.org/include.js');
  66. $file_mtime = @filemtime(PUBLIC_PATH . '/scripts/persona.js');
  67. Minz_View::appendScript(Minz_Url::display('/scripts/persona.js?' . $file_mtime));
  68. }
  69. }
  70. private function loadNotifications() {
  71. $notif = Minz_Session::param('notification');
  72. if ($notif) {
  73. Minz_View::_param('notification', $notif);
  74. Minz_Session::_param('notification');
  75. }
  76. }
  77. private function loadExtensions() {
  78. $extensionPath = FRESHRSS_PATH . '/extensions/';
  79. //TODO: Add a preference to load only user-selected extensions
  80. foreach (scandir($extensionPath) as $key => $extension) {
  81. if (ctype_alpha($extension)) {
  82. $mtime = @filemtime($extensionPath . $extension . '/style.css');
  83. if ($mtime !== false) {
  84. Minz_View::appendStyle(Minz_Url::display('/ext.php?c&amp;e=' . $extension . '&amp;' . $mtime));
  85. }
  86. $mtime = @filemtime($extensionPath . $extension . '/script.js');
  87. if ($mtime !== false) {
  88. Minz_View::appendScript(Minz_Url::display('/ext.php?j&amp;e=' . $extension . '&amp;' . $mtime));
  89. }
  90. if (file_exists($extensionPath . $extension . '/module.php')) {
  91. //TODO: include
  92. }
  93. }
  94. }
  95. }
  96. }