clickable link in chat

clickable link in chat

by Paulo Felisbino -
Number of replies: 4

Afternoon,

Is there a way to make moodle reconize a link pasted by the user in chat and turn it into a normal link?

When i enter https://www.google.com.br/, the link is not clickable, it appears like a normal text...

Anyone can help me?

Hugs,

Paulo

Average of ratings: -
In reply to Paulo Felisbino

Re: clickable link in chat

by Jacqui Riding -

Hi Paulo

Are you meaning when someone is typing in chat and enters a website link - you want this to be active as a hyperlink? I gather you would enter the text in the chat as:-

<a href="http://www.moodle.org">This is the link to Moodle</a>

"This is the link to Moodle" would be a hyperlink to the Moodle site within the chat.  This takes over the page though. You would have to add target="_blank" in it to force a new page.

<a href="http://www.moodle.org" target="_blank">www.moodle.org</a>

Unfortunately when I test this, the link worked but took you out of the chat.  Maybe someone else can add to this.

In reply to Paulo Felisbino

Re: clickable link in chat

by brami petluri -

Hi Paulo Felisbino,

You have to edit moodle core code, go to "mod\chat\gui_header_js\insert.php".
In insert.php file search lines like:
$chat_message = clean_text($chat_message, FORMAT_MOODLE);  // Strip bad tags

below that line copy the following code:

$pattern = '/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/';


$msg_array = explode(' ',$chat_message);
$msg = array();


foreach($msg_array as $msg_arr)

{
    
    if(preg_match($pattern,$msg_arr))
    
    {
        
        $msg_arr = '<a href='.$msg_arr.'>'.$msg_arr.'</a>';
    
    }
    
    $msg[] = $msg_arr;

}


$chat_message = implode(' ',$msg);


And test chat window... smile

 

Note:-This works only in normal chat.