Monday, November 08, 2010 at 12:05 AM.
system.verbs.builtins.radio.weblog.archive.update
on update () {
<<Changes
<<7/10/02; 9:33:33 PM by JES
<<On MacOS, limit filenames to 31 characters.
<<12/20/01; 1:47:21 AM by JES
<<Use file.writeTextFile instead of file.writeWholeFile to write the files. This fixes the mac type/creator codes and line-endings.
<<12/15/01; 7:21:57 AM by DW
<<Ooops, I forgot to put an <xml> header on the files.
<<12/14/01; 7:08:29 PM by DW
<<Created.
local (startticks = clock.ticks ());
local (xmlheader = "<?xml version=\"1.0\"?>\r");
local (ctcategoriessaved = 0, ctpostssaved = 0, flprefssaved = false);
local (adrdata = radio.weblog.init ());
bundle { //do categories
local (folder = user.radio.prefs.weblogArchiveFolder + "categories" + file.getpathchar (), adrcat);
for adrcat in @adrdata^.categories {
local (flwrite = true);
local (fname = nameOf (adrcat^));
if system.environment.isMac { //limit filename to 31 chars
if sizeOf (fname) > 27 { //27 + 4 for .xml is 31
fname = string.mid (fname, 1, 27)}};
local (f = folder + fname + ".xml");
if file.exists (f) {
if timemodified (adrcat) < file.modified (f) {
flwrite = false}};
if flwrite {
local (localtable, catname = nameof (adrcat^), adrsubtable);
bundle { //fill localtable
new (tabletype, @localtable);
adrsubtable = @localtable.[catname];
adrsubtable^ = adrcat^;
try {delete (@adrsubtable^.flDirty)};
try {delete (@adrsubtable^.rss)};
try {delete (@adrsubtable^.subscribers)}}; //some very old files will have this
msg ("Writing XML version of category \"" + catname + "\".");
local (xmltext = xmlheader + table.tabletoxml (adrsubtable));
file.surefilepath (f);
file.writeTextFile (f, xmltext);
ctcategoriessaved++}}};
bundle { //do prefs
local (f = user.radio.prefs.weblogArchiveFolder + "prefs" + ".xml");
local (adrprefs = @adrdata^.prefs);
local (flwrite = true);
if file.exists (f) {
if timemodified (adrprefs) < file.modified (f) {
flwrite = false}};
if flwrite {
local (prefs = adrprefs^); //work with a copy
bundle { //delete stuff we don't want to save in the XMLization
try {delete (@prefs.lastThemeApplied)};
try {delete (@prefs.manila)};
try {delete (@prefs.template)};
try {delete (@prefs.daytemplate)};
try {delete (@prefs.itemTemplate)};
try {delete (@prefs.ftp)};
try {prefs.mailposting.password = ""}};
local (xmltext = xmlheader + table.tabletoxml (@prefs));
file.surefilepath (f);
file.writewholefile (f, xmltext);
flprefssaved = true}};
bundle { //do posts
local (folder = user.radio.prefs.weblogArchiveFolder + "posts" + file.getpathchar (), adrpost);
for adrpost in @adrdata^.posts {
local (flwrite = true);
local (f = folder + nameof (adrpost^) + ".xml");
if file.exists (f) {
if timemodified (adrpost) < file.modified (f) {
flwrite = false}};
if flwrite {
local (localtable, postname = nameof (adrpost^), adrsubtable);
bundle { //fill localtable
new (tabletype, @localtable);
adrsubtable = @localtable.[postname];
adrsubtable^ = adrpost^;
try {
if sizeof (adrsubtable^.categories) == 0 {
delete (@adrsubtable^.categories)}};
try {table.assign (@adrsubtable^.text, string (adrsubtable^.text))}};
msg ("Writing XML version of post #" + number (postname) + ".");
local (xmltext = xmlheader + table.tabletoxml (adrsubtable));
file.surefilepath (f);
file.writewholefile (f, xmltext);
ctpostssaved++}}};
if user.radio.prefs.flLogWeblogArchive {
if (ctcategoriessaved > 0) or (ctpostssaved > 0) or flprefssaved {
local (htmltext = "");
if ctpostssaved > 0 {
if ctpostssaved == 1 {
htmltext = htmltext + "1 post was archived, "}
else {
htmltext = htmltext + ctpostssaved + " posts were archived, "}};
if ctcategoriessaved > 0 {
if ctcategoriessaved == 1 {
htmltext = htmltext + "1 category was archived, "}
else {
htmltext = htmltext + ctcategoriessaved + " categories were archived, "}};
if flprefssaved {
if sizeof (htmltext) > 0 {
htmltext = htmltext + " and "};
htmltext = htmltext + "the weblog prefs were archived"};
if htmltext endswith ", " {
htmltext = string.mid (htmltext, 1, sizeof (htmltext) - 2)};
htmltext = htmltext + ".";
radio.log.add ("Weblog Archive", htmltext, startticks)}};
msg ("")} //clear the About window
<<bundle //test code
<<update ()
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.