protected function getPageContent(Url $url)
{
- $options = array('http' => array('user_agent' => 'poche'));
- if (isset($_SERVER['AUTH_TYPE']) && "basic" === strtolower($_SERVER['AUTH_TYPE'])) {
- $options['http']['header'] = sprintf(
- "Authorization: Basic %s",
- base64_encode(
- sprintf('%s:%s', $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])
- )
+ // Saving and clearing context
+ $REAL = array();
+ foreach( $GLOBALS as $key => $value ) {
+ if( $key != "GLOBALS" && $key != "_SESSION" ) {
+ $GLOBALS[$key] = array();
+ $REAL[$key] = $value;
+ }
+ }
+ // Saving and clearing session
+ $REAL_SESSION = array();
+ foreach( $_SESSION as $key => $value ) {
+ $REAL_SESSION[$key] = $value;
+ unset($_SESSION[$key]);
+ }
+
+ // Running code in different context
+ $scope = function() {
+ extract( func_get_arg(1) );
+ $_GET = $_REQUEST = array(
+ "url" => $url->getUrl(),
+ "max" => 5,
+ "links" => "preserve",
+ "exc" => "",
+ "format" => "json",
+ "submit" => "Create Feed"
);
+ ob_start();
+ require func_get_arg(0);
+ $json = ob_get_flush();
+ return $json;
+ };
+ $json = $scope( "inc/3rdparty/makefulltextfeed.php", array("url" => $url) );
+
+ // Clearing and restoring context
+ foreach( $GLOBALS as $key => $value ) {
+ if( $key != "GLOBALS" && $key != "_SESSION" ) {
+ unset($GLOBALS[$key]);
+ }
+ }
+ foreach( $REAL as $key => $value ) {
+ $GLOBALS[$key] = $value;
+ }
+ // Clearing and restoring session
+ foreach( $_SESSION as $key => $value ) {
+ unset($_SESSION[$key]);
+ }
+ foreach( $REAL_SESSION as $key => $value ) {
+ $_SESSION[$key] = $value;
}
- $context = stream_context_create($options);
- $json = file_get_contents(Tools::getPocheUrl() . '/inc/3rdparty/makefulltextfeed.php?url='.urlencode($url->getUrl()).'&max=5&links=preserve&exc=&format=json&submit=Create+Feed', false, $context);
return json_decode($json, true);
}