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:

function hesk_makeURL($text, $class = '')
{
global $hesk_settings;</code>

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 (&gt;.])([a-z][a-zd+]*:/{2}(?:(?:[a-z0-9-._~!$&amp;'(*+,;=:@|]+|%[dA-F]{2})+|[0-9.]+|[[a-z0-9.]+:[a-z0-9.]+:[a-z0-9.:]+])(?::d*)?(?:/(?:[a-z0-9-._~!$&amp;'(*+,;=:@|]+|%[dA-F]{2})*)*(?:?(?:[a-z0-9-._~!$&amp;'(*+,;=:@/?|]+|%[dA-F]{2})*)?(?:#(?:[a-z0-9-._~!$&amp;'(*+,;=:@/?|]+|%[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 (&gt;.])(www.(?:[a-z0-9-._~!$&amp;'(*+,;=:@|]+|%[dA-F]{2})+(?::d*)?(?:/(?:[a-z0-9-._~!$&amp;'(*+,;=:@|]+|%[dA-F]{2})*)*(?:?(?:[a-z0-9-._~!$&amp;'(*+,;=:@/?|]+|%[dA-F]{2})*)?(?:#(?:[a-z0-9-._~!$&amp;'(*+,;=:@/?|]+|%[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 (&gt;.])(([w!#$%&amp;'*+-/=?^`{|}~]+.)*(?:[w!#$%'*+-/=?^`{|}~]|&amp;)+@((((([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()

And replace it with the code from the previous version of Hesk:

function hesk_makeURL($strUrl)
{
    $myMsg = ' ' . $strUrl;
    $myMsg = preg_replace("#(^|[n ])([w]+?://[^ "nrt<&#93;*)#is", "$1<a href="$2" target="_blank">$2</a>", $myMsg);
    $myMsg = preg_replace("#(^|[n ])((www|ftp).[^ "tnr<&#93;*)#is", "$1<a href="http://$2" target="_blank">$2</a>", $myMsg);
    $myMsg = preg_replace("#(^|[n ])([a-z0-9&-_.]+?)@([w-]+.([w-.]+.)*[w]+)#i", "$1<a href="mailto:$2@$3">$2@$3</a>", $myMsg);
    $myMsg = substr($myMsg, 1);
    return($myMsg);
} // End hesk_makeURL()

Save file and have fun.

10 thoughts on “How to Open Links in a New Tab in Hesk 2.5.2

  1. e-commerce

    Wow, marvelous blog format! How long have you ever been running a blog for?
    you made running a blog look easy. The entire glance of
    your website is excellent, let alone the content material!
    You can see similar here sklep online

    Reply
  2. dobry sklep

    Hello! Do you know if they make any plugins to help with
    Search Engine Optimization? I’m trying to get my blog to
    rank for some targeted keywords but I’m not seeing very
    good results. If you know of any please share. Appreciate it!
    You can read similar blog here: E-commerce

    Reply
  3. sklep online

    Hi! Do you know if they make any plugins to help with Search Engine
    Optimization? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing
    very good results. If you know of any please share. Thanks!
    You can read similar art here: Sklep online

    Reply
  4. sklep online

    Hey! Do you know if they make any plugins to help with Search Engine Optimization? I’m trying to
    get my blog to rank for some targeted keywords but I’m not seeing
    very good gains. If you know of any please share. Kudos!
    You can read similar article here: Dobry sklep

    Reply
  5. Auto Approve List

    Hi! Do you know if they make any plugins to help with SEO?
    I’m trying to get my site to rank for some targeted keywords but I’m not seeing very
    good gains. If you know of any please share. Kudos!
    You can read similar article here: Backlink Portfolio

    Reply
  6. Lester71

    Wow, wonderful blog format!
    How long have you been running a blog for?
    you made blogging glance easy. The overall glance of
    your web site is great, let alone the content material!
    You can read similar here prev next
    and that was wrote by Sharmaine97.

    Reply
  7. Amy62

    Wow, awesome weblog layout!

    How lengthy have you ever been running a blog for? you make blogging
    look easy. The total glance of your website
    is magnificent, let alone the content! You can read similar here
    prev
    next and it’s was wrote by Corey79.

    Reply
  8. Winifred82

    Wow, incredible blog layout!
    How lengthy have you ever been running a blog for? you make running a blog glance easy.
    The full glance of your site is wonderful, let alone the content!
    You can read similar here prev
    next and it’s was wrote by Eldon78.

    Reply
  9. Sheila63

    Wow, amazing blog format!
    How lengthy have you been running a blog
    for? you make blogging glance easy. The overall look of your
    website is great, let alone the content material! You can see similar here
    prev next and that was wrote by Santos88.

    Reply

Leave a Reply

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