Digests

Changing name in email - Digests

Changing name in email

by caseydev » Wed Sep 11, 2019 10:17 am

Hello!

I've modified our intranet board to use full names that are stored within the same table. Currently on 3.2 I'm handling this by hooking into core.modify_username_string and changing both 'username' and 'username_string' This works fine across the board, except for both Memberlist profile and Emailed Digests.

Could you assist me in pointing out what hooks I can use to change the names used by the digests?
caseydev
Registered User
Posts: 7
Joined: Tue Jul 23, 2019 9:54 am
Contact:

Re: Changing name in email

by MarkDHamill » Tue Sep 17, 2019 12:12 pm

You would probably have to modify /event/main_listener.php. I'm not sure how familiar you are with extensions, but changing PHP Core Events and creating listeners for extensions is discussed here:

https://area51.phpbb.com/docs/dev/3.1.x ... -listeners

You may need to change /config/services.yml as well if you need to pass new services to the program.
Get the latest versions of my Digests and Smartfeed extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.
User avatar
MarkDHamill
Registered User
Posts: 3942
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: Changing name in email

by caseydev » Tue Sep 17, 2019 2:58 pm

I come from WordPress, so I'm mostly discovering how to work with PHPBB by means of documentation and screaming.

I've built a seperate plugin that currently hooks into the above and changes the username elsewhere.

I've done some more digging, and I've seem to have achieved my desired result by changing line 791 of cron/task/digests.php.

Code: Select all

'S_DIGESTS_SALUTATION_BLURB' => $row['username'] . $this->language->lang('DIGESTS_COMMA'),
to

Code: Select all

'S_DIGESTS_SALUTATION_BLURB' => get_username_string( 'username', (int) $row['user_id'], (string) $row['username'] ) . $this->language->lang('DIGESTS_COMMA'),
Now the usernames pulled in via your digests plugin are now translated to full names. Other than the edit to your plugin, do you think I will encounter any troubles going down this route? I'm happy to keep internal references (e.g. admin) as usernames, just want the dear xxx to be showing full names instead.

EDIT: Clarified file and line no.
caseydev
Registered User
Posts: 7
Joined: Tue Jul 23, 2019 9:54 am
Contact:

Re: Changing name in email

by MarkDHamill » Wed Sep 18, 2019 12:41 pm

Unfortunately, if you upgrade digests you will have to reapply this code change. Did you create custom profile fields to hold the real first and last names of the user? I've scanned the function and it looks like it mostly colorizes the username.
Get the latest versions of my Digests and Smartfeed extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.
User avatar
MarkDHamill
Registered User
Posts: 3942
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: Changing name in email

by caseydev » Wed Sep 18, 2019 1:12 pm

MarkDHamill wrote:Unfortunately, if you upgrade digests you will have to reapply this code change. Did you create custom profile fields to hold the real first and last names of the user? I've scanned the function and it looks like it mostly colorizes the username.
Yeah the function seems to handle the formatting and display of usernames. Our plugin checks for when a 'username' (basically just the same string as the third argument returned, without colours or URL), but PHPBB have added a string modification hook, and in this which is where my background plugin jumps in and modifies the displayed username string to full name (stored as custom columns rather than custom fields, because apparently the original developer didn't RTFM about custom profile fields). That way it changes the username displayed to the user to our preferred visual style, but without modifying the username stored in the system.

I'm mostly out of the loop on PHPBB dev thanks to WordPress, so I don't know if this is actually helpful or a bad approach. I'm the sole system maintainer so I've added the modification to our docs.
caseydev
Registered User
Posts: 7
Joined: Tue Jul 23, 2019 9:54 am
Contact:

Re: Changing name in email

by MarkDHamill » Wed Sep 18, 2019 1:20 pm

I might offer an option in digests to select the custom profile fields you want to substitute for the username at some point. Until now, it's not been an issue.
Get the latest versions of my Digests and Smartfeed extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.
User avatar
MarkDHamill
Registered User
Posts: 3942
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: Changing name in email

by MarkDHamill » Fri Oct 04, 2019 11:13 pm

I'm testing a control that I think does what you want. See attached screenshot for the Digest General Settings page. It should show up in version 3.2.16.
Attachments
Screen Shot 2019-10-04 at 7.11.55 PM.png
Get the latest versions of my Digests and Smartfeed extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.
User avatar
MarkDHamill
Registered User
Posts: 3942
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: Changing name in email

by caseydev » Thu Oct 10, 2019 1:32 pm

MarkDHamill wrote:I'm testing a control that I think does what you want. See attached screenshot for the Digest General Settings page. It should show up in version 3.2.16.
Neat feature, thanks for implementing that!

Unfortunately for us our custom names are stored as custom columns instead of the correct way of using custom profile fields. I need to get round to migrating that in which case I'll definitely drop my modification for this proper method.
caseydev
Registered User
Posts: 7
Joined: Tue Jul 23, 2019 9:54 am
Contact: