url_parser.php 3.1 KB

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