News:

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

Main Menu

@mention members

Started by Dragooon, May 02, 2014, 01:07:58 PM

Previous topic - Next topic

jsx

@Dragooon

The selection does not appear in this checkbox:

Enable mentions e-mail for current members

Whereas, the selection appears correctly in this checkbox:

Enable mentions e-mail by default

landyvlad

For anyone wanting to explain to their forum members how this mod is used feel free to copy
http://gsx1400owners.org/forum/index.php?topic=477.0
to your hearts content.  Cheers
"Put as much effort into your question as you'd expect someone to give in an answer"

Please do not PM, IM or Email me with questions on astrophysics or theology.  You will get better and faster responses by asking homeless people in the street. Thank you.

Be the person your dog thinks you are.

grzeg8102

Great mod! Very useful. Since I started being a user of a Discourse forum I dreamt of something similar in my my own SMF forum I'm running.

@Dragoon - I'm only missing the mod to run also on the recents page ("/index.php?action=recent"). Can you please add it? Hopefully it's nothing complex and only requires the function mentions_post_scripts(); to be called in one more place.

BTW. I'd like to share my CSS for it - it tries to mimic Discourse mention style. Attached

Shambles

Under PHP 7.1, when unchecking Profile > Profile Info > Mentions > E-mail mention notifications:





The (bool) cast within Mentions.php is no longer returning 0 when false; it's returning null, causing the above error.

Solution:

Sources/Mentions.php

Code (Find) Select

if (!empty($_POST['save']) && $user_info['id'] == $memID)
updateMemberData($memID, array('email_mentions' => (bool) !empty($_POST['email_mentions'])));


Code (Replace) Select

if (!empty($_POST['save']) && $user_info['id'] == $memID)
updateMemberData($memID, array('email_mentions' => empty($_POST['email_mentions']) ? 0 : 1));

Arantor

(bool) returns true or false, which would need to be explicitly cast to numbers to make that work - false, by default, implicit casts to empty string, not 0, unless explicit-casting to int.

Shambles

Yep - that's what was happening. Must have been different under 5.6 as that seemed to return 0?

With the change above it I now get 0 or 1 (obviously) instead of null or 1.

Arantor

Nope, those semantics have never changed. I'm assuming it's just always been left ticked - unlike false, true will convert to 1 as far as the DB library cares.

Shambles

I wonder how many people have tried to untick it? Not me, that's for sure.

I only spotted it when doing my routine checks on the error logs.


Quote... unlike false, true will convert to 1 ...

That implies the original code has always been imperfect, as far as setting a 0 or 1 into the int-only DB space.

Arantor


Xpresskonami

Quote from: jsx on April 05, 2019, 04:04:24 AM
@Dragooon

The selection does not appear in this checkbox:

Enable mentions e-mail for current members

Whereas, the selection appears correctly in this checkbox:

Enable mentions e-mail by default

I Want to Enable mentions e-mail for current members. I select the box, and the box is not selecting... any solutions please

jsx

Quote from: Xpresskonami on December 14, 2019, 05:54:51 AM
Quote from: jsx on April 05, 2019, 04:04:24 AM
@Dragooon

The selection does not appear in this checkbox:

Enable mentions e-mail for current members

Whereas, the selection appears correctly in this checkbox:

Enable mentions e-mail by default

I Want to Enable mentions e-mail for current members. I select the box, and the box is not selecting... any solutions please

Yes, but when you save this setting, this setting will work.

jsx

Quote from: Shambles on December 04, 2019, 02:34:33 PM
Under PHP 7.1, when unchecking Profile > Profile Info > Mentions > E-mail mention notifications:





The (bool) cast within Mentions.php is no longer returning 0 when false; it's returning null, causing the above error.

Solution:

Sources/Mentions.php

Code (Find) Select

if (!empty($_POST['save']) && $user_info['id'] == $memID)
updateMemberData($memID, array('email_mentions' => (bool) !empty($_POST['email_mentions'])));


Code (Replace) Select

if (!empty($_POST['save']) && $user_info['id'] == $memID)
updateMemberData($memID, array('email_mentions' => empty($_POST['email_mentions']) ? 0 : 1));


Such a mistake appears in the logs:





Is this the same mistake you mentioned?

Shambles

QuoteIs this the same mistake you mentioned?

Since it's a completely different error message from an entirely different region of Subs.php handling something not even close to a DB query, the answer has to be no.

jsx

Can anyone help me solve this error?

GL700Wing

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


rarecorp

Hello,

I was wondering if this mod or any other mods out there can tag a whole membergroup? Not a user-specific tag, but the whole user group that will be notified when tagged.

Thank you in advance.

Edit: I saw a mod hxxp:www.smfpacks.com/mentionsmod/ [nonactive] -- but it seems to be paid, anything free mod similar to this one?

Shambles

Is $9.99 over your budget?

GL700Wing

