本文整理汇总了PHP中Feed::setLastBuildDate方法的典型用法代码示例。如果您正苦于以下问题:PHP Feed::setLastBuildDate方法的具体用法?PHP Feed::setLastBuildDate怎么用?PHP Feed::setLastBuildDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Feed
的用法示例。
在下文中一共展示了Feed::setLastBuildDate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
public function parse()
{
$this->xml->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
$this->xml->feed->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
$feed = new Feed();
$feed->type = "atom";
$feed->url = $this->url;
$feed->setLastBuildDate((string) $this->xml->updated);
$feed->title = (string) $this->xml->title;
$feed->summary = (string) $this->xml->subtitle;
$links = $this->xml->xpath('atom:link[@rel="alternate"]');
if (!empty($links)) {
$link = $links[0]->attributes();
$feed->link = (string) $link->href;
}
if (!$feed->link) {
$feed->link = $feed->url;
}
// Default link is the URL to the feed itself
foreach ($this->xml->xpath('/atom:feed/atom:entry') as $entry) {
$entry->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
$article = new Article();
$article->guid = (string) $entry->id;
$article->published = 0;
$pubDate = (string) $entry->published;
if (!$pubDate) {
$pubDate = (string) $entry->updated;
}
if ($pubDate) {
if (($timestamp = strtotime($pubDate)) !== false) {
$article->published = $timestamp;
}
}
$article->link_url = null;
$links = $entry->xpath('atom:link[@rel="alternate"]');
if ($links) {
$link = $links[0]->attributes();
$article->link_url = (string) $link->href;
}
// If still no link_url, try first link of any type
if (!$article->link_url) {
$links = $entry->xpath('atom:link');
$link = $links[0]->attributes();
$article->link_url = (string) $link->href;
}
// If a post has no GUID, use its link as a GUID instead
if (!$article->guid) {
$article->guid = $article->link_url;
}
if (!$article->guid) {
continue;
}
if ((string) $entry->content) {
$article->text = (string) $entry->content;
} else {
$article->text = (string) $entry->summary;
}
if (isset($entry->author) && isset($entry->author->name)) {
$article->author = (string) $entry->author->name;
}
$article->title = (string) $entry->title;
$feed->articles[] = $article;
}
return $feed;
}
示例2: parse
public function parse()
{
$feed = new Feed();
$this->xml->channel->registerXPathNamespace('sy', 'http://purl.org/rss/1.0/modules/syndication/');
$feed->type = "rss";
$feed->url = $this->url;
$feed->setLastBuildDate((string) $this->xml->channel->lastBuildDate);
$feed->title = (string) $this->xml->channel->title;
$feed->summary = (string) $this->xml->channel->description;
$feed->link = (string) $this->xml->channel->link;
$sy = $this->xml->channel->children('http://purl.org/rss/1.0/modules/syndication/');
$feed->setUpdateInformation((string) $sy->updatePeriod, (string) $sy->updateFrequency);
if (!$feed->link) {
$feed->link = $feed->url;
}
// Default link is the URL to the feed itself
$rss1 = false;
if ($this->xml->channel->items) {
$rdf = $this->xml->channel->items->children('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
if (count($rdf) > 0) {
$rss1 = true;
}
}
if ($rss1) {
// RSS 1.0
$parent = $this->xml;
} else {
// RSS 2.0 and higher
$parent = $this->xml->channel;
}
foreach ($parent->item as $item) {
$item->registerXPathNamespace('dc', 'http://purl.org/dc/elements/1.1/');
$item->registerXPathNamespace('content', 'http://purl.org/rss/1.0/modules/content/');
$article = new Article();
$article->guid = (string) $item->guid;
$article->published = 0;
if ($rss1) {
$pubDate = (string) current($item->xpath('dc:date'));
} else {
$pubDate = (string) $item->pubDate;
}
if ($pubDate) {
if (($timestamp = strtotime($pubDate)) !== false) {
$article->published = $timestamp;
}
}
$article->link_url = (string) $item->link;
$article->title = (string) $item->title;
$article->author = current($item->xpath('dc:creator'));
// If a post has no GUID, use its link as a GUID instead
if (!$article->guid) {
$article->guid = $article->link_url;
}
if (!$article->guid) {
continue;
}
$encoded = $item->xpath('content:encoded');
if ($encoded) {
$article->text = (string) current($encoded);
} else {
$article->text = (string) $item->description;
}
$feed->articles[] = $article;
}
return $feed;
}