$xoopsModuleConfig['picture_width'] && $xoopsModuleConfig['make_intermediate'] && !file_exists($normal))
if (!resize_image($image, $normal, $xoopsModuleConfig['picture_width'], $xoopsModuleConfig['thumb_method']))
return false;
$image_filesize = filesize($image);
$total_filesize = $image_filesize + (file_exists($normal) ? filesize($normal) : 0) + filesize($thumb);
// Test if disk quota exceeded
if (!USER_IS_ADMIN && $USER_DATA['group_quota']) {
if (is_object($xoopsUser)) $quota_opt = "owner_id = '".USER_ID."'";
else $quota_opt = "ip = '".$HTTP_SERVER_VARS['REMOTE_ADDR']."'";
$result =$xoopsDB->query("SELECT sum(total_filesize) FROM ".$xoopsDB->prefix("xcgal_pictures")." WHERE $quota_opt");
$record = $xoopsDB->fetchArray($result);
$total_space_used = $record['sum(total_filesize)'];
//echo $total_space_used;
$xoopsDB->freeRecordSet($result);
if ($total_space_used + $total_filesize > ($USER_DATA['group_quota'] << 10)){
@unlink($image);
@unlink($normal);
@unlink($thumb);
$msg = strtr(_MD_QUOTA_EXCEEDED, array(
'[quota]' => ($USER_DATA['group_quota']),
'[space]' => ($total_space_used >>10)));
redirect_header('index.php',2,$msg);
}
}
// Test if picture requires approval
if (!$USER_DATA['priv_upl_need_approval'] && $category == FIRST_USER_CAT + USER_ID) {
$approved = 'YES';
} elseif (!$USER_DATA['pub_upl_need_approval']){
$approved = 'YES';
} else {
$approved = 'NO';
}
$PIC_NEED_APPROVAL = ($approved == 'NO');
// User ID is not recorded when in admin mode (ie. for batch uploads)
$user_id = USER_ID;
$user_name = USER_NAME;
$query = "INSERT INTO ".$xoopsDB->prefix("xcgal_pictures")." (pid, aid, filepath, filename, filesize, total_filesize, pwidth, pheight, mtime, ctime, owner_id, owner_name, title, caption, keywords, approved, user1, user2, user3, user4, ip) VALUES ('', '$aid', '".$myts->makeTboxData4Save($filepath)."', '".$myts->makeTboxData4Save($filename)."', '$image_filesize', '$total_filesize', '{$imagesize[0]}', '{$imagesize[1]}','".time()."', '".time()."', '$user_id','$user_name', '$title', '$caption', '$keywords', '$approved', '$user1', '$user2', '$user3', '$user4','".$HTTP_SERVER_VARS['REMOTE_ADDR']."')";
$result = $xoopsDB->queryf($query);
if ($approved == 'YES')
$picinID= $xoopsDB->getInsertId();
if ($approved == 'YES') $xoopsUser->incrementPost();
return $result;
}
define("GIS_GIF", 1);
define("GIS_JPG", 2);
define("GIS_PNG", 3);
/**
* resize_image()
*
* Create a file containing a resized image
*
* @param $src_file the source file
* @param $dest_file the destination file
* @param $new_size the size of the square within which the new image must fit
* @param $method the method used for image resizing
* @return 'true' in case of success
**/
function resize_image($src_file, $dest_file, $new_size, $method)
{
global $xoopsModuleConfig, $ERROR;
$imginfo = getimagesize($src_file);
if ($imginfo == null)
return false;
// GD can only handle JPG & PNG images
if ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && ($method == 'gd1' || $method == 'gd2')){
$ERROR = _MD_GD_FILE_TYPE_ERR;
return false;
}
// height/width
$srcWidth = $imginfo[0];
$srcHeight = $imginfo[1];
$ratio = max($srcWidth, $srcHeight) / $new_size;
$ratio = max($ratio, 1.0);
$destWidth = (int)($srcWidth / $ratio);
$destHeight = (int)($srcHeight / $ratio);
// Method for thumbnails creation
switch ($method) {
case "im" :
if (preg_match("#[A-Z]:|\\\\#Ai",__FILE__)){
// get the basedir, remove '/include'
$cur_dir = substr(dirname(__FILE__),0, -8);
$src_file = '"'.$cur_dir.'\\'.strtr($src_file, '/', '\\').'"';
$im_dest_file = str_replace('%', '%%', ('"'.$cur_dir.'\\'.strtr($dest_file, '/', '\\').'"'));
} else {
$src_file = escapeshellarg($src_file);
$im_dest_file = str_replace('%', '%%', escapeshellarg($dest_file));
}
$output = array();
$cmd = "{$xoopsModuleConfig['impath']}convert -quality {$xoopsModuleConfig['jpeg_qual']} {$xoopsModuleConfig['im_options']} -geometry {$destWidth}x{$destHeight} $src_file $im_dest_file";
exec ($cmd, $output, $retval);
if ($retval) {
$ERROR = _MD_IM_ERROR." $retval";
if ($xoopsModuleConfig['debug_mode']) {
// Re-execute the command with the backtit operator in order to get all outputs
// will not work is safe mode is enabled
$output = `$cmd 2>&1`;
$ERROR .= "