]>
Commit | Line | Data |
---|---|---|
eb1af592 NL |
1 | <?php |
2 | /** | |
c95b78a8 | 3 | * wallabag, self hostable application allowing you to not miss any content anymore |
eb1af592 | 4 | * |
c95b78a8 NL |
5 | * @category wallabag |
6 | * @author Nicolas Lœuillet <nicolas@loeuillet.org> | |
eb1af592 | 7 | * @copyright 2013 |
3602405e | 8 | * @license http://opensource.org/licenses/MIT see COPYING file |
eb1af592 NL |
9 | */ |
10 | ||
11 | class Poche | |
12 | { | |
3602405e NL |
13 | /** |
14 | * @var User | |
15 | */ | |
7ce7ec4c | 16 | public $user; |
3602405e NL |
17 | /** |
18 | * @var Database | |
19 | */ | |
eb1af592 | 20 | public $store; |
3602405e NL |
21 | /** |
22 | * @var Template | |
23 | */ | |
eb1af592 | 24 | public $tpl; |
3602405e NL |
25 | /** |
26 | * @var Language | |
27 | */ | |
28 | public $language; | |
29 | /** | |
30 | * @var Routing | |
31 | */ | |
32 | public $routing; | |
33 | /** | |
34 | * @var Messages | |
35 | */ | |
55821e04 | 36 | public $messages; |
3602405e NL |
37 | /** |
38 | * @var Paginator | |
39 | */ | |
6a361945 | 40 | public $pagination; |
182faf26 | 41 | |
00dbaf90 | 42 | public function __construct() |
eb1af592 | 43 | { |
3602405e | 44 | $this->init(); |
eb1af592 | 45 | } |
182faf26 MR |
46 | |
47 | private function init() | |
00dbaf90 NL |
48 | { |
49 | Tools::initPhp(); | |
eb1af592 | 50 | |
3602405e NL |
51 | $pocheUser = Session::getParam('poche_user'); |
52 | ||
53 | if ($pocheUser && $pocheUser != array()) { | |
54 | $this->user = $pocheUser; | |
00dbaf90 | 55 | } else { |
3602405e | 56 | // fake user, just for install & login screens |
00dbaf90 NL |
57 | $this->user = new User(); |
58 | $this->user->setConfig($this->getDefaultConfig()); | |
59 | } | |
60 | ||
3602405e NL |
61 | $this->pagination = new Paginator($this->user->getConfigValue('pager'), 'p'); |
62 | $this->language = new Language($this); | |
63 | $this->tpl = new Template($this); | |
64 | $this->store = new Database(); | |
65 | $this->messages = new Messages(); | |
66 | $this->routing = new Routing($this); | |
00dbaf90 | 67 | } |
182faf26 | 68 | |
3602405e NL |
69 | public function run() |
70 | { | |
71 | $this->routing->run(); | |
00dbaf90 | 72 | } |
182faf26 | 73 | |
4a291288 | 74 | /** |
3602405e | 75 | * Creates a new user |
4a291288 | 76 | */ |
3e1daa4c | 77 | public function createNewUser($username, $password, $email = "", $internalRegistration = false) |
eb1af592 | 78 | { |
121691e9 | 79 | Tools::logm('Trying to create a new user...'); |
2f26729c NL |
80 | if (!empty($username) && !empty($password)){ |
81 | $newUsername = filter_var($username, FILTER_SANITIZE_STRING); | |
046b9316 | 82 | $email = filter_var($email, FILTER_SANITIZE_STRING); |
2f26729c | 83 | if (!$this->store->userExists($newUsername)){ |
046b9316 | 84 | if ($this->store->install($newUsername, Tools::encodeString($password . $newUsername), $email)) { |
6cb5e1c9 TC |
85 | if ($email != "") { // if email is filled |
86 | if (SEND_CONFIRMATION_EMAIL && function_exists('mail')) { | |
87 | ||
698eda73 | 88 | // if internal registration from config screen |
6cb5e1c9 TC |
89 | $body_internal = _('Hi,') . "\r\n\r\n" . sprintf(_('Someone just created a wallabag account for you on %1$s.'), Tools::getPocheUrl()) . |
90 | "\r\n\r\n" . sprintf(_('Your login is %1$s.'), $newUsername) ."\r\n\r\n" . | |
91 | _('Note : The password has been chosen by the person who created your account. Get in touch with that person to know your password and change it as soon as possible') . "\r\n\r\n" . | |
92 | _('Have fun with it !') . "\r\n\r\n" . | |
93 | _('This is an automatically generated message, no one will answer if you respond to it.'); | |
3e1daa4c | 94 | |
6cb5e1c9 | 95 | // if external (public) registration |
f2321633 TC |
96 | $body = sprintf(_('Hi, %1$s'), $newUsername) . "\r\n\r\n" . |
97 | sprintf(_('You\'ve just created a wallabag account on %1$s.'), Tools::getPocheUrl()) . | |
98 | "\r\n\r\n" . _("Have fun with it !"); | |
698eda73 | 99 | |
6cb5e1c9 TC |
100 | $body = $internalRegistration ? $body_internal : $body; |
101 | ||
102 | $body = wordwrap($body, 70, "\r\n"); // cut lines with more than 70 caracters (MIME standard) | |
103 | if (mail($email, sprintf(_('Your new wallabag account on %1$s'), Tools::getPocheUrl()), $body, | |
104 | 'X-Mailer: PHP/' . phpversion() . "\r\n" . | |
105 | 'Content-type: text/plain; charset=UTF-8' . "\r\n" . | |
106 | "From: " . $newUsername . "@" . gethostname() . "\r\n")) { | |
107 | Tools::logm('The user ' . $newUsername . ' has been emailed'); | |
108 | $this->messages->add('i', sprintf(_('The new user %1$s has been sent an email at %2$s. You may have to check spam folder.'), $newUsername, $email)); | |
698eda73 | 109 | Tools::redirect('?'); |
6cb5e1c9 TC |
110 | |
111 | } else { | |
112 | Tools::logm('A problem has been encountered while sending an email'); | |
113 | $this->messages->add('e', _('A problem has been encountered while sending an email')); | |
114 | } | |
3e1daa4c | 115 | } else { |
6cb5e1c9 | 116 | Tools::logm('The user has been created, but the server did not authorize sending emails'); |
952faeeb | 117 | $this->messages->add('i', _('The server did not authorize sending a confirmation email, but the user was created.')); |
3e1daa4c | 118 | } |
6cb5e1c9 TC |
119 | } else { |
120 | Tools::logm('The user has been created, but no email was saved, so no confimation email was sent'); | |
121 | $this->messages->add('i', _('The user was created, but no email was sent because email was not filled in')); | |
122 | } | |
3e1daa4c | 123 | Tools::logm('The new user ' . $newUsername . ' has been installed'); |
f2321633 TC |
124 | if (\Session::isLogged()) { |
125 | $this->messages->add('s', sprintf(_('The new user %s has been installed. Do you want to <a href="?logout">logout ?</a>'), $newUsername)); | |
126 | } | |
3e1daa4c | 127 | Tools::redirect(); |
4d99bae8 | 128 | } |
129 | else { | |
2f26729c | 130 | Tools::logm('error during adding new user'); |
4d99bae8 | 131 | Tools::redirect(); |
132 | } | |
133 | } | |
2f26729c NL |
134 | else { |
135 | $this->messages->add('e', sprintf(_('Error : An user with the name %s already exists !'), $newUsername)); | |
136 | Tools::logm('An user with the name ' . $newUsername . ' already exists !'); | |
137 | Tools::redirect(); | |
138 | } | |
4d99bae8 | 139 | } |
121691e9 TC |
140 | else { |
141 | Tools::logm('Password or username were empty'); | |
142 | } | |
4d99bae8 | 143 | } |
b6413975 | 144 | |
3602405e NL |
145 | /** |
146 | * Delete an existing user | |
147 | */ | |
2f26729c | 148 | public function deleteUser($password) |
3602405e | 149 | { |
2f26729c NL |
150 | if ($this->store->listUsers() > 1) { |
151 | if (Tools::encodeString($password . $this->user->getUsername()) == $this->store->getUserPassword($this->user->getId())) { | |
152 | $username = $this->user->getUsername(); | |
153 | $this->store->deleteUserConfig($this->user->getId()); | |
154 | Tools::logm('The configuration for user '. $username .' has been deleted !'); | |
155 | $this->store->deleteTagsEntriesAndEntries($this->user->getId()); | |
156 | Tools::logm('The entries for user '. $username .' has been deleted !'); | |
157 | $this->store->deleteUser($this->user->getId()); | |
158 | Tools::logm('User '. $username .' has been completely deleted !'); | |
159 | Session::logout(); | |
160 | Tools::logm('logout'); | |
161 | Tools::redirect(); | |
162 | $this->messages->add('s', sprintf(_('User %s has been successfully deleted !'), $username)); | |
4d99bae8 | 163 | } |
164 | else { | |
2f26729c NL |
165 | Tools::logm('Bad password !'); |
166 | $this->messages->add('e', _('Error : The password is wrong !')); | |
4d99bae8 | 167 | } |
168 | } | |
2f26729c NL |
169 | else { |
170 | Tools::logm('Only user !'); | |
171 | $this->messages->add('e', _('Error : You are the only user, you cannot delete your account !')); | |
172 | } | |
4d99bae8 | 173 | } |
eb1af592 | 174 | |
8d3275be | 175 | public function getDefaultConfig() |
182faf26 | 176 | { |
8d3275be NL |
177 | return array( |
178 | 'pager' => PAGINATION, | |
179 | 'language' => LANG, | |
00dbaf90 NL |
180 | 'theme' => DEFAULT_THEME |
181 | ); | |
8d3275be NL |
182 | } |
183 | ||
eb1af592 NL |
184 | /** |
185 | * Call action (mark as fav, archive, delete, etc.) | |
186 | */ | |
926acd7b | 187 | public function action($action, Url $url, $id = 0, $import = FALSE, $autoclose = FALSE, $tags = null) |
eb1af592 NL |
188 | { |
189 | switch ($action) | |
190 | { | |
191 | case 'add': | |
a297fb1e MR |
192 | $content = Tools::getPageContent($url); |
193 | $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'); | |
194 | $body = $content['rss']['channel']['item']['description']; | |
195 | ||
196 | // clean content from prevent xss attack | |
2f26729c | 197 | $purifier = $this->_getPurifier(); |
a297fb1e MR |
198 | $title = $purifier->purify($title); |
199 | $body = $purifier->purify($body); | |
1570a653 | 200 | |
182faf26 | 201 | //search for possible duplicate |
8d7cd2cc | 202 | $duplicate = NULL; |
8cebef88 | 203 | $clean_url = $url->getUrl(); |
488fc63b | 204 | |
8cebef88 TC |
205 | // Clean URL to remove parameters from feedburner and all this stuff. Taken from Shaarli. |
206 | $i=strpos($clean_url,'&utm_source='); if ($i!==false) $clean_url=substr($clean_url,0,$i); | |
207 | $i=strpos($clean_url,'?utm_source='); if ($i!==false) $clean_url=substr($clean_url,0,$i); | |
208 | $i=strpos($clean_url,'#xtor=RSS-'); if ($i!==false) $clean_url=substr($clean_url,0,$i); | |
209 | ||
210 | $duplicate = $this->store->retrieveOneByURL($clean_url, $this->user->getId()); | |
211 | ||
212 | $last_id = $this->store->add($clean_url, $title, $body, $this->user->getId()); | |
a297fb1e | 213 | if ( $last_id ) { |
8cebef88 | 214 | Tools::logm('add link ' . $clean_url); |
ec397236 | 215 | if (DOWNLOAD_PICTURES) { |
8cebef88 | 216 | $content = Picture::filterPicture($body, $clean_url, $last_id); |
ec397236 NL |
217 | Tools::logm('updating content article'); |
218 | $this->store->updateContent($last_id, $content, $this->user->getId()); | |
219 | } | |
488fc63b MR |
220 | |
221 | if ($duplicate != NULL) { | |
222 | // duplicate exists, so, older entry needs to be deleted (as new entry should go to the top of list), BUT favorite mark and tags should be preserved | |
8cebef88 | 223 | Tools::logm('link ' . $clean_url . ' is a duplicate'); |
488fc63b MR |
224 | // 1) - preserve tags and favorite, then drop old entry |
225 | $this->store->reassignTags($duplicate['id'], $last_id); | |
226 | if ($duplicate['is_fav']) { | |
227 | $this->store->favoriteById($last_id, $this->user->getId()); | |
228 | } | |
229 | if ($this->store->deleteById($duplicate['id'], $this->user->getId())) { | |
8cebef88 | 230 | Tools::logm('previous link ' . $clean_url .' entry deleted'); |
488fc63b MR |
231 | } |
232 | } | |
233 | ||
7f782e44 | 234 | // if there are tags, add them to the new article |
235 | if (isset($_GET['tags'])) { | |
236 | $_POST['value'] = $_GET['tags']; | |
237 | $_POST['entry_id'] = $last_id; | |
238 | $this->action('add_tag', $url); | |
239 | } | |
240 | ||
182faf26 | 241 | $this->messages->add('s', _('the link has been added successfully')); |
eb1af592 NL |
242 | } |
243 | else { | |
a297fb1e | 244 | $this->messages->add('e', _('error during insertion : the link wasn\'t added')); |
8cebef88 | 245 | Tools::logm('error during insertion : the link wasn\'t added ' . $clean_url); |
b916bcfc | 246 | } |
ec397236 | 247 | |
a297fb1e | 248 | if ($autoclose == TRUE) { |
1c911789 | 249 | Tools::redirect('?view=home&closewin=true'); |
a297fb1e | 250 | } else { |
1c911789 | 251 | Tools::redirect('?view=home'); |
eb1af592 | 252 | } |
3052cfb7 | 253 | return $last_id; |
eb1af592 NL |
254 | break; |
255 | case 'delete': | |
512e5e5b | 256 | if (isset($_GET['search'])) { |
257 | //when we want to apply a delete to a search | |
258 | $tags = array($_GET['search']); | |
259 | $allentry_ids = $this->store->search($tags[0], $this->user->getId()); | |
260 | $entry_ids = array(); | |
261 | foreach ($allentry_ids as $eachentry) { | |
262 | $entry_ids[] = $eachentry[0]; | |
eb1af592 | 263 | } |
512e5e5b | 264 | } else { // delete a single article |
265 | $entry_ids = array($id); | |
eb1af592 | 266 | } |
512e5e5b | 267 | foreach($entry_ids as $id) { |
268 | $msg = 'delete link #' . $id; | |
269 | if ($this->store->deleteById($id, $this->user->getId())) { | |
270 | if (DOWNLOAD_PICTURES) { | |
271 | Picture::removeDirectory(ABS_PATH . $id); | |
272 | } | |
273 | $this->messages->add('s', _('the link has been deleted successfully')); | |
274 | } | |
275 | else { | |
276 | $this->messages->add('e', _('the link wasn\'t deleted')); | |
277 | $msg = 'error : can\'t delete link #' . $id; | |
278 | } | |
279 | Tools::logm($msg); | |
eb1af592 | 280 | } |
985ce3ec | 281 | Tools::redirect('?'); |
eb1af592 NL |
282 | break; |
283 | case 'toggle_fav' : | |
8d3275be | 284 | $this->store->favoriteById($id, $this->user->getId()); |
eb1af592 | 285 | Tools::logm('mark as favorite link #' . $id); |
c2cf7075 MR |
286 | if ( Tools::isAjaxRequest() ) { |
287 | echo 1; | |
288 | exit; | |
289 | } | |
290 | else { | |
291 | Tools::redirect(); | |
292 | } | |
eb1af592 NL |
293 | break; |
294 | case 'toggle_archive' : | |
13c7f9a4 | 295 | if (isset($_GET['tag_id'])) { |
296 | //when we want to archive a whole tag | |
297 | $tag_id = $_GET['tag_id']; | |
298 | $allentry_ids = $this->store->retrieveEntriesByTag($tag_id, $this->user->getId()); | |
299 | $entry_ids = array(); | |
300 | foreach ($allentry_ids as $eachentry) { | |
301 | $entry_ids[] = $eachentry[0]; | |
302 | } | |
303 | } else { //archive a single article | |
304 | $entry_ids = array($id); | |
305 | } | |
306 | foreach($entry_ids as $id) { | |
307 | $this->store->archiveById($id, $this->user->getId()); | |
308 | Tools::logm('archive link #' . $id); | |
309 | } | |
c2cf7075 MR |
310 | if ( Tools::isAjaxRequest() ) { |
311 | echo 1; | |
312 | exit; | |
059a3380 | 313 | } else { |
c2cf7075 MR |
314 | Tools::redirect(); |
315 | } | |
eb1af592 | 316 | break; |
059a3380 | 317 | case 'archive_and_next' : |
8a66458b | 318 | $nextid = $this->store->getPreviousArticle($id, $this->user->getId()); |
059a3380 TC |
319 | $this->store->archiveById($id, $this->user->getId()); |
320 | Tools::logm('archive link #' . $id); | |
321 | Tools::redirect('?view=view&id=' . $nextid); | |
322 | break; | |
f14807de NL |
323 | case 'archive_all' : |
324 | $this->store->archiveAll($this->user->getId()); | |
325 | Tools::logm('archive all links'); | |
a297fb1e | 326 | Tools::redirect(); |
f14807de | 327 | break; |
c432fa16 | 328 | case 'add_tag' : |
decc23aa | 329 | if (isset($_GET['search'])) { |
330 | //when we want to apply a tag to a search | |
decc23aa | 331 | $tags = array($_GET['search']); |
332 | $allentry_ids = $this->store->search($tags[0], $this->user->getId()); | |
333 | $entry_ids = array(); | |
334 | foreach ($allentry_ids as $eachentry) { | |
335 | $entry_ids[] = $eachentry[0]; | |
336 | } | |
337 | } else { //add a tag to a single article | |
338 | $tags = explode(',', $_POST['value']); | |
339 | $entry_ids = array($_POST['entry_id']); | |
fb26cc93 | 340 | } |
decc23aa | 341 | foreach($entry_ids as $entry_id) { |
342 | $entry = $this->store->retrieveOneById($entry_id, $this->user->getId()); | |
343 | if (!$entry) { | |
344 | $this->messages->add('e', _('Article not found!')); | |
345 | Tools::logm('error : article not found'); | |
346 | Tools::redirect(); | |
347 | } | |
348 | //get all already set tags to preven duplicates | |
349 | $already_set_tags = array(); | |
350 | $entry_tags = $this->store->retrieveTagsByEntry($entry_id); | |
351 | foreach ($entry_tags as $tag) { | |
352 | $already_set_tags[] = $tag['value']; | |
353 | } | |
354 | foreach($tags as $key => $tag_value) { | |
355 | $value = trim($tag_value); | |
356 | if ($value && !in_array($value, $already_set_tags)) { | |
357 | $tag = $this->store->retrieveTagByValue($value); | |
358 | if (is_null($tag)) { | |
359 | # we create the tag | |
360 | $tag = $this->store->createTag($value); | |
361 | $sequence = ''; | |
362 | if (STORAGE == 'postgres') { | |
363 | $sequence = 'tags_id_seq'; | |
364 | } | |
365 | $tag_id = $this->store->getLastId($sequence); | |
fb26cc93 | 366 | } |
decc23aa | 367 | else { |
368 | $tag_id = $tag['id']; | |
369 | } | |
370 | ||
371 | # we assign the tag to the article | |
372 | $this->store->setTagToEntry($tag_id, $entry_id); | |
373 | } | |
c432fa16 | 374 | } |
c432fa16 | 375 | } |
9c743ab9 | 376 | $this->messages->add('s', _('The tag has been applied successfully')); |
24696800 | 377 | Tools::logm('The tag has been applied successfully'); |
a297fb1e | 378 | Tools::redirect(); |
c432fa16 NL |
379 | break; |
380 | case 'remove_tag' : | |
381 | $tag_id = $_GET['tag_id']; | |
b89d5a2b NL |
382 | $entry = $this->store->retrieveOneById($id, $this->user->getId()); |
383 | if (!$entry) { | |
384 | $this->messages->add('e', _('Article not found!')); | |
385 | Tools::logm('error : article not found'); | |
386 | Tools::redirect(); | |
387 | } | |
c432fa16 | 388 | $this->store->removeTagForEntry($id, $tag_id); |
9c743ab9 | 389 | Tools::logm('tag entry deleted'); |
24696800 | 390 | if ($this->store->cleanUnusedTag($tag_id)) { |
391 | Tools::logm('tag deleted'); | |
392 | } | |
9c743ab9 | 393 | $this->messages->add('s', _('The tag has been successfully deleted')); |
c432fa16 NL |
394 | Tools::redirect(); |
395 | break; | |
d4b6e20e | 396 | |
44b95cb8 TC |
397 | case 'reload_article' : |
398 | Tools::logm('reload article'); | |
399 | $id = $_GET['id']; | |
400 | $entry = $this->store->retrieveOneById($id, $this->user->getId()); | |
401 | Tools::logm('reload url ' . $entry['url']); | |
402 | $url = new Url(base64_encode($entry['url'])); | |
403 | $this->action('add', $url); | |
404 | break; | |
405 | ||
e51487f9 TC |
406 | /* For some unknown reason I can't get displayView() to work here (it redirects to home view afterwards). So here's a dirty fix which redirects directly to URL */ |
407 | case 'random': | |
e51487f9 | 408 | Tools::logm('get a random article'); |
cdee5e65 | 409 | if ($this->store->getRandomId($this->user->getId())) { |
336797f3 TC |
410 | $id_array = $this->store->getRandomId($this->user->getId()); |
411 | $id = $id_array[0]; | |
cdee5e65 TC |
412 | Tools::redirect('?view=view&id=' . $id[0]); |
413 | Tools::logm('got the article with id ' . $id[0]); | |
414 | } | |
e51487f9 | 415 | break; |
eb1af592 NL |
416 | default: |
417 | break; | |
418 | } | |
419 | } | |
420 | ||
421 | function displayView($view, $id = 0) | |
422 | { | |
423 | $tpl_vars = array(); | |
424 | ||
425 | switch ($view) | |
426 | { | |
3c133bff NL |
427 | case 'about': |
428 | break; | |
eb1af592 | 429 | case 'config': |
2f26729c | 430 | $dev_infos = $this->_getPocheVersion('dev'); |
11c680f9 NL |
431 | $dev = trim($dev_infos[0]); |
432 | $check_time_dev = date('d-M-Y H:i', $dev_infos[1]); | |
2f26729c | 433 | $prod_infos = $this->_getPocheVersion('prod'); |
11c680f9 NL |
434 | $prod = trim($prod_infos[0]); |
435 | $check_time_prod = date('d-M-Y H:i', $prod_infos[1]); | |
031df528 NL |
436 | $compare_dev = version_compare(POCHE, $dev); |
437 | $compare_prod = version_compare(POCHE, $prod); | |
3602405e NL |
438 | $themes = $this->tpl->getInstalledThemes(); |
439 | $languages = $this->language->getInstalledLanguages(); | |
72c20a52 | 440 | $token = $this->user->getConfigValue('token'); |
1810c13b | 441 | $http_auth = (isset($_SERVER['PHP_AUTH_USER']) || isset($_SERVER['REMOTE_USER'])) ? true : false; |
4d99bae8 | 442 | $only_user = ($this->store->listUsers() > 1) ? false : true; |
32520785 | 443 | $tpl_vars = array( |
00dbaf90 | 444 | 'themes' => $themes, |
5011388f | 445 | 'languages' => $languages, |
32520785 NL |
446 | 'dev' => $dev, |
447 | 'prod' => $prod, | |
11c680f9 NL |
448 | 'check_time_dev' => $check_time_dev, |
449 | 'check_time_prod' => $check_time_prod, | |
32520785 NL |
450 | 'compare_dev' => $compare_dev, |
451 | 'compare_prod' => $compare_prod, | |
72c20a52 NL |
452 | 'token' => $token, |
453 | 'user_id' => $this->user->getId(), | |
df6afaf0 | 454 | 'http_auth' => $http_auth, |
4d99bae8 | 455 | 'only_user' => $only_user |
32520785 | 456 | ); |
eb1af592 NL |
457 | Tools::logm('config view'); |
458 | break; | |
6cab59c3 NL |
459 | case 'edit-tags': |
460 | # tags | |
b89d5a2b NL |
461 | $entry = $this->store->retrieveOneById($id, $this->user->getId()); |
462 | if (!$entry) { | |
463 | $this->messages->add('e', _('Article not found!')); | |
464 | Tools::logm('error : article not found'); | |
465 | Tools::redirect(); | |
466 | } | |
6cab59c3 | 467 | $tags = $this->store->retrieveTagsByEntry($id); |
512ff180 | 468 | $all_tags = $this->store->retrieveAllTags($this->user->getId()); |
ab87a7fe TC |
469 | $maximus = 0; |
470 | foreach ($all_tags as $eachtag) { // search for the most times a tag is present | |
471 | if ($eachtag["entriescount"] > $maximus) $maximus = $eachtag["entriescount"]; | |
472 | } | |
473 | foreach ($all_tags as $key => $eachtag) { // get the percentage of presence of each tag | |
474 | $percent = floor(($eachtag["entriescount"] / $maximus) * 100); | |
475 | ||
476 | if ($percent < 20): // assign a css class, depending on the number of entries count | |
477 | $cssclass = 'smallesttag'; | |
478 | elseif ($percent >= 20 and $percent < 40): | |
479 | $cssclass = 'smalltag'; | |
480 | elseif ($percent >= 40 and $percent < 60): | |
481 | $cssclass = 'mediumtag'; | |
482 | elseif ($percent >= 60 and $percent < 80): | |
483 | $cssclass = 'largetag'; | |
484 | else: | |
485 | $cssclass = 'largesttag'; | |
486 | endif; | |
487 | $all_tags[$key]['cssclass'] = $cssclass; | |
488 | } | |
6cab59c3 | 489 | $tpl_vars = array( |
c432fa16 | 490 | 'entry_id' => $id, |
6cab59c3 | 491 | 'tags' => $tags, |
512ff180 | 492 | 'alltags' => $all_tags, |
032e0ca1 | 493 | 'entry' => $entry, |
4886ed6d NL |
494 | ); |
495 | break; | |
2e2ebe5e | 496 | case 'tags': |
f778e472 | 497 | $token = $this->user->getConfigValue('token'); |
fb26cc93 MR |
498 | //if term is set - search tags for this term |
499 | $term = Tools::checkVar('term'); | |
500 | $tags = $this->store->retrieveAllTags($this->user->getId(), $term); | |
501 | if (Tools::isAjaxRequest()) { | |
502 | $result = array(); | |
503 | foreach ($tags as $tag) { | |
504 | $result[] = $tag['value']; | |
505 | } | |
506 | echo json_encode($result); | |
507 | exit; | |
508 | } | |
2e2ebe5e | 509 | $tpl_vars = array( |
f778e472 NL |
510 | 'token' => $token, |
511 | 'user_id' => $this->user->getId(), | |
2e2ebe5e NL |
512 | 'tags' => $tags, |
513 | ); | |
514 | break; | |
a4585f7e MR |
515 | case 'search': |
516 | if (isset($_GET['search'])) { | |
517 | $search = filter_var($_GET['search'], FILTER_SANITIZE_STRING); | |
518 | $tpl_vars['entries'] = $this->store->search($search, $this->user->getId()); | |
519 | $count = count($tpl_vars['entries']); | |
520 | $this->pagination->set_total($count); | |
521 | $page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')), | |
522 | $this->pagination->page_links('?view=' . $view . '?search=' . $search . '&sort=' . $_SESSION['sort'] . '&' )); | |
523 | $tpl_vars['page_links'] = $page_links; | |
524 | $tpl_vars['nb_results'] = $count; | |
1b6e21d7 | 525 | $tpl_vars['searchterm'] = $search; |
a4585f7e MR |
526 | } |
527 | break; | |
eb1af592 | 528 | case 'view': |
8d3275be | 529 | $entry = $this->store->retrieveOneById($id, $this->user->getId()); |
eb1af592 NL |
530 | if ($entry != NULL) { |
531 | Tools::logm('view link #' . $id); | |
532 | $content = $entry['content']; | |
533 | if (function_exists('tidy_parse_string')) { | |
534 | $tidy = tidy_parse_string($content, array('indent'=>true, 'show-body-only' => true), 'UTF8'); | |
535 | $tidy->cleanRepair(); | |
536 | $content = $tidy->value; | |
3408ed48 | 537 | } |
a3223127 | 538 | |
3408ed48 | 539 | # flattr checking |
37cad522 TC |
540 | $flattr = NULL; |
541 | if (FLATTR) { | |
542 | $flattr = new FlattrItem(); | |
543 | $flattr->checkItem($entry['url'], $entry['id']); | |
544 | } | |
545 | ||
059a3380 TC |
546 | # previous and next |
547 | $previous = FALSE; | |
548 | $previous_id = $this->store->getPreviousArticle($id, $this->user->getId()); | |
549 | $next = FALSE; | |
550 | $next_id = $this->store->getNextArticle($id, $this->user->getId()); | |
551 | ||
552 | if ($this->store->retrieveOneById($previous_id, $this->user->getId())) { | |
553 | $previous = TRUE; | |
554 | } | |
555 | if ($this->store->retrieveOneById($next_id, $this->user->getId())) { | |
556 | $next = TRUE; | |
557 | } | |
558 | $navigate = $arrayName = array('previous' => $previous, 'previousid' => $previous_id, 'next' => $next, 'nextid' => $next_id); | |
559 | ||
7b171c73 NL |
560 | # tags |
561 | $tags = $this->store->retrieveTagsByEntry($entry['id']); | |
a3223127 | 562 | |
3408ed48 | 563 | $tpl_vars = array( |
7b171c73 NL |
564 | 'entry' => $entry, |
565 | 'content' => $content, | |
566 | 'flattr' => $flattr, | |
059a3380 TC |
567 | 'tags' => $tags, |
568 | 'navigate' => $navigate | |
3408ed48 | 569 | ); |
eb1af592 NL |
570 | } |
571 | else { | |
d8d1542e | 572 | Tools::logm('error in view call : entry is null'); |
eb1af592 NL |
573 | } |
574 | break; | |
032e0ca1 | 575 | default: # home, favorites, archive and tag views |
eb1af592 | 576 | $tpl_vars = array( |
3eb04903 N |
577 | 'entries' => '', |
578 | 'page_links' => '', | |
7f9f5281 | 579 | 'nb_results' => '', |
6065553c | 580 | 'listmode' => (isset($_COOKIE['listmode']) ? true : false), |
eb1af592 | 581 | ); |
182faf26 | 582 | |
3602405e | 583 | //if id is given - we retrieve entries by tag: id is tag id |
032e0ca1 MR |
584 | if ($id) { |
585 | $tpl_vars['tag'] = $this->store->retrieveTag($id, $this->user->getId()); | |
586 | $tpl_vars['id'] = intval($id); | |
587 | } | |
588 | ||
589 | $count = $this->store->getEntriesByViewCount($view, $this->user->getId(), $id); | |
590 | ||
591 | if ($count > 0) { | |
592 | $this->pagination->set_total($count); | |
c515ffec | 593 | $page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')), |
032e0ca1 MR |
594 | $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . (($id)?'&id='.$id:'') . '&' )); |
595 | $tpl_vars['entries'] = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit(), $id); | |
3eb04903 | 596 | $tpl_vars['page_links'] = $page_links; |
032e0ca1 | 597 | $tpl_vars['nb_results'] = $count; |
3eb04903 | 598 | } |
6a361945 | 599 | Tools::logm('display ' . $view . ' view'); |
eb1af592 NL |
600 | break; |
601 | } | |
602 | ||
603 | return $tpl_vars; | |
604 | } | |
c765c367 | 605 | |
07ee09f4 | 606 | /** |
182faf26 MR |
607 | * update the password of the current user. |
608 | * if MODE_DEMO is TRUE, the password can't be updated. | |
07ee09f4 NL |
609 | * @todo add the return value |
610 | * @todo set the new password in function header like this updatePassword($newPassword) | |
611 | * @return boolean | |
612 | */ | |
2f26729c | 613 | public function updatePassword($password, $confirmPassword) |
c765c367 | 614 | { |
55821e04 | 615 | if (MODE_DEMO) { |
8d3275be | 616 | $this->messages->add('i', _('in demo mode, you can\'t update your password')); |
55821e04 | 617 | Tools::logm('in demo mode, you can\'t do this'); |
6a361945 | 618 | Tools::redirect('?view=config'); |
55821e04 NL |
619 | } |
620 | else { | |
2f26729c NL |
621 | if (isset($password) && isset($confirmPassword)) { |
622 | if ($password == $confirmPassword && !empty($password)) { | |
8d3275be | 623 | $this->messages->add('s', _('your password has been updated')); |
2f26729c | 624 | $this->store->updatePassword($this->user->getId(), Tools::encodeString($password . $this->user->getUsername())); |
c765c367 | 625 | Session::logout(); |
8d3275be | 626 | Tools::logm('password updated'); |
c765c367 NL |
627 | Tools::redirect(); |
628 | } | |
629 | else { | |
8d3275be | 630 | $this->messages->add('e', _('the two fields have to be filled & the password must be the same in the two fields')); |
6a361945 | 631 | Tools::redirect('?view=config'); |
c765c367 NL |
632 | } |
633 | } | |
634 | } | |
635 | } | |
182faf26 | 636 | |
df6afaf0 | 637 | /** |
2f26729c NL |
638 | * Get credentials from differents sources |
639 | * It redirects the user to the $referer link | |
640 | * | |
df6afaf0 DS |
641 | * @return array |
642 | */ | |
2f26729c NL |
643 | private function credentials() |
644 | { | |
645 | if (isset($_SERVER['PHP_AUTH_USER'])) { | |
646 | return array($_SERVER['PHP_AUTH_USER'], 'php_auth', true); | |
1810c13b | 647 | } |
2f26729c NL |
648 | if (!empty($_POST['login']) && !empty($_POST['password'])) { |
649 | return array($_POST['login'], $_POST['password'], false); | |
1810c13b | 650 | } |
2f26729c NL |
651 | if (isset($_SERVER['REMOTE_USER'])) { |
652 | return array($_SERVER['REMOTE_USER'], 'http_auth', true); | |
1810c13b | 653 | } |
5cfafc61 | 654 | |
2f26729c | 655 | return array(false, false, false); |
6af66b11 | 656 | } |
df6afaf0 | 657 | |
07ee09f4 NL |
658 | /** |
659 | * checks if login & password are correct and save the user in session. | |
660 | * it redirects the user to the $referer link | |
661 | * @param string $referer the url to redirect after login | |
662 | * @todo add the return value | |
663 | * @return boolean | |
664 | */ | |
c765c367 NL |
665 | public function login($referer) |
666 | { | |
6af66b11 | 667 | list($login,$password,$isauthenticated)=$this->credentials(); |
df6afaf0 DS |
668 | if($login === false || $password === false) { |
669 | $this->messages->add('e', _('login failed: you have to fill all fields')); | |
670 | Tools::logm('login failed'); | |
671 | Tools::redirect(); | |
672 | } | |
673 | if (!empty($login) && !empty($password)) { | |
6af66b11 | 674 | $user = $this->store->login($login, Tools::encodeString($password . $login), $isauthenticated); |
7ce7ec4c NL |
675 | if ($user != array()) { |
676 | # Save login into Session | |
6af66b11 MR |
677 | $longlastingsession = isset($_POST['longlastingsession']); |
678 | $passwordTest = ($isauthenticated) ? $user['password'] : Tools::encodeString($password . $login); | |
679 | Session::login($user['username'], $user['password'], $login, $passwordTest, $longlastingsession, array('poche_user' => new User($user))); | |
9cf6bac1 NL |
680 | |
681 | # reload l10n | |
682 | $language = $user['config']['language']; | |
683 | @putenv('LC_ALL=' . $language); | |
684 | setlocale(LC_ALL, $language); | |
685 | bindtextdomain($language, LOCALE); | |
686 | textdomain($language); | |
687 | ||
26929c08 | 688 | $this->messages->add('s', _('welcome to your wallabag')); |
8d3275be | 689 | Tools::logm('login successful'); |
c765c367 NL |
690 | Tools::redirect($referer); |
691 | } | |
8d3275be | 692 | $this->messages->add('e', _('login failed: bad login or password')); |
c86b40f0 GV |
693 | // log login failure in web server log to allow fail2ban usage |
694 | error_log('user '.$login.' authentication failure'); | |
c765c367 NL |
695 | Tools::logm('login failed'); |
696 | Tools::redirect(); | |
c765c367 NL |
697 | } |
698 | } | |
699 | ||
07ee09f4 NL |
700 | /** |
701 | * log out the poche user. It cleans the session. | |
702 | * @todo add the return value | |
182faf26 | 703 | * @return boolean |
07ee09f4 | 704 | */ |
c765c367 NL |
705 | public function logout() |
706 | { | |
7ce7ec4c | 707 | $this->user = array(); |
c765c367 | 708 | Session::logout(); |
b916bcfc | 709 | Tools::logm('logout'); |
c765c367 NL |
710 | Tools::redirect(); |
711 | } | |
712 | ||
07ee09f4 | 713 | /** |
2f26729c | 714 | * import datas into your wallabag |
182faf26 | 715 | * @return boolean |
07ee09f4 | 716 | */ |
2f26729c | 717 | |
182faf26 MR |
718 | public function import() { |
719 | ||
dc764892 | 720 | if ( isset($_FILES['file']) && $_FILES['file']['tmp_name'] ) { |
5ce39784 MR |
721 | Tools::logm('Import stated: parsing file'); |
722 | ||
182faf26 MR |
723 | // assume, that file is in json format |
724 | $str_data = file_get_contents($_FILES['file']['tmp_name']); | |
725 | $data = json_decode($str_data, true); | |
726 | ||
727 | if ( $data === null ) { | |
728 | //not json - assume html | |
729 | $html = new simple_html_dom(); | |
730 | $html->load_file($_FILES['file']['tmp_name']); | |
731 | $data = array(); | |
732 | $read = 0; | |
733 | foreach (array('ol','ul') as $list) { | |
734 | foreach ($html->find($list) as $ul) { | |
86da3988 MR |
735 | foreach ($ul->find('li') as $li) { |
736 | $tmpEntry = array(); | |
a8ef1f3f MR |
737 | $a = $li->find('a'); |
738 | $tmpEntry['url'] = $a[0]->href; | |
739 | $tmpEntry['tags'] = $a[0]->tags; | |
740 | $tmpEntry['is_read'] = $read; | |
741 | if ($tmpEntry['url']) { | |
742 | $data[] = $tmpEntry; | |
743 | } | |
86da3988 MR |
744 | } |
745 | # the second <ol/ul> is for read links | |
746 | $read = ((sizeof($data) && $read)?0:1); | |
182faf26 MR |
747 | } |
748 | } | |
1daa8e4a | 749 | } |
182faf26 | 750 | |
2f26729c NL |
751 | // for readability structure |
752 | ||
753 | foreach($data as $record) { | |
754 | if (is_array($record)) { | |
755 | $data[] = $record; | |
756 | foreach($record as $record2) { | |
757 | if (is_array($record2)) { | |
758 | $data[] = $record2; | |
759 | } | |
760 | } | |
761 | } | |
a297fb1e | 762 | } |
a297fb1e | 763 | |
2f26729c NL |
764 | $urlsInserted = array(); //urls of articles inserted |
765 | foreach($data as $record) { | |
766 | $url = trim(isset($record['article__url']) ? $record['article__url'] : (isset($record['url']) ? $record['url'] : '')); | |
767 | if ($url and !in_array($url, $urlsInserted)) { | |
768 | $title = (isset($record['title']) ? $record['title'] : _('Untitled - Import - ') . '</a> <a href="./?import">' . _('click to finish import') . '</a><a>'); | |
769 | $body = (isset($record['content']) ? $record['content'] : ''); | |
770 | $isRead = (isset($record['is_read']) ? intval($record['is_read']) : (isset($record['archive']) ? intval($record['archive']) : 0)); | |
771 | $isFavorite = (isset($record['is_fav']) ? intval($record['is_fav']) : (isset($record['favorite']) ? intval($record['favorite']) : 0)); | |
772 | ||
773 | // insert new record | |
774 | ||
775 | $id = $this->store->add($url, $title, $body, $this->user->getId() , $isFavorite, $isRead); | |
776 | if ($id) { | |
777 | $urlsInserted[] = $url; //add | |
778 | if (isset($record['tags']) && trim($record['tags'])) { | |
779 | ||
9a490ad6 | 780 | $tags = explode(',', $record['tags']); |
3052cfb7 | 781 | foreach($tags as $tag) { |
782 | $entry_id = $id; | |
783 | $tag_id = $this->store->retrieveTagByValue($tag); | |
784 | if ($tag_id) { | |
785 | $this->store->setTagToEntry($tag_id['id'], $entry_id); | |
786 | } else { | |
787 | $this->store->createTag($tag); | |
788 | $tag_id = $this->store->retrieveTagByValue($tag); | |
789 | $this->store->setTagToEntry($tag_id['id'], $entry_id); | |
790 | } | |
791 | } | |
2f26729c NL |
792 | |
793 | } | |
794 | } | |
795 | } | |
182faf26 | 796 | } |
182faf26 | 797 | |
2f26729c NL |
798 | $i = sizeof($urlsInserted); |
799 | if ($i > 0) { | |
800 | $this->messages->add('s', _('Articles inserted: ') . $i . _('. Please note, that some may be marked as "read".')); | |
801 | } | |
802 | ||
5ce39784 | 803 | Tools::logm('Import of articles finished: '.$i.' articles added (w/o content if not provided).'); |
182faf26 | 804 | } |
dc764892 | 805 | else { |
df89c6f7 | 806 | $this->messages->add('e', _('Did you forget to select a file?')); |
dc764892 | 807 | } |
2f26729c NL |
808 | // file parsing finished here |
809 | // now download article contents if any | |
810 | // check if we need to download any content | |
182faf26 | 811 | |
2f26729c NL |
812 | $recordsDownloadRequired = $this->store->retrieveUnfetchedEntriesCount($this->user->getId()); |
813 | ||
814 | if ($recordsDownloadRequired == 0) { | |
182faf26 | 815 | |
2f26729c | 816 | // nothing to download |
182faf26 | 817 | |
2f26729c NL |
818 | $this->messages->add('s', _('Import finished.')); |
819 | Tools::logm('Import finished completely'); | |
820 | Tools::redirect(); | |
821 | } | |
822 | else { | |
182faf26 | 823 | |
2f26729c | 824 | // if just inserted - don't download anything, download will start in next reload |
182faf26 | 825 | |
2f26729c | 826 | if (!isset($_FILES['file'])) { |
182faf26 | 827 | |
2f26729c | 828 | // download next batch |
182faf26 | 829 | |
2f26729c NL |
830 | Tools::logm('Fetching next batch of articles...'); |
831 | $items = $this->store->retrieveUnfetchedEntries($this->user->getId() , IMPORT_LIMIT); | |
832 | $purifier = $this->_getPurifier(); | |
833 | foreach($items as $item) { | |
834 | $url = new Url(base64_encode($item['url'])); | |
fde4cf06 EP |
835 | if( $url->isCorrect() ) |
836 | { | |
837 | Tools::logm('Fetching article ' . $item['id']); | |
838 | $content = Tools::getPageContent($url); | |
839 | $title = (($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled')); | |
840 | $body = (($content['rss']['channel']['item']['description'] != '') ? $content['rss']['channel']['item']['description'] : _('Undefined')); | |
841 | ||
842 | // clean content to prevent xss attack | |
843 | ||
844 | $title = $purifier->purify($title); | |
845 | $body = $purifier->purify($body); | |
846 | $this->store->updateContentAndTitle($item['id'], $title, $body, $this->user->getId()); | |
847 | Tools::logm('Article ' . $item['id'] . ' updated.'); | |
848 | } else | |
849 | { | |
850 | Tools::logm('Unvalid URL (' . $item['url'] .') to fetch for article ' . $item['id']); | |
851 | } | |
2f26729c NL |
852 | } |
853 | } | |
63c35580 | 854 | } |
182faf26 | 855 | |
2f26729c NL |
856 | return array( |
857 | 'includeImport' => true, | |
858 | 'import' => array( | |
859 | 'recordsDownloadRequired' => $recordsDownloadRequired, | |
860 | 'recordsUnderDownload' => IMPORT_LIMIT, | |
861 | 'delay' => IMPORT_DELAY * 1000 | |
862 | ) | |
863 | ); | |
63c35580 | 864 | } |
c765c367 | 865 | |
07ee09f4 NL |
866 | /** |
867 | * export poche entries in json | |
868 | * @return json all poche entries | |
869 | */ | |
2f26729c NL |
870 | public function export() |
871 | { | |
a8ef1f3f MR |
872 | $filename = "wallabag-export-".$this->user->getId()."-".date("Y-m-d").".json"; |
873 | header('Content-Disposition: attachment; filename='.$filename); | |
874 | ||
875 | $entries = $this->store->retrieveAll($this->user->getId()); | |
876 | echo $this->tpl->render('export.twig', array( | |
877 | 'export' => Tools::renderJson($entries), | |
878 | )); | |
879 | Tools::logm('export view'); | |
c765c367 | 880 | } |
32520785 | 881 | |
07ee09f4 | 882 | /** |
a3436d4c | 883 | * Checks online the latest version of poche and cache it |
07ee09f4 NL |
884 | * @param string $which 'prod' or 'dev' |
885 | * @return string latest $which version | |
886 | */ | |
2f26729c | 887 | private function _getPocheVersion($which = 'prod') { |
a8ef1f3f MR |
888 | $cache_file = CACHE . '/' . $which; |
889 | $check_time = time(); | |
890 | ||
891 | # checks if the cached version file exists | |
892 | if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 86400 ))) { | |
893 | $version = file_get_contents($cache_file); | |
894 | $check_time = filemtime($cache_file); | |
895 | } else { | |
896 | $version = file_get_contents('http://static.wallabag.org/versions/' . $which); | |
897 | file_put_contents($cache_file, $version, LOCK_EX); | |
898 | } | |
899 | return array($version, $check_time); | |
32520785 | 900 | } |
72c20a52 | 901 | |
2f26729c NL |
902 | /** |
903 | * Update token for current user | |
904 | */ | |
905 | public function updateToken() | |
72c20a52 | 906 | { |
2f26729c NL |
907 | $token = Tools::generateToken(); |
908 | $this->store->updateUserConfig($this->user->getId(), 'token', $token); | |
909 | $currentConfig = $_SESSION['poche_user']->config; | |
910 | $currentConfig['token'] = $token; | |
911 | $_SESSION['poche_user']->setConfig($currentConfig); | |
912 | Tools::redirect(); | |
72c20a52 NL |
913 | } |
914 | ||
2f26729c NL |
915 | /** |
916 | * Generate RSS feeds for current user | |
917 | * | |
918 | * @param $token | |
919 | * @param $user_id | |
7fe8a9ad VM |
920 | * @param $tag_id if $type is 'tag', the id of the tag to generate feed for |
921 | * @param string $type the type of feed to generate | |
922 | * @param int $limit the maximum number of items (0 means all) | |
2f26729c | 923 | */ |
7fe8a9ad | 924 | public function generateFeeds($token, $user_id, $tag_id, $type = 'home', $limit = 0) |
72c20a52 | 925 | { |
f778e472 | 926 | $allowed_types = array('home', 'fav', 'archive', 'tag'); |
72c20a52 NL |
927 | $config = $this->store->getConfigUser($user_id); |
928 | ||
17b2afef | 929 | if ($config == null) { |
30bd2735 | 930 | die(sprintf(_('User with this id (%d) does not exist.'), $user_id)); |
17b2afef NL |
931 | } |
932 | ||
7dd8b502 MR |
933 | if (!in_array($type, $allowed_types) || !isset($config['token']) || $token != $config['token']) { |
934 | die(_('Uh, there is a problem while generating feed. Wrong token used?')); | |
72c20a52 | 935 | } |
72c20a52 | 936 | |
9e7c840b | 937 | $feed = new FeedWriter(RSS2); |
2e4440c3 | 938 | $feed->setTitle('wallabag — ' . $type . ' feed'); |
72c20a52 | 939 | $feed->setLink(Tools::getPocheUrl()); |
223268c2 NL |
940 | $feed->setChannelElement('pubDate', date(DATE_RSS , time())); |
941 | $feed->setChannelElement('generator', 'wallabag'); | |
942 | $feed->setDescription('wallabag ' . $type . ' elements'); | |
72c20a52 | 943 | |
f778e472 | 944 | if ($type == 'tag') { |
b89d5a2b | 945 | $entries = $this->store->retrieveEntriesByTag($tag_id, $user_id); |
f778e472 NL |
946 | } |
947 | else { | |
948 | $entries = $this->store->getEntriesByView($type, $user_id); | |
949 | } | |
950 | ||
7fe8a9ad VM |
951 | // if $limit is set to zero, use all entries |
952 | if (0 == $limit) { | |
953 | $limit = count($entries); | |
954 | } | |
72c20a52 | 955 | if (count($entries) > 0) { |
7fe8a9ad VM |
956 | for ($i = 0; $i < min(count($entries), $limit); $i++) { |
957 | $entry = $entries[$i]; | |
72c20a52 | 958 | $newItem = $feed->createNewItem(); |
0b57c682 | 959 | $newItem->setTitle($entry['title']); |
f86784c2 | 960 | $newItem->setSource(Tools::getPocheUrl() . '?view=view&id=' . $entry['id']); |
ed02e38e | 961 | $newItem->setLink($entry['url']); |
72c20a52 NL |
962 | $newItem->setDate(time()); |
963 | $newItem->setDescription($entry['content']); | |
964 | $feed->addItem($newItem); | |
965 | } | |
966 | } | |
967 | ||
968 | $feed->genarateFeed(); | |
969 | exit; | |
970 | } | |
6285e57c | 971 | |
6285e57c | 972 | |
0f859c6f MR |
973 | |
974 | /** | |
2f26729c | 975 | * Returns new purifier object with actual config |
0f859c6f | 976 | */ |
2f26729c NL |
977 | private function _getPurifier() |
978 | { | |
979 | $config = HTMLPurifier_Config::createDefault(); | |
980 | $config->set('Cache.SerializerPath', CACHE); | |
981 | $config->set('HTML.SafeIframe', true); | |
35d4e275 | 982 | |
2f26729c NL |
983 | //allow YouTube, Vimeo and dailymotion videos |
984 | $config->set('URI.SafeIframeRegexp', '%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/|www\.dailymotion\.com/embed/video/)%'); | |
ec15d0a7 | 985 | |
2f26729c | 986 | return new HTMLPurifier($config); |
0f859c6f | 987 | } |
cbc75bef | 988 | |
cbc75bef | 989 | |
37cad522 | 990 | } |