How to Open Links in a New Tab in Hesk 2.5.2

By | January 4, 2014

If you have used Hesk before, you must have mentioned that all links that were posted by users at the time of ticlet creation/reply were opening in new tabs. If you decide to update to 2.5.2 (I was using version 2.3 before), you will notice that all links will be opening in the current tab.

If you want to change this, you’ll need to change one function.

Go to inc/common.inc.php

Find function hesk_makeURL($text, $class = ”)

it should look like:

[code]
function hesk_makeURL($text, $class = ”)
{
global $hesk_settings;

if ( ! defined(‘MAGIC_URL_EMAIL’))
{
define(‘MAGIC_URL_EMAIL’, 1);
define(‘MAGIC_URL_FULL’, 2);
define(‘MAGIC_URL_LOCAL’, 3);
define(‘MAGIC_URL_WWW’, 4);
}

$class = ($class) ? ‘ class=”‘ . $class . ‘”‘ : ”;

// matches a xxxx://aaaaa.bbb.cccc. …
$text = preg_replace_callback(
‘#(^|[nt (>.])([a-z][a-zd+]*:/{2}(?:(?:[a-z0-9-._~!$&'(*+,;=:@|]+|%[dA-F]{2})+|[0-9.]+|[[a-z0-9.]+:[a-z0-9.]+:[a-z0-9.:]+])(?::d*)?(?:/(?:[a-z0-9-._~!$&'(*+,;=:@|]+|%[dA-F]{2})*)*(?:?(?:[a-z0-9-._~!$&'(*+,;=:@/?|]+|%[dA-F]{2})*)?(?:#(?:[a-z0-9-._~!$&'(*+,;=:@/?|]+|%[dA-F]{2})*)?)#i’,
create_function(
“$matches”,
“return make_clickable_callback(MAGIC_URL_FULL, $matches[1], $matches[2], ”, ‘$class’);”
),
$text
);

// matches a “www.xxxx.yyyy[/zzzz]” kinda lazy URL thing
$text = preg_replace_callback(
‘#(^|[nt (>.])(www.(?:[a-z0-9-._~!$&'(*+,;=:@|]+|%[dA-F]{2})+(?::d*)?(?:/(?:[a-z0-9-._~!$&'(*+,;=:@|]+|%[dA-F]{2})*)*(?:?(?:[a-z0-9-._~!$&'(*+,;=:@/?|]+|%[dA-F]{2})*)?(?:#(?:[a-z0-9-._~!$&'(*+,;=:@/?|]+|%[dA-F]{2})*)?)#i’,
create_function(
“$matches”,
“return make_clickable_callback(MAGIC_URL_WWW, $matches[1], $matches[2], ”, ‘$class’);”
),
$text
);

// matches an email address
$text = preg_replace_callback(
‘#(^|[nt (>.])(([w!#$%&’*+-/=?^`{|}~]+.)*(?:[w!#$%’*+-/=?^`{|}~]|&)+@((((([a-z0-9]{1}[a-z0-9-]{0,62}[a-z0-9]{1})|[a-z]).)+[a-z]{2,63})|(d{1,3}.){3}d{1,3}(:d{1,5})?))#i’,
create_function(
“$matches”,
“return make_clickable_callback(MAGIC_URL_EMAIL, $matches[1], $matches[2], ”, ‘$class’);”
),
$text
);

// return $text;
} // END hesk_makeURL()
[/code]

And replace it with the code from the previous version of Hesk:
[code]
function hesk_makeURL($strUrl)
{
$myMsg = ‘ ‘ . $strUrl;
$myMsg = preg_replace(“#(^|[n ])([w]+?://[^ “nrt<]*)#is", "$1$2“, $myMsg);
$myMsg = preg_replace(“#(^|[n ])((www|ftp).[^ “tnr<]*)#is", "$1$2“, $myMsg);
$myMsg = preg_replace(“#(^|[n ])([a-z0-9&-_.]+?)@([w-]+.([w-.]+.)*[w]+)#i”, “$1$2@$3“, $myMsg);
$myMsg = substr($myMsg, 1);
return($myMsg);
} // End hesk_makeURL()
[/code]

Save file and have fun.

Leave a Reply

Your email address will not be published. Required fields are marked *