]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/user/fo_voting.pl
added version check
[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 );
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; #$null =~ s/\\/\//g; # for win :-(
29 # $Bin = ($null =~ /^(.*)\/.*$/)? $1 : '.';
30 # $Config = "$Bin/../../../cgi-config/devforum";
31 # $Shared = "$Bin/../../../cgi-shared";
32 # $Script = ($null =~ /^.*\/(.*)$/)? $1 : $null;
33 }
34
35 use lib $Shared;
36 use CGI::Carp qw(fatalsToBrowser);
37
38 use Conf;
39 use Conf::Admin;
40 use Posting::Cache;
41 use Template::Posting;
42
43 use CGI qw(param header remote_addr);
44
45 print header(-type => 'text/html');
46
47 my $conf = read_script_conf ($Config, $Shared, $Script);
48
49 my $show = $conf -> {show};
50 my $show_forum = $show -> {Forum};
51 my $show_posting = $show -> {Posting};
52 my $cgi = $show -> {assign} -> {cgi};
53 my $tree = $show -> {assign} -> {thread};
54 my $adminDefault = read_admin_conf ($conf -> {files} -> {adminDefault});
55
56 my $forum_file = $conf -> {files} -> {forum};
57 my $message_path = $conf -> {files} -> {messagePath};
58
59 my $formdata = $show_posting -> {form} -> {data};
60 my $fup = param ($formdata -> {followUp} -> {name}) || '';
61 my $unid = param ($formdata -> {uniqueID} -> {name}) || '';
62 my $voted;
63
64 my ($tid, $mid) = map {$_ || 0} split /;/ => $fup, 2;
65
66 $tid = ($tid=~/(\d+)/)[0] || 0;
67 $mid = ($mid=~/(\d+)/)[0] || 0;
68
69 my $cache = new Posting::Cache ($conf->{files}->{cachePath});
70 my $hash;
71
72 if ($hash = $cache -> pick ({thread => $tid, posting => $mid})) {
73 unless (exists ($hash->{voteRef}->{$unid})) {
74
75 $voted=1;
76 my $ip = remote_addr;
77 my %iphash = map {
78 $hash->{voteRef}->{$_}->{IP} => $hash->{voteRef}->{$_}->{time}
79 } keys %{$hash->{voteRef}};
80
81 my $time = time;
82
83 unless (exists($iphash{$ip}) and $iphash{$ip}>($time-$adminDefault->{Voting}->{voteLock}*60)) {
84 $cache -> add_voting (
85 { posting => $mid,
86 thread => $tid,
87 IP => $ip,
88 time => $time,
89 ID => $unid
90 }
91 ) or die $cache->error;
92 }
93 }
94 }
95
96 print_posting_as_HTML (
97 $message_path,
98 $show_posting -> {templateFile},
99 { assign => $show_posting -> {assign},
100 thread => $tid,
101 posting => $mid,
102 adminDefault => $adminDefault,
103 messages => $conf -> {template} -> {messages},
104 form => $show_posting -> {form},
105 cgi => $cgi,
106 tree => $tree,
107 voted => $voted || '',
108 cachepath => $conf -> {files} -> {cachePath}
109 }
110 );
111
112 #
113 #
114 ### end of fo_voting.pl ########################################################

patrick-canterino.de