2 /* URL Passing code to allow links from with in emails */
4 $url_parser_php = true;
6 function replaceBlock ($in, $replace, $start, $end) {
7 $begin = substr($in,0,$start);
8 $end = substr($in,$end,strlen($in)-$end);
9 $ret = $begin.$replace.$end;
13 function parseEmail ($body) {
16 // Changed the expression to the one in abook_take
17 // This works very well, especially it looks like you might have
18 // three instances of it below. Having it defined in
19 // just one spot could help when you need to change it.
20 $Expression = "[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-wyz][a-z](g|l|m|pa|t|u|v)?";
23 This is here in case we ever decide to use highlighting of searched
24 text. this does it for email addresses
26 if ($what && ($where == "BODY" || $where == "TEXT")) {
27 // Use the $Expression
28 eregi ($Expression, $body, $regs);
31 $newaddr = eregi_replace ($what, "<b><font color=\"$color[2]\">$what</font></font></b>", $oldaddr);
32 $body = str_replace ($oldaddr, "<a href=\"../src/compose.php?send_to=$oldaddr\">$newaddr</a>", $body);
35 // Use the $Expression
36 $body = eregi_replace ($Expression, "<a href=\"../src/compose.php?send_to=\\0\">\\0</a>", $body);
39 // Use the $Expression
40 $body = eregi_replace ($Expression, "<a href=\"../src/compose.php?send_to=\\0\">\\0</a>", $body);
44 function parseUrl ($body) {
45 #Possible ways a URL could finish.
47 // Removed "--" since it could be part of a URL
48 $poss_ends=array(" ", "\n", "\r", "<", ">", ".\r", ".\n", ". ", " ", ")", "(",
49 """, "<", ">", ".<", "]", "[", "{", "}");
52 #Look for when a URL starts
53 // Added gopher, news. Modified telnet.
58 "telnet:", // Special case -- doesn't need the slashes
61 for($i = 0; $i < sizeof($url_tokens); $i++
) {
62 // Removed the use of "^^" -- it is unneeded
63 if(is_int($where = strpos(strtolower($body), $url_tokens[$i], $start)))
66 // Look between $start and $where for email links
67 $check_str = substr($body, $start, $where);
68 $new_str = parseEmail($check_str);
70 if ($check_str != $new_str)
72 $body = replaceBlock($body, $new_str, $start, $where);
73 $where = strlen($new_str) +
$start;
76 //$where = strpos(strtolower($body),"http://",$start);
77 // Fixed this to work with $i instead of $where
78 if ($i < sizeof($url_tokens)) {
79 // Removed the "^^" so I removed the next line
80 //$where = $where - 2; // because we added the ^^ at the begining
81 # Find the end of that URL
82 reset($poss_ends); $end=0;
83 while (list($key, $val) = each($poss_ends)) {
84 $enda = strpos($body,$val,$where);
85 if ($end == 0) $end = $enda;
86 if ($enda < $end and $enda != 0) $end = $enda;
88 if (!$end) $end = strlen($body);
90 $url = substr($body,$where,$end-$where);
91 #Replace URL with HyperLinked Url
92 // Now this code doesn't simply match on url_tokens
93 // It will need some more text. This is good.
94 if ($url != "" && $url != $url_tokens[$i]) {
95 $url_str = "<a href=\"$url\" target=\"_blank\">$url</a>";
96 # $body = str_replace($url,$url_str,$body);
97 # echo "$where, $end<br>";
98 $body = replaceBlock($body,$url_str,$where,$end);
99 // Removed unnecessary strpos call. Searching
100 // a string takes longer than just figuring out
102 // $start = strpos($body,"</a>",$where);
103 $start = $where +
strlen($url_str);
105 // Proper length increment -- Don't just assume 7
106 $start = $where +
strlen($url_tokens[$i]);
113 // Look after $start for more email links.
114 $check_str = substr($body, $start);
115 $new_str = parseEmail($check_str);
117 if ($check_str != $new_str)
119 $body = replaceBlock($body, $new_str, $start, strlen($body));