Getting topic content without view count?

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
Kami-sama
Registered User
Posts: 137
Joined: Sat May 26, 2018 3:07 pm

Getting topic content without view count?

Post by Kami-sama »

Hey!

I am using this simple JS to get topic content and display on selected div:

Code: Select all

$(function(){
		var elem=$(".news_forum");
		if(!elem.length) return;
		
		$.get("www.URL.com", function(data){
			data=$(".content", data).last().html();
			elem.html(data);
		});
	});
It works perfectly fine, but it does activate topic view count.
So you can imagine that view count for that topic is generated pretty fast now.

I wonder if there is another way to get the content without adding to topic view count?
Or maybe I can disable view count for this specific topic?
Or maybe just leave it alone until 6 zero digits start popping up? :D
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Getting topic content without view count?

Post by 3Di »

If you hit that url that's what you get.
Probably cUrl could be an alternative, not sure.
to get topic content and display on selected div
Why not to use a simple query in PHP to fetch that topic, assign the result to a row and pass it to the template? Instead.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Getting topic content without view count?

Post by kasimi »

Add an extra argument to your request that serves as a flag that updating the view counter should be skipped. Then, in the core.viewtopic_modify_post_data event, do this:

Code: Select all

if ($this->request->is_set('your flag', false) && isset($this->user->data['session_page']))
{
    $this->user->data['session_page'] .= '&t=' . $event['topic_id'];
}
User avatar
Kami-sama
Registered User
Posts: 137
Joined: Sat May 26, 2018 3:07 pm

Re: Getting topic content without view count?

Post by Kami-sama »

3Di wrote: Sat Jul 21, 2018 2:10 am If you hit that url that's what you get.
Probably cUrl could be an alternative, not sure.
to get topic content and display on selected div
Why not to use a simple query in PHP to fetch that topic, assign the result to a row and pass it to the template? Instead.
Thank you for the advice. I will try it out.
Well, I am very new to PHP, this seamed like an easier way to do it. Would not even know how to do same in PHP ;D
User avatar
Kami-sama
Registered User
Posts: 137
Joined: Sat May 26, 2018 3:07 pm

Re: Getting topic content without view count?

Post by Kami-sama »

kasimi wrote: Sat Jul 21, 2018 8:04 am Add an extra argument to your request that serves as a flag that updating the view counter should be skipped. Then, in the core.viewtopic_modify_post_data event, do this:

Code: Select all

if ($this->request->is_set('your flag', false) && isset($this->user->data['session_page']))
{
    $this->user->data['session_page'] .= '&t=' . $event['topic_id'];
}

I was trying your method, but this looks like it would apply to all topics?
Or am I missing something?
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53379
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Getting topic content without view count?

Post by Brf »

I would assume only your JS code would be using that tag the code is checking for.
User avatar
Kami-sama
Registered User
Posts: 137
Joined: Sat May 26, 2018 3:07 pm

Re: Getting topic content without view count?

Post by Kami-sama »

Brf wrote: Wed Aug 15, 2018 12:28 am I would assume only your JS code would be using that tag the code is checking for.

yes, but the problem is that this JS is in overall header and runs on each page refresh.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53379
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Getting topic content without view count?

Post by Brf »

Yes, but your special javascript would add a unique parameter tag to the URL it uses. The PHP code kasimi has given you would check for that parameter and skip adding to the view count if it finds it.
User avatar
Kami-sama
Registered User
Posts: 137
Joined: Sat May 26, 2018 3:07 pm

Re: Getting topic content without view count?

Post by Kami-sama »

Sorry, I am pretty fresh with this, so getting it a bit slowly :D But I think I kinda got the idea. Tho the code is still not working, unless I am missing something.

Adjusted JS like this just by adding the flag:

Code: Select all

$(function(){
		var ntflag = false;
		var elem = $(".news_forum");		
		if(!elem.length) return;
		
		$.get("URL   t=14&view=unread#unread", function(data){
			data=$(".content", data).last().html();
			elem.html(data);
		});
	});
And in the listener I added this to the core event kasimi mentioned:

Code: Select all

public function nt_viewcount($event)
	{
		if ($this->request->is_set('ntflag', false) && isset($this->user->data['session_page']))
		{
			$this->user->data['session_page'] .= '&t=' . $event['14'];
		}

	}
Am I missing something?
Post Reply

Return to “Extension Writers Discussion”