1. Добавляем в function/function.php код выделенный зеленым


Цитата
if (file_exists("config/config_function.php")) require_once("config/config_function.php");
require_once("function/filters.php");
require_once("function/sources.php");


# Format ajax rating
function ajax_rating($typ, $id, $mod, $rat, $scor)
{
include('config/config_ratings.php');
$con = explode('|', $confra[$mod]);
if (($con[1] and $id and $mod) or ($rat and $scor))
{
$content = ($typ or (empty($typ) and empty($con[2]))) ? '<script type="text/javascript">ajax(\'ajax.php?go=1&op=rating&mod='.$mod.'&id='.$id.'\', \'rate'.$id.'\');</script><div class="rate" id="rate'.$id.'"></div>' : '<div class="rate">'.vote_graphic_ajax($rat, $scor).'</div>';
return $content;
}
}


# Get IP
function getip() {
if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) {
$ip = getenv("REMOTE_ADDR");
} elseif (!empty($_SERVER['REMOTE_ADDR']) && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown")) {
$ip = $_SERVER['REMOTE_ADDR'];
} else {
$ip = "unknown";
}
return $ip;
}

# Analyze a variable
function analyze($var) {
$var = (preg_match("#[^a-zA-Z0-9_]#", $var)) ? "" : $var;
return $var;
}

