RSSConfiguration.php 5.2 KB

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