PHPIN.NET

 找回密码
 立即注册
查看: 11942|回复: 1

[7.X版] 帝国CMS远程附件插件

[复制链接]

469

主题

31

回帖

5507

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
5507
发表于 2014-3-21 10:25:32 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

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

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

第二步,打开e/class/connect.php文件找到以下函数并替换。
  1. //上传文件
  2. function DoTranFile($file,$file_name,$file_type,$file_size,$classid,$ecms=0,$deftp=true){
  3. global $public_r,$class_r,$doetran,$efileftp_fr;
  4. global $ftpoff,$ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout,$ftpuppat,$ftpuptb;
  5. //文件类型
  6. $r[filetype]=GetFiletype($file_name);
  7. //文件名
  8. $r[insertfile]=ReturnDoTranFilename($file_name,$classid);
  9. $r[filename]=$r[insertfile].$r[filetype];
  10. //日期目录
  11. $r[filepath]=FormatFilePath($classid,$mynewspath,0);
  12. $filepath=$r[filepath]?$r[filepath].'/':$r[filepath];
  13. //存放目录
  14. $fspath=ReturnFileSavePath($classid);
  15. $r[savepath]=ECMS_PATH.$fspath['filepath'].$filepath;
  16. //附件地址
  17. $r[url]=$fspath['fileurl'].$filepath.$r[filename];
  18. //缩图文件
  19. $r[name]=$r[savepath]."small".$r[insertfile];
  20. //附件文件
  21. $r[yname]=$r[savepath].$r[filename];
  22. $r[tran]=1;
  23. //验证类型
  24. if(CheckSaveTranFiletype($r[filetype]))
  25. {
  26. if($doetran)
  27. {
  28. $r[tran]=0;
  29. return $r;
  30. }
  31. else
  32. {
  33. printerror('TranFail','',$ecms);
  34. }
  35. }
  36. if ($ftpoff && $deftp) {
  37. $ftp =& new ftps();
  38. $ftp->connect($ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout);
  39. // 远程存放地址
  40. $remote = $ftpuppat . str_replace(ECMS_PATH, "", $r[yname]);
  41. if ($ftp->put($remote, $file)) {
  42. //为false时,继续上传到网站附件目录,为true时,只上传到FTP上
  43. if(!$ftpuptb){
  44. return $r;
  45. }
  46. } else {
  47. printerror2("FTP上传失败!","");
  48. }
  49. }
  50. //上传文件
  51. $cp=@move_uploaded_file($file,$r[yname]);
  52. if(empty($cp))
  53. {
  54. if($doetran)
  55. {
  56. $r[tran]=0;
  57. return $r;
  58. }
  59. else
  60. {
  61. printerror('TranFail','',$ecms);
  62. }
  63. }
  64. DoChmodFile($r[yname]);
  65. $r[filesize]=(int)$file_size;
  66. //FileServer
  67. if($public_r['openfileserver'])
  68. {
  69. $efileftp_fr[]=$r['yname'];
  70. }
  71. return $r;
  72. }
