Monday, November 08, 2010 at 12:05 AM.
system.verbs.builtins.radio.weblog.editCategory
on editCategory (bgcolor=radio.data.htmlColors.cellBgColor, hilightBgColor=radio.data.htmlColors.highlightColor) {
<<Changes
<<10/13/02; 2:39:20 AM by JES
<<Localized prompt strings.
<<6/21/02; 2:27:39 PM by JES
<<Fixed broken help link.
<<2/14/01; 1:03:50 PM by JES
<<Fixed a bug where editing a category which has no theme applied, would result in a macro error: "The file "-none- selected.fttb" wasn't found."
<<2/13/02; 11:31:46 PM by JES
<<Maintain the theme sub-table of the category table, when applying or removing a Theme.
<<2/4/02; 6:44:39 PM by JES
<<When applying a Theme to the category folder, make sure the folder exists first. Avoids a file not found macro error.
<<2/4/02; 3:07:08 PM by JES
<<Added a Theme popup, which allows you to use a separate Theme for each category. There's also a -None- option, which clears the Theme templates out of the category's sub-folder.
<<1/28/02; 6:32:25 PM by JES
<<If this is MacOS, convert the category name and description to Mac text, before saving the values.
<<1/21/02; 1:43:53 PM by DW
<<Make notification checkbox work for new categories.
<<1/21/02; 11:59:28 AM by DW
<<New checkbox to send notification to Weblogs.Com when a category that's rendered in HTML has updated.
<<1/20/02; 8:17:17 PM by DW
<<New language popup.
<<1/8/02; 9:20:19 PM by JES
<<Added error handling for the case where the user failed to supply the name for a new category.
<<12/21/01; 12:36:12 PM by JES
<<Changed help link to the Edit Category help page.
<<12/2/01; 11:04:20 PM by JES
<<Changed help link to link to the correct page.
<<1/21/01; 6:03:08 PM by DW
<<Rewrite. Takes no params. If there's a catname attribute we edit an existing category, otherwise it's a new category.
<<1/12/01; 2:21:14 PM by PBS
<<The Submit button appears at the end of the form when editing a category.
<<Link to the RSS file of the category if it exists.
<<1/11/01; 6:24:09 PM by PBS
<<flNew is a new optional parameter. If true, a new category is being created.
<<1/10/01; 4:03:12 PM by PBS
<<Edit a category's attributes.
local (pta = html.getpagetableaddress ());
local (adrdata = radio.weblog.init ());
local (helplink = radio.userInterface.helpLink ("The Categories page"));
local (htmltext = "\r", indentlevel = 0);
on add (s) {
htmltext = htmltext + string.filledstring ("\t", indentlevel) + s + "\r\n"};
local (catname = "", flnewcategory = true, adrcat = nil, referer = "", flrenderhtml = false, errormessage = "");
if pta^.method == "GET" {
local (args);
new (tabletype, @args);
webserver.parseargs (pta^.searchargs, @args);
<<scratchpad.args = args; edit (@scratchpad.args)
if defined (args.catname) {
catname = args.catname;
adrcat = @adrdata^.categories.[catname];
flnewcategory = false};
if defined (args.referer) {
referer = args.referer}};
if pta^.method == "POST" {
local (args);
new (tabletype, @args);
webserver.parseargs (pta^.requestbody, @args);
<<scratchpad.args = args; edit (@scratchpad.args)
on renderCategoryPageIfNeeded (adrcat) {
local (f = radio.weblog.file.getCategoryFolder (nameOf (adrcat^), adrdata) + "index.txt");
if radio.file.locateFileIgnoringExtension (f, @f) {
radio.weblog.publish (adrdata, nameOf (adrcat^))}};
on applyThemeIfNeeded (adrcat, theme) {
if adrcat^.flRenderHtml {
local (catname = nameOf (adrcat^));
local (folder = radio.weblog.file.getCategoryFolder (catname, adrdata));
file.sureFilePath (folder + "xxx");
if args.theme == "-none-" { //remove the Theme files from the folder
on deleteFileIgnoringExtension (fname) {
local (fileToDelete);
if radio.file.locateFileIgnoringExtension (folder + fname, @fileToDelete) {
file.delete (fileToDelete)}};
deleteFileIgnoringExtension ("#template");
deleteFileIgnoringExtension ("#homeTemplate");
deleteFileIgnoringExtension ("#dayTemplate");
deleteFileIgnoringExtension ("#itemTemplate");
deleteFileIgnoringExtension ("#desktopWebsiteTemplate");
if defined (adrcat^.theme) {
delete (@adrcat^.theme)};
local (lastThemeApplied = "-none-");
try {lastThemeApplied = adrcat^.lastThemeApplied};
adrcat^.lastThemeApplied = "-none-";
if adrcat^.lastThemeApplied != lastThemeApplied {
renderCategoryPageIfNeeded (adrcat)}}
else { //apply the theme to the category folder
local (fname = theme + ".fttb");
local (f = radio.theme.getThemesFolder () + fname);
local (theme);
radio.theme.importThemeFile (f, @theme);
radio.theme.apply.main (@theme, folder, @adrcat^.theme);
local (lastThemeApplied = "-none-");
try {lastThemeApplied = adrcat^.lastThemeApplied};
adrcat^.lastThemeApplied = radio.theme.getShortName (theme.info.name);
if adrcat^.lastThemeApplied != lastThemeApplied {
renderCategoryPageIfNeeded (adrcat)}}}};
if args.flnewcategory {
flrenderhtml = defined (args.flRenderHtml);
if args.displayName != "" { //we need a name for the table
local (displayName = args.displayName);
local (description = args.description);
if system.environment.isMac {
displayName = string.latinToMac (displayName);
description = string.latinToMac (description)};
radio.weblog.newCategory (displayName, description, flrenderhtml, args.language, defined (args.flNotify));
adrcat = @adrdata^.categories.[displayName];
applyThemeIfNeeded (adrcat, args.theme)}
else { //error -- there was no name provided
errormessage = radio.string.getLocalizedString ("editCategory.noNameError")}}
else {
catname = args.catname;
adrcat = @adrdata^.categories.[catname];
adrcat^.displayName = args.displayName;
adrcat^.description = args.description;
adrcat^.flRenderHtml = defined (args.flRenderHtml);
adrcat^.language = args.language;
adrcat^.flNotifyWeblogsCom = defined (args.flNotify);
applyThemeIfNeeded (adrcat, args.theme);
flnewcategory = false};
if defined (args.referer) and (errormessage == "") {
radio.webServer.redirect (args.referer);
return (true)}};
bundle { //set flrenderhtml
if adrcat != nil {
if defined (adrcat^.flRenderHtml) {
flrenderhtml = adrcat^.flRenderHtml}}};
bundle { //set the page title, add the intro
if flnewcategory {
pta^.title = radio.string.getlocalizedstring ("editCategory.newCategoryTitle");
add ("<p>" + radio.string.getlocalizedstring ("editCategory.newCategoryIntro") + " " + helplink + "</p>")}
else {
pta^.title = radio.string.getlocalizedstring ("editCategory.editCategoryTitle") + ": " + catname;
add ("<p>" + radio.string.getlocalizedstring ("editCategory.editCategoryIntro") + " " + helplink + "</p>")}};
bundle { //add error message if there was an error
if errormessage != "" {
add ("<p><font color=\"maroon\">" + errormessage + "</font></p>")}};
bundle { //add the form
local (initialname, initialdescription, languagePopup, themePopup);
bundle { //set initialname, initialdescription
if adrcat == nil {
initialname = "";
initialdescription = "";
if pta^.method == "POST" and (errormessage != "") {
try {
initialname = pta^.radioResponder.postArgs.displayName;
initialdescription = pta^.radioResponder.postArgs.description}}}
else {
initialname = adrcat^.displayname;
initialdescription = adrcat^.description}};
bundle { //set languagePopup
local (s = string (radio.data.localization.languages.english.strings.editCategory.languages));
local (defaultLanguage = "\"none\"");
try {defaultLanguage = "\"" + adrcat^.language + "\""};
languagePopup = string.replace (s, defaultLanguage, defaultLanguage + " selected")};
bundle { //set themePopup
local (s = "<select name=\"theme\">\r");
local (defaultTheme = "\"-none-\"");
try {defaultTheme = "\"" + adrcat^.lastThemeApplied + "\""};
s = s + "\t<option value=\"-none-\">- None -";
local (folder = radio.theme.getThemesFolder ());
local (floop);
fileloop (floop in folder) {
try {
local (fname = file.fileFromPath (floop));
if not (string.lower (fname) endsWith ".fttb") {
continue};
local (themeTable);
radio.theme.importThemeFile (floop, @themeTable);
local (adrinfo = @themeTable.info);
local (name = adrinfo^.name);
local (shortname = radio.theme.getShortName (name));
s = s + "\t<option value=\"" + shortname + "\">" + name + "\r";
if defined (adrcat^.lastThemeApplied) {
if adrcat^.lastThemeApplied == shortname {
defaultTheme = "\"" + shortname + "\""}}}};
s = s + "</select>";
themePopup = string.replace (s, defaultTheme, defaultTheme + " selected")};
add ("<form method=\"POST\">"); indentlevel++;
add ("<table cellspacing=\"0\" cellpadding=\"5\">"); indentlevel++;
add ("<tr><td>" + radio.string.getLocalizedString ("editCategory.categoryPrompt") + "</td><td><input name=\"displayName\" size=\"30\" value=\"" + initialname + "\"></td></tr>");
add ("<tr><td valign=\"top\">" + radio.string.getLocalizedString ("editCategory.descriptionPrompt") + "</td><td><textarea name=\"description\" rows=\"7\" cols=\"55\">" + initialdescription + "</textarea></td></tr>");
bundle { //add render html checkbox
local (label = radio.string.getlocalizedstring ("editCategory.checkToRenderHtml"));
if flrenderhtml { //checked
add ("<tr><td colspan=\"2\"><input type=\"checkbox\" name=\"flRenderHtml\" value=\"xxx\" checked> " + label + "</td></tr>")}
else { //unchecked
add ("<tr><td colspan=\"2\"><input type=\"checkbox\" name=\"flRenderHtml\"> " + label + "</td></tr>")}};
bundle { //add Weblogs.Com checkbox
local (fnotify = false);
try {fnotify = adrcat^.flNotifyWeblogsCom};
local (label = radio.string.getlocalizedstring ("editCategory.checkToNotify"));
if fnotify { //checked
add ("<tr><td colspan=\"2\"><input type=\"checkbox\" name=\"flNotify\" value=\"xxx\" checked> " + label + "</td></tr>")}
else { //unchecked
add ("<tr><td colspan=\"2\"><input type=\"checkbox\" name=\"flNotify\"> " + label + "</td></tr>")}};
add ("<tr><td valign=\"top\">" + radio.string.getLocalizedString ("editCategory.themePrompt") + "</td><td>" + themePopup + "</td></tr>");
add ("<tr><td valign=\"top\">" + radio.string.getLocalizedString ("editCategory.languagePrompt") + "</td><td>" + languagePopup + "</td></tr>");
add ("<tr><td colspan=\"2\" valign=\"top\"><br><input type=\"submit\" value=\"" + radio.string.getlocalizedstring ("editCategory.submitButton") + "\"></td></tr>");
add ("</table>"); indentlevel--;
add ("<input type=\"hidden\" name=\"flnewcategory\" value=\"" + flnewcategory + "\">");
add ("<input type=\"hidden\" name=\"catname\" value=\"" + catname + "\">");
add ("<input type=\"hidden\" name=\"referer\" value=\"" + referer + "\">");
add ("</form>"); indentlevel--};
<<bundle //add the recent posts from this category
<<if catname != ""
<<htmltext = htmltext + radio.macros.weblogRecentPosts (adrdata, bgcolor, hilightBgColor, catname)
return (htmltext)}
<<bundle //testing
<<html.setPageTableAddress (@workspace.pt)
<<editCategory ()
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.