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

763 lines
28KB

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