editorfun.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <?php
  2. //提示信息
  3. function ECMS_EditorPrintError($errorNumber,$fileUrl,$fileName,$customMsg,$fileno,$filesize){
  4. global $public_r;
  5. if(empty($errorNumber))
  6. {
  7. $errorNumber=0;
  8. $filesize=ChTheFilesize($filesize);
  9. }
  10. else
  11. {
  12. @include '../'.LoadLang("pub/message.php");
  13. $customMsg=$message_r[$customMsg];
  14. }
  15. $errorNumber=(int)$errorNumber;
  16. $typer=ECMS_EditorReturnType('');
  17. $type=$typer['ftype'];
  18. //附件
  19. if($type==0)
  20. {
  21. $fileUrl=$fileUrl.'##'.$fileno.'##'.$filesize;
  22. }
  23. ECMS_PTEditorShowError($type,addslashes($customMsg),addslashes($fileUrl),$add,0);
  24. db_close();
  25. exit();
  26. }
  27. //返回表格格式
  28. function eTranMoreTbGs($r){
  29. if($r['tbcolor'])
  30. {
  31. $tbcolor=" bgcolor='".$r['tbcolor']."'";
  32. }
  33. if($r['tbbordercolor'])
  34. {
  35. $tbbordercolor=" bordercolor='".$r['tbbordercolor']."'";
  36. }
  37. if($r['tbsp'])
  38. {
  39. $tbsp=" cellspacing='".$r['tbsp']."'";
  40. }
  41. if($r['tbpa'])
  42. {
  43. $tbpa=" cellpadding='".$r['tbpa']."'";
  44. }
  45. if($r['tbwidth'])
  46. {
  47. $tbwidth=" width='".$r['tbwidth'].$r['tbwidthdw']."'";
  48. }
  49. $table="<table".$tbwidth." border='".$r['tbborder']."'".$tbpa.$tbsp.$tbbordercolor.$tbcolor." align='".$r['tbalign']."'>";
  50. return $table;
  51. }
  52. //编辑器上传多图片
  53. function eTranMorePic($file,$file_name,$file_type,$file_size,$add,$userid,$username){
  54. global $empire,$public_r,$dbtbpre,$fun_r;
  55. //导入gd处理文件
  56. if($add['getsmall']||$add['getmark'])
  57. {
  58. @include(ECMS_PATH."e/class/gd.php");
  59. }
  60. $tranfrom=(int)$add['tranfrom'];
  61. $j=0;
  62. $line=(int)$add['line'];
  63. if($line==0)
  64. {
  65. $line=1;
  66. }
  67. $add['classid']=(int)$add['classid'];
  68. $modtype=(int)$add['modtype'];
  69. $infoid=(int)$add['infoid'];
  70. $fstb=0;
  71. if(empty($modtype))
  72. {
  73. $fstb=GetInfoTranFstb($add['classid'],$infoid,0);
  74. }
  75. //远程保存
  76. if($add['saveurl'])
  77. {
  78. $url_r=explode("\r\n",$add['saveurl']);
  79. $count=count($url_r);
  80. for($i=0;$i<$count;$i++)
  81. {
  82. if(empty($url_r[$i]))
  83. {continue;}
  84. //验证图片
  85. $check=eTranMorePicCheck($url_r[$i],0);
  86. if($check==0)
  87. {continue;}
  88. //开始上传
  89. $r=DoTranUrl($url_r[$i],$add['classid']);
  90. if(empty($r[tran]))
  91. {
  92. continue;
  93. }
  94. $imgurl=$r['url'];
  95. $bimgurl=$r['url'];
  96. //写入数据库
  97. $r[filesize]=(int)$r[filesize];
  98. $add[classid]=(int)$add[classid];
  99. $add[type]=(int)$add[type];
  100. $add[filepass]=(int)$add[filepass];
  101. eInsertFileTable($r[filename],$r[filesize],$r[filepath],$username,$add[classid],$r[filename],$add[type],$add[filepass],$add[filepass],$public_r[fpath],0,$modtype,$fstb);
  102. //缩略图
  103. if($add['getsmall'])
  104. {
  105. $sfiler=GetMySmallImg($add['classid'],$r[filename],$r[insertfile],$r[filepath],$r[yname],$add[swidth],$add[sheight],$r[name],$add['filepass'],$add['filepass'],$userid,$username,$modtype,$fstb);
  106. $imgurl=str_replace("/".$r[filename],"/small".$r[insertfile].$sfiler['filetype'],$r[url]);
  107. }
  108. //水印
  109. if($add['getmark'])
  110. {
  111. GetMyMarkImg($r['yname']);
  112. }
  113. //开始输出字符
  114. $j++;
  115. //分页
  116. if($add['exptype']==1)
  117. {
  118. $classtext.="<p align='".$add['align']."'>".eTranMorePicGs($bimgurl,$imgurl,$add)."</p>";
  119. if($j%$line==0)
  120. {
  121. $classtext.="[!--empirenews.page--]";
  122. }
  123. }
  124. //表格
  125. else
  126. {
  127. if(($j-1)%$line==0||$j==1)
  128. {$classtext.="<tr>";}
  129. $classtext.="<td align=".$add['align'].">".eTranMorePicGs($bimgurl,$imgurl,$add)."</td>";
  130. if($j%$line==0)
  131. {$classtext.="</tr>";}
  132. }
  133. }
  134. //表格
  135. if($add['exptype']==0)
  136. {
  137. if($j<>0)
  138. {
  139. $table=eTranMoreTbGs($add);
  140. $table1="</table>";
  141. $ys=$line-$j%$line;
  142. $p=0;
  143. for($k=0;$k<$ys&&$ys!=$line;$k++)
  144. {
  145. $p=1;
  146. $classtext.="<td></td>";
  147. }
  148. if($p==1)
  149. {
  150. $classtext.="</tr>";
  151. }
  152. }
  153. $classtext=$table.$classtext.$table1;
  154. }
  155. //分页
  156. else
  157. {
  158. if($j%$line==0)
  159. {
  160. $classtext=substr($classtext,0,strlen($classtext)-22);
  161. }
  162. }
  163. }
  164. //本地上传
  165. else
  166. {
  167. $count=count($file_name);
  168. if($count==0)
  169. {
  170. $tranfrom==0?printerror("MustChangeTranOneFile","history.go(-1)",8):ECMS_EditorPrintError(1,'','','MustChangeTranOneFile','','');
  171. }
  172. $GLOBALS['doetran']=1;
  173. for($i=0;$i<$count;$i++)
  174. {
  175. if(empty($file_name[$i]))
  176. {
  177. continue;
  178. }
  179. //验证图片
  180. $check=eTranMorePicCheck($file_name[$i],$file_size[$i]);
  181. if($check==0)
  182. {
  183. continue;
  184. }
  185. //上传
  186. $r=DoTranFile($file[$i],$file_name[$i],$file_type[$i],$file_size[$i],$add['classid']);
  187. if(empty($r[tran]))
  188. {
  189. continue;
  190. }
  191. $imgurl=$r['url'];
  192. $bimgurl=$r['url'];
  193. //写入数据库
  194. $r[filesize]=(int)$r[filesize];
  195. $add[classid]=(int)$add[classid];
  196. $add[type]=(int)$add[type];
  197. $add[filepass]=(int)$add[filepass];
  198. eInsertFileTable($r[filename],$r[filesize],$r[filepath],$username,$add[classid],$file_name[$i],$add[type],$add[filepass],$add[filepass],$public_r[fpath],0,$modtype,$fstb);
  199. //缩略图
  200. if($add['getsmall'])
  201. {
  202. $sfiler=GetMySmallImg($add['classid'],$r[filename],$r[insertfile],$r[filepath],$r[yname],$add[swidth],$add[sheight],$r[name],$add['filepass'],$add['filepass'],$userid,$username,$modtype,$fstb);
  203. $imgurl=str_replace("/".$r[filename],"/small".$r[insertfile].$sfiler['filetype'],$r[url]);
  204. }
  205. //水印
  206. if($add['getmark'])
  207. {
  208. GetMyMarkImg($r['yname']);
  209. }
  210. //开始输出字符
  211. $j++;
  212. //分页
  213. if($add['exptype']==1)
  214. {
  215. $classtext.="<p align=".$add['align'].">".eTranMorePicGs($bimgurl,$imgurl,$add)."</p>";
  216. if($j%$line==0)
  217. {
  218. $classtext.="[!--empirenews.page--]";
  219. }
  220. }
  221. //表格
  222. else
  223. {
  224. if(($j-1)%$line==0||$j==1)
  225. {$classtext.="<tr>";}
  226. $classtext.="<td align=".$add['align'].">".eTranMorePicGs($bimgurl,$imgurl,$add)."</td>";
  227. if($j%$line==0)
  228. {$classtext.="</tr>";}
  229. }
  230. }
  231. //表格
  232. if($add['exptype']==0)
  233. {
  234. if($j<>0)
  235. {
  236. $table=eTranMoreTbGs($add);
  237. $table1="</table>";
  238. $ys=$line-$j%$line;
  239. $p=0;
  240. for($k=0;$k<$ys&&$ys!=$line;$k++)
  241. {
  242. $p=1;
  243. $classtext.="<td></td>";
  244. }
  245. if($p==1)
  246. {
  247. $classtext.="</tr>";
  248. }
  249. }
  250. $classtext=$table.$classtext.$table1;
  251. }
  252. //分页
  253. else
  254. {
  255. if($j%$line==0)
  256. {
  257. $classtext=substr($classtext,0,strlen($classtext)-22);
  258. }
  259. }
  260. }
  261. $typer=ECMS_EditorReturnType('');
  262. $type=$typer['ftype'];
  263. ECMS_PTEditorShowError($type,'',$classtext,$add,0);
  264. db_close();
  265. exit();
  266. }
  267. //返回图片格式
  268. function eTranMorePicGs($bimgurl,$imgurl,$r){
  269. if($r['width'])
  270. {
  271. $width=" width=".$r['width'];
  272. }
  273. if($r['height'])
  274. {
  275. $height=" height=".$r['height'];
  276. }
  277. $pic="<a href='".$bimgurl."' target='_blank'><img src='".$imgurl."' border=".$r['imgborder'].$width.$height."></a>";
  278. return $pic;
  279. }
  280. //验证图片是否合法
  281. function eTranMorePicCheck($url,$filesize){
  282. global $public_r,$ecms_config;
  283. $filetype=GetFiletype($url);//扩展名
  284. //如果是.php文件
  285. if(CheckSaveTranFiletype($filetype))
  286. {
  287. return 0;
  288. }
  289. if(!strstr($public_r['filetype'],"|".$filetype."|"))
  290. {
  291. return 0;
  292. }
  293. if($filesize>$public_r['filesize']*1024)
  294. {
  295. return 0;
  296. }
  297. //扩展名是否合法
  298. if(!strstr($ecms_config['sets']['tranpicturetype'],','.$filetype.','))
  299. {
  300. return 0;
  301. }
  302. return 1;
  303. }
  304. //上传文件
  305. function TranFile($file,$file_name,$file_type,$file_size,$tranurl,$no,$classid,$type,$post,$userid,$username){
  306. global $empire,$public_r,$loginrnd,$dbtbpre,$ecms_config;
  307. if(!$no)
  308. {
  309. $no=$file_name;
  310. }
  311. $tranfrom=(int)$post['tranfrom'];
  312. $classid=(int)$classid;
  313. $modtype=(int)$post['modtype'];
  314. $infoid=(int)$post['infoid'];
  315. $fstb=0;
  316. if(empty($modtype))
  317. {
  318. $fstb=GetInfoTranFstb($classid,$infoid,0);
  319. }
  320. //是否为空
  321. if(!$file_name)
  322. {
  323. if(empty($tranurl)||$tranurl=="http://")
  324. {
  325. $tranfrom==0?printerror("EmptyHttp","history.go(-1)",8):ECMS_EditorPrintError(1,'','','EmptyHttp','','');
  326. }
  327. $filetype=GetFiletype($tranurl);//取得文件类型
  328. $file_size=0;
  329. }
  330. else
  331. {
  332. $filetype=GetFiletype($file_name);//取得文件类型
  333. }
  334. //如果是.php文件
  335. if(CheckSaveTranFiletype($filetype))
  336. {
  337. $tranfrom==0?printerror("TranPHP","history.go(-1)",8):ECMS_EditorPrintError(1,'','','TranPHP','','');
  338. }
  339. $type_r=explode("|".$filetype."|",$public_r['filetype']);
  340. if(count($type_r)<2)
  341. {
  342. $tranfrom==0?printerror("TranFiletypeFail","history.go(-1)",8):ECMS_EditorPrintError(1,'','','TranFiletypeFail','','');
  343. }
  344. if($file_size>$public_r['filesize']*1024)
  345. {
  346. $tranfrom==0?printerror("TranFilesizeFail","history.go(-1)",8):ECMS_EditorPrintError(1,'','','TranFilesizeFail','','');
  347. }
  348. if($type==1)//上传图片
  349. {
  350. if(!strstr($ecms_config['sets']['tranpicturetype'],','.$filetype.','))
  351. {
  352. $tranfrom==0?printerror("NotTranImg","history.go(-1)",8):ECMS_EditorPrintError(1,'','','NotTranImg','','');
  353. }
  354. }
  355. elseif($type==2)//上传flash
  356. {
  357. if(!strstr($ecms_config['sets']['tranflashtype'],','.$filetype.','))
  358. {
  359. $tranfrom==0?printerror("NotTranFlash","history.go(-1)",8):ECMS_EditorPrintError(1,'','','NotTranFlash','','');
  360. }
  361. }
  362. elseif($type==3)//上传多媒体
  363. {}
  364. else//上传附件
  365. {}
  366. //远程保存
  367. if(empty($file_name))
  368. {
  369. $r=DoTranUrl($tranurl,$classid);
  370. if(empty($r[tran]))
  371. {
  372. $tranfrom==0?printerror("TranHttpFail","history.go(-1)",8):ECMS_EditorPrintError(1,'','','TranHttpFail','','');
  373. }
  374. }
  375. //本地上传
  376. else
  377. {
  378. $r=DoTranFile($file,$file_name,$file_type,$file_size,$classid);
  379. if(empty($r[tran]))
  380. {
  381. $tranfrom==0?printerror("TranFail","history.go(-1)",8):ECMS_EditorPrintError(1,'','','TranFail','','');
  382. }
  383. }
  384. if(!$no)
  385. {
  386. $no=$r[filename];
  387. }
  388. //写入数据库
  389. $r[filesize]=(int)$r[filesize];
  390. $classid=(int)$classid;
  391. $post[filepass]=(int)$post[filepass];
  392. $type=(int)$type;
  393. $sql=eInsertFileTable($r[filename],$r[filesize],$r[filepath],$username,$classid,$no,$type,$post[filepass],$post[filepass],$public_r[fpath],0,$modtype,$fstb);
  394. $fileid=$empire->lastid();
  395. //导入gd.php文件
  396. if($type==1&&($post['getsmall']||$post['getmark']))
  397. {
  398. @include(ECMS_PATH."e/class/gd.php");
  399. }
  400. //缩略图
  401. if($type==1&&$post['getsmall'])
  402. {
  403. GetMySmallImg($classid,$no,$r[insertfile],$r[filepath],$r[yname],$post[width],$post[height],$r[name],$post['filepass'],$post['filepass'],$userid,$username,$modtype,$fstb);
  404. }
  405. //水印
  406. if($type==1&&$post['getmark'])
  407. {
  408. GetMyMarkImg($r['yname']);
  409. }
  410. if($sql)
  411. {
  412. if($tranfrom==1)//编辑器上传
  413. {
  414. //$imgstr=EditorSetTranPic($r[url],$r[url],$post);
  415. ECMS_EditorPrintError(0,$r[url],$r[filename],'',$no,$r[filesize]);
  416. db_close();
  417. exit();
  418. }
  419. echo"<script>parent.location.reload();</script>";
  420. db_close();
  421. exit();
  422. }
  423. else
  424. {
  425. $tranfrom==0?printerror("InTranRecordFail","history.go(-1)",8):ECMS_EditorPrintError(1,'','','InTranRecordFail','','');
  426. }
  427. }
  428. //插入图片
  429. function EditorSetTranPic($picurl,$smallpic,$add){
  430. $imgstr="<img src='$picurl'";
  431. if($add[pic_autosize])
  432. {
  433. $imgstr.=" onload='autosimg(this);' onmousewheel='return zoomimg(this);'";
  434. }
  435. if($add[pic_height])
  436. {
  437. $imgstr.=" height='$add[pic_height]'";
  438. }
  439. if($add[pic_width])
  440. {
  441. $imgstr.=" width='$add[pic_width]'";
  442. }
  443. $imgstr.=" border='$add[pic_border]'";
  444. if($add[pic_alt])
  445. {
  446. $imgstr.=" alt='$add[pic_alt]'";
  447. }
  448. if($add[pic_vspace])
  449. {
  450. $imgstr.=" vspace='$add[pic_vspace]'";
  451. }
  452. if($add[pic_hspace])
  453. {
  454. $imgstr.=" hspace='$add[pic_hspace]'";
  455. }
  456. if($add[pic_align])
  457. {
  458. $imgstr.=" align='$add[pic_align]'";
  459. }
  460. if(empty($add[pic_link]))
  461. {
  462. $add[pic_link]=$picurl;
  463. }
  464. $imgstr="<a href='$add[pic_link]' target='$add[pic_linktarget]'>".$imgstr."></a>";
  465. if($add[pic_say])
  466. {
  467. $imgstr.="<br><span style='line-height=18pt'>".ehtmlspecialchars($add[pic_say])."</span>";
  468. }
  469. if($add[pic_align]=='center')
  470. {
  471. $imgstr='<center>'.$imgstr.'</center>';
  472. }
  473. return $imgstr;
  474. }
  475. ?>