• Home
  • Services
  • Profile
  • Portfolio
  • Contact
  • Links
  • Blog
  • Archives
  • Sitemap
Subscribe: Posts | Comments | E-mail
  • Ajax XMLHttpRequestAsynchronous HTTP Request How To's
  • FreebiesBest Freebies Collection
  • MiscellaneousNews, Announcements & General Stuffs
  • Print & Web DesignPhotoshop, Vector, CSS, XHTML
  • ProgrammingProgramming PHP, ASP, .NET and more

Bali Web Design

Posted on September 12, 2009 - by ruby

How to embed plurk status in wordpress blog

Programming Tutorials

I had signup with plurk a year ago but haven’t “plurking” since i use twitter a lot, and for me both of them were created for same purpose, microblogging, sharing what you’re up to in few sentences and follow what your friends up to. Today i had re-theming my personal blog and use free seven five wordpress theme by press75 which is very simple and already integrated with twitter status, delicious bookmarks, and external RSS feed, then i thinks its good to add plurk also.

Theres a wordpress plugin to achieve this purpose already, but here i only need to fetch status update, and dont need any widget or possibility to update my status from my blog, and here we go,

// fetch plurk messages
function plurk_messages(
$username = '',
$num = 1,
$list = true,
$show_username = false,
$show_moods = true,
$encode_utf8 = false)
{
$plurk_url = 'http://www.plurk.com';

$plurk_moods = array('loves','likes','shares','gives','hates','wants','wishes','needs','will','hopes','asks','has','was','wonders','feels','thinks','says','is');
array_walk($plurk_moods, 'plurk_addspace');

$plurk_mood_replace = array();
$plurk_mood_replacer = array();

include_once(ABSPATH . WPINC . '/rss.php');

$messages = fetch_rss('http://www.plurk.com/user/' . $username . '.xml');

if ($list) echo '<ul class="plurk">';

if ($username == '')
{
if ($list) echo '<li>';
echo 'RSS not configured';
if ($list) echo '</li>';
}
else
{
if ( empty($messages->items) )
{
if ($list) echo '<li>';
echo 'No public plurk messages.';
if ($list) echo '</li>';
}
else
{
// start fetching
$i = 0;
foreach ( $messages->items as $message )
{
$msg = $message['atom_content'];
$author_name = $message['author_name'];
$link = $plurk_url.$message['link_'];
$time = strtotime($message['published']);

if(!$show_moods) { $msg = str_replace($plurk_moods,'',$msg); }
else {
if(empty($plurk_mood_replace)||empty($plurk_moods_replacer)){
list($plurk_mood_replace,$plurk_mood_replacer) = plurk_moods_format($plurk_moods,$author_name);
}
$msg = str_replace($plurk_mood_replace,$plurk_mood_replacer,$msg);
}

if(!$show_username) { $msg = str_replace($author_name.' ','',$msg); }
else { $msg = str_replace($author_name,'<a class="plurk_username" href="'.$plurk_url.'/'.$username.'">'.$author_name.'</a>',$msg); }

if($encode_utf8) $msg = utf8_encode($msg);

if ($list) { echo '<li class="plurk-item">'; } else { echo '<p class="plurk-message">'; }

$msg = preg_replace("/<a href=[\"' ]?([^\"' >]+)[\"' ]?[^>]*>(.*?)<\/a>/i",'$1',$msg);
$msg = plurk_hyperlinks($msg);
$msg = plurk_users($msg);

echo $msg;

if ( ( abs( time() - $time) ) < 86400 ) {  $h_time = sprintf( __('%s ago'), human_time_diff( $time ) ); }
else{ $h_time = date(__('Y/m/d'), $time); }

echo '<span class="plurk-timestamp"><abbr title="' . date(__('Y/m/d H:i:s'), $time) . '">' . $h_time . '</abbr></span>';

if ($list) { echo '</li>'; } else { echo '</p>'; }

$i++;
if ( $i >= $num ) break;
}
// end fetching -->
}
}
if ($list) echo '</ul>';
}
// set pattern + replacement for message prefix (says, is etc.)
function plurk_moods_format($plurk_moods,$user){
$plurk_moods_replace = $plurk_moods_replacer = array();
foreach($plurk_moods as $mood){
$plurk_moods_replace[] = "$user $mood";
$plurk_moods_replacer[] = $user.' <span class="plurk-'.trim($mood).'">'.trim($mood).'</span> ';
}
return array($plurk_moods_replace,$plurk_moods_replacer);
}
// add spaces into moods
function plurk_addspace(&$item,$key) { $item = "$item "; }

