Created
June 23, 2012 18:19
-
-
Save philsturgeon/2979285 to your computer and use it in GitHub Desktop.
MODX Revolution Output filter to create links from Twitter @name, #tag and URLs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* TwitterHighlights | |
* Output filter to create links from Twitter @name, #tag and URLs | |
*/ | |
$input = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" rel=\"nofollow\">\\2</a>", $input); | |
$input = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" rel=\"nofollow\">\\2</a>", $input); | |
$input = preg_replace("/@(\w+)/", "<a href=\"https://www.twitter.com/\\1\" rel=\"nofollow\">@\\1</a>", $input); | |
$input = preg_replace("/#(\w+)/", "<a href=\"https://www.twitter.com/search/\\1\" rel=\"nofollow\">#\\1</a>", $input); | |
return $input; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment