'http://foo.bar', 'title'=>'My beautiful foobar', 'content'='Hello, world !','timestamp'=>'1375864834'),
* array('uri'=>'http://toto.com', 'title'=>'Welcome to toto', 'content'='What is this website about ?','timestamp'=>'1375868313')
* )
* Keys in dictionnaries:
* uri (string;mandatory) = The URI the item points to.
* title (string;mandatory) = Title of item
* content (string;optionnal) = item content (usually HTML code)
* timestamp (string;optionnal) = item date. Must be in EPOCH format.
* Other keys can be added, but will be ignored.
* $items will be used to build the ATOM feed, json and other outputs.
*/
public $items;
private $contentType; // MIME type returned to browser.
/**
* Sets the content-type returns to browser.
*
* @param string Content-type returns to browser - Example: $this->setContentType('text/html; charset=UTF-8')
* @return this
*/
private function setContentType($value){
$this->contentType = $value;
header('Content-Type: '.$value);
return $this;
}
/**
* collectData() will be called to ask the bridge to go collect data on the net.
* All derived classes must implement this method.
* This method must fill $this->items with collected items.
* @param mixed $request : The incoming request (=$_GET). This can be used or ignored by the bridge.
*/
abstract protected function collectData($request);
/**
* Returns a HTTP error to user, with a message.
* Example: $this->returnError(404, 'no results.');
* @param integer $code
* @param string $message
*/
protected function returnError($code, $message){
$errors = array(
400 => 'Bad Request',
404 => 'Not Found',
501 => 'Not Implemented',
);
header('HTTP/1.1 ' . $code . ( isset($errors[$code]) ? ' ' . $errors[$code] : ''));
header('Content-Type: text/plain;charset=' . CHARSET);
die('ERROR : ' . $message);
}
/**
* Builds an ATOM feed from $this->items and return it to browser.
*/
private function returnATOM(){
$this->setContentType('application/atom+xml; charset=' . CHARSET);
$https = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : '' );
$httpHost = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
$httpInfo = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
echo '
'.$item['content'].'
'; } echo "