diff options
Diffstat (limited to 'vendor/miniflux/picofeed/lib/PicoFeed/Generator')
3 files changed, 126 insertions, 0 deletions
diff --git a/vendor/miniflux/picofeed/lib/PicoFeed/Generator/ContentGeneratorInterface.php b/vendor/miniflux/picofeed/lib/PicoFeed/Generator/ContentGeneratorInterface.php new file mode 100644 index 00000000..5c2f205c --- /dev/null +++ b/vendor/miniflux/picofeed/lib/PicoFeed/Generator/ContentGeneratorInterface.php @@ -0,0 +1,23 @@ +<?php + +namespace PicoFeed\Generator; + +use PicoFeed\Parser\Item; + +/** + * Content Generator Interface + * + * @package PicoFeed\Generator + * @author Frederic Guillot + */ +interface ContentGeneratorInterface +{ + /** + * Execute Content Generator + * + * @access public + * @param Item $item + * @return boolean + */ + public function execute(Item $item); +} diff --git a/vendor/miniflux/picofeed/lib/PicoFeed/Generator/FileContentGenerator.php b/vendor/miniflux/picofeed/lib/PicoFeed/Generator/FileContentGenerator.php new file mode 100644 index 00000000..03f37e16 --- /dev/null +++ b/vendor/miniflux/picofeed/lib/PicoFeed/Generator/FileContentGenerator.php @@ -0,0 +1,36 @@ +<?php + +namespace PicoFeed\Generator; + +use PicoFeed\Base; +use PicoFeed\Parser\Item; + +/** + * File Content Generator + * + * @package PicoFeed\Generator + * @author Frederic Guillot + */ +class FileContentGenerator extends Base implements ContentGeneratorInterface +{ + private $extensions = array('pdf'); + + /** + * Execute Content Generator + * + * @access public + * @param Item $item + * @return boolean + */ + public function execute(Item $item) + { + foreach ($this->extensions as $extension) { + if (substr($item->getUrl(), - strlen($extension)) === $extension) { + $item->setContent('<a href="'.$item->getUrl().'" target="_blank">'.$item->getUrl().'</a>'); + return true; + } + } + + return false; + } +} diff --git a/vendor/miniflux/picofeed/lib/PicoFeed/Generator/YoutubeContentGenerator.php b/vendor/miniflux/picofeed/lib/PicoFeed/Generator/YoutubeContentGenerator.php new file mode 100644 index 00000000..198090d4 --- /dev/null +++ b/vendor/miniflux/picofeed/lib/PicoFeed/Generator/YoutubeContentGenerator.php @@ -0,0 +1,67 @@ +<?php + +namespace PicoFeed\Generator; + +use PicoFeed\Base; +use PicoFeed\Parser\Item; + +/** + * Youtube Content Generator + * + * @package PicoFeed\Generator + * @author Frederic Guillot + */ +class YoutubeContentGenerator extends Base implements ContentGeneratorInterface +{ + /** + * Execute Content Generator + * + * @access public + * @param Item $item + * @return boolean + */ + public function execute(Item $item) + { + if ($item->hasNamespace('yt')) { + return $this->generateHtmlFromXml($item); + } + + return $this->generateHtmlFromUrl($item); + } + + /** + * Generate HTML + * + * @access public + * @param Item $item + * @return boolean + */ + private function generateHtmlFromXml(Item $item) + { + $videoId = $item->getTag('yt:videoId'); + + if (! empty($videoId)) { + $item->setContent('<iframe width="560" height="315" src="//www.youtube.com/embed/'.$videoId[0].'" frameborder="0"></iframe>'); + return true; + } + + return false; + } + + /** + * Generate HTML from item URL + * + * @access public + * @param Item $item + * @return bool + */ + public function generateHtmlFromUrl(Item $item) + { + if (preg_match('/youtube\.com\/watch\?v=(.*)/', $item->getUrl(), $matches)) { + $item->setContent('<iframe width="560" height="315" src="//www.youtube.com/embed/'.$matches[1].'" frameborder="0"></iframe>'); + return true; + } + + return false; + } +} |