I've been using this mod since just after it was released (I use it on multiple forums) and I've made two enhancements to suit my needs.






The first is, if the option 'Enable mentions e-mail by default' is enabled, to also notify a member by PM that they have been mentioned and then to only send an email message if the member does not receive email notifications of PMs.

In ./Sources/Mentions.php
Find:
sendmail($mention['email_address'], $subject, $body)
Replace With:
// Send the mention notification by PM.
sendpm(array('to' => array($mention['id']), 'bcc' => array()), $subject, $body);

// If the member being mentioned does not receive email notifications of PMs send a separate email message.
$result = $smcFunc['db_query']('', '
SELECT id_member, pm_email_notify
FROM {db_prefix}members
WHERE id_member = {int:mention_id}',
array(
'mention_id' => (int) array($mention['id']),
)
);
$row = $smcFunc['db_fetch_assoc']($result);
$smcFunc['db_free_result']($result);
$pmMailNotify = ($row['pm_email_notify']);
if ($pmMailNotify == 0)
sendmail($mention['email_address'], $subject, $body);







The second is to enable forum admins to fix incorrectly formatted mentions in existing posts (eg, '@ name' instead of '@name') and to have the corrected mention attributed to the post author (by default the corrected mention is attributed to the member editing the post).

In ./Sources/Mentions.php
Find:
function mentions_process_store(array $mentions, $id_post, $subject, $approved = true)
{
global $smcFunc, $txt, $user_info, $scripturl;

Replace With:
function mentions_process_store(array $mentions, $id_post, $subject, $approved = true, $pa_id = 0, $pa_name = null)
{
global $smcFunc, $txt, $user_info, $scripturl;

// Check if the user editing post is the same as the post author.
$mention_member_id = $user_info['id'];
$mention_member_name = $user_info['name'];
if ($pa_id != $user_info['id'])
{
$mention_member_id = $pa_id;
$mention_member_name = $pa_name;
}


Find:
array($id_post, $user_info['id'], $mention['id'], time()),
Replace With:
// Use $mention_member_id instead of $user_info['id'].
array($id_post, $mention_member_id, $mention['id'], time()),


Find:
'MEMBERNAME' => $user_info['name'],
Replace With:
// Use $mention_member_name instead of $user_info['name'].
'MEMBERNAME' => $mention_member_name,





In ./Sources/Post.php
Find:
if (!empty($topic_info['locked']) && !allowedTo('moderate_board'))
Add Before:
// Added pa_id to user_info to enable Admins to correct mentions in existing posts and have the mention attributed to the post author.
$user_info['pa_id'] = $row['id_member'];


Find:
$posterOptions = array(
'id' => $user_info['id'],
'name' => $_POST['guestname'],
'email' => $_POST['email'],
'update_post_count' => !$user_info['is_guest'] && !isset($_REQUEST['msg']) && $board_info['posts_count'],

Add After:
// Added pa_id and pa_name to enable Admins to correct mentions in existing posts and have the mention attributed to the post author.
'pa_id' => isset($_REQUEST['msg']) && !empty($topic) ? $user_info['pa_id'] : $user_info['id'],
'pa_name' => $_POST['guestname'],





In ./Sources/Subs-Post.php
Find:


mentions_process_post($msgOptions, $topicOptions, $posterOptions);
if (!empty($msgOptions['mentions']))
mentions_process_store($msgOptions['mentions'], $msgOptions['id'], $msgOptions['subject'], $msgOptions['approved']);

Replace With:
// If an Admin is modifying another member's post to correct mentions have the mention attributed to the post author.
if ($user_info['is_admin'] && isset($posterOptions['pa_id']) && ($posterOptions['id'] !== $posterOptions['pa_id']))
{
$pa_posterOptions = $posterOptions;
$pa_posterOptions['id'] = $posterOptions['pa_id'];
$pa_posterOptions['name'] = $posterOptions['pa_name'];
mentions_process_post($msgOptions, $topicOptions, $pa_posterOptions);
}
else
mentions_process_post($msgOptions, $topicOptions, $posterOptions);

if (!empty($msgOptions['mentions']))
// Fix for bug - see https://www.simplemachines.org/community/index.php?topic=522005.msg3695332#msg3695332
// Added $posterOptions['pa_id'] and $posterOptions['pa_name'] to enable Admins to correct mentions in existing posts and have the mention attributed to the post author.
mentions_process_store($msgOptions['mentions'], $msgOptions['id'], $msgOptions['subject'], isset($msgOptions['approved']) ? $msgOptions['approved'] : 1, $posterOptions['pa_id'], $posterOptions['pa_name']);

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

landyvlad

"Put as much effort into your question as you'd expect someone to give in an answer"

Please do not PM, IM or Email me with questions on astrophysics or theology.  You will get better and faster responses by asking homeless people in the street. Thank you.

Be the person your dog thinks you are.

Advertisement: