Sitemaps!
authorArt Cancro <ajc@citadel.org>
Fri, 10 Sep 2010 22:22:00 +0000 (18:22 -0400)
committerArt Cancro <ajc@citadel.org>
Fri, 10 Sep 2010 22:22:00 +0000 (18:22 -0400)
webcit/Makefile.in
webcit/sitemap.c [new file with mode: 0644]
webcit/webcit.h

index 9189c9096b7c9fe282dbcd6b92e9c30ed9140a78..2b1ba5de4529d60bdf4dc46d57536674c371f27f 100644 (file)
@@ -53,7 +53,7 @@ webcit: webserver.o context_loop.o ical_dezonify.o \
        calendar.o calendar_tools.o calendar_view.o tasks.o event.o smtpqueue.o \
        availability.o iconbar.o crypto.o inetconf.o notes.o wiki.o \
        groupdav_main.o groupdav_get.o groupdav_propfind.o fmt_date.o \
-       groupdav_options.o autocompletion.o gettext.o tabs.o sieve.o \
+       groupdav_options.o autocompletion.o gettext.o tabs.o sieve.o sitemap.o \
        groupdav_delete.o groupdav_put.o http_datestring.o setup_wizard.o \
        downloads.o addressbook_popup.o pushemail.o sysdep.o openid.o \
        decode.o modules_init.o paramhandling.o utils.o \
@@ -69,7 +69,7 @@ webcit: webserver.o context_loop.o ical_dezonify.o \
        summary.o calendar.o calendar_tools.o calendar_view.o tasks.o event.o wiki.o \
        availability.o ical_dezonify.o iconbar.o crypto.o inetconf.o notes.o \
        groupdav_main.o groupdav_get.o groupdav_propfind.o groupdav_delete.o \
-       groupdav_options.o autocompletion.o tabs.o smtpqueue.o sieve.o \
+       groupdav_options.o autocompletion.o tabs.o smtpqueue.o sieve.o sitemap.o \
        groupdav_put.o http_datestring.o setup_wizard.o fmt_date.o modules_init.o \
        gettext.o downloads.o addressbook_popup.o pushemail.o sysdep.o decode.o \
        paramhandling.o utils.o ical_maps.o ical_subst.o static.o feed_generator.o \
diff --git a/webcit/sitemap.c b/webcit/sitemap.c
new file mode 100644 (file)
index 0000000..0bc394b
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * XML sitemap generator
+ *
+ * Copyright (c) 2010 by the citadel.org team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "webcit.h"
+#include "webserver.h"
+
+
+/*
+ * XML sitemap generator -- go through the message list
+ */
+void sitemap_do_messages(void) {
+       wcsession *WCC = WC;
+       int num_msgs = 0;
+       int i;
+       SharedMessageStatus Stat;
+       message_summary *Msg = NULL;
+
+       memset(&Stat, 0, sizeof Stat);
+       Stat.maxload = INT_MAX;
+       Stat.lowest_found = (-1);
+       Stat.highest_found = (-1);
+       num_msgs = load_msg_ptrs("MSGS ALL", &Stat, NULL);
+       if (num_msgs < 1) return;
+
+       for (i=0; i<num_msgs; i+=20) {
+               Msg = GetMessagePtrAt(i, WCC->summ);
+               if (Msg != NULL) {
+                       wc_printf("<url><loc>%s/readfwd", ChrPtr(site_prefix));
+                       wc_printf("?gotofirst=");
+                       urlescputs(ChrPtr(WC->CurRoom.name));
+                       wc_printf("?start_reading_at=%ld", Msg->msgnum);
+                       wc_printf("</loc></url>\r\n");
+               }
+       }
+}
+
+
+/*
+ * Entry point for RSS feed generator
+ */
+void sitemap(void) {
+
+       output_headers(0, 0, 0, 0, 1, 0);
+       hprintf("Content-type: text/xml\r\n");
+       hprintf(
+               "Server: %s / %s\r\n"
+               "Connection: close\r\n"
+       ,
+               PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software)
+       );
+       begin_burst();
+
+       wc_printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
+       wc_printf("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\r\n");
+
+       HashList *roomlist = GetRoomListHashLKRA(NULL, NULL);
+       HashPos *it = GetNewHashPos(roomlist, 0);
+       long HKlen;
+       const char *HashKey;
+       folder *room;
+
+       while (GetNextHashPos(roomlist, it, &HKlen, &HashKey, (void *)&room))
+       {
+               /* Output the messages in this room only if it's a message board */
+               if (room->defview == VIEW_BBS)
+               {
+                       gotoroom(room->name);
+                       sitemap_do_messages();
+               }
+       }
+
+       DeleteHashPos(&it);
+       DeleteHash(&roomlist);
+
+       wc_printf("</urlset>\r\n");
+       wDumpContent(0);
+}
+
+
+void 
+InitModule_SITEMAP
+(void)
+{
+       WebcitAddUrlHandler(HKEY("sitemap"), "", 0, sitemap, ANONYMOUS|COOKIEUNNEEDED);
+}
index 054ed3000f78e1744a2dd22bbc557a844c335fb8..6b3de478d879568b783b2a26b214b1f8be254775 100644 (file)
@@ -809,6 +809,7 @@ long guess_calhourformat(void);
 int get_time_format_cached (void);
 const char *get_selected_language(void);
 void display_wiki_pagelist(void);
+HashList *GetRoomListHashLKRA(StrBuf *Target, WCTemplputParams *TP);
 
 #define DATEFMT_FULL 0
 #define DATEFMT_BRIEF 1