Allow Tokens in Subject also

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
User avatar
wads24
Registered User
Posts: 512
Joined: Fri Jun 10, 2005 4:44 am
Name: James

Allow Tokens in Subject also

Post by wads24 » Tue Jan 08, 2019 7:18 pm

I am trying to edit the listener to allow the tokens to also be used in pmwelcome_subject like they are allowed in pmwelcome_post_text

I would appreciate any advice on making this edit.

From Welcome PM Message Extension. Nobody ever replies in the discussion group though.

Code: Select all

<?php
/**
*
* @package PM Welcome
* @copyright (c) bb3.mobi 2014 Anvar
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

namespace apwa\pmwelcome\event;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class listener implements EventSubscriberInterface
{
	/** @var \phpbb\user */
	protected $user;

	/** @var \phpbb\config\config */
	protected $config;

	/** @var \phpbb\config\db_text */
	protected $config_text;

	/** @var string phpbb_root_path */
	protected $phpbb_root_path;

	/** @var string phpEx */
	protected $php_ext;

	public function __construct(\phpbb\user $user, \phpbb\config\config $config, \phpbb\config\db_text $config_text, $phpbb_root_path, $php_ext)
	{
		$this->user = $user;
		$this->config = $config;
		$this->text = $config_text;
		$this->phpbb_root_path = $phpbb_root_path;
		$this->php_ext = $php_ext;
	}

	static public function getSubscribedEvents()
	{
		return array(
			'core.user_add_after'		=> 'pm_welcome',
			'core.ucp_activate_after'	=> 'pm_activate_welcome',
		);
	}

	public function pm_welcome($event)
	{
		$user_row = $event['user_row'];
		if ($user_row['user_type'] == USER_NORMAL)
		{
			$pwm_user = $this->config['pmwelcome_user'];
			$pwm_subject = $this->config['pmwelcome_subject'];
			$pwm_text = $this->text->get('pmwelcome_post_text');
			if ($pwm_user && $pwm_subject && $pwm_text)
			{
				$user_to = array(
					'user_id'	=> $event['user_id'],
					'username'	=> $user_row['username'],
					'user_email'   => $user_row['user_email'],
                    'sitename'   => $this->config['sitename'],
                    'site_desc'   => $this->config['site_desc'],
                    'board_contact'   => $this->config['board_contact'],
                    'board_email'   => $this->config['board_email'],
                    'board_email_sig'   => $this->config['board_email_sig'],
				);

				$this->user_welcome($user_to, $pwm_user, $pwm_subject, $pwm_text);
			}
		}
	}

	public function pm_activate_welcome($event)
	{
		$user_row = $event['user_row'];
		if (!$user_row['user_newpasswd'])
		{
			$pwm_user = $this->config['pmwelcome_user'];
			$pwm_subject = $this->config['pmwelcome_subject'];
			$pwm_text = $this->text->get('pmwelcome_post_text');
			if ($pwm_user && $pwm_subject && $pwm_text)
			{
				$user_to = array(
					'user_id'	=> $user_row['user_id'],
					'username'	=> $user_row['username'],
					'user_email'   => $user_row['user_email'],
                    'sitename'   => $this->config['sitename'],
                    'site_desc'   => $this->config['site_desc'],
                    'board_contact'   => $this->config['board_contact'],
                    'board_email'   => $this->config['board_email'],
                    'board_email_sig'   => $this->config['board_email_sig'],
				);

				$this->user_welcome($user_to, $pwm_user, $pwm_subject, $pwm_text);
			}
		}
	}

	/** User PM welcome message */
	private function user_welcome($user_to, $user_id, $subject, $text)
	{
		$m_flags = 3; // 1 is bbcode, 2 is smiles, 4 is urls (add together to turn on more than one)
		$uid = $bitfield = '';
		$allow_bbcode = $allow_urls = $allow_smilies = true;

		$text = str_replace('{USERNAME}', $user_to['username'], $text);
		$text = str_replace('{USER_EMAIL}', $user_to['user_email'], $text);
        $text = str_replace('{SITE_NAME}', $user_to['sitename'], $text);
        $text = str_replace('{SITE_DESC}', $user_to['site_desc'], $text);
        $text = str_replace('{BOARD_CONTACT}', $user_to['board_contact'], $text);
        $text = str_replace('{BOARD_EMAIL}', $user_to['board_email'], $text);
        $text = str_replace('{BOARD_SIG}', $user_to['board_email_sig'], $text);

		generate_text_for_storage($text, $uid, $bitfield, $m_flags, $allow_bbcode, $allow_urls, $allow_smilies);

		include_once($this->phpbb_root_path . 'includes/functions_privmsgs.' . $this->php_ext);

		$pm_data = array(
			'address_list'		=> array('u' => array($user_to['user_id'] => 'to')),
			'from_user_id'		=> $user_id,
			'from_user_ip'		=> $this->user->ip,
			'enable_sig'		=> false,
			'enable_bbcode'		=> $allow_bbcode,
			'enable_smilies'	=> $allow_smilies,
			'enable_urls'		=> $allow_urls,
			'icon_id'			=> 0,
			'bbcode_bitfield'	=> $bitfield,
			'bbcode_uid'		=> $uid,
			'message'			=> utf8_normalize_nfc($text),
		);

		submit_pm('post', utf8_normalize_nfc($subject), $pm_data, false);
	}
}
Thanks in advance for a reply.

