예제 #1
0
 private function parseItem()
 {
     $item = new NewsItem();
     while ($this->reader->read()) {
         if ($this->reader->nodeType == XMLReader::END_ELEMENT && $this->reader->name == 'item') {
             if ($item->getTitle() == $item->desc) {
                 $item->desc = '';
             }
             $this->items[] = $item;
             return;
         }
         if ($this->reader->nodeType != XMLReader::ELEMENT) {
             continue;
         }
         $key = strtolower($this->reader->name);
         switch ($key) {
             case 'title':
                 $item->setTitle(trim($this->reader->readValue()));
                 break;
             case 'description':
                 $item->desc = trim($this->reader->readValue());
                 break;
             case 'content:encoded':
                 // XXX non standard tag
                 $item->body = trim($this->reader->readValue());
                 break;
             case 'author':
             case 'dc:creator':
                 // XXX non standard tag
                 $item->author = $this->reader->readValue();
                 break;
             case 'link':
                 $url = $this->reader->readValue();
                 $item->setUrl(trim(self::FixUrl($url)));
                 break;
             case 'pubdate':
             case 'dc:date':
                 // XXX non standard tag, <dc:date>2012-02-01 05:50:00</dc:date>
                 $item->setTimestamp($this->reader->readValue());
                 break;
             case 'guid':
                 $item->guid = $this->reader->readValue();
                 break;
             case 'category':
                 $item->category = $this->reader->readValue();
                 break;
             default:
                 if (in_array($key, $this->ext_tags)) {
                     $this->pluginParseTag($key, $item);
                 } else {
                     // echo 'unknown item entry ' .$this->reader->name.ln();
                 }
                 break;
         }
     }
     $this->items[] = $item;
 }