Customizing SMF > Tips and Tricks

[TIP/TRICK] Who Viewed The Topic

(1/10) > >>

[SiNaN]:
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: --- fatal_lang_error('smf232', false);
--- End code ---

Replace:


--- Code: --- fatal_lang_error('smf232', false);

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

--- End code ---

Find:


--- Code: ---?>
--- End code ---

Replace:


--- Code: ---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';
}

?>
--- End code ---

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

Find:


--- Code: ---?>
--- End code ---

Replace:


--- Code: ---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>';
}

?>
--- End code ---

Find:


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

Replace:


--- Code: --- <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 '
--- End code ---

Eliana Tamerin:
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?

[SiNaN]:
Nothing is impossible. :P

I hope I understand your question correctly.

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

Find:


--- Code: --- ', $topic['views'], '
--- End code ---

Replace:


--- Code: --- <a href="' . $scripturl . '?topic='. $topic['id'] . '.0;sa=log">', $topic['views'], '</a>
--- End code ---

jossanaijr:
Wow!  I had already asked for this sometime ago...
Please submit it to MOD site.
Thanks!

[SiNaN]:
This is not that complex to be a mod. But I can think of adding a view count and view time for members. Maybe.

Navigation

[0] Message Index

[#] Next page

Go to full version