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

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