1 # =====================================================================
2 # groupRecentHeadlines.awk: W-TW group recent-headlines 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 fmt1=fmt2=""; delete a; delete b; delete c
24 delete e; delete f1; delete f2
25
26 # work-out the format of each page header.
27 fmt1 = readfmt("tw-page-header")
28 gsub(/%/,"%%",fmt1) # turn plain '%' into '%%'.
29 gsub(/\\/,"\\\\&",fmt1) # turn '\' into '\\'.
30 gsub(/[\n\r]+/,"",fmt1) # just in case.
31 tmp = fmt1
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-5 ]+$/) tmp = "1 2 3 4 5"
37
38 # pad missing arg specs with "0".
39 if ((i=split(tmp,f1," ")) < 5) {
40 while (i++ <= 5) tmp = tmp " 0"
41 i = split(tmp,f1," ")
42 }
43
44 tmp = _NULL
45
46 for (j=1; j<=i; j++) {
47 if (j > 5) break # ignore excess arg specs.
48 if (!sub(//,"%s",fmt1)) fmt1 = fmt1 ""
49 tmp = tmp " " f1[j]
50 }
51
52 # encode any extra markers.
53 gsub(//,"\\<tw:s/\\>",fmt1)
54
55 fmt1 = fmt1 "\n"
56
57 split(_strip(tmp),f1," "); f1[0] = 0
58
59 # work-out the format of each page footer.
60 fmt2 = readfmt("tw-page-footer")
61 gsub(/%/,"%%",fmt2) # turn plain '%' into '%%'.
62 gsub(/\\/,"\\\\&",fmt2) # turn '\' into '\\'.
63 gsub(/[\n\r]+/,"",fmt2) # just in case.
64 tmp = fmt2
65
66 # Handle custom positioning of output tokens.
67 sub(/.*\[:/,_NULL,tmp); sub(/:].*/,_NULL,tmp)
68 tmp = _strip(tmp,_O_MIDDLE)
69 if (tmp !~ /^[0-2 ]+$/) tmp = "1 2"
70
71 # pad missing arg specs with "0".
72 if ((i=split(tmp,f2," ")) < 2) {
73 while (i++ <= 2) tmp = tmp " 0"
74 i = split(tmp,f2," ")
75 }
76
77 tmp = _NULL
78
79 for (j=1; j<=i; j++) {
80 if (j > 2) break # ignore excess arg specs.
81 if (!sub(//,"%s",fmt2)) fmt2 = fmt2 ""
82 tmp = tmp " " f2[j]
83 }
84
85 # encode any extra markers.
86 gsub(//, "\\<tw:s/\\>",fmt2)
87
88 fmt2 = fmt2 "\n"
89
90 split(_strip(tmp),f2," "); f2[0] = 0
91
92 g_uri = _rcget("tbl_group.g_uri")
93
94 url = ENVIRON["CSA_RPC_URI"] "/" ENVIRON["CSA_LANG"] "/"
95
96 e[0] = _NULL
97 }
98
99 /^\001/ { next } # skip table header, if any.
100
101 {
102 # Process each input record in turn, setting the proper
103 # headers/footers along the way.
104
105 # k_page, p_vtime, p_name, p_modau, p_uri, p_descr, p_etime
106
107 split($0,a,"\t") # split each record into fields.
108
109 # Exclude hidden pages from this view. Note that this is now done
110 # directly by 'updatePage' before the input list is fed into this
111 # script, so that we always get the configured no. of entries on
112 # output even after skipping hidden/redirected pages (although
113 # restricted pages are still included, as explained in 'updatePage').
114 #
115 #if (a[6] ~ /^ *-/) next
116
117 if (a[4] != _NULL) ftr = a[4]
118 else ftr = _nlsmap(_NULL,"anonymous")
119
120 # strip ranking.
121 sub(/^.*,/,"",a[2])
122
123 # page header.
124
125 tmp = a[2]
126 gsub(/ /,"T",tmp)
127 gsub(/:/,"_",tmp)
128 tmp = tmp "." ENVIRON["CSA_RID"]
129 tmp = _xmlencode(tmp "." NR)
130
131 split(_localdate(a[2],1),b," "); sub(/:..$/,"",b[2])
132
133 split(_localdate(a[7],1),c," "); sub(/:..$/,"",c[2])
134
135 # Remove any redirection URL from visible description.
136 sub(/ *\+*\(:redirect .*/,_NULL,a[6])
137
138 if (a[6] == _NULL) a[6] = a[3] # default description
139
140 e[1] = tmp
141 e[2] = b[1]
142 e[3] = b[2]
143 e[4] = c[1]
144 e[5] = c[2]
145
146 # print header.
147 printf(fmt1,e[f1[1]],e[f1[2]],e[f1[3]],e[f1[4]],e[f1[5]])
148
149 print _xmlencode(a[6]) # print excerpt.
150
151 e[1] = _xmlencode(ftr)
152 e[2] = url g_uri "/" a[5]
153 printf(fmt2,e[f2[1]],e[f2[2]]) # print footer.
154
155 }
156
157 # EOF