X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=scripts%2Flib%2Fcocanwiki_template.ml;h=56d2d06adfa6540df727d45e330f1cc151ce429a;hb=d303f75eed3a09bbe2516d9a2a9a4aa9b862ceb3;hp=c64784573544cd98009ae1c1b8b253a864189a13;hpb=20923b33c08fccfca617b21935c4a4f6201593f8;p=cocanwiki.git diff --git a/scripts/lib/cocanwiki_template.ml b/scripts/lib/cocanwiki_template.ml index c647845..56d2d06 100644 --- a/scripts/lib/cocanwiki_template.ml +++ b/scripts/lib/cocanwiki_template.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * 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.6 2006/03/27 16:43:44 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 @@ -77,53 +77,123 @@ let _get_template filename = Hashtbl.replace cache path (template, mtime); template -let get_template ?page (dbh : Dbi.connection) hostid filename = +let get_template ?page dbh 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 - sth#execute [`Int hostid]; - - let theme_css = - match sth#fetch1 () with - [ `Null ] -> "/_css/standard.css" - | [ `String file ] -> file + if hostid > 0l then ( + (* Get standard fields concerning this host from the database. *) + let rows = + PGSQL(dbh) "nullable-results" + "select h.theme_css, p.name, p.url, h.search_box, + h.brand, h.brand_tagline, h.brand_description, + h.pagebug + from hosts h left outer join powered_by p on h.powered_by = p.id + where h.id = $hostid" in + + let theme_css, powered_by_name, powered_by_url, search_box, + brand, brand_tagline, brand_description, pagebug = + match rows with + | [ row ] -> row | _ -> 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 theme_css = + match theme_css with + | None -> "/_css/standard.css" + | Some file -> file in + + let powered_by_name, powered_by_url = + match powered_by_name, powered_by_url with + | None, None -> + let url = "http://sandbox.merjis.com/" in + let name = Cocanwiki_version.package ^ " " ^ + Cocanwiki_version.version in + name, url + | Some name, Some url -> name, url + | _ -> assert false in - let is_homepage = - match page with + let branding, brand, + has_brand_tagline, brand_tagline, + has_brand_description, brand_description = + match brand with + | None -> false, "", false, "", false, "" + | Some brand -> + let has_brand_tagline, brand_tagline = + match brand_tagline with + | None -> false, "" + | Some s -> true, s in + let has_brand_description, brand_description = + match brand_description with + | None -> false, "" + | Some s -> true, s in + true, brand, + has_brand_tagline, brand_tagline, + has_brand_description, brand_description in + + let has_pagebug, pagebug = + match pagebug with + | None -> false, "" + | Some pagebug -> true, pagebug in + + let search_box = match search_box with Some b -> b | _ -> 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; + template#conditional "has_pagebug" has_pagebug; + template#set "pagebug" pagebug; + + (* Site menu. *) + let rows = PGSQL(dbh) + "select url, label, ordering from sitemenu + where hostid = hostid order by ordering" in + + let is_homepage = + match page with | None -> false | Some "index" -> true | _ -> false in - template#conditional "is_homepage" is_homepage; - - let table = sth#map (function [`String url; `String label; _] -> - let is_linked = - match page with - | None -> true - | Some page when page = url -> false - | _ -> true in - let id = id_of_url url in - [ "url", Template.VarString url; - "label", Template.VarString label; - "is_linked", Template.VarConditional is_linked; - "id", Template.VarString id ] - | _ -> assert false) in - - template#table "sitemenu" table; - - (* Wiki version. *) - template#set "cocanwiki_package" Cocanwiki_version.package; - template#set "cocanwiki_version" Cocanwiki_version.version; - + template#conditional "is_homepage" is_homepage; + + let table = List.map + (fun (url, label, _) -> + let is_linked = + match page with + | None -> true + | Some page when page = url -> false + | _ -> true in + let id = id_of_url url in + [ "url", Template.VarString url; + "label", Template.VarString label; + "is_linked", Template.VarConditional is_linked; + "id", Template.VarString id ] + ) rows in + + template#table "sitemenu" table; + ) + else (* if we have no hostid *) ( + template#set "theme_css" "/_css/standard.css"; + template#set "powered_by_name" (Cocanwiki_version.package ^ " " ^ + Cocanwiki_version.version); + template#set "powered_by_url" "http://sandbox.merjis.com/"; + template#conditional "search_box" false; + template#conditional "branding" false; + template#set "brand" ""; + template#conditional "has_brand_tagline" false; + template#set "brand_tagline" ""; + template#conditional "has_brand_description" false; + template#set "brand_description" ""; + template#conditional "has_pagebug" false; + template#set "pagebug" ""; + template#conditional "is_homepage" false; + template#table "sitemenu" []; + ); (* Copyright year. *) template#set "year" (string_of_int year);