FreshRSS.php 3.0 KB

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