<?php

// PteryxTweet
// A Twitter Embedder for PHP-enabled websites
// by Christopher Bair
//
// Released under the GNU GPL version 2
// http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
//
// Usage:
// Upload this file as a .php file to any PHP-enabled website
// that has CURL enabled.
// (You may want to ask your webmaster for help)
//
// Your page must be a PHP script to call this page.
//
// Call this script with an include call precisely where you
// want your Twitter feed to be seen on your page.
//
// Make sure to edit the STYLE section to make the Twitter
// feed returns match the look and feel of your website
//
// Enjoy this free software! If you find it useful, give a link
// back to my homepage somewhere on your site.
// http://www.christopherbair.com/

// STYLE Section
// Edit these to make the Twitter feed look and feel like the
// rest of your website!

// XHTML/HTML
// Select either "XHTML" or "HTML" to have tags properly rendered
// Only uncomment the correct version of your page

// $tagstyle = "XHTML";
// $tagstyle = "HTML";

// List Type
// Select either "ordered" or "unordered" to have your list properly
// rendered. Only uncomment the correct version you wish to have.
// Note: Ordered means to have the output numbered, unordered means
// use graphics or wingdings for each line

// $listtype = "ordered";
// $listtype = "unordered";

// Image Size
// Choose how large to make the avatar of the Twitter user
// Note: Avatars are square, so the size in pixels will reflect
// both the width and height of the output

$imagesize 16;

// Look and Feel
// These are variables that enhance the look of the output by
// modifying the elements of the table rendered

// $tableelement
// The overall look at feel of the table rendered
// Becomes <table THISELEMENT>

$tableelement "style='border:rgb(255,255,255) 2px solid;background:rgb(0,0,0);width:250px;height:auto;'";

// $theadelement
// The appearance of the header row
// Becomes <tr THISELEMENT>

$theadelement "valign='top' style='background:rgb(0,30,0);'";

// $headelement
// The appearance of the cell for the header
// Becomes <td THISELEMENT>

$headelement "";

// $titleelement
// The appearance of the anchor tag for the username at the top
// Becomes <a THISELEMENT>

$titleelement "style='font-weight:bold;text-decoration:none;font-size:10pt;font-family:Verdana, sans-serif;color:rgb(255,255,255);'";

// $trowelement
// The appearance of the body row, where the tweets will be
// Becomes <tr THISELEMENT>

$trowelement "valign='top'";

// $rowelement
// The appearance of the body cell, where the tweets will be
// Becomes <td THISELEMENT>

$rowelement "style='border:rgb(100,0,0) 2px dotted;padding:3px;'";

// $liststyle
// The appearance of the list's bullets/numbers
// Becomes <ol/ul THISELEMENT>

$liststyle "style='list-style-type:square;color:rgb(200,255,200);'";

// $listelement
// The appearance of each element of the list
// Becomes <li THISELEMENT>

$listelement "style='color:rgb(200,200,200);font-size:9pt;font-weight:normal;font-family:Verdana, sans-serif;padding:2px 0px;position:relative;left:-10px;'";

// $anchorlielement
// The appearance of the anchor element of each tweet
// Becomes <a THISELEMENT>

$anchorlielement "style='text-decoration:none;color:rgb(255,255,255);'";

// $tfooterelement
// The appearance of the footer row
// Becomes <tr THISELEMENT>

$tfooterelement "valign='top'";

// $footerelement
// The appearance of the cell of the footer row
// Becomes <td THISELEMENT>

$footerelement "style='font-family:Verdana,sans-serif;color:rgb(200,200,200);font-size:7pt;background:rgb(0,0,30);'";

// $urlelement
// The appearance of anchor elements in the footer
// Becomes <a THISELEMENT>

$urlelement "style='color:rgb(200,200,255);text-decoration:none;'";

// $descelement
// The appearance of the description elements of the footer
// Becomes <div THISELEMENT>

$descelement "style='font-family:monospaced;'";

