diff --git a/.gitignore b/.gitignore index 2f87cd7..30d01f8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor +/.idea composer.phar composer.lock diff --git a/composer.json b/composer.json index fa9609d..2ebd7a8 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "require": { "php": ">=5.4.0", "illuminate/support": "~5.0", - "simplepie/simplepie": "1.5.*" + "simplepie/simplepie": "1.5.*", + "ext-curl": "*" }, "autoload": { "psr-4": { diff --git a/src/Facades/FeedsFacade.php b/src/Facades/FeedsFacade.php index 4cdefdf..687bfb9 100644 --- a/src/Facades/FeedsFacade.php +++ b/src/Facades/FeedsFacade.php @@ -1,11 +1,20 @@ -simplepie = new SimplePie(); + $this->simplePie = new simplePie(); $this->configure(); - $this->simplepie->set_feed_url($feed_url); - $this->simplepie->set_item_limit($limit); - if ($force_feed === true) { - $this->simplepie->force_feed(true); + $this->simplePie->set_feed_url($feedUrl); + $this->simplePie->set_item_limit($limit); + + if ($forceFeed === true) { + $this->simplePie->force_feed(true); } - if (!$this->config['strip_html_tags.disabled'] && !empty($this->config['strip_html_tags.tags']) && is_array($this->config['strip_html_tags.tags'])) { - $this->simplepie->strip_htmltags($this->config['strip_html_tags.tags']); + + $stripHtmlTags = Arr::get($this->config, 'strip_html_tags.disabled', false); + + if (! $stripHtmlTags && ! empty($this->config['strip_html_tags.tags']) && is_array($this->config['strip_html_tags.tags'])) { + $this->simplePie->strip_htmltags($this->config['strip_html_tags.tags']); } else { - $this->simplepie->strip_htmltags(false); + $this->simplePie->strip_htmltags(false); } - if (!$this->config['strip_attribute.disabled'] && !empty($this->config['strip_attribute.tags']) && is_array($this->config['strip_attribute.tags'])) { - $this->simplepie->strip_attributes($this->config['strip_attribute.tags']); + + if (! $stripHtmlTags && ! empty($this->config['strip_attribute.tags']) && is_array($this->config['strip_attribute.tags'])) { + $this->simplePie->strip_attributes($this->config['strip_attribute.tags']); } else { - $this->simplepie->strip_attributes(false); + $this->simplePie->strip_attributes(false); } + if (isset($this->config['curl.timeout']) && is_int($this->config['curl.timeout'])) { - $this->simplepie->set_timeout($this->config['curl.timeout']); + $this->simplePie->set_timeout($this->config['curl.timeout']); } + if (isset($options) && is_array($options)) { if (isset($options['curl.options']) && is_array($options['curl.options'])) { - $this->simplepie->set_curl_options($this->simplepie->curl_options + $options['curl.options']); + $this->simplePie->set_curl_options($this->simplePie->curl_options + $options['curl.options']); } + if (isset($options['strip_html_tags.tags']) && is_array($options['strip_html_tags.tags'])) { - $this->simplepie->strip_htmltags($options['strip_html_tags.tags']); + $this->simplePie->strip_htmltags($options['strip_html_tags.tags']); } + if (isset($options['strip_attribute.tags']) && is_array($options['strip_attribute.tags'])) { - $this->simplepie->strip_attributes($options['strip_attribute.tags']); + $this->simplePie->strip_attributes($options['strip_attribute.tags']); } + if (isset($options['curl.timeout']) && is_int($options['curl.timeout'])) { - $this->simplepie->set_timeout($options['curl.timeout']); + $this->simplePie->set_timeout($options['curl.timeout']); } } - $this->simplepie->init(); - return $this->simplepie; + $this->simplePie->init(); + + return $this->simplePie; } + /** + * Configure SimplePie. + * + * @return void + */ protected function configure() { - $curloptions = []; + $curlOptions = []; + if ($this->config['cache.disabled']) { - $this->simplepie->enable_cache(false); + $this->simplePie->enable_cache(false); } else { - $this->simplepie->set_cache_location($this->config['cache.location']); - $this->simplepie->set_cache_duration($this->config['cache.life']); + $this->simplePie->set_cache_location($this->config['cache.location']); + $this->simplePie->set_cache_duration($this->config['cache.life']); } + if (isset($this->config['curl.options']) && is_array($this->config['curl.options'])) { - $curloptions += $this->config['curl.options']; + $curlOptions += $this->config['curl.options']; } + if ($this->config['ssl_check.disabled']) { - $curloptions[CURLOPT_SSL_VERIFYHOST] = false; - $curloptions[CURLOPT_SSL_VERIFYPEER] = false; + $curlOptions[CURLOPT_SSL_VERIFYHOST] = false; + $curlOptions[CURLOPT_SSL_VERIFYPEER] = false; } - if (is_array($curloptions)) { - $this->simplepie->set_curl_options($curloptions); + + if (is_array($curlOptions)) { + $this->simplePie->set_curl_options($curlOptions); } } } diff --git a/src/FeedsServiceProvider.php b/src/FeedsServiceProvider.php index 1caa72d..6c3237f 100644 --- a/src/FeedsServiceProvider.php +++ b/src/FeedsServiceProvider.php @@ -1,47 +1,53 @@ publishes([ - __DIR__ . '/config/feeds.php' => config_path('feeds.php'), - ]); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() { - $this->app->singleton('Feeds', function () { - $config = config('feeds'); - - if (!$config) { - throw new \RunTimeException('Feeds configuration not found. Please run `php artisan vendor:publish`'); - } - - return new FeedsFactory($config); - }); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() { - return ['Feeds']; - } +class FeedsServiceProvider extends ServiceProvider +{ + /** + * Indicates if loading of the provider is deferred. + * + * @var bool + */ + protected $defer = true; + + /** + * Bootstrap any application services. + * + * @return void + */ + public function boot() + { + $this->publishes([ + __DIR__ . '/config/feeds.php' => config_path('feeds.php'), + ]); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->app->singleton('Feeds', function () { + $config = config('feeds'); + + if (! $config) { + throw new \RunTimeException('Feeds configuration not found. Please run `php artisan vendor:publish`'); + } + + return new FeedsFactory($config); + }); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return ['Feeds']; + } } diff --git a/src/config/feeds.php b/src/config/feeds.php index 56e15bf..05e6ec6 100644 --- a/src/config/feeds.php +++ b/src/config/feeds.php @@ -2,98 +2,104 @@ return [ - /* - |-------------------------------------------------------------------------- - | Cache Location - |-------------------------------------------------------------------------- - | - | Filesystem path to use for caching, the default should be acceptable in - | most cases. - | - */ - 'cache.location' => storage_path() . '/framework/cache', + /* + |-------------------------------------------------------------------------- + | Cache Location + |-------------------------------------------------------------------------- + | + | Filesystem path to use for caching, the default should be acceptable in + | most cases. + | + */ + 'cache.location' => storage_path('framework/cache'), + + /* + |-------------------------------------------------------------------------- + | Cache Life + |-------------------------------------------------------------------------- + | + | Life of cache, in seconds + | + */ + 'cache.life' => 3600, - /* - |-------------------------------------------------------------------------- - | Cache Life - |-------------------------------------------------------------------------- - | - | Life of cache, in seconds - | - */ - 'cache.life' => 3600, + /* + |-------------------------------------------------------------------------- + | Cache Disabled + |-------------------------------------------------------------------------- + | + | Whether to disable the cache. + | + */ + 'cache.disabled' => false, - /* - |-------------------------------------------------------------------------- - | Cache Disabled - |-------------------------------------------------------------------------- - | - | - | - */ - 'cache.disabled' => false, /* - |-------------------------------------------------------------------------- - | Disable Check for SSL certificates (enable for self signed certificates) - |-------------------------------------------------------------------------- - | - | - | - */ - 'ssl_check.disabled' => false, - /* - |-------------------------------------------------------------------------- - | Strip Html Tags Disabled - |-------------------------------------------------------------------------- - | - | - | - */ - 'strip_html_tags.disabled'=> false, + |-------------------------------------------------------------------------- + | Disable Check for SSL certificates (enable for self signed certificates) + |-------------------------------------------------------------------------- + | + | + | + */ + 'ssl_check.disabled' => false, - /* - |-------------------------------------------------------------------------- - | Striped Html Tags - |-------------------------------------------------------------------------- - | - | - | - */ - // 'base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style' - 'strip_html_tags.tags'=> [ 'base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'], + /* + |-------------------------------------------------------------------------- + | Strip Html Tags Disabled + |-------------------------------------------------------------------------- + | + | + | + */ + 'strip_html_tags.disabled' => false, - /* - |-------------------------------------------------------------------------- - | Strip Attributes Disabled - |-------------------------------------------------------------------------- - | - | - | - */ - 'strip_attribute.disabled'=> false, + /* + |-------------------------------------------------------------------------- + | Stripped Html Tags + |-------------------------------------------------------------------------- + | + | + | + */ + 'strip_html_tags.tags' => [ + 'base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', + 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style', + ], - /* - |-------------------------------------------------------------------------- - | Striped Attributes Tags - |-------------------------------------------------------------------------- - | - | - | - */ - // 'bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc' - 'strip_attributes.tags'=> [ 'bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'], + /* + |-------------------------------------------------------------------------- + | Strip Attributes Disabled + |-------------------------------------------------------------------------- + | + | + | + */ + 'strip_attribute.disabled' => false, + + /* + |-------------------------------------------------------------------------- + | Stripped Attributes Tags + |-------------------------------------------------------------------------- + | + | + | + */ + 'strip_attributes.tags' => [ + 'bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', + 'onfocus', 'onblur', 'lowsrc', 'dynsrc', + ], + + /* + |-------------------------------------------------------------------------- + | CURL Options + |-------------------------------------------------------------------------- + | + | Array of CURL options (see curl_setopt()) + | Set to null to disable + | + */ + 'curl.options' => null, - /* - |-------------------------------------------------------------------------- - | CURL Options - |-------------------------------------------------------------------------- - | - | Array of CURL options (see curl_setopt()) - | Set to null to disable - | - */ - 'curl.options' => null, - - 'curl.timeout' => null, + 'curl.timeout' => null, ];