RSSConfiguration.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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 $view_mode;
  10. private $default_view;
  11. private $display_posts;
  12. private $lazyload;
  13. private $sort_order;
  14. private $old_entries;
  15. private $shortcuts = array ();
  16. private $mail_login = '';
  17. private $mark_when = array ();
  18. private $url_shaarli = '';
  19. private $theme;
  20. private $anon_access;
  21. private $token;
  22. private $auto_load_more;
  23. public function __construct () {
  24. $confDAO = new RSSConfigurationDAO ();
  25. $this->_language ($confDAO->language);
  26. $this->_postsPerPage ($confDAO->posts_per_page);
  27. $this->_viewMode ($confDAO->view_mode);
  28. $this->_defaultView ($confDAO->default_view);
  29. $this->_displayPosts ($confDAO->display_posts);
  30. $this->_lazyload ($confDAO->lazyload);
  31. $this->_sortOrder ($confDAO->sort_order);
  32. $this->_oldEntries ($confDAO->old_entries);
  33. $this->_shortcuts ($confDAO->shortcuts);
  34. $this->_mailLogin ($confDAO->mail_login);
  35. $this->_markWhen ($confDAO->mark_when);
  36. $this->_urlShaarli ($confDAO->url_shaarli);
  37. $this->_theme ($confDAO->theme);
  38. $this->_anonAccess ($confDAO->anon_access);
  39. $this->_token ($confDAO->token);
  40. $this->_autoLoadMore ($confDAO->auto_load_more);
  41. }
  42. public function availableLanguages () {
  43. return $this->available_languages;
  44. }
  45. public function language () {
  46. return $this->language;
  47. }
  48. public function postsPerPage () {
  49. return $this->posts_per_page;
  50. }
  51. public function viewMode () {
  52. return $this->view_mode;
  53. }
  54. public function defaultView () {
  55. return $this->default_view;
  56. }
  57. public function displayPosts () {
  58. return $this->display_posts;
  59. }
  60. public function lazyload () {
  61. return $this->lazyload;
  62. }
  63. public function sortOrder () {
  64. return $this->sort_order;
  65. }
  66. public function oldEntries () {
  67. return $this->old_entries;
  68. }
  69. public function shortcuts () {
  70. return $this->shortcuts;
  71. }
  72. public function mailLogin () {
  73. return $this->mail_login;
  74. }
  75. public function markWhen () {
  76. return $this->mark_when;
  77. }
  78. public function markWhenArticle () {
  79. return $this->mark_when['article'];
  80. }
  81. public function markWhenSite () {
  82. return $this->mark_when['site'];
  83. }
  84. public function markWhenScroll () {
  85. return $this->mark_when['scroll'];
  86. }
  87. public function urlShaarli () {
  88. return $this->url_shaarli;
  89. }
  90. public function theme () {
  91. return $this->theme;
  92. }
  93. public function anonAccess () {
  94. return $this->anon_access;
  95. }
  96. public function token () {
  97. return $this->token;
  98. }
  99. public function autoLoadMore () {
  100. return $this->auto_load_more;
  101. }
  102. public function _language ($value) {
  103. if (!isset ($this->available_languages[$value])) {
  104. $value = 'en';
  105. }
  106. $this->language = $value;
  107. }
  108. public function _postsPerPage ($value) {
  109. if (is_int (intval ($value)) && $value > 0) {
  110. $this->posts_per_page = $value;
  111. } else {
  112. $this->posts_per_page = 10;
  113. }
  114. }
  115. public function _viewMode ($value) {
  116. if ($value == 'global' || $value == 'reader') {
  117. $this->view_mode = $value;
  118. } else {
  119. $this->view_mode = 'normal';
  120. }
  121. }
  122. public function _defaultView ($value) {
  123. if ($value == 'not_read') {
  124. $this->default_view = 'not_read';
  125. } else {
  126. $this->default_view = 'all';
  127. }
  128. }
  129. public function _displayPosts ($value) {
  130. if ($value == 'yes') {
  131. $this->display_posts = 'yes';
  132. } else {
  133. $this->display_posts = 'no';
  134. }
  135. }
  136. public function _lazyload ($value) {
  137. if ($value == 'no') {
  138. $this->lazyload = 'no';
  139. } else {
  140. $this->lazyload = 'yes';
  141. }
  142. }
  143. public function _sortOrder ($value) {
  144. if ($value == 'high_to_low') {
  145. $this->sort_order = 'high_to_low';
  146. } else {
  147. $this->sort_order = 'low_to_high';
  148. }
  149. }
  150. public function _oldEntries ($value) {
  151. if (is_int (intval ($value)) && $value > 0) {
  152. $this->old_entries = $value;
  153. } else {
  154. $this->old_entries = 3;
  155. }
  156. }
  157. public function _shortcuts ($values) {
  158. foreach ($values as $key => $value) {
  159. $this->shortcuts[$key] = $value;
  160. }
  161. }
  162. public function _mailLogin ($value) {
  163. if (filter_var ($value, FILTER_VALIDATE_EMAIL)) {
  164. $this->mail_login = $value;
  165. } elseif ($value == false) {
  166. $this->mail_login = false;
  167. }
  168. }
  169. public function _markWhen ($values) {
  170. if(!isset($values['article'])) {
  171. $values['article'] = 'yes';
  172. }
  173. if(!isset($values['site'])) {
  174. $values['site'] = 'yes';
  175. }
  176. if(!isset($values['scroll'])) {
  177. $values['scroll'] = 'yes';
  178. }
  179. $this->mark_when['article'] = $values['article'];
  180. $this->mark_when['site'] = $values['site'];
  181. $this->mark_when['scroll'] = $values['scroll'];
  182. }
  183. public function _urlShaarli ($value) {
  184. $this->url_shaarli = '';
  185. if (filter_var ($value, FILTER_VALIDATE_URL)) {
  186. $this->url_shaarli = $value;
  187. }
  188. }
  189. public function _theme ($value) {
  190. $this->theme = $value;
  191. }
  192. public function _anonAccess ($value) {
  193. if ($value == 'yes') {
  194. $this->anon_access = 'yes';
  195. } else {
  196. $this->anon_access = 'no';
  197. }
  198. }
  199. public function _token ($value) {
  200. $this->token = $value;
  201. }
  202. public function _autoLoadMore ($value) {
  203. if ($value == 'yes') {
  204. $this->auto_load_more = 'yes';
  205. } else {
  206. $this->auto_load_more = 'no';
  207. }
  208. }
  209. }
  210. class RSSConfigurationDAO extends Model_array {
  211. public $language = 'en';
  212. public $posts_per_page = 20;
  213. public $view_mode = 'normal';
  214. public $default_view = 'not_read';
  215. public $display_posts = 'no';
  216. public $lazyload = 'yes';
  217. public $sort_order = 'low_to_high';
  218. public $old_entries = 3;
  219. public $shortcuts = array (
  220. 'mark_read' => 'r',
  221. 'mark_favorite' => 'f',
  222. 'go_website' => 'space',
  223. 'next_entry' => 'j',
  224. 'prev_entry' => 'k',
  225. 'next_page' => 'right',
  226. 'prev_page' => 'left',
  227. );
  228. public $mail_login = '';
  229. public $mark_when = array (
  230. 'article' => 'yes',
  231. 'site' => 'yes',
  232. 'scroll' => 'no'
  233. );
  234. public $url_shaarli = '';
  235. public $theme = 'default';
  236. public $anon_access = 'no';
  237. public $token = '';
  238. public $auto_load_more = 'no';
  239. public function __construct () {
  240. parent::__construct (PUBLIC_PATH . '/data/Configuration.array.php');
  241. // TODO : simplifier ce code, une boucle for() devrait suffir !
  242. if (isset ($this->array['language'])) {
  243. $this->language = $this->array['language'];
  244. }
  245. if (isset ($this->array['posts_per_page'])) {
  246. $this->posts_per_page = $this->array['posts_per_page'];
  247. }
  248. if (isset ($this->array['view_mode'])) {
  249. $this->view_mode = $this->array['view_mode'];
  250. }
  251. if (isset ($this->array['default_view'])) {
  252. $this->default_view = $this->array['default_view'];
  253. }
  254. if (isset ($this->array['display_posts'])) {
  255. $this->display_posts = $this->array['display_posts'];
  256. }
  257. if (isset ($this->array['lazyload'])) {
  258. $this->lazyload = $this->array['lazyload'];
  259. }
  260. if (isset ($this->array['sort_order'])) {
  261. $this->sort_order = $this->array['sort_order'];
  262. }
  263. if (isset ($this->array['old_entries'])) {
  264. $this->old_entries = $this->array['old_entries'];
  265. }
  266. if (isset ($this->array['shortcuts'])) {
  267. $this->shortcuts = $this->array['shortcuts'];
  268. }
  269. if (isset ($this->array['mail_login'])) {
  270. $this->mail_login = $this->array['mail_login'];
  271. }
  272. if (isset ($this->array['mark_when'])) {
  273. $this->mark_when = $this->array['mark_when'];
  274. }
  275. if (isset ($this->array['url_shaarli'])) {
  276. $this->url_shaarli = $this->array['url_shaarli'];
  277. }
  278. if (isset ($this->array['theme'])) {
  279. $this->theme = $this->array['theme'];
  280. }
  281. if (isset ($this->array['anon_access'])) {
  282. $this->anon_access = $this->array['anon_access'];
  283. }
  284. if (isset ($this->array['token'])) {
  285. $this->token = $this->array['token'];
  286. }
  287. if (isset ($this->array['auto_load_more'])) {
  288. $this->auto_load_more = $this->array['auto_load_more'];
  289. }
  290. }
  291. public function update ($values) {
  292. foreach ($values as $key => $value) {
  293. $this->array[$key] = $value;
  294. }
  295. $this->writeFile($this->array);
  296. }
  297. }