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

348 lines
12KB

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