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

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