/web/htdocs/www.euroroma.net/home/zenphoto/zp-core/full-image.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
<?php

/**
 * handles the watermarking and protecting of the full image link
 * @package core
 */
// force UTF-8 Ø
if (!defined('OFFSET_PATH'))
    
define('OFFSET_PATH'1);
require_once(
dirname(__FILE__) . "/functions.php");
require_once(
dirname(__FILE__) . "/functions-image.php");

$disposal getOption('protect_full_image');
if (
$disposal == 'No access') { // illegal use of the script!
    
imageError('403 Forbidden'gettext("Forbidden"));
} else {
    if (isset(
$_GET['dsp'])) {
        
$disposal sanitize($_GET['dsp']);
    }
}
// Check for minimum parameters.
if (!isset($_GET['a']) || !isset($_GET['i'])) {
    
imageError('404 Not Found'gettext("Too few arguments! Image not found."), 'err-imagenotfound.png');
}

list(
$album8$image8) = rewrite_get_album_image('a''i');
$album internalToFilesystem($album8);
$image internalToFilesystem($image8);

/* Prevent hotlinking to the full image from other domains. */
if (getOption('hotlink_protection') && isset($_SERVER['HTTP_REFERER'])) {
    
preg_match('|(.*)//([^/]*)|'$_SERVER['HTTP_REFERER'], $matches);
    if (
preg_replace('/^www\./'''strtolower($_SERVER['SERVER_NAME'])) != preg_replace('/^www\./'''strtolower($matches[2]))) {
        
/* It seems they are directly requesting the full image. */
        
header('Location: ' FULLWEBPATH '/index.php?album=' $album8 '&image=' $image8);
        
exitZP();
    }
}

$albumobj newAlbum($album8);
$imageobj newImage($albumobj$image8);
$args getImageArgs($_GET);
$args[0] = 'FULL';
$adminrequest $args[12];

if (
$forbidden getOption('image_processor_flooding_protection') && (!isset($_GET['check']) || $_GET['check'] != sha1(HASH_SEED serialize($args)))) {
    
// maybe it was from the tinyZenpage javascript which does not know better!
    
zp_session_start();
    
$forbidden = !isset($_SESSION['adminRequest']) || $_SESSION['adminRequest'] != @$_COOKIE['zp_user_auth'];
}

$args[0] = 'FULL';

$hash getOption('protected_image_password');
if ((
$hash || !$albumobj->checkAccess()) && !zp_loggedin(VIEW_FULLIMAGE_RIGHTS)) {
    
//    handle password form if posted
    
zp_handle_password('zp_image_auth'getOption('protected_image_password'), getOption('protected_image_user'));
    
//check for passwords
    
$authType 'zp_image_auth';
    
$hint get_language_string(getOption('protected_image_hint'));
    
$show getOption('protected_image_user');
    if (empty(
$hash)) { // check for album password
        
$hash $albumobj->getPassword();
        
$authType "zp_album_auth_" $albumobj->getID();
        
$hint $albumobj->getPasswordHint();
        
$show $albumobj->getUser();
        if (empty(
$hash)) {
            
$albumobj $albumobj->getParent();
            while (!
is_null($albumobj)) {
                
$hash $albumobj->getPassword();
                
$authType "zp_album_auth_" $albumobj->getID();
                
$hint $albumobj->getPasswordHint();
                
$show $albumobj->getUser();
                if (!empty(
$hash)) {
                    break;
                }
                
$albumobj $albumobj->getParent();
            }
        }
    }
    if (empty(
$hash)) { // check for gallery password
        
$hash $_zp_gallery->getPassword();
        
$authType 'zp_gallery_auth';
        
$hint $_zp_gallery->getPasswordHint();
        
$show $_zp_gallery->getUser();
    }

    if (empty(
$hash) || (!empty($hash) && zp_getCookie($authType) != $hash)) {
        require_once(
dirname(__FILE__) . "/template-functions.php");
        require_once(
SERVERPATH "/" ZENFOLDER '/functions-controller.php');
        
zp_load_gallery();
        
$theme setupTheme($albumobj);
        
$custom $_zp_themeroot '/functions.php';
        if (
file_exists($custom)) {
            require_once(
$custom);
        }
        
$_zp_gallery_page 'password.php';
        
$_zp_script $_zp_themeroot '/password.php';
        if (!
file_exists(internalToFilesystem($_zp_script))) {
            
$_zp_script SERVERPATH '/' ZENFOLDER '/password.php';
        }
        
header('Content-Type: text/html; charset=' LOCAL_CHARSET);
        
header("HTTP/1.0 302 Found");
        
header("Status: 302 Found");
        
header('Last-Modified: ' ZP_LAST_MODIFIED);
        include(
internalToFilesystem($_zp_script));
        
exposeZenPhotoInformations($_zp_script, array(), $theme);
        
exitZP();
    }
}

$image_path $imageobj->localpath;
$suffix getSuffix($image_path);

switch (
$suffix) {
    case 
'bmp':
        
$suffix 'wbmp';
        break;
    case 
'jpg':
        
$suffix 'jpeg';
        break;
    case 
'png':
    case 
'gif':
    case 
'jpeg':
        break;
    default:
        if (
$disposal == 'Download') {
            require_once(
dirname(__FILE__) . '/lib-MimeTypes.php');
            
$mimetype getMimeString($suffix);
            
header('Content-Disposition: attachment; filename="' $image '"'); // enable this to make the image a download
            
$fp fopen($image_path'rb');
            
// send the right headers
            
header('Last-Modified: ' gmdate('D, d M Y H:i:s') . ' GMT');
            
header("Content-Type: $mimetype");
            
header("Content-Length: " filesize($image_path));
            
// dump the picture and stop the script
            
fpassthru($fp);
            
fclose($fp);
        } else {
            
header('Location: ' $imageobj->getFullImageURL(), true301);
        }
        
exitZP();
}
if (
$force_cache getOption('cache_full_image')) {
    
$cache_file getImageCacheFilename($album$image$args);
    
$cache_path SERVERCACHE $cache_file;
    
mkdir_recursive(dirname($cache_path), FOLDER_MOD);
} else {
    
$cache_file $album "/" stripSuffix($image) . '_FULL.' $suffix;
    
$cache_path NULL;
}

