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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
<?php
class indexController extends ActionController {
private $get = false;
private $nb_not_read = 0;
private $mode = 'all';
public function indexAction () {
View::appendScript (Url::display ('/scripts/shortcut.js'));
View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'main')));
$entryDAO = new EntryDAO ();
$feedDAO = new FeedDAO ();
$catDAO = new CategoryDAO ();
$error = false;
// pour optimiser
$page = Request::param ('page', 1);
$entryDAO->_nbItemsPerPage ($this->view->conf->postsPerPage ());
$entryDAO->_currentPage ($page);
// récupération de la catégorie/flux à filtrer
$this->initFilter ();
// Compte le nombre d'articles non lus en prenant en compte le filtre
$this->countNotRead ();
// mode de vue (tout ou seulement non lus)
$this->initCurrentMode ();
// ordre de listage des flux
$order = Session::param ('order', $this->view->conf->sortOrder ());
// recherche sur les titres (pour le moment)
$search = Request::param ('search');
// Récupère les flux par catégorie, favoris ou tous
if ($this->get['type'] == 'all') {
$entries = $entryDAO->listEntries ($this->mode, $search, $order);
View::prependTitle ('Vos flux RSS - ');
} elseif ($this->get['type'] == 'favoris') {
$entries = $entryDAO->listFavorites ($this->mode, $search, $order);
View::prependTitle ('Vos favoris - ');
} elseif ($this->get != false) {
if ($this->get['type'] == 'c') {
$cat = $catDAO->searchById ($this->get['filter']);
if ($cat) {
$entries = $entryDAO->listByCategory ($this->get['filter'], $this->mode, $search, $order);
View::prependTitle ($cat->name () . ' - ');
} else {
$error = true;
}
} elseif ($this->get['type'] == 'f') {
$feed = $feedDAO->searchById ($this->get['filter']);
if ($feed) {
$entries = $entryDAO->listByFeed ($this->get['filter'], $this->mode, $search, $order);
$this->view->get_c = $feed->category ();
View::prependTitle ($feed->name () . ' - ');
} else {
$error = true;
}
} else {
$error = true;
}
} else {
$error = true;
}
if ($error) {
Error::error (
404,
array ('error' => array ('La page que vous cherchez n\'existe pas'))
);
} else {
$this->view->mode = $this->mode;
$this->view->order = $order;
try {
$this->view->entryPaginator = $entryDAO->getPaginator ($entries);
} catch (CurrentPagePaginationException $e) {
}
$this->view->cat_aside = $catDAO->listCategories ();
$this->view->nb_favorites = $entryDAO->countFavorites ();
$this->view->nb_total = $entryDAO->count ();
}
}
public function aboutAction () {
View::prependTitle ('À propos - ');
}
public function changeModeAction () {
$mode = Request::param ('mode');
if ($mode == 'not_read') {
Session::_param ('mode', 'not_read');
} else {
Session::_param ('mode', 'all');
}
Request::forward (array (), true);
}
public function changeOrderAction () {
$order = Request::param ('order');
if ($order == 'low_to_high') {
Session::_param ('order', 'low_to_high');
} else {
Session::_param ('order', 'high_to_low');
}
Request::forward (array (), true);
}
public function loginAction () {
$this->view->_useLayout (false);
$url = 'https://verifier.login.persona.org/verify';
$assert = Request::param ('assertion');
$params = 'assertion=' . $assert . '&audience=' .
urlencode (Url::display () . ':80');
$ch = curl_init ();
$options = array (
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_POST => 2,
CURLOPT_POSTFIELDS => $params
);
curl_setopt_array ($ch, $options);
$result = curl_exec ($ch);
curl_close ($ch);
$res = json_decode ($result, true);
if ($res['status'] == 'okay' && $res['email'] == $this->view->conf->mailLogin ()) {
Session::_param ('mail', $res['email']);
} else {
$res = array ();
$res['status'] = 'failure';
$res['reason'] = 'L\'identifiant est invalide';
}
$this->view->res = json_encode ($res);
}
public function logoutAction () {
$this->view->_useLayout (false);
Session::_param ('mail');
}
private function initFilter () {
$get = Request::param ('get');
$this->view->get_c = false;
$this->view->get_f = false;
$typeGet = $get[0];
$filter = substr ($get, 2);
if ($get == 'favoris') {
$this->view->get_c = $get;
$this->get = array (
'type' => $get,
'filter' => $get
);
} elseif ($get == false) {
$this->get = array (
'type' => 'all',
'filter' => 'all'
);
} else {
if ($typeGet == 'f') {
$this->view->get_f = $filter;
$this->get = array (
'type' => $typeGet,
'filter' => $filter
);
} elseif ($typeGet == 'c') {
$this->view->get_c = $filter;
$this->get = array (
'type' => $typeGet,
'filter' => $filter
);
} else {
$this->get = false;
}
}
}
private function countNotRead () {
$entryDAO = new EntryDAO ();
if ($this->get != false) {
if ($this->get['type'] == 'all') {
$this->nb_not_read = $this->view->nb_not_read;
} elseif ($this->get['type'] == 'favoris') {
$this->nb_not_read = $entryDAO->countNotReadFavorites ();
} elseif ($this->get['type'] == 'c') {
$this->nb_not_read = $entryDAO->countNotReadByCat ($this->get['filter']);
} elseif ($this->get['type'] == 'f') {
$this->nb_not_read = $entryDAO->countNotReadByFeed ($this->get['filter']);
}
}
}
private function initCurrentMode () {
$default_view = $this->view->conf->defaultView ();
$mode = Session::param ('mode');
if ($mode == false) {
if ($default_view == 'not_read' && $this->nb_not_read < 1) {
$mode = 'all';
} else {
$mode = $default_view;
}
}
$this->mode = $mode;
}
}
|