Advertisement:

Author Topic: Forum admin and "Views" counter  (Read 1515 times)

Offline mikk

  • Semi-Newbie
  • *
  • Posts: 34
  • Gender: Male
Forum admin and "Views" counter
« 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.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,851
    • StoryBB/StoryBB on GitHub
Re: Forum admin and "Views" counter
« Reply #1 on: May 07, 2014, 02:12:32 PM »
I'm curious, what benefit would it bring?
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline mikk

  • Semi-Newbie
  • *
  • Posts: 34
  • Gender: Male
Re: Forum admin and "Views" counter
« Reply #2 on: May 07, 2014, 04:51:03 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.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,851
    • StoryBB/StoryBB on GitHub
Re: Forum admin and "Views" counter
« Reply #3 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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline mikk

  • Semi-Newbie
  • *
  • Posts: 34
  • Gender: Male
Re: Forum admin and "Views" counter
« Reply #4 on: May 07, 2014, 05:10:43 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?

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,851
    • StoryBB/StoryBB on GitHub
Re: Forum admin and "Views" counter
« Reply #5 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

Code: [Select]
// 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:
Code: [Select]
// 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;
}
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline mikk

  • Semi-Newbie
  • *
  • Posts: 34
  • Gender: Male
Re: Forum admin and "Views" counter
« Reply #6 on: May 07, 2014, 05:26:48 PM »
Thank you, this woks!

This line:

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

need replace with this:

Code: [Select]
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?

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,851
    • StoryBB/StoryBB on GitHub
Re: Forum admin and "Views" counter
« Reply #7 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:
Code: [Select]
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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline mikk

  • Semi-Newbie
  • *
  • Posts: 34
  • Gender: Male
Re: Forum admin and "Views" counter
« Reply #8 on: May 07, 2014, 06:09:14 PM »
Very thank you, this is works too! You are fantastic!