Warning: session_start(): Unable to clear session lock record in /www/wwwroot/reaff.com/wp-content/themes/Autumn-Pro/functions.php on line 5

Warning: session_start(): Failed to read session data: memcached (path: 127.0.0.1:11211) in /www/wwwroot/reaff.com/wp-content/themes/Autumn-Pro/functions.php on line 5
Emlog非插件实现一键点赞功能 – 王板汪之家

Emlog非插件实现一键点赞功能

cera cera

第一步:在module.php中加入以下代码:

$sql = “ALTER TABLE “.DB_PREFIX.”blog ADD slzan int unsigned NOT NULL DEFAULT ‘0’”;
$DB->query($sql);}}syzan();
function update($logid){
$logid = intval($_POST[‘id’]);
$DB = Database::getInstance();
$DB->query(“UPDATE ” . DB_PREFIX . “blog SET slzan=slzan+1 WHERE gid=$logid”);
setcookie(‘slzanpd_’. $logid, ‘true’, time() + 31536000);}
function lemoninit() {if( @$_POST[‘plugin’] == ‘slzanpd’ &&@$_POST[‘action’] == ‘slzan’ &&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 slzan FROM ” . DB_PREFIX . “blog WHERE gid=$id”;
$res = $DB->query($sql);
$row = $DB->fetch_array($res);
$arr[$id] = intval($row[‘slzan’]);
return $arr[$id];}
?>

第二步:在文章页echo_log.php位置下加入以下代码:

赞 (次)

第三步:在JS文件里加上以下代码:

$(document).on(‘click’, ‘.slzanpd’,
function() {
var a = $(this),
id = a.data(‘slzanpd’);
if (slzanpd_check(id)) {
alert(‘您已赞过本文!’);
} else {
$.post(”, {
plugin: ‘slzanpd’,
action: ‘slzan’,
id: id
},
function(b) {
a.find(‘u’).html(b);
slzanpd_(a);
});
}
});
function slzanpd_check(id) {
return new RegExp(‘slzanpd_’ + id + ‘=true’).test(document.cookie);
}
$(‘[data-slzanpd]’).each(function() {
var a = $(this),
id = a.data(‘slzanpd’);
if (slzanpd_check(id)) {
slzanpd_(a);
} else {
a.attr(‘title’, ‘给小站来点动力吧!’)
}
});
function slzanpd_(a) {
a.css(‘cursor’, ‘not-allowed’).attr(‘title’, ‘您已赞过本文!’);
}

cera cloudiplc tengxunyun

相关推荐