Example #1
0
 public function findByUrlHash($hash, $userId)
 {
     $sql = 'SELECT `feeds`.*, COUNT(`items`.`id`) AS `unread_count` ' . 'FROM `*PREFIX*news_feeds` `feeds` ' . 'LEFT JOIN `*PREFIX*news_items` `items` ' . 'ON `feeds`.`id` = `items`.`feed_id` ' . 'AND (`items`.`status` & ' . StatusFlag::UNREAD . ') = ' . StatusFlag::UNREAD . ' ' . 'WHERE `feeds`.`url_hash` = ? ' . 'AND `feeds`.`user_id` = ? ' . 'GROUP BY `feeds`.`id`, `feeds`.`user_id`, `feeds`.`url_hash`,' . '`feeds`.`url`, `feeds`.`title`, `feeds`.`link`,' . '`feeds`.`favicon_link`, `feeds`.`added`, `feeds`.`articles_per_update`,' . '`feeds`.`folder_id`, `feeds`.`prevent_update`, `feeds`.`deleted_at`';
     $params = array($hash, $userId);
     $row = $this->findOneQuery($sql, $params);
     $feed = new Feed();
     $feed->fromRow($row);
     return $feed;
 }
Example #2
0
 public function testPlaylistUrl()
 {
     $url = 'http://youtube.com/something/weird?a=b&list=sobo3&c=1';
     $transformedUrl = 'http://gdata.youtube.com/feeds/api/playlists/sobo3';
     $favicon = true;
     $modified = 3;
     $etag = 5;
     $feed = new Feed();
     $feed->setUrl('http://google.de');
     $result = [$feed, []];
     $this->feedFetcher->expects($this->once())->method('fetch')->with($this->equalTo($transformedUrl), $this->equalTo($favicon), $this->equalTo($modified), $this->equalTo($etag))->will($this->returnValue($result));
     $feed = $this->fetcher->fetch($url, $favicon, $modified, $etag);
     $this->assertEquals($url, $result[0]->getUrl());
 }
Example #3
0
 public function __construct(array $defaults = [])
 {
     parent::__construct();
     $defaults = array_merge(['userId' => 'test', 'urlHash' => 'urlHash', 'url' => 'http://the.url.com', 'title' => 'title', 'faviconLink' => 'http://feed.com/favicon.ico', 'added' => 3000, 'folderId' => 0, 'link' => 'http://feed.com/rss', 'preventUpdate' => false, 'deletedAt' => 0, 'articlesPerUpdate' => 40, 'lastModified' => 10, 'etag' => '', 'location' => 'http://feed.com/rss', 'ordering' => 0, 'fullTextEnabled' => false, 'pinned' => false, 'updateMode' => 0, 'updateErrorCount' => 0, 'lastUpdateError' => ''], $defaults);
     unset($defaults['items']);
     $this->fillDefaults($defaults);
 }
Example #4
0
 public function testGetAllArticles()
 {
     $item1 = new Item();
     $item1->setFeedId(3);
     $item2 = new Item();
     $item2->setFeedId(5);
     $feed1 = new Feed();
     $feed1->setId(3);
     $feed1->setLink('http://goo');
     $feed2 = new Feed();
     $feed2->setId(5);
     $feed2->setLink('http://gee');
     $feeds = array($feed1, $feed2);
     $articles = array($item1, $item2);
     $this->feedBusinessLayer->expects($this->once())->method('findAll')->with($this->equalTo($this->user))->will($this->returnValue($feeds));
     $this->itemBusinessLayer->expects($this->once())->method('getUnreadOrStarred')->with($this->equalTo($this->user))->will($this->returnValue($articles));
     $return = $this->controller->articles();
     $headers = $return->getHeaders();
     $this->assertEquals('attachment; filename="articles.json"', $headers['Content-Disposition']);
     $this->assertEquals('[{"guid":null,"url":null,"title":null,' . '"author":null,"pubDate":null,"body":null,"enclosureMime":null,' . '"enclosureLink":null,"unread":false,"starred":false,' . '"feedLink":"http:\\/\\/goo"},{"guid":null,"url":null,"title":null,' . '"author":null,"pubDate":null,"body":null,"enclosureMime":null,' . '"enclosureLink":null,"unread":false,"starred":false,' . '"feedLink":"http:\\/\\/gee"}]', $return->render());
 }
Example #5
0
 public function testSetPinned()
 {
     $feed = Feed::fromRow(['id' => 3, 'pinned' => false]);
     $this->feedMapper->expects($this->once())->method('find')->with($this->equalTo($feed->getId()), $this->equalTo($this->user))->will($this->returnValue($feed));
     $feed->setPinned(true);
     $this->feedMapper->expects($this->once())->method('update')->with($this->equalTo($feed));
     $this->feedService->setPinned(3, true, $this->user);
 }