复制代码


  1. //远程保存
  2. function DoTranUrl($url,$classid,$deftp=true){
  3. global $public_r,$class_r,$ecms_config,$efileftp_fr;
  4. global $ftpoff,$ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout,$ftpuppat,$ftpuptb;
  5. //处理地址
  6. $url=trim($url);
  7. $url=str_replace(" ","%20",$url);
  8. $r[tran]=1;
  9. //附件地址
  10. $r[url]=$url;
  11. //文件类型
  12. $r[filetype]=GetFiletype($url);
  13. if(CheckSaveTranFiletype($r[filetype]))
  14. {
  15. $r[tran]=0;
  16. return $r;
  17. }
  18. //是否已上传的文件
  19. $havetr=CheckNotSaveUrl($url);
  20. if($havetr)
  21. {
  22. $r[tran]=0;
  23. return $r;
  24. }
  25. //是否地址
  26. if(!strstr($url,'://'))
  27. {
  28. $r[tran]=0;
  29. return $r;
  30. }
  31. $string=ReadFiletext($url);
  32. if(empty($string))//读取不了
  33. {
  34. $r[tran]=0;
  35. return $r;
  36. }
  37. //文件名
  38. $r[insertfile]=ReturnDoTranFilename($file_name,$classid);
  39. $r[filename]=$r[insertfile].$r[filetype];
  40. //日期目录
  41. $r[filepath]=FormatFilePath($classid,$mynewspath,0);
  42. $filepath=$r[filepath]?$r[filepath].'/':$r[filepath];
  43. //存放目录
  44. $fspath=ReturnFileSavePath($classid);
  45. $r[savepath]=ECMS_PATH.$fspath['filepath'].$filepath;
  46. //附件地址
  47. $r[url]=$fspath['fileurl'].$filepath.$r[filename];
  48. //缩图文件
  49. $r[name]=$r[savepath]."small".$r[insertfile];
  50. //附件文件
  51. $r[yname]=$r[savepath].$r[filename];
  52. WriteFiletext_n($r[yname],$string);
  53. $r[filesize]=@filesize($r[yname]);
  54. //返回类型
  55. if(strstr($ecms_config['sets']['tranflashtype'],','.$r[filetype].','))
  56. {
  57. $r[type]=2;
  58. }
  59. elseif(strstr($ecms_config['sets']['tranpicturetype'],','.$r[filetype].','))
  60. {
  61. $r[type]=1;
  62. }
  63. elseif(strstr($ecms_config['sets']['mediaplayertype'],','.$r[filetype].',')||strstr($ecms_config['sets']['realplayertype'],','.$r[filetype].','))//多媒体
  64. {
  65. $r[type]=3;
  66. }
  67. else
  68. {
  69. $r[type]=0;
  70. }
  71. //FileServer
  72. if($public_r['openfileserver'])
  73. {
  74. $efileftp_fr[]=$r['yname'];
  75. }
  76. //FTP上传
  77. if ($ftpoff && $deftp) {
  78. $ftp =& new ftps();
  79. $ftp->connect($ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout);
  80. // 远程存放地址
  81. $remote = $ftpuppat . str_replace(ECMS_PATH, "", $r[savepath]).$r['filename'];
  82. if ($ftp->put($remote, $r["yname"])) {
  83. if(!$ftpuptb){
  84. DelFiletext($r["yname"]);
  85. }
  86. print_r($r);exit;
  87. return $r;
  88. } else {
  89. printerror2("FTP上传失败!","");
  90. }
  91. }
  92. return $r;
  93. }
复制代码

  1. //删除附件
  2. function DoDelFile($r){
  3. global $class_r,$public_r,$efileftp_dr;
  4. global $ftpoff,$ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout,$ftpuppat,$ftpuptb;
  5. $path=$r['path']?$r['path'].'/':$r['path'];
  6. $fspath=ReturnFileSavePath($r[classid],$r[fpath]);
  7. $delfile=ECMS_PATH.$fspath['filepath'].$path.$r['filename'];
  8. if ($ftpoff) {
  9. $ftp =& new ftps();
  10. $ftp->connect($ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout);
  11. $ftp->f_delete($ftpuppat.$fspath['filepath'].$path.$r['filename']);
  12. }
  13. DelFiletext($delfile);
  14. //FileServer
  15. if($public_r['openfileserver'])
  16. {
  17. $efileftp_dr[]=$delfile;
  18. }
  19. }
复制代码



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

  1. //引入FTP类
  2. require_once ECMS_PATH . 'e/extend/ecms_upftp/ftps.class.php';
  3. //引入配置文件
  4. require_once ECMS_PATH . 'e/extend/ecms_upftp/setconfig.php';
