X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;ds=sidebyside;f=scripts%2Fcocanwiki_links.ml;h=9d856d2d7c2a4b25c2239b7e514da4383978dd73;hb=2b332786c6f216c5e2e72cc1596ba4c66b5aa2a4;hp=417fe19ed71b8afd9a75b6a91bb5e9193f8c9539;hpb=eeb304015c65ccf593a77058d5db5f5a3e3b45d5;p=cocanwiki.git diff --git a/scripts/cocanwiki_links.ml b/scripts/cocanwiki_links.ml index 417fe19..9d856d2 100644 --- a/scripts/cocanwiki_links.ml +++ b/scripts/cocanwiki_links.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_links.ml,v 1.1 2004/09/28 10:56:39 rich Exp $ + * $Id: cocanwiki_links.ml,v 1.2 2004/09/28 11:28:39 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 @@ -58,3 +58,41 @@ let get_links_from_section dbh hostid content = (* Return the list of links. *) links + +let insert_link dbh hostid from_url to_url = + if from_url <> to_url then ( + let sth = dbh#prepare_cached "select 1 from links + where hostid = ? + and from_url = ? and to_url = ?" in + sth#execute [`Int hostid; `String from_url; `String to_url]; + + let exists = try sth#fetch1int () = 1 with Not_found -> false in + + if not exists then ( + let sth = + dbh#prepare_cached "insert into links (hostid, from_url, to_url) + values (?, ?, ?)" in + sth#execute [`Int hostid; `String from_url; `String to_url] + ) + ) + +let update_links_for_page dbh hostid page = + (* Delete entries in the old links table. *) + let sth = dbh#prepare_cached "delete from links + where hostid = ? and from_url = ?" in + sth#execute [`Int hostid; `String page]; + + (* Get the sections from the page. *) + let sth = dbh#prepare_cached "select c.content from contents c, pages p + where c.pageid = p.id + and p.hostid = ? + and p.url = ? + and p.redirect is null" in + sth#execute [`Int hostid; `String page]; + + (* Get the links from each section. *) + sth#iter + (function [`String content] -> + let links = get_links_from_section dbh hostid content in + List.iter (insert_link dbh hostid page) links + | _ -> assert false)