Simple mentions

Makeing "simple mention"clickable - Simple mentions

Makeing "simple mention"clickable

by ivailo95 » Fri Mar 29, 2019 7:42 pm

Hi thhere
i want to make this ext clickable,mean when mention someone can click on the mentioned nickname
is this possible?
User avatar
ivailo95
Registered User
Posts: 819
Joined: Tue Sep 05, 2017 8:00 am
Location: Bulgaria
Name: Ivailo
Contact:

Re: Makeing "simple mention"clickable

by Exabot » Tue Jul 02, 2019 8:03 pm

Good idea! +1
Exabot
Translator
Posts: 175
Joined: Sun Jan 18, 2015 8:21 pm
Location: Estonia
Contact:

Re: Makeing "simple mention"clickable

by thepostman » Fri Jul 05, 2019 7:32 pm

yes! I just installed the extension and am a little disappointed they aren't clickable.
thepostman
Registered User
Posts: 5
Joined: Sun May 12, 2019 1:19 am
Contact:

Re: Makeing "simple mention"clickable

by dingus33 » Fri Aug 02, 2019 3:49 am

agreed, it would be very nice if mentions were clickable links to user profiles.

sadly, i somehow doubt paul will add this functionality to the extension. it is a very nice extension, but he has repeatedly stated that the focus is 'simplicity'. that's fair, but this feature sure would be nice :D

however, i have this working on the current version (1.0.3). i tried to do it in a way that creates the least possible interference with the current official version and with hypothetical future versions. if you want, you can get it working on your forums by doing these changes:

----------

/paul999/mention/styles/all/template/js/mention.js:

old:

Code: Select all

insertTpl: '[mention]${name}[/mention]',
new:

Code: Select all

insertTpl: '[mention=${id}]${name}[/mention]',
----------

/paul999/mention/migrations/update_bbcode.php:

old:

Code: Select all

        public function update_bbcodes()
        {
                $install = new bbcodes_installer($this->db, $this->container->get('request'), $this->container->get('user'), $this->phpbb_root_path, $this->php_ext);
                $install->install_bbcodes([
                        'mention' => [
                                'display_on_posting'    => false,
                                'bbcode_match'              => '[mention]{TEXT}[/mention]',
                                'bbcode_tpl'                => '<span class="mention">@{TEXT}</span>',
                        ],
                ]);

        }
new:

Code: Select all

        public function update_bbcodes()
        {
                $install = new bbcodes_installer($this->db, $this->container->get('request'), $this->container->get('user'), $this->phpbb_root_path, $this->php_ext);
                $install->install_bbcodes([
                        'mention' => [
                                'display_on_posting'    => false,
                                'bbcode_match'              => '[mention={NUMBER}]{TEXT}[/mention]',
                                'bbcode_tpl'                => '<a class="mention" href="./memberlist.php?mode=viewprofile&u={NUMBER}">@{TEXT}</a>',
                        ],
                ]);

        }
----------

/paul999/mention/event/main_listener.php:

old:

Code: Select all

private $regex = '#\[mention\]<\/s>(.*?)<e>\[\/mention\]#';
new:

Code: Select all

private $regex = '#\[mention=?(?:\d+)?\]<\/s>(.*?)<e>\[\/mention\]#';
----------

/paul999/mention/event/main_listener.php:

old:

Code: Select all

	public function remove_mention_in_quote($event)
	{
		if ($event['submit'] || $event['preview'] || $event['refresh'] || $event['mode'] != 'quote' || !isset($event['page_data']) || !isset($event['page_data']['MESSAGE']))
		{
			return;
		}
		$page_data = $event['page_data'];
		$page_data['MESSAGE'] = preg_replace('#\[mention\](.*?)\[\/mention\]#uis', '@\\1', $page_data['MESSAGE']);
		$event['page_data'] = $page_data;
	}
new:

