GTTB
12-30-2005, 01:48 PM
I need some help with a vB plugin code. The code below is used for adding ed2k links and ed2k server links to your board. But the links open in "New Browser Window" when clicked on the forum which I don't want. Is there anybody here who knows what needs to be changed or added to the code below so the links open in the "Same Browser Window" instead.
if (!function_exists('convert_url_to_bbcode_callback_extended'))
{
/**
* Extended callback function for convert_url_to_bbcode
*
* @param string Message text
* @param string Text to prepend
*
* @return string
*/
function convert_url_to_bbcode_callback_extended($messagetext, $prepend)
{
// the auto parser - adds tags around neccessary things
$messagetext = str_replace('\"', '"', $messagetext);
$prepend = str_replace('\"', '"', $prepend);
static $urlSearchArray, $urlReplaceArray, $emailSearchArray, $emailReplaceArray;
if (empty($urlSearchArray))
{
$taglist = '\[b|\[i|\[u|\[left|\[center|\[right|\[indent|\[quote|\[highlight|\[\*' .
'|\[/b|\[/i|\[/u|\[/left|\[/center|\[/right|\[/indent|\[/quote|\[/highlight';
// Note the slightly changed regex which introduces ed2k and sip protocols and allows "|" as a character in URIs
$urlSearchArray = array(
"#(^|(?<=[^_a-z0-9-=\]\"'/@]|(?<=" . $taglist . ")\]))((https?|ftp|gopher|news|telnet)://|www\.|sip:|ed2k://)((\[(?!/)|[^\s[^$!`\"'{}<>])+)(?!\[/url|\[/img)(?=[,.]*(\)\s|\)$|[\s[]|$))#siUe",
);
$urlReplaceArray = array(
"convert_url_to_bbcode_callback_extended_callback('\\2','\\4')",
);
$emailSearchArray = array(
"/([ \n\r\t])([_a-z0-9-]+(\.[_a-z0-9-]+)*@[^\s]+(\.[a-z0-9-]+)*(\.[a-z]{2,4}))/si",
"/^([_a-z0-9-]+(\.[_a-z0-9-]+)*@[^\s]+(\.[a-z0-9-]+)*(\.[a-z]{2,4}))/si"
);
$emailReplaceArray = array(
"\\1 (file://\\1)\\2",
"\\0"
);
}
$text = preg_replace($urlSearchArray, $urlReplaceArray, $messagetext);
if (strpos($text, "@"))
{
$text = preg_replace($emailSearchArray, $emailReplaceArray, $text);
}
return $prepend . $text;
}
}
if (!function_exists('convert_url_to_bbcode_callback_extended_callback'))
{
/**
* Callback function returning "normal" links as usual and ed2k links specially formatted
*
* @param string Prefix containing the protocol part of the url
* @param string Remainder of the link
*
* @return string
*/
function convert_url_to_bbcode_callback_extended_callback($protocolprefix, $link)
{
// Optionally specify a tag which get automatically added to the ed2k link
// $filenametag = '[MyCrewTag]';
if (strtolower($protocolprefix) == 'ed2k://')
{
$ed2klinkparts = @split('\|', $link);
if (is_array($ed2klinkparts) && count($ed2klinkparts) > 5 && strtolower($ed2klinkparts[1]) == 'file')
{
if ($filenametag != '')
{
// Add tag to filename
$path_parts = pathinfo($ed2klinkparts[2]);
$tempfilename = $ed2klinkparts[2];
$ed2klinkparts[2] = basename($path_parts['basename'], $path_parts['extension']) . urlencode($filenametag) . '.' . $path_parts['extension'];
$link = join('|', $ed2klinkparts);
$ed2klinkparts[2] = $tempfilename;
}
return '' . urldecode($ed2klinkparts[2]) . ' (' . $protocolprefix . $link . ') (' . format_bytesize($ed2klinkparts[3]) . ')';
}
elseif (is_array($ed2klinkparts) && count($ed2klinkparts) > 3 && strtolower($ed2klinkparts[1]) == 'server')
{
return 'ed2k Server ' . $ed2klinkparts[2] . ':' . $ed2klinkparts[3] . ' (' . $protocolprefix . $link . ')';
}
else
{
return $protocolprefix . $link;
}
}
else
{
return '[url]' . $protocolprefix . $link . '';
}
}
}
if (!function_exists('format_bytesize'))
{
/**
* Function to convert a byte size in a human readable form
*
* @param int Bytes
* @param int decimal places
*
* @return string
*/
function format_bytesize($bytes, $dec_places = 2)
{
if ($bytes > (1024*1024*1024)) {
$result = sprintf('%.' . $dec_places . 'f', $bytes / (1024*1024*1024));
$result .= 'GBytes';
} elseif ($bytes > (1024*1024)) {
$result = sprintf('%.' . $dec_places . 'f', $bytes / (1024*1024));
$result .= 'MBytes';
} elseif ($bytes > 1024) {
$result = sprintf('%.' . $dec_places . 'f', $bytes / 1024);
$result .= 'kBytes';
}
return $result;
}
}
// Return replacement using extended callback function
$messagetext = preg_replace(
'#(^|\[/(' . $skiptaglist . ')\])(.*(\[(' . $skiptaglist . ')|$))#siUe',
"convert_url_to_bbcode_callback_extended('\\3', '\\1')",
$messagetext
);
if (!function_exists('convert_url_to_bbcode_callback_extended'))
{
/**
* Extended callback function for convert_url_to_bbcode
*
* @param string Message text
* @param string Text to prepend
*
* @return string
*/
function convert_url_to_bbcode_callback_extended($messagetext, $prepend)
{
// the auto parser - adds tags around neccessary things
$messagetext = str_replace('\"', '"', $messagetext);
$prepend = str_replace('\"', '"', $prepend);
static $urlSearchArray, $urlReplaceArray, $emailSearchArray, $emailReplaceArray;
if (empty($urlSearchArray))
{
$taglist = '\[b|\[i|\[u|\[left|\[center|\[right|\[indent|\[quote|\[highlight|\[\*' .
'|\[/b|\[/i|\[/u|\[/left|\[/center|\[/right|\[/indent|\[/quote|\[/highlight';
// Note the slightly changed regex which introduces ed2k and sip protocols and allows "|" as a character in URIs
$urlSearchArray = array(
"#(^|(?<=[^_a-z0-9-=\]\"'/@]|(?<=" . $taglist . ")\]))((https?|ftp|gopher|news|telnet)://|www\.|sip:|ed2k://)((\[(?!/)|[^\s[^$!`\"'{}<>])+)(?!\[/url|\[/img)(?=[,.]*(\)\s|\)$|[\s[]|$))#siUe",
);
$urlReplaceArray = array(
"convert_url_to_bbcode_callback_extended_callback('\\2','\\4')",
);
$emailSearchArray = array(
"/([ \n\r\t])([_a-z0-9-]+(\.[_a-z0-9-]+)*@[^\s]+(\.[a-z0-9-]+)*(\.[a-z]{2,4}))/si",
"/^([_a-z0-9-]+(\.[_a-z0-9-]+)*@[^\s]+(\.[a-z0-9-]+)*(\.[a-z]{2,4}))/si"
);
$emailReplaceArray = array(
"\\1 (file://\\1)\\2",
"\\0"
);
}
$text = preg_replace($urlSearchArray, $urlReplaceArray, $messagetext);
if (strpos($text, "@"))
{
$text = preg_replace($emailSearchArray, $emailReplaceArray, $text);
}
return $prepend . $text;
}
}
if (!function_exists('convert_url_to_bbcode_callback_extended_callback'))
{
/**
* Callback function returning "normal" links as usual and ed2k links specially formatted
*
* @param string Prefix containing the protocol part of the url
* @param string Remainder of the link
*
* @return string
*/
function convert_url_to_bbcode_callback_extended_callback($protocolprefix, $link)
{
// Optionally specify a tag which get automatically added to the ed2k link
// $filenametag = '[MyCrewTag]';
if (strtolower($protocolprefix) == 'ed2k://')
{
$ed2klinkparts = @split('\|', $link);
if (is_array($ed2klinkparts) && count($ed2klinkparts) > 5 && strtolower($ed2klinkparts[1]) == 'file')
{
if ($filenametag != '')
{
// Add tag to filename
$path_parts = pathinfo($ed2klinkparts[2]);
$tempfilename = $ed2klinkparts[2];
$ed2klinkparts[2] = basename($path_parts['basename'], $path_parts['extension']) . urlencode($filenametag) . '.' . $path_parts['extension'];
$link = join('|', $ed2klinkparts);
$ed2klinkparts[2] = $tempfilename;
}
return '' . urldecode($ed2klinkparts[2]) . ' (' . $protocolprefix . $link . ') (' . format_bytesize($ed2klinkparts[3]) . ')';
}
elseif (is_array($ed2klinkparts) && count($ed2klinkparts) > 3 && strtolower($ed2klinkparts[1]) == 'server')
{
return 'ed2k Server ' . $ed2klinkparts[2] . ':' . $ed2klinkparts[3] . ' (' . $protocolprefix . $link . ')';
}
else
{
return $protocolprefix . $link;
}
}
else
{
return '[url]' . $protocolprefix . $link . '';
}
}
}
if (!function_exists('format_bytesize'))
{
/**
* Function to convert a byte size in a human readable form
*
* @param int Bytes
* @param int decimal places
*
* @return string
*/
function format_bytesize($bytes, $dec_places = 2)
{
if ($bytes > (1024*1024*1024)) {
$result = sprintf('%.' . $dec_places . 'f', $bytes / (1024*1024*1024));
$result .= 'GBytes';
} elseif ($bytes > (1024*1024)) {
$result = sprintf('%.' . $dec_places . 'f', $bytes / (1024*1024));
$result .= 'MBytes';
} elseif ($bytes > 1024) {
$result = sprintf('%.' . $dec_places . 'f', $bytes / 1024);
$result .= 'kBytes';
}
return $result;
}
}
// Return replacement using extended callback function
$messagetext = preg_replace(
'#(^|\[/(' . $skiptaglist . ')\])(.*(\[(' . $skiptaglist . ')|$))#siUe',
"convert_url_to_bbcode_callback_extended('\\3', '\\1')",
$messagetext
);
