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. // 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. // TODO: remove $this->view->conf variable which is contained in context
  24. FreshRSS_Context::init();
  25. Minz_View::_param('conf', FreshRSS_Context::$conf);
  26. $this->loadParamsView();
  27. $this->loadStylesAndScripts();
  28. $this->loadNotifications();
  29. $this->loadExtensions();
  30. }
  31. private function loadParamsView() {
  32. // TODO: outputs should be different actions.
  33. $output = Minz_Request::param('output', '');
  34. if (($output === '') || ($output !== 'normal' && $output !== 'rss' && $output !== 'reader' && $output !== 'global')) {
  35. $output = FreshRSS_Context::$conf->view_mode;
  36. Minz_Request::_param('output', $output);
  37. }
  38. }
  39. private function loadStylesAndScripts() {
  40. $theme = FreshRSS_Themes::load(FreshRSS_Context::$conf->theme);
  41. if ($theme) {
  42. foreach($theme['files'] as $file) {
  43. if ($file[0] === '_') {
  44. $theme_id = 'base-theme';
  45. $filename = substr($file, 1);
  46. } else {
  47. $theme_id = $theme['id'];
  48. $filename = $file;
  49. }
  50. $filetime = @filemtime(PUBLIC_PATH . '/themes/' . $theme_id . '/' . $filename);
  51. Minz_View::appendStyle(Minz_Url::display(
  52. '/themes/' . $theme_id . '/' . $filename . '?' . $filetime
  53. ));
  54. }
  55. }
  56. Minz_View::appendScript(Minz_Url::display('/scripts/jquery.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.min.js')));
  57. Minz_View::appendScript(Minz_Url::display('/scripts/shortcut.js?' . @filemtime(PUBLIC_PATH . '/scripts/shortcut.js')));
  58. Minz_View::appendScript(Minz_Url::display('/scripts/main.js?' . @filemtime(PUBLIC_PATH . '/scripts/main.js')));
  59. if (Minz_Configuration::authType() === 'persona') {
  60. // TODO move it in a plugin
  61. // Needed for login AND logout with Persona.
  62. Minz_View::appendScript('https://login.persona.org/include.js');
  63. $file_mtime = @filemtime(PUBLIC_PATH . '/scripts/persona.js');
  64. Minz_View::appendScript(Minz_Url::display('/scripts/persona.js?' . $file_mtime));
  65. }
  66. }
  67. private function loadNotifications() {
  68. $notif = Minz_Session::param('notification');
  69. if ($notif) {
  70. Minz_View::_param('notification', $notif);
  71. Minz_Session::_param('notification');
  72. }
  73. }
  74. private function loadExtensions() {
  75. $extensionPath = FRESHRSS_PATH . '/extensions/';
  76. //TODO: Add a preference to load only user-selected extensions
  77. foreach (scandir($extensionPath) as $key => $extension) {
  78. if (ctype_alpha($extension)) {
  79. $mtime = @filemtime($extensionPath . $extension . '/style.css');
  80. if ($mtime !== false) {
  81. Minz_View::appendStyle(Minz_Url::display('/ext.php?c&amp;e=' . $extension . '&amp;' . $mtime));
  82. }
  83. $mtime = @filemtime($extensionPath . $extension . '/script.js');
  84. if ($mtime !== false) {
  85. Minz_View::appendScript(Minz_Url::display('/ext.php?j&amp;e=' . $extension . '&amp;' . $mtime));
  86. }
  87. if (file_exists($extensionPath . $extension . '/module.php')) {
  88. //TODO: include
  89. }
  90. }
  91. }
  92. }
  93. }