RSSConfiguration.php 13 KB

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