From 1f3361c6b40f60e512bac7b108c0add5082d9b1c Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Mon, 22 Aug 2016 18:54:36 +0200 Subject: [PATCH] [formats] Change item to associative array Previously the item class was used to dump literaly any data into an object. The same can be archived by using an array with named keys (associative array). Technically it makes more sense to use an array as we want to be able to store any parameter into our item. --- formats/AtomFormat.php | 10 +++++----- formats/HtmlFormat.php | 10 +++++----- formats/MrssFormat.php | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/formats/AtomFormat.php b/formats/AtomFormat.php index 06ef8eb0..7ec7d504 100644 --- a/formats/AtomFormat.php +++ b/formats/AtomFormat.php @@ -23,11 +23,11 @@ class AtomFormat extends FormatAbstract{ $entries = ''; foreach($this->getDatas() as $data){ - $entryAuthor = is_null($data->author) ? '' : $this->xml_encode($data->author); - $entryTitle = is_null($data->title) ? '' : $this->xml_encode($data->title); - $entryUri = is_null($data->uri) ? '' : $this->xml_encode($data->uri); - $entryTimestamp = is_null($data->timestamp) ? '' : $this->xml_encode(date(DATE_ATOM, $data->timestamp)); - $entryContent = is_null($data->content) ? '' : $this->xml_encode($this->sanitizeHtml($data->content)); + $entryAuthor = is_null($data['author']) ? '' : $this->xml_encode($data['author']); + $entryTitle = is_null($data['title']) ? '' : $this->xml_encode($data['title']); + $entryUri = is_null($data['uri']) ? '' : $this->xml_encode($data['uri']); + $entryTimestamp = is_null($data['timestamp']) ? '' : $this->xml_encode(date(DATE_ATOM, $data['timestamp'])); + $entryContent = is_null($data['content']) ? '' : $this->xml_encode($this->sanitizeHtml($data['content'])); $entries .= << diff --git a/formats/HtmlFormat.php b/formats/HtmlFormat.php index 19b7702d..211a1371 100644 --- a/formats/HtmlFormat.php +++ b/formats/HtmlFormat.php @@ -17,11 +17,11 @@ class HtmlFormat extends FormatAbstract{ $entries = ''; foreach($this->getDatas() as $data){ - $entryAuthor = is_null($data->author) ? '' : '

by: ' . $data->author . '

'; - $entryTitle = is_null($data->title) ? '' : $this->sanitizeHtml(strip_tags($data->title)); - $entryUri = is_null($data->uri) ? $uri : $data->uri; - $entryTimestamp = is_null($data->timestamp) ? '' : ''; - $entryContent = is_null($data->content) ? '' : '
' . $this->sanitizeHtml($data->content). '
'; + $entryAuthor = isset($data['author']) ? '

by: ' . $data['author'] . '

' : ''; + $entryTitle = isset($data['title']) ? $this->sanitizeHtml(strip_tags($data['title'])) : ''; + $entryUri = isset($data['uri']) ? $data['uri'] : $uri; + $entryTimestamp = isset($data['timestamp']) ? '' : ''; + $entryContent = isset($data['content']) ? '
' . $this->sanitizeHtml($data['content']). '
' : ''; $entries .= << diff --git a/formats/MrssFormat.php b/formats/MrssFormat.php index 46012e97..7d939f36 100644 --- a/formats/MrssFormat.php +++ b/formats/MrssFormat.php @@ -21,11 +21,11 @@ class MrssFormat extends FormatAbstract{ $items = ''; foreach($this->getDatas() as $data){ - $itemAuthor = is_null($data->author) ? '' : $this->xml_encode($data->author); - $itemTitle = strip_tags(is_null($data->title) ? '' : $this->xml_encode($data->title)); - $itemUri = is_null($data->uri) ? '' : $this->xml_encode($data->uri); - $itemTimestamp = is_null($data->timestamp) ? '' : $this->xml_encode(date(DATE_RFC2822, $data->timestamp)); - $itemContent = is_null($data->content) ? '' : $this->xml_encode($this->sanitizeHtml($data->content)); + $itemAuthor = is_null($data['author']) ? '' : $this->xml_encode($data['author']); + $itemTitle = strip_tags(is_null($data['title']) ? '' : $this->xml_encode($data['title'])); + $itemUri = is_null($data['uri']) ? '' : $this->xml_encode($data['uri']); + $itemTimestamp = is_null($data['timestamp']) ? '' : $this->xml_encode(date(DATE_RFC2822, $data['timestamp'])); + $itemContent = is_null($data['content']) ? '' : $this->xml_encode($this->sanitizeHtml($data['content'])); $items .= <<