Example #6
0
 public function testPurgeDeletedWithoutInterval()
 {
     $feed1 = new Feed();
     $feed1->setId(3);
     $feed2 = new Feed();
     $feed2->setId(5);
     $feeds = array($feed1, $feed2);
     $this->feedMapper->expects($this->once())->method('getToDelete')->with($this->equalTo(null), $this->equalTo($this->user))->will($this->returnValue($feeds));
     $this->feedMapper->expects($this->at(1))->method('delete')->with($this->equalTo($feed1));
     $this->feedMapper->expects($this->at(2))->method('delete')->with($this->equalTo($feed2));
     $this->feedBusinessLayer->purgeDeleted($this->user, false);
 }
Example #7
0
 private function createFeed($hasFavicon = false)
 {
     $this->expectFeed('getTitle', $this->feedTitle);
     $this->expectFeed('getSiteUrl', $this->feedLink);
     $feed = new Feed();
     $feed->setTitle('&its a title');
     $feed->setUrl($this->url);
     $feed->setLink($this->feedLink);
     $feed->setAdded($this->time);
     $feed->setLastModified($this->modified);
     $feed->setEtag($this->etag);
     $feed->setLocation($this->location);
     if ($hasFavicon) {
         $this->faviconFactory->expects($this->once())->method('build')->will($this->returnValue($this->faviconFetcher));
         $this->faviconFetcher->expects($this->once())->method('find')->with($this->equalTo($this->feedLink))->will($this->returnValue($this->webFavicon));
         $feed->setFaviconLink($this->webFavicon);
     }
     return $feed;
 }
 public function testUpdate()
 {
     $feed = new Feed();
     $feed->setId(3);
     $feed->setUnreadCount(44);
     $result = ['feeds' => [['id' => $feed->getId(), 'unreadCount' => $feed->getUnreadCount()]]];
     $this->feedService->expects($this->once())->method('update')->with($this->equalTo(4), $this->equalTo($this->user))->will($this->returnValue($feed));
     $response = $this->controller->update(4);
     $this->assertEquals($result, $response);
 }
Example #9
0
 public function testUpdate()
 {
     $feed = new Feed();
     $feed->setId(3);
     $feed->setUnreadCount(44);
     $result = array('feeds' => array(array('id' => $feed->getId(), 'unreadCount' => $feed->getUnreadCount())));
     $url = array('feedId' => 4);
     $this->controller = $this->getPostController(array(), $url);
     $this->feedBusinessLayer->expects($this->once())->method('update')->with($this->equalTo($url['feedId']), $this->equalTo($this->user))->will($this->returnValue($feed));
     $response = $this->controller->update();
     $this->assertEquals($result, $response->getData());
 }
Example #10
0
 public function testFetchMapItemsNoGetFavicon()
 {
     $this->expectCore('get_title', $this->feedTitle);
     $this->expectCore('get_permalink', $this->feedLink, 2);
     $feed = new Feed();
     $feed->setTitle('&its a title');
     $feed->setUrl($this->url);
     $feed->setLink($this->feedLink);
     $feed->setAdded($this->time);
     $this->core->expects($this->once())->method('init')->will($this->returnValue(true));
     $this->faviconFetcher->expects($this->never())->method('fetch');
     $item = $this->createItem(false, true);
     $this->expectCore('get_items', array($this->item));
     $result = $this->fetcher->fetch($this->url, false);
     $this->assertEquals(array($feed, array($item)), $result);
 }
Example #11
0
    /**
     * Import articles
     * @param array $json the array with json
     * @param string $userId the username
     * @return Feed if one had to be created for nonexistent feeds
     */
    public function importArticles($json, $userId) {
        $url = 'http://owncloud/nofeed';
        $urlHash = md5($url);

        // build assoc array for fast access
        $feeds = $this->findAll($userId);
        $feedsDict = [];
        foreach($feeds as $feed) {
            $feedsDict[$feed->getLink()] = $feed;
        }

        $createdFeed = false;

        // loop over all items and get the corresponding feed
        // if the feed does not exist, create a separate feed for them
        foreach ($json as $entry) {
            $item = Item::fromImport($entry);
            $item->setLastModified($this->timeFactory->getTime());
            $feedLink = $entry['feedLink'];  // this is not set on the item yet

            if(array_key_exists($feedLink, $feedsDict)) {
                $feed = $feedsDict[$feedLink];
                $item->setFeedId($feed->getId());
            } elseif(array_key_exists($url, $feedsDict)) {
                $feed = $feedsDict[$url];
                $item->setFeedId($feed->getId());
            } else {
                $createdFeed = true;
                $feed = new Feed();
                $feed->setUserId($userId);
                $feed->setLink($url);
                $feed->setUrl($url);
                $feed->setTitle($this->l10n->t('Articles without feed'));
                $feed->setAdded($this->timeFactory->getTime());
                $feed->setFolderId(0);
                $feed->setPreventUpdate(true);
                $feed = $this->feedMapper->insert($feed);

                $item->setFeedId($feed->getId());
                $feedsDict[$feed->getLink()] = $feed;
            }

            try {
                // if item exists, copy the status
                $existingItem = $this->itemMapper->findByGuidHash(
                    $item->getGuidHash(), $feed->getId(), $userId);
                $existingItem->setStatus($item->getStatus());
                $this->itemMapper->update($existingItem);
            } catch(DoesNotExistException $ex){
                $item->setBody($this->purifier->purify($item->getBody()));
                $this->itemMapper->insert($item);
            }
        }

        if($createdFeed) {
            return $this->feedMapper->findByUrlHash($urlHash, $userId);
        }

        return null;
    }
