tags $body = addBreaks($body); // create hyperlinks for http:// addresses // there's a testcase for this in /build/testcases/urllinking.txt $replaceFrom = array( '/([^:\/\/\w]|^)((https:\/\/)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/ie', '/([^:\/\/\w]|^)((http:\/\/|www\.)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/ie', '/([^:\/\/\w]|^)((ftp:\/\/|ftp\.)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/ie', '/([^:\/\/\w]|^)(mailto:(([a-zA-Z\@\%\.\-\+_])+))/ie' ); $replaceTo = array( 'COMMENT::createLinkCode("\\1", "\\2","https")', 'COMMENT::createLinkCode("\\1", "\\2","http")', 'COMMENT::createLinkCode("\\1", "\\2","ftp")', 'COMMENT::createLinkCode("\\1", "\\3","mailto")' ); $body = preg_replace($replaceFrom, $replaceTo, $body); return $body; } /** * Creates a link code for unlinked URLs with different protocols * * @ static */ function createLinkCode($pre, $url, $protocol = 'http') { $post = ''; // it's possible that $url ends contains entities we don't want, // since htmlspecialchars is applied _before_ URL linking // move the part of URL, starting from the disallowed entity to the 'post' link part $aBadEntities = array('"', '>', '<'); foreach ($aBadEntities as $entity) { $pos = strpos($url, $entity); if ($pos) { $post = substr($url, $pos) . $post; $url = substr($url, 0, $pos); } } // remove entities at end (&&&&) if (preg_match('/(&\w+;)+$/i', $url, $matches)) { $post = $matches[0] . $post; // found entities (1 or more) $url = substr($url, 0, strlen($url) - strlen($post)); } // move ending comma from url to 'post' part if (substr($url, strlen($url) - 1) == ',') { $url = substr($url, 0, strlen($url) - 1); $post = ',' . $post; } if (!ereg('^'.$protocol.'://',$url)) $linkedUrl = $protocol . (($protocol == 'mailto') ? ':' : '://') . $url; else $linkedUrl = $url; if ($protocol != 'mailto') $displayedUrl = $linkedUrl; else $displayedUrl = $url; return $pre . ''.shorten($displayedUrl,30,'...').'' . $post; } } ?>