Skip to content
This repository
tree: 43bb311a80
Fetching contributors…

Cannot retrieve contributors at this time

file 277 lines (247 sloc) 8.301 kb
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
/**
*
* @package Icy Phoenix
* @version $Id$
* @copyright (c) 2008 Icy Phoenix
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

define('IMG_THUMB', true);
define('CT_SECLEVEL', 'MEDIUM');
$ct_ignoregvar = array('');
define('IN_ICYPHOENIX', true);
if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
include(IP_ROOT_PATH . 'common.' . PHP_EXT);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
// End session management

// Get general album information
include(ALBUM_MOD_PATH . 'album_common.' . PHP_EXT);
require(IP_ROOT_PATH . 'includes/class_image.' . PHP_EXT);

// ------------------------------------
// Check the request
// ------------------------------------

$pic_id = request_var('pic_id', '');
if (empty($pic_id))
{
image_no_thumbnail('no_thumb.jpg');
exit;
//die($lang['NO_PICS_SPECIFIED']);
//message_die(GENERAL_MESSAGE, $lang['NO_PICS_SPECIFIED']);
}
$pic_id = urldecode($pic_id);

// ------------------------------------
//Configuration Options
// ------------------------------------
/*
$config['show_pic_size_on_thumb'] = 1; //1 = Size Informations on Thumbnails; 0 = Size Informations on Thumbnails
$config['show_img_no_gd'] = 0;
$config['thumbnail_cache'] = 1;
$config['gd_version'] = 2;
$config['thumbnail_quality'] = 85;
$config['thumbnail_size'] = 400;
$config['thumbnail_posts'] = 1;
*/

// Mighty Gorgon: this code is reserved for generating extra thumbnail size on the fly...
$req_thumb_size = request_var('thumbnail_size', $config['thumbnail_size']);
$req_thumb_size = (($req_thumb_size > 600) || ($req_thumb_size < 30)) ? $config['thumbnail_size'] : $req_thumb_size;

$pic_fullpath = str_replace(array(' '), array('%20'), $pic_id);
$pic_id = str_replace('http://', '', str_replace('https://', '', $pic_id));
$pic_path[] = array();
$pic_path = explode('/', $pic_id);
$pic_filename = $pic_path[sizeof($pic_path) - 1];
$file_part = explode('.', strtolower($pic_filename));
$pic_filetype = $file_part[sizeof($file_part) - 1];
// Mighty Gorgon: this prefix is needed to not overwrite standard thumbnails with the ones generated with the extra size...
$pic_thumbnail_prefix = 'mid_' . (($req_thumb_size != $config['thumbnail_size']) ? ($req_thumb_size . '_') : '') . md5($pic_id);
$thumb_ext_array = array('gif', 'jpg', 'png');
$image_processed = false;
if (!in_array($pic_filetype, $thumb_ext_array))
{
$image_processed = true;
$pic_size = get_full_image_info($pic_fullpath);

if(empty($pic_size))
{
image_no_thumbnail('thumb_' . $pic_title_reg . '.' . $pic_filetype);
exit;
}

$pic_width = $pic_size['width'];
$pic_height = $pic_size['height'];
$pic_filetype = strtolower($pic_size['type']);

$pic_title = substr($pic_filename, 0, strlen($pic_filename) - strlen($pic_filetype) - 1);
$pic_title_reg = preg_replace('/[^A-Za-z0-9]+/', '_', $pic_title);
$pic_thumbnail = $pic_thumbnail_prefix . '.' . $pic_filetype;
}
else
{
$pic_title = substr($pic_filename, 0, strlen($pic_filename) - strlen($pic_filetype) - 1);
$pic_title_reg = preg_replace('/[^A-Za-z0-9]+/', '_', $pic_title);
$pic_thumbnail = $pic_thumbnail_prefix . '_' . $pic_filename;
}

$pic_thumbnail_fullpath = POSTED_IMAGES_THUMBS_PATH . $pic_thumbnail;

if (USERS_SUBFOLDERS_IMG == true)
{
if ((sizeof($pic_path) > 4) && (strpos($pic_id, $config['server_name']) !== false))
{
// Mighty Gorgon: this prefix is needed to not overwrite standard thumbnails with the ones generated with the extra size...
$pic_thumbnail_prefix = (($req_thumb_size != $config['thumbnail_size']) ? ('__' . $req_thumb_size . '__') : '');
// We need to add IP_ROOT_PATH because POSTED_IMAGES_PATH already includes it...
$pic_main_folder = IP_ROOT_PATH . $pic_path[sizeof($pic_path) - 4] . '/' . $pic_path[sizeof($pic_path) - 3] . '/';
if ($pic_main_folder == POSTED_IMAGES_PATH)
{
$pic_thumbnail_path = POSTED_IMAGES_THUMBS_PATH . $pic_path[sizeof($pic_path) - 2];
if (is_dir($pic_thumbnail_path))
{
$pic_thumbnail = $pic_thumbnail_prefix . $pic_filename;
$pic_thumbnail_fullpath = $pic_thumbnail_path . '/' . $pic_thumbnail;
}
else
{
$dir_creation = @mkdir($pic_thumbnail_path, 0777);
if ($dir_creation == true)
{
$pic_thumbnail = $pic_thumbnail_prefix . $pic_filename;
$pic_thumbnail_fullpath = $pic_thumbnail_path . '/' . $pic_thumbnail;
}
}
}
}
}

