MyBB Community Forums

Full Version: Newreply -> Pregmatch second parameter?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Hey guys, I need to check if a users has a URL in there post. I'm using preg_match to check but was wondering what the second parameter would be ?

I'm using this hook:
$plugins->add_hook('newreply_do_newreply_end', 'test_do_newreply');

This is my function:
function test_do_newreply()
{
if (preg_match ("/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/")) {
echo "URL is present";
}

Cheers Smile
You can try changing your test_newreply function to this, however I'm not sure if that hook passes an argument:
function test_do_newreply($message)
{
if (preg_match ("/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/", $message)) {
echo "URL is present";
}

If this doesn't work I believe the $post[] that contains the content of the post (can't remember if it's $post['data'] or 'message' or something, don't have time to check right now) could be checked instead of $message in the above example.
Cheers for the reply

Just tried that and unfortunately it didn't work.

Thanks Smile
Darn sorry, I'll look into it further when I get home in a few hours Smile
Please, don't apologise! I appreciate you replying. That'd be great if you could let me know Smile

+Rep for trying to help me Smile
newreply_do_newreply_end doesn't pass any argument by reference. $message must be $mybb->input['message'].

Add "global $mybb;" first.
Thanks Omar, It still didn't work unfortunatly.

My current function is:
function test_do_newreply()
{
    global $mybb;
if (preg_match ("/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/", $mybb->input['message'])) {
echo "URL is present";
}

Thanks Smile
Are you sure it is not the regex? What happens with this?:
global $mybb;
die($mybb->input['message']);
When I add that code and post a new reply, the loading spinner starts and after it stops, nothing happens. When I reload, the post is there.

Thanks Smile

EDIT:

It works when it's submitted now, it says "URL Is present" when it's submitted. What would be the best way to keep it there?

Cheers Smile
What do you mean you want to keep the message there? I though you wanted to create some kind of validation.
Pages: 1 2 3