1 (* COCANWIKI - a wiki written in Objective CAML.
2 * Written by Richard W.M. Jones <rich@merjis.com>.
3 * Copyright (C) 2004 Merjis Ltd.
4 * $Id: rss.ml,v 1.2 2004/10/04 15:19:56 rich Exp $
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * This generates an RSS feed from a page. Articles in the RSS feed are
24 * mapped to sections in the page. At the moment it's fairly crude, but
25 * it's good enough for blogging at the moment. We can think about
26 * cleaning it up later.
35 open Cocanwiki_template
37 let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} _ =
38 let template = get_template dbh hostid "rss.xml" in
40 let page = q#param "page" in
41 let page = if page = "" then "index" else page in
42 template#set "page" page;
44 template#set "hostname" hostname;
46 (* Get the title and description of the page. *)
47 let sth = dbh#prepare_cached "select id, title, description
49 where hostid = ? and url = ?
50 and redirect is null" in
51 sth#execute [`Int hostid; `String page];
53 let pageid, title, description =
54 match sth#fetch1 () with
55 [ `Int id; `String title; `String description ] ->
56 id, title, description
57 | _ -> assert false in
59 template#set "title" title;
60 template#set "description" description;
62 (* Get the sections in the live page. *)
63 let sth = dbh#prepare_cached "select sectionname, content, ordering
66 and sectionname is not null
68 sth#execute [`Int pageid];
71 sth#map (function [`String sectionname; `String content; _] ->
73 | _ -> assert false) in
76 List.map (fun (sectionname, content) ->
77 let content = Wikilib.xhtml_of_content dbh hostid content in
78 let linkname = linkname_of_sectionname sectionname in
79 [ "sectionname", Template.VarString sectionname;
80 "linkname", Template.VarString linkname;
81 "content", Template.VarString content ]
84 template#table "sections" sections;
86 q#template ~content_type:"text/xml" template
89 register_script ~restrict:[CanView] run