<?php
/*
	Copyright (c) PORTANEO.

	This file is part of POSH (Portaneo Open Source Homepage) http://sourceforge.net/projects/posh/.

	POSH is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version

	POSH is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Posh.  If not, see <http://www.gnu.org/licenses/>.
*/
# !! be careful, this file must be saved under uft8 format, and display an e accentuated here : éàèù
/*
    @file
        tools/xmltunproxypac.php

        tunnel to get data from other domain in ajax request ( bypass cross-domain  )
        
        @param ptyp
        
        @param url
        
        @param useproxy
        
        @param proxy
        
        @deprecated
        
        Same code in xmltunproxy and xmlvalidrss
        
*/
$tp=$_REQUEST["ptyp"];
//$t=$_SERVER['QUERY_STRING'];
//$t=substr($t,strpos($t,"url")+4);
//$t=substr($t,0,strpos($t,"&proxy"));
$url = $_REQUEST["url"];

if ($tp=="xml") header("Content-type: text/xml; charset=UTF-8");
if ($url == "") exit();

require_once('../includes/http.inc.php');
require_once('../includes/misc.inc.php');
require('../includes/config.inc.php');
require_once('../includes/feed.inc.php');

$h = new http($url);
$x = '';

/*
if (__useproxy)
{
    if (isset($_REQUEST["proxy"]))
    {
        $proxy=$_REQUEST["proxy"];
        $pos=strpos($proxy,":");
        $proxyserver=substr($proxy,0,$pos);
        $proxyport=substr($proxy,$pos+1);
    }
    else
    {
        $proxyserver=__PROXYSERVER;
        $proxyport=__PROXYPORT;
    }
    $h->cServer=$proxyserver;
    $h->cPort=$proxyport;
    $h->proxy_auth = "Proxy-Authorization: Basic ".__PROXYCONNECTION."\r\n";    
}
*/
if (isset($_REQUEST['auth']))
{
    $h->put_authorization("Basic ".$_REQUEST["auth"]);
}
$body = $h->get();
$f = new feed('');
$body = $f->transcode($body);
echo $body;



/*

$x = '';

$proxy=$_GET["proxy"];
$pos=strpos($proxy,":");
$proxyserver=substr($proxy,0,$pos);
$proxyport=substr($proxy,$pos+1);

$proxy_fp = fsockopen($proxyserver, $proxyport);
if (!$proxy_fp)    {return false;}
fputs($proxy_fp, "GET $t HTTP/1.0\r\n");
fputs($proxy_fp, "Proxy-Authorization: Basic ".__PROXYCONNECTION."\r\n\r\n");
//while(!feof($proxy_fp)) {$x .= fread($proxy_fp,4092);}
while(!feof($proxy_fp)) {$x .= fgets($proxy_fp,4092);}
fclose($proxy_fp);
//suppress http header
$x = substr($x, strpos($x,"\r\n\r\n")+4);
echo $x;

*/

?>