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

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