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

369 lines
13KB

  1. <?php
  2. /**
  3. * 文档处理函数
  4. *
  5. * @version $Id: inc_archives_functions.php 1 13:52 2010年7月9日Z tianya $
  6. * @package DedeBIZ.Member
  7. * @copyright Copyright (c) 2022, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. if (!defined('DEDEMEMBER')) exit('dedebiz');
  12. require_once(DEDEINC.'/image.func.php');
  13. require_once(DEDEINC.'/archives.func.php');
  14. require_once(DEDEINC."/userlogin.class.php");
  15. //检查用户是否被禁言
  16. CheckNotAllow();
  17. /**
  18. * 获得HTML里的外部资源,针对图集
  19. *
  20. * @param string $body 内容
  21. * @param string $rfurl 地址
  22. * @param string $firstdd 第一个缩略图
  23. * @return string
  24. */
  25. function GetCurContentAlbum($body, $rfurl, &$firstdd)
  26. {
  27. global $cfg_multi_site, $cfg_basehost, $ddmaxwidth, $cfg_basedir, $pagestyle, $cfg_mb_rmdown, $title, $cfg_ml, $cfg_user_dir;
  28. include_once(DEDEINC."/dedecollection.func.php");
  29. if (empty($ddmaxwidth)) $ddmaxwidth = 240;
  30. $rsimg = '';
  31. $basehost = "http://".$_SERVER["HTTP_HOST"];
  32. $img_array = array();
  33. preg_match_all("/(src)=[\"|'| ]{0,}(http:\/\/([^>]*)\.(gif|jpg|png))/isU", $body, $img_array);
  34. $img_array = array_unique($img_array[2]);
  35. $imgUrl = $cfg_user_dir."/".$cfg_ml->M_ID;
  36. $imgPath = $cfg_basedir.$imgUrl;
  37. if (!is_dir($imgPath."/")) {
  38. MkdirAll($imgPath, $GLOBALS['cfg_dir_purview']);
  39. CloseFtp();
  40. }
  41. $milliSecond = MyDate("ymdHis", time());
  42. foreach ($img_array as $key => $value) {
  43. if (preg_match("#".$basehost."#i", $value)) {
  44. continue;
  45. }
  46. if ($cfg_basehost != $basehost && preg_match("#".$cfg_basehost."#i", $value)) {
  47. continue;
  48. }
  49. if (!preg_match("#^http[s]?:\/\/#i", $value)) {
  50. continue;
  51. }
  52. if ($cfg_mb_rmdown == 'Y') {
  53. $value = trim($value);
  54. $itype = substr($value, -4, 4);
  55. if (!preg_match("#\.(gif|jpg|png)#i", $itype)) $itype = ".jpg";
  56. $rndFileName = $imgPath."/".$milliSecond.$key.$itype;
  57. $iurl = $imgUrl."/".$milliSecond.$key.$itype;
  58. //下载并保存文件
  59. //$rs = $htd->SaveToBin($rndFileName);
  60. $rs = DownImageKeep($value, $rfurl, $rndFileName, '', 0, 30);
  61. if ($rs) {
  62. if ($pagestyle > 2) {
  63. $litpicname = GetImageMapDD($iurl, $ddmaxwidth);
  64. if ($litpicname != '') SaveUploadInfo($title, $litpicname, 1, $addinfos);
  65. } else {
  66. $litpicname = '';
  67. }
  68. if (empty($firstdd)) {
  69. $firstdd = $litpicname;
  70. if (!file_exists($cfg_basedir.$firstdd)) $firstdd = $iurl;
  71. }
  72. @WaterImg($rndFileName, 'down');
  73. $info = '';
  74. $imginfos = GetImageSize($rndFileName, $info);
  75. SaveUploadInfo($title, $iurl, 1, $imginfos);
  76. $rsimg .= "{dede:img ddimg='$litpicname' text='' width='".$imginfos[0]."' height='".$imginfos[1]."'} $iurl {/dede:img}\r\n";
  77. }
  78. } else {
  79. $rsimg .= "{dede:img ddimg='$value' text='' width='0' height='0'} $value {/dede:img}\r\n";
  80. }
  81. }
  82. return $rsimg;
  83. }
  84. /**
  85. * 图集里大图的小图
  86. *
  87. * @param string $filename 文件名
  88. * @param string $ddm 缩略图
  89. * @param string $oldname 旧的名称
  90. * @return string
  91. */
  92. function GetImageMapDD($filename, $ddm, $oldname = '')
  93. {
  94. if ($oldname != '' && !preg_match("#^http:\/\/#i", $oldname)) {
  95. $ddpicok = $oldname;
  96. } else {
  97. $ddn = substr($filename, -3);
  98. $ddpicok = preg_replace("#\.".$ddn."$#", "-lp.".$ddn, $filename);
  99. }
  100. $toFile = $GLOBALS['cfg_basedir'].$ddpicok;
  101. ImageResize($GLOBALS['cfg_basedir'].$filename, $ddm, 300, $toFile);
  102. return $ddpicok;
  103. }
  104. /**
  105. * 把上传的信息保存到数据库
  106. *
  107. * @param string $title 标题
  108. * @param string $filename 文件名称
  109. * @param string $medaitype 附件类型
  110. * @param string $addinfos 附加信息
  111. * @return string
  112. */
  113. function SaveUploadInfo($title, $filename, $medaitype = 1, $addinfos = '')
  114. {
  115. global $dsql, $cfg_ml, $cfg_basedir;
  116. if ($filename == '') {
  117. return FALSE;
  118. }
  119. if (!is_array($addinfos)) {
  120. $addinfos[0] = $addinfos[1] = $addinfos[2] = 0;
  121. }
  122. if ($medaitype == 1) {
  123. $info = '';
  124. $addinfos = GetImageSize($cfg_basedir.$filename, $info);
  125. }
  126. $addinfos[2] = @filesize($cfg_basedir.$filename);
  127. $row = $dsql->GetOne("SELECT aid,title,url FROM `#@__uploads` WHERE url LIKE '$filename' AND mid='".$cfg_ml->M_ID."'; ");
  128. $uptime = time();
  129. if (is_array($row)) {
  130. $query = "UPDATE `#@__uploads` SET title='$title',mediatype='$medaitype',
  131. width='{$addinfos[0]}',height='{$addinfos[1]}',filesize='{$addinfos[2]}',uptime='$uptime'
  132. WHERE aid='{$row['aid']}'; ";
  133. $dsql->ExecuteNoneQuery($query);
  134. } else {
  135. $inquery = "INSERT INTO `#@__uploads`(title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  136. VALUES ('$title','$filename','$medaitype','".$addinfos[0]."','".$addinfos[1]."','0','".$addinfos[2]."','$uptime','".$cfg_ml->M_ID."'); ";
  137. $dsql->ExecuteNoneQuery($inquery);
  138. }
  139. $fid = $dsql->GetLastID();
  140. AddMyAddon($fid, $filename);
  141. return TRUE;
  142. }
  143. /**
  144. * 获得一个附加表单
  145. *
  146. * @param object $ctag
  147. * @return string
  148. */
  149. function GetFormItemA($ctag)
  150. {
  151. return GetFormItem($ctag, 'member');
  152. }
  153. /**
  154. * 处理不同类型的数据
  155. *
  156. * @param string $dvalue
  157. * @param string $dtype
  158. * @param int $aid
  159. * @param string $job
  160. * @param string $addvar
  161. * @return string
  162. */
  163. function GetFieldValueA($dvalue, $dtype, $aid = 0, $job = 'add', $addvar = '')
  164. {
  165. return GetFieldValue($dvalue, $dtype, $aid, $job, $addvar, 'member');
  166. }
  167. /**
  168. * 获得带值的表单(编辑时用)
  169. *
  170. * @param object $ctag
  171. * @param string $fvalue 默认值
  172. * @return string
  173. */
  174. function GetFormItemValueA($ctag, $fvalue)
  175. {
  176. return GetFormItemValue($ctag, $fvalue, 'member');
  177. }
  178. /**
  179. * 载入自定义表单(用于发布)
  180. *
  181. * @access public
  182. * @param string $fieldset
  183. * @param string $loadtype
  184. * @param bool $isprint 是否打印
  185. * @return string
  186. */
  187. function PrintAutoFieldsAdd(&$fieldset, $loadtype = 'all', $isprint = TRUE)
  188. {
  189. $dtp = new DedeTagParse();
  190. $dtp->SetNameSpace('field', '<', '>');
  191. $dtp->LoadSource($fieldset);
  192. $dede_addonfields = '';
  193. $addonfieldsname = '';
  194. if (is_array($dtp->CTags)) {
  195. foreach ($dtp->CTags as $tid => $ctag) {
  196. if ($loadtype != 'autofield' || $ctag->GetAtt('autofield') == 1) {
  197. $dede_addonfields .= ($dede_addonfields == "" ? $ctag->GetName().",".$ctag->GetAtt('type') : ";".$ctag->GetName().",".$ctag->GetAtt('type'));
  198. $addonfieldsname .= ",".$ctag->GetName();
  199. if ($isprint) echo GetFormItemA($ctag);
  200. }
  201. }
  202. }
  203. echo "<input type=\"hidden\" name=\"dede_addonfields\" value=\"".$dede_addonfields."\" />";
  204. echo "<input type=\"hidden\" name=\"_csrf_token\" value=\"".$GLOBALS['csrf_token']."\" />";
  205. //增加一个返回
  206. return $addonfieldsname;
  207. }
  208. /**
  209. * 载入自定义表单(用于编辑)
  210. *
  211. * @param string $fieldset
  212. * @param string $fieldValues
  213. * @param string $loadtype
  214. * @return string
  215. */
  216. function PrintAutoFieldsEdit(&$fieldset, &$fieldValues, $loadtype = 'all')
  217. {
  218. $dtp = new DedeTagParse();
  219. $dtp->SetNameSpace("field", "<", ">");
  220. $dtp->LoadSource($fieldset);
  221. $dede_addonfields = "";
  222. if (is_array($dtp->CTags)) {
  223. foreach ($dtp->CTags as $tid => $ctag) {
  224. if (
  225. $loadtype != 'autofield'
  226. || ($loadtype == 'autofield' && $ctag->GetAtt('autofield') == 1)
  227. ) {
  228. $dede_addonfields .= ($dede_addonfields == '' ? $ctag->GetName().",".$ctag->GetAtt('type') : ";".$ctag->GetName().",".$ctag->GetAtt('type'));
  229. echo GetFormItemValueA($ctag, $fieldValues[$ctag->GetName()]);
  230. }
  231. }
  232. }
  233. echo "<input type=\"hidden\" name=\"dede_addonfields\" value=\"".$dede_addonfields."\" />";
  234. echo "<input type=\"hidden\" name=\"_csrf_token\" value=\"".$GLOBALS['csrf_token']."\" />";
  235. }
  236. /**
  237. * 创建指定ID的文档
  238. *
  239. * @param int $aid
  240. * @param bool $ismakesign
  241. * @return string
  242. */
  243. function MakeArt($aid, $ismakesign = FALSE)
  244. {
  245. include_once(DEDEINC.'/arc.archives.class.php');
  246. if ($ismakesign) {
  247. $envs['makesign'] = 'yes';
  248. }
  249. $arc = new Archives($aid);
  250. $reurl = $arc->MakeHtml();
  251. if (isset($typeid)) {
  252. $preRow = $arc->dsql->GetOne("SELECT id FROM `#@__arctiny` WHERE id<$aid AND arcrank>-1 AND typeid='$typeid' order by id desc");
  253. $nextRow = $arc->dsql->GetOne("SELECT id FROM `#@__arctiny` WHERE id>$aid AND arcrank>-1 AND typeid='$typeid' order by id asc");
  254. if (is_array($preRow)) {
  255. $arc = new Archives($preRow['id']);
  256. $arc->MakeHtml();
  257. }
  258. if (is_array($nextRow)) {
  259. $arc = new Archives($nextRow['id']);
  260. $arc->MakeHtml();
  261. }
  262. }
  263. return $reurl;
  264. }
  265. /**
  266. * 处理HTML文本、自动摘要、自动获取缩略图等
  267. *
  268. * @access public
  269. * @param string $body 文档内容
  270. * @param string $description 描述
  271. * @param string $dtype 类型
  272. * @return string
  273. */
  274. function AnalyseHtmlBody($body, &$description, $dtype = '')
  275. {
  276. global $cfg_mb_rmdown, $cfg_basehost, $cfg_auot_description, $arcID;
  277. $autolitpic = (empty($autolitpic) ? '' : $autolitpic);
  278. $body = stripslashes($body);
  279. //远程图片本地化
  280. if ($cfg_mb_rmdown == 'Y') {
  281. $body = GetCurContent($body);
  282. }
  283. //自动摘要
  284. if ($description == '' && $cfg_auot_description > 0) {
  285. $description = cn_substr(html2text($body), $cfg_auot_description);
  286. $description = trim(preg_replace('/#p#|#e#/', '', $description));
  287. $description = addslashes($description);
  288. }
  289. $body = addslashes($body);
  290. return $body;
  291. }
  292. /**
  293. * 获得文章body里的外部资源
  294. *
  295. * @access public
  296. * @param string $body 内容
  297. * @return string
  298. */
  299. function GetCurContent(&$body)
  300. {
  301. global $cfg_multi_site, $cfg_basehost, $cfg_basedir, $cfg_user_dir, $title, $cfg_ml;
  302. include_once(DEDEINC."/dedecollection.func.php");
  303. $htd = new DedeHttpDown();
  304. $basehost = "http://".$_SERVER["HTTP_HOST"];
  305. $img_array = array();
  306. preg_match_all("/(src|SRC)=[\"|'| ]{0,}(http[s]?:\/\/([^>]*)\.(gif|jpg|png))/isU", $body, $img_array);
  307. $img_array = array_unique($img_array[2]);
  308. $imgUrl = $cfg_user_dir."/".$cfg_ml->M_ID;
  309. $imgPath = $cfg_basedir.$imgUrl;
  310. if (!is_dir($imgPath."/")) {
  311. MkdirAll($imgPath, $GLOBALS['cfg_dir_purview']);
  312. CloseFtp();
  313. }
  314. $milliSecond = MyDate("ymdHis", time());
  315. foreach ($img_array as $key => $value) {
  316. if (preg_match("#".$basehost."#i", $value)) {
  317. continue;
  318. }
  319. if ($cfg_basehost != $basehost && preg_match("#".$cfg_basehost."#i", $value)) {
  320. continue;
  321. }
  322. if (!preg_match("#^http:\/\/#i", $value)) {
  323. continue;
  324. }
  325. $htd->OpenUrl($value);
  326. $itype = $htd->GetHead("content-type");
  327. $itype = substr($value, -4, 4);
  328. if (!preg_match("#\.(jpg|gif|png)#i", $itype)) {
  329. if ($itype == 'image/gif') {
  330. $itype = ".gif";
  331. } else if ($itype == 'image/png') {
  332. $itype = ".png";
  333. } else {
  334. $itype = '.jpg';
  335. }
  336. }
  337. $milliSecondN = dd2char($milliSecond.'-'.mt_rand(1000, 8000));
  338. $value = trim($value);
  339. $rndFileName = $imgPath."/".$milliSecondN.'-'.$key.$itype;
  340. $fileurl = $imgUrl."/".$milliSecondN.'-'.$key.$itype;
  341. $rs = $htd->SaveToBin($rndFileName);
  342. if ($rs) {
  343. $body = str_replace($value, $fileurl, $body);
  344. @WaterImg($rndFileName, 'down');
  345. }
  346. $info = '';
  347. $imginfos = GetImageSize($rndFileName, $info);
  348. SaveUploadInfo($title, $fileurl, 1, $imginfos);
  349. }
  350. $htd->Close();
  351. return $body;
  352. }