diff -r 9b20277de139 -r bead0341e247 web/res/js/live-polemic.js --- a/web/res/js/live-polemic.js Wed Apr 10 17:41:03 2013 +0200 +++ b/web/res/js/live-polemic.js Wed Apr 10 18:13:33 2013 +0200 @@ -109,7 +109,7 @@ function getTweetUrl(url) { $.getJSON(url, function(data) { - options.tweets = options.tweets.concat(data.results); + options.tweets = options.tweets.concat(data.statuses); options.currentPage++; if (options.cbData) { options.cbData(); @@ -139,10 +139,10 @@ options.pages || (options.pages = 1); options.rpp || (options.rpp = 100); options.currentPage = 0; - var baseurl = "http://search.twitter.com/search.json", + var baseurl = "search_tweets.php", firstparams = "?q=" + encodeURIComponent(options.keyword)+ "&rpp=" + options.rpp + (options.lang ? "&lang=" + options.lang : '' ), - lastparams = (options.since_id ? "&since_id=" + options.since_id : '' ) + "&callback=?", + lastparams = (options.since_id ? "&since_id=" + options.since_id : '' ), jsonurl = baseurl + firstparams + lastparams; getTweetUrl(jsonurl); } @@ -205,53 +205,41 @@ return; } - tweet.entities = [] + tweet.html_parts = [] - var _users = tweet.text.match(/@[\w_]+/gm), - _lastpos = 0; - if (_users) { - for (var _i = 0; _i < _users.length; _i++) { - var _m = _users[_i], - _start = _lastpos + tweet.text.substr(_lastpos).search(_m), - _lastpos = _start + _m.length; - tweet.entities.push({ - "text" : _m, - "start" : _start, - "end" : _lastpos, - "link" :'' + if (tweet.entities && tweet.entities.user_mentions) { + for (var _i = 0; _i < tweet.entities.user_mentions.length; _i++) { + var _m = tweet.entities.user_mentions[_i]; + tweet.html_parts.push({ + "text" : "@" + _m.screen_name, + "start" : _m.indices[0], + "end" : _m.indices[1], + "link" :'' }); } } - var _hashes = tweet.text.match(/([^&]|^)#[^\s,.!?=#@&;()]+/gm), - _lastpos = 0; - if (_hashes) { - for (var _i = 0; _i < _hashes.length; _i++) { - var _m = _hashes[_i], - _h = ( _m[0] == '#' ? _m : _m.substr(1) ), - _start = _lastpos + tweet.text.substr(_lastpos).search(_h), - _lastpos = _start + _h.length; - tweet.entities.push({ + if (tweet.entities && tweet.entities.hashtags) { + for (var _i = 0; _i < tweet.entities.hashtags.length; _i++) { + var _m = tweet.entities.hashtags[_i], + _h = "#" + _m.text; + tweet.html_parts.push({ "text" : _h, - "start" : _start, - "end" : _lastpos, + "start" : _m.indices[0], + "end" : _m.indices[1], "link" :'' }); } } - var _urls = tweet.text.match(/(www\.|https?:\/\/)[\w./_\-]+/gim), - _lastpos = 0; - if (_urls) { - for (var _i = 0; _i < _urls.length; _i++) { - var _m = _urls[_i], - _start = _lastpos + tweet.text.substr(_lastpos).search(_m), - _lastpos = _start + _m.length; - tweet.entities.push({ - "text" : _m, - "start" : _start, - "end" : _lastpos, - "link" :'' + if (tweet.entities && tweet.entities.urls) { + for (var _i = 0; _i < tweet.entities.urls.length; _i++) { + var _m = tweet.entities.urls[_i]; + tweet.html_parts.push({ + "text" : _m.display_url || _m.url, + "start" : _m.indices[0], + "end" : _m.indices[1], + "link" :'' }); } } @@ -273,17 +261,10 @@ if (tweet.in_reply_to_status_id) { backRef( tweet.id, tweet.in_reply_to_status_id, "reply" ); } - var _retweet = tweet.text.match(/RT @[\w_]+:? /) - if (_retweet) { - var _user = _retweet[0].match(/@[\w_]+/)[0].substr(1).toLowerCase(), - _originalText = tweet.text.substr(tweet.text.search(_retweet[0]) + _retweet[0].length); - for (var i = 0; i < twCx.tweets.length; i++) { - if (twCx.tweets[i].from_user && twCx.tweets[i].from_user.toLowerCase() == _user && twCx.tweets[i].text == _originalText) { - tweet.retweeted_status_id = twCx.tweets[i].id; - backRef( tweet.id, twCx.tweets[i].id, "retweet" ); - break; - } - } + + if (tweet.retweeted_status && tweet.retweeted_status.id_str) { + tweet.retweeted_status_id = tweet.retweeted_status.id_str; + backRef( tweet.id, tweet.retweeted_status_id, "retweet" ); } @@ -471,11 +452,11 @@ + '" id="tweet_' + tweet.id + '" data-title="Tweet by ' - + _(tweet.from_user_name).escape() + + _(tweet.user.name).escape() + '" data-description="' + _(tweet.text).escape() + '" data-uri="http://twitter.com/' - + tweet.from_user + + tweet.user.screen_name + '/status/' + tweet.id + '"'; @@ -495,8 +476,8 @@ html += ''; } html += '
'; - var a_user = ''; - html += '
'; + var a_user = ''; + html += '
'; if (className == 'full') { html += '

' + new Date(tweet.date_value).toTimeString().substr(0,8) + '

'; } @@ -504,15 +485,15 @@ if (className != 'icons') { lastend = 0; var txt = ''; - tweet.entities.sort(function(a, b) { return a.start - b.start }); - _(tweet.entities).each(function(_e) { + tweet.html_parts.sort(function(a, b) { return a.start - b.start }); + _(tweet.html_parts).each(function(_e) { txt += highlight( tweet.text.substring(lastend, _e.start) ) + _e.link + highlight( _e.text ) + ''; lastend = _e.end; }); txt += highlight( tweet.text.substring(lastend) ); - html += '

' + a_user + highlight('@' + tweet.from_user) + '' + ( className == 'full' ? ' (' + tweet.from_user_name + ')
' : ' : ') + txt + '

'; + html += '

' + a_user + highlight('@' + tweet.user.screen_name) + '' + ( className == 'full' ? ' (' + tweet.user.name + ')
' : ' : ') + txt + '

'; if (className == 'full' && el == 'li') { - html += '
afficher tweet - '; + html += '
afficher tweet - '; html += 'répondre · '; html += 'retweeter · '; html += 'favori
'; @@ -710,7 +691,7 @@ } if (twCx.filtre) { var tweets = _(twCx.tweets).filter(function(tweet) { - var mention = '@' + tweet.from_user; + var mention = '@' + tweet.user.screen_name; return ( tweet.text.search(twCx.filtre) != -1 ) || ( mention.search(twCx.filtre) != -1 ); }); $("#inp_q").val(twCx.filtreTexte + ' (' + tweets.length + ' tweets)'); @@ -1059,21 +1040,6 @@ document.location.href = "data:text/json;base64," + btoa(_buf); } -function saveCSV() { - function csvEncode(tableau) { - return _(tableau).map(function(el) { - return '"' + unescape(encodeURIComponent(el)).replace(/"/gm, '""') + '"'; - }).join(",") - }; - var _csvfields = [ "id", "from_user", "from_user_name", "created_at", "text" ], - _csvtxt = csvEncode(_csvfields) + "\n" + _(twCx.tweets).map(function(tw) { - return csvEncode(_(_csvfields).map(function(field) { - return tw[field]; - })); - }).join("\n"); - document.location.href = "data:text/csv;base64," + btoa(_csvtxt); -} - $(document).ready(function() { twCx.tlWidth = $("#timeline").width(); twCx.tlHeight = $("#timeline").height();