Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: mikk on May 07, 2014, 01:53:11 PM

Title: Forum admin and "Views" counter
Post by: mikk on May 07, 2014, 01:53:11 PM
Hi!

If anyone see any topic, the topic views counter is increased.

I want: If the forum admin see any topic, this do not increase the topic views counter. How can I do this?

Thanks for the help.
Title: Re: Forum admin and "Views" counter
Post by: Arantor on May 07, 2014, 02:12:32 PM
I'm curious, what benefit would it bring?
Title: Re: Forum admin and "Views" counter
Post by: mikk on May 07, 2014, 04:51:03 PM
Quote from: Arantor on May 07, 2014, 02:12:32 PM
I'm curious, what benefit would it bring?

Hi!

This simple.

My forum users is few, but I very often read my (admin) messages again, or I often see other topics. So I don't know how many users seems these topics really.

Thanks.
Title: Re: Forum admin and "Views" counter
Post by: Arantor on May 07, 2014, 04:57:59 PM
You won't ever know how many users see the topics anyway, not from the view counts, because they're skewed by search engine visits too. Or by people re-visiting topics that aren't you.

The entire view system is pretty much broken; there are topics on this forum that have tens of thousands of views within hours of being posted and not being of anything special in themselves.

Unless your forum is private and very small, the view count is so skewed it is of little real use to you anyway.
Title: Re: Forum admin and "Views" counter
Post by: mikk on May 07, 2014, 05:10:43 PM
Quote from: Arantor on May 07, 2014, 04:57:59 PM
(...)
Unless your forum is private and very small, the view count is so skewed it is of little real use to you anyway.

Hi, yes, this my forum is private and small, guests users is not allowed here.

You have any idea?
Title: Re: Forum admin and "Views" counter
Post by: Arantor on May 07, 2014, 05:14:45 PM
Sure I have an idea. I just wanted to be sure that giving you any code was being done for the right reason. I refuse to give out answers without asserting it's the correct thing to be doing.

Sources/Display.php

// Add 1 to the number of views of this topic.
if (empty($_SESSION['last_read_topic']) || $_SESSION['last_read_topic'] != $topic)
{
$smcFunc['db_query']('', '
UPDATE {db_prefix}topics
SET num_views = num_views + 1
WHERE id_topic = {int:current_topic}',
array(
'current_topic' => $topic,
)
);

$_SESSION['last_read_topic'] = $topic;
}


Replace with:
// Add 1 to the number of views of this topic.
if (!$user_info['is_admin'] && (empty($_SESSION['last_read_topic']) || $_SESSION['last_read_topic'] != $topic))
{
$smcFunc['db_query']('', '
UPDATE {db_prefix}topics
SET num_views = num_views + 1
WHERE id_topic = {int:current_topic}',
array(
'current_topic' => $topic,
)
);

$_SESSION['last_read_topic'] = $topic;
}
Title: Re: Forum admin and "Views" counter
Post by: mikk on May 07, 2014, 05:26:48 PM
Thank you, this woks!

This line:


if (empty($_SESSION['last_read_topic']) || $_SESSION['last_read_topic'] != $topic)


need replace with this:


if (!$user_info['is_admin'] && (empty($_SESSION['last_read_topic']) || $_SESSION['last_read_topic'] != $topic))


Thanks again! Only one question is left for me. Now I want reset all views counter in my forum. How can I do this?
Title: Re: Forum admin and "Views" counter
Post by: Arantor on May 07, 2014, 05:38:17 PM
Yes, that's the line I suggested changing. I just provided the rest for context.

Resetting the view count means a direct change to the database in phpMyAdmin with the following query:
UPDATE smf_topics SET num_views = 0

Your installation may not have smf_ as the prefix, if so you'll have to change that for yourself.
Title: Re: Forum admin and "Views" counter
Post by: mikk on May 07, 2014, 06:09:14 PM
Very thank you, this is works too! You are fantastic!