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

231 lines
8.9KB

  1. <?php
  2. /**
  3. *
  4. * 下载
  5. *
  6. * @version $Id: download.php$
  7. * @package DedeBIZ.Site
  8. * @copyright Copyright (c) 2021, DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license
  10. * @link https://www.dedebiz.com
  11. */
  12. require_once(dirname(__FILE__)."/../include/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(' Request Error! ');
  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. ------------------------*/ 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. ------------------------*/ else if ($open == 2) {
  83. $id = intval($id);
  84. //获得附加表信息
  85. $row = $dsql->GetOne("SELECT ch.addtable,arc.mid FROM `#@__arctiny` arc LEFT JOIN `#@__channeltype` ch ON ch.id=arc.channel WHERE arc.id='$id' ");
  86. if (empty($row['addtable'])) {
  87. ShowMsg('找不到所需要的软件资源!', 'javascript:;');
  88. exit();
  89. }
  90. $mid = $row['mid'];
  91. //读取连接列表、下载权限信息
  92. $row = $dsql->GetOne("SELECT softlinks,daccess,needmoney FROM `{$row['addtable']}` WHERE aid='$id' ");
  93. if (empty($row['softlinks'])) {
  94. ShowMsg('找不到所需要的软件资源!', 'javascript:;');
  95. exit();
  96. }
  97. $softconfig = $dsql->GetOne("SELECT * FROM `#@__softconfig` ");
  98. $needRank = $softconfig['dfrank'];
  99. $needMoney = $softconfig['dfywboy'];
  100. if ($softconfig['argrange'] == 0) {
  101. $needRank = $row['daccess'];
  102. $needMoney = $row['needmoney'];
  103. }
  104. //分析连接列表
  105. require_once(DEDEINC.'/dedetag.class.php');
  106. $softUrl = '';
  107. $islocal = 0;
  108. $dtp = new DedeTagParse();
  109. $dtp->LoadSource($row['softlinks']);
  110. if (!is_array($dtp->CTags)) {
  111. $dtp->Clear();
  112. ShowMsg('找不到所需要的软件资源!', 'javascript:;');
  113. exit();
  114. }
  115. foreach ($dtp->CTags as $ctag) {
  116. if ($ctag->GetName() == 'link') {
  117. $link = trim($ctag->GetInnerText());
  118. $islocal = $ctag->GetAtt('islocal');
  119. //分析本地链接
  120. if (!isset($firstLink) && $islocal == 1) $firstLink = $link;
  121. if ($islocal == 1 && $softconfig['islocal'] != 1) continue;
  122. //支持http,迅雷下载,ftp,flashget
  123. if (!preg_match("#^http:\/\/|^thunder:\/\/|^ftp:\/\/|^flashget:\/\/#i", $link)) {
  124. $link = $cfg_mainsite.$link;
  125. }
  126. $dbhash = substr(md5($link), 0, 24);
  127. if ($uhash == $dbhash) $softUrl = $link;
  128. }
  129. }
  130. $dtp->Clear();
  131. if (
  132. $softUrl == '' && $softconfig['ismoresite'] == 1
  133. && $softconfig['moresitedo'] == 1 && trim($softconfig['sites']) != '' && isset($firstLink)
  134. ) {
  135. $firstLink = preg_replace("#http:\/\/([^\/]*)\/#i", '/', $firstLink);
  136. $softconfig['sites'] = preg_replace("#[\r\n]{1,}#", "\n", $softconfig['sites']);
  137. $sites = explode("\n", trim($softconfig['sites']));
  138. foreach ($sites as $site) {
  139. if (trim($site) == '') continue;
  140. list($link, $serverName) = explode('|', $site);
  141. $link = trim(preg_replace("#\/$#", "", $link)).$firstLink;
  142. $dbhash = substr(md5($link), 0, 24);
  143. if ($uhash == $dbhash) $softUrl = $link;
  144. }
  145. }
  146. if ($softUrl == '') {
  147. ShowMsg('找不到所需要的软件资源!', 'javascript:;');
  148. exit();
  149. }
  150. //-------------------------
  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 = "这个软件需要 <font color='red'>".$memberTypes[$needRank]."</font> 才能下载,您目前是:<font color='red'>".$memberTypes[$cfg_ml->M_Rank]."</font> !";
  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 = "这个软件需要 <font color='red'>".$needMoney." 金币</font> 才能下载,您目前拥有金币:<font color='red'>".$cfg_ml->M_Money." 个</font> !";
  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