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

350 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.User
  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."/userlogin.class.php");
  14. //检查用户是否被禁言
  15. CheckNotAllow();
  16. /**
  17. * 获得HTML里的外部资源,针对图集
  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'
  130. WHERE aid='{$row['aid']}'; ";
  131. $dsql->ExecuteNoneQuery($query);
  132. } else {
  133. $inquery = "INSERT INTO `#@__uploads`(title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  134. VALUES ('$title','$filename','$medaitype','".$addinfos[0]."','".$addinfos[1]."','0','".$addinfos[2]."','$uptime','".$cfg_ml->M_ID."'); ";
  135. $dsql->ExecuteNoneQuery($inquery);
  136. }
  137. $fid = $dsql->GetLastID();
  138. AddMyAddon($fid, $filename);
  139. return TRUE;
  140. }
  141. /**
  142. * 获得一个附加表单
  143. *
  144. * @param object $ctag
  145. * @return string
  146. */
  147. function GetFormItemA($ctag)
  148. {
  149. return GetFormItem($ctag, 'member');
  150. }
  151. /**
  152. * 处理不同类型的数据
  153. *
  154. * @param string $dvalue
  155. * @param string $dtype
  156. * @param int $aid
  157. * @param string $job
  158. * @param string $addvar
  159. * @return string
  160. */
  161. function GetFieldValueA($dvalue, $dtype, $aid = 0, $job = 'add', $addvar = '')
  162. {
  163. return GetFieldValue($dvalue, $dtype, $aid, $job, $addvar, 'member');
  164. }
  165. /**
  166. * 获得带值的表单(编辑时用)
  167. *
  168. * @param object $ctag
  169. * @param string $fvalue 默认值
  170. * @return string
  171. */
  172. function GetFormItemValueA($ctag, $fvalue)
  173. {
  174. return GetFormItemValue($ctag, $fvalue, 'member');
  175. }
  176. /**
  177. * 载入自定义表单(用于发布)
  178. *
  179. * @access public
  180. * @param string $fieldset
  181. * @param string $loadtype
  182. * @param bool $isprint 是否打印
  183. * @return string
  184. */
  185. function PrintAutoFieldsAdd(&$fieldset, $loadtype = 'all', $isprint = TRUE)
  186. {
  187. $dtp = new DedeTagParse();
  188. $dtp->SetNameSpace('field', '<', '>');
  189. $dtp->LoadSource($fieldset);
  190. $dede_addonfields = '';
  191. $addonfieldsname = '';
  192. if (is_array($dtp->CTags)) {
  193. foreach ($dtp->CTags as $tid => $ctag) {
  194. if ($loadtype != 'autofield' || $ctag->GetAtt('autofield') == 1) {
  195. $dede_addonfields .= ($dede_addonfields == "" ? $ctag->GetName().",".$ctag->GetAtt('type') : ";".$ctag->GetName().",".$ctag->GetAtt('type'));
  196. $addonfieldsname .= ",".$ctag->GetName();
  197. if ($isprint) echo GetFormItemA($ctag);
  198. }
  199. }
  200. }
  201. echo "<input type=\"hidden\" name=\"dede_addonfields\" value=\"".$dede_addonfields."\" />";
  202. echo "<input type=\"hidden\" name=\"_csrf_token\" value=\"".$GLOBALS['csrf_token']."\" />";
  203. //增加一个返回
  204. return $addonfieldsname;
  205. }
  206. /**
  207. * 载入自定义表单(用于编辑)
  208. *
  209. * @param string $fieldset
  210. * @param string $fieldValues
  211. * @param string $loadtype
  212. * @return string
  213. */
  214. function PrintAutoFieldsEdit(&$fieldset, &$fieldValues, $loadtype = 'all')
  215. {
  216. $dtp = new DedeTagParse();
  217. $dtp->SetNameSpace("field", "<", ">");
  218. $dtp->LoadSource($fieldset);
  219. $dede_addonfields = "";
  220. if (is_array($dtp->CTags)) {
  221. foreach ($dtp->CTags as $tid => $ctag) {
  222. if (
  223. $loadtype != 'autofield'
  224. || ($loadtype == 'autofield' && $ctag->GetAtt('autofield') == 1)
  225. ) {
  226. $dede_addonfields .= ($dede_addonfields == '' ? $ctag->GetName().",".$ctag->GetAtt('type') : ";".$ctag->GetName().",".$ctag->GetAtt('type'));
  227. echo GetFormItemValueA($ctag, $fieldValues[$ctag->GetName()]);
  228. }
  229. }
  230. }
  231. echo "<input type=\"hidden\" name=\"dede_addonfields\" value=\"".$dede_addonfields."\" />";
  232. echo "<input type=\"hidden\" name=\"_csrf_token\" value=\"".$GLOBALS['csrf_token']."\" />";
  233. }
  234. /**
  235. * 创建指定id的文档
  236. *
  237. * @param int $aid
  238. * @param bool $ismakesign
  239. * @return string
  240. */
  241. function MakeArt($aid, $ismakesign = FALSE)
  242. {
  243. include_once(DEDEINC.'/archive/archives.class.php');
  244. if ($ismakesign) {
  245. $envs['makesign'] = 'yes';
  246. }
  247. $arc = new Archives($aid);
  248. $reurl = $arc->MakeHtml();
  249. if (isset($typeid)) {
  250. $preRow = $arc->dsql->GetOne("SELECT id FROM `#@__arctiny` WHERE id<$aid AND arcrank>-1 AND typeid='$typeid' order by id desc");
  251. $nextRow = $arc->dsql->GetOne("SELECT id FROM `#@__arctiny` WHERE id>$aid AND arcrank>-1 AND typeid='$typeid' order by id asc");
  252. if (is_array($preRow)) {
  253. $arc = new Archives($preRow['id']);
  254. $arc->MakeHtml();
  255. }
  256. if (is_array($nextRow)) {
  257. $arc = new Archives($nextRow['id']);
  258. $arc->MakeHtml();
  259. }
  260. }
  261. return $reurl;
  262. }
  263. /**
  264. * 处理HTML文本、自动摘要、自动获取缩略图等
  265. *
  266. * @access public
  267. * @param string $body 文档内容
  268. * @param string $description 描述
  269. * @param string $dtype 类型
  270. * @return string
  271. */
  272. function AnalyseHtmlBody($body, &$description, $dtype = '')
  273. {
  274. global $cfg_mb_rmdown, $cfg_basehost, $cfg_auot_description, $arcID;
  275. $autolitpic = (empty($autolitpic) ? '' : $autolitpic);
  276. $body = stripslashes($body);
  277. //远程图片本地化
  278. if ($cfg_mb_rmdown == 'Y') {
  279. $body = GetCurContent($body);
  280. }
  281. //自动摘要
  282. if ($description == '' && $cfg_auot_description > 0) {
  283. $description = cn_substr(html2text($body), $cfg_auot_description);
  284. $description = trim(preg_replace('/#p#|#e#/', '', $description));
  285. $description = addslashes($description);
  286. }
  287. $body = addslashes($body);
  288. return $body;
  289. }
  290. /**
  291. * 获得文档body里的外部资源
  292. *
  293. * @access public
  294. * @param string $body 内容
  295. * @return string
  296. */
  297. function GetCurContent(&$body)
  298. {
  299. global $cfg_multi_site, $cfg_basehost, $cfg_basedir, $cfg_user_dir, $title, $cfg_ml;
  300. include_once(DEDEINC."/dedecollection.func.php");
  301. $htd = new DedeHttpDown();
  302. $basehost = IsSSL()? "https://".$_SERVER["HTTP_HOST"] : "http://".$_SERVER["HTTP_HOST"];
  303. $img_array = array();
  304. preg_match_all("/(src|SRC)=[\"|'| ]{0,}(http[s]?:\/\/([^>]*)\.(gif|jpg|png))/isU", $body, $img_array);
  305. $img_array = array_unique($img_array[2]);
  306. $imgUrl = $cfg_user_dir."/".$cfg_ml->M_ID;
  307. $imgPath = $cfg_basedir.$imgUrl;
  308. if (!is_dir($imgPath."/")) {
  309. MkdirAll($imgPath, $GLOBALS['cfg_dir_purview']);
  310. CloseFtp();
  311. }
  312. $milliSecond = MyDate("ymdHis", time());
  313. foreach ($img_array as $key => $value) {
  314. if (preg_match("#".$basehost."#i", $value)) {
  315. continue;
  316. }
  317. if ($cfg_basehost != $basehost && preg_match("#".$cfg_basehost."#i", $value)) {
  318. continue;
  319. }
  320. if (!preg_match("#^(http|https):\/\/#i", $value)) {
  321. continue;
  322. }
  323. $htd->OpenUrl($value);
  324. $itype = $htd->GetHead("content-type");
  325. $itype = substr($value, -4, 4);
  326. if (!preg_match("#\.(jpg|gif|png)#i", $itype)) {
  327. if ($itype == 'image/gif') {
  328. $itype = ".gif";
  329. } else if ($itype == 'image/png') {
  330. $itype = ".png";
  331. } else {
  332. $itype = '.jpg';
  333. }
  334. }
  335. $milliSecondN = dd2char($milliSecond.'-'.mt_rand(1000, 8000));
  336. $value = trim($value);
  337. $rndFileName = $imgPath."/".$milliSecondN.'-'.$key.$itype;
  338. $fileurl = $imgUrl."/".$milliSecondN.'-'.$key.$itype;
  339. $rs = $htd->SaveToBin($rndFileName);
  340. if ($rs) {
  341. $body = str_replace($value, $fileurl, $body);
  342. @WaterImg($rndFileName, 'down');
  343. }
  344. $info = '';
  345. $imginfos = GetImageSize($rndFileName, $info);
  346. SaveUploadInfo($title, $fileurl, 1, $imginfos);
  347. }
  348. $htd->Close();
  349. return $body;
  350. }