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

935 lines
28KB

  1. <?php
  2. /**
  3. * 文档操作相关函数
  4. *
  5. * @version $Id: inc_archives_functions.php 1 9:56 2010年7月21日Z tianya $
  6. * @package DedeCMS.Administrator
  7. * @copyright Copyright (c) 2007 - 2020, DesDev, Inc.
  8. * @copyright Copyright (c) 2020, DedeBIZ.COM
  9. * @license http://help.dedecms.com/usersguide/license.html
  10. * @link http://www.dedecms.com
  11. */
  12. require_once(DEDEINC.'/dedehttpdown.class.php');
  13. require_once(DEDEINC.'/image.func.php');
  14. require_once(DEDEINC.'/archives.func.php');
  15. require_once(DEDEINC.'/arc.partview.class.php');
  16. $backurl = !empty($_COOKIE['ENV_GOBACK_URL']) ? $_COOKIE['ENV_GOBACK_URL'] : '';
  17. $backurl = preg_match("#content_#", $backurl) ? "<a href='$backurl' class='btn btn-secondary btn-sm'>记忆的列表页</a> &nbsp;" : '';
  18. if(!isset($_NOT_ARCHIVES))
  19. {
  20. require_once(DEDEINC.'/customfields.func.php');
  21. }
  22. /**
  23. * 获得HTML里的外部资源,针对图集
  24. *
  25. * @access public
  26. * @param string $body 文档内容
  27. * @param string $rfurl 来源地址
  28. * @param string $firstdd 开始标记
  29. * @return string
  30. */
  31. function GetCurContentAlbum($body, $rfurl, &$firstdd)
  32. {
  33. global $dsql,$cfg_multi_site,$cfg_basehost,$cfg_ddimg_width;
  34. global $cfg_basedir,$pagestyle,$cuserLogin,$cfg_addon_savetype;
  35. require_once(DEDEINC.'/dedecollection.func.php');
  36. if(empty($cfg_ddimg_width)) $cfg_ddimg_width = 320;
  37. $rsimg = '';
  38. $cfg_uploaddir = $GLOBALS['cfg_image_dir'];
  39. $cfg_basedir = $GLOBALS['cfg_basedir'];
  40. $basehost = 'http://'.$_SERVER['HTTP_HOST'];
  41. $img_array = array();
  42. preg_match_all("/(src)=[\"|'| ]{0,}(http:\/\/([^>]*)\.(gif|jpg|png))/isU",$body,$img_array);
  43. $img_array = array_unique($img_array[2]);
  44. $imgUrl = $cfg_uploaddir.'/'.MyDate($cfg_addon_savetype, time());
  45. $imgPath = $cfg_basedir.$imgUrl;
  46. if(!is_dir($imgPath.'/'))
  47. {
  48. MkdirAll($imgPath,$GLOBALS['cfg_dir_purview']);
  49. CloseFtp();
  50. }
  51. $milliSecond = 'co'.dd2char( MyDate('ymdHis',time())) ;
  52. foreach($img_array as $key=>$value)
  53. {
  54. $value = trim($value);
  55. if(preg_match("#".$basehost."#i", $value) || !preg_match("#^http:\/\/#i", $value)
  56. || ($cfg_basehost != $basehost && preg_match("#".$cfg_basehost."#i", $value)))
  57. {
  58. continue;
  59. }
  60. $itype = substr($value, -4, 4);
  61. if( !preg_match("#\.(gif|jpg|png)#", $itype) ) $itype = ".jpg";
  62. $rndFileName = $imgPath.'/'.$milliSecond.'-'.$key.$itype;
  63. $iurl = $imgUrl.'/'.$milliSecond.'-'.$key.$itype;
  64. //下载并保存文件
  65. $rs = DownImageKeep($value, $rfurl, $rndFileName, '', 0, 30);
  66. if($rs)
  67. {
  68. $info = '';
  69. $imginfos = GetImageSize($rndFileName, $info);
  70. $fsize = filesize($rndFileName);
  71. $filename = $milliSecond.'-'.$key.$itype;
  72. //保存图片附件信息
  73. $inquery = "INSERT INTO `#@__uploads`(arcid,title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  74. VALUES ('0','$filename','$iurl','1','{$imginfos[0]}','$imginfos[1]','0','$fsize','".time()."','".$cuserLogin->getUserID()."'); ";
  75. $dsql->ExecuteNoneQuery($inquery);
  76. $fid = $dsql->GetLastID();
  77. AddMyAddon($fid, $iurl);
  78. if($pagestyle > 2)
  79. {
  80. $litpicname = GetImageMapDD($iurl, $cfg_ddimg_width);
  81. }
  82. else
  83. {
  84. $litpicname = $iurl;
  85. }
  86. if(empty($firstdd) && !empty($litpicname))
  87. {
  88. $firstdd = $litpicname;
  89. if(!file_exists($cfg_basedir.$firstdd))
  90. {
  91. $firstdd = $iurl;
  92. }
  93. }
  94. @WaterImg($rndFileName, 'down');
  95. $rsimg .= "{dede:img ddimg='$litpicname' text='' width='".$imginfos[0]."' height='".$imginfos[1]."'} $iurl {/dede:img}\r\n";
  96. }
  97. }
  98. return $rsimg;
  99. }
  100. /**
  101. * 获得文章body里的外部资源
  102. *
  103. * @access public
  104. * @param string $body 文档内容
  105. * @return string
  106. */
  107. function GetCurContent($body)
  108. {
  109. global $cfg_multi_site,$cfg_basehost,$cfg_basedir,$cfg_image_dir,$arcID,$cuserLogin,$dsql;
  110. $cfg_uploaddir = $cfg_image_dir;
  111. $htd = new DedeHttpDown();
  112. $basehost = "http://".$_SERVER["HTTP_HOST"];
  113. $img_array = array();
  114. preg_match_all("/src=[\"|'|\s]([^\"|^\'|^\s]*?)/isU",$body,$img_array);
  115. $img_array = array_unique($img_array[1]);
  116. $imgUrl = $cfg_uploaddir.'/'.MyDate("ymd", time());
  117. $imgPath = $cfg_basedir.$imgUrl;
  118. if(!is_dir($imgPath.'/'))
  119. {
  120. MkdirAll($imgPath, $GLOBALS['cfg_dir_purview']);
  121. CloseFtp();
  122. }
  123. $milliSecond = MyDate('His',time());
  124. foreach($img_array as $key=>$value)
  125. {
  126. if(preg_match("#".$basehost."#i", $value))
  127. {
  128. continue;
  129. }
  130. if($cfg_basehost != $basehost && preg_match("#".$cfg_basehost."#i", $value))
  131. {
  132. continue;
  133. }
  134. if(!preg_match("#^(http|https):\/\/#i", $value))
  135. {
  136. continue;
  137. }
  138. $htd->OpenUrl($value);
  139. $itype = $htd->GetHead("content-type");
  140. $itype = substr($value, -4, 4);
  141. if(!preg_match("#\.(jpg|gif|png)#i", $itype))
  142. {
  143. if($itype=='image/gif')
  144. {
  145. $itype = ".gif";
  146. }
  147. else if($itype=='image/png')
  148. {
  149. $itype = ".png";
  150. }
  151. else
  152. {
  153. $itype = '.jpg';
  154. }
  155. }
  156. $milliSecondN = dd2char($milliSecond.mt_rand(1000, 8000));
  157. $value = trim($value);
  158. $rndFileName = $imgPath.'/'.$milliSecondN.'-'.$key.$itype;
  159. $fileurl = $imgUrl.'/'.$milliSecondN.'-'.$key.$itype;
  160. $rs = $htd->SaveToBin($rndFileName);
  161. if($rs)
  162. {
  163. $info = '';
  164. $imginfos = GetImageSize($rndFileName, $info);
  165. $fsize = filesize($rndFileName);
  166. //保存图片附件信息
  167. $inquery = "INSERT INTO `#@__uploads`(arcid,title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  168. VALUES ('{$arcID}','$rndFileName','$fileurl','1','{$imginfos[0]}','$imginfos[1]','0','$fsize','".time()."','".$cuserLogin->getUserID()."'); ";
  169. $dsql->ExecuteNoneQuery($inquery);
  170. $fid = $dsql->GetLastID();
  171. AddMyAddon($fid, $fileurl);
  172. if($cfg_multi_site == 'Y')
  173. {
  174. $fileurl = $cfg_basehost.$fileurl;
  175. }
  176. $body = str_replace($value, $fileurl, $body);
  177. @WaterImg($rndFileName, 'down');
  178. }
  179. }
  180. $htd->Close();
  181. return $body;
  182. }
  183. /**
  184. * 获取一个远程图片
  185. *
  186. * @access public
  187. * @param string $url 地址
  188. * @param int $uid 用户id
  189. * @return array
  190. */
  191. function GetRemoteImage($url, $uid=0)
  192. {
  193. global $cfg_basedir, $cfg_image_dir, $cfg_addon_savetype;
  194. $cfg_uploaddir = $cfg_image_dir;
  195. $revalues = Array();
  196. $ok = false;
  197. $htd = new DedeHttpDown();
  198. $htd->OpenUrl($url);
  199. $sparr = Array("image/pjpeg", "image/jpeg", "image/gif", "image/png", "image/xpng", "image/wbmp");
  200. if(!in_array($htd->GetHead("content-type"),$sparr))
  201. {
  202. return '';
  203. }
  204. else
  205. {
  206. $imgUrl = $cfg_uploaddir.'/'.MyDate($cfg_addon_savetype, time());
  207. $imgPath = $cfg_basedir.$imgUrl;
  208. CreateDir($imgUrl);
  209. $itype = $htd->GetHead("content-type");
  210. if($itype=="image/gif")
  211. {
  212. $itype = '.gif';
  213. }
  214. else if($itype=="image/png")
  215. {
  216. $itype = '.png';
  217. }
  218. else if($itype=="image/wbmp")
  219. {
  220. $itype = '.bmp';
  221. }
  222. else
  223. {
  224. $itype = '.jpg';
  225. }
  226. $rndname = dd2char($uid.'_'.MyDate('mdHis',time()).mt_rand(1000,9999));
  227. $rndtrueName = $imgPath.'/'.$rndname.$itype;
  228. $fileurl = $imgUrl.'/'.$rndname.$itype;
  229. $ok = $htd->SaveToBin($rndtrueName);
  230. @WaterImg($rndtrueName, 'down');
  231. if($ok)
  232. {
  233. $data = GetImageSize($rndtrueName);
  234. $revalues[0] = $fileurl;
  235. $revalues[1] = $data[0];
  236. $revalues[2] = $data[1];
  237. }
  238. }
  239. $htd->Close();
  240. return ($ok ? $revalues : '');
  241. }
  242. /**
  243. * 获取远程flash
  244. *
  245. * @access public
  246. * @param string $url 地址
  247. * @param int $uid 用户id
  248. * @return string
  249. */
  250. function GetRemoteFlash($url, $uid=0)
  251. {
  252. global $cfg_addon_savetype, $cfg_media_dir, $cfg_basedir;
  253. $cfg_uploaddir = $cfg_media_dir;
  254. $revalues = '';
  255. $sparr = 'application/x-shockwave-flash';
  256. $htd = new DedeHttpDown();
  257. $htd->OpenUrl($url);
  258. if($htd->GetHead("content-type")!=$sparr)
  259. {
  260. return '';
  261. }
  262. else
  263. {
  264. $imgUrl = $cfg_uploaddir.'/'.MyDate($cfg_addon_savetype, time());
  265. $imgPath = $cfg_basedir.$imgUrl;
  266. CreateDir($imgUrl);
  267. $itype = '.swf';
  268. $milliSecond = $uid.'_'.MyDate('mdHis', time());
  269. $rndFileName = $imgPath.'/'.$milliSecond.$itype;
  270. $fileurl = $imgUrl.'/'.$milliSecond.$itype;
  271. $ok = $htd->SaveToBin($rndFileName);
  272. if($ok)
  273. {
  274. $revalues = $fileurl;
  275. }
  276. }
  277. $htd->Close();
  278. return $revalues;
  279. }
  280. /**
  281. * 检测频道ID
  282. *
  283. * @access public
  284. * @param int $typeid 栏目ID
  285. * @param int $channelid 频道ID
  286. * @return bool
  287. */
  288. function CheckChannel($typeid, $channelid)
  289. {
  290. global $dsql;
  291. if($typeid==0) return TRUE;
  292. $row = $dsql->GetOne("SELECT ispart,channeltype FROM `#@__arctype` WHERE id='$typeid' ");
  293. if($row['ispart']!=0 || $row['channeltype'] != $channelid) return FALSE;
  294. else return TRUE;
  295. }
  296. /**
  297. * 检测档案权限
  298. *
  299. * @access public
  300. * @param int $aid 文档AID
  301. * @param int $adminid 管理员ID
  302. * @return bool
  303. */
  304. function CheckArcAdmin($aid, $adminid)
  305. {
  306. global $dsql;
  307. $row = $dsql->GetOne("SELECT mid FROM `#@__archives` WHERE id='$aid' ");
  308. if($row['mid']!=$adminid) return FALSE;
  309. else return TRUE;
  310. }
  311. /**
  312. * 文档自动分页
  313. *
  314. * @access public
  315. * @param string $mybody 内容
  316. * @param string $spsize 分页大小
  317. * @param string $sptag 分页标记
  318. * @return string
  319. */
  320. function SpLongBody($mybody, $spsize, $sptag)
  321. {
  322. if(strlen($mybody) < $spsize)
  323. {
  324. return $mybody;
  325. }
  326. $mybody = stripslashes($mybody);
  327. $bds = explode('<', $mybody);
  328. $npageBody = '';
  329. $istable = 0;
  330. $mybody = '';
  331. foreach($bds as $i=>$k)
  332. {
  333. if($i==0)
  334. {
  335. $npageBody .= $bds[$i]; continue;
  336. }
  337. $bds[$i] = "<".$bds[$i];
  338. if(strlen($bds[$i])>6)
  339. {
  340. $tname = substr($bds[$i],1,5);
  341. if(strtolower($tname)=='table')
  342. {
  343. $istable++;
  344. }
  345. else if(strtolower($tname)=='/tabl')
  346. {
  347. $istable--;
  348. }
  349. if($istable>0)
  350. {
  351. $npageBody .= $bds[$i]; continue;
  352. }
  353. else
  354. {
  355. $npageBody .= $bds[$i];
  356. }
  357. }
  358. else
  359. {
  360. $npageBody .= $bds[$i];
  361. }
  362. if(strlen($npageBody)>$spsize)
  363. {
  364. $mybody .= $npageBody.$sptag;
  365. $npageBody = '';
  366. }
  367. }
  368. if($npageBody!='')
  369. {
  370. $mybody .= $npageBody;
  371. }
  372. return addslashes($mybody);
  373. }
  374. /**
  375. * 创建指定ID的文档
  376. *
  377. * @access public
  378. * @param string $aid 文档ID
  379. * @param string $ismakesign 生成标志
  380. * @param int $isremote 是否远程
  381. * @return string
  382. */
  383. function MakeArt($aid, $mkindex=FALSE, $ismakesign=FALSE, $isremote=0)
  384. {
  385. global $envs, $typeid;
  386. require_once(DEDEINC.'/arc.archives.class.php');
  387. if($ismakesign) $envs['makesign'] = 'yes';
  388. $arc = new Archives($aid);
  389. $reurl = $arc->MakeHtml($isremote);
  390. return $reurl;
  391. }
  392. /**
  393. * 取第一个图片为缩略图
  394. *
  395. * @access public
  396. * @param string $body 文档内容
  397. * @return string
  398. */
  399. function GetDDImgFromBody(&$body)
  400. {
  401. $litpic = '';
  402. preg_match_all("/(src)=[\"|'| ]{0,}([^>]*\.(gif|jpg|bmp|png))/isU",$body,$img_array);
  403. $img_array = array_unique($img_array[2]);
  404. if(count($img_array)>0)
  405. {
  406. $picname = preg_replace("/[\"|'| ]{1,}/", '', $img_array[0]);
  407. if(preg_match("#_lit\.#", $picname)) $litpic = $picname;
  408. else $litpic = GetDDImage('ddfirst', $picname,1);
  409. }
  410. return $litpic;
  411. }
  412. /**
  413. * 获得缩略图
  414. *
  415. * @access public
  416. * @param string $litpic 缩略图
  417. * @param string $picname 图片名称
  418. * @param string $isremote 是否远程
  419. * @return string
  420. */
  421. function GetDDImage($litpic, $picname, $isremote)
  422. {
  423. global $cuserLogin,$cfg_ddimg_width,$cfg_ddimg_height,$cfg_basedir,$ddcfg_image_dir,$cfg_addon_savetype;
  424. $ntime = time();
  425. if( ($litpic != 'none' || $litpic != 'ddfirst') &&
  426. !empty($_FILES[$litpic]['tmp_name']) && is_uploaded_file($_FILES[$litpic]['tmp_name']))
  427. {
  428. //如果用户自行上传缩略图
  429. $istype = 0;
  430. $sparr = Array("image/pjpeg", "image/jpeg", "image/gif", "image/png");
  431. $_FILES[$litpic]['type'] = strtolower(trim($_FILES[$litpic]['type']));
  432. if(!in_array($_FILES[$litpic]['type'], $sparr))
  433. {
  434. ShowMsg("上传的图片格式错误,请使用JPEG、GIF、PNG格式的其中一种!","-1");
  435. exit();
  436. }
  437. $savepath = $ddcfg_image_dir.'/'.MyDate($cfg_addon_savetype, $ntime);
  438. CreateDir($savepath);
  439. $fullUrl = $savepath.'/'.dd2char(MyDate('mdHis', $ntime).$cuserLogin->getUserID().mt_rand(1000, 9999));
  440. if(strtolower($_FILES[$litpic]['type']) == "image/gif")
  441. {
  442. $fullUrl = $fullUrl.".gif";
  443. }
  444. else if(strtolower($_FILES[$litpic]['type']) == "image/png")
  445. {
  446. $fullUrl = $fullUrl.".png";
  447. }
  448. else
  449. {
  450. $fullUrl = $fullUrl.".jpg";
  451. }
  452. @move_uploaded_file($_FILES[$litpic]['tmp_name'], $cfg_basedir.$fullUrl);
  453. $litpic = $fullUrl;
  454. if($GLOBALS['cfg_ddimg_full']=='Y') @ImageResizeNew($cfg_basedir.$fullUrl,$cfg_ddimg_width,$cfg_ddimg_height);
  455. else @ImageResize($cfg_basedir.$fullUrl,$cfg_ddimg_width,$cfg_ddimg_height);
  456. $img = $cfg_basedir.$litpic;
  457. }
  458. else
  459. {
  460. $picname = trim($picname);
  461. if($isremote==1 && preg_match("#^http:\/\/#i", $picname))
  462. {
  463. $litpic = $picname;
  464. $ddinfos = GetRemoteImage($litpic, $cuserLogin->getUserID());
  465. if(!is_array($ddinfos))
  466. {
  467. $litpic = '';
  468. }
  469. else
  470. {
  471. $litpic = $ddinfos[0];
  472. if($ddinfos[1] > $cfg_ddimg_width || $ddinfos[2] > $cfg_ddimg_height)
  473. {
  474. if($GLOBALS['cfg_ddimg_full']=='Y') @ImageResizeNew($cfg_basedir.$litpic,$cfg_ddimg_width,$cfg_ddimg_height);
  475. else @ImageResize($cfg_basedir.$litpic,$cfg_ddimg_width,$cfg_ddimg_height);
  476. }
  477. }
  478. }
  479. else
  480. {
  481. if($litpic=='ddfirst' && !preg_match("#^http:\/\/#i", $picname))
  482. {
  483. $oldpic = $cfg_basedir.$picname;
  484. $litpic = str_replace('.', '-lp.', $picname);
  485. if($GLOBALS['cfg_ddimg_full']=='Y') @ImageResizeNew($oldpic,$cfg_ddimg_width,$cfg_ddimg_height,$cfg_basedir.$litpic);
  486. else @ImageResize($oldpic,$cfg_ddimg_width,$cfg_ddimg_height,$cfg_basedir.$litpic);
  487. if(!is_file($cfg_basedir.$litpic)) $litpic = '';
  488. }
  489. else
  490. {
  491. $litpic = $picname;
  492. return $litpic;
  493. }
  494. }
  495. }
  496. if($litpic=='litpic' || $litpic=='ddfirst') $litpic = '';
  497. return $litpic;
  498. }
  499. /**
  500. * 获得一个附加表单
  501. *
  502. * @access public
  503. * @param object $ctag ctag
  504. * @return string
  505. */
  506. function GetFormItemA($ctag)
  507. {
  508. return GetFormItem($ctag, 'admin');
  509. }
  510. /**
  511. * 处理不同类型的数据
  512. *
  513. * @access public
  514. * @param string $dvalue
  515. * @param string $dtype
  516. * @param int $aid
  517. * @param string $job
  518. * @param string $addvar
  519. * @return string
  520. */
  521. function GetFieldValueA($dvalue, $dtype, $aid=0, $job='add', $addvar='')
  522. {
  523. return GetFieldValue($dvalue, $dtype, $aid, $job, $addvar, 'admin');
  524. }
  525. /**
  526. * 获得带值的表单(编辑时用)
  527. *
  528. * @access public
  529. * @param object $ctag ctag
  530. * @param string $fvalue fvalue
  531. * @return string
  532. */
  533. function GetFormItemValueA($ctag, $fvalue)
  534. {
  535. return GetFormItemValue($ctag, $fvalue, 'admin');
  536. }
  537. /**
  538. * 载入自定义表单(用于发布)
  539. *
  540. * @access public
  541. * @param string $fieldset 字段列表
  542. * @param string $loadtype 载入类型
  543. * @return string
  544. */
  545. function PrintAutoFieldsAdd(&$fieldset, $loadtype='all')
  546. {
  547. $dtp = new DedeTagParse();
  548. $dtp->SetNameSpace('field','<','>');
  549. $dtp->LoadSource($fieldset);
  550. $dede_addonfields = '';
  551. if(is_array($dtp->CTags))
  552. {
  553. foreach($dtp->CTags as $tid=>$ctag)
  554. {
  555. if($loadtype!='autofield'
  556. || ($loadtype=='autofield' && $ctag->GetAtt('autofield')==1) )
  557. {
  558. $dede_addonfields .= ( $dede_addonfields=="" ? $ctag->GetName().",".$ctag->GetAtt('type') : ";".$ctag->GetName().",".$ctag->GetAtt('type') );
  559. echo GetFormItemA($ctag);
  560. }
  561. }
  562. }
  563. echo "<input type='hidden' name='dede_addonfields' value=\"".$dede_addonfields."\">\r\n";
  564. }
  565. /**
  566. * 载入自定义表单(用于编辑)
  567. *
  568. * @access public
  569. * @param string $fieldset 字段列表
  570. * @param string $fieldValues 字段值
  571. * @param string $loadtype 载入类型
  572. * @return string
  573. */
  574. function PrintAutoFieldsEdit(&$fieldset, &$fieldValues, $loadtype='all')
  575. {
  576. $dtp = new DedeTagParse();
  577. $dtp->SetNameSpace("field", "<", ">");
  578. $dtp->LoadSource($fieldset);
  579. $dede_addonfields = "";
  580. if(is_array($dtp->CTags))
  581. {
  582. foreach($dtp->CTags as $tid=>$ctag)
  583. {
  584. if($loadtype != 'autofield'
  585. || ($loadtype == 'autofield' && $ctag->GetAtt('autofield') == 1) )
  586. {
  587. $dede_addonfields .= ( $dede_addonfields=='' ? $ctag->GetName().",".$ctag->GetAtt('type') : ";".$ctag->GetName().",".$ctag->GetAtt('type') );
  588. echo GetFormItemValueA($ctag, $fieldValues[$ctag->GetName()]);
  589. }
  590. }
  591. }
  592. echo "<input type='hidden' name='dede_addonfields' value=\"".$dede_addonfields."\">\r\n";
  593. }
  594. /**
  595. * 处理HTML文本
  596. * 删除非站外链接、自动摘要、自动获取缩略图
  597. *
  598. * @access public
  599. * @param string $body 内容
  600. * @param string $description 描述
  601. * @param string $litpic 缩略图
  602. * @param string $keywords 关键词
  603. * @param string $dtype 类型
  604. * @return string
  605. */
  606. function AnalyseHtmlBody($body,&$description,&$litpic,&$keywords,$dtype='')
  607. {
  608. global $autolitpic,$remote,$dellink,$autokey,$cfg_basehost,$cfg_auot_description,$id,$title,$cfg_soft_lang;
  609. $autolitpic = (empty($autolitpic) ? '' : $autolitpic);
  610. $body = stripslashes($body);
  611. //远程图片本地化
  612. if($remote==1)
  613. {
  614. $body = GetCurContent($body);
  615. }
  616. //删除非站内链接
  617. if($dellink==1)
  618. {
  619. $allow_urls = array($_SERVER['HTTP_HOST']);
  620. // 读取允许的超链接设置
  621. if(file_exists(DEDEDATA."/admin/allowurl.txt"))
  622. {
  623. $allow_urls = array_merge($allow_urls, file(DEDEDATA."/admin/allowurl.txt"));
  624. }
  625. $body = Replace_Links($body, $allow_urls);
  626. }
  627. //自动摘要
  628. if($description=='' && $cfg_auot_description>0)
  629. {
  630. $description = cn_substr(html2text($body),$cfg_auot_description);
  631. $description = trim(preg_replace('/#p#|#e#/','',$description));
  632. $description = addslashes($description);
  633. }
  634. //自动获取缩略图
  635. if($autolitpic==1 && $litpic=='')
  636. {
  637. $litpic = GetDDImgFromBody($body);
  638. }
  639. //自动获取关键字
  640. if($autokey==1 && $keywords=='')
  641. {
  642. $subject = $title;
  643. $message = $body;
  644. include_once(DEDEINC.'/splitword.class.php');
  645. $keywords = '';
  646. $sp = new SplitWord($cfg_soft_lang, $cfg_soft_lang);
  647. $sp->SetSource($subject, $cfg_soft_lang, $cfg_soft_lang);
  648. $sp->StartAnalysis();
  649. $titleindexs = preg_replace("/#p#|#e#/",'',$sp->GetFinallyIndex());
  650. $sp->SetSource(Html2Text($message), $cfg_soft_lang, $cfg_soft_lang);
  651. $sp->StartAnalysis();
  652. $allindexs = preg_replace("/#p#|#e#/",'',$sp->GetFinallyIndex());
  653. if(is_array($allindexs) && is_array($titleindexs))
  654. {
  655. foreach($titleindexs as $k => $v)
  656. {
  657. if(strlen($keywords.$k)>=60)
  658. {
  659. break;
  660. }
  661. else
  662. {
  663. if(strlen($k) <= 2) continue;
  664. $keywords .= $k.',';
  665. }
  666. }
  667. foreach($allindexs as $k => $v)
  668. {
  669. if(strlen($keywords.$k)>=60)
  670. {
  671. break;
  672. }
  673. else if(!in_array($k,$titleindexs))
  674. {
  675. if(strlen($k) <= 2) continue;
  676. $keywords .= $k.',';
  677. }
  678. }
  679. }
  680. $sp = null;
  681. }
  682. $body = GetFieldValueA($body,$dtype,$id);
  683. $body = addslashes($body);
  684. return $body;
  685. }
  686. /**
  687. * 删除非站内链接
  688. *
  689. * @access public
  690. * @param string $body 内容
  691. * @param array $allow_urls 允许的超链接
  692. * @return string
  693. */
  694. function Replace_Links( &$body, $allow_urls=array() )
  695. {
  696. $host_rule = join('|', $allow_urls);
  697. $host_rule = preg_replace("#[\n\r]#", '', $host_rule);
  698. $host_rule = str_replace('.', "\\.", $host_rule);
  699. $host_rule = str_replace('/', "\\/", $host_rule);
  700. $arr = '';
  701. preg_match_all("#<a([^>]*)>(.*)<\/a>#iU", $body, $arr);
  702. if( is_array($arr[0]) )
  703. {
  704. $rparr = array();
  705. $tgarr = array();
  706. foreach($arr[0] as $i=>$v)
  707. {
  708. if( $host_rule != '' && preg_match('#'.$host_rule.'#i', $arr[1][$i]) )
  709. {
  710. continue;
  711. } else {
  712. $rparr[] = $v;
  713. $tgarr[] = $arr[2][$i];
  714. }
  715. }
  716. if( !empty($rparr) )
  717. {
  718. $body = str_replace($rparr, $tgarr, $body);
  719. }
  720. }
  721. $arr = $rparr = $tgarr = '';
  722. return $body;
  723. }
  724. /**
  725. * 图集里大图的小图
  726. *
  727. * @access public
  728. * @param string $filename 图片名称
  729. * @param string $maxwidth 最大宽度
  730. * @return string
  731. */
  732. function GetImageMapDD($filename, $maxwidth)
  733. {
  734. global $cuserLogin, $dsql, $cfg_ddimg_height, $cfg_ddimg_full;
  735. $ddn = substr($filename, -3);
  736. $ddpicok = preg_replace("#\.".$ddn."$#", "-lp.".$ddn, $filename);
  737. $toFile = $GLOBALS['cfg_basedir'].$ddpicok;
  738. if($cfg_ddimg_full=='Y') ImageResizeNew($GLOBALS['cfg_basedir'].$filename, $maxwidth, $cfg_ddimg_height, $toFile);
  739. else ImageResize($GLOBALS['cfg_basedir'].$filename, $maxwidth, $cfg_ddimg_height, $toFile);
  740. //保存图片附件信息
  741. $fsize = filesize($toFile);
  742. $ddpicoks = explode('/', $ddpicok);
  743. $filename = $ddpicoks[count($ddpicoks)-1];
  744. $inquery = "INSERT INTO `#@__uploads`(arcid,title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  745. VALUES ('0','$filename','$ddpicok','1','0','0','0','$fsize','".time()."','".$cuserLogin->getUserID()."'); ";
  746. $dsql->ExecuteNoneQuery($inquery);
  747. $fid = $dsql->GetLastID();
  748. AddMyAddon($fid, $ddpicok);
  749. return $ddpicok;
  750. }
  751. /**
  752. * 上传一个未经处理的图片
  753. *
  754. * @access public
  755. * @param string $upname 上传框名称
  756. * @param string $handurl 手工填写的网址
  757. * @param string $ddisremote 是否下载远程图片 0 不下, 1 下载
  758. * @param string $ntitle 注解文字 如果表单有 title 字段可不管
  759. * @return mixed
  760. */
  761. function UploadOneImage($upname,$handurl='',$isremote=1,$ntitle='')
  762. {
  763. global $cuserLogin,$cfg_basedir,$cfg_image_dir,$title, $dsql;
  764. if($ntitle!='')
  765. {
  766. $title = $ntitle;
  767. }
  768. $ntime = time();
  769. $filename = '';
  770. $isrm_up = FALSE;
  771. $handurl = trim($handurl);
  772. //如果用户自行上传了图片
  773. if(!empty($_FILES[$upname]['tmp_name']) && is_uploaded_file($_FILES[$upname]['tmp_name']))
  774. {
  775. $istype = 0;
  776. $sparr = Array("image/pjpeg", "image/jpeg", "image/gif", "image/png");
  777. $_FILES[$upname]['type'] = strtolower(trim($_FILES[$upname]['type']));
  778. if(!in_array($_FILES[$upname]['type'], $sparr))
  779. {
  780. ShowMsg("上传的图片格式错误,请使用JPEG、GIF、PNG格式的其中一种!","-1");
  781. exit();
  782. }
  783. if(!empty($handurl) && !preg_match("#^http:\/\/#i", $handurl) && file_exists($cfg_basedir.$handurl) )
  784. {
  785. if(!is_object($dsql))
  786. {
  787. $dsql = new DedeSql();
  788. }
  789. $dsql->ExecuteNoneQuery("DELETE FROM `#@__uploads` WHERE url LIKE '$handurl' ");
  790. $fullUrl = preg_replace("#\.([a-z]*)$#i", "", $handurl);
  791. }
  792. else
  793. {
  794. $savepath = $cfg_image_dir.'/'.strftime("%Y-%m",$ntime);
  795. CreateDir($savepath);
  796. $fullUrl = $savepath.'/'.strftime("%d",$ntime).dd2char(strftime("%H%M%S", $ntime).'0'.$cuserLogin->getUserID().'0'.mt_rand(1000, 9999));
  797. }
  798. if(strtolower($_FILES[$upname]['type'])=="image/gif")
  799. {
  800. $fullUrl = $fullUrl.".gif";
  801. }
  802. else if(strtolower($_FILES[$upname]['type'])=="image/png")
  803. {
  804. $fullUrl = $fullUrl.".png";
  805. }
  806. else
  807. {
  808. $fullUrl = $fullUrl.".jpg";
  809. }
  810. //保存
  811. @move_uploaded_file($_FILES[$upname]['tmp_name'], $cfg_basedir.$fullUrl);
  812. $filename = $fullUrl;
  813. //水印
  814. @WaterImg($imgfile, 'up');
  815. $isrm_up = TRUE;
  816. }
  817. //远程或选择本地图片
  818. else
  819. {
  820. if($handurl=='')
  821. {
  822. return '';
  823. }
  824. //远程图片并要求本地化
  825. if($isremote==1 && preg_match("#^http:\/\/#i", $handurl))
  826. {
  827. $ddinfos = GetRemoteImage($handurl, $cuserLogin->getUserID());
  828. if(!is_array($ddinfos))
  829. {
  830. $litpic = "";
  831. }
  832. else
  833. {
  834. $filename = $ddinfos[0];
  835. }
  836. $isrm_up = TRUE;
  837. //本地图片或远程不要求本地化
  838. }
  839. else
  840. {
  841. $filename = $handurl;
  842. }
  843. }
  844. $imgfile = $cfg_basedir.$filename;
  845. if(is_file($imgfile) && $isrm_up && $filename!='')
  846. {
  847. $info = "";
  848. $imginfos = GetImageSize($imgfile, $info);
  849. //把新上传的图片信息保存到媒体文档管理档案中
  850. $inquery = "
  851. INSERT INTO #@__uploads(title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  852. VALUES ('$title','$filename','1','".$imginfos[0]."','".$imginfos[1]."','0','".filesize($imgfile)."','".time()."','".$cuserLogin->getUserID()."');
  853. ";
  854. $dsql->ExecuteNoneQuery($inquery);
  855. }
  856. return $filename;
  857. }
  858. /**
  859. * 获取更新测试信息
  860. *
  861. * @access public
  862. * @return string
  863. */
  864. function GetUpdateTest()
  865. {
  866. global $arcID, $typeid, $cfg_make_andcat, $cfg_makeindex, $cfg_make_prenext;
  867. $revalue = $dolist = '';
  868. if($cfg_makeindex=='Y' || $cfg_make_andcat=='Y' || $cfg_make_prenext=='Y')
  869. {
  870. if($cfg_make_prenext=='Y' && !empty($typeid)) $dolist = 'makeprenext';
  871. if($cfg_makeindex=='Y') $dolist .= empty($dolist) ? 'makeindex' : ',makeindex';
  872. if($cfg_make_andcat=='Y') $dolist .= empty($dolist) ? 'makeparenttype' : ',makeparenttype';
  873. $dolists = explode(',', $dolist);
  874. $jumpUrl = "task_do.php?typeid={$typeid}&aid={$arcID}&dopost={$dolists[0]}&nextdo=".preg_replace("#".$dolists[0]."[,]{0,1}#", '', $dolist);
  875. $revalue = "<table width='80%' style='border:1px dashed #cdcdcd;margin-left:20px;margin-bottom:15px' id='tgtable' align='left'><tr><td bgcolor='#EBF5C9'>&nbsp;<strong>正在进行相关内容更新,请完成前不要进行其它操作:</strong>\r\n</td></tr>\r\n";
  876. $revalue .= "<tr><td>\r\n<iframe name='stafrm' frameborder='0' id='stafrm' width='100%' height='200px' src='$jumpUrl'></iframe>\r\n</td></tr>\r\n";
  877. $revalue .= "</table>";
  878. }
  879. else
  880. {
  881. $revalue = '';
  882. }
  883. return $revalue;
  884. }