Page 2 of 3

Re: shortlink sitename in language file

Posted: Sat Aug 18, 2018 9:46 pm
by 3Di
You should follow an order:

Code: Select all

services:
    alex75.welcomeback.listener:
        class: alex75\welcomeback\event\listener
        arguments:
            - '@user'
            - '@config'
            - '@template'
            - '%core.root_path%'
            - '%core.php_ext%'
            - '@language'
        tags:
            - { name: event.listener }
and purge cache again.

https://area51.phpbb.com/docs/dev/3.2.x ... -injection
The arguments are the service dependencies required by the class. It is important that the order of arguments must match the order of parameters in the __construct() method definition.

Re: shortlink sitename in language file

Posted: Sat Aug 18, 2018 9:50 pm
by alex75
I have reorganized the file services and purge the cache...

Code: Select all

services:
    alex75.welcomeback.listener:
        class: alex75\welcomeback\event\listener
        arguments:
            - '@user'
            - '@template'
            - '%core.root_path%'
            - '%core.php_ext%'
            - '@config'
            - '@language'
        tags:
            - { name: event.listener }
Catchable fatal error: Argument 2 passed to alex75\welcomeback\event\listener::__construct() must be an instance of phpbb\config\config, instance of phpbb\template\twig\twig given in C:\xampp\htdocs\phpbbstoreit\ext\alex75\welcomeback\event\listener.php on line 27

Re: shortlink sitename in language file

Posted: Sat Aug 18, 2018 9:53 pm
by 3Di
read my post above.

Re: shortlink sitename in language file

Posted: Sat Aug 18, 2018 10:02 pm
by alex75
3Di wrote:
Sat Aug 18, 2018 9:53 pm
read my post above.
ok now no error... but template not replace the string sitename.
i have
welcomeback on %s

Re: shortlink sitename in language file

Posted: Sat Aug 18, 2018 10:04 pm
by 3Di
post your template and lang files.

Re: shortlink sitename in language file

Posted: Sat Aug 18, 2018 10:10 pm
by alex75
my lang file:

Code: Select all

<?php
/** 
* 
* @package welcome back
* @copyright (c) 2015 alex75 https://www.phpbb-store.it
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 
* 
*/ 
if (!defined('IN_PHPBB'))
{
exit;
}
if (empty($lang) || !is_array($lang))
{
$lang = array();
}
$lang = array_merge($lang, array(
'WELCOMEBACK_ON'			=> 'Welcome back on %s',
'WELCOMEBACK_HI'			=> 'Hi',
'WELCOMEBACK_SEE'			=> 'Nice to see you here',
'WBMY_TOPICS'				=> 'Your Topics',
'YOUR_SUBSCRIBED'			=> 'Your subscribed',
'YOUR_BOOKMARKS'			=> 'Your bookmarks',
'YOUR_DRAFTS'		    	=> 'Your drafts',
'YOUR_ATTACHMENTS'		   	=> 'Your attachments',
'IN_THIS_FORUM'		    	=> 'In this forum',
'IN_THIS_TOPIC'		    	=> 'In this topic',
'YOU_ARE_HERE'		    	=> 'You are here',
));
in the template, we call the {L_WELCOMEBACK_ON} string

Re: shortlink sitename in language file

Posted: Sat Aug 18, 2018 10:15 pm
by 3Di
Try and replace your whole listener file with this.

Code: Select all

<?php
/**
*
* @package welcome back
* @copyright (c) 2015 alex75 https://www.phpbb-store.it
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

namespace alex75\welcomeback\event;

/**
 * @ignore
 */
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * welcome back Event listener.
 */
class listener implements EventSubscriberInterface
{

	protected $user;
	protected $template;
	protected $root_path;
	protected $phpEx;
	protected $config;
	protected $language;

	public function __construct(
		\phpbb\user $user,
		\phpbb\config\config $config,
		\phpbb\template\template $template,
		$root_path,
		$phpEx,
		\phpbb\language\language $language)
	{
		$this->user			= $user;
		$this->config		= $config;
		$this->template		= $template;
		$this->root_path	= $root_path;
		$this->phpEx		= $phpEx;
		$this->language		= $language;
	}

