admin 发表于 2014-3-21 10:25:32

帝国CMS远程附件插件

第一步,下载附件到e\extend目录下

登陆后台后运行/e/extend/ecms_upftp/install按照提示进行安装
安装后的管理地址为/e/extend/ecms_upftp/admin.php
在这里填写对应的FTP信息生成配置文件

第二步,打开e/class/connect.php文件找到以下函数并替换。
//上传文件
function DoTranFile($file,$file_name,$file_type,$file_size,$classid,$ecms=0,$deftp=true){
global $public_r,$class_r,$doetran,$efileftp_fr;
global $ftpoff,$ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout,$ftpuppat,$ftpuptb;
//文件类型
$r=GetFiletype($file_name);
//文件名
$r=ReturnDoTranFilename($file_name,$classid);
$r=$r.$r;
//日期目录
$r=FormatFilePath($classid,$mynewspath,0);
$filepath=$r?$r.'/':$r;
//存放目录
$fspath=ReturnFileSavePath($classid);
$r=ECMS_PATH.$fspath['filepath'].$filepath;
//附件地址
$r=$fspath['fileurl'].$filepath.$r;
//缩图文件
$r=$r."small".$r;
//附件文件
$r=$r.$r;
$r=1;
//验证类型
if(CheckSaveTranFiletype($r))
{
if($doetran)
{
$r=0;
return $r;
}
else
{
printerror('TranFail','',$ecms);
}
}
if ($ftpoff && $deftp) {
$ftp =& new ftps();
$ftp->connect($ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout);
// 远程存放地址
$remote = $ftpuppat . str_replace(ECMS_PATH, "", $r);
if ($ftp->put($remote, $file)) {
//为false时,继续上传到网站附件目录,为true时,只上传到FTP上
if(!$ftpuptb){
return $r;
}
} else {
printerror2("FTP上传失败!","");
}
}
//上传文件
$cp=@move_uploaded_file($file,$r);
if(empty($cp))
{
if($doetran)
{
$r=0;
return $r;
}
else
{
printerror('TranFail','',$ecms);
}
}
DoChmodFile($r);
$r=(int)$file_size;
//FileServer
if($public_r['openfileserver'])
{
$efileftp_fr[]=$r['yname'];
}
return $r;
}


//远程保存
function DoTranUrl($url,$classid,$deftp=true){
global $public_r,$class_r,$ecms_config,$efileftp_fr;
global $ftpoff,$ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout,$ftpuppat,$ftpuptb;
//处理地址
$url=trim($url);
$url=str_replace(" ","%20",$url);
$r=1;
//附件地址
$r=$url;
//文件类型
$r=GetFiletype($url);
if(CheckSaveTranFiletype($r))
{
$r=0;
return $r;
}
//是否已上传的文件
$havetr=CheckNotSaveUrl($url);
if($havetr)
{
$r=0;
return $r;
}
//是否地址
if(!strstr($url,'://'))
{
$r=0;
return $r;
}
$string=ReadFiletext($url);
if(empty($string))//读取不了
{
$r=0;
return $r;
}
//文件名
$r=ReturnDoTranFilename($file_name,$classid);
$r=$r.$r;
//日期目录
$r=FormatFilePath($classid,$mynewspath,0);
$filepath=$r?$r.'/':$r;
//存放目录
$fspath=ReturnFileSavePath($classid);
$r=ECMS_PATH.$fspath['filepath'].$filepath;
//附件地址
$r=$fspath['fileurl'].$filepath.$r;
//缩图文件
$r=$r."small".$r;
//附件文件
$r=$r.$r;
WriteFiletext_n($r,$string);
$r=@filesize($r);
//返回类型
if(strstr($ecms_config['sets']['tranflashtype'],','.$r.','))
{
$r=2;
}
elseif(strstr($ecms_config['sets']['tranpicturetype'],','.$r.','))
{
$r=1;
}
elseif(strstr($ecms_config['sets']['mediaplayertype'],','.$r.',')||strstr($ecms_config['sets']['realplayertype'],','.$r.','))//多媒体
{
$r=3;
}
else
{
$r=0;
}
//FileServer
if($public_r['openfileserver'])
{
$efileftp_fr[]=$r['yname'];
}
//FTP上传
if ($ftpoff && $deftp) {
$ftp =& new ftps();
$ftp->connect($ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout);
// 远程存放地址
$remote = $ftpuppat . str_replace(ECMS_PATH, "", $r).$r['filename'];
if ($ftp->put($remote, $r["yname"])) {
if(!$ftpuptb){
DelFiletext($r["yname"]);
}
print_r($r);exit;
return $r;
} else {
printerror2("FTP上传失败!","");
}
}
return $r;
}

//删除附件
function DoDelFile($r){
global $class_r,$public_r,$efileftp_dr;
global $ftpoff,$ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout,$ftpuppat,$ftpuptb;
$path=$r['path']?$r['path'].'/':$r['path'];
$fspath=ReturnFileSavePath($r,$r);
$delfile=ECMS_PATH.$fspath['filepath'].$path.$r['filename'];
if ($ftpoff) {
$ftp =& new ftps();
$ftp->connect($ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout);
$ftp->f_delete($ftpuppat.$fspath['filepath'].$path.$r['filename']);
}
DelFiletext($delfile);
//FileServer
if($public_r['openfileserver'])
{
$efileftp_dr[]=$delfile;
}
}


第三步,打开e/class/functions.php,在 define('InEmpireCMSHfun',TRUE); 下面增加如下代码:

//引入FTP类
require_once ECMS_PATH . 'e/extend/ecms_upftp/ftps.class.php';
//引入配置文件
require_once ECMS_PATH . 'e/extend/ecms_upftp/setconfig.php';

第四步,同样是e/class/functions.php这个文件,找到如下函数并替换:


//截取图片
function CopyImg($text,$copyimg,$copyflash,$classid,$qz,$username,$theid,$cjid,$mark,$fstb=1){
global $empire,$public_r,$cjnewsurl,$navtheid,$dbtbpre;
global $ftpoff,$ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout,$ftpuppat,$ftpuptb;
if(empty($text))
{return "";}
$fstb=(int)$fstb;
if($copyimg)
{
$text=RepImg($text,$copyflash);
}
if($copyflash)
{$text=RepFlash($text,$copyflash);}
$exp1="[--copyimg--]";
$exp2="[/--copyimg--]";
$r=explode($exp1,$text);
for($i=1;$i<count($r);$i++)
{
$r1=explode($exp2,$r[$i]);
if(strstr($r1,"http://")||strstr($r1,"https://"))
{
$dourl=$r1;
}
else
{
//是否是本地址
if(!strstr($r1,"/")&&$cjnewsurl)
{
$fileqz_r=GetPageurlQz($cjnewsurl);
$fileqz=$fileqz_r['selfqz'];
$dourl=$fileqz.$r1;
}
else
{
$dourl=$qz.$r1;
}
}
if($mark){
$return_r=DoTranUrl($dourl,$classid,false);
}else{
$return_r=DoTranUrl($dourl,$classid);
}
$text=str_replace($exp1.$r1.$exp2,$return_r,$text);
if($return_r)
{
//记录数据库
$filetime=date("Y-m-d H:i:s");
//变量处理
$return_r=(int)$return_r;
$classid=(int)$classid;
$return_r=(int)$return_r;
$theid=(int)$theid;
$cjid=(int)$cjid;
eInsertFileTable($return_r,$return_r,$return_r,$username,$classid,''.$return_r,$return_r,$theid,$cjid,$public_r,0,0,$fstb);
//加水
if($mark&&$return_r==1)
{
GetMyMarkImg($return_r['yname']);
if ($ftpoff) {
$ftp =& new ftps();
$ftp->connect($ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout);
// 远程存放地址
$remote = $ftpuppat . str_replace(ECMS_PATH, "", $return_r).$return_r['filename'];
if ($ftp->put($remote, $return_r["yname"])) {
//删除图片
if(!$ftpuptb){
DelFiletext($return_r["yname"]);
}
} else {
printerror2("FTP上传失败!","");
}
}
}
}
}
return $text;
}


以下功能暂未完善,


