Getting topic content without view count?

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

Getting topic content without view count?

Post by Kami-sama » Fri Jul 20, 2018 8:52 pm

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
Registered User
Posts: 12990
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Getting topic content without view count?

Post by 3Di » 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.
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3296
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Getting topic content without view count?

Post by kasimi » 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'];
}

User avatar
Kami-sama
Registered User
Posts: 104
Joined: Sat May 26, 2018 3:07 pm

Re: Getting topic content without view count?

Post by Kami-sama » Sat Jul 21, 2018 4:33 pm

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: 104
Joined: Sat May 26, 2018 3:07 pm

Re: Getting topic content without view count?

Post by Kami-sama » Tue Aug 14, 2018 10:01 pm

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: 51402
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Getting topic content without view count?

Post by Brf » Wed Aug 15, 2018 12:28 am

I would assume only your JS code would be using that tag the code is checking for.

User avatar
Kami-sama
Registered User
Posts: 104
Joined: Sat May 26, 2018 3:07 pm

Re: Getting topic content without view count?

Post by Kami-sama » Fri Oct 12, 2018 9:24 pm

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: 51402
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Getting topic content without view count?

Post by Brf » Sat Oct 13, 2018 1:32 am

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: 104
Joined: Sat May 26, 2018 3:07 pm

Re: Getting topic content without view count?

Post by Kami-sama » Mon Oct 15, 2018 10:04 pm

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”

Who is online

Users browsing this forum: No registered users and 19 guests