[RC2] eD2k links processing with availability statistics

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
DonGato
Registered User
Posts: 127
Joined: Wed Apr 20, 2005 7:48 am

[RC2] eD2k links processing with availability statistics

Post by DonGato »

MOD Title: eD2k links processing with availability statistics
MOD Description: Displays all kind of ed2k links formatted in any possible way and provides a link to file statistics.
MOD Version: 1.0.5

This is an update over an abandoned mod (old thread) and I plan to maintain it so far. Thanks to the people (Meithar, Bill Hicks and C0de_m0nkey) who made it and updated it until now.

MOD Download: ed2kmod_1.0.5.zip
Last Stable version: 1.0.5

Tested on phpBB version 2.0.22
For a phpBB 3 release go to this thread.

Examples:
Image

Updates:
2006.12.15 - Fixed issue with sizes in bytes and added Razorback's Memorial
2006.03.24 - Replaced Razorback by eMugle
2006.01.24 - Added "Add All Links" feature
Last edited by DonGato on Sun Jul 08, 2007 1:58 pm, edited 6 times in total.

Gary Bolton
Registered User
Posts: 93
Joined: Wed Aug 06, 2003 5:34 am
Contact:

Post by Gary Bolton »

Can you add the "Add All" links to this hack that was used in Simon Moons code please

DonGato
Registered User
Posts: 127
Joined: Wed Apr 20, 2005 7:48 am

Post by DonGato »

Done in 1.0.3. Hope it works as expected (just tested it with a couple of topics with multiple links).

Let me know if there is any trouble.

Anybody used those *evil* automation tools to install this mod?
I want to know if it works well the install code. :P

Gary Bolton
Registered User
Posts: 93
Joined: Wed Aug 06, 2003 5:34 am
Contact:

Post by Gary Bolton »

I decided to take a look at this while I was waiting for a reply and added the "ADD ALL LINKS" to the code.

I also made a few other changes also listed below.

1: The file size is highlighted in RED now and is not part of the link itself, I moved the "</a>" forward in-front of the file size so thats not part of the link and kept separate.

2: Added ed2k.gif icon to eD2k, Friends and Server links instead of just plain text message for comsmetic looks, also changes the icons for Razorback to stats.gif image too.

3: "Add All links" added to the code below.

Code: Select all

##############################################################
## MOD Title: eD2k links processing with razorback's statistics
##
## MOD Author: Meithar, then updated by Bill Hicks, C0de_m0nkey
##             and DonGato (current maintainer)
##
## MoD Description: Displays all kind of ed2k links formatted
##                  in any possible way and provides a link
##                  to razorback's statistics.
##
## MOD Version: 1.0.2
##
## Installation Level: Easy
## Installation Time: 2 Minutes
## Files To Edit: includes/bbcode.php
## Included Files: ed2k-info.gif
## License: GNU General Public License v2
##          http://opensource.org/licenses/gpl-license.php
##############################################################
## For security purposes, please check: http://www.phpbb.com/mods/
## for the latest version of this MOD. Although MODs are checked
## before being allowed in the MODs Database there is no guarantee
## that there are no security problems within the MOD. No support
## will be given for MODs not found within the MODs Database which
## can be found at http://www.phpbb.com/mods/
##############################################################
## Author Notes (Bill Hicks):
##
## The razorback's search idea was mentioned one day by a friend
## who found it hard to see how files he had released were
## spread on the network.
## Before I came up with this mod he had to open a second client
## to check the spread status; not any more!
## With the link posted in phpBB you will see a small icon after
## the link. If you click this icon the code will automatically
## redirect you to razorback's statistics web.
## When you click the icon it searches the hash id for that link
## and returns how many full sources and users are downloading
## the file, as well as other useful data.
##
## Thanks to Meithar who made the filesize link code in the first place.
##############################################################
## MOD History:
##
##   2006-01-04 - Version 1.0.2
##      - DonGato updated code to last phpBB version, added processing of
##        other link formats and fixed some minor issues.
##
##   2005-03-26 - Version 1.0.1
##      - Bill Hicks/c0de_m0nkey updated the code to include razorback2
##        source search from hash id through a small info
##        icon in front of the ed2k link.
##
##   2005-03-12 - Version 1.0.0
##      - Meithar posted the file size mod at www.phpbb.com
##
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################
#

#
#-----[ COPY ]------------------------------------------
#

