Advertisement:

Author Topic: [TIP/TRICK] Who Viewed The Topic  (Read 45259 times)

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,524
  • Young and Foolish
    • SimplePortal
[TIP/TRICK] Who Viewed The Topic
« on: June 04, 2008, 11:45:57 AM »
Mod is out:

http://custom.simplemachines.org/mods/index.php?mod=1300

This trick will allow you to view the users that viewed the topic.


../Sources/Display.php

Find:

Code: [Select]
fatal_lang_error('smf232', false);
Replace:

Code: [Select]
fatal_lang_error('smf232', false);

if(!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'log') {
DisplayLog();
}

Find:

Code: [Select]
?>
Replace:

Code: [Select]
function DisplayLog()
{
global $context, $scripturl, $db_prefix, $topic;

isAllowedTo('moderate_forum');

$request = db_query("
SELECT
lt.ID_MEMBER, lt.ID_TOPIC, mem.realName
FROM {$db_prefix}log_topics AS lt
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = lt.ID_MEMBER)
WHERE ID_TOPIC = $topic", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
{
// Build the array.
$context['logs'][] = array(
'member' => array(
'id' => $row['ID_MEMBER'],
'name' => $row['realName'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a>',
'href' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
),
);
}
mysql_free_result($request);

$context['sub_template'] = 'displaylog';
}

?>

../Themes/default/Display.template.php

Find:

Code: [Select]
?>
Replace:

Code: [Select]
function template_displaylog()
{
global $context, $settings, $options, $txt, $scripturl, $modSettings;

echo '
<table border="0" cellpadding="0" cellspacing="0" style="padding-top: 1ex;" align="center">
<tr class="titlebg">
<td>Who Viewed The Topic</td>
</tr>';

foreach($context['logs'] as $log) {
echo '
<tr class="windowbg">
<td>', $log['member']['link'], '</td>
</tr>';
}

echo '
</table>';
}

?>

Find:

Code: [Select]
<div class="nav" style="margin-bottom: 2px;"> ', $context['previous_next'], '</div>
Replace:

Code: [Select]
<div class="nav" style="margin-bottom: 2px;"> ', $context['previous_next'], '</div>';
if($context['can_moderate_forum'])
echo '
<a href="' . $scripturl . '?topic='. $context['current_topic'] . '.0;sa=log">View Topic Log</a>';
echo '
« Last Edit: July 27, 2008, 08:16:05 AM by [SiNaN] »
Former SMF Core Developer | My Mods | SimplePortal

Offline Eliana Tamerin

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,611
  • Gender: Female
Re: [TIP/TRICK] Who Viewed The Topic
« Reply #1 on: June 04, 2008, 12:15:14 PM »
SiNaN, that's seriously amazing! Awesome job!

I'm using this and it works wonderfully.

I've seen this kind of thing on other forum software, and the one other place I've seen it is on the Message Index, under the Views column. The number of views would be a link to the View Topic Log or whatever they called it. Do you think that's possible?
Do NOT PM me for support.

SimplePortal 2.3.6 is OUT!
SimplePortal Project Manager
Download | Docs
SimplePortal: Power of Simplicity!

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,524
  • Young and Foolish
    • SimplePortal
Re: [TIP/TRICK] Who Viewed The Topic
« Reply #2 on: June 04, 2008, 12:20:53 PM »
Nothing is impossible. :P

I hope I understand your question correctly.

../Themes/default/MessageIndex.template.php

Find:

Code: [Select]
', $topic['views'], '
Replace:

Code: [Select]
<a href="' . $scripturl . '?topic='. $topic['id'] . '.0;sa=log">', $topic['views'], '</a>
Former SMF Core Developer | My Mods | SimplePortal

Offline jossanaijr

  • SMF Hero
  • ******
  • Posts: 2,131
  • Gender: Male
    • Netbook Forum
Re: [TIP/TRICK] Who Viewed The Topic
« Reply #3 on: June 04, 2008, 12:24:44 PM »
Wow!  I had already asked for this sometime ago...
Please submit it to MOD site.
Thanks!

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,524
  • Young and Foolish
    • SimplePortal
Re: [TIP/TRICK] Who Viewed The Topic
« Reply #4 on: June 04, 2008, 12:26:23 PM »
This is not that complex to be a mod. But I can think of adding a view count and view time for members. Maybe.
Former SMF Core Developer | My Mods | SimplePortal

Offline jossanaijr

  • SMF Hero
  • ******
  • Posts: 2,131
  • Gender: Male
    • Netbook Forum
Re: [TIP/TRICK] Who Viewed The Topic
« Reply #5 on: June 04, 2008, 12:27:37 PM »
SiNan - > Sadrazam!

Offline jossanaijr

  • SMF Hero
  • ******
  • Posts: 2,131
  • Gender: Male
    • Netbook Forum
Re: [TIP/TRICK] Who Viewed The Topic
« Reply #6 on: June 04, 2008, 12:28:54 PM »
Question: Who can see this list?  All that can read the post?  And if member list is not public?

Offline Eliana Tamerin

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,611
  • Gender: Female
Re: [TIP/TRICK] Who Viewed The Topic
« Reply #7 on: June 04, 2008, 12:29:31 PM »
Yep, you understood perfectly. ;)

Hehe, I should have thought of that. No matter. Works beautifully.

Thanks again!

BTW, View Count and time would be an awesome feature.
Do NOT PM me for support.

SimplePortal 2.3.6 is OUT!
SimplePortal Project Manager
Download | Docs
SimplePortal: Power of Simplicity!

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,524
  • Young and Foolish
    • SimplePortal
Re: [TIP/TRICK] Who Viewed The Topic
« Reply #8 on: June 04, 2008, 12:38:12 PM »
SiNan - > Sadrazam!

