FreshRSS.php 3.2 KB

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