diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-13 23:56:41 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-13 23:56:41 +0200 |
commit | 33342f4ea6c217975a7c2998ba3d13d9becd8f24 (patch) | |
tree | e73cc421ca41148d6d5d8d6f54722e00bb8c0899 | |
parent | ce7cd121f42b093569d7a31fac3bcd5837429cff (diff) |
add code to get favicons, fix #49
-rw-r--r-- | css/feeds.css | 2 | ||||
-rw-r--r-- | js/app/services/bl/feedbl.coffee | 9 | ||||
-rw-r--r-- | js/public/app.js | 10 | ||||
-rw-r--r-- | js/tests/services/bl/feedblSpec.coffee | 6 | ||||
-rw-r--r-- | tests/unit/bl/FolderBlTest.php | 1 | ||||
-rw-r--r-- | utility/feedfetcher.php | 42 |
6 files changed, 52 insertions, 18 deletions
diff --git a/css/feeds.css b/css/feeds.css index ba8b6a367..441b77720 100644 --- a/css/feeds.css +++ b/css/feeds.css @@ -134,7 +134,7 @@ button.action:hover { } .progress-icon { - background-image: url('%webroot%/core/img/loading.gif') !important; + background-image: url('%webroot%/core/img/loading.gif'); } .problem-icon { diff --git a/js/app/services/bl/feedbl.coffee b/js/app/services/bl/feedbl.coffee index ead15fcd7..38aa5bff0 100644 --- a/js/app/services/bl/feedbl.coffee +++ b/js/app/services/bl/feedbl.coffee @@ -23,14 +23,14 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. angular.module('News').factory 'FeedBl', ['_Bl', 'ShowAll', 'Persistence', 'ActiveFeed', 'FeedType', 'ItemModel', -'FeedModel', 'NewLoading', '_ExistsError', +'FeedModel', 'NewLoading', '_ExistsError', 'Utils', (_Bl, ShowAll, Persistence, ActiveFeed, FeedType, ItemModel, FeedModel, -NewLoading, _ExistsError) -> +NewLoading, _ExistsError, Utils) -> class FeedBl extends _Bl constructor: (@_showAll, @_feedModel, persistence, activeFeed, feedType, - itemModel, @_newLoading) -> + itemModel, @_newLoading, @_utils) -> super(activeFeed, persistence, itemModel, feedType.Feed) @@ -147,6 +147,7 @@ NewLoading, _ExistsError) -> urlHash: urlHash folderId: parentId unreadCount: 0 + faviconLink: 'url('+@_utils.imagePath('core', 'loading.gif')+')' @_feedModel.add(feed) @@ -171,6 +172,6 @@ NewLoading, _ExistsError) -> return new FeedBl(ShowAll, FeedModel, Persistence, ActiveFeed, FeedType, - ItemModel, NewLoading) + ItemModel, NewLoading, Utils) ]
\ No newline at end of file diff --git a/js/public/app.js b/js/public/app.js index 04dfaaf79..826ed2891 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -625,16 +625,17 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; angular.module('News').factory('FeedBl', [ - '_Bl', 'ShowAll', 'Persistence', 'ActiveFeed', 'FeedType', 'ItemModel', 'FeedModel', 'NewLoading', '_ExistsError', function(_Bl, ShowAll, Persistence, ActiveFeed, FeedType, ItemModel, FeedModel, NewLoading, _ExistsError) { + '_Bl', 'ShowAll', 'Persistence', 'ActiveFeed', 'FeedType', 'ItemModel', 'FeedModel', 'NewLoading', '_ExistsError', 'Utils', function(_Bl, ShowAll, Persistence, ActiveFeed, FeedType, ItemModel, FeedModel, NewLoading, _ExistsError, Utils) { var FeedBl; FeedBl = (function(_super) { __extends(FeedBl, _super); - function FeedBl(_showAll, _feedModel, persistence, activeFeed, feedType, itemModel, _newLoading) { + function FeedBl(_showAll, _feedModel, persistence, activeFeed, feedType, itemModel, _newLoading, _utils) { this._showAll = _showAll; this._feedModel = _feedModel; this._newLoading = _newLoading; + this._utils = _utils; FeedBl.__super__.constructor.call(this, activeFeed, persistence, itemModel, feedType.Feed); } @@ -780,7 +781,8 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. url: url, urlHash: urlHash, folderId: parentId, - unreadCount: 0 + unreadCount: 0, + faviconLink: 'url(' + this._utils.imagePath('core', 'loading.gif') + ')' }; this._feedModel.add(feed); success = function(response) { @@ -817,7 +819,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. return FeedBl; })(_Bl); - return new FeedBl(ShowAll, FeedModel, Persistence, ActiveFeed, FeedType, ItemModel, NewLoading); + return new FeedBl(ShowAll, FeedModel, Persistence, ActiveFeed, FeedType, ItemModel, NewLoading, Utils); } ]); diff --git a/js/tests/services/bl/feedblSpec.coffee b/js/tests/services/bl/feedblSpec.coffee index 0303dd4c1..6e83874b2 100644 --- a/js/tests/services/bl/feedblSpec.coffee +++ b/js/tests/services/bl/feedblSpec.coffee @@ -34,6 +34,12 @@ describe 'FeedBl', -> getItems: @getItemsSpy createFeed: -> } + angular.module('News').factory 'Utils', => + @imagePath = jasmine.createSpy('imagePath') + @utils = { + imagePath: @imagePath + } + beforeEach inject (@FeedBl, @FeedModel, @ItemModel, @FeedType, @ShowAll, @ActiveFeed, @_ExistsError) => diff --git a/tests/unit/bl/FolderBlTest.php b/tests/unit/bl/FolderBlTest.php index f99dfda9e..ded6e1ddf 100644 --- a/tests/unit/bl/FolderBlTest.php +++ b/tests/unit/bl/FolderBlTest.php @@ -66,6 +66,7 @@ class FolderBlTest extends \OCA\AppFramework\Utility\TestUtility { $folder->setName('hey'); $folder->setParentId(5); $folder->setUserId('john'); + $folder->setOpened(true); $this->folderMapper->expects($this->once()) ->method('insert') diff --git a/utility/feedfetcher.php b/utility/feedfetcher.php index 65d6b2683..ad0ef8baf 100644 --- a/utility/feedfetcher.php +++ b/utility/feedfetcher.php @@ -121,7 +121,7 @@ class FeedFetcher implements IFeedFetcher { // or the webpage } else { - $webFavicon = $this->discoverFavicon($url); + $webFavicon = $this->discoverFavicon($feed->getLink()); if ($webFavicon !== null) { $feed->setFaviconLink($webFavicon); } @@ -145,7 +145,11 @@ class FeedFetcher implements IFeedFetcher { if($file->success) { $sniffer = new \SimplePie_Content_Type_Sniffer($file); - if(substr($sniffer->get_type(), 0, 6) === 'image/') { + $mimeType = $sniffer->get_type(); + if(substr($mimeType, 0, 6) === 'image/') { + return true; + } elseif($mimeType === 'application/octet-stream' && + strpos($favicon, 'favicon.ico') === strlen($favicon) - 11){ return true; } } @@ -154,9 +158,18 @@ class FeedFetcher implements IFeedFetcher { private function discoverFavicon($url) { + // try the /favicon.ico + $url = rtrim($url, '/'); + + $baseFavicon = $url . '/favicon.ico'; + if($this->isValidFavIcon($baseFavicon)){ + return $baseFavicon; + } + echo $baseFavicon; //try to extract favicon from web page $page = $this->api->getUrlContent($url); + if ( FALSE !== $page ) { $doc = @\DOMDocument::loadHTML($page); @@ -167,17 +180,28 @@ class FeedFetcher implements IFeedFetcher { if ( $elements->length > 0 ) { if ( $favicon = $elements->item(0)->getAttribute('href') ) { - // the specified uri might be an url, an absolute or a relative path - // we have to turn it into a url to be able to display it out of context - if ( !parse_url($favicon, PHP_URL_SCHEME) ) { - $absoluteUrl = \SimplePie_Misc::absolutize_url('/', $url); - $favicon = \SimplePie_Misc::absolutize_url($favicon, $absoluteUrl); + // remove // + $favicon = ltrim($favicon, '/'); + + // if it does not start with http, add it + if (strpos($favicon, 'http') !== 0){ + $favicon = 'http://' . $favicon; } - if($this->isValidFavIcon($favicon)){ + // if its already valid, return it + if ($this->isValidFavIcon($favicon)){ return $favicon; + + // assume its a realtive path or absolute path + } else { + // add slash to make it absolute + $favicon = '/' . $favicon; + $favicon = $url . $favicon; + + if($this->isValidFavIcon($favicon)){ + return $favicon; + } } - } } } |