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

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