mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-07-30 21:30:14 +02:00
Refonte du code
This commit is contained in:
79
formats/AtomFormat.php
Normal file
79
formats/AtomFormat.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Atom
|
||||
* Documentation Source http://en.wikipedia.org/wiki/Atom_%28standard%29 and http://tools.ietf.org/html/rfc4287
|
||||
*
|
||||
* @name Atom
|
||||
*/
|
||||
class AtomFormat extends FormatAbstract{
|
||||
|
||||
public function stringify(){
|
||||
/* Datas preparation */
|
||||
$https = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : '' );
|
||||
$httpHost = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
|
||||
$httpInfo = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
|
||||
|
||||
$serverRequestUri = htmlspecialchars($_SERVER['REQUEST_URI']);
|
||||
|
||||
$extraInfos = $this->getExtraInfos();
|
||||
$title = htmlspecialchars($extraInfos['name']);
|
||||
$uri = htmlspecialchars($extraInfos['uri']);
|
||||
|
||||
$entries = '';
|
||||
foreach($this->getDatas() as $data){
|
||||
$entryName = is_null($data->name) ? $title : $data->name;
|
||||
$entryAuthor = is_null($data->author) ? $uri : $data->author;
|
||||
$entryTitle = is_null($data->title) ? '' : $data->title;
|
||||
$entryUri = is_null($data->uri) ? '' : $data->uri;
|
||||
$entryTimestamp = is_null($data->timestamp) ? '' : date(DATE_ATOM, $data->timestamp);
|
||||
$entryContent = is_null($data->content) ? '' : '<![CDATA[' . htmlentities($data->content) . ']]>';
|
||||
|
||||
$entries .= <<<EOD
|
||||
|
||||
<entry>
|
||||
<author>
|
||||
<name>{$entryName}</name>
|
||||
<uri>{$entryAuthor}</uri>
|
||||
</author>
|
||||
<title type="html"><![CDATA[{$entryTitle}]]></title>
|
||||
<link rel="alternate" type="text/html" href="{$entryUri}" />
|
||||
<id>{$entryUri}</id>
|
||||
<updated>{$entryTimestamp}</updated>
|
||||
<content type="html">{$entryContent}</content>
|
||||
</entry>
|
||||
|
||||
EOD;
|
||||
}
|
||||
|
||||
/*
|
||||
TODO :
|
||||
- Security: Disable Javascript ?
|
||||
- <updated> : Define new extra info ?
|
||||
- <content type="html"> : RFC look with xhtml, keep this in spite of ?
|
||||
*/
|
||||
|
||||
/* Data are prepared, now let's begin the "MAGIE !!!" */
|
||||
$toReturn = '<?xml version="1.0" encoding="UTF-8"?>';
|
||||
$toReturn .= <<<EOD
|
||||
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xml:lang="en-US">
|
||||
|
||||
<title type="text">{$title}</title>
|
||||
<id>http{$https}://{$httpHost}{$httpInfo}/</id>
|
||||
<updated></updated>
|
||||
<link rel="alternate" type="text/html" href="{$uri}" />
|
||||
<link rel="self" href="http{$https}://{$httpHost}{$serverRequestUri}" />
|
||||
{$entries}
|
||||
</feed>
|
||||
EOD;
|
||||
|
||||
return $toReturn;
|
||||
}
|
||||
|
||||
public function display(){
|
||||
// $this
|
||||
// ->setContentType('application/atom+xml; charset=' . $this->getCharset())
|
||||
// ->callContentType();
|
||||
|
||||
return parent::display();
|
||||
}
|
||||
}
|
62
formats/HtmlFormat.php
Normal file
62
formats/HtmlFormat.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* Html
|
||||
* Documentation Source http://en.wikipedia.org/wiki/Atom_%28standard%29 and http://tools.ietf.org/html/rfc4287
|
||||
*
|
||||
* @name Html
|
||||
*/
|
||||
class HtmlFormat extends FormatAbstract{
|
||||
|
||||
public function stringify(){
|
||||
/* Datas preparation */
|
||||
$extraInfos = $this->getExtraInfos();
|
||||
$title = htmlspecialchars($extraInfos['name']);
|
||||
$uri = htmlspecialchars($extraInfos['uri']);
|
||||
|
||||
$entries = '';
|
||||
foreach($this->getDatas() as $data){
|
||||
$entryUri = is_null($data->uri) ? $uri : $data->uri;
|
||||
$entryTitle = is_null($data->title) ? '' : htmlspecialchars(strip_tags($data->title));
|
||||
$entryTimestamp = is_null($data->timestamp) ? '' : '<small>' . date(DATE_ATOM, $data->timestamp) . '</small>';
|
||||
$entryContent = is_null($data->content) ? '' : '<p>' . $data->content . '</p>';
|
||||
|
||||
$entries .= <<<EOD
|
||||
|
||||
<div class="rssitem">
|
||||
<h2><a href="{$entryUri}">{$entryTitle}</a></h2>
|
||||
{$entryTimestamp}
|
||||
{$entryContent}
|
||||
</div>
|
||||
|
||||
EOD;
|
||||
}
|
||||
|
||||
$styleCss = <<<'EOD'
|
||||
body{font-family:"Trebuchet MS",Verdana,Arial,Helvetica,sans-serif;font-size:10pt;background-color:#aaa;}div.rssitem{border:1px solid black;padding:5px;margin:10px;background-color:#fff;}
|
||||
EOD;
|
||||
|
||||
/* Data are prepared, now let's begin the "MAGIE !!!" */
|
||||
$toReturn = <<<EOD
|
||||
<html>
|
||||
<head>
|
||||
<title>{$title}</title>
|
||||
<style type="text/css">{$styleCss}</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{$title}</h1>
|
||||
{$entries}
|
||||
</body>
|
||||
</html>
|
||||
EOD;
|
||||
|
||||
return $toReturn;
|
||||
}
|
||||
|
||||
public function display(){
|
||||
$this
|
||||
->setContentType('text/html; charset=' . $this->getCharset())
|
||||
->callContentType();
|
||||
|
||||
return parent::display();
|
||||
}
|
||||
}
|
24
formats/JsonFormat.php
Normal file
24
formats/JsonFormat.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Json
|
||||
* Builds a JSON string from $this->items and return it to browser.
|
||||
*
|
||||
* @name Json
|
||||
*/
|
||||
class JsonFormat extends FormatAbstract{
|
||||
|
||||
public function stringify(){
|
||||
// FIXME : sometime content can be null, transform to empty string
|
||||
$datas = $this->getDatas();
|
||||
|
||||
return json_encode($datas);
|
||||
}
|
||||
|
||||
public function display(){
|
||||
$this
|
||||
->setContentType('application/json')
|
||||
->callContentType();
|
||||
|
||||
return parent::display();
|
||||
}
|
||||
}
|
22
formats/PlaintextFormat.php
Normal file
22
formats/PlaintextFormat.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* Plaintext
|
||||
* Returns $this->items as raw php data.
|
||||
*
|
||||
* @name Plaintext
|
||||
*/
|
||||
class PlaintextFormat extends FormatAbstract{
|
||||
|
||||
public function stringify(){
|
||||
$datas = $this->getDatas();
|
||||
return print_r($datas, true);
|
||||
}
|
||||
|
||||
public function display(){
|
||||
$this
|
||||
->setContentType('text/plain;charset=' . $this->getCharset())
|
||||
->callContentType();
|
||||
|
||||
return parent::display();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user