public static function importString($string) { $xml = simplexml_load_string($string); if ($xml === false) { return; } if (isset($xml->channel)) { // RSS return RSSFeed::import($xml->channel[0]); } if (isset($xml->entry)) { // Atom return AtomFeed::import($xml); } }
/** * Get DOM node */ public function getNode($document) { $node_name = $this->node_name; if ($this->name_space !== null) { $name = $this->name_space . ':' . $node_name; } $author = $document->createElement($node_name); $author->appendChild(AtomFeed::getTextNode($document, 'name', $this->name, $this->name_space)); if ($this->email !== null) { $author->appendChild(AtomFeed::getTextNode($document, 'email', $this->email, $this->name_space)); } if ($this->uri !== null) { $author->appendChild(AtomFeed::getTextNode($document, 'uri', $this->uri, $this->name_space)); } return $author; }
function format($changes) { global $request; include_once 'lib/RssWriter.php'; $rss = new AtomFeed(); // "channel" is called "feed" in atom $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl'); extract($this->_args); $title = WIKI_NAME; $description = $this->title(); if ($category) { $title = $category; } elseif ($pagematch) { $title = $pagematch; } $feed_props = array('title' => $description, 'link' => array('rel' => "alternate", 'type' => "text/html", 'href' => $rc_url), 'id' => md5($rc_url), 'modified' => Iso8601DateTime(time()), 'generator' => 'PhpWiki-' . PHPWIKI_VERSION, 'tagline' => ''); $rss->feed($feed_props); $first = true; while ($rev = $changes->next()) { // enforce view permission if (mayAccessPage('view', $rev->_pagename)) { $props = $this->item_properties($rev); $rss->addItem($props, false, $this->pageURI($rev)); if ($first) { $this->setValidators($rev); } $first = false; } } $request->discardOutput(); $rss->finish(); //header("Content-Type: application/atom; charset=" . $GLOBALS['charset']); printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION); // Flush errors in comment, otherwise it's invalid XML. global $ErrorManager; if ($errors = $ErrorManager->getPostponedErrorsAsHTML()) { printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors)); } $request->finish(); // NORETURN!!!! }
} // Handle request to delete an entry before we load them all if (isset($_POST['delete_entry']) && strlen($_POST['delete_entry'])) { $del = $_POST['delete_entry']; $dr = new AtomRequest('DELETE', $del, $auth); $dr->exec(); $code = $dr->get_httpcode(); if ($code != 200 && $code != 204) { echo "<script language=\"JavaScript\" type=\"text/javascript\">\n"; echo "<!--\n"; echo "alert('Can\\'t delete that post - you might not have permission to do so.');\n"; echo "// -->\n"; echo "</script>\n"; } } $af = new AtomFeed(urldecode($_REQUEST['f']), $auth); $entries = $af->get_entries(); if (is_array($entries)) { foreach ($entries as $e => $entry) { $link = $entry->get_links('rel', 'service.edit'); $link = $link[0]['href']; $title = trim($entry->get_title('title')); $title = preg_replace('/(<[^>]*>)/is', '', $title); $title = preg_replace('/(<.*>)/sUi', '', $title); $title = preg_replace('/(\\n)/sUi', '', $title); $title_short = substr($title, 0, 45) . (strlen($title) > 45 ? '...' : ''); if ($title == '') { $title = 'No Title (Created: ' . $entry->get_created() . ')'; } echo "<a href=\"javascript:select(" . $e . ", '" . addslashes($title) . "', '" . urlencode($link) . "', '" . urlencode($_REQUEST['f']) . "');\" ondblclick=\"select(" . $e . ", '" . addslashes($title) . "', '" . urlencode($link) . "', '" . urlencode($_REQUEST['f']) . "'); if (confirm_open()) {parent.document.file.submit();}\" id=\"entry" . $e . "\" title=\"" . $title . "\"><img src=\"../../images/files_file.gif\" width=\"19\" height=\"18\" border=\"0\" align=\"absmiddle\" />�" . $title_short . "</a>\n"; }
/** * Get DOM node */ public function getNode($document) { $entry = $document->createElement('entry'); $entry->appendChild(AtomFeed::getTextNode($document, 'title', $this->title)); $entry->appendChild(AtomFeed::getTextNode($document, 'id', $this->id)); $entry->appendChild(AtomFeed::getDateNode($document, 'updated', $this->updated)); if ($this->summary !== null) { $entry->appendChild(AtomFeed::getCDATANode($document, 'summary', $this->summary)); } if ($this->link !== null) { $entry->appendChild($this->link->getNode($document)); } if ($this->published !== null) { $entry->appendChild(AtomFeed::getDateNode($document, 'published', $this->published)); } if ($this->contributor !== null) { $entry->appendChild($this->contributor->getNode($document)); } // add authors foreach ($this->authors as $author) { $entry->appendChild($author->getNode($document)); } if ($this->content !== null) { $entry->appendChild(AtomFeed::getCDATANode($document, 'content', $this->content)); } return $entry; }
<?php require_once 'feeder.php'; $channel = array('title' => 'My Feed', 'author' => 'Proger_XP proger.xp@gmail.com http://proger.i-forge.net', 'description' => 'Just another PHP Feed', 'category' => 'http://example.com Category Label here.', 'category 2' => 'Second Label', 'icon' => '100x20 http://example.com/icon.gif', 'logo' => '121x83 http://example.com/logo.png'); $entries = array(array('title' => 'My first post', 'updated' => strtotime('22 Jan 2011'), 'author' => 'Proger_XP proger.xp@gmail.com', 'content' => 'Thinking about something to write...', 'content html' => 'Thinking about <em>something</em> to write…'), array('title' => 'Another filler', 'updated' => strtotime('23 May 2012'), 'author' => 'Proger_XP proger.xp@gmail.com', 'contributor' => 'Camilo http://camilomm.deviantart.com', 'content html' => 'Why? Because he\'s my friend <img src="smile.png" />')); $feeder = new Feeder(); $feeder->Channel()->SetFromArray($channel); foreach ($entries as $i => $entry) { $feeder->Entry($i, new FeedEntry($entry)); } $output = new AtomFeed(); $output->Output($feeder);
<?php include 'config.php'; include 'lib/atom.class.inc'; include 'classes/jforg_news.php'; include 'functions/jforg_cleanurl.php'; if (in_array($_GET['lang'], $config['languages'])) { $language = $_GET['lang']; } else { die('Language ist nicht bekannt'); } if ($language == 'de') { $news_link = 'neuigkeiten'; } else { $news_link = 'news'; } $news = new jforg_news(); $feed = new AtomFeed('JForg :: Neuigkeiten', 'http://www.jabberfriends.org/de/rss/neuigkeiten.xml', $config['url']); $lastnews = $news->get_latest(10); foreach ($lastnews as $news) { $news_absatz = explode("\n", $news['text']); $feed->addEntry(new Entry($news['title'], $config['url'] . $language . '/' . $news_link . '/' . $news['id'] . '-' . cleanurl($news['title']) . '.htm', $news['datetime'], $news['datetime'], 'Daniel Gultsch', $news_absatz[0], $news['text'])); } $feed->setEncoding("utf-8"); $feed->generate();
function caldav_get_feed($request, $collection) { global $c, $session; dbg_error_log("feed", "GET method handler"); $collection->NeedPrivilege(array('DAV::read')); if (!$collection->Exists()) { $request->DoResponse(404, translate("Resource Not Found.")); } if (!$collection->IsCollection() || !$collection->IsCalendar() && !(isset($c->get_includes_subcollections) && $c->get_includes_subcollections)) { $request->DoResponse(405, translate("Feeds are only supported for calendars at present.")); } // Try and pull the answer out of a hat $cache = getCacheInstance(); $cache_ns = 'collection-' . $collection->dav_name(); $cache_key = 'feed' . $session->user_no; $response = $cache->get($cache_ns, $cache_key); if ($response !== false) { return $response; } $principal = $collection->GetProperty('principal'); /** * The CalDAV specification does not define GET on a collection, but typically this is * used as a .ics download for the whole collection, which is what we do also. */ $sql = 'SELECT caldav_data, caldav_type, caldav_data.user_no, caldav_data.dav_name,'; $sql .= ' caldav_data.modified, caldav_data.created, '; $sql .= ' summary, dtstart, dtend, calendar_item.description '; $sql .= ' FROM collection INNER JOIN caldav_data USING(collection_id) INNER JOIN calendar_item USING ( dav_id ) WHERE '; if (isset($c->get_includes_subcollections) && $c->get_includes_subcollections) { $sql .= ' (collection.dav_name ~ :path_match '; $sql .= ' OR collection.collection_id IN (SELECT bound_source_id FROM dav_binding WHERE dav_binding.dav_name ~ :path_match)) '; $params = array(':path_match' => '^' . $request->path); } else { $sql .= ' caldav_data.collection_id = :collection_id '; $params = array(':collection_id' => $collection->resource_id()); } $sql .= ' ORDER BY caldav_data.created DESC'; $sql .= ' LIMIT ' . (isset($c->feed_item_limit) ? $c->feed_item_limit : 15); $qry = new AwlQuery($sql, $params); if (!$qry->Exec("GET", __LINE__, __FILE__)) { $request->DoResponse(500, translate("Database Error")); } /** * Here we are constructing the feed response for this collection, including * the timezones that are referred to by the events we have selected. * Library used: http://framework.zend.com/manual/en/zend.feed.writer.html */ require_once 'AtomFeed.php'; $feed = new AtomFeed(); $feed->setTitle('DAViCal Atom Feed: ' . $collection->GetProperty('displayname')); $url = $c->protocol_server_port . $collection->url(); $url = preg_replace('{/$}', '.ics', $url); $feed->setLink($url); $feed->setFeedLink($c->protocol_server_port_script . $request->path, 'atom'); $feed->addAuthor(array('name' => $principal->GetProperty('displayname'), 'email' => $principal->GetProperty('email'), 'uri' => $c->protocol_server_port . $principal->url())); $feed_description = $collection->GetProperty('description'); if (isset($feed_description) && $feed_description != '') { $feed->setDescription($feed_description); } require_once 'RRule-v2.php'; $need_zones = array(); $timezones = array(); while ($event = $qry->Fetch()) { if ($event->caldav_type != 'VEVENT' && $event->caldav_type != 'VTODO' && $event->caldav_type != 'VJOURNAL') { dbg_error_log('feed', 'Skipping peculiar "%s" component in VCALENDAR', $event->caldav_type); continue; } $is_todo = $event->caldav_type == 'VTODO'; $ical = new vComponent($event->caldav_data); $event_data = $ical->GetComponents('VTIMEZONE', false); $item = $feed->createEntry(); $item->setId($c->protocol_server_port_script . ConstructURL($event->dav_name)); $dt_created = new RepeatRuleDateTime($event->created); $item->setDateCreated($dt_created->epoch()); $dt_modified = new RepeatRuleDateTime($event->modified); $item->setDateModified($dt_modified->epoch()); $summary = $event->summary; $p_title = $summary != '' ? $summary : translate('No summary'); if ($is_todo) { $p_title = "TODO: " . $p_title; } $item->setTitle($p_title); $content = ""; $dt_start = new RepeatRuleDateTime($event->dtstart); if ($dt_start != null) { $p_time = '<strong>' . translate('Time') . ':</strong> ' . strftime(translate('%F %T'), $dt_start->epoch()); $dt_end = new RepeatRuleDateTime($event->dtend); if ($dt_end != null) { $p_time .= ' - ' . ($dt_end->AsDate() == $dt_start->AsDate() ? strftime(translate('%T'), $dt_end->epoch()) : strftime(translate('%F %T'), $dt_end->epoch())); } $content .= $p_time; } $p_location = $event_data[0]->GetProperty('LOCATION'); if ($p_location != null) { $content .= '<br />' . '<strong>' . translate('Location') . '</strong>: ' . hyperlink($p_location->Value()); } $p_attach = $event_data[0]->GetProperty('ATTACH'); if ($p_attach != null) { $content .= '<br />' . '<strong>' . translate('Attachment') . '</strong>: ' . hyperlink($p_attach->Value()); } $p_url = $event_data[0]->GetProperty('URL'); if ($p_url != null) { $content .= '<br />' . '<strong>' . translate('URL') . '</strong>: ' . hyperlink($p_url->Value()); } $p_cat = $event_data[0]->GetProperty('CATEGORIES'); if ($p_cat != null) { $content .= '<br />' . '<strong>' . translate('Categories') . '</strong>: ' . $p_cat->Value(); $categories = explode(',', $p_cat->Value()); foreach ($categories as $category) { $item->addCategory(array('term' => trim($category))); } } $p_description = $event->description; if ($p_description != '') { $content .= '<br />' . '<br />' . '<strong>' . translate('Description') . '</strong>:<br />' . nl2br(hyperlink($p_description)); $item->setDescription($p_description); } $item->setContent($content); $feed->addEntry($item); //break; } $last_modified = new RepeatRuleDateTime($collection->GetProperty('modified')); $feed->setDateModified($last_modified->epoch()); $response = $feed->export('atom'); $cache->set($cache_ns, $cache_key, $response); return $response; }
<?php ini_set('include_path', '.:/so/sites/veseys2/pear/lib:/usr/share/zend/library'); @(include_once 'PackageConfig.php'); if (class_exists('PackageConfig')) { PackageConfig::addPath('/so/packages/pear/pear/Date'); } require_once '../AtomFeed/AtomFeed.php'; require_once 'Date.php'; $feed = new AtomFeed(); $feed->title = 'My test feed'; $feed->addNameSpace('g', 'http://base.google.com/ns/1.0'); $feed->addAuthor(new AtomFeedAuthor('Nick Burka', '*****@*****.**', 'http://www.silverorange.com')); $feed->link = new AtomFeedLink('http://www.silverorange.com', 'self'); $feed->updated = new Date(); for ($i = 0; $i <= 10; $i++) { $entry = new AtomFeedEntry('entry' . $i, 'Entry ' . $i, new Date()); $entry->contributor = new AtomFeedAuthor('Nick Burka', '*****@*****.**', 'http://www.silverorange.com'); $entry->addAuthor(new AtomFeedAuthor('Nick Burka', '*****@*****.**', 'http://www.silverorange.com')); $feed->addEntry($entry); } $feed->display(); header("Content-type: text/xml");
} $status = fclose($handle); return $buffer; } $atom_filename = 'atom.xml'; echo "<h2>News</h2>"; /********************************************************************** CONSTRUCT A FEED OBJECT AND ENTRY OBJECTS FOR ALL AVAILABLE ENTRIES **********************************************************************/ // Collect entries from the cached feed $rfeed = read_atom_xml($atom_filename); if ($rfeed === false) { echo "could not read atom feed\n"; return false; } $feed = new AtomFeed(false, false, $rfeed); // Create objects from all available entries $entries = $feed->get_entries(); $maxdisplay = 2; echo '<h2>Last ' . $maxdisplay . ' Entries</h2>'; $inum = 0; foreach ($entries as $entry) { if (++$inum > $maxdisplay) { break; } $link = $entry->get_links('type', 'text/html'); $link = $link[0]['href']; // Get the title $title = $entry->get_title(); $title = $title['title']; $content = $entry->get_content();
} public function id($value) { $this->params[] = array('name' => 'id', 'value' => $value); } public function summary($value) { $this->params[] = array('name' => 'summary', 'value' => $value, 'attributes' => array('type' => 'html'), 'cdata' => true); } } ///////////////////////////////////////////////////////////////////////////////////////////////////// $contents2 = dbSortedContents(array()); extract($contents2[0]); global $blog; // $atom = new AtomFeed(array('xml:lang' => 'ja')); $atom->title($blog); $atom->link("{$_SERVER['SCRIPT_NAME']}"); $atom->link("{$_SERVER['REQUEST_URI']}", 'self'); $atom->id("{$_SERVER['SCRIPT_NAME']}/feed"); $atom->updated($moddate); $atom->author(array('name' => 'nyankoPress')); $cnt = 0; foreach ($contents2 as $value) { extract($value); $entry = new AtomEntry(); $entry->title($title); $entry->link("{$_SERVER['SCRIPT_NAME']}?p={$page}"); $entry->id("{$_SERVER['SCRIPT_NAME']}/p{$page}"); $entry->summary(mb_strimwidth(strip_tags($contents), 0, 80, '…', 'utf-8')); $entry->updated($moddate);