diff options
author | Frederic Guillot <fred@kanboard.net> | 2017-10-25 16:22:10 -0700 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2017-10-25 16:22:10 -0700 |
commit | 9e2b2a32fd0e967ad3184e9a5d091a29953acb91 (patch) | |
tree | 00822e24aa1110c73ca455a8d096ef296c008cbc /vendor/miniflux/picofeed/lib/PicoFeed/Processor | |
parent | c507c5416251c505cb3e088a03c6664bed73c812 (diff) |
Include composer dependencies in repo
Diffstat (limited to 'vendor/miniflux/picofeed/lib/PicoFeed/Processor')
5 files changed, 313 insertions, 0 deletions
diff --git a/vendor/miniflux/picofeed/lib/PicoFeed/Processor/ContentFilterProcessor.php b/vendor/miniflux/picofeed/lib/PicoFeed/Processor/ContentFilterProcessor.php new file mode 100644 index 00000000..9b7ddcce --- /dev/null +++ b/vendor/miniflux/picofeed/lib/PicoFeed/Processor/ContentFilterProcessor.php @@ -0,0 +1,37 @@ +<?php + +namespace PicoFeed\Processor; + +use PicoFeed\Base; +use PicoFeed\Filter\Filter; +use PicoFeed\Logging\Logger; +use PicoFeed\Parser\Feed; +use PicoFeed\Parser\Item; + +/** + * Item Content Filter + * + * @package PicoFeed\Processor + * @author Frederic Guillot + */ +class ContentFilterProcessor extends Base implements ItemProcessorInterface +{ + /** + * Execute Item Processor + * + * @access public + * @param Feed $feed + * @param Item $item + * @return bool + */ + public function execute(Feed $feed, Item $item) + { + if ($this->config->getContentFiltering(true)) { + $filter = Filter::html($item->getContent(), $feed->getSiteUrl()); + $filter->setConfig($this->config); + $item->setContent($filter->execute()); + } else { + Logger::setMessage(get_called_class().': Content filtering disabled'); + } + } +} diff --git a/vendor/miniflux/picofeed/lib/PicoFeed/Processor/ContentGeneratorProcessor.php b/vendor/miniflux/picofeed/lib/PicoFeed/Processor/ContentGeneratorProcessor.php new file mode 100644 index 00000000..49adf9cc --- /dev/null +++ b/vendor/miniflux/picofeed/lib/PicoFeed/Processor/ContentGeneratorProcessor.php @@ -0,0 +1,49 @@ +<?php + +namespace PicoFeed\Processor; + +use PicoFeed\Base; +use PicoFeed\Parser\Feed; +use PicoFeed\Parser\Item; + +/** + * Item Content Generator + * + * @package PicoFeed\Processor + * @author Frederic Guillot + */ +class ContentGeneratorProcessor extends Base implements ItemProcessorInterface +{ + /** + * List of generators + * + * @access protected + * @var array + */ + protected $generators = array( + 'youtube', + 'file', + ); + + /** + * Execute Item Processor + * + * @access public + * @param Feed $feed + * @param Item $item + * @return bool + */ + public function execute(Feed $feed, Item $item) + { + foreach ($this->generators as $generator) { + $className = '\PicoFeed\Generator\\'.ucfirst($generator).'ContentGenerator'; + $object = new $className($this->config); + + if ($object->execute($item)) { + return true; + } + } + + return false; + } +} diff --git a/vendor/miniflux/picofeed/lib/PicoFeed/Processor/ItemPostProcessor.php b/vendor/miniflux/picofeed/lib/PicoFeed/Processor/ItemPostProcessor.php new file mode 100644 index 00000000..d2787677 --- /dev/null +++ b/vendor/miniflux/picofeed/lib/PicoFeed/Processor/ItemPostProcessor.php @@ -0,0 +1,106 @@ +<?php + +namespace PicoFeed\Processor; + +use PicoFeed\Base; +use PicoFeed\Parser\Feed; +use PicoFeed\Parser\Item; +use PicoFeed\Config\Config; + +/** + * Item Post Processor + * + * @package PicoFeed\Processor + * @author Frederic Guillot + */ +class ItemPostProcessor extends Base +{ + /** + * List of processors + * + * @access private + * @var array + */ + private $processors = array(); + + /** + * Execute all processors + * + * @access public + * @param Feed $feed + * @param Item $item + * @return bool + */ + public function execute(Feed $feed, Item $item) + { + foreach ($this->processors as $processor) { + if ($processor->execute($feed, $item)) { + return true; + } + } + + return false; + } + + /** + * Register a new Item post-processor + * + * @access public + * @param ItemProcessorInterface $processor + * @return ItemPostProcessor + */ + public function register(ItemProcessorInterface $processor) + { + $this->processors[get_class($processor)] = $processor; + return $this; + } + + /** + * Remove Processor instance + * + * @access public + * @param string $class + * @return ItemPostProcessor + */ + public function unregister($class) + { + if (isset($this->processors[$class])) { + unset($this->processors[$class]); + } + + return $this; + } + + /** + * Checks wheather a specific processor is registered or not + * + * @access public + * @param string $class + * @return bool + */ + public function hasProcessor($class) + { + return isset($this->processors[$class]); + } + + /** + * Get Processor instance + * + * @access public + * @param string $class + * @return ItemProcessorInterface|null + */ + public function getProcessor($class) + { + return isset($this->processors[$class]) ? $this->processors[$class] : null; + } + + public function setConfig(Config $config) + { + foreach ($this->processors as $processor) { + $processor->setConfig($config); + } + + return false; + } +} diff --git a/vendor/miniflux/picofeed/lib/PicoFeed/Processor/ItemProcessorInterface.php b/vendor/miniflux/picofeed/lib/PicoFeed/Processor/ItemProcessorInterface.php new file mode 100644 index 00000000..5d532262 --- /dev/null +++ b/vendor/miniflux/picofeed/lib/PicoFeed/Processor/ItemProcessorInterface.php @@ -0,0 +1,25 @@ +<?php + +namespace PicoFeed\Processor; + +use PicoFeed\Parser\Feed; +use PicoFeed\Parser\Item; + +/** + * Item Processor Interface + * + * @package PicoFeed\Processor + * @author Frederic Guillot + */ +interface ItemProcessorInterface +{ + /** + * Execute Item Processor + * + * @access public + * @param Feed $feed + * @param Item $item + * @return bool + */ + public function execute(Feed $feed, Item $item); +} diff --git a/vendor/miniflux/picofeed/lib/PicoFeed/Processor/ScraperProcessor.php b/vendor/miniflux/picofeed/lib/PicoFeed/Processor/ScraperProcessor.php new file mode 100644 index 00000000..0c467af0 --- /dev/null +++ b/vendor/miniflux/picofeed/lib/PicoFeed/Processor/ScraperProcessor.php @@ -0,0 +1,96 @@ +<?php + +namespace PicoFeed\Processor; + +use Closure; +use PicoFeed\Base; +use PicoFeed\Parser\Feed; +use PicoFeed\Parser\Item; +use PicoFeed\Scraper\Scraper; + +/** + * Scraper Processor + * + * @package PicoFeed\Processor + * @author Frederic Guillot + */ +class ScraperProcessor extends Base implements ItemProcessorInterface +{ + private $ignoredUrls = array(); + private $scraper; + + /** + * Callback function for each scraper execution + * + * @var Closure + */ + private $executionCallback; + + /** + * Add a new execution callback + * + * @access public + * @param Closure $executionCallback + * @return $this + */ + public function setExecutionCallback(Closure $executionCallback) + { + $this->executionCallback = $executionCallback; + return $this; + } + + /** + * Execute Item Processor + * + * @access public + * @param Feed $feed + * @param Item $item + * @return bool + */ + public function execute(Feed $feed, Item $item) + { + if (!in_array($item->getUrl(), $this->ignoredUrls)) { + $scraper = $this->getScraper(); + $scraper->setUrl($item->getUrl()); + $scraper->execute(); + + if ($this->executionCallback && is_callable($this->executionCallback)) { + call_user_func($this->executionCallback, $feed, $item, $scraper); + } + + if ($scraper->hasRelevantContent()) { + $item->setContent($scraper->getFilteredContent()); + } + } + + return false; + } + + /** + * Ignore list of URLs + * + * @access public + * @param array $urls + * @return $this + */ + public function ignoreUrls(array $urls) + { + $this->ignoredUrls = $urls; + return $this; + } + + /** + * Returns Scraper instance + * + * @access public + * @return Scraper + */ + public function getScraper() + { + if ($this->scraper === null) { + $this->scraper = new Scraper($this->config); + } + + return $this->scraper; + } +} |