like.pl
Copying Source is Forbidden
147 lines of code
1
#!/usr/local/bin/perl
2
3
($<,$>) = (getpwnam('nobody'), getpwnam('nobody')) or die $!;
4
5
binmode(STDIN, ":utf8");
6
binmode(STDOUT, ":utf8");
7
8
# must have's!
9
use strict;
10
use warnings;
11
use CGI::Carp qw(fatalsToBrowser);
12
use DBI;
13
use URI::Escape;
14
15
use lib "/var/www/html/Pm";
16
17
use Html qw(pre_html_header header html_end debug_banner);
18
use Html2 qw(tag br hr);
19
use Bc_chef qw(cookie_get);
20
use Bc_misc qw(get_param referrer get_params_asHash);
21
use Bc_sql qw(
22
get_constant
23
Bc_sql::sql_execute
24
user_exists
25
26
$QUERY_PAGE
27
$QUERY_UID
28
$LOGGEDIN
29
30
$DB
31
);
32
33
use Security qw(banned); Security::count_hits();
34
35
use Redir qw(error_redir notice_redir);
36
37
#######################################
38
# add your own USE statements here
39
40
use Likes qw(like liked dislike disliked);
41
use User qw(
42
isUserSuperAdmin
43
isUserAdmin
44
);
45
46
# end of your USE statements
47
#######################################
48
49
my $DEBUG = 0;
50
my $DEBUG_STR = "";
51
52
my %params = get_params_asHash();
53
54
my $output;
55
56
if (not user_exists($LOGGEDIN) or banned($LOGGEDIN)) {
57
my $msg = "Access Denied";
58
if ($DEBUG) { $msg .= " (like.pl)"; }
59
$output = error_redir("/", $msg);
60
} else {
61
############################################################
62
### YOUR CONTENT HERE
63
$output = pre_html_header();
64
$output .= header(
65
"Like",
66
"?nobg_img=1&nogrid=1",
67
0,
68
"setTimeout(removeMsg, " . get_constant("REMOVE_MSG_TIMEOUT") . ");",
69
"",
70
"style=\"padding: 2px;\""
71
);
72
73
if (isUserSuperAdmin() or isUserAdmin()) {
74
$DEBUG_STR .= "You are an admin, or super admin" . br;
75
} else {
76
$DEBUG_STR .= "You are NOT an admin, or super admin" . br;
77
}
78
79
# first, does the image asked for exist within the DB
80
my $imgchksql = "select * from images where ID=" . $DB->quote($params{id});
81
$DEBUG_STR .= $imgchksql . br();
82
my $imgchk = Bc_sql::sql_execute($imgchksql, "", 1);
83
84
if (@$imgchk) {
85
$DEBUG_STR .= "image exists!" . br;
86
87
# now, check if the image is being liked, or disliked
88
$DEBUG_STR .= "Function: ";
89
if ($params{dislike}) {
90
$DEBUG_STR .= "Dislike" . br;
91
92
if (disliked($params{id})) {
93
$DEBUG_STR .= "Image is Disliked" . br;
94
} else {
95
$DEBUG_STR .= "Image is NOT Disliked" . br;
96
}
97
if (liked($params{id})) { $DEBUG_STR .= "but it is liked!" . br; }
98
99
if (not $DEBUG) {
100
# admins, and superadmins will have features here
101
dislike($params{id});
102
103
print notice_redir(referrer(), "Liked/Disliked");
104
exit 1;
105
} else {
106
$DEBUG_STR .= "no update made" . br;
107
}
108
109
###########################
110
} # end if $params{dislike}
111
###########################
112
else {
113
114
$DEBUG_STR .= "Like" . br;
115
116
if (liked($params{id})) {
117
$DEBUG_STR .= "Image is Liked" . br;
118
} else {
119
$DEBUG_STR .= "Image is NOT Liked" . br;
120
if (disliked($params{id})) { $DEBUG_STR .= "but it is disliked!" . br; }
121
}
122
123
if (not $DEBUG) {
124
like($params{id});
125
126
print notice_redir(referrer(), "Liked/Disliked");
127
exit 1;
128
} else {
129
$DEBUG_STR .= "no update made" . br;
130
}
131
} # end else of if $params{dislike}
132
} else {
133
$DEBUG_STR .= "image does NOT exist!" . br;
134
}
135
136
if ($DEBUG) {
137
$output .= debug_banner("like.pl", $DEBUG_STR, 1);
138
}
139
140
### END YOUR CONTENT
141
$output .= html_end();
142
############################################################
143
}
144
145
print $output;
146
147
exit 1;