EMlog非插件实现点赞功能

emlog教程 2020-08-25

  你的模版/module.php增加如下代码 别放错了哦

  点赞

  function syzan(){

  $DB = MySql::getInstance();

  if($DB->num_rows($DB->query(“show columns from “.DB_PREFIX.”blog like ‘slzan'”)) == 0){

  $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];}

  ?>

  你的模板公用的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’, ‘您已赞过本文!’);

  }

  你的模板公用的css 放点赞的css特效代码

  .shareBox {

  width: 130px;

  height: 40px;

  line-height: 40px;

  border: 1px solid #F74840;

  text-align: center;

  margin: 0 2px;

  color: #F74840;

  font-size: 14px;

  }

  点赞的输出按钮放在你要显示的地方就行了

  

评论 (0)
    Top