]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/user/fo_voting.pl
added purge method
[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> #
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 );
20
21 BEGIN {
22 my $null = $0; $null =~ s/\\/\//g; # for win :-(
23 $Bin = ($null =~ /^(.*)\/.*$/)? $1 : '.';
24 $Shared = "$Bin/../shared";
25 $Config = "$Bin/config";
26 $Script = ($null =~ /^.*\/(.*)$/)? $1 : $null;
27
28 # my $null = $0;
29 # $Bin = ($null =~ /^(.*)\/.*$/)? $1 : '.';
30 # $Config = "$Bin/../../daten/forum/config";
31 # $Shared = "$Bin/../../cgi-shared";
32 # $Script = ($null =~ /^.*\/(.*)$/)? $1 : $null;
33 }
34
35 # setting umask, remove or comment it, if you don't need
36 #
37 umask 006;
38
39 use lib $Shared;
40 use CGI::Carp qw(fatalsToBrowser);
41
42 use Conf;
43 use Conf::Admin;
44 use Posting::Cache;
45 use Template::Posting;
46
47 use CGI qw(
48 param
49 header
50 remote_addr
51 request_method
52 );
53
54 ################################################################################
55 #
56 # Version check
57 #
58 # last modified:
59 # $Date$ (GMT)
60 # by $Author$
61 #
62 sub VERSION {(q$Revision$ =~ /([\d.]+)\s*$/)[0] or '0.0'}
63
64 my $conf = read_script_conf ($Config, $Shared, $Script);
65
66 my $show = $conf -> {show};
67 my $show_forum = $show -> {Forum};
68 my $show_posting = $show -> {Posting};
69 my $cgi = $show -> {assign} -> {cgi};
70 my $tree = $show -> {assign} -> {thread};
71 my $adminDefault = read_admin_conf ($conf -> {files} -> {adminDefault});
72
73 my $forum_file = $conf -> {files} -> {forum};
74 my $message_path = $conf -> {files} -> {messagePath};
75
76 my $formdata = $show_posting -> {form} -> {data};
77 my $fup = param ($formdata -> {followUp} -> {name}) || '';
78 my $unid = param ($formdata -> {uniqueID} -> {name}) || '';
79 my $voted;
80
81 my ($tid, $mid) = map {$_ || 0} split /;/ => $fup, 2;
82
83 $tid = (defined $tid and $tid=~/(\d+)/)? $1: 0;
84 $mid = (defined $mid and $mid=~/(\d+)/)? $1: 0;
85
86 if ($tid and $mid and $unid) {
87
88 print header(-type => 'text/html');
89
90 my $cache = new Posting::Cache ($conf->{files}->{cachePath});
91 my $hash;
92
93 if ($hash = $cache -> pick ({thread => $tid, posting => $mid})) {
94 unless (exists ($hash->{voteRef}->{$unid})) {
95
96 $voted=1;
97 my $ip = remote_addr;
98 my %iphash = map {
99 $hash->{voteRef}->{$_}->{IP} => $hash->{voteRef}->{$_}->{time}
100 } keys %{$hash->{voteRef}};
101
102 my $time = time;
103
104 unless (exists($iphash{$ip}) and $iphash{$ip}>($time-$adminDefault->{Voting}->{voteLock}*60)) {
105 if (request_method eq 'POST') {
106 $cache -> add_voting (
107 { posting => $mid,
108 thread => $tid,
109 IP => $ip,
110 time => $time,
111 ID => $unid
112 }
113 );# or die $cache->error;
114 }
115 }
116 }
117 }
118
119 print_posting_as_HTML (
120 $message_path,
121 $show_posting -> {templateFile},
122 { assign => $show_posting -> {assign},
123 thread => $tid,
124 posting => $mid,
125 adminDefault => $adminDefault,
126 messages => $conf -> {template} -> {messages},
127 form => $show_posting -> {form},
128 cgi => $cgi,
129 tree => $tree,
130 voted => $voted || '',
131 cachepath => $conf -> {files} -> {cachePath}
132 }
133 );
134 }
135 else {
136 print header(-status => '204 No Response');
137 }
138
139 #
140 #
141 ### end of fo_voting.pl ########################################################

patrick-canterino.de