Add-on ED2K Links Addon

mrGTB

Well-known member
This is a mod I used with MyBB for a good while, I've made lots of changes to it myself "mainly styling wise, I'm not a coder", and getting help from other coders to help add a lot more functionality with it over time.

There was 2 known issues with this mod working proper with MyBB that I never got solved, one was "Search Highlighting" function breaking links due to colour style span tag being added to keywords searched for. The second very minor issue was "wordwrap" causing problems inserting unwanted space in some very long links. You can read me asking for help here which I never got: http://server.yaldaram.com/showthread.php?mode=linear&tid=1437&pid=6136

If anyone is interested in taking a look at this and converting it over for XenForo as a plug-in, feel free to play around with this code below. If you have any questions what certain things in it do to understand better how it works, please ask.

Reason why I'm asking about this now? One; XenForo doesn't use "Colour Search Highlighting" like MyBB, so it's a none issue. Two; XenForo doesn't use WordWrap either, another none issue. It's just a case of a coder being able to convert this over to XF as a plug-in.

This mod can be used for offering "LEGAL" downloads the same way eMule themselves do being shared on the ED2K networks (think torrent). Difference is nothing is uploaded to your forum (server) and are effectively just normal URL links, that when clicked "if you have emule installed" will add the downloads to your list shared by others using the network.

Take look here: http://contentdb.emule-project.net/

This mod was later expanded to show "File-Size, Download Availably (external site link with no follow), Custom Tag added to links getting advertised in eMule itself. Great for link-backs to your own forum!

Here is the code:

Code:
<?php
 
// --- USER CONFIGURABLE --- //
define('ED2KLINKS_STATISTICSSERVER', 'http://ed2k.shortypower.org/?hash=');
define('ED2KLINKS_LANGSTATISTICS', 'statistics');
// ------------------------- //
 
$plugins->add_hook('parse_message_end', 'ed2klinks_parsetext');
 
function ed2klinks_info()
{
    return array(
        "name"            => "ED2K Links",
        "description"        => "Allows you to download emule links posted on the forum board.",
        "website"        => "http://mybb.com",
        "author"        => "MyBB Group",
        "authorsite"        => "http://mybb.com",
        "version"        => "1.1",
        "guid"            => "",
        "compatibility"    => "16*"
    );
}
 
function ed2klinks_activate()
{
}
 
function ed2klinks_deactivate()
{
}
 
function ed2klinks_parsetext($text)
{
    // Parse ed2k links
 
    preg_match_all("#ed2k://\|file\|(.*?)\|([0-9]+)\|(.*?)\|/#", $text, $link_list, PREG_SET_ORDER);
 
    foreach ($link_list as $link)
    {
        $match = $link[0];
 
    $name  = str_replace('%20', '_', '[mrgtb.com]-' . $link[1]);
        $size  = get_friendly_size($link[2]);
 
        $hashEnd = strpos($link[3], '|');
        if ($hashEnd === false)
        {
            $hash = $link[3];
        }
        else
        {
            $hash  = substr($link[3], 0, strpos($link[3], '|'));
        }
 
    $text = str_replace($match, '<table border="0" cellspacing="1" cellpadding="4" class="tborder">
<thead>
<tr>
<td class="thead" colspan="2"><div><strong>ED2K Link</strong></div></td>
</tr>
</thead>
<tbody>
<tr>
<td class="tcat" colspan="2">
<span class="smalltext"><strong>You need "<a target="_blank" rel="nofollow" href="http://www.emule-project.net/home/perl/general.cgi?l=1&amp;rm=download">eMule</a>" to down these links</strong></span></td>
</tr>
<tr>
<td class="trow1" align="left"><span class="smalltext"><a href="ed2k://|file|[mrgtb.com]-' . $link[1] . '|' . $link[2] . '|' . $hash . '|/">' . $name . '</a></span></td><td width="25%" class="trow2" align="center"><span class="smalltext">[' . $size . ', <a target="_blank" rel="nofollow" href="' . ED2KLINKS_STATISTICSSERVER . $hash . '">' . ED2KLINKS_LANGSTATISTICS . '</a>]</span></td>
</tr>
</tbody>
</table><br />', $text);
    }
 
    preg_match_all("#ed2k://\|server\|(.*?)\|([0-9]+)\|/#", $text, $link_list, PREG_SET_ORDER);
 
    foreach ($link_list as $link)
    {
        $match = $link[0];
        $ip    = $link[1];
        $port  = $link[2];
 
        $text = str_replace($match, 'ed2k server: <a href="' . $match . '">' . $ip . '</a> [port: ' . $port . ']', $text);
    }
 
    return $text;
}
?>
 
All the table style coding was added by me to look nicer in MyBB, it's not required and should be removed. Here is a break-down of code now without all that unwanted stuff included to simply things better for working with.

Code:
<?php
 
// --- USER CONFIGURABLE --- //
define('ED2KLINKS_STATISTICSSERVER', 'http://ed2k.shortypower.org/?hash=');
define('ED2KLINKS_LANGSTATISTICS', 'statistics');
// ------------------------- //
 
function ed2klinks_parsetext($text)
{
    // Parse ed2k links
 
    preg_match_all("#ed2k://\|file\|(.*?)\|([0-9]+)\|(.*?)\|/#", $text, $link_list, PREG_SET_ORDER);
 
    foreach ($link_list as $link)
    {
        $match = $link[0];
 
    $name  = str_replace('%20', '_', '[mrgtb.com]-' . $link[1]);
        $size  = get_friendly_size($link[2]);
 
        $hashEnd = strpos($link[3], '|');
        if ($hashEnd === false)
        {
            $hash = $link[3];
        }
        else
        {
            $hash  = substr($link[3], 0, strpos($link[3], '|'));
        }
 
    $text = str_replace($match, '<a href="ed2k://|file|[mrgtb.com]-' . $link[1] . '|' . $link[2] . '|' . $hash . '|/">' . $name . '</a> [' . $size . ', <a target="_blank" rel="nofollow" href="' . ED2KLINKS_STATISTICSSERVER . $hash . '">' . ED2KLINKS_LANGSTATISTICS . '</a>]', $text);
    }
 
    preg_match_all("#ed2k://\|server\|(.*?)\|([0-9]+)\|/#", $text, $link_list, PREG_SET_ORDER);
 
    foreach ($link_list as $link)
    {
        $match = $link[0];
        $ip    = $link[1];
        $port  = $link[2];
 
        $text = str_replace($match, 'ed2k server: <a href="' . $match . '">' . $ip . '</a> [port: ' . $port . ']', $text);
    }
 
    return $text;
}
?>
 
Top Bottom