summaryrefslogtreecommitdiffstats
path: root/utility/articleenhancer/enhancer.php
diff options
context:
space:
mode:
Diffstat (limited to 'utility/articleenhancer/enhancer.php')
-rw-r--r--utility/articleenhancer/enhancer.php33
1 files changed, 23 insertions, 10 deletions
diff --git a/utility/articleenhancer/enhancer.php b/utility/articleenhancer/enhancer.php
index 059904f63..d7d96f6a9 100644
--- a/utility/articleenhancer/enhancer.php
+++ b/utility/articleenhancer/enhancer.php
@@ -28,23 +28,36 @@ namespace OCA\News\Utility\ArticleEnhancer;
class Enhancer {
- private $enhancers;
+ private $enhancers = array();
- public function __construct(){
- $this->enhancers = array();
+ public function registerEnhancer($feedUrl, ArticleEnhancer $enhancer){
+ $feedUrl = $this->removeTrailingSlash($feedUrl);
+
+ // create hashkeys for all supported protocols for quick access
+ $this->enhancers[$feedUrl] = $enhancer;
+ $this->enhancers['https://' . $feedUrl] = $enhancer;
+ $this->enhancers['http://' . $feedUrl] = $enhancer;
+ $this->enhancers['https://www.' . $feedUrl] = $enhancer;
+ $this->enhancers['http://www.' . $feedUrl] = $enhancer;
}
- public function registerEnhancer(ArticleEnhancer $enhancer){
- array_push($this->enhancers, $enhancer);
+ public function enhance($item, $feedUrl){
+ $feedUrl = $this->removeTrailingSlash($feedUrl);
+
+ if(array_key_exists($feedUrl, $this->enhancers)) {
+ return $this->enhancers[$feedUrl]->enhance($item);
+ } else {
+ return $item;
+ }
}
- public function enhance($item){
- foreach($this->enhancers as $enhancer){
- if($enhancer->canHandle($item)){
- return $enhancer->enhance($item);
- }
+ private function removeTrailingSlash($url) {
+ if($url[strlen($url)-1] === '/') {
+ return substr($url, 0, -1);
+ } else {
+ return $url;
}
}