Emlog非插件实现一键点赞教程

点赞功能还是比较有意思的,所以必须要来一个

用法很简单,在module.php里面加如以下代码

<?php //点赞
function addzan(){
$DB = MySql::getInstance();
if($DB->num_rows($DB->query("show columns from ".DB_PREFIX."blog like 'lemonzan'")) == 0){
$sql = "ALTER TABLE ".DB_PREFIX."blog ADD lemonzan int unsigned NOT NULL DEFAULT '0'";
$DB->query($sql);}}addzan();
function update($logid){
$logid = intval($_POST['id']);
$DB = Database::getInstance();
$DB->query("UPDATE " . DB_PREFIX . "blog SET lemonzan=lemonzan+1 WHERE gid=$logid");
setcookie('lemonzanpd_'. $logid, 'true', time() + 31536000);}
function lemoninit() {if( @$_POST['plugin'] == 'lemonzanpd' &&@$_POST['action'] == 'lemonzan' &&isset($_POST['id'])){
$id = intval($_POST['id']);
header("Access-Control-Allow-Origin: *");
update($id);echo getnum($id);die;}}lemoninit();
function getnum($id){
static $arr = array();
$DB = Database::getInstance();
if(isset($arr[$logid])) return $arr[$logid];
$sql = "SELECT lemonzan FROM " . DB_PREFIX . "blog WHERE gid=$id";
$res = $DB->query($sql);
$row = $DB->fetch_array($res);
$arr[$id] = intval($row['lemonzan']);
return $arr[$id];}
?>
再在文章页加入以下代码,CSS自己搞定

<div class="nrzan"><a class="lemonzanpd" data-lemonzanpd="<?php echo $logData['logid'] ; ?>" title="喜欢这篇文章就赞一个吧!"><i class="fa fa-thumbs-up"></i>赞 <b><u><?php echo(isset($logData['lemonzan'])?$logData['lemonzan']:getnum($logData['logid']));?></u></b> 次</a></div>


Comments : 0

有问题可在下面发表评论,当然没事也可以在下面吹吹牛皮、扯扯淡!! 有事私聊可以发邮件(ikiny#foxmail)!

发表评论

*