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
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
Darn sorry, I'll look into it further when I get home in a few hours
Please, don't apologise! I appreciate you replying. That'd be great if you could let me know
+Rep for trying to help me
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
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
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
What do you mean you want to keep the message there? I though you wanted to create some kind of validation.