Configuration.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <?php
  2. class FreshRSS_Configuration extends Minz_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 FreshRSS_ConfigurationDAO ();
  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. FreshRSS_Themes::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 markUponReception () {
  114. return $this->mark_when['reception'];
  115. }
  116. public function sharing ($key = false) {
  117. if ($key === false) {
  118. return $this->sharing;
  119. } elseif (isset ($this->sharing[$key])) {
  120. return $this->sharing[$key];
  121. }
  122. return false;
  123. }
  124. public function theme () {
  125. return $this->theme;
  126. }
  127. public function anonAccess () {
  128. return $this->anon_access;
  129. }
  130. public function token () {
  131. return $this->token;
  132. }
  133. public function autoLoadMore () {
  134. return $this->auto_load_more;
  135. }
  136. public function toplineRead () {
  137. return $this->topline_read;
  138. }
  139. public function toplineFavorite () {
  140. return $this->topline_favorite;
  141. }
  142. public function toplineDate () {
  143. return $this->topline_date;
  144. }
  145. public function toplineLink () {
  146. return $this->topline_link;
  147. }
  148. public function bottomlineRead () {
  149. return $this->bottomline_read;
  150. }
  151. public function bottomlineFavorite () {
  152. return $this->bottomline_favorite;
  153. }
  154. public function bottomlineSharing () {
  155. return $this->bottomline_sharing;
  156. }
  157. public function bottomlineTags () {
  158. return $this->bottomline_tags;
  159. }
  160. public function bottomlineDate () {
  161. return $this->bottomline_date;
  162. }
  163. public function bottomlineLink () {
  164. return $this->bottomline_link;
  165. }
  166. public function _language ($value) {
  167. if (!isset ($this->available_languages[$value])) {
  168. $value = 'en';
  169. }
  170. $this->language = $value;
  171. }
  172. public function _postsPerPage ($value) {
  173. $value = intval($value);
  174. $this->posts_per_page = $value > 0 ? $value : 10;
  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. if(!isset($values['reception'])) {
  244. $values['reception'] = 'no';
  245. }
  246. $this->mark_when['article'] = $values['article'];
  247. $this->mark_when['site'] = $values['site'];
  248. $this->mark_when['scroll'] = $values['scroll'];
  249. $this->mark_when['reception'] = $values['reception'];
  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. }