Файл: adultscript-2.0.3-pro/files/mobile/templates/default/extend/ajax/channel_like.plugin.php
Строк: 81
<?php
defined('_VALID') or die('Restricted Access!');
function ajax_plugin_channel_like()
{
$data = array('status' => 0, 'coode' => '', 'msg' => '');
VLanguage::load('frontend.channel');
if (isset($_POST['channel_id'])) {
$user_id = (VAuth::loggedin()) ? (int) $_SESSION['user_id'] : 0;
$type = VF::cfg_item('module.channel.rating_type');
if ($type == 'user' && !$user_id) {
$data['msg'] = __('rating-login');
return json_encode($data);
}
$channel_id = (int) trim($_POST['channel_id']);
$ip = VServer::ip(true);
$db = VF::factory('database');
if (VF::cfg_item('module.channel.rating_count') == '1') {
if ($type == 'user') {
$sql = "SELECT rating_id
FROM #__channel_rating
WHERE channel_id = ".$channel_id."
AND voter_id = ".$user_id."
LIMIT 1";
} else {
$sql = "SELECT rating_id
FROM #__channel_rating
WHERE channel_id = ".$channel_id."
AND voter_ip = ".$ip."
LIMIT 1";
}
$db->query($sql);
if ($db->affected_rows()) {
$data['msg'] = __('rating-already');
return json_encode($data);
}
}
$db->query("SELECT total_likes, total_votes
FROM #__channel
WHERE channel_id = ".$channel_id."
LIMIT 1");
if ($db->affected_rows()) {
$total_likes = (int) $db->fetch_field('total_likes');
$total_votes = (int) $db->fetch_field('total_votes');
$db->query("UPDATE #__channel
SET total_likes = total_likes+1,
total_votes = total_votes+1
WHERE channel_id = ".$channel_id."
LIMIT 1");
$db->query("INSERT INTO #__channel_rating
SET channel_id = ".$channel_id.",
voter_id = ".$user_id.",
voter_ip = ".$ip.",
rating = 5,
add_time = ".time());
$data['code'] = $total_likes+1;
$data['status'] = 1;
$data['msg'] = __('liked');
} else {
$data['msg'] = __('channel-invalid');;
}
}
return json_encode($data);
}
?>