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 = 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'];
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).
30 public static function getPageContent(Url
$url)
32 // Saving and clearing context
34 foreach ($GLOBALS as $key => $value) {
35 if ($key != 'GLOBALS' && $key != '_SESSION' && $key != 'HTTP_SESSION_VARS') {
36 $GLOBALS[$key] = array();
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]);
49 // Running code in different context
50 $scope = function () {
51 extract(func_get_arg(1));
52 $_GET = $_REQUEST = array(
53 'url' => $url->getUrl(),
55 'links' => 'preserve',
58 'submit' => 'Create Feed',
61 require func_get_arg(0);
62 $json = ob_get_contents();
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));
73 // Clearing and restoring context
74 foreach ($GLOBALS as $key => $value) {
75 if ($key != 'GLOBALS' && $key != '_SESSION') {
76 unset($GLOBALS[$key]);
79 foreach ($REAL as $key => $value) {
80 $GLOBALS[$key] = $value;
83 // Clearing and restoring session
84 if (isset($REAL_SESSION)) {
85 foreach ($_SESSION as $key => $value) {
86 unset($_SESSION[$key]);
89 foreach ($REAL_SESSION as $key => $value) {
90 $_SESSION[$key] = $value;
94 return json_decode($json, true);