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