$dest_x = max(0, floor(($imw - $nw) * $offset_w)); $dest_y = max(0, floor(($imh - $nh) * $offset_h)); zp_copyCanvas($newim, $watermark, $dest_x, $dest_y, 0, 0, $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)), true, 301); } exitZP(); } ?>
/** * * Returns an URI to the image: * * If the image is not cached, the uri will be to the image processor * If the image is cached then the uri will depend on the site option for * cache serving. If the site is set for open cache the uri will point to * the cached image. If the site is set for protected cache the uri will * point to the image processor (which will serve the image from the cache.) * NOTE: this latter implies added overhead for each and every image fetch! * * @param array $args * @param string $album the album name * @param string $image the image name * @param int $mitme mtime of the image * @return string */ function getImageURI($args, $album, $image, $mtime) { $cachefilename = getImageCacheFilename($album, $image, $args); if (OPEN_IMAGE_CACHE && file_exists(SERVERCACHE . $cachefilename) && (!$mtime || filemtime(SERVERCACHE . $cachefilename) >= $mtime)) { return WEBPATH . '/' . CACHEFOLDER . imgSrcURI($cachefilename); } else { return getImageProcessorURI($args, $album, $image); } }
/** * Get a custom sized version of this image based on the parameters. * * @param string $alt Alt text for the url * @param int $size size * @param int $width width * @param int $height height * @param int $cropw crop width * @param int $croph crop height * @param int $cropx crop x axis * @param int $cropy crop y axis * @param string $class Optional style class * @param string $id Optional style id * @param bool $thumbStandin set true to inhibit watermarking * @return string */ function getCustomImage($size, $width, $height, $cropw, $croph, $cropx, $cropy, $thumbStandin = false) { if ($thumbStandin & 1) { if ($this->objectsThumb == NULL) { $filename = makeSpecialImageName($this->getThumbImageFile()); $path = ZENFOLDER . '/i.php?a=' . urlencode($this->album->name) . '&i=' . urlencode($filename); return WEBPATH . "/" . $path . ($size ? "&s={$size}" : "") . ($width ? "&w={$width}" : "") . ($height ? "&h={$height}" : "") . ($cropw ? "&cw={$cropw}" : "") . ($croph ? "&ch={$croph}" : "") . ($cropx ? "&cx={$cropx}" : "") . ($cropy ? "&cy={$cropy}" : "") . "&t=true"; } else { $filename = $this->objectsThumb; $wmt = getOption(get_class($this) . '_watermark'); if ($wmt) { $wmt = '&wmt=' . $wmt; } $cachefilename = getImageCacheFilename($alb = $this->album->name, $filename, getImageParameters(array($size, $width, $height, $cropw, $croph, $cropx, $cropy, NULL, NULL, NULL, $thumbStandin, NULL, NULL))); if (file_exists(SERVERCACHE . $cachefilename) && filemtime(SERVERCACHE . $cachefilename) > $this->filemtime) { return WEBPATH . substr(CACHEFOLDER, 0, -1) . pathurlencode(imgSrcURI($cachefilename)); } else { $path = ZENFOLDER . '/i.php?a=' . urlencode($alb) . '&i=' . urlencode($filename); if (substr($path, 0, 1) == "/") { $path = substr($path, 1); } return WEBPATH . "/" . $path . ($size ? "&s={$size}" : "") . ($width ? "&w={$width}" : "") . ($height ? "&h={$height}" : "") . ($cropw ? "&cw={$cropw}" : "") . ($croph ? "&ch={$croph}" : "") . ($cropx ? "&cx={$cropx}" : "") . ($cropy ? "&cy={$cropy}" : "") . "&t=true" . $wmt; } } } else { $filename = $this->filename; $cachefilename = getImageCacheFilename($this->album->name, $filename, getImageParameters(array($size, $width, $height, $cropw, $croph, $cropx, $cropy, NULL, NULL, NULL, $thumbStandin, NULL, NULL))); if (file_exists(SERVERCACHE . $cachefilename) && filemtime(SERVERCACHE . $cachefilename) > $this->filemtime) { return WEBPATH . substr(CACHEFOLDER, 0, -1) . pathurlencode(imgSrcURI($cachefilename)); } else { return WEBPATH . '/' . ZENFOLDER . '/i.php?a=' . urlencode($this->album->name) . '&i=' . urlencode($filename) . ($size ? "&s={$size}" : "") . ($width ? "&w={$width}" : "") . ($height ? "&h={$height}" : "") . ($cropw ? "&cw={$cropw}" : "") . ($croph ? "&ch={$croph}" : "") . ($cropx ? "&cx={$cropx}" : "") . ($cropy ? "&cy={$cropy}" : ""); } } }
/** * Returns the IPTC data of an image * * @param string $filename * @return string */ function zp_imageIPTC($filename) { $ping = new Imagick(); if ($ping->pingImage(imgSrcURI($filename))) { try { return $ping->getImageProfile('iptc'); } catch (ImagickException $e) { // IPTC profile does not exist } } return false; }
/** * Returns an url to the password protected/watermarked current image * * @param object $image optional image object overrides the current image * @param string $disposal set to override the 'protect_full_image' option * @return string * */ function getProtectedImageURL($image = NULL, $disposal = NULL) { global $_zp_current_image; if (is_null($disposal)) { $disposal = getOption('protect_full_image'); } if ($disposal == 'No access') { return NULL; } if (is_null($image)) { if (!in_context(ZP_IMAGE)) { return false; } if (is_null($_zp_current_image)) { return false; } $image = $_zp_current_image; } $album = $image->getAlbum(); $watermark_use_image = getWatermarkParam($image, WATERMARK_FULL); if (!empty($watermark_use_image)) { $wmt = $watermark_use_image; } else { $wmt = false; } $args = array('FULL', NULL, NULL, NULL, NULL, NULL, NULL, (int) getOption('full_image_quality'), NULL, NULL, NULL, $wmt, false, NULL, NULL); $cache_file = getImageCacheFilename($album->name, $image->filename, $args); $cache_path = SERVERCACHE . $cache_file; if ($disposal != 'Download' && OPEN_IMAGE_CACHE && file_exists($cache_path)) { return WEBPATH . '/' . CACHEFOLDER . pathurlencode(imgSrcURI($cache_file)); } else { if ($disposal == 'Unprotected') { return getImageURI($args, $album->name, $image->filename, $image->filemtime); } else { $params = '&q=' . getOption('full_image_quality'); if (!empty($watermark_use_image)) { $params .= '&wmk=' . $watermark_use_image; } if ($disposal) { $params .= '&dsp=' . $disposal; } $params .= '&check=' . sha1(HASH_SEED . serialize($args)); if (is_array($image->filename)) { $album = dirname($image->filename['source']); $image = basename($image->filename['source']); } else { $album = $album->name; $image = $image->filename; } return WEBPATH . '/' . ZENFOLDER . '/full-image.php?a=' . $album . '&i=' . $image . $params; } } }
/** * Get a default-sized thumbnail of this image. * * @return string */ function getThumb($type = 'image') { if (getOption('thumb_crop') && !is_null($cy = $this->get('thumbY'))) { $ts = getOption('thumb_size'); $sw = getOption('thumb_crop_width'); $sh = getOption('thumb_crop_height'); $cx = $this->get('thumbX'); $cw = $this->get('thumbW'); $ch = $this->get('thumbH'); // upscale to thumb_size proportions if ($sw == $sh) { // square crop, set the size/width to thumbsize $sw = $sh = $ts; } else { if ($sw > $sh) { $r = $ts / $sw; $sw = $ts; $sh = $sh * $r; } else { $r = $ts / $sh; $sh = $ts; $sh = $r * $sh; } } return $this->getCustomImage(NULL, $sw, $sh, $cw, $ch, $cx, $cy, true); } $filename = $this->filename; $wmt = getOption('Image_watermark'); if ($wmt) { $wmt = '&wmt=' . $wmt; } $cachefilename = getImageCacheFilename($alb = $this->album->name, $filename, getImageParameters(array('thumb'))); if (file_exists(SERVERCACHE . $cachefilename) && filemtime(SERVERCACHE . $cachefilename) > $this->filemtime) { return WEBPATH . substr(CACHEFOLDER, 0, -1) . pathurlencode(imgSrcURI($cachefilename)); } else { if (getOption('mod_rewrite') && empty($wmt) && !empty($alb)) { $path = pathurlencode($alb) . '/' . $type . '/thumb/' . urlencode($filename); } else { $path = ZENFOLDER . '/i.php?a=' . urlencode($this->album->name) . '&i=' . urlencode($filename) . '&s=thumb' . $wmt; if ($type !== 'image') { $path .= '&' . $type . '=true'; } } if (substr($path, 0, 1) == "/") { $path = substr($path, 1); } return WEBPATH . "/" . $path; } }
* http://creativecommons.org/licenses/MIT/ */ define('OFFSET_PATH', 3); require_once dirname(dirname(dirname(__FILE__))) . '/admin-globals.php'; $_zp_loggedin = NULL; if (isset($_POST['auth'])) { $hash = sanitize($_POST['auth']); $id = sanitize($_POST['id']); $_zp_loggedin = $_zp_authority->checkAuthorization($hash, $id); } admin_securityChecks(UPLOAD_RIGHTS, $return = currentRelativeURL()); $folder = zp_apply_filter('admin_upload_process', sanitize_path($_POST['folder'])); $types = array_keys($_zp_extra_filetypes); $types = array_merge($_zp_supported_images, $types); $types = zp_apply_filter('upload_filetypes', $types); $options = array('upload_dir' => $targetPath = ALBUM_FOLDER_SERVERPATH . internalToFilesystem($folder) . '/', 'upload_url' => imgSrcURI(ALBUM_FOLDER_WEBPATH . $folder) . '/', 'accept_file_types' => '/(' . implode('|\\.', $types) . ')$/i'); $new = !is_dir($targetPath); if (!empty($folder)) { if ($new) { $rightsalbum = newAlbum(dirname($folder), true, true); } else { $rightsalbum = newAlbum($folder, true, true); } if ($rightsalbum->exists) { if (!$rightsalbum->isMyItem(UPLOAD_RIGHTS)) { if (!zp_apply_filter('admin_managed_albums_access', false, $return)) { header('Location: ' . FULLWEBPATH . '/' . ZENFOLDER . '/admin.php'); exitZP(); } } } else {
/** * Get a default-sized thumbnail of this image. * * @return string */ function getThumb($type = 'image') { $ts = getOption('thumb_size'); if (getOption('thumb_crop')) { list($custom, $sw, $sh, $cw, $ch, $cx, $cy) = $this->getThumbCropping($type); if ($custom) { return $this->getCustomImage(NULL, $sw, $sh, $cw, $ch, $cx, $cy, true); } } else { $sw = $sh = NULL; } $filename = $this->filename; $wmt = getWatermarkParam($this, WATERMARK_THUMB); $args = getImageParameters(array($ts, NULL, NULL, $sw, $sh, NULL, NULL, NULL, true, NULL, true, $wmt, NULL, NULL), $this->album->name); $cachefilename = getImageCacheFilename($alb = $this->album->name, $filename, $args); if (file_exists(SERVERCACHE . $cachefilename) && filemtime(SERVERCACHE . $cachefilename) > $this->filemtime) { return WEBPATH . '/' . CACHEFOLDER . pathurlencode(imgSrcURI($cachefilename)); } else { return getImageProcessorURI($args, $this->album->name, $this->filename); } }
if ($process) { // If the file hasn't been cached yet, create it. if ($forbidden) { imageError('403 Forbidden', gettext("Forbidden(2)")); } $iMutex = new zpMutex('i', getOption('imageProcessorConcurrency')); $iMutex->lock(); $result = cacheImage($newfilename, $imgfile, $args, $allowWatermark, $theme, $album); $iMutex->unlock(); if (!$result) { imageError('404 Not Found', sprintf(gettext('Image processing of %s resulted in a fatal error.'), filesystemToInternal($image))); } $fmt = filemtime($newfile); } $protocol = FULLWEBPATH; $path = $protocol . '/' . CACHEFOLDER . pathurlencode(imgSrcURI($newfilename)); if (!$debug) { // ... and redirect the browser to it. $suffix = getSuffix($newfilename); switch ($suffix) { case 'wbm': case 'wbmp': $suffix = 'wbmp'; break; case 'jpg': $suffix = 'jpeg'; break; case 'png': case 'gif': case 'jpeg': break;
/** * Get a custom sized version of this image based on the parameters. * * @param string $alt Alt text for the url * @param int $size size * @param int $width width * @param int $height height * @param int $cropw crop width * @param int $croph crop height * @param int $cropx crop x axis * @param int $cropy crop y axis * @param string $class Optional style class * @param string $id Optional style id * @param bool $thumbStandin set to true to treat as thumbnail * @param bool $effects ignored * @return string */ function getCustomImage($size, $width, $height, $cropw, $croph, $cropx, $cropy, $thumbStandin = false, $effects = NULL) { if ($thumbStandin) { $wmt = getOption('Video_watermark'); if (empty($wmt)) { $wmt = getWatermarkParam($this, WATERMARK_THUMB); } } else { $wmt = NULL; } $args = getImageParameters(array($size, $width, $height, $cropw, $croph, $cropx, $cropy, NULL, $thumbStandin, NULL, $thumbStandin, $wmt, NULL, $effects), $this->album->name); if ($thumbStandin & 1) { if ($this->objectsThumb == NULL) { $filename = makeSpecialImageName($this->getThumbImageFile()); if (!getOption('video_watermark_default_images')) { $args[11] = '!'; } return getImageProcessorURI($args, $this->album->name, $filename); } else { $filename = $this->objectsThumb; $cachefilename = getImageCacheFilename($alb = $this->album->name, $filename, getImageParameters(array($size, $width, $height, $cropw, $croph, $cropx, $cropy, NULL, $thumbStandin, NULL, $thumbStandin, NULL, NULL, NULL)), $this->album->name); if (file_exists(SERVERCACHE . $cachefilename) && filemtime(SERVERCACHE . $cachefilename) > $this->filemtime) { return WEBPATH . '/' . CACHEFOLDER . pathurlencode(imgSrcURI($cachefilename)); } else { return getImageProcessorURI($args, $this->album->name, $filename); } } } else { $filename = $this->filename; $cachefilename = getImageCacheFilename($this->album->name, $filename, $args); if (file_exists(SERVERCACHE . $cachefilename) && filemtime(SERVERCACHE . $cachefilename) > $this->filemtime) { return WEBPATH . '/' . CACHEFOLDER . pathurlencode(imgSrcURI($cachefilename)); } else { return getImageProcessorURI($args, $this->album->name, $filename); } } }
/** * Returns an url to the password protected/watermarked current image * * @param object $image optional image object overrides the current image * @param string $disposal set to override the 'protect_full_image' option * @return string **/ function getProtectedImageURL($image = NULL, $disposal = NULL) { global $_zp_current_image; if ($disposal == 'No access') { return NULL; } if (is_null($image)) { if (!in_context(ZP_IMAGE)) { return false; } if (is_null($_zp_current_image)) { return false; } $image = $_zp_current_image; } $album = $image->getAlbum(); $wmt = $image->getWatermark(); if (!empty($wmt) || !($image->getWMUse() & WATERMARK_FULL)) { $wmt = NULL; } $args = array('FULL', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, $wmt, NULL); $cache_file = getImageCacheFilename($album->name, $image->filename, $args); $cache_path = SERVERCACHE . $cache_file; if (empty($disposal) && file_exists($cache_path)) { return WEBPATH . '/' . CACHEFOLDER . pathurlencode(imgSrcURI($cache_file)); } else { $params = '&q=' . getOption('full_image_quality'); $watermark_use_image = getWatermarkParam($image, WATERMARK_FULL); if (!empty($watermark_use_image)) { $params .= '&wmk=' . $watermark_use_image; } if ($disposal) { $params .= '&dsp=' . $disposal; } return WEBPATH . '/' . ZENFOLDER . '/full-image.php?a=' . urlencode($album->name) . '&i=' . urlencode($image->filename) . $params; } }
$process = false; } } // If the file hasn't been cached yet, create it. if ($process) { // setup standard image options from the album theme if it exists cacheImage($newfilename, $imgfile, $args, $allowWatermark, false, $theme); } if (!$debug) { // ... and redirect the browser to it. header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $fmt) . ' GMT'); header('Content-Type: image/jpeg'); header('Location: ' . FULLWEBPATH . substr(CACHEFOLDER, 0, -1) . pathurlencode(imgSrcURI($newfilename)), true, 301); exit; } else { echo "\n<p>Image: <img src=\"" . FULLWEBPATH . substr(CACHEFOLDER, 0, -1) . pathurlencode(imgSrcURI($newfilename)) . "\" /></p>"; } //////////////////////////////////////////////////////////////////////////////// function themeSetup($album) { // a real hack--but we need to conserve memory in i.php so loading the classes is out of the question. $theme = getOption('current_theme'); $folders = explode('/', str_replace('\\', '/', $album)); if (isset($_GET['album'])) { //it is an album thumb if (count($folders) <= 1) { // and the album is in the gallery return $theme; } } $uralbum = FilesystemToUTF8($folders[0]);