59177427 |
1 | <?php |
43fcef5c |
2 | /* URL Passing code to allow links from with in emails */ |
3 | |
4 | $url_parser_php = true; |
5 | |
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; |
10 | return $ret; |
11 | } |
12 | |
175e7218 |
13 | function parseEmail ($body) { |
9297917e |
14 | global $color; |
15 | /* |
16 | This is here in case we ever decide to use highlighting of searched |
17 | text. this does it for email addresses |
18 | |
19 | if ($what && ($where == "BODY" || $where == "TEXT")) { |
20 | eregi ("([a-z]|[0-9]|_|\.|-)+\@([a-z]|[0-9]|_|-)+(\.([a-z]|[0-9]|_|-)+)*", $body, $regs); |
21 | $oldaddr = $regs[0]; |
22 | if ($oldaddr) { |
23 | $newaddr = eregi_replace ($what, "<b><font color=\"$color[2]\">$what</font></font></b>", $oldaddr); |
24 | $body = str_replace ($oldaddr, "<a href=\"../src/compose.php?send_to=$oldaddr\">$newaddr</a>", $body); |
25 | } |
26 | } else { |
27 | $body = eregi_replace ("([a-z]|[0-9]|_|\.|-)+\@([a-z]|[0-9]|_|-)+(\.([a-z]|[0-9]|_|-)+)*", "<a href=\"../src/compose.php?send_to=\\0\">\\0</a>", $body); |
28 | } |
29 | */ |
76e6ff64 |
30 | $body = eregi_replace ("([a-z]|[0-9]|_|\.|-)+\@([a-z]|[0-9]|_|-)+(\.([a-z]|[A-Z])|[a-z]|[0-9]|_|-)+", "<a href=\"../src/compose.php?send_to=\\0\">\\0</a>", $body); |
175e7218 |
31 | return $body; |
32 | } |
33 | |
43fcef5c |
34 | function parseUrl ($body) { |
35 | #Possible ways a URL could finish. |
36 | |
612eda0a |
37 | $poss_ends=array(" ", "\n", "\r", "<", ">", ".\r", ".\n", ". ", " ", ")", "(", |
a037624d |
38 | """, "<", ">", ".<", "]", "[", "{", "}", "--"); |
43fcef5c |
39 | $done=False; |
40 | while (!$done) { |
41 | #Look for when a URL starts |
2b3db0f2 |
42 | $url_tokens = array( |
43 | "http://", |
44 | "https://", |
45 | "ftp://", |
46 | "telnet://"); |
47 | for($i = 0; $i < sizeof($url_tokens); $i++) { |
7e79f496 |
48 | if($where = strpos(strtolower("^^".$body), $url_tokens[$i], $start)) |
2b3db0f2 |
49 | break; |
50 | } |
51 | //$where = strpos(strtolower($body),"http://",$start); |
43fcef5c |
52 | if ($where) { |
7e79f496 |
53 | $where = $where - 2; // because we added the ^^ at the begining |
43fcef5c |
54 | # Find the end of that URL |
55 | reset($poss_ends); $end=0; |
56 | while (list($key, $val) = each($poss_ends)) { |
57 | $enda = strpos($body,$val,$where); |
58 | if ($end == 0) $end = $enda; |
59 | if ($enda < $end and $enda != 0) $end = $enda; |
60 | } |
612eda0a |
61 | if (!$end) $end = strlen($body); |
43fcef5c |
62 | #Extract URL |
63 | $url = substr($body,$where,$end-$where); |
64 | #Replace URL with HyperLinked Url |
65 | if ($url != "") { |
66 | $url_str = "<a href=\"$url\" target=\"_blank\">$url</a>"; |
67 | # $body = str_replace($url,$url_str,$body); |
14a1d0be |
68 | # echo "$where, $end<br>"; |
43fcef5c |
69 | $body = replaceBlock($body,$url_str,$where,$end); |
70 | $start = strpos($body,"</a>",$where); |
71 | } else { |
72 | $start = $where + 7; |
73 | } |
74 | } else { |
75 | $done=true; |
76 | } |
77 | } |
78 | |
79 | return $body; |
80 | } |
81 | |
82 | ?> |
83 | |