复制代码


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


  1. //截取图片
  2. function CopyImg($text,$copyimg,$copyflash,$classid,$qz,$username,$theid,$cjid,$mark,$fstb=1){
  3. global $empire,$public_r,$cjnewsurl,$navtheid,$dbtbpre;
  4. global $ftpoff,$ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout,$ftpuppat,$ftpuptb;
  5. if(empty($text))
  6. {return "";}
  7. $fstb=(int)$fstb;
  8. if($copyimg)
  9. {
  10. $text=RepImg($text,$copyflash);
  11. }
  12. if($copyflash)
  13. {$text=RepFlash($text,$copyflash);}
  14. $exp1="[--copyimg--]";
  15. $exp2="[/--copyimg--]";
  16. $r=explode($exp1,$text);
  17. for($i=1;$i<count($r);$i++)
  18. {
  19. $r1=explode($exp2,$r[$i]);
  20. if(strstr($r1[0],"http://")||strstr($r1[0],"https://"))
  21. {
  22. $dourl=$r1[0];
  23. }
  24. else
  25. {
  26. //是否是本地址
  27. if(!strstr($r1[0],"/")&&$cjnewsurl)
  28. {
  29. $fileqz_r=GetPageurlQz($cjnewsurl);
  30. $fileqz=$fileqz_r['selfqz'];
  31. $dourl=$fileqz.$r1[0];
  32. }
  33. else
  34. {
  35. $dourl=$qz.$r1[0];
  36. }
  37. }
  38. if($mark){
  39. $return_r=DoTranUrl($dourl,$classid,false);
  40. }else{
  41. $return_r=DoTranUrl($dourl,$classid);
  42. }
  43. $text=str_replace($exp1.$r1[0].$exp2,$return_r[url],$text);
  44. if($return_r[tran])
  45. {
  46. //记录数据库
  47. $filetime=date("Y-m-d H:i:s");
  48. //变量处理
  49. $return_r[filesize]=(int)$return_r[filesize];
  50. $classid=(int)$classid;
  51. $return_r[type]=(int)$return_r[type];
  52. $theid=(int)$theid;
  53. $cjid=(int)$cjid;
  54. eInsertFileTable($return_r[filename],$return_r[filesize],$return_r[filepath],$username,$classid,'[URL]'.$return_r[filename],$return_r[type],$theid,$cjid,$public_r[fpath],0,0,$fstb);
  55. //加水
  56. if($mark&&$return_r[type]==1)
  57. {
  58. GetMyMarkImg($return_r['yname']);
  59. if ($ftpoff) {
  60. $ftp =& new ftps();
  61. $ftp->connect($ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout);
  62. // 远程存放地址
  63. $remote = $ftpuppat . str_replace(ECMS_PATH, "", $return_r[savepath]).$return_r['filename'];
  64. if ($ftp->put($remote, $return_r["yname"])) {
  65. //删除图片
  66. if(!$ftpuptb){
  67. DelFiletext($return_r["yname"]);
  68. }
  69. } else {
  70. printerror2("FTP上传失败!","");
  71. }
  72. }
  73. }
  74. }
  75. }
  76. return $text;
  77. }
复制代码



以下功能暂未完善,


第五步,打开e/admin/ecmseditor/cropimg/CropImage.php 这个文件,找到 if(!file_exists($big_image_name))把下面一行
  1. printerror('NotCropImage','history.go(-1)');
复制代码