# Format rating
function rating() {
global $db, $prefix, $user;
include("config/config_ratings.php");
$id = (isset($_GET['id'])) ? intval($_GET['id']) : "";
$mod = (preg_match("/[^a-zA-Z0-9_]/", $_GET['mod'])) ? "" : $_GET['mod'];
$rating = (isset($_GET['rating'])) ? intval($_GET['rating']) : 0;
$con = explode("|", $confra[$mod]);
if ($id && $mod) {
if ($mod == "Account") {
$query = "user_votes, user_totalvotes FROM ".$prefix."_users WHERE user_id='$id'";
} elseif ($mod == "Faq") {
$query = "ratings, score FROM ".$prefix."_faq WHERE fid='$id'";
} elseif ($mod == "Files") {
$query = "votes, totalvotes FROM ".$prefix."_files WHERE lid='$id'";
} elseif ($mod == "Jokes") {
$query = "ratingtot, rating FROM ".$prefix."_jokes WHERE jokeid='$id'";
} elseif ($mod == "Links") {
$query = "votes, totalvotes FROM ".$prefix."_links WHERE lid='$id'";
} elseif ($mod == "Media") {
$query = "votes, totalvotes FROM ".$prefix."_media WHERE id='$id'";
} elseif ($mod == "News") {
$query = "ratings, score FROM ".$prefix."_stories WHERE sid='$id'";
} elseif ($mod == "Pages") {
$query = "ratings, score FROM ".$prefix."_page WHERE pid='$id'";
} elseif ($mod == "Shop") {
$query = "product_votes, product_totalvotes FROM ".$prefix."_products WHERE product_id='$id'";
}
$ip = getip();
$past = time() - intval($con[0]);
$cookies = (intval($_COOKIE[''.substr($mod, 0, 2).'-'.$id.''])) ? $_COOKIE[''.substr($mod, 0, 2).'-'.$id.''] : "";
$postname = (is_user()) ? text_filter(substr($user[1], 0, 25)) : "";
$db->sql_query("DELETE FROM ".$prefix."_rating WHERE time<'$past' AND modul='$mod'");
list($num) = $db->sql_fetchrow($db->sql_query("SELECT Count(id) FROM ".$prefix."_rating WHERE (mid='$id' AND host='$ip') OR (mid='$id' AND name='$postname' AND name!='')"));
if ($cookies == $id || $num > 0) {
list($votes, $totalvotes) = $db->sql_fetchrow($db->sql_query("SELECT ".$query.""));
echo "".vote_graphic_ajax($votes, $totalvotes)."";
} elseif (!$cookies && !$num && !$rating) {
list($votes, $totalvotes) = $db->sql_fetchrow($db->sql_query("SELECT ".$query.""));
$votes = (intval($votes)) ? $votes : 1;
$width = number_format($totalvotes/$votes, 2) * 17;
echo "<ul class=\"urating\">"
."<li class=\"crating\" style=\"width:".$width."px;\"></li>"
."<li><div class=\"out1\" OnMouseOver=\"this.className='over1';\" OnMouseOut=\"this.className='out1';\" OnClick=\"ajax('ajax.php?go=1&op=rating&mod=$mod&id=$id&rating=1', 'rate".$id."');\" title=\""._RATE1."\"></div></li>"
."<li><div class=\"out2\" OnMouseOver=\"this.className='over2';\" OnMouseOut=\"this.className='out2';\" OnClick=\"ajax('ajax.php?go=1&op=rating&mod=$mod&id=$id&rating=2', 'rate".$id."');\" title=\""._RATE2."\"></div></li>"
."<li><div class=\"out3\" OnMouseOver=\"this.className='over3';\" OnMouseOut=\"this.className='out3';\" OnClick=\"ajax('ajax.php?go=1&op=rating&mod=$mod&id=$id&rating=3', 'rate".$id."');\" title=\""._RATE3."\"></div></li>"
."<li><div class=\"out4\" OnMouseOver=\"this.className='over4';\" OnMouseOut=\"this.className='out4';\" OnClick=\"ajax('ajax.php?go=1&op=rating&mod=$mod&id=$id&rating=4', 'rate".$id."');\" title=\""._RATE4."\"></div></li>"
."<li><div class=\"out5\" OnMouseOver=\"this.className='over5';\" OnMouseOut=\"this.className='out5';\" OnClick=\"ajax('ajax.php?go=1&op=rating&mod=$mod&id=$id&rating=5', 'rate".$id."');\" title=\""._RATE5."\"></div></li>"
."</ul>";
} elseif (!$cookies && !$num && $rating) {
setcookie("".substr($mod, 0, 2)."-".$id."", $id, time() + intval($con[0]));
$new = time();
$db->sql_query("INSERT INTO ".$prefix."_rating VALUES (NULL, '$id', '$mod', '$new', '$postname', '$ip')");
if ($mod == "Account" || $mod == "Members") {
$db->sql_query("UPDATE ".$prefix."_users SET user_votes=user_votes+1, user_totalvotes=user_totalvotes+$rating WHERE user_id='$id'");
update_points(2);
} elseif ($mod == "Faq") {
$db->sql_query("UPDATE ".$prefix."_faq SET score=score+$rating, ratings=ratings+1 WHERE fid='$id'");
update_points(8);
} elseif ($mod == "Files") {
$db->sql_query("UPDATE ".$prefix."_files SET votes=votes+1, totalvotes=totalvotes+$rating WHERE lid='$id'");
update_points(12);
} elseif ($mod == "Forum") {
#$db->sql_query("UPDATE ".$prefix."_files SET votes=votes+1, totalvotes=totalvotes+$rating WHERE lid='$id'");
update_points(15);
} elseif ($mod == "Gallery") {
#$db->sql_query("UPDATE ".$prefix."_files SET votes=votes+1, totalvotes=totalvotes+$rating WHERE lid='$id'");
update_points(18);
} elseif ($mod == "Jokes") {
$db->sql_query("UPDATE ".$prefix."_jokes SET rating=rating+$rating, ratingtot=ratingtot+1 WHERE jokeid='$id'");
update_points(20);
} elseif ($mod == "Links") {
$db->sql_query("UPDATE ".$prefix."_links SET votes=votes+1, totalvotes=totalvotes+$rating WHERE lid='$id'");
update_points(24);
} elseif ($mod == "Media") {
$db->sql_query("UPDATE ".$prefix."_media SET votes=votes+1, totalvotes=totalvotes+$rating WHERE id='$id'");
update_points(27);
} elseif ($mod == "Multimedia") {
#$db->sql_query("UPDATE ".$prefix."_media SET votes=votes+1, totalvotes=totalvotes+$rating WHERE id='$id'");
update_points(30);
} elseif ($mod == "News") {
$db->sql_query("UPDATE ".$prefix."_stories SET score=score+$rating, ratings=ratings+1 WHERE sid='$id'");
update_points(33);
} elseif ($mod == "Pages") {
$db->sql_query("UPDATE ".$prefix."_page SET score=score+$rating, ratings=ratings+1 WHERE pid='$id'");
update_points(37);
} elseif ($mod == "Shop") {
$db->sql_query("UPDATE ".$prefix."_products SET product_votes=product_votes+1, product_totalvotes=product_totalvotes+$rating WHERE product_id='$id'");
update_points(41);
}
list($votes, $totalvotes) = $db->sql_fetchrow($db->sql_query("SELECT ".$query.""));
echo "".vote_graphic_ajax($votes, $totalvotes)."";
}
}
}


# Format vote graphic
function vote_graphic_ajax($votes, $total)
{
$votes = intval($votes)>0 ? $votes : 1;
$width = number_format($total / $votes, 2) * 17;
$result = substr($total / $votes, 0, 4);
$title = (intval($votes)>0 and intval($total)>0) ? 'title="Рейтинг: '.$result.'/'.$votes.' "Голосов": '.$result.'"' : 'title="Рейтинг: 0/0 Голосов: 0"';
$content ='<font style="display: none;">'.$result.'</font><ul class="urating" '.$title.'><li class="crating" style="width: '.$width.'px;"></li></ul>';
return $content;
}


2. Копируем файлы и папки (см. прикреплённый архив), соблюдая вложенность:
Цитата
- ajax.php
- /ajax/global_func.js
- config/config_ratings.php
- rating.gif ==> templates/ВашаТема/images/rating.gif
- function/no-cache.php


3. SQL-запрос:

