Bravo List
Register
Go Back   > Bravo List > Sourcecode > Free Torrent Source > Mods & Themes
Reply
  #1  
Old 15-09-09, 20:18
Edgein's Avatar
Edgein Edgein is offline
Staff
 
Join Date: Sep 2008
Netherlands
Posts: 154
Smile [FTS 1.1] userhits in profile
this mod will show the number of times a user's profile has been viewed, and by who.

First the database

PHP Code:
CREATE TABLE `userhits` (
  `
idint(10unsigned NOT NULL auto_increment,
  `
useridint(10unsigned NOT NULL default '0',
  `
hitidint(10unsigned NOT NULL default '0',
  `
numberint(10unsigned NOT NULL default '0',
  `
addeddatetime NOT NULL default '00-00-00 00:00:00',
  
PRIMARY KEY (`id`)
); 
then add
PHP Code:
ALTER TABLE `usersADD `hitsint(10NOT NULL default '0'
then in userdetails.php find

PHP Code:
$id $_GET["id"];
int_check($id,true);
if(
$id != $CURUSER['id'])
if(
$usergroups['canviewotherprofile'] != 'yes')
 
ug();
$r = @sql_query("SELECT * FROM users WHERE id=".mysql_real_escape_string($id)) or sqlerr(__FILE____LINE__);
$user mysql_fetch_array($r) or bark(str11);
if (
$user["status"] == "pending")
    die; 
and add after it

PHP Code:
if (!$_GET["hit"] && $CURUSER["id"] <> $user["id"]) {
  
$res mysql_query("SELECT added FROM userhits WHERE userid = $CURUSER[id] AND hitid = $id LIMIT 1") or sqlerr(); // *3
  
$row mysql_fetch_row($res); // *3
  
if ($row[0] > get_date_time(gmtime() - 3600)) { // *3
        
header("Location: $BASEURL$_SERVER[REQUEST_URI]&hit=1"); // *3
  
} else { // *3
//  $hitnumber = $userhits + 1; // *1
        
$hitnumber $user["hits"] + 1// *2
        
mysql_query("UPDATE users SET hits = hits + 1 WHERE id = $id") or sqlerr(); // *2
        
mysql_query("INSERT INTO userhits (userid, hitid, number, added) VALUES($CURUSER[id]$id$hitnumber, '".get_date_time()."')") or sqlerr();
        
header("Location: $BASEURL$_SERVER[REQUEST_URI]&hit=1");
  } 
// *3

then find in userdetails.php

PHP Code:
    $ip_res sql_query("SELECT * FROM ips WHERE userid = $id") or die(mysql_error());

    print(
"<tr><td class=rowhead>".str47."</td><td align=left>");
    while (
$arr mysql_fetch_assoc($ip_res)) {
        echo 
$arr[ip] ::";
    }
    print(
"</td></tr>\n"); 
And add above

PHP Code:
print("<tr><td class=rowhead>Profile views</td><td align=left><a href=userhits.php?id=$id>".number_format($user["hits"])."</a></td></tr>\n"); 
Create userhits.php:
PHP Code:
<?
require_once("include/bittorrent.php");
dbconn();
loggedinorreturn();

$id = 0 + $_GET["id"];

if (!is_valid_id($id) || $CURUSER["id"] <> $id && get_user_class() < UC_MODERATOR)
  $id = $CURUSER["id"];

$res = mysql_query("SELECT COUNT(*) FROM userhits WHERE hitid = $id") or sqlerr();
$row = mysql_fetch_row($res);
$count = $row[0];
$perpage = 100;
list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, "?id=$id&");

if (!$count)
  stderr("No views", "This user has had no profile views yet.");

$res = mysql_query("SELECT username FROM users WHERE id = $id") or sqlerr(); // remove 'hits' if you do NOT use the cleanup code
$user = mysql_fetch_assoc($res);

stdhead("Profile views of $user[username]");
print("<h1>Profile views of <a href=\"userdetails.php?id=$id\">$user[username]</a></h1>\n");
print("<h2>In total $count views</h2>\n"); // replace $user[hits] with $count if you do NOT use the cleanup code
if ($count > $perpage)
  print("$pagertop");
print("<table border=0 cellspacing=0 cellpadding=5>\n");
print("<tr><td class=colhead>Nr.</td><td class=colhead>Username</td><td class=colhead>Viewed at</td></tr>\n");

$res = mysql_query("SELECT uh.*, username, users.id as uid FROM userhits uh LEFT JOIN users ON uh.userid = users.id WHERE hitid = $id ORDER BY uh.id DESC") or sqlerr();
while ($arr = mysql_fetch_assoc($res))
  print("<tr><td>".number_format($arr["number"])."</td><td><b><a href=\"userdetails.php?id=$arr[uid]\">$arr[username]</a></b></td><td>$arr[added]</td></tr>\n");

print("</table>\n");
if ($count > $perpage)
  print("$pagerbottom");
stdfoot();
?>
good luck
grtzz edgein

Big thanx to the original makers
Reply With Quote
The Following 4 Users Say Thank You to Edgein For This Useful Post:
benjaminbih (21-12-09), Daz (04-02-10), Moh.ElBaz (21-12-09), Phogo (15-09-09)
  #2  
Old 14-12-09, 01:32
benjaminbih's Avatar
benjaminbih benjaminbih is offline
Hobby Coder
 
Join Date: Jul 2008
Bosnia-Herzegovina
Posts: 70
Default
thank you
Reply With Quote
  #3  
Old 21-12-09, 04:37
yoligim's Avatar
yoligim yoligim is offline
Senior Member
 
Join Date: Nov 2009
Spain
Posts: 43
Default
Done, thank you Edgein for your posts
Reply With Quote
  #4  
Old 16-01-10, 22:29
elvira's Avatar
elvira elvira is offline
Veteran
 
Join Date: Jan 2008
Slovenia
Posts: 65
Default
And if you want old hits to be removed add this to cleanup.php:

Quote:
// Remove userprofile views
$days = 7;
$dt = sqlesc(get_date_time(gmtime() - ($days * 68400)));
mysql_query("DELETE FROM userhits WHERE added < $dt");
Reply With Quote
The Following User Says Thank You to elvira For This Useful Post:
Phogo (18-01-10)
Reply

Tags
11 , fts , profile , userhits

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
New profile layout in phpMyBitTorrent joeroberts Community Cafe 1 07-06-10 00:48
Group image in user profile cop1976 Mods & Themes 0 17-02-10 03:57
Owner change profile ciobancai Template Shares 0 04-05-09 23:28
Hide profile PuterDude Torrent Strike 6 06-10-08 15:58



All times are GMT +2. The time now is 01:25. vBulletin skin by ForumMonkeys. Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2017, vBulletin Solutions Inc.