- let sql = "select id, " ^
- (if is_thumb then "tn_width, tn_height"
- else "width, height") ^
- ", alt, title, longdesc, class
- from images
- where hostid = ? and name = ?" in
- let sth = dbh#prepare_cached sql in
- sth#execute [`Int hostid; `String name];
+ let rows =
+ PGSQL(dbh)
+ "select id, width, height, tn_width, tn_height,
+ alt, title, longdesc, class
+ from images
+ where hostid = $hostid and name = $name" in
+
+ match is_thumb, rows with
+ (* [[image:...]] *)
+ | false, [imageid, width, height, _, _, alt, title, longdesc, clasz]
+ (* [[thumb:...]], but no thumbnail in the database - treat as image *)
+ | true, [imageid, width, height, None, None,
+ alt, title, longdesc, clasz] ->
+ let link = "/_image/" ^ escape_url name in
+
+ "<img src=\"" ^ link ^ "?version=" ^ Int32.to_string imageid ^
+ "\" width=\"" ^
+ Int32.to_string width ^
+ "\" height=\"" ^
+ Int32.to_string height ^
+ "\" alt=\"" ^
+ escape_html_tag alt ^
+ "\"" ^
+ tag "title" title ^
+ tag "longdesc" longdesc ^
+ tag "class" clasz ^
+ "/>"
+
+ (* [[thumb:...]] *)
+ | true, [imageid, _, _, Some tn_width, Some tn_height,
+ alt, title, longdesc, clasz] ->
+ let link = "/_image/" ^ escape_url name in
+ "<a href=\"" ^ link ^ "\">" ^
+ "<img src=\"" ^ link ^ "?version=" ^ Int32.to_string imageid ^
+ "&thumbnail=1" ^
+ "\" width=\"" ^
+ Int32.to_string tn_width ^
+ "\" height=\"" ^
+ Int32.to_string tn_height ^
+ "\" alt=\"" ^
+ escape_html_tag alt ^
+ "\"" ^
+ tag "title" title ^
+ tag "longdesc" longdesc ^
+ tag "class" clasz ^
+ "/>" ^
+ "</a>"