Document support for address lookup
[infodrom.org/www.infodrom.org] / Styles / projects.style
1 # Special utilities for projects pages
2 #read "contributors.list"
3
4 # Documentation
5 #
6 # . All contributors are listed in the file 'contributors.list' as
7 #   RFC822-compliant addresses, i.e. "Real Name <email@domain.tld>".
8 #   They will automatically be added into a Contributors box (at max
9 #   <maxcontrib> names, default is 10).
10 #
11 # . There are three boxes that will appear on the right side if the
12 #   environment <projectpg project=foo> will be used:
13 #
14 #   . News (max. <maxnews> items)
15 #   . Download (max. <maxdownload> items)
16 #   . Contributors (max. <maxcontrib> items)
17 #
18 # . The download items will be revers sorted, i.e. the most recent
19 #   appears at the top of the list.
20 #
21 # . The same applies for news boxes and the entire news listing
22 #
23 # . The entire list of contributors it reserved for peoples.wml.  Use
24 #   <contributors> there
25 #
26 # . All news have to be named news-yyyy-mm-dd.wml, otherwise they won't
27 #   get included properly in the listings.  Additionally, the
28 #   headline/subject of an item has to be written in
29 #   <headline>...</headline> and has to be at last one line long, no
30 #   linebreaks are allowed.
31 #
32 # . The entire list of news items is reserved for news.wml.  Please use
33 #   <newslist> there
34 #
35 # . The entire list of ChangeLog entries reserved for changes.wml.
36 #   #Please use <changes> there
37 #
38 # . Since /projects/sysklogd/ was the first project to work on, use it
39 #   as an example.
40
41
42 <define-tag download-dir>download</define-tag>
43
44 <:
45   sub get_news_list
46   {
47     my @news;
48
49     opendir (THIS, ".");
50     @news = reverse (sort (grep (/^news-.*\.wml$/, readdir (THIS))));
51     closedir (THIS);
52     return @news;
53   }
54
55   sub get_news_headline
56   {
57     my $file = shift;
58     my $headline;
59
60     $headline = "";
61     if (open (NEWS, $file)) {
62       while (<NEWS>) {
63         next until (/<headline>(.*)<\/headline>/);
64         $headline = $1;
65         }
66       close (NEWS);
67     }
68     return $headline;
69   }
70
71   sub get_contrib_list
72   {
73     my @contrib;
74
75     open (CONTRIB, "contributors.list"); # Bail out if the file is not there
76     while (<CONTRIB>) {
77       chomp();
78       next if /^\s*#/;
79       next if /^\s*$/;
80       push (@contrib, $_);
81     }
82     close (CONTRIB);
83     return @contrib;
84   }
85
86   sub get_changes_list
87   {
88     my @news;
89
90     opendir (THIS, ".");
91     @news = reverse (sort (grep (/^changes-.*\.wml$/, readdir (THIS))));
92     closedir (THIS);
93     return @news;
94   }
95
96   sub get_changes_date
97   {
98     my $file = shift;
99     my $date;
100
101     $date = "";
102     if (open (F, $file)) {
103       while (<F>) {
104         next until (/<b>Releasedate: (.*)<\/b>/);
105         $date = $1;
106         }
107       close (F);
108     }
109     return $date;
110   }
111 :>
112
113 <define-tag get_tarfiles>
114 <?
115   function get_tarfiles ($dirname)
116   {
117     $file = array ();
118     if (is_dir ($dirname)) {
119       $dir = dir ($dirname);
120       while ($dentry = $dir->read())
121         if ($dentry != "." && $dentry != ".." && is_file ($dirname . "/" . $dentry)
122             && strstr ($dentry, ".tar.") !== false && substr ($dentry, -4, 4) != '.asc')
123           $file[] = $dentry;
124     }
125     return $file;
126   }
127 ?>
128 </define-tag>
129
130 <define-tag get_tarfiles2>
131 <?
132   function get_tarfiles2 ($dirname)
133   {
134     $file = array ();
135     if (is_dir ($dirname)) {
136       $dir = dir ($dirname);
137       while ($dentry = $dir->read()) {
138         if ($dentry != "." && $dentry != ".." && is_file ($dirname . "/" . $dentry)) {
139           $foo = strstr ($dentry, ".tar.");
140           if ($foo) {
141             #$name = substr ($dentry, 0, (strlen ($dentry) - strlen ($foo)));
142             $file[] = $dentry;
143           }
144         }
145       }
146     }
147     return $file;
148   }
149 ?>
150 </define-tag>
151
152 <define-tag get_files>
153 <?
154   function get_files ($dirname, $version)
155   {
156     $file = array ();
157     if (is_dir ($dirname)) {
158       $dir = dir ($dirname);
159       while ($dentry = $dir->read()) {
160         if ($dentry != "." && $dentry != ".." && is_file ($dirname . "/" . $dentry)) {
161           if (preg_match ("/.*-$version\.[^0-9].*/", $dentry)) {
162             $file[] = $dentry;
163           }
164         }
165       }
166     }
167     return $file;
168   }
169 ?>
170 </define-tag>
171
172 # Default: maxcontrib=10
173 #          maxnews=3
174 #          maxdownload=4
175 <define-tag projectpg endtag=required>
176 <preserve project maxcontrib maxnews maxnews keywords>
177 <set-var %attributes>
178
179 <if <get-var title>
180   <set-var title=" -- <get-var title>">
181 >
182 <if <not <get-var maxcontrib>>
183   <set-var maxcontrib=10>
184 >
185 <if <not <get-var maxnews>>
186   <set-var maxnews=3>
187 >
188 <if <not <get-var maxdownload>>
189   <set-var maxdownload=4>
190 >
191
192 <page title="Infodrom Projects -- <get-var project><get-var title>" keywords="<get-var keywords>">
193 <table width=100% class=font cellpadding=0 cellspacing=0 border=0>
194 <tr>
195 <td valign=top align=left><ifont>
196
197 <h1 align=center><get-var project></h1>
198
199 %body
200 <p>&nbsp;</p>
201
202 </ifont></td><td valign=top><img src=<root_prefix>gifs/imgdot-1x1-transp.gif width=3 height=0 alt="">
203 </td><td width=175 valign=top align=right>
204
205 <ifneq <get-var WML_SRC_BASENAME> "news"
206
207 # Only draw a news box if more than 0 news are to be displayed
208 #
209 <ifneq <get-var maxnews> "0"
210
211 <titlebox title=News
212           titlebgcolor=20b705
213           bordercolor=20b705
214           titlecolor=ffffff
215           bgcolor=ffffff>
216 <div class="smallfont padding">
217
218 <:
219   $row = "<b>%s</b> %s <a href=\"news-%s.php\"><span style=\"color: #20b705; text-weight: bold\">more</span></a>";
220   $delim = "<br";
221
222   @news = get_news_list ();
223
224   $i = 0;$printed=0;
225   while ($printed < <get-var maxnews> && $i <= $#news) {
226     print $delim if ($printed > 0);
227     if ($news[$i] ne "<get-var WML_SRC_BASENAME>.wml") {
228       $news[$i] =~ /news-(\d{4}-\d{2}-\d{2})\.wml/;
229       $date = $1;
230       $headline = get_news_headline ($news[$i]);
231       printf $row, $date, $headline, $date;
232       $printed++;
233     }
234     $i++;
235   }
236 :>
237
238 </div>
239
240 </titlebox><p>
241
242 # <ifneq <get-var maxnews> "0"
243 >
244 # <ifneq <get-var WML_SRC_BASENAME> "news"
245 >
246
247 <: if (-r "download.wml" && "<get-var WML_SRC_BASENAME>" ne "download") { :>
248
249 <titlebox title=Download
250           titlebgcolor=20b705
251           bordercolor=20b705
252           titlecolor=ffffff
253           bgcolor=ffffff>
254 <div class="smallfont padding">
255
256 <get_tarfiles>
257 <?
258   $file = get_tarfiles ("<download-dir>");
259   rsort ($file);
260
261   for ($i=0; ($i < count ($file)) && ($i < <get-var maxdownload>); $i++) {
262     # Correct the filename again...
263     $foo = strstr ($file[$i], ".tar.");
264     if ($foo) {
265       $name = substr ($file[$i], 0, (strlen ($file[$i]) - strlen ($foo)));
266       $copy = 0;
267       for ($token = strtok ($name, "-"); strlen ($token); $token = strtok ("-")) {
268         if ($copy) {
269           $version .= "-" . $token;
270         } else {
271           if (preg_match("/^[0-9][0-9a-zA-Z\.:]*/", $token)) {
272             $copy = 1;
273             $version = $token;
274           }
275         }
276       }
277     }
278     printf ("<a href=\"<download-dir>/%s\">Version %s</a> (%d kB)<br>",
279             $file[$i], $version, filesize ("<download-dir>/" . $file[$i]) / 1024);
280   }
281   if (count ($file) == 0) {
282     echo "Nothing to download yet.";
283   }
284 ?>
285 #&nbsp;<a href=download.php>all files</a>
286 </div></titlebox><p>
287
288 <: } :>
289
290 <ifneq <get-var WML_SRC_BASENAME> "people"
291
292 <titlebox title=Contributors
293           titlebgcolor=20b705
294           bordercolor=20b705
295           titlecolor=ffffff
296           bgcolor=ffffff>
297 <div class="smallfont padding">
298 <?
299   $contrib = array();
300 <:
301   @contrib = get_contrib_list ();
302   foreach $c (@contrib) {
303     $c =~ /(.*)\s+<(.*)>/;
304     printf "  \$contrib[] = \"%s\";\n", $1;
305   }
306 :>
307   srand (time ());
308   $ci = array ();
309   $max = <get-var maxcontrib> > count ($contrib) ? count ($contrib) : <get-var maxcontrib>;
310
311   if (count ($contrib) == 1) {
312     $ci[0] = 0;
313   } else {
314     while (count ($ci) < $max) {
315       $r = rand (0, count ($contrib)-1);
316
317       # Filter out already selected items
318       $new = 1;
319       for ($i=0; $i < count ($ci); $i++) {
320         if ($ci[$i] == $r) $new = 0;
321       }
322
323       if ($new) $ci[] = $r;
324     }
325   }
326
327   for ($i=0; $i < count ($ci); $i++) {
328     printf ("%s<br>", $contrib[$ci[$i]]);
329   }
330 ?>
331 </div></titlebox><p>
332
333 # <ifneq <get-var WML_SRC_BASENAME> "people"
334 >
335
336 </td></tr></table>
337
338 </page>
339 <restore project maxcontrib maxnews maxnews keywords>
340 </define-tag>
341
342 <define-tag headline endtag=required>
343 <h3><:
344
345   "<get-var WML_SRC_BASENAME>" =~ /news-(\d{4}-\d{2}-\d{2})/;
346   print $1;
347
348 :>: %body</h3>
349 </define-tag>
350
351 <define-tag contributors>
352
353 <h3>Contributors</h3>
354
355 <em>Alphabetically sorted</em>
356
357 <ul><:
358   $row = "<li><b>%s</b> &lt;%s&gt;<br>";
359
360   @contrib = get_contrib_list ();
361   foreach $c (sort(@contrib)) {
362     if ($c =~ /(.*)\s+<(.*)>/) {
363       $n = $1;
364       $e = $2;
365       $e =~ s/\@/&#64;/;
366       printf $row, $n, $e;
367     } else {
368       printf $row, $c, "";
369     }
370   }
371 :></ul><p>
372 </define-tag>
373
374
375 <define-tag newslist>
376
377 <h3>News Items</h3>
378
379 <:
380 #  $delim = '<line color="XXXXXX">';
381 #  $delim =~ s/XXXXXX/$menucolor/;
382   $delim = "<p>";
383   $row = "<b>%s</b>: %s <a href=\"news-%s.php\"><span style=\"color: #20b705; text-weight: bold\">more</span></a>";
384   
385   @news = get_news_list ();
386
387   $i = 0;
388   while ($i <= $#news) {
389     print $delim if ($i > 0);
390     $news[$i] =~ /news-(\d{4}-\d{2}-\d{2})\.wml/;
391     $date = $1;
392     $headline = get_news_headline ($news[$i]);
393     printf $row, $date, $headline, $date;
394     $i++;
395   }
396
397 :><p>
398 </define-tag>
399
400 <define-tag changes>
401
402 <h3>ChangeLog entries</h3>
403
404 <:
405   $delim = "<p>";
406   $row = "<b>%s</b>: Version %s <a href=\"changes-%s.php\"><span style=\"color: #20b705; text-weight: bold\">more</span></a>";
407   
408   @changes = get_changes_list ();
409
410   $i = 0;
411   while ($i <= $#changes) {
412     print $delim if ($i > 0);
413     $changes[$i] =~ /changes-(.*)\.wml/;
414     $version = $1;
415     $date = get_changes_date ($changes[$i]);
416     printf $row, $date, $version, $version;
417     $i++;
418   }
419
420 :><p>
421 </define-tag>
422
423 <define-tag download>
424
425 #<h3>Download</h3>
426 <get_tarfiles>
427 <get_files>
428 <?
429   $file = get_tarfiles ("<download-dir>");
430   rsort ($file);
431
432   for ($i=0; $i < count ($file); $i++) {
433     $foo = strstr ($file[$i], ".tar.");
434     if ($foo) {
435       $name = substr ($file[$i], 0, (strlen ($file[$i]) - strlen ($foo)));
436       $copy = 0;
437       for ($token = strtok ($name, "-"); strlen ($token); $token = strtok ("-")) {
438         if ($copy) {
439           $version .= "-" . $token;
440         } else {
441           if (preg_match("/^[0-9][0-9a-zA-Z\.:]*/", $token)) {
442             $copy = 1;
443             $version = $token;
444           }
445         }
446       }
447     }
448     printf ("<h3>Version %s</h3>", $version);
449     $files = get_files ("<download-dir>", $version);
450     sort ($files);
451     if (count ($files) > 0) {
452       echo "<ul>";
453       if (is_file ("changes-" . $version . ".php")) {
454         printf ("<li> <a href=\"changes-%s.php\">ChangeLog</a>", $version);
455       }
456       for ($k=0; $k < count ($files); $k++) {
457         printf ("<li> <a href=\"<download-dir>/%s\">%s</a> (%d kB)",
458                 $files[$k], $files[$k], filesize ("<download-dir>/" . $files[$k]) / 1024);
459       }
460       echo "</ul>";
461     }
462
463   }
464   echo "<h3><a href=\"<download-dir>/\">All files</a></h3>";
465
466 ?>
467
468 </define-tag>
469
470 # Only available for changes-*.wml files
471 <define-tag downloadbutton>
472 <:
473   if ("<get-var WML_SRC_BASENAME>" =~ /^changes-(.*)/) {
474     $version = $1;
475     $version =~ s/\./\\./g;
476 :>
477
478 # Should already known because of download box, but the box comes
479 #  later in source
480 <get_tarfiles2>
481 <?
482   $fstr = "<p><b><a href=\"<download-dir>/%s\">Download</a></b><p>";
483   $file = get_tarfiles2 ("<download-dir>");
484
485   for ($i=0; $i < count ($file); $i++) {
486     if (preg_match("/.*-<: print $version; :>\.tar\..*/", $file[$i])) {
487       printf ($fstr, $file[$i]);
488     }
489   }
490 ?>
491 <: } :>
492 </define-tag>
493
494 # Local variables:
495 # mode: indented-text
496 # mode: auto-fill
497 # end: