本教程實現(xiàn)DEDECMS功能:文章模型整合下載功能,可判斷點數(shù),會員組等下載權(quán)限,前臺可判斷是否有附件下載,有則顯示,沒有則不顯示。適用類型:有些文章有下載地址,有些文章沒有下載地址的網(wǎng)站。想附件收費的網(wǎng)站等等……具體就不啰嗦了。用得上您就拿走。
后臺效果圖
本教程為站長似水星辰原創(chuàng),轉(zhuǎn)載注明出處。
注:本教程中的金幣和會員組設(shè)置只針對下載連接有效。不對文章內(nèi)容生效,和文章本身的閱讀權(quán)限和消費金幣并不沖突,是分開設(shè)置的。文章中所有sql語句中涉及表名的,請把表前綴換成您自己的表前綴。如:js_addonarticle 換成 您的表前綴_addonarticle。
一、首先規(guī)劃要加入的字段
下載鏈接:softlinks
消費金幣:needmoney
會員組權(quán)限:daccess
這些字段要加入到文章附加表中,前綴_addonarticle,也可以根據(jù)自己情況加入需要的表中,自己修改就行了。
進入后臺系統(tǒng)-SQL命令行工具,執(zhí)行:
-
ALTER TABLE `js_addonarticle` ADD `softlinks` TEXT NOT NULL ,
-
ADD `needmoney` SMALLINT( 5 ) NOT NULL ,
-
ADD `daccess` SMALLINT( 5 ) NOT NULL
也可以在phpmyadmin中自行添加。
然后在后臺打開核心-頻道模型-內(nèi)容模型管理-普通文章-修改-字段管理,在模型字段配置(文本模式) 里添加
-
<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" />
如果不添加則會出現(xiàn)無鏈接信息錯誤!請務(wù)必添加。
二、數(shù)據(jù)庫字段添加完畢就要修改文章模型的4個文件了。分別是dede管理目錄下的article_add.php,article_edit.php和管理模板article_add.htm,article_edit.htm,打開這4個文件依次修改。
1、修改article_add.htm,在頭部的<script></script>中加入以下,在</script>之前加入就行
-
var startNum = 0;
-
function MakeUpload()
-
{
-
var upfield = document.getElementById("uploadfield");
-
var endNum = parseInt(document.form1.picnum.value) + startNum-1;
-
if(endNum > 30) endNum = 30;
-
for(startNum; startNum<=endNum; startNum++){
-
upfield.innerHTML += "<div style='line-height:36px'>軟件地址"+startNum+":<input type='text' name='softurl"+startNum+"' style='width:280px' value='http://' /> 服務(wù)器名稱:<input type='text' name='servermsg"+startNum+"' style='width:150px' /></div>\r\n";
-
}
-
}
-
function ShowHideAddr()
-
{
-
document.getElementById('morelink').style.display = (document.getElementById('morelink').style.display=='block' ? 'none' : 'block');
-
document.getElementById('morelink').style.height = '100%';
-
document.getElementById('btsh3').value = (document.getElementById('morelink').style.display=='block' ? '隱藏地址' : '顯示地址');
-
}
這個是可以增加下載地址個數(shù)的JS代碼。
2、找到
-
<tr>
-
<td colspan="2"><?php PrintAutoFieldsAdd($cInfos['fieldset'],'autofield'); ?></td>
-
</tr>
再其后邊加入
-
<tr>
-
<td height="24" bgcolor="#F9FCEF"" class="bline2"><strong> 下載限制:</strong></td>
-
</tr>
-
<tr>
-
<td height="24" class="bline">
-
<table width="800" border="0" cellpadding="0" cellspacing="0">
-
<tr>
-
<td width="90" height="30"> 需會員權(quán)限:</td>
-
<td width="179" align="left">
-
<select name="daccess" id="daccess" style="width:90px">
-
<?php
-
$dsql->SetQuery("Select * from `js_arcrank` where rank>=0 ");
-
$dsql->Execute();
-
while($row = $dsql->GetArray())
-
{
-
if($row['rank']==0) $row['membername'] = "不限會員";
-
if($row['rank'] == $softconfig['dfrank']) echo " <option value='{$row['rank']}' selected>{$row['membername']}</option>\r\n";
-
else echo " <option value='{$row['rank']}'>{$row['membername']}</option>\r\n";
-
}
-
?>
-
</select> </td>
-
<td width="120" align="center">需消費金幣:</td>
-
<td width="411">
-
<input name="needmoney" type="text" id="needmoney" value="<?php echo $softconfig['dfywboy']; ?>" size="8" />個 </td>
-
</tr>
-
<tr>
-
<td height="26" colspan="4" style="border-top:1px dashed #8EAF61"> <span class="STYLE1">(如果設(shè)定了下載限制,[<a href="soft_config.php" target="_blank"><u>軟件頻道設(shè)置</u></a>]中“附件下載方式:”必須選擇“鏈接到跳轉(zhuǎn)頁面”) </span></td>
-
</tr>
-
</table>
-
</td>
-
</tr>
-
<tr>
-
<td height="24" bgcolor="#F9FCEF" class="bline2"><strong> 本地軟件選擇:</strong></td>
-
</tr>
-
<tr>
-
<td height="24" class="bline">
-
<table width="800" border="0" cellspacing="0" cellpadding="0">
-
<tr>
-
<td width="90" height="30"> 本地地址:</td>
-
<td>
-
<input name="softurl1" type="text" id="softurl1" size="35" />
-
<input name="sel1" type="button" id="sel1" value="選取" onClick="SelectSoft('form1.softurl1')" />
-
服務(wù)器名稱:
-
<input name="servermsg1" type="text" id="servermsg1" value="本地下載" style="width:150px" />
-
</td>
-
</tr>
-
</table>
-
</td>
-
</tr>
-
<?php
-
if($softconfig['moresitedo'] == 0 && trim($softconfig['sites']) != '')
-
{
-
?>
-
<tr>
-
<td height="24" bgcolor="#F9FCEF" class="bline2"><b> 預設(shè)的鏡像服務(wù)器:</b></td>
-
</tr>
-
<tr class="bline">
-
<td style="padding-left:10px;">
-
(服務(wù)器地址 + 軟件地址 = 軟件真實地址 [<a href="soft_config.php" target="_blank"><u>軟件頻道設(shè)置</u></a>])<br />
-
<?php
-
$sites = explode("\n", $softconfig['sites']);
-
$startNum = 2;
-
foreach($sites as $site)
-
{
-
$site = trim($site);
-
if(empty($site)) continue;
-
list($siteurl, $sitename) = explode('|', $site);
-
$siteurl = trim($siteurl);
-
$sitename = trim($sitename);
-
?>
-
<?php echo $sitename; ?>:
-
<input type='hidden' name='forconfig<?php echo $startNum; ?>' value='1' />
-
<input type='text' name='softurlfirst<?php echo $startNum; ?>' style='width:200px' value='<?php echo $siteurl; ?>' /> +
-
<input type='text' name='softurl<?php echo $startNum; ?>' style='width:120px' value='' />
-
<input type='text' name='servermsg<?php echo $startNum; ?>' style='width:150px' value='<?php echo $sitename; ?>' />
-
<input type='checkbox' name='need<?php echo $startNum; ?>' class='np' value='1' checked />啟用
-
<br />
-
<?php
-
$startNum++;
-
}//foreach
-
echo "<script language='javascript'>startNum = $startNum;</script>\r\n";
-
?>
-
</td>
-
</tr>
-
<?php
-
}//需要預設(shè)鏡像
-
?>
-
<tr>
-
<td height="24" bgcolor="#F9FCEF" class="bline2"><b> 手動指定地址:</b></td>
-
</tr>
-
<tr>
-
<td height="24" class="bline" style="padding-left:8px">
-
<table width="800" border="0" cellspacing="0" cellpadding="0" style="margin-bottom:5px;" class="bline">
-
<tr>
-
<td width="90">其它地址:</td>
-
<td>
-
<input name="picnum" type="text" id="picnum" size="8" value="5" />
-
<input name='kkkup' type='button' id='kkkup2' value='增加地址' onClick="MakeUpload();" />
-
-
<input type="button" name="Submit3" id="btsh3" value="隱藏地址" onClick="ShowHideAddr();" />
-
(最多為30個鏈接)
-
</td>
-
</tr>
-
</table>
-
<div id="morelink" style="display:block">
-
<div id='uploadfield' style="width:790px"></div>
-
</div>
-
</td>
-
</tr>
到這里article_add.htm文件就修改完了。
3、打開article_edit.htm文件,在頭部的<script></script>中加入以下代碼,在</script>之前加入就行
-
var startNum = <?php echo $newRowStart?>;
-
function MakeUpload()
-
{
-
var upfield = document.getElementById('uploadfield');
-
var endNum = parseInt(document.form1.picnum.value) + startNum;
-
if(endNum > 30) endNum = 30;
-
for(startNum; startNum < endNum; startNum++)
-
{
-
upfield.innerHTML += "<div style='line-height:36px'>軟件地址"+startNum+":<input type='text' name='softurl"+startNum+"' style='width:280px' value='http://' /> 服務(wù)器名稱:<input type='text' name='servermsg"+startNum+"' style='width:150px' /></div>\r\n";
-
}
-
}
-
-
function ShowHideAddr()
-
{
-
document.getElementById('morelink').style.display = (document.getElementById('morelink').style.display=='block' ? 'none' : 'block');
-
document.getElementById('btsh3').value = (document.getElementById('morelink').style.display=='block' ? '隱藏地址' : '顯示地址');
-
}
4、找到
-
<tr>
-
<td colspan="2"><?php
-
PrintAutoFieldsEdit($cInfos['fieldset'],$addRow,'autofield');
-
?></td>
-
</tr>
在其下邊加入以下代碼:
-
<tr>
-
<td height="24" class="bline">
-
<table width="800" border="0" cellpadding="0" cellspacing="0">
-
<tr>
-
<td width="90" height="30"> 需會員權(quán)限:</td>
-
<td width="179" align="center">
-
<select name="daccess" id="daccess" style="width:90px">
-
<?php
-
$dsql->SetQuery("Select * from `js_arcrank` where rank>=0 ");
-
$dsql->Execute();
-
while($row = $dsql->GetArray())
-
{
-
if($row['rank']==0) $row['membername'] = "不限會員";
-
if($row['rank'] == $daccess) echo " <option value='{$row['rank']}' selected>{$row['membername']}</option>\r\n";
-
else echo " <option value='{$row['rank']}'>{$row['membername']}</option>\r\n";
-
}
-
?>
-
</select>
-
</td>
-
<td width="120" align="center">需消費金幣:</td>
-
<td width="411">
-
<input name="needmoney" type="text" id="needmoney" value="<?php echo $needmoney; ?>" size="8" />個
-
</td>
-
</tr>
-
<tr>
-
<td height="26" colspan="4" style="border-top:1px dashed #8EAF61"> <span class="STYLE1">(如果設(shè)定了下載限制,<a href="soft_config.php" target="_blank"><u>軟件頻道設(shè)置</u></a>中“附件下載方式:”必須選擇“鏈接到跳轉(zhuǎn)頁面”) </span></td>
-
</tr>
-
</table>
-
</td>
-
</tr>
-
<tr>
-
<td height="24" colspan="4" bgcolor="#F9FCEF"class="bline2"><strong> 軟件鏈接列表:</strong></td>
-
</tr>
-
<tr>
-
<td height="24" colspan="4" class="bline">
-
<table width="800" border="0" cellspacing="0" cellpadding="0">
-
<tr>
-
<td width="72"> 其它地址:</td>
-
<td>
-
<input name="picnum" type="text" id="picnum" size="8" value="5" />
-
<input name='kkkup' type='button' id='kkkup2' value='增加數(shù)量' onClick="MakeUpload();" />
-
-
<input type="button" name="Submit3" id="btsh3" value="隱藏地址" onClick="ShowHideAddr();" />
-
(最多為30個鏈接)
-
</td>
-
</tr>
-
</table>
-
</td>
-
</tr>
-
<tr>
-
<td height="24" colspan="4" class="bline" style="padding-left:8px">
-
<?php
-
echo $nForm;
-
?>
-
<div id='morelink' style='display:block'>
-
<div id='uploadfield' style='width:800px'></div>
-
</div>
-
</td>
-
</tr>
article_edit.html修改完畢,接下來開始修改article_add.php,要認真看哦!
5、打開article_add.php,找到
-
//保存到附加表
-
$cts = $dsql->GetOne("SELECT addtable FROM `js_channeltype` WHERE id='$channelid' ");
在其上邊加入
-
//軟件鏈接列表
-
$urls = '';
-
-
//本地鏈接處理
-
$softurl1 = stripslashes($softurl1);
-
$nsoftsize = '';
-
if($softurl1 != '')
-
{
-
$urls .= "{dede:link islocal='1' text='{$servermsg1}'} $softurl1 {/dede:link}\r\n";
-
}
-
-
//其它鏈接處理
-
for($i=2; $i<=30; $i++)
-
{
-
if(!(${'softurl'.$i}))
-
{
-
$forconfig = (${'forconfig'.$i}) ? FALSE : TRUE;
-
if($forconfig)
-
{
-
if(empty(${'need'.$i})) continue;
-
$serverUrl = stripslashes(${'softurlfirst'.$i});
-
$serverUrl = preg_replace("#\/$#", "", $serverUrl);
-
$softurl = stripslashes(${'softurl'.$i});
-
if( cn_substr($softurl, 1) != '/' ) $softurl = '/'.$softurl;
-
$softurl = $serverUrl.$softurl;
-
}
-
else
-
{
-
$softurl = stripslashes(${'softurl'.$i});
-
}
-
$servermsg = str_replace("'", "", stripslashes(${'servermsg'.$i}));
-
if($servermsg=='') $servermsg = '下載地址'.$i;
-
if($softurl != 'http://')
-
{
-
$urls .= "{dede:link text='$servermsg'} $softurl {/dede:link}\r\n";
-
}
-
}
-
}
-
$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修改完畢,添加一下文章,把下載地址,金幣,會員組都寫進去,看看數(shù)據(jù)庫是不是有這條記錄了^ ^。
6、打開article_edit.php,找到
-
$channelid = $arcRow['channel'];
在其上邊加入
-
$newRowStart = 1;
-
$nForm = '';
-
$daccess = $addRow['daccess'];
-
$needmoney = $addRow['needmoney'];
-
if($addRow['softlinks'] != '')
-
{
-
$dtp = new DedeTagParse();
-
$dtp->LoadSource($addRow['softlinks']);
-
if(is_array($dtp->CTags))
-
{
-
foreach($dtp->CTags as $ctag)
-
{
-
if($ctag->GetName()=='link')
-
{
-
$islocal = $ctag->GetAtt('islocal');
-
if($islocal != 1) $needmsg = "<input type='checkbox' name='del{$newRowStart}' value='1' />刪除";
-
else $needmsg = '<input name="sel1" type="button" id="sel1" value="選取" onClick="SelectSoft(\'form1.softurl'.$newRowStart.'\')" />';
-
$nForm .= "<div style='line-height:36px'>軟件地址{$newRowStart}:<input type='text' name='softurl{$newRowStart}' style='width:280px' value='".trim($ctag->GetInnerText())."' />
-
服務(wù)器名稱:<input type='text' name='servermsg{$newRowStart}' value='".$ctag->GetAtt("text")."' style='width:150px' />
-
<input type='hidden' name='islocal{$newRowStart}' value='{$islocal}' />
-
$needmsg
-
</div>\r\n";
-
$newRowStart++;
-
}
-
}
-
}
-
$dtp->Clear();
-
}
找到
-
$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'";
至此本教程后臺修改部分已經(jīng)完畢,你學會了嗎?接下來開始前臺部分。
三、前臺調(diào)用,和軟件的前臺調(diào)用方式一樣,看以下代碼
-
{dede:field name='softlinks'/}
這個就是調(diào)用下載地址,打開的頁面為軟件模型的下載頁,在哪里可以判斷到下載的權(quán)限。這里就不多講了,改完后就可以看到了。
有一種情況,就是有些網(wǎng)友希望沒有下載地址的話就不顯示,這里可以提供一種方法。把如下代碼復制到文章模板里即可。
-
{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}
前臺效果圖
到這里,本教程全文完畢。