aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Poche.class.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2014-03-07 13:26:56 +0100
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2014-03-07 13:26:56 +0100
commitded2c63312c32c85f386d6cd8cd7085d8a9407e9 (patch)
tree4de5518586a1f45a3947d780962f264deaa0482d /inc/poche/Poche.class.php
parent25114854b3e6b42c7be5e21a62539d8f23d3a10e (diff)
parentbf79463070c0dc96eacc52a949c1e3ad356817c0 (diff)
downloadwallabag-ded2c63312c32c85f386d6cd8cd7085d8a9407e9.tar.gz
wallabag-ded2c63312c32c85f386d6cd8cd7085d8a9407e9.tar.zst
wallabag-ded2c63312c32c85f386d6cd8cd7085d8a9407e9.zip
Merge pull request #532 from wallabag/upload-file
New import system
Diffstat (limited to 'inc/poche/Poche.class.php')
-rwxr-xr-xinc/poche/Poche.class.php110
1 files changed, 36 insertions, 74 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index ba262c98..fb4e1a7f 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) {
@@ -903,7 +855,7 @@ class Poche
903 # the second <ol> is for read links 855 # the second <ol> is for read links
904 $read = 1; 856 $read = 1;
905 } 857 }
906 $this->messages->add('s', _('import from instapaper completed')); 858 $this->messages->add('s', _('import from instapaper completed. You have to execute the cron to fetch content.'));
907 Tools::logm('import from instapaper completed'); 859 Tools::logm('import from instapaper completed');
908 Tools::redirect(); 860 Tools::redirect();
909 } 861 }
@@ -947,7 +899,7 @@ class Poche
947 # the second <ul> is for read links 899 # the second <ul> is for read links
948 $read = 1; 900 $read = 1;
949 } 901 }
950 $this->messages->add('s', _('import from pocket completed')); 902 $this->messages->add('s', _('import from pocket completed. You have to execute the cron to fetch content.'));
951 Tools::logm('import from pocket completed'); 903 Tools::logm('import from pocket completed');
952 Tools::redirect(); 904 Tools::redirect();
953 } 905 }
@@ -1003,7 +955,7 @@ class Poche
1003 } 955 }
1004 } 956 }
1005 } 957 }
1006 $this->messages->add('s', _('import from Readability completed. ' . $count . ' new links.')); 958 $this->messages->add('s', _('import from Readability completed. You have to execute the cron to fetch content.'));
1007 Tools::logm('import from Readability completed'); 959 Tools::logm('import from Readability completed');
1008 Tools::redirect(); 960 Tools::redirect();
1009 } 961 }
@@ -1049,7 +1001,7 @@ class Poche
1049 } 1001 }
1050 1002
1051 } 1003 }
1052 $this->messages->add('s', _('import from Poche completed. ' . $count . ' new links.')); 1004 $this->messages->add('s', _('import from Poche completed. You have to execute the cron to fetch content.'));
1053 Tools::logm('import from Poche completed'); 1005 Tools::logm('import from Poche completed');
1054 Tools::redirect(); 1006 Tools::redirect();
1055 } 1007 }
@@ -1074,13 +1026,7 @@ class Poche
1074 Tools::redirect(); 1026 Tools::redirect();
1075 } 1027 }
1076 1028
1077 $targetDefinition = 'IMPORT_' . strtoupper($from) . '_FILE'; 1029 $targetFile = CACHE . '/' . constant(strtoupper($from) . '_FILE');
1078 $targetFile = constant($targetDefinition);
1079
1080 if (! defined($targetDefinition)) {
1081 $this->messages->add('e', _('Incomplete inc/poche/define.inc.php file, please define "' . $targetDefinition . '".'));
1082 Tools::redirect();
1083 }
1084 1030
1085 if (! file_exists($targetFile)) { 1031 if (! file_exists($targetFile)) {
1086 $this->messages->add('e', _('Could not find required "' . $targetFile . '" import file.')); 1032 $this->messages->add('e', _('Could not find required "' . $targetFile . '" import file.'));
@@ -1090,6 +1036,22 @@ class Poche
1090 $this->$providers[$from]($targetFile); 1036 $this->$providers[$from]($targetFile);
1091 } 1037 }
1092 1038
1039 public function uploadFile() {
1040 if(isset($_FILES['file']))
1041 {
1042 $dir = CACHE . '/';
1043 $file = basename($_FILES['file']['name']);
1044 if(move_uploaded_file($_FILES['file']['tmp_name'], $dir . $file)) {
1045 $this->messages->add('s', _('File uploaded. You can now execute import.'));
1046 }
1047 else {
1048 $this->messages->add('e', _('Error while importing file. Do you have access to upload it?'));
1049 }
1050 }
1051
1052 Tools::redirect('?view=config');
1053 }
1054
1093 /** 1055 /**
1094 * export poche entries in json 1056 * export poche entries in json
1095 * @return json all poche entries 1057 * @return json all poche entries