aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Poche.class.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2014-02-28 21:49:38 +0100
committerNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2014-02-28 21:49:38 +0100
commit53e3158dfe697ea59da1fa0e401e8da75ae13030 (patch)
tree60cac2249e5ebedc7b87f33025048f3b66490ab3 /inc/poche/Poche.class.php
parent31a10069a52c2fd2aca3a835a7bdc1accae197f5 (diff)
downloadwallabag-53e3158dfe697ea59da1fa0e401e8da75ae13030.tar.gz
wallabag-53e3158dfe697ea59da1fa0e401e8da75ae13030.tar.zst
wallabag-53e3158dfe697ea59da1fa0e401e8da75ae13030.zip
[add] cron to fetch content on imported entries
Diffstat (limited to 'inc/poche/Poche.class.php')
-rwxr-xr-xinc/poche/Poche.class.php86
1 files changed, 19 insertions, 67 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 026b0b4e..5a89a8d2 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -362,60 +362,6 @@ class Poche
362 ); 362 );
363 } 363 }
364 364
365 protected function getPageContent(Url $url)
366 {
367 // Saving and clearing context
368 $REAL = array();
369 foreach( $GLOBALS as $key => $value ) {
370 if( $key != 'GLOBALS' && $key != '_SESSION' && $key != 'HTTP_SESSION_VARS' ) {
371 $GLOBALS[$key] = array();
372 $REAL[$key] = $value;
373 }
374 }
375 // Saving and clearing session
376 $REAL_SESSION = array();
377 foreach( $_SESSION as $key => $value ) {
378 $REAL_SESSION[$key] = $value;
379 unset($_SESSION[$key]);
380 }
381
382 // Running code in different context
383 $scope = function() {
384 extract( func_get_arg(1) );
385 $_GET = $_REQUEST = array(
386 "url" => $url->getUrl(),
387 "max" => 5,
388 "links" => "preserve",
389 "exc" => "",
390 "format" => "json",
391 "submit" => "Create Feed"
392 );
393 ob_start();
394 require func_get_arg(0);
395 $json = ob_get_flush();
396 return $json;
397 };
398 $json = $scope( "inc/3rdparty/makefulltextfeed.php", array("url" => $url) );
399
400 // Clearing and restoring context
401 foreach( $GLOBALS as $key => $value ) {
402 if( $key != "GLOBALS" && $key != "_SESSION" ) {
403 unset($GLOBALS[$key]);
404 }
405 }
406 foreach( $REAL as $key => $value ) {
407 $GLOBALS[$key] = $value;
408 }
409 // Clearing and restoring session
410 foreach( $_SESSION as $key => $value ) {
411 unset($_SESSION[$key]);
412 }
413 foreach( $REAL_SESSION as $key => $value ) {
414 $_SESSION[$key] = $value;
415 }
416 return json_decode($json, true);
417 }
418
419 /** 365 /**
420 * Call action (mark as fav, archive, delete, etc.) 366 * Call action (mark as fav, archive, delete, etc.)
421 */ 367 */
@@ -424,15 +370,21 @@ class Poche
424 switch ($action) 370 switch ($action)
425 { 371 {
426 case 'add': 372 case 'add':
427 $content = $this->getPageContent($url); 373 if (!$import) {
428 $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'); 374 $content = Tools::getPageContent($url);
429 $body = $content['rss']['channel']['item']['description']; 375 $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled');
430 376 $body = $content['rss']['channel']['item']['description'];
431 // clean content from prevent xss attack 377
432 $config = HTMLPurifier_Config::createDefault(); 378 // clean content from prevent xss attack
433 $purifier = new HTMLPurifier($config); 379 $config = HTMLPurifier_Config::createDefault();
434 $title = $purifier->purify($title); 380 $purifier = new HTMLPurifier($config);
435 $body = $purifier->purify($body); 381 $title = $purifier->purify($title);
382 $body = $purifier->purify($body);
383 }
384 else {
385 $title = '';
386 $body = '';
387 }
436 388
437 //search for possible duplicate if not in import mode 389 //search for possible duplicate if not in import mode
438 if (!$import) { 390 if (!$import) {
@@ -897,7 +849,7 @@ class Poche
897 # the second <ol> is for read links 849 # the second <ol> is for read links
898 $read = 1; 850 $read = 1;
899 } 851 }
900 $this->messages->add('s', _('import from instapaper completed')); 852 $this->messages->add('s', _('import from instapaper completed. You have to execute the cron to fetch content.'));
901 Tools::logm('import from instapaper completed'); 853 Tools::logm('import from instapaper completed');
902 Tools::redirect(); 854 Tools::redirect();
903 } 855 }
@@ -941,7 +893,7 @@ class Poche
941 # the second <ul> is for read links 893 # the second <ul> is for read links
942 $read = 1; 894 $read = 1;
943 } 895 }
944 $this->messages->add('s', _('import from pocket completed')); 896 $this->messages->add('s', _('import from pocket completed. You have to execute the cron to fetch content.'));
945 Tools::logm('import from pocket completed'); 897 Tools::logm('import from pocket completed');
946 Tools::redirect(); 898 Tools::redirect();
947 } 899 }
@@ -997,7 +949,7 @@ class Poche
997 } 949 }
998 } 950 }
999 } 951 }
1000 $this->messages->add('s', _('import from Readability completed. ' . $count . ' new links.')); 952 $this->messages->add('s', _('import from Readability completed. You have to execute the cron to fetch content.'));
1001 Tools::logm('import from Readability completed'); 953 Tools::logm('import from Readability completed');
1002 Tools::redirect(); 954 Tools::redirect();
1003 } 955 }
@@ -1043,7 +995,7 @@ class Poche
1043 } 995 }
1044 996
1045 } 997 }
1046 $this->messages->add('s', _('import from Poche completed. ' . $count . ' new links.')); 998 $this->messages->add('s', _('import from Poche completed. You have to execute the cron to fetch content.'));
1047 Tools::logm('import from Poche completed'); 999 Tools::logm('import from Poche completed');
1048 Tools::redirect(); 1000 Tools::redirect();
1049 } 1001 }