[formats] Rename variable 'data' to 'item'

This makes the intend of the variable more clear and is now
coherent with all Bridges
This commit is contained in:
logmanoriginal 2016-08-29 19:47:21 +02:00
parent a84016bcb6
commit cf146523be
6 changed files with 27 additions and 28 deletions

View file

@ -19,12 +19,12 @@ class AtomFormat extends FormatAbstract{
$uri = $this->xml_encode($uri); $uri = $this->xml_encode($uri);
$entries = ''; $entries = '';
foreach($this->getItems() as $data){ foreach($this->getItems() as $item){
$entryAuthor = isset($data['author']) ? $this->xml_encode($data['author']) : ''; $entryAuthor = isset($item['author']) ? $this->xml_encode($item['author']) : '';
$entryTitle = isset($data['title']) ? $this->xml_encode($data['title']) : ''; $entryTitle = isset($item['title']) ? $this->xml_encode($item['title']) : '';
$entryUri = isset($data['uri']) ? $this->xml_encode($data['uri']) : ''; $entryUri = isset($item['uri']) ? $this->xml_encode($item['uri']) : '';
$entryTimestamp = isset($data['timestamp']) ? $this->xml_encode(date(DATE_ATOM, $data['timestamp'])) : ''; $entryTimestamp = isset($item['timestamp']) ? $this->xml_encode(date(DATE_ATOM, $item['timestamp'])) : '';
$entryContent = isset($data['content']) ? $this->xml_encode($this->sanitizeHtml($data['content'])) : ''; $entryContent = isset($item['content']) ? $this->xml_encode($this->sanitizeHtml($item['content'])) : '';
$entries .= <<<EOD $entries .= <<<EOD
<entry> <entry>

View file

@ -9,12 +9,12 @@ class HtmlFormat extends FormatAbstract{
$mrssquery = str_replace('format=Html', 'format=Mrss', htmlentities($_SERVER['QUERY_STRING'])); $mrssquery = str_replace('format=Html', 'format=Mrss', htmlentities($_SERVER['QUERY_STRING']));
$entries = ''; $entries = '';
foreach($this->getItems() as $data){ foreach($this->getItems() as $item){
$entryAuthor = isset($data['author']) ? '<br /><p class="author">by: ' . $data['author'] . '</p>' : ''; $entryAuthor = isset($item['author']) ? '<br /><p class="author">by: ' . $item['author'] . '</p>' : '';
$entryTitle = isset($data['title']) ? $this->sanitizeHtml(strip_tags($data['title'])) : ''; $entryTitle = isset($item['title']) ? $this->sanitizeHtml(strip_tags($item['title'])) : '';
$entryUri = isset($data['uri']) ? $data['uri'] : $uri; $entryUri = isset($item['uri']) ? $item['uri'] : $uri;
$entryTimestamp = isset($data['timestamp']) ? '<time datetime="' . date(DATE_ATOM, $data['timestamp']) . '">' . date(DATE_ATOM, $data['timestamp']) . '</time>' : ''; $entryTimestamp = isset($item['timestamp']) ? '<time datetime="' . date(DATE_ATOM, $item['timestamp']) . '">' . date(DATE_ATOM, $item['timestamp']) . '</time>' : '';
$entryContent = isset($data['content']) ? '<div class="content">' . $this->sanitizeHtml($data['content']). '</div>' : ''; $entryContent = isset($item['content']) ? '<div class="content">' . $this->sanitizeHtml($item['content']). '</div>' : '';
$entries .= <<<EOD $entries .= <<<EOD
<section class="feeditem"> <section class="feeditem">

View file

@ -7,9 +7,9 @@ class JsonFormat extends FormatAbstract{
public function stringify(){ public function stringify(){
// FIXME : sometime content can be null, transform to empty string // FIXME : sometime content can be null, transform to empty string
$datas = $this->getItems(); $items = $this->getItems();
return json_encode($datas, JSON_PRETTY_PRINT); return json_encode($items, JSON_PRETTY_PRINT);
} }
public function display(){ public function display(){

View file

@ -17,12 +17,12 @@ class MrssFormat extends FormatAbstract{
$uri = $this->xml_encode(!empty($extraInfos['uri']) ? $extraInfos['uri'] : 'https://github.com/sebsauvage/rss-bridge'); $uri = $this->xml_encode(!empty($extraInfos['uri']) ? $extraInfos['uri'] : 'https://github.com/sebsauvage/rss-bridge');
$items = ''; $items = '';
foreach($this->getItems() as $data){ foreach($this->getItems() as $item){
$itemAuthor = isset($data['author']) ? $this->xml_encode($data['author']) : ''; $itemAuthor = isset($item['author']) ? $this->xml_encode($item['author']) : '';
$itemTitle = strip_tags(isset($data['title']) ? $this->xml_encode($data['title']) : ''); $itemTitle = strip_tags(isset($item['title']) ? $this->xml_encode($item['title']) : '');
$itemUri = isset($data['uri']) ? $this->xml_encode($data['uri']) : ''; $itemUri = isset($item['uri']) ? $this->xml_encode($item['uri']) : '';
$itemTimestamp = isset($data['timestamp']) ? $this->xml_encode(date(DATE_RFC2822, $data['timestamp'])) : ''; $itemTimestamp = isset($item['timestamp']) ? $this->xml_encode(date(DATE_RFC2822, $item['timestamp'])) : '';
$itemContent = isset($data['content']) ? $this->xml_encode($this->sanitizeHtml($data['content'])) : ''; $itemContent = isset($item['content']) ? $this->xml_encode($this->sanitizeHtml($item['content'])) : '';
$items .= <<<EOD $items .= <<<EOD
<item> <item>

View file

@ -6,8 +6,8 @@
class PlaintextFormat extends FormatAbstract{ class PlaintextFormat extends FormatAbstract{
public function stringify(){ public function stringify(){
$datas = $this->getItems(); $items = $this->getItems();
return print_r($datas, true); return print_r($items, true);
} }
public function display(){ public function display(){

View file

@ -16,7 +16,7 @@ abstract class FormatAbstract implements FormatInterface{
protected protected
$contentType, $contentType,
$charset, $charset,
$datas, $items,
$extraInfos $extraInfos
; ;
@ -48,17 +48,16 @@ abstract class FormatAbstract implements FormatInterface{
return $this; return $this;
} }
public function setItems(array $datas){ public function setItems(array $items){
$this->datas = $datas; $this->items = $items;
return $this; return $this;
} }
public function getItems(){ public function getItems(){
if( !is_array($this->datas) ){ if(!is_array($this->items))
throw new \LogicException('Feed the ' . get_class($this) . ' with "setItems" method before !'); throw new \LogicException('Feed the ' . get_class($this) . ' with "setItems" method before !');
}
return $this->datas; return $this->items;
} }
/** /**