So, i have written a little addition for this MOD.
Description: With this addition you will have a possible to show something like this "Most Popular Photographer" on your main page.
Files to edit:
page_header.php
member_rating.php
includes/functions.php
lang/.../mail.php
home.html
Installation:
1) If you haven`t installed this mod, skip this step and go to 2 step.
In your PhpMyAdmin select table 4images_users_rating and search for user_id field.
Rename:
user_id
to user_ids
2) In includes/functions.php search:
if (!function_exists('member_rating_check_table')) {
function member_rating_check_table() {
global $site_db, $table_prefix;
if (defined('MEMBER_RATING_ACTIVE') && MEMBER_RATING_ACTIVE == 0) {
return;
}
if (!defined('USERS_RATING_TABLE')) {
define('USERS_RATING_TABLE', $table_prefix . 'users_rating');
}
$sql = "
CREATE TABLE IF NOT EXISTS " . USERS_RATING_TABLE . " (
field_id int(11) unsigned NOT NULL AUTO_INCREMENT,
user_id int(11) NOT NULL DEFAULT '0',
other_user_id int(11) NOT NULL DEFAULT '0',
rating_date int(11) NOT NULL DEFAULT '0',
rating_value int(2) NOT NULL DEFAULT '0',
rating_count int(11) NOT NULL DEFAULT '0',
PRIMARY KEY(field_id)
) TYPE=MyISAM;
";
$result = $site_db->query($sql);
}
}
if (!function_exists('member_rating_check_user')) {
function member_rating_check_user($user_id = 0, $other_user_id = 0, $user_level = GUEST) {
global $site_db, $table_prefix;
if (defined('MEMBER_RATING_ACTIVE') && MEMBER_RATING_ACTIVE == 0) {
return;
}
$user_id = preg_replace("/[^0-9]+/i", "", $user_id);
$other_user_id = preg_replace("/[^0-9]+/i", "", $other_user_id);
$user_level = preg_replace("/[^0-9]+/i", "", $user_level);
if (empty($user_id) || empty($other_user_id) || $user_level == GUEST || $user_level == USER_AWAITING) {
return;
}
if (!defined('USERS_RATING_TABLE')) {
define('USERS_RATING_TABLE', $table_prefix . 'users_rating');
}
$sql = "
SELECT SUM(ur.rating_value) AS total_rates
FROM " . USERS_RATING_TABLE . " ur
LEFT JOIN " . USERS_TABLE . " u ON (" . get_user_table_field("u.", "user_id") . " = ur.user_id)
WHERE " . get_user_table_field("u.", "user_id") . " = ur.user_id AND ur.user_id = " . $user_id . " AND ur.other_user_id = " . $other_user_id . " AND " . get_user_table_field("u.", "user_level") . " >= '" . USER . "'
";
$row = $site_db->query_firstrow($sql);
$total_rates = (isset($row['total_rates'])) ? number_format($row['total_rates'], MEMBER_RATING_DECIMAL_VALUE) : 0;
if (isset($total_rates) && $total_rates > 0) {
$sql = "
SELECT ur.rating_value
FROM " . USERS_RATING_TABLE . " ur
LEFT JOIN " . USERS_TABLE . " u ON (" . get_user_table_field("u.", "user_id") . " = ur.other_user_id)
WHERE " . get_user_table_field("u.", "user_id") . " = " . $other_user_id . " AND " . get_user_table_field("u.", "user_level") . " >= '" . USER . "'
";
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);
if (isset($num_rows) && $num_rows > 0) {
$rating_value = "";
while ($rate_row = $site_db->fetch_array($result)) {
$rating_value += $rate_row['rating_value'];
}
$calc_total_rates = ($rating_value / $num_rows);
$answer_total_rates = (isset($calc_total_rates)) ? number_format($calc_total_rates, MEMBER_RATING_DECIMAL_VALUE) : "";
return $answer_total_rates . "/" . MEMBER_RATING_MARK_VALUE;
} else {
return false;
}
}
}
}
if (!function_exists('member_rating_insert_rates')) {
function member_rating_insert_rates($user_id = 0, $other_user_id = 0, $user_level = GUEST, $user_rates = 0) {
global $site_db, $table_prefix;
if (defined('MEMBER_RATING_ACTIVE') && MEMBER_RATING_ACTIVE == 0) {
return;
}
$user_id = preg_replace("/[^0-9]+/i", "", $user_id);
$other_user_id = preg_replace("/[^0-9]+/i", "", $other_user_id);
$user_level = preg_replace("/[^0-9]+/i", "", $user_level);
$user_rates = preg_replace("/[^0-9]+/i", "", $user_rates);
if (empty($user_id) || empty($other_user_id) || $user_level == GUEST || $user_level == USER_AWAITING || empty($user_rates)) {
return;
}
if (!defined('USERS_RATING_TABLE')) {
define('USERS_RATING_TABLE', $table_prefix . 'users_rating');
}
$sql = "
INSERT INTO " . USERS_RATING_TABLE . "
(field_id, user_id, other_user_id, rating_date, rating_value, rating_count)
VALUES(NULL, '" . $user_id . "', '" . $other_user_id . "', '" . time() . "', '" . $user_rates . "', '1')
";
if ($site_db->query($sql)) {
return true;
} else {
return false;
}
}
}
Replace:
if (!function_exists('member_rating_check_table')) {
function member_rating_check_table() {
global $site_db, $table_prefix;
if (defined('MEMBER_RATING_ACTIVE') && MEMBER_RATING_ACTIVE == 0) {
return;
}
if (!defined('USERS_RATING_TABLE')) {
define('USERS_RATING_TABLE', $table_prefix . 'users_rating');
}
$sql = "
CREATE TABLE IF NOT EXISTS " . USERS_RATING_TABLE . " (
field_id int(11) unsigned NOT NULL AUTO_INCREMENT,
user_ids int(11) NOT NULL DEFAULT '0',
other_user_id int(11) NOT NULL DEFAULT '0',
rating_date int(11) NOT NULL DEFAULT '0',
rating_value int(2) NOT NULL DEFAULT '0',
rating_count int(11) NOT NULL DEFAULT '0',
PRIMARY KEY(field_id)
) TYPE=MyISAM;
";
$result = $site_db->query($sql);
}
}
if (!function_exists('member_rating_check_user')) {
function member_rating_check_user($user_id = 0, $other_user_id = 0, $user_level = GUEST) {
global $site_db, $table_prefix;
if (defined('MEMBER_RATING_ACTIVE') && MEMBER_RATING_ACTIVE == 0) {
return;
}
$user_id = preg_replace("/[^0-9]+/i", "", $user_id);
$other_user_id = preg_replace("/[^0-9]+/i", "", $other_user_id);
$user_level = preg_replace("/[^0-9]+/i", "", $user_level);
if (empty($user_id) || empty($other_user_id) || $user_level == GUEST || $user_level == USER_AWAITING) {
return;
}
if (!defined('USERS_RATING_TABLE')) {
define('USERS_RATING_TABLE', $table_prefix . 'users_rating');
}
$sql = "
SELECT SUM(ur.rating_value) AS total_rates
FROM " . USERS_RATING_TABLE . " ur
LEFT JOIN " . USERS_TABLE . " u ON (" . get_user_table_field("u.", "user_id") . " = ur.user_ids)
WHERE " . get_user_table_field("u.", "user_id") . " = ur.user_ids AND ur.user_ids = " . $user_id . " AND ur.other_user_id = " . $other_user_id . " AND " . get_user_table_field("u.", "user_level") . " >= '" . USER . "'
";
$row = $site_db->query_firstrow($sql);
$total_rates = (isset($row['total_rates'])) ? number_format($row['total_rates'], MEMBER_RATING_DECIMAL_VALUE) : 0;
if (isset($total_rates) && $total_rates > 0) {
$sql = "
SELECT ur.rating_value
FROM " . USERS_RATING_TABLE . " ur
LEFT JOIN " . USERS_TABLE . " u ON (" . get_user_table_field("u.", "user_id") . " = ur.other_user_id)
WHERE " . get_user_table_field("u.", "user_id") . " = " . $other_user_id . " AND " . get_user_table_field("u.", "user_level") . " >= '" . USER . "'
";
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);
if (isset($num_rows) && $num_rows > 0) {
$rating_value = "";
while ($rate_row = $site_db->fetch_array($result)) {
$rating_value += $rate_row['rating_value'];
}
$calc_total_rates = ($rating_value / $num_rows);
$answer_total_rates = (isset($calc_total_rates)) ? number_format($calc_total_rates, MEMBER_RATING_DECIMAL_VALUE) : "";
return $answer_total_rates . "/" . MEMBER_RATING_MARK_VALUE;
} else {
return false;
}
}
}
}
if (!function_exists('member_rating_insert_rates')) {
function member_rating_insert_rates($user_id = 0, $other_user_id = 0, $user_level = GUEST, $user_rates = 0) {
global $site_db, $table_prefix;
if (defined('MEMBER_RATING_ACTIVE') && MEMBER_RATING_ACTIVE == 0) {
return;
}
$user_id = preg_replace("/[^0-9]+/i", "", $user_id);
$other_user_id = preg_replace("/[^0-9]+/i", "", $other_user_id);
$user_level = preg_replace("/[^0-9]+/i", "", $user_level);
$user_rates = preg_replace("/[^0-9]+/i", "", $user_rates);
if (empty($user_id) || empty($other_user_id) || $user_level == GUEST || $user_level == USER_AWAITING || empty($user_rates)) {
return;
}
if (!defined('USERS_RATING_TABLE')) {
define('USERS_RATING_TABLE', $table_prefix . 'users_rating');
}
$sql = "
INSERT INTO " . USERS_RATING_TABLE . "
(field_id, user_ids, other_user_id, rating_date, rating_value, rating_count)
VALUES(NULL, '" . $user_id . "', '" . $other_user_id . "', '" . time() . "', '" . $user_rates . "', '1')
";
if ($site_db->query($sql)) {
return true;
} else {
return false;
}
}
}
3) In member_rating.php replace all path by this code:
<?php
$main_template = "member_rating";
define('ROOT_PATH', './');
include(ROOT_PATH . 'global.php');
require(ROOT_PATH . 'includes/sessions.php');
@include_once(ROOT_PATH . 'includes/page_header.php');
if ($user_info['user_level'] < USER) {
redirect($url);
}
if ($action == "") {
$action = "viewrating";
}
if ($action == "delete_rate") {
if (isset($HTTP_POST_VARS['delete_rate'])) {
$delete_rate = (isset($HTTP_POST_VARS['delete_rate'])) ? $HTTP_POST_VARS['delete_rate'] : $HTTP_GET_VARS['delete_rate'];
} else {
$delete_rate = "";
}
if (empty($delete_rate)) {
redirect("member_rating.php");
}
if (isset($delete_rate) && is_array($delete_rate) && !empty($delete_rate)) {
$field_id_implode = implode(", ", $delete_rate);
if (!defined('USERS_RATING_TABLE')) {
define('USERS_RATING_TABLE', $table_prefix . 'users_rating');
}
$result = $site_db->query("DELETE FROM " . USERS_RATING_TABLE . " WHERE field_id IN (" . $field_id_implode . ")");
if (isset($result) && $result) {
redirect("member_rating.php");
}
} else {
redirect("member_rating.php");
}
}
if ($action == "viewrating") {
if (!defined('USERS_RATING_TABLE')) {
define('USERS_RATING_TABLE', $table_prefix . 'users_rating');
}
if (isset($additional_user_fields) && is_array($additional_user_fields) && !empty($additional_user_fields)) {
$additional_sql = "";
foreach ($additional_user_fields as $key => $val) {
$additional_sql .= ", u." . $key;
}
}
$sql = "
SELECT ur.field_id, ur.user_ids, ur.rating_date, ur.rating_value" . get_user_table_field(", u.", "user_name") . $additional_sql . "
FROM " . USERS_RATING_TABLE . " ur
LEFT JOIN " . USERS_TABLE . " u ON (" . get_user_table_field("u.", "user_id") . " = ur.user_ids)
WHERE ur.other_user_id = " . $user_info['user_id'] . " AND " . get_user_table_field("u.", "user_level") . " >= '" . USER . "'
ORDER BY ur.rating_date DESC
";
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);
if (isset($num_rows) && $num_rows <= 0) {
$msg = $lang['member_rating_no_content'];
} elseif (isset($num_rows) && $num_rows > 0) {
$member_rating_content = "";
$calc_rating_value = "";
$bgcounter = 0;
while ($rate_row = $site_db->fetch_array($result)) {
$row_bg_number = ($bgcounter++ % 2 == 0) ? 1 : 2;
$field_id = $rate_row['field_id'];
$user_id = $rate_row['user_ids'];
$user_name = format_text(trim($rate_row[$user_table_fields['user_name']]), 2);
$user_url = $site_sess->url(ROOT_PATH . "member.php?action=showprofile&" . URL_USER_ID . "=" . $user_id);
$rating_date = format_date($config['date_format'] . ", " . $config['time_format'], $rate_row['rating_date']);
$rating_value = $rate_row['rating_value'];
$calc_rating_value += $rate_row['rating_value'];
$site_template->register_vars(array(
"field_id" => $field_id,
"user_id" => $user_id,
"user_name" => $user_name,
"user_url" => $user_url,
"rating_date" => $rating_date,
"rating_value" => $rating_value,
"counter" => $row_bg_number
));
if (isset($additional_user_fields) && is_array($additional_user_fields) && !empty($additional_user_fields)) {
$additional_field_array = array();
foreach ($additional_user_fields as $key => $val) {
$additional_field_array[$key] = (!empty($rate_row[$key])) ? format_text($rate_row[$key], 1) : REPLACE_EMPTY;
$additional_field_array['lang_'.$key] = $val[0];
}
if (!empty($additional_field_array)) {
$site_template->register_vars($additional_field_array);
}
}
$member_rating_content .= $site_template->parse_template("member_rating_content");
}
$calc_total_rates = (isset($calc_rating_value) && !empty($calc_rating_value)) ? ($calc_rating_value / $num_rows) : "";
$answer_total_rates = (isset($calc_total_rates)) ? number_format($calc_total_rates, MEMBER_RATING_DECIMAL_VALUE) : "";
}
}
$clickstream = "<a href=\"" . $site_sess->url(ROOT_PATH . "index.php") . "\">" . $lang['home'] . "</a>" . $config['category_separator'] . $lang['member_rating_title'];
$lang['delete'] = str_replace("[", "", $lang['delete']);
$lang['delete'] = str_replace("]", "", $lang['delete']);
$site_template->register_vars(array(
"clickstream" => trim($clickstream),
"msg" => trim($msg),
"lang_member_rating_title" => $lang['member_rating_title'],
"lang_member_rating_user_name" => $lang['member_rating_user_name'],
"lang_member_rating_date" => $lang['member_rating_date'],
"lang_member_rating_value" => $lang['member_rating_value'],
"lang_member_rating_total_rates" => $lang['member_rating_total_rates_title'],
"lang_member_rating_delete" => $lang['member_rating_delete'],
"lang_delete" => $lang['delete'],
"member_rating_content" => (isset($member_rating_content)) ? trim($member_rating_content) : "",
"rated_value" => (isset($answer_total_rates) && $answer_total_rates > 0 && defined('MEMBER_RATING_MARK_VALUE')) ? preg_replace("/" . $site_template->start . "answer_total_rates" . $site_template->end . "/siU", $answer_total_rates . "/" . MEMBER_RATING_MARK_VALUE, $lang['member_rating_rated_value']) : ""
));
$site_template->print_template($site_template->parse_template($main_template));
@include_once(ROOT_PATH . 'includes/page_footer.php');
?>
4) Open includes/page_header and before ?> add:
//-----------------------------------------------------
//--- MOST RATED USERS --------------------------------
//-----------------------------------------------------
$most_rated_user = "";
$sql = "SELECT `other_user_id`, SUM(`rating_value`) AS `vot_sum`, `user_name` AS `name`
FROM ".USERS_RATING_TABLE." AS `rating`, ".USERS_TABLE." AS `users`
WHERE `other_user_id` = `user_id`
GROUP BY `other_user_id` ORDER BY `vot_sum` DESC LIMIT 10";
$result = $site_db->query($sql);
$sum = (isset($row['vot_sum'])) ? $row['vot_sum'] : 0;
while ($row = $site_db->fetch_array($result)) {
$most_rated_user .= "<tr>";
$most_rated_user .= "<td width=\"180\" align=\"left\">";
$most_rated_user .= '<a href ="'.ROOT_PATH.'search.php?search_user='.$row['name'].'"><b>'.$row['name'].'</b></a>';
$most_rated_user .= "</td>";
$most_rated_user .= "<td width=\"70\" align=\"center\">";
$most_rated_user .= '<span class="smalltext"><b>'.$row['vot_sum'].'</b></span>';
$most_rated_user .= "</td>";
$most_rated_user .= "</tr>";
}
$site_template->register_vars(array(
"most_rated_user" => $most_rated_user,
));
unset($most_rated_user);
//-----------------------------------------------------
5) Open home.html and add where you want to show top
<TABLE border="0" cellpadding="0" cellspacing="0" width="100%" class="head1">
<TR>
<TD>
<TABLE border="0" cellpadding="2" cellspacing="1" width="100%">
<TR>
<TD bgcolor="#434242" ALIGN="center"><TABLE CELLPADDING="1" CELLSPACING="0" BORDER="0" WIDTH="100%"><TR><TD ALIGN="center"><FONT FACE="verdana" SIZE="2" COLOR="#f3f3f3"><b>- {lang_most_pop_spotter} -</FONT></TD></TR></TABLE></TD>
</TR>
<TR>
<TD BGCOLOR="#e2e0e0">
<TABLE BORDER="0" WIDTH="100%">
<TR>
<TD VALIGN="top" align="center" width="250">
<table border="0" cellspacing="1" cellpadding="1" background="{template_url}/images/cat.gif">
<tr>
<td class="row1" td width="180" align="left"><font color="black">{lang_spotter_name}</font></td>
<td class="row1" width="70" align="center"><span class="smalltext"><font color="black">{lang_total_rates}</font></span></td>
</tr>
<tr>
<td class="row1">{most_rated_user}</td>
</tr>
{if user_loggedin}
<tr>
<td class="row1" align="center" colspan="2"><a href="{url_member_rating}">{lang_member_rating_title}</a></td>
</tr>
{endif user_loggedin}
</table>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</table>
6) Open your lang/english/main.php and at the end of ?> add next:
$lang['most_pop_spotter'] = "Most Popular Spotters";
$lang['spotter_name'] = "Spotter name";
$lang['total_rates'] = "Total rates";
$lang['total_photos'] = "Total photos";
7) Upload all files to you site path, and enjoy you new TOPS!!!