Need to pass the block's instanceid to the twitter client.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 16 Aug 2010 15:59:38 +0000 (11:59 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 16 Aug 2010 15:59:38 +0000 (11:59 -0400)
Need to know which twitter client we are updating. Some misc H4
tweaks as well.

horde/js/twitterclient.js
horde/lib/Block/twitter_timeline.php
horde/services/twitter.php
horde/templates/block/twitter_tweet.html.php

index 2640ed2..4443e64 100644 (file)
@@ -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 {
index 52251c4..489265d 100644 (file)
@@ -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 = <<<EOT
             var Horde = window.Horde || {};
             Horde.twitter{$instance} = new Horde_Twitter({
+               instanceid: '{$instance}',
                getmore: 'getmore{$instance}',
                input: '{$instance}_newStatus',
                spinner: '{$instance}_loading',
index 2253523..703e8ef 100644 (file)
@@ -7,6 +7,8 @@
  * See the enclosed file COPYING for license information (LGPL). If you
  * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  *
+ * @author Michael J. Rubinsky <mrubinsk.horde.org>
+ * @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');
     }
index a613ea9..931ffa6 100644 (file)
@@ -11,6 +11,7 @@
  *   ->createdAt
  *   ->clientName
  *   ->tweet
+ *   ->instanceid
  *
  */
 ?>
@@ -30,8 +31,8 @@
     </div>
     <?php endif; ?>
     <div class="fbstreaminfo">
-      <?php echo Horde::link('#', '', '', '', 'Horde.twitter.buildReply(\'' . $this->tweet->id . '\', \'' . $this->tweet->user->screen_name . '\', \'' . $this->tweet->user->name . '\')') .  _("Reply") ?></a>
-      &nbsp;|&nbsp; <?php echo Horde::link('#', '', '', '', 'Horde.twitter.retweet(\'' . $this->tweet->id . '\')') . _("Retweet") ?></a>
+      <?php echo Horde::selfUrl()->link(array('onclick' => 'Horde.' . $this->instanceid . '.buildReply(\'' . $this->tweet->id . '\', \'' . $this->tweet->user->screen_name . '\', \'' . $this->tweet->user->name . '\'); return false;')) .  _("Reply") ?></a>
+      &nbsp;|&nbsp; <?php echo Horde::selfUrl()->link(array('onclick' => 'Horde.twitter' . $this->instanceid . '.retweet(\'' . $this->tweet->id . '\'); return false;')) . _("Retweet") ?></a>
     </div>
     <div class="clear">&nbsp;</div>
   </div>