-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.php
203 lines (172 loc) · 8.19 KB
/
queue.php
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
define('USING_SMARTY', true);
define('USING_QUEUEDB', true);
include('common.php');
include($config['paths']['includes']."directorydb.class.php");
// Must be logged in to access the queue
if (!$user)
{
header('Location: '.$config['paths']['baseURL']);
exit;
}
// Must be a moderator to access the queue
else if (!$user['moderator'])
{
header('Location: '.$config['paths']['baseURL']);
exit;
}
// If they submit the form, let's process that
if (sizeof($_POST) > 0)
{
//////////////////////////////////////////
// Read user input
//////////////////////////////////////////
// Queue table primary key value
if (isset($_POST['queueid']))
$input['queueid'] = $_POST['queueid'];
// Message to the user
if (isset($_POST['message']))
$input['message'] = $_POST['message'];
// Action to complete (Accept or Reject)
if (isset($_POST['action']))
$input['action'] = $_POST['action'];
//////////////////////////////////////////
// Process input and generate any errors
//////////////////////////////////////////
$data['queueitem'] = $qdb->Queue_Fetch_ByID($input['queueid']);
header('Content-Type: text/plain');
if ($data['queueitem'])
{
echo "Database entry exists for this item. Contents:\n";
print_r($data['queueitem']);
if (strtolower($input['action']) == 'accept')
{
echo "Action selected was 'accept'.\n";
if (file_exists($config['paths']['tmp'].$data['queueitem']['bzid'].'_'.$data['queueitem']['filename']))
{
$subdir = strtolower(substr($data['queueitem']['uploaderfirstname'], 0, 1).$data['queueitem']['uploaderlastname']);
echo "Subdirectory name for this uploader will be '$subdir'\n";
echo "Final location for file will be: ".$config['paths']['publicDirectory'].$subdir.'/'.$data['queueitem']['filename'];
echo "\n";
echo "Final URL for file will be: ".$config['paths']['publicURL'].$subdir.'/'.$data['queueitem']['filename'];
echo "\n";
// First, make sure our destination directory exists. If not, try to create it
if (is_dir($config['paths']['publicDirectory'].$subdir.'/') || mkdir($config['paths']['publicDirectory'].$subdir.'/')) {
// Attempt to rename the file into this directory
if (rename($config['paths']['tmp'].$data['queueitem']['bzid'].'_'.$data['queueitem']['filename'], $config['paths']['publicDirectory'].$subdir.'/'.$data['queueitem']['filename']))
{
echo "This item was successfully moved into the public directory.\n";
// Prepare the data to be added into the SQLite database
$data['file'] = Array();
$data['file']['filename'] = $data['queueitem']['filename'];
$data['file']['bzid'] = $data['queueitem']['bzid'];
$data['file']['username'] = $data['queueitem']['username'];
$data['file']['ipaddress'] = $data['queueitem']['ipaddress'];
$data['file']['uploaderfirstname'] = $data['queueitem']['uploaderfirstname'];
$data['file']['uploaderlastname'] = $data['queueitem']['uploaderlastname'];
$data['file']['uploaderemail'] = $data['queueitem']['uploaderemail'];
$data['file']['filemd5'] = $data['queueitem']['filemd5'];
$data['file']['authorname'] = $data['queueitem']['authorname'];
if (substr($data['queueitem']['licensename'], 0, 1) == "*")
$data['file']['licensename'] = substr($data['queueitem']['licensename'], 1);
else
$data['file']['licensename'] = $data['queueitem']['licensename'];
$data['file']['licenseurl'] = $data['queueitem']['licenseurl'];
$data['file']['licensetext'] = $data['queueitem']['licensetext'];
$data['file']['moderationmessage'] = $input['message'];
$data['file']['moderator'] = $user['username'];
$dirdb = new DirectoryDB($config['paths']['publicDirectory'].$subdir.'/data.sqlite3');
if ($dirdb->File_Insert($data['file']))
{
if ($qdb->Queue_Delete_ByID($data['queueitem']['queueid']))
{
// Send an email to the upload letting them know their image
// was accepted.
$data['email'] = Array();
$data['email']['username'] = $data['queueitem']['username'];
$data['email']['uploaderfirstname'] = $data['queueitem']['uploaderfirstname'];
$data['email']['uploaderlastname'] = $data['queueitem']['uploaderlastname'];
$data['email']['imageURL'] = $config['paths']['publicURL'].$subdir.'/'.$data['queueitem']['filename'];
$email['body'] = $tpl->fetch('email_approve.tpl');
email($data['queueitem']['uploaderemail'], $config['mail']['fromaddress'], "Image Submission Approved", $email['body']);
}
else
echo "There was an error deleting the MySQL database entry for this item.\n";
}
else
echo "There was an error adding the directory database entry for this item.\n";
}
else
echo "We were unable to rename the file to the destination location.\n";
}
else
{
echo "We were unable to create create the destination directory for this image.\n";
}
}
else
{
echo "Error... The temporary file did not exist.\n";
}
}
else
{
echo "Action selected was 'reject'.\n";
if (!isset($input['message']) || strlen(trim($input['message'])) == 0)
{
echo "When rejecting an image, a message to the user must be specified.\n";
}
else
{
echo "Rejecting image with the following message to the user:\n".$input['message']."\n\n";
// Try to delete the database entry
if ($qdb->Queue_Delete_ByID($data['queueitem']['queueid']))
{
// Send an email to the upload letting them know their image
// was accepted.
$data['email'] = Array();
$data['email']['username'] = $data['queueitem']['username'];
$data['email']['uploaderfirstname'] = $data['queueitem']['uploaderfirstname'];
$data['email']['uploaderlastname'] = $data['queueitem']['uploaderlastname'];
$data['email']['filename'] = $data['queueitem']['filename'];
$data['email']['authorname'] = $data['queueitem']['authorname'];
$data['email']['licensename'] = $data['queueitem']['licensename'];
$data['email']['message'] = $input['message'];
$email['body'] = $tpl->fetch('email_reject.tpl');
email($data['queueitem']['uploaderemail'], $config['mail']['fromaddress'], "Image Submission Rejected", $email['body']);
}
else
echo "There was an error removing the database entry for this item.\n";
// Try to delete the temporary file
if (!unlink($config['paths']['tmp'].$data['queueitem']['bzid'].'_'.$data['queueitem']['filename']))
echo "There was an error removing the temporary file for this item.\n";
}
}
}
else
{
echo "The image specified was not found in the queue.\n";
}
exit;
}
// We'll just be listing the queue
else
{
// Handle data
$data['queue'] = $qdb->Queue_Fetch_All();
if ($data['queue'] && is_array($data['queue']) && sizeof($data['queue']) > 0)
{
foreach ($data['queue'] as &$item)
{
if (substr($item['licensename'], 0, 1) == "*")
$item['licensename'] = "[".$lang['other']."] ".substr($item['licensename'], 1);
}
}
}
$page['title'] = 'Moderation Queue';
$page['javascripts'] = Array('lang.js.php?lang=en', 'util.js', 'queue.js');
// Render the page
$tpl->display('header.tpl');
$tpl->display('queue.tpl');
$tpl->display('footer.tpl');
?>