FreshRSS.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. class FreshRSS extends Minz_FrontController {
  3. public function init() {
  4. if (!isset($_SESSION)) {
  5. Minz_Session::init('FreshRSS');
  6. }
  7. // Need to be called just after session init because it initializes
  8. // current user.
  9. FreshRSS_Auth::init();
  10. if (Minz_Request::isPost() && !is_referer_from_same_domain()) {
  11. // Basic protection against XSRF attacks
  12. FreshRSS_Auth::removeAccess();
  13. $http_referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
  14. Minz_Error::error(
  15. 403,
  16. array('error' => array(
  17. _t('access_denied'),
  18. ' [HTTP_REFERER=' . htmlspecialchars($http_referer) . ']'
  19. ))
  20. );
  21. }
  22. // Load context and configuration.
  23. FreshRSS_Context::init();
  24. $this->loadParamsView();
  25. $this->loadStylesAndScripts();
  26. $this->loadNotifications();
  27. $this->loadExtensions();
  28. }
  29. private function loadParamsView() {
  30. // TODO: outputs should be different actions.
  31. $output = Minz_Request::param('output', '');
  32. if (($output === '') || ($output !== 'normal' && $output !== 'rss' && $output !== 'reader' && $output !== 'global')) {
  33. $output = FreshRSS_Context::$conf->view_mode;
  34. Minz_Request::_param('output', $output);
  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. private function loadExtensions() {
  73. $extensionPath = FRESHRSS_PATH . '/extensions/';
  74. //TODO: Add a preference to load only user-selected extensions
  75. foreach (scandir($extensionPath) as $key => $extension) {
  76. if (ctype_alpha($extension)) {
  77. $mtime = @filemtime($extensionPath . $extension . '/style.css');
  78. if ($mtime !== false) {
  79. Minz_View::appendStyle(Minz_Url::display('/ext.php?c&amp;e=' . $extension . '&amp;' . $mtime));
  80. }
  81. $mtime = @filemtime($extensionPath . $extension . '/script.js');
  82. if ($mtime !== false) {
  83. Minz_View::appendScript(Minz_Url::display('/ext.php?j&amp;e=' . $extension . '&amp;' . $mtime));
  84. }
  85. if (file_exists($extensionPath . $extension . '/module.php')) {
  86. //TODO: include
  87. }
  88. }
  89. }
  90. }
  91. }