X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FService%2FExtractor.php;h=d38b0d76958335df06610061f4ca6191757fa207;hb=7df80cb32ca9b7d0fe452320ddc3563a1e373e2f;hp=1c6ff0ae851632fd80ef36a5a7c7ac21674806d2;hpb=1990517b2263a080946853ed697a6d687262ae80;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Service/Extractor.php b/src/Wallabag/CoreBundle/Service/Extractor.php index 1c6ff0ae..d38b0d76 100644 --- a/src/Wallabag/CoreBundle/Service/Extractor.php +++ b/src/Wallabag/CoreBundle/Service/Extractor.php @@ -7,29 +7,30 @@ use Wallabag\CoreBundle\Helper\Url; final class Extractor { - public static function extract($url) { + public static function extract($url) + { $pageContent = Extractor::getPageContent(new Url(base64_encode($url))); $title = ($pageContent['rss']['channel']['item']['title'] != '') ? $pageContent['rss']['channel']['item']['title'] : _('Untitled'); $body = $pageContent['rss']['channel']['item']['description']; $content = new Content(); $content->setTitle($title); - $content->setBody($body);; + $content->setBody($body); return $content; } /** * Get the content for a given URL (by a call to FullTextFeed) * - * @param Url $url + * @param Url $url * @return mixed */ public static function getPageContent(Url $url) { // Saving and clearing context $REAL = array(); - foreach( $GLOBALS as $key => $value ) { - if( $key != 'GLOBALS' && $key != '_SESSION' && $key != 'HTTP_SESSION_VARS' ) { + foreach ($GLOBALS as $key => $value) { + if ($key != 'GLOBALS' && $key != '_SESSION' && $key != 'HTTP_SESSION_VARS') { $GLOBALS[$key] = array(); $REAL[$key] = $value; } @@ -37,38 +38,39 @@ final class Extractor // Saving and clearing session if (isset($_SESSION)) { $REAL_SESSION = array(); - foreach( $_SESSION as $key => $value ) { + foreach ($_SESSION as $key => $value) { $REAL_SESSION[$key] = $value; unset($_SESSION[$key]); } } // Running code in different context - $scope = function() { - extract( func_get_arg(1) ); + $scope = function () { + extract(func_get_arg(1)); $_GET = $_REQUEST = array( "url" => $url->getUrl(), "max" => 5, "links" => "preserve", "exc" => "", "format" => "json", - "submit" => "Create Feed" + "submit" => "Create Feed", ); ob_start(); require func_get_arg(0); $json = ob_get_contents(); ob_end_clean(); + return $json; }; // Silence $scope function to avoid // issues with FTRSS when error_reporting is to high // FTRSS generates PHP warnings which break output - $json = @$scope(__DIR__ . "/../../../../vendor/wallabag/Fivefilters_Libraries/makefulltextfeed.php", array("url" => $url)); + $json = @$scope(__DIR__."/../../../../vendor/wallabag/Fivefilters_Libraries/makefulltextfeed.php", array("url" => $url)); // Clearing and restoring context foreach ($GLOBALS as $key => $value) { - if($key != "GLOBALS" && $key != "_SESSION" ) { + if ($key != "GLOBALS" && $key != "_SESSION") { unset($GLOBALS[$key]); } } @@ -78,15 +80,15 @@ final class Extractor // Clearing and restoring session if (isset($REAL_SESSION)) { - foreach($_SESSION as $key => $value) { + foreach ($_SESSION as $key => $value) { unset($_SESSION[$key]); } - foreach($REAL_SESSION as $key => $value) { + foreach ($REAL_SESSION as $key => $value) { $_SESSION[$key] = $value; } } return json_decode($json, true); } -} \ No newline at end of file +}