删除或者前面加2个反斜杠。



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


  1. <?php
  2. //裁剪图片
  3. function DoCropImage($add,$userid,$username){
  4. global $empire,$dbtbpre,$public_r,$class_r,$tranpicturetype,$efileftp_fr,$efileftp_dr;
  5. global $ftpoff,$ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout,$ftpuppat,$ftpuptb;
  6. $ftp =& new ftps();
  7. $ftp->connect($ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout);
  8. //参数处理
  9. $pic_x=(int)$add['pic_x'];
  10. $pic_y=(int)$add['pic_y'];
  11. $pic_w=(int)$add['pic_w'];
  12. $pic_h=(int)$add['pic_h'];
  13. $doing=(int)$add['doing'];
  14. $fileid=(int)$add['fileid'];
  15. $filepass=(int)$add['filepass'];
  16. //取得文件地址
  17. if(empty($fileid))
  18. {
  19. printerror('NotCropImage','history.go(-1)');
  20. }
  21. $filer=$empire->fetch1("select fileid,path,filename,classid,fpath,no from {$dbtbpre}enewsfile where fileid='$fileid'");
  22. if(empty($filer['fileid']))
  23. {
  24. printerror('NotCropImage','history.go(-1)');
  25. }
  26. $path=$filer['path']?$filer['path'].'/':$filer['path'];
  27. $fspath=ReturnFileSavePath($filer['classid'],$filer['fpath']);
  28. $big_image_name=$fspath['fileurl'].$path.$filer['filename'];
  29. $up=DoTranUrlimg($big_image_name,$filer);
  30. $big_image_name=$up['yname'];
  31. if(!file_exists($big_image_name))
  32. {
  33. printerror('NotCropImage','history.go(-1)');
  34. }
  35. $filetype=GetFiletype($filer['filename']);//取得文件类型
  36. if(!strstr($tranpicturetype,','.$filetype.','))
  37. {
  38. printerror('CropImageFiletypeFail','history.go(-1)');
  39. }
  40. //目标图片
  41. $new_datepath=FormatFilePath($filer['classid'],'',0);
  42. $new_path=$new_datepath?$new_datepath.'/':$new_datepath;
  43. $new_insertfile=ReturnDoTranFilename($filer['filename'],0);
  44. $new_fspath=ReturnFileSavePath($filer['classid']);
  45. $new_savepath=ECMS_PATH.$new_fspath['filepath'].$new_path;
  46. $new_name=$new_savepath.$new_insertfile;
  47. //处理图片
  48. $returnr['file']='';
  49. $returnr['filetype']='';
  50. if($temp_img_type = @getimagesize($big_image_name)) {preg_match('/\/([a-z]+)$/i', $temp_img_type[mime], $tpn); $img_type = $tpn[1];}
  51. else {preg_match('/\.([a-z]+)$/i', $big_image_name, $tpn); $img_type = $tpn[1];}
  52. $all_type = array(
  53. "jpg"   => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg"  , "exn"=>".jpg"),
  54. "gif"   => array("create"=>"ImageCreateFromGIF" , "output"=>"imagegif"   , "exn"=>".gif"),
  55. "jpeg"  => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg"  , "exn"=>".jpg"),
  56. "png"   => array("create"=>"imagecreatefrompng" , "output"=>"imagepng"   , "exn"=>".png"),
  57. "wbmp"  => array("create"=>"imagecreatefromwbmp", "output"=>"image2wbmp" , "exn"=>".wbmp")
  58. );
  59. $func_create = $all_type[$img_type]['create'];
  60. if(empty($func_create) or !function_exists($func_create))
  61. {
  62. printerror('CropImageFiletypeFail','history.go(-1)');
  63. }
  64. //输出
  65. $func_output = $all_type[$img_type]['output'];
  66. $func_exname = $all_type[$img_type]['exn'];
  67. if(($func_exname=='.gif'||$func_exname=='.png'||$func_exname=='.wbmp')&&!function_exists($func_output))
  68. {
  69. $func_output='imagejpeg';
  70. $func_exname='.jpg';
  71. }
  72. $big_image   = $func_create($big_image_name);
  73. $big_width   = imagesx($big_image);
  74. $big_height  = imagesy($big_image);
  75. if(!$big_width||!$big_height||$big_width<10||$big_height<10)
  76. {
  77. printerror('CropImageFilesizeFail','history.go(-1)');
  78. }
  79. if(function_exists("imagecopyresampled"))
  80. {
  81. $temp_image=imagecreatetruecolor($pic_w,$pic_h);
  82. imagecopyresampled($temp_image, $big_image, 0, 0, $pic_x, $pic_y, $pic_w, $pic_h, $pic_w, $pic_h);
  83. }
  84. else
  85. {
  86. $temp_image=imagecreate($pic_w,$pic_h);
  87. imagecopyresized($temp_image, $big_image, 0, 0, $pic_x, $pic_y, $pic_w, $pic_h, $pic_w, $pic_h);
  88. }
  89. $func_output($temp_image, $new_name.$func_exname);
  90. ImageDestroy($big_image);
  91. ImageDestroy($temp_image);
  92. $insert_file=$new_name.$func_exname;
  93. $insert_filename=$new_insertfile.$func_exname;
  94. if(file_exists($insert_file))
  95. {
  96. //删除原图
  97. if(!$doing)
  98. {
  99. $empire->query("delete from {$dbtbpre}enewsfile where fileid='$fileid'");
  100. DelFiletext($big_image_name);
  101. if($ftpoff){
  102. $ftp->f_delete($ftpuppat.$fspath['filepath'].$path.$filer['filename']);
  103. }
  104. //FileServer
  105. if($public_r['openfileserver'])
  106. {
  107. $efileftp_dr[]=$big_image_name;
  108. }
  109. }
  110. //写入数据库
  111. $no='[CropImg]'.$filer['no'];
  112. $filesize=filesize($insert_file);
  113. $filesize=(int)$filesize;
  114. $classid=(int)$filer['classid'];
  115. $type=1;
  116. $filetime=date("Y-m-d H:i:s");
  117. $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[fpath]');");
  118. //FileServer
  119. if($public_r['openfileserver'])
  120. {
  121. $efileftp_fr[]=$insert_file;
  122. }
  123. //FTP上传
  124. if($ftpoff){
  125. $remote = $ftpuppat.$fspath['filepath'].$new_datepath."/".$insert_filename;
  126. $ftp->put($remote, $insert_file);
  127. if(!$ftpuptb){
  128. DelFiletext($insert_file);
  129. }
  130. }
  131. }
  132. echo"<script>opener.ReloadChangeFilePage();window.close();</script>";
  133. db_close();
  134. exit();
  135. }
  136. //保存远程图片
  137. function DoTranUrlimg($url,$file=array()){
  138. $classid = $file['classid'];
  139. global $public_r,$class_r,$tranpicturetype,$tranflashtype,$mediaplayertype,$realplayertype,$efileftp_fr;
  140. global $ftpoff,$ftphost, $ftpusername, $ftppassword, $ftpport, $ftppasv, $ftpssl, $ftptimeout,$ftpuppat,$ftpuptb;
  141. //处理地址
  142. $url=trim($url);
  143. $url=str_replace(" ","%20",$url);
  144. $r[tran]=1;
  145. //附件地址
  146. $r[url]=$url;
  147. //文件类型
  148. $r[filetype]=GetFiletype($url);
  149. if(CheckSaveTranFiletype($r[filetype]))
  150. {
  151. $r[tran]=1;
  152. return $r;
  153. }
  154. $string=ReadFiletext($url);
  155. if(empty($string))//读取不了
  156. {
  157. $r[tran]=3;
  158. return $r;
  159. }
  160. //文件名
  161. $r[insertfile]=ReturnDoTranFilename($file_name,$classid);
  162. $r[filename]=$r[insertfile].$r[filetype];
  163. //日期目录
  164. $r[filepath]=FormatFilePath($classid,$mynewspath,0);
  165. $filepath=$r[filepath]?$r[filepath].'/':$r[filepath];
  166. //存放目录
  167. $fspath=ReturnFileSavePath($classid);
  168. $r[savepath]=ECMS_PATH.$fspath['filepath'].$filepath;
  169. //附件地址
  170. $r[url]=$fspath['fileurl'].$filepath.$r[filename];
  171. //缩图文件
  172. $r[name]=$r[savepath]."small".$r[insertfile];
  173. //附件文件
  174. $r[yname]=$r[savepath].$r[filename];
  175. WriteFiletext_n($r[yname],$string);
  176. $r[filesize]=@filesize($r[yname]);
  177. //返回类型
  178. if(strstr($tranflashtype,','.$r[filetype].','))
  179. {
  180. $r[type]=2;
  181. }
  182. elseif(strstr($tranpicturetype,','.$r[filetype].','))
  183. {
  184. $r[type]=1;
  185. }
  186. elseif(strstr($mediaplayertype,','.$r[filetype].',')||strstr($realplayertype,','.$r[filetype].','))//多媒体
  187. {
  188. $r[type]=3;
  189. }
  190. else
  191. {
  192. $r[type]=0;
  193. }
  194. //FileServer
  195. if($public_r['openfileserver'])
  196. {
  197. $efileftp_fr[]=$r['yname'];
  198. }
  199. return $r;
  200. }
  201. ?>
复制代码



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

插件演示截图:

帝国CMS远程附件插件(免费版)

帝国CMS远程附件插件(免费版)



附件下载:
远程附件.rar (10.96 KB, 下载次数: 7, 售价: 300 贡献)


0

主题

1

回帖

19

积分

新手上路

Rank: 1

积分
19
发表于 2020-2-3 21:42:58 | 显示全部楼层
哪里可以赚贡献分
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|PHPIN.NET ( 冀ICP备12000898号-14 )|网站地图

GMT+8, 2024-4-19 18:00

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表