SimplePortal

Customization => Custom Coding => Topic started by: PokemonS on June 02, 2014, 05:36:51 AM

Title: Multiple whispers in Shoutbox
Post by: PokemonS on June 02, 2014, 05:36:51 AM
SMF 2.0.6
SP 2.3.5

Hi,
I recently edit the whispers feature to be more stylish.


(http://puu.sh/9bDLC/7bff5c4f27.jpg)


Our forum use like this example for whisper -> /Chillarmy/ Hello! I'am here!
But is it possible to have multi whispers like this? -> /Chillarmy1/ /Chillarmy2/ /Chillarmy3/ Hello!

Thanks!
Title: Re: Multiple whispers in Shoutbox
Post by: AngelinaBelle on June 05, 2014, 03:36:30 PM
This would require some customization.  How will SimplePortal know when the list of names has ended and the text has begun?  What if there is another / in the text?
Title: Re: Multiple whispers in Shoutbox
Post by: PokemonS on June 06, 2014, 04:03:11 PM
This would require some customization.  How will SimplePortal know when the list of names has ended and the text has begun?  What if there is another / in the text?

Use /(.+?)/ preg_match?
It's more to the "summon" feature, for example:

-> Hey /Chillarmy3/ and /Chillarmy2/, do know how to do it?
Only me, Chillarmy2, and Chillarmy3 can see that text.

-> I think it's better, right /Chillarmy2/?
Only me and Chillarmy2 can see that text.

And I will announce to our members to use / only for sumonning.
Title: Re: Multiple whispers in Shoutbox
Post by: AngelinaBelle on June 09, 2014, 02:12:55 PM
I'll move this to customization.  Maybe you can get some help with your regexp creation, and then the more complicated multi -whisper part. 
Title: Re: Multiple whispers in Shoutbox
Post by: Chen Zhen on June 09, 2014, 05:49:56 PM

Imo use commas to separate the names within your deliminators.  It might be best to use regex to break down the text input in which case you have it only show the message to those user names within the created array.

example:
Code: [Select]
$text = '/fred, ginger/: hello you two!!';

preg_match('~[/](.+?)[/]~',$text,$matches);
$names = !empty($matches[1]) ? explode(',', $matches[1]) : array();

Title: Re: Multiple whispers in Shoutbox
Post by: Chen Zhen on June 09, 2014, 11:43:36 PM

The actual edit will be like this...

File: ../Sources/Subs-Portal.php

find:
Code: [Select]
if (preg_match('~^@(.+?): ~' . ($context['utf8'] ? 'u' : ''), $shout['text'], $target) && $smcFunc['strtolower']($target[1]) !== $smcFunc['strtolower']($user_info['name']) && $shout['author']['id'] != $user_info['id'] && !$user_info['is_admin'])
{
unset($shouts[$shout['id']]);
continue;
}

replace with:
Code: [Select]
$names = (preg_match('~[/](.+?)[/]~i', $shout['text'], $targets)) ? explode(',', $targets[1]) : array();
if (!empty($names) && !in_array($smcFunc['strtolower']($user_info['name']), array_map('trim',$names)) && $shout['author']['id'] != $user_info['id'] && !$user_info['is_admin'])
{
unset($shouts[$shout['id']]);
continue;
}
elseif (preg_match('~^@(.+?): ~' . ($context['utf8'] ? 'u' : ''), $shout['text'], $target) && $smcFunc['strtolower']($target[1]) !== $smcFunc['strtolower']($user_info['name']) && $shout['author']['id'] != $user_info['id'] && !$user_info['is_admin'])
{
unset($shouts[$shout['id']]);
continue;
}


Example use will be:

-> /Chillarmy1, Chillarmy2, Chillarmy3/ I am whispering to these 3 user names!!!

The current whisper function for a single user will also still work unless you want to remove the other condition.

Regards.
Title: Re: Multiple whispers in Shoutbox
Post by: PokemonS on June 14, 2014, 12:14:29 PM
Thanks for answers!

Tested myself with different 3 accounts, but the code still won't work.
Then, I tried to edit a little code from preg_match and $names, still won't work.
Title: Re: Multiple whispers in Shoutbox
Post by: [SiNaN] on June 14, 2014, 12:54:54 PM
Try this:

Sources/Subs-Portal.php

Code: (Find) [Select]
$shouts[$shout['id']] += array(
Code: (Replace) [Select]
if (preg_match_all('~/([^/]+)/~' . ($context['utf8'] ? 'u' : ''), $shout['text'], $targets) && !in_array($smcFunc['strtolower']($user_info['name']), array_map($smcFunc['strtolower'], $targets[1])) && $shout['author']['id'] != $user_info['id'] && !$user_info['is_admin'])
{
unset($shouts[$shout['id']]);
continue;
}

$shouts[$shout['id']] += array(

This will work as in your initial example, like:

Code: [Select]
Hey /Chillarmy3/ and /Chillarmy2/, do know how to do it?
Title: Re: Multiple whispers in Shoutbox
Post by: Chen Zhen on June 14, 2014, 07:21:48 PM
Sinan,

  Please read this: http://us2.php.net//manual/en/reference.pcre.pattern.modifiers.php#usernotes
.. not sure about using the /u modifier as it can display an error under certain circumstances. At least the documentation states something in that regard.
  Should I be using that regex modifier for any forum set to utf-8??



PokemonS,
  That regex pattern was working for me although I may have had something incorrect. Oh well, try Sinan's version out to see if it functions as desired.
Title: Re: Multiple whispers in Shoutbox
Post by: [SiNaN] on June 15, 2014, 02:07:44 AM
I'm not sure, but it's there in SMF 2.0 and as long as it's there, I'll use it.
Title: Re: Multiple whispers in Shoutbox
Post by: Chen Zhen on June 15, 2014, 04:18:38 PM
I recently released a mod that uses quite a bit of regex. I will check if SMF uses that in all its regex & if so then I suppose I may have to apply it. If it has been working all this time without anyone complaining about issues then I suppose there are none.

\\Edit ->  Only occasionally so.. it depends on what chars are being searched within the string.  The regex I used only looks for ascii type chars surrounding any others so I suppose there is nothing for me to worry about.
SimplePortal 2.3.8 © 2008-2024, SimplePortal