When copying a template during site creation, force the hosts.is_template
[cocanwiki.git] / scripts / cocanwiki_template.ml
index 9e267da..9759cd5 100644 (file)
@@ -1,7 +1,22 @@
-(* COCANWIKI scripts.
+(* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki_template.ml,v 1.3 2004/09/08 15:46:52 rich Exp $
+ * $Id: cocanwiki_template.ml,v 1.5 2004/09/09 12:21:22 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 module wraps around the Template library.  It provides caching
  * of templates and fills in standard fields on a host-specific basis.
@@ -25,6 +40,10 @@ let base =
              "(see README file for more details)");
   base
 
+(* The webserver gets restarted regularly enough that this is reasonable. *)
+let { tm_year = year } = gmtime (time ())
+let year = year + 1900
+
 (* Cache of precompiled templates, arranged by full path. *)
 let cache = Hashtbl.create 32
 
@@ -53,6 +72,35 @@ let get_template (dbh : Dbi.connection) hostid filename =
   let template = _get_template filename in
 
   (* Get standard fields concerning this host from the database. *)
-  (* XXX *)
+  let sth = dbh#prepare_cached "select theme_css from hosts
+                                 where id = ?" in
+  sth#execute [`Int hostid];
+
+  let theme_css =
+    match sth#fetch1 () with
+       [ `Null ] -> "/_css/standard.css"
+      | [ `String file ] -> file
+      | _ -> assert false in
+
+  template#set "theme_css" theme_css;
+
+  (* Site menu. *)
+  let sth = dbh#prepare_cached "select url, label, ordering from sitemenu
+                                 where hostid = ? order by ordering" in
+  sth#execute [`Int hostid];
+
+  let table = sth#map (function [`String url; `String label; _] ->
+                        [ "url", Template.VarString url;
+                          "label", Template.VarString label ]
+                        | _ -> assert false) in
+
+  template#table "sitemenu" table;
+
+  (* Wiki version. *)
+  template#set "cocanwiki_package" Cocanwiki_version.package;
+  template#set "cocanwiki_version" Cocanwiki_version.version;
+
+  (* Copyright year. *)
+  template#set "year" (string_of_int year);
 
   template