RSSConfiguration.php 4.7 KB

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