Yes. :)

What about just the users who has the moderate forum permission?

Change the code like this:

Find:

Code: [Select]
<div class="nav" style="margin-bottom: 2px;"> ', $context['previous_next'], '</div>
Replace:

Code: [Select]
<div class="nav" style="margin-bottom: 2px;"> ', $context['previous_next'], '</div>';
if($context['can_moderate_forum'])
echo '
<a href="' . $scripturl . '?topic='. $context['current_topic'] . '.0;sa=log">View Topic Log</a>';
echo '
Former SMF Core Developer | My Mods | SimplePortal

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,524
  • Young and Foolish
    • SimplePortal
Re: [TIP/TRICK] Who Viewed The Topic
« Reply #9 on: June 04, 2008, 12:41:31 PM »
Yep, you understood perfectly. ;)

Hehe, I should have thought of that. No matter. Works beautifully.

Thanks again!

BTW, View Count and time would be an awesome feature.

And this is for you Eliana:

MessageIndex.template.php

Find:

Code: [Select]
', $topic['views'], '
Replace:

Code: [Select]
', $context['can_moderate_forum'] ? '<a href="' . $scripturl . '?topic='. $topic['id'] . '.0;sa=log">' . $topic['views'] . '</a>' : $topic['views'], '
Also you can use !$context['user']['is_guest'] instead of $context['can_moderate_forum'] if you want it to display it just for users.

I'll make a mod with view count and time after my finals.

Made it more secure, added isAllowedTo('moderate_forum');.
« Last Edit: June 04, 2008, 12:48:44 PM by Sadrazam »
Former SMF Core Developer | My Mods | SimplePortal

Offline Eliana Tamerin

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,611
  • Gender: Female
Re: [TIP/TRICK] Who Viewed The Topic
« Reply #10 on: June 04, 2008, 12:55:05 PM »
Awesome. And I've used this context on the Display.template.php file instead.

Code: [Select]
', !$context['user']['is_guest'] ? '<a href="' . $scripturl . '?topic='. $context['current_topic'] . '.0;sa=log" class="middletext"><b>View Topic Log</b></a>' : '', '
Do NOT PM me for support.

SimplePortal 2.3.6 is OUT!
SimplePortal Project Manager
Download | Docs
SimplePortal: Power of Simplicity!

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,524
  • Young and Foolish
    • SimplePortal
Re: [TIP/TRICK] Who Viewed The Topic
« Reply #11 on: June 04, 2008, 12:56:41 PM »
Okay, mod will include a permission for viewing it. Any other ideas?
Former SMF Core Developer | My Mods | SimplePortal

Offline Eliana Tamerin

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,611
  • Gender: Female
Re: [TIP/TRICK] Who Viewed The Topic
« Reply #12 on: June 04, 2008, 01:02:53 PM »
Maybe a little table of information.

Member Name 1        Last Viewed Time       (Views #)
Member Name 2Last Viewed Time(Views #)
Member Name 3Last Viewed Time(Views #)
Member Name 4Last Viewed Time(Views #)
Member Name 5Last Viewed Time(Views #)
GuestsLast Viewed Time(Views #)
Total Views
Do NOT PM me for support.

SimplePortal 2.3.6 is OUT!
SimplePortal Project Manager
Download | Docs
SimplePortal: Power of Simplicity!

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,524
  • Young and Foolish
    • SimplePortal
Re: [TIP/TRICK] Who Viewed The Topic
« Reply #13 on: June 04, 2008, 01:03:58 PM »
Exactly what I thought Eliana, thanks. ;)
Former SMF Core Developer | My Mods | SimplePortal

Offline jossanaijr

  • SMF Hero
  • ******
  • Posts: 2,131
  • Gender: Male
    • Netbook Forum
Re: [TIP/TRICK] Who Viewed The Topic
« Reply #14 on: June 04, 2008, 01:08:20 PM »
Wow!
Installed and working perfectly!
Thanks again!

Offline jossanaijr

  • SMF Hero
  • ******
  • Posts: 2,131
  • Gender: Male
    • Netbook Forum
Re: [TIP/TRICK] Who Viewed The Topic
« Reply #15 on: June 04, 2008, 01:12:38 PM »
BTW, is it ordered alphabetically or by order?

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,524
  • Young and Foolish
    • SimplePortal
Re: [TIP/TRICK] Who Viewed The Topic
« Reply #16 on: June 05, 2008, 02:11:23 AM »
BTW, is it ordered alphabetically or by order?

By order I guess.
Former SMF Core Developer | My Mods | SimplePortal

Offline H

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 21,660
  • Gender: Male
Re: [TIP/TRICK] Who Viewed The Topic
« Reply #17 on: June 05, 2008, 12:37:54 PM »
Topic moved to Tips and Tricks :D
-H
Former Support Team Lead
                              I recommend:
Namecheap (domains)
Fastmail (e-mail)
Linode (VPS)
                             

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,524
  • Young and Foolish
    • SimplePortal
Re: [TIP/TRICK] Who Viewed The Topic
« Reply #18 on: June 05, 2008, 12:38:18 PM »
Topic moved to Tips and Tricks :D

Thanks Huw. :)
Former SMF Core Developer | My Mods | SimplePortal

Offline jdizine

  • Semi-Newbie
  • *
  • Posts: 99
  • Gender: Female
    • GFX Unleashed
Re: [TIP/TRICK] Who Viewed The Topic
« Reply #19 on: June 12, 2008, 05:44:22 AM »
@[SiNaN]  I looked at your mods I never noticed they have that down there at the bottom!
Anyway, I don't know much but I have a couple of your mods installed and they work wonderfully!
I trust your work!
Have you made that mod yet? "Who Viewed The Topic"
I looked but I didn't see it.