Customized Tweet Feed Display « Kevin Pajak – Interactive Web Developer/PHP Engineer

Customized Tweet Feed Display

STEP 1 – index.php
Copy and paste this code, save as a page titled ‘index.php’

<?php

echo "<html><head><title>Customized Tweet Feed Display (beta)</title></head><body>

<form action=’process.php’ method=’POST’>
<b>Enter the Twitter username(s) here:</b><BR> (with multiple names separated by spaces) <input type=’text’ name=’twitterusername’><BR><BR>
Enter a name for this Twitter Feed Group (i.e. "Social Media News," "Travel Alerts," etc): <input type=’text’ name=’tweetfeedgroup’><BR><BR>
<b>How many of this user’s latest tweets would you like to see?:</b>
<select name=’numberoftweets’>";

for ($n=1;$n<=20;$n++)
{
echo "<option value=’$n’>{$n}";
}

echo "<BR><p><input type=’submit’ value=’Show me the tweets!’></p></form></body></html>";
?>

STEP 2 – process.php
Copy and paste this code, save as a page titled ‘process.php’

<?php

$twitterusername = $_POST['twitterusername'];
$numberoftweets = $_POST['numberoftweets'];
$tweetfeedgroup = $_POST['tweetfeedgroup'];
/* $time = date ("g:ia F/d/y"); */
echo "<html><head><title>$numberoftweets Most Recent Tweets from @$twitterusername, grouped under "$tweetfeedgroup" (within the last 2.5 wks)</title></head><body>";

$show = 1; // Show username? 0 = No, 1 = Yes.
$prefix = "<b>{$tweetfeedgroup}</b><BR>"; // This comes before the entire block of tweets.
$prefix_sub = ""; // This comes before each tweet on the feed.
$wedge = " "; // This comes after the username but before the tweet content.
$suffix_sub = "<br>"; // This comes after each tweet on the feed.
$suffix = "<BR><HR><BR>"; // This comes after the entire block of tweets.

function parse_feed($twitterusername, $numberoftweets, $show, $prefix_sub, $wedge, $suffix_sub) {

$twitterusername = str_replace(" ", "+OR+from%3A", $twitterusername);
$feed = "http://search.twitter.com/search.atom?q=from%3A" . $twitterusername . "&rpp=" . $numberoftweets;
$feed = file_get_contents($feed);
$feed = str_replace("&", "&", $feed);
$feed = str_replace("<", "<", $feed);
$feed = str_replace(">", ">", $feed);
$clean = explode("<entry>", $feed);
$amount = count($clean) – 1;

for ($i = 1; $i <= $amount; $i++) {

$entry_close = explode("</entry>", $clean[$i]);
$clean_content_1 = explode("<content type="html">", $entry_close[0]);
$clean_content = explode("</content>", $clean_content_1[1]);
$clean_name_2 = explode("<name>", $entry_close[0]);
$clean_name_1 = explode("(", $clean_name_2[1]);
$clean_name = explode(")</name>", $clean_name_1[1]);
$clean_uri_1 = explode("<uri>", $entry_close[0]);
$clean_uri = explode("</uri>", $clean_uri_1[1]);

echo $prefix_sub;
if ($show == 1) { echo "<a href="" . $clean_uri[0] . "">" . $clean_name[0] . "</a>" . $wedge; }

// Make the links clickable
$clean_content[0] = str_replace("&lt;", "<", $clean_content[0]);
$clean_content[0] = str_replace("&gt;", ">", $clean_content[0]);
$clean_content[0] = str_replace("&amp;quot;", "&quot;", $clean_content[0]);
$clean_content[0] = str_replace("&amp;lt", "<", $clean_content[0]);
$clean_content[0] = str_replace("&amp;gt", ">", $clean_content[0]);
$clean_content[0] = str_replace("&quot;", "\"", $clean_content[0]);
echo $clean_content[0];
echo $suffix_sub;

}
}

echo $prefix;
parse_feed($twitterusername, $numberoftweets, $show, $prefix_sub, $wedge, $suffix_sub);
echo $suffix;
/* echo "<BR>Submitted at: ".$time; */

echo "</body></html>";

?>




STEP 2 – process.php
Copy and paste this code, save as a page titled ‘process.php’

<?php

$twitterusername = $_POST['twitterusername'];
$numberoftweets = $_POST['numberoftweets'];
$tweetfeedgroup = $_POST['tweetfeedgroup'];
/* $time = date ("g:ia F/d/y"); */
echo "<html><head><title>$numberoftweets Most Recent Tweets from @$twitterusername, grouped under "$tweetfeedgroup" (within the last 2.5 wks)</title></head><body>";

$show = 1; // Show username? 0 = No, 1 = Yes.
$prefix = "<b>{$tweetfeedgroup}</b><BR>"; // This comes before the entire block of tweets.
$prefix_sub = ""; // This comes before each tweet on the feed.
$wedge = " "; // This comes after the username but before the tweet content.
$suffix_sub = "<br>"; // This comes after each tweet on the feed.
$suffix = "<BR><HR><BR>"; // This comes after the entire block of tweets.

function parse_feed($twitterusername, $numberoftweets, $show, $prefix_sub, $wedge, $suffix_sub) {

$twitterusername = str_replace(" ", "+OR+from%3A", $twitterusername);
$feed = "http://search.twitter.com/search.atom?q=from%3A" . $twitterusername . "&rpp=" . $numberoftweets;
$feed = file_get_contents($feed);
$feed = str_replace("&", "&", $feed);
$feed = str_replace("<", "<", $feed);
$feed = str_replace(">", ">", $feed);
$clean = explode("<entry>", $feed);
$amount = count($clean) – 1;

for ($i = 1; $i <= $amount; $i++) {

$entry_close = explode("</entry>", $clean[$i]);
$clean_content_1 = explode("<content type="html">", $entry_close[0]);
$clean_content = explode("</content>", $clean_content_1[1]);
$clean_name_2 = explode("<name>", $entry_close[0]);
$clean_name_1 = explode("(", $clean_name_2[1]);
$clean_name = explode(")</name>", $clean_name_1[1]);
$clean_uri_1 = explode("<uri>", $entry_close[0]);
$clean_uri = explode("</uri>", $clean_uri_1[1]);

echo $prefix_sub;
if ($show == 1) { echo "<a href="" . $clean_uri[0] . "">" . $clean_name[0] . "</a>" . $wedge; }

// Make the links clickable
$clean_content[0] = str_replace("&lt;", "<", $clean_content[0]);
$clean_content[0] = str_replace("&gt;", ">", $clean_content[0]);
$clean_content[0] = str_replace("&amp;quot;", "&quot;", $clean_content[0]);
$clean_content[0] = str_replace("&amp;lt", "<", $clean_content[0]);
$clean_content[0] = str_replace("&amp;gt", ">", $clean_content[0]);
echo $clean_content[0];
echo $suffix_sub;

}
}

echo $prefix;
parse_feed($twitterusername, $numberoftweets, $show, $prefix_sub, $wedge, $suffix_sub);
echo $suffix;
/* echo "<BR>Submitted at: ".$time; */

echo "</body></html>";

?>


—————————————————-
With very special thanks to Daniel & Nicholi at InstantShift.com for the original source code and help in the beginning in setting up this powerful little app! ;) Thanks guys, and keep on rockin!

Leave a Reply