예제 #1
0
 /**
  *
  * @param DOMElement $node
  * @param Item       $item
  */
 protected function setContent(DOMElement $node, Item $item)
 {
     $value = $this->getNodeValueByTagNameNS($node, 'http://purl.org/rss/1.0/modules/content/', 'encoded');
     if ($value) {
         $item->setContent($value);
     }
 }
예제 #2
0
 /**
  * @param Item $item
  *
  * @return bool|string
  */
 protected function setImageFromContent(Item $item)
 {
     $images = $this->getImages($item->getContent());
     foreach ($images as $image) {
         if ($this->isOnIgnoredPatterns($image)) {
             continue;
         }
         $item->setImage($image);
         return;
     }
 }
예제 #3
0
 /**
  * @param Item $item
  *
  * @return bool|string
  */
 protected function setImagesFromContent(Item $item)
 {
     $allImages = $this->getImages($item->getContent());
     $images = array();
     foreach ($allImages as $image) {
         if ($this->isOnIgnoredPatterns($image)) {
             continue;
         }
         $images[$image] = $image;
     }
     $item->setExtra('images', array_values($images));
 }
예제 #4
0
 /**
  * @param Item $item
  *
  * @return Item
  */
 protected function fixPaths(Item $item)
 {
     $url = new Url($item->getSource());
     $item->setIntro($this->getFixedText($item->getIntro(), $url->getFullHost()));
     $item->setContent($this->getFixedText($item->getContent(), $url->getFullHost()));
     return $item;
 }
예제 #5
0
 /**
  * @param Item $item
  *
  * @return Item
  */
 public function removeStyle(Item $item)
 {
     $item->setIntro(preg_replace('/(<[^>]+) style=".*?"/i', '$1', $item->getIntro()));
     $item->setContent(preg_replace('/(<[^>]+) style=".*?"/i', '$1', $item->getContent()));
     return $item;
 }
예제 #6
0
 /**
  * @param Item $item
  *
  * @return Item
  */
 protected function doClean(Item $item)
 {
     $item->setIntro(strip_tags($item->getIntro(), $this->allowedTags['intro']));
     $item->setContent(strip_tags($item->getContent(), $this->allowedTags['content']));
     return $item;
 }
 /**
  * @dataProvider dataProvider
  */
 public function testTags(Item $item, $content, $fileName)
 {
     $expected = $this->getFirstValueFromXpath($content, "*/item[1]/category");
     $tags = $item->getTags();
     if (!$expected) {
         $this->assertCount(0, $item->getTags(), 'Fail asserting that first element of ' . $fileName . ' has no tags');
         return;
     }
     $this->assertEquals($expected, array_shift($tags), 'Fail asserting that first element of ' . $fileName . ' has first tag "' . $expected . '"');
 }
예제 #8
0
 public function testItem()
 {
     $item = new Item();
     $date = new DateTime();
     $item->setId('id');
     $item->setName('name');
     $item->setIntro('intro');
     $item->setContent('content');
     $item->setSource('source');
     $item->setAuthor('author');
     $item->setImage('image');
     $item->setDate($date);
     $item->setExtra('key', 'value');
     $item->setTags(array('tag'));
     $this->assertEquals('id', $item->getId());
     $this->assertEquals('name', $item->getName());
     $this->assertEquals('intro', $item->getIntro());
     $this->assertEquals('content', $item->getContent());
     $this->assertEquals('source', $item->getSource());
     $this->assertEquals('author', $item->getAuthor());
     $this->assertEquals('image', $item->getImage());
     $this->assertEquals($date, $item->getDate());
     $this->assertEquals('value', $item->getExtra('key'));
     $this->assertEquals(null, $item->getExtra('key-no-exist'));
     $this->assertEquals(array('tag'), $item->getTags());
 }
예제 #9
0
 /**
  * @param Item $item
  *
  * @return string
  */
 protected function doClean(Item $item)
 {
     $item->setIntro($this->purifier->purify($item->getIntro()));
     $item->setContent($this->purifier->purify($item->getContent()));
     return $item;
 }
예제 #10
0
 /**
  * @param DOMElement $node
  * @param Item       $item
  */
 protected function setTags(DOMElement $node, Item $item)
 {
     $tags = $this->getNodeValuesByTagName($node, 'category');
     foreach ($tags as $tag) {
         $item->addTag($tag);
     }
 }
예제 #11
0
 /**
  * Execute the Aggregator
  *
  * @param DOMElement $node
  * @param Item       $item
  */
 public function process(DOMElement $node, Item $item)
 {
     foreach ($this->keys as $key) {
         $item->setExtra($key, $this->getValue($node, $key));
     }
 }