-
Notifications
You must be signed in to change notification settings - Fork 1
/
pic_editor.php
407 lines (353 loc) · 14.4 KB
/
pic_editor.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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<?php
/*************************
Coppermine Photo Gallery
************************
Copyright (c) 2003-2016 Coppermine Dev Team
v1.0 originally written by Gregory Demar
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3
as published by the Free Software Foundation.
********************************************
Coppermine version: 1.6.03
$HeadURL$
**********************************************/
// embedded images
function cornerleft()
{
header("Content-type: image/gif");
header("Content-length: 290");
echo base64_decode(
'R0lGODlhGQAZAMQAAP///+zu8d3h5tXb4dbW1s/V3czU2sXN1c'.
'PK0cPExMHCw7y+wLW1tbC2va6yuKurrJmZmf///wAAAAAAAAAA'.
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BA'.
'UUABEALAAAAAAZABkAAAWfICCOZGmeaHoqysI8CZG4sEzHSZ6I'.
'CeJEEULg8AsOi0IgULRACgoNIOEZDQoGyoiIAUwECkUvuBvAZk'.
'UPI1F6ZBuyS0Ds6RxbzXCR0C4Ol+FKPAdVQmtGb4BxTVJ0jHiJ'.
'W2R8f4mBAGmFSAGIlXFzdlOPnXpffqKjcoNunYBMTqeskRFesL'.
'GXh6yVPKG5ugBCtb08vbYJxKjGx5ByyokhADs='.
'');
}
function cornerright()
{
header("Content-type: image/gif");
header("Content-length: 292");
echo base64_decode(
'R0lGODlhGQAZAMQAAP///+zv8t3h5tXc5NbW1s/V3dHS08XN1c'.
'PK0cLDw8HCw7y+wLW1ta+0u66yuKurrJmZmf///wAAAAAAAAAA'.
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BA'.
'UUABEALAAAAAAZABkAAAWhYCSOZGlGCQCc7JmubSy+skzX5xAY'.
'Km4OAsLNJyrsIo8eMaJTiBhKH9AgciyiNSM10jgMZc2qFtuaih'.
'qF4JelPR+OSVg54Iw4jIknuWTmprdWeyNtXG9bXWsjYXZ4YjuC'.
'fWgCh2lCe4RdR4VwZIt3AXmMoHpyTAOUk2d/Z1elAQRVb7B2sm'.
'cILwm5CQYJDwwLu72/wb7ALyrIycrLzM3OyyEAOw=='.
'');
}
define('IN_COPPERMINE', true);
define('EDITPICS_PHP', true);
require('include/init.inc.php');
require('include/picmgmt.inc.php');
define('IMG_DIR', $CONFIG['fullpath'].'edit/');
// image calls
if ($superCage->get->keyExists('img')) {
if ($superCage->get->getAlpha('img') == "left") {
cornerleft();
exit;
} elseif ($superCage->get->getAlpha('img') == "right") {
cornerright();
exit;
}
}
if ($superCage->get->keyExists('id')) {
$pid = $superCage->get->getInt('id');
} elseif ($superCage->post->keyExists('id')) {
$pid = $superCage->post->getInt('id');
} else {
cpg_die(ERROR, $lang_errors['param_missing'], __FILE__, __LINE__);
}
if ($pid > 0) {
$result = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_PICTURES']} WHERE pid = '$pid'");
$CURRENT_PIC = $result->fetchAssoc(true);
$result = cpg_db_query("SELECT category FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid = '{$CURRENT_PIC['aid']}'");
$CURRENT_ALBUM = $result->fetchAssoc(true);
} else {
cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
}
if (!(GALLERY_ADMIN_MODE || ($CONFIG['users_can_edit_pics'] && $CURRENT_PIC['owner_id'] == USER_ID) || ($CURRENT_ALBUM['category'] == FIRST_USER_CAT + USER_ID)) || !USER_ID) {
cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);
}
//Garbage collection run at an probability of 25% and delete all files older than one hour
if (rand(1,100) < 25){
$d = opendir(IMG_DIR);
while ($file = readdir($d)){
if (is_file(IMG_DIR.$file) && ((time() - filemtime(IMG_DIR.$file))/60) > 60 && $file !="index.php" && $file !="no_FTP-uploads_into_this_folder!.txt"){
@unlink(IMG_DIR.$file);
}
}
}
//Include the proper class (imageObject) for image manipulation
getImageTool();
//////////////////////////////////Main script//////////////////////////////////////
// PREVENTING CACHING
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
// PAGE INIT
if (!$img_dir) $img_dir = IMG_DIR;
//if ($_GET['id']){
if ($superCage->get->getInt('id')) {
//Copy the Image file to the editing directory
if (copy($CONFIG['fullpath'].$CURRENT_PIC['filepath'].$CURRENT_PIC['filename'],$img_dir.$CURRENT_PIC['filename']))
$newimage = $CURRENT_PIC['filename'];
} else if (!isset($newimage)){
//$newimage = $_POST['newimage'];
$matches = $superCage->post->getMatched('newimage', '/^[0-9A-Za-z_.\-~]+$/');
$newimage = $matches[0];
}
if ($newimage) {
$imgObj = new imageObject($img_dir,$newimage);
/*if ($_POST['quality']){
$imgObj->quality = $_POST['quality'];
}*/
if ($superCage->post->keyExists('quality')) {
$imgObj->quality = $superCage->post->getInt('quality');
}
if ($imgObj->imgRes){
/*if ($_POST['clipval'] && $_POST['cropping']==true){
$imgObj = $imgObj->cropImage($_POST['clipval']);
}*/
if ($superCage->post->getEscaped('clipval') && $superCage->post->getEscaped('cropping') == true) {
$imgObj = $imgObj->cropImage($superCage->post->getEscaped('clipval'));
}
/*if ($_POST['angle']<>0){
$imgObj = $imgObj->rotateImage($_POST['angle']);
}*/
if ($superCage->post->getInt('angle') <> 0) {
$imgObj = $imgObj->rotateImage($superCage->post->getInt('angle'));
}
}
$newimage = $imgObj->filename;
}//newimage
//if(isset($_POST["save"])) {
if ($superCage->post->keyExists('save')) {
$width = $imgObj->width;
$height = $imgObj->height;
$normal = $CONFIG['fullpath'] . $CURRENT_PIC['filepath'] . $CONFIG['normal_pfx'] . $CURRENT_PIC['filename'];
$thumbnail = $CONFIG['fullpath'] . $CURRENT_PIC['filepath'] . $CONFIG['thumb_pfx'] . $CURRENT_PIC['filename'];
$filesize = @filesize($img_dir.$newimage);
//Full image replace
copy($img_dir.$newimage,$CONFIG['fullpath'].$CURRENT_PIC['filepath'].$CURRENT_PIC['filename']) ;
// Normal image resized and replace, use the CPG resize method instead of the object resizeImage
// as using the object resizeImage will make the final display of image to be a thumbnail in the editor
if (max($width, $height) > $CONFIG['picture_width'] && $CONFIG['make_intermediate']) {
resize_image($img_dir.$newimage, $normal, $CONFIG['picture_width'], $CONFIG['thumb_use']);
} else {
@unlink($normal);
}
//thumbnail resized and replace
resize_image($img_dir.$newimage, $thumbnail, $CONFIG['thumb_width'], $CONFIG['thumb_use']);
$total_filesize = $filesize + (file_exists($normal) ? filesize($normal) : 0) + filesize($thumbnail);
//Update the image size in the DB
cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']}
SET pheight = $height,
pwidth = $width,
filesize = $filesize,
total_filesize = $total_filesize
WHERE pid = '$pid'");
$message = sprintf($lang_editpics_php['success_picture'], '<a href="#" onclick="self.close();">', '</a>');
}
//if(isset($_POST["save_thumb"])) {
if ($superCage->post->keyExists('save_thumb')) {
$width=$imgObj->width;
$height=$imgObj->height;
$normal = $CONFIG['fullpath'] . $CURRENT_PIC['filepath'] . $CONFIG['normal_pfx'] . $CURRENT_PIC['filename'];
$thumbnail = $CONFIG['fullpath'] . $CURRENT_PIC['filepath'] . $CONFIG['thumb_pfx'] . $CURRENT_PIC['filename'];
$currentPic = $CONFIG['fullpath'] . $CURRENT_PIC['filepath'] . $CURRENT_PIC['filename'];
//Calculate the thumbnail dimensions
if ($CONFIG['thumb_use'] == 'ht') {
$ratio = $height / $CONFIG['thumb_width'] ;
} elseif ($CONFIG['thumb_use'] == 'wd') {
$ratio = $width / $CONFIG['thumb_width'] ;
} else {
$ratio = max($width, $height) / $CONFIG['thumb_width'] ;
}
$ratio = max($ratio, 1.0);
$dstWidth = (int)($width / $ratio);
$dstHeight = (int)($height / $ratio);
//$imgObj->quality = (int)($_POST['quality']);
$imgObj->quality = $superCage->post->getInt('quality');
$imgObj = $imgObj->resizeImage($dstWidth,$dstHeight);
$newimage = $imgObj->filename;
copy($img_dir.$newimage,$CONFIG['fullpath'].$CURRENT_PIC['filepath'].$CONFIG['thumb_pfx'].$CURRENT_PIC['filename']) ;
$total_filesize = filesize($currentPic) + (file_exists($normal) ? filesize($normal) : 0) + filesize($thumbnail);
//Update the image size in the DB
cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET total_filesize = $total_filesize WHERE pid = '$pid'");
$message = sprintf($lang_editpics_php['success_thumb'], '<a href="#" onclick="self.close();">', '</a>');
}
// Convert the array to json object string
$js_vars['width'] = $imgObj->width;
$js_vars['height'] = $imgObj->height;
$js_vars['error_document_size'] = $lang_editpics_php['error_document_size'];
$json_vars = json_encode($js_vars);
// Output the json object
$json_script = "<script type=\"text/javascript\">var js_vars = eval('($json_vars)');</script>" . $LINEBREAK;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="imagetoolbar" content="no" />
<meta http-equiv="content-type" content="text/html; charset=<?php echo $CONFIG['charset'] == 'language file' ? $lang_charset : $CONFIG['charset'] ?>" />
<title><?php echo $lang_editpics_php['crop_title'] ?></title>
<?php if($imgObj){
echo $json_script;
?>
<script type="text/javascript" src="js/pic_editor.js"></script>
<script type="text/javascript" src="<?php echo CPG_JQUERY_VERSION; ?>"></script>
<script type="text/javascript" src="js/scripts.js"></script>
<?php }?>
<style type="text/css">
#lefttopdiv{
position:absolute;
background-image:url(<?php echo $CPG_PHP_SELF ?>?img=left);
left:0px;
top:100px;
height:25px;
width:25px;
z-index:8;
cursor:move;
visibility:hidden;
}
#rightbottomdiv{
position:absolute;
background-image:url(<?php echo $CPG_PHP_SELF ?>?img=right);
left:0px;
top:225px;
height:25px;
width:25px;
z-index:9;
cursor:move;
visibility:hidden;
}
#imgdiv{
position:absolute;
top:100px;
width:<?php echo $imgObj->width?>px;
height:<?php echo $imgObj->height?>px;
text-align:center;
margin-left:auto;
margin-right:auto;
z-index:0;
<?php
if (!$imgObj->imgRes) {
echo 'visibility:hidden;' . $LINEBREAK;
}
?>
}
</style>
<link rel="stylesheet" href="css/coppermine.css" type="text/css" />
<link rel="stylesheet" href="themes/<?php echo $CONFIG['theme'];?>/style.css" type="text/css" />
</head>
<body>
<?php if ($imgObj) print "<script type=\"text/javascript\">addonload('libinit()');</script>";?>
<form name="mainform" id="cpgform" method="post" enctype="multipart/form-data" action="pic_editor.php">
<input type="hidden" name="clipval" value="" />
<input type="hidden" name="newimage" value="<?php print $newimage ; ?>" />
<input type="hidden" name="img_dir" value="<?php print $img_dir ; ?>" />
<?php
if ($superCage->get->keyExists('id')) {
$get_id = $superCage->get->getInt('id');
} else {
$get_id = $superCage->post->getInt('id');
}
?>
<input type="hidden" name="id" value="<?php print ($get_id); ?>" />
<?php starttable("100%", $lang_editpics_php['crop_title'], 3); ?>
<tr>
<td>
<table border="0" cellspacing="2" cellpadding="2" class="maintableb" width="100%" >
<tr>
<?php if ($CONFIG['thumb_method']=='im' || $CONFIG['thumb_method']=='imx' || ($CONFIG['thumb_method']=='gd2' && function_exists('imagerotate'))) { ?>
<td>
<select name="angle" class="listbox">
<option value="0" selected="selected"><?php print $lang_editpics_php['rotate']; ?></option>
<option value="90">-90°</option>
<option value="180">180°</option>
<option value="270">+90°</option>
</select>
</td>
<?php } ?>
<!--
<td >
<input valign="bottom" type="checkbox" class="checkbox" name="mirror" id="mirror" value="true" />
<label for="mirror" class="clickable_option">
<?php print $lang_editpics_php['mirror']; ?>
</label>
</td>
<td>
<select name="rescale" class="listbox">
<option value=""><?php print $lang_editpics_php['scale']; ?></option>
<?php
for ($i=0.1;$i<=2.01;$i=$i+0.01) {
print ' <option value="'.$i.'">';
print $i*100;
print '%</option>';
print $LINEBREAK;
}
?>
</select>
</td>
<td>
<?php print $lang_editpics_php['or']; ?>
</td>
<td>
<select name="widthheight" class="listbox" >
<option value="width"><?php print $lang_editpics_php['new_width']; ?></option>
<option value="height"><?php print $lang_editpics_php['new_height']; ?></option>
</select>
</td>
<td>
<input type="text" size="3" name="newsize" id="newsize" class="textinput" /> px
</td>
-->
<td>
<input type="checkbox" class="checkbox" name="cropping" id="cropping" value="true" onclick="showCorners(this)" />
<label for="cropping" class="clickable_option">
<?php print $lang_editpics_php['enable_clipping']; ?>
</label>
</td>
<td title="Less quality creates a smaller file, default is 80%" >
<select id="quality" name="quality" class="listbox" >
<option value="<?php print $CONFIG['jpeg_qual']; ?>" selected="selected"><?php print $lang_editpics_php['jpeg_quality']; ?></option>
<?php
for ( $counter = 10; $counter <= 100; $counter += 5) {
$selected = ($imgObj->quality == $counter) ? 'selected="selected" ' : '';
echo "<option value=\"$counter\" $selected>$counter</option>";
}
?>
</select>
</td>
<td><input type="submit" name="submit" class="button" value=" <?php echo $lang_editpics_php['preview'] ?> " /></td>
<td><input type="submit" name="save" class="button" value=" <?php echo $lang_editpics_php['save'] ?> " /></td>
<td><input type="submit" name="save_thumb" class="button" value=" <?php echo $lang_editpics_php['save_thumb'] ?> " /></td>
</tr>
</table>
</td>
</tr>
<?php endtable(); ?>
<div id="lefttopdiv" onclick="showPreview(); return false;">
</div>
<div id="rightbottomdiv" onclick="showPreview(); return false;">
</div>
<?php if ($message){ ?>
<h1 align=center><?php echo $message?></h1>
<?php } ?>
<div id="imgdiv">
<?php if ($imgObj) { ?>
<img src="<?php echo $imgObj->directory.$imgObj->filename?>?<?php echo rand(); ?>" <?php echo $imgObj->string; ?> style="vertical-align: middle;" alt="" />
<?php } ?>
</div>
</form>
</body>
</html>