User avatar
kinerity
Community Team Member
Community Team Member
Posts: 2079
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Truscott
Contact:

Re: Allow Tokens in Subject also

Post by kinerity » Fri Jan 11, 2019 4:54 pm

wads24 wrote:
Tue Jan 08, 2019 7:18 pm
Nobody ever replies in the discussion group though
Unfortunately, you need to receive support from the author of that extension.
Kailey Truscott - Community Team

User avatar
wads24
Registered User
Posts: 512
Joined: Fri Jun 10, 2005 4:44 am
Name: James

Re: Allow Tokens in Subject also

Post by wads24 » Sat Jan 12, 2019 12:39 am

kinerity wrote:
Fri Jan 11, 2019 4:54 pm
wads24 wrote:
Tue Jan 08, 2019 7:18 pm
Nobody ever replies in the discussion group though
Unfortunately, you need to receive support from the author of that extension.
Sorry to read that.... :o :shock: :(
Thanks in advance for a reply.

User avatar
battye
Extension Customisations
Extension Customisations
Posts: 10910
Joined: Wed Feb 11, 2004 11:02 am
Location: Australia
Contact:

Re: Allow Tokens in Subject also

Post by battye » Sat Jan 12, 2019 3:56 am

We can certainly try though, it'll just be harder because we don't know the ins and outs of the extension as well as the author would. Can you elaborate on what you mean by "the tokens"? Perhaps if you can provide a description or screenshots of what you're trying to achieve we might be able to assist further :)
Customisations Team Member

User avatar
wads24
Registered User
Posts: 512
Joined: Fri Jun 10, 2005 4:44 am
Name: James

Re: Allow Tokens in Subject also

Post by wads24 » Sun Jan 13, 2019 2:27 am

battye wrote:
Sat Jan 12, 2019 3:56 am
We can certainly try though, it'll just be harder because we don't know the ins and outs of the extension as well as the author would. Can you elaborate on what you mean by "the tokens"? Perhaps if you can provide a description or screenshots of what you're trying to achieve we might be able to assist further :)
Thanks... The variables

It says, "You can use bbcode and smilies, and these tokens: {USERNAME}, {USER_EMAIL}, {SITE_NAME}, {SITE_DESC}, {BOARD_CONTACT}, {BOARD_EMAIL} and {BOARD_SIG}"

The tokens work in the body of the private message but I would also like to have them work on the subject of the private message.
Screenshot_20190112-192338_Chrome.jpg
Screenshot_20190112-192353_Chrome.jpg
Thanks in advance for a reply.

User avatar
battye
Extension Customisations
Extension Customisations
Posts: 10910
Joined: Wed Feb 11, 2004 11:02 am
Location: Australia
Contact:

Re: Allow Tokens in Subject also

Post by battye » Sun Jan 13, 2019 2:47 am

I take it you've already made a few edits because your listener file looks different to the one on the authors GitHub page: https://github.com/bb3mobi/apwa/blob/ma ... stener.php :?:

I think all you need to do is something like this:

FIND

Code: Select all

$text = str_replace('{USERNAME}', $user_to['username'], $text);
$text = str_replace('{USER_EMAIL}', $user_to['user_email'], $text);
$text = str_replace('{SITE_NAME}', $user_to['sitename'], $text);
$text = str_replace('{SITE_DESC}', $user_to['site_desc'], $text);
$text = str_replace('{BOARD_CONTACT}', $user_to['board_contact'], $text);
$text = str_replace('{BOARD_EMAIL}', $user_to['board_email'], $text);
$text = str_replace('{BOARD_SIG}', $user_to['board_email_sig'], $text);
REPLACE WITH:

Code: Select all

// Replace main text
$text = str_replace('{USERNAME}', $user_to['username'], $text);
$text = str_replace('{USER_EMAIL}', $user_to['user_email'], $text);
$text = str_replace('{SITE_NAME}', $user_to['sitename'], $text);
$text = str_replace('{SITE_DESC}', $user_to['site_desc'], $text);
$text = str_replace('{BOARD_CONTACT}', $user_to['board_contact'], $text);
$text = str_replace('{BOARD_EMAIL}', $user_to['board_email'], $text);
$text = str_replace('{BOARD_SIG}', $user_to['board_email_sig'], $text);

// Replace subject
$subject = str_replace('{USERNAME}', $user_to['username'], $subject);
$subject = str_replace('{USER_EMAIL}', $user_to['user_email'], $subject);
$subject = str_replace('{SITE_NAME}', $user_to['sitename'], $subject);
$subject = str_replace('{SITE_DESC}', $user_to['site_desc'], $subject);
$subject = str_replace('{BOARD_CONTACT}', $user_to['board_contact'], $subject);
$subject = str_replace('{BOARD_EMAIL}', $user_to['board_email'], $subject);
$subject = str_replace('{BOARD_SIG}', $user_to['board_email_sig'], $subject);
Customisations Team Member

User avatar
wads24
Registered User
Posts: 512
Joined: Fri Jun 10, 2005 4:44 am
Name: James

Re: Allow Tokens in Subject also

Post by wads24 » Sun Jan 13, 2019 3:58 am

Yes, I added some..

That worked... Thanks buddy
Thanks in advance for a reply.

User avatar
battye
Extension Customisations
Extension Customisations
Posts: 10910
Joined: Wed Feb 11, 2004 11:02 am
Location: Australia
Contact:

Re: Allow Tokens in Subject also

Post by battye » Sun Jan 13, 2019 4:33 am

No problem :)
Customisations Team Member

User avatar
AmigoJack
Registered User
Posts: 5479
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Allow Tokens in Subject also

Post by AmigoJack » Mon Jan 14, 2019 7:23 am

Do you know why the choice was made to call the function again and again instead of once and using arrays for the find and replace parameters?
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.

User avatar
wads24
Registered User
Posts: 512
Joined: Fri Jun 10, 2005 4:44 am
Name: James

Re: Allow Tokens in Subject also

Post by wads24 » Fri Jan 18, 2019 9:23 pm

AmigoJack wrote:
Mon Jan 14, 2019 7:23 am
Do you know why the choice was made to call the function again and again instead of once and using arrays for the find and replace parameters?
No, I do not.
Thanks in advance for a reply.

Post Reply

Return to “phpBB Custom Coding”

Who is online

Users browsing this forum: No registered users and 6 guests