Thanks for SMF 2.1

Started by GL700Wing, May 19, 2022, 07:25:39 PM

Previous topic - Next topic

GL700Wing

Link to the mod

Thanks for SMF 2.1 - v1.4

This mod is a 'Thanks' version of the 'Likes' feature that is a standard part of SMF 2.1.

For those who want/need a 'Thanks' feature, it provides a consistent look/feel and the same functionality the default SMF 2.1 'Likes' feature.

Notes:
All the source code for this mod is derived from the SMF 2.1 'Likes' system.
Apart from replacing the 'Like' word with the equivalent 'Thank' word the only other source code changes are as follows:
1. Configure an icon for the 'Thank' action/alert and an icon for the 'Unthank' action; and
2. Configure extra spacing to the left of the 'Thank' button in a message if the 'Likes' feature is also enabled.



Release History:
1.0 - 13-May-22
o Initial Release with support only for SMF 2.1.2

1.1 - 26-May-22
o As per this message specified resources in 'db-install.php' to enable mod to install on large forums.
o Fixed bug in './Themes/default/scripts/topic.js' that prevented 'Quick Edit' feature from working.

1.2 - 19-Jun-22
o As per this message fixed issue of incorrect thank/unthank icons being displayed and of thank/unthank text/icon not maintaining left spacing in relation to the like/unlike text/icon.

1.3 - 10-Jun-23
o As per this message fixed issue where clicking on Thank button repeatedly in quick succession generated a database error.
o Updated core and mod files to incorporate changes made in SMF 2.1.4 to inbuilt 'Likes' system.
o Added 'import-thanks.php' script to import 'Thanks'' created by SMF 2.0 'Thank Posts' mod - based on code provided by shawnb61 for importing ''Likes' from SMF 2.0.

1.4 - 19-Nov-23
o As per this report by @Dave J fixed issue that caused '500 internal server error' when trying to view who had liked a post (the same issue also prevented the removal of a thank).
o Made some minor changes to core files that were missed in v1.3 (these changes specifically relate to the adaptation of the inbuilt SMF 2.1.4  'Likes' system to this mod).




License
Copyright 2022-2023 Kathy Leslie

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

gevv

Hi, thanks @GL700Wing

I think it will be very difficult to install in the big forum.

I tried (my pc wampserver) 4 minutes later, the white page opened,

index.php?action=admin;area=packages;sa=install2;package=Thanks_for_SMF21_v1.0.zip;pid=0

the mod was not installed (didn't create error log)

ElkArte is a modern, powerful community building forum software. https://www.elkarte.net/

GL700Wing

Quote from: gevv on May 20, 2022, 03:00:49 PMI think it will be very difficult to install in the big forum.

I tried (my pc wampserver) 4 minutes later, the white page opened,

index.php?action=admin;area=packages;sa=install2;package=Thanks_for_SMF21_v1.0.zip;pid=0

the mod was not installed (didn't create error log)
The mod installation makes some database changes (ie, creates the 'user_thanks' table, adds a 'thanks' column and index to the 'messages' table, and adds a 'msg_thank' row to the alerts table) and I suspect that on a large forum  a timeout is occurring then the 'messages' table is being updated.

I've attached a replacement db_install.php file to which I've added the following lines before any changes are made to the database:
// Secure some resources
@set_time_limit(600);
@ini_set('mysql.connect_timeout', -1);
@ini_set('default_socket_timeout', 900);
@ini_set('memory_limit', '512M');

I've used the same values that are in the 'upgrade'php' file that is run when a forum is upgraded from SMF 2.0 to SMF 2.1 - you may need to adjust these values if you used different values when upgrading or if you still get timeout issues when installing this mod (you may need to check/adjust the corresponding timeout values configured in cPanel as well).
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

gevv

Thanks @GL700Wing  Adding code worked. It took a while, but it was installed and working without any problems.
ElkArte is a modern, powerful community building forum software. https://www.elkarte.net/

GL700Wing

#4
Version 1.1 - 25-May-22
o As per this message specified reources in 'db-install.php' to enable mod to install on large forums.
o Fixed bug in './Themes/default/scripts/topic.js' that prevented 'Quick Edit' feature from working.


Note: Upgrade option for v1.0

@gevv - FYI
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

Steve

Will this give an alert like the 'like' feature?
DO NOT pm me for support!

GL700Wing

Quote from: Steve on June 18, 2022, 01:28:48 PMWill this give an alert like the 'like' feature?
Yes.

All the source code for this mod is derived from the SMF 2.1 'Likes' system.
Apart from replacing the 'Like' word with the equivalent 'Thank' word the only other source code changes are as follows:
1. Configure an icon for the 'Thank' action/alert and an icon for the 'Unthank' action; and
2. Configure extra spacing to the left of the 'Thank' button in a message if the 'Likes' feature is also enabled.
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

Steve

I read all that in your initial post lol ... just wanted to be sure it gave an alert. Thanks GL.  :)
DO NOT pm me for support!

GL700Wing

Quote from: Steve on June 18, 2022, 07:10:40 PMI read all that in your initial post lol ... just wanted to be sure it gave an alert. Thanks GL.  :)
Yep - I have tested and confirmed that the alerts are generated!
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

Steve

It installed without a hitch and works but there a couple of issues.

The 'Thank' icon and text move when clicked and again when unthanked. A refresh shows it in the original position.

If you click 'Thank', then 'Unthank', then 'Thank' again, another refresh is needed to show it in the correct spot instead right next to 'Like'.

When 'Thank' is clicked a thumb down appears in order to unthank. However, if you refresh after clicking 'Thank', the thumb down becomes a red x.

It's getting late so I can give you screenshots of what I'm talking about in the morning if you want them.
DO NOT pm me for support!

GL700Wing

#10
Quote from: Steve on June 18, 2022, 07:41:52 PMIt installed without a hitch and works but there a couple of issues.

The 'Thank' icon and text move when clicked and again when unthanked. A refresh shows it in the original position.

If you click 'Thank', then 'Unthank', then 'Thank' again, another refresh is needed to show it in the correct spot instead right next to 'Like'.

When 'Thank' is clicked a thumb down appears in order to unthank. However, if you refresh after clicking 'Thank', the thumb down becomes a red x.

It's getting late so I can give you screenshots of what I'm talking about in the morning if you want them.
Thanks for the feedback.

The icons for the 'thank'/'unthank' actions are a tick and a cross/X so I don't understand why the thumb up/down icons are coming into play or why a refresh is sometimes needed for stuff to display correctly.  These issues didn't occur when I was testing the mod but it could be related to a different browser/OS to what I'm using - I'll have to check the Javascript again ...

PS:  Confirmed and found cause of thumbup/thumbdown  icon issue and text/icon moving - working on a fix now ...
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

GL700Wing

Version 1.2 - 19-Jun-22
o As per this message fixed issue of incorrect thank/unthank icons being displayed and of thank/unthank text/icon not maintaining left spacing in relation to the like/unlike text/icon.


Note: Upgrade option available for v1.0 and v1.1

@Steve - thanks for reporting the issues and apologies for not identifying them during original testing.

Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

Steve

No worries GL. That's what you have us for, to find things that may have gotten missed.  ;D

Works beautifully now.
DO NOT pm me for support!

sevamaster

Hello,
Tell me please, doesn't your mod conflict with "Pretty URLs" mod?

I have not install your mod yet. But I have that conflict with "Say Thanks" mod.

So, I want to know if I will not get the same result with your mod.

Thank you.

Steve

To be honest, it's not the mod author's responsibility to ensure that their mod doesn't conflict with any other. Conflicts can be reported and they may take a look at why.

In your case, backup your forum, uninstall the Say Thanks mod if you haven't already and try installing this one. I had errors with the Say Thanks mod (no offense to that mod's author) but this one works perfectly.
DO NOT pm me for support!

Steve

If I accidentally hit the thanks button twice in rapid succession instead of once I get this error (twice):

Type of error
Database
Error message
Database Error: Duplicate entry '224902-msg-1' for key 'PRIMARY'
File
/home/steve/public_html/forums/Sources/Thanks.php
Line
314
URL of page causing the error
https://myforum/index.php?action=thanks;ltype=msg;sa=thank;thank=224902;f9f55c68=f139920d391efaf1fa359848cc5f9b0e;js=1&_=1665659189529
Backtrace information

    #0: smf_db_error()
    Called from /home/steve/public_html/forums/Sources/Subs-Db-mysql.php on line 494
    #1: smf_db_query()
    Called from /home/steve/public_html/forums/Sources/Subs-Db-mysql.php on line 802
    #2: smf_db_insert()
    Called from /home/steve/public_html/forums/Sources/Thanks.php on line 314
    #3: insert()
    Called from /home/steve/public_html/forums/Sources/Thanks.php on line 398
    #4: thank()
    Called from /home/steve/public_html/forums/Sources/Thanks.php on line 150
    #5: call()
    Called from /home/steve/public_html/forums/index.php on line 191

I have Essential Tremors so this happens to me a lot and I was wondering if there was an easy way to stop it from doing this? If not, it's not a problem, I know this is a niche case. :)
DO NOT pm me for support!

jsx

Hello @GL700Wing

This mod cannot be installed normally on SMF 2.1.3:



Only when I install by emulating 2.1.2

GL700Wing

Quote from: Steve on October 13, 2022, 07:25:33 AMIf I accidentally hit the thanks button twice in rapid succession instead of once I get this error (twice):

Type of error
Database
Error message
Database Error: Duplicate entry '224902-msg-1' for key 'PRIMARY'
File
/home/steve/public_html/forums/Sources/Thanks.php
Line
314
URL of page causing the error
https://myforum/index.php?action=thanks;ltype=msg;sa=thank;thank=224902;f9f55c68=f139920d391efaf1fa359848cc5f9b0e;js=1&_=1665659189529
Backtrace information

    #0: smf_db_error()
    Called from /home/steve/public_html/forums/Sources/Subs-Db-mysql.php on line 494
    #1: smf_db_query()
    Called from /home/steve/public_html/forums/Sources/Subs-Db-mysql.php on line 802
    #2: smf_db_insert()
    Called from /home/steve/public_html/forums/Sources/Thanks.php on line 314
    #3: insert()
    Called from /home/steve/public_html/forums/Sources/Thanks.php on line 398
    #4: thank()
    Called from /home/steve/public_html/forums/Sources/Thanks.php on line 150
    #5: call()
    Called from /home/steve/public_html/forums/index.php on line 191

I have Essential Tremors so this happens to me a lot and I was wondering if there was an easy way to stop it from doing this? If not, it's not a problem, I know this is a niche case. :)
@Steve I can't reproduce this error but I think it can be fixed by replacing the 'insert' mode with the 'ignore' mode for the 'db_insert' operations as follows:

In ./Sources/Thanks.php

