<?php include_once('../spider.inc.php'); ?>{charset:UTF-8}<?php
$target		= 'news';
if( isset($_GET['rt']) ) {
	$target	= trim(stripslashes($_GET['rt']));
}
$targetUrlHash	= array(
	'news'		=> 'http://sourceforge.jp/projects/shopformer/topic/rss.php',
	'bbs'		=> 'http://sourceforge.jp/projects/shopformer/support/rss.php',
	'ver'		=> 'http://sourceforge.jp/projects/shopformer/products/'.RELEASE_NAME.'/version.xml',
	'blog'		=> 'http://sourceforge.jp/projects/shopformer/blog/?feed=rss2',
);
$outputContentType	= 'Content-Type: application/xml; charset=UTF-8';
$replaceWordHash	= array();
$targetUrl	= $targetUrlHash['news'];
if( isset($targetUrlHash[$target]) && strlen($targetUrlHash[$target]) > 0 ) {
	$targetUrl	= $targetUrlHash[$target];
} else if( $target == 'adv' ){
	$type		= '';
	$position	= 'top';
	$number		= 1;
	if( isset($_GET['type']) && strlen($_GET['type']) > 0 ) {
		$type		= trim(stripslashes($_GET['type']));
	}
	if( isset($_GET['pos']) && strlen($_GET['pos']) > 0 ) {
		$position	= trim(stripslashes($_GET['pos']));
	}
	if( isset($_GET['num']) && preg_match('/^[0-9]{1,2}$/',$_GET['num']) > 0 ) {
		$number		= trim(stripslashes($_GET['num']));
	}
	if( $type == 'img' ) {
		$targetUrl	= 'http://sourceforge.jp/projects/shopformer/adv/'.$position.'_'.sprintf('%02d',$number).'.gif';
		$outputContentType	= 'Content-Type: image/gif;';
	} else {
		$targetUrl	= 'http://sourceforge.jp/projects/shopformer/adv/'.$position.'_'.sprintf('%02d',$number).'.php';
		$imageUri	= SPIDER_URI_APP.'?rt=adv&amp;type=img&amp;pos='.urlencode($position).'&amp;num='.$number;
		$replaceWordHash['{advimageuri}'] = $imageUri;
		$outputContentType	= 'Content-Type: text/plain;charset=UTF-8';
	}
}
if( defined('DIR_PATH_LIB') && file_exists(DIR_PATH_LIB) && file_exists(DIR_PATH_LIB.DIRECTORY_SEPARATOR.'util'.DIRECTORY_SEPARATOR.'HttpRequest.class.php') ) {
	require_once(DIR_PATH_LIB.DIRECTORY_SEPARATOR.'util'.DIRECTORY_SEPARATOR.'HttpRequest.class.php');
	$httpRequest	= new util_HttpRequest($targetUrl,'get');
	if( $httpRequest->send(null,10) ) {
		if( $httpRequest->statusCode == 200 ) {
			foreach( $replaceWordHash as $key => $val ) {
				$httpRequest->responseBody	= str_replace($key,$val,$httpRequest->responseBody);
			}
			header($outputContentType);
			if( preg_match('/image/',$outputContentType) > 0 ) {
				header('Content-Length: '.strlen($httpRequest->responseBody));
			} else {
				$httpRequest->responseBody	= str_replace("\r\n","\n",$httpRequest->responseBody);
				$httpRequest->responseBody	= str_replace("\r","\n",$httpRequest->responseBody);
			}
			echo $httpRequest->responseBody;
		} else {
			header('Content-Type: text/plain;charset=UTF-8');
			echo '';
			echo 'Error!'.$httpRequest->statusCode.' '.$httpRequest->statusMessage .' : '.$targetUrl;
		}
	} else {
		header('Content-Type: text/plain;charset=UTF-8');
		echo '';
		echo 'Error!'.$httpRequest->statusCode.' '.$httpRequest->statusMessage
			.' : Error Number='.$httpRequest->errorNumber.' '.$httpRequest->errorMessage.' : '.$targetUrl;
	}
}
?>