$process $rotate false;
if (
zp_imageCanRotate()) {
    
$rotate getImageRotation($image_path);
    
$process $rotate;
}
$watermark_use_image getWatermarkParam($imageobjWATERMARK_FULL);
if (
$watermark_use_image == NO_WATERMARK) {
    
$watermark_use_image '';
} else {
    
$process 2;
}

if (isset(
$_GET['q'])) {
    
$quality sanitize_numeric($_GET['q']);
} else {
    
$quality getOption('full_image_quality');
}

if (!(
$process || $force_cache)) { // no processing needed
    
if (getOption('album_folder_class') != 'external' && $disposal != 'Download') { // local album system, return the image directly
        
header('Content-Type: image/' $suffix);
        if (
UTF8_IMAGE_URI) {
            
header("Location: " getAlbumFolder(FULLWEBPATH) . pathurlencode($album8) . "/" rawurlencode($image8));
        } else {
            
header("Location: " getAlbumFolder(FULLWEBPATH) . pathurlencode($album) . "/" rawurlencode($image));
        }
        
exitZP();
    } else { 
// the web server does not have access to the image, have to supply it
        
$fp fopen($image_path'rb');
        
// send the right headers
        
header('Last-Modified: ' gmdate('D, d M Y H:i:s') . ' GMT');
        
header("Content-Type: image/$suffix");
        if (
$disposal == 'Download') {
            
header('Content-Disposition: attachment; filename="' $image '"'); // enable this to make the image a download
        
}
        
header("Content-Length: " filesize($image_path));
        
// dump the picture and stop the script
        
fpassthru($fp);
        
fclose($fp);
        
exitZP();
    }
}

header('Last-Modified: ' gmdate('D, d M Y H:i:s') . ' GMT');
header("Content-Type: image/$suffix");
if (
$disposal == 'Download') {
    
header('Content-Disposition: attachment; filename="' $image '"'); // enable this to make the image a download
}

if (
is_null($cache_path) || !file_exists($cache_path)) { //process the image
    
if ($forbidden) {
        
imageError('403 Forbidden'gettext("Forbidden(2)"));
    }
    if (
$force_cache && !$process) {
        
// we can just use the original!
        
if (SYMLINK && @symlink($image_path$cache_path)) {
            if (
DEBUG_IMAGE)
                
debugLog("full-image:symlink original " basename($image));
            
clearstatcache();
        } else if (@
copy($image_path$cache_path)) {
            if (
DEBUG_IMAGE)
                
debugLog("full-image:copy original " basename($image));
            
clearstatcache();
        }
    } else {
        
//    have to create the image
        
$iMutex = new Mutex('i'getOption('imageProcessorConcurrency'));
        
$iMutex->lock();
        
$newim zp_imageGet($image_path);
        if (
$rotate) {
            
$newim zp_rotateImage($newim$rotate);
        }
        if (
$watermark_use_image) {
            
$watermark_image getWatermarkPath($watermark_use_image);
            if (!
file_exists($watermark_image))
                
$watermark_image SERVERPATH '/' ZENFOLDER '/images/imageDefault.png';
            
$offset_h getOption('watermark_h_offset') / 100;
            
$offset_w getOption('watermark_w_offset') / 100;
            
$watermark zp_imageGet($watermark_image);
            
$watermark_width zp_imageWidth($watermark);
            
$watermark_height zp_imageHeight($watermark);
            
$imw zp_imageWidth($newim);
            
$imh zp_imageHeight($newim);
            
$percent getOption('watermark_scale') / 100;
            
$r sqrt(($imw $imh $percent) / ($watermark_width $watermark_height));
            if (!
getOption('watermark_allow_upscale')) {
                
$r min(1$r);
            }
            
$nw round($watermark_width $r);
            
$nh round($watermark_height $r);
            if ((
$nw != $watermark_width) || ($nh != $watermark_height)) {
                
$watermark zp_imageResizeAlpha($watermark$nw$nh);
            }
            
// Position Overlay in Bottom Right
            
$dest_x max(0floor(($imw $nw) * $offset_w));
            
$dest_y max(0floor(($imh $nh) * $offset_h));
            
zp_copyCanvas($newim$watermark$dest_x$dest_y00$nw$nh);
            
zp_imageKill($watermark);
        }
        
$iMutex->unlock();
        if (!
zp_imageOutput($newim$suffix$cache_path$quality) && DEBUG_IMAGE) {
            
debugLog('full-image failed to create:' $image);
        }
    }
}

if (!
is_null($cache_path)) {
    if (
$disposal == 'Download' || !OPEN_IMAGE_CACHE) {
        require_once(
dirname(__FILE__) . '/lib-MimeTypes.php');
        
$mimetype getMimeString($suffix);
        
$fp fopen($cache_path'rb');
        
// send the right headers
        
header('Last-Modified: ' gmdate('D, d M Y H:i:s') . ' GMT');
        
header("Content-Type: $mimetype");
        
header("Content-Length: " filesize($image_path));
        
// dump the picture and stop the script
        
fpassthru($fp);
        
fclose($fp);
    } else {
        
header('Location: ' FULLWEBPATH '/' CACHEFOLDER pathurlencode(imgSrcURI($cache_file)), true301);
    }
    
exitZP();
}
?>