Configuration.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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 $keep_history_default;
  17. private $shortcuts = array ();
  18. private $mail_login = '';
  19. private $mark_when = array ();
  20. private $sharing = array ();
  21. private $theme;
  22. private $anon_access;
  23. private $token;
  24. private $auto_load_more;
  25. private $topline_read;
  26. private $topline_favorite;
  27. private $topline_date;
  28. private $topline_link;
  29. private $bottomline_read;
  30. private $bottomline_favorite;
  31. private $bottomline_sharing;
  32. private $bottomline_tags;
  33. private $bottomline_date;
  34. private $bottomline_link;
  35. public function __construct () {
  36. $confDAO = new FreshRSS_ConfigurationDAO ();
  37. $this->_language ($confDAO->language);
  38. $this->_postsPerPage ($confDAO->posts_per_page);
  39. $this->_viewMode ($confDAO->view_mode);
  40. $this->_defaultView ($confDAO->default_view);
  41. $this->_displayPosts ($confDAO->display_posts);
  42. $this->_onread_jump_next ($confDAO->onread_jump_next);
  43. $this->_lazyload ($confDAO->lazyload);
  44. $this->_sortOrder ($confDAO->sort_order);
  45. $this->_oldEntries ($confDAO->old_entries);
  46. $this->_keepHistoryDefault($confDAO->keep_history_default);
  47. $this->_shortcuts ($confDAO->shortcuts);
  48. $this->_mailLogin ($confDAO->mail_login);
  49. $this->_markWhen ($confDAO->mark_when);
  50. $this->_sharing ($confDAO->sharing);
  51. $this->_theme ($confDAO->theme);
  52. FreshRSS_Themes::setThemeId ($confDAO->theme);
  53. $this->_anonAccess ($confDAO->anon_access);
  54. $this->_token ($confDAO->token);
  55. $this->_autoLoadMore ($confDAO->auto_load_more);
  56. $this->_topline_read ($confDAO->topline_read);
  57. $this->_topline_favorite ($confDAO->topline_favorite);
  58. $this->_topline_date ($confDAO->topline_date);
  59. $this->_topline_link ($confDAO->topline_link);
  60. $this->_bottomline_read ($confDAO->bottomline_read);
  61. $this->_bottomline_favorite ($confDAO->bottomline_favorite);
  62. $this->_bottomline_sharing ($confDAO->bottomline_sharing);
  63. $this->_bottomline_tags ($confDAO->bottomline_tags);
  64. $this->_bottomline_date ($confDAO->bottomline_date);
  65. $this->_bottomline_link ($confDAO->bottomline_link);
  66. }
  67. public function availableLanguages () {
  68. return $this->available_languages;
  69. }
  70. public function language () {
  71. return $this->language;
  72. }
  73. public function postsPerPage () {
  74. return $this->posts_per_page;
  75. }
  76. public function viewMode () {
  77. return $this->view_mode;
  78. }
  79. public function defaultView () {
  80. return $this->default_view;
  81. }
  82. public function displayPosts () {
  83. return $this->display_posts;
  84. }
  85. public function onread_jump_next () {
  86. return $this->onread_jump_next;
  87. }
  88. public function lazyload () {
  89. return $this->lazyload;
  90. }
  91. public function sortOrder () {
  92. return $this->sort_order;
  93. }
  94. public function oldEntries () {
  95. return $this->old_entries;
  96. }
  97. public function keepHistoryDefault() {
  98. return $this->keep_history_default;
  99. }
  100. public function shortcuts () {
  101. return $this->shortcuts;
  102. }
  103. public function mailLogin () {
  104. return $this->mail_login;
  105. }
  106. public function markWhen () {
  107. return $this->mark_when;
  108. }
  109. public function markWhenArticle () {
  110. return $this->mark_when['article'];
  111. }
  112. public function markWhenSite () {
  113. return $this->mark_when['site'];
  114. }
  115. public function markWhenScroll () {
  116. return $this->mark_when['scroll'];
  117. }
  118. public function markUponReception () {
  119. return $this->mark_when['reception'];
  120. }
  121. public function sharing ($key = false) {
  122. if ($key === false) {
  123. return $this->sharing;
  124. } elseif (isset ($this->sharing[$key])) {
  125. return $this->sharing[$key];
  126. }
  127. return false;
  128. }
  129. public function theme () {
  130. return $this->theme;
  131. }
  132. public function anonAccess () {
  133. return $this->anon_access;
  134. }
  135. public function token () {
  136. return $this->token;
  137. }
  138. public function autoLoadMore () {
  139. return $this->auto_load_more;
  140. }
  141. public function toplineRead () {
  142. return $this->topline_read;
  143. }
  144. public function toplineFavorite () {
  145. return $this->topline_favorite;
  146. }
  147. public function toplineDate () {
  148. return $this->topline_date;
  149. }
  150. public function toplineLink () {
  151. return $this->topline_link;
  152. }
  153. public function bottomlineRead () {
  154. return $this->bottomline_read;
  155. }
  156. public function bottomlineFavorite () {
  157. return $this->bottomline_favorite;
  158. }
  159. public function bottomlineSharing () {
  160. return $this->bottomline_sharing;
  161. }
  162. public function bottomlineTags () {
  163. return $this->bottomline_tags;
  164. }
  165. public function bottomlineDate () {
  166. return $this->bottomline_date;
  167. }
  168. public function bottomlineLink () {
  169. return $this->bottomline_link;
  170. }
  171. public function _language ($value) {
  172. if (!isset ($this->available_languages[$value])) {
  173. $value = 'en';
  174. }
  175. $this->language = $value;
  176. }
  177. public function _postsPerPage ($value) {
  178. $value = intval($value);
  179. $this->posts_per_page = $value > 0 ? $value : 10;
  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. $this->sort_order = $value === 'ASC' ? 'ASC' : 'DESC';
  218. }
  219. public function _oldEntries($value) {
  220. $value = intval($value);
  221. $this->old_entries = $value > 0 ? $value : 3;
  222. }
  223. public function _keepHistoryDefault($value) {
  224. $value = intval($value);
  225. $this->keep_history_default = $value >= -1 ? $value : 0;
  226. }
  227. public function _shortcuts ($values) {
  228. foreach ($values as $key => $value) {
  229. $this->shortcuts[$key] = $value;
  230. }
  231. }
  232. public function _mailLogin ($value) {
  233. if (filter_var ($value, FILTER_VALIDATE_EMAIL)) {
  234. $this->mail_login = $value;
  235. } elseif ($value == false) {
  236. $this->mail_login = false;
  237. }
  238. }
  239. public function _markWhen ($values) {
  240. if(!isset($values['article'])) {
  241. $values['article'] = 'yes';
  242. }
  243. if(!isset($values['site'])) {
  244. $values['site'] = 'yes';
  245. }
  246. if(!isset($values['scroll'])) {
  247. $values['scroll'] = 'yes';
  248. }
  249. if(!isset($values['reception'])) {
  250. $values['reception'] = 'no';
  251. }
  252. $this->mark_when['article'] = $values['article'];
  253. $this->mark_when['site'] = $values['site'];
  254. $this->mark_when['scroll'] = $values['scroll'];
  255. $this->mark_when['reception'] = $values['reception'];
  256. }
  257. public function _sharing ($values) {
  258. $are_url = array ('shaarli', 'poche', 'diaspora');
  259. foreach ($values as $key => $value) {
  260. if (in_array($key, $are_url)) {
  261. $is_url = (
  262. filter_var ($value, FILTER_VALIDATE_URL) ||
  263. (version_compare(PHP_VERSION, '5.3.3', '<') &&
  264. (strpos($value, '-') > 0) &&
  265. ($value === filter_var($value, FILTER_SANITIZE_URL)))
  266. ); //PHP bug #51192
  267. if (!$is_url) {
  268. $value = '';
  269. }
  270. } elseif(!is_bool ($value)) {
  271. $value = true;
  272. }
  273. $this->sharing[$key] = $value;
  274. }
  275. }
  276. public function _theme ($value) {
  277. $this->theme = $value;
  278. }
  279. public function _anonAccess ($value) {
  280. if ($value == 'yes') {
  281. $this->anon_access = 'yes';
  282. } else {
  283. $this->anon_access = 'no';
  284. }
  285. }
  286. public function _token ($value) {
  287. $this->token = $value;
  288. }
  289. public function _autoLoadMore ($value) {
  290. if ($value == 'yes') {
  291. $this->auto_load_more = 'yes';
  292. } else {
  293. $this->auto_load_more = 'no';
  294. }
  295. }
  296. public function _topline_read ($value) {
  297. $this->topline_read = $value === 'yes';
  298. }
  299. public function _topline_favorite ($value) {
  300. $this->topline_favorite = $value === 'yes';
  301. }
  302. public function _topline_date ($value) {
  303. $this->topline_date = $value === 'yes';
  304. }
  305. public function _topline_link ($value) {
  306. $this->topline_link = $value === 'yes';
  307. }
  308. public function _bottomline_read ($value) {
  309. $this->bottomline_read = $value === 'yes';
  310. }
  311. public function _bottomline_favorite ($value) {
  312. $this->bottomline_favorite = $value === 'yes';
  313. }
  314. public function _bottomline_sharing ($value) {
  315. $this->bottomline_sharing = $value === 'yes';
  316. }
  317. public function _bottomline_tags ($value) {
  318. $this->bottomline_tags = $value === 'yes';
  319. }
  320. public function _bottomline_date ($value) {
  321. $this->bottomline_date = $value === 'yes';
  322. }
  323. public function _bottomline_link ($value) {
  324. $this->bottomline_link = $value === 'yes';
  325. }
  326. }