3 namespace Wallabag\CoreBundle\Service
;
5 use Wallabag\CoreBundle\Helper\Content
;
6 use Wallabag\Wallabag\Url
;
10 public static function extract($url) {
11 $pageContent = Extractor
::getPageContent(new Url(base64_encode($url)));
12 $title = ($pageContent['rss']['channel']['item']['title'] != '') ? $pageContent['rss']['channel']['item']['title'] : _('Untitled');
13 $body = $pageContent['rss']['channel']['item']['description'];
15 $content = new Content();
16 $content->setTitle($title);
17 $content->setBody($body);;
22 * Get the content for a given URL (by a call to FullTextFeed)
27 public static function getPageContent(Url
$url)
29 // Saving and clearing context
31 foreach( $GLOBALS as $key => $value ) {
32 if( $key != 'GLOBALS' && $key != '_SESSION' && $key != 'HTTP_SESSION_VARS' ) {
33 $GLOBALS[$key] = array();
37 // Saving and clearing session
38 if (isset($_SESSION)) {
39 $REAL_SESSION = array();
40 foreach( $_SESSION as $key => $value ) {
41 $REAL_SESSION[$key] = $value;
42 unset($_SESSION[$key]);
46 // Running code in different context
48 extract( func_get_arg(1) );
49 $_GET = $_REQUEST = array(
50 "url" => $url->getUrl(),
52 "links" => "preserve",
55 "submit" => "Create Feed"
58 require func_get_arg(0);
59 $json = ob_get_contents();
64 // Silence $scope function to avoid
65 // issues with FTRSS when error_reporting is to high
66 // FTRSS generates PHP warnings which break output
67 $json = @$scope(__DIR__
. "/../../../../vendor/wallabag/Fivefilters_Libraries/makefulltextfeed.php", array("url" => $url));
69 // Clearing and restoring context
70 foreach ($GLOBALS as $key => $value) {
71 if($key != "GLOBALS" && $key != "_SESSION" ) {
72 unset($GLOBALS[$key]);
75 foreach ($REAL as $key => $value) {
76 $GLOBALS[$key] = $value;
79 // Clearing and restoring session
80 if (isset($REAL_SESSION)) {
81 foreach($_SESSION as $key => $value) {
82 unset($_SESSION[$key]);
85 foreach($REAL_SESSION as $key => $value) {
86 $_SESSION[$key] = $value;
90 return json_decode($json, true);