Thursday, March 17, 2011 at 10:04 AM.
scripting2Suite.server.setupMacrosTable
on setupMacrosTable (username, adrtable) {
<<Changes
<<3/17/11; 9:08:54 AM by DW
<<t.baseurl has the wrong value. Instead of computing it here, we're now just using the value determined by scripting2Suite.server.getBaseUrl.
<<6/26/10; 10:19:04 PM by DW
<<We can't use the urls that are stored in the stats table because we need to build the HTML before we build the RSS file and the blogroll and other stuff we can link to from the HTML. So instead, we compute the URLs in buildUrlFromPath.
<<6/15/10; 8:57:20 AM by DW
<<Add a mini XML icon to the blogroll rendering, links to the OPML of the blogroll.
<<6/14/10; 4:33:18 PM by DW
<<Define <%urlBlogroll%>.
<<6/14/10; 7:19:20 AM by DW
<<Change <%whenLastUpdate%> to include day of week, and the long version of the date.
<<6/13/10; 7:08:16 PM by DW
<<Define <%urlStoryTemplate%> and <%urlHomeTemplate%>.
<<6/6/10; 7:18:32 AM by DW
<<There are at least two different kinds of pages on a scripting2 blog, stories pages and the main page. They have *many* common elements, but each have the need to customize the table of generated texadrtable^. These initializations set up the common elements.
local (adrsystemdata = scripting2suite.init (), now = clock.now ());
local (adrdata = scripting2suite.inituser (username));
local (baseurl = scripting2Suite.server.getBaseUrl (username));
adrtable^.year = date.year ();
adrtable^.crumbTrail = "";
adrtable^.now = now;
adrtable^.programName = frontier.getprogramname ();
on buildUrlFromPath (path) { //6/26/10 by DW
if path beginswith "/" {
path = string.delete (path, 1, 1)};
return (baseurl + path)};
<<old code
<<if not (path beginswith "/")
<<path = "/" + path
<<if adrdata^.prefs.ftp.enabled
<<local (url = adrdata^.prefs.ftp.url)
<<if url endswith "/"
<<url = string.mid (url, 1, sizeof (url) - 1)
<<return (url + path)
<<else
<<return (adrsystemdata^.prefs.ftp.baseurl + username + path)
adrtable^.urlRSS = buildUrlFromPath (scripting2Suite.data.paths.rss); //adrdata^.stats.urlRSS
adrtable^.urlBlogroll = buildUrlFromPath (scripting2Suite.data.paths.blogroll); //adrdata^.stats.urlBlogroll
adrtable^.urlRecentStories = buildUrlFromPath (scripting2Suite.data.paths.recentStories); //adrdata^.stats.urlRecentStories
adrtable^.urlLiveBlogFeed = buildUrlFromPath (scripting2Suite.data.paths.liveBlogFeed); //6/27/10 by DW
bundle { //define links to the text versions of the templates, 6/13/10 by DW
on gettextlink (url) {
return (string.popsuffix (url) + ".txt")};
adrtable^.urlStoryTemplate = gettextlink (adrdata^.stats.urlStoryTemplate);
adrtable^.urlHomeTemplate = gettextlink (adrdata^.stats.urlHomeTemplate)};
adrtable^.expandCollapseScript = string (scripting2Suite.data.expandCollapse.topOfPageScript);
table.copycontents (@adrdata^.prefs, adrtable);
adrtable^.urlStylesheet = scripting2Suite.server.saveStylesheet (username); //only writes if it changed
bundle { //fix up big objects
on fix (adrobj) {
local (s = string (adrobj^));
try {delete (adrobj)};
adrobj^ = s};
fix (@adrtable^.headerImage);
<<fix (@adrtable^.aboutTheAuthor)
fix (@adrtable^.blogroll)};
bundle { //set disqus code elements
if adrdata^.prefs.flDisqusComments {
on process (s) {
return (string.replaceall (s, "<%shortname%>", adrdata^.prefs.disqusShortName))};
adrtable^.disqusStoryScript = process (string (scripting2Suite.data.disqus.storyPageScript));
adrtable^.disqusBottomPageScript = process (string (scripting2Suite.data.disqus.bottomPageScript))}
else {
adrtable^.disqusStoryScript = "";
adrtable^.disqusBottomPageScript = ""}};
bundle { //set email
local (s = adrtable^.ownerEmail);
s = string.replace (s, "@", " at ");
s = string.replace (s, ".", " dot ");
if sizeof (s) > 0 {
adrtable^.email = "<img src=\"http://images.scripting.com/archiveScriptingCom/2005/10/17/mailto.gif\" width=\"14\" height=\"10\" border=\"0\"alt=\"Mailto icon\"> " + s}
else {
adrtable^.email = ""}};
bundle { //set baseurl, 3/17/11 -- simplified
adrtable^.baseurl = baseurl};
<<if not adrdata^.prefs.ftp.enabled
<<adrtable^.baseurl = adrsystemdata^.prefs.baseurl + username + "/"
<<else
<<adrtable^.baseurl = adrdata^.prefs.ftp.url
bundle { //whenLastUpdate
if defined (adrtable^.whenLastUpdate) {
local (tzn = adrdata^.prefs.timeZoneName);
local (when = scripting2Suite.server.getLocalTime (username, adrtable^.whenLastUpdate));
when = date.longstring (when) + " at " + date.timestring (when, false) + " " + tzn; //6/14/10 by DW
adrtable^.whenLastUpdate = when}};
<<bundle //aboutTheAuthor is expandable
<<local (s = "<p class=\"aboutTheAuthor\">" + adrtable^.aboutTheAuthor + "</p>")
<<adrtable^.aboutTheAuthor = scripting2Suite.server.makeExpandable ("About the Author", s)
bundle { //blogroll is expandable
local (adrcache = @system.temp.scripting2.server.users.[username].blogrollCache, flbuild = true);
local (adrblogroll = @adrdata^.prefs.blogroll);
if defined (adrcache^) {
if adrcache^.whenLastBuild >= timemodified (adrblogroll) {
adrtable^.blogroll = adrcache^.htmltext;
adrcache^.ctrefs++;
adrcache^.whenLastRef = now;
flbuild = false}};
if flbuild {
local (xmlimg = "<a href=\"" + adrtable^.urlBlogroll + "\">" + string (scripting2Suite.data.html.miniXmlImg) + "</a>");
adrtable^.blogroll = scripting2Suite.server.makeOutlineExpandable (adrblogroll) + "<br />" + xmlImg;
new (tabletype, adrcache);
adrcache^.htmltext = adrtable^.blogroll;
adrcache^.whenLastBuild = now;
adrcache^.ctrefs = 1}}};
bundle { //test code
new (tabletype, @scratchpad.t);
setupMacrosTable ("adam", @scratchpad.t)}
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.