From 73112ca4f58d89c4b5b703f2bf6218930649f28e Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Mon, 16 Aug 2010 11:59:38 -0400 Subject: [PATCH] Need to pass the block's instanceid to the twitter client. Need to know which twitter client we are updating. Some misc H4 tweaks as well. --- horde/js/twitterclient.js | 15 +++++++++++++-- horde/lib/Block/twitter_timeline.php | 3 ++- horde/services/twitter.php | 5 ++++- horde/templates/block/twitter_tweet.html.php | 5 +++-- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/horde/js/twitterclient.js b/horde/js/twitterclient.js index 2640ed28c..4443e6498 100644 --- a/horde/js/twitterclient.js +++ b/horde/js/twitterclient.js @@ -11,6 +11,7 @@ var Horde_Twitter = Class.create({ inReplyTo: '', oldestId: null, newestId: null, + instanceid: null, /** * Const'r @@ -26,6 +27,7 @@ var Horde_Twitter = Class.create({ * opts.strings.defaultText * opts.strings.justnow * opts.getmore + * opts.instanceid */ initialize: function(opts) { this.opts = Object.extend({ @@ -48,6 +50,7 @@ var Horde_Twitter = Class.create({ e.stop(); }.bind(this)); + this.instanceid = opts.instanceid; /* Get the first page */ this.getNewEntries(); }, @@ -107,7 +110,11 @@ var Horde_Twitter = Class.create({ * @param integer page The page number to retrieve. */ getOlderEntries: function() { - var params = { actionID: 'getPage' }; + var params = { + actionID: 'getPage', + i: this.instanceid + }; + if (this.oldestId) { params.max_id = this.oldestId; } @@ -126,7 +133,11 @@ var Horde_Twitter = Class.create({ * request. */ getNewEntries: function() { - var params = { actionID: 'getPage' }; + var params = { + actionID: 'getPage', + i: this.instanceid + }; + if (this.newestId) { params.since_id = this.newestId; } else { diff --git a/horde/lib/Block/twitter_timeline.php b/horde/lib/Block/twitter_timeline.php index 52251c404..489265dbc 100644 --- a/horde/lib/Block/twitter_timeline.php +++ b/horde/lib/Block/twitter_timeline.php @@ -111,7 +111,7 @@ class Horde_Block_Horde_twitter_timeline extends Horde_Block } /* Get a unique ID in case we have multiple Twitter blocks. */ - $instance = md5(mt_rand()); + $instance = (string)new Horde_Support_Randomid(); /* Latest status */ if (empty($this->_profile->status)) { @@ -143,6 +143,7 @@ class Horde_Block_Horde_twitter_timeline extends Horde_Block $script = << + * @package @horde */ require_once dirname(__FILE__) . '/../lib/Application.php'; @@ -56,7 +58,7 @@ case 'getPage': } elseif ($since = Horde_Util::getPost('since_id')) { $params['since_id'] = $since; } - + $instance = Horde_Util::getPost('i'); $stream = Horde_Serialize::unserialize($twitter->statuses->homeTimeline($params), Horde_Serialize::JSON); } catch (Horde_Service_Twitter_Exception $e) { echo sprintf(_("Unable to contact Twitter. Please try again later. Error returned: %s"), $e->getMessage()); @@ -100,6 +102,7 @@ case 'getPage': $view->createdAt = $tweetObj->created_at; $view->clientText = $filter->filter($tweet->source, 'xss'); $view->tweet = $tweet; + $view->instanceid = $instance; $oldest = $tweet->id; $html .= $view->render('twitter_tweet'); } diff --git a/horde/templates/block/twitter_tweet.html.php b/horde/templates/block/twitter_tweet.html.php index a613ea9ef..931ffa673 100644 --- a/horde/templates/block/twitter_tweet.html.php +++ b/horde/templates/block/twitter_tweet.html.php @@ -11,6 +11,7 @@ * ->createdAt * ->clientName * ->tweet + * ->instanceid * */ ?> @@ -30,8 +31,8 @@
- tweet->id . '\', \'' . $this->tweet->user->screen_name . '\', \'' . $this->tweet->user->name . '\')') . _("Reply") ?> -  |  tweet->id . '\')') . _("Retweet") ?> + link(array('onclick' => 'Horde.' . $this->instanceid . '.buildReply(\'' . $this->tweet->id . '\', \'' . $this->tweet->user->screen_name . '\', \'' . $this->tweet->user->name . '\'); return false;')) . _("Reply") ?> +  |  link(array('onclick' => 'Horde.twitter' . $this->instanceid . '.retweet(\'' . $this->tweet->id . '\'); return false;')) . _("Retweet") ?>
 
-- 2.11.0