RSSConfiguration.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  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 (is_int (intval ($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. if ($value == 'high_to_low') {
  213. $this->sort_order = 'high_to_low';
  214. } else {
  215. $this->sort_order = 'low_to_high';
  216. }
  217. }
  218. public function _oldEntries ($value) {
  219. if (is_int (intval ($value)) && $value > 0) {
  220. $this->old_entries = $value;
  221. } else {
  222. $this->old_entries = 3;
  223. }
  224. }
  225. public function _shortcuts ($values) {
  226. foreach ($values as $key => $value) {
  227. $this->shortcuts[$key] = $value;
  228. }
  229. }
  230. public function _mailLogin ($value) {
  231. if (filter_var ($value, FILTER_VALIDATE_EMAIL)) {
  232. $this->mail_login = $value;
  233. } elseif ($value == false) {
  234. $this->mail_login = false;
  235. }
  236. }
  237. public function _markWhen ($values) {
  238. if(!isset($values['article'])) {
  239. $values['article'] = 'yes';
  240. }
  241. if(!isset($values['site'])) {
  242. $values['site'] = 'yes';
  243. }
  244. if(!isset($values['scroll'])) {
  245. $values['scroll'] = 'yes';
  246. }
  247. $this->mark_when['article'] = $values['article'];
  248. $this->mark_when['site'] = $values['site'];
  249. $this->mark_when['scroll'] = $values['scroll'];
  250. }
  251. public function _sharing ($values) {
  252. $are_url = array ('shaarli', 'poche', 'diaspora');
  253. foreach ($values as $key => $value) {
  254. if (in_array($key, $are_url)) {
  255. $is_url = (
  256. filter_var ($value, FILTER_VALIDATE_URL) ||
  257. (version_compare(PHP_VERSION, '5.3.3', '<') &&
  258. (strpos($value, '-') > 0) &&
  259. ($value === filter_var($value, FILTER_SANITIZE_URL)))
  260. ); //PHP bug #51192
  261. if (!$is_url) {
  262. $value = '';
  263. }
  264. } elseif(!is_bool ($value)) {
  265. $value = true;
  266. }
  267. $this->sharing[$key] = $value;
  268. }
  269. }
  270. public function _theme ($value) {
  271. $this->theme = $value;
  272. }
  273. public function _anonAccess ($value) {
  274. if ($value == 'yes') {
  275. $this->anon_access = 'yes';
  276. } else {
  277. $this->anon_access = 'no';
  278. }
  279. }
  280. public function _token ($value) {
  281. $this->token = $value;
  282. }
  283. public function _autoLoadMore ($value) {
  284. if ($value == 'yes') {
  285. $this->auto_load_more = 'yes';
  286. } else {
  287. $this->auto_load_more = 'no';
  288. }
  289. }
  290. public function _topline_read ($value) {
  291. $this->topline_read = $value === 'yes';
  292. }
  293. public function _topline_favorite ($value) {
  294. $this->topline_favorite = $value === 'yes';
  295. }
  296. public function _topline_date ($value) {
  297. $this->topline_date = $value === 'yes';
  298. }
  299. public function _topline_link ($value) {
  300. $this->topline_link = $value === 'yes';
  301. }
  302. public function _bottomline_read ($value) {
  303. $this->bottomline_read = $value === 'yes';
  304. }
  305. public function _bottomline_favorite ($value) {
  306. $this->bottomline_favorite = $value === 'yes';
  307. }
  308. public function _bottomline_sharing ($value) {
  309. $this->bottomline_sharing = $value === 'yes';
  310. }
  311. public function _bottomline_tags ($value) {
  312. $this->bottomline_tags = $value === 'yes';
  313. }
  314. public function _bottomline_date ($value) {
  315. $this->bottomline_date = $value === 'yes';
  316. }
  317. public function _bottomline_link ($value) {
  318. $this->bottomline_link = $value === 'yes';
  319. }
  320. }
  321. class RSSConfigurationDAO extends Model_array {
  322. public $language = 'en';
  323. public $posts_per_page = 20;
  324. public $view_mode = 'normal';
  325. public $default_view = 'not_read';
  326. public $display_posts = 'no';
  327. public $onread_jump_next = 'yes';
  328. public $lazyload = 'yes';
  329. public $sort_order = 'low_to_high';
  330. public $old_entries = 3;
  331. public $shortcuts = array (
  332. 'mark_read' => 'r',
  333. 'mark_favorite' => 'f',
  334. 'go_website' => 'space',
  335. 'next_entry' => 'j',
  336. 'prev_entry' => 'k',
  337. 'collapse_entry' => 'c',
  338. );
  339. public $mail_login = '';
  340. public $mark_when = array (
  341. 'article' => 'yes',
  342. 'site' => 'yes',
  343. 'scroll' => 'no'
  344. );
  345. public $sharing = array (
  346. 'shaarli' => '',
  347. 'poche' => '',
  348. 'diaspora' => '',
  349. 'twitter' => true,
  350. 'g+' => true,
  351. 'facebook' => true,
  352. 'email' => true,
  353. 'print' => true
  354. );
  355. public $theme = 'default';
  356. public $anon_access = 'no';
  357. public $token = '';
  358. public $auto_load_more = 'no';
  359. public $topline_read = 'yes';
  360. public $topline_favorite = 'yes';
  361. public $topline_date = 'yes';
  362. public $topline_link = 'yes';
  363. public $bottomline_read = 'yes';
  364. public $bottomline_favorite = 'yes';
  365. public $bottomline_sharing = 'yes';
  366. public $bottomline_tags = 'yes';
  367. public $bottomline_date = 'yes';
  368. public $bottomline_link = 'yes';
  369. public function __construct () {
  370. parent::__construct (DATA_PATH . '/' . Configuration::currentUser () . '_user.php');
  371. // TODO : simplifier ce code, une boucle for() devrait suffir !
  372. if (isset ($this->array['language'])) {
  373. $this->language = $this->array['language'];
  374. }
  375. if (isset ($this->array['posts_per_page'])) {
  376. $this->posts_per_page = $this->array['posts_per_page'];
  377. }
  378. if (isset ($this->array['view_mode'])) {
  379. $this->view_mode = $this->array['view_mode'];
  380. }
  381. if (isset ($this->array['default_view'])) {
  382. $this->default_view = $this->array['default_view'];
  383. }
  384. if (isset ($this->array['display_posts'])) {
  385. $this->display_posts = $this->array['display_posts'];
  386. }
  387. if (isset ($this->array['onread_jump_next'])) {
  388. $this->onread_jump_next = $this->array['onread_jump_next'];
  389. }
  390. if (isset ($this->array['lazyload'])) {
  391. $this->lazyload = $this->array['lazyload'];
  392. }
  393. if (isset ($this->array['sort_order'])) {
  394. $this->sort_order = $this->array['sort_order'];
  395. }
  396. if (isset ($this->array['old_entries'])) {
  397. $this->old_entries = $this->array['old_entries'];
  398. }
  399. if (isset ($this->array['shortcuts'])) {
  400. $this->shortcuts = array_merge (
  401. $this->shortcuts, $this->array['shortcuts']
  402. );
  403. }
  404. if (isset ($this->array['mail_login'])) {
  405. $this->mail_login = $this->array['mail_login'];
  406. }
  407. if (isset ($this->array['mark_when'])) {
  408. $this->mark_when = $this->array['mark_when'];
  409. }
  410. if (isset ($this->array['sharing'])) {
  411. $this->sharing = array_merge (
  412. $this->sharing, $this->array['sharing']
  413. );
  414. }
  415. if (isset ($this->array['theme'])) {
  416. $this->theme = $this->array['theme'];
  417. }
  418. if (isset ($this->array['anon_access'])) {
  419. $this->anon_access = $this->array['anon_access'];
  420. }
  421. if (isset ($this->array['token'])) {
  422. $this->token = $this->array['token'];
  423. }
  424. if (isset ($this->array['auto_load_more'])) {
  425. $this->auto_load_more = $this->array['auto_load_more'];
  426. }
  427. if (isset ($this->array['topline_read'])) {
  428. $this->topline_read = $this->array['topline_read'];
  429. }
  430. if (isset ($this->array['topline_favorite'])) {
  431. $this->topline_favorite = $this->array['topline_favorite'];
  432. }
  433. if (isset ($this->array['topline_date'])) {
  434. $this->topline_date = $this->array['topline_date'];
  435. }
  436. if (isset ($this->array['topline_link'])) {
  437. $this->topline_link = $this->array['topline_link'];
  438. }
  439. if (isset ($this->array['bottomline_read'])) {
  440. $this->bottomline_read = $this->array['bottomline_read'];
  441. }
  442. if (isset ($this->array['bottomline_favorite'])) {
  443. $this->bottomline_favorite = $this->array['bottomline_favorite'];
  444. }
  445. if (isset ($this->array['bottomline_sharing'])) {
  446. $this->bottomline_sharing = $this->array['bottomline_sharing'];
  447. }
  448. if (isset ($this->array['bottomline_tags'])) {
  449. $this->bottomline_tags = $this->array['bottomline_tags'];
  450. }
  451. if (isset ($this->array['bottomline_date'])) {
  452. $this->bottomline_date = $this->array['bottomline_date'];
  453. }
  454. if (isset ($this->array['bottomline_link'])) {
  455. $this->bottomline_link = $this->array['bottomline_link'];
  456. }
  457. }
  458. public function update ($values) {
  459. foreach ($values as $key => $value) {
  460. $this->array[$key] = $value;
  461. }
  462. $this->writeFile($this->array);
  463. invalidateHttpCache();
  464. }
  465. }