Example #1
0
 /**
  * Read an item from a SimpleXMLElement.
  *
  * @return	SpoonAtomRSSItem				An instance of SpoonAtomRSSItem
  * @param	SimpleXMLElement $item			The XML-element that represents a single item in the feed.
  */
 public static function readFromXML(SimpleXMLElement $item)
 {
     // get title, id and summary
     $title = (string) $item->title;
     $id = (string) $item->id;
     $summary = (string) $item->summary;
     // create instance
     $rssItem = new SpoonFeedAtomRSSItem($title, $id, $summary);
     // set updated date
     if (isset($item->updated)) {
         $rssItem->setUpdatedDate((int) strtotime($item->updated));
     }
     // add authors
     if (isset($item->author)) {
         foreach ($item->author as $author) {
             // get the values
             $author['name'] = (string) $item->author->name;
             if (isset($item->author->email)) {
                 $author['email'] = (string) $item->author->email;
             }
             if (isset($item->author->uri)) {
                 $author['uri'] = (string) $item->author->uri;
             }
             // set the values
             $rssItem->addAuthor($author);
         }
     }
     // set content
     if (isset($item->content)) {
         $rssItem->setContent((string) $item->content);
     }
     // add links
     if (isset($item->link)) {
         foreach ($item->link as $link) {
             // build link
             $aLink['href'] = $link['href'];
             if (isset($link['rel'])) {
                 $aLink['rel'] = $link['rel'];
             }
             if (isset($link['type'])) {
                 $aLink['type'] = $link['type'];
             }
             if (isset($link['title'])) {
                 $aLink['title'] = $link['title'];
             }
             if (isset($link['hreflang'])) {
                 $aLink['hreflang'] = $link['hreflang'];
             }
             if (isset($link['length'])) {
                 $aLink['length'] = $link['length'];
             }
             // set property
             $rssItem->addLink($aLink);
         }
     }
     // add categories
     if (isset($item->category)) {
         foreach ($item->category as $category) {
             // build category
             $cat['term'] = (string) $category['term'];
             if (isset($category['scheme'])) {
                 $cat['scheme'] = (string) $category['scheme'];
             }
             if (isset($category['label'])) {
                 $cat['label'] = (string) $category['label'];
             }
             // set property
             $rssItem->addCategory($cat);
         }
     }
     // add contributors
     if (isset($item->contributor)) {
         foreach ($item->contributor as $contributor) {
             $name = (string) $contributor['name'];
             $email = isset($contributor['scheme']) ? (string) $contributor['email'] : null;
             $uri = isset($contributor['label']) ? (string) $contributor['uri$contributor'] : null;
             // set property
             $rssItem->addContributor($name, $email, $uri);
         }
     }
     // set publication date
     if (isset($item->published)) {
         $rssItem->setPublicationDate((int) strtotime($item->published));
     }
     // set rights
     if (isset($XML->rights)) {
         $rssItem->setRights((string) $XML->rights);
     }
     return $rssItem;
 }