Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so dont bother with any of their useless mail servers here and just use oauth login instead. Thank the nice Russians for causing that. :)
Paste
Pasted as PHP by registered user atmaca ( 5 months ago )
<?php
// Forumtutkusu mesaj tepki sistemi
define('THIS_SCRIPT', 'ft_react');
require_once('./global.php');
header('Content-Type: application/json; charset=utf-8');
global $vbulletin;
// -------------------------
// Giriş kontrolü
// -------------------------
if (empty($vbulletin->userinfo['userid']))
{
echo json_encode(array(
'success' => false,
'error' => 'not_logged_in',
));
exit;
}
// -------------------------
// Parametreleri al
// -------------------------
$vbulletin->input->clean_array_gpc('p', array(
'type' => TYPE_STR, // şimdilik 'post'
'postid' => TYPE_UINT,
'reactionid' => TYPE_INT, // 0 = tepkiyi kaldır
));
$type = $vbulletin->GPC['type'];
$postid = intval($vbulletin->GPC['postid']);
$reactionid = intval($vbulletin->GPC['reactionid']); // 0 olabilir
$userid = intval($vbulletin->userinfo['userid']);
$username = $vbulletin->userinfo['username'];
if (!$postid)
{
echo json_encode(array(
'success' => false,
'error' => 'invalid_post',
));
exit;
}
$valid_reactions = array(1,2,3,4,5,6,7);
if ($reactionid < 0 || ($reactionid > 0 && !in_array($reactionid, $valid_reactions)))
{
echo json_encode(array(
'success' => false,
'error' => 'invalid_reaction',
));
exit;
}
// -------------------------
//Mesaj sahibini bul
// -------------------------
$post = $vbulletin->db->query_first("
SELECT userid, threadid
FROM " . TABLE_PREFIX . "post
WHERE postid = $postid
LIMIT 1
");
if (!$post)
{
echo json_encode(array(
'success' => false,
'error' => 'post_not_found',
));
exit;
}
$dest_userid = intval($post['userid']);
$threadid = intval($post['threadid']);
// Kendi mesajına tepki verilmesin
if ($userid && $dest_userid == $userid)
{
echo json_encode(array(
'success' => false,
'error' => 'own_post',
));
exit;
}
$now = TIMENOW;
// -------------------------
// Bu kullanıcı bu mesaja daha önce tepki vermiş mi?
// -------------------------
$existing = $vbulletin->db->query_first("
SELECT *
FROM vbseo_likes
WHERE l_contentid = $postid
AND l_ctype = 1
AND l_cgroup = 0
AND l_from_userid = $userid
LIMIT 1
");
$existing_reactionid = $existing ? intval($existing['reactionid']) : 0;
$action = 'none'; // add | update | remove | none
$new_reactionid = $existing_reactionid;
// -------------------------
//Veritabanı işlemleri
// -------------------------
if ($reactionid === 0)
{
if ($existing)
{
$vbulletin->db->query_write("
DELETE FROM vbseo_likes
WHERE l_contentid = $postid
AND l_ctype = 1
AND l_cgroup = 0
AND l_from_userid = $userid
");
$action = 'remove';
$new_reactionid = 0;
}
}
else
{
if ($existing && $existing_reactionid === $reactionid)
{
$vbulletin->db->query_write("
DELETE FROM vbseo_likes
WHERE l_contentid = $postid
AND l_ctype = 1
AND l_cgroup = 0
AND l_from_userid = $userid
");
$action = 'remove';
$new_reactionid = 0;
}
elseif ($existing)
{
$vbulletin->db->query_write("
UPDATE vbseo_likes
SET reactionid = $reactionid,
l_dateline = $now
WHERE l_contentid = $postid
AND l_ctype = 1
AND l_cgroup = 0
AND l_from_userid = $userid
");
$action = 'update';
$new_reactionid = $reactionid;
}
else
{
$vbulletin->db->query_write("
INSERT INTO vbseo_likes
(l_contentid, l_ctype, l_cgroup,
l_from_userid, l_from_username,
l_dest_userid, l_dateline, reactionid)
VALUES
($postid, 1, 0,
$userid, '" . $vbulletin->db->escape_string($username) . "',
$dest_userid, $now, $reactionid)
");
$action = 'add';
$new_reactionid = $reactionid;
}
}
if ($action === 'add' || $action === 'remove')
{
// Mesaj sahibi (beğeni alan kişi)
if ($dest_userid > 0)
{
if ($action === 'add')
{
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET vbseo_likes_in = vbseo_likes_in + 1,
vbseo_likes_unread = vbseo_likes_unread + 1
WHERE userid = $dest_userid
");
}
else
{
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET vbseo_likes_in = IF(vbseo_likes_in > 0, vbseo_likes_in - 1, 0),
vbseo_likes_unread = IF(vbseo_likes_unread > 0, vbseo_likes_unread - 1, 0)
WHERE userid = $dest_userid
");
}
}
if ($userid > 0)
{
if ($action === 'add')
{
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET vbseo_likes_out = vbseo_likes_out + 1
WHERE userid = $userid
");
}
else
{
$vbulletin->db->query_write("
UPDATE " . TABLE_PREFIX . "user
SET vbseo_likes_out = IF(vbseo_likes_out > 0, vbseo_likes_out - 1, 0)
WHERE userid = $userid
");
}
}
}
// -------------------------
// JSON yanıtı
// -------------------------
echo json_encode(array(
'success' => true,
'removed' => ($new_reactionid === 0 ? true : false),
'user_reactionid' => intval($new_reactionid),
));
exit;
Revise this Paste