And couple of functions below taken from Twitter for Wordpress plugin by Ricardo Gonzalez to format autolink and in-reply message.

// format autolink
function plurk_hyperlinks($text) {
// Props to Allen Shaw & webmancers.com
// match protocol://address/path/file.extension?some=variable&another=asf%
//$text = preg_replace("/\b([a-zA-Z]+:\/\/[a-z][a-z0-9\_\.\-]*[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%]*)\b/i","<a href=\"$1\" class=\"plurk-link\">$1</a>", $text);
$text = preg_replace('/\b([a-zA-Z]+:\/\/[\w_.\-]+\.[a-zA-Z]{2,6}[\/\w\-~.?=&%#+$*!]*)\b/i',"<a href=\"$1\" class=\"plurk-link\">$1</a>", $text);
// match www.something.domain/path/file.extension?some=variable&another=asf%
//$text = preg_replace("/\b(www\.[a-z][a-z0-9\_\.\-]*[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%]*)\b/i","<a href=\"http://$1\" class=\"plurk-link\">$1</a>", $text);
$text = preg_replace('/\b(?<!:\/\/)(www\.[\w_.\-]+\.[a-zA-Z]{2,6}[\/\w\-~.?=&%#+$*!]*)\b/i',"<a href=\"http://$1\" class=\"plurk-link\">$1</a>", $text);

// match name@address
$text = preg_replace("/\b([a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]*\@[a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]{2,6})\b/i","<a href=\"mailto://$1\" class=\"plurk-link\">$1</a>", $text);
//mach #trendingtopics. Props to Michael Voigt
$text = preg_replace('/([\.|\,|\:|\¡|\¿|\>|\{|\(]?)#{1}(\w*)([\.|\,|\:|\!|\?|\>|\}|\)]?)\s/i', "$1<a href=\"http://plurk.com/#search?q=$2\" class=\"plurk-link\">#$2</a>$3 ", $text);
return $text;
}
// in-reply to
function plurk_users($text) {
$text = preg_replace('/([\.|\,|\:|\¡|\¿|\>|\{|\(]?)@{1}(\w*)([\.|\,|\:|\!|\?|\>|\}|\)]?)\s/i', "$1<a href=\"http://plurk.com/$2\" class=\"plurk-user\">@$2</a>$3 ", $text);
return $text;
}

Copy those functions in your functions.php at your active theme folder, or you can put it in separate file then include it in your functions.php file.

The implementation is simple, just call the function in your file where you need your plurk status to be placed.

plurk_messages('username',10) ;

The function tahe few parameters in sequential order as follow:

  1. Username
  2. Number of status to be displayed
  3. Flag true/false Use unordinal list or note (ul li or p)
  4. Flag true/false show your username in the message
  5. Flag true/false show the message prefix or not
  6. Flag true/false Encode the message in UTF8 or not

How to styling? you need to add CSS for few class of the HTML tag which are auto generated by the function

ul.plurk, li.plurk-item. p.plurk-message, a.plurk_username, span.plurk-timestamp, a.plurk-link, a.pluk-user, also series of span with classes prefix by plurk- and followed by message prefix eg: span.plurk-says, span.plurk-loves etc.

Do you plurking? add me!

Thas it, hopely it usefull for you.

Share this article:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • Ping.fm
  • Pownce
  • Slashdot
  • StumbleUpon
  • Technorati
  • Tumblr
  • TwitThis
This entry was posted on Saturday, September 12th, 2009 at 08:13 and is filed under Programming, Tutorials. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

