4 and stripos($set['tnlTypes'],strtolower(substr($fName,-3))) !== false) {
if (!empty($tnSearch) and stripos(substr($fName,0,-4),$tnSearch) === false) { continue; }
$fileList[] = array(
'name' => $fName,
'name-id' => $fName[4] != '~' ? $fName : substr($fName,5),
'size' => filesize($path.$fName),
'lastmod' => filemtime($path.$fName)
);
}
}
$mulFactor = $order == 'a' ? 1 : -1;
uasort($fileList,function($a,$b) use($sort,$mulFactor) {return (($a[$sort] > $b[$sort]) ? 1 : -1) * $mulFactor;}); //sort on $sort-field
return $fileList;
}
function showTnails($userID,$myTnails,$mayDel) {
global $xx, $tnPath, $tnailList, $delLimit;
$nofTnails = 0;
foreach($tnailList as $tnail) {
if (substr($tnail['name'],0,5) == str_pad($userID,4,'0',STR_PAD_LEFT).'~') { //my thumbnails
if (!$myTnails) { continue; }
} else { //other thumbnails
if ($myTnails) { continue; }
}
$fullName = str_replace(' ','%20',$tnail['name']); //deal with spaces
$tnID = ($myTnails ? 'mTn' : 'oTn').++$nofTnails;
$stH = dbQuery("SELECT `sDate`,`eDate`,`rType`,`rUntil`
FROM `events`
WHERE status >= 0 AND `text1` LIKE '%{$fullName}%' OR `text2` LIKE '%{$fullName}%' OR `text3` LIKE '%{$fullName}%'");
$lastUsed = '0000-00-00';
while ($row = $stH->fetch(PDO::FETCH_ASSOC)) {
if ($row['rType'] > 0 and $row['rUntil'][0] == '9') { $lastUsed = '9999-99-99'; break; }
if ($row['rType'] > 0 and $row['rUntil'][0] != '9' and $lastUsed < $row['rUntil']) { $lastUsed = $row['rUntil']; }
if ($row['eDate'][0] != '9' and $lastUsed < $row['eDate']) { $lastUsed = $row['eDate']; }
if ($lastUsed < $row['sDate']) { $lastUsed = $row['sDate']; }
}
$stH = null;
$delX = '';
if ($mayDel and $lastUsed[0] != '9' and ($lastUsed[0] == '0' or $lastUsed < $delLimit)) { //may delete thumbnail
$delX = "\n❌";
}
$lastUsed = $lastUsed[0] == '0' ? $xx['tns_not_used'] : ($lastUsed[0] == '9' ? $xx['tns_infinite'] : IDtoDD($lastUsed));
echo "
\n";
}
if ($nofTnails == 0) {
echo $xx['none'];
}
}
/* image resize function
$file - file name to resize
$width - new image width
$height - new image height
$output - name of the new file (include path if needed)
$deleteOriginal - if true the original image will be deleted
$quality - enter 1-100 (100 is best quality) default is 100
*/
function resize_image($file,$width,$height,$output,$deleteOriginal = true,$quality = 100) {
//setting defaults and meta
list($widthOld, $heightOld, $imageType) = getimagesize($file);
//calculating proportionality
if ($width == 0) $factor = $height/$heightOld;
elseif ($height == 0) $factor = $width/$widthOld;
else $factor = min($width / $widthOld, $height / $heightOld);
$newWidth = round($widthOld * $factor);
$newHeight = round($heightOld * $factor);
//loading image to memory
switch ( $imageType ) {
case IMAGETYPE_JPEG: $image = imagecreatefromjpeg($file); break;
case IMAGETYPE_GIF: $image = imagecreatefromgif($file); break;
case IMAGETYPE_PNG: $image = imagecreatefrompng($file); break;
default: return false;
}
//this is the resizing/resampling/transparency-preserving magic
$imageResized = imagecreatetruecolor($newWidth,$newHeight);
if (($imageType == IMAGETYPE_GIF) || ($imageType == IMAGETYPE_PNG)) {
$transparency = imagecolortransparent($image);
$palletsize = imagecolorstotal($image);
if ($transparency >= 0 && $transparency < $palletsize) {
$transparentColor = imagecolorsforindex($image,$transparency);
$transparency = imagecolorallocate($imageResized,$transparentColor['red'],$transparentColor['green'],$transparentColor['blue']);
imagefill($imageResized,0,0,$transparency);
imagecolortransparent($imageResized, $transparency);
}
elseif ($imageType == IMAGETYPE_PNG) {
imagealphablending($imageResized, false);
$color = imagecolorallocatealpha($imageResized,0,0,0,127);
imagefill($imageResized,0,0,$color);
imagesavealpha($imageResized,true);
}
}
imagecopyresampled($imageResized,$image,0,0,0,0,$newWidth,$newHeight,$widthOld,$heightOld);
//delete original, if needed
if ($deleteOriginal) {
@unlink($file);
}
//writing image according to type to the output destination and image quality
switch ($imageType) {
case IMAGETYPE_GIF: imagegif($imageResized,$output); break;
case IMAGETYPE_JPEG: imagejpeg($imageResized,$output,$quality); break;
case IMAGETYPE_PNG:
$quality = 9 - (int)((0.9*$quality)/10.0);
imagepng($imageResized,$output,$quality);
break;
default: return false;
}
return true;
}
//here it starts
//get POST arguments
$tnSort = isset($_POST['tnSort']) ? $_POST['tnSort'] : 'n';
$tnOrder = isset($_POST['tnOrder']) ? $_POST['tnOrder'] : 'a';
$tnSearch = isset($_POST['tnSearch']) ? trim($_POST['tnSearch']) : '';
$tnOwrite = !empty($_POST['tnOwrite']) ? 1 : 0;
//init
$tnPath = './thumbnails/';
$nMsg = $eMsg = ''; //notice, error messages
$mayMng = $usr['tnPrivs'][0] == '2';
$sortOn = $tnSort == 'n' ? 'name-id' : 'lastmod';
$delLimit = date('Y-m-d',$nowTS-($set['tnlDelDays'] * 86400)); //date after which no delete allowed
//thumbnail to delete?
if (isset($_POST['delTn']) and file_exists("{$tnPath}{$_POST['delTn']}")) {
unlink("{$tnPath}{$_POST['delTn']}");
$tnail = $_POST['delTn'][4] == '~' ? substr($_POST['delTn'],5) : $_POST['delTn'];
$nMsg .= "{$xx['tns_tnail']} {$tnail} {$xx['tns_deleted']}
";
}
//thumbnails to upload?
if (!empty($_FILES['uplTnl'])) { //if file(s) uploaded, save files to thumbnails folder
$nrUpload = 0;
foreach($_FILES['uplTnl']['name'] as $k => $fName) {
if ($fName) {
if ($_FILES['uplTnl']['error'][$k] > 1) { $eMsg .= "{$fName} {$xx['tns_upload_error']}
"; continue; }
if (stripos($set['tnlTypes'],substr($fName,-4)) === false) { $eMsg .= "{$fName} {$xx['tns_no_valid_img']}
"; continue; }
if ($_FILES['uplTnl']['error'][$k] == 1 or $_FILES['uplTnl']['size'][$k] > ($set['maxUplSize'] * 1048570)) { $eMsg .= "{$fName} {$xx['tns_file_too_large']}
"; continue; } //max. $set['maxUplSize'] MB
$tnName = $fName[4] == '~' ? substr($fName,5) : $fName; //remove possible userID prefix
$tnfName = str_pad($usr['ID'],4,'0',STR_PAD_LEFT).'~'.$tnName; //add current userID prefix
if ($tnOwrite or !file_exists("./thumbnails/{$tnfName}")) {
move_uploaded_file($_FILES['uplTnl']['tmp_name'][$k],"./thumbnails/{$tnfName}");
$nrUpload++;
$tnSize = getimagesize("./thumbnails/{$tnfName}");
if ($tnSize[0] > $set['tnlMaxW'] or $tnSize[1] > $set['tnlMaxH']) { //width & height
$result = resize_image("./thumbnails/{$tnfName}",$set['tnlMaxW'],$set['tnlMaxH'],"./thumbnails/{$tnfName}"); //resize image
if ($result) {
$nMsg .= "{$tnName} {$xx['tns_resized']}
";
} else {
$eMsg .= "{$tnName} {$xx['tns_resize_error']}
";
}
}
} else {
$nMsg .= "{$tnName} {$xx['tns_tn_exists']}
";
}
}
}
if ($nrUpload > 0) {
$nMsg .= "{$nrUpload} {$xx['tns_tn_uploaded']}
";
}
}
//get all thumbnails
$tnailList = getTnList($tnPath,$sortOn,$tnOrder);
//load page
echo "\n";
?>