	static public function getSubscribedEvents()
	{
		return array(
			'core.user_setup'	=> 'load_language',
			'core.page_header'	=> 'wb_tpl_vars', 
		);
	}

	public function load_language($event)
	{
		$lang_set_ext = $event['lang_set_ext'];
		$lang_set_ext[] = array(
			'ext_name' => 'alex75/welcomeback',
			'lang_set' => 'welcomebacklang',
		);
		$event['lang_set_ext'] = $lang_set_ext;
	}

	public function wb_tpl_vars($event)
	{
		$url_1 = append_sid($this->root_path . 'search.' . $this->phpEx, 'author=' . $this->user->data['username'] . '&amp;sf=firstpost&amp;sr=topics');
		$url_2 = append_sid($this->root_path . "ucp." . $this->phpEx, "i=ucp_main&amp;mode=drafts");
		$url_3 = append_sid($this->root_path . "ucp." . $this->phpEx, "i=ucp_main&amp;mode=subscribed");
		$url_4 = append_sid($this->root_path . "ucp." . $this->phpEx, "i=ucp_main&amp;mode=bookmarks");
		$url_5 = append_sid($this->root_path . "ucp." . $this->phpEx, "i=ucp_attachments&amp;mode=attachments");

		$this->template->assign_vars(array(
			'U_WBYOURTOPICS'		=> $url_1,
			'U_WBYOURDRAFTS'		=> $url_2,
			'U_WBYOURSUBSCRIBED'	=> $url_3,
			'U_WBYOURBOOKMARKS'		=> $url_4,
			'U_WBYOURATTACHMENTS'	=> $url_5,
			'WB_SITENAME'			=> $this->language->lang('WELCOMEBACK_ON', $this->config['sitename']),
		));
	}
}

Re: shortlink sitename in language file

Posted: Sat Aug 18, 2018 10:22 pm
by alex75
no difference. thanks for your patience.
I believe the error is here:

Code: Select all

'WELCOMEBACK_ON'			=> 'Welcome back on %s',

Re: shortlink sitename in language file

Posted: Sat Aug 18, 2018 10:26 pm
by 3Di
{L_WELCOMEBACK_ON} should be {WB_SITENAME} in the template

Re: shortlink sitename in language file

Posted: Sat Aug 18, 2018 10:31 pm
by alex75
Yes! finally it works! many thanks ;-)

Re: shortlink sitename in language file

Posted: Sat Aug 18, 2018 10:42 pm
by alex75
Today I learned so many new rules. Thanks to @3Di , @david63 , @GanstaZ.
Here http://www.phpbb-store.it/test/ you can see the working welcomeback (for logged users. see the username and password in header).
Now I will send to the validation team my extension for phpbb 3.2.x if you want to preview the sending in mp ;-)

Re: shortlink sitename in language file

Posted: Mon Aug 20, 2018 5:47 am
by 3Di
If you wish someone to admire your work then place your development extension into the dedicated forum, where you may receive opinions about it.

Re: shortlink sitename in language file

Posted: Mon Aug 20, 2018 8:44 am
by alex75
The forum I mentioned earlier is test-only and should not be registered; username and password are written on the header.
The extension for phpbb 3.1.x is already public on the CDB. this change is for phpbb 3.2.x. Yesterday I sent the new package pending validation.
Thanks again for your help.

Re: shortlink sitename in language file

Posted: Mon Aug 20, 2018 10:38 am
by david63
It would help in the future if you used GitHub (or similar) so that we can see the full picture and save time

Re: shortlink sitename in language file

Posted: Mon Aug 20, 2018 10:59 am
by alex75
david63 wrote:
Mon Aug 20, 2018 10:38 am
It would help in the future if you used GitHub (or similar) so that we can see the full picture and save time
Here she is. Uploaded now on github for you.
Next time I'll upload it before asking for help. ;-)
https://github.com/phpbb-store/alex75-welcomeback