-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalbum_thumbnail.php
335 lines (269 loc) · 7.99 KB
/
album_thumbnail.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<?php
/***************************************************************************
* album_thumbnail.php
* -------------------
* begin : Wednesday, February 05, 2003
* copyright : (C) 2003 Smartor
* email : [email protected]
*
* $Id: album_thumbnail.php,v 2.0.6 2003/03/02 13:44:46 ngoctu Exp $
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
define('IN_PHPBB', true);
$phpbb_root_path = './';
$album_root_path = $phpbb_root_path . 'album_mod/';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_ALBUM);
init_userprefs($userdata);
//
// End session management
//
//
// Get general album information
//
include($album_root_path . 'album_common.'.$phpEx);
// ------------------------------------
// Check the request
// ------------------------------------
if( isset($HTTP_GET_VARS['pic_id']) )
{
$pic_id = intval($HTTP_GET_VARS['pic_id']);
}
else if( isset($HTTP_POST_VARS['pic_id']) )
{
$pic_id = intval($HTTP_POST_VARS['pic_id']);
}
else
{
die('No pics specified');
}
// ------------------------------------
// Get this pic info
// ------------------------------------
$sql = "SELECT *
FROM ". ALBUM_TABLE ."
WHERE pic_id = '$pic_id'";
if( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not query pic information', '', __LINE__, __FILE__, $sql);
}
$thispic = $db->sql_fetchrow($result);
$cat_id = $thispic['pic_cat_id'];
$user_id = $thispic['pic_user_id'];
$pic_filetype = substr($thispic['pic_filename'], strlen($thispic['pic_filename']) - 4, 4);
$pic_filename = $thispic['pic_filename'];
$pic_thumbnail = $thispic['pic_thumbnail'];
if( empty($thispic) or !file_exists(ALBUM_UPLOAD_PATH . $pic_filename) )
{
die($lang['Pic_not_exist']);
}
// ------------------------------------
// Get the current Category Info
// ------------------------------------
if ($cat_id != PERSONAL_GALLERY)
{
$sql = "SELECT *
FROM ". ALBUM_CAT_TABLE ."
WHERE cat_id = '$cat_id'";
if( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not query category information', '', __LINE__, __FILE__, $sql);
}
$thiscat = $db->sql_fetchrow($result);
}
else
{
$thiscat = init_personal_gallery_cat($user_id);
}
if (empty($thiscat))
{
die($lang['Category_not_exist']);
}
// ------------------------------------
// Check the permissions
// ------------------------------------
$album_user_access = album_user_access($cat_id, $thiscat, 1, 0, 0, 0, 0, 0); // VIEW
if ($album_user_access['view'] == 0)
{
die($lang['Not_Authorised']);
}
// ------------------------------------
// Check Pic Approval
// ------------------------------------
if ($userdata['user_level'] != ADMIN)
{
if( ($thiscat['cat_approval'] == ADMIN) or (($thiscat['cat_approval'] == MOD) and !$album_user_access['moderator']) )
{
if ($thispic['pic_approval'] != 1)
{
die($lang['Not_Authorised']);
}
}
}
// ------------------------------------
// Check hotlink
// ------------------------------------
if( ($album_config['hotlink_prevent'] == 1) and (isset($HTTP_SERVER_VARS['HTTP_REFERER'])) )
{
$check_referer = explode('?', $HTTP_SERVER_VARS['HTTP_REFERER']);
$check_referer = trim($check_referer[0]);
$good_referers = array();
if ($album_config['hotlink_allowed'] != '')
{
$good_referers = explode(',', $album_config['hotlink_allowed']);
}
$good_referers[] = $board_config['server_name'] . $board_config['script_path'];
$errored = TRUE;
for ($i = 0; $i < count($good_referers); $i++)
{
$good_referers[$i] = trim($good_referers[$i]);
if( (strstr($check_referer, $good_referers[$i])) and ($good_referers[$i] != '') )
{
$errored = FALSE;
}
}
if ($errored)
{
die($lang['Not_Authorised']);
}
}
/*
+----------------------------------------------------------
| Main work here...
+----------------------------------------------------------
*/
// ------------------------------------
// Send Thumbnail to browser
// ------------------------------------
if( ($pic_filetype != '.jpg') and ($pic_filetype != '.png') )
{
// --------------------------------
// GD does not support GIF so we must SEND a premade No-thumbnail pic then EXIT
// --------------------------------
header('Content-type: image/jpeg');
readfile($images['no_thumbnail']);
exit;
}
else
{
// --------------------------------
// Check thumbnail cache. If cache is available we will SEND & EXIT
// --------------------------------
if( ($album_config['thumbnail_cache'] == 1) and ($pic_thumbnail != '') and file_exists(ALBUM_CACHE_PATH . $pic_thumbnail) )
{
switch ($pic_filetype)
{
case '.jpg':
header('Content-type: image/jpeg');
break;
case '.png':
header('Content-type: image/png');
break;
}
readfile(ALBUM_CACHE_PATH . $pic_thumbnail);
exit;
}
// --------------------------------
// Hmm, cache is empty. Try to re-generate!
// --------------------------------
$pic_size = @getimagesize(ALBUM_UPLOAD_PATH . $pic_filename);
$pic_width = $pic_size[0];
$pic_height = $pic_size[1];
$gd_errored = FALSE;
switch ($pic_filetype)
{
case '.jpg':
$read_function = 'imagecreatefromjpeg';
break;
case '.png':
$read_function = 'imagecreatefrompng';
break;
}
$src = @$read_function(ALBUM_UPLOAD_PATH . $pic_filename);
if (!$src)
{
$gd_errored = TRUE;
$pic_thumbnail = '';
}
else if( ($pic_width > $album_config['thumbnail_size']) or ($pic_height > $album_config['thumbnail_size']) )
{
// ----------------------------
// Resize it
// ----------------------------
if ($pic_width > $pic_height)
{
$thumbnail_width = $album_config['thumbnail_size'];
$thumbnail_height = $album_config['thumbnail_size'] * ($pic_height/$pic_width);
}
else
{
$thumbnail_height = $album_config['thumbnail_size'];
$thumbnail_width = $album_config['thumbnail_size'] * ($pic_width/$pic_height);
}
$thumbnail = ($album_config['gd_version'] == 1) ? @imagecreate($thumbnail_width, $thumbnail_height) : @imagecreatetruecolor($thumbnail_width, $thumbnail_height);
$resize_function = ($album_config['gd_version'] == 1) ? 'imagecopyresized' : 'imagecopyresampled';
@$resize_function($thumbnail, $src, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $pic_width, $pic_height);
}
else
{
$thumbnail = $src;
}
if (!$gd_errored)
{
if ($album_config['thumbnail_cache'] == 1)
{
// ------------------------
// Re-generate successfully. Write it to disk!
// ------------------------
$pic_thumbnail = $pic_filename;
switch ($pic_filetype)
{
case '.jpg':
@imagejpeg($thumbnail, ALBUM_CACHE_PATH . $pic_thumbnail, $album_config['thumbnail_quality']);
break;
case '.png':
@imagepng($thumbnail, ALBUM_CACHE_PATH . $pic_thumbnail);
break;
}
@chmod(ALBUM_CACHE_PATH . $pic_thumbnail, 0777);
}
// ----------------------------
// After write to disk, donot forget to send to browser also
// ----------------------------
switch ($pic_filetype)
{
case '.jpg':
@imagejpeg($thumbnail, '', $album_config['thumbnail_quality']);
break;
case '.png':
@imagepng($thumbnail);
break;
}
exit;
}
else
{
// ----------------------------
// It seems you have not GD installed :(
// ----------------------------
header('Content-type: image/jpeg');
readfile('images/nothumbnail.jpg');
exit;
}
}
// +------------------------------------------------------+
// | Powered by Photo Album 2.x.x (c) 2002-2003 Smartor |
// +------------------------------------------------------+
?>