7 Comments

We'd love to hear yours!



  1. Visit My Website

    September 12, 2009

    Permalink

    Jauhari said:

    Nice tuts bro



  2. Visit My Website

    September 15, 2009

    Permalink

    Varun Mehta said:

    Nice stuff, but your website is too cramped to display code properly, also it does not gel well with the existing layout



  3. Visit My Website

    September 19, 2009

    Permalink

    Cody said:

    Cool – Thanks for the updated, I’ve never heard of Plurk before. I’ll have to check it out.



  4. Visit My Website

    September 24, 2009

    Permalink

    PHP Class Create Short URL via TinyURL, Is.gd, Hex.io & Bit.ly API said:

    [...] How to embed plurk status in wordpress blog by ruby on September 12, 2009 [...]



  5. Visit My Website

    September 29, 2009

    Permalink

    How to Embed Plurk Timeline « Bali Web Design Studio said:

    [...] Plurk Timeline, Flickr Photostreams, and Delicious Bookmarks, I need to write my own function to grab and display my plurk timeline using PHP since the blog is built in wordpress [...]



  6. Visit My Website

    May 1, 2010

    Permalink

    Adam Brooks said:

    microblogging is really useful when you want to broadcast short updates. i am still leaning towards traditional blogging.~”-



  7. Visit My Website

    May 11, 2010

    Permalink

    iwan trisna said:

    Nice Post:) never heard about plurk before. lets cekidot.
    oh iya tinggal di bali ya;) kapan2 bole dunk belajar. good portofolio
    CU



Leave a Comment

Here's your chance to speak.

  1. Name (required)

    Mail (required)

    Website

    Message

  • Most Popular Posts

    • { 108 } ResponsesPHP ajax login form using Jquery
    • { 79 } Responsesphp ajax tutorial create ajax based login form using jquery
    • { 71 } ResponsesASP Classic Programming Still Alive
    • { 53 } Responses63+ best practice to optimize PHP code performances
    • { 44 } ResponsesVideobox: Lightbox for videos
  • Latest Posts

    • PHP Newbie: Proper handling of Error & Exception in PHP
    • Why SEO lost importance
    • jQuery Mobile Announced : Touch-Optimized Web Framework for Smartphones & Tablets
    • Multiple Google Account Signin
    • Install, Configure & Running Memcache in Windows as Service
    • DynamicWP Image Cube Wordpress Plugin
    • New Wordpress 3.0 API menu_page_url
    • Wordpress 3.0 Custom Taxonomy
    • JQuery DataGrid Plugin Compass
    • Upgrading to upcoming CodeIgniter 2.0
  • Categories

    • advertorial
    • Ajax XMLHttpRequest
    • Featured
    • Freebies
    • Miscellaneous
    • Print & Web Design
    • Programming
    • Tutorials
    • Web 2.0
  • Featured News

    • PHP Newbie: Proper handling of Error & Exception in PHP by webmaster on August 18, 2010
    • Why SEO lost importance by webmaster on August 16, 2010
    • jQuery Mobile Announced : Touch-Optimized Web Framework for Smartphones & Tablets by webmaster on August 16, 2010
    • Install, Configure & Running Memcache in Windows as Service by webmaster on June 27, 2010
    • Website Optimization Best Practices, speed up your website load by ruby on May 21, 2009
  • Tag Cloud

    • Actionscript advertorial Ajax XMLHttpRequest API best practices CakePHP chat Classic ASP CMS CSS Development facebook firefox Flash flickr Freebies gmail HTML icons Javascript Jobs jQuery jQuery Plugins Library Lightbox memcache Mootools news Personal PHP PHP Frameworks plurk Print & Web Design prism Prototype regex regular expression Scriptaculous SEO Tutorial twitter Web 2.0 Wordpress Works YUI
  • Archives

    • August 2010
    • June 2010
    • May 2010
    • September 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
    • September 2008
    • August 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • March 2008
    • February 2008
    • January 2008
    • December 2007
    • November 2007
    • October 2007
copyleft 2007 - 2010 Bali Website Design Studio