RSSConfiguration.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. class RSSConfiguration extends Model {
  3. private $posts_per_page;
  4. private $default_view;
  5. private $display_posts;
  6. private $sort_order;
  7. private $old_entries;
  8. private $shortcuts = array ();
  9. private $mail_login = '';
  10. public function __construct () {
  11. $confDAO = new RSSConfigurationDAO ();
  12. $this->_postsPerPage ($confDAO->posts_per_page);
  13. $this->_defaultView ($confDAO->default_view);
  14. $this->_displayPosts ($confDAO->display_posts);
  15. $this->_sortOrder ($confDAO->sort_order);
  16. $this->_oldEntries ($confDAO->old_entries);
  17. $this->_shortcuts ($confDAO->shortcuts);
  18. $this->_mailLogin ($confDAO->mail_login);
  19. }
  20. public function postsPerPage () {
  21. return $this->posts_per_page;
  22. }
  23. public function defaultView () {
  24. return $this->default_view;
  25. }
  26. public function displayPosts () {
  27. return $this->display_posts;
  28. }
  29. public function sortOrder () {
  30. return $this->sort_order;
  31. }
  32. public function oldEntries () {
  33. return $this->old_entries;
  34. }
  35. public function shortcuts () {
  36. return $this->shortcuts;
  37. }
  38. public function mailLogin () {
  39. return $this->mail_login;
  40. }
  41. public function _postsPerPage ($value) {
  42. if (is_int (intval ($value))) {
  43. $this->posts_per_page = $value;
  44. } else {
  45. $this->posts_per_page = 10;
  46. }
  47. }
  48. public function _defaultView ($value) {
  49. if ($value == 'not_read') {
  50. $this->default_view = 'not_read';
  51. } else {
  52. $this->default_view = 'all';
  53. }
  54. }
  55. public function _displayPosts ($value) {
  56. if ($value == 'yes') {
  57. $this->display_posts = 'yes';
  58. } else {
  59. $this->display_posts = 'no';
  60. }
  61. }
  62. public function _sortOrder ($value) {
  63. if ($value == 'high_to_low') {
  64. $this->sort_order = 'high_to_low';
  65. } else {
  66. $this->sort_order = 'low_to_high';
  67. }
  68. }
  69. public function _oldEntries ($value) {
  70. if (is_int (intval ($value))) {
  71. $this->old_entries = $value;
  72. } else {
  73. $this->old_entries = 3;
  74. }
  75. }
  76. public function _shortcuts ($values) {
  77. foreach ($values as $key => $value) {
  78. $this->shortcuts[$key] = $value;
  79. }
  80. }
  81. public function _mailLogin ($value) {
  82. if (filter_var ($value, FILTER_VALIDATE_EMAIL)) {
  83. $this->mail_login = $value;
  84. } elseif ($value == false) {
  85. $this->mail_login = false;
  86. }
  87. }
  88. }
  89. class RSSConfigurationDAO extends Model_array {
  90. public $posts_per_page = 10;
  91. public $default_view = 'all';
  92. public $display_posts = 'no';
  93. public $sort_order = 'low_to_high';
  94. public $old_entries = 3;
  95. public $shortcuts = array (
  96. 'mark_read' => 'r',
  97. 'mark_favorite' => 'f',
  98. 'go_website' => 'space',
  99. 'next_entry' => 'page_down',
  100. 'prev_entry' => 'page_up',
  101. 'next_page' => 'right',
  102. 'prev_page' => 'left',
  103. );
  104. public $mail_login = '';
  105. public function __construct () {
  106. parent::__construct (PUBLIC_PATH . '/data/Configuration.array.php');
  107. if (isset ($this->array['posts_per_page'])) {
  108. $this->posts_per_page = $this->array['posts_per_page'];
  109. }
  110. if (isset ($this->array['default_view'])) {
  111. $this->default_view = $this->array['default_view'];
  112. }
  113. if (isset ($this->array['display_posts'])) {
  114. $this->display_posts = $this->array['display_posts'];
  115. }
  116. if (isset ($this->array['sort_order'])) {
  117. $this->sort_order = $this->array['sort_order'];
  118. }
  119. if (isset ($this->array['old_entries'])) {
  120. $this->old_entries = $this->array['old_entries'];
  121. }
  122. if (isset ($this->array['shortcuts'])) {
  123. $this->shortcuts = $this->array['shortcuts'];
  124. }
  125. if (isset ($this->array['mail_login'])) {
  126. $this->mail_login = $this->array['mail_login'];
  127. }
  128. }
  129. public function update ($values) {
  130. foreach ($values as $key => $value) {
  131. $this->array[$key] = $value;
  132. }
  133. $this->writeFile($this->array);
  134. }
  135. }