diff options
author | Nicolas Lœuillet <nicolas@loeuillet.org> | 2014-02-21 15:57:10 +0100 |
---|---|---|
committer | Nicolas Lœuillet <nicolas@loeuillet.org> | 2014-02-21 15:57:10 +0100 |
commit | 99679d06884120c57f43b44e55e03595f1f87bed (patch) | |
tree | a3f2a1aa1afdaeca1386d0c6e8a75344fd2241fb /inc/poche/Poche.class.php | |
parent | 655214ab30ee84884dc408488b85586f36263fcb (diff) | |
parent | d3b47e94705e17b3ba3529cbb1dc6efe69c5d2b7 (diff) | |
download | wallabag-1.5.2.tar.gz wallabag-1.5.2.tar.zst wallabag-1.5.2.zip |
Merge pull request #481 from wallabag/dev1.5.2
1.5.2
Diffstat (limited to 'inc/poche/Poche.class.php')
-rwxr-xr-x[-rw-r--r--] | inc/poche/Poche.class.php | 142 |
1 files changed, 106 insertions, 36 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 753bd7f0..34f2ff5a 100644..100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -23,6 +23,19 @@ class Poche | |||
23 | private $currentLanguage = ''; | 23 | private $currentLanguage = ''; |
24 | private $notInstalledMessage = array(); | 24 | private $notInstalledMessage = array(); |
25 | 25 | ||
26 | private $language_names = array( | ||
27 | 'cs_CZ.utf8' => 'čeština', | ||
28 | 'de_DE.utf8' => 'German', | ||
29 | 'en_EN.utf8' => 'English', | ||
30 | 'es_ES.utf8' => 'Español', | ||
31 | 'fa_IR.utf8' => 'فارسی', | ||
32 | 'fr_FR.utf8' => 'Français', | ||
33 | 'it_IT.utf8' => 'Italiano', | ||
34 | 'pl_PL.utf8' => 'Polski', | ||
35 | 'ru_RU.utf8' => 'Pусский', | ||
36 | 'sl_SI.utf8' => 'Slovenščina', | ||
37 | 'uk_UA.utf8' => 'Український', | ||
38 | ); | ||
26 | public function __construct() | 39 | public function __construct() |
27 | { | 40 | { |
28 | if ($this->configFileIsAvailable()) { | 41 | if ($this->configFileIsAvailable()) { |
@@ -307,6 +320,8 @@ class Poche | |||
307 | $themes[$theme] = $this->getThemeInfo($theme); | 320 | $themes[$theme] = $this->getThemeInfo($theme); |
308 | } | 321 | } |
309 | 322 | ||
323 | ksort($themes); | ||
324 | |||
310 | return $themes; | 325 | return $themes; |
311 | } | 326 | } |
312 | 327 | ||
@@ -331,7 +346,7 @@ class Poche | |||
331 | $current = true; | 346 | $current = true; |
332 | } | 347 | } |
333 | 348 | ||
334 | $languages[] = array('name' => $language, 'current' => $current); | 349 | $languages[] = array('name' => $this->language_names[$language], 'value' => $language, 'current' => $current); |
335 | } | 350 | } |
336 | 351 | ||
337 | return $languages; | 352 | return $languages; |
@@ -348,24 +363,62 @@ class Poche | |||
348 | 363 | ||
349 | protected function getPageContent(Url $url) | 364 | protected function getPageContent(Url $url) |
350 | { | 365 | { |
351 | $options = array('http' => array('user_agent' => 'poche')); | 366 | // Saving and clearing context |
352 | if (isset($_SERVER['AUTH_TYPE']) && "basic" === strtolower($_SERVER['AUTH_TYPE'])) { | 367 | $REAL = array(); |
353 | $options['http']['header'] = sprintf( | 368 | foreach( $GLOBALS as $key => $value ) { |
354 | "Authorization: Basic %s", | 369 | if( $key != "GLOBALS" && $key != "_SESSION" ) { |
355 | base64_encode( | 370 | $GLOBALS[$key] = array(); |
356 | sprintf('%s:%s', $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) | 371 | $REAL[$key] = $value; |
357 | ) | 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" | ||
358 | ); | 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; | ||
359 | } | 414 | } |
360 | $context = stream_context_create($options); | ||
361 | $json = file_get_contents(Tools::getPocheUrl() . '/inc/3rdparty/makefulltextfeed.php?url='.urlencode($url->getUrl()).'&max=5&links=preserve&exc=&format=json&submit=Create+Feed', false, $context); | ||
362 | return json_decode($json, true); | 415 | return json_decode($json, true); |
363 | } | 416 | } |
364 | 417 | ||
365 | /** | 418 | /** |
366 | * Call action (mark as fav, archive, delete, etc.) | 419 | * Call action (mark as fav, archive, delete, etc.) |
367 | */ | 420 | */ |
368 | public function action($action, Url $url, $id = 0, $import = FALSE, $autoclose = FALSE) | 421 | public function action($action, Url $url, $id = 0, $import = FALSE, $autoclose = FALSE, $tags = null) |
369 | { | 422 | { |
370 | switch ($action) | 423 | switch ($action) |
371 | { | 424 | { |
@@ -374,6 +427,12 @@ class Poche | |||
374 | $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'); | 427 | $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'); |
375 | $body = $content['rss']['channel']['item']['description']; | 428 | $body = $content['rss']['channel']['item']['description']; |
376 | 429 | ||
430 | // clean content from prevent xss attack | ||
431 | $config = HTMLPurifier_Config::createDefault(); | ||
432 | $purifier = new HTMLPurifier($config); | ||
433 | $title = $purifier->purify($title); | ||
434 | $body = $purifier->purify($body); | ||
435 | |||
377 | //search for possible duplicate if not in import mode | 436 | //search for possible duplicate if not in import mode |
378 | if (!$import) { | 437 | if (!$import) { |
379 | $duplicate = $this->store->retrieveOneByURL($url->getUrl(), $this->user->getId()); | 438 | $duplicate = $this->store->retrieveOneByURL($url->getUrl(), $this->user->getId()); |
@@ -461,8 +520,14 @@ class Poche | |||
461 | } | 520 | } |
462 | break; | 521 | break; |
463 | case 'add_tag' : | 522 | case 'add_tag' : |
464 | $tags = explode(',', $_POST['value']); | 523 | if($import){ |
465 | $entry_id = $_POST['entry_id']; | 524 | $entry_id = $id; |
525 | $tags = explode(',', $tags); | ||
526 | } | ||
527 | else{ | ||
528 | $tags = explode(',', $_POST['value']); | ||
529 | $entry_id = $_POST['entry_id']; | ||
530 | } | ||
466 | $entry = $this->store->retrieveOneById($entry_id, $this->user->getId()); | 531 | $entry = $this->store->retrieveOneById($entry_id, $this->user->getId()); |
467 | if (!$entry) { | 532 | if (!$entry) { |
468 | $this->messages->add('e', _('Article not found!')); | 533 | $this->messages->add('e', _('Article not found!')); |
@@ -489,7 +554,9 @@ class Poche | |||
489 | # we assign the tag to the article | 554 | # we assign the tag to the article |
490 | $this->store->setTagToEntry($tag_id, $entry_id); | 555 | $this->store->setTagToEntry($tag_id, $entry_id); |
491 | } | 556 | } |
492 | Tools::redirect(); | 557 | if(!$import) { |
558 | Tools::redirect(); | ||
559 | } | ||
493 | break; | 560 | break; |
494 | case 'remove_tag' : | 561 | case 'remove_tag' : |
495 | $tag_id = $_GET['tag_id']; | 562 | $tag_id = $_GET['tag_id']; |
@@ -547,14 +614,7 @@ class Poche | |||
547 | $tpl_vars = array( | 614 | $tpl_vars = array( |
548 | 'entry_id' => $id, | 615 | 'entry_id' => $id, |
549 | 'tags' => $tags, | 616 | 'tags' => $tags, |
550 | ); | 617 | 'entry' => $entry, |
551 | break; | ||
552 | case 'tag': | ||
553 | $entries = $this->store->retrieveEntriesByTag($id, $this->user->getId()); | ||
554 | $tag = $this->store->retrieveTag($id, $this->user->getId()); | ||
555 | $tpl_vars = array( | ||
556 | 'tag' => $tag, | ||
557 | 'entries' => $entries, | ||
558 | ); | 618 | ); |
559 | break; | 619 | break; |
560 | case 'tags': | 620 | case 'tags': |
@@ -595,22 +655,28 @@ class Poche | |||
595 | Tools::logm('error in view call : entry is null'); | 655 | Tools::logm('error in view call : entry is null'); |
596 | } | 656 | } |
597 | break; | 657 | break; |
598 | default: # home, favorites and archive views | 658 | default: # home, favorites, archive and tag views |
599 | $entries = $this->store->getEntriesByView($view, $this->user->getId()); | ||
600 | $tpl_vars = array( | 659 | $tpl_vars = array( |
601 | 'entries' => '', | 660 | 'entries' => '', |
602 | 'page_links' => '', | 661 | 'page_links' => '', |
603 | 'nb_results' => '', | 662 | 'nb_results' => '', |
604 | ); | 663 | ); |
605 | 664 | ||
606 | if (count($entries) > 0) { | 665 | //if id is given - we retrive entries by tag: id is tag id |
607 | $this->pagination->set_total(count($entries)); | 666 | if ($id) { |
667 | $tpl_vars['tag'] = $this->store->retrieveTag($id, $this->user->getId()); | ||
668 | $tpl_vars['id'] = intval($id); | ||
669 | } | ||
670 | |||
671 | $count = $this->store->getEntriesByViewCount($view, $this->user->getId(), $id); | ||
672 | |||
673 | if ($count > 0) { | ||
674 | $this->pagination->set_total($count); | ||
608 | $page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')), | 675 | $page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')), |
609 | $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&')); | 676 | $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . (($id)?'&id='.$id:'') . '&' )); |
610 | $datas = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit()); | 677 | $tpl_vars['entries'] = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit(), $id); |
611 | $tpl_vars['entries'] = $datas; | ||
612 | $tpl_vars['page_links'] = $page_links; | 678 | $tpl_vars['page_links'] = $page_links; |
613 | $tpl_vars['nb_results'] = count($entries); | 679 | $tpl_vars['nb_results'] = $count; |
614 | } | 680 | } |
615 | Tools::logm('display ' . $view . ' view'); | 681 | Tools::logm('display ' . $view . ' view'); |
616 | break; | 682 | break; |
@@ -704,7 +770,7 @@ class Poche | |||
704 | $actualLanguage = false; | 770 | $actualLanguage = false; |
705 | 771 | ||
706 | foreach ($languages as $language) { | 772 | foreach ($languages as $language) { |
707 | if ($language['name'] == $_POST['language']) { | 773 | if ($language['value'] == $_POST['language']) { |
708 | $actualLanguage = true; | 774 | $actualLanguage = true; |
709 | break; | 775 | break; |
710 | } | 776 | } |
@@ -852,14 +918,18 @@ class Poche | |||
852 | $a = $li->find('a'); | 918 | $a = $li->find('a'); |
853 | $url = new Url(base64_encode($a[0]->href)); | 919 | $url = new Url(base64_encode($a[0]->href)); |
854 | $this->action('add', $url, 0, TRUE); | 920 | $this->action('add', $url, 0, TRUE); |
921 | $sequence = ''; | ||
922 | if (STORAGE == 'postgres') { | ||
923 | $sequence = 'entries_id_seq'; | ||
924 | } | ||
925 | $last_id = $this->store->getLastId($sequence); | ||
855 | if ($read == '1') { | 926 | if ($read == '1') { |
856 | $sequence = ''; | ||
857 | if (STORAGE == 'postgres') { | ||
858 | $sequence = 'entries_id_seq'; | ||
859 | } | ||
860 | $last_id = $this->store->getLastId($sequence); | ||
861 | $this->action('toggle_archive', $url, $last_id, TRUE); | 927 | $this->action('toggle_archive', $url, $last_id, TRUE); |
862 | } | 928 | } |
929 | $tags = $a[0]->tags; | ||
930 | if(!empty($tags)) { | ||
931 | $this->action('add_tag',$url,$last_id,true,false,$tags); | ||
932 | } | ||
863 | } | 933 | } |
864 | 934 | ||
865 | # the second <ul> is for read links | 935 | # the second <ul> is for read links |