[Free] Logging Members Who Viewed Topic(s)

Started by Hambo, October 24, 2024, 11:21:57 PM

Previous topic - Next topic

Hambo

FOR SMF VERSION: 2.1.4

DESCRIPTION:
Hi. I am currently running SMF 2.1.4 and I have used the latest SMF at the time for the years of 2017(?) with a mod/plugin where after the end of every topic, there would be a list of users who had taken a look at it if they are logged in with a date which implied "last read on.."

Example; 1 topic has been made with 3 responses from other viewers and at the bottom of that 4th post or whichever, there would either be a button that you press and it shows all the people who viewed it in a new window. Or at the very bottom listing all the users who looked at it such as..
    MEMBER A (09 - 13 - 2020), MEMBER B ( 11 - 30 - 2021 )

And if the same MEMBER A viewed it again, it would overwrite to where it would be MEMBER A ( 12 - 01 - 2021 )


I have been searching for days on the Modifications and the closest I can find are the 2.0.x ones located below but I can't fully remember which ones were the ones I used if at all. Last update or mentions of them were years ago and I get the "It has been over 120 days+.." unless I really have to warning.

Who has Read this Topic - https://www.simplemachines.org/community/index.php?topic=559171.0
Topic View Log - https://www.simplemachines.org/community/index.php?topic=538187.0


PERMISSIONS:
For Admin and Moderator use (separate ticking).


Hambo

#2
Quote from: Doug Heffernan on October 25, 2024, 08:10:22 AM
Quote from: Hambo on October 24, 2024, 11:21:57 PMWho has Read this Topic - https://www.simplemachines.org/community/index.php?topic=559171.0

My mod should work on 2.1.x as well.

Oh hi mod creator! I get an error (actually 2 errors but the error looks to be the same but just different theme's display template php file thing) when attempting to install this earlier so I held off on it due to my very limited understanding of php.

The error shows when trying to replace/add code in
./Themes/default/Display.template.php


Where would I need to manually add that code
Quote// Allow adding new buttons easily.
   call_integration_hook('integrate_display_buttons', array(&$normal_buttons));
   
   //Add the link to display the topic viewers button. We will style it a bit to stand out
   if($context['can_moderate_forum'])
   echo '
         <span style="background-color: #e7e7e7; border: none; border-radius: 12px; color: white; padding: 10px 24px; text-align: center; text-decoration: none; display: inline-block; font-size: 12px; font-weight: bold;"><a href="' . $scripturl . '?topic='. $context['current_topic'] . '.0;log=topicviews">', $txt['topic_viewers_link'] ,'</a></span>
   ';
to which function?


As to note, the mod was just recently installed at the time of this post while ignoring the error above. I was unable to find any button called Log Views under the topic title after posting a topic. So I think.. I have to manually add that bit of code in to finally make it work? As the code did not install into the specified php file by itself.


Doug Heffernan

Quote from: Hambo on October 25, 2024, 12:47:41 PMbut just different theme's display template php file thing)

In that case it looks like the custom themes that you are using have altered the aforementioned files. That explains the error. That being said, look up the code in the default smf file and then compare it with that of the custom theme and experiment with it until you get it right.


Hambo

On a fresh 2.0.x install, it works where I have been comparing both 2.1.4 (the one I am using) and 2.0.x display.template.php files.
I put the code in the location above the code below as I noticed it was above it in 2.0.x.
Quote// Show the page index... "Pages: [1]".
   echo '
      <div class="pagesection top">
         ', template_button_strip($context['normal_buttons'], 'right'), '
         ', $context['menu_separator'], '
         <div class="pagelinks floatleft">
            <a href="#bot" class="button">', $txt['go_down'], '</a>
            ', $context['page_index'], '
         </div>';


I have done my best in applying where I thought it worked just enough to see the little circle/bubble button where the text Viewer Log should be in (as it was located in the same place as 2.0.x). As I go to every topic or refresh a topic in 2.1.4, it logs errors repeatedly under
Quote2: Undefined array key "topic_viewers_link"
Where it references
Quote$txt['topic_viewers_link']
From the line,
Quote<span style="background-color: #e7e7e7; border: none; border-radius: 12px; color: white; padding: 10px 24px; text-align: center; text-decoration: none; display: inline-block; font-size: 12px; font-weight: bold;"><a href="' . $scripturl . '?topic='. $context['current_topic'] . '.0;log=topicviews">', $txt['topic_viewers_link'] ,'</a></span>


I do not know how to fix the undefined array key (I tried deleting that $txt['topic_viewers_link'] but it did nothing aside from stopping generating the error in the error log). Also I have just figured how to upload screenshots/images on here.

Doug Heffernan

Quote from: Hambo on October 25, 2024, 06:02:34 PMUndefined array key "topic_viewers_link"

Is said language string added to the Modifications.english.php file? As per our rules, it's best to post any custom mod/themesupport questions on their support topics. And I will try to help you there.

That being said, that mod is not very effcient as all topic views will be deleted if the mark as read button is used. Your post made me think maybe it's a good idea to develop a new mod that will avoid that and be 2.1.x compatible.

Hambo

Yes. The language string made it to that file, being the last before ?> as
Quote$txt['topic_viewers_link'] = 'Views Log';
$txt['topic_viewers'] = 'Here you can see the list of all users who read topic:';




I will mark this as solved as I move over to the other mod link topic due to possible renewed interest. Thank you so much. :D

Advertisement: