cf6fc3d9fb5e9d187a014fde0990f28d027acf78
2 /* URL Passing code to allow links from with in emails */
5 $url_parser_php = true;
7 function replaceBlock ($in, $replace, $start, $end) {
8 $begin = substr($in,0,$start);
9 $end = substr($in,$end,strlen($in)-$end);
10 $ret = $begin.$replace.$end;
14 function parseEmail (&$body) {
16 $Size = strlen($body);
18 // Having this defined in just one spot could help when changes need
19 // to be made to the pattern
20 // Make sure that the expression is evaluated case insensitively
22 // Here's pretty sophisticated IP matching:
23 // $IPMatch = '(2[0-5][0-9]|1?[0-9]{1,2})';
24 // $IPMatch = '\[?' . $IPMatch . '(\.' . $IPMatch . '){3}\]?';
27 $IPMatch = '\[?[0-9]{1,3}(\.[0-9]{1,3}){3}\]?';
28 $Host = '(' . $IPMatch . '|[0-9a-z]([-.]?[0-9a-z])*\.[a-wyz][a-z](g|l|m|pa|t|u|v)?)';
29 $Expression = '[0-9a-z]([-_.]?[0-9a-z])*(%' . $Host . ')?@' . $Host;
32 This is here in case we ever decide to use highlighting of searched
33 text. this does it for email addresses
35 if ($what && ($where == "BODY" || $where == "TEXT")) {
36 eregi ($Expression, $body, $regs);
39 $newaddr = eregi_replace ($what, "<b><font color=\"$color[2]\">$what</font></font></b>", $oldaddr);
40 $body = str_replace ($oldaddr, "<a href=\"../src/compose.php?send_to=$oldaddr\">$newaddr</a>", $body);
43 $body = eregi_replace ($Expression, "<a href=\"../src/compose.php?send_to=\\0\">\\0</a>", $body);
47 $body = eregi_replace ($Expression, "<a href=\"../src/compose.php?send_to=\\0\">\\0</a>", $body);
49 // If there are any changes, it'll just get bigger.
50 if ($Size != strlen($body))
56 function parseUrl (&$body)
62 'telnet:', // Special case -- doesn't need the slashes
66 $poss_ends = array(' ', '\n', '\r', '<', '>', '.\r', '.\n', '. ',
67 ' ', ')', '(', '"', '<', '>', '.<', ']', '[', '{',
71 $target_pos = strlen($body);
73 while ($start != $target_pos)
77 // Find the first token to replace
78 foreach ($url_tokens as $the_token)
80 $pos = strpos(strtolower($body), $the_token, $start);
81 if (is_int($pos) && $pos < $target_pos)
84 $target_token = $the_token;
88 // Look for email addresses between $start and $target_pos
89 $check_str = substr($body, $start, $target_pos);
91 if (parseEmail($check_str))
93 $body = replaceBlock($body, $check_str, $start, $target_pos);
94 $target_pos = strlen($check_str) +
$start;
97 // If there was a token to replace, replace it
98 if ($target_token != '')
100 // Find the end of the URL
102 foreach ($poss_ends as $key => $val)
104 $enda = strpos($body,$val,$target_pos);
105 if (is_int($enda) && $enda < $end)
110 $url = substr($body, $target_pos, $end-$target_pos);
112 // Replace URL with HyperLinked Url, requires 1 char in link
113 if ($url != '' && $url != $target_token)
115 $url_str = "<a href=\"$url\" target=\"_blank\">$url</a>";
116 $body = replaceBlock($body,$url_str,$target_pos,$end);
117 $target_pos +
= strlen($url_str);
121 // Not quite a valid link, skip ahead to next chance
122 $target_pos +
= strlen($target_token);
127 $start = $target_pos;
128 $target_pos = strlen($body);