Applied patch from Gerfried Fuchs (Debian blosxom package maintainer)
[matthijs/upstream/blosxom-plugins.git] / general / whoami
1 # Blosxom Plugin: whoami
2 # Author(s): Rael Dornfest <rael@oreilly.com> 
3 #  Modified: Gerfried Fuchs <alfie@ist.org>
4 #      Allows ?user=$whoami::username links to just request that user's entries
5 #      $whoami::fullname is stripped off the GECOS stuff
6 # Version: 2.0b4-5.1
7 # Documentation: See the bottom of this file or type: perldoc whoami
8
9 package whoami;
10
11 # --- Configurable variables -----
12
13 # --------------------------------
14
15 $fullname;
16 $username;
17
18 use File::stat qw();
19 use CGI qw(param);
20
21 sub start {
22   1;
23 }
24
25 sub story {
26   my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
27
28   $username = $fullname = '';
29
30   if ( -e "$blosxom::datadir$path/$filename.$blosxom::file_extension" ) {
31     my @user_info = getpwuid( File::stat::stat("$blosxom::datadir$path/$filename.$blosxom::file_extension")->uid );
32     ($username, $fullname) = ($user_info[0],$user_info[6] =~ m/^([^,]*)/);
33   };
34
35   1;
36 }
37
38 sub filter {
39   my $self = shift;
40   my ($files, $others) = @_;
41   if (param('user')) {
42     foreach (keys %$files) {
43       delete $files->{$_} if getpwuid((stat($_))[4]) ne param('user');
44       }
45   }
46 }
47
48 1;
49
50 __END__
51
52 =head1 NAME
53
54 Blosxom Plug-in: whoami
55
56 =head1 SYNOPSIS
57
58 Populates $whoami::username and $whoami::$fullname with 
59 local username and full name, respectively, for each story.  Useful
60 for group Blosxom blogs. You can also request just the blog entries
61 of a specific username by linking things like
62 $url?user=$whoami::username.
63
64 =head1 VERSION
65
66 2.0b4-5
67
68 Version number coincides with the version of Blosxom with which the 
69 current version was first bundled.
70
71 =head1 AUTHOR
72
73 Rael Dornfest  <rael@oreilly.com>, http://www.raelity.org/
74
75 =head1 SEE ALSO
76
77 Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/
78
79 Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml
80
81 =head1 BUGS
82
83 Address bug reports and comments to the Blosxom mailing list 
84 [http://www.yahoogroups.com/group/blosxom].
85
86 =head1 LICENSE
87
88 Blosxom and this Blosxom Plug-in
89 Copyright 2003, Rael Dornfest 
90
91 Permission is hereby granted, free of charge, to any person obtaining a
92 copy of this software and associated documentation files (the "Software"),
93 to deal in the Software without restriction, including without limitation
94 the rights to use, copy, modify, merge, publish, distribute, sublicense,
95 and/or sell copies of the Software, and to permit persons to whom the
96 Software is furnished to do so, subject to the following conditions:
97
98 The above copyright notice and this permission notice shall be included
99 in all copies or substantial portions of the Software.
100
101 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
102 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
103 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
104 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
105 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
106 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
107 OTHER DEALINGS IN THE SOFTWARE.