copy images/ed2k.gif to your "images" directory
copy images/stats.gif to your "images" directory

#
#-----[ OPEN ]------------------------------------------
#

includes/bbcode.php

#
#-----[ FIND ]------------------------------------------
#

	$replacements[] = $bbcode_tpl['email'];

#
#-----[ AFTER, ADD ]------------------------------------------
#

	// [url]ed2k://|file|...[/url] code
	$patterns[] = "#\[url\](ed2k://\|file\|(.*?)\|\d+\|\w+\|(h=\w+\|)?/?)\[/url\]#is";
	$replacements[] = '<a href="$1" class="postlink">$2</a>';
	// [url=ed2k://|file|...]name[/url] code
	$patterns[] = "#\[url=(ed2k://\|file\|(.*?)\|\d+\|\w+\|(h=\w+\|)?/?)\](.*?)\[/url\]#si";
	$replacements[] = '<a href="$1" class="postlink">$4</a>';
	// [url]ed2k://|server|ip|port|/[/url] code
	$patterns[] = "#\[url\](ed2k://\|server\|([\d\.]+?)\|(\d+?)\|/?)\[/url\]#si";
	$replacements[] = 'ed2k server: <a href="$1" class="postlink">$2:$3</a>';
	// [url=ed2k://|server|ip|port|/]name[/url] code
	$patterns[] = "#\[url=(ed2k://\|server\|[\d\.]+\|\d+\|/?)\](.*?)\[/url\]#si";
	$replacements[] = '<a href="$1" class="postlink">$2</a>';
	// [url]ed2k://|friend|name|ip|port|/[/url] code
	$patterns[] = "#\[url\](ed2k://\|friend\|(.*?)\|[\d\.]+\|\d+\|/?)\[/url\]#si";
	$replacements[] = 'ed2k friend: <a href="$1" class="postlink">$2</a>';
	// [url=ed2k://|friend|name|ip|port|/]name[/url] code
	$patterns[] = "#\[url=(ed2k://\|friend\|(.*?)\|[\d\.]+\|\d+\|/?)\](.*?)\[/url\]#si";
	$replacements[] = '<a href="$1" class="postlink">$3</a>';

#
#-----[ 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;

#
#-----[ REPLACE WITH ]------------------------------------------
#

function humanize_size ($size, $rounder = 0, $min = '')
{
	$sizes   = array('Bytes', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb');
	$rounders = array(0, 1, 2, 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];
		 $format =  '%.' . $rnd . 'f ' . $ext;
	  }
	}

	if (!$rounder)
	{
	  $rounder = $rnd;
	}

	return sprintf($format, round($size, $rounder));
}

function ed2k_link_callback ($m)
{
	$max_len = 100;
	$href = 'href="' . $m[2] . '" class="postlink"';
	$fname = rawurldecode($m[3]);
	$size = humanize_size($m[4]);

	if (strlen($fname) > $max_len)
	{
	  $fname = substr($fname, 0, $max_len - 19) . '...' . substr($fname, -16);
	}
	if (preg_match('#[<>"]#', $fname))
	{
	  $fname = htmlspecialchars($fname);
	}
	return "<img src='images/ed2k.gif' border='0' title='eD2K Link' style='vertical-align: middle;'> <a $href>$fname</a> <font color='red'>[$size]</font> <a href='http://stats.razorback2.com/ed2khistory?ed2k=$m[5]' target='_blank'><img src='images/stats.gif' border='0' title='Razorback Statistics' style='vertical-align: middle;'></a>";
}

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;

	// 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|serverIP|serverPort|/
	$ret = preg_replace("#(^|(?<=[^\w\"']))(ed2k://\|server\|([\d\.]+?)\|(\d+?)\|/?)#i", "<img src='images/ed2k.gif' border='0' title='eD2K Server Link' style='vertical-align: middle;'> <a href=\"\\2\" class=\"postLink\">\\3:\\4</a>", $ret);
	// ed2k://|friend|name|clientIP|clientPort|/
	$ret = preg_replace("#(^|(?<=[^\w\"']))(ed2k://\|friend\|([^\\/\|:<>\*\?\"]+?)\|([\d\.]+?)\|(\d+?)\|/?)#i", "<img src='images/ed2k.gif' border='0' title='eD2K Friend Link' style='vertical-align: middle;'> <a href=\"\\2\" class=\"postLink\">\\3</a>", $ret);

