View Full Version : Extended auto-linker (adds ed2k and sip link recognition)
The M.I.P.
11-02-2005, 10:00 PM
Extended auto-linker 0.2
20051003 by mip
This plugin extends the auto-parse url option to recognize ed2k and sip (VoIP) links correctly.
ed2k file links are pretty-printed with the file name and a human-readable file size.
INSTALLATION:
Upload and activate plugin as usual.
If you want to automatically include a tag in a parsed ed2k link, you should uncomment line 67 (// $filenametag = ...) and set your desired tag.
NOTES:
This plugin uses (among other things) a slightly modified regex which allows "|" characters inside all auto-recognized URLs as required for ed2k links.
SCREENSHOTS:
http://prao.mine.nu/tmp/vbb35-extended-auto-linker-1.jpg
Writing a post containing some ed2k and sip URIs. Auto-parse URL option must be on.
http://prao.mine.nu/tmp/vbb35-extended-auto-linker-2.jpg
Preview of posting with recognized URLs.
Note the formatting of ed2k file urls with the human readable size.
Snake
11-03-2005, 07:15 PM
First one to install, thank you! :D
MioTraGusa
11-07-2005, 07:47 AM
God job, but if the ed2k link contain [ ] don?t work correctly :surprised:
is a minor bug, but it is possible to be solved?
tanks for the modification *installed
Sovereign
11-07-2005, 08:52 PM
Didn't EDonkey shut down because of fileswapping? Does this technology now have a legal use then?
MioTraGusa
11-08-2005, 05:16 PM
Legal_controversy (http://en.wikipedia.org/wiki/Peer-to-peer#Legal_controversy)
Under US law, "the Betamax decision" case holds that copying "technologies" are not inherently illegal, if substantial non-infringing use can be made of them. This decision, predating the widespread use of the Internet applies to most data networks, including peer-to-peer networks, since distribution of correctly licensed files can be performed. These non-infringing uses include sending open source software, public domain files and out of copyright works. Other jurisdictions tend to view the situation in somewhat similar ways.
legal or not legal? that is the question:ninja:
Mastar
11-22-2005, 03:49 PM
Are they any options/settings for this?
MRGTB
12-02-2005, 09:30 AM
Any chance you can port this over as a vB 3.0 hack?
MRGTB
12-27-2005, 01:01 AM
I see this is still in the Beta stages. I hope you fix the square brackets "[]" problem as this hack is very promising.
I also think the option to add your own tag is a great idea, very cool indeed and that gives you the ability to advertise your site in the tag in links.
I have one sugestion though. Make the ed2k links so they open in the same browser window instead of a new browser window. By doing that you won't have to close a new browser window everytime to add a link from the board.
Also take a look here at this same ed2k code created for phpbb for some extra ideas that might prove useful. This hack has come a long way and is the best ed2k hack out there. I'm sure there is stuff in this below you can use.
################################################## ############
## MOD Title: eD2k Links add all Feature
## MOD Author: Simon Moon <simon@gomp.net> (Christian Riesen) http://www.blackpearltech.com/
## MOD Authors: [ Oki/Mozes/Meithar/ppw ]
##
## MOD Description: Makes ed2k links for files and servers clickable and adds a link for adding all files in a post at once.
## MOD Version: 1.2.0
##
## Installation Level: moderate
## Installation Time: 6 Minutes
## Files To Edit: 2
## includes/bbcode.php
## viewtopic.php
## Included Files: images/mule_icon.gif (http://www.ed2k-it.com/forum/images/mule_icon.gif)
## images/ed2k-info.gif (http://www.ed2k-it.com/forum/images/ed2k-info.gif)
##
## Tested with phpBB Version 2.0.11 to 2.0.15
## Forum Link: http://www.phpbb.com/phpBB/viewtopic.php?t=206016
################################################## ############
## For Security Purposes, Please Check: http://www.phpbb.com/mods/downloads/ for the
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered
## in our MOD-Database, located at: http://www.phpbb.com/mods/downloads/
################################################## ############
## Author Notes:
## If you have already installed a ed2k hack (which you mostlikely will have)
## check the files mentioned below anyways and change it to this version of
## the hack. This is very important to ensure it will work properly, otherwise
## you might have weird problems.
## Change the line below that looks like this to have a different text:
## $t_ed2kinsert .= "<a href='javascript:addall()'>Add ".$t_ed2k_confirmed." links to ed2k client</a> ";
## You can for example leave away the number of files.
################################################## ############
## MOD History:
## 2005-05-07 - Version 1.2.0
## - compatible with latest ed2k link formats
## - friendly readable names, kB, MB
## - added icons
##
## 2004-06-27 - Version 1.1.1
## - Error with ' sign in filenames
##
## 2004-06-27 - Version 1.1.0
## - Javascript bug in add all, predefining of filearray
##
## 2004-06-27 - Version 1.0.0
## - First release, works fine, could use some different look
##
################################################## ############
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
################################################## ############
#
#-----[ OPEN ]-----------------------------------------------
#
includes/bbcode.php
#
#-----[ FIND ]-----
#
$bbcode_tpl['url4'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['url4']);
#
#-----[ AFTER, ADD ]-----------------------------------------------
#
// ed2k links
$bbcode_tpl['url5'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']);
$bbcode_tpl['url5'] = str_replace('{DESCRIPTION}', '\\2', $bbcode_tpl['url5']);
// ed2k links with description
$bbcode_tpl['url6'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']);
$bbcode_tpl['url6'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['url6']);
// end ed2k links
#
#-----[ FIND ]-----------------------------------------------
#
// phpBB (www.phpbb.com) code.. (no xxxx:// prefix).
$patterns[] = "#\[url=((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is";
$replacements[] = $bbcode_tpl['url4'];
#
#-----[ AFTER, ADD ]-----------------------------------------------
#
// url-ed2k, name code
$patterns[] = "#\[url=(ed2k://\|file\|.*\|\d+\|\w+\|/?)\](.*?)\[/url\]#si";
$replacements[] = $bbcode_tpl['url5'];
// name code
$patterns[] = "#\[url=(ed2k:(//)?\|server\|[\d\.]+\|\d+\|/?)\](.*?)\[/url\]#si";
$replacements[] = $bbcode_tpl['url6'];
// end url-ed2k
#
#-----[ FIND ]-----------------------------------------------
#
/**
* Rewritten by Nathan Codding - Feb 6, 2001.
* - Goes through the given string, and replaces xxxx://yyyy with an HTML <a> tag linking
* to that URL
#
#-----[ BEFORE, ADD ]-----------------------------------------------
#
// ed2k links
// Returns a file size formatted in a more human-friendly format, rounded
// to the nearest Gb, Mb, Kb, or byte.
function ed2k_humanize_size ($size, $rounder = 0, $min = '')
{
$sizes = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$rounders = array(0, 0, 0, 2, 2, 3, 3, 3, 3);
$ext = $sizes[0];
$rnd = $rounders[0];
if ($min == 'KB' && $size < 1024)
{
$size = $size / 1024;
$ext = 'KB';
$rounder = 1;
}
else
{
for ($i=1, $cnt=count($sizes); ($i < $cnt && $size >= 1024); $i++)
{
$size = $size / 1024;
$ext = $sizes[$i];
$rnd = $rounders[$i];
}
}
if (!$rounder)
{
$rounder = $rnd;
}
return round($size, $rounder) . ' ' . $ext;
}
function ed2k_link_callback ($m)
{
$max_len = 120;
$href = 'href="' . $m[2] . '" class="postlink"';
$size = ed2k_humanize_size($m[4]);
$fname = urldecode($m[3]);
if (strlen($fname) > $max_len)
{
$fname = substr($fname, 0, $max_len - 19) . '...' . substr($fname, -16);
}
if (preg_match('#[<>"]#', $fname))
{
$fname = htmlspecialchars($fname);
}
// added an icon in front of link (ppw)
return "<img src='images/mule_icon.gif' border='0'> <a $href>$fname ($size)</a>";
}
// ed2k links end
#
#-----[ FIND ]-----------------------------------------------
#
function make_clickable($text)
{
$text = preg_replace('#(script|about|applet|activex|chrome ):#is', "\\1:", $text);
// pad it with a space so we can match things at the start of the 1st line.
$ret = ' ' . $text;
#
#-----[ AFTER, ADD ]------------------------------------------
#
// ed2k file links (Meithar):
// ed2k://|file|fileName|fileSize|fileHash|(optional params)|(optional params)|etc|
$ret = preg_replace_callback("#(^|(?<=[^\w\"']))(ed2k://\|file\|([^\\/\|:<>\*\?\"]+?)\|(\d+?)\|([a-f0-9]{32})\|(.*?)/?)(?![\"'])(?=([,\.]*?[\s<\[])|[,\.]*?$)#i", "ed2k_link_callback", $ret);
// ed2k server links:
// ed2k://|server|serverIP|serverPort
$ret = preg_replace("#(^|(?<=[^\w\"']))(ed2k://\|server\|([\d\.]+?)\|(\d+?)\|/?)#i", "<a href=\"\\2\" class=\"postLink\">\\3:\\4</a>", $ret);
// ed2k file links end
#
#-----[ FIND ]-----------------------------------------------
#
// Note: Only the followed chars are valid; alphanums, "-", "_" and or ".".
$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
// Remove our padding..
$ret = substr($ret, 1);
return($ret);
}
#
#-----[ AFTER, ADD ]-----------------------------------------------
#
/**
* Christian Riesen - Jun 27, 2004
* Adds the "Add all links to ed2k client" link to the end of the post text
*/
function make_addalled2k_link($text,$post_id)
{
// padding
$ret = ' ' . $text;
// dig through the message for all ed2k links!
// split up by "ed2k:"
$t_ed2k_raw = explode("ed2k:",$text);
// The first item is garbage
unset($t_ed2k_raw[0]);
// no need to dig through it if there are not at least 2 links!
$t_ed2k_possibles = count($t_ed2k_raw);
if ($t_ed2k_possibles > 1)
{
unset($t_ed2k_reallinks);
foreach ($t_ed2k_raw as $t_ed2k_raw_line)
{
$t_ed2k_parts = explode("|",$t_ed2k_raw_line);
// This looks now like this (only important parts included
/*
[1]=>
string(4) "file"
[2]=>
string(46) "some-filename-here.txt"
[3]=>
string(9) "321456789"
[4]=>
string(32) "112233445566778899AABBCCDDEEFF11"
*/
// Check the obvious things
if (strlen($t_ed2k_parts[1]) == 4 AND $t_ed2k_parts[1] === "file" AND strlen($t_ed2k_parts[2]) > 0 AND strlen($t_ed2k_parts[4]) == 32 AND floatval($t_ed2k_parts[3]) > 0)
{
// This is a true link, lets paste it together and put it in an array
$t_ed2k_reallinks[] = "ed2k://|file|".str_replace("'","\'",$t_ed2k_parts[2])."|".$t_ed2k_parts[3]."|".$t_ed2k_parts[4]."|";
}
}
// Now lets see if we have 2 or more links
// Only then, we do our little trick, because otherwise, it would be wasted for one link alone!
$t_ed2k_confirmed = count($t_ed2k_reallinks);
if ($t_ed2k_confirmed > 1)
{
$t_ed2kinsert = " \n";
$t_ed2kinsert .= "<SCRIPT> ";
$t_ed2kinsert .= "filearray".$post_id."=new Array; ";
$t_ed2kinsert .= "n=0; ";
$i = 0;
foreach($t_ed2k_reallinks as $t_ed2klink)
{
$t_ed2kinsert .= "filearray".$post_id."[".$i."]='".$t_ed2klink."'; ";
$i++;
}
$t_ed2kinsert .= "iv=false; ";
$t_ed2kinsert .= "function addfile".$post_id."(){ ";
$t_ed2kinsert .= " var s=filearray".$post_id."[n]; ";
$t_ed2kinsert .= " n++; ";
$t_ed2kinsert .= " if(n==filearray".$post_id.".length && iv){ ";
$t_ed2kinsert .= " top.clearInterval(iv); ";
$t_ed2kinsert .= " n=0; ";
$t_ed2kinsert .= " } ";
$t_ed2kinsert .= " top.document.location=s; ";
$t_ed2kinsert .= " return true; ";
$t_ed2kinsert .= "} ";
$t_ed2kinsert .= "function addall".$post_id."(){iv=top.setInterval('addfile".$post_id."()',250)} ";
$t_ed2kinsert .= "</SCRIPT> ";
//added an icon in front of link (ppw)
$t_ed2kinsert .= "<img src='images/ed2k-info.gif' border='0'> <a href='javascript:addall".$post_id."()'>Add ".$t_ed2k_confirmed." links to ed2k client</a> ";
$ret = $ret . $t_ed2kinsert;
}
}
// remove padding
$ret = substr($ret, 1);
return($ret);
}
// Add all links to ed2k client end
#
#-----[ OPEN ]-----------------------------------------------
#
viewtopic.php
#
#-----[ FIND ]-----------------------------------------------
#
$message = make_clickable($message);
#
#-----[ BEFORE, ADD ]-----------------------------------------------
#
$message = make_addalled2k_link($message,$postrow[$i]['post_id']); // ed2k link and add all
#-----[ SAVE/CLOSE ALL FILES ]-----------------------------------------------
Symen_4ab
01-05-2006, 08:04 AM
God job, but if the ed2k link contain [ ] don?t work correctly :surprised:
is a minor bug, but it is possible to be solved?
tanks for the modification *installed
Quick-note, to resolve the [ and ] problem, you just have to add quotes to the link parsed, so :
[*url=link]title[/url]
becomes
[*url="link"]title[/url]
I tried to modify the plugin, and now it does add the quotes, but the hack doesn't recognize the link as a link anymore :(
So, if I post a "normal" edk link (without [ or ]), it works, and adds the quotes, but if I post a link with [ in it, it doesn't parse it at all.
edit : Did some code search in the plugin, but regex are a little bit like chinese to me :(
MRGTB
01-05-2006, 10:13 AM
Quick-note, to resolve the [ and ] problem, you just have to add quotes to the link parsed, so :
[*url=link]title[/url]
becomes
[*url="link"]title[/url]
I tried to modify the plugin, and now it does add the quotes, but the hack doesn't recognize the link as a link anymore :(
So, if I post a "normal" edk link (without [ or ]), it works, and adds the quotes, but if I post a link with [ in it, it doesn't parse it at all.
edit : Did some code search in the plugin, but regex are a little bit like chinese to me :(
just a thought, did you try using this instead.
[*url='link']title[/url]
single quotes instead of double to see if that works
Symen_4ab
01-05-2006, 10:18 AM
The main problem is before the parsing, actually !
If you post an ed2k link with brackets, it will not be parsed at all.
If think the regex used is the cause of this, but as I said, I am lost when it comes to regular expressions.
MRGTB
01-05-2006, 10:33 AM
Well I'm not sure if this helps or not.
But I do have ed2k links working on my site no matter if they contain "[]" or not using a simple vBCode command. Of course it will not display the file name, let you add your tag, or even show the file size like this hacks does which is what we want.
But it does work and this is the vBCode I use if it can help this hack in anyway, plus all link using the vBCode way open in the same browser window.
---------------------
Title
ed2k Link
Tag
ed2k
Replacement
<img src="http://www.garybolton.co.uk/vb/images/editor/ed2k.gif"> <a href="{param}" target="_self"><b>Add ed2k link</b></a>
Example
ed2k link goes here
You have to also disable WORD WRAP length in the vB Options to "0". Otherwise spaces will be inserted into the links due to there long length when word wrap is enabled (which are most). Otherwise most links won't works because word wrap will insert spaces into the links. But that get fixed with it set to "0".
---------------------
While this works with all links that use thr "[]" and opens them in the same browser window, it's only a very basic way to get them working. (maybe java code could be used also in vBCode to add more). But it's no were near what we want.
This hack is good because it enables you to add your own TAG to the file names to advertise your site, as well as showing the file size and file name correctly. Plus there is no need to have to use a [ed2k] tag to post the links.
Symen_4ab
01-05-2006, 11:38 AM
Thanks for sharing the bb code Gary, but I would prefer to kame this hack works (but I will make the ed2k tag available as an alternative, for sure !)
I just quit testing different things, and it appears that only the opening bracket poses problems.
I tried to modify some things in the regexp, but it's just too complicated for me :(
edit : The @ character is also a problem, as it sees a part of the link as an email adress
MRGTB
01-05-2006, 12:08 PM
Thanks for sharing the bb code Gary, but I would prefer to kame this hack works (but I will make the ed2k tag available as an alternative, for sure !)
I just quit testing different things, and it appears that only the opening bracket poses problems.
I tried to modify some things in the regexp, but it's just too complicated for me :(
edit : The @ character is also a problem, as it sees a part of the link as an email adress
Same here, I'm not a coder and all that regex stuff is way over my head. Another problem though is the plugin seems to use vBulletins default setting of opening the links in a new browser window also, which is a real no no really.
Because if you had lets say 5 ed2k links in a thread which you clicked. It would mean you having to close 5 new browser windows after. Which is why they have to open in the same browser window just like the phpbb ed2k hacks do to avoid that.
That can be done using a vBCode because of the "target="_self" command. I'm just looking at javascript now to see if that can be used to expand the ed2k vBcode hack further. As it does work when used in vBCode. But it would still be very limited and really it's this hack that needs to be improved upon as a real solution
LOL
Symen_4ab
01-14-2006, 05:37 PM
A quick edit to fix the @ charcater problem (doesn't fix the [ proble, though)...
Add :
$link = str_replace('@', 'a', $link);
Under
if (strtolower($protocolprefix) == 'ed2k://')
{
In the module.
I tried to do something for the [ problem, but as it doesn't even recognize the link as a link, I don't think I'll be able to do anything :(
MRGTB
01-14-2006, 05:55 PM
A quick edit to fix the @ charcater problem (doesn't fix the [ proble, though)...
Add :
$link = str_replace('@', 'a', $link);
Under
if (strtolower($protocolprefix) == 'ed2k://')
{
In the module.
I tried to do something for the [ problem, but as it doesn't even recognize the link as a link, I don't think I'll be able to do anything :(
maybe some other smark coder would be good enough to look this over and fix it seeing as the author is not supporting this hack.
Come you advanced coders, were are you when your needed!
Symen_4ab
01-14-2006, 06:53 PM
Seems I was a little drunk when I wrote my last post, it's full of typos..
Anyway, the bracket is more than a hack problem, it's vbulletin's "problem"
If you post an url with a bracket in it, it will break the url parser too !
I don't think brackets are useable in url anyway :(
http://www.vbulletin.org
vs
http://www.vbulle[tin.org
MRGTB
01-14-2006, 07:29 PM
Seems I was a little drunk when I wrote my last post, it's full of typos..
Anyway, the bracket is more than a hack problem, it's vbulletin's "problem"
If you post an url with a bracket in it, it will break the url parser too !
I don't think brackets are useable in url anyway :(
http://www.vbulletin.org
vs
http://www.vbulle[tin.org
So how comes they work with the BBCode when posted, which I use on my site. I can post ed2k on my site using the bbcode method and "[]" works fine in the links
Symen_4ab
01-14-2006, 07:58 PM
True, because when you use a bbcode, vbulletin does not try to auto-recognize something, it just makes everything inside it a link (or something elese, depending of your bbcode).
So :
[*URL]http://www.vbu[lletin.org[/URL]
becomes
http://www.vbu[lletin.org
But if you don't put the URL tags, it doesn't parse it correctly. You can reproduce this anytime you want ;)
MRGTB
01-14-2006, 08:14 PM
I'm betting there is no way around that and the same with the links opening in a new browser window problem. Without edits some php files like BBCode etc.
The plugin editing templates can only do so much as is limited by the vbcoding. So this would have to be a plugin with files edits as well. I don't see any other way around that.
MRGTB
03-06-2006, 05:50 PM
Has this hack been abandoned now?
As I'm pretty sure the "[]" url parse error has been fixed in this hack here that was causing the same problem:
https://vborg.vbsupport.ru/showthread.php?t=95753&page=8&pp=15
Which might be able to be used from that hack to fix the parse error in this hack if anybody is interested in taking a peep at the code in that to fix the parse error in this when ed2k links use "[]"
MRGTB
09-16-2006, 01:01 PM
Will M.I.P the author or this hack please contact me, I want to talk to you about taking a feature from this hack (ADD TAGS) to incorporate into my ed2k links here:
https://vborg.vbsupport.ru/showthread.php?t=126481&highlight=ed2k
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.