RSSConfiguration.php 8.1 KB

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