#
#-----[ 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'>&nbsp;<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 ]------------------------------------------
#
# EoM
I would like to point out though that HTML ed2k links don't work when copied and pasted into the board (even if you have HTML enabled). Check my HTML demo link here, as well as viewing the other changes I've made to make the links just look nicer. Hope you don't mind!

Demo Link with changes: http://www.garybolton.co.uk/forum/viewtopic.php?t=3

DonGato
Registered User
Posts: 127
Joined: Wed Apr 20, 2005 7:48 am

Post by DonGato »

Well, I don't like to highlight nor include the size inside the link.
I'm not a friend of icons so the eMule icon won't be there as well.
There are people out there allowing HTML in php forums? 8O

Gary Bolton
Registered User
Posts: 93
Joined: Wed Aug 06, 2003 5:34 am
Contact:

Post by Gary Bolton »

DonGato wrote: Well, I don't like to highlight nor include the size inside the link.
I'm not a friend of icons so the eMule icon won't be there as well.
There are people out there allowing HTML in php forums? 8O


No, the File Size was previously included in the link. I moved the File Size outside of the link so it was not underlined when hovered over as thought it was part of the link, by moving the </a> forward and removing the two code spaces also as they were not needed when the </a> tag was moved.

No, people don't use HTML as it poses a security risk. So that doesn't matter, I must have mis-understood. As I thought your hack fixed the HTML ed2k links. I must have read things wrong. No problem!

If you don't like the file size highlighted in red to stand out and the ed2k images added to the links instead of a text message, thats OK. Just a matter of taste really. I just did it for my own personal taste really.

Gary Bolton
Registered User
Posts: 93
Joined: Wed Aug 06, 2003 5:34 am
Contact:

Post by Gary Bolton »

There is a problem with the ADD ALL LINKS

If you post ed2k links using the [url] brackets around them, it counts one link as two links.

Try mixing normal ed2k links with a few using the [url] to see what I mean. While it will count normal ed2k links added in the normal way correct as one link, as soon as you add others with [url] bbcode. It starts to count each link as two links

DonGato
Registered User
Posts: 127
Joined: Wed Apr 20, 2005 7:48 am

Post by DonGato »

No, I don't see such thing... maybe you're adding the line in viewtopic.php in the wrong place. Download 1.0.3 code and see. ;)

Gary Bolton
Registered User
Posts: 93
Joined: Wed Aug 06, 2003 5:34 am
Contact:

Post by Gary Bolton »

Just double checked again, same problem though. If I add two ed2k link the normal way by just pasting the ed2k links it works fine in saying "add 2 links".

But if I edit the post and add a 3rd ed2k using the [url] brackets around it, it then counts 4 links instead of 3. It seems to be counting links added using the [url] brackets wrapped around them as 2 links instead of one for some strange reason.

DonGato
Registered User
Posts: 127
Joined: Wed Apr 20, 2005 7:48 am

Post by DonGato »

Sorry, but I can't repro. You should check the changes if there are like the ones I have in this mod, and maybe another mod you're using in your forum is colliding with it. Really strange. :?

User avatar
felipe
Registered User
Posts: 112
Joined: Wed Dec 21, 2005 6:12 am
Contact:

Post by felipe »

I need an ed2k MOD, a really really simple one that makes a ed2k:// protocol link and a DONKEY icon. I've been up all night, and can't find s**t. can anybody point me to one? i'm just out of steam at the moment.......................
Felipe Alvarez's website

DonGato
Registered User
Posts: 127
Joined: Wed Apr 20, 2005 7:48 am

Post by DonGato »

And why not use this one?
It's really easy to install...

User avatar
felipe
Registered User
Posts: 112
Joined: Wed Dec 21, 2005 6:12 am
Contact:

Post by felipe »

Gary Bolton:
Your link doesn't work for me...dead(?)

I'm gonna install this one, and take your word for it Don Cat :wink: (I"m teasin', i trust its gonna be great!)
Felipe Alvarez's website

User avatar
felipe
Registered User
Posts: 112
Joined: Wed Dec 21, 2005 6:12 am
Contact:

Post by felipe »

is there any way to add a mule's head to the start of the link when posted? what about a [emule] ed2k ://|file|798790707 [/emule]
tag that will add the mule's head and make the protocol ed2k : ?

this is an example of me asking nicely, i hope it came out like that :shock:
Felipe Alvarez's website

