<?php
/*
Plugin Name: Tweets @ Me
Plugin URI: http://www.joetech.com/tools/
Description: This simply shows all the people who @ you on Twitter.  The idea is that they get exposure on your blog while you get the @ tweet exposure.
Author: Joe Colburn / JoeTech.com
Version: 1.0
Author URI: http://www.joetech.com/
*/

function display_tweets_at_me() {
    
$cache_path './';


    
#====================================================================================
    # Find out when tweets were last pulled
    #====================================================================================

    
include_once('tm_json.class.php');
    include_once(
'tm_twitter.class.php');
    include_once(
'tm_config.inc.php');
    
$json = new Services_JSON();

    
$filename $cache_path 'tm_last.txt';
    
$handle fopen($filename"r");
    
$contents fread($handlefilesize($filename));
    
fclose($handle);
    
$old_time intval($contents);
    
$current_time time();
    
$since $current_time $old_time;

    if ((
$old_time==10) && ($tm_config["announce"]=='yes')) {
        
#====================================================================================
        # A new install will announce itself via your twitter
        #====================================================================================
        
$twitter = new Twitter($tm_config["username"], $tm_config["password"]);
        
$status "I just added the Tweet @ Me (http://joetech.com/tools) plugin.  It adds replies you write @ me to my WordPress blog.";
        
$update_result $twitter->updateStatus($status);
    }

    if ((
$since $tm_config["seconds"]) || ($tm_config["debug"]=='yes')) {
        
#====================================================================================
        # If it's been an hour or more, get tweets again
        #====================================================================================

        
$twitter = new Twitter($tm_config["username"], $tm_config["password"]);
        
$test $json->decode($twitter->getReplies("json",$html_last_api_call));
        
$x 0;
        
$tm_bg $tm_style["bg1"];
        
$msg '<div style="width:'.$tm_style["width"].';font-size:10px;"><table>';
        while ((
$test[$x]) && ($x $tm_config["to_display"])) {
            
// starting with this format: Mon Apr 07 17:37:17 +0000 2008
            
$months = array("Jan"=>1,"Feb"=>2,"Mar"=>3,"Apr"=>4,"May"=>5,"Jun"=>6,"Jul"=>7,"Aug"=>8,"Sep"=>9,"Oct"=>10,"Nov"=>11,"Dec"=>12);
            
$ca explode(' ',$test[$x]->created_at);
            
$time explode(':',$ca[3]);
            
$ago mktime($time[0],$time[1],$time[2],$months[$ca[1]],$ca[2],$ca[5]);
            if ((
$tm_config["show_image"]=='yes') && ($test[$x]->user->screen_name!='')) {
                
$msg_img '<a href="http://twitter.com/'.$test[$x]->user->screen_name.'"><img style="border:0px;padding:5px;" valign="top" align="left" src="'.$test[$x]->user->profile_image_url.'"></a>';
            } else {
                
$msg_img '';
            }
            
$msg .= '<tr><td style="background:'.$tm_bg.';"><div style="display:block;width:'.$tm_style["width"].'; margin:'.$tm_style["margin"].'; padding:'.$tm_style["padding"].'; border-top:'.$tm_style["border-top"].'; border-right:'.$tm_style["border-right"].'; border-bottom:'.$tm_style["border-bottom"].'; border-left:'.$tm_style["border-left"].'; background:'.$tm_bg.'; font-size:'.$tm_style["font-size"].';">'.$msg_img.'<a style="color:'.$tm_style["font-color"].';font-weight:bold;" href="http://twitter.com/'.$test[$x]->user->screen_name.'" target="new">'.$test[$x]->user->screen_name.'</a> : <a style="color:'.$tm_style["font-color"].';" href="http://twitter.com/'.$test[$x]->user->screen_name.'/statuses/'.$test[$x]->id.'" target="new">'.$test[$x]->text.'</a></div></td></tr>'.$tm_style["divider"];
            if (
$tm_bg == $tm_style["bg1"]) {
                
$tm_bg $tm_style["bg2"];
            } else {
                
$tm_bg $tm_style["bg1"];
            }
            
$x++;
        }
        
$msg .= '</table><br /><a href="http://www.joetech.com/tools/">Tweets @ Me</a> by <a href="http://www.joetech.com/">JoeTech.com</a></div>';

        
$filename $cache_path 'tm_last.txt';
        
$handle fopen($filename"w");
        
fwrite($handletime());
        
fclose($handle);

        
$filename $cache_path 'tm_tweets.txt';
        
$handle fopen($filename"w");
        
fwrite($handle$msg);
        
fclose($handle);
    } else {
        
$filename $cache_path 'tm_tweets.txt';
        
$handle fopen($filename"r");
        
$msg fread($handlefilesize($filename));
        
fclose($handle);
    }

    echo 
$msg;
}
?>