Context.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * The context object handles the current configuration file and different
  4. * useful functions associated to the current view state.
  5. */
  6. class FreshRSS_Context {
  7. public static $conf = null;
  8. public static $total_unread = 0;
  9. public static $total_starred = array(
  10. 'all' => 0,
  11. 'read' => 0,
  12. 'unread' => 0,
  13. );
  14. public static $state = 0;
  15. public static $current_get = array(
  16. 'all' => false,
  17. 'starred' => false,
  18. 'feed' => false,
  19. 'category' => false,
  20. );
  21. public static $order = 'DESC';
  22. public static function init() {
  23. // Init configuration.
  24. $current_user = Minz_Session::param('currentUser');
  25. try {
  26. self::$conf = new FreshRSS_Configuration($current_user);
  27. } catch(Minz_Exception $e) {
  28. Minz_Log::error('Cannot load configuration file of user `' . $current_user . '`');
  29. die($e->getMessage());
  30. }
  31. // Init i18n.
  32. Minz_Session::_param('language', self::$conf->language);
  33. Minz_Translate::init();
  34. // Get the current state.
  35. // self::$state = self::$conf->default_view;
  36. }
  37. public static function isStateEnabled($state) {
  38. return self::$state & $state;
  39. }
  40. public static function getRevertState($state) {
  41. if (self::$state & $state) {
  42. return self::$state & ~$state;
  43. } else {
  44. return self::$state | $state;
  45. }
  46. }
  47. public static function currentGet() {
  48. if (self::$current_get['all']) {
  49. return 'a';
  50. } elseif (self::$current_get['starred']) {
  51. return 's';
  52. } elseif (self::$current_get['feed']) {
  53. return 'f_' . self::$current_get['feed'];
  54. } elseif (self::$current_get['category']) {
  55. return 'c_' . self::$current_get['category'];
  56. }
  57. }
  58. public static function isCurrentGet($get) {
  59. $type = $get[0];
  60. $id = substr($get, 2);
  61. switch($type) {
  62. case 'a':
  63. return self::$current_get['all'];
  64. case 's':
  65. return self::$current_get['starred'];
  66. case 'f':
  67. return self::$current_get['feed'] === $id;
  68. case 'c':
  69. return self::$current_get['category'] === $id;
  70. default:
  71. return false;
  72. }
  73. }
  74. public static function nextStep() {
  75. // TODO: fix this method.
  76. return array(
  77. 'get' => 'a',
  78. 'idMax' => (time() - 1) . '000000'
  79. );
  80. }
  81. }