If you have Microsoft Word this is an easy way to create forms that others can fill in, although your recipients will also need to have MS Word.
Saturday, November 20, 2010
Sunday, November 14, 2010
PHP snippets to interact with Twitter
Get number of Twitter followers
Have you seen my blog sidebar? I display the number of followers I have in full text. This is actually pretty easy to do. The first thing you need is this function:
function get_followers($twitter_id){ $xml=file_get_contents('http://twitter.com/users/show.xml?screen_name='.$twitter_id); if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) { $tw['count'] = $match[1]; } return $tw['count']; }Once you have the function, you can call it as shown below:
$nb = get_followers('phpsnippets'); echo "PHP Snippets already have ".$nb." followers!";» Credit: http://www.phpsnippets.info/get-twitters-followers-in-php
Get latest Twitter status
Using PHP and cURL, it is pretty easy to get the status of a specific user. Once you have it, what about displaying it on your blog, like I do in WPRecipes footer?
function get_status($twitter_id, $hyperlinks = true) { $c = curl_init(); curl_setopt($c, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/$twitter_id.xml?count=1"); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); $src = curl_exec($c); curl_close($c); preg_match('/<text>(.*)<\/text>/', $src, $m); $status = htmlentities($m[1]); if( $hyperlinks ) $status = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", '\\0', $status); return($status); }The function is extremely easy to use:
echo get_status('catswhocode');» http://www.phpsnippets.info/get-twitter-status-using-php
Link to update status, without encoding problems
Many websites and blogs show you how to create a link to Twitter that will update your status. But unfortunely, most websites don’t explain what you need to do in order to avoid encoding problems of spaces and special characters.
Tweet!So, where’s the change? Pretty simple: Just note that I havent linked to
http://www.twitter.com
, but tohttp://twitter.com
, without the www.A working example can be seen on my company website: http://www.webdevcat.com/contact.
Get number of retweets for a specific page
Most bloggers are using the Tweetmeme widget to display the number of retweets of their posts. Did you know that Tweetmeme also has an API you can use to get how many times a specific url has been retweeted?
The following function will get the number of RT’s of the url passed as a parameter:
function tweetCount($url) { $content = file_get_contents("http://api.tweetmeme.com/url_info?url=".$url); $element = new SimpleXmlElement($content); $retweets = $element->story->url_count; if($retweets){ return $retweets; } else { return 0; } }Using the function is easy, as you can expect:
echo tweetCount('http://www.catswhocode.com');Note that the Twitter API also provide a way to get the number of retweets. See http://urls.api.twitter.com/1/urls/count.json?url=www.google.com for example.
» http://www.phpsnippets.info/get-how-many-times-a-page-have-been-retweeted-using-php
Testing friendship between two users
If you want to know if a specific user is following you (or someone else) you have to use the Twitter API. This snippet will echo
true
if the two users specified on lines 18 and 19 are friends. It will returnfalse
otherwise./* makes the request */ function make_request($url) { $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $result = curl_exec($ch); curl_close($ch); return $result; } /* gets the match */ function get_match($regex,$content) { preg_match($regex,$content,$matches); return $matches[1]; } /* persons to test */ $person1 = 'phpsnippets'; $person2 = 'catswhocode'; /* send request to twitter */ $url = 'https://api.twitter.com/1/friendships/exist'; $format = 'xml'; /* check */ $persons12 = make_request($url.'.'.$format.'?user_a='.$person1.'&user_b='.$person2); $result = get_match('/<friends>(.*)<\/friends>/isU',$persons12); echo $result; // returns "true" or "false"» http://www.phpsnippets.info/get-twitter-status-using-php
Shorten urls for Twitter
As you know if you’re a Twitter user, you can’t post messages which are longer than 140 characters. To avoid this problem, you have to use an url shortener. There’s lots of different url shorteners on the internet. TinyUrl.com is one of them, it doesn’t produce the shortest urls but what I really love it is that you don’t need to have an account to use it with PHP.
The following function takes a long url as a parameter and return a shorter url, using the TinyUrl url shortener.
function getTinyUrl($url) { return file_get_contents("http://tinyurl.com/api-create.php?url=".$url); }» http://www.phpsnippets.info/convert-url-to-tinyurl
Shorten urls using Bit.ly
In the previous snippet of that article, I’ve shown you how you can shorten your urls using TinyUrl.com. This is cool, but I’m pretty sure some of you prefer using the bit.ly service. No problem, you can still use PHP to get your shortened url.
function bitly($url) { $content = file_get_contents("http://api.bit.ly/v3/shorten?login=YOURLOGIN&apiKey=YOURAPIKEY&longUrl=".$url."&format=xml"); $element = new SimpleXmlElement($content); $bitly = $element->data->url; if($bitly){ return $bitly; } else { return '0'; } }To use the function, simply use the following:
echo bitly("http://www.catswhocode.com");» http://woorkup.com/2010/06/06/3-practical-wordpress-code-snippets-you-probably-must-know/
You don't need plugins for everything!
Posted by Unknown at 12:42 PM 0 comments
Wednesday, November 10, 2010
How To Easily Turn Your WordPress Blog Into An E-Commerce Site
Posted by Unknown at 8:47 PM 0 comments
Putting FTP Info in wp-config.php to Ease Updates
Posted by Unknown at 8:42 PM 0 comments
Tuesday, November 2, 2010
How to Add an Admin to Your Facebook FanPage
How to Add an Admin to Your Facebook FanPage
Welcome! If you are new here, you might want to get Free Blog Updates via your Favorite RSS Reader . Not sure what an RSS Reader is? Get Free Updates by EmailPowered by WP Greet Box WordPress PluginI get asked quite often how to add an admin to a Facebook FanPage, as it is not such an intuitive process, so here is a quick step-by-step guide to doing just that.
Adding an Admin to Your FanPage on Facebook
- Log in to your Facebook Account. On the top right click on “Account.” Then click on “Manage Pages.” Once you click on “Manage Pages,” select the page you wish to add an Admin for.
- At the top left of your page right under your Fan Page’s logo you will see a link called “Edit Page.” Click on “Edit Page.” (Figure 1)
- Scroll down to the middle of the page. To the right you will see a small box with your profile picture on it. You will see the word “Admins” above your picture. To the right of that header you will see the word “add.” Click on “Add.”
- Once you do that, a window will pop open and ask you to select friends of yours to become admins of your FanPage. You can start typing in the field next to “find friends” or click on the picture if you see the friend in your window. You can also add admins via email by entering the admin’s email address in the email field.
- You can then add a personal message for your new admin. Finally, select “Add Admins.”
All Done!
If you enjoyed this post feed yourself updates!
No comments ]-->
Posted in Facebook Marketing.
Great info to add an admin to your facebook fanpage!
Posted by Unknown at 6:34 PM 0 comments