3 namespace Wallabag\CoreBundle\Service
;
5 use Wallabag\CoreBundle\Helper\Content
;
6 use Wallabag\CoreBundle\Helper\Url
;
10 public static function extract($url)
12 $pageContent = Extractor
::getPageContent(new Url(base64_encode($url)));
13 $title = $pageContent['rss']['channel']['item']['title'] ?: 'Untitled';
14 $body = $pageContent['rss']['channel']['item']['description'];
16 $content = new Content();
17 $content->setTitle($title);
18 $content->setBody($body);
24 * Get the content for a given URL (by a call to FullTextFeed)
29 public static function getPageContent(Url
$url)
31 // Saving and clearing context
33 foreach ($GLOBALS as $key => $value) {
34 if ($key != 'GLOBALS' && $key != '_SESSION' && $key != 'HTTP_SESSION_VARS') {
35 $GLOBALS[$key] = array();
39 // Saving and clearing session
40 if (isset($_SESSION)) {
41 $REAL_SESSION = array();
42 foreach ($_SESSION as $key => $value) {
43 $REAL_SESSION[$key] = $value;
44 unset($_SESSION[$key]);
48 // Running code in different context
49 $scope = function () {
50 extract(func_get_arg(1));
51 $_GET = $_REQUEST = array(
52 "url" => $url->getUrl(),
54 "links" => "preserve",
57 "submit" => "Create Feed",
60 require func_get_arg(0);
61 $json = ob_get_contents();
67 // Silence $scope function to avoid
68 // issues with FTRSS when error_reporting is to high
69 // FTRSS generates PHP warnings which break output
70 $json = @$scope(__DIR__
."/../../../../vendor/wallabag/Fivefilters_Libraries/makefulltextfeed.php", array("url" => $url));
72 // Clearing and restoring context
73 foreach ($GLOBALS as $key => $value) {
74 if ($key != "GLOBALS" && $key != "_SESSION") {
75 unset($GLOBALS[$key]);
78 foreach ($REAL as $key => $value) {
79 $GLOBALS[$key] = $value;
82 // Clearing and restoring session
83 if (isset($REAL_SESSION)) {
84 foreach ($_SESSION as $key => $value) {
85 unset($_SESSION[$key]);
88 foreach ($REAL_SESSION as $key => $value) {
89 $_SESSION[$key] = $value;
93 return json_decode($json, true);