Skip to content

Instantly share code, notes, and snippets.

@drrobotnik
Created August 12, 2015 22:27
Show Gist options
  • Save drrobotnik/7a7a2eb4c04031ee03a1 to your computer and use it in GitHub Desktop.
Save drrobotnik/7a7a2eb4c04031ee03a1 to your computer and use it in GitHub Desktop.
url_shortener_shortener
function short_url_replace( $matches ) {
return '>' . $matches[1] . '/' . $matches[2] . '<';
}
function cv_short_url_truncator( $text ) {
$urls = apply_filters( 'cv_short_url_services', array( 't.co', 'bit.ly', 'ow.ly' ) );
return preg_replace_callback( "/]*>http[s]?:\/\/(".implode("|", $urls).")\/([^<]{3})[^<]+</", "short_url_replace", $text );
}
foreach($timeline as $tweet) {
echo'<h2>';
$text = isset( $tweet->retweeted_status ) ? $tweet->retweeted_status->text : $tweet->text;
$text = popuplinks( make_clickable( $text ) );
$text .= ' <a href="http://bit.ly/chv9zxjkcal">http://bit.ly/chv9zxjkcal</a>';
$text .= ' <a href="http://bit.ly/chv9zxjkcal">http://ow.ly/macadoooo</a>';
echo cv_short_url_truncator( $text );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment