예제 #1
0
 protected function buildItem($parsedItem)
 {
     $item = new Item();
     $item->setUnread();
     $item->setUrl($parsedItem->getUrl());
     $item->setGuid($parsedItem->getId());
     $item->setGuidHash($item->getGuid());
     $item->setPubDate($parsedItem->getDate()->getTimestamp());
     $item->setLastModified($this->time->getTime());
     // unescape content because angularjs helps against XSS
     $item->setTitle($this->decodeTwice($parsedItem->getTitle()));
     $item->setAuthor($this->decodeTwice($parsedItem->getAuthor()));
     // purification is done in the service layer
     $body = $parsedItem->getContent();
     $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) {
             $item->setEnclosureMime($enclosureType);
             $item->setEnclosureLink($enclosureUrl);
         }
     }
     $item->generateSearchIndex();
     return $item;
 }
예제 #2
0
 public function testImportArticlesCreatesOwnFeedWhenNotFound()
 {
     $url = 'http://owncloud/args';
     $feed = new Feed();
     $feed->setId(3);
     $feed->setUserId($this->user);
     $feed->setUrl($url);
     $feed->setLink($url);
     $feed->setTitle('Articles without feed');
     $feed->setAdded($this->time);
     $feed->setFolderId(0);
     $feed->setPreventUpdate(true);
     $feeds = [$feed];
     $item = new Item();
     $item->setFeedId(3);
     $item->setAuthor('john');
     $item->setGuid('s');
     $item->setGuidHash('s');
     $item->setTitle('hey');
     $item->setPubDate(333);
     $item->setBody('come over');
     $item->setEnclosureMime('mime');
     $item->setEnclosureLink('lin');
     $item->setUnread();
     $item->setUnstarred();
     $item->setLastModified($this->time);
     $json = $item->toExport(['feed3' => $feed]);
     $json2 = $json;
     // believe it or not this copies stuff :D
     $json2['feedLink'] = 'http://test.com';
     $items = [$json, $json2];
     $insertFeed = new Feed();
     $insertFeed->setLink('http://owncloud/nofeed');
     $insertFeed->setUrl('http://owncloud/nofeed');
     $insertFeed->setUserId($this->user);
     $insertFeed->setTitle('Articles without feed');
     $insertFeed->setAdded($this->time);
     $insertFeed->setPreventUpdate(true);
     $insertFeed->setFolderId(0);
     $this->l10n->expects($this->once())->method('t')->will($this->returnValue('Articles without feed'));
     $this->feedMapper->expects($this->once())->method('findAllFromUser')->with($this->equalTo($this->user))->will($this->returnValue($feeds));
     $this->feedMapper->expects($this->once())->method('insert')->with($this->equalTo($insertFeed))->will($this->returnValue($insertFeed));
     $this->itemMapper->expects($this->at(0))->method('findByGuidHash')->will($this->throwException(new DoesNotExistException('yo')));
     $this->purifier->expects($this->once())->method('purify')->with($this->equalTo($item->getBody()))->will($this->returnValue($item->getBody()));
     $this->itemMapper->expects($this->at(1))->method('insert')->with($this->equalTo($item));
     $this->itemMapper->expects($this->at(2))->method('findByGuidHash')->will($this->returnValue($item));
     $this->itemMapper->expects($this->at(3))->method('update')->with($this->equalTo($item));
     $this->feedMapper->expects($this->once())->method('findByUrlHash')->will($this->returnValue($feed));
     $result = $this->feedService->importArticles($items, $this->user);
     $this->assertEquals($feed, $result);
 }
예제 #3
0
 private function createItem($enclosureType = null)
 {
     $this->expectItem('getUrl', $this->permalink);
     $this->expectItem('getTitle', $this->title);
     $this->expectItem('getId', $this->guid);
     $this->expectItem('getContent', $this->body);
     $item = new Item();
     date_default_timezone_set('America/Los_Angeles');
     $date = new \DateTime();
     $date->setTimestamp($this->pub);
     $this->expectItem('getDate', $date);
     $item->setPubDate($this->pub);
     $item->setStatus(0);
     $item->setUnread();
     $item->setUrl($this->permalink);
     $item->setTitle('my<\' title');
     $item->setGuid($this->guid);
     $item->setGuidHash($this->guid);
     $item->setBody($this->body);
     $item->setLastModified($this->time);
     $item->generateSearchIndex();
     $this->expectItem('getAuthor', $this->author);
     $item->setAuthor(html_entity_decode($this->author));
     if ($enclosureType === 'audio/ogg' || $enclosureType === 'video/ogg') {
         $this->expectItem('getEnclosureUrl', $this->enclosureLink);
         $this->expectItem('getEnclosureType', $enclosureType);
         $item->setEnclosureMime($enclosureType);
         $item->setEnclosureLink($this->enclosureLink);
     }
     return $item;
 }