Example #12
0
 private function createFeed($feed)
 {
     $newFeed = new Feed();
     $newFeed->setUserId($this->userId);
     $newFeed->setFolderId($feed['folderId']);
     $newFeed->setTitle($feed['title']);
     $newFeed->setUrl($feed['url']);
     $newFeed->setLocation($feed['location']);
     $newFeed->setFaviconLink($feed['faviconLink']);
     $newFeed->setAdded($feed['added']);
     $newFeed->setLink($feed['link']);
     $newFeed->setPreventUpdate($feed['preventUpdate']);
     $newFeed->setDeletedAt($feed['deletedAt']);
     $newFeed->setArticlesPerUpdate($feed['articlesPerUpdate']);
     $newFeed->setLastModified($feed['lastModified']);
     $newFeed->setEtag($feed['etag']);
     return $this->feedMapper->insert($newFeed);
 }
Example #13
0
 public function testfromAllUsers()
 {
     $feed = new Feed();
     $feed->setUrl(3);
     $feed->setId(1);
     $feed->setUserId('john');
     $feeds = array($feed);
     $this->feedBusinessLayer->expects($this->once())->method('findAllFromAllUsers')->will($this->returnValue($feeds));
     $response = $this->feedAPI->fromAllUsers();
     $this->assertEquals('{"feeds":[{"id":1,"userId":"john"}]}', $response->render());
 }
Example #14
0
 protected function buildFeed($parsedFeed, $url, $getFavicon, $modified, $etag, $location)
 {
     $feed = new Feed();
     $link = $parsedFeed->getSiteUrl();
     if (!$link) {
         $link = $location;
     }
     // unescape content because angularjs helps against XSS
     $title = strip_tags($this->decodeTwice($parsedFeed->getTitle()));
     $feed->setTitle($title);
     $feed->setUrl($url);
     // the url used to add the feed
     $feed->setLocation($location);
     // the url where the feed was found
     $feed->setLink($link);
     // <link> attribute in the feed
     $feed->setLastModified($modified);
     $feed->setEtag($etag);
     $feed->setAdded($this->time->getTime());
     if ($getFavicon) {
         $faviconFetcher = $this->faviconFactory->build();
         $favicon = $faviconFetcher->find($feed->getLink());
         $feed->setFaviconLink($favicon);
     }
     return $feed;
 }
Example #15
0
 public function testfromAllUsers()
 {
     $feed = new Feed();
     $feed->setUrl(3);
     $feed->setId(1);
     $feed->setUserId('john');
     $feeds = [$feed];
     $this->feedService->expects($this->once())->method('findAllFromAllUsers')->will($this->returnValue($feeds));
     $response = json_encode($this->feedAPI->fromAllUsers());
     $this->assertEquals('{"feeds":[{"id":1,"userId":"john"}]}', $response);
 }
Example #16
0
 /**
  * @expectedException OCA\News\Service\ServiceNotFoundException
  */
 public function testOrderingDoesNotExist()
 {
     $feed = Feed::fromRow(['id' => 3]);
     $this->feedMapper->expects($this->once())->method('find')->will($this->throwException(new DoesNotExistException('')));
     $this->feedService->setOrdering(3, 2, $this->user);
 }
Example #17
0
 protected function buildFeed($simplePieFeed, $url, $getFavicon)
 {
     $feed = new Feed();
     // unescape content because angularjs helps against XSS
     $title = strip_tags($this->decodeTwice($simplePieFeed->get_title()));
     // if there is no title use the url
     if (!$title) {
         $title = $url;
     }
     $feed->setTitle($title);
     $feed->setUrl($url);
     $link = $simplePieFeed->get_permalink();
     if (!$link) {
         $link = $url;
     }
     $feed->setLink($link);
     $feed->setAdded($this->time->getTime());
     if ($getFavicon) {
         // use the favicon from the page first since most feeds use a weird image
         $favicon = $this->faviconFetcher->fetch($feed->getLink());
         if (!$favicon) {
             $favicon = $simplePieFeed->get_image_url();
         }
         $feed->setFaviconLink($favicon);
     }
     return $feed;
 }