(* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. * $Id: page_rss.ml,v 1.2 2004/11/02 11:05:59 rich Exp $ * * 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 2 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; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * *--- * * This generates an RSS feed from a page. Articles in the RSS feed are * mapped to sections in the page. At the moment it's fairly crude, but * it's good enough for blogging at the moment. We can think about * cleaning it up later. *) open Apache open Registry open Cgi open Printf open Cocanwiki open Cocanwiki_template let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} _ = let template = get_template dbh hostid "page_rss.xml" in let page = q#param "page" in let page = if page = "" then "index" else page in template#set "page" page; template#set "hostname" hostname; (* Get the title and description of the page. *) let sth = dbh#prepare_cached "select id, title, description from pages where hostid = ? and url = ? and redirect is null" in sth#execute [`Int hostid; `String page]; let pageid, title, description = match sth#fetch1 () with [ `Int id; `String title; `String description ] -> id, title, description | _ -> assert false in template#set "title" title; template#set "description" description; (* Get the sections in the live page. *) let sth = dbh#prepare_cached "select sectionname, content, ordering from contents where pageid = ? and sectionname is not null order by ordering" in sth#execute [`Int pageid]; let sections = sth#map (function [`String sectionname; `String content; _] -> sectionname, content | _ -> assert false) in let sections = List.map (fun (sectionname, content) -> let content = Wikilib.xhtml_of_content dbh hostid content in let linkname = linkname_of_sectionname sectionname in [ "sectionname", Template.VarString sectionname; "linkname", Template.VarString linkname; "content", Template.VarString content ] ) sections in template#table "sections" sections; q#template ~content_type:"application/rss+xml" template let () = register_script ~restrict:[CanView] run