Code: Select all

	public function remove_mention_in_quote($event)
	{
		if ($event['submit'] || $event['preview'] || $event['refresh'] || $event['mode'] != 'quote' || !isset($event['page_data']) || !isset($event['page_data']['MESSAGE']))
		{
			return;
		}
		$page_data = $event['page_data'];
		$page_data['MESSAGE'] = preg_replace('#\[mention=?(?:\d+)?\](.*?)\[\/mention\]#uis', '\\1', $page_data['MESSAGE']);
		$event['page_data'] = $page_data;
	}
----------

note that this also resolves the issue here: https://www.phpbb.com/customise/db/exte ... 61#p648861

note that the [mention] bbcode needs to be updated as well. you can do this one of two ways:
  • disable the extension and delete extension data and then re-enable the extension. this just forces the bbcode to be updated automatically using the existing migration that was edited above. for obvious reasons, i didn't add a new migration (unofficial migrations are bad idea). and future official migrations should work fine. note that since you deleted data, your users will lose their mention notification histories in the notification center.
  • you can manually update the bbcode in the ACP instead. ACP > Posting > BBCodes. change the BBCode usage to [mention={NUMBER}]{TEXT}[/mention], and change the HTML replacement to <a class="mention" href="./memberlist.php?mode=viewprofile&u={NUMBER}">@{TEXT}</a>
and i don't think it's necessary, but you could also purge the cache if you want.

note that there are a couple of issues with my approach:
  • only new mentions going forward will be properly clickable. the ideal solution would be to write something that goes back through older posts and updates the previous mentions to include user IDs (IDs are required for the profile links).
  • if paul implements something similar, he might not do it exactly the same way, and there could be issues there.
    personally, i'm still using the above code on my forum without a care. worst case scenario is that some of the mentions (the older ones) on my site will be malformed links if paul eventually implements it another way.
note for the future: in the new version (1.0.5?) that is not released yet here on the CDB, paul changed his extension to use Tribute and also changed his controller as well..
good news is, i bet the bugs are fixed! :D
'bad' news is my added functionality above won't work anymore. and looks like user IDs are not returned in the controller json anymore?
but if there is demand, i'll write another guide with the changes to make for new versions. or, ideally, paul can just officially add it to his extension. (paul has said that he has no plans to add this feature)
Last edited by dingus33 on Fri Aug 02, 2019 7:24 pm
User avatar
dingus33
Registered User
Posts: 125
Joined: Fri Sep 29, 2017 11:11 am
Contact:

Re: Makeing "simple mention"clickable

by Exabot » Fri Aug 02, 2019 11:19 am

Perfect! Thanks!!
Exabot
Translator
Posts: 175
Joined: Sun Jan 18, 2015 8:21 pm
Location: Estonia
Contact:

Re: Makeing "simple mention"clickable

by dingus33 » Fri Aug 02, 2019 6:34 pm

also, if there's demand, i'll write a thing to go back and fix the older mentions so they're properly clickable. and maybe even a script to revert all mentions to the original style if you wanna undo
User avatar
dingus33
Registered User
Posts: 125
Joined: Fri Sep 29, 2017 11:11 am
Contact:

Re: Makeing "simple mention"clickable

by Exabot » Fri Aug 02, 2019 6:48 pm

+1 :!:
Exabot
Translator
Posts: 175
Joined: Sun Jan 18, 2015 8:21 pm
Location: Estonia
Contact:

Re: Makeing "simple mention"clickable

by Paul » Fri Aug 02, 2019 6:51 pm

Please keep in mind that I won't be providing support for these changes, and they most certainly won't work for the nest release.
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 25455
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: Makeing "simple mention"clickable

by dingus33 » Fri Aug 02, 2019 7:09 pm

indeed, that's very reasonable, paul.

however, would you please consider doing something similar soon in an official release?

and thank you for making a nice extension
User avatar
dingus33
Registered User
Posts: 125
Joined: Fri Sep 29, 2017 11:11 am
Contact:

Re: Makeing "simple mention"clickable

by Paul » Fri Aug 02, 2019 7:10 pm

No, I have no plans adding it
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 25455
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: Makeing "simple mention"clickable

by dingus33 » Fri Aug 02, 2019 7:25 pm

thanks for clarifying
User avatar
dingus33
Registered User
Posts: 125
Joined: Fri Sep 29, 2017 11:11 am
Contact: