/    Sign up×
Community /Pin to ProfileBookmark

Adding timestamp fetch to twitter post fetch

So here’s the code for twitter post fetch:

[CODE]01 <?php
02
03 function get_url_contents($url){
04 $crl = curl_init();
05 $timeout = 5;
06 curl_setopt ($crl, CURLOPT_URL,$url);
07 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
08 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
09 $ret = curl_exec($crl);
10 curl_close($crl);
11 return $ret;
12 }
13
14 function generatetwitter($twittername){
15
16 $username = $twittername; // Your twitter username.
17 if ($username == “”){
18 $username = “discorax”;
19 }
20 $limit = “15”; // Number of tweets to pull in.
21 /* These prefixes and suffixes will display before and after the entire block of tweets. */
22 $prefix = “”; // Prefix – some text you want displayed before all your tweets.
23 $suffix = “”; // Suffix – some text you want displayed after all your tweets.
24 $tweetprefix = “<li>”; // Tweet Prefix – some text you want displayed before each tweet.
25 $tweetsuffix = “</li> r”; // Tweet Suffix – some text you want displayed after each tweet.
26 $feed_string = “http://search.twitter.com/search.atom?q=from:” . $username . “&rpp=” . $limit;
27
28 function parse_feed($feed, $prefix, $tweetprefix, $tweetsuffix, $suffix, $username) {
29 $feed = str_replace(“<“, “<“, $feed); $feed = str_replace(“>”, “>”, $feed);
30 $clean = explode(“<content type=”html”>”, $feed);
31 $link = explode(“search.twitter.com,2005:”, $feed);
32 $amount = count($clean) – 1;
33 echo $prefix;
34 for ($i = 1; $i <= $amount; $i++) { $cleaner = explode(“</content>”, $clean[$i]);
35 $linker = explode(“</id>”, $link[$i+1]);
36 $this_tweets = str_replace(“&apos;”, “‘”, $cleaner[0]);
37 $this_tweets = str_replace(“&gt;”, “>”, $this_tweets);
38 $this_tweets = preg_replace(‘!<a href.*?>!’, ”, $this_tweets);
39 $this_tweets = preg_replace(‘!</a>!’, ”, $this_tweets);
40 echo $tweetprefix.'<a href=”http://twitter.com/’.$username.’/status/’;
41 echo $linker[0];
42 echo ‘” target=”_blank”>’.$this_tweets.'</a>’;
43 echo $tweetsuffix;
44 }
45 echo $suffix;
46 }
47
48 $twitter_cache_file = ‘twittercache.xml’;
49
50 $mtime= null;
51
52 if($mtime== null ||(time()-$mtime)>(9*60)){// 9 minutes or older?
53 $content=get_url_contents($feed_string);
54 if(strlen($content)>0){
55 $cache_static=fopen($twitter_cache_file,’w+’);
56 fwrite($cache_static,$content);
57 fclose($cache_static);
58 }
59 }else{
60 $mtime=filemtime($twitter_cache_file);
61 }
62
63 if (!@file_get_contents($twitter_cache_file)){
64 echo __(‘Oops, something went wrong. Did you rename the cache folder? The cache file? You shouldn’t have done that…’, ‘jfr_theme’);
65 }else {
66 $twitterFeed = file_get_contents($twitter_cache_file);
67 }
68
69 parse_feed($twitterFeed, $prefix, $tweetprefix, $tweetsuffix, $suffix, $username);
70
71 }
72 ?>

Where you simply need to call the generatetwitter() function like so.
view source
print?
1 <php
2 echo “<div>”;
3 echo “<ul>”;
4 generatetwitter(“discorax”);
5 echo “</ul></div>”;
6 ?>
[/CODE]

And what I am trying to do is add also post timestamp next to twitter post.

I tried making it part of the post.
I tried entering it as a part of $prefix.
and no success so far =/

What am I doing wrong?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@javaGuyavaauthorOct 29.2011 — btw timestamp aside, the code works perfectly.

Copy and paste to try yourself.
×

Success!

Help @javaGuyava spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...