summaryrefslogtreecommitdiff
path: root/kolab.org
diff options
context:
space:
mode:
authorTorsten Grote <grote@kolabsys.com>2013-07-03 13:29:36 (GMT)
committerTorsten Grote <grote@kolabsys.com>2013-07-03 13:29:36 (GMT)
commit025ef4e4be959c3f448a5381598528ac18a53035 (patch)
treedb48bc090b6f8cde251e1f1e1df8d70a40ff0c7b /kolab.org
parentdab170e32f9ab7e9a918dcef4636f64769c1b171 (diff)
downloadkolab.org-www-025ef4e4be959c3f448a5381598528ac18a53035.tar.gz
update twitter module
Diffstat (limited to 'kolab.org')
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/README.txt18
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/TODO.txt6
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/tests/twitter_mock.info6
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/tweet.tpl.php43
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.api.php13
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.css90
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.drush.inc84
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.inc180
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.info10
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.install129
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.lib.php1289
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.module243
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.pages.inc416
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.views.inc44
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.views_default.inc280
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_actions/twitter_actions.info7
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_actions/twitter_actions.module214
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_actions/twitter_actions.rules.inc88
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_post/twitter_post.info8
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_post/twitter_post.install40
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_post/twitter_post.module28
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_post/twitter_post.pages.inc15
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_signin/twitter_signin.info7
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_signin/twitter_signin.module48
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_signin/twitter_signin.pages.inc2
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_views_field_handlers.inc96
26 files changed, 2580 insertions, 824 deletions
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/README.txt b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/README.txt
index c8ded0d..0b74eae 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/README.txt
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/README.txt
@@ -7,18 +7,14 @@ provides useful input filters to easily link Twitter accounts and searches withi
Twitter's submodules allow posting to twitter, executing actions/rules when tweeting or login
with a Twitter account.
-OAuth
-=====
-Except for just listing tweets, OAuth module is required to authenticate against Twitter. If you
-just want to list tweets in a block, follow the steps at http://drupal.org/node/1253026.
-
-When you download the OAuth module, get the latest stable release available at http://drupal.org/project/oauth
+Installation
+============
+OAuth module is required for all requests to the Twitter REST API 1.1. When you download the OAuth module, get the latest stable release available at http://drupal.org/project/oauth
-Once OAuth has been enabled, go to admin/config/services/twitter and follow instructions.
+Once OAuth and Twitter have been enabled, go to admin/config/services/twitter and follow instructions in order
+to provide your Twitter Application keys.
-How to add a Twitter account to a Drupal user account
-=====================================================
-Read http://drupal.org/node/1253026 for details.
+You can find further installation instructions at http://drupal.org/node/1346824
How to use the username and hashtag input filters
=================================================
@@ -41,6 +37,8 @@ How to post to Twitter
3. Verify permissions at admin/people/permissions.
4. Add a Twitter account and try to edit or post content.
+Further information can be found at http://drupal.org/node/1016584.
+
How to sign in with Twitter
===========================
Existing and new users can sign in with Twitter by enabling the twitter_signin module. The following scenarios are being contemplated so far:
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/TODO.txt b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/TODO.txt
deleted file mode 100644
index 1fbaead..0000000
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/TODO.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-## Things left to do before release
-
- * Migrate twitter_actions to new API
- * Implement the twitter search API
- * Implement geo features in the API & integrate with location/geo
- * Implement support for DMs (direct messages)
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/tests/twitter_mock.info b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/tests/twitter_mock.info
index 0bcd06b..28baae7 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/tests/twitter_mock.info
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/tests/twitter_mock.info
@@ -5,9 +5,9 @@ hidden = TRUE
dependencies[] = twitter
dependencies[] = simpletest
-; Information added by drupal.org packaging script on 2012-08-11
-version = "7.x-3.2"
+; Information added by drupal.org packaging script on 2013-06-03
+version = "7.x-5.8"
core = "7.x"
project = "twitter"
-datestamp = "1344714197"
+datestamp = "1370303463"
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/tweet.tpl.php b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/tweet.tpl.php
new file mode 100644
index 0000000..e411b54
--- /dev/null
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/tweet.tpl.php
@@ -0,0 +1,43 @@
+<?php
+/**
+ * @file
+ * Renders a tweet as it does look like at Twitter.com.
+ * @see twitter.css
+ */
+?>
+<div class="twitter-status clearfix">
+ <div class="avatar">
+ <a alt="<?php print $author->name; ?>" title="<?php print $author->name; ?>" href=
+ "https://twitter.com/<?php print $author->screen_name; ?>"><img src=
+ "<?php print $author->profile_image_url; ?>"></a>
+ </div>
+
+ <div class="timestamp">
+ <?php print $status->time_ago; ?>
+ </div>
+
+ <div class="name-handle">
+ <div class="name">
+ <a href="http://twitter.com/<?php print $author->screen_name; ?>"><?php print $author->name; ?></a>
+ </div>
+
+ <div class="handle">
+ <a href="http://twitter.com/<?php print $author->screen_name; ?>">@<?php print $author->screen_name; ?></a>
+ </div>
+ </div>
+
+ <div class="text">
+ <?php print _twitter_filter_link(_twitter_filter_hashtag(_twitter_filter_username($status->text, NULL), NULL), NULL); ?>
+ </div>
+
+ <ul class="actions">
+ <li><a href=
+ "https://twitter.com/intent/tweet?in_reply_to=<?php print $status->twitter_id; ?>">Reply</a></li>
+
+ <li><a href=
+ "https://twitter.com/intent/retweet?tweet_id=<?php print $status->twitter_id; ?>">Retweet</a></li>
+
+ <li><a href=
+ "https://twitter.com/intent/favorite?tweet_id=<?php print $status->twitter_id; ?>">Favorite</a></li>
+ </ul>
+</div>
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.api.php b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.api.php
index 62e6a32..0507b7d 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.api.php
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.api.php
@@ -21,6 +21,17 @@ function hook_twitter_accounts($account) {}
*
* @param $status
* stdClass containing information about the status message.
- * @see twitter_status_save() for details about the contents of $status.
+ * @see https://dev.twitter.com/docs/platform-objects/tweets for details about the contents of $status.
*/
function hook_twitter_status_save($status) {}
+
+/**
+ * Notifies of a saved twitter account.
+ *
+ * @param $account
+ * User account object.
+ * @param $values
+ * Twitter account values.
+ * @see twitter_account_save()
+ */
+function hook_twitter_account_save($account, $values) {}
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.css b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.css
new file mode 100644
index 0000000..926ea0c
--- /dev/null
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.css
@@ -0,0 +1,90 @@
+/**
+ * Styles to render a tweet as it is shown at Twitter.com.
+ *
+ * Thanks @makangus.
+ */
+div.view-tweets ul{
+ list-style-type: none;
+ padding: 0px;
+}
+
+.twitter-status{
+ background: #ffffff;
+ color: #333333;
+ padding: 10px 10px 0;
+ margin-bottom: 2px;
+ font-size: 1.077em;
+ line-height: 1.42857142857143em;
+}
+
+.twitter-status .timestamp{
+ float: right;
+ color: #999999;
+ font-size: 0.85714285714286em;
+}
+
+.twitter-status .name-handle{
+ margin-left: 60px;
+}
+
+.twitter-status .text{
+ margin-left: 60px;
+}
+
+.twitter-status .name-handle .name, .twitter-status .name-handle .handle{
+ display: inline;
+}
+
+.twitter-status .name-handle .name a{
+ font-weight: bold;
+ margin-right: 5px;
+ color: #333333;
+}
+
+.twitter-status .name-handle .handle a{
+ color: #999999;
+ font-size: 0.85714285714286em;
+}
+
+.twitter-status .avatar{
+ float: left;
+}
+
+.twitter-status .avatar img{
+ border-radius: 3px;
+}
+
+.twitter-status a {
+ color: #30a9ff;
+}
+
+.twitter-status a:hover {
+ text-decoration: underline;
+}
+
+.twitter-status .actions{
+ text-align: right;
+ font-size: 0.85714285714286em;
+ padding: 0;
+ margin: 0;
+ visibility: hidden;
+}
+
+.twitter-status:hover .actions{
+ visibility: visible;
+}
+
+.twitter-status .actions li{
+ display: inline-block;
+ list-style: none;
+ padding: 0;
+ margin: 0;
+}
+
+.twitter-status .actions a{
+ display: inline-block;
+ line-height: 16px;
+ margin-left: 10px;
+ vertical-align: top;
+ color: #999999;
+}
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.drush.inc b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.drush.inc
new file mode 100644
index 0000000..12f68e4
--- /dev/null
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.drush.inc
@@ -0,0 +1,84 @@
+<?php
+/**
+ * @file
+ * Drush commands for the Twitter module.
+ */
+
+/**
+ * Implements COMMANDFILE_drush_command()
+ */
+function twitter_drush_command() {
+ $items = array();
+
+ $items['twitter-search'] = array(
+ 'description' => 'Searches the Twitter API for something.',
+ 'arguments' => array(
+ 'keyword' => 'The keyword you are searching for. Add @ for usernames and # for hashtags.',
+ ),
+ 'required-arguments' => TRUE,
+ 'options' => array(
+ 'limit' => 'Limit the number of results to be printed.',
+ 'randomize' => 'Randomize the result.',
+ ),
+ 'examples' => array(
+ 'drush twitter-search \'#drupal\'' => 'Pull tweets containing the hashtag #drupal.',
+ 'drush twitter-search \'#drupalconmunich\' --limit=1 --randomize' =>
+ 'Picks a random tweet containing \'#drupalconmunich\'.',
+ ),
+ 'aliases' => array('tws'),
+ 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_SITE,
+ );
+ return $items;
+}
+
+/**
+ * Implements drush_COMMANDFILE_COMMANDNAME()
+ *
+ * Searches for a keyword at Twitter and return the results.
+ */
+function drush_twitter_search($keyword) {
+ $keyword = urlencode($keyword);
+ // This is not even using the Twitter library at twitter.lib.inc, but it will.
+ $url = 'http://search.twitter.com/search.json?rpp=100&q=';
+
+ $response = drupal_http_request($url . $keyword);
+
+ if (isset($response->code) && ($response->code == 200)) {
+ $data = json_decode($response->data);
+ if (!count($data->results)) {
+ drush_set_error(dt('No tweets found for this keyword.'));
+ }
+ else {
+ drush_print(dt('There are !total tweets containing \'@keyword\'.', array(
+ '!total' => count($data->results),
+ '@keyword' => $keyword,
+ )));
+ $tweets = $data->results;
+
+ // Should we randomize?
+ if (drush_get_option('randomize')) {
+ $results = shuffle($tweets);
+ }
+
+ // Should we limit the list of results?
+ if (drush_get_option('limit')) {
+ $tweets = array_slice($tweets, 0, drush_get_option('limit'));
+ }
+
+ // Print results
+ foreach ($tweets as $tweet) {
+ drush_print('');
+ drush_print(dt('User "@!user", tweeted "!tweet".', array(
+ '!user' => $tweet->from_user,
+ '!tweet' => $tweet->text,
+ )));
+ drush_print('');
+ }
+ }
+ }
+ else {
+ drush_set_error(dt('There was an error. Full raw response was !response', array(
+ '!response' => print_r($response, TRUE)
+ )));
+ }
+}
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.inc b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.inc
index 92b18cd..be2993c 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.inc
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.inc
@@ -5,31 +5,42 @@
* Twitter API functions
*/
+module_load_include('php', 'oauth_common', 'lib/OAuth');
+
/**
- * Connect to the API using the 'proper' version (Oauth vs. standard)
+ * Connect to the Twitter API.
+ *
+ * @param object $account
+ * An authenticated twitter_account object to be used to authenticate against
+ * Twitter.
+ * @return
+ * a Twitter object ready to be used to query the Twitter API or FALSE.
*/
-function twitter_connect($account) {
- $auth = $account->get_auth();
- if (_twitter_use_oauth() && $auth['oauth_token'] && $auth['oauth_token_secret']) {
- module_load_include('lib.php', 'oauth_common');
- return new TwitterOAuth(variable_get('twitter_consumer_key', ''), variable_get('twitter_consumer_secret', ''),
- $auth['oauth_token'], $auth['oauth_token_secret']);
- }
- elseif ($auth['password']) {
- return new Twitter($account->screen_name, $auth['password']);
+function twitter_connect($account = NULL) {
+ if (!$account) {
+ // Load the first authenticated account.
+ $twitter_uid = db_query("SELECT twitter_uid
+ FROM {twitter_account}
+ WHERE oauth_token <> ''
+ AND oauth_token_secret <> '' ")->fetchField();
+ $account = twitter_account_load($twitter_uid);
}
- else {
- return new Twitter;
+ if ($account) {
+ $auth = $account->get_auth();
+ if (isset($auth['oauth_token']) && isset($auth['oauth_token_secret'])) {
+ return new Twitter(variable_get('twitter_consumer_key', ''), variable_get('twitter_consumer_secret', ''),
+ $auth['oauth_token'], $auth['oauth_token_secret']);
+ }
}
+ return FALSE;
}
/**
* Saves a TwitterUser object to {twitter_account}
*/
-function twitter_account_save($twitter_user, $save_auth = FALSE, $account = NULL) {
+function twitter_account_save($twitter_user, $save_auth = FALSE) {
$values = (array) $twitter_user;
$values['twitter_uid'] = $values['id'];
- // bool => int for DB storage
foreach (array('protected', 'verified', 'profile_background_tile') as $k) {
if (isset($values[$k])) {
$values[$k] = (int) $values[$k];
@@ -38,11 +49,6 @@ function twitter_account_save($twitter_user, $save_auth = FALSE, $account = NULL
if ($save_auth) {
$values += $twitter_user->get_auth();
- if (empty($account)) {
- global $user;
- $account = $user;
- }
- $values['uid'] = $account->uid;
}
$schema = drupal_get_schema('twitter_account');
foreach ($values as $k => $v) {
@@ -50,40 +56,97 @@ function twitter_account_save($twitter_user, $save_auth = FALSE, $account = NULL
unset($values[$k]);
}
}
-
db_merge('twitter_account')
->key(array('twitter_uid' => $values['twitter_uid']))
->fields($values)
->execute();
+
+ // Notify other modules of the twitter account save
+ module_invoke_all('twitter_account_save', $values);
}
/**
* Load a Twitter account from {twitter_account}.
*
- * @param $id
- * Twitter UID
+ * @param mixed $id
+ * int Twitter User id or string Twitter user screen name.
*
* @return
- * TwitterUser object
- *
+ * TwitterUser object or NULL.
*/
function twitter_account_load($id) {
- if ( $values = db_query("SELECT * FROM {twitter_account} WHERE twitter_uid = :twitter_uid", array(':twitter_uid' => $id))->fetchAssoc() ) {
+ $values = db_query('SELECT *
+ FROM {twitter_account}
+ WHERE twitter_uid = :id_1
+ OR screen_name = :id_2',
+ array(':id_1' => $id, ':id_2' => $id))
+ ->fetchAssoc();
+ if (!empty($values)) {
$values['id'] = $values['twitter_uid'];
$account = new TwitterUser($values);
$account->set_auth($values);
- $account->uid = $values['uid'];
$account->import = $values['import'];
+ $account->mentions = $values['mentions'];
$account->is_global = $values['is_global'];
return $account;
}
+ return NULL;
+}
+
+/**
+ * Loads all Twitter accounts added by a user.
+ *
+ * @return
+ * array of TwitterUser objects.
+ */
+function twitter_account_load_all() {
+ $accounts = array();
+ $result = db_query('SELECT twitter_uid
+ FROM {twitter_account}
+ WHERE uid <> 0
+ ORDER BY screen_name');
+ foreach ($result as $account) {
+ $accounts[] = twitter_account_load($account->twitter_uid);
+ }
+ return $accounts;
+}
+
+/**
+ * Returns a list of authenticated Twitter accounts.
+ *
+ * @return
+ * array of TwitterUser objects.
+ */
+function twitter_load_authenticated_accounts() {
+ $accounts = twitter_account_load_all();
+ $auth_accounts = array();
+ foreach ($accounts as $index => $account) {
+ if ($account->is_auth()) {
+ $auth_accounts[] = $account;
+ }
+ }
+ return $auth_accounts;
+}
+
+/**
+ * Load a Twitter status.
+ *
+ * @param $status_id
+ * The status id of this tweet.
+ *
+ * @return
+ * An instance of stdClass object with the Tweet data or FALSE.
+ */
+function twitter_status_load($status_id) {
+ return db_query("SELECT * FROM {twitter} WHERE twitter_id = :status_id",
+ array(':status_id' => $status_id))->fetchObject();
}
/**
* Saves a TwitterStatus object to {twitter}
*/
function twitter_status_save($status) {
- $status = array(
+ $row = array(
'twitter_id' => $status->id,
'screen_name' => $status->user->screen_name,
'created_time' => strtotime($status->created_at),
@@ -95,10 +158,10 @@ function twitter_status_save($status) {
'truncated' => (int) $status->truncated,
);
db_merge('twitter')
- ->key(array('twitter_id' => $status['twitter_id']))
- ->fields($status)
+ ->key(array('twitter_id' => $row['twitter_id']))
+ ->fields($row)
->execute();
- // Let other modules know that an status has been just saved.
+ // Let other modules know that a status has been saved.
module_invoke_all('twitter_status_save', $status);
}
@@ -114,39 +177,72 @@ function twitter_status_save($status) {
*/
function twitter_set_status($twitter_account, $status) {
$twitter = twitter_connect($twitter_account);
- return $twitter->status_update($status);
+ return $twitter->statuses_update($status);
}
/**
- * Fetches a user's timeline
+ * Fetches a user's timeline.
*/
function twitter_fetch_user_timeline($id) {
$account = twitter_account_load($id);
-
$since = db_query("SELECT MAX(twitter_id) FROM {twitter} WHERE screen_name = :screen_name", array(':screen_name' => $account->screen_name))->fetchField();
- $twitter = twitter_connect($account);
-
+ // Connect to the Twitter's API.
+ $twitter = twitter_connect();
$params = array();
if ($since) {
$params['since_id'] = $since;
}
- $statuses = $twitter->user_timeline($account->id, $params, $account->protected);
+ // Fetch tweets.
+ $statuses = $twitter->user_timeline($id, $params);
foreach ($statuses as $status) {
twitter_status_save($status);
}
if (count($statuses) > 0) {
+ // Update account details.
twitter_account_save($statuses[0]->user);
}
+}
- db_update('twitter_account')
- ->fields(array(
- 'last_refresh' => REQUEST_TIME,
- ))
- ->condition('twitter_uid', $account->id)
- ->execute();
+/**
+ * Fetches user's mentions of an authenticated account.
+ */
+function twitter_fetch_mentions_timeline($id) {
+ $account = twitter_account_load($id);
+ // Connect to Twitter's API using the authenticated account to fetch mentions.
+ $twitter = twitter_connect($account);
+
+ $params = array();
+ $statuses = $twitter->mentions_timeline($params);
+ foreach ($statuses as $status) {
+ if (!twitter_account_load($status->user->id)) {
+ twitter_account_save($status->user);
+ }
+ twitter_status_save($status);
+ }
+}
+
+/**
+ * Pulls tweets from the database.
+ *
+ * @param string $screen_name
+ * Optionally provide a screen_name to filter.
+ */
+function twitter_tweets($screen_name = NULL) {
+ $query = db_select('twitter', 't')
+ ->fields('t');
+ if (isset($screen_name)) {
+ $query->condition('t.screen_name', $screen_name);
+ }
+ $result = $query->execute();
+
+ $tweets = array();
+ foreach ($result as $row) {
+ $tweets[] = $row;
+ }
+ return $tweets;
}
/**
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.info b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.info
index dfeeace..b8bc15c 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.info
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.info
@@ -2,15 +2,17 @@ name = Twitter
description = Adds integration with the Twitter microblogging service.
php = 5.1
core = 7.x
-files[] = twitter.lib.php
files[] = twitter_views_field_handlers.inc
+files[] = twitter.lib.php
files[] = tests/core.test
files[] = tests/input_filters.test
+dependencies[] = oauth_common
+dependencies[] = views
configure = admin/config/services/twitter
-; Information added by drupal.org packaging script on 2012-08-11
-version = "7.x-3.2"
+; Information added by drupal.org packaging script on 2013-06-03
+version = "7.x-5.8"
core = "7.x"
project = "twitter"
-datestamp = "1344714197"
+datestamp = "1370303463"
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.install b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.install
index 3892f45..e721596 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.install
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.install
@@ -1,5 +1,4 @@
<?php
-
/**
* @file
* Install, update and uninstall functions for the twitter module.
@@ -7,6 +6,34 @@
*/
/**
+ * Implements hook_requirements()
+ */
+function twitter_requirements($phase) {
+ $requirements = array();
+ $t = get_t();
+ if ($phase == 'runtime') {
+ // Verify that the Twitter Application keys are set.
+ $requirements['twitter_keys'] = array('title' => $t('Twitter Application keys'));
+ $consumer_key = variable_get('twitter_consumer_key', NULL);
+ $consumer_secret = variable_get('twitter_consumer_secret', NULL);
+ if (empty($consumer_key) || empty($consumer_secret)) {
+ $requirements['twitter_keys']['value'] = $t('Missing');
+ $requirements['twitter_keys']['description'] =
+ $t('In order to interact with Twitter, you need to create an application at ' .
+ '<a href="http://dev.twitter.com" target="_blank">http://dev.twitter.com</a> ' .
+ 'and set the generated Application keys at the ' .
+ '<a href="/admin/config/services/twitter">Twitter settings page</a>');
+ $requirements['twitter_keys']['severity'] = REQUIREMENT_ERROR;
+ }
+ else {
+ $requirements['twitter_keys']['value'] = $t('Configured');
+ $requirements['twitter_keys']['severity'] = REQUIREMENT_OK;
+ }
+ }
+ return $requirements;
+}
+
+/**
* Implements hook_schema().
*/
function twitter_schema() {
@@ -99,13 +126,6 @@ function twitter_schema() {
'not null' => TRUE,
'default' => 0,
),
- 'uid' => array(
- 'description' => "The {users}.uid of the owner of this account",
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'size' => 'big',
- 'not null' => TRUE,
- ),
'host' => array(
'description' => 'The host for this account can be a laconi.ca instance',
'type' => 'varchar',
@@ -260,7 +280,14 @@ function twitter_schema() {
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
- 'default' => 1,
+ 'default' => 0,
+ ),
+ 'mentions' => array(
+ 'description' => "Boolean flag indicating whether the {twitter_user}'s mentions should be pulled in by the site.",
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
),
'last_refresh' => array(
'description' => "A UNIX timestamp marking the date Twitter statuses were last fetched on.",
@@ -269,7 +296,14 @@ function twitter_schema() {
'default' => 0,
),
'is_global' => array(
- 'description' => "Boolean flag indicating if this account is available for global use",
+ 'description' => "Boolean flag indicating if this account is available for global use.",
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ ),
+ 'uid' => array(
+ 'description' => "The uid of the user who added this Twitter account.",
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
@@ -306,9 +340,7 @@ function twitter_uninstall() {
variable_del('twitter_expire');
variable_del('twitter_consumer_key');
variable_del('twitter_consumer_secret');
- variable_del('twitter_post_types');
variable_del('twitter_host');
- variable_del('twitter_post_default_format');
variable_del('twitter_signin_button');
variable_del('twitter_signin_register');
variable_del('twitter_host');
@@ -318,11 +350,80 @@ function twitter_uninstall() {
}
/**
- * Implements hook_update_N().
- *
* Removes password field
*/
function twitter_update_7300() {
db_drop_field('twitter_account', 'password');
return t('Password field was removed from Twitter accounts.');
}
+
+/**
+ * Removes include_retweets field
+ */
+function twitter_update_7301() {
+ if (db_field_exists('twitter_account', 'include_retweets')) {
+ db_drop_field('twitter_account', 'include_retweets');
+ return t('Include Retweets field was removed from Twitter accounts.');
+ }
+}
+
+/**
+ * Adds field mentions to twitter_account table.
+ */
+function twitter_update_7400() {
+ $data = array(
+ 'description' => "Boolean flag indicating whether the {twitter_user}'s mentions should be pulled in by the site.",
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ );
+ db_add_field('twitter_account', 'mentions', $data);
+}
+
+/**
+ * Drops field uid at twitter_account.
+ *
+ * This update has been set empty afterwards as the field is actually needed.
+ */
+function twitter_update_7401() {}
+
+/**
+ * Makes the import field not enabled by default at twitter_account table.
+ */
+function twitter_update_7402() {
+ $spec = array(
+ 'description' => "Boolean flag indicating whether the {twitter_user}'s posts should be pulled in by the site.",
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ );
+
+ db_change_field('twitter_account', 'import', 'import', $spec);
+}
+
+/**
+ * Adds field added_by_uid to twitter_account table.
+ *
+ * This update has been set empty afterwards as the existing field twitter_account.uid is used.
+ */
+function twitter_update_7403() {}
+
+/**
+ * Renames twitter_account.added_by_uid to twitter_account.uid.
+ *
+ * This reverts update 7403.
+ */
+function twitter_update_7500() {
+ if (db_field_exists('twitter_account', 'added_by_uid')) {
+ $spec = array(
+ 'description' => "The uid of the user who added this Twitter account.",
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ );
+ db_change_field('twitter_account', 'added_by_uid', 'uid', $spec);
+ }
+}
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.lib.php b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.lib.php
index a852b57..b58a1d7 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.lib.php
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.lib.php
@@ -1,71 +1,206 @@
<?php
/**
* @file
- * Classes to implement the full Twitter API
+ * Integration layer to communicate with the Twitter REST API 1.1.
+ * https://dev.twitter.com/docs/api/1.1
+ *
+ * Original work my James Walker (@walkah).
+ * Upgraded to 1.1 by Juampy (@juampy72).
*/
/**
* Exception handling class.
*/
-class TwitterException extends Exception {
- /**
- * Overrides constructor to log the error.
- */
- public function __construct($message = NULL, $code = 0, Exception $previous = NULL) {
- watchdog('twitter', 'Unexpected error: @message', array(
- '@message' => $message,
- ), WATCHDOG_ERROR);
- parent::__construct($message, $code, $previous);
- }
-}
+class TwitterException extends Exception {}
+
/**
* Primary Twitter API implementation class
- * Supports the full REST API for twitter.
*/
class Twitter {
-
/**
- * @var $format API format to use: can be json or xml
+ * @var $source the twitter api 'source'
*/
- protected $format = 'json';
+ protected $source = 'drupal';
+
+ protected $signature_method;
+
+ protected $consumer;
+
+ protected $token;
+
+ /********************************************//**
+ * Authentication
+ ***********************************************/
/**
- * @var $source the twitter api 'source'
+ * Constructor for the Twitter class
*/
- protected $source = 'drupal';
+ public function __construct($consumer_key, $consumer_secret, $oauth_token = NULL,
+ $oauth_token_secret = NULL) {
+ $this->signature_method = new OAuthSignatureMethod_HMAC_SHA1();
+ $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
+ if (!empty($oauth_token) && !empty($oauth_token_secret)) {
+ $this->token = new OAuthConsumer($oauth_token, $oauth_token_secret);
+ }
+ }
+
+ public function get_request_token() {
+ $url = variable_get('twitter_api', TWITTER_API) . '/oauth/request_token';
+ try {
+ $params = array('oauth_callback' => url('twitter/oauth', array('absolute' => TRUE)));
+ $response = $this->auth_request($url, $params);
+ }
+ catch (TwitterException $e) {
+ watchdog('twitter', '!message', array('!message' => $e->__toString()), WATCHDOG_ERROR);
+ return FALSE;
+ }
+ parse_str($response, $token);
+ $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
+ return $token;
+ }
+
+ public function get_authorize_url($token) {
+ $url = variable_get('twitter_api', TWITTER_API) . '/oauth/authorize';
+ $url.= '?oauth_token=' . $token['oauth_token'];
+
+ return $url;
+ }
+
+ public function get_authenticate_url($token) {
+ $url = variable_get('twitter_api', TWITTER_API) . '/oauth/authenticate';
+ $url.= '?oauth_token=' . $token['oauth_token'];
+
+ return $url;
+ }
/**
- * @var $username Twitter username to use for authenticated requests
+ * Request an access token to the Twitter API.
+ * @see https://dev.twitter.com/docs/auth/implementing-sign-twitter
+ *
+ * @param string$oauth_verifier
+ * String an access token to append to the request or NULL.
+ * @return
+ * String the access token or FALSE when there was an error.
*/
- protected $username;
+ public function get_access_token($oauth_verifier = NULL) {
+ $url = variable_get('twitter_api', TWITTER_API) . '/oauth/access_token';
+
+ // Adding parameter oauth_verifier to auth_request
+ $parameters = array();
+ if (!empty($oauth_verifier)) {
+ $parameters['oauth_verifier'] = $oauth_verifier;
+ }
+
+ try {
+ $response = $this->auth_request($url, $parameters);
+ }
+ catch (TwitterException $e) {
+ watchdog('twitter', '!message', array('!message' => $e->__toString()), WATCHDOG_ERROR);
+ return FALSE;
+ }
+ parse_str($response, $token);
+ $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
+ return $token;
+ }
/**
- * @var $password Twitter password to use for authenticated requests
+ * Performs an authenticated request.
*/
- protected $password;
+ public function auth_request($url, $params = array(), $method = 'GET') {
+ $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $params);
+ $request->sign_request($this->signature_method, $this->consumer, $this->token);
+ switch ($method) {
+ case 'GET':
+ return $this->request($request->to_url());
+ case 'POST':
+ return $this->request($request->get_normalized_http_url(), $request->get_parameters(), 'POST');
+ }
+ }
/**
- * Constructor for the Twitter class
+ * Performs a request.
+ *
+ * @throws TwitterException
*/
- public function __construct($username = NULL, $password = NULL) {
- if (!empty($username) && !empty($password)) {
- $this->set_auth($username, $password);
+ protected function request($url, $params = array(), $method = 'GET') {
+ $data = '';
+ if (count($params) > 0) {
+ if ($method == 'GET') {
+ $url .= '?'. http_build_query($params, '', '&');
+ }
+ else {
+ $data = http_build_query($params, '', '&');
+ }
+ }
+
+ $headers = array();
+
+ $headers['Authorization'] = 'Oauth';
+ $headers['Content-type'] = 'application/x-www-form-urlencoded';
+
+ $response = $this->doRequest($url, $headers, $method, $data);
+ if (!isset($response->error)) {
+ return $response->data;
}
+ else {
+ $error = $response->error;
+ $data = $this->parse_response($response->data);
+ if (isset($data['error'])) {
+ $error = $data['error'];
+ }
+ throw new TwitterException($error);
+ }
+ }
+
+ /**
+ * Actually performs a request.
+ *
+ * This method can be easily overriden through inheritance.
+ *
+ * @param string $url
+ * The url of the endpoint.
+ * @param array $headers
+ * Array of headers.
+ * @param string $method
+ * The HTTP method to use (normally POST or GET).
+ * @param array $data
+ * An array of parameters
+ * @return
+ * stdClass response object.
+ */
+ protected function doRequest($url, $headers, $method, $data) {
+ return drupal_http_request($url, array('headers' => $headers, 'method' => $method, 'data' => $data));
}
+ protected function parse_response($response) {
+ // http://drupal.org/node/985544 - json_decode large integer issue
+ $length = strlen(PHP_INT_MAX);
+ $response = preg_replace('/"(id|in_reply_to_status_id)":(\d{' . $length . ',})/', '"\1":"\2"', $response);
+ return json_decode($response, TRUE);
+ }
/**
- * Set the username and password
+ * Creates an API endpoint URL.
+ *
+ * @param string $path
+ * The path of the endpoint.
+ * @param string $format
+ * The format of the endpoint to be appended at the end of the path.
+ * @return
+ * The complete path to the endpoint.
*/
- public function set_auth($username, $password) {
- $this->username = $username;
- $this->password = $password;
+ protected function create_url($path, $format = '.json') {
+ $url = variable_get('twitter_api', TWITTER_API) .'/1.1/'. $path . $format;
+ return $url;
}
+ /********************************************//**
+ * Helpers used to convert responses in objects
+ ***********************************************/
/**
* Get an array of TwitterStatus objects from an API endpoint
*/
- protected function get_statuses($path, $params = array(), $use_auth = FALSE) {
- $values = $this->call($path, $params, 'GET', $use_auth);
+ protected function get_statuses($path, $params = array()) {
+ $values = $this->call($path, $params, 'GET');
// Check on successfull call
if ($values) {
$statuses = array();
@@ -83,267 +218,1023 @@ class Twitter {
}
/**
+ * Get an array of TwitterUser objects from an API endpoint
+ */
+ protected function get_users($path, $params = array()) {
+ $values = $this->call($path, $params, 'GET');
+ // Check on successfull call
+ if ($values) {
+ $users = array();
+ foreach ($values as $user) {
+ $users[] = new TwitterUser($user);
+ }
+ return $users;
+ }
+ // Call might return FALSE , e.g. on failed authentication
+ else {
+ // As call allready throws an exception, we can return an empty array to
+ // break no code.
+ return array();
+ }
+ }
+
+ /********************************************//**
+ * Timelines
+ ***********************************************/
+ /**
+ * Returns the 20 most recent mentions (tweets containing a users's @screen_name).
+ *
+ * @param array $params
+ * an array of parameters.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/get/statuses/mentions_timeline
+ */
+ public function mentions_timeline($params = array()) {
+ return $this->get_statuses('statuses/mentions_timeline', $params);
+ }
+
+ /**
* Fetch a user's timeline
*
- * @see http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-user_timeline
+ * Returns a collection of the most recent Tweets posted by the user indicated
+ * by the screen_name or user_id parameters.
+ *
+ * @param mixed $id
+ * either a Twitter user_id or a Twitter screen_name.
+ *
+ * @param array $params
+ * an array of parameters.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
*/
- public function user_timeline($id, $params = array(), $use_auth = FALSE) {
+ public function user_timeline($id, $params = array()) {
if (is_numeric($id)) {
$params['user_id'] = $id;
}
else {
$params['screen_name'] = $id;
}
- return $this->get_statuses('statuses/user_timeline', $params, $use_auth);
+ return $this->get_statuses('statuses/user_timeline', $params);
}
/**
+ * Returns a collection of the most recent Tweets and retweets posted by
+ * the authenticating user and the users they follow.
*
- * @see http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-mentions
+ * @param array $params
+ * an array of parameters.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline
*/
- public function mentions($params = array()) {
- return $this->get_statuses('statuses/mentions', $params, TRUE);
+ public function home_timeline($params = array()) {
+ return $this->get_statuses('statuses/home_timeline', $params);
}
/**
+ * Returns the most recent tweets authored by the authenticating user
+ * that have recently been retweeted by others.
+ *
+ * @param array $params
+ * an array of parameters.
*
- * @see http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses%C2%A0update
+ * @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweets_of_me
*/
- public function status_update($status, $params = array()) {
- $params['status'] = $status;
- if ($this->source) {
- $params['source'] = $this->source;
+ public function retweets_of_me($params = array()) {
+ return $this->get_statuses('statuses/retweets_of_me', $params);
+ }
+
+ /********************************************//**
+ * Tweets
+ ***********************************************/
+ /**
+ * Returns up to 100 of the first retweets of a given tweet.
+ *
+ * @param int $id
+ * The numerical ID of the desired status.
+ * @param array $params
+ * an array of parameters.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweets
+ */
+ public function statuses_retweets($id, $params = array()) {
+ return $this->get_statuses('statuses/retweets/' . $id, $params);
+ }
+
+ /**
+ * Destroys the status specified by the required ID parameter.
+ *
+ * @param array $params
+ * an array of parameters.
+ *
+ * @return
+ * TwitterStatus object if successful or FALSE.
+ * @see https://dev.twitter.com/docs/api/1.1/get/statuses/destroy
+ */
+ public function statuses_destroy($id, $params = array()) {
+ $values = $this->call('statuses/update', $params, 'POST');
+ if ($values) {
+ return new TwitterStatus($values);
}
- $values = $this->call('statuses/update', $params, 'POST', TRUE);
+ else {
+ return FALSE;
+ }
+ }
+
+ /**
+ * Updates the authenticating user's current status, also known as tweeting.
+ *
+ * @param string $status
+ * The text of the status update (the tweet).
+ * @param array $params
+ * an array of parameters.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/post/statuses/update
+ */
+ public function statuses_update($status, $params = array()) {
+ $params['status'] = $status;
+ $values = $this->call('statuses/update', $params, 'POST');
return new TwitterStatus($values);
}
/**
- * Returns profile information about a user.
- * @see http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-users%C2%A0show
+ * Retweets a tweet. Returns the original tweet with retweet details embedded.
+ *
+ * @param int $id
+ * The numerical ID of the desired status.
+ * @param array $params
+ * an array of parameters.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/%3Aid
*/
- public function users_show($id, $use_auth = TRUE) {
- $params = array();
+ public function statuses_retweet($id, $params = array()) {
+ $values = $this->call('statuses/retweet/' . $id, $params, 'POST');
+ return new TwitterStatus($values);
+ }
+
+ /**
+ * Creates a Tweet with a picture attached.
+ *
+ * @param string $status
+ * The text of the status update (the tweet).
+ * @param array $media
+ * An array of physical paths of images.
+ * @param array $params
+ * an array of parameters.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media
+ */
+ public function statuses_update_with_media($status, $media, $params = array()) {
+ $params['status'] = $status;
+ $params['media[]'] = '@{' . implode(',', $media) . '}';
+ $values = $this->call('statuses/statuses/update_with_media', $params, 'POST');
+ // @TODO support media at TwitterStatus class.
+ return new TwitterStatus($values);
+ }
+
+ /**
+ * Returns information allowing the creation of an embedded representation of
+ * a Tweet on third party sites.
+ *
+ * @param mixed $id
+ * The Tweet/status ID or the URL of the Tweet/status to be embedded.
+ * @param array $params
+ * an array of parameters.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/get/statuses/oembed
+ */
+ public function statuses_oembed($id, $params = array()) {
if (is_numeric($id)) {
- $params['user_id'] = $id;
+ $params['id'] = $id;
}
else {
- $params['screen_name'] = $id;
+ $params['url'] = $id;
}
+ return $this->call('statuses/oembed', $params, 'GET');
+ }
- $values = $this->call('users/show', $params, 'GET', $use_auth);
- return new TwitterUser($values);
+ /********************************************//**
+ * Search
+ ***********************************************/
+ /**
+ * Returns a collection of relevant Tweets matching a specified query.
+ *
+ * @param string $query
+ * A UTF-8, URL-encoded search query of 1,000 characters maximum,
+ * including operators.
+ * @param array $params
+ * an array of parameters.
+ * @return
+ * array of Twitter statuses.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/get/search/tweets
+ */
+ public function search_tweets($query, $params = array()) {
+ $params['q'] = $query;
+ return $this->get_statuses('statuses/oembed', $params);
}
+ /********************************************//**
+ * Streaming
+ ***********************************************/
/**
+ * Returns public statuses that match one or more filter predicates.
+ *
+ * At least one predicate parameter (follow, locations, or track) must be specified.
*
- * @see http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-account%C2%A0verify_credentials
+ * @param string $follow
+ * A comma separated list of user IDs.
+ * @param string $track
+ * Keywords to track.
+ * @param string $locations
+ * Specifies a set of bounding boxes to track.
+ * @param array $params
+ * an array of parameters.
+ * @return
+ * array of Twitter statuses.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/post/statuses/filter
*/
- public function verify_credentials() {
- $values = $this->call('account/verify_credentials', array(), 'GET', TRUE);
- if (!$values) {
- return FALSE;
+ public function statuses_filter($follow = '', $track = '', $locations = '', $params = array()) {
+ if (!empty($follow)) {
+ $params['follow'] = $follow;
}
- return new TwitterUser($values);
+ if (!empty($track)) {
+ $params['track'] = $track;
+ }
+ if (!empty($locations)) {
+ $params['locations'] = $locations;
+ }
+ return $this->call('statuses/filter', $params, 'POST');
}
+ /**
+ * Returns a small random sample of all public statuses.
+ *
+ * @param array $params
+ * an array of parameters.
+ * @return
+ * array of Twitter statuses.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/get/statuses/sample
+ */
+ public function statuses_sample($params = array()) {
+ return $this->get_statuses('statuses/sample', $params);
+ }
/**
- * Method for calling any twitter api resource
+ * Returns all public statuses. Few applications require this level of access.
+ *
+ * @param array $params
+ * an array of parameters.
+ * @return
+ * array of Twitter statuses.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/get/statuses/firehose
*/
- public function call($path, $params = array(), $method = 'GET', $use_auth = FALSE) {
- $url = $this->create_url($path);
+ public function statuses_firehose($params = array()) {
+ return $this->get_statuses('statuses/firehose', $params);
+ }
- if ($use_auth) {
- $response = $this->auth_request($url, $params, $method);
+ /**
+ * Streams messages for a single user.
+ *
+ * @param array $params
+ * an array of parameters.
+ * @return
+ * array of Twitter statuses.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/get/user
+ */
+ public function user($params = array()) {
+ return $this->get_statuses('user', $params);
+ }
+
+ /**
+ * Streams messages for a set of users.
+ *
+ * @param string $follow
+ * A comma separated list of user IDs
+ * @param array $params
+ * an array of parameters.
+ * @return
+ * array of Twitter statuses.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/get/site
+ */
+ public function site($follow, $params = array()) {
+ $params['follow'] = $follow;
+ return $this->get_statuses('site', $params);
+ }
+
+ /********************************************//**
+ * Direct Messages
+ ***********************************************/
+ /**
+ * Returns the 20 most recent direct messages sent to the authenticating user.
+ *
+ * This method requires an access token with RWD (read, write & direct message)
+ * permissions
+ *
+ * @param array $params
+ * an array of parameters.
+ * @return
+ * array of Twitter statuses.
+ * @see https://dev.twitter.com/docs/api/1.1/get/direct_messages
+ */
+ public function direct_messages($params = array()) {
+ return $this->get_statuses('direct_messages', $params);
+ }
+
+ /**
+ * Returns the 20 most recent direct messages sent by the authenticating user.
+ *
+ * This method requires an access token with RWD (read, write & direct message)
+ * permissions
+ *
+ * @param array $params
+ * An array of parameters.
+ * @return
+ * Array of Twitter statuses.
+ * @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/sent
+ */
+ public function direct_messages_sent($params = array()) {
+ return $this->get_statuses('direct_messages/sent', $params);
+ }
+
+ /**
+ * Returns a single direct message, specified by an id parameter.
+ *
+ * This method requires an access token with RWD (read, write & direct message)
+ * permissions
+ *
+ * @param int $id
+ * The ID of the direct message.
+ * @return
+ * array of Twitter statuses.
+ * @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/show
+ */
+ public function direct_messages_show($id) {
+ $params = array('id' => $id);
+ return $this->get_statuses('direct_messages/show', $params);
+ }
+
+ /**
+ * Destroys the direct message specified in the required ID parameter.
+ *
+ * This method requires an access token with RWD (read, write & direct message)
+ * permissions
+ *
+ * @param int $id
+ * The ID of the direct message.
+ * @param array $params
+ * An array of parameters.
+ * @return
+ * The deleted direct message
+ * @see https://dev.twitter.com/docs/api/1.1/post/direct_messages/destroy
+ */
+ public function direct_messages_destroy($id, $params = array()) {
+ $params['id'] = $id;
+ return $this->get_statuses('direct_messages/destroy', $params);
+ }
+
+ /**
+ * Sends a new direct message to the specified user from the authenticating user.
+ *
+ * @param mixed $id
+ * The user ID or the screen name.
+ * @param string $text
+ * The URL encoded text of the message.
+ * @return
+ * array of Twitter statuses.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/post/direct_messages/new
+ */
+ public function direct_messages_new($id, $params = array()) {
+ if (is_numeric($id)) {
+ $params['user_id'] = $id;
}
else {
- $response = $this->request($url, $params, $method);
+ $params['screen_name'] = $id;
}
+ return $this->call('direct_messages/new', $params, 'POST');
+ }
- if (!$response) {
- return FALSE;
+ /********************************************//**
+ * Friends & Followers
+ ***********************************************/
+ /**
+ * Returns a cursored collection of user IDs for every user the specified user
+ * is following.
+ *
+ * @param mixed $id
+ * The user ID or the screen name.
+ * @return
+ * An array of user IDS.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/get/friends/ids
+ */
+ public function friends_ids($id, $params = array()) {
+ if (is_numeric($id)) {
+ $params['user_id'] = $id;
}
+ else {
+ $params['screen_name'] = $id;
+ }
+ return $this->call('friends/ids', $params, 'GET');
+ }
- return $this->parse_response($response);
+ /**
+ * Returns a cursored collection of user IDs for every user following the
+ * specified user.
+ *
+ * @param mixed $id
+ * The user ID or the screen name.
+ * @return
+ * An array of user IDS.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/get/followers/ids
+ */
+ public function followers_ids($id, $params = array()) {
+ if (is_numeric($id)) {
+ $params['user_id'] = $id;
+ }
+ else {
+ $params['screen_name'] = $id;
+ }
+ return $this->call('followers/ids', $params, 'GET');
}
/**
- * Perform an authentication required request.
+ * Returns the relationships of the authenticating user to the
+ * comma-separated list of up to 100 screen_names or user_ids provided.
+ *
+ * @param string $screen_name
+ * A comma separated list of screen names.
+ * @param string $user_id
+ * A comma separated list of user IDs.
+ * @return
+ * An array of user IDs and relationships.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/get/friendships/lookup
*/
- protected function auth_request($path, $params = array(), $method = 'GET') {
- if (empty($this->username) || empty($this->password)) {
- return false;
+ public function friendships_lookup($screen_name = '', $user_id = '') {
+ if (!empty($screen_name)) {
+ $params['screen_name'] = $screen_name;
}
+ if (!empty($user_id)) {
+ $params['user_id'] = $user_id;
+ }
+ return $this->call('friendships/lookup', $params, 'GET');
+ }
- return $this->request($path, $params, $method, TRUE);
+ /**
+ * Returns a collection of numeric IDs for every user who has a pending
+ * request to follow the authenticating user.
+ *
+ * @param array $params
+ * An array of parameters.
+ * @return
+ * An array of numeric user IDs.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/get/friendships/incoming
+ */
+ public function friendships_incoming($params = array()) {
+ return $this->call('friendships/incoming', $params, 'GET');
}
/**
- * Perform a request
+ * Returns a collection of numeric IDs for every protected user for whom
+ * the authenticating user has a pending follow request.
*
- * @throws TwitterException
+ * @param array $params
+ * An array of parameters.
+ * @return
+ * An array of numeric user IDs.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/get/friendships/outgoing
*/
- protected function request($url, $params = array(), $method = 'GET', $use_auth = FALSE) {
- $data = '';
- if (count($params) > 0) {
- if ($method == 'GET') {
- $url .= '?'. http_build_query($params, '', '&');
- }
- else {
- $data = http_build_query($params, '', '&');
- }
+ public function friendships_outgoing($params = array()) {
+ return $this->call('friendships/outgoing', $params, 'GET');
+ }
+
+ /**
+ * Allows the authenticating users to follow the user specified in the
+ * ID parameter.
+ *
+ * @param mixed $id
+ * The user ID or the screen name.
+ * @param bool $follow
+ * Wether to enable notifications for the target user.
+ * @return
+ * The befriended user in the requested format when successful, or a
+ * string describing the failure condition when unsuccessful.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/post/friendships/create
+ */
+ public function friendships_create($id, $follow = NULL) {
+ if (is_numeric($id)) {
+ $params['user_id'] = $id;
+ }
+ else {
+ $params['screen_name'] = $id;
+ }
+ if ($follow !== NULL) {
+ $params['follow'] = $id;
}
+ return $this->call('friendships/create', $params, 'POST');
+ }
- $headers = array();
+ /**
+ * Allows the authenticating user to unfollow the user specified in the
+ * ID parameter.
+ *
+ * @param mixed $id
+ * The user ID or the screen name.
+ * @return
+ * The unfollowed user in the requested format when successful, or a
+ * string describing the failure condition when unsuccessful.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/post/friendships/destroy
+ */
+ public function friendships_destroy($id) {
+ $params = array();
+ if (is_numeric($id)) {
+ $params['user_id'] = $id;
+ }
+ else {
+ $params['screen_name'] = $id;
+ }
+ return $this->call('friendships/destroy', $params, 'POST');
+ }
- if ($use_auth) {
- $headers['Authorization'] = 'Basic '. base64_encode($this->username .':'. $this->password);
- $headers['Content-type'] = 'application/x-www-form-urlencoded';
+ /**
+ * Allows one to enable or disable retweets and device notifications
+ * from the specified user.
+ *
+ * @param mixed $id
+ * The user ID or the screen name.
+ * @param bool $device
+ * Whether to enable/disable device notifications from the target user.
+ * @param bool $retweets
+ * Whether to enable/disable retweets from the target user.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/post/friendships/update
+ */
+ public function friendships_update($id, $device = NULL, $retweets = NULL) {
+ $params = array();
+ if (is_numeric($id)) {
+ $params['user_id'] = $id;
+ }
+ else {
+ $params['screen_name'] = $id;
}
+ if ($device !== NULL) {
+ $params['device'] = $device;
+ }
+ if ($retweets!== NULL) {
+ $params['retweets'] = $retweets;
+ }
+ return $this->call('friendships/update', $params, 'POST');
+ }
- $response = drupal_http_request($url, array('headers' => $headers, 'method' => $method, 'data' => $data));
- if (!isset($response->error)) {
- return $response->data;
+ /**
+ * Returns detailed information about the relationship between two arbitrary
+ * users.
+ *
+ * @param mixed $source_id
+ * The user ID or the screen name of the subject user.
+ * @param mixed $target_id
+ * The user ID or the screen name of the target user.
+ * @return
+ * An array of numeric user IDs.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/get/friendships/show
+ */
+ public function friendships_show($source_id, $target_id) {
+ if (is_numeric($source_id)) {
+ $params['source_id'] = $source_id;
}
else {
- $error = $response->error;
- // Check if Twitter returned an error in the response data.
- if (isset($response->data)) {
- $data = $this->parse_response($response->data);
- if (isset($data['errors'])) {
- $error = $data['errors'][0]['message'];
- }
- elseif (isset($data['error'])) {
- $error = $data['error'];
- }
- }
- throw new TwitterException($error);
+ $params['source_screen_name'] = $source_id;
}
+ if (is_numeric($target_id)) {
+ $params['target_id'] = $target_id;
+ }
+ else {
+ $params['target_screen_name'] = $target_id;
+ }
+ return $this->call('friendships/show', $params, 'GET');
}
- protected function parse_response($response, $format = NULL) {
- if (empty($format)) {
- $format = $this->format;
+ /********************************************//**
+ * Users
+ ***********************************************/
+ /**
+ * Returns settings (including current trend, geo and sleep time
+ * information) for the authenticating user.
+ *
+ * @return
+ * An array of settings.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/get/account/settings
+ */
+ public function account_settings() {
+ return $this->call('account/settings', $params, 'GET');
+ }
+
+ /**
+ * Returns an HTTP 200 OK response code and a representation of the
+ * requesting user if authentication was successful; returns a 401
+ * status code and an error message if not.
+ *
+ * @param array $params
+ * An array of parameters.
+ * @return
+ * A TwitterUser object or FALSE.
+ * @see https://dev.twitter.com/docs/api/1.1/get/account/verify_credentials
+ */
+ public function verify_credentials($params = array()) {
+ $values = $this->call('account/verify_credentials', $params, 'GET');
+ if (!$values) {
+ return FALSE;
}
+ return new TwitterUser($values);
+ }
- switch ($format) {
- case 'json':
- // http://drupal.org/node/985544 - json_decode large integer issue
- $length = strlen(PHP_INT_MAX);
- $response = preg_replace('/"(id|in_reply_to_status_id)":(\d{' . $length . ',})/', '"\1":"\2"', $response);
- return json_decode($response, TRUE);
+ /**
+ * Updates the authenticating user's settings.
+ *
+ * @param array $params
+ * An array of parameters.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/post/account/settings
+ */
+ public function account_settings_update($params = array()) {
+ return $this->call('account/settings', $params, 'POST');
+ }
+
+ /**
+ * Sets which device Twitter delivers updates to for the authenticating user.
+ *
+ * @param string $device
+ * A string which must be one of: sms, none.
+ * @param bool $include_entities
+ * Whether tweets should include entities or not.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/post/account/update_delivery_device
+ */
+ public function account_update_delivery_device($device, $include_entities = NULL) {
+ $params = array('device' => $device);
+ if ($include_entities !== NULL) {
+ $params['include_entities'] = $include_entities;
}
+ return $this->call('account/settings', $params, 'POST');
}
- protected function create_url($path, $format = NULL) {
- if (is_null($format)) {
- $format = $this->format;
+ /**
+ * Sets values that users are able to set under the "Account" tab of their
+ * settings page.
+ *
+ * @param array $params
+ * An array of parameters.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile
+ */
+ public function account_update_profile($params = array()) {
+ return $this->call('account/update_profile', $params, 'POST');
+ }
+
+ /**
+ * Updates the authenticating user's profile background image.
+ *
+ * This method can also be used to enable or disable the profile
+ * background image.
+ * At least one of image, tile or use must be provided when making this
+ * request.
+ *
+ * @param string $image
+ * A base64-encoded. Must be a valid GIF, JPG, or PNG image of less
+ * than 800 kilobytes in size.
+ * @param bool $tile
+ * Whether or not to tile the background image.
+ * @param bool $use
+ * Whether or not to use the background image.
+ * @param array $params
+ * An array of parameters.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_background_image
+ */
+ public function account_update_profile_background_image($image = NULL, $tile = NULL,
+ $use = NULL, $params = array()) {
+ if ($image !== NULL) {
+ $params['image'] = $image;
}
- $url = variable_get('twitter_api', TWITTER_API) .'/1/'. $path;
- if (!empty($format)) {
- $url .= '.'. $this->format;
+ if ($tile !== NULL) {
+ $params['tile'] = $tile;
}
- return $url;
+ if ($use !== NULL) {
+ $params['use'] = $use;
+ }
+ return $this->call('account/update_profile_background_image', $params, 'POST');
}
-}
-/**
- * A class to provide OAuth enabled access to the twitter API
- */
-class TwitterOAuth extends Twitter {
+ /**
+ * Sets one or more hex values that control the color scheme of the
+ * authenticating user's profile page on twitter.com.
+ *
+ * @param array $params
+ * An array of parameters.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_colors
+ */
+ public function account_update_profile_colors($params = array()) {
+ return $this->call('account_update_profile_colors', $params, 'POST');
+ }
- protected $signature_method;
+ /**
+ * Updates the authenticating user's profile image.
+ *
+ * @param string $image
+ * The avatar image for the profile, base64-encoded. Must be a valid
+ * GIF, JPG, or PNG
+ * @param array $params
+ * An array of parameters.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_image
+ */
+ public function account_update_profile_image($image, $params = array()) {
+ $params['image'] = $image;
+ return $this->call('account_update_profile_image', $params, 'POST');
+ }
- protected $consumer;
+ /**
+ * Returns a collection of user objects that the authenticating user is
+ * blocking.
+ *
+ * @param array $params
+ * An array of parameters.
+ * @return
+ * A TwitterUser object or FALSE.
+ * @see https://dev.twitter.com/docs/api/1.1/get/blocks/list
+ */
+ public function blocks_list($params = array()) {
+ $values = $this->call('blocks/list', $params, 'GET');
+ if (!$values) {
+ return FALSE;
+ }
+ return new TwitterUser($values);
+ }
- protected $token;
+ /**
+ * Returns an array of numeric user ids the authenticating user is blocking.
+ *
+ * @param array $params
+ * An array of parameters.
+ * @return
+ * A TwitterUser object or FALSE.
+ * @see https://dev.twitter.com/docs/api/1.1/get/blocks/ids
+ */
+ public function blocks_ids($params = array()) {
+ return $this->call('blocks/ids', $params, 'GET');
+ }
- public function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) {
- $this->signature_method = new OAuthSignatureMethod_HMAC_SHA1();
- $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
- if (!empty($oauth_token) && !empty($oauth_token_secret)) {
- $this->token = new OAuthConsumer($oauth_token, $oauth_token_secret);
+ /**
+ * Blocks the specified user from following the authenticating user.
+ *
+ * @param mixed $id
+ * The numeric id or screen name of a Twitter user.
+ * @param array $params
+ * An array of parameters.
+ * @see https://dev.twitter.com/docs/api/1.1/post/blocks/create
+ */
+ public function blocks_create($id, $params = array()) {
+ if (is_numeric($id)) {
+ $params['user_id'] = $id;
+ }
+ else {
+ $params['screen_name'] = $id;
}
+ $params['image'] = $image;
+ return $this->call('blocks/create', $params, 'POST');
}
/**
- * Builds a full URL to perform an OAuth operation
+ * Un-blocks the user specified in the ID parameter for the authenticating
+ * user.
*
- * @param $path
- * string the path of the operation
- * @param $format
- * string a valid format
- * @return
- * string full URL
+ * @param mixed $id
+ * The numeric id or screen name of a Twitter user.
+ * @param array $params
+ * An array of parameters.
+ * @see https://dev.twitter.com/docs/api/1.1/post/blocks/destroy
*/
- protected function create_url($path, $format = NULL) {
- if (is_null($format)) {
- $format = $this->format;
+ public function blocks_destroy($id, $params = array()) {
+ if (is_numeric($id)) {
+ $params['user_id'] = $id;
}
- $url = variable_get('twitter_api', TWITTER_API) .'/'. $path;
- if (!empty($format)) {
- $url .= '.'. $this->format;
+ else {
+ $params['screen_name'] = $id;
}
- return $url;
+ $params['image'] = $image;
+ return $this->call('blocks/destroy', $params, 'POST');
}
- public function get_request_token() {
- $url = $this->create_url('oauth/request_token', '');
- try {
- $response = $this->auth_request($url);
+ /**
+ * Returns fully-hydrated user objects for up to 100 users per request,
+ * as specified by comma-separated values passed to the user_id and/or
+ * screen_name parameters.
+ *
+ * @param string $screen_name
+ * A comma separated list of screen names.
+ * @param string user_id
+ * A comma separated list of user IDs.
+ * @param bool $include_entities
+ * Whether to include entities or not.
+ * @see https://dev.twitter.com/docs/api/1.1/get/users/lookup
+ */
+ protected function users_lookup($screen_name = NULL, $user_id = NULL,
+ $include_entities = NULL) {
+ if ($screen_name !== NULL) {
+ $params['screen_name'] = $screen_name;
}
- catch (TwitterException $e) {
+ if ($user_id !== NULL) {
+ $params['user_id'] = $user_id;
}
- parse_str($response, $token);
- $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
- return $token;
+ if ($include_entities !== NULL) {
+ $params['include_entities'] = $include_entities;
+ }
+ return $this->get_users('users/lookup', $params);
}
- public function get_authorize_url($token) {
- $url = $this->create_url('oauth/authorize', '');
- $url.= '?oauth_token=' . $token['oauth_token'];
+ /**
+ * Returns a variety of information about the user specified by the
+ * required user_id or screen_name parameter.
+ *
+ * @param mixed $id
+ * The numeric id or screen name of a Twitter user.
+ * @param bool $include_entities
+ * Whether to include entities or not.
+ * @see https://dev.twitter.com/docs/api/1.1/get/users/show
+ */
+ public function users_show($id, $include_entities = NULL) {
+ $params = array();
+ if (is_numeric($id)) {
+ $params['user_id'] = $id;
+ }
+ else {
+ $params['screen_name'] = $id;
+ }
+ if ($include_entities !== NULL) {
+ $params['include_entities'] = $include_entities;
+ }
+ $values = $this->call('users/show', $params, 'GET');
+ return new TwitterUser($values);
+ }
- return $url;
+ /**
+ * Provides a simple, relevance-based search interface to public user
+ * accounts on Twitter.
+ *
+ * @param string $query
+ * The search query to run against people search.
+ * @param array $params
+ * an array of parameters.
+ * @return
+ * array of TwitterUser objects.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/get/users/search
+ */
+ public function users_search($query, $params = array()) {
+ $params['q'] = $query;
+ return $this->get_users('users/search', $params);
}
- public function get_authenticate_url($token) {
- $url = $this->create_url('oauth/authenticate', '');
- $url.= '?oauth_token=' . $token['oauth_token'];
+ /**
+ * Returns a collection of users that the specified user can "contribute" to.
+ *
+ * @param mixed $id
+ * The numeric id or screen name of a Twitter user.
+ * @param array $params
+ * an array of parameters.
+ * @see https://dev.twitter.com/docs/api/1.1/get/users/contributees
+ */
+ public function users_contributees($id, $params = array()) {
+ if (is_numeric($id)) {
+ $params['user_id'] = $id;
+ }
+ else {
+ $params['screen_name'] = $id;
+ }
+ return $this->get_users('users/contributees', $params);
+ }
- return $url;
+ /**
+ * Returns a collection of users who can contribute to the specified account.
+ *
+ * @param mixed $id
+ * The numeric id or screen name of a Twitter user.
+ * @param array $params
+ * an array of parameters.
+ * @see https://dev.twitter.com/docs/api/1.1/get/users/contributors
+ */
+ public function users_contributors($id, $params = array()) {
+ if (is_numeric($id)) {
+ $params['user_id'] = $id;
+ }
+ else {
+ $params['screen_name'] = $id;
+ }
+ return $this->get_users('users/contributors', $params);
}
- public function get_access_token() {
- $url = $this->create_url('oauth/access_token', '');
- try {
- $response = $this->auth_request($url);
+ /**
+ * Removes the uploaded profile banner for the authenticating user.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/post/account/remove_profile_banner
+ */
+ public function account_remove_profile_banner() {
+ return $this->call('account/remove_profile_banner', array(), 'POST');
+ }
+
+ /**
+ * Uploads a profile banner on behalf of the authenticating user.
+ *
+ * @param string $banner
+ * The Base64-encoded or raw image data being uploaded as the user's new
+ * profile banner.
+ * @param array $params
+ * An array of parameters.
+ * @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_banner
+ */
+ public function account_update_profile_banner($banner, $params = array()) {
+ $params['banner'] = $banner;
+ return $this->call('account/update_profile_banner', $params, 'POST');
+ }
+
+ /**
+ * Returns a map of the available size variations of the specified user's
+ * profile banner.
+ *
+ * @param mixed $id
+ * The numeric id or screen name of a Twitter user.
+ * @see https://dev.twitter.com/docs/api/1.1/get/users/profile_banner
+ */
+ public function account_profile_banner($id) {
+ if (is_numeric($id)) {
+ $params['user_id'] = $id;
}
- catch (TwitterException $e) {
+ else {
+ $params['screen_name'] = $id;
}
- parse_str($response, $token);
- $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
- return $token;
+ return $this->call('account/profile_banner', $params, 'GET');
}
- public function auth_request($url, $params = array(), $method = 'GET') {
- $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $params);
- $request->sign_request($this->signature_method, $this->consumer, $this->token);
- switch ($method) {
- case 'GET':
- return $this->request($request->to_url());
- case 'POST':
- return $this->request($request->get_normalized_http_url(), $request->get_parameters(), 'POST');
+ /********************************************//**
+ * Favorites
+ ***********************************************/
+ /**
+ * Returns the 20 most recent favorited tweets for a user.
+ *
+ * @param mixed $id
+ * The numeric id or screen name of a Twitter user.
+ * @param array $params
+ * an array of parameters.
+ *
+ * @see https://dev.twitter.com/docs/api/1.1/get/favorites/list
+ */
+ public function favorites_list($id, $params = array()) {
+ if (is_numeric($id)) {
+ $params['user_id'] = $id;
+ }
+ else {
+ $params['screen_name'] = $id;
}
+ return $this->get_statuses('favorites/list', $params);
}
-}
+ /********************************************//**
+ * Utilities
+ ***********************************************/
+ /**
+ * Calls a Twitter API endpoint.
+ */
+ public function call($path, $params = array(), $method = 'GET') {
+ $url = $this->create_url($path);
-/**
- * Twitter search is not used in this module yet
- */
-class TwitterSearch extends Twitter {
- public function search($params = array()) {}
+ try {
+ $response = $this->auth_request($url, $params, $method);
+ }
+ catch (TwitterException $e) {
+ watchdog('twitter', '!message', array('!message' => $e->__toString()), WATCHDOG_ERROR);
+ return FALSE;
+ }
+
+ if (!$response) {
+ return FALSE;
+ }
+
+ return $this->parse_response($response);
+ }
}
/**
@@ -390,7 +1281,6 @@ class TwitterStatus {
$this->user = new TwitterUser($values['user']);
}
}
-
}
class TwitterUser {
@@ -443,8 +1333,6 @@ class TwitterUser {
public $status;
- protected $password;
-
protected $oauth_token;
protected $oauth_token_secret;
@@ -471,7 +1359,10 @@ class TwitterUser {
$this->profile_background_tile = $values['profile_background_tile'];
$this->verified = $values['verified'];
$this->created_at = $values['created_at'];
- if ($values['created_at'] && $created_time = strtotime($values['created_at'])) {
+ if (!empty($values['uid'])) {
+ $this->uid = $values['uid'];
+ }
+ if (!empty($values['created_at']) && $created_time = strtotime($values['created_at'])) {
$this->created_time = $created_time;
}
$this->utc_offset = $values['utc_offset']?$values['utc_offset']:0;
@@ -481,12 +1372,34 @@ class TwitterUser {
}
}
+ /**
+ * Returns an array with the authentication tokens.
+ *
+ * @return
+ * array with the oauth token key and secret.
+ */
public function get_auth() {
- return array('password' => $this->password, 'oauth_token' => $this->oauth_token, 'oauth_token_secret' => $this->oauth_token_secret);
+ return array('oauth_token' => $this->oauth_token, 'oauth_token_secret' => $this->oauth_token_secret);
}
+ /**
+ * Sets the authentication tokens to a user.
+ *
+ * @param array $values
+ * Array with 'oauth_token' and 'oauth_token_secret' keys.
+ */
public function set_auth($values) {
$this->oauth_token = isset($values['oauth_token'])?$values['oauth_token']:NULL;
$this->oauth_token_secret = isset($values['oauth_token_secret'])?$values['oauth_token_secret']:NULL;
}
+
+ /**
+ * Checks whether the account is authenticated or not.
+ *
+ * @return
+ * boolean TRUE when the account is authenticated.
+ */
+ public function is_auth() {
+ return !empty($this->oauth_token) && !empty($this->oauth_token_secret);
+ }
}
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.module b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.module
index b50ed9c..9b91bec 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.module
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.module
@@ -14,7 +14,7 @@ define ('TWITTER_TINYURL', 'http://tinyurl.com');
*/
function twitter_menu() {
$items['twitter/oauth'] = array(
- 'title' => 'Twitter',
+ 'title' => 'Twitter OAuth',
'access callback' => TRUE,
'page callback' => 'drupal_get_form',
'page arguments' => array('twitter_oauth_callback'),
@@ -24,10 +24,9 @@ function twitter_menu() {
$items['admin/config/services/twitter'] = array(
'title' => 'Twitter',
- 'description' => 'Configure integration with Twitter (and compatible) API services.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('twitter_admin_form'),
- 'access arguments' => array('administer site configuration'),
+ 'description' => 'Twitter accounts and settings.',
+ 'page callback' => 'twitter_user_settings',
+ 'access arguments' => array('administer twitter accounts'),
'file' => 'twitter.pages.inc',
);
@@ -36,37 +35,30 @@ function twitter_menu() {
'type' => MENU_DEFAULT_LOCAL_TASK,
);
- $items['user/%user_category/edit/twitter'] = array(
- 'title' => 'Twitter accounts',
- 'page callback' => 'twitter_user_settings',
- 'page arguments' => array(1),
- 'access callback' => 'twitter_edit_access',
- 'access arguments' => array(1),
- 'load arguments' => array('%map', '%index'),
- 'weight' => 10,
+ $items['admin/config/services/twitter/settings'] = array(
+ 'title' => 'Settings',
+ 'description' => 'Twitter settings.',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('twitter_admin_form'),
+ 'access arguments' => array('administer site configuration'),
'file' => 'twitter.pages.inc',
'type' => MENU_LOCAL_TASK,
);
- $items['user/%user/edit/twitter/global/%'] = array(
+ $items['user/%user/edit/twitter'] = array(
'title' => 'Twitter accounts',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('twitter_user_make_global', 1, 5),
- 'access arguments' => array('make twitter accounts global'),
+ 'page callback' => 'twitter_user_settings',
+ 'page arguments' => array(1),
+ 'access callback' => 'twitter_account_access',
+ 'weight' => 10,
'file' => 'twitter.pages.inc',
+ 'type' => MENU_LOCAL_TASK,
);
return $items;
}
/**
- * Access callback for twitter account editing.
- */
-function twitter_edit_access($account) {
- return user_edit_access($account) && user_access('add twitter accounts');
-}
-
-/**
* Implements hook_permission().
*/
function twitter_permission() {
@@ -74,29 +66,23 @@ function twitter_permission() {
'add twitter accounts' => array(
'title' => t('Add Twitter accounts'),
),
- 'use global twitter account' => array(
- 'title' => t('Use the site global Twitter account'),
+ 'add authenticated twitter accounts' => array(
+ 'title' => t('Add authenticated Twitter accounts'),
),
- 'make twitter accounts global' => array(
- 'title' => t('Assign a Twitter account as the site global account.'),
- ),
- 'import own tweets' => array(
- 'title' => t('Import own tweets to the site.'),
+ 'administer twitter accounts' => array(
+ 'title' => t('Administer Twitter accounts'),
),
);
}
/**
- * Implements hook_user_categories().
+ * Access callback for the Twitter accounts page.
+ *
+ * @return
+ * Boolean TRUE if the current user has access.
*/
-function twitter_user_categories() {
- return array(
- array(
- 'name' => 'twitter',
- 'title' => t('Twitter accounts'),
- 'weight' => 3,
- ),
- );
+function twitter_account_access() {
+ return user_access('add twitter accounts') || user_access('add authenticated twitter accounts');
}
/**
@@ -107,10 +93,45 @@ function twitter_theme() {
'twitter_account_list_form' => array(
'render element' => 'form',
),
+ 'twitter_status' => array(
+ 'variables' => array(
+ 'status' => NULL,
+ 'author' => NULL,
+ ),
+ 'template' => 'tweet',
+ 'path' => drupal_get_path('module', 'twitter'),
+ ),
+ 'twitter_user_accounts' => array(
+ 'variables' => array(
+ 'accounts' => array(),
+ ),
+ ),
);
}
/**
+ * Default callback for theme('twitter_user_accounts');
+ *
+ * Renders a list of Twitter accounts for the user profile page.
+ */
+function theme_twitter_user_accounts($variables) {
+ module_load_include('inc', 'twitter');
+ $accounts = $variables['accounts'];
+ $items = array();
+ foreach ($accounts as $twitter_account) {
+ $tweets = twitter_tweets($twitter_account->screen_name);
+ // If we have tweets for this Twitter account, link to the View. If not, link to Twitter.
+ if (count($tweets)) {
+ $items[] = l('@' . $twitter_account->screen_name, 'tweets/' . $twitter_account->screen_name);
+ }
+ else {
+ $items[] = _twitter_user_profile($twitter_account->screen_name);
+ }
+ }
+ return theme('item_list', array('items' => $items));
+}
+
+/**
* Very lightweight helper function to generate a TinyURL for a given post.
*/
function twitter_shorten_url($url) {
@@ -137,15 +158,36 @@ function twitter_cron() {
if (!variable_get('twitter_import', TRUE)) {
return;
}
+ // Check if we can connect to Twitter before proceeding.
+ module_load_include('inc', 'twitter');
+ $twitter = twitter_connect();
+ if (!$twitter) {
+ return;
+ }
// Pull up a list of Twitter accounts that are flagged for updating,
// sorted by how long it's been since we last updated them. This ensures
// that the most out-of-date accounts get updated first.
- module_load_include('inc', 'twitter');
- $result = db_query_range("SELECT twitter_uid FROM {twitter_account} WHERE import = :import ORDER BY last_refresh ASC", 0, 20, array(':import' => 1));
+ $result = db_query_range("SELECT twitter_uid
+ FROM {twitter_account}
+ WHERE uid <> 0 AND import = 1
+ ORDER BY last_refresh ASC",
+ 0, 20);
try {
foreach ($result as $account) {
+ // Fetch tweets and mentions.
twitter_fetch_user_timeline($account->twitter_uid);
+ $twitter_account = twitter_account_load($account->twitter_uid);
+ if ($twitter_account->is_auth() && $twitter_account->mentions) {
+ twitter_fetch_mentions_timeline($twitter_account->id);
+ }
+ // Mark the time this account was updated.
+ db_update('twitter_account')
+ ->fields(array(
+ 'last_refresh' => REQUEST_TIME,
+ ))
+ ->condition('twitter_uid', $twitter_account->id)
+ ->execute();
}
} catch (TwitterException $e) {
// The exception has already been logged so we do not need to do anything here apart from catching it.
@@ -160,7 +202,7 @@ function twitter_cron() {
}
/**
- * Implements hook_filter_info().
+ * Implements hook_filter_info()
*/
function twitter_filter_info() {
$filters['twitter_username'] = array(
@@ -175,18 +217,26 @@ function twitter_filter_info() {
'process callback' => '_twitter_filter_hashtag',
'tips callback' => '_twitter_filter_tip_hashtag',
);
+ $filters['twitter_links'] = array(
+ 'title' => t('Twitter link converter'),
+ 'description' => t('Makes links in Twitter messages to be opened in new windows and adds ' .
+ 'rel="nofollow" so these links do not penalize SEO.'),
+ 'process callback' => '_twitter_filter_link',
+ 'tips callback' => '_twitter_filter_tip_link',
+ );
+
return $filters;
}
/**
- * Filter tips callback function for $filters[0] in hook_filter_info().
+ * Filter tips callback function for Twitter usernames.
*/
function _twitter_filter_tip_username($filter, $format, $long = FALSE) {
return t('Twitter-style @usernames are linked to their Twitter account pages.');
}
/**
- * Filter tips callback function for $filters[1] in hook_filter_info().
+ * Filter tips callback function for Twitter hashtags.
*/
function _twitter_filter_tip_hashtag($format, $long = FALSE) {
return t('Twitter-style #hashtags are linked to !url.', array(
@@ -195,7 +245,14 @@ function _twitter_filter_tip_hashtag($format, $long = FALSE) {
}
/**
- * Callback for twitter @username converter
+ * Filter tips callback function for Twitter links.
+ */
+function _twitter_filter_tip_link($filter, $format, $long = FALSE) {
+ return t('Twitter message links are opened in new windows and rel="nofollow" is added.');
+}
+
+/**
+ * Callback for twitter @username converter.
*/
function _twitter_filter_username($text, $filter) {
$prefix = '@';
@@ -204,7 +261,7 @@ function _twitter_filter_username($text, $filter) {
}
/**
- * Callback for twitter #hashtag converter
+ * Callback for twitter #hashtag converter.
*/
function _twitter_filter_hashtag($text, $filter) {
$prefix = '#';
@@ -218,19 +275,33 @@ function _twitter_filter_hashtag($text, $filter) {
*/
function _twitter_filter_text($text, $prefix, $destination) {
$matches = array(
- '/\>' . $prefix . '([a-z0-9_]+)/i',
- '/^' . $prefix . '([a-z0-9_]+)/i',
- '/(\s+)' . $prefix . '([a-z0-9_]+)/i',
+ '/\>' . $prefix . '(\w+)/ui',
+ '/^' . $prefix . '(\w+)/ui',
+ '/(\s+)' . $prefix . '(\w+)/ui',
);
$replacements = array(
- '><a href="' . $destination . '${1}" target="_blank">' . $prefix . '${1}</a>',
- '<a href="' . $destination . '${1}" target="_blank">' . $prefix . '${1}</a>',
- '${1}<a href="' . $destination . '${2}" target="_blank">' . $prefix . '${2}</a>',
+ '><a href="' . $destination . '${1}">' . $prefix . '${1}</a>',
+ '<a href="' . $destination . '${1}">' . $prefix . '${1}</a>',
+ '${1}<a href="' . $destination . '${2}">' . $prefix . '${2}</a>',
);
return preg_replace($matches, $replacements, $text);
}
/**
+ * Callback for twitter link converter.
+ */
+function _twitter_filter_link($text, $filter) {
+ return str_replace("<a ", '<a target="_blank" rel="nofollow" ', $text);
+}
+
+/**
+ * Implements hook_views_api().
+ */
+function twitter_views_api() {
+ return array('api' => 2);
+}
+
+/**
* Implements hook_user_load().
*/
function twitter_user_load($accounts) {
@@ -240,10 +311,7 @@ function twitter_user_load($accounts) {
}
/**
- * An implementation of hook_twitter_accounts. We want to move this into a
- * separate module eventually, but sticking the code here and using a hook
- * lets other modules solve the 'what accounts can a user post with' problem
- * in cleaner ways.
+ * Implements hook_twitter_accounts().
*
* @return
* array with Twitter accounts
@@ -252,16 +320,8 @@ function twitter_twitter_accounts($account) {
module_load_include('inc', 'twitter');
$query = db_select('twitter_account', 'ta')
- ->fields('ta', array('twitter_uid'));
- if (user_access('use global twitter account', $account)) {
- $or = db_or();
- $or->condition('ta.uid', $account->uid);
- $or->condition('ta.is_global', 1);
- $query->condition($or);
- }
- else {
- $query->condition('ta.uid', $account->uid);
- }
+ ->fields('ta', array('twitter_uid'))
+ ->condition('ta.uid', $account->uid);
$twitter_accounts = array();
foreach ($query->execute()->fetchCol() as $twitter_uid) {
@@ -271,36 +331,49 @@ function twitter_twitter_accounts($account) {
}
/**
- * Detect whether we should use oauth. This can probably just go now :)
+ * Implements hook_user_delete().
+ *
+ * Removes user's Twitter accounts and tweets
*/
-function _twitter_use_oauth() {
- return module_exists('oauth_common') && variable_get('twitter_consumer_key', '') &&
- variable_get('twitter_consumer_secret', '');
+function twitter_user_delete($account) {
+ module_load_include('inc', 'twitter');
+ foreach ($account->twitter_accounts as $twitter_account) {
+ twitter_account_delete($twitter_account->id);
+ }
}
/**
- * Implements hook_views_api().
+ * Implements hook_user_view_alter()
+ *
+ * Adds Twitter account information to the user profile.
*/
-function twitter_views_api() {
- return array('api' => 2);
+function twitter_user_view_alter(&$build) {
+ $user = $build['#account'];
+ if (!empty($user->twitter_accounts)) {
+ $build['twitter'] = array(
+ '#type' => 'user_profile_item',
+ '#title' => t('Twitter accounts'),
+ '#markup' => theme('twitter_user_accounts', array('accounts' => $user->twitter_accounts)),
+ '#weight' => 10,
+ );
+ }
}
/**
- * Implements hook_admin_paths_alter().
+ * Checks if the Twitter Application keys are set.
*
- * OAuth callback disagrees with overlay.
+ * @return
+ * boolean TRUE if both the Twitter Application key and secret are set.
*/
-function twitter_admin_paths_alter(&$paths) {
- $paths['user/*/edit/twitter'] = FALSE;
+function twitter_api_keys() {
+ $key = variable_get('twitter_consumer_key');
+ $secret = variable_get('twitter_consumer_secret');
+ return !(empty($key) && empty($secret));
}
/**
- * Implements hook_user_delete().
- *
- * Removes user's Twitter accounts and tweets
+ * Helper to build a Twitter profile URL
*/
-function twitter_user_delete($account) {
- foreach ($account->twitter_accounts as $twitter_account) {
- twitter_account_delete($twitter_account->id);
- }
+function _twitter_user_profile($screen_name) {
+ return l('@' . $screen_name, TWITTER_HOST . '/' . $screen_name);
}
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.pages.inc b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.pages.inc
index d17fff7..caaa940 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.pages.inc
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.pages.inc
@@ -5,7 +5,7 @@
*/
/**
- * Form builder; Twitter settings form.
+ * Twitter settings form.
*/
function twitter_admin_form($form, &$form_state) {
$form['twitter_import'] = array(
@@ -79,24 +79,69 @@ function twitter_admin_form($form, &$form_state) {
}
/**
- * @todo Please document this function.
- * @see http://drupal.org/node/1354
+ * Form builder that lists Twitter accounts.
+ *
+ * @param object $account
+ * Optional user account.
+ * @return
+ * A list of Twitter accounts and a form to add more.
*/
-function twitter_user_settings($account) {
- module_load_include('inc', 'twitter');
+function twitter_user_settings($account = NULL) {
+ // Verify OAuth keys.
+ if (!twitter_api_keys()) {
+ $variables = array('@twitter-settings' => url('admin/config/services/twitter/settings'));
+ $output = '<p>' . t('You need to authenticate at least one Twitter account in order to use the Twitter API. Please fill out the OAuth fields at <a href="@twitter-settings">Twitter Settings</a> and then return here.', $variables) . '</p>';
+ }
+ else {
+ module_load_include('inc', 'twitter');
+ if (!$account) {
+ $twitter_accounts = twitter_account_load_all();
+ }
+ else {
+ $twitter_accounts = twitter_twitter_accounts($account);
+ }
+
+ $output = array();
+ if (count($twitter_accounts)) {
+ // List Twitter accounts.
+ $output['header']['#markup'] = '<p>';
+ if (user_access('administer site configuration')) {
+ $variables = array('@run-cron' => url('admin/reports/status/run-cron', array('query' => array('destination' => 'admin/config/services/twitter'))));
+ $output['header']['#markup'] .= t('Tweets are pulled from Twitter by <a href="@run-cron">running cron</a>.', $variables) . ' ';
+ }
+ $variables = array('@tweets' => url('tweets'));
+ $output['header']['#markup'] .= t('You can view the full list of tweets at the <a href="@tweets">Tweets</a> view.', $variables);
+ $output['header']['#markup'] .= '</p>';
+ $output['list_form'] = drupal_get_form('twitter_account_list_form', $twitter_accounts);
+ }
+ else {
+ // No accounts added. Inform about how to add one.
+ $output['header'] = array(
+ '#markup' => '<p>' . t('No Twitter accounts have been added yet. Click on the following button to add one.') . '</p>',
+ );
+ }
+
+ $output['add_account'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Add Twitter accounts'),
+ '#weight' => 5,
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ );
- $output = array();
- if (!empty($account->twitter_accounts)) {
- $output['list_form'] = drupal_get_form('twitter_account_list_form', $account->twitter_accounts);
+ if (user_access('add authenticated twitter accounts')) {
+ $output['add_account']['form'] = drupal_get_form('twitter_auth_account_form');
+ }
+ if (twitter_connect()) {
+ $output['add_account']['non_auth'] = drupal_get_form('twitter_non_auth_account_form');
+ }
}
- $output['form'] = drupal_get_form('twitter_account_form', $account);
return $output;
}
/**
- * @todo Please document this function.
- * @see http://drupal.org/node/1354
+ * Formats each Twitter account as a row within a form.
*/
function twitter_account_list_form($form, $form_state, $twitter_accounts = array()) {
$form['#tree'] = TRUE;
@@ -116,6 +161,9 @@ function twitter_account_list_form($form, $form_state, $twitter_accounts = array
return $form;
}
+/**
+ * Returns the form fields to manage a Twitter account.
+ */
function _twitter_account_list_row($account) {
$form['#account'] = $account;
@@ -124,11 +172,6 @@ function _twitter_account_list_row($account) {
'#value' => $account->id,
);
- $form['uid'] = array(
- '#type' => 'value',
- '#value' => $account->uid,
- );
-
$form['screen_name'] = array(
'#type' => 'value',
'#value' => $account->screen_name,
@@ -139,25 +182,45 @@ function _twitter_account_list_row($account) {
);
$form['visible_name'] = array(
- '#markup' => l($account->screen_name, 'http://www.twitter.com/' . $account->screen_name),
+ '#markup' => _twitter_user_profile($account->screen_name),
);
$form['description'] = array(
'#markup' => filter_xss($account->description),
);
+ if (user_access('administer twitter accounts')) {
+ $user = user_load($account->uid);
+ $form['user'] = array(
+ '#markup' => l($user->name, 'user/' . $account->uid),
+ );
+ }
+
+ $form['auth'] = array(
+ '#markup' => $account->is_auth() ? t('Yes') : t('No'),
+ );
+
$form['protected'] = array(
'#markup' => empty($account->protected) ? t('No') : t('Yes'),
);
- // Here we use user_access('import own tweets') to check permission
- // instead of user_access('import own tweets', $account->uid)
- // because we allow roles with sufficient permission to overwrite
- // the user's import settings.
- if (variable_get('twitter_import', TRUE) && user_access('import own tweets')) {
- $form['import'] = array(
+ $form['import'] = array(
+ '#type' => 'checkbox',
+ '#default_value' => $account->import ? $account->import : '',
+ );
+ if ($account->import == TRUE) {
+ $form['import']['#suffix'] = l('View', 'tweets/' . $account->screen_name, array('attributes' => array('target' => '_blank')));
+ }
+
+ if ($account->is_auth()) {
+ $form['mentions'] = array(
'#type' => 'checkbox',
- '#default_value' => user_access('import own tweets') ? $account->import : '',
+ '#default_value' => $account->mentions ? $account->mentions : '',
+ );
+ }
+ else {
+ $form['mentions'] = array(
+ '#markup' => '',
);
}
@@ -169,52 +232,46 @@ function _twitter_account_list_row($account) {
}
/**
- * @todo Please document this function.
- * @see http://drupal.org/node/1354
+ * Themes the list of Twitter accounts.
*/
function theme_twitter_account_list_form($variables) {
$form = $variables['form'];
- if (variable_get('twitter_import', TRUE) && user_access('import own tweets')) {
- $header = array('', t('Name'), t('Description'), t('Private'), t('Import'), t('Delete'));
- }
- else {
- $header = array('', t('Name'), t('Description'), t('Private'), t('Delete'));
- }
-
- if (user_access('make twitter accounts global')) {
- $header[] = '';
+ $header = array(
+ '',
+ t('Name'),
+ t('Description'),
+ );
+ if (user_access('administer twitter accounts')) {
+ $header[] = t('Added by');
}
+ $header = array_merge($header, array(
+ t('Auth'),
+ t('Private'),
+ t('Tweets'),
+ t('Mentions'),
+ t('Delete'),
+ ));
$rows = array();
-
foreach (element_children($form['accounts']) as $key) {
$element = &$form['accounts'][$key];
- if (variable_get('twitter_import', TRUE) && user_access('import own tweets')) {
- $row = array(
- drupal_render($element['image']),
- drupal_render($element['id']) . drupal_render($element['screen_name']) . drupal_render($element['visible_name']),
- drupal_render($element['description']),
- drupal_render($element['protected']),
- drupal_render($element['import']),
- drupal_render($element['delete']),
- );
- }
- else {
- $row = array(
- drupal_render($element['image']),
- drupal_render($element['id']) . drupal_render($element['screen_name']) . drupal_render($element['visible_name']),
- drupal_render($element['description']),
- drupal_render($element['protected']),
- drupal_render($element['delete']),
- );
- }
-
- if (user_access('make twitter accounts global')) {
- $label = ($element['#account']->is_global) ? t('remove global') : t('make global');
- $row[] = l($label, 'user/' . $element['#account']->uid . '/edit/twitter/global/' . $element['#account']->id);
+ $row = array(
+ drupal_render($element['image']),
+ drupal_render($element['id']) . drupal_render($element['screen_name']) .
+ drupal_render($element['visible_name']),
+ drupal_render($element['description']),
+ );
+ if (user_access('administer twitter accounts')) {
+ $row[] = drupal_render($element['user']);
}
-
+ $row = array_merge($row, array(
+ drupal_render($element['auth']),
+ drupal_render($element['protected']),
+ drupal_render($element['import']),
+ drupal_render($element['mentions']),
+ drupal_render($element['delete']),
+ ));
$rows[] = $row;
}
@@ -224,165 +281,95 @@ function theme_twitter_account_list_form($variables) {
}
/**
- * @todo Please document this function.
- * @see http://drupal.org/node/1354
+ * Form submit handler for altering the list of Twitter accounts.
*/
function twitter_account_list_form_submit($form, &$form_state) {
$accounts = $form_state['values']['accounts'];
foreach ($accounts as $account) {
if (empty($account['delete'])) {
twitter_account_save($account);
- drupal_set_message(t('The Twitter account settings were updated.'));
}
else {
+ $twitter_account = twitter_account_load($account['id']);
twitter_account_delete($account['id']);
- drupal_set_message(t('The Twitter account was deleted.'));
+ drupal_set_message(t('The Twitter account <em>!account</em> was deleted.',
+ array('!account' => $twitter_account->screen_name)));
}
}
+ drupal_set_message(t('The Twitter account settings were updated.'));
}
/**
- * @todo Please document this function.
- * @see http://drupal.org/node/1354
- */
-function twitter_user_make_global($form, $form_state, $account, $twitter_uid) {
- module_load_include('inc', 'twitter');
-
- $twitter_account = twitter_account_load($twitter_uid);
-
- $form = array();
-
- $form['uid'] = array(
- '#type' => 'value',
- '#value' => $account->uid,
- );
-
- $form['twitter_uid'] = array(
- '#type' => 'value',
- '#value' => $twitter_uid,
- );
-
- if ($twitter_account->is_global) {
- $text = t('Are you sure you want to remove %screen_name from the global accounts?', array('%screen_name' => $twitter_account->screen_name));
- $description = t('This means other users will no longer be allowed to post using this account.');
- }
- else {
- $text = t('Are you sure you want to allow other users to access the %screen_name account?', array('%screen_name' => $twitter_account->screen_name));
- $description = t('This will allow other users to post using this account.');
- }
-
- return confirm_form($form, $text, 'user/' . $account->uid . '/edit/twitter', $description);
-}
-
-/**
- * @todo Please document this function.
- * @see http://drupal.org/node/1354
+ * Form to add an authenticated Twitter account.
*/
-function twitter_user_make_global_submit($form, &$form_state) {
- db_update('twitter_account')
- ->expression('is_global', '(1 - is_global)')
- ->condition('twitter_uid', $form_state['values']['twitter_uid'])
- ->execute();
-
- $form_state['redirect'] = 'user/' . $form_state['values']['uid'] . '/edit/twitter';
-}
-
-/**
- * Form to add a Twitter account
- *
- * If OAuth is not enabled, a text field lets users to add their
- * Twitter screen name. If it is, a submit button redirects to
- * Twitter.com asking for authorisation.
- */
-function twitter_account_form($form, $form_state, $account = NULL) {
- if (empty($account)) {
- global $user;
- $account = $user;
- }
-
- $form['uid'] = array(
- '#type' => 'value',
- '#value' => $account->uid,
- );
-
- if (_twitter_use_oauth()) {
- $form['#validate'] = array('twitter_account_oauth_validate');
- }
- else {
- $form['screen_name'] = array(
- '#type' => 'textfield',
- '#required' => TRUE,
- '#title' => t('Twitter user name'),
- );
-
- $form['import'] = array(
- '#type' => 'checkbox',
- '#title' => t('Import statuses from this account'),
- '#default_value' => TRUE,
- '#access' => FALSE,
- );
- }
-
+function twitter_auth_account_form($form, $form_state) {
$form['submit'] = array(
'#type' => 'submit',
- '#value' => t('Add account'),
+ '#value' => t('Go to Twitter to add an authenticated account'),
+ '#prefix' => t('Authenticated accounts can post, sign in and pull mentions. ' .
+ 'At least one authenticated account is needed for Twitter ' .
+ 'module to work.</br>'),
);
return $form;
}
/**
- * Implements hook_FORM_ID_submit()
- *
- * Loads Twitter account details and adds them to the user account
+ * Form validation for adding a new Twitter account.
*/
-function twitter_account_form_submit($form, &$form_state) {
- module_load_include('lib.php', 'twitter');
- module_load_include('inc', 'twitter');
-
- $name = $form_state['values']['screen_name'];
- $twitter = new Twitter($name);
- try {
- $account = $twitter->users_show($name, FALSE);
- } catch (TwitterException $e) {
- form_set_error('screen_name', t('Request failed: @message.', array('@message' => $e->getMessage())));
- return;
+function twitter_auth_account_form_validate($form, &$form_state) {
+ $key = variable_get('twitter_consumer_key', '');
+ $secret = variable_get('twitter_consumer_secret', '');
+ if ($key == '' || $secret == '') {
+ form_set_error('', t('Please configure your consumer key and secret key at ' .
+ '<a href="!url">Twitter settings</a>.', array( '!url' => url('admin/config/services/twitter'),
+ )));
}
- twitter_account_save($account, TRUE, user_load($form_state['values']['uid']));
}
/**
- * If OAuth is enabled, intercept submission of 'Add Account' form on
- * user/%/edit/twitter page and redirect to Twitter for auth.
+ * Form submit handler for adding a Twiter account.
+ *
+ * Loads Twitter account details and adds them to the user account
*/
-function twitter_account_oauth_validate($form, &$form_state) {
- module_load_include('lib.php', 'oauth_common');
- module_load_include('lib.php', 'twitter');
-
+function twitter_auth_account_form_submit($form, &$form_state) {
$key = variable_get('twitter_consumer_key', '');
$secret = variable_get('twitter_consumer_secret', '');
- if ($key == '' || $secret == '') {
- form_set_error('', t('Please configure your Twitter consumer key and secret.'));
- }
-
- $twitter = new TwitterOAuth($key, $secret);
+ $twitter = new Twitter($key, $secret);
$token = $twitter->get_request_token();
-
- $_SESSION['twitter_oauth']['account'] = user_load($form['uid']['#value']);
- $_SESSION['twitter_oauth']['token'] = $token;
- $_SESSION['twitter_oauth']['destination'] = $_GET['q'];
- drupal_goto($twitter->get_authorize_url($token));
+ if ($token) {
+ $_SESSION['twitter_oauth']['token'] = $token;
+ $_SESSION['twitter_oauth']['destination'] = $_GET['q'];
+ // Check for the overlay.
+ if (module_exists('overlay') && overlay_get_mode() == 'child') {
+ overlay_close_dialog($twitter->get_authorize_url($token), array('external' => TRUE));
+ overlay_deliver_empty_page();
+ }
+ else {
+ drupal_goto($twitter->get_authorize_url($token));
+ }
+ }
+ else {
+ drupal_set_message(t('Could not obtain a valid token from the Twitter API. Please review the configuration.'),
+ 'error');
+ }
}
/**
- * @TODO This code should probably be reviewed.
- *
* Wrapper to call drupal_form_submit() which wasn't required in D6.
*/
function twitter_oauth_callback() {
if (isset($_GET['denied']) || empty($_GET['oauth_token'])) {
drupal_set_message(t('The connection to Twitter failed. Please try again.'), 'error');
- drupal_goto('<front>');
+ global $user;
+ if ($user->uid) {
+ // User is logged in, was attempting to OAuth a Twitter account.
+ drupal_goto('admin/config/services/twitter');
+ }
+ else {
+ // Anonymous user, redirect to front page.
+ drupal_goto('<front>');
+ }
}
$form_state['values']['oauth_token'] = $_GET['oauth_token'];
drupal_form_submit('twitter_oauth_callback_form', $form_state);
@@ -410,10 +397,6 @@ function twitter_oauth_callback_form_validate($form, &$form_state) {
$key = variable_get('twitter_consumer_key', '');
$secret = variable_get('twitter_consumer_secret', '');
- if ($key == '' || $secret == '') {
- form_set_error('', t('Please configure your Twitter consumer key and secret.'));
- }
-
if (isset($_SESSION['twitter_oauth'])) {
$form_state['twitter_oauth'] = $_SESSION['twitter_oauth'];
unset($_SESSION['twitter_oauth']);
@@ -435,12 +418,11 @@ function twitter_oauth_callback_form_validate($form, &$form_state) {
form_set_error('oauth_token', t('Invalid Twitter OAuth request'));
}
- module_load_include('lib.php', 'oauth_common');
- module_load_include('lib.php', 'twitter');
module_load_include('inc', 'twitter');
- if ($twitter = new TwitterOAuth($key, $secret, $token['oauth_token'], $token['oauth_token_secret'])) {
- if ($response = $twitter->get_access_token()) {
+ if ($twitter = new Twitter($key, $secret, $token['oauth_token'], $token['oauth_token_secret'])) {
+ //Collect oauth_verifier from url
+ if ($response = $twitter->get_access_token($_GET['oauth_verifier'])) {
$form_state['twitter_oauth']['response'] = $response;
}
else {
@@ -454,24 +436,76 @@ function twitter_oauth_callback_form_validate($form, &$form_state) {
/**
* Handle a Twitter OAuth return request and store the account creds
- * in the DB. Redirects to user/%/edit/twitter
+ * in the DB.
*/
function twitter_oauth_callback_form_submit($form, &$form_state) {
$key = variable_get('twitter_consumer_key', '');
$secret = variable_get('twitter_consumer_secret', '');
$response = $form_state['twitter_oauth']['response'];
- $twitter = new TwitterOAuth($key, $secret, $response['oauth_token'], $response['oauth_token_secret']);
+ $twitter = new Twitter($key, $secret, $response['oauth_token'], $response['oauth_token_secret']);
try {
$twitter_account = $twitter->users_show($response['screen_name']);
} catch (TwitterException $e) {
form_set_error('screen_name', t('Request failed: @message.', array('@message' => $e->getMessage())));
return;
}
+ // Save the new Twitter account and set the user's uid who added it.
$twitter_account->set_auth($response);
- $account = $form_state['twitter_oauth']['account'];
- twitter_account_save($twitter_account, TRUE, $account);
+ global $user;
+ $twitter_account->uid = $user->uid;
+ twitter_account_save($twitter_account, TRUE);
$form_state['programmed'] = FALSE;
$form_state['redirect'] = $form_state['twitter_oauth']['destination'];
}
+
+/**
+ * Form to add a non-authenticated Twitter account.
+ */
+function twitter_non_auth_account_form($form, $form_state) {
+ $form['screen_name'] = array(
+ '#type' => 'textfield',
+ '#required' => TRUE,
+ '#title' => t('Twitter account name'),
+ '#prefix' => t('If you simply want to pull tweets from additional Twitter accounts, ' .
+ 'enter the Twitter account name below and click on the following button.</br>'),
+ );
+
+ $form['submit_non_auth'] = array(
+ '#type' => 'submit',
+ '#value' => t('Add a non-authenticated account'),
+ );
+
+ return $form;
+}
+
+/**
+ * Form validation for adding a new non-authenticated Twitter account.
+ */
+function twitter_non_auth_account_form_validate($form, &$form_state) {
+ $screen_name = $form_state['values']['screen_name'];
+ if (twitter_account_load($screen_name)) {
+ form_set_error('screen_name', t('The Twitter account <em>@screen_name</em> has been added already.',
+ array('@screen_name' => $screen_name)));
+ }
+}
+
+/**
+ * Submit form handler to add a non-authenticated Twitter account.
+ */
+function twitter_non_auth_account_form_submit($form, &$form_state) {
+ $name = $form_state['values']['screen_name'];
+ $twitter = twitter_connect();
+ $twitter_account = $twitter->users_show($name, FALSE);
+ if (!isset($twitter_account->id)) {
+ form_set_error('screen_name', t('Could not add the Twitter account <em>@name</em>. ' .
+ 'Check the recent messages log.', array('@name' => $name)));
+ }
+ else {
+ global $user;
+ $twitter_account->uid = $user->uid;
+ twitter_account_save($twitter_account, FALSE);
+ drupal_set_message(t('Twitter account added successfully'));
+ }
+}
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.views.inc b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.views.inc
index bf45437..6e319f1 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.views.inc
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.views.inc
@@ -5,19 +5,10 @@
*/
/**
- * @defgroup views_twitter_module twitter.module handlers
- *
- * Includes the ability to create views of just the twitter table.
- * @{
- */
-
-
-/**
* Implements hook_views_data().
*/
function twitter_views_data() {
// Basic table information.
-
$data['twitter']['table']['group'] = t('Twitter');
// Advertise this table as a possible base table
@@ -87,7 +78,7 @@ function twitter_views_data() {
// Twitter screen name
$data['twitter']['screen_name'] = array(
'title' => t('Login name'),
- 'help' => t('The login account of the Twitter user.'),
+ 'help' => t('The screen name of the author of the tweet.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
@@ -148,11 +139,35 @@ function twitter_views_data() {
),
);
+ // Twitter Web Intents.
+ $data['twitter']['web_intents'] = array(
+ 'title' => t('Web Intents'),
+ 'help' => t('Links to Reply, Retweet and Favorite a tweet.'),
+ 'field' => array(
+ 'handler' => 'twitter_views_handler_field_web_intents',
+ ),
+ );
+ // Follow link
+ $data['twitter']['follow'] = array(
+ 'title' => t('Follow'),
+ 'help' => t('Link to Follow a Twitter user.'),
+ 'field' => array(
+ 'handler' => 'twitter_views_handler_field_follow',
+ ),
+ );
+ // Renders a formatted tweet.
+ $data['twitter']['formatted_tweet'] = array(
+ 'title' => t('Formatted tweet'),
+ 'help' => t('Renders a tweet as it is shown at Twitter.com.'),
+ 'field' => array(
+ 'handler' => 'twitter_views_handler_field_formatted_tweet',
+ ),
+ );
+ // Table twitter_account.
$data['twitter_account']['table']['group'] = t('Twitter');
-
$data['twitter_account']['table']['join'] = array(
'twitter' => array(
'left_field' => 'screen_name',
@@ -315,7 +330,8 @@ function twitter_views_data() {
'title' => t('User ID'),
'help' => t('The UID of the Twitter account.'),
);
- // Twitter account protected
+
+ // Twitter account protected.
$data['twitter_account']['import'] = array(
'title' => t('Import status'),
'help' => t('Whether posts from this Twitter account should be imported automatically.'),
@@ -351,7 +367,3 @@ function twitter_views_data_alter(&$data) {
'field' => 'uid',
);
}
-
-/**
- * @}
- */
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.views_default.inc b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.views_default.inc
index 1205e1d..6883bca 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.views_default.inc
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter.views_default.inc
@@ -4,18 +4,19 @@
* Default views for Twitter module.
*/
function twitter_views_default_views() {
- $view = new view;
+ $view = new view();
$view->name = 'tweets';
$view->description = 'Displays Twitter.com status messages for users who have associated Twitter accounts.';
$view->tag = '';
$view->base_table = 'twitter';
- $view->human_name = '';
+ $view->human_name = 'Tweets';
$view->core = 0;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Tweets */
$handler = $view->new_display('default', 'Tweets', 'default');
+ $handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
@@ -44,8 +45,6 @@ function twitter_views_default_views() {
'separator' => '',
),
);
- $handler->display->display_options['style_options']['override'] = 1;
- $handler->display->display_options['style_options']['sticky'] = 0;
/* Field: Twitter: Profile image */
$handler->display->display_options['fields']['profile_image_url']['id'] = 'profile_image_url';
$handler->display->display_options['fields']['profile_image_url']['table'] = 'twitter_account';
@@ -56,24 +55,7 @@ function twitter_views_default_views() {
$handler->display->display_options['fields']['text']['table'] = 'twitter';
$handler->display->display_options['fields']['text']['field'] = 'text';
$handler->display->display_options['fields']['text']['label'] = '';
- $handler->display->display_options['fields']['text']['alter']['alter_text'] = 0;
- $handler->display->display_options['fields']['text']['alter']['make_link'] = 0;
- $handler->display->display_options['fields']['text']['alter']['absolute'] = 0;
- $handler->display->display_options['fields']['text']['alter']['external'] = 0;
- $handler->display->display_options['fields']['text']['alter']['replace_spaces'] = 0;
- $handler->display->display_options['fields']['text']['alter']['trim_whitespace'] = 0;
- $handler->display->display_options['fields']['text']['alter']['nl2br'] = 0;
- $handler->display->display_options['fields']['text']['alter']['word_boundary'] = 1;
- $handler->display->display_options['fields']['text']['alter']['ellipsis'] = 1;
- $handler->display->display_options['fields']['text']['alter']['more_link'] = 0;
- $handler->display->display_options['fields']['text']['alter']['strip_tags'] = 0;
- $handler->display->display_options['fields']['text']['alter']['trim'] = 0;
- $handler->display->display_options['fields']['text']['alter']['html'] = 0;
$handler->display->display_options['fields']['text']['element_label_colon'] = FALSE;
- $handler->display->display_options['fields']['text']['element_default_classes'] = 1;
- $handler->display->display_options['fields']['text']['hide_empty'] = 0;
- $handler->display->display_options['fields']['text']['empty_zero'] = 0;
- $handler->display->display_options['fields']['text']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['text']['link_urls'] = 1;
$handler->display->display_options['fields']['text']['link_usernames'] = 1;
$handler->display->display_options['fields']['text']['link_hashtags'] = 1;
@@ -88,33 +70,6 @@ function twitter_views_default_views() {
$handler->display->display_options['sorts']['created_time']['table'] = 'twitter';
$handler->display->display_options['sorts']['created_time']['field'] = 'created_time';
$handler->display->display_options['sorts']['created_time']['order'] = 'DESC';
- /* Contextual filter: User: Uid */
- $handler->display->display_options['arguments']['uid']['id'] = 'uid';
- $handler->display->display_options['arguments']['uid']['table'] = 'users';
- $handler->display->display_options['arguments']['uid']['field'] = 'uid';
- $handler->display->display_options['arguments']['uid']['default_action'] = 'default';
- $handler->display->display_options['arguments']['uid']['exception']['title_enable'] = 1;
- $handler->display->display_options['arguments']['uid']['exception']['title'] = 'All author';
- $handler->display->display_options['arguments']['uid']['title_enable'] = 1;
- $handler->display->display_options['arguments']['uid']['title'] = '%1\'s tweets';
- $handler->display->display_options['arguments']['uid']['default_argument_type'] = 'user';
- $handler->display->display_options['arguments']['uid']['default_argument_options']['user'] = TRUE;
- $handler->display->display_options['arguments']['uid']['summary']['format'] = 'default_summary';
- $handler->display->display_options['arguments']['uid']['specify_validation'] = 1;
- $handler->display->display_options['arguments']['uid']['validate']['type'] = 'php';
- $handler->display->display_options['arguments']['uid']['validate_options']['code'] = '$uid = arg(1);
- if (!empty($uid)) {
- $account = user_load($uid);
- $twitter_accounts = twitter_twitter_accounts($account);
- if(count($twitter_accounts)) {
- return TRUE;
- }
- else {
- return FALSE;
- }
- }';
- $handler->display->display_options['arguments']['uid']['break_phrase'] = 0;
- $handler->display->display_options['arguments']['uid']['not'] = 0;
/* Filter criterion: Twitter: Protected status */
$handler->display->display_options['filters']['protected']['id'] = 'protected';
$handler->display->display_options['filters']['protected']['table'] = 'twitter_account';
@@ -123,15 +78,166 @@ function twitter_views_default_views() {
$handler->display->display_options['filters']['protected']['group'] = '0';
$handler->display->display_options['filters']['protected']['expose']['operator'] = FALSE;
- /* Display: Page */
- $handler = $view->new_display('page', 'Page', 'page');
- $handler->display->display_options['path'] = 'user/%/tweets';
- $handler->display->display_options['menu']['type'] = 'tab';
- $handler->display->display_options['menu']['title'] = 'Twitter';
- $handler->display->display_options['menu']['weight'] = '1';
+ /* Display: Tweets Raw */
+ $handler = $view->new_display('page', 'Tweets Raw', 'page_all_tweets');
+ $handler->display->display_options['defaults']['title'] = FALSE;
+ $handler->display->display_options['title'] = 'Tweets';
+ $handler->display->display_options['display_description'] = 'Lists tweets within a table.';
+ $handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
+ $handler->display->display_options['defaults']['pager'] = FALSE;
+ $handler->display->display_options['pager']['type'] = 'full';
+ $handler->display->display_options['pager']['options']['items_per_page'] = '20';
+ $handler->display->display_options['pager']['options']['offset'] = '0';
+ $handler->display->display_options['pager']['options']['id'] = '0';
+ $handler->display->display_options['pager']['options']['quantity'] = '9';
+ $handler->display->display_options['defaults']['style_plugin'] = FALSE;
+ $handler->display->display_options['style_plugin'] = 'table';
+ $handler->display->display_options['style_options']['columns'] = array(
+ 'twitter_id' => 'twitter_id',
+ 'profile_image_url' => 'profile_image_url',
+ 'name' => 'name',
+ 'screen_name' => 'screen_name',
+ 'follow' => 'follow',
+ 'text' => 'text',
+ 'created_time' => 'created_time',
+ 'web_intents' => 'web_intents',
+ );
+ $handler->display->display_options['style_options']['default'] = '-1';
+ $handler->display->display_options['style_options']['info'] = array(
+ 'twitter_id' => array(
+ 'sortable' => 0,
+ 'default_sort_order' => 'asc',
+ 'align' => '',
+ 'separator' => '',
+ 'empty_column' => 0,
+ ),
+ 'profile_image_url' => array(
+ 'sortable' => 0,
+ 'default_sort_order' => 'asc',
+ 'align' => '',
+ 'separator' => '',
+ 'empty_column' => 0,
+ ),
+ 'name' => array(
+ 'sortable' => 0,
+ 'default_sort_order' => 'asc',
+ 'align' => '',
+ 'separator' => '',
+ 'empty_column' => 0,
+ ),
+ 'screen_name' => array(
+ 'sortable' => 0,
+ 'default_sort_order' => 'asc',
+ 'align' => '',
+ 'separator' => '',
+ 'empty_column' => 0,
+ ),
+ 'follow' => array(
+ 'align' => '',
+ 'separator' => '',
+ 'empty_column' => 0,
+ ),
+ 'text' => array(
+ 'sortable' => 0,
+ 'default_sort_order' => 'asc',
+ 'align' => '',
+ 'separator' => '',
+ 'empty_column' => 0,
+ ),
+ 'created_time' => array(
+ 'sortable' => 0,
+ 'default_sort_order' => 'asc',
+ 'align' => '',
+ 'separator' => '',
+ 'empty_column' => 0,
+ ),
+ 'web_intents' => array(
+ 'align' => '',
+ 'separator' => '',
+ 'empty_column' => 0,
+ ),
+ );
+ $handler->display->display_options['defaults']['style_options'] = FALSE;
+ $handler->display->display_options['defaults']['row_plugin'] = FALSE;
+ $handler->display->display_options['defaults']['row_options'] = FALSE;
+ $handler->display->display_options['defaults']['fields'] = FALSE;
+ /* Field: Twitter: Twitter status message ID */
+ $handler->display->display_options['fields']['twitter_id']['id'] = 'twitter_id';
+ $handler->display->display_options['fields']['twitter_id']['table'] = 'twitter';
+ $handler->display->display_options['fields']['twitter_id']['field'] = 'twitter_id';
+ $handler->display->display_options['fields']['twitter_id']['label'] = '';
+ $handler->display->display_options['fields']['twitter_id']['exclude'] = TRUE;
+ $handler->display->display_options['fields']['twitter_id']['element_label_colon'] = FALSE;
+ /* Field: Twitter: Profile image */
+ $handler->display->display_options['fields']['profile_image_url']['id'] = 'profile_image_url';
+ $handler->display->display_options['fields']['profile_image_url']['table'] = 'twitter_account';
+ $handler->display->display_options['fields']['profile_image_url']['field'] = 'profile_image_url';
+ $handler->display->display_options['fields']['profile_image_url']['label'] = '';
+ /* Field: Twitter: Full name */
+ $handler->display->display_options['fields']['name']['id'] = 'name';
+ $handler->display->display_options['fields']['name']['table'] = 'twitter_account';
+ $handler->display->display_options['fields']['name']['field'] = 'name';
+ $handler->display->display_options['fields']['name']['label'] = '';
+ $handler->display->display_options['fields']['name']['alter']['make_link'] = TRUE;
+ $handler->display->display_options['fields']['name']['alter']['path'] = 'https://twitter.com/[screen_name]';
+ $handler->display->display_options['fields']['name']['alter']['absolute'] = TRUE;
+ $handler->display->display_options['fields']['name']['alter']['target'] = '_blank';
+ $handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
+ /* Field: Twitter: Login name */
+ $handler->display->display_options['fields']['screen_name']['id'] = 'screen_name';
+ $handler->display->display_options['fields']['screen_name']['table'] = 'twitter';
+ $handler->display->display_options['fields']['screen_name']['field'] = 'screen_name';
+ $handler->display->display_options['fields']['screen_name']['label'] = '';
+ $handler->display->display_options['fields']['screen_name']['alter']['make_link'] = TRUE;
+ $handler->display->display_options['fields']['screen_name']['alter']['path'] = 'https://twitter.com/[screen_name] ';
+ $handler->display->display_options['fields']['screen_name']['alter']['absolute'] = TRUE;
+ $handler->display->display_options['fields']['screen_name']['alter']['prefix'] = '@';
+ $handler->display->display_options['fields']['screen_name']['alter']['target'] = '_blank';
+ $handler->display->display_options['fields']['screen_name']['element_label_colon'] = FALSE;
+ /* Field: Twitter: Follow */
+ $handler->display->display_options['fields']['follow']['id'] = 'follow';
+ $handler->display->display_options['fields']['follow']['table'] = 'twitter';
+ $handler->display->display_options['fields']['follow']['field'] = 'follow';
+ $handler->display->display_options['fields']['follow']['label'] = '';
+ $handler->display->display_options['fields']['follow']['element_label_colon'] = FALSE;
+ /* Field: Twitter: Message text */
+ $handler->display->display_options['fields']['text']['id'] = 'text';
+ $handler->display->display_options['fields']['text']['table'] = 'twitter';
+ $handler->display->display_options['fields']['text']['field'] = 'text';
+ $handler->display->display_options['fields']['text']['label'] = '';
+ $handler->display->display_options['fields']['text']['element_label_colon'] = FALSE;
+ $handler->display->display_options['fields']['text']['link_urls'] = 1;
+ $handler->display->display_options['fields']['text']['link_usernames'] = 1;
+ $handler->display->display_options['fields']['text']['link_hashtags'] = 1;
+ /* Field: Twitter: Created time */
+ $handler->display->display_options['fields']['created_time']['id'] = 'created_time';
+ $handler->display->display_options['fields']['created_time']['table'] = 'twitter';
+ $handler->display->display_options['fields']['created_time']['field'] = 'created_time';
+ $handler->display->display_options['fields']['created_time']['label'] = '';
+ $handler->display->display_options['fields']['created_time']['date_format'] = 'time ago';
+ /* Field: Twitter: Web Intents */
+ $handler->display->display_options['fields']['web_intents']['id'] = 'web_intents';
+ $handler->display->display_options['fields']['web_intents']['table'] = 'twitter';
+ $handler->display->display_options['fields']['web_intents']['field'] = 'web_intents';
+ $handler->display->display_options['fields']['web_intents']['label'] = '';
+ $handler->display->display_options['fields']['web_intents']['element_label_colon'] = FALSE;
+ $handler->display->display_options['defaults']['arguments'] = FALSE;
+ /* Contextual filter: Twitter: Login name */
+ $handler->display->display_options['arguments']['screen_name']['id'] = 'screen_name';
+ $handler->display->display_options['arguments']['screen_name']['table'] = 'twitter';
+ $handler->display->display_options['arguments']['screen_name']['field'] = 'screen_name';
+ $handler->display->display_options['arguments']['screen_name']['title_enable'] = TRUE;
+ $handler->display->display_options['arguments']['screen_name']['title'] = 'Tweets by @%1';
+ $handler->display->display_options['arguments']['screen_name']['default_argument_type'] = 'fixed';
+ $handler->display->display_options['arguments']['screen_name']['summary']['number_of_records'] = '0';
+ $handler->display->display_options['arguments']['screen_name']['summary']['format'] = 'default_summary';
+ $handler->display->display_options['arguments']['screen_name']['summary_options']['items_per_page'] = '25';
+ $handler->display->display_options['arguments']['screen_name']['limit'] = '0';
+ $handler->display->display_options['path'] = 'tweets-raw';
/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');
+ $handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['defaults']['use_more'] = FALSE;
$handler->display->display_options['use_more'] = TRUE;
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
@@ -152,27 +258,11 @@ function twitter_views_default_views() {
$handler->display->display_options['fields']['text']['table'] = 'twitter';
$handler->display->display_options['fields']['text']['field'] = 'text';
$handler->display->display_options['fields']['text']['label'] = '';
- $handler->display->display_options['fields']['text']['alter']['alter_text'] = 0;
- $handler->display->display_options['fields']['text']['alter']['make_link'] = 0;
- $handler->display->display_options['fields']['text']['alter']['absolute'] = 0;
- $handler->display->display_options['fields']['text']['alter']['external'] = 0;
- $handler->display->display_options['fields']['text']['alter']['replace_spaces'] = 0;
- $handler->display->display_options['fields']['text']['alter']['trim_whitespace'] = 0;
- $handler->display->display_options['fields']['text']['alter']['nl2br'] = 0;
- $handler->display->display_options['fields']['text']['alter']['word_boundary'] = 1;
- $handler->display->display_options['fields']['text']['alter']['ellipsis'] = 1;
- $handler->display->display_options['fields']['text']['alter']['more_link'] = 0;
- $handler->display->display_options['fields']['text']['alter']['strip_tags'] = 0;
- $handler->display->display_options['fields']['text']['alter']['trim'] = 0;
- $handler->display->display_options['fields']['text']['alter']['html'] = 0;
$handler->display->display_options['fields']['text']['element_label_colon'] = FALSE;
- $handler->display->display_options['fields']['text']['element_default_classes'] = 1;
- $handler->display->display_options['fields']['text']['hide_empty'] = 0;
- $handler->display->display_options['fields']['text']['empty_zero'] = 0;
- $handler->display->display_options['fields']['text']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['text']['link_urls'] = 1;
$handler->display->display_options['fields']['text']['link_usernames'] = 1;
$handler->display->display_options['fields']['text']['link_hashtags'] = 1;
+ $handler->display->display_options['fields']['text']['link_attributes'] = 1;
/* Field: Twitter: Created time */
$handler->display->display_options['fields']['created_time']['id'] = 'created_time';
$handler->display->display_options['fields']['created_time']['table'] = 'twitter';
@@ -180,7 +270,53 @@ function twitter_views_default_views() {
$handler->display->display_options['fields']['created_time']['label'] = '';
$handler->display->display_options['fields']['created_time']['date_format'] = 'time ago';
$handler->display->display_options['defaults']['arguments'] = FALSE;
- $handler->display->display_options['block_description'] = 'User Tweets';
+ $handler->display->display_options['block_description'] = 'Tweets';
+
+ /* Display: Tweets */
+ $handler = $view->new_display('page', 'Tweets', 'page_2');
+ $handler->display->display_options['defaults']['title'] = FALSE;
+ $handler->display->display_options['title'] = 'Tweets';
+ $handler->display->display_options['display_description'] = 'Displays a formatted list of tweets';
+ $handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
+ $handler->display->display_options['defaults']['pager'] = FALSE;
+ $handler->display->display_options['pager']['type'] = 'full';
+ $handler->display->display_options['pager']['options']['items_per_page'] = '20';
+ $handler->display->display_options['pager']['options']['offset'] = '0';
+ $handler->display->display_options['pager']['options']['id'] = '0';
+ $handler->display->display_options['pager']['options']['quantity'] = '9';
+ $handler->display->display_options['defaults']['style_plugin'] = FALSE;
+ $handler->display->display_options['style_plugin'] = 'list';
+ $handler->display->display_options['defaults']['style_options'] = FALSE;
+ $handler->display->display_options['defaults']['row_plugin'] = FALSE;
+ $handler->display->display_options['row_plugin'] = 'fields';
+ $handler->display->display_options['defaults']['row_options'] = FALSE;
+ $handler->display->display_options['defaults']['fields'] = FALSE;
+ /* Field: Twitter: Twitter status message ID */
+ $handler->display->display_options['fields']['twitter_id']['id'] = 'twitter_id';
+ $handler->display->display_options['fields']['twitter_id']['table'] = 'twitter';
+ $handler->display->display_options['fields']['twitter_id']['field'] = 'twitter_id';
+ $handler->display->display_options['fields']['twitter_id']['label'] = '';
+ $handler->display->display_options['fields']['twitter_id']['exclude'] = TRUE;
+ $handler->display->display_options['fields']['twitter_id']['element_label_colon'] = FALSE;
+ /* Field: Twitter: Formatted tweet */
+ $handler->display->display_options['fields']['formatted_tweet']['id'] = 'formatted_tweet';
+ $handler->display->display_options['fields']['formatted_tweet']['table'] = 'twitter';
+ $handler->display->display_options['fields']['formatted_tweet']['field'] = 'formatted_tweet';
+ $handler->display->display_options['fields']['formatted_tweet']['label'] = '';
+ $handler->display->display_options['fields']['formatted_tweet']['element_label_colon'] = FALSE;
+ $handler->display->display_options['defaults']['arguments'] = FALSE;
+ /* Contextual filter: Twitter: Login name */
+ $handler->display->display_options['arguments']['screen_name']['id'] = 'screen_name';
+ $handler->display->display_options['arguments']['screen_name']['table'] = 'twitter';
+ $handler->display->display_options['arguments']['screen_name']['field'] = 'screen_name';
+ $handler->display->display_options['arguments']['screen_name']['title_enable'] = TRUE;
+ $handler->display->display_options['arguments']['screen_name']['title'] = 'Tweets by @%1';
+ $handler->display->display_options['arguments']['screen_name']['default_argument_type'] = 'fixed';
+ $handler->display->display_options['arguments']['screen_name']['summary']['number_of_records'] = '0';
+ $handler->display->display_options['arguments']['screen_name']['summary']['format'] = 'default_summary';
+ $handler->display->display_options['arguments']['screen_name']['summary_options']['items_per_page'] = '25';
+ $handler->display->display_options['arguments']['screen_name']['limit'] = '0';
+ $handler->display->display_options['path'] = 'tweets';
return array('tweets' => $view);
}
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_actions/twitter_actions.info b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_actions/twitter_actions.info
index 4d2b6d3..66c6cea 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_actions/twitter_actions.info
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_actions/twitter_actions.info
@@ -2,11 +2,10 @@ name = Twitter actions
description = Exposes Drupal actions to send Twitter messages.
core = 7.x
dependencies[] = twitter
-dependencies[] = oauth_common
-; Information added by drupal.org packaging script on 2012-08-11
-version = "7.x-3.2"
+; Information added by drupal.org packaging script on 2013-06-03
+version = "7.x-5.8"
core = "7.x"
project = "twitter"
-datestamp = "1344714197"
+datestamp = "1370303463"
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_actions/twitter_actions.module b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_actions/twitter_actions.module
index 25d1fd5..7a36541 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_actions/twitter_actions.module
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_actions/twitter_actions.module
@@ -36,31 +36,25 @@ function twitter_actions_action_info() {
/**
* Returns a form definition so the Twitter action can be configured.
*
- * @param $context
+ * @param array $context
* Default values (if we are editing an existing action instance).
* @return
* Form definition.
*/
function twitter_actions_set_status_action_form($context) {
- $options = array();
- $results = db_query("SELECT screen_name FROM {twitter_account}");
- foreach ($results as $result) {
- $options[$result->screen_name] = $result->screen_name;
- }
+ $options = twitter_actions_account_options();
// Set default values for form.
$form['screen_name'] = array(
'#type' => 'select',
'#title' => t('Twitter account name'),
- '#options' => $options,
+ '#description' => t('Twitter account which will be used. ' .
+ 'By selecting [current user] the rule will check if the user ' .
+ 'has authenticated a Twitter account to use.'),
+ '#options' => $options,
'#default_value' => isset($context['screen_name']) ? $context['screen_name'] : '',
'#required' => TRUE,
);
- if (!count($options)) {
- $form['screen_name']['#description'] = t('You first need to add a Twitter account to one of ' .
- 'your users with rights for posting to Twitter.');
- }
-
$form['message'] = array(
'#type' => 'textarea',
'#title' => t('Message'),
@@ -77,14 +71,21 @@ function twitter_actions_set_status_action_form($context) {
}
/**
- * Verifies if Oauth module has been setup and also checks the Twitter
- * authentication against the provided screen name.
+ * Returns a list of authenticated Twitter accounts to be used as options.
+ *
+ * @return
+ * array of screen_name => screen_name entries.
*/
-function twitter_actions_set_status_action_validate($form, $form_state) {
- if (!_twitter_use_oauth()) {
- form_set_error('screen_name', t('Oauth has not been setup yet. Please go to !link and follow steps.',
- array('!link' => l(t('Twitter settings'), 'admin/settings/twitter'))));
+function twitter_actions_account_options() {
+ module_load_include('inc', 'twitter');
+ $twitter_accounts = twitter_load_authenticated_accounts();
+ $options = array();
+ foreach ($twitter_accounts as $twitter_account) {
+ $options[$twitter_account->screen_name] = '@' . $twitter_account->screen_name;
}
+ // Extra token to use current user's account.
+ $options['[current user]'] = '[current user]';
+ return $options;
}
/**
@@ -93,11 +94,9 @@ function twitter_actions_set_status_action_validate($form, $form_state) {
*/
function twitter_actions_set_status_action_submit($form, $form_state) {
$form_values = $form_state['values'];
- $twitter_uid = db_query("SELECT twitter_uid FROM {twitter_account} WHERE screen_name = :screen_name", array(':screen_name' => $form_values['screen_name']))->fetchField();
// Process the HTML form to store configuration. The keyed array that
// we return will be serialized to the database.
$params = array(
- 'twitter_uid' => $twitter_uid,
'screen_name' => $form_values['screen_name'],
'message' => $form_values['message'],
);
@@ -106,7 +105,39 @@ function twitter_actions_set_status_action_submit($form, $form_state) {
}
/**
- * Implementation of a configurable Twitter actions.
+ * Validates the Twitter account to use to send a Tweet.
+ *
+ * If it is a Twitter account, it will check it still exists.
+ * If it is [current user], it will see if the current user has an
+ * authenticated Twitter account to use.
+ *
+ * @param string $screen_name
+ * The selected value that represents a Twitter account to use.
+ * @return
+ * Integer the Twitter ID of the account to use or NULL.
+ */
+function _twitter_actions_get_twitter_id($screen_name) {
+ $twitter_uid = NULL;
+ // Find out the Twitter ID to use.
+ if ($screen_name == '[current user]') {
+ // Check if this user has an authenticated account.
+ global $user;
+ $account = user_load($user->uid);
+ foreach ($account->twitter_accounts as $twitter_account) {
+ if ($twitter_account->is_auth()) {
+ $twitter_uid = $twitter_account->id;
+ }
+ }
+ }
+ else {
+ $twitter_uid = db_query("SELECT twitter_uid FROM {twitter_account} WHERE screen_name = :screen_name",
+ array(':screen_name' => $screen_name))->fetchField();
+ }
+ return $twitter_uid;
+}
+
+/**
+ * Implementation of a configurable Twitter action.
* @todo Implementation for language negotiation for the body and sumary. Also
* need implementation for bodies with multiple values. Right now it is hard
* coded and it will only get body and summary for 'und' language and only
@@ -114,75 +145,86 @@ function twitter_actions_set_status_action_submit($form, $form_state) {
* If the final message is over 140 chars, there is no feedback to the user.
*/
function twitter_actions_set_status_action($object, $context) {
- global $user;
- $variables['%site_name'] = variable_get('site_name', 'Drupal');
- // Seting variables array depending on action's group
- switch ($context['group']) {
- case 'node':
- $node = $context['node'];
- if (isset($node)) {
- $variables = array_merge($variables, array(
- '%uid' => $node->uid,
- '%username' => $node->name,
- '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)),
- '%node_type' => node_type_get_name($node),
- '%title' => $node->title,
- '%summary' => isset($node->body['und'][0]['value']) ? $node->body['und'][0]['summary'] : '',
- '%body' => isset($node->body['und'][0]['value']) ? $node->body['und'][0]['value'] : '',
- )
- );
- }
- break;
+ $twitter_uid = _twitter_actions_get_twitter_id($context['screen_name']);
+ if ($twitter_uid) {
+ global $user;
+ $variables['%site_name'] = variable_get('site_name', 'Drupal');
+ // Seting variables array depending on action's group
+ switch ($context['group']) {
+ case 'node':
+ $node = $context['node'];
+ if (isset($node)) {
+ $variables = array_merge($variables, array(
+ '%uid' => $node->uid,
+ '%username' => $node->name,
+ '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)),
+ '%node_type' => node_type_get_name($node),
+ '%title' => $node->title,
+ '%summary' => isset($node->body['und'][0]['value']) ? $node->body['und'][0]['summary'] : '',
+ '%body' => isset($node->body['und'][0]['value']) ? $node->body['und'][0]['value'] : '',
+ )
+ );
+ }
+ break;
- case 'comment':
- $node = node_load($context['comment']->nid);
- if (isset($node)) {
- $variables = array_merge($variables, array(
- '%uid' => $context['comment']->uid,
- '%username' => $context['comment']->name,
- '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)),
- '%node_type' => node_type_get_name($node),
- '%title' => $node->title,
- '%summary' => isset($node->body['und'][0]['value']) ? $node->body['und'][0]['summary'] : '',
- '%body' => isset($node->body['und'][0]['value']) ? $node->body['und'][0]['value'] : '',
- )
- );
- }
- break;
+ case 'comment':
+ $node = node_load($context['comment']->nid);
+ if (isset($node)) {
+ $variables = array_merge($variables, array(
+ '%uid' => $context['comment']->uid,
+ '%username' => $context['comment']->name,
+ '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)),
+ '%node_type' => node_type_get_name($node),
+ '%title' => $node->title,
+ '%summary' => isset($node->body[LANGUAGE_NONE][0]['value']) ? $node->body['und'][0]['summary'] : '',
+ '%body' => isset($node->body[LANGUAGE_NONE][0]['value']) ? $node->body['und'][0]['value'] : '',
+ )
+ );
+ }
+ break;
- case 'user':
- $variables['%username'] = $context['user']->name;
- break;
+ case 'user':
+ $variables['%username'] = $context['user']->name;
+ break;
- case 'cron':
- break;
+ case 'cron':
+ break;
- default:
- // We are being called directly.
- $node = $object;
- if (isset($node) && is_object($node)) {
- $variables = array_merge($variables, array(
- '%uid' => $node->uid,
- '%username' => $node->name,
- '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)),
- '%node_type' => node_type_get_name($node),
- '%title' => $node->title,
- '%summary' => isset($node->body['und'][0]['value']) ? $node->body['und'][0]['summary'] : '',
- '%body' => isset($node->body['und'][0]['value']) ? $node->body['und'][0]['value'] : '',
- )
- );
- }
- }
+ default:
+ // We are being called directly.
+ $node = $object;
+ if (isset($node) && is_object($node)) {
+ $variables = array_merge($variables, array(
+ '%uid' => $node->uid,
+ '%username' => $node->name,
+ '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)),
+ '%node_type' => node_type_get_name($node),
+ '%title' => $node->title,
+ '%summary' => isset($node->body[LANGUAGE_NONE][0]['value']) ? $node->body['und'][0]['summary'] : '',
+ '%body' => isset($node->body[LANGUAGE_NONE][0]['value']) ? $node->body['und'][0]['value'] : '',
+ )
+ );
+ }
+ }
- // Only make a tinyurl if it was asked for.
- if (strstr($context['message'], '%tinyurl') !== FALSE) {
- $variables = array_merge($variables, array(
- '%tinyurl' => twitter_shorten_url(url('node/' . $node->nid, array('absolute' => TRUE))),
- ));
- }
+ // Only make a tinyurl if it was asked for.
+ if (strstr($context['message'], '%tinyurl') !== FALSE) {
+ $variables = array_merge($variables, array(
+ '%tinyurl' => twitter_shorten_url(url('node/' . $node->nid, array('absolute' => TRUE))),
+ ));
+ }
- $message = strtr($context['message'], $variables);
- module_load_include('inc', 'twitter');
- $twitter_account = twitter_account_load($context['twitter_uid']);
- twitter_set_status($twitter_account, $message);
+ // Send the tweet.
+ $message = strtr($context['message'], $variables);
+ module_load_include('inc', 'twitter');
+ try {
+ $twitter_account = twitter_account_load($twitter_uid);
+ twitter_set_status($twitter_account, $message);
+ drupal_set_message(t('Successfully posted to Twitter'));
+ }
+ catch (TwitterException $e) {
+ drupal_set_message(t('An error occurred when posting to Twitter: @message',
+ array('@message' => $e->getMessage())), 'warning');
+ }
+ }
}
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_actions/twitter_actions.rules.inc b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_actions/twitter_actions.rules.inc
index 1efac55..7b77043 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_actions/twitter_actions.rules.inc
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_actions/twitter_actions.rules.inc
@@ -1,11 +1,11 @@
<?php
/**
* @file
- * Provide better intergration into the rules module
+ * Provides Rules integration in order to post tweets.
*/
/**
- * Implements hook_rules_action_info() on behalf of the twitter module.
+ * Implements hook_rules_action_info() on behalf of the Twitter module.
*/
function twitter_actions_rules_action_info() {
return array(
@@ -19,9 +19,14 @@ function twitter_actions_rules_action_info() {
'description' => t("The content of the tweet."),
),
'sender' => array(
- 'type' => 'user',
+ 'type' => 'text',
'label' => t('Sender'),
- 'description' => t("User whose Twitter account will be used."),
+ 'description' => t('Twitter account which will be used. ' .
+ 'By selecting [current user] the rule will check if the user ' .
+ 'has authenticated a Twitter account to use.'),
+ 'options list' => '_twitter_rules_account_options',
+ 'restriction' => 'input',
+ 'default mode' => 'input',
),
),
'base' => 'twitter_actions_set_status',
@@ -31,7 +36,18 @@ function twitter_actions_rules_action_info() {
}
/**
- * Fetches Twitter account info and submits with the message to the Twitter API
+ * Returns the list of Twitter accounts to be used for posting.
+ *
+ * @return
+ * an array of Twitter accounts.
+ * @see twitter_actions_account_options()
+ */
+function _twitter_rules_account_options(RulesPlugin $element, $param_name) {
+ return twitter_actions_account_options();
+}
+
+/**
+ * Fetches Twitter account info and submits with the message to the Twitter API.
*
* @param $message
* The message to post
@@ -39,21 +55,22 @@ function twitter_actions_rules_action_info() {
* The Drupal user that has a Twitter account
*/
function twitter_actions_set_status($message, $sender) {
- if ($twitter_uid = db_query("SELECT twitter_uid FROM {twitter_account} WHERE uid = :uid", array(':uid' => $sender->uid))->fetchField()) {
- module_load_include('inc', 'twitter');
- $twitter_account = twitter_account_load($twitter_uid);
- try {
- twitter_set_status($twitter_account, $message);
- drupal_set_message(t('Successfully posted to Twitter'));
- }
- catch (TwitterException $e) {
- drupal_set_message(t('An error occurred when posting to Twitter: @message',
- array('@message' => $e->getMessage())), 'warning');
- }
+ $twitter_uid = _twitter_actions_get_twitter_id($sender);
+ if (!isset($twitter_uid)) {
+ // No Twitter authenticated account found.
+ return;
+ }
+
+ // Send tweet.
+ module_load_include('inc', 'twitter');
+ $twitter_account = twitter_account_load($twitter_uid);
+ try {
+ twitter_set_status($twitter_account, $message);
+ drupal_set_message(t('Successfully posted to Twitter'));
}
- else {
- watchdog('twitter', 'Could not find the Twitter account to be used for posting. Please review the rule settings.',
- array(), WATCHDOG_ERROR);
+ catch (TwitterException $e) {
+ drupal_set_message(t('An error occurred when posting to Twitter: @message',
+ array('@message' => $e->getMessage())), 'warning');
}
}
@@ -61,23 +78,7 @@ function twitter_actions_set_status($message, $sender) {
* Implements hook_rules_condition_info().
*/
function twitter_actions_rules_condition_info() {
- $defaults = array(
- 'group' => t('Twitter'),
- 'parameter' => array(
- 'user' => array(
- 'type' => 'user',
- 'label' => t('User'),
- 'description' => t('The user to be checked for.'),
- ),
- ),
- 'named parameter' => TRUE,
- 'access callback' => 'rules_twitter_actions_access_callback',
- );
- $items['rules_core_twitter_conditions_user_has_linked'] = $defaults + array(
- 'label' => t('User has linked Twitter account'),
- 'help' => t('Evaluates to TRUE in case there is a record in the twitter_account for the provided user.'),
- 'base' => 'twitter_actions_has_linked',
- );
+ $items = array();
$items['rules_core_twitter_conditions_text_is_under_140'] = array(
'group' => t('Twitter'),
@@ -99,20 +100,9 @@ function twitter_actions_rules_condition_info() {
/**
* The callback function for the Rules condition
* @param $element
- * $element['user']: The user to be checked for.
- * @return
- * TRUE if the user has linked his/her Twitter account.
- */
-function twitter_actions_has_linked($element) {
- return db_query("SELECT twitter_uid FROM {twitter_account} WHERE uid = :uid", array(':uid' => $element['user']->uid))->fetchField() ? TRUE : FALSE;
-}
-
-/**
- * The callback function for the Rules condition
- * @param $element
- * $element['user']: The user to be checked for.
+ * $element['text']: The text of the message.
* @return
- * TRUE if the user has linked his/her Twitter account.
+ * TRUE if the message length is less than 141 characters.
*/
function twitter_actions_less_140($element) {
return strlen($element['text']) < 141;
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_post/twitter_post.info b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_post/twitter_post.info
index f515a7f..2ff82ce 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_post/twitter_post.info
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_post/twitter_post.info
@@ -2,11 +2,11 @@ name = Twitter Post
description = Enables posting to twitter
core = 7.x
dependencies[] = twitter
-dependencies[] = oauth_common
+configure = admin/config/services/twitter/post
-; Information added by drupal.org packaging script on 2012-08-11
-version = "7.x-3.2"
+; Information added by drupal.org packaging script on 2013-06-03
+version = "7.x-5.8"
core = "7.x"
project = "twitter"
-datestamp = "1344714197"
+datestamp = "1370303463"
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_post/twitter_post.install b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_post/twitter_post.install
new file mode 100644
index 0000000..af71041
--- /dev/null
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_post/twitter_post.install
@@ -0,0 +1,40 @@
+<?php
+/**
+ * @file
+ * Install, update and uninstall functions for the twitter module.
+ *
+ */
+
+/**
+ * Implements hook_uninstall().
+ */
+function twitter_post_uninstall() {
+ variable_del('twitter_post_types');
+ variable_del('twitter_post_default_format');
+ variable_del('twitter_post_default_value');
+}
+
+/**
+ * Don't default to TinyURL any more.
+ */
+function twitter_post_update_7300() {
+ if (variable_get('twitter_post_default_format', NULL) == 'New post: !title !tinyurl') {
+ variable_set('twitter_post_default_format', "New post: !title !url-alias");
+ }
+ return t('Twitter Post now defaults to using aliases, not TinyURL.');
+}
+
+/**
+ * Implements hook_update_N().
+ *
+ * Increase module weight to run after pathauto.
+ */
+function twitter_post_update_7301() {
+ db_update('system')
+ ->fields(array(
+ 'weight' => 10,
+ ))
+ ->condition('name', 'twitter_post', '=')
+ ->execute();
+ return t('Updated system weight to 10 for Twitter Post.');
+}
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_post/twitter_post.module b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_post/twitter_post.module
index b1debd3..0effd13 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_post/twitter_post.module
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_post/twitter_post.module
@@ -1,8 +1,7 @@
<?php
-
/**
* @file
- * Main hooks for twitter post module
+ * Hook implementations for twitter_post module.
*/
/**
@@ -39,16 +38,14 @@ function twitter_post_permission() {
function twitter_post_form_alter(&$form, $form_state, $form_id) {
// Alter any node forms.
if (isset($form['#node']) && $form['#node']->type . '_node_form' == $form_id) {
- // If we haven't enabled Twitter posting on this node type, nothing to do
- // here.
+ // If we haven't enabled Twitter posting on this node type, nothing to do here.
$type = $form['#node']->type;
- $allowed_types = variable_get('twitter_post_types', array('story' => 'story', 'blog' => 'blog'));
+ $allowed_types = variable_get('twitter_post_types', array());
if (empty($allowed_types[$type])) {
return;
}
module_load_include('inc', 'twitter');
-
$twitter_form = twitter_post_form();
if (!$twitter_form) {
return;
@@ -64,11 +61,11 @@ function twitter_post_form_alter(&$form, $form_state, $form_id) {
$form['twitter']['post'] = array(
'#type' => 'checkbox',
'#title' => t('Announce this post on Twitter'),
- '#default_value' => (empty($form['nid']['#value'])),
+ '#default_value' => variable_get('twitter_post_default_value', 0),
'#id' => 'twitter-toggle',
);
$form['twitter'] += $twitter_form;
- $form['twitter']['status']['#default_value'] = variable_get('twitter_post_default_format', 'New post: !title !tinyurl');
+ $form['twitter']['status']['#default_value'] = variable_get('twitter_post_default_format', 'New post: !title !url-alias');
$form['twitter']['status']['#description'] = t('The given text will be posted to twitter.com. You can use !url, !url-alias, !tinyurl, !title and !user as replacement text.');
$form['twitter']['status']['#maxlength'] = 150;
}
@@ -77,7 +74,7 @@ function twitter_post_form_alter(&$form, $form_state, $form_id) {
/**
* Implementation of hook_node_insert().
*
- * Intercepts newly published nodes and posts noticed to Twitter.
+ * Intercepts newly published nodes and posts notices to Twitter.
*/
function twitter_post_node_insert($node) {
if (!empty($node->status) && !empty($node->twitter) && !empty($node->twitter['post'])) {
@@ -98,14 +95,9 @@ function twitter_post_node_insert($node) {
}
$status = strtr($node->twitter['status'], $replacements);
- try {
- twitter_set_status($twitter_account, $status);
+ if (twitter_set_status($twitter_account, $status)) {
drupal_set_message(t('Successfully posted to Twitter'));
}
- catch (TwitterException $e) {
- drupal_set_message(t('An error occurred when posting to Twitter: @message',
- array('@message' => $e->getMessage())), 'warning');
- }
}
}
@@ -123,8 +115,6 @@ function twitter_post_node_update($node) {
* A Drupal user object.
*/
function twitter_post_form($account = NULL) {
- drupal_add_js(drupal_get_path('module', 'twitter_post') . '/twitter_post.js');
-
if (empty($account)) {
$account = user_load($GLOBALS['user']->uid);
}
@@ -133,8 +123,10 @@ function twitter_post_form($account = NULL) {
return;
}
+ drupal_add_js(drupal_get_path('module', 'twitter_post') . '/twitter_post.js');
$options = array();
- foreach ($account->twitter_accounts as $twitter_account) {
+ $twitter_accounts = twitter_load_authenticated_accounts();
+ foreach ($twitter_accounts as $twitter_account) {
$options[$twitter_account->id] = $twitter_account->screen_name;
}
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_post/twitter_post.pages.inc b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_post/twitter_post.pages.inc
index 5fe9b89..a0bf4cb 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_post/twitter_post.pages.inc
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_post/twitter_post.pages.inc
@@ -10,19 +10,28 @@
*/
function twitter_post_admin_settings($form, &$form_state) {
$form['twitter_post_types'] = array(
- '#type' => 'checkboxes',
'#title' => t('Node types'),
+ '#type' => 'checkboxes',
+ '#description' => t('Choose which node types should support posting to Twitter.'),
'#options' => node_type_get_names(),
- '#default_value' => variable_get('twitter_post_types', array('story' => 'story', 'blog' => 'blog')),
+ '#default_value' => variable_get('twitter_post_types', NULL),
);
$form['twitter_post_default_format'] = array(
'#type' => 'textfield',
'#title' => t('Default format string'),
'#maxlength' => 140,
- '#description' => t('The given text will be posted to twitter.com. You can use !url, !url-alias, !tinyurl, !title, and !user as replacement text.'),
+ '#description' => t('The given text will be used as a template for posting to Twitter.com. ' .
+ 'The following token replacements are available: !url, !url-alias, !tinyurl, !title, and !user'),
'#default_value' => variable_get('twitter_post_default_format', 'New post: !title !tinyurl'),
);
+ $form['twitter_post_default_value'] = array(
+ '#type' => 'checkbox',
+ '#description' => t('When active, tweets will be automatically published.'),
+ '#title' => t('Post to twitter by default'),
+ '#default_value' => variable_get('twitter_post_default_value', 0),
+ );
+
return system_settings_form($form);
}
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_signin/twitter_signin.info b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_signin/twitter_signin.info
index 1ff530c..af708de 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_signin/twitter_signin.info
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_signin/twitter_signin.info
@@ -2,12 +2,11 @@ name = Twitter Signin
description = Adds support for "Sign in with Twitter"
core = 7.x
dependencies[] = twitter
-dependencies[] = oauth_common
configure = admin/config/services/twitter/signin
-; Information added by drupal.org packaging script on 2012-08-11
-version = "7.x-3.2"
+; Information added by drupal.org packaging script on 2013-06-03
+version = "7.x-5.8"
core = "7.x"
project = "twitter"
-datestamp = "1344714197"
+datestamp = "1370303463"
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_signin/twitter_signin.module b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_signin/twitter_signin.module
index a4c1bc3..dfea8ef 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_signin/twitter_signin.module
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_signin/twitter_signin.module
@@ -1,4 +1,8 @@
<?php
+/**
+ * @file
+ * Hook implementations for Twitter Signin module.
+ */
/**
* Implements hook_menu().
@@ -38,7 +42,7 @@ function twitter_signin_block_info() {
function twitter_signin_block_view($delta) {
global $user;
- if (!$user->uid && _twitter_use_oauth()) {
+ if (!$user->uid) {
$block['subject'] = t('Sign in with Twitter');
$block['content'] = twitter_signin_button();
return $block;
@@ -74,13 +78,11 @@ function theme_twitter_signin_button() {
* Submit handler for Twitter signin.
*/
function twitter_signin_redirect() {
- module_load_include('lib.php', 'oauth');
- module_load_include('lib.php', 'twitter');
module_load_include('inc', 'twitter');
$key = variable_get('twitter_consumer_key', '');
$secret = variable_get('twitter_consumer_secret', '');
- $twitter = new TwitterOAuth($key, $secret);
+ $twitter = new Twitter($key, $secret);
$token = $twitter->get_request_token();
$_SESSION['twitter_oauth']['token'] = $token;
@@ -93,11 +95,6 @@ function twitter_signin_redirect() {
* Implements hook_form_alter().
*/
function twitter_signin_form_alter(&$form, $form_state, $form_id) {
- // This only applies if we've got OAuth / signin enabled.
- if (!_twitter_use_oauth()) {
- return;
- }
-
if ($form_id == 'twitter_oauth_callback_form' && isset($_SESSION['twitter_oauth']['signin'])) {
$form['#submit'] = array_merge(array('twitter_signin_oauth_callback_submit'), $form['#submit']);
}
@@ -124,7 +121,6 @@ function twitter_signin_form_alter(&$form, $form_state, $form_id) {
*/
function twitter_signin_oauth_callback_submit(&$form, &$form_state) {
global $user;
-
$success = FALSE;
$key = variable_get('twitter_consumer_key', '');
@@ -164,15 +160,20 @@ function twitter_signin_oauth_callback_submit(&$form, &$form_state) {
$user = $account;
$form_state['twitter_oauth']['account'] = $account;
drupal_set_message(t('You have been automatically registered with the password !password. ' .
- 'Copy it to <a href="!link">set your account settings</a>.', array(
+ 'Copy it to !link.', array(
'!password' => $password,
- '!link' => 'user/' . $account->uid . '/edit',
+ '!link' => l('set your account settings', 'user/' . $account->uid . '/edit'),
)
));
$success = TRUE;
}
else {
- drupal_set_message(t('The nickname %name is already in use on this site, please register below with a new nick name, or @login to continue.', array('%name' => $response['screen_name'], '@login' => url('user/login'))), 'warning');
+ drupal_set_message(t('The nickname %name is already in use on this site, please register below with a new nick name, or @login to continue.',
+ array(
+ '%name' => $response['screen_name'],
+ '@login' => url('user/login')
+ )
+ ), 'warning');
}
}
else {
@@ -182,7 +183,10 @@ function twitter_signin_oauth_callback_submit(&$form, &$form_state) {
if (!$success) {
$_SESSION['twitter']['values'] = $response;
- drupal_goto('user/register');
+ drupal_goto('user/login');
+ }
+ else {
+ user_login_finalize();
}
}
@@ -193,17 +197,17 @@ function twitter_signin_oauth_callback_submit(&$form, &$form_state) {
* signed in with Twitter but did not have an account in the site yet.
*/
function twitter_signin_user_insert(&$edit, $account, $category) {
- _twitter_signin_add_account($account);
+ _twitter_signin_add_account($edit, $account);
}
/**
- * Implements hook_user_insert().
- *
+ * Implements hook_user_login().
+ *
* Relates a Twitter account with an existing user account if the user
* signed in with Twitter.
*/
function twitter_signin_user_login(&$edit, $account) {
- _twitter_signin_add_account($account);
+ _twitter_signin_add_account($edit, $account);
}
/**
@@ -212,15 +216,14 @@ function twitter_signin_user_login(&$edit, $account) {
* @param $account
* The Drupal user account.
*/
-function _twitter_signin_add_account($account) {
+function _twitter_signin_add_account($edit, $account) {
if (isset($_SESSION['twitter']['values'])) {
- module_load_include('lib.php', 'twitter');
module_load_include('inc', 'twitter');
$key = variable_get('twitter_consumer_key', '');
$secret = variable_get('twitter_consumer_secret', '');
$response = $_SESSION['twitter']['values'];
- $twitter = new TwitterOAuth($key, $secret, $response['oauth_token'], $response['oauth_token_secret']);
+ $twitter = new Twitter($key, $secret, $response['oauth_token'], $response['oauth_token_secret']);
try {
$twitter_account = $twitter->users_show($response['screen_name']);
} catch (TwitterException $e) {
@@ -228,7 +231,8 @@ function _twitter_signin_add_account($account) {
return;
}
$twitter_account->set_auth($response);
- twitter_account_save($twitter_account, TRUE, $account);
+ $twitter_account->uid = $account->uid;
+ twitter_account_save($twitter_account, TRUE);
unset($_SESSION['twitter']);
drupal_set_message(t('You have related a Twitter account with your user. Next time you can sign in with Twitter.'));
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_signin/twitter_signin.pages.inc b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_signin/twitter_signin.pages.inc
index 19b3299..4f7963e 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_signin/twitter_signin.pages.inc
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_signin/twitter_signin.pages.inc
@@ -19,7 +19,7 @@ function twitter_signin_admin_settings($form, &$form_state) {
}
$form['twitter_signin_button'] = array(
- '#type' => 'radios',
+ '#type' => 'radios',
'#title' => t('Select sign-in button'),
'#options' => $options,
'#default_value' => variable_get('twitter_signin_button', 'Sign-in-with-Twitter-lighter-small.png'),
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_views_field_handlers.inc b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_views_field_handlers.inc
index ebd6de2..567dd37 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_views_field_handlers.inc
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/twitter/twitter_views_field_handlers.inc
@@ -14,6 +14,7 @@ class twitter_views_handler_field_xss extends views_handler_field {
$options['link_usernames'] = array('default' => TRUE);
$options['link_hashtags'] = array('default' => FALSE);
$options['hashtags_url'] = array('default' => variable_get('twitter_search', TWITTER_SEARCH) . '/search?q=%23');
+ $options['link_attributes'] = array('default' => TRUE);
return $options;
}
@@ -40,8 +41,16 @@ class twitter_views_handler_field_xss extends views_handler_field {
'#process' => array('ctools_dependent_process'),
'#dependency' => array('edit-options-link-hashtags' => array(TRUE)),
);
+ $form['link_attributes'] = array(
+ '#title' => t('Open links in new windows/tabs and add rel="nofollow" attributes.'),
+ '#type' => 'checkbox',
+ '#default_value' => !empty($this->options['link_attributes']),
+ );
}
+ /**
+ * Processes the message through the selected options.
+ */
function render($values) {
$value = $values->{$this->field_alias};
if (!empty($this->options['link_urls'])) {
@@ -51,11 +60,19 @@ class twitter_views_handler_field_xss extends views_handler_field {
);
$value = _filter_url($value, $filter);
}
+ // Link usernames with their profiles.
if (!empty($this->options['link_usernames'])) {
$value = _twitter_filter_text($value, '@', variable_get('twitter_host', TWITTER_HOST) . '/');
- } if (!empty($this->options['link_hashtags']) && valid_url($this->options['hashtags_url'])) {
+ }
+ // Link hashtags.
+ if (!empty($this->options['link_hashtags']) && valid_url($this->options['hashtags_url'])) {
$value = _twitter_filter_text($value, '#', url($this->options['hashtags_url']));
}
+ // Add extra attributes to links.
+ if (!empty($this->options['link_attributes'])) {
+ $value = _twitter_filter_link($value, NULL);
+ }
+ // Avoid XSS within the message.
return filter_xss($value);
}
}
@@ -69,3 +86,80 @@ class twitter_views_handler_field_profile_image extends views_handler_field {
return theme('image', array('path' => $value));
}
}
+
+/**
+ * Adds Twitter Intents links.
+ *
+ * @see https://dev.twitter.com/docs/intents
+ */
+class twitter_views_handler_field_web_intents extends views_handler_field {
+ /**
+ * Add twitter_id field, which is needed during rendering.
+ */
+ function construct() {
+ parent::construct();
+ $this->additional_fields['twitter_id'] = 'twitter_id';
+ }
+
+ function query() {
+ $this->ensure_my_table();
+ $this->add_additional_fields();
+ }
+
+ function render($values) {
+ drupal_add_js('//platform.twitter.com/widgets.js', 'external');
+ return '<span><a href="https://twitter.com/intent/tweet?in_reply_to=' . $values->twitter_id . '">Reply</a></span> ' .
+ '<span><a href="https://twitter.com/intent/retweet?tweet_id=' . $values->twitter_id . '">Retweet</a></span> ' .
+ '<span><a href="https://twitter.com/intent/favorite?tweet_id=' . $values->twitter_id . '">Favorite</a></span>';
+ }
+}
+
+/**
+ * Adds Twitter Follow link.
+ *
+ * @see https://dev.twitter.com/docs/intents#follow-intent
+ */
+class twitter_views_handler_field_follow extends views_handler_field {
+ function query() {}
+
+ function render($values) {
+ drupal_add_js('//platform.twitter.com/widgets.js', 'external');
+ return '<span><a href="https://twitter.com/intent/user?screen_name=' . $values->twitter_screen_name . '">Follow</a></span>';
+ }
+}
+
+/**
+ * Renders a tweet as it is presented at Twitter.com.
+ *
+ * @see https://dev.twitter.com/terms/display-requirements
+ */
+class twitter_views_handler_field_formatted_tweet extends views_handler_field {
+ function query() {}
+
+ function render($values) {
+ drupal_add_js('//platform.twitter.com/widgets.js', 'external');
+ drupal_add_css(drupal_get_path('module', 'twitter') . '/twitter.css');
+ module_load_include('inc', 'twitter');
+
+ // Load tweet and author.
+ $status = twitter_status_load($values->twitter_id);
+ $author = twitter_account_load($status->screen_name);
+
+ // Format the timestamp.
+ $time_diff = REQUEST_TIME - $values->twitter_created_time;
+
+ // Format the message.
+ $status->time_ago = t('%time ago', array('%time' => format_interval($time_diff, 2)));
+ $filter = new stdClass;
+ $filter->settings = array(
+ 'filter_url_length' => 496,
+ );
+ $status->text = _filter_url($status->text, $filter);
+
+ // Render the tweet.
+ return theme('twitter_status', array(
+ 'status' => $status,
+ 'author' => $author,
+ ));
+ }
+}