国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

inc_archives_functions.php 27KB

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