Пример #1
0
 public function parseWithMinDate($latestDate = null)
 {
     $this->_fead = new Application_Model_Entity_Fead();
     $this->_fead->setType('atom');
     $this->_fead->_version = 1.0;
     $document = new DOMDocument();
     $document->loadXML($this->_data);
     foreach ($document->getElementsByTagName('entry') as $article) {
         $a = new Application_Model_Entity_Article();
         $a->setFeadId($this->_feadId);
         for ($n = $article->firstChild; $n; $n = $n->nextSibling) {
             if ($n instanceof DOMElement) {
                 if ('title' === $n->tagName) {
                     $a->setTitle($n->nodeValue);
                 } else {
                     if ('summary' === $n->tagName && !$a->getContent()) {
                         $a->setContent($n->nodeValue);
                     } else {
                         if ('content' === $n->tagName) {
                             $a->setContent($n->nodeValue);
                         } else {
                             if ('link' === $n->tagName) {
                                 $a->setUrl($n->getAttribute('href'));
                             } else {
                                 if ('updated' === $n->tagName) {
                                     $date = $this->parseDate($n->nodeValue);
                                     // check if article is newer than the latest in the database
                                     if ($date <= $latestDate) {
                                         return;
                                     }
                                     $a->setDateCreated($date);
                                     $a->setDateModified($date);
                                 } else {
                                     if ('id' === $n->tagName) {
                                         $a->setGuid(substr($n->nodeValue, strrpos($n->nodeValue, ':')));
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $a->fill();
         array_push($this->_articles, $a);
     }
 }
Пример #2
0
 public function parseWithMinDate($latestDate = null)
 {
     $this->_fead = new Application_Model_Entity_Fead();
     $this->_fead->setType('rss');
     $document = new DOMDocument();
     $document->loadXML($this->_data);
     // version
     //$this->_fead->_version = $document->getElementsByTagName('rss')->item(0)->getAttribute('version');
     foreach ($document->getElementsByTagName('item') as $article) {
         $a = new Application_Model_Entity_Article();
         $a->setFeadId($this->_feadId);
         for ($n = $article->firstChild; $n; $n = $n->nextSibling) {
             if ($n instanceof DOMElement) {
                 if ('title' === $n->tagName) {
                     $a->setTitle($n->nodeValue);
                 } else {
                     if ('description' === $n->tagName) {
                         $a->setContent($n->nodeValue);
                         $preview = strip_tags($a->getContent(), ['p', 'span', 'i']);
                         $length = 255;
                         if ($length < strlen($preview)) {
                             $preview = substr($preview, 0, $length);
                         }
                         $a->setPreview($preview);
                     } else {
                         if ('link' === $n->tagName) {
                             $a->setUrl($n->nodeValue);
                         } else {
                             if ('pubDate' === $n->tagName) {
                                 $date = $this->parseDate($n->nodeValue);
                                 // check if article is newer than the latest in the database
                                 if ($date <= $latestDate) {
                                     return;
                                 }
                                 $a->setDateCreated($date);
                                 $a->setDateModified($date);
                             } else {
                                 if ('guid' === $n->tagName) {
                                     $a->setGuid($n->nodeValue);
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $a->fill();
         array_push($this->_articles, $a);
     }
 }
Пример #3
0
 public function addArticle(Application_Model_Entity_Article $article)
 {
     $border = date('Y-m-d H:i:s', strtotime('-1 day'));
     $result = $this->_db->query('SELECT id FROM ' . $this->_table . ' WHERE feadId=? AND (dateCreated=? OR ' . 'title=? OR content=?) AND dateModified>? ORDER BY dateModified DESC', [$article->getFeadid(), $article->getDateCreated(), $article->getTitle(), $article->getContent(), $border])->fetch();
     if (!$result) {
         $this->_db->insert($this->_table, ['feadId' => $article->getFeadId(), 'title' => $article->getTitle(), 'preview' => $article->getPreview(), 'url' => $article->getUrl(), 'thumb' => $article->getThumb(), 'dateCreated' => $article->getDateCreated(), 'dateModified' => $article->getDate(), 'content' => $article->getContent(), 'guid' => $article->getGuid()]);
     } else {
         $this->_db->update($this->_table, ['feadId' => $article->getFeadId(), 'title' => $article->getTitle(), 'preview' => $article->getPreview(), 'url' => $article->getUrl(), 'dateModified' => $article->getDate(), 'content' => $article->getContent()], $this->_db->quoteInto('id=?', [$result['id']]));
     }
 }