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

207 lines
8.8KB

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