// This is the numerical ID of your Twitter account

$userid "yourid";

// Max message length
// In case you want to limit the length of message text in your page

$maxmessagelength 160;


//
// You shouldn't need to change anything below here
// This is the program section and it runs without modification
//


// Get with CURL

$nowopen curl_init();
curl_setopt($nowopenCURLOPT_URL"twitter.com/statuses/user_timeline/$userid.xml");
curl_setopt($nowopenCURLOPT_RETURNTRANSFER1);
$output curl_exec($nowopen);
curl_close($nowopen);

$mydata xml_parser_create("UTF-8");
xml_parse_into_struct($mydata,$output,$values,$indices);
xml_parser_free($mydata);

$data '';

switch(
$tagstyle) {
    case 
"XHTML":
        
$endoftag " />";
        break;
    case 
"HTML":
        
$endoftag ">";
        break;
    default:
        
$endoftag ">";
        break;
    }

// Render output

$id4userfullname $indices['NAME'][0];
$userfullname $values["$id4userfullname"]["value"];
$id4userscreenname $indices['SCREEN_NAME'][0];
$userscreenname $values["$id4userscreenname"]["value"];
$id4userlogo $indices['PROFILE_IMAGE_URL'][0];
$userlogo $values["$id4userlogo"]["value"];
$id4userurl $indices['URL'][0];
$userurl $values["$id4userurl"]["value"];
$id4userdescription $indices['DESCRIPTION'][0];
$userdescription $values["$id4userdescription"]["value"];
$returnable $indices["TEXT"];
$numberofreturns sizeof($returnable);

// Grab Tweets!
$data .= "<table $tableelement>\n<tr $theadelement>\n<td $headelement>\n<div align=\"center\"><a href=\"http://twitter.com/$userscreenname\"><img src=\"$userlogo\" width=$imagesize height=$imagesize border=0></a> <a href=\"http://twitter.com/$userscreenname\" $titleelement>$userscreenname</a>\n</td>\n</tr>\n<tr $trowelement>\n<td $rowelement>\n";

switch(
$listtype) {
    case 
"ordered":
        
$data .= "<ol $liststyle>\n";
        break;
    case 
"unordered":
        
$data .= "<ul $liststyle>\n";
        break;
    default:
        
$data .= "<ul $liststyle>\n";
        break;
    }

for (
$a=0;$a $numberofreturns;$a++) {
    
$getcount $a 2;
    
$id4messageid $indices['ID']["$getcount"];
    
$messageid $values["$id4messageid"]["value"];
    
$id4messagetext $indices['TEXT']["$a"];
    
$messagefulltext trim($values["$id4messagetext"]["value"]);
    if (
strlen($messagefulltext) > $maxmessagelength) {
        
$messagetext substr($messagefulltext,0,$maxmessagelength) . "...";
        } else {
        
$messagetext $messagefulltext;
        }
    
$id4messagecreate $indices['CREATED_AT']["$a"];
    
$messagefullcreate $values["$id4messagecreate"]["value"];
    
$data .= "<li $listelement>&nbsp;<a href=\"http://twitter.com/$userscreenname/status/$messageid\" $anchorlielement>$messagetext</a> at $messagefullcreate</li>\n";
    }

switch(
$listtype) {
    case 
"ordered":
        
$data .= "</ol>\n";
        break;
    case 
"unordered":
        
$data .= "</ul>\n";
        break;
    default:
        
$data .= "</ul>\n";
        break;
    }

$data .= "</td>\n</tr>\n<tr $tfooterelement>\n<td $footerelement><div align=\"center\"><a href=\"$userurl\" $urlelement>$userurl</a><br$endoftag\n<div $descelement>$userdescription</div><br$endoftag<br$endoftag\nRendered by <a href=\"http://www.christopherbair.com/software\" $urlelement>PteryxTweet v 0.1</a></div>\n</td>\n</tr>\n</table>\n";


print 
$data;

?>