Convert WordPress links to references

As you can see, I am eating my own food here – writing all links in standard notation but giving them a different outlook.

 1:
 2:
 3:
 4:
 5:
 6:
 7:
 8:
 9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
56:
<?php
/*
Plugin Name: LinkToRef
Version: 0.1
Plugin URI: http://www.wjst.de
Description: Converts links to references
Author: Matthias Wjst
Author URI: http://www.wjst.de
includes code from linknotes script at http://jeremycurry.com
*/

$lnCfg['notes_code'] = '<br /><div class="tagdata"><strong>References: </strong>%items%</div>';
$lnCfg['item_code']  = '[%noted-id%] <a href="%title%" target="_new">%url%</a>&nbsp;';
$lnCfg['desc_code']  = ' - %desc_text%';
$lnCfg = (object) $lnCfg;

class 
linktoref
{
    function 
linkify($text) {
        
$text preg_replace_callback('/<a\shref="(.*)">(.*)<\/a>(.*)(?=\s|$)/Ux', array(&$this"linkd"), $text);
        if (
$this->are_links) {
            for (
$i=1$i <= $this->count$i++) {
                
$links .= $this->items[$i];
            }
            
$linktoref str_replace('%items%'$links$this->notes_code);
            
$text $text.$linktoref;
        }
        return 
$text;
    }
            
    function 
linkd($m) {
        list(, 
$title$url) = $m;
        
$this->count++;
        
$this->are_links true;
        
$itm_replace = array('%noted-id%''%url%','%title%','%return%');
        
$desc $text;
        if (
$text && $url$desc str_replace('%desc_text%'$text$this->desc_code);
        
$itm = array( "$this->count"$url$title$desc$text"#noted-$this->id-$this->count");
        
$this->items[$this->count] = str_replace($itm_replace$itm$this->item_code);
        
$at_title strip_tags($title.$desc);
        return 
"$url<sup><a href=\"$at_title\" target=\"_new\" title=\"$at_title\">[$this->count]</a></sup>";
    }
}

function 
linktoref$string ) {
    global 
$lnCfg,$id;
    
$ln = new linktoref;
    
$ln -> id $id;        
    
$ln->notes_code $lnCfg->notes_code;
    
$ln->item_code  $lnCfg->item_code;
    
$ln->desc_code    $lnCfg->desc_code;                
    return 
$ln->linkify($string);
}

add_filter('the_content''linktoref'4);