文章不错非常喜欢
<?php $zancai = zan_cai($logid);?> <span class="win_zan" data-zan="<?php echo $logid;?>">踩:<b><?php echo $zancai[0];?></b></span> <span class="win_cai" data-cai="<?php echo $logid;?>">赞:<b><?php echo $zancai[1];?></b></span>
<?php //文章赞踩 function zan_cai($logid){ if($logid){ $DB = Database::getInstance(); $row = $DB->fetch_array($DB->query("SELECT digg FROM ".DB_PREFIX."blog WHERE gid=$logid")); return explode(',',$row['digg']); } } function zancai_logid(){ $DB = Database::getInstance(); if($DB->fetch_array($DB->query( "Describe ".DB_PREFIX."blog digg" )) == false ){ $sql = "ALTER TABLE ".DB_PREFIX."blog ADD digg varchar(10) NOT NULL DEFAULT '0,0'"; $DB->query($sql); } if($_POST['plugin'] == 'digg') { header("Access-Control-Allow-Origin: *"); echo zancai_updata($DB,$_POST['mark'],$_POST['id']);die; } } zancai_logid(); function zancai_updata($DB,$mark,$id){ $gid = intval($id); $data = zan_cai($id); if ($mark == 'zan'){ $data[0] += 1; $zancai = $data[0].','.$data[1]; $DB->query("UPDATE ". DB_PREFIX."blog SET digg='{$zancai}' WHERE gid={$gid}"); setcookie('zakura_digg'.$gid,$gid, time() + (10 * 365 * 24 * 60 * 60) ); return $data[0]; }elseif($mark == 'cai'){ $data[1] += 1; $zancai = $data[0].','.$data[1]; $DB->query("UPDATE ". DB_PREFIX."blog SET digg='{$zancai}' WHERE gid={$gid}"); setcookie('zakura_undigg'.$gid,$gid, time() + (10 * 365 * 24 * 60 * 60) ); return $data[1]; } } ?>
<script> $(document).ready(function() { $('.win_zan').on('click', function() { var a = $(this); var postid = a.attr('data-zan'); if (new RegExp('zakura_digg' + postid + '', 'i').test(document.cookie)) { alert('已经赞过了'); } else { if (new RegExp('zakura_undigg' + postid + '', 'i').test(document.cookie)) { alert('踩过了,不能再赞'); } else { a.addClass('current'); $.post('', { plugin: 'digg', mark: 'zan', id: postid }, function(data, status) { alert('赞了一下'); a.find('b').text(data); }); } } }); $('.win_cai').on('click', function() { var a = $(this); var postid = a.attr('data-cai'); if (new RegExp('zakura_undigg' + postid + '', 'i').test(document.cookie)) { alert('已经踩过了'); } else { if (new RegExp('zakura_digg' + postid + '', 'i').test(document.cookie)) { alert('赞过了,不能再踩'); } else { a.addClass('current'); $.post('', { plugin: 'digg', mark: 'cai', id: postid }, function(data, status) { alert('踩了一下'); a.find('b').text(data); }); } } }); }); </script>