summaryrefslogtreecommitdiffstats
path: root/lib/Fetcher/FeedFetcher.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Fetcher/FeedFetcher.php')
-rw-r--r--lib/Fetcher/FeedFetcher.php180
1 files changed, 101 insertions, 79 deletions
diff --git a/lib/Fetcher/FeedFetcher.php b/lib/Fetcher/FeedFetcher.php
index e63db2772..9a2e67445 100644
--- a/lib/Fetcher/FeedFetcher.php
+++ b/lib/Fetcher/FeedFetcher.php
@@ -5,10 +5,10 @@
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
- * @author Alessandro Cosentino <cosenal@gmail.com>
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright Alessandro Cosentino 2012
- * @copyright Bernhard Posselt 2012, 2014
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright 2012 Alessandro Cosentino
+ * @copyright 2012-2014 Bernhard Posselt
*/
namespace OCA\News\Fetcher;
@@ -38,7 +38,8 @@ use OCA\News\Utility\PicoFeedFaviconFactory;
use OCA\News\Utility\PicoFeedReaderFactory;
use OCA\News\Utility\Time;
-class FeedFetcher implements IFeedFetcher {
+class FeedFetcher implements IFeedFetcher
+{
private $faviconFactory;
private $reader;
@@ -47,10 +48,11 @@ class FeedFetcher implements IFeedFetcher {
private $clientService;
public function __construct(Reader $reader,
- PicoFeedFaviconFactory $faviconFactory,
- IL10N $l10n,
- Time $time,
- IClientService $clientService) {
+ PicoFeedFaviconFactory $faviconFactory,
+ IL10N $l10n,
+ Time $time,
+ IClientService $clientService
+ ) {
$this->faviconFactory = $faviconFactory;
$this->reader = $reader;
$this->time = $time;
@@ -62,39 +64,47 @@ class FeedFetcher implements IFeedFetcher {
/**
* This fetcher handles all the remaining urls therefore always returns true
*/
- public function canHandle($url) {
+ public function canHandle($url)
+ {
return true;
}
/**
* Fetch a feed from remote
- * @param string $url remote url of the feed
- * @param boolean $getFavicon if the favicon should also be fetched,
- * defaults to true
- * @param string $lastModified a last modified value from an http header
- * defaults to false. If lastModified matches the http header from the feed
- * no results are fetched
- * @param string $etag an etag from an http header.
- * If lastModified matches the http header from the feed
- * no results are fetched
- * @param bool fullTextEnabled if true tells the fetcher to enhance the
+ *
+ * @param string $url remote url of the feed
+ * @param boolean $getFavicon if the favicon should also be fetched,
+ * defaults to true
+ * @param string $lastModified a last modified value from an http header
+ * defaults to false. If lastModified
+ * matches the http header from the feed no
+ * results are fetched
+ * @param string $etag an etag from an http header.
+ * If lastModified matches the
+ * http header from the feed no
+ * results are fetched
+ * @param bool fullTextEnabled if true tells the fetcher to enhance the
* articles by fetching custom enhanced content
- * @param string $basicAuthUser if given, basic auth is set for this feed
- * @param string $basicAuthPassword if given, basic auth is set for this
- * feed. Ignored if user is null or an empty string
+ * @param string $basicAuthUser if given, basic auth is set for this feed
+ * @param string $basicAuthPassword if given, basic auth is set for this
+ * feed. Ignored if user is null or an
+ * empty string
* @throws FetcherException if it fails
* @return array an array containing the new feed and its items, first
* element being the Feed and second element being an array of Items
*/
public function fetch($url, $getFavicon = true, $lastModified = null,
- $etag = null, $fullTextEnabled = false,
- $basicAuthUser = null, $basicAuthPassword = null) {
+ $etag = null, $fullTextEnabled = false,
+ $basicAuthUser = null, $basicAuthPassword = null
+ ) {
try {
if ($basicAuthUser !== null && trim($basicAuthUser) !== '') {
- $resource = $this->reader->discover($url, $lastModified, $etag,
+ $resource = $this->reader->discover(
+ $url, $lastModified, $etag,
$basicAuthUser,
- $basicAuthPassword);
+ $basicAuthPassword
+ );
} else {
$resource = $this->reader->discover($url, $lastModified, $etag);
}
@@ -136,16 +146,19 @@ class FeedFetcher implements IFeedFetcher {
}
- private function handleError(Exception $ex, $url) {
+ private function handleError(Exception $ex, $url)
+ {
$msg = $ex->getMessage();
if ($ex instanceof MalFormedXmlException) {
$msg = $this->l10n->t('Feed contains invalid XML');
} else if ($ex instanceof SubscriptionNotFoundException) {
- $msg = $this->l10n->t('Feed not found: Either the website ' .
+ $msg = $this->l10n->t(
+ 'Feed not found: Either the website ' .
'does not provide a feed or blocks access. To rule out ' .
'blocking, try to download the feed on your server\'s ' .
- 'command line using curl: curl ' . $url);
+ 'command line using curl: curl ' . $url
+ );
} else if ($ex instanceof UnsupportedFeedFormatException) {
$msg = $this->l10n->t('Detected feed format is not supported');
} else if ($ex instanceof InvalidCertificateException) {
@@ -159,8 +172,10 @@ class FeedFetcher implements IFeedFetcher {
} else if ($ex instanceof TimeoutException) {
$msg = $this->l10n->t('Request timed out');
} else if ($ex instanceof UnauthorizedException) {
- $msg = $this->l10n->t('Required credentials for feed were ' .
- 'either missing or incorrect');
+ $msg = $this->l10n->t(
+ 'Required credentials for feed were ' .
+ 'either missing or incorrect'
+ );
} else if ($ex instanceof ForbiddenException) {
$msg = $this->l10n->t('Forbidden to access feed');
}
@@ -168,57 +183,59 @@ class FeedFetcher implements IFeedFetcher {
throw new FetcherException($msg);
}
- private function buildCurlSslErrorMessage($errorCode) {
+ private function buildCurlSslErrorMessage($errorCode)
+ {
switch ($errorCode) {
- case 35: // CURLE_SSL_CONNECT_ERROR
- return $this->l10n->t(
- 'Certificate error: A problem occurred ' .
+ case 35: // CURLE_SSL_CONNECT_ERROR
+ return $this->l10n->t(
+ 'Certificate error: A problem occurred ' .
'somewhere in the SSL/TLS handshake. Could be ' .
'certificates (file formats, paths, permissions), ' .
'passwords, and others.'
- );
- case 51: // CURLE_PEER_FAILED_VERIFICATION
- return $this->l10n->t(
- 'Certificate error: The remote server\'s SSL ' .
+ );
+ case 51: // CURLE_PEER_FAILED_VERIFICATION
+ return $this->l10n->t(
+ 'Certificate error: The remote server\'s SSL ' .
'certificate or SSH md5 fingerprint was deemed not OK.'
- );
- case 58: // CURLE_SSL_CERTPROBLEM
- return $this->l10n->t(
- 'Certificate error: Problem with the local client ' .
+ );
+ case 58: // CURLE_SSL_CERTPROBLEM
+ return $this->l10n->t(
+ 'Certificate error: Problem with the local client ' .
'certificate.'
- );
- case 59: // CURLE_SSL_CIPHER
- return $this->l10n->t(
- 'Certificate error: Couldn\'t use specified cipher.'
- );
- case 60: // CURLE_SSL_CACERT
- return $this->l10n->t(
- 'Certificate error: Peer certificate cannot be ' .
+ );
+ case 59: // CURLE_SSL_CIPHER
+ return $this->l10n->t(
+ 'Certificate error: Couldn\'t use specified cipher.'
+ );
+ case 60: // CURLE_SSL_CACERT
+ return $this->l10n->t(
+ 'Certificate error: Peer certificate cannot be ' .
'authenticated with known CA certificates.'
- );
- case 64: // CURLE_USE_SSL_FAILED
- return $this->l10n->t(
- 'Certificate error: Requested FTP SSL level failed.'
- );
- case 66: // CURLE_SSL_ENGINE_INITFAILED
- return $this->l10n->t(
- 'Certificate error: Initiating the SSL engine failed.'
- );
- case 77: // CURLE_SSL_CACERT_BADFILE
- return $this->l10n->t(
- 'Certificate error: Problem with reading the SSL CA ' .
+ );
+ case 64: // CURLE_USE_SSL_FAILED
+ return $this->l10n->t(
+ 'Certificate error: Requested FTP SSL level failed.'
+ );
+ case 66: // CURLE_SSL_ENGINE_INITFAILED
+ return $this->l10n->t(
+ 'Certificate error: Initiating the SSL engine failed.'
+ );
+ case 77: // CURLE_SSL_CACERT_BADFILE
+ return $this->l10n->t(
+ 'Certificate error: Problem with reading the SSL CA ' .
'cert (path? access rights?)'
- );
- case 83: // CURLE_SSL_ISSUER_ERROR
- return $this->l10n->t(
- 'Certificate error: Issuer check failed'
- );
- default:
- return $this->l10n->t('Unknown SSL certificate error!');
+ );
+ case 83: // CURLE_SSL_ISSUER_ERROR
+ return $this->l10n->t(
+ 'Certificate error: Issuer check failed'
+ );
+ default:
+ return $this->l10n->t('Unknown SSL certificate error!');
}
}
- private function decodeTwice($string) {
+ private function decodeTwice($string)
+ {
return html_entity_decode(
html_entity_decode(
$string, ENT_QUOTES | ENT_HTML5, 'UTF-8'
@@ -228,7 +245,8 @@ class FeedFetcher implements IFeedFetcher {
}
- protected function determineRtl($parsedItem, $parsedFeed) {
+ protected function determineRtl($parsedItem, $parsedFeed)
+ {
$itemLang = $parsedItem->getLanguage();
$feedLang = $parsedFeed->getLanguage();
@@ -240,7 +258,8 @@ class FeedFetcher implements IFeedFetcher {
}
- protected function buildItem($parsedItem, $parsedFeed) {
+ protected function buildItem($parsedItem, $parsedFeed)
+ {
$item = new Item();
$item->setUnread(true);
$item->setUrl($parsedItem->getUrl());
@@ -256,15 +275,17 @@ class FeedFetcher implements IFeedFetcher {
// purification is done in the service layer
$body = $parsedItem->getContent();
- $body = mb_convert_encoding($body, 'HTML-ENTITIES',
- mb_detect_encoding($body));
+ $body = mb_convert_encoding(
+ $body, 'HTML-ENTITIES',
+ mb_detect_encoding($body)
+ );
$item->setBody($body);
$enclosureUrl = $parsedItem->getEnclosureUrl();
if ($enclosureUrl) {
$enclosureType = $parsedItem->getEnclosureType();
- if (stripos($enclosureType, 'audio/') !== false ||
- stripos($enclosureType, 'video/') !== false
+ if (stripos($enclosureType, 'audio/') !== false
+ || stripos($enclosureType, 'video/') !== false
) {
$item->setEnclosureMime($enclosureType);
$item->setEnclosureLink($enclosureUrl);
@@ -278,7 +299,8 @@ class FeedFetcher implements IFeedFetcher {
protected function buildFeed($parsedFeed, $url, $getFavicon, $modified,
- $etag, $location) {
+ $etag, $location
+ ) {
$feed = new Feed();
$link = $parsedFeed->getSiteUrl();