made it so searched results are bold
[squirrelmail.git] / functions / url_parser.php
... / ...
CommitLineData
1<?php
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
13 function parseEmail ($body) {
14 $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);
15 return $body;
16 }
17
18 function parseUrl ($body) {
19 #Possible ways a URL could finish.
20
21 $poss_ends=array(" ", "\n", "\r", "<", ">", ".\r", ".\n", ".&nbsp", "&nbsp", ")", "(","&quot");
22 $done=False;
23 while (!$done) {
24 #Look for when a URL starts
25 $url_tokens = array(
26 "http://",
27 "https://",
28 "ftp://",
29 "telnet://");
30 for($i = 0; $i < sizeof($url_tokens); $i++) {
31 if($where = strpos(strtolower($body), $url_tokens[$i], $start))
32 break;
33 }
34 //$where = strpos(strtolower($body),"http://",$start);
35 if ($where) {
36 # Find the end of that URL
37 reset($poss_ends); $end=0;
38 while (list($key, $val) = each($poss_ends)) {
39 $enda = strpos($body,$val,$where);
40 if ($end == 0) $end = $enda;
41 if ($enda < $end and $enda != 0) $end = $enda;
42 }
43 #Extract URL
44 $url = substr($body,$where,$end-$where);
45 #Replace URL with HyperLinked Url
46 if ($url != "") {
47 $url_str = "<a href=\"$url\" target=\"_blank\">$url</a>";
48 # $body = str_replace($url,$url_str,$body);
49 $body = replaceBlock($body,$url_str,$where,$end);
50 $start = strpos($body,"</a>",$where);
51 } else {
52 $start = $where + 7;
53 }
54 } else {
55 $done=true;
56 }
57 }
58
59 return $body;
60 }
61
62?>
63