Log in

View Full Version : Recently Viewed (Hack in Progress)


Logikos
02-01-2006, 07:28 PM
After lurking around sitepoint today, I thought I would create a hack much like they have. "Recently Viewed". The first thing I did is search vB.org to see if it was recently released, or released in the past. I did find a few request for this, but no hack has ever been acually released to the public.

So I started thinking how I can create this hack the best way possiable. The first thing that came into mind is create a new table called "recentlyviewed" with the following information.

'recentlyviewed' Table

userid
The userid of the user viewing the thread
threadid
The threadid of the thead the user is viewing
dateline
The date/time user viewed thread. (TIMENOW)


This means the 1 query will be added on the showthread.php page (per user). Now this method can instantly start filling the "recentlyviewed" table with large boards; Seeing as showthread.php is the mosted used file IMHO. So I thought, lets only keep 5 listing per userid.


Keep only 5 listing in database (per userid)
This would be done using the global.php file...

Scenario:
User has viewed 10 threads (according to the recentlyviewed table). Delete the oldest 5.

Conditions before sql execution:



SQL = count total threads where userid = userid

if (user has more the 5 viewed threads)
{
Delete the oldest threads viewed, keeping the latest 5
}
else
{
exit();
}


Now please note that I havn't even started coding this. I just started thinking about it and wanted to get in on paper, and also hear what a few other coders input before I start. So, if you have a better method, please explain. If not, how can I delete the oldest threads viewed, keeping the latest 5? Thanks everyone! :)

Also, I will publicly release this once this is finished...

amykhar
02-01-2006, 07:32 PM
I am a bit dense today. Where is this meant to show? Does it show recently viewed posts by anyone or does it show the user the posts they recently viewed?

Logikos
02-01-2006, 07:38 PM
This will show the latest 5 threads (Recently Viewed) per logged in user. This can be shown anywhere one would want really. I will code the public version so its shown on the forumhome page. My personal version will be shown on my cutom portal I'm creating.

I should also note that even though the Recently Viewed table only has 3 rows, I will be able to get the rest of the information using JOINs in the SQL. In case anyone was wondering...

amykhar
02-01-2006, 07:40 PM
Gotcha. I think if I were doing this, I would try to hook into how vbulletin is recording what threads the user has viewed. It tracks them already by user for the getnew to work properly. So, obviously, the info about the threads viewed is stored somewhere. It's just a matter of finding it and pulling it.

Logikos
02-01-2006, 07:51 PM
yea, though how vBulletin determins which post have been read, is beyond me. I don't think I will beable to hook into there method though. I can't seem to understand/find how they record which post have been read/unread. I would guess its a combination of the post dateline, vistlog, and users last activity. I just don't see a table that would keep track of this all..

amykhar
02-01-2006, 07:56 PM
From what I'm seeing, it looks like it's in a cookie.

in showthread.php, you'll see,

$threadview = intval(fetch_bbarray_cookie('thread_lastview', $thread['threadid']));


and

if ($displayed_dateline <= $threadview)
{
$updatethreadcookie = true;
}


I found this by going to the forum settings, seeing that jelsoft called it thread marking and searching showthread for marking and then following the code.

Marco van Herwaarden
02-01-2006, 08:06 PM
Adding to the table could be done with a shutdown query.

I wouldn't do any cleaning on pageloads. Better create a scheduled task for that. Clean the table by either maximum X rows/user, or by dateline.

Logikos
02-01-2006, 08:21 PM
I was thinking what Marco said. a vBcron every X mins. The thing that stoped me was how can I clean the table out per userid? Wouldn't be able to use WHERE userid = $vbulletin->userinfo['userid'] since its running as a cron...

I would have to get every userid from the users table and during the while statement I could clean up the table, but that seems like alot of work for a cron right?

Marco van Herwaarden
02-01-2006, 08:55 PM
A lot of cronjobs perform actions on all users. All it would probably take is a single wellformed SQL-statement.



Cleaning up once a day would be enough i think, maybe once an hour.

Logikos
02-01-2006, 09:15 PM
Thanks Marco, I'll prolly end up doing it that way and will release to the public when finished. :)

Paul M
02-01-2006, 09:32 PM
yea, though how vBulletin determins which post have been read, is beyond me. I don't think I will beable to hook into there method though. It either uses a cookie (old method) or the threadread and forumread tables (new method). The threadread is the more useful as it records each thread you have read over the period set by the database marking system. This is what I use for this hack (https://vborg.vbsupport.ru/showthread.php?s=&threadid=92339).

rob30UK
09-18-2007, 10:59 AM
I'm sure this got finished, but I'm looking for something similar for 3.6.8

(I know.... way to drag up an old thread)

mistyPotato
10-01-2007, 12:17 PM
It either uses a cookie (old method) or the threadread and forumread tables (new method). The threadread is the more useful as it records each thread you have read over the period set by the database marking system. This is what I use for this hack (https://vborg.vbsupport.ru/showthread.php?s=&threadid=92339).

I'm Using 3.6.4 and the ForumThreadRead table is empty after two years and thousands of posts?