1 # =====================================================================
2 # groupCatCloud: W-TW group meta-category cloud applet.
3 #
4 # Copyright (c) 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 tmp=url=fmt=""; i=j=f1=f2=f3=0
24 delete a; delete b; delete t; delete f
25
26 g_uri = _rcget("tbl_group.g_uri")
27 if ((g_descr=_rcget("tbl_group.g_descr")) == _NULL)
28 g_descr = _rcget("tbl_group.g_name")
29 }
30
31 /^\001/ { next } # skip table header, if any.
32
33 {
34 # p_name, p_descr
35
36 split($0,a,"\t")
37 split(a[1],b,".")
38
39 # Pages with nil descriptions and pages not belonging
40 # into a subcat are excluded from this view.
41
42 if (a[2] ~ /^ *-/ || getcat(a[1]) == _NULL) next
43
44 t[++j] = b[1]
45 }
46
47 END {
48
49 if (!j) exit(0) # no subcats.
50
51 # Note: the following algorithm was written based on the following
52 # links:
53 #
54 # http://blog.html.it/archivi/2006/02/20/programmare-una-tag-cloud.php
55 # http://www.petefreitag.com/item/396.cfm
56 #
57 # I'm not at all sure whether I got it right, so I'll keep an eye on
58 # it until it proves itself to be correctly implemented.
59
60 _sort(t,j,1)
61 for (i=1; i<=j; i++) {
62 if (tolower(t[i]) == tmp) {
63 f[t[i]]++
64 if (f[t[i]] > f2) f2 = f[t[i]] # max freq.
65 }
66 else {
67 f[t[i]] = 1
68 tmp = tolower(t[i])
69 }
70 }
71
72 f1 = f2
73
74 for (tmp in f) {
75 # set min freq.
76 if (f[tmp] > ENVIRON["TNS_CAT_FREQ_MIN"] && f[tmp] < f1) f1 = f[tmp]
77 }
78
79 f3 = f2 - f1
80
81 f4 = f3 / 3
82
83 j = _uniq(t,j,1)
84
85 url = ENVIRON["CSA_RPC_URI"] "/" ENVIRON["CSA_LANG"] "/" g_uri "/5"
86
87 gsub(/%/,"%%",url) # needed by printf()
88
89 fmt = readfmt("tw-cat-cloud")
90
91 gsub(/%/,"%%",fmt) # turn plain '%' into '%%'.
92 gsub(/\\/,"\\\\&",fmt) # turn '\' into '\\'.
93 gsub(/[\n\r]+/,"",fmt) # just in case.
94
95 # this format string is currently not customizable.
96 for (i=1; i<=5; i++) {
97 if (!sub(//,"%s",fmt)) fmt = fmt ""
98 }
99
100 # encode any extra markers.
101 gsub(//,"\\<tw:s/\\>",fmt)
102
103 fmt = fmt "\n"
104
105 print "" # documentation.
106
107 for (i=1; i<=j; i++) {
108 value = t[i]
109 tmp = _uriencode(t[i],_O_PATHINFO) "?3=1" # use paging by default.
110 gsub(/_/," ",value)
111 value = _xmlencode(value)
112 tmp1 = value
113 sub(/^[gkM]:/,_NULL,tmp1)
114 if (f[t[i]] == f1)
115 printf(fmt,url "/" tmp,"smallestTag",g_descr,value,tmp1)
116 else if (f[t[i]] == f2)
117 printf(fmt,url "/" tmp,"largestTag",g_descr,value,tmp1)
118 else if (f[t[i]] > (f1 + f4*2))
119 printf(fmt,url "/" tmp,"largeTag",g_descr,value,tmp1)
120 else if (f[t[i]] > (f1 + f4))
121 printf(fmt,url "/" tmp,"mediumTag",g_descr,value,tmp1)
122 else printf(fmt,url "/" tmp,"smallTag",g_descr,value,tmp1)
123 }
124 }
125
126 # EOF