Thursday, March 31, 2011 at 1:05 AM.
river2Suite.opmlBuild
on opmlBuild (title="", adruser=nil) {
<<Changes
<<3/30/11; 7:02:33 AM by DW
<<If adruser is nil, output the feeds in the main feed table. Otherwise output the feeds in the user's feeds table.
<<4/27/10; 9:57:15 AM by DW
<<It was a mistake for us to get adruser from pta -- instead, take it as an optional parameter, so other routines can get the OPML for an individual user without having to mess with pta.
<<4/4/10; 9:30:55 PM by DW
<<Previous change broke the case where we build OPML from doScanNow and pta isn't defined.
<<3/30/10; 3:40:44 PM by DW
<<If pta^.adruser is non-nil, only show the feeds that the user is subscribed to.
<<12/25/09; 6:17:11 PM by DW
<<Encode all the attributes of outline elements.
<<12/25/09; 5:55:52 PM by DW
<<Factored. I need a routine that will just return the OPML text.
<<local (adruser)
<<bundle //set adruser, 4/4/10 by DW
<<try
<<local (pta = html.getpagetableaddress ())
<<adruser = pta^.adruser
<<else
<<adruser = nil
local (adrdata = river2suite.init ());
local (xmltext = "", indentlevel = 0, now = clock.now ());
on add (s) {
xmltext = xmltext + string.filledstring ("\t", indentlevel) + s + "\r"};
on encode (s) {
if system.environment.isMac {
return (xml.entityEncode (latinToMac.macToLatin (s), true))}
else {
return (xml.entityEncode (s, true))}};
add ("<?xml version=\"1.0\"?>");
add ("<opml version=\"2.0\">"); indentlevel++;
bundle { //<head> section
add ("<head>"); indentlevel++;
if title != "" {
add ("<title>" + encode (title) + "</title>")};
<<add ("<dateCreated>" + date.netstandardstring (now) + "</dateCreated>")
add ("</head>"); indentlevel--};
bundle { //<body> section
local (adrfeed);
on addfeed (adrfeed) {
local (language, feedurl = nameof (adrfeed^));
if defined (adrfeed^.feedinfo.language) {
language = adrfeed^.feedinfo.language}
else {
language = "en-US"};
add ("<outline text=\"" + encode (adrfeed^.feedinfo.title) + "\" description=\"" + encode (adrfeed^.feedinfo.description) + "\" htmlUrl=\"" + encode (adrfeed^.feedinfo.link) + "\" language=\"" + language + "\" title=\"" + encode (adrfeed^.feedinfo.title) + "\" type=\"rss\" version=\"RSS2\" xmlUrl=\"" + encode (feedurl) + "\" />")};
on addlist (adrlist) {
local (feedurl = nameof (adrlist^));
add ("<outline text=\"" + encode (adrlist^.listinfo.title) + "\" title=\"" + encode (adrlist^.listinfo.title) + "\" type=\"rss\" version=\"OPML\" xmlUrl=\"" + encode (feedurl) + "\" />")};
add ("<body>"); indentlevel++;
if adruser == nil {
for adrfeed in @adrdata^.feeds {
local (feedurl = nameof (adrfeed^));
if adruser != nil { //3/30/10 by DW
if not defined (adruser^.feeds.[feedurl]) { //user isn't following this feed
continue}};
addfeed (adrfeed)}}
<<if defined (adrfeed^.feedinfo.language)
<<language = adrfeed^.feedinfo.language
<<else
<<language = "en-US"
<<add ("<outline text=\"" + encode (adrfeed^.feedinfo.title) + "\" description=\"" + encode (adrfeed^.feedinfo.description) + "\" htmlUrl=\"" + encode (adrfeed^.feedinfo.link) + "\" language=\"" + language + "\" title=\"" + encode (adrfeed^.feedinfo.title) + "\" type=\"rss\" version=\"RSS2\" xmlUrl=\"" + encode (feedurl) + "\" />")
else {
local (urlfeed, adrfeedtable, adrlisttable);
for adrfeed in @adruser^.feeds {
urlfeed = nameof (adrfeed^);
adrfeedtable = @adrdata^.feeds.[urlfeed];
if defined (adrfeedtable^) {
addfeed (adrfeedtable)}
else {
adrlisttable = @adrdata^.lists.[urlfeed];
if defined (adrlisttable^) {
addlist (adrlisttable)}}}};
add ("</body>"); indentlevel--};
add ("</opml>"); indentlevel--;
return (xmltext)};
bundle { //test code
wp.newtextobject (opmlBuild (), @scratchpad.opmltext)}
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.