Начнём 1 база:
CREATE TABLE IF NOT EXISTS `karma` ( `id` int(10) unsigned NOT NULL auto_increment, `type` enum('torrent','comment','user','humor') default 'torrent', `user` int(10) unsigned NOT NULL, `value` int(10) unsigned NOT NULL, `added` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id`), UNIQUE KEY `type` (`type`,`user`,`value`) ) ENGINE=MyISAM DEFAULT CHARSET=cp1251 AUTO_INCREMENT=857 ; ALTER TABLE `users` ADD karma int(11) default '0'; ALTER TABLE `torrents` ADD karma int(11) default '0'; ALTER TABLE `comments` ADD karma int(11) default '0';
2. в детаилс
ПОСЛЕ
echo "<tr><td align=\"right\"><b>Просматривают это сейчас</b></td><td align=\"left\"> <span align=\"center\" id=\"details_online\">Загрузка кто смотрит данный торрент</span> </td></tr>";
ВСТАВИТЬ
?> <script language="javascript" type="text/javascript" src="js/bubble.js"></script> <script language="JavaScript" type="text/javascript"> function karma(id,type,act) { jQuery.post("karma.php",{"id":id,"act":act,"type":type},function (response) { jQuery("#karma").empty(); jQuery("#karma").append(response); }); setTimeout("kcount();"); setTimeout("kavat();"); } function kcount(id,type,act) { jQuery.post("like.php" , {"id":"<?=$row['id']?>","action":"kcount","type":"torrents"} , function(response) { jQuery("#like").empty(); jQuery("#like").append(response); }); } kcount(); function kavat(id,type,act) { jQuery.post("like.php" , {"id":"<?=$row['id']?>","action":"kavat","type":"torrents"} , function(response) { jQuery("#avatars").empty(); jQuery("#avatars").append(response); }); } kavat(); </script> <? if ($row["canrate"] > 0) { echo("<tr><td align=\"right\"><b>Лайк</b></td><td align=\"left\"> <div class=\"bubbleInfo\"><div class=\"trigger\"> <div id=\"karma\"><div onclick=\"javascript: karma('$row[id]','torrent','minus');\" class=\"karma\" style=\"color:#2c78ea;\"><span style=\"line-height:8px;vertical-align:middle;float:left;\">мне нравиться</span><img src=\"pic/likes.png\" style=\"padding-left:5px;cursor:pointer;\"/><span style=\"font-weight:bold;position:absolute;padding-left:3px;line-height:8px;\">$row[karma]</span></div></div> </div><div class=\"popup\">Понравилось <span id=\"like\"></span><hr><span id=\"avatars\"></span> </div></div></td></tr>\n"); } else { echo("<tr><td align=\"right\"><b>Лайк</b></td><td align=\"left\"> <div class=\"bubbleInfo\"><div class=\"trigger\"> <div id=\"karma\"><div onclick=\"javascript: karma('$row[id]','torrent','plus');\" class=\"karma\"><span style=\"line-height:8px;vertical-align:middle;float:left;\">мне нравиться</span><img src=\"pic/like.png\" style=\"padding-left:5px;cursor:pointer;\"/><span style=\"position:absolute;padding-left:3px;line-height:8px;\">$row[karma]</span></div></div> </div><div class=\"popup\">Понравилось <span id=\"like\"></span><hr><span id=\"avatars\"></span> </div></div></td></tr>\n"); }
3. в CSS вставить :
.karma{ color:grey; height:10px; width:auto; padding: 5px 5px 5px 5px; cursor:pointer; } .karma:hover{ color:#000000; height:10px; width:auto; border:1px solid #d3e8fe; border-radius:5; background-color: #d3e8fe; padding: 5px 5px 5px 5px; cursor:pointer; } .bubbleInfo { width:15%; position: relative; } .popup { padding: 3px 5px 0px 5px; font-weight:bold; color:#FFFFFF; position: absolute; z-index: 50; display: none; border: 1px solid #000000; border-radius:5px; opacity:0.50; }
Скриншот:
Это в js bubble.js:
$(function () {
$('.bubbleInfo').each(function () {
// options
var distance = 10;
var time = 250;
var hideDelay = 200;var hideDelayTimer = null;
// tracker
var beingShown = false;
var shown = false;
var trigger = $('.trigger', this);
var popup = $('.popup', this).css('opacity', 0);// set the mouseover and mouseout on both element
$([trigger.get(0), popup.get(0)]).mouseover(function () {
// stops the hide event if we move from the trigger to the popup element
if (hideDelayTimer) clearTimeout(hideDelayTimer);// don't trigger the animation again if we're being shown, or already visible
if (beingShown || shown) {
return;
} else {
beingShown = true;// reset position of popup box
popup.css({
top: -85,
left: -20,
background: 'black',
width:210,
display: 'block' // brings the popup back in to view
})// (we're using chaining on the popup) now animate it's opacity and position
.animate({
top: '-=' + distance + 'px',
opacity: 1
}, time, 'swing', function() {
// once the animation is complete, set the tracker variables
beingShown = false;
shown = true;
});
}
}).mouseout(function () {
// reset the timer if we get fired again - avoids double animations
if (hideDelayTimer) clearTimeout(hideDelayTimer);
// store the timer so that it can be cleared in the mouseover if required
hideDelayTimer = setTimeout(function () {
hideDelayTimer = null;
popup.animate({
top: '-=' + distance + 'px',
opacity: 0
}, time, 'swing', function () {
// once the animate is complete, set the tracker variables
shown = false;
// hide the popup entirely after the effect (opacity alone doesn't do the job)
popup.css('display', 'none');
});
}, hideDelay);
});
});
});
Эти файлы в корень:
<?php
require_once("include/bittorrent.php");
dbconn();
header ("Content-Type: text/html; charset=" . $tracker_lang['language_charset']);if ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' && $_SERVER["REQUEST_METHOD"] == 'POST')
{
$id = (int)$_POST['id'];
$user = (int)$CURUSER['id'];
$act = (string)$_POST["act"];
$type = (string)$_POST["type"];if (empty($id) || empty($user) || empty($act) || empty($type))
die("Прямой доступ закрыт");if (!in_array($type, array("torrent", "comment", "user", "humor")))
die("Прямой доступ закрыт");
if ($type == "torrent")
$table = "torrents";
elseif ($type == "comment")
$table = "comments";
elseif ($type == "humor")
$table = "humor";
else
$table = "users";if ($act == 'plus')
{
sql_query("UPDATE $table SET karma = karma + 1 WHERE id = ".sqlesc($id)."");
sql_query("INSERT INTO karma (type, value, user, added) VALUES (" . sqlesc($type) . ", ".sqlesc($id).", ".sqlesc($user).", " . time() . ")");
if ($table=="humor"){
sql_query("UPDATE users SET uploaded=uploaded+26214400 WHERE uploaded / downloaded >= 1 AND id=(SELECT uid FROM humor WHERE id=".sqlesc($id).")") or sqlerr(__FILE__,__LINE__);
}
$font = "font-weight:bold";
$color = "color:#2c78ea";
$actb = "minus";
$img = "likes";
$show = true;
}
elseif ($act == 'minus')
{
sql_query("UPDATE $table SET karma = karma - 1 WHERE id = ".sqlesc($id)."");
sql_query("DELETE FROM karma WHERE type = ".sqlesc($type)." AND user = ".sqlesc($user)." AND value = ".sqlesc($id)."") or sqlerr(__FILE__,__LINE__);;
if ($table=="humor"){
sql_query("UPDATE users SET uploaded=uploaded-13107200 WHERE uploaded / downloaded >= 1 AND id=(SELECT uid FROM humor WHERE id=".sqlesc($id).")") or sqlerr(__FILE__,__LINE__);
}
$actb = "plus";
$img = "like";
$show = true;
}
else
die("Прямой доступ закрыт");if ($show)
{
$res = sql_query("SELECT karma FROM $table WHERE id = ".sqlesc($id)."");
$row = mysql_fetch_array($res);
die("<div onclick=\"javascript: karma('$id','$type','$actb');\" class=\"karma\" style=\"$color;\"><span style=\"line-height:8px;vertical-align:middle;float:left;\">мне нравиться</span><img src=\"pic/$img.png\" style=\"padding-left:5px;cursor:pointer;\"/><span style=\"$font;position:absolute;padding-left:3px;line-height:8px;\">$row[karma]</span></div>");
}}
else
die("Прямой доступ закрыт");?>
<?
require_once 'include/bittorrent.php';
header ("Content-Type: text/html; charset=windows-1251");
dbconn (false, true);if ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
$id = (int)$_POST['id'];
$action = (string) $_POST["action"];
$table = (string)$_POST["type"];if (empty($id) || empty($action) || empty($table))
die("Прямой доступ закрыт");
if ($action == "kcount"){
$res = sql_query("SELECT karma FROM $table WHERE id = ".sqlesc($id)."");
$row = mysql_fetch_array($res);
if ($row[karma] == 1)
$people = "человеку:";
else
$people = "людям:";
echo "$row[karma] $people";
}if ($action == "kavat"){
$karm = sql_query("SELECT * FROM karma AS k LEFT JOIN $table AS t ON k.value = t.id JOIN users AS u ON k.user = u.id WHERE t.id=" .sqlesc($id) . " ORDER by k.added DESC limit 0,4") or sqlerr(__FILE__,__LINE__);
while ($arr = mysql_fetch_array($karm)) {
if ($arr["avatar"])
$avatar = "src=\"pic/avatar/$arr[avatar]\"";
else
$avatar = "src=\"pic/avatar/default_avatar.gif\"";
echo "<a href=\"userdetails.php?id=$arr[id]\"><img width=\"50\" height=\"50\" $avatar title=\"$arr[username]\"></a> ";}
}
}
?>