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

835 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) 2021, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. require_once(DEDEINC . '/dedehttpdown.class.php');
  12. require_once(DEDEINC . '/image.func.php');
  13. require_once(DEDEINC . '/archives.func.php');
  14. require_once(DEDEINC . '/arc.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-secondary 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 . '/arc.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') &&
  376. !empty($_FILES[$litpic]['tmp_name']) && is_uploaded_file($_FILES[$litpic]['tmp_name'])
  377. ) {
  378. //如果用户自行上传缩略图
  379. $istype = 0;
  380. $sparr = array("image/pjpeg", "image/jpeg", "image/gif", "image/png");
  381. $_FILES[$litpic]['type'] = strtolower(trim($_FILES[$litpic]['type']));
  382. if (!in_array($_FILES[$litpic]['type'], $sparr)) {
  383. ShowMsg("上传的图片格式错误,请使用JPEG、GIF、PNG格式的其中一种!", "-1");
  384. exit();
  385. }
  386. $savepath = $ddcfg_image_dir . '/' . MyDate($cfg_addon_savetype, $ntime);
  387. CreateDir($savepath);
  388. $fullUrl = $savepath . '/' . dd2char(MyDate('mdHis', $ntime) . $cuserLogin->getUserID() . mt_rand(1000, 9999));
  389. if (strtolower($_FILES[$litpic]['type']) == "image/gif") {
  390. $fullUrl = $fullUrl . ".gif";
  391. } else if (strtolower($_FILES[$litpic]['type']) == "image/png") {
  392. $fullUrl = $fullUrl . ".png";
  393. } else {
  394. $fullUrl = $fullUrl . ".jpg";
  395. }
  396. @move_uploaded_file($_FILES[$litpic]['tmp_name'], $cfg_basedir . $fullUrl);
  397. $litpic = $fullUrl;
  398. if ($GLOBALS['cfg_ddimg_full'] == 'Y') @ImageResizeNew($cfg_basedir . $fullUrl, $cfg_ddimg_width, $cfg_ddimg_height);
  399. else @ImageResize($cfg_basedir . $fullUrl, $cfg_ddimg_width, $cfg_ddimg_height);
  400. $img = $cfg_basedir . $litpic;
  401. } else {
  402. $picname = trim($picname);
  403. if ($isremote == 1 && preg_match("#^http:\/\/#i", $picname)) {
  404. $litpic = $picname;
  405. $ddinfos = GetRemoteImage($litpic, $cuserLogin->getUserID());
  406. if (!is_array($ddinfos)) {
  407. $litpic = '';
  408. } else {
  409. $litpic = $ddinfos[0];
  410. if ($ddinfos[1] > $cfg_ddimg_width || $ddinfos[2] > $cfg_ddimg_height) {
  411. if ($GLOBALS['cfg_ddimg_full'] == 'Y') @ImageResizeNew($cfg_basedir . $litpic, $cfg_ddimg_width, $cfg_ddimg_height);
  412. else @ImageResize($cfg_basedir . $litpic, $cfg_ddimg_width, $cfg_ddimg_height);
  413. }
  414. }
  415. } else {
  416. if ($litpic == 'ddfirst' && !preg_match("#^http:\/\/#i", $picname)) {
  417. $oldpic = $cfg_basedir . $picname;
  418. $litpic = str_replace('.', '-lp.', $picname);
  419. if ($GLOBALS['cfg_ddimg_full'] == 'Y') @ImageResizeNew($oldpic, $cfg_ddimg_width, $cfg_ddimg_height, $cfg_basedir . $litpic);
  420. else @ImageResize($oldpic, $cfg_ddimg_width, $cfg_ddimg_height, $cfg_basedir . $litpic);
  421. if (!is_file($cfg_basedir . $litpic)) $litpic = '';
  422. } else {
  423. $litpic = $picname;
  424. return $litpic;
  425. }
  426. }
  427. }
  428. if ($litpic == 'litpic' || $litpic == 'ddfirst') $litpic = '';
  429. return $litpic;
  430. }
  431. /**
  432. * 获得一个附加表单
  433. *
  434. * @access public
  435. * @param object $ctag ctag
  436. * @return string
  437. */
  438. function GetFormItemA($ctag)
  439. {
  440. return GetFormItem($ctag, 'admin');
  441. }
  442. /**
  443. * 处理不同类型的数据
  444. *
  445. * @access public
  446. * @param string $dvalue
  447. * @param string $dtype
  448. * @param int $aid
  449. * @param string $job
  450. * @param string $addvar
  451. * @return string
  452. */
  453. function GetFieldValueA($dvalue, $dtype, $aid = 0, $job = 'add', $addvar = '')
  454. {
  455. return GetFieldValue($dvalue, $dtype, $aid, $job, $addvar, 'admin');
  456. }
  457. /**
  458. * 获得带值的表单(编辑时用)
  459. *
  460. * @access public
  461. * @param object $ctag ctag
  462. * @param string $fvalue fvalue
  463. * @return string
  464. */
  465. function GetFormItemValueA($ctag, $fvalue)
  466. {
  467. return GetFormItemValue($ctag, $fvalue, 'admin');
  468. }
  469. /**
  470. * 载入自定义表单(用于发布)
  471. *
  472. * @access public
  473. * @param string $fieldset 字段列表
  474. * @param string $loadtype 载入类型
  475. * @return string
  476. */
  477. function PrintAutoFieldsAdd($fieldset, $loadtype = 'all')
  478. {
  479. $dtp = new DedeTagParse();
  480. $dtp->SetNameSpace('field', '<', '>');
  481. $dtp->LoadSource($fieldset);
  482. $dede_addonfields = '';
  483. if (is_array($dtp->CTags)) {
  484. foreach ($dtp->CTags as $tid => $ctag) {
  485. if (
  486. $loadtype != 'autofield'
  487. || ($loadtype == 'autofield' && $ctag->GetAtt('autofield') == 1)
  488. ) {
  489. $dede_addonfields .= ($dede_addonfields == "" ? $ctag->GetName() . "," . $ctag->GetAtt('type') : ";" . $ctag->GetName() . "," . $ctag->GetAtt('type'));
  490. echo GetFormItemA($ctag);
  491. }
  492. }
  493. }
  494. echo "<input type='hidden' name='dede_addonfields' value=\"" . $dede_addonfields . "\">\r\n";
  495. }
  496. /**
  497. * 载入自定义表单(用于编辑)
  498. *
  499. * @access public
  500. * @param string $fieldset 字段列表
  501. * @param string $fieldValues 字段值
  502. * @param string $loadtype 载入类型
  503. * @return string
  504. */
  505. function PrintAutoFieldsEdit(&$fieldset, &$fieldValues, $loadtype = 'all')
  506. {
  507. $dtp = new DedeTagParse();
  508. $dtp->SetNameSpace("field", "<", ">");
  509. $dtp->LoadSource($fieldset);
  510. $dede_addonfields = "";
  511. if (is_array($dtp->CTags)) {
  512. foreach ($dtp->CTags as $tid => $ctag) {
  513. if (
  514. $loadtype != 'autofield'
  515. || ($loadtype == 'autofield' && $ctag->GetAtt('autofield') == 1)
  516. ) {
  517. $dede_addonfields .= ($dede_addonfields == '' ? $ctag->GetName() . "," . $ctag->GetAtt('type') : ";" . $ctag->GetName() . "," . $ctag->GetAtt('type'));
  518. echo GetFormItemValueA($ctag, $fieldValues[$ctag->GetName()]);
  519. }
  520. }
  521. }
  522. echo "<input type='hidden' name='dede_addonfields' value=\"" . $dede_addonfields . "\">\r\n";
  523. }
  524. /**
  525. * 处理HTML文本
  526. * 删除非站外链接、自动摘要、自动获取缩略图
  527. *
  528. * @access public
  529. * @param string $body 内容
  530. * @param string $description 描述
  531. * @param string $litpic 缩略图
  532. * @param string $keywords 关键词
  533. * @param string $dtype 类型
  534. * @return string
  535. */
  536. function AnalyseHtmlBody($body, &$description, &$litpic, &$keywords, $dtype = '')
  537. {
  538. global $autolitpic, $remote, $dellink, $autokey, $cfg_basehost, $cfg_auot_description, $id, $title, $cfg_soft_lang;
  539. global $cfg_bizcore_appid, $cfg_bizcore_key, $cfg_bizcore_hostname, $cfg_bizcore_port;
  540. $autolitpic = (empty($autolitpic) ? '' : $autolitpic);
  541. $body = stripslashes($body);
  542. //远程图片本地化
  543. if ($remote == 1) {
  544. $body = GetCurContent($body);
  545. }
  546. //删除非站内链接
  547. if ($dellink == 1) {
  548. $allow_urls = array($_SERVER['HTTP_HOST']);
  549. // 读取允许的超链接设置
  550. if (file_exists(DEDEDATA . "/admin/allowurl.txt")) {
  551. $allow_urls = array_merge($allow_urls, file(DEDEDATA . "/admin/allowurl.txt"));
  552. }
  553. $body = Replace_Links($body, $allow_urls);
  554. }
  555. //自动摘要
  556. if ($description == '' && $cfg_auot_description > 0) {
  557. $description = cn_substr(html2text($body), $cfg_auot_description);
  558. $description = trim(preg_replace('/#p#|#e#/', '', $description));
  559. $description = addslashes($description);
  560. }
  561. //自动获取缩略图
  562. if ($autolitpic == 1 && $litpic == '') {
  563. $litpic = GetDDImgFromBody($body);
  564. }
  565. //自动获取关键字
  566. if ($autokey == 1 && $keywords == '') {
  567. $subject = $title;
  568. $message = $body;
  569. // 采用DedeBIZ Core分词组件分词
  570. if (!empty($cfg_bizcore_appid) && !empty($cfg_bizcore_key)) {
  571. $keywords = '';
  572. $client = new DedeBizClient($cfg_bizcore_hostname, $cfg_bizcore_port);
  573. $client->appid = $cfg_bizcore_appid;
  574. $client->key = $cfg_bizcore_key;
  575. $data = $client->Spliteword($subject . Html2Text($message));
  576. $keywords = $data->data;
  577. $client->Close();
  578. } else {
  579. include_once(DEDEINC . '/splitword.class.php');
  580. $keywords = '';
  581. $sp = new SplitWord($cfg_soft_lang, $cfg_soft_lang);
  582. $sp->SetSource($subject, $cfg_soft_lang, $cfg_soft_lang);
  583. $sp->StartAnalysis();
  584. $titleindexs = preg_replace("/#p#|#e#/", '', $sp->GetFinallyIndex());
  585. $sp->SetSource(Html2Text($message), $cfg_soft_lang, $cfg_soft_lang);
  586. $sp->StartAnalysis();
  587. $allindexs = preg_replace("/#p#|#e#/", '', $sp->GetFinallyIndex());
  588. if (is_array($allindexs) && is_array($titleindexs)) {
  589. foreach ($titleindexs as $k => $v) {
  590. if (strlen($keywords . $k) >= 60) {
  591. break;
  592. } else {
  593. if (strlen($k) <= 2) continue;
  594. $keywords .= $k . ',';
  595. }
  596. }
  597. foreach ($allindexs as $k => $v) {
  598. if (strlen($keywords . $k) >= 60) {
  599. break;
  600. } else if (!in_array($k, $titleindexs)) {
  601. if (strlen($k) <= 2) continue;
  602. $keywords .= $k . ',';
  603. }
  604. }
  605. }
  606. $sp = null;
  607. }
  608. }
  609. $body = GetFieldValueA($body, $dtype, $id);
  610. $body = addslashes($body);
  611. return $body;
  612. }
  613. /**
  614. * 删除非站内链接
  615. *
  616. * @access public
  617. * @param string $body 内容
  618. * @param array $allow_urls 允许的超链接
  619. * @return string
  620. */
  621. function Replace_Links(&$body, $allow_urls = array())
  622. {
  623. $host_rule = join('|', $allow_urls);
  624. $host_rule = preg_replace("#[\n\r]#", '', $host_rule);
  625. $host_rule = str_replace('.', "\\.", $host_rule);
  626. $host_rule = str_replace('/', "\\/", $host_rule);
  627. $arr = array();
  628. preg_match_all("#<a([^>]*)>(.*)<\/a>#iU", $body, $arr);
  629. if (is_array($arr[0])) {
  630. $rparr = array();
  631. $tgarr = array();
  632. foreach ($arr[0] as $i => $v) {
  633. if ($host_rule != '' && preg_match('#' . $host_rule . '#i', $arr[1][$i])) {
  634. continue;
  635. } else {
  636. $rparr[] = $v;
  637. $tgarr[] = $arr[2][$i];
  638. }
  639. }
  640. if (!empty($rparr)) {
  641. $body = str_replace($rparr, $tgarr, $body);
  642. }
  643. }
  644. $arr = $rparr = $tgarr = '';
  645. return $body;
  646. }
  647. /**
  648. * 图集里大图的小图
  649. *
  650. * @access public
  651. * @param string $filename 图片名称
  652. * @param string $maxwidth 最大宽度
  653. * @return string
  654. */
  655. function GetImageMapDD($filename, $maxwidth)
  656. {
  657. global $cuserLogin, $dsql, $cfg_ddimg_height, $cfg_ddimg_full;
  658. $ddn = substr($filename, -3);
  659. $ddpicok = preg_replace("#\." . $ddn . "$#", "-lp." . $ddn, $filename);
  660. $toFile = $GLOBALS['cfg_basedir'] . $ddpicok;
  661. if ($cfg_ddimg_full == 'Y') ImageResizeNew($GLOBALS['cfg_basedir'] . $filename, $maxwidth, $cfg_ddimg_height, $toFile);
  662. else ImageResize($GLOBALS['cfg_basedir'] . $filename, $maxwidth, $cfg_ddimg_height, $toFile);
  663. //保存图片附件信息
  664. $fsize = filesize($toFile);
  665. $ddpicoks = explode('/', $ddpicok);
  666. $filename = $ddpicoks[count($ddpicoks) - 1];
  667. $inquery = "INSERT INTO `#@__uploads`(arcid,title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  668. VALUES ('0','$filename','$ddpicok','1','0','0','0','$fsize','" . time() . "','" . $cuserLogin->getUserID() . "'); ";
  669. $dsql->ExecuteNoneQuery($inquery);
  670. $fid = $dsql->GetLastID();
  671. AddMyAddon($fid, $ddpicok);
  672. return $ddpicok;
  673. }
  674. /**
  675. * 上传一个未经处理的图片
  676. *
  677. * @access public
  678. * @param string $upname 上传框名称
  679. * @param string $handurl 手工填写的网址
  680. * @param string $ddisremote 是否下载远程图片 0 不下, 1 下载
  681. * @param string $ntitle 注解文字 如果表单有 title 字段可不管
  682. * @return mixed
  683. */
  684. function UploadOneImage($upname, $handurl = '', $isremote = 1, $ntitle = '')
  685. {
  686. global $cuserLogin, $cfg_basedir, $cfg_image_dir, $title, $dsql;
  687. if ($ntitle != '') {
  688. $title = $ntitle;
  689. }
  690. $ntime = time();
  691. $filename = '';
  692. $isrm_up = FALSE;
  693. $handurl = trim($handurl);
  694. //如果用户自行上传了图片
  695. if (!empty($_FILES[$upname]['tmp_name']) && is_uploaded_file($_FILES[$upname]['tmp_name'])) {
  696. $istype = 0;
  697. $sparr = array("image/pjpeg", "image/jpeg", "image/gif", "image/png");
  698. $_FILES[$upname]['type'] = strtolower(trim($_FILES[$upname]['type']));
  699. if (!in_array($_FILES[$upname]['type'], $sparr)) {
  700. ShowMsg("上传的图片格式错误,请使用JPEG、GIF、PNG格式的其中一种!", "-1");
  701. exit();
  702. }
  703. if (!empty($handurl) && !preg_match("#^http:\/\/#i", $handurl) && file_exists($cfg_basedir . $handurl)) {
  704. if (!is_object($dsql)) {
  705. $dsql = new DedeSql();
  706. }
  707. $dsql->ExecuteNoneQuery("DELETE FROM `#@__uploads` WHERE url LIKE '$handurl' ");
  708. $fullUrl = preg_replace("#\.([a-z]*)$#i", "", $handurl);
  709. } else {
  710. $savepath = $cfg_image_dir . '/' . strftime("%Y-%m", $ntime);
  711. CreateDir($savepath);
  712. $fullUrl = $savepath . '/' . strftime("%d", $ntime) . dd2char(strftime("%H%M%S", $ntime) . '0' . $cuserLogin->getUserID() . '0' . mt_rand(1000, 9999));
  713. }
  714. if (strtolower($_FILES[$upname]['type']) == "image/gif") {
  715. $fullUrl = $fullUrl . ".gif";
  716. } else if (strtolower($_FILES[$upname]['type']) == "image/png") {
  717. $fullUrl = $fullUrl . ".png";
  718. } else {
  719. $fullUrl = $fullUrl . ".jpg";
  720. }
  721. //保存
  722. @move_uploaded_file($_FILES[$upname]['tmp_name'], $cfg_basedir . $fullUrl);
  723. $filename = $fullUrl;
  724. //水印
  725. @WaterImg($cfg_basedir . $fullUrl, 'up');
  726. $isrm_up = TRUE;
  727. }
  728. //远程或选择本地图片
  729. else {
  730. if ($handurl == '') {
  731. return '';
  732. }
  733. //远程图片并要求本地化
  734. if ($isremote == 1 && preg_match("#^http[s]?:\/\/#i", $handurl)) {
  735. $ddinfos = GetRemoteImage($handurl, $cuserLogin->getUserID());
  736. if (!is_array($ddinfos)) {
  737. $litpic = "";
  738. } else {
  739. $filename = $ddinfos[0];
  740. }
  741. $isrm_up = TRUE;
  742. //本地图片或远程不要求本地化
  743. } else {
  744. $filename = $handurl;
  745. }
  746. }
  747. $imgfile = $cfg_basedir . $filename;
  748. if (is_file($imgfile) && $isrm_up && $filename != '') {
  749. $info = "";
  750. $imginfos = GetImageSize($imgfile, $info);
  751. //把新上传的图片信息保存到媒体文档管理档案中
  752. $inquery = "
  753. INSERT INTO `#@__uploads`(title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  754. VALUES ('$title','$filename','1','" . $imginfos[0] . "','" . $imginfos[1] . "','0','" . filesize($imgfile) . "','" . time() . "','" . $cuserLogin->getUserID() . "');
  755. ";
  756. $dsql->ExecuteNoneQuery($inquery);
  757. }
  758. return $filename;
  759. }
  760. /**
  761. * 获取更新测试信息
  762. *
  763. * @access public
  764. * @return string
  765. */
  766. function GetUpdateTest()
  767. {
  768. global $arcID, $typeid, $cfg_make_andcat, $cfg_makeindex, $cfg_make_prenext;
  769. $revalue = $dolist = '';
  770. if ($cfg_makeindex == 'Y' || $cfg_make_andcat == 'Y' || $cfg_make_prenext == 'Y') {
  771. if ($cfg_make_prenext == 'Y' && !empty($typeid)) $dolist = 'makeprenext';
  772. if ($cfg_makeindex == 'Y') $dolist .= empty($dolist) ? 'makeindex' : ',makeindex';
  773. if ($cfg_make_andcat == 'Y') $dolist .= empty($dolist) ? 'makeparenttype' : ',makeparenttype';
  774. $dolists = explode(',', $dolist);
  775. $jumpUrl = "task_do.php?typeid={$typeid}&aid={$arcID}&dopost={$dolists[0]}&nextdo=" . preg_replace("#" . $dolists[0] . "[,]{0,1}#", '', $dolist);
  776. $revalue = "<table width='80%' style='border:1px dashed #cdcdcd;margin-left:20px;margin-bottom:15px' id='tgtable' align='left'><tr><td bgcolor='#EBF5C9'>&nbsp;<strong>正在进行相关内容更新,请完成前不要进行其它操作:</strong>\r\n</td></tr>\r\n";
  777. $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";
  778. $revalue .= "</table>";
  779. } else {
  780. $revalue = '';
  781. }
  782. return $revalue;
  783. }