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

946 lines
29KB

  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) 2020, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.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' class='btn btn-secondary btn-sm'>记忆的列表页</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. global $cfg_bizcore_appid,$cfg_bizcore_key,$cfg_bizcore_hostname,$cfg_bizcore_port;
  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. // 采用DedeBIZ Core分词组件分词
  645. if (!empty($cfg_bizcore_appid) && !empty($cfg_bizcore_key)) {
  646. $keywords = '';
  647. $client = new DedeBizClient($cfg_bizcore_hostname, $cfg_bizcore_port);
  648. $client->appid = $cfg_bizcore_appid;
  649. $client->key = $cfg_bizcore_key;
  650. $data = $client->Spliteword($subject.Html2Text($message));
  651. $keywords = $data->data;
  652. $client->Close();
  653. } else {
  654. include_once(DEDEINC.'/splitword.class.php');
  655. $keywords = '';
  656. $sp = new SplitWord($cfg_soft_lang, $cfg_soft_lang);
  657. $sp->SetSource($subject, $cfg_soft_lang, $cfg_soft_lang);
  658. $sp->StartAnalysis();
  659. $titleindexs = preg_replace("/#p#|#e#/",'',$sp->GetFinallyIndex());
  660. $sp->SetSource(Html2Text($message), $cfg_soft_lang, $cfg_soft_lang);
  661. $sp->StartAnalysis();
  662. $allindexs = preg_replace("/#p#|#e#/",'',$sp->GetFinallyIndex());
  663. if(is_array($allindexs) && is_array($titleindexs))
  664. {
  665. foreach($titleindexs as $k => $v)
  666. {
  667. if(strlen($keywords.$k)>=60)
  668. {
  669. break;
  670. }
  671. else
  672. {
  673. if(strlen($k) <= 2) continue;
  674. $keywords .= $k.',';
  675. }
  676. }
  677. foreach($allindexs as $k => $v)
  678. {
  679. if(strlen($keywords.$k)>=60)
  680. {
  681. break;
  682. }
  683. else if(!in_array($k,$titleindexs))
  684. {
  685. if(strlen($k) <= 2) continue;
  686. $keywords .= $k.',';
  687. }
  688. }
  689. }
  690. $sp = null;
  691. }
  692. }
  693. $body = GetFieldValueA($body,$dtype,$id);
  694. $body = addslashes($body);
  695. return $body;
  696. }
  697. /**
  698. * 删除非站内链接
  699. *
  700. * @access public
  701. * @param string $body 内容
  702. * @param array $allow_urls 允许的超链接
  703. * @return string
  704. */
  705. function Replace_Links( &$body, $allow_urls=array() )
  706. {
  707. $host_rule = join('|', $allow_urls);
  708. $host_rule = preg_replace("#[\n\r]#", '', $host_rule);
  709. $host_rule = str_replace('.', "\\.", $host_rule);
  710. $host_rule = str_replace('/', "\\/", $host_rule);
  711. $arr = array();
  712. preg_match_all("#<a([^>]*)>(.*)<\/a>#iU", $body, $arr);
  713. if( is_array($arr[0]) )
  714. {
  715. $rparr = array();
  716. $tgarr = array();
  717. foreach($arr[0] as $i=>$v)
  718. {
  719. if( $host_rule != '' && preg_match('#'.$host_rule.'#i', $arr[1][$i]) )
  720. {
  721. continue;
  722. } else {
  723. $rparr[] = $v;
  724. $tgarr[] = $arr[2][$i];
  725. }
  726. }
  727. if( !empty($rparr) )
  728. {
  729. $body = str_replace($rparr, $tgarr, $body);
  730. }
  731. }
  732. $arr = $rparr = $tgarr = '';
  733. return $body;
  734. }
  735. /**
  736. * 图集里大图的小图
  737. *
  738. * @access public
  739. * @param string $filename 图片名称
  740. * @param string $maxwidth 最大宽度
  741. * @return string
  742. */
  743. function GetImageMapDD($filename, $maxwidth)
  744. {
  745. global $cuserLogin, $dsql, $cfg_ddimg_height, $cfg_ddimg_full;
  746. $ddn = substr($filename, -3);
  747. $ddpicok = preg_replace("#\.".$ddn."$#", "-lp.".$ddn, $filename);
  748. $toFile = $GLOBALS['cfg_basedir'].$ddpicok;
  749. if($cfg_ddimg_full=='Y') ImageResizeNew($GLOBALS['cfg_basedir'].$filename, $maxwidth, $cfg_ddimg_height, $toFile);
  750. else ImageResize($GLOBALS['cfg_basedir'].$filename, $maxwidth, $cfg_ddimg_height, $toFile);
  751. //保存图片附件信息
  752. $fsize = filesize($toFile);
  753. $ddpicoks = explode('/', $ddpicok);
  754. $filename = $ddpicoks[count($ddpicoks)-1];
  755. $inquery = "INSERT INTO `#@__uploads`(arcid,title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  756. VALUES ('0','$filename','$ddpicok','1','0','0','0','$fsize','".time()."','".$cuserLogin->getUserID()."'); ";
  757. $dsql->ExecuteNoneQuery($inquery);
  758. $fid = $dsql->GetLastID();
  759. AddMyAddon($fid, $ddpicok);
  760. return $ddpicok;
  761. }
  762. /**
  763. * 上传一个未经处理的图片
  764. *
  765. * @access public
  766. * @param string $upname 上传框名称
  767. * @param string $handurl 手工填写的网址
  768. * @param string $ddisremote 是否下载远程图片 0 不下, 1 下载
  769. * @param string $ntitle 注解文字 如果表单有 title 字段可不管
  770. * @return mixed
  771. */
  772. function UploadOneImage($upname,$handurl='',$isremote=1,$ntitle='')
  773. {
  774. global $cuserLogin,$cfg_basedir,$cfg_image_dir,$title, $dsql;
  775. if($ntitle!='')
  776. {
  777. $title = $ntitle;
  778. }
  779. $ntime = time();
  780. $filename = '';
  781. $isrm_up = FALSE;
  782. $handurl = trim($handurl);
  783. //如果用户自行上传了图片
  784. if(!empty($_FILES[$upname]['tmp_name']) && is_uploaded_file($_FILES[$upname]['tmp_name']))
  785. {
  786. $istype = 0;
  787. $sparr = Array("image/pjpeg", "image/jpeg", "image/gif", "image/png");
  788. $_FILES[$upname]['type'] = strtolower(trim($_FILES[$upname]['type']));
  789. if(!in_array($_FILES[$upname]['type'], $sparr))
  790. {
  791. ShowMsg("上传的图片格式错误,请使用JPEG、GIF、PNG格式的其中一种!","-1");
  792. exit();
  793. }
  794. if(!empty($handurl) && !preg_match("#^http:\/\/#i", $handurl) && file_exists($cfg_basedir.$handurl) )
  795. {
  796. if(!is_object($dsql))
  797. {
  798. $dsql = new DedeSql();
  799. }
  800. $dsql->ExecuteNoneQuery("DELETE FROM `#@__uploads` WHERE url LIKE '$handurl' ");
  801. $fullUrl = preg_replace("#\.([a-z]*)$#i", "", $handurl);
  802. }
  803. else
  804. {
  805. $savepath = $cfg_image_dir.'/'.strftime("%Y-%m",$ntime);
  806. CreateDir($savepath);
  807. $fullUrl = $savepath.'/'.strftime("%d",$ntime).dd2char(strftime("%H%M%S", $ntime).'0'.$cuserLogin->getUserID().'0'.mt_rand(1000, 9999));
  808. }
  809. if(strtolower($_FILES[$upname]['type'])=="image/gif")
  810. {
  811. $fullUrl = $fullUrl.".gif";
  812. }
  813. else if(strtolower($_FILES[$upname]['type'])=="image/png")
  814. {
  815. $fullUrl = $fullUrl.".png";
  816. }
  817. else
  818. {
  819. $fullUrl = $fullUrl.".jpg";
  820. }
  821. //保存
  822. @move_uploaded_file($_FILES[$upname]['tmp_name'], $cfg_basedir.$fullUrl);
  823. $filename = $fullUrl;
  824. //水印
  825. @WaterImg($cfg_basedir.$fullUrl, 'up');
  826. $isrm_up = TRUE;
  827. }
  828. //远程或选择本地图片
  829. else
  830. {
  831. if($handurl=='')
  832. {
  833. return '';
  834. }
  835. //远程图片并要求本地化
  836. if($isremote==1 && preg_match("#^http[s]?:\/\/#i", $handurl))
  837. {
  838. $ddinfos = GetRemoteImage($handurl, $cuserLogin->getUserID());
  839. if(!is_array($ddinfos))
  840. {
  841. $litpic = "";
  842. }
  843. else
  844. {
  845. $filename = $ddinfos[0];
  846. }
  847. $isrm_up = TRUE;
  848. //本地图片或远程不要求本地化
  849. }
  850. else
  851. {
  852. $filename = $handurl;
  853. }
  854. }
  855. $imgfile = $cfg_basedir.$filename;
  856. if(is_file($imgfile) && $isrm_up && $filename!='')
  857. {
  858. $info = "";
  859. $imginfos = GetImageSize($imgfile, $info);
  860. //把新上传的图片信息保存到媒体文档管理档案中
  861. $inquery = "
  862. INSERT INTO `#@__uploads`(title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  863. VALUES ('$title','$filename','1','".$imginfos[0]."','".$imginfos[1]."','0','".filesize($imgfile)."','".time()."','".$cuserLogin->getUserID()."');
  864. ";
  865. $dsql->ExecuteNoneQuery($inquery);
  866. }
  867. return $filename;
  868. }
  869. /**
  870. * 获取更新测试信息
  871. *
  872. * @access public
  873. * @return string
  874. */
  875. function GetUpdateTest()
  876. {
  877. global $arcID, $typeid, $cfg_make_andcat, $cfg_makeindex, $cfg_make_prenext;
  878. $revalue = $dolist = '';
  879. if($cfg_makeindex=='Y' || $cfg_make_andcat=='Y' || $cfg_make_prenext=='Y')
  880. {
  881. if($cfg_make_prenext=='Y' && !empty($typeid)) $dolist = 'makeprenext';
  882. if($cfg_makeindex=='Y') $dolist .= empty($dolist) ? 'makeindex' : ',makeindex';
  883. if($cfg_make_andcat=='Y') $dolist .= empty($dolist) ? 'makeparenttype' : ',makeparenttype';
  884. $dolists = explode(',', $dolist);
  885. $jumpUrl = "task_do.php?typeid={$typeid}&aid={$arcID}&dopost={$dolists[0]}&nextdo=".preg_replace("#".$dolists[0]."[,]{0,1}#", '', $dolist);
  886. $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";
  887. $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";
  888. $revalue .= "</table>";
  889. }
  890. else
  891. {
  892. $revalue = '';
  893. }
  894. return $revalue;
  895. }