-
Notifications
You must be signed in to change notification settings - Fork 0
/
photos.pl
executable file
·189 lines (139 loc) · 4.38 KB
/
photos.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/perl
use lib "lib";
use strict;
use template2;
use Profiles;
use photos;
use Image::Magick;
use CM_Tags;
use List::Util qw(first);
use points;
use CONFIG;
my $photoDir = "$staticPath/photos";
my $tmp = "$tempPath";
# main
{
my $P = Profiles->new();
# if (!verify(\%user)) {
# exit;
# }
if ($P->{command} eq "") {
default($P);
} elsif ($P->{command} eq "/minipicker") {
minipicker($P);
} elsif ($P->{command} eq "/picked") {
picked($P);
} elsif ($P->{command} eq "/upload") {
upload($P);
}
}
sub default {
my ($P) = @_;
my ($sql,$sth,$count);
$sql = "SELECT * FROM photos WHERE userId=$P->{user}{user}{id} order by timestamp desc;";
$sth = $P->{dbh}->prepare($sql);
$sth->execute;
while (my $photo = $sth->fetchrow_hashref) {
$photo->{place} = $count + 1;
if ($photo->{rank} <= 5) {
%{ $P->{user}{'photo'. $photo->{rank} } }= %{$photo};
$photo->{selected} = 'selected';
}
push(@{ $P->{user}{photos}},{photo => $photo});
}
$P->{user}{photo}{incontest} = $P->{dbh}->selectrow_array("SELECT COUNT(*) FROM photo_contest c, photo_contest_entry e WHERE e.contestId=c.id AND c.itson=1 AND e.userId=?",undef,$P->{user}{user}{id}) || 0;
print $P->Header();
print processTemplate($P->{user},"settings/photos.html");
}
sub minipicker {
my ($P) = @_;
my $show = $P->{query}->param('show') || 5;
my $offset = $P->{query}->param('offset') || 0;
if ($offset < 0) { $offset = 0; }
my ($sql,$sth,$count);
$sql = "SELECT count(1) FROM photos WHERE userId=$P->{user}{user}{id}";
$sth = $P->{dbh}->prepare($sql);
$sth->execute;
my $count = $sth->fetchrow;
$sth->finish;
$sql = "SELECT * FROM photos WHERE userId=$P->{user}{user}{id} order by timestamp desc limit $offset,$show;";
$sth = $P->{dbh}->prepare($sql);
$sth->execute;
my $shown = 0;
while (my $photo = $sth->fetchrow_hashref) {
push(@{$P->{user}{photos}},{photo => $photo});
$shown++;
}
if ($count > ($offset+$shown)) {
$P->{user}{page}{more} = $offset + $shown;
}
if ($offset > 0) {
my $less =$offset - $show;
$less = 0 if ($less < 0);
$P->{user}{page}{less} = $less;
}
my $mode = $P->{query}->param('mode');
print $P->Header();
if ($mode eq "" || $mode eq "qow") {
print processTemplate($P->{user},"play/photopicker/questions.html",1);
} elsif ($mode eq "photocontest") {
print processTemplate($P->{user},"play/photopicker/photos.html",1);
}
}
sub picked {
my ($P) = @_;
$P->{user}{photo}{id} = $P->{query}->param('id');
$P->{user}{page}{contest} = $P->{query}->param('contest');
$P->{user}{page}{remind} = $P->{query}->param('remind');
$P->{user}{entry}{ups} = $P->{query}->param('ups');
$P->{user}{entry}{downs} = $P->{query}->param('downs');
my $mode = $P->{query}->param('mode');
print $P->Header();
if ($mode eq "" || $mode eq "qow") {
print processTemplate($P->{user},"play/photopicker/questions.picked.html",1);
} elsif ($mode eq "photocontest") {
print processTemplate($P->{user},"play/photopicker/photos.picked.html",1);
}
}
sub upload {
my ($P) = @_;
my $userId = $P->{user}{user}{id};
my $imageId = savePhoto($P->{query},$P->{user}{user}{id},$P->{dbh});
if ($imageId != 0) {
if (0) {
my $Points = points->new(dbh => $P->{dbh}, cache => $P->{cache});
if ($P->{user}{user}{firstUpload} ne "Y") {
my $sql = "UPDATE users SET firstUpload='Y',points=points+1 WHERE id=$P->{user}{user}{id}";
$P->{dbh}->do($sql);
my $msg = "Your account has been credited <b>1 point</b> for uploading your first photo!";
$Points->storeTransaction({
userid => $P->{user}{user}{id},
points => $Points->{system}{firstupload},
type => 'system',
desc => "$Points->{system}{firstupload}{desc}"
}
);
} else {
my $bin = $Points->getTransactions(userid => $P->{user}{user}{id}, type => 'system');
unless (first {$_ eq $Points->{system}{first5upload}{desc}} @$bin) {
$Points->storeTransaction({
userid => $P->{user}{user}{id},
points => $Points->{system}{first5upload},
type => 'system',
desc => "$Points->{system}{first5upload}{desc}"
}
);
}
}
}
my $mode = $P->{query}->param('mode') || "normal";
if ($mode eq "normal") {
print $P->{query}->redirect("/photos.pl?saved=1");
} elsif ($mode eq "minipicker") {
print $P->{query}->redirect("/photos.pl/picked?id=$imageId");
}
} else {
print $P->Header();
print "There was a problem uploading your photo.";
}
}