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

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