예제 #4
0
    private function createItem($enclosureType=null) {
        $this->expectItem('getUrl', $this->permalink);
        $this->expectItem('getTitle', $this->title);
        $this->expectItem('getId', $this->guid);
        $this->expectItem('getContent', $this->body);

        $item = new Item();

        $this->expectItem('getDate', $this->pub);
        $item->setPubDate($this->pub);

        $item->setStatus(0);
        $item->setUnread();
        $item->setUrl($this->permalink);
        $item->setTitle('my<\' title');
        $item->setGuid($this->guid);
        $item->setGuidHash($this->guid);
        $item->setBody($this->body);
        $item->setLastModified($this->time);

        $this->expectItem('getAuthor', $this->author);
        $item->setAuthor(html_entity_decode($this->author));

        if($enclosureType === 'audio/ogg' || $enclosureType === 'video/ogg') {
            $this->expectItem('getEnclosureUrl', $this->enclosureLink);
            $this->expectItem('getEnclosureType', $enclosureType);

            $item->setEnclosureMime($enclosureType);
            $item->setEnclosureLink($this->enclosureLink);
        }
        return $item;
    }
예제 #5
0
 private function createItem($author = false, $enclosureType = null, $noPubDate = false)
 {
     $this->expectItem('get_permalink', $this->permalink);
     $this->expectItem('get_title', $this->title);
     $this->expectItem('get_id', $this->guid);
     $this->expectItem('get_content', $this->body);
     $item = new Item();
     if ($noPubDate) {
         $this->expectItem('get_date', 0);
         $item->setPubDate($this->time);
     } else {
         $this->expectItem('get_date', $this->pub);
         $item->setPubDate($this->pub);
     }
     $item->setStatus(0);
     $item->setUnread();
     $item->setUrl($this->permalink);
     $item->setTitle('my<\' title');
     $item->setGuid($this->guid);
     $item->setGuidHash(md5($this->guid));
     $item->setBody($this->body);
     $item->setLastModified($this->time);
     if ($author) {
         $mock = $this->getMock('author', array('get_name'));
         $mock->expects($this->once())->method('get_name')->will($this->returnValue($this->author));
         $this->expectItem('get_author', $mock);
         $item->setAuthor(html_entity_decode($this->author));
     } else {
         $mock = $this->getMock('author', array('get_name', 'get_email'));
         $mock->expects($this->any())->method('get_name')->will($this->returnValue(''));
         $mock->expects($this->any())->method('get_email')->will($this->returnValue($this->authorMail));
         $this->expectItem('get_author', $mock);
         $item->setAuthor(html_entity_decode($this->authorMail));
     }
     if ($enclosureType === 'audio/ogg') {
         $mock = $this->getMock('enclosure', array('get_type', 'get_link'));
         $mock->expects($this->any())->method('get_type')->will($this->returnValue($enclosureType));
         $this->expectItem('get_enclosure', $this->mock);
         $item->setEnclosureMime($enclosureType);
         $item->setEnclosureLink($this->enclosureLink);
     }
     return $item;
 }
예제 #6
0
파일: bootstrap.php 프로젝트: sbambach/news
 private function createItem($item)
 {
     $newItem = new Item();
     $newItem->setFeedId($item['feedId']);
     $newItem->setStatus($item['status']);
     $newItem->setBody($item['body']);
     $newItem->setTitle($item['title']);
     $newItem->setAuthor($item['author']);
     $newItem->setGuid($item['guid']);
     $newItem->setGuidHash($item['guid']);
     $newItem->setUrl($item['url']);
     $newItem->setPubDate($item['pubDate']);
     $newItem->setLastModified($item['lastModified']);
     $newItem->setEnclosureMime($item['enclosureMime']);
     $newItem->setEnclosureLink($item['enclosureLink']);
     return $this->itemMapper->insert($newItem);
 }
예제 #7
0
 protected function buildItem($simplePieItem, $feedLink)
 {
     $item = new Item();
     $item->setStatus(0);
     $item->setUnread();
     $url = $this->decodeTwice($simplePieItem->get_permalink());
     if (!$url) {
         $url = $feedLink;
     }
     $item->setUrl($url);
     // unescape content because angularjs helps against XSS
     $item->setTitle($this->decodeTwice($simplePieItem->get_title()));
     $guid = $simplePieItem->get_id();
     $item->setGuid($guid);
     // purification is done in the businesslayer
     $item->setBody($simplePieItem->get_content());
     // pubdate is not required. if not given use the current date
     $date = $simplePieItem->get_date('U');
     if (!$date) {
         $date = $this->time->getTime();
     }
     $item->setPubDate($date);
     $item->setLastModified($this->time->getTime());
     $author = $simplePieItem->get_author();
     if ($author !== null) {
         $name = $this->decodeTwice($author->get_name());
         if ($name) {
             $item->setAuthor($name);
         } else {
             $item->setAuthor($this->decodeTwice($author->get_email()));
         }
     }
     // TODO: make it work for video files also
     $enclosure = $simplePieItem->get_enclosure();
     if ($enclosure !== null) {
         $enclosureType = $enclosure->get_type();
         if (stripos($enclosureType, "audio/") !== false) {
             $item->setEnclosureMime($enclosureType);
             $item->setEnclosureLink($enclosure->get_link());
         }
     }
     return $item;
 }