aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Service/Extractor.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Service/Extractor.php')
-rw-r--r--src/Wallabag/CoreBundle/Service/Extractor.php30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/Wallabag/CoreBundle/Service/Extractor.php b/src/Wallabag/CoreBundle/Service/Extractor.php
index 1c6ff0ae..d38b0d76 100644
--- a/src/Wallabag/CoreBundle/Service/Extractor.php
+++ b/src/Wallabag/CoreBundle/Service/Extractor.php
@@ -7,29 +7,30 @@ use Wallabag\CoreBundle\Helper\Url;
7 7
8final class Extractor 8final class Extractor
9{ 9{
10 public static function extract($url) { 10 public static function extract($url)
11 {
11 $pageContent = Extractor::getPageContent(new Url(base64_encode($url))); 12 $pageContent = Extractor::getPageContent(new Url(base64_encode($url)));
12 $title = ($pageContent['rss']['channel']['item']['title'] != '') ? $pageContent['rss']['channel']['item']['title'] : _('Untitled'); 13 $title = ($pageContent['rss']['channel']['item']['title'] != '') ? $pageContent['rss']['channel']['item']['title'] : _('Untitled');
13 $body = $pageContent['rss']['channel']['item']['description']; 14 $body = $pageContent['rss']['channel']['item']['description'];
14 15
15 $content = new Content(); 16 $content = new Content();
16 $content->setTitle($title); 17 $content->setTitle($title);
17 $content->setBody($body);; 18 $content->setBody($body);
18 19
19 return $content; 20 return $content;
20 } 21 }
21 /** 22 /**
22 * Get the content for a given URL (by a call to FullTextFeed) 23 * Get the content for a given URL (by a call to FullTextFeed)
23 * 24 *
24 * @param Url $url 25 * @param Url $url
25 * @return mixed 26 * @return mixed
26 */ 27 */
27 public static function getPageContent(Url $url) 28 public static function getPageContent(Url $url)
28 { 29 {
29 // Saving and clearing context 30 // Saving and clearing context
30 $REAL = array(); 31 $REAL = array();
31 foreach( $GLOBALS as $key => $value ) { 32 foreach ($GLOBALS as $key => $value) {
32 if( $key != 'GLOBALS' && $key != '_SESSION' && $key != 'HTTP_SESSION_VARS' ) { 33 if ($key != 'GLOBALS' && $key != '_SESSION' && $key != 'HTTP_SESSION_VARS') {
33 $GLOBALS[$key] = array(); 34 $GLOBALS[$key] = array();
34 $REAL[$key] = $value; 35 $REAL[$key] = $value;
35 } 36 }
@@ -37,38 +38,39 @@ final class Extractor
37 // Saving and clearing session 38 // Saving and clearing session
38 if (isset($_SESSION)) { 39 if (isset($_SESSION)) {
39 $REAL_SESSION = array(); 40 $REAL_SESSION = array();
40 foreach( $_SESSION as $key => $value ) { 41 foreach ($_SESSION as $key => $value) {
41 $REAL_SESSION[$key] = $value; 42 $REAL_SESSION[$key] = $value;
42 unset($_SESSION[$key]); 43 unset($_SESSION[$key]);
43 } 44 }
44 } 45 }
45 46
46 // Running code in different context 47 // Running code in different context
47 $scope = function() { 48 $scope = function () {
48 extract( func_get_arg(1) ); 49 extract(func_get_arg(1));
49 $_GET = $_REQUEST = array( 50 $_GET = $_REQUEST = array(
50 "url" => $url->getUrl(), 51 "url" => $url->getUrl(),
51 "max" => 5, 52 "max" => 5,
52 "links" => "preserve", 53 "links" => "preserve",
53 "exc" => "", 54 "exc" => "",
54 "format" => "json", 55 "format" => "json",
55 "submit" => "Create Feed" 56 "submit" => "Create Feed",
56 ); 57 );
57 ob_start(); 58 ob_start();
58 require func_get_arg(0); 59 require func_get_arg(0);
59 $json = ob_get_contents(); 60 $json = ob_get_contents();
60 ob_end_clean(); 61 ob_end_clean();
62
61 return $json; 63 return $json;
62 }; 64 };
63 65
64 // Silence $scope function to avoid 66 // Silence $scope function to avoid
65 // issues with FTRSS when error_reporting is to high 67 // issues with FTRSS when error_reporting is to high
66 // FTRSS generates PHP warnings which break output 68 // FTRSS generates PHP warnings which break output
67 $json = @$scope(__DIR__ . "/../../../../vendor/wallabag/Fivefilters_Libraries/makefulltextfeed.php", array("url" => $url)); 69 $json = @$scope(__DIR__."/../../../../vendor/wallabag/Fivefilters_Libraries/makefulltextfeed.php", array("url" => $url));
68 70
69 // Clearing and restoring context 71 // Clearing and restoring context
70 foreach ($GLOBALS as $key => $value) { 72 foreach ($GLOBALS as $key => $value) {
71 if($key != "GLOBALS" && $key != "_SESSION" ) { 73 if ($key != "GLOBALS" && $key != "_SESSION") {
72 unset($GLOBALS[$key]); 74 unset($GLOBALS[$key]);
73 } 75 }
74 } 76 }
@@ -78,15 +80,15 @@ final class Extractor
78 80
79 // Clearing and restoring session 81 // Clearing and restoring session
80 if (isset($REAL_SESSION)) { 82 if (isset($REAL_SESSION)) {
81 foreach($_SESSION as $key => $value) { 83 foreach ($_SESSION as $key => $value) {
82 unset($_SESSION[$key]); 84 unset($_SESSION[$key]);
83 } 85 }
84 86
85 foreach($REAL_SESSION as $key => $value) { 87 foreach ($REAL_SESSION as $key => $value) {
86 $_SESSION[$key] = $value; 88 $_SESSION[$key] = $value;
87 } 89 }
88 } 90 }
89 91
90 return json_decode($json, true); 92 return json_decode($json, true);
91 } 93 }
92} \ No newline at end of file 94}