• 全国400电话网上服务平台
    强大号码库资源任选,方便,快捷,快速开通。
    咨询热线:400-1100-266  

    织梦dedecms文章模型整合下载功能,可判断点数,
    POST TIME:2017-11-12 23:53

    本教程实现DEDECMS功能:文章模型整合下载功能,可判断点数,会员组等下载权限,前台可判断是否有附件下载,有则显示,没有则不显示。适用类型:有些文章有下载地址,有些文章没有下载地址的网站。想附件收费的网站等等……具体就不啰嗦了。用得上您就拿走。

    DEDECMS文章模型整合下载功能,可判断点数,会员组等下载权限



    后台效果图


    注:本教程中的金币和会员组设置只针对下载连接有效。不对文章内容生效,和文章本身的阅读权限和消费金币并不冲突,是分开设置的。文章中所有sql语句中涉及表名的,请把表前缀换成您自己的表前缀。如:js_addonarticle 换成 您的表前缀_addonarticle。
    一、首先规划要加入的字段
    下载链接:softlinks
    消费金币:needmoney
    会员组权限:daccess
    这些字段要加入到文章附加表中,前缀_addonarticle,也可以根据自己情况加入需要的表中,自己修改就行了。
    进入后台系统-SQL命令行工具,执行:
    ALTER TABLE `js_addonarticle`ADD `softlinks` TEXT NOT NULL ,
    ADD `needmoney` SMALLINT( 5 ) NOT NULL ,
    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>
    之前加入就行
    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&quot;+startNum+&quot;" style="width:280px;" value="" /> 服务器名称:<input type="text" name="servermsg&quot;+startNum+&quot;" 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' ? '隐藏地址' : '显示地址');
    }
    这个是可以增加下载地址个数的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"> 需会员权限:</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">(如果设定了下载限制,[<a href="soft_config.php" target="_blank"><u>软件频道设置</u></a>]中“附件下载方式:”必须选择“链接到跳转页面”) </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')" /> 服务器名称: <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> 预设的镜像服务器:</b></td></tr><tr class="bline"><td style="padding-left:10px;">(服务器地址 + 软件地址 = 软件真实地址 [<a href="soft_config.php" target="_blank"><u>软件频道设置</u></a>])
    <?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="checked" />启用
    <?php
    $startNum++;
    }//foreach
    echo "
    <script language="javascript">startNum = $startNum;</script>
    \r\n";
    ?></td></tr><?php
    }//需要预设镜像
    ?><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&quot;+startNum+&quot;" style="width:280px;" value="" /> 服务器名称:<input type="text" name="servermsg&quot;+startNum+&quot;" 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"> 需会员权限:</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">(如果设定了下载限制,<a href="soft_config.php" target="_blank"><u>软件频道设置</u></a>中“附件下载方式:”必须选择“链接到跳转页面”) </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="增加数量" 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 != '')
    {
    $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修改完毕,添加一下文章,把下载地址,金币,会员组都写进去,看看数据库是不是有这条记录了^ ^。
    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="&quot;.trim($ctag->GetInnerText()).&quot;" /> 服务器名称:<input type="text" name="servermsg{$newRowStart}" value="&quot;.$ctag->GetAtt(&quot;text&quot;).&quot;" 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 != '')
    {
    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}


    前台效果图
    到这里,本教程全文完毕。

    感谢支持跟版网,你的支持,我们的无限动力!!!
    
    关于我们 | 付款方式 | 建站知识 | 增值服务 | 网站模板
    Copyright © 2003-2016
    时间:9:00-21:00 (节假日不休)
    版权所有:巨人网络(扬州)科技有限公司
    总部地址:江苏省信息产业基地11号楼四层
    《增值电信业务经营许可证》 苏B2-20120278
    X

    截屏,微信识别二维码

    微信号:veteran88

    (点击微信号复制,添加好友)

     打开微信

    微信号已复制,请打开微信添加咨询详情!