RSSConfiguration.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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. private $topline_read;
  25. private $topline_favorite;
  26. private $topline_date;
  27. private $topline_link;
  28. private $bottomline_read;
  29. private $bottomline_favorite;
  30. private $bottomline_sharing;
  31. private $bottomline_tags;
  32. private $bottomline_date;
  33. private $bottomline_link;
  34. public function __construct () {
  35. $confDAO = new RSSConfigurationDAO ();
  36. $this->_language ($confDAO->language);
  37. $this->_postsPerPage ($confDAO->posts_per_page);
  38. $this->_viewMode ($confDAO->view_mode);
  39. $this->_defaultView ($confDAO->default_view);
  40. $this->_displayPosts ($confDAO->display_posts);
  41. $this->_onread_jump_next ($confDAO->onread_jump_next);
  42. $this->_lazyload ($confDAO->lazyload);
  43. $this->_sortOrder ($confDAO->sort_order);
  44. $this->_oldEntries ($confDAO->old_entries);
  45. $this->_shortcuts ($confDAO->shortcuts);
  46. $this->_mailLogin ($confDAO->mail_login);
  47. $this->_markWhen ($confDAO->mark_when);
  48. $this->_urlShaarli ($confDAO->url_shaarli);
  49. $this->_theme ($confDAO->theme);
  50. $this->_anonAccess ($confDAO->anon_access);
  51. $this->_token ($confDAO->token);
  52. $this->_autoLoadMore ($confDAO->auto_load_more);
  53. $this->_topline_read ($confDAO->topline_read);
  54. $this->_topline_favorite ($confDAO->topline_favorite);
  55. $this->_topline_date ($confDAO->topline_date);
  56. $this->_topline_link ($confDAO->topline_link);
  57. $this->_bottomline_read ($confDAO->bottomline_read);
  58. $this->_bottomline_favorite ($confDAO->bottomline_favorite);
  59. $this->_bottomline_sharing ($confDAO->bottomline_sharing);
  60. $this->_bottomline_tags ($confDAO->bottomline_tags);
  61. $this->_bottomline_date ($confDAO->bottomline_date);
  62. $this->_bottomline_link ($confDAO->bottomline_link);
  63. }
  64. public function availableLanguages () {
  65. return $this->available_languages;
  66. }
  67. public function language () {
  68. return $this->language;
  69. }
  70. public function postsPerPage () {
  71. return $this->posts_per_page;
  72. }
  73. public function viewMode () {
  74. return $this->view_mode;
  75. }
  76. public function defaultView () {
  77. return $this->default_view;
  78. }
  79. public function displayPosts () {
  80. return $this->display_posts;
  81. }
  82. public function onread_jump_next () {
  83. return $this->onread_jump_next;
  84. }
  85. public function lazyload () {
  86. return $this->lazyload;
  87. }
  88. public function sortOrder () {
  89. return $this->sort_order;
  90. }
  91. public function oldEntries () {
  92. return $this->old_entries;
  93. }
  94. public function shortcuts () {
  95. return $this->shortcuts;
  96. }
  97. public function mailLogin () {
  98. return $this->mail_login;
  99. }
  100. public function markWhen () {
  101. return $this->mark_when;
  102. }
  103. public function markWhenArticle () {
  104. return $this->mark_when['article'];
  105. }
  106. public function markWhenSite () {
  107. return $this->mark_when['site'];
  108. }
  109. public function markWhenScroll () {
  110. return $this->mark_when['scroll'];
  111. }
  112. public function urlShaarli () {
  113. return $this->url_shaarli;
  114. }
  115. public function theme () {
  116. return $this->theme;
  117. }
  118. public function anonAccess () {
  119. return $this->anon_access;
  120. }
  121. public function token () {
  122. return $this->token;
  123. }
  124. public function autoLoadMore () {
  125. return $this->auto_load_more;
  126. }
  127. public function toplineRead () {
  128. return $this->topline_read;
  129. }
  130. public function toplineFavorite () {
  131. return $this->topline_favorite;
  132. }
  133. public function toplineDate () {
  134. return $this->topline_date;
  135. }
  136. public function toplineLink () {
  137. return $this->topline_link;
  138. }
  139. public function bottomlineRead () {
  140. return $this->bottomline_read;
  141. }
  142. public function bottomlineFavorite () {
  143. return $this->bottomline_favorite;
  144. }
  145. public function bottomlineSharing () {
  146. return $this->bottomline_sharing;
  147. }
  148. public function bottomlineTags () {
  149. return $this->bottomline_tags;
  150. }
  151. public function bottomlineDate () {
  152. return $this->bottomline_date;
  153. }
  154. public function bottomlineLink () {
  155. return $this->bottomline_link;
  156. }
  157. public function _language ($value) {
  158. if (!isset ($this->available_languages[$value])) {
  159. $value = 'en';
  160. }
  161. $this->language = $value;
  162. }
  163. public function _postsPerPage ($value) {
  164. if (is_int (intval ($value)) && $value > 0) {
  165. $this->posts_per_page = $value;
  166. } else {
  167. $this->posts_per_page = 10;
  168. }
  169. }
  170. public function _viewMode ($value) {
  171. if ($value == 'global' || $value == 'reader') {
  172. $this->view_mode = $value;
  173. } else {
  174. $this->view_mode = 'normal';
  175. }
  176. }
  177. public function _defaultView ($value) {
  178. if ($value == 'not_read') {
  179. $this->default_view = 'not_read';
  180. } else {
  181. $this->default_view = 'all';
  182. }
  183. }
  184. public function _displayPosts ($value) {
  185. if ($value == 'yes') {
  186. $this->display_posts = 'yes';
  187. } else {
  188. $this->display_posts = 'no';
  189. }
  190. }
  191. public function _onread_jump_next ($value) {
  192. if ($value == 'no') {
  193. $this->onread_jump_next = 'no';
  194. } else {
  195. $this->onread_jump_next = 'yes';
  196. }
  197. }
  198. public function _lazyload ($value) {
  199. if ($value == 'no') {
  200. $this->lazyload = 'no';
  201. } else {
  202. $this->lazyload = 'yes';
  203. }
  204. }
  205. public function _sortOrder ($value) {
  206. if ($value == 'high_to_low') {
  207. $this->sort_order = 'high_to_low';
  208. } else {
  209. $this->sort_order = 'low_to_high';
  210. }
  211. }
  212. public function _oldEntries ($value) {
  213. if (is_int (intval ($value)) && $value > 0) {
  214. $this->old_entries = $value;
  215. } else {
  216. $this->old_entries = 3;
  217. }
  218. }
  219. public function _shortcuts ($values) {
  220. foreach ($values as $key => $value) {
  221. $this->shortcuts[$key] = $value;
  222. }
  223. }
  224. public function _mailLogin ($value) {
  225. if (filter_var ($value, FILTER_VALIDATE_EMAIL)) {
  226. $this->mail_login = $value;
  227. } elseif ($value == false) {
  228. $this->mail_login = false;
  229. }
  230. }
  231. public function _markWhen ($values) {
  232. if(!isset($values['article'])) {
  233. $values['article'] = 'yes';
  234. }
  235. if(!isset($values['site'])) {
  236. $values['site'] = 'yes';
  237. }
  238. if(!isset($values['scroll'])) {
  239. $values['scroll'] = 'yes';
  240. }
  241. $this->mark_when['article'] = $values['article'];
  242. $this->mark_when['site'] = $values['site'];
  243. $this->mark_when['scroll'] = $values['scroll'];
  244. }
  245. public function _urlShaarli ($value) {
  246. if (filter_var ($value, FILTER_VALIDATE_URL)) {
  247. $this->url_shaarli = $value;
  248. } elseif (version_compare(PHP_VERSION, '5.3.3', '<') && (strpos($value, '-') > 0) && ($value === filter_var($value, FILTER_SANITIZE_URL))) { //PHP bug #51192
  249. $this->url_shaarli = $value;
  250. } else {
  251. $this->url_shaarli = '';
  252. }
  253. }
  254. public function _theme ($value) {
  255. $this->theme = $value;
  256. }
  257. public function _anonAccess ($value) {
  258. if ($value == 'yes') {
  259. $this->anon_access = 'yes';
  260. } else {
  261. $this->anon_access = 'no';
  262. }
  263. }
  264. public function _token ($value) {
  265. $this->token = $value;
  266. }
  267. public function _autoLoadMore ($value) {
  268. if ($value == 'yes') {
  269. $this->auto_load_more = 'yes';
  270. } else {
  271. $this->auto_load_more = 'no';
  272. }
  273. }
  274. public function _topline_read ($value) {
  275. $this->topline_read = $value === 'yes';
  276. }
  277. public function _topline_favorite ($value) {
  278. $this->topline_favorite = $value === 'yes';
  279. }
  280. public function _topline_date ($value) {
  281. $this->topline_date = $value === 'yes';
  282. }
  283. public function _topline_link ($value) {
  284. $this->topline_link = $value === 'yes';
  285. }
  286. public function _bottomline_read ($value) {
  287. $this->bottomline_read = $value === 'yes';
  288. }
  289. public function _bottomline_favorite ($value) {
  290. $this->bottomline_favorite = $value === 'yes';
  291. }
  292. public function _bottomline_sharing ($value) {
  293. $this->bottomline_sharing = $value === 'yes';
  294. }
  295. public function _bottomline_tags ($value) {
  296. $this->bottomline_tags = $value === 'yes';
  297. }
  298. public function _bottomline_date ($value) {
  299. $this->bottomline_date = $value === 'yes';
  300. }
  301. public function _bottomline_link ($value) {
  302. $this->bottomline_link = $value === 'yes';
  303. }
  304. }
  305. class RSSConfigurationDAO extends Model_array {
  306. public $language = 'en';
  307. public $posts_per_page = 20;
  308. public $view_mode = 'normal';
  309. public $default_view = 'not_read';
  310. public $display_posts = 'no';
  311. public $onread_jump_next = 'yes';
  312. public $lazyload = 'yes';
  313. public $sort_order = 'low_to_high';
  314. public $old_entries = 3;
  315. public $shortcuts = array (
  316. 'mark_read' => 'r',
  317. 'mark_favorite' => 'f',
  318. 'go_website' => 'space',
  319. 'next_entry' => 'j',
  320. 'prev_entry' => 'k',
  321. 'collapse_entry' => 'c',
  322. );
  323. public $mail_login = '';
  324. public $mark_when = array (
  325. 'article' => 'yes',
  326. 'site' => 'yes',
  327. 'scroll' => 'no'
  328. );
  329. public $url_shaarli = '';
  330. public $theme = 'default';
  331. public $anon_access = 'no';
  332. public $token = '';
  333. public $auto_load_more = 'no';
  334. public $topline_read = 'yes';
  335. public $topline_favorite = 'yes';
  336. public $topline_date = 'yes';
  337. public $topline_link = 'yes';
  338. public $bottomline_read = 'yes';
  339. public $bottomline_favorite = 'yes';
  340. public $bottomline_sharing = 'yes';
  341. public $bottomline_tags = 'yes';
  342. public $bottomline_date = 'yes';
  343. public $bottomline_link = 'yes';
  344. public function __construct () {
  345. parent::__construct (DATA_PATH . '/' . Configuration::currentUser () . '_user.php');
  346. // TODO : simplifier ce code, une boucle for() devrait suffir !
  347. if (isset ($this->array['language'])) {
  348. $this->language = $this->array['language'];
  349. }
  350. if (isset ($this->array['posts_per_page'])) {
  351. $this->posts_per_page = $this->array['posts_per_page'];
  352. }
  353. if (isset ($this->array['view_mode'])) {
  354. $this->view_mode = $this->array['view_mode'];
  355. }
  356. if (isset ($this->array['default_view'])) {
  357. $this->default_view = $this->array['default_view'];
  358. }
  359. if (isset ($this->array['display_posts'])) {
  360. $this->display_posts = $this->array['display_posts'];
  361. }
  362. if (isset ($this->array['onread_jump_next'])) {
  363. $this->onread_jump_next = $this->array['onread_jump_next'];
  364. }
  365. if (isset ($this->array['lazyload'])) {
  366. $this->lazyload = $this->array['lazyload'];
  367. }
  368. if (isset ($this->array['sort_order'])) {
  369. $this->sort_order = $this->array['sort_order'];
  370. }
  371. if (isset ($this->array['old_entries'])) {
  372. $this->old_entries = $this->array['old_entries'];
  373. }
  374. if (isset ($this->array['shortcuts'])) {
  375. $this->shortcuts = array_merge ($this->shortcuts, $this->array['shortcuts']);
  376. }
  377. if (isset ($this->array['mail_login'])) {
  378. $this->mail_login = $this->array['mail_login'];
  379. }
  380. if (isset ($this->array['mark_when'])) {
  381. $this->mark_when = $this->array['mark_when'];
  382. }
  383. if (isset ($this->array['url_shaarli'])) {
  384. $this->url_shaarli = $this->array['url_shaarli'];
  385. }
  386. if (isset ($this->array['theme'])) {
  387. $this->theme = $this->array['theme'];
  388. }
  389. if (isset ($this->array['anon_access'])) {
  390. $this->anon_access = $this->array['anon_access'];
  391. }
  392. if (isset ($this->array['token'])) {
  393. $this->token = $this->array['token'];
  394. }
  395. if (isset ($this->array['auto_load_more'])) {
  396. $this->auto_load_more = $this->array['auto_load_more'];
  397. }
  398. if (isset ($this->array['topline_read'])) {
  399. $this->topline_read = $this->array['topline_read'];
  400. }
  401. if (isset ($this->array['topline_favorite'])) {
  402. $this->topline_favorite = $this->array['topline_favorite'];
  403. }
  404. if (isset ($this->array['topline_date'])) {
  405. $this->topline_date = $this->array['topline_date'];
  406. }
  407. if (isset ($this->array['topline_link'])) {
  408. $this->topline_link = $this->array['topline_link'];
  409. }
  410. if (isset ($this->array['bottomline_read'])) {
  411. $this->bottomline_read = $this->array['bottomline_read'];
  412. }
  413. if (isset ($this->array['bottomline_favorite'])) {
  414. $this->bottomline_favorite = $this->array['bottomline_favorite'];
  415. }
  416. if (isset ($this->array['bottomline_sharing'])) {
  417. $this->bottomline_sharing = $this->array['bottomline_sharing'];
  418. }
  419. if (isset ($this->array['bottomline_tags'])) {
  420. $this->bottomline_tags = $this->array['bottomline_tags'];
  421. }
  422. if (isset ($this->array['bottomline_date'])) {
  423. $this->bottomline_date = $this->array['bottomline_date'];
  424. }
  425. if (isset ($this->array['bottomline_link'])) {
  426. $this->bottomline_link = $this->array['bottomline_link'];
  427. }
  428. }
  429. public function update ($values) {
  430. foreach ($values as $key => $value) {
  431. $this->array[$key] = $value;
  432. }
  433. $this->writeFile($this->array);
  434. touch(DATA_PATH . '/touch.txt');
  435. }
  436. }