]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/poche/Poche.class.php
c8a09f30b9aa5c75665f6774f4e65082ca930a8e
3 * wallabag, self hostable application allowing you to not miss any content anymore
6 * @author Nicolas Lœuillet <nicolas@loeuillet.org>
8 * @license http://opensource.org/licenses/MIT see COPYING file
42 public function __construct ()
47 private function init ()
51 $pocheUser = Session
:: getParam ( 'poche_user' );
53 if ( $pocheUser && $pocheUser != array ()) {
54 $this- > user
= $pocheUser ;
56 // fake user, just for install & login screens
57 $this- > user
= new User ();
58 $this- > user
-> setConfig ( $this- > getDefaultConfig ());
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 );
71 $this- > routing
-> run ();
77 public function createNewUser ( $username , $password , $email = "" )
79 if (! empty ( $username ) && ! empty ( $password )){
80 $newUsername = filter_var ( $username , FILTER_SANITIZE_STRING
);
81 $email = filter_var ( $email , FILTER_SANITIZE_STRING
);
82 if (! $this- > store
-> userExists ( $newUsername )){
83 if ( $this- > store
-> install ( $newUsername , Tools
:: encodeString ( $password . $newUsername ), $email )) {
84 Tools
:: logm ( 'The new user ' . $newUsername . ' has been installed' );
85 $this- > messages
-> add ( 's' , sprintf ( _ ( 'The new user %s has been installed. Do you want to <a href="?logout">logout ?</a>' ), $newUsername ));
89 Tools
:: logm ( 'error during adding new user' );
94 $this- > messages
-> add ( 'e' , sprintf ( _ ( 'Error : An user with the name %s already exists !' ), $newUsername ));
95 Tools
:: logm ( 'An user with the name ' . $newUsername . ' already exists !' );
102 * Delete an existing user
104 public function deleteUser ( $password )
106 if ( $this- > store
-> listUsers () > 1 ) {
107 if ( Tools
:: encodeString ( $password . $this- > user
-> getUsername ()) == $this- > store
-> getUserPassword ( $this- > user
-> getId ())) {
108 $username = $this- > user
-> getUsername ();
109 $this- > store
-> deleteUserConfig ( $this- > user
-> getId ());
110 Tools
:: logm ( 'The configuration for user ' . $username . ' has been deleted !' );
111 $this- > store
-> deleteTagsEntriesAndEntries ( $this- > user
-> getId ());
112 Tools
:: logm ( 'The entries for user ' . $username . ' has been deleted !' );
113 $this- > store
-> deleteUser ( $this- > user
-> getId ());
114 Tools
:: logm ( 'User ' . $username . ' has been completely deleted !' );
116 Tools
:: logm ( 'logout' );
118 $this- > messages
-> add ( 's' , sprintf ( _ ( 'User %s has been successfully deleted !' ), $username ));
121 Tools
:: logm ( 'Bad password !' );
122 $this- > messages
-> add ( 'e' , _ ( 'Error : The password is wrong !' ));
126 Tools
:: logm ( 'Only user !' );
127 $this- > messages
-> add ( 'e' , _ ( 'Error : You are the only user, you cannot delete your account !' ));
131 public function getDefaultConfig ()
134 'pager' => PAGINATION
,
136 'theme' => DEFAULT_THEME
141 * Call action (mark as fav, archive, delete, etc.)
143 public function action ( $action , Url
$url , $id = 0 , $import = FALSE , $autoclose = FALSE , $tags = null )
148 $content = Tools
:: getPageContent ( $url );
149 $title = ( $content [ 'rss' ][ 'channel' ][ 'item' ][ 'title' ] != '' ) ? $content [ 'rss' ][ 'channel' ][ 'item' ][ 'title' ] : _ ( 'Untitled' );
150 $body = $content [ 'rss' ][ 'channel' ][ 'item' ][ 'description' ];
152 // clean content from prevent xss attack
153 $purifier = $this- > _getPurifier ();
154 $title = $purifier- > purify ( $title );
155 $body = $purifier- > purify ( $body );
157 //search for possible duplicate
159 $duplicate = $this- > store
-> retrieveOneByURL ( $url- > getUrl (), $this- > user
-> getId ());
161 $last_id = $this- > store
-> add ( $url- > getUrl (), $title , $body , $this- > user
-> getId ());
163 Tools
:: logm ( 'add link ' . $url- > getUrl ());
164 if ( DOWNLOAD_PICTURES
) {
165 $content = Picture
:: filterPicture ( $body , $url- > getUrl (), $last_id );
166 Tools
:: logm ( 'updating content article' );
167 $this- > store
-> updateContent ( $last_id , $content , $this- > user
-> getId ());
170 if ( $duplicate != NULL ) {
171 // 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
172 Tools
:: logm ( 'link ' . $url- > getUrl () . ' is a duplicate' );
173 // 1) - preserve tags and favorite, then drop old entry
174 $this- > store
-> reassignTags ( $duplicate [ 'id' ], $last_id );
175 if ( $duplicate [ 'is_fav' ]) {
176 $this- > store
-> favoriteById ( $last_id , $this- > user
-> getId ());
178 if ( $this- > store
-> deleteById ( $duplicate [ 'id' ], $this- > user
-> getId ())) {
179 Tools
:: logm ( 'previous link ' . $url- > getUrl () . ' entry deleted' );
183 $this- > messages
-> add ( 's' , _ ( 'the link has been added successfully' ));
186 $this- > messages
-> add ( 'e' , _ ( 'error during insertion : the link wasn \' t added' ));
187 Tools
:: logm ( 'error during insertion : the link wasn \' t added ' . $url- > getUrl ());
190 if ( $autoclose == TRUE ) {
191 Tools
:: redirect ( '?view=home' );
193 Tools
:: redirect ( '?view=home&closewin=true' );
197 $msg = 'delete link #' . $id ;
198 if ( $this- > store
-> deleteById ( $id , $this- > user
-> getId ())) {
199 if ( DOWNLOAD_PICTURES
) {
200 Picture
:: removeDirectory ( ABS_PATH
. $id );
202 $this- > messages
-> add ( 's' , _ ( 'the link has been deleted successfully' ));
205 $this- > messages
-> add ( 'e' , _ ( 'the link wasn \' t deleted' ));
206 $msg = 'error : can \' t delete link #' . $id ;
209 Tools
:: redirect ( '?' );
212 $this- > store
-> favoriteById ( $id , $this- > user
-> getId ());
213 Tools
:: logm ( 'mark as favorite link #' . $id );
214 if ( Tools
:: isAjaxRequest () ) {
222 case 'toggle_archive' :
223 $this- > store
-> archiveById ( $id , $this- > user
-> getId ());
224 Tools
:: logm ( 'archive link #' . $id );
225 if ( Tools
:: isAjaxRequest () ) {
234 $this- > store
-> archiveAll ( $this- > user
-> getId ());
235 Tools
:: logm ( 'archive all links' );
239 if ( isset ( $_GET [ 'search' ])) {
240 //when we want to apply a tag to a search
241 $tags = array ( $_GET [ 'search' ]);
242 $allentry_ids = $this- > store
-> search ( $tags [ 0 ], $this- > user
-> getId ());
243 $entry_ids = array ();
244 foreach ( $allentry_ids as $eachentry ) {
245 $entry_ids [] = $eachentry [ 0 ];
247 } else { //add a tag to a single article
248 $tags = explode ( ',' , $_POST [ 'value' ]);
249 $entry_ids = array ( $_POST [ 'entry_id' ]);
251 foreach ( $entry_ids as $entry_id ) {
252 $entry = $this- > store
-> retrieveOneById ( $entry_id , $this- > user
-> getId ());
254 $this- > messages
-> add ( 'e' , _ ( 'Article not found!' ));
255 Tools
:: logm ( 'error : article not found' );
258 //get all already set tags to preven duplicates
259 $already_set_tags = array ();
260 $entry_tags = $this- > store
-> retrieveTagsByEntry ( $entry_id );
261 foreach ( $entry_tags as $tag ) {
262 $already_set_tags [] = $tag [ 'value' ];
264 foreach ( $tags as $key => $tag_value ) {
265 $value = trim ( $tag_value );
266 if ( $value && ! in_array ( $value , $already_set_tags )) {
267 $tag = $this- > store
-> retrieveTagByValue ( $value );
270 $tag = $this- > store
-> createTag ( $value );
272 if ( STORAGE
== 'postgres' ) {
273 $sequence = 'tags_id_seq' ;
275 $tag_id = $this- > store
-> getLastId ( $sequence );
278 $tag_id = $tag [ 'id' ];
281 # we assign the tag to the article
282 $this- > store
-> setTagToEntry ( $tag_id , $entry_id );
286 $this- > messages
-> add ( 's' , _ ( 'The tag has been applied successfully' ));
287 Tools
:: logm ( 'The tag has been applied successfully' );
291 $tag_id = $_GET [ 'tag_id' ];
292 $entry = $this- > store
-> retrieveOneById ( $id , $this- > user
-> getId ());
294 $this- > messages
-> add ( 'e' , _ ( 'Article not found!' ));
295 Tools
:: logm ( 'error : article not found' );
298 $this- > store
-> removeTagForEntry ( $id , $tag_id );
299 Tools
:: logm ( 'tag entry deleted' );
300 if ( $this- > store
-> cleanUnusedTag ( $tag_id )) {
301 Tools
:: logm ( 'tag deleted' );
303 $this- > messages
-> add ( 's' , _ ( 'The tag has been successfully deleted' ));
311 function displayView ( $view , $id = 0 )
318 $dev_infos = $this- > _getPocheVersion ( 'dev' );
319 $dev = trim ( $dev_infos [ 0 ]);
320 $check_time_dev = date ( 'd-M-Y H:i' , $dev_infos [ 1 ]);
321 $prod_infos = $this- > _getPocheVersion ( 'prod' );
322 $prod = trim ( $prod_infos [ 0 ]);
323 $check_time_prod = date ( 'd-M-Y H:i' , $prod_infos [ 1 ]);
324 $compare_dev = version_compare ( POCHE
, $dev );
325 $compare_prod = version_compare ( POCHE
, $prod );
326 $themes = $this- > tpl
-> getInstalledThemes ();
327 $languages = $this- > language
-> getInstalledLanguages ();
328 $token = $this- > user
-> getConfigValue ( 'token' );
329 $http_auth = ( isset ( $_SERVER [ 'PHP_AUTH_USER' ]) || isset ( $_SERVER [ 'REMOTE_USER' ])) ? true : false ;
330 $only_user = ( $this- > store
-> listUsers () > 1 ) ? false : true ;
333 'languages' => $languages ,
336 'check_time_dev' => $check_time_dev ,
337 'check_time_prod' => $check_time_prod ,
338 'compare_dev' => $compare_dev ,
339 'compare_prod' => $compare_prod ,
341 'user_id' => $this- > user
-> getId (),
342 'http_auth' => $http_auth ,
343 'only_user' => $only_user
345 Tools
:: logm ( 'config view' );
349 $entry = $this- > store
-> retrieveOneById ( $id , $this- > user
-> getId ());
351 $this- > messages
-> add ( 'e' , _ ( 'Article not found!' ));
352 Tools
:: logm ( 'error : article not found' );
355 $tags = $this- > store
-> retrieveTagsByEntry ( $id );
363 $token = $this- > user
-> getConfigValue ( 'token' );
364 //if term is set - search tags for this term
365 $term = Tools
:: checkVar ( 'term' );
366 $tags = $this- > store
-> retrieveAllTags ( $this- > user
-> getId (), $term );
367 if ( Tools
:: isAjaxRequest ()) {
369 foreach ( $tags as $tag ) {
370 $result [] = $tag [ 'value' ];
372 echo json_encode ( $result );
377 'user_id' => $this- > user
-> getId (),
382 if ( isset ( $_GET [ 'search' ])) {
383 $search = filter_var ( $_GET [ 'search' ], FILTER_SANITIZE_STRING
);
384 $tpl_vars [ 'entries' ] = $this- > store
-> search ( $search , $this- > user
-> getId ());
385 $count = count ( $tpl_vars [ 'entries' ]);
386 $this- > pagination
-> set_total ( $count );
387 $page_links = str_replace ( array ( 'previous' , 'next' ), array ( _ ( 'previous' ), _ ( 'next' )),
388 $this- > pagination
-> page_links ( '?view=' . $view . '?search=' . $search . '&sort=' . $_SESSION [ 'sort' ] . '&' ));
389 $tpl_vars [ 'page_links' ] = $page_links ;
390 $tpl_vars [ 'nb_results' ] = $count ;
391 $tpl_vars [ 'search_term' ] = $search ;
395 $entry = $this- > store
-> retrieveOneById ( $id , $this- > user
-> getId ());
396 if ( $entry != NULL ) {
397 Tools
:: logm ( 'view link #' . $id );
398 $content = $entry [ 'content' ];
399 if ( function_exists ( 'tidy_parse_string' )) {
400 $tidy = tidy_parse_string ( $content , array ( 'indent' => true , 'show-body-only' => true ), 'UTF8' );
401 $tidy- > cleanRepair ();
402 $content = $tidy- > value
;
406 $flattr = new FlattrItem ();
407 $flattr- > checkItem ( $entry [ 'url' ], $entry [ 'id' ]);
410 $tags = $this- > store
-> retrieveTagsByEntry ( $entry [ 'id' ]);
414 'content' => $content ,
420 Tools
:: logm ( 'error in view call : entry is null' );
423 default : # home, favorites, archive and tag views
428 'listmode' => ( isset ( $_COOKIE [ 'listmode' ]) ? true : false ),
431 //if id is given - we retrieve entries by tag: id is tag id
433 $tpl_vars [ 'tag' ] = $this- > store
-> retrieveTag ( $id , $this- > user
-> getId ());
434 $tpl_vars [ 'id' ] = intval ( $id );
437 $count = $this- > store
-> getEntriesByViewCount ( $view , $this- > user
-> getId (), $id );
440 $this- > pagination
-> set_total ( $count );
441 $page_links = str_replace ( array ( 'previous' , 'next' ), array ( _ ( 'previous' ), _ ( 'next' )),
442 $this- > pagination
-> page_links ( '?view=' . $view . '&sort=' . $_SESSION [ 'sort' ] . (( $id )? '&id=' . $id : '' ) . '&' ));
443 $tpl_vars [ 'entries' ] = $this- > store
-> getEntriesByView ( $view , $this- > user
-> getId (), $this- > pagination
-> get_limit (), $id );
444 $tpl_vars [ 'page_links' ] = $page_links ;
445 $tpl_vars [ 'nb_results' ] = $count ;
447 Tools
:: logm ( 'display ' . $view . ' view' );
455 * update the password of the current user.
456 * if MODE_DEMO is TRUE, the password can't be updated.
457 * @todo add the return value
458 * @todo set the new password in function header like this updatePassword($newPassword)
461 public function updatePassword ( $password , $confirmPassword )
464 $this- > messages
-> add ( 'i' , _ ( 'in demo mode, you can \' t update your password' ));
465 Tools
:: logm ( 'in demo mode, you can \' t do this' );
466 Tools
:: redirect ( '?view=config' );
469 if ( isset ( $password ) && isset ( $confirmPassword )) {
470 if ( $password == $confirmPassword && ! empty ( $password )) {
471 $this- > messages
-> add ( 's' , _ ( 'your password has been updated' ));
472 $this- > store
-> updatePassword ( $this- > user
-> getId (), Tools
:: encodeString ( $password . $this- > user
-> getUsername ()));
474 Tools
:: logm ( 'password updated' );
478 $this- > messages
-> add ( 'e' , _ ( 'the two fields have to be filled & the password must be the same in the two fields' ));
479 Tools
:: redirect ( '?view=config' );
486 * Get credentials from differents sources
487 * It redirects the user to the $referer link
491 private function credentials ()
493 if ( isset ( $_SERVER [ 'PHP_AUTH_USER' ])) {
494 return array ( $_SERVER [ 'PHP_AUTH_USER' ], 'php_auth' , true );
496 if (! empty ( $_POST [ 'login' ]) && ! empty ( $_POST [ 'password' ])) {
497 return array ( $_POST [ 'login' ], $_POST [ 'password' ], false );
499 if ( isset ( $_SERVER [ 'REMOTE_USER' ])) {
500 return array ( $_SERVER [ 'REMOTE_USER' ], 'http_auth' , true );
503 return array ( false , false , false );
507 * checks if login & password are correct and save the user in session.
508 * it redirects the user to the $referer link
509 * @param string $referer the url to redirect after login
510 * @todo add the return value
513 public function login ( $referer )
515 list ( $login , $password , $isauthenticated )= $this- > credentials ();
516 if ( $login === false || $password === false ) {
517 $this- > messages
-> add ( 'e' , _ ( 'login failed: you have to fill all fields' ));
518 Tools
:: logm ( 'login failed' );
521 if (! empty ( $login ) && ! empty ( $password )) {
522 $user = $this- > store
-> login ( $login , Tools
:: encodeString ( $password . $login ), $isauthenticated );
523 if ( $user != array ()) {
524 # Save login into Session
525 $longlastingsession = isset ( $_POST [ 'longlastingsession' ]);
526 $passwordTest = ( $isauthenticated ) ? $user [ 'password' ] : Tools
:: encodeString ( $password . $login );
527 Session
:: login ( $user [ 'username' ], $user [ 'password' ], $login , $passwordTest , $longlastingsession , array ( 'poche_user' => new User ( $user )));
528 $this- > messages
-> add ( 's' , _ ( 'welcome to your wallabag' ));
529 Tools
:: logm ( 'login successful' );
530 Tools
:: redirect ( $referer );
532 $this- > messages
-> add ( 'e' , _ ( 'login failed: bad login or password' ));
533 Tools
:: logm ( 'login failed' );
539 * log out the poche user. It cleans the session.
540 * @todo add the return value
543 public function logout ()
545 $this- > user
= array ();
547 Tools
:: logm ( 'logout' );
552 * import datas into your wallabag
555 public function import ()
557 if ( isset ( $_FILES [ 'file' ])) {
558 Tools
:: logm ( 'Import stated: parsing file' );
560 // assume, that file is in json format
562 $str_data = file_get_contents ( $_FILES [ 'file' ][ 'tmp_name' ]);
563 $data = json_decode ( $str_data , true );
564 if ( $data === null ) {
566 // not json - assume html
568 $html = new simple_html_dom ();
569 $html- > load_file ( $_FILES [ 'file' ][ 'tmp_name' ]);
572 foreach ( array ( 'ol' , 'ul' ) as $list ) {
573 foreach ( $html- > find ( $list ) as $ul ) {
574 foreach ( $ul- > find ( 'li' ) as $li ) {
577 $tmpEntry [ 'url' ] = $a [ 0 ]-> href
;
578 $tmpEntry [ 'tags' ] = $a [ 0 ]-> tags
;
579 $tmpEntry [ 'is_read' ] = $read ;
580 if ( $tmpEntry [ 'url' ]) {
585 // the second <ol/ul> is for read links
587 $read = (( sizeof ( $data ) && $read ) ? 0 : 1 );
592 // for readability structure
594 foreach ( $data as $record ) {
595 if ( is_array ( $record )) {
597 foreach ( $record as $record2 ) {
598 if ( is_array ( $record2 )) {
605 $urlsInserted = array (); //urls of articles inserted
606 foreach ( $data as $record ) {
607 $url = trim ( isset ( $record [ 'article__url' ]) ? $record [ 'article__url' ] : ( isset ( $record [ 'url' ]) ? $record [ 'url' ] : '' ));
608 if ( $url and ! in_array ( $url , $urlsInserted )) {
609 $title = ( isset ( $record [ 'title' ]) ? $record [ 'title' ] : _ ( 'Untitled - Import - ' ) . '</a> <a href="./?import">' . _ ( 'click to finish import' ) . '</a><a>' );
610 $body = ( isset ( $record [ 'content' ]) ? $record [ 'content' ] : '' );
611 $isRead = ( isset ( $record [ 'is_read' ]) ? intval ( $record [ 'is_read' ]) : ( isset ( $record [ 'archive' ]) ? intval ( $record [ 'archive' ]) : 0 ));
612 $isFavorite = ( isset ( $record [ 'is_fav' ]) ? intval ( $record [ 'is_fav' ]) : ( isset ( $record [ 'favorite' ]) ? intval ( $record [ 'favorite' ]) : 0 ));
616 $id = $this- > store
-> add ( $url , $title , $body , $this- > user
-> getId () , $isFavorite , $isRead );
618 $urlsInserted [] = $url ; //add
619 if ( isset ( $record [ 'tags' ]) && trim ( $record [ 'tags' ])) {
628 $i = sizeof ( $urlsInserted );
630 $this- > messages
-> add ( 's' , _ ( 'Articles inserted: ' ) . $i . _ ( '. Please note, that some may be marked as "read".' ));
633 Tools
:: logm ( 'Import of articles finished: ' . $i . ' articles added (w/o content if not provided).' );
636 // file parsing finished here
637 // now download article contents if any
638 // check if we need to download any content
640 $recordsDownloadRequired = $this- > store
-> retrieveUnfetchedEntriesCount ( $this- > user
-> getId ());
642 if ( $recordsDownloadRequired == 0 ) {
644 // nothing to download
646 $this- > messages
-> add ( 's' , _ ( 'Import finished.' ));
647 Tools
:: logm ( 'Import finished completely' );
652 // if just inserted - don't download anything, download will start in next reload
654 if (! isset ( $_FILES [ 'file' ])) {
656 // download next batch
658 Tools
:: logm ( 'Fetching next batch of articles...' );
659 $items = $this- > store
-> retrieveUnfetchedEntries ( $this- > user
-> getId () , IMPORT_LIMIT
);
660 $purifier = $this- > _getPurifier ();
661 foreach ( $items as $item ) {
662 $url = new Url ( base64_encode ( $item [ 'url' ]));
663 Tools
:: logm ( 'Fetching article ' . $item [ 'id' ]);
664 $content = Tools
:: getPageContent ( $url );
665 $title = (( $content [ 'rss' ][ 'channel' ][ 'item' ][ 'title' ] != '' ) ? $content [ 'rss' ][ 'channel' ][ 'item' ][ 'title' ] : _ ( 'Untitled' ));
666 $body = (( $content [ 'rss' ][ 'channel' ][ 'item' ][ 'description' ] != '' ) ? $content [ 'rss' ][ 'channel' ][ 'item' ][ 'description' ] : _ ( 'Undefined' ));
668 // clean content to prevent xss attack
670 $title = $purifier- > purify ( $title );
671 $body = $purifier- > purify ( $body );
672 $this- > store
-> updateContentAndTitle ( $item [ 'id' ], $title , $body , $this- > user
-> getId ());
673 Tools
:: logm ( 'Article ' . $item [ 'id' ] . ' updated.' );
679 'includeImport' => true ,
681 'recordsDownloadRequired' => $recordsDownloadRequired ,
682 'recordsUnderDownload' => IMPORT_LIMIT
,
683 'delay' => IMPORT_DELAY
* 1000
689 * export poche entries in json
690 * @return json all poche entries
692 public function export ()
694 $filename = "wallabag-export-" . $this- > user
-> getId (). "-" . date ( "Y-m-d" ). ".json" ;
695 header ( 'Content-Disposition: attachment; filename=' . $filename );
697 $entries = $this- > store
-> retrieveAll ( $this- > user
-> getId ());
698 echo $this- > tpl
-> render ( 'export.twig' , array (
699 'export' => Tools
:: renderJson ( $entries ),
701 Tools
:: logm ( 'export view' );
705 * Checks online the latest version of poche and cache it
706 * @param string $which 'prod' or 'dev'
707 * @return string latest $which version
709 private function _getPocheVersion ( $which = 'prod' ) {
710 $cache_file = CACHE
. '/' . $which ;
711 $check_time = time ();
713 # checks if the cached version file exists
714 if ( file_exists ( $cache_file ) && ( filemtime ( $cache_file ) > ( time () - 86400 ))) {
715 $version = file_get_contents ( $cache_file );
716 $check_time = filemtime ( $cache_file );
718 $version = file_get_contents ( 'http://static.wallabag.org/versions/' . $which );
719 file_put_contents ( $cache_file , $version , LOCK_EX
);
721 return array ( $version , $check_time );
725 * Update token for current user
727 public function updateToken ()
729 $token = Tools
:: generateToken ();
730 $this- > store
-> updateUserConfig ( $this- > user
-> getId (), 'token' , $token );
731 $currentConfig = $_SESSION [ 'poche_user' ]-> config
;
732 $currentConfig [ 'token' ] = $token ;
733 $_SESSION [ 'poche_user' ]-> setConfig ( $currentConfig );
738 * Generate RSS feeds for current user
743 * @param string $type
745 public function generateFeeds ( $token , $user_id , $tag_id , $type = 'home' )
747 $allowed_types = array ( 'home' , 'fav' , 'archive' , 'tag' );
748 $config = $this- > store
-> getConfigUser ( $user_id );
750 if ( $config == null ) {
751 die ( sprintf ( _ ( 'User with this id (%d) does not exist.' ), $user_id ));
754 if (! in_array ( $type , $allowed_types ) || $token != $config [ 'token' ]) {
755 die ( _ ( 'Uh, there is a problem while generating feeds.' ));
758 $feed = new FeedWriter ( RSS2
);
759 $feed- > setTitle ( 'wallabag — ' . $type . ' feed' );
760 $feed- > setLink ( Tools
:: getPocheUrl ());
761 $feed- > setChannelElement ( 'pubDate' , date ( DATE_RSS
, time ()));
762 $feed- > setChannelElement ( 'generator' , 'wallabag' );
763 $feed- > setDescription ( 'wallabag ' . $type . ' elements' );
765 if ( $type == 'tag' ) {
766 $entries = $this- > store
-> retrieveEntriesByTag ( $tag_id , $user_id );
769 $entries = $this- > store
-> getEntriesByView ( $type , $user_id );
772 if ( count ( $entries ) > 0 ) {
773 foreach ( $entries as $entry ) {
774 $newItem = $feed- > createNewItem ();
775 $newItem- > setTitle ( $entry [ 'title' ]);
776 $newItem- > setSource ( Tools
:: getPocheUrl () . '?view=view&id=' . $entry [ 'id' ]);
777 $newItem- > setLink ( $entry [ 'url' ]);
778 $newItem- > setDate ( time ());
779 $newItem- > setDescription ( $entry [ 'content' ]);
780 $feed- > addItem ( $newItem );
784 $feed- > genarateFeed ();
791 * Returns new purifier object with actual config
793 private function _getPurifier ()
795 $config = HTMLPurifier_Config
:: createDefault ();
796 $config- > set ( 'Cache.SerializerPath' , CACHE
);
797 $config- > set ( 'HTML.SafeIframe' , true );
799 //allow YouTube, Vimeo and dailymotion videos
800 $config- > set ( 'URI.SafeIframeRegexp' , '%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/|www\.dailymotion\.com/embed/video/)%' );
802 return new HTMLPurifier ( $config );