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

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