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 | |
// Queries the TweetMeme API to check for tweets about this url | |
// If no results, TweetMeme will create a story for this link | |
// Uses the get_url function: http://gist.github.com/370985 | |
// Make sure you set the right permissions for you cache directory! | |
function tweetMeme($bloglink) { | |
// Set some vars: | |
$tweetmemeAPI = 'http://api.tweetmeme.com/url_info?url='; |
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 | |
// Don't like fopen(), use curl to get contents | |
function get_url($url) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); | |
$content = curl_exec($ch); | |
curl_close($ch); |
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 | |
// Fixes a (long) link description to fit your shortened printed string | |
// uses WordCut: http://gist.github.com/370982 | |
// @var = your full text string (function will cut this) | |
function linkfix($var) { | |
$pattern = '%(<a href=")([-/_+0-9a-z]{3,})(">)(.*?)(</a>)%i'; | |
preg_match($pattern, $var, $matches); | |
$newtext = wordCut($matches[4], 20, '...'); |
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 | |
// Generic function for nicely cutting of strings | |
// @text = textstring | |
// @limit = characters to display at end of string (...) | |
// @end = end at xth character | |
function wordCut($text, $limit, $end) { | |
if (strlen($text) > $limit) { | |
$text = strip_tags($text); |
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 | |
// Function to fix the links in tweets (@'s and #'s) | |
// From http://www.snipe.net/2009/09/php-twitter-clickable-links/ | |
function fixTweet($tweet) { | |
$tweet = html_entity_decode($tweet); | |
$tweet = preg_replace('#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#', '\\1<a href="\\2" target="_blank">\\2</a>', $tweet); | |
$tweet = preg_replace('/(@([_a-z0-9\-]+))/i', '<a href="http://twitter.com/$2" title="View $2 on Twitter" target="_blank">$1</a>', $tweet); | |
$tweet = preg_replace('/(#([_a-z0-9\-]+))/i', '<a href="http://search.twitter.com/search?q=%23$2" title="Search $1 on Twitter" target="_blank">$1</a>', $tweet); | |
return $tweet; |
NewerOlder