From 059b099436735ea4f9c2eba7024453621a8c784c Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Mon, 29 Aug 2016 19:05:10 +0200 Subject: [PATCH 1/8] [formats] Fix missing element conditions This fixes download behavior when requesting Atom/Mrss formats, which was caused by is_null attempting to expand missing array elements. --- formats/AtomFormat.php | 12 ++++++------ formats/MrssFormat.php | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/formats/AtomFormat.php b/formats/AtomFormat.php index 56c36963..26badb83 100644 --- a/formats/AtomFormat.php +++ b/formats/AtomFormat.php @@ -7,7 +7,7 @@ class AtomFormat extends FormatAbstract{ public function stringify(){ /* Datas preparation */ - $https = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : '' ); + $https = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : ''; $httpHost = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''; $httpInfo = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : ''; @@ -21,11 +21,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 = isset($data['author']) ? $this->xml_encode($data['author']) : ''; + $entryTitle = isset($data['title']) ? $this->xml_encode($data['title']) : ''; + $entryUri = isset($data['uri']) ? $this->xml_encode($data['uri']) : ''; + $entryTimestamp = isset($data['timestamp']) ? $this->xml_encode(date(DATE_ATOM, $data['timestamp'])) : ''; + $entryContent = isset($data['content']) ? $this->xml_encode($this->sanitizeHtml($data['content'])) : ''; $entries .= << diff --git a/formats/MrssFormat.php b/formats/MrssFormat.php index d7cb682e..498db3b9 100644 --- a/formats/MrssFormat.php +++ b/formats/MrssFormat.php @@ -7,7 +7,7 @@ class MrssFormat extends FormatAbstract{ public function stringify(){ /* Datas preparation */ - $https = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : '' ); + $https = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : ''; $httpHost = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''; $httpInfo = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : ''; @@ -19,11 +19,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 = isset($data['author']) ? $this->xml_encode($data['author']) : ''; + $itemTitle = strip_tags(isset($data['title']) ? $this->xml_encode($data['title']) : ''); + $itemUri = isset($data['uri']) ? $this->xml_encode($data['uri']) : ''; + $itemTimestamp = isset($data['timestamp']) ? $this->xml_encode(date(DATE_RFC2822, $data['timestamp'])) : ''; + $itemContent = isset($data['content']) ? $this->xml_encode($this->sanitizeHtml($data['content'])) : ''; $items .= << From 1e9b5c86110343e13cb5e849580913a2d1e9a22f Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Mon, 29 Aug 2016 19:24:31 +0200 Subject: [PATCH 2/8] [formats] Remove all unnecessary code comments --- formats/AtomFormat.php | 19 ++----------------- formats/HtmlFormat.php | 1 - formats/MrssFormat.php | 15 +-------------- 3 files changed, 3 insertions(+), 32 deletions(-) diff --git a/formats/AtomFormat.php b/formats/AtomFormat.php index 26badb83..991d5be6 100644 --- a/formats/AtomFormat.php +++ b/formats/AtomFormat.php @@ -6,7 +6,6 @@ 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'] : ''; @@ -42,16 +41,7 @@ class AtomFormat extends FormatAbstract{ EOD; } - /* - TODO : - - Security: Disable Javascript ? - - : Define new extra info ? - - : RFC look with xhtml, keep this in spite of ? - */ - -// #### TEMPORARY FIX ### -$feedTimestamp = date(DATE_ATOM, time()); -// ################ + $feedTimestamp = date(DATE_ATOM, time()); /* Data are prepared, now let's begin the "MAGIE !!!" */ $toReturn = ''; @@ -70,11 +60,6 @@ $feedTimestamp = date(DATE_ATOM, time()); EOD; // Remove invalid non-UTF8 characters - - // We cannot use iconv because of a bug in some versions of iconv. - // See http://www.php.net/manual/fr/function.iconv.php#108643 - //$toReturn = iconv("UTF-8", "UTF-8//IGNORE", $toReturn); - // So we use mb_convert_encoding instead: ini_set('mbstring.substitute_character', 'none'); $toReturn= mb_convert_encoding($toReturn, 'UTF-8', 'UTF-8'); return $toReturn; @@ -82,7 +67,7 @@ EOD; public function display(){ $this - ->setContentType('application/atom+xml; charset=UTF-8') // We force UTF-8 in ATOM output. + ->setContentType('application/atom+xml; charset=UTF-8') ->callContentType(); return parent::display(); diff --git a/formats/HtmlFormat.php b/formats/HtmlFormat.php index 4a9aab01..f2f6e413 100644 --- a/formats/HtmlFormat.php +++ b/formats/HtmlFormat.php @@ -2,7 +2,6 @@ class HtmlFormat extends FormatAbstract{ public function stringify(){ - /* Datas preparation */ $extraInfos = $this->getExtraInfos(); $title = htmlspecialchars($extraInfos['name']); $uri = htmlspecialchars($extraInfos['uri']); diff --git a/formats/MrssFormat.php b/formats/MrssFormat.php index 498db3b9..361d64aa 100644 --- a/formats/MrssFormat.php +++ b/formats/MrssFormat.php @@ -6,7 +6,6 @@ class MrssFormat 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'] : ''; @@ -38,13 +37,6 @@ class MrssFormat extends FormatAbstract{ EOD; } - /* - TODO : - - Security: Disable Javascript ? - - : Define new extra info ? - - : RFC look with xhtml, keep this in spite of ? - */ - /* Data are prepared, now let's begin the "MAGIE !!!" */ $toReturn = ''; $toReturn .= <<setContentType('application/rss+xml; charset=UTF-8') // We force UTF-8 in RSS output. + ->setContentType('application/rss+xml; charset=UTF-8') ->callContentType(); return parent::display(); From a84016bcb6790290e8b9963a36a1da54615512f9 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Mon, 29 Aug 2016 19:42:58 +0200 Subject: [PATCH 3/8] [core] Rename item getter/setter getDatas -> getItems setDatas -> setItems Note: Bridge->setDatas actually sets data, where Bridge->getItems only returns items (this is why Bridge->setDatas was not changed) --- formats/AtomFormat.php | 2 +- formats/HtmlFormat.php | 2 +- formats/JsonFormat.php | 2 +- formats/MrssFormat.php | 2 +- formats/PlaintextFormat.php | 2 +- index.php | 2 +- lib/Bridge.php | 6 +++--- lib/Format.php | 9 ++++----- lib/RssBridge.php | 2 +- 9 files changed, 14 insertions(+), 15 deletions(-) diff --git a/formats/AtomFormat.php b/formats/AtomFormat.php index 991d5be6..e1b88c99 100644 --- a/formats/AtomFormat.php +++ b/formats/AtomFormat.php @@ -19,7 +19,7 @@ class AtomFormat extends FormatAbstract{ $uri = $this->xml_encode($uri); $entries = ''; - foreach($this->getDatas() as $data){ + foreach($this->getItems() as $data){ $entryAuthor = isset($data['author']) ? $this->xml_encode($data['author']) : ''; $entryTitle = isset($data['title']) ? $this->xml_encode($data['title']) : ''; $entryUri = isset($data['uri']) ? $this->xml_encode($data['uri']) : ''; diff --git a/formats/HtmlFormat.php b/formats/HtmlFormat.php index f2f6e413..4a8f9359 100644 --- a/formats/HtmlFormat.php +++ b/formats/HtmlFormat.php @@ -9,7 +9,7 @@ class HtmlFormat extends FormatAbstract{ $mrssquery = str_replace('format=Html', 'format=Mrss', htmlentities($_SERVER['QUERY_STRING'])); $entries = ''; - foreach($this->getDatas() as $data){ + foreach($this->getItems() as $data){ $entryAuthor = isset($data['author']) ? '

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

' : ''; $entryTitle = isset($data['title']) ? $this->sanitizeHtml(strip_tags($data['title'])) : ''; $entryUri = isset($data['uri']) ? $data['uri'] : $uri; diff --git a/formats/JsonFormat.php b/formats/JsonFormat.php index c1b076ee..261f2250 100644 --- a/formats/JsonFormat.php +++ b/formats/JsonFormat.php @@ -7,7 +7,7 @@ class JsonFormat extends FormatAbstract{ public function stringify(){ // FIXME : sometime content can be null, transform to empty string - $datas = $this->getDatas(); + $datas = $this->getItems(); return json_encode($datas, JSON_PRETTY_PRINT); } diff --git a/formats/MrssFormat.php b/formats/MrssFormat.php index 361d64aa..0f707548 100644 --- a/formats/MrssFormat.php +++ b/formats/MrssFormat.php @@ -17,7 +17,7 @@ class MrssFormat extends FormatAbstract{ $uri = $this->xml_encode(!empty($extraInfos['uri']) ? $extraInfos['uri'] : 'https://github.com/sebsauvage/rss-bridge'); $items = ''; - foreach($this->getDatas() as $data){ + foreach($this->getItems() as $data){ $itemAuthor = isset($data['author']) ? $this->xml_encode($data['author']) : ''; $itemTitle = strip_tags(isset($data['title']) ? $this->xml_encode($data['title']) : ''); $itemUri = isset($data['uri']) ? $this->xml_encode($data['uri']) : ''; diff --git a/formats/PlaintextFormat.php b/formats/PlaintextFormat.php index 7916bc61..059db4c5 100644 --- a/formats/PlaintextFormat.php +++ b/formats/PlaintextFormat.php @@ -6,7 +6,7 @@ class PlaintextFormat extends FormatAbstract{ public function stringify(){ - $datas = $this->getDatas(); + $datas = $this->getItems(); return print_r($datas, true); } diff --git a/index.php b/index.php index 610c19a8..10a13e0b 100644 --- a/index.php +++ b/index.php @@ -137,7 +137,7 @@ try{ try { $format = Format::create($format); $format - ->setDatas($bridge->getDatas()) + ->setItems($bridge->getItems()) ->setExtraInfos(array( 'name' => $bridge->getName(), 'uri' => $bridge->getURI(), diff --git a/lib/Bridge.php b/lib/Bridge.php index c8f5cbac..583598d8 100644 --- a/lib/Bridge.php +++ b/lib/Bridge.php @@ -139,7 +139,7 @@ abstract class BridgeAbstract implements BridgeInterface { * Return items stored in the bridge * @return mixed */ - public function getDatas(){ + public function getItems(){ return $this->items; } @@ -267,7 +267,7 @@ abstract class BridgeAbstract implements BridgeInterface { $this->collectData(); if(!is_null($this->cache)){ - $this->cache->saveData($this->getDatas()); + $this->cache->saveData($this->getItems()); } return; } @@ -360,7 +360,7 @@ abstract class BridgeAbstract implements BridgeInterface { $this->collectData(); if(!is_null($this->cache)){ - $this->cache->saveData($this->getDatas()); + $this->cache->saveData($this->getItems()); } } diff --git a/lib/Format.php b/lib/Format.php index 486ae849..d01a3cd1 100644 --- a/lib/Format.php +++ b/lib/Format.php @@ -7,7 +7,7 @@ interface FormatInterface{ public function stringify(); public function display(); - public function setDatas(array $bridge); + public function setItems(array $bridges); } abstract class FormatAbstract implements FormatInterface{ @@ -48,15 +48,14 @@ abstract class FormatAbstract implements FormatInterface{ return $this; } - public function setDatas(array $datas){ + public function setItems(array $datas){ $this->datas = $datas; - return $this; } - public function getDatas(){ + public function getItems(){ if( !is_array($this->datas) ){ - throw new \LogicException('Feed the ' . get_class($this) . ' with "setDatas" method before !'); + throw new \LogicException('Feed the ' . get_class($this) . ' with "setItems" method before !'); } return $this->datas; diff --git a/lib/RssBridge.php b/lib/RssBridge.php index 7e175017..4b0aab52 100644 --- a/lib/RssBridge.php +++ b/lib/RssBridge.php @@ -32,7 +32,7 @@ require_once $vendorLibSimpleHtmlDom; Format::setDir(__DIR__ . '/formats/'); $format = Format::create('Atom'); $format - ->setDatas($bridge->getDatas()) + ->setItems($bridge->getItems()) ->setExtraInfos(array( 'name' => $bridge->getName(), 'uri' => $bridge->getURI(), From cf146523bed450181ec8656ecff4be4334e8dcfe Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Mon, 29 Aug 2016 19:47:21 +0200 Subject: [PATCH 4/8] [formats] Rename variable 'data' to 'item' This makes the intend of the variable more clear and is now coherent with all Bridges --- formats/AtomFormat.php | 12 ++++++------ formats/HtmlFormat.php | 12 ++++++------ formats/JsonFormat.php | 4 ++-- formats/MrssFormat.php | 12 ++++++------ formats/PlaintextFormat.php | 4 ++-- lib/Format.php | 11 +++++------ 6 files changed, 27 insertions(+), 28 deletions(-) diff --git a/formats/AtomFormat.php b/formats/AtomFormat.php index e1b88c99..238dc884 100644 --- a/formats/AtomFormat.php +++ b/formats/AtomFormat.php @@ -19,12 +19,12 @@ class AtomFormat extends FormatAbstract{ $uri = $this->xml_encode($uri); $entries = ''; - foreach($this->getItems() as $data){ - $entryAuthor = isset($data['author']) ? $this->xml_encode($data['author']) : ''; - $entryTitle = isset($data['title']) ? $this->xml_encode($data['title']) : ''; - $entryUri = isset($data['uri']) ? $this->xml_encode($data['uri']) : ''; - $entryTimestamp = isset($data['timestamp']) ? $this->xml_encode(date(DATE_ATOM, $data['timestamp'])) : ''; - $entryContent = isset($data['content']) ? $this->xml_encode($this->sanitizeHtml($data['content'])) : ''; + foreach($this->getItems() as $item){ + $entryAuthor = isset($item['author']) ? $this->xml_encode($item['author']) : ''; + $entryTitle = isset($item['title']) ? $this->xml_encode($item['title']) : ''; + $entryUri = isset($item['uri']) ? $this->xml_encode($item['uri']) : ''; + $entryTimestamp = isset($item['timestamp']) ? $this->xml_encode(date(DATE_ATOM, $item['timestamp'])) : ''; + $entryContent = isset($item['content']) ? $this->xml_encode($this->sanitizeHtml($item['content'])) : ''; $entries .= << diff --git a/formats/HtmlFormat.php b/formats/HtmlFormat.php index 4a8f9359..d7c927b0 100644 --- a/formats/HtmlFormat.php +++ b/formats/HtmlFormat.php @@ -9,12 +9,12 @@ class HtmlFormat extends FormatAbstract{ $mrssquery = str_replace('format=Html', 'format=Mrss', htmlentities($_SERVER['QUERY_STRING'])); $entries = ''; - foreach($this->getItems() as $data){ - $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']). '
' : ''; + foreach($this->getItems() as $item){ + $entryAuthor = isset($item['author']) ? '

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

' : ''; + $entryTitle = isset($item['title']) ? $this->sanitizeHtml(strip_tags($item['title'])) : ''; + $entryUri = isset($item['uri']) ? $item['uri'] : $uri; + $entryTimestamp = isset($item['timestamp']) ? '' : ''; + $entryContent = isset($item['content']) ? '
' . $this->sanitizeHtml($item['content']). '
' : ''; $entries .= << diff --git a/formats/JsonFormat.php b/formats/JsonFormat.php index 261f2250..ce259531 100644 --- a/formats/JsonFormat.php +++ b/formats/JsonFormat.php @@ -7,9 +7,9 @@ class JsonFormat extends FormatAbstract{ public function stringify(){ // 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(){ diff --git a/formats/MrssFormat.php b/formats/MrssFormat.php index 0f707548..d0a74177 100644 --- a/formats/MrssFormat.php +++ b/formats/MrssFormat.php @@ -17,12 +17,12 @@ class MrssFormat extends FormatAbstract{ $uri = $this->xml_encode(!empty($extraInfos['uri']) ? $extraInfos['uri'] : 'https://github.com/sebsauvage/rss-bridge'); $items = ''; - foreach($this->getItems() as $data){ - $itemAuthor = isset($data['author']) ? $this->xml_encode($data['author']) : ''; - $itemTitle = strip_tags(isset($data['title']) ? $this->xml_encode($data['title']) : ''); - $itemUri = isset($data['uri']) ? $this->xml_encode($data['uri']) : ''; - $itemTimestamp = isset($data['timestamp']) ? $this->xml_encode(date(DATE_RFC2822, $data['timestamp'])) : ''; - $itemContent = isset($data['content']) ? $this->xml_encode($this->sanitizeHtml($data['content'])) : ''; + foreach($this->getItems() as $item){ + $itemAuthor = isset($item['author']) ? $this->xml_encode($item['author']) : ''; + $itemTitle = strip_tags(isset($item['title']) ? $this->xml_encode($item['title']) : ''); + $itemUri = isset($item['uri']) ? $this->xml_encode($item['uri']) : ''; + $itemTimestamp = isset($item['timestamp']) ? $this->xml_encode(date(DATE_RFC2822, $item['timestamp'])) : ''; + $itemContent = isset($item['content']) ? $this->xml_encode($this->sanitizeHtml($item['content'])) : ''; $items .= << diff --git a/formats/PlaintextFormat.php b/formats/PlaintextFormat.php index 059db4c5..e2cf0b94 100644 --- a/formats/PlaintextFormat.php +++ b/formats/PlaintextFormat.php @@ -6,8 +6,8 @@ class PlaintextFormat extends FormatAbstract{ public function stringify(){ - $datas = $this->getItems(); - return print_r($datas, true); + $items = $this->getItems(); + return print_r($items, true); } public function display(){ diff --git a/lib/Format.php b/lib/Format.php index d01a3cd1..142b4c87 100644 --- a/lib/Format.php +++ b/lib/Format.php @@ -16,7 +16,7 @@ abstract class FormatAbstract implements FormatInterface{ protected $contentType, $charset, - $datas, + $items, $extraInfos ; @@ -48,17 +48,16 @@ abstract class FormatAbstract implements FormatInterface{ return $this; } - public function setItems(array $datas){ - $this->datas = $datas; + public function setItems(array $items){ + $this->items = $items; return $this; } 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 !'); - } - return $this->datas; + return $this->items; } /** From 5d0ee926a576606c5b6a06e7a58f4444b7ee558f Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Mon, 29 Aug 2016 19:57:10 +0200 Subject: [PATCH 5/8] [JsonFormat] Remove obsolete FIXME We don't need to convert fields that are NULL, since json_encode will correctly encode those fields. --- formats/JsonFormat.php | 1 - 1 file changed, 1 deletion(-) diff --git a/formats/JsonFormat.php b/formats/JsonFormat.php index ce259531..e173f230 100644 --- a/formats/JsonFormat.php +++ b/formats/JsonFormat.php @@ -6,7 +6,6 @@ class JsonFormat extends FormatAbstract{ public function stringify(){ - // FIXME : sometime content can be null, transform to empty string $items = $this->getItems(); return json_encode($items, JSON_PRETTY_PRINT); From e46a480c5d8ebeb1d0e97430cde512a642eef1ab Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Mon, 29 Aug 2016 20:05:45 +0200 Subject: [PATCH 6/8] [MrssFormat] Add icon to feed --- formats/MrssFormat.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/formats/MrssFormat.php b/formats/MrssFormat.php index d0a74177..ddbd5d35 100644 --- a/formats/MrssFormat.php +++ b/formats/MrssFormat.php @@ -15,6 +15,7 @@ class MrssFormat extends FormatAbstract{ $extraInfos = $this->getExtraInfos(); $title = $this->xml_encode($extraInfos['name']); $uri = $this->xml_encode(!empty($extraInfos['uri']) ? $extraInfos['uri'] : 'https://github.com/sebsauvage/rss-bridge'); + $icon = $this->xml_encode('http://icons.better-idea.org/icon?url='. $uri .'&size=64'); $items = ''; foreach($this->getItems() as $item){ @@ -45,6 +46,7 @@ EOD; {$title} http{$https}://{$httpHost}{$httpInfo}/ {$title} + {$items} From f49fca516d937fda49be01dbc3a19ff97c465e7a Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Mon, 29 Aug 2016 20:50:02 +0200 Subject: [PATCH 7/8] [Format] Trim all items elements This removes unnecessary whitespace in output data --- lib/Format.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Format.php b/lib/Format.php index 142b4c87..e89f388f 100644 --- a/lib/Format.php +++ b/lib/Format.php @@ -49,7 +49,8 @@ abstract class FormatAbstract implements FormatInterface{ } public function setItems(array $items){ - $this->items = $items; + $this->items = array_map(array($this, 'array_trim'), $items); + return $this; } @@ -105,6 +106,14 @@ abstract class FormatAbstract implements FormatInterface{ // We leave alone object and embed so that videos can play in RSS readers. return $html; } + + protected function array_trim($elements){ + foreach($elements as $key => $value){ + if(is_string($value)) + $elements[$key] = trim($value); + } + return $elements; + } } class Format{ From 8d050c233bf2dc677d9d91f6546be54a011cd13b Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Mon, 29 Aug 2016 20:51:11 +0200 Subject: [PATCH 8/8] [Format] Change scope of 'sanitizeHtml' to protected --- lib/Format.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Format.php b/lib/Format.php index e89f388f..8053d36d 100644 --- a/lib/Format.php +++ b/lib/Format.php @@ -98,7 +98,7 @@ abstract class FormatAbstract implements FormatInterface{ * Maybe we'll switch to http://htmlpurifier.org/ * or http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed/index.php */ - public function sanitizeHtml($html) + protected function sanitizeHtml($html) { $html = str_replace('