Цитата
CREATE TABLE `slaed_rating` (
`id` int( 11 ) NOT NULL AUTO_INCREMENT ,
`mid` int( 11 ) NOT NULL default '0',
`modul` varchar( 50 ) NOT NULL default '',
`time` varchar( 14 ) NOT NULL default '',
`name` varchar( 25 ) NOT NULL default '',
`host` varchar( 60 ) default NULL ,
PRIMARY KEY ( `id` ) ,
KEY `mid` ( `mid` ) ,
KEY `modul` ( `modul` )
) ENGINE = MYISAM DEFAULT CHARSET = cp1251 AUTO_INCREMENT =1;


4.
Добавляем стили для рейтинга templates/ВашаТема/style.css:

Цитата
/*RATING*/
.rate {
float: left;
padding: 2px 5px 0 0;
}

.urating {
list-style: none;
margin: 0px;
padding: 0px;
width: 85px;
height: 17px;
position: relative;
background: url(images/rating.gif) top left no-repeat;
}

.urating li {
text-indent: -90000px;
padding: 0px;
margin: 0px;
float: left;
}

.urating li div {
outline: none;
display: block;
width: 17px;
height: 17px;
text-decoration: none;
text-indent: -9000px;
z-index: 20;
position: absolute;
padding: 0px;
}

.urating div.out1 { left: 0px; }
.urating li div.over1 { background: url(images/rating.gif) left center; z-index: 2; left: 0px; width: 17px; cursor: pointer; }
.urating div.out2 { left: 17px; }
.urating li div.over2 { background: url(images/rating.gif) left center; z-index: 2; left: 0px; width: 34px; cursor: pointer; }
.urating div.out3 {left: 34px; }
.urating li div.over3 { background: url(images/rating.gif) left center; z-index: 2; left: 0px; width: 51px; cursor: pointer; }
.urating div.out4 {left: 51px; }
.urating li div.over4 { background: url(images/rating.gif) left center; z-index: 2; left: 0px; width: 68px; cursor: pointer; }
.urating div.out5 {left: 68px; }
.urating li div.over5 { background: url(images/rating.gif) left center; z-index: 2; left: 0px; width: 85px; cursor: pointer; }

.urating li.crating {
background: url(images/rating.gif) left bottom;
position: absolute;
height: 17px;
display: block;
text-indent: -9000px;
z-index: 1;
}


5. В config/config._header.php добавляем:

Цитата
echo '<script language="JavaScript" type="text/javascript" src="ajax/global_func.js"></script>';


6. Добавляем в function/sources.php

Цитата
include("function/no-cache.php");
$strhead .= "<meta name=\"resource-type\" content=\"document\">\n"
."<meta name=\"document-state\" content=\"dynamic\">\n"



7. Редактируем modules/News/index.php

Цитата

$act_ajax='1'; //---------1-Вкл/0-Выкл Ajax рейтинг

if ($act_ajax=='1') {
$arating = "".ajax_rating(0, $sid, $module_name, $ratings, $score)."";
echo "<center><font class=\"option\">"._RATEARTICLE."</font></center><br>"
."<table align=\"center\"><tr><td>"._AVERAGESCORE.": </td><td>$arating</td><td>"._VOTES.":</td><td>$ratings</td></tr></table>";
}
else {

echo "<center><font class=\"option\">"._RATEARTICLE."</font></center><br>"

."<table align=\"center\"><tr><td>"._AVERAGESCORE.": </td><td>".vote_graphic($ratings, $score)."</td><td>"._VOTES.":</td><td>$ratings</td></tr></table>"
."<hr><table width=\"100%\" align=\"center\" border=\"0\"><tr><td><form action=\"index.php?name=$module_name\" method=\"post\">"
."<input type=\"hidden\" name=\"sid\" value=\"$sid\">"
."<input type=\"hidden\" name=\"op\" value=\"ratearticle\">"
."<input type=\"radio\" name=\"score\" value=\"5\"> <img src=\"images/articles/stars-5.gif\" border=\"0\" alt=\""._EXCELLENT."\" title=\""._EXCELLENT."\"></td>"
."<td><input type=\"radio\" name=\"score\" value=\"4\"> <img src=\"images/articles/stars-4.gif\" border=\"0\" alt=\""._VERYGOOD."\" title=\""._VERYGOOD."\"></td>"
."<td><input type=\"radio\" name=\"score\" value=\"3\"> <img src=\"images/articles/stars-3.gif\" border=\"0\" alt=\""._GOOD."\" title=\""._GOOD."\"></td>"
."<td><input type=\"radio\" name=\"score\" value=\"2\"> <img src=\"images/articles/stars-2.gif\" border=\"0\" alt=\""._REGULAR."\" title=\""._REGULAR."\"></td>"
."<td><input type=\"radio\" name=\"score\" value=\"1\"> <img src=\"images/articles/stars-1.gif\" border=\"0\" alt=\""._BAD."\" title=\""._BAD."\"></td>"
."<td align=\"right\"><input type=\"submit\" value=\""._CASTMYVOTE."\"></td></tr></form></table>";

} //---ДОБАВЛЕНА СКОБКА!!!



P.S
Практически не тестировал, хотя вроде всё работает нормально...

Проверялось на:
2.2 Lite
2.4 Lite
Оригинал статьи: