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

776 lines
28KB

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