RSSConfiguration.php 3.1 KB

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