RSSConfiguration.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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 $sharing = array ();
  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->_sharing ($confDAO->sharing);
  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 sharing ($key = false) {
  114. if ($key === false) {
  115. return $this->sharing;
  116. } elseif (isset ($this->sharing[$key])) {
  117. return $this->sharing[$key];
  118. }
  119. return false;
  120. }
  121. public function theme () {
  122. return $this->theme;
  123. }
  124. public function anonAccess () {
  125. return $this->anon_access;
  126. }
  127. public function token () {
  128. return $this->token;
  129. }
  130. public function autoLoadMore () {
  131. return $this->auto_load_more;
  132. }
  133. public function toplineRead () {
  134. return $this->topline_read;
  135. }
  136. public function toplineFavorite () {
  137. return $this->topline_favorite;
  138. }
  139. public function toplineDate () {
  140. return $this->topline_date;
  141. }
  142. public function toplineLink () {
  143. return $this->topline_link;
  144. }
  145. public function bottomlineRead () {
  146. return $this->bottomline_read;
  147. }
  148. public function bottomlineFavorite () {
  149. return $this->bottomline_favorite;
  150. }
  151. public function bottomlineSharing () {
  152. return $this->bottomline_sharing;
  153. }
  154. public function bottomlineTags () {
  155. return $this->bottomline_tags;
  156. }
  157. public function bottomlineDate () {
  158. return $this->bottomline_date;
  159. }
  160. public function bottomlineLink () {
  161. return $this->bottomline_link;
  162. }
  163. public function _language ($value) {
  164. if (!isset ($this->available_languages[$value])) {
  165. $value = 'en';
  166. }
  167. $this->language = $value;
  168. }
  169. public function _postsPerPage ($value) {
  170. if (ctype_digit ($value) && $value > 0) {
  171. $this->posts_per_page = $value;
  172. } else {
  173. $this->posts_per_page = 10;
  174. }
  175. }
  176. public function _viewMode ($value) {
  177. if ($value == 'global' || $value == 'reader') {
  178. $this->view_mode = $value;
  179. } else {
  180. $this->view_mode = 'normal';
  181. }
  182. }
  183. public function _defaultView ($value) {
  184. if ($value == 'not_read') {
  185. $this->default_view = 'not_read';
  186. } else {
  187. $this->default_view = 'all';
  188. }
  189. }
  190. public function _displayPosts ($value) {
  191. if ($value == 'yes') {
  192. $this->display_posts = 'yes';
  193. } else {
  194. $this->display_posts = 'no';
  195. }
  196. }
  197. public function _onread_jump_next ($value) {
  198. if ($value == 'no') {
  199. $this->onread_jump_next = 'no';
  200. } else {
  201. $this->onread_jump_next = 'yes';
  202. }
  203. }
  204. public function _lazyload ($value) {
  205. if ($value == 'no') {
  206. $this->lazyload = 'no';
  207. } else {
  208. $this->lazyload = 'yes';
  209. }
  210. }
  211. public function _sortOrder ($value) {
  212. $this->sort_order = $value === 'ASC' ? 'ASC' : 'DESC';
  213. }
  214. public function _oldEntries ($value) {
  215. if (ctype_digit ($value) && $value > 0) {
  216. $this->old_entries = $value;
  217. } else {
  218. $this->old_entries = 3;
  219. }
  220. }
  221. public function _shortcuts ($values) {
  222. foreach ($values as $key => $value) {
  223. $this->shortcuts[$key] = $value;
  224. }
  225. }
  226. public function _mailLogin ($value) {
  227. if (filter_var ($value, FILTER_VALIDATE_EMAIL)) {
  228. $this->mail_login = $value;
  229. } elseif ($value == false) {
  230. $this->mail_login = false;
  231. }
  232. }
  233. public function _markWhen ($values) {
  234. if(!isset($values['article'])) {
  235. $values['article'] = 'yes';
  236. }
  237. if(!isset($values['site'])) {
  238. $values['site'] = 'yes';
  239. }
  240. if(!isset($values['scroll'])) {
  241. $values['scroll'] = 'yes';
  242. }
  243. $this->mark_when['article'] = $values['article'];
  244. $this->mark_when['site'] = $values['site'];
  245. $this->mark_when['scroll'] = $values['scroll'];
  246. }
  247. public function _sharing ($values) {
  248. $are_url = array ('shaarli', 'poche', 'diaspora');
  249. foreach ($values as $key => $value) {
  250. if (in_array($key, $are_url)) {
  251. $is_url = (
  252. filter_var ($value, FILTER_VALIDATE_URL) ||
  253. (version_compare(PHP_VERSION, '5.3.3', '<') &&
  254. (strpos($value, '-') > 0) &&
  255. ($value === filter_var($value, FILTER_SANITIZE_URL)))
  256. ); //PHP bug #51192
  257. if (!$is_url) {
  258. $value = '';
  259. }
  260. } elseif(!is_bool ($value)) {
  261. $value = true;
  262. }
  263. $this->sharing[$key] = $value;
  264. }
  265. }
  266. public function _theme ($value) {
  267. $this->theme = $value;
  268. }
  269. public function _anonAccess ($value) {
  270. if ($value == 'yes') {
  271. $this->anon_access = 'yes';
  272. } else {
  273. $this->anon_access = 'no';
  274. }
  275. }
  276. public function _token ($value) {
  277. $this->token = $value;
  278. }
  279. public function _autoLoadMore ($value) {
  280. if ($value == 'yes') {
  281. $this->auto_load_more = 'yes';
  282. } else {
  283. $this->auto_load_more = 'no';
  284. }
  285. }
  286. public function _topline_read ($value) {
  287. $this->topline_read = $value === 'yes';
  288. }
  289. public function _topline_favorite ($value) {
  290. $this->topline_favorite = $value === 'yes';
  291. }
  292. public function _topline_date ($value) {
  293. $this->topline_date = $value === 'yes';
  294. }
  295. public function _topline_link ($value) {
  296. $this->topline_link = $value === 'yes';
  297. }
  298. public function _bottomline_read ($value) {
  299. $this->bottomline_read = $value === 'yes';
  300. }
  301. public function _bottomline_favorite ($value) {
  302. $this->bottomline_favorite = $value === 'yes';
  303. }
  304. public function _bottomline_sharing ($value) {
  305. $this->bottomline_sharing = $value === 'yes';
  306. }
  307. public function _bottomline_tags ($value) {
  308. $this->bottomline_tags = $value === 'yes';
  309. }
  310. public function _bottomline_date ($value) {
  311. $this->bottomline_date = $value === 'yes';
  312. }
  313. public function _bottomline_link ($value) {
  314. $this->bottomline_link = $value === 'yes';
  315. }
  316. }
  317. class RSSConfigurationDAO extends Model_array {
  318. public $language = 'en';
  319. public $posts_per_page = 20;
  320. public $view_mode = 'normal';
  321. public $default_view = 'not_read';
  322. public $display_posts = 'no';
  323. public $onread_jump_next = 'yes';
  324. public $lazyload = 'yes';
  325. public $sort_order = 'DESC';
  326. public $old_entries = 3;
  327. public $shortcuts = array (
  328. 'mark_read' => 'r',
  329. 'mark_favorite' => 'f',
  330. 'go_website' => 'space',
  331. 'next_entry' => 'j',
  332. 'prev_entry' => 'k',
  333. 'collapse_entry' => 'c',
  334. 'load_more' => 'm'
  335. );
  336. public $mail_login = '';
  337. public $mark_when = array (
  338. 'article' => 'yes',
  339. 'site' => 'yes',
  340. 'scroll' => 'no'
  341. );
  342. public $sharing = array (
  343. 'shaarli' => '',
  344. 'poche' => '',
  345. 'diaspora' => '',
  346. 'twitter' => true,
  347. 'g+' => true,
  348. 'facebook' => true,
  349. 'email' => true,
  350. 'print' => true
  351. );
  352. public $theme = 'default';
  353. public $anon_access = 'no';
  354. public $token = '';
  355. public $auto_load_more = 'no';
  356. public $topline_read = 'yes';
  357. public $topline_favorite = 'yes';
  358. public $topline_date = 'yes';
  359. public $topline_link = 'yes';
  360. public $bottomline_read = 'yes';
  361. public $bottomline_favorite = 'yes';
  362. public $bottomline_sharing = 'yes';
  363. public $bottomline_tags = 'yes';
  364. public $bottomline_date = 'yes';
  365. public $bottomline_link = 'yes';
  366. public function __construct () {
  367. parent::__construct (DATA_PATH . '/' . Configuration::currentUser () . '_user.php');
  368. // TODO : simplifier ce code, une boucle for() devrait suffir !
  369. if (isset ($this->array['language'])) {
  370. $this->language = $this->array['language'];
  371. }
  372. if (isset ($this->array['posts_per_page'])) {
  373. $this->posts_per_page = $this->array['posts_per_page'];
  374. }
  375. if (isset ($this->array['view_mode'])) {
  376. $this->view_mode = $this->array['view_mode'];
  377. }
  378. if (isset ($this->array['default_view'])) {
  379. $this->default_view = $this->array['default_view'];
  380. }
  381. if (isset ($this->array['display_posts'])) {
  382. $this->display_posts = $this->array['display_posts'];
  383. }
  384. if (isset ($this->array['onread_jump_next'])) {
  385. $this->onread_jump_next = $this->array['onread_jump_next'];
  386. }
  387. if (isset ($this->array['lazyload'])) {
  388. $this->lazyload = $this->array['lazyload'];
  389. }
  390. if (isset ($this->array['sort_order'])) {
  391. $this->sort_order = $this->array['sort_order'];
  392. }
  393. if (isset ($this->array['old_entries'])) {
  394. $this->old_entries = $this->array['old_entries'];
  395. }
  396. if (isset ($this->array['shortcuts'])) {
  397. $this->shortcuts = array_merge (
  398. $this->shortcuts, $this->array['shortcuts']
  399. );
  400. }
  401. if (isset ($this->array['mail_login'])) {
  402. $this->mail_login = $this->array['mail_login'];
  403. }
  404. if (isset ($this->array['mark_when'])) {
  405. $this->mark_when = $this->array['mark_when'];
  406. }
  407. if (isset ($this->array['sharing'])) {
  408. $this->sharing = array_merge (
  409. $this->sharing, $this->array['sharing']
  410. );
  411. }
  412. if (isset ($this->array['theme'])) {
  413. $this->theme = $this->array['theme'];
  414. }
  415. if (isset ($this->array['anon_access'])) {
  416. $this->anon_access = $this->array['anon_access'];
  417. }
  418. if (isset ($this->array['token'])) {
  419. $this->token = $this->array['token'];
  420. }
  421. if (isset ($this->array['auto_load_more'])) {
  422. $this->auto_load_more = $this->array['auto_load_more'];
  423. }
  424. if (isset ($this->array['topline_read'])) {
  425. $this->topline_read = $this->array['topline_read'];
  426. }
  427. if (isset ($this->array['topline_favorite'])) {
  428. $this->topline_favorite = $this->array['topline_favorite'];
  429. }
  430. if (isset ($this->array['topline_date'])) {
  431. $this->topline_date = $this->array['topline_date'];
  432. }
  433. if (isset ($this->array['topline_link'])) {
  434. $this->topline_link = $this->array['topline_link'];
  435. }
  436. if (isset ($this->array['bottomline_read'])) {
  437. $this->bottomline_read = $this->array['bottomline_read'];
  438. }
  439. if (isset ($this->array['bottomline_favorite'])) {
  440. $this->bottomline_favorite = $this->array['bottomline_favorite'];
  441. }
  442. if (isset ($this->array['bottomline_sharing'])) {
  443. $this->bottomline_sharing = $this->array['bottomline_sharing'];
  444. }
  445. if (isset ($this->array['bottomline_tags'])) {
  446. $this->bottomline_tags = $this->array['bottomline_tags'];
  447. }
  448. if (isset ($this->array['bottomline_date'])) {
  449. $this->bottomline_date = $this->array['bottomline_date'];
  450. }
  451. if (isset ($this->array['bottomline_link'])) {
  452. $this->bottomline_link = $this->array['bottomline_link'];
  453. }
  454. }
  455. public function update ($values) {
  456. foreach ($values as $key => $value) {
  457. $this->array[$key] = $value;
  458. }
  459. $this->writeFile($this->array);
  460. invalidateHttpCache();
  461. }
  462. }