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

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