16
Mods & Plugins (Requests & Discussions) / Re: [MOD REQ] Rate comments - good / bad
« on: January 08, 2009, 09:01:28 AM »
Hi all,
maybe you will like my mod for rating comments.
1. in the file details.php
find
add below
1.1 find line with
insert in
1.2 find
add below
2. in the file lang/your_lang/main.php
add before ?>
3. in the file comment_bit.html
use
4. Add new rows to existing table 4images_comment
5. new images
You will need 4 images with the names: good.png, bad.png, good_off.png, bad_off.png
save them in the folder template/your_template/images
PS: Only registered users allowed to vote
maybe you will like my mod for rating comments.
1. in the file details.php
find
Code: [Select]
unset($random_cat_image);
add below
Code: [Select]
if ($action == "comrate_good" && $id) {
if ($user_info['user_level'] != GUEST) {
$sql = "SELECT who_rated
FROM ".COMMENTS_TABLE."
WHERE comment_id = $id";
$row = $site_db->query_firstrow($sql);
$who_rated_ids = $row['who_rated'];
$who_rated_array = explode(" ", $who_rated_ids);
if (!in_array($user_info['user_id'], $who_rated_array)) {
$who_rated_ids .= " ".$user_info['user_id'];
$sql = "UPDATE ".COMMENTS_TABLE."
SET is_good = is_good+1, who_rated = '$who_rated_ids'
WHERE comment_id = $id";
if ($site_db->query($sql)) {
$msg = $lang['voting_com_success'];
}
else {
$msg = $lang['voting_error'];
}
}
}
else {
$msg = $lang['only_for_registered'];
}
}
if ($action == "comrate_bad" && $id) {
if ($user_info['user_level'] != GUEST) {
$sql = "SELECT who_rated
FROM ".COMMENTS_TABLE."
WHERE comment_id = $id";
$row = $site_db->query_firstrow($sql);
$who_rated_ids = $row['who_rated'];
$who_rated_array = explode(" ", $who_rated_ids);
if (!in_array($user_info['user_id'], $who_rated_array)) {
$who_rated_ids .= " ".$user_info['user_id'];
$sql = "UPDATE ".COMMENTS_TABLE."
SET is_bad = is_bad+1, who_rated = '$who_rated_ids'
WHERE comment_id = $id";
if ($site_db->query($sql)) {
$msg = $lang['voting_com_success'];
}
else {
$msg = $lang['voting_error'];
}
}
}
else {
$msg = $lang['only_for_registered'];
}
}
1.1 find line with
Code: [Select]
$sql = "SELECT c.comment_id, c.image_id, c.user_id, c.user_name AS comment_user_name,
insert in
Code: [Select]
c.is_good, c.is_bad, c.who_rated,
1.2 find
Code: [Select]
$admin_links = "";
if ($user_info['user_level'] == ADMIN) {
$admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("comments.php?action=editcomment&comment_id=".$comment_row[$i]['comment_id']))."\" target=\"_blank\">".$lang['edit']."</a> ";
$admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("comments.php?action=removecomment&comment_id=".$comment_row[$i]['comment_id']))."\" target=\"_blank\">".$lang['delete']."</a>";
}
elseif ($is_image_owner) {
$admin_links .= ($config['user_edit_comments'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=editcomment&".URL_COMMENT_ID."=".$comment_row[$i]['comment_id'])."\">".$lang['edit']."</a> ";
$admin_links .= ($config['user_delete_comments'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removecomment&".URL_COMMENT_ID."=".$comment_row[$i]['comment_id'])."\">".$lang['delete']."</a>";
}
add below
Code: [Select]
$comment_rank = "";
if ($user_info['user_level'] == GUEST){
$comrate_good = "<img src=\"".get_gallery_image("good_off.png")."\" border=\"0\" alt=\"\" title=\"".$lang['only_for_registered']."\" />";
$comrate_bad = "<img src=\"".get_gallery_image("bad_off.png")."\" border=\"0\" alt=\"\" title=\"".$lang['only_for_registered']."\" />";
}
elseif ($user_info['user_id'] == $comment_row[$i]['user_id']) {
$comrate_good = "<img src=\"".get_gallery_image("good_off.png")."\" border=\"0\" alt=\"\" title=\"".$lang['owner_vote']."\" />";
$comrate_bad = "<img src=\"".get_gallery_image("bad_off.png")."\" border=\"0\" alt=\"\" title=\"".$lang['owner_vote']."\" />";
}
else {
$comrate_url = $self_url;
$comrate_url .= (!empty($mode)) ? ((strpos($comrate_url, '?') !== false) ? "&" : "?")."mode=".$mode : "";
$comrate_url .= strpos($comrate_url, '?') !== false ? "&" : "?";
$who_rated_array = explode(" ", $comment_row[$i]['who_rated']);
if (!in_array($user_info['user_id'], $who_rated_array)) {
$comrate_good_url = $comrate_url."action=comrate_good&id=".$comment_row[$i]['comment_id'];
$comrate_bad_url = $comrate_url."action=comrate_bad&id=".$comment_row[$i]['comment_id'];
$comrate_good = "<a href=\"".$site_sess->url($comrate_good_url)."\"><img src=\"".get_gallery_image("good.png")."\" border=\"0\" alt=\"\" title=\"".$lang['is_good']."\" /></a>";
$comrate_bad = "<a href=\"".$site_sess->url($comrate_bad_url)."\"><img src=\"".get_gallery_image("bad.png")."\" border=\"0\" alt=\"\" title=\"".$lang['is_bad']."\" /></a>";
}
else {
$comrate_good = "<img src=\"".get_gallery_image("good_off.png")."\" border=\"0\" alt=\"\" title=\"".$lang['already_com_voted']."\" />";
$comrate_bad = "<img src=\"".get_gallery_image("bad_off.png")."\" border=\"0\" alt=\"\" title=\"".$lang['already_com_voted']."\" />";
}
}
$comment_rank .= "+".$comment_row[$i]['is_good']." ".$comrate_good." ".$comrate_bad." ".$comment_row[$i]['is_bad']."-";
$site_template->register_vars("comment_rank", $comment_rank);
2. in the file lang/your_lang/main.php
add before ?>
Code: [Select]
$lang['voting_com_success'] = "Thank you for rating this comment";
$lang['already_com_voted'] = "Sorry, you've already rated for this comment once recently.";
$lang['only_for_registered'] = "Only registered users can use this function";
$lang['is_good'] = "It is good comment";
$lang['is_bad'] = "It is bad comment";
$lang['owner_vote'] = "You can not rate your own comment";
3. in the file comment_bit.html
use
Code: [Select]
{comment_rank}
4. Add new rows to existing table 4images_comment
Code: [Select]
ALTER TABLE `4images_comments`
ADD `is_good` int(10) unsigned NOT NULL default '0',
ADD `is_bad` int(10) unsigned NOT NULL default '0',
ADD `who_rated` text
5. new images
You will need 4 images with the names: good.png, bad.png, good_off.png, bad_off.png
save them in the folder template/your_template/images
PS: Only registered users allowed to vote