让dedecms系统ding实现【支持】【反对】投票功能

新建dedecms   htm 模板: body标签中:
{dede:arclist limit=’0,5′ titlelen=’50’}

<table width=”100%” border=”0″ cellspacing=”10″ cellpadding=”0″>

<tr  style=”background:#cccccc;” height=”200″>

<td width=”20%”>  <a href=”[field:arcurl/]”>[field:title/]</a> </td>
<td width=”30%”>[field:infos/]</td>
<td width=”50%”> <table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td>  <span id=”diggNum[field:id/]”><a href=”javascript:location.reload()” onclick=”javascript:postDigg(‘good’,[field:id/])”><img src=”/zt/da/zc.jpg” border=”0″></a><br><br>

    <a href=”javascript:location.reload()” onclick=”javascript:postDigg(‘bad’,[field:id/])”><img src=”/zt/da/fd.jpg” border=”0″></a></span>
</td>
<td> 赞成:([field:goodpost/]票)<br><br>
反对:([field:badpost/]票)<br>
最后投票时间[field:lastpost function=”MyDate(‘m-d H:m:s’,@me)”/]
</td>
</tr>
</table>
</td>
</tr>
</table><script language=”javascript” type=”text/javascript”>getDigg([field:id/]);</script>
{/dede:arclist}
—————————————————-华丽的分割线————————
head标签插入:
<script language=”javascript” type=”text/javascript” src=”{dede:global.cfg_cmsurl/}/include/dedeajax2.js”></script>
<script language=”javascript” type=”text/javascript”>
<!–
function postDigg(ftype,aid)
{
var taget_obj = document.getElementById(‘digg’+aid);
var saveid = GetCookie(‘diggid’);
if(saveid != null)
{
var saveids = saveid.split(‘,’);
var hasid = false;
saveid = ”;
j = 1;
for(i=saveids.length-1;i>=0;i–)
{
if(saveids[i]==aid && hasid) continue;
else {
if(saveids[i]==aid && !hasid) hasid = true;
saveid += (saveid==” ? saveids[i] : ‘,’+saveids[i]);
j++;
if(j==20 && hasid) break;
if(j==19 && !hasid) break;
}
}
if(hasid) { alert(‘您已经投过票了!’); return; }
else saveid += ‘,’+aid;
SetCookie(‘diggid’,saveid,1);
}
else
{
SetCookie(‘diggid’,aid,1);
}
myajax = new DedeAjax(taget_obj,false,false,”,”,”);
var url = “{dede:global.cfg_phpurl/}/digg_ajax_index.php?action=”+ftype+”&id=”+aid;
myajax.SendGet2(url);
DedeXHTTP = null;
}
function getDigg(aid)
{
var taget_obj = document.getElementById(‘digg’ + aid);
myajax = new DedeAjax(taget_obj,false,false,”,”,”);
myajax.SendGet2(“{dede:global.cfg_phpurl/}/digg_ajax_index.php?id=”+aid);
DedeXHTTP = null;
}
–>
</script>
—————————————————-华丽的分割线————————
新建digg_ajax_index.php 放到plus 文件夹下
代码:
<?php

/****************
@@ 功能:用于列表中DIGG处理效果
@@ 作者:华强℡(QQ:3421209)
@@ 网站:织梦教程网(xuewl.com)
@@ 日期:2010-09-28
****************/
require_once(dirname(__FILE__).”/../include/common.inc.php”);

$action = isset($action) ? trim($action) : ”;
$id = empty($id)? 0 : intval(preg_replace(“/[^\d]/”,”, $id));

if($id < 1)
{
exit();
}
$maintable = ‘c_archives’;
if($action == ‘good’)
{
$dsql->ExecuteNoneQuery(“Update `$maintable` set scores = scores + {$cfg_caicai_add},goodpost=goodpost+1,lastpost=”.time().” where id=’$id'”);
}
else if($action==’bad’)
{
$dsql->ExecuteNoneQuery(“Update `$maintable` set scores = scores – {$cfg_caicai_sub},badpost=badpost+1,lastpost=”.time().” where id=’$id'”);
}
$digg = ”;
$row = $dsql->GetOne(“Select goodpost,badpost,scores From `$maintable` where id=’$id’ “);
if(!is_array($row))
{
exit();
}
if($row[‘goodpost’]+$row[‘badpost’] == 0)
{
$row[‘goodper’] = $row[‘badper’] = 0;
}
else
{
$row[‘goodper’] = number_format($row[‘goodpost’]/($row[‘goodpost’]+$row[‘badpost’]),3)*100;
$row[‘badper’] = 100-$row[‘goodper’];
}

if(empty($formurl)) $formurl = ”;
if($formurl==’caicai’)
{
if($action == ‘good’) $digg = $row[‘goodpost’];
if($action == ‘bad’) $digg  = $row[‘badpost’];
}
else
{
$row[‘goodper’] = trim(sprintf(“%4.2f”, $row[‘goodper’]));
$row[‘badper’] = trim(sprintf(“%4.2f”, $row[‘badper’]));
$digg = ‘操作区:<a href=”javascript:” onclick=”javascript:postDigg(\’good\’,’.$id.’)”>顶</a>(’.$row[‘goodpost’].’) <a href=”javascript:” onclick=”javascript:postDigg(\’bad\’,’.$id.’)”>踩</a>(’.$row[‘badpost’].’)’;
}
AjaxHead();
echo $digg;
exit();
?>

—————————————————-华丽的分割线————————