vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.5 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=113)
-   -   Extended auto-linker (adds ed2k and sip link recognition) (https://vborg.vbsupport.ru/showthread.php?t=100008)

The M.I.P. 11-02-2005 10:00 PM

Extended auto-linker (adds ed2k and sip link recognition)
 
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-extend...o-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-extend...o-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

Quote:

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.

Code:

##############################################################
## 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 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) . '&nbsp;' . $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'>&nbsp;<a $href>$fname&nbsp;($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'>&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 ]-----------------------------------------------


Symen_4ab 01-05-2006 08:04 AM

Quote:

Originally Posted by MioTraGusa
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

Quote:

Originally Posted by Symen_4ab
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


All times are GMT. The time now is 08:21 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01746 seconds
  • Memory Usage 1,790KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete