private function parseEntry() { $item = new NewsItem(); while ($this->reader->read()) { if ($this->reader->nodeType == \XMLReader::END_ELEMENT && $this->reader->name == 'entry') { if ($item->title == $item->desc) { $item->desc = ''; } $this->items[] = $item; return; } if ($this->reader->nodeType != \XMLReader::ELEMENT) { continue; } switch (strtolower($this->reader->name)) { case 'title': $this->reader->read(); $item->title = html_entity_decode($this->reader->value, ENT_QUOTES, 'UTF-8'); break; case 'summary': $this->reader->read(); $item->desc = html_entity_decode($this->reader->value, ENT_QUOTES, 'UTF-8'); break; case 'content': $this->reader->read(); $item->body = html_entity_decode($this->reader->value, ENT_QUOTES, 'UTF-8'); break; case 'updated': $this->reader->read(); $item->setTimestamp($this->reader->value); break; case 'name': ///XXX :hack to avoid 2-level parsing of <author><name>Sveriges Radio</name></author> $this->reader->read(); $item->author = html_entity_decode($this->reader->value, ENT_QUOTES, 'UTF-8'); break; case 'id': $this->reader->read(); $item->guid = $this->reader->value; break; case 'link': switch ($this->reader->getAttribute('rel')) { case 'alternate': $item->setUrl($this->reader->getAttribute('href')); break; case 'enclosure': switch ($this->reader->getAttribute('type')) { case 'video/x-flv': case 'video/quicktime': $item->video_url = $this->reader->getAttribute('href'); $item->video_mime = $this->reader->getAttribute('type'); if ($this->reader->getAttribute('length')) { $this->duration = $this->reader->getAttribute('length'); } break; case 'image/jpeg': $item->image_url = $this->reader->getAttribute('href'); $item->image_mime = $this->reader->getAttribute('type'); break; default: throw new \Exception('unknown enclosure mime: ' . $this->reader->getAttribute('type')); } break; case 'image': switch ($this->reader->getAttribute('type')) { case 'image/png': $img = new ImageResource(); $img->setUrl($this->reader->getAttribute('href')); $img->setMimetype($this->reader->getAttribute('type')); $item->addMedia($img); break; default: throw new \Exception('unknown image mime: ' . $this->reader->getAttribute('type')); } break; case 'replies': //FIXME: handle break; case 'edit': //XXX ??? //XXX ??? case 'self': //XXX ??? //XXX ??? case '': // no "rel" attribute exists break; default: d($item); throw new \Exception('unknown link type: ' . $this->reader->getAttribute('rel')); } break; default: // echo 'unknown entry entry: '.$this->reader->name.ln(); break; } } }