FreshRSS.php 3.1 KB

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