1 # =====================================================================
2 # groupRecentComments.awk: W-TW group recent-comments applet.
3 #
4 # Copyright (c) 2007-2011 Carlo Strozzi
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; version 2 dated June, 1991.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #
19 # =====================================================================
20
21 BEGIN {
22
23 fmt = tmp = ""; delete a; delete e; delete f
24
25 # build links to recent comments.
26
27 fmt = readfmt("tw-recent-comments")
28 gsub(/%/,"%%",fmt) # turn plain '%' into '%%'.
29 gsub(/\\/,"\\\\&",fmt) # turn '\' into '\\'.
30 gsub(/[\n\r]+/,"",fmt) # just in case.
31 tmp = fmt
32
33 # Handle custom positioning of output tokens.
34 sub(/.*\[:/,_NULL,tmp); sub(/:].*/,_NULL,tmp)
35 tmp = _strip(tmp,_O_MIDDLE)
36 if (tmp !~ /^[0-2 ]+$/) tmp = "1 2"
37
38 # pad missing arg specs with "0".
39 if ((i=split(tmp,f," ")) < 2) {
40 while (i++ <= 2) tmp = tmp " 0"
41 i = split(tmp,f," ")
42 }
43
44 tmp = _NULL
45
46 for (j=1; j<=i; j++) {
47 if (j > 2) break # ignore excess arg specs.
48 if (!sub(//,"%s",fmt)) fmt = fmt ""
49 tmp = tmp " " f[j]
50 }
51
52 # encode any extra markers.
53 gsub(//,"\\<tw:s/\\>",fmt)
54
55 fmt = fmt "\n"
56
57 split(_strip(tmp),f," "); f[0] = 0
58
59 g_uri = _rcget("tbl_group.g_uri")
60
61 e[0] = _NULL
62
63 print "" # documentation.
64 }
65
66 /^\001/ { next } # skip table header, if any.
67
68 {
69 split($0,a,"\t")
70
71 # By default, display only about 30 chars of visible link title,
72 # or it may overflow the side-bar where these things are usually
73 # placed. I use the same width config var for all recent links.
74
75 if (!(tmp=ENVIRON["TNS_RECENT_LINKS_WIDTH"])) tmp = 23
76
77 if (substr(a[3],tmp) != "") dots = " ..."
78 else dots = ""
79
80 e[1] = ENVIRON["CSA_RPC_URI"] "/" ENVIRON["CSA_LANG"] "/" g_uri \
81 "/" _uriencode(a[2]) "/comment" "/" _uriencode(a[1])
82 e[2] = _xmlencode(substr(a[3],1,tmp-1) dots)
83
84 printf(fmt,e[f[1]],e[f[2]])
85 }
86
87 # EOF