aboutsummaryrefslogtreecommitdiff
path: root/app/models/RSSConfiguration.php
blob: ca56ec3a80bdd33e7063a4de964db4b67655d506 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php

class RSSConfiguration extends Model {
	private $posts_per_page;
	private $default_view;
	private $display_posts;
	private $sort_order;
	private $old_entries;
	private $shortcuts = array ();
	private $mail_login = '';
	private $mark_when = array ();
	private $url_shaarli = '';
	
	public function __construct () {
		$confDAO = new RSSConfigurationDAO ();
		$this->_postsPerPage ($confDAO->posts_per_page);
		$this->_defaultView ($confDAO->default_view);
		$this->_displayPosts ($confDAO->display_posts);
		$this->_sortOrder ($confDAO->sort_order);
		$this->_oldEntries ($confDAO->old_entries);
		$this->_shortcuts ($confDAO->shortcuts);
		$this->_mailLogin ($confDAO->mail_login);
		$this->_markWhen ($confDAO->mark_when);
		$this->_urlShaarli ($confDAO->url_shaarli);
	}
	
	public function postsPerPage () {
		return $this->posts_per_page;
	}
	public function defaultView () {
		return $this->default_view;
	}
	public function displayPosts () {
		return $this->display_posts;
	}
	public function sortOrder () {
		return $this->sort_order;
	}
	public function oldEntries () {
		return $this->old_entries;
	}
	public function shortcuts () {
		return $this->shortcuts;
	}
	public function mailLogin () {
		return $this->mail_login;
	}
	public function markWhen () {
		return $this->mark_when;
	}
	public function markWhenArticle () {
		return $this->mark_when['article'];
	}
	public function markWhenSite () {
		return $this->mark_when['site'];
	}
	public function markWhenPage () {
		return $this->mark_when['page'];
	}
	public function urlShaarli () {
		return $this->url_shaarli;
	}
	
	public function _postsPerPage ($value) {
		if (is_int (intval ($value))) {
			$this->posts_per_page = $value;
		} else {
			$this->posts_per_page = 10;
		}
	}
	public function _defaultView ($value) {
		if ($value == 'not_read') {
			$this->default_view = 'not_read';
		} else {
			$this->default_view = 'all';
		}
	}
	public function _displayPosts ($value) {
		if ($value == 'yes') {
			$this->display_posts = 'yes';
		} else {
			$this->display_posts = 'no';
		}
	}
	public function _sortOrder ($value) {
		if ($value == 'high_to_low') {
			$this->sort_order = 'high_to_low';
		} else {
			$this->sort_order = 'low_to_high';
		}
	}
	public function _oldEntries ($value) {
		if (is_int (intval ($value))) {
			$this->old_entries = $value;
		} else {
			$this->old_entries = 3;
		}
	}
	public function _shortcuts ($values) {
		foreach ($values as $key => $value) {
			$this->shortcuts[$key] = $value;
		}
	}
	public function _mailLogin ($value) {
		if (filter_var ($value, FILTER_VALIDATE_EMAIL)) {
			$this->mail_login = $value;
		} elseif ($value == false) {
			$this->mail_login = false;
		}
	}
	public function _markWhen ($values) {
		$this->mark_when['article'] = $values['article'];
		$this->mark_when['site'] = $values['site'];
		$this->mark_when['page'] = $values['page'];
	}
	public function _urlShaarli ($value) {
		$this->url_shaarli = '';
		if (filter_var ($value, FILTER_VALIDATE_URL)) {
			$this->url_shaarli = $value;
		}
	}
}

class RSSConfigurationDAO extends Model_array {
	public $posts_per_page = 20;
	public $default_view = 'not_read';
	public $display_posts = 'no';
	public $sort_order = 'low_to_high';
	public $old_entries = 3;
	public $shortcuts = array (
		'mark_read' => 'r',
		'mark_favorite' => 'f',
		'go_website' => 'space',
		'next_entry' => 'j',
		'prev_entry' => 'k',
		'next_page' => 'right',
		'prev_page' => 'left',
	);
	public $mail_login = '';
	public $mark_when = array (
		'article' => 'yes',
		'site' => 'yes',
		'page' => 'no'
	);
	public $url_shaarli = '';

	public function __construct () {
		parent::__construct (PUBLIC_PATH . '/data/Configuration.array.php');
		
		if (isset ($this->array['posts_per_page'])) {
			$this->posts_per_page = $this->array['posts_per_page'];
		}
		if (isset ($this->array['default_view'])) {
			$this->default_view = $this->array['default_view'];
		}
		if (isset ($this->array['display_posts'])) {
			$this->display_posts = $this->array['display_posts'];
		}
		if (isset ($this->array['sort_order'])) {
			$this->sort_order = $this->array['sort_order'];
		}
		if (isset ($this->array['old_entries'])) {
			$this->old_entries = $this->array['old_entries'];
		}
		if (isset ($this->array['shortcuts'])) {
			$this->shortcuts = $this->array['shortcuts'];
		}
		if (isset ($this->array['mail_login'])) {
			$this->mail_login = $this->array['mail_login'];
		}
		if (isset ($this->array['mark_when'])) {
			$this->mark_when = $this->array['mark_when'];
		}
		if (isset ($this->array['url_shaarli'])) {
			$this->url_shaarli = $this->array['url_shaarli'];
		}
	}
	
	public function update ($values) {
		foreach ($values as $key => $value) {
			$this->array[$key] = $value;
		}
	
		$this->writeFile($this->array);
	}
}