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

811 lines
29KB

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