code /

zentwitter

script to show twitter tweets and twitpics together in zenphoto (or any other page)

 

note 18/11/2009

My code has been beautified and turned into a real zenphoto plugin byMicheall Malone

 

On my site I used MediaBoxAdvanced to show the external image links... this is not embedded in the code below.. You have to link back to twitter or twitpic in your page and using mediaboz/lightbox is a way around to prevent going to the twitter page by clicking the links without omitting the links .

please bare my bad scripting.. but it works :-)

<code>

<?php

// download SimplePie and extract the file simplepie.inc
// and make a folder containing a php folder and a cache folder eg. simplepie/php and simplepie/php
// put the file simplepie.inc from the download in the php folder
// put a 40x40 px profile thumb in the simplepie folder,jpg/png
// in this script change these values
//
// YOUR_SIMPLEPIE_PHP_FOLDER_LOCATION
// YOUR_SIMPLEPIE_CACHE_FOLDER_LOCATION
// TWITTERUSERNAME your user name with a trailing: eg TWITTERUSERNAME: or JohnSmith:
// NAME_OF_A_40_X_40_PROFILE_THUMB
//
// put this script in the simplefie folder call it zentwitter :-)
// create a page in zenphoto
// and put a include in your zenpage codeblock (make sure it gets printed..) like:
//<?php include ('LOCATION_OF_THIS_SCRIPT/simplepie/zentwitter.php');?>


require_once('YOUR_SIMPLEPIE_PHP_FOLDER_LOCATION/simplepie.inc');
$feed = new SimplePie();
$feed->set_feed_url('YOUR_TWITTER_RSS_HERE');

//something like http://twitter.com/statuses/user_timeline/xxxxxxxx.rss

// there is a bug in twitter rss header update regarding dates so disable cache

$feed->enable_order_by_date(true);
$feed->set_cache_location('YOUR_SIMPLEPIE_CACHE_FOLDER_LOCATION/');
$feed->init();
$feed->enable_cache(false);
$feed->handle_content_type();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <title></title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<body>

<?php
foreach ($feed->get_items() as $item):
$check = $item->get_description();
$check= strpos($check,"http://twitpic.com");
if($check === false){
$twit = $item->get_description();
$twit = explode('TWITTERUSERNAME:', $twit);?>

<div class="item" style="height:55px;margin-top:0px">
    <div style="margin-top:0px">
    <a><img align='top' HEIGHT='40' WIDTH='40' src='NAME_OF_A_40_X_40_PROFILE_THUMB'></a>
    </div>
    <div style="margin-left:60px;margin-top:-45px"><small><?php echo $item->get_date('j/m/Y  G:i'); ?></small>   : <a href="<?php echo $item->get_link(); ?>"<?php echo $twit[1] ?></a>
    </div>
</div>


<?php }else{

$data = $item->get_description();
$splitdata = explode('-', $data);
$pictwit = $splitdata[1];
$splitdata2 = explode('TWITTERUSERNAME:', $splitdata[0]);
$imgurl = explode('com', $splitdata2[1]);?>

<div class="item" style="height:55px;margin-top:0px">

    <div style="margin-top:0px">
    <?php echo "<a  title='$pictwit' href='http://twitpic.com$imgurl[1]'><img align='top' HEIGHT='40' WIDTH='40' src='http://twitpic.com/show/thumb$imgurl[1]'></a>";?>
    </div>
    <div style="margin-left:60px;margin-top:-45px"><small><?php echo $item->get_date('j/m/Y  G:i'); ?>   :</small><?php echo $pictwit; ?>
    </div>
</div>

<?php } ?>
<?php endforeach; ?>
</body>
</html>

</code>

Tags: