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'] != '') ? $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);
23 * Get the content for a given URL (by a call to FullTextFeed)
28 public static function getPageContent(Url
$url)
30 // Saving and clearing context
32 foreach ($GLOBALS as $key => $value) {
33 if ($key != 'GLOBALS' && $key != '_SESSION' && $key != 'HTTP_SESSION_VARS') {
34 $GLOBALS[$key] = array();
38 // Saving and clearing session
39 if (isset($_SESSION)) {
40 $REAL_SESSION = array();
41 foreach ($_SESSION as $key => $value) {
42 $REAL_SESSION[$key] = $value;
43 unset($_SESSION[$key]);
47 // Running code in different context
48 $scope = function () {
49 extract(func_get_arg(1));
50 $_GET = $_REQUEST = array(
51 "url" => $url->getUrl(),
53 "links" => "preserve",
56 "submit" => "Create Feed",
59 require func_get_arg(0);
60 $json = ob_get_contents();
66 // Silence $scope function to avoid
67 // issues with FTRSS when error_reporting is to high
68 // FTRSS generates PHP warnings which break output
69 $json = @$scope(__DIR__
."/../../../../vendor/wallabag/Fivefilters_Libraries/makefulltextfeed.php", array("url" => $url));
71 // Clearing and restoring context
72 foreach ($GLOBALS as $key => $value) {
73 if ($key != "GLOBALS" && $key != "_SESSION") {
74 unset($GLOBALS[$key]);
77 foreach ($REAL as $key => $value) {
78 $GLOBALS[$key] = $value;
81 // Clearing and restoring session
82 if (isset($REAL_SESSION)) {
83 foreach ($_SESSION as $key => $value) {
84 unset($_SESSION[$key]);
87 foreach ($REAL_SESSION as $key => $value) {
88 $_SESSION[$key] = $value;
92 return json_decode($json, true);