PDA

View Full Version : Add "TAG NAME" to my hack.


MRGTB
09-16-2006, 08:23 PM
I released a hack here that is all but complete now as final version except for one feature I want to add to it: https://vborg.vbsupport.ru/showthread.php?t=126481&highlight=ed2k

The feature I want to add is included in another hack here which is very much like mine. But suffered from problems which mine doesn't. But there is a feature in that hack that I want to incorporate into my hack. I have tried loads of ways to contact the author all week, but have been unable to get in touch with him.

The feature in that hack that I want to incorporate into mine, is the "ADD CUSTOM TAG" feature. Which basicley lets you add a custom TAG which will be included in the links posted. The best way I can describe this is to post the code and then highlight bits of the code I'm interested in RED so you can see what I'm talking about.

You will of course have to download my hack from the link above, so you can open my hack and look at how this can be done, by comparing both hacks together. Here is the code below that I'm interested in taking over to my hack. And here is links to both hacks to download both version to compare.

https://vborg.vbsupport.ru/showthread.php?t=100008&highlight=ed2k
https://vborg.vbsupport.ru/showthread.php?t=126481&highlight=ed2k


<?xml version="1.0" encoding="ISO-8859-1"?>

<plugins>
<plugin active="1" product="vbulletin">
<title>Extended auto-linker (adds ed2k and sip link recognition)</title>
<hookname>url_to_bbcode</hookname>
<phpcode><![CDATA[// Hook url_to_bbcode

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($messagete xt, $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\\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
);

return $messagetext;]]></phpcode>
</plugin>
</plugins>


Just want to add that I have been working on this for days, but have been unable my self to carry the ADD TAG across to mine, not because it can't be done. I just can't figure it out!