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

215 lines
8.7KB

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