Example #1
0
 /**
  * @param string $source
  * @return array
  */
 public function parse($source)
 {
     $this->_initialize($source);
     $result = array();
     $rows = $this->_xpath->query(static::XPATH_ROWS);
     foreach ($rows as $row) {
         $item = new RssItem();
         $item->setTitle(preg_replace(static::REGEX_EXTRA_TRIM, '', trim($this->_xpath->query(static::XPATH_TITLE, $row)->item(0)->nodeValue)));
         $description = $this->_xpath->query(static::XPATH_DESCRIPTION, $row)->item(0);
         $url = sprintf(static::MASK_FULL_URL, static::BASE_DOMAIN, trim($description->attributes->getNamedItem(static::ATTRIBUTE_HREF)->nodeValue));
         $item->setUrl($url);
         $item->setGUID($url);
         $item->setDescription(trim($description->nodeValue));
         $result[] = $item;
     }
     return $result;
 }
 protected function _createMockRssItem()
 {
     $item = new RssItem();
     if (!is_null(static::VALUE_DATE)) {
         $item->setEventDate(\DateTime::createFromFormat(static::FORMAT_DATETIME, static::VALUE_DATE));
     }
     $item->setTitle(static::VALUE_TITLE);
     $item->setUrl(static::VALUE_URL);
     $item->setGUID(static::VALUE_URL);
     $item->setCategory(static::VALUE_CATEGORY);
     $item->setDescription(static::VALUE_DESCRIPTION);
     return $item;
 }
Example #3
0
 /**
  * @param string $source
  * @return array
  */
 public function parse($source)
 {
     $data = json_decode($this->convertEncoding($source), true);
     $result = array();
     if (isset($data['records'])) {
         foreach ($data['records'] as $record) {
             $container = new RssItem();
             $container->setTitle($record[static::INDEX_TITLE]);
             $container->setEventDate(new \DateTime($record[static::INDEX_EVENT_DATE]));
             $container->setDescription($this->parseDescription($record[static::INDEX_CONTENT]));
             $url = $this->prepareUrl($record[static::INDEX_URI]);
             $container->setUrl($url);
             $container->setGUID($url);
             $result[] = $container;
         }
     }
     return $result;
 }
Example #4
0
 /**
  * @param string $source
  * @return array
  */
 public function parse($source)
 {
     $this->_initialize($source);
     $rows = $this->_xpath->query(static::XPATH_ROWS);
     $result = array();
     foreach ($rows as $article) {
         $rssItem = new RssItem();
         $rssItem->setTitle(trim($this->_xpath->query(static::XPATH_TITLE, $article)->item(0)->nodeValue));
         $url = sprintf(static::MASK_FULL_URL, static::BASIC_URL, trim($this->_xpath->query(static::XPATH_URL, $article)->item(0)->attributes->getNamedItem('href')->nodeValue));
         $rssItem->setGUID($url);
         $rssItem->setUrl($url);
         $descriptionNode = $this->_xpath->query(static::XPATH_DESCRIPTION, $article)->item(0);
         $descriptionNode->removeChild($descriptionNode->childNodes->item(1));
         $rssItem->setDescription(trim($descriptionNode->nodeValue));
         $rssItem->setEventDate(new \DateTime($this->_xpath->query(static::XPATH_DATE, $article)->item(0)->nodeValue));
         $result[] = $rssItem;
     }
     return $result;
 }
 /**
  * @param string $source
  * @return mixed
  */
 public function parse($source)
 {
     $this->_initialize($source);
     $result = array();
     $rowsList = $this->_xpath->query(static::XPATH_ROWS);
     foreach ($rowsList as $row) {
         $item = new RssItem();
         $target = $this->_xpath->query(static::XPATH_URL, $row)->item(0);
         $url = sprintf(static::MASK_FULL_URL, static::BASE_DOMAIN, trim($target->attributes->getNamedItem('href')->nodeValue));
         $year = trim($this->_xpath->query(static::XPATH_DATE_YEAR, $row)->item(0)->nodeValue);
         $month = trim($this->_xpath->query(static::XPATH_DATE_MONTH, $row)->item(0)->nodeValue);
         $day = trim($this->_xpath->query(static::XPATH_DATE_DAY, $row)->item(0)->nodeValue);
         $eventDate = \DateTime::createFromFormat(static::FORMAT_DATETIME, sprintf(static::MASK_DATETIME, $year, $month, $day));
         $item->setEventDate($eventDate);
         $item->setTitle(trim($target->nodeValue));
         $item->setUrl($url);
         $item->setGUID($url);
         $item->setCategory(trim($this->_xpath->query(static::XPATH_CATEGORY, $row)->item(0)->nodeValue));
         $result[] = $item;
     }
     return $result;
 }