<?php
require_once MVROOT."/misc/PostRequest.php";
require_once MVROOT."/aggregation_service/models/Content.class.php";
require_once MVROOT."/aggregation_service/ContentImporter.class.php";

class BaseFeed {

	private $response_mode="XML";
	public static $total_bytes=0;

	protected function __construct($mode="") {
		if($mode!="") $this->response_mode=$mode;
	}

	protected function request($url) {
		$req=new Request();
		$buffer=$req->hit($url);
		self::$total_bytes+=strlen($buffer);
		//print $buffer;
		//print "-----------------------";
		if (!empty($buffer)) {
			if($this->response_mode=="XML") {
				return json_decode(json_encode((array) simplexml_load_string($buffer)),1);
			}
			else if($this->response_mode=="JSON") {
				return json_decode($buffer);
			}
			else if($this->response_mode=="TEXT") {
				return $buffer;
			}
		}
		return false;
	}
	
	protected function import($c=array()) {
		if(gettype($c)=='array') $c=new Content($c);
		ContentImporter::AddContent($c);
	}
	
}

?>