Bravo List

Bravo List (http://www.bvlist.com/index.php)
-   Mods & Themes (http://www.bvlist.com/forumdisplay.php?f=113)
-   -   [FTS 1.1] userhits in profile (http://www.bvlist.com/showthread.php?t=3408)

Edgein 15th September 2009 20:18

[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 $_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 :drink:

benjaminbih 14th December 2009 01:32

thank you

yoligim 21st December 2009 04:37

Done, thank you Edgein for your posts

elvira 16th January 2010 22:29

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");

aidzis7 19th July 2017 03:02

Thank you
But how to add (tzoffset) time zone code?


All times are GMT +2. The time now is 01:12.

Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.