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

256 lines
9.0KB

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