国内流行的内容管理系统(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.

411 lines
13KB

  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. $dtp = new DedeTagParse();
  212. $dtp->SetNameSpace('field','<','>');
  213. $dtp->LoadSource($fieldset);
  214. $dede_addonfields = '';
  215. $addonfieldsname = '';
  216. if(is_array($dtp->CTags))
  217. {
  218. foreach($dtp->CTags as $tid=>$ctag)
  219. {
  220. if($loadtype!='autofield' || $ctag->GetAtt('autofield')==1 )
  221. {
  222. $dede_addonfields .= ( $dede_addonfields=="" ? $ctag->GetName().",".$ctag->GetAtt('type') : ";".$ctag->GetName().",".$ctag->GetAtt('type') );
  223. $addonfieldsname .= ",".$ctag->GetName();
  224. if ($isprint) echo GetFormItemA($ctag);
  225. }
  226. }
  227. }
  228. echo "<input type=\"hidden\" name=\"_csrf_token\" value=\"".$GLOBALS['csrf_token']."\" />";
  229. // 增加一个返回
  230. return $addonfieldsname;
  231. }
  232. /**
  233. * 载入自定义表单(用于编辑)
  234. *
  235. * @param string $fieldset
  236. * @param string $fieldValues
  237. * @param string $loadtype
  238. * @return string
  239. */
  240. function PrintAutoFieldsEdit(&$fieldset, &$fieldValues, $loadtype='all')
  241. {
  242. $dtp = new DedeTagParse();
  243. $dtp->SetNameSpace("field","<",">");
  244. $dtp->LoadSource($fieldset);
  245. $dede_addonfields = "";
  246. if(is_array($dtp->CTags))
  247. {
  248. foreach($dtp->CTags as $tid=>$ctag)
  249. {
  250. if($loadtype!='autofield'
  251. || ($loadtype=='autofield' && $ctag->GetAtt('autofield')==1) )
  252. {
  253. $dede_addonfields .= ( $dede_addonfields=='' ? $ctag->GetName().",".$ctag->GetAtt('type') : ";".$ctag->GetName().",".$ctag->GetAtt('type') );
  254. echo GetFormItemValueA($ctag,$fieldValues[$ctag->GetName()]);
  255. }
  256. }
  257. }
  258. echo "<input type=\"hidden\" name=\"_csrf_token\" value=\"".$GLOBALS['csrf_token']."\" />";
  259. }
  260. /**
  261. * 创建指定ID的文档
  262. *
  263. * @param int $aid
  264. * @param bool $ismakesign
  265. * @return string
  266. */
  267. function MakeArt($aid, $ismakesign=FALSE)
  268. {
  269. include_once(DEDEINC.'/arc.archives.class.php');
  270. if($ismakesign)
  271. {
  272. $envs['makesign'] = 'yes';
  273. }
  274. $arc = new Archives($aid);
  275. $reurl = $arc->MakeHtml();
  276. if(isset($typeid))
  277. {
  278. $preRow = $arc->dsql->GetOne("SELECT id FROM `#@__arctiny` WHERE id<$aid AND arcrank>-1 AND typeid='$typeid' order by id desc");
  279. $nextRow = $arc->dsql->GetOne("SELECT id FROM `#@__arctiny` WHERE id>$aid AND arcrank>-1 AND typeid='$typeid' order by id asc");
  280. if(is_array($preRow))
  281. {
  282. $arc = new Archives($preRow['id']);
  283. $arc->MakeHtml();
  284. }
  285. if(is_array($nextRow))
  286. {
  287. $arc = new Archives($nextRow['id']);
  288. $arc->MakeHtml();
  289. }
  290. }
  291. return $reurl;
  292. }
  293. /**
  294. * 处理HTML文本、自动摘要、自动获取缩略图等
  295. *
  296. * @access public
  297. * @param string $body 文档内容
  298. * @param string $description 描述
  299. * @param string $dtype 类型
  300. * @return string
  301. */
  302. function AnalyseHtmlBody($body, &$description, $dtype='')
  303. {
  304. global $cfg_mb_rmdown,$cfg_basehost,$cfg_auot_description,$arcID;
  305. $autolitpic = (empty($autolitpic) ? '' : $autolitpic);
  306. $body = stripslashes($body);
  307. //远程图片本地化
  308. if($cfg_mb_rmdown=='Y')
  309. {
  310. $body = GetCurContent($body);
  311. }
  312. //自动摘要
  313. if($description=='' && $cfg_auot_description>0)
  314. {
  315. $description = cn_substr(html2text($body),$cfg_auot_description);
  316. $description = trim(preg_replace('/#p#|#e#/','',$description));
  317. $description = addslashes($description);
  318. }
  319. $body = addslashes($body);
  320. return $body;
  321. }
  322. /**
  323. * 获得文章body里的外部资源
  324. *
  325. * @access public
  326. * @param string $body 内容
  327. * @return string
  328. */
  329. function GetCurContent(&$body)
  330. {
  331. global $cfg_multi_site,$cfg_basehost,$cfg_basedir,$cfg_user_dir,$title,$cfg_ml;
  332. include_once(DEDEINC."/dedecollection.func.php");
  333. $htd = new DedeHttpDown();
  334. $basehost = "http://".$_SERVER["HTTP_HOST"];
  335. $img_array = array();
  336. preg_match_all("/(src|SRC)=[\"|'| ]{0,}(http:\/\/([^>]*)\.(gif|jpg|png))/isU",$body,$img_array);
  337. $img_array = array_unique($img_array[2]);
  338. $imgUrl = $cfg_user_dir."/".$cfg_ml->M_ID;
  339. $imgPath = $cfg_basedir.$imgUrl;
  340. if(!is_dir($imgPath."/"))
  341. {
  342. MkdirAll($imgPath,$GLOBALS['cfg_dir_purview']);
  343. CloseFtp();
  344. }
  345. $milliSecond = MyDate("ymdHis",time());
  346. foreach($img_array as $key=>$value)
  347. {
  348. if(preg_match("#".$basehost."#i", $value))
  349. {
  350. continue;
  351. }
  352. if($cfg_basehost!=$basehost && preg_match("#".$cfg_basehost."#i", $value))
  353. {
  354. continue;
  355. }
  356. if(!preg_match("#^http:\/\/#i", $value))
  357. {
  358. continue;
  359. }
  360. $htd->OpenUrl($value);
  361. $itype = $htd->GetHead("content-type");
  362. $itype = substr($value,-4,4);
  363. if(!preg_match("#\.(jpg|gif|png)#i", $itype))
  364. {
  365. if($itype=='image/gif')
  366. {
  367. $itype = ".gif";
  368. }
  369. else if($itype=='image/png')
  370. {
  371. $itype = ".png";
  372. }
  373. else
  374. {
  375. $itype = '.jpg';
  376. }
  377. }
  378. $milliSecondN = dd2char($milliSecond.'-'.mt_rand(1000,8000));
  379. $value = trim($value);
  380. $rndFileName = $imgPath."/".$milliSecondN.'-'.$key.$itype;
  381. $fileurl = $imgUrl."/".$milliSecondN.'-'.$key.$itype;
  382. $rs = $htd->SaveToBin($rndFileName);
  383. if($rs)
  384. {
  385. $body = str_replace($value,$fileurl,$body);
  386. @WaterImg($rndFileName,'down');
  387. }
  388. $info = '';
  389. $imginfos = GetImageSize($rndFileName,$info);
  390. SaveUploadInfo($title,$fileurl,1,$imginfos);
  391. }
  392. $htd->Close();
  393. return $body;
  394. }