// This is needed to set up the new thumbnail size if requested via $_GET
$config['thumbnail_size'] = $req_thumb_size;

// --------------------------------
// Check thumbnail cache. If cache is available we will SEND & EXIT
// --------------------------------
// Do not use CACHE if cache=false parameter is passed through the url: posted_img_thumbnail.php?pic_id=XXX&cache=false
if(!empty($_GET['cache']))
{
$config['thumbnail_cache'] = ($_GET['cache'] == 'false') ? false : $config['thumbnail_cache'];
}

if(($config['thumbnail_cache'] == true) && file_exists($pic_thumbnail_fullpath))
{
image_output($pic_thumbnail_fullpath, $pic_title_reg, $pic_filetype, 'thumb_');
exit;
}

$server_path = create_server_url();
$pic_exists = false;
$pic_local = false;
if ((strpos($pic_fullpath, $server_path) !== false) || @file_exists($pic_fullpath))
{
$pic_local = true;
$pic_localpath = str_replace($server_path, '', $pic_fullpath);
if(@file_exists($pic_localpath))
{
// Mighty Gorgon - Are we sure that this won't cause other issues??? Test please...
$pic_fullpath = $pic_localpath;
$pic_exists = true;
}
else
{
if (@file_exists(array_shift(explode('?', basename($pic_localpath)))))
{
$pic_exists = true;
}
}
}

if(!$pic_exists && any_url_exists($pic_fullpath))
{
$pic_exists = true;
}

if(!$pic_exists)
{
image_no_thumbnail('thumb_' . $pic_title_reg . '.' . $pic_filetype);
exit;
}

if ($image_processed == false)
{
$pic_size = get_full_image_info($pic_fullpath, null, $pic_local);
if(empty($pic_size))
{
image_no_thumbnail('thumb_' . $pic_title_reg . '.' . $pic_filetype);
exit;
}

$pic_width = $pic_size['width'];
$pic_height = $pic_size['height'];
$pic_filetype = strtolower($pic_size['type']);
}

// ------------------------------------
// Send Thumbnail to browser
// ------------------------------------
if(($pic_width < $config['thumbnail_size']) && ($pic_height < $config['thumbnail_size']))
{
if($config['thumbnail_cache'] == true)
{
$copy_success = @copy($pic_fullpath, $pic_thumbnail_fullpath);
@chmod($pic_thumbnail_fullpath, 0777);
}
image_output($pic_fullpath, $pic_title_reg, $pic_filetype, '');
exit;
}
else
{
// --------------------------------
// Cache is empty. Try to re-generate!
// --------------------------------
if ($pic_width > $pic_height)
{
$thumbnail_width = $config['thumbnail_size'];
$thumbnail_height = $config['thumbnail_size'] * ($pic_height / $pic_width);
}
else
{
$thumbnail_height = $config['thumbnail_size'];
$thumbnail_width = $config['thumbnail_size'] * ($pic_width / $pic_height);
}

$Image = new ImgObj();

if ($pic_filetype == 'jpg')
{
$Image->ReadSourceFileJPG($pic_fullpath);
}
else
{
$Image->ReadSourceFile($pic_fullpath);
}

$Image->Resize($thumbnail_width, $thumbnail_height);

if( $config['show_pic_size_on_thumb'] == 1)
{
$dimension_string = intval($pic_width) . "x" . intval($pic_height) . "(" . intval(filesize($pic_fullpath)/1024) . "KB)";
$Image->Text($dimension_string);
}

if ($config['thumbnail_cache'] == true)
{
if ($pic_filetype == 'jpg')
{
$Image->SendToFileJPG($pic_thumbnail_fullpath, $album_config['thumbnail_quality']);
}
else
{
$Image->SendToFile($pic_thumbnail_fullpath, $album_config['thumbnail_quality']);
}
//$Image->SendToFile($pic_thumbnail_fullpath, $config['thumbnail_quality']);
//@chmod($pic_thumbnail_fullpath, 0777);
}

if ($pic_filetype == 'jpg')
{
$Image->SendToBrowserJPG($pic_title_reg, $pic_filetype, 'thumb_', '', $config['thumbnail_quality']);
}
else
{
$Image->SendToBrowser($pic_title_reg, $pic_filetype, 'thumb_', '', $config['thumbnail_quality']);
}

if ($Image == true)
{
$Image->Destroy();
exit;
}
else
{
$Image->Destroy();
image_no_thumbnail('thumb_' . $pic_title_reg . '.' . $pic_filetype);
exit;
}
}

?>
Something went wrong with that request. Please try again.