FreshRSS.php 3.2 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. FreshRSS_Auth::init();
  8. $this->loadConfiguration();
  9. $this->loadParamsView();
  10. if (Minz_Request::isPost() && !is_referer_from_same_domain()) {
  11. //Basic protection against XSRF attacks
  12. FreshRSS_Auth::removeAccess();
  13. Minz_Error::error(
  14. 403,
  15. array('error' => array(_t('access_denied') . ' [HTTP_REFERER=' .
  16. htmlspecialchars(empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']) . ']'))
  17. );
  18. }
  19. $this->loadStylesAndScripts();
  20. $this->loadNotifications();
  21. $this->loadExtensions();
  22. }
  23. private function loadConfiguration() {
  24. $current_user = Minz_Session::param('currentUser');
  25. try {
  26. $this->conf = new FreshRSS_Configuration($current_user);
  27. Minz_View::_param('conf', $this->conf);
  28. } catch(Minz_Exception $e) {
  29. Minz_Log::error('Cannot load configuration file of user `' . $current_user . '`');
  30. die($e->getMessage());
  31. }
  32. }
  33. private function loadParamsView() {
  34. Minz_Session::_param('language', $this->conf->language);
  35. Minz_Translate::init();
  36. $output = Minz_Request::param('output', '');
  37. if (($output === '') || ($output !== 'normal' && $output !== 'rss' && $output !== 'reader' && $output !== 'global')) {
  38. $output = $this->conf->view_mode;
  39. Minz_Request::_param('output', $output);
  40. }
  41. }
  42. private function loadStylesAndScripts() {
  43. $theme = FreshRSS_Themes::load($this->conf->theme);
  44. if ($theme) {
  45. foreach($theme['files'] as $file) {
  46. if ($file[0] === '_') {
  47. $theme_id = 'base-theme';
  48. $filename = substr($file, 1);
  49. } else {
  50. $theme_id = $theme['id'];
  51. $filename = $file;
  52. }
  53. $filetime = @filemtime(PUBLIC_PATH . '/themes/' . $theme_id . '/' . $filename);
  54. Minz_View::appendStyle(Minz_Url::display(
  55. '/themes/' . $theme_id . '/' . $filename . '?' . $filetime
  56. ));
  57. }
  58. }
  59. Minz_View::appendScript(Minz_Url::display('/scripts/jquery.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/jquery.min.js')));
  60. Minz_View::appendScript(Minz_Url::display('/scripts/shortcut.js?' . @filemtime(PUBLIC_PATH . '/scripts/shortcut.js')));
  61. Minz_View::appendScript(Minz_Url::display('/scripts/main.js?' . @filemtime(PUBLIC_PATH . '/scripts/main.js')));
  62. }
  63. private function loadNotifications() {
  64. $notif = Minz_Session::param('notification');
  65. if ($notif) {
  66. Minz_View::_param('notification', $notif);
  67. Minz_Session::_param('notification');
  68. }
  69. }
  70. private function loadExtensions() {
  71. $extensionPath = FRESHRSS_PATH . '/extensions/';
  72. //TODO: Add a preference to load only user-selected extensions
  73. foreach (scandir($extensionPath) as $key => $extension) {
  74. if (ctype_alpha($extension)) {
  75. $mtime = @filemtime($extensionPath . $extension . '/style.css');
  76. if ($mtime !== false) {
  77. Minz_View::appendStyle(Minz_Url::display('/ext.php?c&amp;e=' . $extension . '&amp;' . $mtime));
  78. }
  79. $mtime = @filemtime($extensionPath . $extension . '/script.js');
  80. if ($mtime !== false) {
  81. Minz_View::appendScript(Minz_Url::display('/ext.php?j&amp;e=' . $extension . '&amp;' . $mtime));
  82. }
  83. if (file_exists($extensionPath . $extension . '/module.php')) {
  84. //TODO: include
  85. }
  86. }
  87. }
  88. }
  89. }