第五步,打开e/admin/ecmseditor/cropimg/CropImage.php 这个文件,找到 if(!file_exists($big_image_name))把下面一行
printerror('NotCropImage','history.go(-1)');
删除或者前面加2个反斜杠。



第六步,打开e/admin/ecmseditor/cropimg/copyimgfun.php这个文件,全部替换以下代码:


<?php
//裁剪图片
function DoCropImage($add,$userid,$username){
global $empire,$dbtbpre,$public_r,$class_r,$tranpicturetype,$efileftp_fr,$efileftp_dr;
global $ftpoff,$ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout,$ftpuppat,$ftpuptb;
$ftp =& new ftps();
$ftp->connect($ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout);
//参数处理
$pic_x=(int)$add['pic_x'];
$pic_y=(int)$add['pic_y'];
$pic_w=(int)$add['pic_w'];
$pic_h=(int)$add['pic_h'];
$doing=(int)$add['doing'];
$fileid=(int)$add['fileid'];
$filepass=(int)$add['filepass'];
//取得文件地址
if(empty($fileid))
{
printerror('NotCropImage','history.go(-1)');
}
$filer=$empire->fetch1("select fileid,path,filename,classid,fpath,no from {$dbtbpre}enewsfile where fileid='$fileid'");
if(empty($filer['fileid']))
{
printerror('NotCropImage','history.go(-1)');
}
$path=$filer['path']?$filer['path'].'/':$filer['path'];
$fspath=ReturnFileSavePath($filer['classid'],$filer['fpath']);
$big_image_name=$fspath['fileurl'].$path.$filer['filename'];
$up=DoTranUrlimg($big_image_name,$filer);
$big_image_name=$up['yname'];
if(!file_exists($big_image_name))
{
printerror('NotCropImage','history.go(-1)');
}
$filetype=GetFiletype($filer['filename']);//取得文件类型
if(!strstr($tranpicturetype,','.$filetype.','))
{
printerror('CropImageFiletypeFail','history.go(-1)');
}
//目标图片
$new_datepath=FormatFilePath($filer['classid'],'',0);
$new_path=$new_datepath?$new_datepath.'/':$new_datepath;
$new_insertfile=ReturnDoTranFilename($filer['filename'],0);
$new_fspath=ReturnFileSavePath($filer['classid']);
$new_savepath=ECMS_PATH.$new_fspath['filepath'].$new_path;
$new_name=$new_savepath.$new_insertfile;
//处理图片
$returnr['file']='';
$returnr['filetype']='';
if($temp_img_type = @getimagesize($big_image_name)) {preg_match('/\/(+)$/i', $temp_img_type, $tpn); $img_type = $tpn;}
else {preg_match('/\.(+)$/i', $big_image_name, $tpn); $img_type = $tpn;}
$all_type = array(
"jpg"   => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg", "exn"=>".jpg"),
"gif"   => array("create"=>"ImageCreateFromGIF" , "output"=>"imagegif"   , "exn"=>".gif"),
"jpeg"=> array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg", "exn"=>".jpg"),
"png"   => array("create"=>"imagecreatefrompng" , "output"=>"imagepng"   , "exn"=>".png"),
"wbmp"=> array("create"=>"imagecreatefromwbmp", "output"=>"image2wbmp" , "exn"=>".wbmp")
);
$func_create = $all_type[$img_type]['create'];
if(empty($func_create) or !function_exists($func_create))
{
printerror('CropImageFiletypeFail','history.go(-1)');
}
//输出
$func_output = $all_type[$img_type]['output'];
$func_exname = $all_type[$img_type]['exn'];
if(($func_exname=='.gif'||$func_exname=='.png'||$func_exname=='.wbmp')&&!function_exists($func_output))
{
$func_output='imagejpeg';
$func_exname='.jpg';
}
$big_image   = $func_create($big_image_name);
$big_width   = imagesx($big_image);
$big_height= imagesy($big_image);
if(!$big_width||!$big_height||$big_width<10||$big_height<10)
{
printerror('CropImageFilesizeFail','history.go(-1)');
}
if(function_exists("imagecopyresampled"))
{
$temp_image=imagecreatetruecolor($pic_w,$pic_h);
imagecopyresampled($temp_image, $big_image, 0, 0, $pic_x, $pic_y, $pic_w, $pic_h, $pic_w, $pic_h);
}
else
{
$temp_image=imagecreate($pic_w,$pic_h);
imagecopyresized($temp_image, $big_image, 0, 0, $pic_x, $pic_y, $pic_w, $pic_h, $pic_w, $pic_h);
}
$func_output($temp_image, $new_name.$func_exname);
ImageDestroy($big_image);
ImageDestroy($temp_image);
$insert_file=$new_name.$func_exname;
$insert_filename=$new_insertfile.$func_exname;
if(file_exists($insert_file))
{
//删除原图
if(!$doing)
{
$empire->query("delete from {$dbtbpre}enewsfile where fileid='$fileid'");
DelFiletext($big_image_name);
if($ftpoff){
$ftp->f_delete($ftpuppat.$fspath['filepath'].$path.$filer['filename']);
}
//FileServer
if($public_r['openfileserver'])
{
$efileftp_dr[]=$big_image_name;
}
}
//写入数据库
$no=''.$filer['no'];
$filesize=filesize($insert_file);
$filesize=(int)$filesize;
$classid=(int)$filer['classid'];
$type=1;
$filetime=date("Y-m-d H:i:s");
$sql=$empire->query("insert into {$dbtbpre}enewsfile(filename,filesize,adduser,path,filetime,classid,no,type,id,cjid,fpath) values('$insert_filename','$filesize','$username','$new_datepath','$filetime','$classid','$no','$type','$filepass','$filepass','$public_r');");
//FileServer
if($public_r['openfileserver'])
{
$efileftp_fr[]=$insert_file;
}
//FTP上传
if($ftpoff){
$remote = $ftpuppat.$fspath['filepath'].$new_datepath."/".$insert_filename;
$ftp->put($remote, $insert_file);
if(!$ftpuptb){
DelFiletext($insert_file);
}
}
}
echo"<script>opener.ReloadChangeFilePage();window.close();</script>";
db_close();
exit();
}
//保存远程图片
function DoTranUrlimg($url,$file=array()){
$classid = $file['classid'];
global $public_r,$class_r,$tranpicturetype,$tranflashtype,$mediaplayertype,$realplayertype,$efileftp_fr;
global $ftpoff,$ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout,$ftpuppat,$ftpuptb;
//处理地址
$url=trim($url);
$url=str_replace(" ","%20",$url);
$r=1;
//附件地址
$r=$url;
//文件类型
$r=GetFiletype($url);
if(CheckSaveTranFiletype($r))
{
$r=1;
return $r;
}
$string=ReadFiletext($url);
if(empty($string))//读取不了
{
$r=3;
return $r;
}
//文件名
$r=ReturnDoTranFilename($file_name,$classid);
$r=$r.$r;
//日期目录
$r=FormatFilePath($classid,$mynewspath,0);
$filepath=$r?$r.'/':$r;
//存放目录
$fspath=ReturnFileSavePath($classid);
$r=ECMS_PATH.$fspath['filepath'].$filepath;
//附件地址
$r=$fspath['fileurl'].$filepath.$r;
//缩图文件
$r=$r."small".$r;
//附件文件
$r=$r.$r;
WriteFiletext_n($r,$string);
$r=@filesize($r);
//返回类型
if(strstr($tranflashtype,','.$r.','))
{
$r=2;
}
elseif(strstr($tranpicturetype,','.$r.','))
{
$r=1;
}
elseif(strstr($mediaplayertype,','.$r.',')||strstr($realplayertype,','.$r.','))//多媒体
{
$r=3;
}
else
{
$r=0;
}
//FileServer
if($public_r['openfileserver'])
{
$efileftp_fr[]=$r['yname'];
}
return $r;
}
?>


至此即可,此版本暂未做已上传附件的裁剪处理等

插件演示截图:



附件下载:



gcdown 发表于 2020-2-3 21:42:58

哪里可以赚贡献分
页: [1]
查看完整版本: 帝国CMS远程附件插件