Changeset 330945
- Timestamp:
- 01/10/2011 07:33:23 PM (15 years ago)
- Location:
- wp-whos-online/trunk
- Files:
-
- 2 edited
-
wp-whos-online.js (modified) (4 diffs)
-
wp-whos-online.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-whos-online/trunk/wp-whos-online.js
r144379 r330945 19 19 toggleUpdates(); 20 20 updateRecents(); 21 }; 22 23 // from http://snippets.dzone.com/posts/show/5925 24 function formatDate(formatDate, formatString) { 25 if(formatDate instanceof Date) { 26 var months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); 27 var yyyy = formatDate.getFullYear(); 28 var yy = yyyy.toString().substring(2); 29 var m = formatDate.getMonth(); 30 var mm = m < 10 ? "0" + m : m; 31 var mmm = months[m]; 32 var d = formatDate.getDate(); 33 var dd = d < 10 ? "0" + d : d; 34 35 var h = formatDate.getHours(); 36 var hh = h < 10 ? "0" + h : h; 37 var n = formatDate.getMinutes(); 38 var nn = n < 10 ? "0" + n : n; 39 var s = formatDate.getSeconds(); 40 var ss = s < 10 ? "0" + s : s; 41 42 formatString = formatString.replace(/yyyy/i, yyyy); 43 formatString = formatString.replace(/yy/i, yy); 44 formatString = formatString.replace(/mmm/i, mmm); 45 formatString = formatString.replace(/mm/i, mm); 46 formatString = formatString.replace(/m/i, m); 47 formatString = formatString.replace(/dd/i, dd); 48 formatString = formatString.replace(/d/i, d); 49 formatString = formatString.replace(/hh/i, hh); 50 formatString = formatString.replace(/h/i, h); 51 formatString = formatString.replace(/nn/i, nn); 52 formatString = formatString.replace(/n/i, n); 53 formatString = formatString.replace(/ss/i, ss); 54 formatString = formatString.replace(/s/i, s); 55 56 return formatString; 57 } else { 58 return ""; 59 } 21 60 } 22 61 … … 24 63 var now = Math.round(new Date().getTime()/1000.0); 25 64 65 var fresh = 120; // 2 minutes 26 66 var old = 600; // 10 minutes 27 67 var ancient = 7200; // 2 hours … … 32 72 33 73 var last = $o.data('wpwhosonline_timestamp'); 34 if( typeof last == 'undefined' ) { 35 last = Date.parse($o.text()) / 1000; 74 75 // last will be undefined the first time through 76 if( last == null ) { 77 var theText = $o.text(); 78 79 if( theText == 'Online now!' ) { 80 last = now; 81 } else { 82 last = Date.parse($o.text()) / 1000; 83 } 36 84 } 37 85 … … 44 92 } else { 45 93 oclass = "active"; 94 95 // no longer fresh; remove "Online now!' text 96 if(since > fresh && $o.text() == 'Online now!' ) { 97 var theDate = new Date(last * 1000); 98 $o.text( formatDate(theDate, 'dd mmm yyyy HH:MM:ss') ); 99 console.log( $o.text() ); 100 } 46 101 } 47 102 -
wp-whos-online/trunk/wp-whos-online.php
r144379 r330945 57 57 } 58 58 59 $now = time(); 60 59 61 $latest = 0; 60 62 foreach($authors as $author) { … … 63 65 64 66 $author->wpwhosonline_unix = (int)$author->wpwhosonline; 65 $author->wpwhosonline = strftime( '%d %b %Y %H:%M:%S %Z', $author->wpwhosonline ); 67 if( $now - $author->wpwhosonline_unix < 120 ) { 68 $author->wpwhosonline = 'Online now!'; 69 } else { 70 $author->wpwhosonline = strftime( '%d %b %Y %H:%M:%S %Z', $author->wpwhosonline ); 71 } 66 72 } 67 73 … … 190 196 191 197 if ( $wpwhosonline ) { 198 $now = time(); 199 192 200 $wpwhosonline_time = get_usermeta( $author->ID, 'wpwhosonline_timestamp' ); 193 201 if( $wpwhosonline_time ) { 194 $wpwhosonline_time = strftime( '%d %b %Y %H:%M:%S %Z', $wpwhosonline_time ); 202 if( $now - $wpwhosonline_time < 120 ) { 203 $wpwhosonline_time = 'Online now!'; 204 } else { 205 $wpwhosonline_time = strftime( '%d %b %Y %H:%M:%S %Z', $wpwhosonline_time ); 206 } 195 207 } else { 196 208 $wpwhosonline_time = '';
Note: See TracChangeset
for help on using the changeset viewer.