improve admin user profile + image hosting

This commit is contained in:
xiaomlove
2024-12-29 22:16:41 +08:00
parent f146a654c2
commit 5a9f1f1017
40 changed files with 22110 additions and 456 deletions
+188 -171
View File
@@ -58,183 +58,200 @@ if ($Attach->enable_attachment())
if (in_array($ext, $img_ext))
$isimage = true;
else $isimage = false;
if ($savedirectorytype_attachment == 'onedir')
$savepath = "";
elseif ($savedirectorytype_attachment == 'monthdir')
$savepath = date("Ym")."/";
elseif ($savedirectorytype_attachment == 'daydir')
$savepath = date("Ymd")."/";
$filemd5 = md5_file($file['tmp_name']);
$filename = date("YmdHis").$filemd5;
$file_location = make_folder($savedirectory_attachment."/", $savepath) . $filename;
do_log("file_location: $file_location");
$db_file_location = $savepath.$filename;
$abandonorig = false;
$hasthumb = false;
$width = 0;
if ($isimage) //the uploaded file is a image
{
$maycreatethumb = false;
$stop = false;
$imagesize = getimagesize($file['tmp_name']);
if ($imagesize){
$height = $imagesize[1];
$width = $imagesize[0];
$it = $imagesize[2];
if ($it != 1 || !$Attach->is_gif_ani($file['tmp_name'])){ //if it is an animation GIF, stop creating thumbnail and adding watermark
if ($thumbnailtype_attachment != 'no') //create thumbnail for big image
{
//determine the size of thumbnail
if ($altsize == 'yes'){
$targetwidth = $altthumbwidth_attachment;
$targetheight = $altthumbheight_attachment;
}
else
{
$targetwidth = $thumbwidth_attachment;
$targetheight = $thumbheight_attachment;
}
$hscale=$height/$targetheight;
$wscale=$width/$targetwidth;
$scale=($hscale < 1 && $wscale < 1) ? 1 : (( $hscale > $wscale) ? $hscale : $wscale);
$newwidth=floor($width/$scale);
$newheight=floor($height/$scale);
if ($scale != 1){ //thumbnail is needed
if ($it==1)
$orig=@imagecreatefromgif($file["tmp_name"]);
elseif ($it == 2)
$orig=@imagecreatefromjpeg($file["tmp_name"]);
else
$orig=@imagecreatefrompng($file["tmp_name"]);
if ($orig && !$stop)
{
$thumb = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($thumb, $orig, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
if ($thumbnailtype_attachment == 'createthumb'){
$hasthumb = true;
imagejpeg($thumb, $file_location.".".$ext.".thumb.jpg", $thumbquality_attachment);
}
elseif ($thumbnailtype_attachment == 'resizebigimg'){
$ext = "jpg";
$filetype = "image/jpeg";
$it = 2;
$height = $newheight;
$width = $newwidth;
$maycreatethumb = true;
$abandonorig = true;
}
}
}
}
$watermarkpos = $watermarkpos_attachment;
if ($watermarkpos != 'no' && !$stop) //add watermark to image
{
if ($width > $watermarkwidth_attachment && $height > $watermarkheight_attachment)
{
if ($abandonorig)
{
$resource = $thumb;
}
else
{
$resource=imagecreatetruecolor($width,$height);
if ($it==1)
$resource_p=@imagecreatefromgif($file["tmp_name"]);
elseif ($it==2)
$resource_p=@imagecreatefromjpeg($file["tmp_name"]);
else
$resource_p=@imagecreatefrompng($file["tmp_name"]);
imagecopy($resource, $resource_p, 0, 0, 0, 0, $width, $height);
}
$watermark = imagecreatefrompng('pic/watermark.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
//the position of the watermark
if ($watermarkpos == 'random')
$watermarkpos = mt_rand(1, 9);
switch ($watermarkpos)
{
case 1: {
$wmx = 5;
$wmy = 5;
break;
}
case 2: {
$wmx = ($width-$watermark_width)/2;
$wmy = 5;
break;
}
case 3: {
$wmx = $width-$watermark_width-5;
$wmy = 5;
break;
}
case 4: {
$wmx = 5;
$wmy = ($height-$watermark_height)/2;
break;
}
case 5: {
$wmx = ($width-$watermark_width)/2;
$wmy = ($height-$watermark_height)/2;
break;
}
case 6: {
$wmx = $width-$watermark_width-5;
$wmy = ($height-$watermark_height)/2;
break;
}
case 7: {
$wmx = 5;
$wmy = $height-$watermark_height-5;
break;
}
case 8: {
$wmx = ($width-$watermark_width)/2;
$wmy = $height-$watermark_height-5;
break;
}
case 9: {
$wmx = $width-$watermark_width-5;
$wmy = $height-$watermark_height-5;
break;
}
}
$width = $height = 0;
$imagesize = [];
if ($isimage) {
$imagesize = getimagesize($file['tmp_name']);
$height = $imagesize[1];
$width = $imagesize[0];
}
//get driver
$storageDriver = get_setting("image_hosting.driver", "local");
if ($storageDriver == "local" || !$isimage) {
if ($savedirectorytype_attachment == 'onedir')
$savepath = "";
elseif ($savedirectorytype_attachment == 'monthdir')
$savepath = date("Ym")."/";
elseif ($savedirectorytype_attachment == 'daydir')
$savepath = date("Ymd")."/";
$filemd5 = md5_file($file['tmp_name']);
$filename = date("YmdHis").$filemd5;
$file_location = make_folder($savedirectory_attachment."/", $savepath) . $filename;
do_log("file_location: $file_location");
$db_file_location = $savepath.$filename;
$abandonorig = false;
$hasthumb = false;
if ($isimage) //the uploaded file is a image
{
$maycreatethumb = false;
$stop = false;
if ($imagesize){
$it = $imagesize[2];
if ($it != 1 || !$Attach->is_gif_ani($file['tmp_name'])){ //if it is an animation GIF, stop creating thumbnail and adding watermark
if ($thumbnailtype_attachment != 'no') //create thumbnail for big image
{
//determine the size of thumbnail
if ($altsize == 'yes'){
$targetwidth = $altthumbwidth_attachment;
$targetheight = $altthumbheight_attachment;
}
else
{
$targetwidth = $thumbwidth_attachment;
$targetheight = $thumbheight_attachment;
}
$hscale=$height/$targetheight;
$wscale=$width/$targetwidth;
$scale=($hscale < 1 && $wscale < 1) ? 1 : (( $hscale > $wscale) ? $hscale : $wscale);
$newwidth=floor($width/$scale);
$newheight=floor($height/$scale);
if ($scale != 1){ //thumbnail is needed
if ($it==1)
$orig=@imagecreatefromgif($file["tmp_name"]);
elseif ($it == 2)
$orig=@imagecreatefromjpeg($file["tmp_name"]);
else
$orig=@imagecreatefrompng($file["tmp_name"]);
if ($orig && !$stop)
{
$thumb = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($thumb, $orig, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
if ($thumbnailtype_attachment == 'createthumb'){
$hasthumb = true;
imagejpeg($thumb, $file_location.".".$ext.".thumb.jpg", $thumbquality_attachment);
}
elseif ($thumbnailtype_attachment == 'resizebigimg'){
$ext = "jpg";
$filetype = "image/jpeg";
$it = 2;
$height = $newheight;
$width = $newwidth;
$maycreatethumb = true;
$abandonorig = true;
}
}
}
}
$watermarkpos = $watermarkpos_attachment;
if ($watermarkpos != 'no' && !$stop) //add watermark to image
{
if ($width > $watermarkwidth_attachment && $height > $watermarkheight_attachment)
{
if ($abandonorig)
{
$resource = $thumb;
}
else
{
$resource=imagecreatetruecolor($width,$height);
if ($it==1)
$resource_p=@imagecreatefromgif($file["tmp_name"]);
elseif ($it==2)
$resource_p=@imagecreatefromjpeg($file["tmp_name"]);
else
$resource_p=@imagecreatefrompng($file["tmp_name"]);
imagecopy($resource, $resource_p, 0, 0, 0, 0, $width, $height);
}
$watermark = imagecreatefrompng('pic/watermark.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
//the position of the watermark
if ($watermarkpos == 'random')
$watermarkpos = mt_rand(1, 9);
switch ($watermarkpos)
{
case 1: {
$wmx = 5;
$wmy = 5;
break;
}
case 2: {
$wmx = ($width-$watermark_width)/2;
$wmy = 5;
break;
}
case 3: {
$wmx = $width-$watermark_width-5;
$wmy = 5;
break;
}
case 4: {
$wmx = 5;
$wmy = ($height-$watermark_height)/2;
break;
}
case 5: {
$wmx = ($width-$watermark_width)/2;
$wmy = ($height-$watermark_height)/2;
break;
}
case 6: {
$wmx = $width-$watermark_width-5;
$wmy = ($height-$watermark_height)/2;
break;
}
case 7: {
$wmx = 5;
$wmy = $height-$watermark_height-5;
break;
}
case 8: {
$wmx = ($width-$watermark_width)/2;
$wmy = $height-$watermark_height-5;
break;
}
case 9: {
$wmx = $width-$watermark_width-5;
$wmy = $height-$watermark_height-5;
break;
}
}
imagecopy($resource, $watermark, $wmx, $wmy, 0, 0, $watermark_width, $watermark_height);
if ($it==1)
imagegif($resource, $file_location.".".$ext);
elseif ($it==2)
imagejpeg($resource, $file_location.".".$ext, $watermarkquality_attachment);
else
imagepng($resource, $file_location.".".$ext);
$filesize = filesize($file_location.".".$ext);
$maycreatethumb = false;
$abandonorig = true;
}
}
if ($maycreatethumb){ // if no watermark is added, create the thumbnail now for the above resized image.
imagejpeg($thumb, $file_location.".".$ext, $thumbquality_attachment);
$filesize = filesize($file_location.".".$ext);
}
}
}
else $warning = $lang_attachment['text_invalid_image_file'];
}
if (!$abandonorig){
if(!move_uploaded_file($file["tmp_name"], $file_location.".".$ext))
$warning = $lang_attachment['text_cannot_move_file'];
}
imagecopy($resource, $watermark, $wmx, $wmy, 0, 0, $watermark_width, $watermark_height);
if ($it==1)
imagegif($resource, $file_location.".".$ext);
elseif ($it==2)
imagejpeg($resource, $file_location.".".$ext, $watermarkquality_attachment);
else
imagepng($resource, $file_location.".".$ext);
$filesize = filesize($file_location.".".$ext);
$maycreatethumb = false;
$abandonorig = true;
}
}
if ($maycreatethumb){ // if no watermark is added, create the thumbnail now for the above resized image.
imagejpeg($thumb, $file_location.".".$ext, $thumbquality_attachment);
$filesize = filesize($file_location.".".$ext);
}
}
}
else $warning = $lang_attachment['text_invalid_image_file'];
}
if (!$abandonorig){
if(!move_uploaded_file($file["tmp_name"], $file_location.".".$ext))
$warning = $lang_attachment['text_cannot_move_file'];
}
$url = $httpdirectory_attachment."/".$db_file_location . ".$ext";
if ($hasthumb) {
$url .= ".thumb.jpg";
}
} else {
try {
$driver = \Nexus\Attachment\Storage::getDriver();
$location = $driver->uploadGetLocation($file["tmp_name"]);
$db_file_location = substr($location, 0, -1*strlen($ext)-1);
$url = $driver->getImageUrl($location);
} catch (\Exception $exception) {
do_log("upload failed: " . $exception->getMessage() . $exception->getTraceAsString(), 'error');
$warning = $exception->getMessage();
}
}
if (!$warning) //insert into database and add code to editor
{
$dlkey = md5($db_file_location.".".$ext);
sql_query("INSERT INTO attachments (userid, width, added, filename, filetype, filesize, location, dlkey, isimage, thumb) VALUES (".$CURUSER['id'].", ".$width.", ".sqlesc(date("Y-m-d H:i:s")).", ".sqlesc($origfilename).", ".sqlesc($filetype).", ".$filesize.", ".sqlesc($db_file_location.".".$ext).", ".sqlesc($dlkey).", ".($isimage ? 1 : 0).", ".($hasthumb ? 1 : 0).")") or sqlerr(__FILE__, __LINE__);
sql_query("INSERT INTO attachments (userid, width, added, filename, filetype, filesize, location, dlkey, isimage, thumb, driver) VALUES (".$CURUSER['id'].", ".$width.", ".sqlesc(date("Y-m-d H:i:s")).", ".sqlesc($origfilename).", ".sqlesc($filetype).", ".$filesize.", ".sqlesc($db_file_location.".".$ext).", ".sqlesc($dlkey).", ".($isimage ? 1 : 0).", ".($hasthumb ? 1 : 0). "," .sqlesc($storageDriver) . ")") or sqlerr(__FILE__, __LINE__);
$count_left--;
if (!empty($_REQUEST['callback_func']) && preg_match('/^preview_custom_field_image_\d+$/', $_REQUEST['callback_func'])) {
$url = $httpdirectory_attachment."/".$db_file_location . ".$ext";
if ($hasthumb) {
$url .= ".thumb.jpg";
}
echo sprintf('<script type="text/javascript">parent.%s("%s", "%s")</script>', $_REQUEST['callback_func'], $dlkey, $url);
} else {
echo("<script type=\"text/javascript\">parent.tag_extimage('". "[attach]" . $dlkey . "[/attach]" . "');</script>");
+1 -1
View File
@@ -120,7 +120,7 @@ if ($CURUSER['id'] == $user['id'] || user_can('cruprfmanage'))
<table width="100%" border="1" cellspacing="0" cellpadding="5">
<?php
$userIdDisplay = $user['id'];
$userManageSystemUrl = sprintf('%s/%s/users/%s',getSchemeAndHttpHost(), nexus_env('FILAMENT_PATH', 'nexusphp'), $user['id']);
$userManageSystemUrl = sprintf('%s/%s/user/users/%s',getSchemeAndHttpHost(), nexus_env('FILAMENT_PATH', 'nexusphp'), $user['id']);
$userManageSystemText = sprintf('<a href="%s" target="_blank" class="altlink">%s</a>', $userManageSystemUrl, $lang_functions['text_management_system']);
$migratedHelp = sprintf($lang_userdetails['change_field_value_migrated'], $userManageSystemText);
if (user_can('prfmanage') && $user["class"] < get_user_class()) {
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+10018 -14
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+2 -1
View File
@@ -1 +1,2 @@
{"/livewire.js":"/livewire.js?id=de3fca26689cb5a39af4"}
{"/livewire.js":"38dc8241"}