forked from PHPFusion/PHPFusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
photo.php
executable file
·210 lines (208 loc) · 9.45 KB
/
photo.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
<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) PHP-Fusion Inc
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: photo.php
| Author: Robert Gaudyn (Wooya)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
require_once "maincore.php";
if (!db_exists(DB_PHOTO_ALBUMS)) {
$_GET['code'] = 404;
require_once __DIR__.'/error.php';
exit;
}
if (!@ini_get("safe_mode")) {
define("SAFEMODE", FALSE);
} else {
define("SAFEMODE", TRUE);
}
function convert_color($hex) {
$len = strlen($hex);
preg_match("/([0-9]|[A-F]|[a-f]){".$len."}/i", $hex, $arr);
$hex = $arr[0];
if ($hex) {
switch ($len) {
case 2:
$red = hexdec($hex);
$green = 0;
$blue = 0;
break;
case 4:
$red = hexdec(substr($hex, 0, 2));
$green = hexdec(substr($hex, 2, 2));
$blue = 0;
break;
case 6:
$red = hexdec(substr($hex, 0, 2));
$green = hexdec(substr($hex, 2, 2));
$blue = hexdec(substr($hex, 4, 2));
break;
}
$color['success'] = TRUE;
$color['r'] = $red;
$color['g'] = $green;
$color['b'] = $blue;
return $color;
} else {
$color['success'] = FALSE;
$color['error'] = $locale['global_900'];
return $color;
}
}
if (isset($_GET['photo_id']) && isnum($_GET['photo_id'])) {
$result = dbquery("SELECT ta.album_id, ta.album_title, ta.album_description, ta.album_access, tp.photo_title, tp.photo_filename, tp.photo_thumb2
FROM ".DB_PHOTOS." tp INNER JOIN ".DB_PHOTO_ALBUMS." ta USING (album_id)
WHERE photo_id=".$_GET['photo_id']." GROUP BY tp.photo_id");
$data = dbarray($result);
if (checkgroup($data['album_access'])) {
define("PHOTODIR", PHOTOS.(!SAFEMODE ? "album_".$data['album_id']."/" : ""));
$parts = explode(".", $data['photo_filename']);
$wm_file1 = $parts[0]."_w1.".$parts[1];
$wm_file2 = $parts[0]."_w2.".$parts[1];
if (!isset($_GET['full'])) {
$wm_file = PHOTODIR.$wm_file1;
} else {
$wm_file = PHOTODIR.$wm_file2;
}
header("Content-type: image/jpg");
$img = PHOTODIR.$data['photo_filename'];
$cop = BASEDIR.$settings['photo_watermark_image'];
if (preg_match("/.jpg/i", strtolower($img)) || preg_match("/.jpeg/i", strtolower($img))) {
$image = ImageCreateFromJPEG($img);
} else if (preg_match("/.png/i", strtolower($img))) {
$image = ImageCreateFromPNG($img);
} else if (preg_match("/.gif/i", strtolower($img))) {
$image = ImageCreateFromGIF($img);
$sizeX = ImagesX($image);
$sizeY = ImagesY($image);
$image_tmp = ImageCreateTrueColor($sizeX, $sizeY);
$ica = ImageColorAllocate($image_tmp, 255, 255, 255);
ImageFill($image_tmp, 0, 0, $ica);
if ($settings['thumb_compression'] == "gd2") {
ImageCopyResampled($image_tmp, $image, 0, 0, 0, 0, $sizeX, $sizeY, $sizeX, $sizeY);
} else {
ImageCopyResized($image_tmp, $image, 0, 0, 0, 0, $sizeX, $sizeY, $sizeX, $sizeY);
}
$tmp = PHOTODIR.md5(time().$img).'.tmp';
ImageJPEG($image_tmp, $tmp);
ImageDestroy($image_tmp);
$image = ImageCreateFromJPEG($tmp);
unlink($tmp);
}
if (file_exists($cop) && preg_match("/.png/i", strtolower($cop)) && $settings['photo_watermark']) {
$image2 = FALSE;
$image_dim_x = ImagesX($image);
$image_dim_y = ImagesY($image);
$copyright = ImageCreateFromPNG($cop);
$copyright_dim_x = ImagesX($copyright);
$copyright_dim_y = ImagesY($copyright);
$where_x = $image_dim_x-$copyright_dim_x-5;
$where_y = $image_dim_y-$copyright_dim_y-5;
ImageCopy($image, $copyright, $where_x, $where_y, 0, 0, $copyright_dim_x, $copyright_dim_y);
$thumb_w = 0;
$thumb_h = 0;
if (!isset($_GET['full'])) {
if ($image_dim_x > $settings['photo_w'] || $image_dim_y > $settings['photo_h']) {
if ($image_dim_x < $image_dim_y) {
$thumb_w = round(($image_dim_x*$settings['photo_h'])/$image_dim_y);
$thumb_h = $settings['photo_h'];
} elseif ($image_dim_x > $image_dim_y) {
$thumb_w = $settings['photo_w'];
$thumb_h = round(($image_dim_y*$settings['photo_w'])/$image_dim_x);
} else {
$thumb_w = $settings['photo_w'];
$thumb_h = $settings['photo_h'];
}
} else {
$thumb_w = $image_dim_x;
$thumb_h = $image_dim_y;
}
$image2 = ImageCreateTrueColor($thumb_w, $thumb_h);
if ($settings['thumb_compression'] == "gd2") {
ImageCopyResampled($image2, $image, 0, 0, 0, 0, $thumb_w, $thumb_h, $image_dim_x, $image_dim_y);
} else {
ImageCopyResized($image2, $image, 0, 0, 0, 0, $thumb_w, $thumb_h, $image_dim_x, $image_dim_y);
}
ImageDestroy($image);
}
if ($settings['photo_watermark_text']) {
$enc = array("&", """, "'", "\", """, "'", "<", ">");
$dec = array("&", "\"", "'", "\\", '\"', "\'", "<", ">");
$black = ImageColorAllocate(($image2 ? $image2 : $image), 0, 0, 0);
$colors1 = convert_color($settings['photo_watermark_text_color1']);
$colors2 = convert_color($settings['photo_watermark_text_color2']);
$colors3 = convert_color($settings['photo_watermark_text_color3']);
$color1 = ImageColorAllocate(($image2 ? $image2 : $image), $colors1['r'], $colors1['g'], $colors1['b']);
$color2 = ImageColorAllocate(($image2 ? $image2 : $image), $colors2['r'], $colors2['g'], $colors2['b']);
$color3 = ImageColorAllocate(($image2 ? $image2 : $image), $colors3['r'], $colors3['g'], $colors3['b']);
//move text y
$mty1 = ($thumb_h ? $thumb_h : $image_dim_y)-($thumb_h ? 40 : 50);
$mty2 = ($thumb_h ? $thumb_h : $image_dim_y)-($thumb_h ? 25 : 35);
$mty3 = ($thumb_h ? $thumb_h : $image_dim_y)-($thumb_h ? 15 : 20);
$album_title = str_replace("\r", "", $data['album_title']);
$album_title = str_replace("\n", "", $album_title);
$album_title = preg_replace("[\[(.*?)\]]", "", $album_title);
$album_title = preg_replace("<\<(.*?)\>>", "", $album_title);
$album_title = trimlink($album_title, 75);
$album_title = str_replace($enc, $dec, $album_title);
$album_description = str_replace("\r", "", $data['album_description']);
$album_description = str_replace("\n", "", $album_description);
$album_description = preg_replace("[\[(.*?)\]]", "", $album_description);
$album_description = preg_replace("<\<(.*?)\>>", "", $album_description);
$album_description = trimlink($album_description, 75);
$album_description = str_replace($enc, $dec, $album_description);
$photo_title = str_replace("\r", "", $data['photo_title']);
$photo_title = str_replace("\n", "", $photo_title);
$photo_title = preg_replace("[\[(.*?)\]]", "", $photo_title);
$photo_title = preg_replace("<\<(.*?)\>>", "", $photo_title);
$photo_title = trimlink($photo_title, 75);
$photo_title = str_replace($enc, $dec, $photo_title);
$album_title_font_size = !isset($_GET['full']) ? 3 : 5;
$album_descr_font_size = !isset($_GET['full']) ? 1 : 3;
$photo_title_font_size = !isset($_GET['full']) ? 1 : 3;
//album title
ImageString(($image2 ? $image2 : $image), $album_title_font_size, 10, $mty1-1, $album_title, $black);
ImageString(($image2 ? $image2 : $image), $album_title_font_size, 10, $mty1+1, $album_title, $black);
ImageString(($image2 ? $image2 : $image), $album_title_font_size, 9, $mty1, $album_title, $black);
ImageString(($image2 ? $image2 : $image), $album_title_font_size, 11, $mty1, $album_title, $black);
ImageString(($image2 ? $image2 : $image), $album_title_font_size, 10, $mty1, $album_title, $color1);
//album info
ImageString(($image2 ? $image2 : $image), $album_descr_font_size, 10, $mty2-1, $album_description, $black);
ImageString(($image2 ? $image2 : $image), $album_descr_font_size, 10, $mty2+1, $album_description, $black);
ImageString(($image2 ? $image2 : $image), $album_descr_font_size, 9, $mty2, $album_description, $black);
ImageString(($image2 ? $image2 : $image), $album_descr_font_size, 11, $mty2, $album_description, $black);
ImageString(($image2 ? $image2 : $image), $album_descr_font_size, 10, $mty2, $album_description, $color2);
//photo name
ImageString(($image2 ? $image2 : $image), $photo_title_font_size, 10, $mty3-1, $photo_title, $black);
ImageString(($image2 ? $image2 : $image), $photo_title_font_size, 10, $mty3+1, $photo_title, $black);
ImageString(($image2 ? $image2 : $image), $photo_title_font_size, 9, $mty3, $photo_title, $black);
ImageString(($image2 ? $image2 : $image), $photo_title_font_size, 11, $mty3, $photo_title, $black);
ImageString(($image2 ? $image2 : $image), $photo_title_font_size, 10, $mty3, $photo_title, $color3);
}
}
//create image
if ($settings['photo_watermark_save']) {
ImageJPEG(($image2 ? $image2 : $image), $wm_file);
}
ImageJPEG((isset($image2) && $image2 ? $image2 : $image));
ImageDestroy((isset($image2) && $image2 ? $image2 : $image));
if (isset($copyright) && is_resource($copyright)) {
ImageDestroy($copyright);
}
} else {
redirect("index.php");
}
} else {
redirect("index.php");
}
?>