]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/user/fo_voting.pl
fixed the "strict subs" error
[selfforum.git] / selfforum-cgi / user / fo_voting.pl
1 #!/usr/bin/perl -w
2
3 ################################################################################
4 # #
5 # File: user/fo_voting.pl #
6 # #
7 # Authors: André Malo <nd@o3media.de>, 2001-04-23 #
8 # #
9 # Description: vote a posting, return the posting view #
10 # #
11 ################################################################################
12
13 use strict;
14 use vars qw(
15 $Bin
16 $Shared
17 $Script
18 $Config
19 $VERSION
20 );
21
22 BEGIN {
23 my $null = $0; $null =~ s/\\/\//g; # for win :-(
24 $Bin = ($null =~ /^(.*)\/.*$/)? $1 : '.';
25 $Shared = "$Bin/../shared";
26 $Config = "$Bin/config";
27 $Script = ($null =~ /^.*\/(.*)$/)? $1 : $null;
28
29 # my $null = $0;
30 # $Bin = ($null =~ /^(.*)\/.*$/)? $1 : '.';
31 # $Config = "$Bin/../../daten/forum/config";
32 # $Shared = "$Bin/../../cgi-shared";
33 # $Script = ($null =~ /^.*\/(.*)$/)? $1 : $null;
34 }
35
36 # setting umask, remove or comment it, if you don't need
37 #
38 umask 006;
39
40 use lib $Shared;
41 use CGI::Carp qw(fatalsToBrowser);
42
43 use Conf;
44 use Conf::Admin;
45 use Posting::Cache;
46 use Template::Posting;
47
48 use CGI qw(param header remote_addr request_method);
49
50 # Version check
51 #
52 $VERSION = do { my @r =(q$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
53
54 my $conf = read_script_conf ($Config, $Shared, $Script);
55
56 my $show = $conf -> {show};
57 my $show_forum = $show -> {Forum};
58 my $show_posting = $show -> {Posting};
59 my $cgi = $show -> {assign} -> {cgi};
60 my $tree = $show -> {assign} -> {thread};
61 my $adminDefault = read_admin_conf ($conf -> {files} -> {adminDefault});
62
63 my $forum_file = $conf -> {files} -> {forum};
64 my $message_path = $conf -> {files} -> {messagePath};
65
66 my $formdata = $show_posting -> {form} -> {data};
67 my $fup = param ($formdata -> {followUp} -> {name}) || '';
68 my $unid = param ($formdata -> {uniqueID} -> {name}) || '';
69 my $voted;
70
71 my ($tid, $mid) = map {$_ || 0} split /;/ => $fup, 2;
72
73 $tid = (defined $tid and $tid=~/(\d+)/)? $1: 0;
74 $mid = (defined $mid and $mid=~/(\d+)/)? $1: 0;
75
76 if ($tid and $mid and $unid) {
77
78 print header(-type => 'text/html');
79
80 my $cache = new Posting::Cache ($conf->{files}->{cachePath});
81 my $hash;
82
83 if ($hash = $cache -> pick ({thread => $tid, posting => $mid})) {
84 unless (exists ($hash->{voteRef}->{$unid})) {
85
86 $voted=1;
87 my $ip = remote_addr;
88 my %iphash = map {
89 $hash->{voteRef}->{$_}->{IP} => $hash->{voteRef}->{$_}->{time}
90 } keys %{$hash->{voteRef}};
91
92 my $time = time;
93
94 unless (exists($iphash{$ip}) and $iphash{$ip}>($time-$adminDefault->{Voting}->{voteLock}*60)) {
95 if (request_method eq 'POST') {
96 $cache -> add_voting (
97 { posting => $mid,
98 thread => $tid,
99 IP => $ip,
100 time => $time,
101 ID => $unid
102 }
103 );# or die $cache->error;
104 }
105 }
106 }
107 }
108
109 print_posting_as_HTML (
110 $message_path,
111 $show_posting -> {templateFile},
112 { assign => $show_posting -> {assign},
113 thread => $tid,
114 posting => $mid,
115 adminDefault => $adminDefault,
116 messages => $conf -> {template} -> {messages},
117 form => $show_posting -> {form},
118 cgi => $cgi,
119 tree => $tree,
120 voted => $voted || '',
121 cachepath => $conf -> {files} -> {cachePath}
122 }
123 );
124 }
125 else {
126 print header(-status => '204 No Response');
127 }
128
129 #
130 #
131 ### end of fo_voting.pl ########################################################

patrick-canterino.de