本教程实现DEDECMS功能:文章模型整合下载功能,可判断点数,会员组等下载权限,前台可判断是否有附件下载,有则显示,没有则不显示。适用类型:有些文章有下载地址,有些文章没有下载地址的网站。想附件收费的网站等等……具体就不啰嗦了。用得上您就拿走。
后台效果图
本教程为站长似水星辰原创,转载注明出处。
注:本教程中的金币和会员组设置只针对下载连接有效。不对文章内容生效,和文章本身的阅读权限和消费金币并不冲突,是分开设置的。文章中所有sql语句中涉及表名的,请把表前缀换成您自己的表前缀。如:js_addonarticle 换成 您的表前缀_addonarticle。
一、首先规划要加入的字段
下载链接:softlinks
消费金币:needmoney
会员组权限:daccess
这些字段要加入到文章附加表中,前缀_addonarticle,也可以根据自己情况加入需要的表中,自己修改就行了。
进入后台系统-SQL命令行工具,执行:
1
ALTER
TABLE
`js_addonarticle`
ADD
`softlinks` TEXT
NOT
NULL
,
2
ADD
`needmoney`
SMALLINT
( 5 )
NOT
NULL
,
3
ADD
`daccess`
SMALLINT
( 5 )
NOT
NULL
也可以在phpmyadmin中自行添加。
然后在后台打开核心-频道模型-内容模型管理-普通文章-修改-字段管理,在模型字段配置(文本模式) 里添加
- <field:softlinks itemname="软件地址" type="softlinks" isnull="true" default="" rename="" />
- <field:daccess islist="1" itemname="下载级别" type="int" isnull="true" default="0" rename="" function="" notsend="1"/>
- <field:needmoney islist="1" itemname="需要金币" type="int" isnull="true" default="0" rename="" function="" notsend="1" />
如果不添加则会出现无链接信息错误!请务必添加。
二、数据库字段添加完毕就要修改文章模型的4个文件了。分别是dede管理目录下的article_add.php,article_edit.php和管理模板article_add.htm,article_edit.htm,打开这4个文件依次修改。
1、修改article_add.htm,在头部的<script></script>中加入以下,在</script>之前加入就行
01
var startNum = 0;
02
function
MakeUpload()
03
{
04
var upfield = document.getElementById(
"uploadfield"
);
05
var endNum = parseInt(document.form1.picnum.value) + startNum-1;
06
if
(endNum > 30) endNum = 30;
07
for
(startNum; startNum<=endNum; startNum++){
08
upfield.innerHTML +=
"<div style='line-height:36px'>软件地址"
+startNum+
":<input type='text' name='softurl"
+startNum+
"' style='width:280px' value='http://' /> 服务器名称:<input type='text' name='servermsg"
+startNum+
"' style='width:150px' /></div>\r\n"
;
09
}
10
}
11
function
ShowHideAddr()
12
{
13
document.getElementById(
'morelink'
).style.display = (document.getElementById(
'morelink'
).style.display==
'block'
?
'none'
:
'block'
);
14
document.getElementById(
'morelink'
).style.height =
'100%'
;
15
document.getElementById(
'btsh3'
).value = (document.getElementById(
'morelink'
).style.display==
'block'
?
'隐藏地址'
:
'显示地址'
);
16
}
这个是可以增加下载地址个数的JS代码。
2、找到
- <tr>
- <td colspan="2"><?php PrintAutoFieldsAdd($cInfos['fieldset'],'autofield'); ?></td>
- </tr>
再其后边加入
001
<
tr
>
002
<td height=
"24"
bgcolor=
"#F9FCEF"
" class="
bline2"><strong> 下载限制:</strong></td>
003
</
tr
>
004
<
tr
>
005
<td height=
"24"
class=
"bline"
>
006
<table width=
"800"
border=
"0"
cellpadding=
"0"
cellspacing=
"0"
>
007
<
tr
>
008
<td width=
"90"
height=
"30"
> 需会员权限:</td>
009
<td width=
"179"
align=
"left"
>
010
<
select
name=
"daccess"
id
=
"daccess"
style=
"width:90px"
>
011
<?php
012
$dsql->SetQuery(
"Select * from `js_arcrank` where rank>=0 "
);
013
$dsql->Execute();
014
while
($row = $dsql->GetArray())
015
{
016
if
($row[
'rank'
]==0) $row[
'membername'
] =
"不限会员"
;
017
if
($row[
'rank'
] == $softconfig[
'dfrank'
])
echo
" <option value='{$row['rank']}' selected>{$row['membername']}</option>\r\n"
;
018
else
echo
" <option value='{$row['rank']}'>{$row['membername']}</option>\r\n"
;
019
}
020
?>
021
</
select
> </td>
022
<td width=
"120"
align=
"center"
>需消费金币:</td>
023
<td width=
"411"
>
024
<input name=
"needmoney"
type
=
"text"
id
=
"needmoney"
value=
"<?php echo $softconfig['dfywboy']; ?>"
size=
"8"
/>个 </td>
025
</
tr
>
026
<
tr
>
027
<td height=
"26"
colspan=
"4"
style=
"border-top:1px dashed #8EAF61"
> <span class=
"STYLE1"
>(如果设定了下载限制,[<a href=
"soft_config.php"
target=
"_blank"
><u>软件频道设置</u></a>]中“附件下载方式:”必须选择“链接到跳转页面”) </span></td>
028
</
tr
>
029
</table>
030
</td>
031
</
tr
>
032
<
tr
>
033
<td height=
"24"
bgcolor=
"#F9FCEF"
class=
"bline2"
><strong> 本地软件选择:</strong></td>
034
</
tr
>
035
<
tr
>
036
<td height=
"24"
class=
"bline"
>
037
<table width=
"800"
border=
"0"
cellspacing=
"0"
cellpadding=
"0"
>
038
<
tr
>
039
<td width=
"90"
height=
"30"
> 本地地址:</td>
040
<td>
041
<input name=
"softurl1"
type
=
"text"
id
=
"softurl1"
size=
"35"
/>
042
<input name=
"sel1"
type
=
"button"
id
=
"sel1"
value=
"选取"
onClick=
"SelectSoft('form1.softurl1')"
/>
043
服务器名称:
044
<input name=
"servermsg1"
type
=
"text"
id
=
"servermsg1"
value=
"本地下载"
style=
"width:150px"
/>
045
</td>
046
</
tr
>
047
</table>
048
</td>
049
</
tr
>
050
<?php
051
if
($softconfig[
'moresitedo'
] == 0 && trim($softconfig[
'sites'
]) !=
''
)
052
{
053
?>
054
<
tr
>
055
<td height=
"24"
bgcolor=
"#F9FCEF"
class=
"bline2"
><b> 预设的镜像服务器:</b></td>
056
</
tr
>
057
<
tr
class=
"bline"
>
058
<td style=
"padding-left:10px;"
>
059
(服务器地址 + 软件地址 = 软件真实地址 [<a href=
"soft_config.php"
target=
"_blank"
><u>软件频道设置</u></a>])<br />
060
<?php
061
$sites = explode(
"\n"
, $softconfig[
'sites'
]);
062
$startNum = 2;
063
foreach($sites as $site)
064
{
065
$site = trim($site);
066
if
(empty($site))
continue
;
067
list($siteurl, $sitename) = explode(
'|'
, $site);
068
$siteurl = trim($siteurl);
069
$sitename = trim($sitename);
070
?>
071
<?php
echo
$sitename; ?>:
072
<input
type
=
'hidden'
name=
'forconfig<?php echo $startNum; ?>'
value=
'1'
/>
073
<input
type
=
'text'
name=
'softurlfirst<?php echo $startNum; ?>'
style=
'width:200px'
value=
'<?php echo $siteurl; ?>'
/> +
074
<input
type
=
'text'
name=
'softurl<?php echo $startNum; ?>'
style=
'width:120px'
value=
''
/>
075
<input
type
=
'text'
name=
'servermsg<?php echo $startNum; ?>'
style=
'width:150px'
value=
'<?php echo $sitename; ?>'
/>
076
<input
type
=
'checkbox'
name=
'need<?php echo $startNum; ?>'
class=
'np'
value=
'1'
checked />启用
077
<br />
078
<?php
079
$startNum++;
080
}//foreach
081
echo
"<script language='javascript'>startNum = $startNum;</script>\r\n"
;
082
?>
083
</td>
084
</
tr
>
085
<?php
086
}//需要预设镜像
087
?>
088
<
tr
>
089
<td height=
"24"
bgcolor=
"#F9FCEF"
class=
"bline2"
><b> 手动指定地址:</b></td>
090
</
tr
>
091
<
tr
>
092
<td height=
"24"
class=
"bline"
style=
"padding-left:8px"
>
093
<table width=
"800"
border=
"0"
cellspacing=
"0"
cellpadding=
"0"
style=
"margin-bottom:5px;"
class=
"bline"
>
094
<
tr
>
095
<td width=
"90"
>其它地址:</td>
096
<td>
097
<input name=
"picnum"
type
=
"text"
id
=
"picnum"
size=
"8"
value=
"5"
/>
098
<input name=
'kkkup'
type
=
'button'
id
=
'kkkup2'
value=
'增加地址'
onClick=
"MakeUpload();"
/>
099
100
<input
type
=
"button"
name=
"Submit3"
id
=
"btsh3"
value=
"隐藏地址"
onClick=
"ShowHideAddr();"
/>
101
(最多为30个链接)
102
</td>
103
</
tr
>
104
</table>
105
<div
id
=
"morelink"
style=
"display:block"
>
106
<div
id
=
'uploadfield'
style=
"width:790px"
></div>
107
</div>
108
</td>
109
</
tr
>
到这里article_add.htm文件就修改完了。
3、打开article_edit.htm文件,在头部的<script></script>中加入以下代码,在</script>之前加入就行
01
var startNum = <?php
echo
$newRowStart?>;
02
function
MakeUpload()
03
{
04
var upfield = document.getElementById(
'uploadfield'
);
05
var endNum = parseInt(document.form1.picnum.value) + startNum;
06
if
(endNum > 30) endNum = 30;
07
for
(startNum; startNum < endNum; startNum++)
08
{
09
upfield.innerHTML +=
"<div style='line-height:36px'>软件地址"
+startNum+
":<input type='text' name='softurl"
+startNum+
"' style='width:280px' value='http://' /> 服务器名称:<input type='text' name='servermsg"
+startNum+
"' style='width:150px' /></div>\r\n"
;
10
}
11
}
12
13
function
ShowHideAddr()
14
{
15
document.getElementById(
'morelink'
).style.display = (document.getElementById(
'morelink'
).style.display==
'block'
?
'none'
:
'block'
);
16
document.getElementById(
'btsh3'
).value = (document.getElementById(
'morelink'
).style.display==
'block'
?
'隐藏地址'
:
'显示地址'
);
17
}
4、找到
- <tr>
- <td colspan="2"><?php
- PrintAutoFieldsEdit($cInfos['fieldset'],$addRow,'autofield');
- ?></td>
- </tr>
在其下边加入以下代码:
01
<tr>
02
<td height=
"24"
class
=
"bline"
>
03
<table width=
"800"
border=
"0"
cellpadding=
"0"
cellspacing=
"0"
>
04
<tr>
05
<td width=
"90"
height=
"30"
> 需会员权限:</td>
06
<td width=
"179"
align=
"center"
>
07
<select name=
"daccess"
id=
"daccess"
style=
"width:90px"
>
08
<?php
09
$dsql
->SetQuery(
"Select * from `js_arcrank` where rank>=0 "
);
10
$dsql
->Execute();
11
while
(
$row
=
$dsql
->GetArray())
12
{
13
if
(
$row
[
'rank'
]==0)
$row
[
'membername'
] =
"不限会员"
;
14
if
(
$row
[
'rank'
] ==
$daccess
)
echo
" <option value='{$row['rank']}' selected>{$row['membername']}</option>\r\n"
;
15
else
echo
" <option value='{$row['rank']}'>{$row['membername']}</option>\r\n"
;
16
}
17
?>
18
</select>
19
</td>
20
<td width=
"120"
align=
"center"
>需消费金币:</td>
21
<td width=
"411"
>
22
<input name=
"needmoney"
type=
"text"
id=
"needmoney"
value=
"<?php echo $needmoney; ?>"
size=
"8"
/>个
23
</td>
24
</tr>
25
<tr>
26
<td height=
"26"
colspan=
"4"
style=
"border-top:1px dashed #8EAF61"
> <span
class
=
"STYLE1"
>(如果设定了下载限制,<a href=
"soft_config.php"
target=
"_blank"
><u>软件频道设置</u></a>中“附件下载方式:”必须选择“链接到跳转页面”) </span></td>
27
</tr>
28
</table>
29
</td>
30
</tr>
31
<tr>
32
<td height=
"24"
colspan=
"4"
bgcolor=
"#F9FCEF"
class
=
"bline2"
><strong> 软件链接列表:</strong></td>
33
</tr>
34
<tr>
35
<td height=
"24"
colspan=
"4"
class
=
"bline"
>
36
<table width=
"800"
border=
"0"
cellspacing=
"0"
cellpadding=
"0"
>
37
<tr>
38
<td width=
"72"
> 其它地址:</td>
39
<td>
40
<input name=
"picnum"
type=
"text"
id=
"picnum"
size=
"8"
value=
"5"
/>
41
<input name=
'kkkup'
type=
'button'
id=
'kkkup2'
value=
'增加数量'
onClick=
"MakeUpload();"
/>
42
43
<input type=
"button"
name=
"Submit3"
id=
"btsh3"
value=
"隐藏地址"
onClick=
"ShowHideAddr();"
/>
44
(最多为30个链接)
45
</td>
46
</tr>
47
</table>
48
</td>
49
</tr>
50
<tr>
51
<td height=
"24"
colspan=
"4"
class
=
"bline"
style=
"padding-left:8px"
>
52
<?php
53
echo
$nForm
;
54
?>
55
<div id=
'morelink'
style=
'display:block'
>
56
<div id=
'uploadfield'
style=
'width:800px'
></div>
57
</div>
58
</td>
59
</tr>
article_edit.html修改完毕,接下来开始修改article_add.php,要认真看哦!
5、打开article_add.php,找到
01
//保存到附加表
02
$cts
=
$dsql
->GetOne(
"SELECT addtable FROM `js_channeltype` WHERE id='$channelid' "
);
03
在其上边加入
04
//软件链接列表
05
$urls
=
''
;
06
07
//本地链接处理
08
$softurl1
=
stripslashes
(
$softurl1
);
09
$nsoftsize
=
''
;
10
if
(
$softurl1
!=
''
)
11
{
12
$urls
.=
"{dede:link islocal='1' text='{$servermsg1}'} $softurl1 {/dede:link}\r\n"
;
13
}
14
15
//其它链接处理
16
for
(
$i
=2;
$i
<=30;
$i
++)
17
{
18
if
(!(${
'softurl'
.
$i
}))
19
{
20
$forconfig
= (${
'forconfig'
.
$i
}) ? FALSE : TRUE;
21
if
(
$forconfig
)
22
{
23
if
(
empty
(${
'need'
.
$i
}))
continue
;
24
$serverUrl
=
stripslashes
(${
'softurlfirst'
.
$i
});
25
$serverUrl
= preg_replace(
"#\/$#"
,
""
,
$serverUrl
);
26
$softurl
=
stripslashes
(${
'softurl'
.
$i
});
27
if
( cn_substr(
$softurl
, 1) !=
'/'
)
$softurl
=
'/'
.
$softurl
;
28
$softurl
=
$serverUrl
.
$softurl
;
29
}
30
else
31
{
32
$softurl
=
stripslashes
(${
'softurl'
.
$i
});
33
}
34
$servermsg
=
str_replace
(
"'"
,
""
,
stripslashes
(${'servermsg'.
$i
}));
35
if
(
$servermsg
==
''
)
$servermsg
=
'下载地址'
.
$i
;
36
if
(
$softurl
!=
'http://'
)
37
{
38
$urls
.=
"{dede:link text='$servermsg'} $softurl {/dede:link}\r\n"
;
39
}
40
}
41
}
42
$urls
=
addslashes
(
$urls
);
这段大概在203行左右,主要作用是处理下载地址。然后再找到
- $query = "INSERT INTO `{$addtable}`(aid,typeid,redirecturl,templet,userip,body{$inadd_f}) Values('$arcID','$typeid','$redirecturl','$templet','$useip','$body'{$inadd_v})";
替换为
- $query = "INSERT INTO `{$addtable}`(aid,typeid,redirecturl,templet,userip,body,softlinks,needmoney,daccess{$inadd_f}) Values('$arcID','$typeid','$redirecturl','$templet','$useip','$body','$urls','$needmoney','$daccess'{$inadd_v})";
article_add.php修改完毕,添加一下文章,把下载地址,金币,会员组都写进去,看看数据库是不是有这条记录了^ ^。
6、打开article_edit.php,找到
- $channelid = $arcRow['channel'];
在其上边加入
01
$newRowStart
= 1;
02
$nForm
=
''
;
03
$daccess
=
$addRow
[
'daccess'
];
04
$needmoney
=
$addRow
[
'needmoney'
];
05
if
(
$addRow
[
'softlinks'
] !=
''
)
06
{
07
$dtp
=
new
DedeTagParse();
08
$dtp
->LoadSource(
$addRow
[
'softlinks'
]);
09
if
(
is_array
(
$dtp
->CTags))
10
{
11
foreach
(
$dtp
->CTags
as
$ctag
)
12
{
13
if
(
$ctag
->GetName()==
'link'
)
14
{
15
$islocal
=
$ctag
->GetAtt(
'islocal'
);
16
if
(
$islocal
!= 1)
$needmsg
=
"<input type='checkbox' name='del{$newRowStart}' value='1' />删除"
;
17
else
$needmsg
=
'<input name="sel1" type="button" id="sel1" value="选取" onClick="SelectSoft(\'form1.softurl'
.
$newRowStart
.
'\')" />'
;
18
$nForm
.=
"<div style='line-height:36px'>软件地址{$newRowStart}:<input type='text' name='softurl{$newRowStart}' style='width:280px' value='"
.trim(
$ctag
->GetInnerText())."' />
19
服务器名称:<input type=
'text'
name=
'servermsg{$newRowStart}'
value=
'".$ctag->GetAtt("text")."'
style=
'width:150px'
/>
20
<input type=
'hidden'
name=
'islocal{$newRowStart}'
value=
'{$islocal}'
/>
21
$needmsg
22
</div>\r\n";
23
$newRowStart
++;
24
}
25
}
26
}
27
$dtp
->Clear();
28
}
找到
- $cts = $dsql->GetOne("SELECT addtable FROM `js_channeltype` WHERE id='$channelid' ");
在其上边加入以下代码:
- //软件链接列表
- $urls = '';
- for($i=1; $i<=30; $i++)
- {
- if(!empty(${'softurl'.$i}))
- {
- $islocal = empty(${'islocal'.$i}) ? '' : 1;
- $isneed = empty(${'del'.$i}) ? true : false;
- $servermsg = str_replace("'",'',stripslashes(${'servermsg'.$i}));
- $softurl = stripslashes(${'softurl'.$i});
- if($servermsg=='')
- {
- $servermsg = '下载地址'.$i;
- }
- if($softurl != 'http://')
- {
- if($islocal==1) $urls .= "{dede:link islocal='$islocal' text='{$servermsg}'} $softurl {/dede:link}\r\n" ;
- else if($isneed) $urls .= "{dede:link text='$servermsg'} $softurl {/dede:link}\r\n";
- else continue;
- }
- }
- }
- $urls = addslashes($urls);
找到
- $iquery = "UPDATE `$addtable` SET typeid='$typeid',body='$body'{$inadd_f},redirecturl='$redirecturl',templet='$templet',userip='$useip' WHERE aid='$id'";
替换为:
- $iquery = "UPDATE `$addtable` SET typeid='$typeid',body='$body'{$inadd_f},redirecturl='$redirecturl',templet='$templet',userip='$useip',softlinks ='$urls',needmoney = '$needmoney',daccess = '$daccess' WHERE aid='$id'";
至此本教程后台修改部分已经完毕,你学会了吗?接下来开始前台部分。
三、前台调用,和软件的前台调用方式一样,看以下代码
- {dede:field name='softlinks'/}
这个就是调用下载地址,打开的页面为软件模型的下载页,在哪里可以判断到下载的权限。这里就不多讲了,改完后就可以看到了。
有一种情况,就是有些网友希望没有下载地址的话就不显示,这里可以提供一种方法。把如下代码复制到文章模板里即可。
- {dede:php}
- $thisid = $refObj->Fields['aid'];
- $totrow=$dsql->GetOne('select * from js_addonarticle where aid='.$thisid);
- if($totrow['softlinks']!='')
- {
- echo "<a href=\"/plus/download.php?open=0&aid=".$thisid."&cid=1\" style=\"color:white\" target=\"_blank\">下载地址</a>";
- }
- {/dede:php}
前台效果图
到这里,本教程全文完毕。