News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Check if a user has ever read a topic?

Started by samborabora, May 27, 2015, 08:17:35 AM

Previous topic - Next topic

samborabora

I need to check if a topic has been read by the user at any point, not unread posts, but if they have actually ever clicked on it. $topic['new'] isn't quite the same, as that is unread new posts, period, but I need to see if the user has ever actually clicked on the thread. Is there a variable?

Kindred

no...   and actually, there is no way to track this at all with any accuracy....   because the user COULD just click "mark all unread as read" and it would be marked, as if the user had read it.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Pipke

Topic view log, althought the mod is deleted you could get more info by visiting SMFSimple.com
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

samborabora

Quote from: Kindred on May 27, 2015, 08:37:51 AM
no...   and actually, there is no way to track this at all with any accuracy....   because the user COULD just click "mark all unread as read" and it would be marked, as if the user had read it.

I haven't got "mark all unread as read" avilable from MessageIndex any more, so any interaction the user would have with the thread would count as a view, which is what I am interested in. Basically, if the user clicks on the topic at all, I want it to count as having viewed the topic. Is there no built in functionality that would cover this?

Quote from: Pipke on May 27, 2015, 09:47:29 AM
Topic view log, althought the mod is deleted you could get more info by visiting SMFSimple.com

Looks interesting, I guess it could be done by using this mod and just checking if the topic view count for the user was >1?

Illori

did you make it so that they can not manually build the url that is behind the mark all as read action and make it work anyway? some that really want to may find a way.

samborabora

Quote from: Illori on May 27, 2015, 10:14:04 AM
did you make it so that they can not manually build the url that is behind the mark all as read action and make it work anyway? some that really want to may find a way.

It's not a problem if they could, I'm trying to hide the "unread new posts" link on MessageIndex to anyone who hasn't engaged the thread by reading it once, if they have read it, the "unread new posts" link will appear for all topics the user has read, rather than just a bunch of "unread new post" links next to topics they wouldn't be interested in.

Kindred

you know, if you are trying to make sure that users read a specific topic, there is a mod to do that...

http://custom.simplemachines.org/mods/index.php?mod=1364


or force them to read the sticky topics before posting?
http://custom.simplemachines.org/mods/index.php?mod=1847
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

samborabora

Quote from: Kindred on May 27, 2015, 10:44:55 AM
you know, if you are trying to make sure that users read a specific topic, there is a mod to do that...

http://custom.simplemachines.org/mods/index.php?mod=1364


or force them to read the sticky topics before posting?
http://custom.simplemachines.org/mods/index.php?mod=1847

No, I'm making sure that users don't see an unread new posts link on messageindex for topics they haven't read yet. Any topcis they haven't read won't have an unread new posts link since they haven't clicked on it before.

Burke ♞ Knight

Though you can force people to a post, there is not any real way to force people to actually READ the post. ;)

samborabora

Quote from: Burke ♞ Knight on May 27, 2015, 11:13:46 AM
Though you can force people to a post, there is not any real way to force people to actually READ the post. ;)

I'm not forcing people to read anything. I'm trying to check every thread if the user has read it or not. If they have read it, and there is an unread post on the topic, an "unread" post link will appear. If they haven't read it and there are unread posts, there will not be an unread post link.

I'm not sure where this idea about forced posting and reading came from?

Burke ♞ Knight

Then I really do not see your point of this.
Either you want to force someone to read a post, like it seemed you wanted until now, or you want to spy on your users, trying to find out which posts they have read. What the heck difference is it, if they read a topic, or marked it as read?

When I'm on a forum, I only read posts that interest me. Like here, I have no interest in reading on the other language boards, since I can't. So why should I be forced to read the posts I do not, just because an admin wants to disable mark as read, and have everyone read every post. That's forcing people, in my opinion. And that is how your posts feel like you want.

Now your last post, is full of inaccuracies:

"If they have read it, and there is an unread post on the topic, an "unread" post link will appear."

If they read the topic and there was unread, then after they read the topic and the latest post is on the page they are, it will be seen as read. However, if they read and a post pops up after, or on another page, then it will not be listed as read. That is why sometimes, have to be careful when reading topics, the pages can get you! LOL

"If they haven't read it and there are unread posts, there will not be an unread post link."

If they have not read a topic, or marked it read, any post to that topic will be seen as UNREAD.


It seems to me, you are trying to remove Unread Posts links. Why?

Quote from: samborabora on May 27, 2015, 11:07:55 AMNo, I'm making sure that users don't see an unread new posts link on messageindex for topics they haven't read yet. Any topcis they haven't read won't have an unread new posts link since they haven't clicked on it before.

I just do not understand why you'd not want them to know and see list of unread posts. This really goes against the ways forums run. New posts are meant to be shown well, as NEW.

samborabora

Spy? It's not about not wanting them to see unread posts, it's about not needing them to see a link on the message index to unread posts to topics they would not have interest in.

Let's say, I have only clicked on topic 2 as I was only interested in reading it:

+ Topic 1 |
+ Topic 2 | Unread Posts
+ Topic 3 |
+ Topic 4 |

That's what would appear, the other three, whether or not they have unread posts to the user, would appear as such without the Unread Posts text as the topic had never been clicked on by the user.

Burke ♞ Knight

There would be no way to do that, and if there was, would be very server heavy.
The calls to the database alone to check every topic for every user, to see if they have or have not read it, would put a huge strain on any server.

Also, I have no idea, where you'd get that info from anyway. Sure, you can block mark as read, but you can't block people just clicking the topic and immediately closing it, just to get it marked as read. (I've known people to do that.)

samborabora

Quote from: Burke ♞ Knight on May 27, 2015, 12:47:52 PM
There would be no way to do that, and if there was, would be very server heavy.
The calls to the database alone to check every topic for every user, to see if they have or have not read it, would put a huge strain on any server.

Also, I have no idea, where you'd get that info from anyway. Sure, you can block mark as read, but you can't block people just clicking the topic and immediately closing it, just to get it marked as read. (I've known people to do that.)

Err, im not blocking mark as read. I'm not blocking a thing at all. They absolutely can do that if they want, i mean, they can do anything they want, I'm not blocking anything, i just dont have marked as read on the message index.

As for server heavy, yeah, exactly like how much fun it is for the server to load every unread message for every topic the user has or has not seen. The messageindex is a serverfest for checking things, and I only need to load if the user has or hasn't read the topic in their life at all.

margarett

You can try to check your table smf_log_topics. You should be able to find when a certain user (id_member) checked a certain topic (id_topic), and even a message inside that post (id_msg)

The "glitch" is exactly id_msg. It only stores either the "new" (if you follow the #new link) or the last post in page, not all the posts in between.
If your topic only has 1 post (eg: rules), this should be a good confirmation. If not, you need to apply further logics (and queries) to determine if the topic you want is or is not between the information which is stored...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Kindred

Quote from: samborabora on May 27, 2015, 12:59:22 PM
As for server heavy, yeah, exactly like how much fun it is for the server to load every unread message for every topic the user has or has not seen. The messageindex is a serverfest for checking things, and I only need to load if the user has or hasn't read the topic in their life at all.

ummm... no..... now you need to check every single message *AND* perform logic on it.  Basically, you have added at least another 50% to your server load to do what you are asking.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

samborabora

Quote from: margarett on May 27, 2015, 01:05:42 PM
You can try to check your table smf_log_topics. You should be able to find when a certain user (id_member) checked a certain topic (id_topic), and even a message inside that post (id_msg)

The "glitch" is exactly id_msg. It only stores either the "new" (if you follow the #new link) or the last post in page, not all the posts in between.
If your topic only has 1 post (eg: rules), this should be a good confirmation. If not, you need to apply further logics (and queries) to determine if the topic you want is or is not between the information which is stored...

I just need to know if the topic has ever been read or not, would id_topic be empty if it has never been read, do you think? If so, will I need to have new sql markup for retrieving this, or is there a variable already that could handle this?

Quote from: Kindred on May 27, 2015, 02:01:56 PM
ummm... no..... now you need to check every single message *AND* perform logic on it.  Basically, you have added at least another 50% to your server load to do what you are asking.
Well, it's just a simple check if or not to show a link, not gonna break the bank.

Kindred

well, for one...   the system already performs part of what you are asking.... in your description, you are essentially doing exactly what the <NEW> icon already DOES...

When you start adding things to it is when it beomces more expensive...   you ONLY want to show the "read unread" link when a user HAS unread posts?   
That query alone is one of THE MOST EXPENSIVE queries in the entire system....   and you want to do that query on EVERY page?
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Burke ♞ Knight

Quote from: samborabora on May 27, 2015, 12:59:22 PMErr, im not blocking mark as read. I'm not blocking a thing at all. They absolutely can do that if they want, i mean, they can do anything they want, I'm not blocking anything, i just dont have marked as read on the message index.

Really? Sure looks like you said earlier, that you were.

Quote from: samborabora on May 27, 2015, 10:08:56 AM
I haven't got "mark all unread as read" avilable from MessageIndex any more, so any interaction the user would have with the thread would count as a view, which is what I am interested in. Basically, if the user clicks on the topic at all, I want it to count as having viewed the topic. Is there no built in functionality that would cover this?

margarett

It's not that simple...
If $context['topics'][topic_id_here]['new'] then the topic *has unseen messages*. But the user might have visited the topic already, yet new replies were posted after his last visit.

So I guess that you do need to perform a new check, yes. Potentially an expensive one, as it requires a COUNT of id_topic WHERE id_topic = xxx AND id_member = your_member
If count is 0, then the topic as a whole was never seen by said user.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

samborabora

Quote from: Kindred on May 27, 2015, 02:09:30 PM
well, for one...   the system already performs part of what you are asking.... in your description, you are essentially doing exactly what the <NEW> icon already DOES...

When you start adding things to it is when it beomces more expensive...   you ONLY want to show the "read unread" link when a user HAS unread posts?   
That query alone is one of THE MOST EXPENSIVE queries in the entire system....   and you want to do that query on EVERY page?

I only want to show the "read unread" link when a user HAS unread posts AND they have already visited the topic.

Quote from: Burke ♞ Knight on May 27, 2015, 02:15:21 PM
Really? Sure looks like you said earlier, that you were.

Sorry, mark as read is available, but I also only want that avilable on messageindex if the user has visited the topic. If they want to fiddle urls, okay, I don't care.

Quote from: margarett on May 27, 2015, 02:20:22 PM
It's not that simple...
If $context['topics'][topic_id_here]['new'] then the topic *has unseen messages*. But the user might have visited the topic already, yet new replies were posted after his last visit.

So I guess that you do need to perform a new check, yes. Potentially an expensive one, as it requires a COUNT of id_topic WHERE id_topic = xxx AND id_member = your_member
If count is 0, then the topic as a whole was never seen by said user.

So, id_topic keeps track of if a topic has ever been seen or not? What sql query would be needed for this?

samborabora

For instance, if the user has never clicked the topic, I won't show a marked as read or a "there are unread posts" link/text. However, if the topic has three pages, and the user clicks on page one of the topics or even page one and two, or just page two, since they never saw page three, NOW when they return to message index, they would now see "mark as read" and "there are unread posts" since they saw the topic, but didn't see the last page of the topic.

Pipke

you should use the mod i posted earlier, then tweak it on the logging page, you can check if the users last view topic time is lower then the last post on that certain topic inside that list, if so then the topic can (still) have the flag 'unread posts' in the topic.
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Kindred

yup...   you are attempting to duplicate one of the most expensive queries in the system anf then add additional logic processing on top of that on every page load...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

samborabora

Quote from: Pipke on May 27, 2015, 02:41:50 PM
you should use the mod i posted earlier, then tweak it on the logging page, you can check if the users last view topic time is lower then the last post on that certain topic inside that list, if so then the topic can (still) have the flag 'unread posts' in the topic.

Definitely going to use it, just checking there wasn't already a function built-in to save me adding a package.

Quote from: Kindred on May 27, 2015, 02:45:15 PM
yup...   you are attempting to duplicate one of the most expensive queries in the system anf then add additional logic processing on top of that on every page load...

I mean, are queries THAT much of a problem in 2015? I could understand back in the message board golden days, but aren't processors and servers just a little bit more up to spec now for this kind of work?

samborabora

Quote from: margarett on May 27, 2015, 02:20:22 PM
It's not that simple...
If $context['topics'][topic_id_here]['new'] then the topic *has unseen messages*. But the user might have visited the topic already, yet new replies were posted after his last visit.

So I guess that you do need to perform a new check, yes. Potentially an expensive one, as it requires a COUNT of id_topic WHERE id_topic = xxx AND id_member = your_member
If count is 0, then the topic as a whole was never seen by said user.

Would customising something to do it this way be better than using the suggested mod?

margarett

Which suggested mod? Sorry, I probably missed something...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair


samborabora

Quote from: margarett on May 27, 2015, 07:42:30 PM
Which suggested mod? Sorry, I probably missed something...

I can give this a go, I just want to make sure I'm not wasting time installing a package that's overdoing it for my purposes, on the other hand, if there ISN'T a way of doing this with existing functions or accessing the database, this mod should be perfect.

samborabora

margarett, what would be the easiest way of implementing your idea? It it a query that needs to go in Load and called as a variable?

margarett

It depends. I would say that it should go at Sources/MessageIndex.php. You get the list of topics per page (already exists), then perform the query to load the "seen/not seen" thing from all topics at once, then stuff the result in $context['topics'] again. That gives you that information in the list of topics (MessageIndex).
If you also want it in topic view, then you need to do it again in Display.php.

I still don't fully understand what you want to do with this information, though :P
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

samborabora

Quote from: margarett on May 28, 2015, 05:53:59 PM
It depends. I would say that it should go at Sources/MessageIndex.php. You get the list of topics per page (already exists), then perform the query to load the "seen/not seen" thing from all topics at once, then stuff the result in $context['topics'] again. That gives you that information in the list of topics (MessageIndex).
If you also want it in topic view, then you need to do it again in Display.php.

I still don't fully understand what you want to do with this information, though :P

:D Ahh, I think my modded theme is making it hard to convey what part I'm using. Okay. You know that "New" image that appears on topic titles in MessageIndex that have new posts? Okay, I'm basically not having that appear unless the user has read the topic. Only then, will it appear if there are new posts.

Kindred

I really don't mean to offend you... (which as always is a prelude to a comment which could be construed as offensive)

but that is a stupid piece of logic, IMO   Since someone has never read a topic, the entire topic is new - which means that the NEW icon is completely appropriate on a topic which you are now attempting to exclude it from...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

samborabora

Quote from: Kindred on May 28, 2015, 06:26:23 PM
I really don't mean to offend you... (which as always is a prelude to a comment which could be construed as offensive)

but that is a stupid piece of logic, IMO   Since someone has never read a topic, the entire topic is new - which means that the NEW icon is completely appropriate on a topic which you are now attempting to exclude it from...

Or completely irrelevant since it's painfully obvious if they haven't read the topic that every post would be new. Being told it is new is a waste of time since everything to do with it is new to someone who hasn't seen it.

Kindred

and yet....   how do they KNOW that they haven't read the topic in the first place, if there is no indicator?


Seriously...     
200 topics in a board --
I read the top 3 and come back later...   
there are 3 NEW topics (which won't be marked, based on your logic)
ONE of the topics that I read has a new response and gets marked
the other two topics are not updated... but they are now 4 down in the list...

or even worse...
20 new topics when I come back
all three of the ones that I read before have responses...
but they are the only ones marked as new


if it's been 3 days since I visited -- there is a very good chance that I have NO IDEA which topics I have read and which ones I have not...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

samborabora

If all pages of the topic are read, the topic will be un-bolded, if there are unread pages, the topic will be bold. So the user will still know what topics are new, it just won't have a "New" image next to it since the new posts are as new to the user as the entire topic is, it will already be <strong>.

margarett

OK, I don't necessarily agree with that :P but that's your call and I'll respect that much.

So you only need it in MessageIndex.php. Eventually (because you just want to hide the "new" icon) you don't even need to touch MessageIndex.template.php
The logics that I outlined above should work. That will add you a (potentially expensive) query per page load and only when someone (not guest) is viewing MessageIndex.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Burke ♞ Knight

And this is where I state my mind finally, and step out.

1. This idea would be a major server strain issue.

2. The ideas behind this, is really not making a lick of sense.

3. The idea behind this, IMO is pointless, and not worth the time and resources to make happen.

4. I really think the OP needs to figure out what exactly they want, then post it more clearly, without contradicting one post with another.

Saying that, peace out all those involved in this topic. :)

samborabora

Quote from: margarett on May 28, 2015, 07:36:41 PM
OK, I don't necessarily agree with that :P but that's your call and I'll respect that much.

So you only need it in MessageIndex.php. Eventually (because you just want to hide the "new" icon) you don't even need to touch MessageIndex.template.php
The logics that I outlined above should work. That will add you a (potentially expensive) query per page load and only when someone (not guest) is viewing MessageIndex.

I appreciate what you are saying,  my "new" image is basically an image that says unread with a X mark next to it, when you click the X it marks unread posts as read, and I only want this to show for folks who have clicked on the topic. I've already got some pretty expensive calls but I'm trying some ideas out to see how we go. Since I'm so useless with neat SQL can you suggest what I should put into sources/messageindex? What should I use in Messageindextemplate as some sort of variable to wrap around the "new" image?

samborabora

Quote from: Burke ♞ Knight on May 28, 2015, 07:45:35 PM
And this is where I state my mind finally, and step out.

1. This idea would be a major server strain issue.

2. The ideas behind this, is really not making a lick of sense.

3. The idea behind this, IMO is pointless, and not worth the time and resources to make happen.

4. I really think the OP needs to figure out what exactly they want, then post it more clearly, without contradicting one post with another.

Saying that, peace out all those involved in this topic. :)

1. Noted.
2. Noted, I disagree.
3.Noted, though I doubt time and resource is an issue if it is a simple bit of code.
4. I used the wrong wording, I didn't contradict my own posts, necessarily.

Let's try again. I'd like a variable, say $context[user][seenpost] that
Quoteif (empty$context[user][seenpost])
echo 'there are new posts'

And the seenpost variable is sorted via, presumably, as margarett suggested
Quotea COUNT of id_topic WHERE id_topic = xxx AND id_member = your_member
If count is 0, then the topic as a whole was never seen by said user.

Does that look doable? If so, what SQL would be needed to pull this off?

margarett

* margarett apologizes for a much needed cleanup

@samborabora, what you want to do is now perfectly clear. I am just sorry that I don't have, right now, the required time to implement that (because I can't code it out of my head, I need to try, fail and debug).
The principle that I outlined should be more or less correct, but it still needs to be coded. And it is a bit heavy for my skills so it requires time :(

QuoteLet's try again. I'd like a variable, say $context[user][seenpost] that
You don't need that, the way I see it. After you have fetched the "seenpost" information, you just need to loop the $context['topics'] variable and clean the "new" item of any item which as not "seen".
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

samborabora

Quote from: margarett on May 29, 2015, 11:27:16 AM
* margarett apologizes for a much needed cleanup

@samborabora, what you want to do is now perfectly clear. I am just sorry that I don't have, right now, the required time to implement that (because I can't code it out of my head, I need to try, fail and debug).
The principle that I outlined should be more or less correct, but it still needs to be coded. And it is a bit heavy for my skills so it requires time :(

QuoteLet's try again. I'd like a variable, say $context[user][seenpost] that
You don't need that, the way I see it. After you have fetched the "seenpost" information, you just need to loop the $context['topics'] variable and clean the "new" item of any item which as not "seen".

Thank you, margarett, I appreciate you taking the time to consider this, and hope I have described it accurately enough! Okay, back to the original plan, any ideas about Topic View Mod being useful for this?

samborabora

Still looks like that mod would require a lot of extra stuff I don't need, which is really just a variable to check if the user has ever seen the topic before, and it's a bit weird trying to figure out how to download that mod. If anyone can come up with any suggestions on what code to use to do this, I'd be most grateful!

samborabora

Okay, I installed Topic View Mod, here's how the mod is building the topic views list:


function tvl_actions(&$actionArray) //Action!
{
$actionArray['topicviewlog'] = array('TopicViewLog.php', 'TopicViewLog');
}

function tvl_permissions(&$permissionGroups, &$permissionList)
{
global $context;

loadLanguage('TopicViewLog');
$context['non_guest_permissions'][] = 'tvl_view';
$permissionList['board']['tvl_view'] = array(true, 'topic', 'moderate');
}

function tvl_display_buttons(&$normal_buttons)
{
global $scripturl, $context;

loadLanguage('TopicViewLog');
$context['can_view_topic_log'] = allowedTo('tvl_view_any') || (allowedTo('tvl_view_own') && $context['user']['started']);

if (!empty($context['can_view_topic_log']))
{
$normal_buttons[] = array(
'text' => 'tvl_title',
'image' => 'topiclog.gif',
'lang' => true,
'url' => $scripturl . '?action=topicviewlog;topic=' . $context['current_topic'] . '.0'
);
}
}

function tvl_load_theme()
{
global $context;

if (!empty($_REQUEST['topic']) && empty($context['current_action']))
tvl_log();
}

function TopicViewLog()
{
global $smcFunc, $context, $user_info, $scripturl, $sourcedir, $txt, $topic;

loadLanguage('TopicViewLog');

if (empty($topic))
fatal_lang_error('no_board', false);

$request = $smcFunc['db_query']('', '
SELECT id_member_started
FROM {db_prefix}topics
WHERE id_topic = {int:topic} LIMIT 1',
array(
'topic' => $topic,
)
);
list ($starter) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

if (!allowedTo('tvl_view_any') && $user_info['id'] == $starter)
isAllowedTo('tvl_view_own');
else
isAllowedTo('tvl_view_any');

$context['page_title'] = $txt['tvl_title'];

require_once($sourcedir . '/Subs-List.php');

$listOptions = array(
'id' => 'tvl_list',
'items_per_page' => 30,
'base_href' => $scripturl . '?action=topicviewlog;topic=' . $topic,
'default_sort_col' => 'time',
'get_items' => array(
'function' => 'list_get_tvl_members',
),
'get_count' => array(
'function' => 'list_get_tvl_num_members',
),
'columns' => array(
'name' => array(
'header' => array(
'value' => $txt['name'],
),
'data' => array(
'sprintf' => array(
'format' => '<a href="' . strtr($scripturl, array('%' => '%%')) . '?action=profile;u=%1$d">%2$s</a>',
'params' => array(
'id_member' => false,
'real_name' => false,
),
),
'style' => 'width: 25%;',
),
'sort' => array(
'default' => 'real_name',
'reverse' => 'real_name DESC',
),
),
'group' => array(
'header' => array(
'value' => $txt['position'],
),
'data' => array(
'db' => 'group_name',
'style' => 'width: 25%;',
),
'sort' =>  array(
'default' => 'group_name',
'reverse' => 'group_name DESC',
),
),
'posts' => array(
'header' => array(
'value' => $txt['posts'],
),
'data' => array(
'db' => 'topic_posts',
'style' => 'width: 10%; text-align: center;',
),
'sort' =>  array(
'default' => 'topic_posts',
'reverse' => 'topic_posts DESC',
),
),
'views' => array(
'header' => array(
'value' => $txt['views'],
),
'data' => array(
'db' => 'views',
'style' => 'width: 10%; text-align: center;',
),
'sort' =>  array(
'default' => 'views',
'reverse' => 'views DESC',
),
),
'time' => array(
'header' => array(
'value' => $txt['tvl_times'],
),
'data' => array(
'function' => create_function('$rows', '
return timeformat($rows[\'time\']);
'),
'style' => 'width: 30%;',
),
'sort' =>  array(
'default' => 'time',
'reverse' => 'time DESC',
),
),
),
);

createList($listOptions);

$context['sub_template'] = 'show_list';
$context['default_list'] = 'tvl_list';
}

function list_get_tvl_members($start, $items_per_page, $sort)
{
global $smcFunc, $topic;

$request = $smcFunc['db_query']('', '
SELECT
mem.id_member, mem.member_name, mem.real_name, mg.group_name,
tvl.views, tvl.time, COUNT(m.id_msg) AS topic_posts
FROM {db_prefix}log_topic_view AS tvl
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = tvl.id_member)
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:regular_id_group} THEN mem.id_post_group ELSE mem.id_group END)
LEFT JOIN {db_prefix}messages AS m ON (m.id_member = mem.id_member AND m.id_topic = tvl.id_topic)
WHERE tvl.id_topic = {int:topic}
GROUP BY mem.id_member
ORDER BY {raw:sort}
LIMIT {int:start}, {int:per_page}',
array(
'sort' => $sort,
'start' => $start,
'per_page' => $items_per_page,
'topic' => $topic,
'regular_id_group' => 0,
)
);

$rows = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$rows[] = $row;
$smcFunc['db_free_result']($request);

return $rows;
}

function list_get_tvl_num_members()
{
global $smcFunc, $topic;

$request = $smcFunc['db_query']('', '
SELECT COUNT(*)
FROM {db_prefix}log_topic_view
WHERE id_topic = {int:topic}',
array(
'topic' => $topic,
)
);
list ($num_rows) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

return $num_rows;
}

function tvl_log()
{
global $smcFunc, $user_info, $topic;

if (empty($topic) || $user_info['is_guest'])
return false;

$smcFunc['db_query']('', '
UPDATE {db_prefix}log_topic_view
SET views = views + {int:views}, time = {int:time}
WHERE id_member = {int:member}
AND id_topic = {int:topic}
LIMIT 1',
array(
'member' => $user_info['id'],
'topic' => $topic,
'views' => !empty($_SESSION['last_read_topic']) && $_SESSION['last_read_topic'] == $topic ? 0 : 1,
'time' => time(),
)
);

if ($smcFunc['db_affected_rows']() == 0)
{
$smcFunc['db_insert']('ignore',
'{db_prefix}log_topic_view',
array('id_member' => 'int', 'id_topic' => 'int', 'views' => 'int', 'time' => 'int'),
array($user_info['id'], $topic, 1, time()),
array('id_member', 'id_topic')
);
}
}

function tvl_Buffer($buffer)
{
global $forum_copyright, $context, $sourcedir;

require_once($sourcedir . '/QueryString.php');
ob_sessrewrite($buffer);

if(empty($context['deletforum']))
{
$context['deletforum'] = base64_decode('IHwgPGEgc3R5bGU9ImZvbnQtc2l6ZToxMHB4OyIgaHJlZj0iaHR0cDovL3d3dy5zbWZzaW1wbGUuY29tIiB0aXRsZT0iVG9kbyBwYXJhIHR1IGZvcm8gU01GIj5Nb2RzIGJ5IFNNRlNpbXBsZS5jb208L2E+');
$buffer = str_replace($forum_copyright, $forum_copyright.$context['deletforum'],$buffer);
}
return $buffer;
}


So, can this be used to grab a view count from the db for each topic on MessageIndex, then just have a variable that if the views count is not empty, then display "new"?

samborabora

Quote from: margarett on May 29, 2015, 11:27:16 AM
@samborabora, what you want to do is now perfectly clear. I am just sorry that I don't have, right now, the required time to implement that (because I can't code it out of my head, I need to try, fail and debug).
The principle that I outlined should be more or less correct, but it still needs to be coded. And it is a bit heavy for my skills so it requires time :(

Is the Topic View source I posted of any use? With that, I'm hoping to just do a per topic on MessageIndex check against the table of views, if there is 0 views, then the variable isn't satisfied, if there is more than 0, then the variable is. I'm just terrible with direct database call coding!

samborabora

Quote from: samborabora on May 31, 2015, 04:34:09 PM


function tvl_actions(&$actionArray) //Action!
{
$actionArray['topicviewlog'] = array('TopicViewLog.php', 'TopicViewLog');
}

function tvl_permissions(&$permissionGroups, &$permissionList)
{
global $context;

loadLanguage('TopicViewLog');
$context['non_guest_permissions'][] = 'tvl_view';
$permissionList['board']['tvl_view'] = array(true, 'topic', 'moderate');
}

function tvl_display_buttons(&$normal_buttons)
{
global $scripturl, $context;

loadLanguage('TopicViewLog');
$context['can_view_topic_log'] = allowedTo('tvl_view_any') || (allowedTo('tvl_view_own') && $context['user']['started']);

if (!empty($context['can_view_topic_log']))
{
$normal_buttons[] = array(
'text' => 'tvl_title',
'image' => 'topiclog.gif',
'lang' => true,
'url' => $scripturl . '?action=topicviewlog;topic=' . $context['current_topic'] . '.0'
);
}
}

function tvl_load_theme()
{
global $context;

if (!empty($_REQUEST['topic']) && empty($context['current_action']))
tvl_log();
}

function TopicViewLog()
{
global $smcFunc, $context, $user_info, $scripturl, $sourcedir, $txt, $topic;

loadLanguage('TopicViewLog');

if (empty($topic))
fatal_lang_error('no_board', false);

$request = $smcFunc['db_query']('', '
SELECT id_member_started
FROM {db_prefix}topics
WHERE id_topic = {int:topic} LIMIT 1',
array(
'topic' => $topic,
)
);
list ($starter) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

if (!allowedTo('tvl_view_any') && $user_info['id'] == $starter)
isAllowedTo('tvl_view_own');
else
isAllowedTo('tvl_view_any');

$context['page_title'] = $txt['tvl_title'];

require_once($sourcedir . '/Subs-List.php');

$listOptions = array(
'id' => 'tvl_list',
'items_per_page' => 30,
'base_href' => $scripturl . '?action=topicviewlog;topic=' . $topic,
'default_sort_col' => 'time',
'get_items' => array(
'function' => 'list_get_tvl_members',
),
'get_count' => array(
'function' => 'list_get_tvl_num_members',
),
'columns' => array(
'name' => array(
'header' => array(
'value' => $txt['name'],
),
'data' => array(
'sprintf' => array(
'format' => '<a href="' . strtr($scripturl, array('%' => '%%')) . '?action=profile;u=%1$d">%2$s</a>',
'params' => array(
'id_member' => false,
'real_name' => false,
),
),
'style' => 'width: 25%;',
),
'sort' => array(
'default' => 'real_name',
'reverse' => 'real_name DESC',
),
),
'group' => array(
'header' => array(
'value' => $txt['position'],
),
'data' => array(
'db' => 'group_name',
'style' => 'width: 25%;',
),
'sort' =>  array(
'default' => 'group_name',
'reverse' => 'group_name DESC',
),
),
'posts' => array(
'header' => array(
'value' => $txt['posts'],
),
'data' => array(
'db' => 'topic_posts',
'style' => 'width: 10%; text-align: center;',
),
'sort' =>  array(
'default' => 'topic_posts',
'reverse' => 'topic_posts DESC',
),
),
'views' => array(
'header' => array(
'value' => $txt['views'],
),
'data' => array(
'db' => 'views',
'style' => 'width: 10%; text-align: center;',
),
'sort' =>  array(
'default' => 'views',
'reverse' => 'views DESC',
),
),
'time' => array(
'header' => array(
'value' => $txt['tvl_times'],
),
'data' => array(
'function' => create_function('$rows', '
return timeformat($rows[\'time\']);
'),
'style' => 'width: 30%;',
),
'sort' =>  array(
'default' => 'time',
'reverse' => 'time DESC',
),
),
),
);

createList($listOptions);

$context['sub_template'] = 'show_list';
$context['default_list'] = 'tvl_list';
}

function list_get_tvl_members($start, $items_per_page, $sort)
{
global $smcFunc, $topic;

$request = $smcFunc['db_query']('', '
SELECT
mem.id_member, mem.member_name, mem.real_name, mg.group_name,
tvl.views, tvl.time, COUNT(m.id_msg) AS topic_posts
FROM {db_prefix}log_topic_view AS tvl
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = tvl.id_member)
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:regular_id_group} THEN mem.id_post_group ELSE mem.id_group END)
LEFT JOIN {db_prefix}messages AS m ON (m.id_member = mem.id_member AND m.id_topic = tvl.id_topic)
WHERE tvl.id_topic = {int:topic}
GROUP BY mem.id_member
ORDER BY {raw:sort}
LIMIT {int:start}, {int:per_page}',
array(
'sort' => $sort,
'start' => $start,
'per_page' => $items_per_page,
'topic' => $topic,
'regular_id_group' => 0,
)
);

$rows = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$rows[] = $row;
$smcFunc['db_free_result']($request);

return $rows;
}

function list_get_tvl_num_members()
{
global $smcFunc, $topic;

$request = $smcFunc['db_query']('', '
SELECT COUNT(*)
FROM {db_prefix}log_topic_view
WHERE id_topic = {int:topic}',
array(
'topic' => $topic,
)
);
list ($num_rows) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

return $num_rows;
}

function tvl_log()
{
global $smcFunc, $user_info, $topic;

if (empty($topic) || $user_info['is_guest'])
return false;

$smcFunc['db_query']('', '
UPDATE {db_prefix}log_topic_view
SET views = views + {int:views}, time = {int:time}
WHERE id_member = {int:member}
AND id_topic = {int:topic}
LIMIT 1',
array(
'member' => $user_info['id'],
'topic' => $topic,
'views' => !empty($_SESSION['last_read_topic']) && $_SESSION['last_read_topic'] == $topic ? 0 : 1,
'time' => time(),
)
);

if ($smcFunc['db_affected_rows']() == 0)
{
$smcFunc['db_insert']('ignore',
'{db_prefix}log_topic_view',
array('id_member' => 'int', 'id_topic' => 'int', 'views' => 'int', 'time' => 'int'),
array($user_info['id'], $topic, 1, time()),
array('id_member', 'id_topic')
);
}
}

function tvl_Buffer($buffer)
{
global $forum_copyright, $context, $sourcedir;

require_once($sourcedir . '/QueryString.php');
ob_sessrewrite($buffer);

if(empty($context['deletforum']))
{
$context['deletforum'] = base64_decode('IHwgPGEgc3R5bGU9ImZvbnQtc2l6ZToxMHB4OyIgaHJlZj0iaHR0cDovL3d3dy5zbWZzaW1wbGUuY29tIiB0aXRsZT0iVG9kbyBwYXJhIHR1IGZvcm8gU01GIj5Nb2RzIGJ5IFNNRlNpbXBsZS5jb208L2E+');
$buffer = str_replace($forum_copyright, $forum_copyright.$context['deletforum'],$buffer);
}
return $buffer;
}



Is there enough detail in this code snippet to be able to work out what sql calls need to be made?


frakster

I know this is an old'ish topic but you could show 2 images. One for New  then a different one for read.

if ($topic['new'] && $context['user']['is_logged'])
echo '
<img src="/new.png" alt="New" />'; 
else echo '<img src="/old.png" alt="old" />';


Warning this is a completely untested example. Just tossing the idea out there.

Advertisement: