aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Poche.class.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/poche/Poche.class.php')
-rwxr-xr-xinc/poche/Poche.class.php199
1 files changed, 102 insertions, 97 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 87c00b78..7bf33308 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -35,6 +35,7 @@ class Poche
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 {
@@ -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 }
549 } 510 $tag_id = $this->store->getLastId($sequence);
550 else { 511 }
551 $tag_id = $tag['id']; 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);
552 } 518 }
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
@@ -895,7 +875,9 @@ class Poche
895 # the second <ol> is for read links 875 # the second <ol> is for read links
896 $read = 1; 876 $read = 1;
897 } 877 }
898 $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.'));
899 Tools::logm('import from instapaper completed'); 881 Tools::logm('import from instapaper completed');
900 Tools::redirect(); 882 Tools::redirect();
901 } 883 }
@@ -939,7 +921,9 @@ class Poche
939 # the second <ul> is for read links 921 # the second <ul> is for read links
940 $read = 1; 922 $read = 1;
941 } 923 }
942 $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.'));
943 Tools::logm('import from pocket completed'); 927 Tools::logm('import from pocket completed');
944 Tools::redirect(); 928 Tools::redirect();
945 } 929 }
@@ -995,7 +979,9 @@ class Poche
995 } 979 }
996 } 980 }
997 } 981 }
998 $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.'));
999 Tools::logm('import from Readability completed'); 985 Tools::logm('import from Readability completed');
1000 Tools::redirect(); 986 Tools::redirect();
1001 } 987 }
@@ -1041,7 +1027,9 @@ class Poche
1041 } 1027 }
1042 1028
1043 } 1029 }
1044 $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.'));
1045 Tools::logm('import from Poche completed'); 1033 Tools::logm('import from Poche completed');
1046 Tools::redirect(); 1034 Tools::redirect();
1047 } 1035 }
@@ -1066,13 +1054,7 @@ class Poche
1066 Tools::redirect(); 1054 Tools::redirect();
1067 } 1055 }
1068 1056
1069 $targetDefinition = 'IMPORT_' . strtoupper($from) . '_FILE'; 1057 $targetFile = CACHE . '/' . constant(strtoupper($from) . '_FILE');
1070 $targetFile = constant($targetDefinition);
1071
1072 if (! defined($targetDefinition)) {
1073 $this->messages->add('e', _('Incomplete inc/poche/define.inc.php file, please define "' . $targetDefinition . '".'));
1074 Tools::redirect();
1075 }
1076 1058
1077 if (! file_exists($targetFile)) { 1059 if (! file_exists($targetFile)) {
1078 $this->messages->add('e', _('Could not find required "' . $targetFile . '" import file.')); 1060 $this->messages->add('e', _('Could not find required "' . $targetFile . '" import file.'));
@@ -1082,6 +1064,22 @@ class Poche
1082 $this->$providers[$from]($targetFile); 1064 $this->$providers[$from]($targetFile);
1083 } 1065 }
1084 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
1085 /** 1083 /**
1086 * export poche entries in json 1084 * export poche entries in json
1087 * @return json all poche entries 1085 * @return json all poche entries
@@ -1103,15 +1101,17 @@ class Poche
1103 private function getPocheVersion($which = 'prod') 1101 private function getPocheVersion($which = 'prod')
1104 { 1102 {
1105 $cache_file = CACHE . '/' . $which; 1103 $cache_file = CACHE . '/' . $which;
1104 $check_time = time();
1106 1105
1107 # checks if the cached version file exists 1106 # checks if the cached version file exists
1108 if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 86400 ))) { 1107 if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 86400 ))) {
1109 $version = file_get_contents($cache_file); 1108 $version = file_get_contents($cache_file);
1109 $check_time = filemtime($cache_file);
1110 } else { 1110 } else {
1111 $version = file_get_contents('http://static.wallabag.org/versions/' . $which); 1111 $version = file_get_contents('http://static.wallabag.org/versions/' . $which);
1112 file_put_contents($cache_file, $version, LOCK_EX); 1112 file_put_contents($cache_file, $version, LOCK_EX);
1113 } 1113 }
1114 return $version; 1114 return array($version, $check_time);
1115 } 1115 }
1116 1116
1117 public function generateToken() 1117 public function generateToken()
@@ -1136,6 +1136,10 @@ class Poche
1136 $allowed_types = array('home', 'fav', 'archive', 'tag'); 1136 $allowed_types = array('home', 'fav', 'archive', 'tag');
1137 $config = $this->store->getConfigUser($user_id); 1137 $config = $this->store->getConfigUser($user_id);
1138 1138
1139 if ($config == null) {
1140 die(_('User with this id (' . $user_id . ') does not exist.'));
1141 }
1142
1139 if (!in_array($type, $allowed_types) || 1143 if (!in_array($type, $allowed_types) ||
1140 $token != $config['token']) { 1144 $token != $config['token']) {
1141 die(_('Uh, there is a problem while generating feeds.')); 1145 die(_('Uh, there is a problem while generating feeds.'));
@@ -1145,8 +1149,9 @@ class Poche
1145 $feed = new FeedWriter(RSS2); 1149 $feed = new FeedWriter(RSS2);
1146 $feed->setTitle('wallabag — ' . $type . ' feed'); 1150 $feed->setTitle('wallabag — ' . $type . ' feed');
1147 $feed->setLink(Tools::getPocheUrl()); 1151 $feed->setLink(Tools::getPocheUrl());
1148 $feed->setChannelElement('updated', date(DATE_RSS , time())); 1152 $feed->setChannelElement('pubDate', date(DATE_RSS , time()));
1149 $feed->setChannelElement('author', 'wallabag'); 1153 $feed->setChannelElement('generator', 'wallabag');
1154 $feed->setDescription('wallabag ' . $type . ' elements');
1150 1155
1151 if ($type == 'tag') { 1156 if ($type == 'tag') {
1152 $entries = $this->store->retrieveEntriesByTag($tag_id, $user_id); 1157 $entries = $this->store->retrieveEntriesByTag($tag_id, $user_id);
@@ -1159,7 +1164,7 @@ class Poche
1159 foreach ($entries as $entry) { 1164 foreach ($entries as $entry) {
1160 $newItem = $feed->createNewItem(); 1165 $newItem = $feed->createNewItem();
1161 $newItem->setTitle($entry['title']); 1166 $newItem->setTitle($entry['title']);
1162 $newItem->setLink(Tools::getPocheUrl() . '?view=view&amp;id=' . $entry['id']); 1167 $newItem->setLink($entry['url']);
1163 $newItem->setDate(time()); 1168 $newItem->setDate(time());
1164 $newItem->setDescription($entry['content']); 1169 $newItem->setDescription($entry['content']);
1165 $feed->addItem($newItem); 1170 $feed->addItem($newItem);