Permalink
Browse files

Cleaned up the demo code

  • Loading branch information...
1 parent d6e1f3c commit dd451d9dcd5784272337b8dbc163bf98ed5de553 @p-m-p committed Apr 2, 2011
Showing with 119 additions and 37 deletions.
  1. +11 −11 api_cache/API_cache.php
  2. +0 −1 api_cache/twitter.json
  3. +2 −4 index.php
  4. +23 −3 js/tweets.js
  5. +64 −0 style/default.css
  6. BIN style/images/loader.gif
  7. +1 −0 twitter.json
  8. +18 −18 widgets.php
View
22 api_cache/API_cache.php 100644 → 100755
@@ -6,20 +6,20 @@
class API_cache {
private
- $_update_interval // how often to update
- , $_cache_file // file to save results to
- , $_api_call; // API call (URL with params)
-
+ $_update_interval // how often to update
+ , $_cache_file // file to save results to
+ , $_api_call; // API call (URL with params)
+
public function __construct ($tw, $int=10, $cf='api_cache.json') {
$this->_api_call = $tw;
$this->_update_interval = $int * 60; // minutes to seconds
- $this->_cache_file = $cf;
+ $this->_cache_file = $cf;
}
-
- /*
- * Updates cache if last modified is greater than
- * update interval and returns cache contents
- */
+
+ /*
+ * Updates cache if last modified is greater than
+ * update interval and returns cache contents
+ */
public function get_api_cache () {
if (!file_exists($this->_cache_file) ||
time() - filemtime($this->_cache_file) > $this->_update_interval) {
@@ -56,4 +56,4 @@ private function _update_cache () {
}
}
-}
+}
View
1 api_cache/twitter.json 100644 → 100755
@@ -1 +0,0 @@
-{"results":[{"from_user_id_str":"98720","profile_image_url":"http://a2.twimg.com/profile_images/28610502/robot_warrior_2x3_normal.jpg","created_at":"Wed, 30 Mar 2011 21:01:58 +0000","from_user":"dkords","id_str":"53200317780738048","metadata":{"result_type":"recent"},"to_user_id":null,"text":"Nice RT @rauchg Socket.IO 0.6.17 out. *Last* maintenance release before 0.7! #nodejs","id":53200317780738048,"from_user_id":98720,"geo":null,"iso_language_code":"en","to_user_id_str":null,"source":"<a href="http://twidroyd.com" rel="nofollow">twidroyd</a>"},{"from_user_id_str":"7360336","profile_image_url":"http://a1.twimg.com/profile_images/1215812044/173426_214902547_4837443_q_normal.jpg","created_at":"Wed, 30 Mar 2011 20:26:04 +0000","from_user":"whatgoodisaroad","id_str":"53191283568685056","metadata":{"result_type":"recent"},"to_user_id":null,"text":"This is my new LAMP Stack. I am so very impressed with all of this. #nodejs #express #jade http://goo.gl/ShbLr","id":53191283568685056,"from_user_id":7360336,"geo":null,"iso_language_code":"en","to_user_id_str":null,"source":"<a href="http://www.tweetdeck.com" rel="nofollow">TweetDeck</a>"},{"from_user_id_str":"1953132","profile_image_url":"http://a0.twimg.com/profile_images/1290507829/rattazong-avatar_normal.png","created_at":"Wed, 30 Mar 2011 20:14:34 +0000","from_user":"rattazong","id_str":"53188388047683584","metadata":{"result_type":"recent"},"to_user_id":null,"text":"Working on a cool #redis web interface written in #nodejs.","id":53188388047683584,"from_user_id":1953132,"geo":null,"iso_language_code":"en","to_user_id_str":null,"source":"<a href="http://itunes.apple.com/us/app/twitter/id409789998?mt=12" rel="nofollow">Twitter for Mac</a>"},{"from_user_id_str":"13230866","profile_image_url":"http://a3.twimg.com/profile_images/735066427/HenrikJoreteg_normal.jpg","created_at":"Wed, 30 Mar 2011 20:10:59 +0000","from_user":"HenrikJoreteg","id_str":"53187486498828288","metadata":{"result_type":"recent"},"to_user_id":null,"text":"RT @natevw: Lately at @andyet, I wrote a little @chargify-specific REST wrapper for @nodejs which we're sharing: https://github.com/andyet/node-chargify","id":53187486498828288,"from_user_id":13230866,"geo":null,"iso_language_code":"en","to_user_id_str":null,"source":"<a href="http://twitter.com" rel="nofollow">Tweetie for Mac</a>"},{"from_user_id_str":"94414325","profile_image_url":"http://a3.twimg.com/profile_images/1267570543/eightbit-dc7dd4e7-6204-4e14-bfde-c38f31fc280a_normal.png","created_at":"Wed, 30 Mar 2011 19:42:57 +0000","from_user":"iamdanryan","id_str":"53180432954560512","metadata":{"result_type":"recent"},"to_user_id":null,"text":""* 5 years of NODEJS experience"","id":53180432954560512,"from_user_id":94414325,"geo":null,"iso_language_code":"en","to_user_id_str":null,"source":"<a href="http://itunes.apple.com/us/app/twitter/id409789998?mt=12" rel="nofollow">Twitter for Mac</a>"},{"from_user_id_str":"79272700","profile_image_url":"http://a3.twimg.com/profile_images/1249073521/ng_normal.png","created_at":"Wed, 30 Mar 2011 19:29:01 +0000","from_user":"philogb","id_str":"53176926713552898","metadata":{"result_type":"recent"},"to_user_id":null,"text":"RT @robertellen: demo code for my @brisjs talk on data-driven #javascript gfx and charts based on #thejit #flot and #nodejs http://bit.ly/hiQlF8","id":53176926713552898,"from_user_id":79272700,"geo":null,"iso_language_code":"en","to_user_id_str":null,"source":"<a href="http://twitter.com/">web</a>"},{"from_user_id_str":"1873009","profile_image_url":"http://a0.twimg.com/profile_images/1118805590/aaronETsm_normal.jpg","created_at":"Wed, 30 Mar 2011 18:49:08 +0000","from_user":"drunknbass","id_str":"53166888389316608","metadata":{"result_type":"recent"},"to_user_id":75978179,"text":"@nitoTV nope. plus thats a syntax.. like nodejs.. you dont think thats fast and powerful? btw nodejs in in webos now ;)","id":53166888389316608,"from_user_id":1873009,"to_user":"nitoTV","geo":null,"iso_language_code":"en","to_user_id_str":"75978179","source":"<a href="http://itunes.apple.com/us/app/twitter/id409789998?mt=12" rel="nofollow">Twitter for Mac</a>"},{"from_user_id_str":"47208","profile_image_url":"http://a1.twimg.com/profile_images/42260422/mypic_normal.jpg","created_at":"Wed, 30 Mar 2011 18:28:31 +0000","from_user":"_funkyboy","id_str":"53161699884273664","metadata":{"result_type":"recent"},"to_user_id":null,"text":"Nodejs vs Play for Front-End Apps http://bit.ly/eB4EvP","id":53161699884273664,"from_user_id":47208,"geo":null,"iso_language_code":"en","to_user_id_str":null,"source":"<a href="http://tweetmeme.com" rel="nofollow">TweetMeme</a>"},{"from_user_id_str":"2432406","profile_image_url":"http://a2.twimg.com/profile_images/1292084767/DSC_3037_normal.jpg","created_at":"Wed, 30 Mar 2011 18:12:56 +0000","from_user":"gbluma","id_str":"53157777798995969","metadata":{"result_type":"recent"},"to_user_id":null,"text":"Trying HARD to NOT think about memoization of structured html templates in nodejs. (Great ideas come at bad times)","id":53157777798995969,"from_user_id":2432406,"geo":null,"iso_language_code":"en","to_user_id_str":null,"source":"<a href="http://twitter.com" rel="nofollow">Tweetie for Mac</a>"},{"from_user_id_str":"181877","profile_image_url":"http://a0.twimg.com/profile_images/1249088264/Screen_shot_2011-02-19_at_18.04.56_normal.png","created_at":"Wed, 30 Mar 2011 18:06:32 +0000","from_user":"paulbjensen","id_str":"53156167999950848","metadata":{"result_type":"recent"},"to_user_id":null,"text":"How many of you would be interested in a London NodeJS user group?","id":53156167999950848,"from_user_id":181877,"geo":null,"iso_language_code":"en","to_user_id_str":null,"source":"<a href="http://twitter.com/">web</a>"},{"from_user_id_str":"116600570","profile_image_url":"http://a1.twimg.com/profile_images/893658924/fac_normal.png","created_at":"Wed, 30 Mar 2011 17:59:56 +0000","from_user":"roxxypoxxy","id_str":"53154507177213952","metadata":{"result_type":"recent"},"to_user_id":67442910,"text":"@xtranophilist what's that NodeJS thing ....something more that a javascript..","id":53154507177213952,"from_user_id":116600570,"to_user":"xtranophilist","geo":null,"iso_language_code":"en","to_user_id_str":"67442910","source":"<a href="http://twitter.com/">web</a>"},{"from_user_id_str":"14342443","profile_image_url":"http://a1.twimg.com/profile_images/185790073/s1302055748_30281067_8562_normal.jpg","created_at":"Wed, 30 Mar 2011 17:56:50 +0000","from_user":"robertellen","id_str":"53153724327149568","metadata":{"result_type":"recent"},"to_user_id":null,"text":"demo code for my @brisjs talk on data-driven #javascript gfx and charts based on #thejit #flot and #nodejs http://bit.ly/hiQlF8","id":53153724327149568,"from_user_id":14342443,"geo":null,"iso_language_code":"en","to_user_id_str":null,"source":"<a href="http://twitter.com/">web</a>"},{"from_user_id_str":"332009","profile_image_url":"http://a0.twimg.com/profile_images/1197051662/amette-2010c-1_normal.jpg","created_at":"Wed, 30 Mar 2011 17:55:08 +0000","from_user":"amette","id_str":"53153299771293696","metadata":{"result_type":"recent"},"to_user_id":null,"text":"yup, yup! :) RT @fALk_g yas :D #nodejs RT @SelectaSchuppan ... hacking with @amette and @fALk_g ...","id":53153299771293696,"from_user_id":332009,"geo":null,"iso_language_code":"en","to_user_id_str":null,"source":"<a href="http://www.bitlbee.org/" rel="nofollow">BitlBee</a>"},{"from_user_id_str":"19488853","profile_image_url":"http://a3.twimg.com/profile_images/1010521472/Piter_IMG_0366_200x200_normal.gif","created_at":"Wed, 30 Mar 2011 17:54:55 +0000","from_user":"SannisDev","id_str":"53153242108010497","metadata":{"result_type":"recent"},"to_user_id":null,"text":"My #NodeJS #RPM packages updated to v0.4.4 http://bit.ly/nodejs_repos","id":53153242108010497,"from_user_id":19488853,"geo":null,"iso_language_code":"en","to_user_id_str":null,"source":"<a href="http://twitter.com/">web</a>"},{"from_user_id_str":"449744","profile_image_url":"http://a3.twimg.com/profile_images/1131584382/twitterprofile_normal.png","created_at":"Wed, 30 Mar 2011 17:53:38 +0000","from_user":"fALk_g","id_str":"53152919146602497","metadata":{"result_type":"recent"},"to_user_id":null,"text":"yas :D #nodejs RT @SelectaSchuppan ... hacking with @amette and @fALk_g ...","id":53152919146602497,"from_user_id":449744,"geo":null,"iso_language_code":"en","to_user_id_str":null,"source":"<a href="http://www.nambu.com/" rel="nofollow">Nambu</a>"}],"max_id":53200317780738048,"since_id":50663104308183041,"refresh_url":"?since_id=53200317780738048&q=nodeJS","next_page":"?page=2&max_id=53200317780738048&lang=en&q=nodeJS","results_per_page":15,"page":1,"completed_in":0.055278,"warning":"adjusted since_id to 50663104308183041 (), requested since_id was older than allowed -- since_id removed for pagination.","since_id_str":"50663104308183041","max_id_str":"53200317780738048","query":"nodeJS"}
View
@@ -3,13 +3,11 @@
<head>
<meta charset="utf-8">
<title>API Cache</title>
- <style>
- /* to do */
- </style>
+ <link rel="stylesheet" type="text/css" href="style/default.css">
</head>
<body>
<ol id="tweets">
- <li>Loading tweets...</li>
+ <li id="loading">Loading tweets...</li>
</ol>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script src="js/tweets.js"></script>
View
@@ -7,16 +7,36 @@ $(function () {
$.each(res.results, function (i, tw) {
var $li = $(document.createElement("li"))
, $cite = $(document.createElement("cite"))
+ , $author = $(document.createElement("a"))
, $p = $(document.createElement("p"))
- , img = new Image ();
- $cite.text("@" + tw.from_user);
- $p.text(tw.text);
+ , $d = $(document.createElement("p"))
+ , img = new Image ()
+ , tmp = tw.text;
+ $author
+ .attr("href", "http://twitter.com/" + tw.from_user)
+ .text("@" + tw.from_user)
+ .appendTo($cite);
+ tmp = tmp.replace( // URIs
+ /(https?:\/\/[^\s:]+)/gi,"<a href=\"$1\">$1</a>"
+ );
+ tmp = tmp.replace( // mentions
+ /(@(\w+))/g, "<a href=\"http://twitter.com/$2\">$1</a>"
+ );
+ tmp = tmp.replace(
+ /(\#(\w+))/g,
+ "<a href=\"http://search.twitter.com/search?q=%23$2\">$1</a>"
+ );
+ $p.html(tmp);
img.src = tw.profile_image_url;
img.width = img.height = 40;
+ $d
+ .addClass("tweetdate")
+ .text(tw.created_at.replace(" +0000", ""));
$li
.append(img)
.append($cite)
.append($p)
+ .append($d)
.appendTo($tweets);
});
}
View
@@ -0,0 +1,64 @@
+body {
+ font: .9em/1.2em helvetica, sans-serif;
+ color: #888;
+}
+
+a {
+ color: #222;
+ text-decoration: none;
+}
+
+a:hover { color: #6ab9ec; border-bottom: solid 2px orange; }
+
+#tweets {
+ width: 400px;
+ padding: 10px;
+ border: solid 1px #d8d8d8;
+ -moz-border-radius: 12px;
+ -webkit-border-radius: 12px;
+ border-radius: 12px;
+ margin: 20px auto;
+ list-style: none;
+ height: 600px;
+ overflow: auto;
+}
+
+li {
+ margin: 0 0 5px;
+ padding: 0 0 20px 0;
+ position: relative;
+ overflow: hidden;
+ border-bottom: dashed 1px #d8d8d8;
+}
+ li img {
+ float: left;
+ margin: 5px 10px 0 0;
+ border: solid 1px #d8d8d8;
+ padding: 4px;
+ background-color: #efefef;
+}
+
+#loading {
+ background: url(images/loader.gif) left center no-repeat;
+ padding: .4em 30px;
+ border: none;
+}
+
+cite {
+ display: block;
+ margin: .4em 0 0;
+}
+
+p {
+ margin: .4em 0;
+}
+
+.tweetdate {
+ position: absolute;
+ bottom: 3px;
+ right: 0;
+ font-size: .8em;
+ color: #ccc;
+ margin: 0;
+ padding: 0;
+}
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit dd451d9

Please sign in to comment.