Find:
        // Insert the thank.
        $smcFunc['db_insert']('insert',

Replace With:
        // Insert the thank.
        $smcFunc['db_insert']('ignore',


Find:
        if ($this->_type == 'msg')
            $smcFunc['db_insert']('insert',

Replace With:
        if ($this->_type == 'msg')
            $smcFunc['db_insert']('ignore',

Just wondering if you can make and test these changes and let me know the results (they won't prevent the mod from subsequently being uninstalled or upgraded).



Quote from: jsx on November 30, 2022, 04:39:06 AMThis mod cannot be installed normally on SMF 2.1.3:



Only when I install by emulating 2.1.2
@jsx Based on the testing I've done it's only an installer issue (ie, the mod works with SMF 2.1.3) and I'll update the installer to support SMF 2.1.3 when I've solved the issue @Steve reported.
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

Steve

I've made the changes and the mod seems to be working normally. I can't definitively say it's fixed the problem but it appears to have. I tried hitting the Thanks as rapidly as I could with no issues.

Since it works with the changes made, I'd say go ahead and fix the installer issue.

And many thanks GL.  :)  (no pun intended :P )
DO NOT pm me for support!

Steve

Problem ... if I add a new theme, the thanks link doesn't show up. I was going to uninstall and reinstall this but the Package Manager wants me to uninstall while emulating 2.1.2 but doing that gives me a multitude of errors on the uninstall test it does before the actual uninstall.

I know I could manually fix the errors but is there an easier way to do this?
DO NOT pm me for support!

Diego Andrés

I'd say just add the changes that modify files that the new theme has.
I'd imagine that Display.template.php is be the main file to modify in this case.

SMF Tricks - Free & Premium Responsive Themes for SMF.

Steve

Thanks Diego, that's what I'll do until GL gets back.  :)
DO NOT pm me for support!

GL700Wing

v1.3 - 10-Jun-23
o As per this message fixed issue where clicking on Thank button repeatedly in quick succession generated a database error.
o Updated core files to incorporate changes made to inbuilt Likes system.
o Added 'import-thanks.php' script to import 'Thanks' created by SMF 2.0 'Thank Posts' mod - based on code provided by shawnb61 for importing 'Likes' from SMF 2.0.
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

Dave J

Hi GL,

For some reason on 3 different sites when looking to see who thanked a post I get the error as in the image. At first I thought it was something to do with my main site but then I installed it in my other 2 sites and it's the same on there too.

The main site is on SMF2.1.4
PHP8.2.3

the other site is SMF2.1.4
PHP 8.0.28
If you want quizzes to add to the new SMF2.1 quiz mod go here . There are also walkthroughs in the forum to explain how to install them and other tips.

Doug Heffernan

Quote from: Dave J on November 18, 2023, 08:05:28 AMFor some reason on 3 different sites when looking to see who thanked a post I get the error as in the image. At first I thought it was something to do with my main site but then I installed it in my other 2 sites and it's the same on there too.

That type of error is almost always server related. Any specific message(s) logged in either at the forum error lor or server error log?

Dave J

#25
Quote from: Doug Heffernan on November 18, 2023, 08:52:36 AM
Quote from: Dave J on November 18, 2023, 08:05:28 AMFor some reason on 3 different sites when looking to see who thanked a post I get the error as in the image. At first I thought it was something to do with my main site but then I installed it in my other 2 sites and it's the same on there too.

That type of error is almost always server related. Any specific message(s) logged in either at the forum error lor or server error log?

Nothing related to that Doug. The only server error yesterday was for
Cron reschedule event error for hook: then the next previous error was September.

Just in case it was related to the host I just installed the mod on my NAS drives SMF2.1.4 install and it does the same there too.

If you want quizzes to add to the new SMF2.1 quiz mod go here . There are also walkthroughs in the forum to explain how to install them and other tips.

GL700Wing

Version 1.4 - 19-Nov-23
o As per this report by @Dave J fixed issue that caused '500 internal server error' when trying to view who had liked a post (the same issue also prevented the removal of a thank).
o Made some minor changes to core files that were missed in v1.3 (these changes specifically relate to the adaptation of the inbuilt SMF 2.1.4  'Likes' system to this mod).


Note: There is an upgrade option for all previous versions of this mod.
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

Dave J

Quote from: GL700Wing on November 19, 2023, 01:53:51 AMVersion 1.4 - 19-Nov-23
o As per this report by @Dave J fixed issue that caused '500 internal server error' when trying to view who had liked a post (the same issue also prevented the removal of a thank).
o Made some minor changes to core files that were missed in v1.3 (these changes specifically relate to the adaptation of the inbuilt SMF 2.1.4  'Likes' system to this mod).


Note: There is an upgrade option for all previous versions of this mod.


Thanks very much GL.

Tested on my NAS and it's all working as it should.
If you want quizzes to add to the new SMF2.1 quiz mod go here . There are also walkthroughs in the forum to explain how to install them and other tips.

console.log.myName

Hi. We have a problem with Cyrillic. Immediately after you click on the "thank you" button, the text with the wrong encoding appears. But after updating the page, everything is ok. How can I fix this?


GL700Wing

Quote from: console.log.myName on January 27, 2024, 09:01:49 PMHi. We have a problem with Cyrillic. Immediately after you click on the "thank you" button, the text with the wrong encoding appears. But after updating the page, everything is ok. How can I fix this?


Do you have the same issue with the inbuilt Likes system?
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

console.log.myName

Quote from: GL700Wing on January 27, 2024, 09:37:42 PM
Quote from: console.log.myName on January 27, 2024, 09:01:49 PMHi. We have a problem with Cyrillic. Immediately after you click on the "thank you" button, the text with the wrong encoding appears. But after updating the page, everything is ok. How can I fix this?
Do you have the same issue with the inbuilt Likes system?
No

GL700Wing

Quote from: console.log.myName on January 27, 2024, 10:41:13 PM
Quote from: GL700Wing on January 27, 2024, 09:37:42 PMDo you have the same issue with the inbuilt Likes system?
No
Interesting given this mod is a clone of the inbuilt 'Likes' system - I'll look into it.
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

console.log.myName

Quote from: GL700Wing on January 27, 2024, 11:06:52 PM
Quote from: console.log.myName on January 27, 2024, 10:41:13 PM
Quote from: GL700Wing on January 27, 2024, 09:37:42 PMDo you have the same issue with the inbuilt Likes system?
No
Interesting given this mod is a clone of the inbuilt 'Likes' system - I'll look into it.
Ok, thank you.
We will waiting update or fix...

console.log.myName

Do you have a news about fix?

GL700Wing

#34
Quote from: console.log.myName on February 28, 2024, 01:46:42 PMDo you have a news about fix?
No - not yet unfortunately because I've been very busy working on another mod and getting ready for some upcoming trips. 

That said, I should have some time to look into this issue within the next few days.
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

GL700Wing

OK - I've looked into this issue but I cannot reproduce it on an SMF 2.1 forum that has the Russian language installed, the 'Likes' feature enabled and the 'Thanks' mod installed.

I added the following strings (Google translated but no guarantee they are correct) to the index.russian.php file and changed the language for one of my users to Russian.
// Thanks mod.
$txt['thanks'] = 'Спасибо';
$txt['thank'] = 'Спасибо';
$txt['unthank'] = 'Не благодарить';
$txt['thank_success'] = 'Ваш контент был успешно поблагодарён.';
$txt['thank_delete'] = 'Ваш контент был успешно удален.';
$txt['thank_insert'] = 'Ваш контент был успешно вставлен.';
$txt['thank_error'] = 'В вашем запросе произошла ошибка.';
$txt['thank_disable'] = 'Функция «Спасибо» отключена.';
$txt['not_valid_thank_type'] = 'Выбранный тип не является допустимым.';
// Translators, if you need to make more strings to suit your language, e.g. $txt['thanks_2'] = 'Two people thank this', please do so.
$txt['thanks_1'] = '<a href="%1$s">%2$s человек</a> поблагодарил.';
$txt['thanks_n'] = '<a href="%1$s">%2$s человек</a> поблагодарили это.';
$txt['you_thanks_0'] = 'Вы поблагодарили за это.';
$txt['you_thanks_1'] = 'Вы и <a href="%1$s">%2$s другой человек</a> поблагодарили это.';
$txt['you_thanks_n'] = 'Вы и <a href="%1$s">%2$s других людей</a> поблагодарили это.';

I suspect this may be a JavaScript conflict with some other mod you have installed and I noticed the word 'PLAY' in the image you attached and that is definitely not something to do with this mod - what other mods do you have installed?
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

Advertisement: