RSSConfiguration.php 12 KB

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