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

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