/** * xmlをRssに変換する * * @param string $src * @return Rss */ public static function parse($src) { if (Tag::setof($rss, $src, "rss")) { $result = new self(); $result->version($rss->inParam("version", "2.0")); if (Tag::setof($channel, $rss->value(), "channel")) { $result->title($channel->f("title.value()")); $result->link($channel->f("link.value()")); $result->description($channel->f("description.value()")); $result->language($channel->f("language.value()")); $result->copyright($channel->f("copyright.value()")); $result->docs($channel->f("docs.value()")); $result->managingEditor($channel->f("managingEditor.value()")); $result->webMaster($channel->f("webMaster.value()")); $result->lastBuildDate($channel->f("lastBuildDate.value()")); $result->pubDate($channel->f("pubDate.value()")); $value = $channel->value(); $result->item = RssItem::parse($value); return $result; } } throw new Exception("no rss"); /*** $src = text(' <rss version="2.0"> <channel> <title>rhaco</title> <link>http://rhaco.org</link> <description>php</description> <language>ja</language> <copyright>rhaco.org</copyright> <docs>hogehoge</docs> <lastBuildDate>2007-10-10T10:10:10+09:00</lastBuildDate> <managingEditor>tokushima</managingEditor> <pubDate>2007-10-10T10:10:10+09:00</pubDate> <webMaster>kazutaka</webMaster> <item> <title>rhaco</title> <link>http://rhaco.org</link> <description>rhaco desc</description> </item> <item> <title>everes</title> <link>http://www.everes.net</link> <description>everes desc</description> </item> </channel> </rss> '); $xml = Rss::parse($src); eq("2.0",$xml->version()); eq("rhaco",$xml->title()); eq("http://rhaco.org",$xml->link()); eq("php",$xml->description()); eq("ja",$xml->language()); eq("rhaco.org",$xml->copyright()); eq("hogehoge",$xml->docs()); eq(1191978610,$xml->lastBuildDate()); eq("Wed, 10 Oct 2007 10:10:10 +0900",$xml->fmLastBuildDate()); eq("tokushima",$xml->managingEditor()); eq(1191978610,$xml->pubDate()); eq("Wed, 10 Oct 2007 10:10:10 +0900",$xml->fmPubDate()); eq("kazutaka",$xml->webMaster()); eq(2,sizeof($xml->item())); */ }
private function SetItemPublicationDate(RssItem $rssItem) { if (isset($this->itemPublicationDateFieldName)) { $fieldValue = $this->dataset->GetFieldValueByName($this->itemPublicationDateFieldName); if (!(is_object($fieldValue) && get_class($fieldValue) == 'SMDateTime')) { $fieldValue = SMDateTime::Parse($fieldValue, '%d-%m-%Y %H:%M:%S'); } $rssItem->SetPublicationDate($fieldValue); } }
protected function getItemString() { $str = parent::getItemString(); if (is_a($this->bbox, "Mapbender_bbox")) { $str .= "<georss:box>" . $this->bbox->min->x . " " . $this->bbox->min->y . " " . $this->bbox->max->x . " " . $this->bbox->max->y . "</georss:box>\n"; } return $str; }
private function GenerateItemRss(RssItem $rssItem) { $result = ''; AddStr($result, '<item>'); AddStr($result, RssUtils::CreateTag('title', StringUtils::EscapeXmlString($rssItem->GetTitle()))); AddStr($result, RssUtils::CreateTag('link', StringUtils::EscapeXmlString($rssItem->GetLink()))); AddStr($result, RssUtils::CreateTag('description', $rssItem->GetDescription(), true)); if ($rssItem->GetPublicationDate() != null) { AddStr($result, RssUtils::CreateTag('pubDate', StringUtils::EscapeXmlString($rssItem->GetPublicationDate()->ToRfc822String()))); } AddStr($result, '</item>'); return $result; }
public function index() { $this->View->setAutorender(false); $site = Config::get('project.url'); $author = Config::get('project.owner'); $Rss = new RssFeed(); $Rss->setTitle(Config::get('project.name')); $Rss->setDescription(Config::get('project.desc')); $Rss->setDate(date('Y-m-d H:i:s', strtotime('-2 day'))); $Rss->setLink($site); $data = array(); foreach ($data as $row) { $Item = new RssItem(); $Item->setTitle('title'); $Item->setDescription('description'); $Item->setDate('2010-12-25 00:00:00'); $Item->setAuthor('no@email.com (' . Config::get('project.owner') . ')'); $Item->setLink(Config::get('project.url')); $Rss->addItem($Item); } echo $Rss->spit(); }