国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

528 lines
17KB

  1. <?php
  2. /**
  3. * 文档处理函数
  4. *
  5. * @version $Id: inc_archives_functions.php 1 13:52 2010年7月9日Z tianya $
  6. * @package DedeCMS.Member
  7. * @copyright Copyright (c) 2007 - 2010, DesDev, Inc.
  8. * @license http://help.dedecms.com/usersguide/license.html
  9. * @link http://www.dedecms.com
  10. */
  11. if(!defined('DEDEMEMBER')) exit('dedecms');
  12. require_once(DEDEINC.'/image.func.php');
  13. require_once(DEDEINC.'/archives.func.php');
  14. require_once(DEDEINC."/userlogin.class.php");
  15. //检查用户是否被禁言
  16. CheckNotAllow();
  17. /**
  18. * 获得HTML里的外部资源,针对图集
  19. *
  20. * @param string $body 内容
  21. * @param string $rfurl 地址
  22. * @param string $firstdd 第一个缩略图
  23. * @return string
  24. */
  25. function GetCurContentAlbum($body,$rfurl,&$firstdd)
  26. {
  27. global $cfg_multi_site,$cfg_basehost,$ddmaxwidth,$cfg_basedir,$pagestyle,$cfg_mb_rmdown,$title,$cfg_ml,$cfg_user_dir;
  28. include_once(DEDEINC."/dedecollection.func.php");
  29. if(empty($ddmaxwidth)) $ddmaxwidth = 240;
  30. $rsimg = '';
  31. $basehost = "http://".$_SERVER["HTTP_HOST"];
  32. $img_array = array();
  33. preg_match_all("/(src|SRC)=[\"|'| ]{0,}(http:\/\/([^>]*)\.(gif|jpg|png))/isU", $body, $img_array);
  34. $img_array = array_unique($img_array[2]);
  35. $imgUrl = $cfg_user_dir."/".$cfg_ml->M_ID;
  36. $imgPath = $cfg_basedir.$imgUrl;
  37. if(!is_dir($imgPath."/"))
  38. {
  39. MkdirAll($imgPath,$GLOBALS['cfg_dir_purview']);
  40. CloseFtp();
  41. }
  42. $milliSecond = MyDate("ymdHis",time());
  43. foreach($img_array as $key => $value)
  44. {
  45. if(preg_match("#".$basehost."#i", $value))
  46. {
  47. continue;
  48. }
  49. if($cfg_basehost!=$basehost && preg_match("#".$cfg_basehost."#i", $value))
  50. {
  51. continue;
  52. }
  53. if(!preg_match("#^http:\/\/#i", $value))
  54. {
  55. continue;
  56. }
  57. if($cfg_mb_rmdown=='Y')
  58. {
  59. $value = trim($value);
  60. $itype = substr($value,-4,4);
  61. if(!preg_match("#\.(gif|jpg|png)#i", $itype)) $itype = ".jpg";
  62. $rndFileName = $imgPath."/".$milliSecond.$key.$itype;
  63. $iurl = $imgUrl."/".$milliSecond.$key.$itype;
  64. //下载并保存文件
  65. //$rs = $htd->SaveToBin($rndFileName);
  66. $rs = DownImageKeep($value, $rfurl, $rndFileName, '', 0, 30);
  67. if($rs)
  68. {
  69. if($pagestyle > 2)
  70. {
  71. $litpicname = GetImageMapDD($iurl,$ddmaxwidth);
  72. if($litpicname!='') SaveUploadInfo($title,$litpicname,1,$addinfos);
  73. }
  74. else
  75. {
  76. $litpicname = '';
  77. }
  78. if(empty($firstdd))
  79. {
  80. $firstdd = $litpicname;
  81. if(!file_exists($cfg_basedir.$firstdd)) $firstdd = $iurl;
  82. }
  83. @WaterImg($rndFileName,'down');
  84. $info = '';
  85. $imginfos = GetImageSize($rndFileName,$info);
  86. SaveUploadInfo($title,$iurl,1,$imginfos);
  87. $rsimg .= "{dede:img ddimg='$litpicname' text='' width='".$imginfos[0]."' height='".$imginfos[1]."'} $iurl {/dede:img}\r\n";
  88. }
  89. }
  90. else
  91. {
  92. $rsimg .= "{dede:img ddimg='$value' text='' width='0' height='0'} $value {/dede:img}\r\n";
  93. }
  94. }
  95. return $rsimg;
  96. }
  97. /**
  98. * 图集里大图的小图
  99. *
  100. * @param string $filename 文件名
  101. * @param string $ddm 缩略图
  102. * @param string $oldname 旧的名称
  103. * @return string
  104. */
  105. function GetImageMapDD($filename, $ddm, $oldname='')
  106. {
  107. if($oldname!='' && !preg_match("#^http:\/\/#i", $oldname))
  108. {
  109. $ddpicok = $oldname;
  110. }
  111. else
  112. {
  113. $ddn = substr($filename,-3);
  114. $ddpicok = preg_replace("#\.".$ddn."$#", "-lp.".$ddn, $filename);
  115. }
  116. $toFile = $GLOBALS['cfg_basedir'].$ddpicok;
  117. ImageResize($GLOBALS['cfg_basedir'].$filename, $ddm, 300, $toFile);
  118. return $ddpicok;
  119. }
  120. /**
  121. * 把上传的信息保存到数据库
  122. *
  123. * @param string $title 标题
  124. * @param string $filename 文件名称
  125. * @param string $medaitype 附件类型
  126. * @param string $addinfos 附加信息
  127. * @return string
  128. */
  129. function SaveUploadInfo($title,$filename,$medaitype=1,$addinfos='')
  130. {
  131. global $dsql,$cfg_ml,$cfg_basedir;
  132. if($filename=='')
  133. {
  134. return FALSE;
  135. }
  136. if(!is_array($addinfos))
  137. {
  138. $addinfos[0] = $addinfos[1] = $addinfos[2] = 0;
  139. }
  140. if($medaitype==1)
  141. {
  142. $info = '';
  143. $addinfos = GetImageSize($cfg_basedir.$filename,$info);
  144. }
  145. $addinfos[2] = @filesize($cfg_basedir.$filename);
  146. $row = $dsql->GetOne("SELECT aid,title,url FROM `#@__uploads` WHERE url LIKE '$filename' AND mid='".$cfg_ml->M_ID."'; ");
  147. $uptime = time();
  148. if(is_array($row))
  149. {
  150. $query = "UPDATE `#@__uploads` SET title='$title',mediatype='$medaitype',
  151. width='{$addinfos[0]}',height='{$addinfos[1]}',filesize='{$addinfos[2]}',uptime='$uptime'
  152. WHERE aid='{$row['aid']}'; ";
  153. $dsql->ExecuteNoneQuery($query);
  154. }
  155. else
  156. {
  157. $inquery = "INSERT INTO `#@__uploads`(title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  158. VALUES ('$title','$filename','$medaitype','".$addinfos[0]."','".$addinfos[1]."','0','".$addinfos[2]."','$uptime','".$cfg_ml->M_ID."'); ";
  159. $dsql->ExecuteNoneQuery($inquery);
  160. }
  161. $fid = $dsql->GetLastID();
  162. AddMyAddon($fid, $filename);
  163. return TRUE;
  164. }
  165. /**
  166. * 获得一个附加表单
  167. *
  168. * @param object $ctag
  169. * @return string
  170. */
  171. function GetFormItemA($ctag)
  172. {
  173. return GetFormItem($ctag,'member');
  174. }
  175. /**
  176. * 处理不同类型的数据
  177. *
  178. * @param string $dvalue
  179. * @param string $dtype
  180. * @param int $aid
  181. * @param string $job
  182. * @param string $addvar
  183. * @return string
  184. */
  185. function GetFieldValueA($dvalue,$dtype,$aid=0,$job='add',$addvar='')
  186. {
  187. return GetFieldValue($dvalue,$dtype,$aid,$job,$addvar,'member');
  188. }
  189. /**
  190. * 获得带值的表单(编辑时用)
  191. *
  192. * @param object $ctag
  193. * @param string $fvalue 默认值
  194. * @return string
  195. */
  196. function GetFormItemValueA($ctag,$fvalue)
  197. {
  198. return GetFormItemValue($ctag,$fvalue,'member');
  199. }
  200. /**
  201. * 载入自定义表单(用于发布)
  202. *
  203. * @access public
  204. * @param string $fieldset
  205. * @param string $loadtype
  206. * @param bool $isprint 是否打印
  207. * @return string
  208. */
  209. function PrintAutoFieldsAdd(&$fieldset, $loadtype='all', $isprint=TRUE)
  210. {
  211. global $cfg_cookie_encode;
  212. $dtp = new DedeTagParse();
  213. $dtp->SetNameSpace('field','<','>');
  214. $dtp->LoadSource($fieldset);
  215. $dede_addonfields = '';
  216. $addonfieldsname = '';
  217. if(is_array($dtp->CTags))
  218. {
  219. foreach($dtp->CTags as $tid=>$ctag)
  220. {
  221. if($loadtype!='autofield' || $ctag->GetAtt('autofield')==1 )
  222. {
  223. $dede_addonfields .= ( $dede_addonfields=="" ? $ctag->GetName().",".$ctag->GetAtt('type') : ";".$ctag->GetName().",".$ctag->GetAtt('type') );
  224. $addonfieldsname .= ",".$ctag->GetName();
  225. if ($isprint) echo GetFormItemA($ctag);
  226. }
  227. }
  228. }
  229. if ($isprint) echo "<input type='hidden' name='dede_addonfields' value=\"".$dede_addonfields."\">\r\n";
  230. echo "<input type=\"hidden\" name=\"dede_fieldshash\" value=\"".md5($dede_addonfields . 'anythingelse' .$cfg_cookie_encode) ."\" />";
  231. // 增加一个返回
  232. return $addonfieldsname;
  233. }
  234. /**
  235. * 载入自定义表单(用于编辑)
  236. *
  237. * @param string $fieldset
  238. * @param string $fieldValues
  239. * @param string $loadtype
  240. * @return string
  241. */
  242. function PrintAutoFieldsEdit(&$fieldset, &$fieldValues, $loadtype='all')
  243. {
  244. $dtp = new DedeTagParse();
  245. $dtp->SetNameSpace("field","<",">");
  246. $dtp->LoadSource($fieldset);
  247. $dede_addonfields = "";
  248. if(is_array($dtp->CTags))
  249. {
  250. foreach($dtp->CTags as $tid=>$ctag)
  251. {
  252. if($loadtype!='autofield'
  253. || ($loadtype=='autofield' && $ctag->GetAtt('autofield')==1) )
  254. {
  255. $dede_addonfields .= ( $dede_addonfields=='' ? $ctag->GetName().",".$ctag->GetAtt('type') : ";".$ctag->GetName().",".$ctag->GetAtt('type') );
  256. echo GetFormItemValueA($ctag,$fieldValues[$ctag->GetName()]);
  257. }
  258. }
  259. }
  260. echo "<input type='hidden' name='dede_addonfields' value=\"".$dede_addonfields."\">\r\n";
  261. }
  262. /**
  263. * 创建指定ID的文档
  264. *
  265. * @param int $aid
  266. * @param bool $ismakesign
  267. * @return string
  268. */
  269. function MakeArt($aid, $ismakesign=FALSE)
  270. {
  271. global $cfg_makeindex,$cfg_basedir,$cfg_templets_dir,$cfg_df_style;
  272. include_once(DEDEINC.'/arc.archives.class.php');
  273. if($ismakesign)
  274. {
  275. $envs['makesign'] = 'yes';
  276. }
  277. $arc = new Archives($aid);
  278. $reurl = $arc->MakeHtml();
  279. if(isset($typeid))
  280. {
  281. $preRow = $arc->dsql->GetOne("SELECT id FROM `#@__arctiny` WHERE id<$aid AND arcrank>-1 AND typeid='$typeid' order by id desc");
  282. $nextRow = $arc->dsql->GetOne("SELECT id FROM `#@__arctiny` WHERE id>$aid AND arcrank>-1 AND typeid='$typeid' order by id asc");
  283. if(is_array($preRow))
  284. {
  285. $arc = new Archives($preRow['id']);
  286. $arc->MakeHtml();
  287. }
  288. if(is_array($nextRow))
  289. {
  290. $arc = new Archives($nextRow['id']);
  291. $arc->MakeHtml();
  292. }
  293. }
  294. return $reurl;
  295. }
  296. /**
  297. * 处理HTML文本、自动摘要、自动获取缩略图等
  298. *
  299. * @access public
  300. * @param string $body 文档内容
  301. * @param string $description 描述
  302. * @param string $dtype 类型
  303. * @return string
  304. */
  305. function AnalyseHtmlBody($body, &$description, $dtype='')
  306. {
  307. global $cfg_mb_rmdown,$cfg_basehost,$cfg_auot_description,$arcID;
  308. $autolitpic = (empty($autolitpic) ? '' : $autolitpic);
  309. $body = stripslashes($body);
  310. //远程图片本地化
  311. if($cfg_mb_rmdown=='Y')
  312. {
  313. $body = GetCurContent($body);
  314. }
  315. //自动摘要
  316. if($description=='' && $cfg_auot_description>0)
  317. {
  318. $description = cn_substr(html2text($body),$cfg_auot_description);
  319. $description = trim(preg_replace('/#p#|#e#/','',$description));
  320. $description = addslashes($description);
  321. }
  322. $body = addslashes($body);
  323. return $body;
  324. }
  325. /**
  326. * 获得文章body里的外部资源
  327. *
  328. * @access public
  329. * @param string $body 内容
  330. * @return string
  331. */
  332. function GetCurContent(&$body)
  333. {
  334. global $cfg_multi_site,$cfg_basehost,$cfg_basedir,$cfg_user_dir,$title,$cfg_ml;
  335. include_once(DEDEINC."/dedecollection.func.php");
  336. $htd = new DedeHttpDown();
  337. $basehost = "http://".$_SERVER["HTTP_HOST"];
  338. $img_array = array();
  339. preg_match_all("/(src|SRC)=[\"|'| ]{0,}(http:\/\/([^>]*)\.(gif|jpg|png))/isU",$body,$img_array);
  340. $img_array = array_unique($img_array[2]);
  341. $imgUrl = $cfg_user_dir."/".$cfg_ml->M_ID;
  342. $imgPath = $cfg_basedir.$imgUrl;
  343. if(!is_dir($imgPath."/"))
  344. {
  345. MkdirAll($imgPath,$GLOBALS['cfg_dir_purview']);
  346. CloseFtp();
  347. }
  348. $milliSecond = MyDate("ymdHis",time());
  349. foreach($img_array as $key=>$value)
  350. {
  351. if(preg_match("#".$basehost."#i", $value))
  352. {
  353. continue;
  354. }
  355. if($cfg_basehost!=$basehost && preg_match("#".$cfg_basehost."#i", $value))
  356. {
  357. continue;
  358. }
  359. if(!preg_match("#^http:\/\/#i", $value))
  360. {
  361. continue;
  362. }
  363. $htd->OpenUrl($value);
  364. $itype = $htd->GetHead("content-type");
  365. $itype = substr($value,-4,4);
  366. if(!preg_match("#\.(jpg|gif|png)#i", $itype))
  367. {
  368. if($itype=='image/gif')
  369. {
  370. $itype = ".gif";
  371. }
  372. else if($itype=='image/png')
  373. {
  374. $itype = ".png";
  375. }
  376. else
  377. {
  378. $itype = '.jpg';
  379. }
  380. }
  381. $milliSecondN = dd2char($milliSecond.'-'.mt_rand(1000,8000));
  382. $value = trim($value);
  383. $rndFileName = $imgPath."/".$milliSecondN.'-'.$key.$itype;
  384. $fileurl = $imgUrl."/".$milliSecondN.'-'.$key.$itype;
  385. $rs = $htd->SaveToBin($rndFileName);
  386. if($rs)
  387. {
  388. $body = str_replace($value,$fileurl,$body);
  389. @WaterImg($rndFileName,'down');
  390. }
  391. $info = '';
  392. $imginfos = GetImageSize($rndFileName,$info);
  393. SaveUploadInfo($title,$fileurl,1,$imginfos);
  394. }
  395. $htd->Close();
  396. return $body;
  397. }
  398. /**
  399. * 上传一个未经处理的图片
  400. *
  401. * 参数一 upname 上传框名称
  402. * 参数二 handurl 手工填写的网址
  403. * 参数三 ddisremote 是否下载远程图片 0 不下, 1 下载
  404. * 参数四 ntitle 注解文字 如果表单有 title 字段可不管
  405. *
  406. * @access public
  407. * @param string $upname 上传名称
  408. * @param string $handurl 操作地址
  409. * @param int $isremote 是否远程
  410. * @param string $ntitle 注释文字
  411. * @return string
  412. */
  413. function UploadOneImage($upname,$handurl='',$isremote=1,$ntitle='')
  414. {
  415. global $cfg_ml,$cfg_basedir,$cfg_image_dir,$dsql,$title, $dsql;
  416. if($ntitle!='')
  417. {
  418. $title = $ntitle;
  419. }
  420. $ntime = time();
  421. $filename = '';
  422. $isrm_up = false;
  423. $handurl = trim($handurl);
  424. //如果用户自行上传了图片
  425. if(!empty($_FILES[$upname]['tmp_name']) && is_uploaded_file($_FILES[$upname]['tmp_name']))
  426. {
  427. $istype = 0;
  428. $sparr = Array("image/pjpeg","image/jpeg","image/gif","image/png");
  429. $_FILES[$upname]['type'] = strtolower(trim($_FILES[$upname]['type']));
  430. if(!in_array($_FILES[$upname]['type'],$sparr))
  431. {
  432. ShowMsg("上传的图片格式错误,请使用JPEG、GIF、PNG格式的其中一种!","-1");
  433. exit();
  434. }
  435. if(!empty($handurl) && !preg_match("#^http:\/\/#", $handurl) && file_exists($cfg_basedir.$handurl) )
  436. {
  437. $dsql->ExecuteNoneQuery("Delete From #@__uploads where url like '$handurl' ");
  438. $fullUrl = preg_replace("#\.([a-z]*)$#i", "", $handurl);
  439. }
  440. else
  441. {
  442. $savepath = $cfg_image_dir."/".strftime("%Y-%m",$ntime);
  443. CreateDir($savepath);
  444. $fullUrl = $savepath."/".strftime("%d",$ntime).dd2char(strftime("%H%M%S",$ntime).'0'.$cfg_ml->M_ID.'0'.mt_rand(1000,9999));
  445. }
  446. if(strtolower($_FILES[$upname]['type'])=="image/gif")
  447. {
  448. $fullUrl = $fullUrl.".gif";
  449. }
  450. else if(strtolower($_FILES[$upname]['type'])=="image/png")
  451. {
  452. $fullUrl = $fullUrl.".png";
  453. }
  454. else
  455. {
  456. $fullUrl = $fullUrl.".jpg";
  457. }
  458. //保存
  459. @move_uploaded_file($_FILES[$upname]['tmp_name'],$cfg_basedir.$fullUrl);
  460. $filename = $fullUrl;
  461. //水印
  462. @WaterImg($imgfile,'up');
  463. $isrm_up = TRUE;
  464. }
  465. //远程或选择本地图片
  466. else{
  467. if($handurl=='')
  468. {
  469. return '';
  470. }
  471. //远程图片并要求本地化
  472. if($isremote==1 && preg_match("#^http:\/\/#", $handurl))
  473. {
  474. $ddinfos = GetRemoteImage($handurl,$cuserLogin->getUserID());
  475. if(!is_array($ddinfos))
  476. {
  477. $litpic = "";
  478. }
  479. else
  480. {
  481. $filename = $ddinfos[0];
  482. }
  483. $isrm_up = TRUE;
  484. //本地图片或远程不要求本地化
  485. }
  486. else
  487. {
  488. $filename = $handurl;
  489. }
  490. }
  491. $imgfile = $cfg_basedir.$filename;
  492. if(is_file($imgfile) && $isrm_up && $filename!='')
  493. {
  494. $info = "";
  495. $imginfos = GetImageSize($imgfile,$info);
  496. //把新上传的图片信息保存到媒体文档管理档案中
  497. $inquery = "
  498. INSERT INTO #@__uploads(title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  499. VALUES ('$title','$filename','1','".$imginfos[0]."','".$imginfos[1]."','0','".filesize($imgfile)."','".time()."','".$cfg_ml->M_ID."');
  500. ";
  501. $dsql->ExecuteNoneQuery($inquery);
  502. }
  503. $fid = $dsql->GetLastID();
  504. AddMyAddon($fid, $filename);
  505. return $filename;
  506. }