RSSConfiguration.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. private $mark_when = array ();
  11. public function __construct () {
  12. $confDAO = new RSSConfigurationDAO ();
  13. $this->_postsPerPage ($confDAO->posts_per_page);
  14. $this->_defaultView ($confDAO->default_view);
  15. $this->_displayPosts ($confDAO->display_posts);
  16. $this->_sortOrder ($confDAO->sort_order);
  17. $this->_oldEntries ($confDAO->old_entries);
  18. $this->_shortcuts ($confDAO->shortcuts);
  19. $this->_mailLogin ($confDAO->mail_login);
  20. $this->_markWhen ($confDAO->mark_when);
  21. }
  22. public function postsPerPage () {
  23. return $this->posts_per_page;
  24. }
  25. public function defaultView () {
  26. return $this->default_view;
  27. }
  28. public function displayPosts () {
  29. return $this->display_posts;
  30. }
  31. public function sortOrder () {
  32. return $this->sort_order;
  33. }
  34. public function oldEntries () {
  35. return $this->old_entries;
  36. }
  37. public function shortcuts () {
  38. return $this->shortcuts;
  39. }
  40. public function mailLogin () {
  41. return $this->mail_login;
  42. }
  43. public function markWhen () {
  44. return $this->mark_when;
  45. }
  46. public function markWhenArticle () {
  47. return $this->mark_when['article'];
  48. }
  49. public function markWhenSite () {
  50. return $this->mark_when['site'];
  51. }
  52. public function markWhenPage () {
  53. return $this->mark_when['page'];
  54. }
  55. public function _postsPerPage ($value) {
  56. if (is_int (intval ($value))) {
  57. $this->posts_per_page = $value;
  58. } else {
  59. $this->posts_per_page = 10;
  60. }
  61. }
  62. public function _defaultView ($value) {
  63. if ($value == 'not_read') {
  64. $this->default_view = 'not_read';
  65. } else {
  66. $this->default_view = 'all';
  67. }
  68. }
  69. public function _displayPosts ($value) {
  70. if ($value == 'yes') {
  71. $this->display_posts = 'yes';
  72. } else {
  73. $this->display_posts = 'no';
  74. }
  75. }
  76. public function _sortOrder ($value) {
  77. if ($value == 'high_to_low') {
  78. $this->sort_order = 'high_to_low';
  79. } else {
  80. $this->sort_order = 'low_to_high';
  81. }
  82. }
  83. public function _oldEntries ($value) {
  84. if (is_int (intval ($value))) {
  85. $this->old_entries = $value;
  86. } else {
  87. $this->old_entries = 3;
  88. }
  89. }
  90. public function _shortcuts ($values) {
  91. foreach ($values as $key => $value) {
  92. $this->shortcuts[$key] = $value;
  93. }
  94. }
  95. public function _mailLogin ($value) {
  96. if (filter_var ($value, FILTER_VALIDATE_EMAIL)) {
  97. $this->mail_login = $value;
  98. } elseif ($value == false) {
  99. $this->mail_login = false;
  100. }
  101. }
  102. public function _markWhen ($values) {
  103. $this->mark_when['article'] = $values['article'];
  104. $this->mark_when['site'] = $values['site'];
  105. $this->mark_when['page'] = $values['page'];
  106. }
  107. }
  108. class RSSConfigurationDAO extends Model_array {
  109. public $posts_per_page = 10;
  110. public $default_view = 'all';
  111. public $display_posts = 'no';
  112. public $sort_order = 'low_to_high';
  113. public $old_entries = 3;
  114. public $shortcuts = array (
  115. 'mark_read' => 'r',
  116. 'mark_favorite' => 'f',
  117. 'go_website' => 'space',
  118. 'next_entry' => 'j',
  119. 'prev_entry' => 'k',
  120. 'next_page' => 'right',
  121. 'prev_page' => 'left',
  122. );
  123. public $mail_login = '';
  124. public $mark_when = array (
  125. 'article' => 'yes',
  126. 'site' => 'yes',
  127. 'page' => 'no'
  128. );
  129. public function __construct () {
  130. parent::__construct (PUBLIC_PATH . '/data/Configuration.array.php');
  131. if (isset ($this->array['posts_per_page'])) {
  132. $this->posts_per_page = $this->array['posts_per_page'];
  133. }
  134. if (isset ($this->array['default_view'])) {
  135. $this->default_view = $this->array['default_view'];
  136. }
  137. if (isset ($this->array['display_posts'])) {
  138. $this->display_posts = $this->array['display_posts'];
  139. }
  140. if (isset ($this->array['sort_order'])) {
  141. $this->sort_order = $this->array['sort_order'];
  142. }
  143. if (isset ($this->array['old_entries'])) {
  144. $this->old_entries = $this->array['old_entries'];
  145. }
  146. if (isset ($this->array['shortcuts'])) {
  147. $this->shortcuts = $this->array['shortcuts'];
  148. }
  149. if (isset ($this->array['mail_login'])) {
  150. $this->mail_login = $this->array['mail_login'];
  151. }
  152. if (isset ($this->array['mark_when'])) {
  153. $this->mark_when = $this->array['mark_when'];
  154. }
  155. }
  156. public function update ($values) {
  157. foreach ($values as $key => $value) {
  158. $this->array[$key] = $value;
  159. }
  160. $this->writeFile($this->array);
  161. }
  162. }