Вход на сайт
Моя золотая мечта 05.01.2025
1315 просмотров
Перейти к просмотру всей ветки
в ответ uscheswoi_82 05.01.25 02:18
А так чтобы поставить/удалить лайк:

Вот мой код:
wall.js:
const SET_LIKE = 'like.php';
function p_gll() // get_like_list
{
//<div class="tooltip">' . $str_users_likes . '</div>
}
function p_sl(postid, likeid, uid) // set_like
{
var timer1 = null;
var timer2 = null;
var persons_text = '';
$$.ajax(path + SET_LIKE, 'POST', 'cmd=1&type=like&lid=' + likeid + '&uid=' + uid, function(value)
{
$('post_like_' + postid).text(value);
$('post_like_' + postid).attr('onclick', 'p_usl(' + postid + ', ' + likeid + ');');
if(value != '' && value != null)
{
timer1 = setTimeout(function() {
$$.ajax(path + SET_LIKE, 'POST', 'cmd=3&lid=' + likeid, function(persons)
{
persons_text = persons;
});
}, 100);
timer2 = setTimeout(function() {
$$.ajax(path + SET_LIKE, 'POST', 'cmd=2&lid=' + likeid, function(count)
{
if(persons_text == '')
$('like_counter_' + postid).text(count);
else
$('like_counter_' + postid).text('<div class="tooltip_likes">' + persons_text + '</div>' + count);
});
}, 200);
}
});
clearTimeout(timer1);
clearTimeout(timer2);
}
function p_usl(postid, likeid, uid) // un_set_like
{
var timer1 = null;
var timer2 = null;
var persons_text = '';
$$.ajax(path + SET_LIKE, 'POST', 'cmd=1&type=unlike&lid=' + likeid, function(value)
{
$('post_like_' + postid).text(value);
$('post_like_' + postid).attr('onclick', 'p_sl(' + postid + ', ' + likeid + ',' + uid +');');
timer1 = setTimeout(function() {
$$.ajax(path + SET_LIKE, 'POST', 'cmd=3&lid=' + likeid, function(persons)
{
persons_text = persons;
});
}, 100);
timer2 = setTimeout(function() {
$$.ajax(path + SET_LIKE, 'POST', 'cmd=2&lid=' + likeid, function(count)
{
if(persons_text == '')
$('like_counter_' + postid).text(count);
else
$('like_counter_' + postid).text('<div class="tooltip_likes">' + persons_text + '</div>' + count);
});
}, 100);
});
clearTimeout(timer1);
clearTimeout(timer2);
}
like.php:
<?php
require_once('./config/config.php');
require_once('./libs/core/mod_core.php');
require_once('./libs/core/mod_database.php');
require_once('./libs/core/mod_like.php');
require_once('./libs/core/mod_notifications.php');
require_once('./libs/i18n/mod_i18n.php');
session_start();
if(!isset($_SESSION['UserID']))
exit;
if(!isset($_POST['cmd']))
exit;
$int_cmd = $_POST['cmd'];
if(core_is_logged_in())
{
if($int_cmd == 1)
{
I18n_init();
I18n_lang('./i18n/' . core_get_current_language() . '_like.php', './i18n/en_like.php');
if($_POST['type'] == 'like')
{
like_set_like($_POST['lid'], $_SESSION['UserID'], 1);
if($_SESSION['UserID'] != $_POST['uid'])
{
$str_now = date("y-m-d H:i:s");
notifications_add_notification($_SESSION['UserID'], $_POST['uid'], NOTIFICATION_LIKE, $str_now, $_POST['lid']);
}
echo __('unlike');
}
if($_POST['type'] == 'unlike')
{
like_set_like($_POST['lid'], $_SESSION['UserID'], 0);
echo __('like');
}
return ;
}
if($int_cmd == 2)
{
$int_likes_count = like_get_like_count($_POST['lid']);
if($int_likes_count <= 1)
echo sprintf(__choice(__('likes'), 0), $int_likes_count);
else if($int_likes_count > 1)
echo sprintf(__choice(__('likes'), 1), $int_likes_count);
exit;
}
if($int_cmd == 3)
{
$int_like_count = like_get_like_count($_POST['lid']);
$arr_users_likes = like_get_like_users($_POST['lid'], 0, 5);
foreach($arr_users_likes as $arr_user_like)
{
echo $arr_user_like['flname'];
echo '<br />';
}
if($int_like_count > 5)
{
$int_other_count = $int_like_count - 5;
if($int_other_count == 1)
echo sprintf(__(__choice('other', 0)), $int_other_count);
elseif($int_other_count > 1)
echo sprintf(__(__choice('other', 1)), $int_other_count);
}
}
}
?>Если я кому-то отвечаю, это не значит что я ему симпатизирую, каждый остаётся при своём мнении
Моя ФЛ Он и Она
Моя ФЛ Он и Она