Code: Select all
//
// Start Top 5 Thanked Users
//
$sql = "SELECT t.thanked_user, u.username
FROM forum_thanksmod t LEFT JOIN " . USERS_TABLE . " u
ON t.thanked_user = u.user_id
WHERE thanked_user <> " . ANONYMOUS . "
ORDER BY thanked_user DESC";
if ( !($result = $db->sql_query($sql)) ) {
message_die(GENERAL_ERROR, 'Could not query users table', '', __LINE__, __FILE__, $sql);
}
$thanked_count = 1;
$old_user_id = 0;
$x = 0;
while ($row = mysql_fetch_array($result)) {
$user_id = $row['thanked_user'];
$username = $row['username'];
if ($row['thanked_user'] != $old_user_id) {
$thanked_count = 0;
$x++;
}
$old_user_id = $row['thanked_user'];
$thanked_count++;
$thankslist[$x]['count'] = $thanked_count;
$thankslist[$x]['user_id'] = $user_id;
$thankslist[$x]['username'] = $username;
}
rsort($thankslist);
for ($x = 0; $x < 10; $x++) {
if ($thankslist[$x]['user_id']) {
if ($x >= 1) { $top_5_thanked_users .= "<br /> "; }
// Add user to thanked list
$temp_url = "profile.$phpEx?mode=viewprofile&u=" . $thankslist[$x]['user_id'];
$top_5_thanked_users .= '<a href="' . $temp_url . '">' . $thankslist[$x]['username'] . '</a> (' . $thankslist[$x]['count'] . ')';
}
}
//
// End Top 5 Thanked Users
//
Code: Select all
ALTER TABLE `phpbb_posts` ADD `thanks_count` MEDIUMINT( 8 ) NOT NULL DEFAULT '0';
ALTER TABLE `phpbb_posts` ADD `thanks_from_user_id` TEXT NULL;
ALTER TABLE `phpbb_users` ADD `user_thanks_received` MEDIUMINT( 8 ) NOT NULL DEFAULT '0';
ALTER TABLE `phpbb_users` ADD `user_thanks_given` MEDIUMINT( 8 ) NOT NULL DEFAULT '0';
Code: Select all
CREATE TABLE `phpbb_thanksmod` (
`post_id` mediumint(8) unsigned NOT NULL default '0',
`thanked_user` mediumint(8) NOT NULL default '0',
`thanks_by` mediumint(8) NOT NULL default '0',
`thanked_time` int(10) NOT NULL default '0'
);
Code: Select all
$avatar_img = '';
Code: Select all
//
// Start Thank Post by User Mod
//
// Thanks by
$sql = "SELECT COUNT(thanks_by) AS thanks_by
FROM phpbb_thanksmod
WHERE thanks_by = '" . $profiledata['user_id'] . "'";
if ( !($result = $db->sql_query($sql)) ) {
message_die(GENERAL_ERROR, "Could not obtain thanks information", '', __LINE__, __FILE__, $sql);
}
$thanks_by_row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
// Thanked user
$sql = "SELECT post_id, thanked_user
FROM phpbb_thanksmod
WHERE thanked_user = '" . $profiledata['user_id'] . "'
ORDER BY post_id";
if ( !($result = $db->sql_query($sql)) ) {
message_die(GENERAL_ERROR, "Could not obtain thanks information", '', __LINE__, __FILE__, $sql);
}
// Calculate the user's thanks given and thanks received
$thanked_count = 0;
$thanked_posts = 0;
$old_post_id = 0;
while ($row = mysql_fetch_array($result)) {
if ($row['post_id'] != $old_post_id) {
$thanked_posts++;
}
$old_post_id = $row['post_id'];
$thanked_count++;
}
$temp_url = "profile.$phpEx?mode=viewprofile&u=" . $profiledata['user_id'] . "&thankslist=1";
$thanks_given = $thanks_by_row['thanks_by'];
$thanks_received = '<a href="' . $temp_url . '">' . $thanked_count . ' ' . $lang['Thanks_thanked_2'] . ' ' . $thanked_posts . ' ' . $lang['Thanks_thanked_3'] . '</a>';
//
// End Thank Post by User Mod
//
// Thanks Listing
if ( isset($HTTP_GET_VARS['thankslist']) || $HTTP_GET_VARS['thankslist'] ) {
// Thanked Listing SQL
$sql = "SELECT *
FROM phpbb_thanksmod
WHERE thanked_user = '" . $profiledata['user_id'] . "'";
if ( !($result = $db->sql_query($sql)) ) {
message_die(GENERAL_ERROR, "Could not obtain posts information", '', __LINE__, __FILE__, $sql);
}
$thanked_listing = $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
$thanked_listing_count = count($thanked_listing);
// Loop through all users who thanked the post
for ($x = 0; $x < $thanked_listing_count; $x++) {
// Users SQL
$sql = "SELECT user_id, username
FROM " . USERS_TABLE . "
WHERE user_id = " . $thanked_listing[$x]['thanks_by'];
if ( !($result = $db->sql_query($sql)) ) {
message_die(GENERAL_ERROR, "Could not obtain user information", '', __LINE__, __FILE__, $sql);
}
$user_row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
// Posts SQL
$sql = "SELECT topic_id
FROM " . POSTS_TABLE . "
WHERE post_id = " . $thanked_listing[$x]['post_id'];
if ( !($result = $db->sql_query($sql)) ) {
message_die(GENERAL_ERROR, "Could not obtain user information", '', __LINE__, __FILE__, $sql);
}
$post_topic_row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
// Topic SQL
$sql = "SELECT topic_title
FROM " . TOPICS_TABLE . "
WHERE topic_id = '" . $post_topic_row['topic_id'] . "'";
if ( !($result = $db->sql_query($sql)) ) {
message_die(GENERAL_ERROR, "Could not obtain user information", '', __LINE__, __FILE__, $sql);
}
$topic_row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$temp_url_post = "viewtopic.$phpEx?p=" . $thanked_listing[$x]['post_id'] . "#" . $thanked_listing[$x]['post_id'];
$temp_url_topic = "viewtopic.$phpEx?t=" . $post_topic_row['topic_id'];
$thanks_post = '<a href="' . $temp_url_post . '"> (Post #' . $thanked_listing[$x]['post_id'] . ')</a>';
$thanks_topic = '<a href="' . $temp_url_topic . '">' . $topic_row['topic_title'] . '</a>';
$thanks_listing .= "Thanked by " . $user_row['username'] . " in $thanks_topic - $thanks_post<br/>";
}
}
$template->assign_block_vars('thankslist', array(
'THANKS_LISTING' => $thanks_listing,
'L_THANKS_LISTING' => "Thanks Listing")
);