Commented a bug.
[cocanwiki.git] / scripts / lib / cocanwiki_template.ml
index c647845..a90b614 100644 (file)
@@ -1,7 +1,7 @@
 (* 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.1 2004/10/21 11:42:05 rich Exp $
+ * $Id: cocanwiki_template.ml,v 1.3 2004/11/03 13:36:45 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
@@ -81,17 +81,69 @@ let get_template ?page (dbh : Dbi.connection) hostid filename =
   let template = _get_template filename in
 
   (* Get standard fields concerning this host from the database. *)
-  let sth = dbh#prepare_cached "select theme_css from hosts
-                                 where id = ?" in
+  let sth =
+    dbh#prepare_cached
+      "select h.theme_css, p.name, p.url, h.search_box,
+              h.brand, h.brand_tagline, h.brand_description
+         from hosts h left outer join powered_by p on h.powered_by = p.id
+        where h.id = ?" in
   sth#execute [`Int hostid];
 
-  let theme_css =
+  let theme_css, powered_by_name, powered_by_url, search_box,
+      brand, brand_tagline, brand_description =
     match sth#fetch1 () with
-       [ `Null ] -> "/_css/standard.css"
-      | [ `String file ] -> file
+      | [ a; b; c; d; e; f; g] -> a, b, c, d, e, f, g
+      | _ -> assert false in
+
+  let theme_css =
+    match theme_css with
+      | `Null -> "/_css/standard.css"
+      | `String file -> file
+      | _ -> assert false in
+
+  let powered_by_name, powered_by_url =
+    match powered_by_name, powered_by_url with
+      | `Null, `Null ->
+         let url = "http://sandbox.merjis.com/" in
+         let name = Cocanwiki_version.package ^ " " ^
+                    Cocanwiki_version.version in
+         name, url
+      | `String name, `String url -> name, url
+      | _ -> assert false in
+
+  let search_box = match search_box with `Bool b -> b | _ -> assert false in
+
+  let branding, brand,
+      has_brand_tagline, brand_tagline,
+      has_brand_description, brand_description =
+    match brand with
+      | `Null -> false, "", false, "", false, ""
+      | `String brand ->
+         let has_brand_tagline, brand_tagline =
+           match brand_tagline with
+             | `Null -> false, ""
+             | `String s -> true, s
+             | _ -> assert false in
+         let has_brand_description, brand_description =
+           match brand_description with
+             | `Null -> false, ""
+             | `String s -> true, s
+             | _ -> assert false in
+         true, brand,
+           has_brand_tagline, brand_tagline,
+           has_brand_description, brand_description
       | _ -> assert false in
 
   template#set "theme_css" theme_css;
+  template#set "powered_by_name" powered_by_name;
+  template#set "powered_by_url" powered_by_url;
+  template#conditional "search_box" search_box;
+  template#conditional "branding" branding;
+  template#set "brand" brand;
+  template#conditional "has_brand_tagline" has_brand_tagline;
+  template#set "brand_tagline" brand_tagline;
+  template#conditional "has_brand_description" has_brand_description;
+  template#set "brand_description" brand_description;
 
   (* Site menu. *)
   let sth = dbh#prepare_cached "select url, label, ordering from sitemenu
@@ -120,10 +172,6 @@ let get_template ?page (dbh : Dbi.connection) hostid filename =
 
   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);