DonGato
Registered User
Posts: 127
Joined: Wed Apr 20, 2005 7:48 am

Post by DonGato »

Code: Select all

##############################################################
## MOD Title: eD2k links processing with razorback's statistics
##
## MOD Author: Meithar, then updated by Bill Hicks, C0de_m0nkey
##             and DonGato (current maintainer)
##
## MoD Description: Displays all kind of ed2k links formatted
##                  in any possible way and provides a link
##                  to razorback's statistics.
##
## MOD Version: 1.0.3
##
## Installation Level: Easy
## Installation Time: 2 Minutes
## Files To Edit: includes/bbcode.php
## Included Files: ed2k-info.gif
## License: GNU General Public License v2
##          http://opensource.org/licenses/gpl-license.php
##############################################################
## For security purposes, please check: http://www.phpbb.com/mods/
## for the latest version of this MOD. Although MODs are checked
## before being allowed in the MODs Database there is no guarantee
## that there are no security problems within the MOD. No support
## will be given for MODs not found within the MODs Database which
## can be found at http://www.phpbb.com/mods/
##############################################################
## Author Notes (Bill Hicks):
##
## The razorback's search idea was mentioned one day by a friend
## who found it hard to see how files he had released were
## spread on the network.
## Before I came up with this mod he had to open a second client
## to check the spread status; not any more!
## With the link posted in phpBB you will see a small icon after
## the link. If you click this icon the code will automatically
## redirect you to razorback's statistics web.
## When you click the icon it searches the hash id for that link
## and returns how many full sources and users are downloading
## the file, as well as other useful data.
##
## Thanks to Meithar who made the filesize link code in the first place.
##############################################################
## MOD History:
##
##   2006-01-24 - Version 1.0.3
##      - DonGato added modified code for Add All Links with support
##        for one additional parameter
##
##   2006-01-04 - Version 1.0.2
##      - DonGato updated code to last phpBB version, added processing of
##        other link formats and fixed some minor issues.
##
##   2005-03-26 - Version 1.0.1
##      - Bill Hicks/c0de_m0nkey updated the code to include razorback2
##        source search from hash id through a small info
##        icon in front of the ed2k link.
##
##   2005-03-12 - Version 1.0.0
##      - Meithar posted the file size mod at www.phpbb.com
##
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################
#

#
#-----[ COPY ]------------------------------------------
#
copy images/ed2k-info.gif to images/ed2k-info.gif

#
#-----[ OPEN ]------------------------------------------
#
viewtopic.php

#
#-----[ FIND ]------------------------------------------
#

	$message = make_clickable($message);

#
#-----[ BEFORE, ADD ]------------------------------------------
#
	// ed2k Add all links feature
	$message = make_addalled2k_link($message,$postrow[$i]['post_id']);

#
#-----[ OPEN ]------------------------------------------
#
includes/bbcode.php

#
#-----[ FIND ]------------------------------------------
#
	$replacements[] = $bbcode_tpl['email'];

#
#-----[ AFTER, ADD ]------------------------------------------
#

	// [url]ed2k://|file|...[/url] code
	$patterns[] = "#\[url\](ed2k://\|file\|(.*?)\|\d+\|\w+\|(h=\w+\|)?/?)\[/url\]#is";
	$replacements[] = '<img src='images/emule.gif' border='0'> <a href="$1" class="postlink">$2</a>';
	// [url=ed2k://|file|...]name[/url] code
	$patterns[] = "#\[url=(ed2k://\|file\|(.*?)\|\d+\|\w+\|(h=\w+\|)?/?)\](.*?)\[/url\]#si";
	$replacements[] = '<img src='images/emule.gif' border='0'> <a href="$1" class="postlink">$4</a>';
	// [url]ed2k://|server|ip|port|/[/url] code
	$patterns[] = "#\[url\](ed2k://\|server\|([\d\.]+?)\|(\d+?)\|/?)\[/url\]#si";
	$replacements[] = 'ed2k server: <a href="$1" class="postlink">$2:$3</a>';
	// [url=ed2k://|server|ip|port|/]name[/url] code
	$patterns[] = "#\[url=(ed2k://\|server\|[\d\.]+\|\d+\|/?)\](.*?)\[/url\]#si";
	$replacements[] = '<a href="$1" class="postlink">$2</a>';
	// [url]ed2k://|friend|name|ip|port|/[/url] code
	$patterns[] = "#\[url\](ed2k://\|friend\|(.*?)\|[\d\.]+\|\d+\|/?)\[/url\]#si";
	$replacements[] = 'ed2k friend: <a href="$1" class="postlink">$2</a>';
	// [url=ed2k://|friend|name|ip|port|/]name[/url] code
	$patterns[] = "#\[url=(ed2k://\|friend\|(.*?)\|[\d\.]+\|\d+\|/?)\](.*?)\[/url\]#si";
	$replacements[] = '<a href="$1" class="postlink">$3</a>';

