url_parser.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. # Find the end of that URL
  48. reset($poss_ends); $end=0;
  49. while (list($key, $val) = each($poss_ends)) {
  50. $enda = strpos($body,$val,$where);
  51. if ($end == 0) $end = $enda;
  52. if ($enda < $end and $enda != 0) $end = $enda;
  53. }
  54. if (!$end) $end = strlen($body);
  55. #Extract URL
  56. $url = substr($body,$where,$end-$where);
  57. #Replace URL with HyperLinked Url
  58. if ($url != "") {
  59. $url_str = "<a href=\"$url\" target=\"_blank\">$url</a>";
  60. # $body = str_replace($url,$url_str,$body);
  61. echo "$where, $end<br>";
  62. $body = replaceBlock($body,$url_str,$where,$end);
  63. $start = strpos($body,"</a>",$where);
  64. } else {
  65. $start = $where + 7;
  66. }
  67. } else {
  68. $done=true;
  69. }
  70. }
  71. return $body;
  72. }
  73. ?>