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

216 lines
8.8KB

  1. <?php
  2. /**
  3. *
  4. * 下载
  5. *
  6. * @version $Id: download.php$
  7. * @package DedeBIZ.Site
  8. * @copyright Copyright (c) 2022, DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license
  10. * @link https://www.dedebiz.com
  11. */
  12. require_once(dirname(__FILE__)."/../system/common.inc.php");
  13. require_once(DEDEINC."/channelunit.class.php");
  14. if (!isset($open)) $open = 0;
  15. //读取链接列表
  16. if ($open == 0) {
  17. $aid = (isset($aid) && is_numeric($aid)) ? $aid : 0;
  18. if ($aid == 0) exit('dedebiz');
  19. $arcRow = GetOneArchive($aid);
  20. if ($arcRow['aid'] == '') {
  21. ShowMsg('无法获取未知文档的信息!', '-1');
  22. exit();
  23. }
  24. extract($arcRow, EXTR_SKIP);
  25. $cu = new ChannelUnit($arcRow['channel'], $aid);
  26. if (!is_array($cu->ChannelFields)) {
  27. ShowMsg('获取文档信息失败', '-1');
  28. exit();
  29. }
  30. $vname = '';
  31. foreach ($cu->ChannelFields as $k => $v) {
  32. if ($v['type'] == 'softlinks') {
  33. $vname = $k;
  34. break;
  35. }
  36. }
  37. $row = $dsql->GetOne("SELECT $vname FROM `".$cu->ChannelInfos['addtable']."` WHERE aid='$aid'");
  38. include_once(DEDEINC.'/taglib/channel/softlinks.lib.php');
  39. $ctag = '';
  40. $downlinks = ch_softlinks($row[$vname], $ctag, $cu, '', TRUE);
  41. require_once(DEDETEMPLATE.'/plus/download_links_templet.htm');
  42. exit();
  43. }
  44. /*------------------------
  45. //提供软件给用户下载(旧模式)
  46. function getSoft_old()
  47. ------------------------*/
  48. else if ($open == 1) {
  49. //更新下载次数
  50. $id = isset($id) && is_numeric($id) ? $id : 0;
  51. $link = base64_decode(urldecode($link));
  52. $linkinfo = parse_url($link);
  53. if (!$link) {
  54. ShowMsg('无效地址', 'javascript:;');
  55. exit;
  56. }
  57. $hash = md5($link);
  58. $rs = $dsql->ExecuteNoneQuery2("UPDATE `#@__downloads` SET downloads = downloads + 1 WHERE hash='$hash' ");
  59. if ($rs <= 0) {
  60. $query = " INSERT INTO `#@__downloads`(`hash`,`id`,`downloads`) VALUES('$hash','$id',1); ";
  61. $dsql->ExecNoneQuery($query);
  62. }
  63. $row = $dsql->GetOne("SELECT * FROM `#@__softconfig` ");
  64. $sites = explode("\n", $row['sites']);
  65. $allowed = array();
  66. foreach ($sites as $site) {
  67. $site = explode('|', $site);
  68. $domain = parse_url(trim($site[0]));
  69. if ($domain['host']) {
  70. $allowed[] = $domain['host'];
  71. }
  72. }
  73. if (!in_array($linkinfo['host'], $allowed)) {
  74. ShowMsg('非下载地址,禁止访问', 'javascript:;');
  75. exit;
  76. }
  77. header("location:$link");
  78. exit();
  79. }
  80. /*------------------------
  81. //提供软件给用户下载(新模式)
  82. function getSoft_new()
  83. ------------------------*/
  84. else if ($open == 2) {
  85. $id = intval($id);
  86. //获得附加表信息
  87. $row = $dsql->GetOne("SELECT ch.addtable,arc.mid FROM `#@__arctiny` arc LEFT JOIN `#@__channeltype` ch ON ch.id=arc.channel WHERE arc.id='$id' ");
  88. if (empty($row['addtable'])) {
  89. ShowMsg('找不到所需要的软件资源', 'javascript:;');
  90. exit();
  91. }
  92. $mid = $row['mid'];
  93. //读取连接列表、下载权限信息
  94. $row = $dsql->GetOne("SELECT softlinks,daccess,needmoney FROM `{$row['addtable']}` WHERE aid='$id' ");
  95. if (empty($row['softlinks'])) {
  96. ShowMsg('找不到所需要的软件资源', 'javascript:;');
  97. exit();
  98. }
  99. $softconfig = $dsql->GetOne("SELECT * FROM `#@__softconfig` ");
  100. $needRank = $softconfig['dfrank'];
  101. $needMoney = $softconfig['dfywboy'];
  102. if ($softconfig['argrange'] == 0) {
  103. $needRank = $row['daccess'];
  104. $needMoney = $row['needmoney'];
  105. }
  106. //分析连接列表
  107. require_once(DEDEINC.'/dedetag.class.php');
  108. $softUrl = '';
  109. $islocal = 0;
  110. $dtp = new DedeTagParse();
  111. $dtp->LoadSource($row['softlinks']);
  112. if (!is_array($dtp->CTags)) {
  113. $dtp->Clear();
  114. ShowMsg('找不到所需要的软件资源', 'javascript:;');
  115. exit();
  116. }
  117. foreach ($dtp->CTags as $ctag) {
  118. if ($ctag->GetName() == 'link') {
  119. $link = trim($ctag->GetInnerText());
  120. $islocal = $ctag->GetAtt('islocal');
  121. //分析本地链接
  122. if (!isset($firstLink) && $islocal == 1) $firstLink = $link;
  123. if ($islocal == 1 && $softconfig['islocal'] != 1) continue;
  124. //支持http,迅雷下载,ftp,flashget
  125. if (!preg_match("#^http:\/\/|^thunder:\/\/|^ftp:\/\/|^flashget:\/\/#i", $link)) {
  126. $link = $cfg_mainsite.$link;
  127. }
  128. $dbhash = substr(md5($link), 0, 24);
  129. if ($uhash == $dbhash) $softUrl = $link;
  130. }
  131. }
  132. $dtp->Clear();
  133. if (
  134. $softUrl == '' && $softconfig['ismoresite'] == 1
  135. && $softconfig['moresitedo'] == 1 && trim($softconfig['sites']) != '' && isset($firstLink)
  136. ) {
  137. $firstLink = preg_replace("#http:\/\/([^\/]*)\/#i", '/', $firstLink);
  138. $softconfig['sites'] = preg_replace("#[\r\n]{1,}#", "\n", $softconfig['sites']);
  139. $sites = explode("\n", trim($softconfig['sites']));
  140. foreach ($sites as $site) {
  141. if (trim($site) == '') continue;
  142. list($link, $serverName) = explode('|', $site);
  143. $link = trim(preg_replace("#\/$#", "", $link)).$firstLink;
  144. $dbhash = substr(md5($link), 0, 24);
  145. if ($uhash == $dbhash) $softUrl = $link;
  146. }
  147. }
  148. if ($softUrl == '') {
  149. ShowMsg('找不到所需要的软件资源', 'javascript:;');
  150. exit();
  151. }
  152. //读取文档信息,判断权限
  153. $arcRow = GetOneArchive($id);
  154. if ($arcRow['aid'] == '') {
  155. ShowMsg('无法获取未知文档的信息!', '-1');
  156. exit();
  157. }
  158. extract($arcRow, EXTR_SKIP);
  159. //处理需要下载权限的软件
  160. if ($needRank > 0 || $needMoney > 0) {
  161. require_once(DEDEINC.'/memberlogin.class.php');
  162. $cfg_ml = new MemberLogin();
  163. $arclink = $arcurl;
  164. $arctitle = $title;
  165. $arcLinktitle = "<a href=\"{$arcurl}\">".$arctitle."</a>";
  166. $pubdate = GetDateTimeMk($pubdate);
  167. //会员级别不足
  168. if (($needRank > 1 && $cfg_ml->M_Rank < $needRank && $mid != $cfg_ml->M_ID)) {
  169. $dsql->Execute('me', "SELECT * FROM `#@__arcrank` ");
  170. while ($row = $dsql->GetObject('me')) {
  171. $memberTypes[$row->rank] = $row->membername;
  172. }
  173. $memberTypes[0] = "游客";
  174. $msgtitle = "您没有权限下载软件:{$arctitle}";
  175. $moremsg = "这个软件需要 <span style='color:#dc3545'>".$memberTypes[$needRank]."</span> 才能下载,您目前是:<span style='color:#dc3545'>".$memberTypes[$cfg_ml->M_Rank]."</span> ";
  176. include_once(DEDETEMPLATE.'/plus/view_msg.htm');
  177. exit();
  178. }
  179. //以下为正常情况,自动扣点数
  180. //如果文章需要金币,检查用户是否浏览过本文档
  181. if ($needMoney > 0 && $mid != $cfg_ml->M_ID) {
  182. $sql = "SELECT aid,money FROM `#@__member_operation` WHERE buyid='ARCHIVE".$id."' AND mid='".$cfg_ml->M_ID."'";
  183. $row = $dsql->GetOne($sql);
  184. //未购买过此文章
  185. if (!is_array($row)) {
  186. //没有足够的金币
  187. if ($needMoney > $cfg_ml->M_Money || $cfg_ml->M_Money == '') {
  188. $msgtitle = "您没有权限下载软件:{$arctitle}";
  189. $moremsg = "这个软件需要 <span style='color:#dc3545'>".$needMoney." 金币</span> 才能下载,您目前拥有金币:<span style='color:#dc3545'>".$cfg_ml->M_Money." 个</span> ";
  190. include_once(DEDETEMPLATE.'/plus/view_msg.htm');
  191. exit(0);
  192. }
  193. //有足够金币,记录用户信息
  194. $inquery = "INSERT INTO `#@__member_operation`(mid,oldinfo,money,mtime,buyid,product,pname,sta)
  195. VALUES ('".$cfg_ml->M_ID."','$arctitle','$needMoney','".time()."', 'ARCHIVE".$id."', 'archive','下载软件', 2); ";
  196. //记录定单
  197. if (!$dsql->ExecuteNoneQuery($inquery)) {
  198. ShowMsg('记录定单失败, 请返回', '-1');
  199. exit(0);
  200. }
  201. //扣除金币
  202. $dsql->ExecuteNoneQuery("UPDATE `#@__member` SET money = money - $needMoney WHERE mid='".$cfg_ml->M_ID."'");
  203. }
  204. }
  205. }
  206. //更新下载次数
  207. $hash = md5($softUrl);
  208. $rs = $dsql->ExecuteNoneQuery2("UPDATE `#@__downloads` SET downloads = downloads+1 WHERE hash='$hash' ");
  209. if ($rs <= 0) {
  210. $query = " INSERT INTO `#@__downloads`(`hash`, `id`, `downloads`) VALUES('$hash', '$id', 1); ";
  211. $dsql->ExecNoneQuery($query);
  212. }
  213. header("location:{$softUrl}");
  214. exit();
  215. }//opentype=2