#
#-----[ 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;

#
#-----[ REPLACE WITH ]------------------------------------------
#

function humanize_size ($size, $rounder = 0, $min = '')
{
	$sizes   = array('Bytes', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb');
	$rounders = array(0, 1, 2, 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];
		 $format =  '%.' . $rnd . 'f ' . $ext;
	  }
	}

	if (!$rounder)
	{
	  $rounder = $rnd;
	}

	return sprintf($format, round($size, $rounder));
}

function ed2k_link_callback ($m)
{
	$max_len = 100;
	$href = 'href="' . $m[2] . '" class="postlink"';
	$fname = rawurldecode($m[3]);
	$size = humanize_size($m[4]);

	if (strlen($fname) > $max_len)
	{
	  $fname = substr($fname, 0, $max_len - 19) . '...' . substr($fname, -16);
	}
	if (preg_match('#[<>"]#', $fname))
	{
	  $fname = htmlspecialchars($fname);
	}
	return "<img src='images/emule.gif' border='0'> <a $href>$fname&nbsp;&nbsp;[$size]</a> <a href='http://stats.razorback2.com/ed2khistory?ed2k=$m[5]' target='_blank'><img src='images/ed2k-info.gif' border='0' title='razorback statistics' style='vertical-align: middle;'></a>";
}

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;

	// 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|serverIP|serverPort|/
	$ret = preg_replace("#(^|(?<=[^\w\"']))(ed2k://\|server\|([\d\.]+?)\|(\d+?)\|/?)#i", "ed2k server: <a href=\"\\2\" class=\"postLink\">\\3:\\4</a>", $ret);
	// ed2k://|friend|name|clientIP|clientPort|/
	$ret = preg_replace("#(^|(?<=[^\w\"']))(ed2k://\|friend\|([^\\/\|:<>\*\?\"]+?)\|([\d\.]+?)\|(\d+?)\|/?)#i", "ed2k friend: <a href=\"\\2\" class=\"postLink\">\\3</a>", $ret);

#
#-----[ FIND ]------------------------------------------
#
/**
 * Nathan Codding - Feb 6, 2001
 * Reverses the effects of make_clickable(), for use in editpost.
 * - Does not distinguish between "www.xxxx.yyyy" and "http://aaaa.bbbb" type URLs.
 *
 */
function undo_make_clickable($text)

#
#-----[ BEFORE, ADD ]------------------------------------------
#

// Code by Christian Riesen - Jun 27, 2004
// Updated by DonGato to support an additional parameter - January 24, 2005
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) "filename.extension"
			[3]=>
			string(9) "321456789"
			[4]=>
			string(32) "112233445566778899AABBCCDDEEFF11"
			[5]=>
			string(?) "source or AICH hash"
			*/

			// 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 floatval($t_ed2k_parts[3]) > 0 AND strlen($t_ed2k_parts[4]) == 32)
			{
				// This is a true link, lets paste it together and put it in an array
				if (substr($t_ed2k_parts[5], 0, 2) == "h=" || substr($t_ed2k_parts[5], 0, 7) == "sources")
					$t_ed2k_reallinks[] = "ed2k://|file|".str_replace("'","\'",$t_ed2k_parts[2])."|".$t_ed2k_parts[3]."|".$t_ed2k_parts[4]."|".$t_ed2k_parts[5]."|/";
				else
					$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 = "<br /><br />";
			$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> ";
			$t_ed2kinsert .= "<span class='gensmall'><a href='javascript:addall".$post_id."()' class='postlink'>[ Add all ".$t_ed2k_confirmed." links to your ed2k client ]</a></span>";
			$ret = $ret . $t_ed2kinsert;
		}
	}

	// remove padding
	$ret = substr($ret, 1);

	return($ret);
}

#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM
And the image is Image but rename it to emule.gif and put it in the directory.

Post Reply

Return to “[2.0.x] MODs in Development”