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

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