| @@ -11,7 +11,8 @@ | |||
| */ | |||
| require_once(dirname(__FILE__)."/../include/common.inc.php"); | |||
| $action = isset($action) ? trim($action) : ''; | |||
| $id = empty($id)? 0 : intval(preg_replace("/[^\d]/",'', $id)); | |||
| $format = isset($format)? $format : ''; | |||
| $id = empty($id)? 0 : intval($id); | |||
| helper('cache'); | |||
| @@ -91,23 +92,39 @@ if($formurl=='caicai') | |||
| else | |||
| { | |||
| $row['goodper'] = trim(sprintf("%4.2f", $row['goodper'])); | |||
| $row['badper'] = trim(sprintf("%4.2f", $row['badper'])); | |||
| $digg = '<div class="diggbox digg_good" onmousemove="this.style.backgroundPosition=\'left bottom\';" onmouseout="this.style.backgroundPosition=\'left top\';" onclick="postDigg(\'good\','.$id.')"> | |||
| <div class="digg_act">顶一下</div> | |||
| <div class="digg_num">('.$row['goodpost'].')</div> | |||
| <div class="digg_percent"> | |||
| <div class="digg_percent_bar"><span style="width:'.$row['goodper'].'%"></span></div> | |||
| <div class="digg_percent_num">'.$row['goodper'].'%</div> | |||
| </div> | |||
| </div> | |||
| <div class="diggbox digg_bad" onmousemove="this.style.backgroundPosition=\'right bottom\';" onmouseout="this.style.backgroundPosition=\'right top\';" onclick="postDigg(\'bad\','.$id.')"> | |||
| <div class="digg_act">踩一下</div> | |||
| <div class="digg_num">('.$row['badpost'].')</div> | |||
| <div class="digg_percent"> | |||
| <div class="digg_percent_bar"><span style="width:'.$row['badper'].'%"></span></div> | |||
| <div class="digg_percent_num">'.$row['badper'].'%</div> | |||
| </div> | |||
| </div>'; | |||
| $row['badper'] = trim(sprintf("%4.2f", $row['badper'])); | |||
| if (!empty($format)) { | |||
| // 输出JSON API的方式 | |||
| $result = array( | |||
| "code" => 200, | |||
| "data" => array( | |||
| 'goodpost' => $row['goodpost'], | |||
| 'goodper' => $row['goodper'], | |||
| 'badpost' => $row['badpost'], | |||
| 'badper' => $row['badper'], | |||
| ), | |||
| ); | |||
| $digg = json_encode($result); | |||
| } else { | |||
| // 兼容之前的老版本 | |||
| $digg = '<div class="diggbox digg_good" onmousemove="this.style.backgroundPosition=\'left bottom\';" onmouseout="this.style.backgroundPosition=\'left top\';" onclick="postDigg(\'good\','.$id.')"> | |||
| <div class="digg_act">顶一下</div> | |||
| <div class="digg_num">('.$row['goodpost'].')</div> | |||
| <div class="digg_percent"> | |||
| <div class="digg_percent_bar"><span style="width:'.$row['goodper'].'%"></span></div> | |||
| <div class="digg_percent_num">'.$row['goodper'].'%</div> | |||
| </div> | |||
| </div> | |||
| <div class="diggbox digg_bad" onmousemove="this.style.backgroundPosition=\'right bottom\';" onmouseout="this.style.backgroundPosition=\'right top\';" onclick="postDigg(\'bad\','.$id.')"> | |||
| <div class="digg_act">踩一下</div> | |||
| <div class="digg_num">('.$row['badpost'].')</div> | |||
| <div class="digg_percent"> | |||
| <div class="digg_percent_bar"><span style="width:'.$row['badper'].'%"></span></div> | |||
| <div class="digg_percent_num">'.$row['badper'].'%</div> | |||
| </div> | |||
| </div>'; | |||
| } | |||
| } | |||
| AjaxHead(); | |||
| echo $digg; | |||
| @@ -1,53 +0,0 @@ | |||
| <?php | |||
| /** | |||
| * | |||
| * 文档digg处理iframe文件 | |||
| * | |||
| * @version $Id: digg_frame.php 1 21:17 2010年7月8日Z tianya $ | |||
| * @package DedeCMS.Plus | |||
| * @copyright Copyright (c) 2007 - 2020, DesDev, Inc. | |||
| * @license http://help.dedecms.com/usersguide/license.html | |||
| * @link http://www.dedecms.com | |||
| */ | |||
| require_once(dirname(__FILE__)."/../include/common.inc.php"); | |||
| $action = isset($action) ? trim($action) : ''; | |||
| $id = empty($id)? 0 : intval(preg_replace("/[^\d]/",'', $id)); | |||
| $maintable = '#@__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($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']; | |||
| } | |||
| $digg = '<div class="diggbox digg_good" onmousemove="this.style.backgroundPosition=\'left bottom\';" onmouseout="this.style.backgroundPosition=\'left top\';" onclick="postDigg(\'good\','.$id.')"> | |||
| <div class="digg_act">顶一下</div> | |||
| <div class="digg_num">('.$row['goodpost'].')</div> | |||
| <div class="digg_percent"> | |||
| <div class="digg_percent_bar"><span style="width:'.$row['goodper'].'%"></span></div> | |||
| <div class="digg_percent_num">'.$row['goodper'].'%</div> | |||
| </div> | |||
| </div> | |||
| <div class="diggbox digg_bad" onmousemove="this.style.backgroundPosition=\'right bottom\';" onmouseout="this.style.backgroundPosition=\'right top\';" onclick="postDigg(\'bad\','.$id.')"> | |||
| <div class="digg_act">踩一下</div> | |||
| <div class="digg_num">('.$row['badpost'].')</div> | |||
| <div class="digg_percent"> | |||
| <div class="digg_percent_bar"><span style="width:'.$row['badper'].'%"></span></div> | |||
| <div class="digg_percent_num">'.$row['badper'].'%</div> | |||
| </div> | |||
| </div>'; | |||
| include DEDEROOT.'/templets/plus/digg_frame.htm'; | |||
| @@ -0,0 +1,78 @@ | |||
| {dede:comment text="顶踩模块"/} | |||
| <div class="row justify-content-center digg"> | |||
| <div class="comment-container mb-3" onclick="javascript:PostDigg('good',{dede:field.id/})"> | |||
| <div class="comment-top"> | |||
| <i class="fa fa-thumbs-o-up" aria-hidden="true"></i> | |||
| <p class="comment-top-text">顶一下[<span id="goodpost">{dede:field.goodpost/}</span>]</p> | |||
| </div> | |||
| <div class="progress" style="height: 10px;"> | |||
| <div class="progress-bar" role="progressbar" id="goodper" style="width: {dede:field.goodper/}%" | |||
| aria-valuenow="{dede:field.goodper/}" aria-valuemin="0" aria-valuemax="100"></div> | |||
| </div> | |||
| </div> | |||
| <div class="comment-container mb-3" onclick="javascript:PostDigg('bad',{dede:field.id/})"> | |||
| <div class="comment-top"> | |||
| <i class="fa fa-thumbs-o-down" aria-hidden="true"></i> | |||
| <p class="comment-top-text-danger">踩一下[<span id="badpost">{dede:field.badpost/}</span>]</p> | |||
| </div> | |||
| <div class="progress" style="height: 10px;"> | |||
| <div class="progress-bar bg-danger" role="progressbar" id="badper" style="width:{dede:field.badper/}%" | |||
| aria-valuenow="{dede:field.badper/}" aria-valuemin="0" aria-valuemax="100"></div> | |||
| </div> | |||
| </div> | |||
| </div> <!-- ./digg --> | |||
| <script> | |||
| // 获取顶踩数据 | |||
| function GetDigg(aid) { | |||
| let url = `{dede:global.cfg_phpurl/}/digg_ajax.php?id=${aid}&format=json`; | |||
| $.get(url, function (data) { | |||
| let reval = JSON.parse(data); | |||
| if (reval.code === 200) { | |||
| $("#goodpost").html(reval.data.goodpost); | |||
| $("#badpost").html(reval.data.badpost); | |||
| $("#goodper").css("width", `${reval.data.goodper}%`) | |||
| $("#badper").css("width", `${reval.data.badper}%`) | |||
| } | |||
| }) | |||
| } | |||
| function PostDigg(ftype, 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); | |||
| } | |||
| let url = "{dede:global.cfg_phpurl/}/digg_ajax.php?action=" + ftype + "&id=" + aid + "&format=json"; | |||
| $.get(url, function (data) { | |||
| let reval = JSON.parse(data); | |||
| if (reval.code === 200) { | |||
| $("#goodpost").html(reval.data.goodpost); | |||
| $("#badpost").html(reval.data.badpost); | |||
| $("#goodper").css("width", `${reval.data.goodper}%`) | |||
| $("#badper").css("width", `${reval.data.badper}%`) | |||
| } | |||
| }); | |||
| } | |||
| GetDigg("{dede:field.id/}"); | |||
| </script> | |||
| @@ -1,156 +0,0 @@ | |||
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |||
| <html xmlns="http://www.w3.org/1999/xhtml"> | |||
| <head> | |||
| <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $cfg_soft_lang;?>" /> | |||
| <title>digg</title> | |||
| <style> | |||
| body { | |||
| text-align:center; | |||
| } | |||
| #digg { | |||
| margin:0 auto; | |||
| width:420px; | |||
| overflow:hidden; | |||
| } | |||
| .diggbox { | |||
| cursor:pointer; | |||
| float:left; | |||
| height:51px; | |||
| margin-right:8px; | |||
| overflow:hidden; | |||
| width:195px; | |||
| } | |||
| .diggbox .digg_act { | |||
| float:left; | |||
| font-size:14px; | |||
| font-weight:bold; | |||
| height:29px; | |||
| line-height:31px; | |||
| overflow:hidden; | |||
| text-indent:32px; | |||
| } | |||
| .diggbox .digg_num { | |||
| float:left; | |||
| line-height:29px; | |||
| text-indent:5px; | |||
| } | |||
| .diggbox .digg_percent { | |||
| text-align:left; | |||
| clear:both; | |||
| overflow:hidden; | |||
| padding-left:10px; | |||
| width:180px; | |||
| } | |||
| .diggbox .digg_percent .digg_percent_bar { | |||
| background:#E8E8E8 none repeat scroll 0 0; | |||
| border-right:1px solid #CCCCCC; | |||
| float:left; | |||
| height:7px; | |||
| margin-top:3px; | |||
| overflow:hidden; | |||
| width:100px; | |||
| } | |||
| .diggbox .digg_percent .digg_percent_num { | |||
| float:left; | |||
| font-size:10px; | |||
| padding-left:10px; | |||
| } | |||
| .diggbox .digg_percent .digg_percent_bar span { | |||
| background:#000000 none repeat scroll 0 0; | |||
| display:block; | |||
| height:5px; | |||
| overflow:hidden; | |||
| } | |||
| .digg_good { | |||
| background:transparent url(../templets/default/images/newdigg-bg.png) no-repeat scroll left top; | |||
| } | |||
| .digg_bad { | |||
| background:transparent url(../templets/default/images/newdigg-bg.png) no-repeat scroll right top; | |||
| } | |||
| .digg_good .digg_act { | |||
| color:#CC3300; | |||
| } | |||
| .digg_good .digg_num { | |||
| color:#CC6633; | |||
| } | |||
| .digg_bad .digg_act { | |||
| color:#3366CC; | |||
| } | |||
| .digg_bad .digg_num { | |||
| color:#3399CC; | |||
| } | |||
| .digg_good .digg_percent .digg_percent_bar span { | |||
| background:#FFC535 none repeat scroll 0 0; | |||
| border:1px solid #E37F24; | |||
| } | |||
| .digg_bad .digg_percent .digg_percent_bar span { | |||
| background:#94C0E4 none repeat scroll 0 0; | |||
| border:1px solid #689ACC; | |||
| } | |||
| </style> | |||
| <script> | |||
| //读写cookie函数 | |||
| function GetCookie(c_name) | |||
| { | |||
| if (document.cookie.length > 0) | |||
| { | |||
| c_start = document.cookie.indexOf(c_name + "=") | |||
| if (c_start != -1) | |||
| { | |||
| c_start = c_start + c_name.length + 1; | |||
| c_end = document.cookie.indexOf(";",c_start); | |||
| if (c_end == -1) | |||
| { | |||
| c_end = document.cookie.length; | |||
| } | |||
| return unescape(document.cookie.substring(c_start,c_end)); | |||
| } | |||
| } | |||
| return null | |||
| } | |||
| function SetCookie(c_name,value,expiredays) | |||
| { | |||
| var exdate = new Date(); | |||
| exdate.setDate(exdate.getDate() + expiredays); | |||
| document.cookie = c_name + "=" +escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()); //使设置的有效时间正确。增加toGMTString() | |||
| } | |||
| function postDigg(ac, 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 false; } | |||
| else saveid += ','+aid; | |||
| SetCookie('diggid',saveid,1); | |||
| } else { | |||
| SetCookie('diggid',aid,1); | |||
| } | |||
| location.href='digg_frame.php?action='+ac+'&id='+aid; | |||
| } | |||
| </script> | |||
| <body> | |||
| <div id="digg"> | |||
| <?php | |||
| echo $digg; | |||
| ?> | |||
| </div> | |||
| </body> | |||
| </html> | |||