1 # =====================================================================
2 # groupRecentLinks.awk: W-TW group recent-links applet.
3 #
4 # Copyright (c) 2007,2008,2009,2010 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 pages.
26
27 fmt = readfmt("tw-recent-links")
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_name = _rcget("tbl_group.g_name")
60 g_uri = _rcget("tbl_group.g_uri")
61
62 e[0] = _NULL
63
64 print "" # documentation.
65 }
66
67 /^\001/ { next } # skip table header, if any.
68
69 {
70
71 # Note that while I use 'vtime' for the 'recent-pages' and the
72 # 'recent-headlines' views, I prefer to use 'ctime' here as I think
73 # it makes more sense with this type of view.
74
75 # p_name, p_ctime, p_modip, p_creau, p_descr, p_uri, p_vtime
76
77 split($0,a,"\t")
78
79 # Exclude hidden pages from this view. Note that this is now done
80 # directly by 'updatePage' before the input list is fed into this
81 # script, so that we always get the configured no. of entries on
82 # output even after skipping hidden/redirected pages (although
83 # restricted pages are still included, as explained in 'updatePage').
84 #
85 #if (a[5] ~ /^ *-/) next
86
87 # Remove any redirection URL from visible description.
88 sub(/ *\(:redirect .*/,_NULL,a[5])
89
90 # Set default description if unset.
91 if (a[5] == "") a[5] = g_name "/" a[1]
92
93 # By default, only display about 30 chars of visible link title,
94 # or it may overflow the side-bar where these things are usually
95 # placed.
96
97 if (!(tmp=ENVIRON["TNS_RECENT_LINKS_WIDTH"])) tmp = 23
98
99 if (substr(a[5],tmp) != "") dots = " ..."
100 else dots = ""
101
102 e[1] = ENVIRON["CSA_RPC_URI"] "/" ENVIRON["CSA_LANG"] "/" g_uri "/" a[6]
103 e[2] = _xmlencode(substr(a[5],1,tmp-1) dots)
104 printf(fmt,e[f[1]],e[f[2]])
105 }
106
107 # EOF