aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
Diffstat (limited to 'inc/poche')
-rwxr-xr-xinc/poche/Database.class.php76
-rwxr-xr-xinc/poche/Poche.class.php210
-rwxr-xr-x[-rw-r--r--]inc/poche/Tools.class.php73
3 files changed, 233 insertions, 126 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index c998fe14..5b51b507 100755
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -230,8 +230,30 @@ class Database {
230 } 230 }
231 } 231 }
232 232
233 public function updateContentAndTitle($id, $title, $body, $user_id) {
234 $sql_action = 'UPDATE entries SET content = ?, title = ? WHERE id=? AND user_id=?';
235 $params_action = array($body, $title, $id, $user_id);
236 $query = $this->executeQuery($sql_action, $params_action);
237
238 return $query;
239 }
240
241 public function retrieveUnfetchedEntries($user_id, $limit) {
242
243 $sql_limit = "LIMIT 0,".$limit;
244 if (STORAGE == 'postgres') {
245 $sql_limit = "LIMIT ".$limit." OFFSET 0";
246 }
247
248 $sql = "SELECT * FROM entries WHERE (content = '' OR content IS NULL) AND user_id=? ORDER BY id " . $sql_limit;
249 $query = $this->executeQuery($sql, array($user_id));
250 $entries = $query->fetchAll();
251
252 return $entries;
253 }
254
233 public function retrieveAll($user_id) { 255 public function retrieveAll($user_id) {
234 $sql = "SELECT * FROM entries WHERE user_id=? ORDER BY id"; 256 $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? ORDER BY id";
235 $query = $this->executeQuery($sql, array($user_id)); 257 $query = $this->executeQuery($sql, array($user_id));
236 $entries = $query->fetchAll(); 258 $entries = $query->fetchAll();
237 259
@@ -250,7 +272,7 @@ class Database {
250 272
251 public function retrieveOneByURL($url, $user_id) { 273 public function retrieveOneByURL($url, $user_id) {
252 $entry = NULL; 274 $entry = NULL;
253 $sql = "SELECT * FROM entries WHERE url=? AND user_id=?"; 275 $sql = "SELECT * FROM entries WHERE content <> '' AND url=? AND user_id=?";
254 $params = array($url, $user_id); 276 $params = array($url, $user_id);
255 $query = $this->executeQuery($sql, $params); 277 $query = $this->executeQuery($sql, $params);
256 $entry = $query->fetchAll(); 278 $entry = $query->fetchAll();
@@ -267,21 +289,22 @@ class Database {
267 public function getEntriesByView($view, $user_id, $limit = '', $tag_id = 0) { 289 public function getEntriesByView($view, $user_id, $limit = '', $tag_id = 0) {
268 switch ($view) { 290 switch ($view) {
269 case 'archive': 291 case 'archive':
270 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? "; 292 $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? AND is_read=? ";
271 $params = array($user_id, 1); 293 $params = array($user_id, 1);
272 break; 294 break;
273 case 'fav' : 295 case 'fav' :
274 $sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? "; 296 $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? AND is_fav=? ";
275 $params = array($user_id, 1); 297 $params = array($user_id, 1);
276 break; 298 break;
277 case 'tag' : 299 case 'tag' :
278 $sql = "SELECT entries.* FROM entries 300 $sql = "SELECT entries.* FROM entries
279 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id 301 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
280 WHERE entries.user_id=? AND tags_entries.tag_id = ? "; 302 WHERE entries.content <> '' AND
303 entries.user_id=? AND tags_entries.tag_id = ? ";
281 $params = array($user_id, $tag_id); 304 $params = array($user_id, $tag_id);
282 break; 305 break;
283 default: 306 default:
284 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? "; 307 $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? AND is_read=? ";
285 $params = array($user_id, 0); 308 $params = array($user_id, 0);
286 break; 309 break;
287 } 310 }
@@ -294,24 +317,25 @@ class Database {
294 return $entries; 317 return $entries;
295 } 318 }
296 319
297 public function getEntriesByViewCount($view, $user_id, $tag_id = 0) { 320 public function getEntriesByViewCount($view, $user_id, $tag_id = 0) {
298 switch ($view) { 321 switch ($view) {
299 case 'archive': 322 case 'archive':
300 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? "; 323 $sql = "SELECT count(*) FROM entries WHERE content <> '' AND user_id=? AND is_read=? ";
301 $params = array($user_id, 1); 324 $params = array($user_id, 1);
302 break; 325 break;
303 case 'fav' : 326 case 'fav' :
304 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_fav=? "; 327 $sql = "SELECT count(*) FROM entries WHERE content <> '' AND user_id=? AND is_fav=? ";
305 $params = array($user_id, 1); 328 $params = array($user_id, 1);
306 break; 329 break;
307 case 'tag' : 330 case 'tag' :
308 $sql = "SELECT count(*) FROM entries 331 $sql = "SELECT count(*) FROM entries
309 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id 332 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
310 WHERE entries.user_id=? AND tags_entries.tag_id = ? "; 333 WHERE entries.content <> '' AND
311 $params = array($user_id, $tag_id); 334 entries.user_id=? AND tags_entries.tag_id = ? ";
312 break; 335 $params = array($user_id, $tag_id);
336 break;
313 default: 337 default:
314 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? "; 338 $sql = "SELECT count(*) FROM entries WHERE content <> '' AND user_id=? AND is_read=? ";
315 $params = array($user_id, 0); 339 $params = array($user_id, 0);
316 break; 340 break;
317 } 341 }
@@ -319,7 +343,7 @@ class Database {
319 $query = $this->executeQuery($sql, $params); 343 $query = $this->executeQuery($sql, $params);
320 list($count) = $query->fetch(); 344 list($count) = $query->fetch();
321 345
322 return $count; 346 return $count;
323 } 347 }
324 348
325 public function updateContent($id, $content, $user_id) { 349 public function updateContent($id, $content, $user_id) {
@@ -365,12 +389,15 @@ class Database {
365 return $this->getHandle()->lastInsertId($column); 389 return $this->getHandle()->lastInsertId($column);
366 } 390 }
367 391
368 public function retrieveAllTags($user_id) { 392 public function retrieveAllTags($user_id, $term = null) {
369 $sql = "SELECT DISTINCT tags.* FROM tags 393 $sql = "SELECT DISTINCT tags.*, count(entries.id) AS entriescount FROM tags
370 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id 394 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
371 LEFT JOIN entries ON tags_entries.entry_id=entries.id 395 LEFT JOIN entries ON tags_entries.entry_id=entries.id
372 WHERE entries.user_id=?"; 396 WHERE entries.content <> '' AND entries.user_id=?
373 $query = $this->executeQuery($sql, array($user_id)); 397 ". (($term) ? "AND lower(tags.value) LIKE ?" : '') ."
398 GROUP BY tags.id, tags.value
399 ORDER BY tags.value";
400 $query = $this->executeQuery($sql, (($term)? array($user_id, strtolower('%'.$term.'%')) : array($user_id) ));
374 $tags = $query->fetchAll(); 401 $tags = $query->fetchAll();
375 402
376 return $tags; 403 return $tags;
@@ -381,7 +408,7 @@ class Database {
381 $sql = "SELECT DISTINCT tags.* FROM tags 408 $sql = "SELECT DISTINCT tags.* FROM tags
382 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id 409 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
383 LEFT JOIN entries ON tags_entries.entry_id=entries.id 410 LEFT JOIN entries ON tags_entries.entry_id=entries.id
384 WHERE tags.id=? AND entries.user_id=?"; 411 WHERE entries.content <> '' AND tags.id=? AND entries.user_id=?";
385 $params = array(intval($id), $user_id); 412 $params = array(intval($id), $user_id);
386 $query = $this->executeQuery($sql, $params); 413 $query = $this->executeQuery($sql, $params);
387 $tag = $query->fetchAll(); 414 $tag = $query->fetchAll();
@@ -393,7 +420,8 @@ class Database {
393 $sql = 420 $sql =
394 "SELECT entries.* FROM entries 421 "SELECT entries.* FROM entries
395 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id 422 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
396 WHERE tags_entries.tag_id = ? AND entries.user_id=?"; 423 WHERE entries.content <> '' AND
424 tags_entries.tag_id = ? AND entries.user_id=?";
397 $query = $this->executeQuery($sql, array($tag_id, $user_id)); 425 $query = $this->executeQuery($sql, array($tag_id, $user_id));
398 $entries = $query->fetchAll(); 426 $entries = $query->fetchAll();
399 427
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 34f2ff5a..7bf33308 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -34,7 +34,8 @@ class Poche
34 'pl_PL.utf8' => 'Polski', 34 'pl_PL.utf8' => 'Polski',
35 'ru_RU.utf8' => 'Pусский', 35 'ru_RU.utf8' => 'Pусский',
36 'sl_SI.utf8' => 'Slovenščina', 36 'sl_SI.utf8' => 'Slovenščina',
37 'uk_UA.utf8' => 'Український', 37 'uk_UA.utf8' => 'Українська',
38 'pt_BR.utf8' => 'Brasileiro',
38 ); 39 );
39 public function __construct() 40 public function __construct()
40 { 41 {
@@ -336,7 +337,7 @@ class Poche
336 while (($language = readdir($handle)) !== false) { 337 while (($language = readdir($handle)) !== false) {
337 # Languages are stored in a directory, so all directory names are languages 338 # Languages are stored in a directory, so all directory names are languages
338 # @todo move language installation data to database 339 # @todo move language installation data to database
339 if (! is_dir(LOCALE . '/' . $language) || in_array($language, array('..', '.'))) { 340 if (! is_dir(LOCALE . '/' . $language) || in_array($language, array('..', '.', 'tools'))) {
340 continue; 341 continue;
341 } 342 }
342 343
@@ -346,7 +347,7 @@ class Poche
346 $current = true; 347 $current = true;
347 } 348 }
348 349
349 $languages[] = array('name' => $this->language_names[$language], 'value' => $language, 'current' => $current); 350 $languages[] = array('name' => (isset($this->language_names[$language]) ? $this->language_names[$language] : $language), 'value' => $language, 'current' => $current);
350 } 351 }
351 352
352 return $languages; 353 return $languages;
@@ -361,60 +362,6 @@ class Poche
361 ); 362 );
362 } 363 }
363 364
364 protected function getPageContent(Url $url)
365 {
366 // Saving and clearing context
367 $REAL = array();
368 foreach( $GLOBALS as $key => $value ) {
369 if( $key != "GLOBALS" && $key != "_SESSION" ) {
370 $GLOBALS[$key] = array();
371 $REAL[$key] = $value;
372 }
373 }
374 // Saving and clearing session
375 $REAL_SESSION = array();
376 foreach( $_SESSION as $key => $value ) {
377 $REAL_SESSION[$key] = $value;
378 unset($_SESSION[$key]);
379 }
380
381 // Running code in different context
382 $scope = function() {
383 extract( func_get_arg(1) );
384 $_GET = $_REQUEST = array(
385 "url" => $url->getUrl(),
386 "max" => 5,
387 "links" => "preserve",
388 "exc" => "",
389 "format" => "json",
390 "submit" => "Create Feed"
391 );
392 ob_start();
393 require func_get_arg(0);
394 $json = ob_get_flush();
395 return $json;
396 };
397 $json = $scope( "inc/3rdparty/makefulltextfeed.php", array("url" => $url) );
398
399 // Clearing and restoring context
400 foreach( $GLOBALS as $key => $value ) {
401 if( $key != "GLOBALS" && $key != "_SESSION" ) {
402 unset($GLOBALS[$key]);
403 }
404 }
405 foreach( $REAL as $key => $value ) {
406 $GLOBALS[$key] = $value;
407 }
408 // Clearing and restoring session
409 foreach( $_SESSION as $key => $value ) {
410 unset($_SESSION[$key]);
411 }
412 foreach( $REAL_SESSION as $key => $value ) {
413 $_SESSION[$key] = $value;
414 }
415 return json_decode($json, true);
416 }
417
418 /** 365 /**
419 * Call action (mark as fav, archive, delete, etc.) 366 * Call action (mark as fav, archive, delete, etc.)
420 */ 367 */
@@ -423,17 +370,25 @@ class Poche
423 switch ($action) 370 switch ($action)
424 { 371 {
425 case 'add': 372 case 'add':
426 $content = $this->getPageContent($url); 373 if (!$import) {
427 $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'); 374 $content = Tools::getPageContent($url);
428 $body = $content['rss']['channel']['item']['description']; 375 $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled');
429 376 $body = $content['rss']['channel']['item']['description'];
430 // clean content from prevent xss attack 377
431 $config = HTMLPurifier_Config::createDefault(); 378 // clean content from prevent xss attack
432 $purifier = new HTMLPurifier($config); 379 $config = HTMLPurifier_Config::createDefault();
433 $title = $purifier->purify($title); 380 $config->set('Cache.SerializerPath', CACHE);
434 $body = $purifier->purify($body); 381 $purifier = new HTMLPurifier($config);
382 $title = $purifier->purify($title);
383 $body = $purifier->purify($body);
384 }
385 else {
386 $title = '';
387 $body = '';
388 }
435 389
436 //search for possible duplicate if not in import mode 390 //search for possible duplicate if not in import mode
391 $duplicate = NULL;
437 if (!$import) { 392 if (!$import) {
438 $duplicate = $this->store->retrieveOneByURL($url->getUrl(), $this->user->getId()); 393 $duplicate = $this->store->retrieveOneByURL($url->getUrl(), $this->user->getId());
439 } 394 }
@@ -534,25 +489,33 @@ class Poche
534 Tools::logm('error : article not found'); 489 Tools::logm('error : article not found');
535 Tools::redirect(); 490 Tools::redirect();
536 } 491 }
492 //get all already set tags to preven duplicates
493 $already_set_tags = array();
494 $entry_tags = $this->store->retrieveTagsByEntry($entry_id);
495 foreach ($entry_tags as $tag) {
496 $already_set_tags[] = $tag['value'];
497 }
537 foreach($tags as $key => $tag_value) { 498 foreach($tags as $key => $tag_value) {
538 $value = trim($tag_value); 499 $value = trim($tag_value);
539 $tag = $this->store->retrieveTagByValue($value); 500 if ($value && !in_array($value, $already_set_tags)) {
540 501 $tag = $this->store->retrieveTagByValue($value);
541 if (is_null($tag)) { 502
542 # we create the tag 503 if (is_null($tag)) {
543 $tag = $this->store->createTag($value); 504 # we create the tag
544 $sequence = ''; 505 $tag = $this->store->createTag($value);
545 if (STORAGE == 'postgres') { 506 $sequence = '';
546 $sequence = 'tags_id_seq'; 507 if (STORAGE == 'postgres') {
547 } 508 $sequence = 'tags_id_seq';
548 $tag_id = $this->store->getLastId($sequence); 509 }
510 $tag_id = $this->store->getLastId($sequence);
511 }
512 else {
513 $tag_id = $tag['id'];
514 }
515
516 # we assign the tag to the article
517 $this->store->setTagToEntry($tag_id, $entry_id);
549 } 518 }
550 else {
551 $tag_id = $tag['id'];
552 }
553
554 # we assign the tag to the article
555 $this->store->setTagToEntry($tag_id, $entry_id);
556 } 519 }
557 if(!$import) { 520 if(!$import) {
558 Tools::redirect(); 521 Tools::redirect();
@@ -581,8 +544,12 @@ class Poche
581 switch ($view) 544 switch ($view)
582 { 545 {
583 case 'config': 546 case 'config':
584 $dev = trim($this->getPocheVersion('dev')); 547 $dev_infos = $this->getPocheVersion('dev');
585 $prod = trim($this->getPocheVersion('prod')); 548 $dev = trim($dev_infos[0]);
549 $check_time_dev = date('d-M-Y H:i', $dev_infos[1]);
550 $prod_infos = $this->getPocheVersion('prod');
551 $prod = trim($prod_infos[0]);
552 $check_time_prod = date('d-M-Y H:i', $prod_infos[1]);
586 $compare_dev = version_compare(POCHE, $dev); 553 $compare_dev = version_compare(POCHE, $dev);
587 $compare_prod = version_compare(POCHE, $prod); 554 $compare_prod = version_compare(POCHE, $prod);
588 $themes = $this->getInstalledThemes(); 555 $themes = $this->getInstalledThemes();
@@ -594,6 +561,8 @@ class Poche
594 'languages' => $languages, 561 'languages' => $languages,
595 'dev' => $dev, 562 'dev' => $dev,
596 'prod' => $prod, 563 'prod' => $prod,
564 'check_time_dev' => $check_time_dev,
565 'check_time_prod' => $check_time_prod,
597 'compare_dev' => $compare_dev, 566 'compare_dev' => $compare_dev,
598 'compare_prod' => $compare_prod, 567 'compare_prod' => $compare_prod,
599 'token' => $token, 568 'token' => $token,
@@ -619,7 +588,17 @@ class Poche
619 break; 588 break;
620 case 'tags': 589 case 'tags':
621 $token = $this->user->getConfigValue('token'); 590 $token = $this->user->getConfigValue('token');
622 $tags = $this->store->retrieveAllTags($this->user->getId()); 591 //if term is set - search tags for this term
592 $term = Tools::checkVar('term');
593 $tags = $this->store->retrieveAllTags($this->user->getId(), $term);
594 if (Tools::isAjaxRequest()) {
595 $result = array();
596 foreach ($tags as $tag) {
597 $result[] = $tag['value'];
598 }
599 echo json_encode($result);
600 exit;
601 }
623 $tpl_vars = array( 602 $tpl_vars = array(
624 'token' => $token, 603 'token' => $token,
625 'user_id' => $this->user->getId(), 604 'user_id' => $this->user->getId(),
@@ -660,6 +639,7 @@ class Poche
660 'entries' => '', 639 'entries' => '',
661 'page_links' => '', 640 'page_links' => '',
662 'nb_results' => '', 641 'nb_results' => '',
642 'listmode' => (isset($_COOKIE['listmode']) ? true : false),
663 ); 643 );
664 644
665 //if id is given - we retrive entries by tag: id is tag id 645 //if id is given - we retrive entries by tag: id is tag id
@@ -750,6 +730,8 @@ class Poche
750 $currentConfig['theme'] = $_POST['theme']; 730 $currentConfig['theme'] = $_POST['theme'];
751 731
752 $_SESSION['poche_user']->setConfig($currentConfig); 732 $_SESSION['poche_user']->setConfig($currentConfig);
733
734 $this->emptyCache();
753 735
754 Tools::redirect('?view=config'); 736 Tools::redirect('?view=config');
755 } 737 }
@@ -788,6 +770,8 @@ class Poche
788 $currentConfig['language'] = $_POST['language']; 770 $currentConfig['language'] = $_POST['language'];
789 771
790 $_SESSION['poche_user']->setConfig($currentConfig); 772 $_SESSION['poche_user']->setConfig($currentConfig);
773
774 $this->emptyCache();
791 775
792 Tools::redirect('?view=config'); 776 Tools::redirect('?view=config');
793 } 777 }
@@ -891,7 +875,9 @@ class Poche
891 # the second <ol> is for read links 875 # the second <ol> is for read links
892 $read = 1; 876 $read = 1;
893 } 877 }
894 $this->messages->add('s', _('import from instapaper completed')); 878
879 $unlink = unlink($targetFile);
880 $this->messages->add('s', _('import from instapaper completed. You have to execute the cron to fetch content.'));
895 Tools::logm('import from instapaper completed'); 881 Tools::logm('import from instapaper completed');
896 Tools::redirect(); 882 Tools::redirect();
897 } 883 }
@@ -935,7 +921,9 @@ class Poche
935 # the second <ul> is for read links 921 # the second <ul> is for read links
936 $read = 1; 922 $read = 1;
937 } 923 }
938 $this->messages->add('s', _('import from pocket completed')); 924
925 $unlink = unlink($targetFile);
926 $this->messages->add('s', _('import from pocket completed. You have to execute the cron to fetch content.'));
939 Tools::logm('import from pocket completed'); 927 Tools::logm('import from pocket completed');
940 Tools::redirect(); 928 Tools::redirect();
941 } 929 }
@@ -991,7 +979,9 @@ class Poche
991 } 979 }
992 } 980 }
993 } 981 }
994 $this->messages->add('s', _('import from Readability completed. ' . $count . ' new links.')); 982
983 unlink($targetFile);
984 $this->messages->add('s', _('import from Readability completed. You have to execute the cron to fetch content.'));
995 Tools::logm('import from Readability completed'); 985 Tools::logm('import from Readability completed');
996 Tools::redirect(); 986 Tools::redirect();
997 } 987 }
@@ -1037,7 +1027,9 @@ class Poche
1037 } 1027 }
1038 1028
1039 } 1029 }
1040 $this->messages->add('s', _('import from Poche completed. ' . $count . ' new links.')); 1030
1031 unlink($targetFile);
1032 $this->messages->add('s', _('import from Poche completed. You have to execute the cron to fetch content.'));
1041 Tools::logm('import from Poche completed'); 1033 Tools::logm('import from Poche completed');
1042 Tools::redirect(); 1034 Tools::redirect();
1043 } 1035 }
@@ -1062,13 +1054,7 @@ class Poche
1062 Tools::redirect(); 1054 Tools::redirect();
1063 } 1055 }
1064 1056
1065 $targetDefinition = 'IMPORT_' . strtoupper($from) . '_FILE'; 1057 $targetFile = CACHE . '/' . constant(strtoupper($from) . '_FILE');
1066 $targetFile = constant($targetDefinition);
1067
1068 if (! defined($targetDefinition)) {
1069 $this->messages->add('e', _('Incomplete inc/poche/define.inc.php file, please define "' . $targetDefinition . '".'));
1070 Tools::redirect();
1071 }
1072 1058
1073 if (! file_exists($targetFile)) { 1059 if (! file_exists($targetFile)) {
1074 $this->messages->add('e', _('Could not find required "' . $targetFile . '" import file.')); 1060 $this->messages->add('e', _('Could not find required "' . $targetFile . '" import file.'));
@@ -1078,6 +1064,22 @@ class Poche
1078 $this->$providers[$from]($targetFile); 1064 $this->$providers[$from]($targetFile);
1079 } 1065 }
1080 1066
1067 public function uploadFile() {
1068 if(isset($_FILES['file']))
1069 {
1070 $dir = CACHE . '/';
1071 $file = basename($_FILES['file']['name']);
1072 if(move_uploaded_file($_FILES['file']['tmp_name'], $dir . $file)) {
1073 $this->messages->add('s', _('File uploaded. You can now execute import.'));
1074 }
1075 else {
1076 $this->messages->add('e', _('Error while importing file. Do you have access to upload it?'));
1077 }
1078 }
1079
1080 Tools::redirect('?view=config');
1081 }
1082
1081 /** 1083 /**
1082 * export poche entries in json 1084 * export poche entries in json
1083 * @return json all poche entries 1085 * @return json all poche entries
@@ -1099,15 +1101,17 @@ class Poche
1099 private function getPocheVersion($which = 'prod') 1101 private function getPocheVersion($which = 'prod')
1100 { 1102 {
1101 $cache_file = CACHE . '/' . $which; 1103 $cache_file = CACHE . '/' . $which;
1104 $check_time = time();
1102 1105
1103 # checks if the cached version file exists 1106 # checks if the cached version file exists
1104 if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 86400 ))) { 1107 if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 86400 ))) {
1105 $version = file_get_contents($cache_file); 1108 $version = file_get_contents($cache_file);
1109 $check_time = filemtime($cache_file);
1106 } else { 1110 } else {
1107 $version = file_get_contents('http://static.wallabag.org/versions/' . $which); 1111 $version = file_get_contents('http://static.wallabag.org/versions/' . $which);
1108 file_put_contents($cache_file, $version, LOCK_EX); 1112 file_put_contents($cache_file, $version, LOCK_EX);
1109 } 1113 }
1110 return $version; 1114 return array($version, $check_time);
1111 } 1115 }
1112 1116
1113 public function generateToken() 1117 public function generateToken()
@@ -1124,6 +1128,7 @@ class Poche
1124 $currentConfig = $_SESSION['poche_user']->config; 1128 $currentConfig = $_SESSION['poche_user']->config;
1125 $currentConfig['token'] = $token; 1129 $currentConfig['token'] = $token;
1126 $_SESSION['poche_user']->setConfig($currentConfig); 1130 $_SESSION['poche_user']->setConfig($currentConfig);
1131 Tools::redirect();
1127 } 1132 }
1128 1133
1129 public function generateFeeds($token, $user_id, $tag_id, $type = 'home') 1134 public function generateFeeds($token, $user_id, $tag_id, $type = 'home')
@@ -1131,6 +1136,10 @@ class Poche
1131 $allowed_types = array('home', 'fav', 'archive', 'tag'); 1136 $allowed_types = array('home', 'fav', 'archive', 'tag');
1132 $config = $this->store->getConfigUser($user_id); 1137 $config = $this->store->getConfigUser($user_id);
1133 1138
1139 if ($config == null) {
1140 die(_('User with this id (' . $user_id . ') does not exist.'));
1141 }
1142
1134 if (!in_array($type, $allowed_types) || 1143 if (!in_array($type, $allowed_types) ||
1135 $token != $config['token']) { 1144 $token != $config['token']) {
1136 die(_('Uh, there is a problem while generating feeds.')); 1145 die(_('Uh, there is a problem while generating feeds.'));
@@ -1140,8 +1149,9 @@ class Poche
1140 $feed = new FeedWriter(RSS2); 1149 $feed = new FeedWriter(RSS2);
1141 $feed->setTitle('wallabag — ' . $type . ' feed'); 1150 $feed->setTitle('wallabag — ' . $type . ' feed');
1142 $feed->setLink(Tools::getPocheUrl()); 1151 $feed->setLink(Tools::getPocheUrl());
1143 $feed->setChannelElement('updated', date(DATE_RSS , time())); 1152 $feed->setChannelElement('pubDate', date(DATE_RSS , time()));
1144 $feed->setChannelElement('author', 'wallabag'); 1153 $feed->setChannelElement('generator', 'wallabag');
1154 $feed->setDescription('wallabag ' . $type . ' elements');
1145 1155
1146 if ($type == 'tag') { 1156 if ($type == 'tag') {
1147 $entries = $this->store->retrieveEntriesByTag($tag_id, $user_id); 1157 $entries = $this->store->retrieveEntriesByTag($tag_id, $user_id);
@@ -1154,7 +1164,7 @@ class Poche
1154 foreach ($entries as $entry) { 1164 foreach ($entries as $entry) {
1155 $newItem = $feed->createNewItem(); 1165 $newItem = $feed->createNewItem();
1156 $newItem->setTitle($entry['title']); 1166 $newItem->setTitle($entry['title']);
1157 $newItem->setLink(Tools::getPocheUrl() . '?view=view&amp;id=' . $entry['id']); 1167 $newItem->setLink($entry['url']);
1158 $newItem->setDate(time()); 1168 $newItem->setDate(time());
1159 $newItem->setDescription($entry['content']); 1169 $newItem->setDescription($entry['content']);
1160 $feed->addItem($newItem); 1170 $feed->addItem($newItem);
diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php
index 4ed28ed1..ad451fc6 100644..100755
--- a/inc/poche/Tools.class.php
+++ b/inc/poche/Tools.class.php
@@ -193,7 +193,7 @@ class Tools
193 193
194 public static function logm($message) 194 public static function logm($message)
195 { 195 {
196 if (DEBUG_POCHE) { 196 if (DEBUG_POCHE && php_sapi_name() != 'cli') {
197 $t = strval(date('Y/m/d_H:i:s')) . ' - ' . $_SERVER["REMOTE_ADDR"] . ' - ' . strval($message) . "\n"; 197 $t = strval(date('Y/m/d_H:i:s')) . ' - ' . $_SERVER["REMOTE_ADDR"] . ' - ' . strval($message) . "\n";
198 file_put_contents(CACHE . '/log.txt', $t, FILE_APPEND); 198 file_put_contents(CACHE . '/log.txt', $t, FILE_APPEND);
199 error_log('DEBUG POCHE : ' . $message); 199 error_log('DEBUG POCHE : ' . $message);
@@ -241,7 +241,6 @@ class Tools
241 } 241 }
242 } 242 }
243 243
244
245 public static function download_db() { 244 public static function download_db() {
246 header('Content-Disposition: attachment; filename="poche.sqlite.gz"'); 245 header('Content-Disposition: attachment; filename="poche.sqlite.gz"');
247 self::status(200); 246 self::status(200);
@@ -252,4 +251,74 @@ class Tools
252 251
253 exit; 252 exit;
254 } 253 }
254
255 public static function getPageContent(Url $url)
256 {
257 // Saving and clearing context
258 $REAL = array();
259 foreach( $GLOBALS as $key => $value ) {
260 if( $key != 'GLOBALS' && $key != '_SESSION' && $key != 'HTTP_SESSION_VARS' ) {
261 $GLOBALS[$key] = array();
262 $REAL[$key] = $value;
263 }
264 }
265 // Saving and clearing session
266 if ( isset($_SESSION) ) {
267 $REAL_SESSION = array();
268 foreach( $_SESSION as $key => $value ) {
269 $REAL_SESSION[$key] = $value;
270 unset($_SESSION[$key]);
271 }
272 }
273
274 // Running code in different context
275 $scope = function() {
276 extract( func_get_arg(1) );
277 $_GET = $_REQUEST = array(
278 "url" => $url->getUrl(),
279 "max" => 5,
280 "links" => "preserve",
281 "exc" => "",
282 "format" => "json",
283 "submit" => "Create Feed"
284 );
285 ob_start();
286 require func_get_arg(0);
287 $json = ob_get_contents();
288 ob_end_clean();
289 return $json;
290 };
291 $json = $scope( "inc/3rdparty/makefulltextfeed.php", array("url" => $url) );
292
293 // Clearing and restoring context
294 foreach( $GLOBALS as $key => $value ) {
295 if( $key != "GLOBALS" && $key != "_SESSION" ) {
296 unset($GLOBALS[$key]);
297 }
298 }
299 foreach( $REAL as $key => $value ) {
300 $GLOBALS[$key] = $value;
301 }
302 // Clearing and restoring session
303 if ( isset($REAL_SESSION) ) {
304 foreach( $_SESSION as $key => $value ) {
305 unset($_SESSION[$key]);
306 }
307 foreach( $REAL_SESSION as $key => $value ) {
308 $_SESSION[$key] = $value;
309 }
310 }
311
312 return json_decode($json, true);
313 }
314
315 /**
316 * Returns whether we handle an AJAX (XMLHttpRequest) request.
317 * @return boolean whether we handle an AJAX (XMLHttpRequest) request.
318 */
319 public static function isAjaxRequest()
320 {
321 return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest';
322 }
323
255} 324}