diff --git a/twitter.inc b/twitter.inc
index be7c391..c251eaa 100644
--- a/twitter.inc
+++ b/twitter.inc
@@ -11,7 +11,7 @@ function twitter_connect($account) {
module_load_include('lib.php', 'twitter');
$auth = $account->get_auth();
if (_twitter_use_oauth() && $auth['oauth_token'] && $auth['oauth_token_secret']) {
- module_load_include('lib.php', 'oauth');
+ 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']);
}
else if ($auth['password']) {
@@ -26,7 +26,7 @@ function twitter_connect($account) {
* Saves a TwitterUser object to {twitter_account}
*/
function twitter_account_save($twitter_user, $save_auth = FALSE, $account = NULL) {
- $values = (array)$twitter_user;
+ $values = (array) $twitter_user;
$values['twitter_uid'] = $values['id'];
if ($save_auth) {
@@ -37,7 +37,7 @@ function twitter_account_save($twitter_user, $save_auth = FALSE, $account = NULL
}
$values['uid'] = $account->uid;
}
- if (db_result(db_query("SELECT 1 FROM {twitter_account} WHERE twitter_uid = %d", $values['id']))) {
+ if (db_query("SELECT 1 FROM {twitter_account} WHERE twitter_uid = :twitter_uid", array(':twitter_uid' => $values['id']))->fetchField()) {
drupal_write_record('twitter_account', $values, array('twitter_uid'));
}
else {
@@ -45,17 +45,27 @@ function twitter_account_save($twitter_user, $save_auth = FALSE, $account = NULL
}
}
+/**
+ * Load a Twitter account from {twitter_account}.
+ *
+ * @param $id
+ * Twitter UID
+ *
+ * @return
+ * TwitterUser object
+ *
+ * @todo How well does this handle the Twitter UID not being in the
+ * DB?
+ */
function twitter_account_load($id) {
module_load_include('lib.php', 'twitter');
-
- $values = db_fetch_array(db_query("SELECT * FROM {twitter_account} WHERE twitter_uid = %d", $id));
+ $values = db_query("SELECT * FROM {twitter_account} WHERE twitter_uid = :twitter_uid", array(':twitter_uid' => $id))->fetchAssoc();
$values['id'] = $values['twitter_uid'];
$account = new TwitterUser($values);
$account->set_auth($values);
$account->uid = $values['uid'];
$account->import = $values['import'];
$account->is_global = $values['is_global'];
-
return $account;
}
@@ -66,14 +76,14 @@ function twitter_status_save($status) {
$status->twitter_id = $status->id;
$status->screen_name = $status->user->screen_name;
$status->created_time = strtotime($status->created_at);
-
- if (db_result(db_query("SELECT 1 FROM {twitter} WHERE twitter_id = %d", $status->id))) {
+
+ if (db_query("SELECT 1 FROM {twitter} WHERE twitter_id = :twitter_id", array(':twitter_id' => $status->id))->fetchField()) {
drupal_write_record('twitter', $status, array('twitter_id'));
}
else {
drupal_write_record('twitter', $status);
}
-
+
}
/**
@@ -92,8 +102,8 @@ function twitter_set_status($twitter_account, $status) {
function twitter_fetch_user_timeline($id) {
$account = twitter_account_load($id);
- $since = db_result(db_query("SELECT MAX(twitter_id) FROM {twitter} WHERE screen_name = '%s'", $account->screen_name));
-
+ $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);
$params = array();
@@ -109,16 +119,29 @@ function twitter_fetch_user_timeline($id) {
if (count($statuses) > 0) {
twitter_account_save($statuses[0]->user);
}
- db_query("UPDATE {twitter_account} SET last_refresh = %d WHERE twitter_uid=%d", time(), $account->id);
+
+ db_update('twitter_account')
+ ->fields(array(
+ 'last_refresh' => REQUEST_TIME,
+ ))
+ ->condition('twitter_uid', $account->id)
+ ->execute();
}
-function twitter_user_delete($twitter_uid, $screen_name = NULL) {
- $sql = "DELETE FROM {twitter_account} WHERE twitter_uid = %d";
- $args = array($twitter_uid);
+/**
+ * Delete a user from {twitter_account}.
+ *
+ * @param $twitter_uid
+ * An integer with the Twitter UID.
+ *
+ * @param $screen_name
+ * Optional string with the user name.
+ */
+function twitter_account_delete($twitter_uid, $screen_name = NULL) {
+ $query = db_delete('twitter_account');
+ $query->condition('twitter_uid', $twitter_uid);
if (!empty($screen_name)) {
- $sql .= " AND screen_name = '%s'";
- $args[] = $screen_name;
+ $query->condition('screen_name', $screen_name);
}
- db_query($sql, $args);
+ $query->execute();
}
-
diff --git a/twitter.info b/twitter.info
index fd613fa..bad2a9c 100644
--- a/twitter.info
+++ b/twitter.info
@@ -1,4 +1,7 @@
name = Twitter
description = Adds integration with the Twitter microblogging service.
php = 5.1
-core = 6.x
+core = 7.x
+files[] = twitter.lib.php
+files[] = twitter_views_field_handlers.inc
+configure = admin/config/services/twitter
diff --git a/twitter.install b/twitter.install
index 7700507..526957b 100644
--- a/twitter.install
+++ b/twitter.install
@@ -1,54 +1,60 @@
t("Stores individual Twitter posts."),
+ 'description' => "Stores individual Twitter posts.",
'fields' => array(
'twitter_id' => array(
- 'description' => t("Unique identifier for each {twitter} post."),
+ 'description' => "Unique identifier for each {twitter} post.",
'type' => 'numeric',
'unsigned' => TRUE,
'precision' => 20,
'scale' => 0,
'not null' => TRUE,
- 'default' => 0
+ 'default' => 0,
),
'screen_name' => array(
- 'description' => t("Screen Name of the {twitter_account} user."),
+ 'description' => "Screen Name of the {twitter_account} user.",
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
- 'default' => ''
+ 'default' => '',
),
'created_at' => array(
- 'description' => t("Date and time the {twitter} post was created."),
+ 'description' => "Date and time the {twitter} post was created.",
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
- 'default' => ''
+ 'default' => '',
),
'created_time' => array(
- 'description' => t("A duplicate of {twitter}.created_at in UNIX timestamp format."),
+ 'description' => "A duplicate of {twitter}.created_at in UNIX timestamp format.",
'type' => 'int',
- 'not null' => TRUE
+ 'not null' => TRUE,
),
'text' => array(
- 'description' => t("The text of the {twitter} post."),
+ 'description' => "The text of the {twitter} post.",
'type' => 'varchar',
'length' => 255,
- 'not null' => FALSE
+ 'not null' => FALSE,
),
'source' => array(
- 'description' => t("The application that created the {twitter} post."),
+ 'description' => "The application that created the {twitter} post.",
'type' => 'varchar',
'length' => 255,
- 'not null' => FALSE
+ 'not null' => FALSE,
),
'in_reply_to_status_id' => array(
- 'description' => t("Unique identifier of a status this {twitter} post was replying to."),
+ 'description' => "Unique identifier of a status this {twitter} post was replying to.",
'type' => 'numeric',
'unsigned' => TRUE,
'precision' => 20,
@@ -56,7 +62,7 @@ function twitter_schema() {
'not null' => FALSE,
),
'in_reply_to_user_id' => array(
- 'description' => t("Unique identifier for the {twitter_account} this post was replying to."),
+ 'description' => "Unique identifier for the {twitter_account} this post was replying to.",
'type' => 'numeric',
'unsigned' => TRUE,
'precision' => 20,
@@ -64,214 +70,215 @@ function twitter_schema() {
'not null' => FALSE,
),
'in_reply_to_screen_name' => array(
- 'description' => t("Screen name of the {twitter} user this post was replying to."),
+ 'description' => "Screen name of the {twitter} user this post was replying to.",
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
'truncated' => array(
- 'description' => t("Boolean flag indicating whether the {twitter} status was cut off to fit in the 140 character limit."),
+ 'description' => "Boolean flag indicating whether the {twitter} status was cut off to fit in the 140 character limit.",
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
- 'default' => 0
- ),
+ 'default' => 0,
+ ),
),
'indexes' => array('screen_name' => array('screen_name')),
'primary key' => array('twitter_id'),
);
$schema['twitter_account'] = array(
- 'description' => t("Stores information on specific Twitter user accounts."),
+ 'description' => "Stores information on specific Twitter user accounts.",
'fields' => array(
'twitter_uid' => array(
- 'description' => t("The unique identifier of the {twitter_account}."),
+ 'description' => "The unique identifier of the {twitter_account}.",
'type' => 'numeric',
'unsigned' => TRUE,
'precision' => 20,
- 'scale' => 0, 'not null' => TRUE,
- 'default' => 0
+ 'scale' => 0,
+ 'not null' => TRUE,
+ 'default' => 0,
),
'uid' => array(
- 'description' => t("The {users}.uid of the owner of this account"),
+ 'description' => "The {users}.uid of the owner of this account",
'type' => 'int',
'unsigned' => TRUE,
'size' => 'big',
'not null' => TRUE,
),
'host' => array(
- 'description' => t('The host for this account can be a laconi.ca instance'),
+ 'description' => 'The host for this account can be a laconi.ca instance',
'type' => 'varchar',
'length' => 255,
),
'screen_name' => array(
- 'description' => t("The unique login name of the {twitter_account} user."),
+ 'description' => "The unique login name of the {twitter_account} user.",
'type' => 'varchar',
- 'length' => 255
+ 'length' => 255,
),
'password' => array(
- 'description' => t("The password for the Twitter account."),
+ 'description' => "The password for the Twitter account.",
'type' => 'varchar',
- 'length' => 64
+ 'length' => 64,
),
'oauth_token' => array(
- 'description' => t('The token_key for oauth-based access.'),
+ 'description' => 'The token_key for oauth-based access.',
'type' => 'varchar',
'length' => 64,
),
'oauth_token_secret' => array(
- 'description' => t('The token_secret for oauth-based access.'),
+ 'description' => 'The token_secret for oauth-based access.',
'type' => 'varchar',
'length' => 64,
),
'name' => array(
- 'description' => t("The full name of the {twitter_account} user."),
+ 'description' => "The full name of the {twitter_account} user.",
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
- 'default' => ''
+ 'default' => '',
),
'description' => array(
- 'description' => t("The description/biography associated with the {twitter_account}."),
+ 'description' => "The description/biography associated with the {twitter_account}.",
'type' => 'varchar',
- 'length' => 255
+ 'length' => 255,
),
'location' => array(
- 'description' => t("The location of the {twitter_account}'s owner."),
+ 'description' => "The location of the {twitter_account}'s owner.",
'type' => 'varchar',
- 'length' => 255
+ 'length' => 255,
),
'followers_count' => array(
- 'description' => t("The number of users following this {twitter_account}."),
+ 'description' => "The number of users following this {twitter_account}.",
'type' => 'int',
'not null' => TRUE,
- 'default' => 0
+ 'default' => 0,
),
'friends_count' => array(
- 'description' => t("The number of users this {twitter_account} is following."),
+ 'description' => "The number of users this {twitter_account} is following.",
'type' => 'int',
'not null' => TRUE,
- 'default' => 0
- ),
+ 'default' => 0,
+ ),
'statuses_count' => array(
- 'description' => t("The total number of status updates performed by a user, excluding direct messages sent."),
+ 'description' => "The total number of status updates performed by a user, excluding direct messages sent.",
'type' => 'int',
'not null' => TRUE,
- 'default' => 0
- ),
+ 'default' => 0,
+ ),
'favourites_count' => array(
- 'description' => t("The number of statuses a user has marked as favorite."),
+ 'description' => "The number of statuses a user has marked as favorite.",
'type' => 'int',
'not null' => TRUE,
- 'default' => 0
- ),
+ 'default' => 0,
+ ),
'url' => array(
- 'description' => t("The url of the {twitter_account}'s home page."),
+ 'description' => "The url of the {twitter_account}'s home page.",
'type' => 'varchar',
- 'length' => 255
+ 'length' => 255,
),
'profile_image_url' => array(
- 'description' => t("The url of the {twitter_account}'s profile image."),
+ 'description' => "The url of the {twitter_account}'s profile image.",
'type' => 'varchar',
- 'length' => 255
+ 'length' => 255,
),
'protected' => array(
- 'description' => t("Boolean flag indicating whether the {twitter_account}'s posts are publicly accessible."),
+ 'description' => "Boolean flag indicating whether the {twitter_account}'s posts are publicly accessible.",
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
- 'default' => 0
+ 'default' => 0,
),
'profile_background_color' => array(
- 'description' => t("hex RGB value for a user's background color"),
+ 'description' => "hex RGB value for a user's background color",
'type' => 'varchar',
'length' => 6,
'not null' => TRUE,
'default' => '',
),
'profile_text_color' => array(
- 'description' => t("hex RGB value for a user's text color"),
+ 'description' => "hex RGB value for a user's text color",
'type' => 'varchar',
'length' => 6,
'not null' => TRUE,
'default' => '',
),
'profile_link_color' => array(
- 'description' => t("hex RGB value for a user's link color"),
+ 'description' => "hex RGB value for a user's link color",
'type' => 'varchar',
'length' => 6,
'not null' => TRUE,
'default' => '',
),
'profile_sidebar_fill_color' => array(
- 'description' => t("hex RGB value for a user's sidebar color"),
+ 'description' => "hex RGB value for a user's sidebar color",
'type' => 'varchar',
'length' => 6,
'not null' => TRUE,
'default' => '',
),
'profile_sidebar_border_color' => array(
- 'description' => t("hex RGB value for a user's border color"),
+ 'description' => "hex RGB value for a user's border color",
'type' => 'varchar',
'length' => 6,
'not null' => TRUE,
'default' => '',
),
'profile_background_image_url' => array(
- 'description' => t("The url of the {twitter_account}'s profile image."),
+ 'description' => "The url of the {twitter_account}'s profile image.",
'type' => 'varchar',
- 'length' => 255
+ 'length' => 255,
),
'profile_background_tile' => array(
- 'description' => t("Boolean indicating if a user's background is tiled."),
+ 'description' => "Boolean indicating if a user's background is tiled.",
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
- 'default' => 1
+ 'default' => 1,
),
'verified' => array(
- 'description' => t("Indicates if a user is verified."),
+ 'description' => "Indicates if a user is verified.",
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
- 'default' => 1
+ 'default' => 1,
),
'created_at' => array(
- 'description' => t("Date and time the {twitter_account} was created."),
+ 'description' => "Date and time the {twitter_account} was created.",
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
- 'default' => ''
+ 'default' => '',
),
'created_time' => array(
- 'description' => t("A duplicate of {twitter_account}.created_at in UNIX timestamp format."),
+ 'description' => "A duplicate of {twitter_account}.created_at in UNIX timestamp format.",
'type' => 'int',
- 'not null' => TRUE
+ 'not null' => TRUE,
),
'utc_offset' => array(
- 'description' => t("A duplicate of {twitter_account}.created_at in UNIX timestamp format."),
+ 'description' => "A duplicate of {twitter_account}.created_at in UNIX timestamp format.",
'type' => 'int',
- 'not null' => TRUE
+ 'not null' => TRUE,
),
'import' => array(
- 'description' => t("Boolean flag indicating whether the {twitter_user}'s posts should be pulled in by the site."),
+ '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' => 1
+ 'default' => 1,
),
'last_refresh' => array(
- 'description' => t("A UNIX timestamp marking the date Twitter statuses were last fetched on."),
+ 'description' => "A UNIX timestamp marking the date Twitter statuses were last fetched on.",
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'is_global' => array(
- 'description' => t("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
+ 'default' => 0,
),
),
'indexes' => array('screen_name' => array('screen_name')),
@@ -282,413 +289,22 @@ function twitter_schema() {
}
/**
- * Implementation of hook_install().
+ * Implements hook_install().
*/
function twitter_install() {
- // Create tables.
- drupal_install_schema('twitter');
-
- // Set the weight to 3, making it heaving than Pathauto.
- db_query("UPDATE {system} SET weight = 3 WHERE name = 'twitter'");
-}
-
-/**
- * Previous versions of the Twitter module had no database schema.
- * We're safe just running the basic install for update_1.
- */
-function twitter_update_6000() {
- twitter_install();
-}
-
-/**
- * Adding a handful of additional flags on accounts, and saving more metadata
- * when Twitter sends it to us.
- */
-function twitter_update_6001() {
- $ret = array();
- $attributes = array(
- 'description' => t("Boolean flag indicating whether the {twitter_user}'s posts should be pulled in by the site."),
- 'unsigned' => TRUE,
- 'default' => 1,
- 'not null' => TRUE,
- );
- db_add_column($ret, 'twitter_user', 'import', 'int', $attributes);
-
- $attributes = array(
- 'description' => t("The location of the {twitter_account}'s owner."),
- 'length' => 255
- );
- db_add_column($ret, 'twitter_account', 'location', 'varchar(255)', $attributes);
-
- $attributes = array(
- 'description' => t("The number of users following this {twitter_account}."),
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0
- );
- db_add_column($ret, 'twitter_account', 'followers_count', 'int', $attributes);
-
- return $ret;
-}
-
-/**
- * Set the weight a little heavier to allow Pathauto and other modules to do
- * their work on the title, path alias, etc. before the twitter post is sent.
- */
-function twitter_update_6002() {
- $ret = array();
- $ret[] = update_sql("UPDATE {system} SET weight = 3 WHERE name = 'twitter'");
- return $ret;
+ // Set the weight to 3, making it heavier than Pathauto.
+ db_update('system')
+ ->fields(array(
+ 'weight' => 3,
+ ))
+ ->condition('type', 'module')
+ ->condition('name', 'twitter')
+ ->execute();
}
/**
- * Twitter status IDs are hitting the rollover point for signed ints. Let's
- * be sure we're ready. See http://bit.ly/kokvi for details.
+ * Implements hook_update_last_removed().
*/
-function twitter_update_6003() {
- $ret = array();
- db_drop_primary_key($ret, 'twitter');
-
- db_change_field($ret, 'twitter', 'twitter_id', 'twitter_id',
- array('description' => t("Unique identifier for each {twitter} post."),
- 'type' => 'int', 'size' => 'big', 'unsigned' => 'true', 'not null' => TRUE),
- array('primary key' => array('twitter_id')));
-
- return $ret;
-}
-
-/**
- * Add NOT NULL constraint and DEFAULT value to the screen_name field of the
- * twitter and twitter_user tables per updated schema definition.
- *
- * See http://drupal.org/node/336048 and http://drupal.org/node/430442
- */
-function twitter_update_6004() {
- $ret = array();
- // Have to drop PRIMARY KEY and indexes that use the field being changed.
- // twitter
- db_drop_index($ret, 'twitter', 'screen_name');
- db_change_field($ret, 'twitter', 'screen_name', 'screen_name', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), array('indexes' => array('screen_name' => array('screen_name'))));
-
- // twitter_user
- db_drop_index($ret, 'twitter_user', 'screen_name');
- db_drop_primary_key($ret, 'twitter_user');
- db_change_field($ret, 'twitter_user', 'screen_name', 'screen_name', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), array('primary key' => array('uid', 'screen_name'), 'indexes' => array('screen_name' => array('screen_name'))));
- return $ret;
-}
-
-
-/**
- * Dear PHP, I hate you so bad. Love, Jeff.
- *
- * Workaround for drupal_write_record(), which treats a DB bigint as a signed 32
- * bit int on 32 bit PHP builds. We can STORE bigints, and PHP automatically
- * converts them to floats in memory while we work with them, but db_placeholders()
- * always treats them as %d and casts them back to dumb signed ints.
- *
- * See http://drupal.org/node/333788 for more info.
- *
- * Instead we'll set the column type to 'string' which is a little like jumping
- * off the Sears Tower because the elevator's broken. But that's life.
- */
-function twitter_update_6005() {
- $ret = array();
-
- // First clear out any borked statuses.
- $ret[] = update_sql("DELETE FROM {twitter} WHERE twitter_id = 2147483647");
-
- db_drop_primary_key($ret, 'twitter');
-
- db_change_field($ret, 'twitter', 'twitter_id', 'twitter_id',
- array('description' => t("Unique identifier for each {twitter} post."),
- 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
- array('primary key' => array('twitter_id')));
-
- return $ret;
-}
-
-/**
- * Dear PHP, I'm sorry baby. I know I said a lotta things last night, but I was
- * angry. I didn't mean it, you know that. I'll use numbers from now on -- no!
- * No, I'll use *decimals*. You'll like that, won't you, PHP? We're cool, right?
- *
- * Yeah. Yeah, we're cool.
- *
- * Also, while we're at it we'll add support for some of the additional Twitter
- * API data for replies, and convert the twitter_uid field to a numeric type, too.
- */
-function twitter_update_6006() {
- $ret = array();
-
- db_drop_primary_key($ret, 'twitter');
-
- db_change_field($ret, 'twitter', 'twitter_id', 'twitter_id',
- array(
- 'description' => t("Unique identifier for each {twitter} post."),
- 'type' => 'numeric',
- 'unsigned' => TRUE,
- 'precision' => 20,
- 'scale' => 0,
- 'not null' => TRUE,
- 'default' => 0
- ),
- array('primary key' => array('twitter_id'))
- );
-
- db_add_field($ret, 'twitter', 'in_reply_to_status_id',
- array(
- 'description' => t("Unique identifier of a status this {twitter} post was replying to."),
- 'type' => 'numeric',
- 'precision' => 20,
- 'scale' => 0,
- 'unsigned' => TRUE,
- 'not null' => FALSE,
- )
- );
-
- db_add_field($ret, 'twitter', 'in_reply_to_user_id',
- array(
- 'description' => t("Unique identifier for the {twitter_account} this post was replying to."),
- 'type' => 'numeric',
- 'precision' => 20,
- 'scale' => 0,
- 'unsigned' => TRUE,
- 'not null' => FALSE,
- )
- );
-
- db_add_field($ret, 'twitter', 'in_reply_to_screen_name',
- array(
- 'description' => t("Screen name of the {twitter} user this post was replying to."),
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => FALSE,
- )
- );
-
- db_add_field($ret, 'twitter', 'truncated',
- array(
- 'description' => t("Boolean flag indicating whether the {twitter} status was cut off to fit in the 140 character limit."),
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- )
- );
-
- db_drop_primary_key($ret, 'twitter_account');
-
- db_change_field($ret, 'twitter_account', 'twitter_uid', 'twitter_uid',
- array(
- 'description' => t("The unique identifier of the {twitter_account}."),
- 'type' => 'numeric',
- 'unsigned' => TRUE,
- 'precision' => 20,
- 'scale' => 0,
- 'not null' => TRUE,
- 'default' => 0
- ),
- array('primary key' => array('twitter_uid'))
- );
-
-
- return $ret;
-}
-
-/*
- * Update the last_refresh column to supply a default value. http://drupal.org/node/301317
- */
-function twitter_update_6007() {
- $ret = array();
- db_change_field($ret, 'twitter_account', 'last_refresh', 'last_refresh',
- array(
- 'description' => t("A UNIX timestamp marking the date Twitter statuses were last fetched on."),
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- )
- );
- return $ret;
-}
-
-/**
- * Update from 2.x to 3.x
- */
-function twitter_update_6300() {
- $ret = array();
-
- // add additional fields to {twitter_account}
- db_add_field($ret, 'twitter_account', 'uid',
- array(
- 'description' => t("The {users}.uid of the owner of this account"),
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'size' => 'big',
- 'not null' => TRUE,
- ));
-
- db_add_field($ret, 'twitter_account', 'host',
- array(
- 'description' => t('The host for this account can be a laconi.ca instance'),
- 'type' => 'varchar',
- 'length' => 255,
- ));
- db_add_field($ret, 'twitter_account', 'password',
- array(
- 'description' => t("The password for the Twitter account."),
- 'type' => 'varchar',
- 'length' => 64
- ));
- db_add_field($ret, 'twitter_account', 'oauth_token',
- array(
- 'description' => t('The token_key for oauth-based access.'),
- 'type' => 'varchar',
- 'length' => 64,
- ));
- db_add_field($ret, 'twitter_account', 'oauth_token_secret',
- array(
- 'description' => t('The token_secret for oauth-based access.'),
- 'type' => 'varchar',
- 'length' => 64,
- ));
- db_add_field($ret, 'twitter_account', 'friends_count',
- array(
- 'description' => t("The number of users this {twitter_account} is following."),
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0
- ));
- db_add_field($ret, 'twitter_account', 'statuses_count',
- array(
- 'description' => t("The total number of status updates performed by a user, excluding direct messages sent."),
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0
- ));
- db_add_field($ret, 'twitter_account', 'favourites_count',
- array(
- 'description' => t("The number of statuses a user has marked as favorite."),
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0
- ));
- db_add_field($ret, 'twitter_account', 'profile_background_color',
- array(
- 'description' => t("hex RGB value for a user's background color"),
- 'type' => 'varchar',
- 'length' => 6,
- 'not null' => TRUE,
- 'default' => '',
- ));
- db_add_field($ret, 'twitter_account', 'profile_text_color',
- array(
- 'description' => t("hex RGB value for a user's text color"),
- 'type' => 'varchar',
- 'length' => 6,
- 'not null' => TRUE,
- 'default' => '',
- ));
- db_add_field($ret, 'twitter_account', 'profile_link_color',
- array(
- 'description' => t("hex RGB value for a user's link color"),
- 'type' => 'varchar',
- 'length' => 6,
- 'not null' => TRUE,
- 'default' => '',
- ));
- db_add_field($ret, 'twitter_account', 'profile_sidebar_fill_color',
- array(
- 'description' => t("hex RGB value for a user's sidebar color"),
- 'type' => 'varchar',
- 'length' => 6,
- 'not null' => TRUE,
- 'default' => '',
- ));
- db_add_field($ret, 'twitter_account', 'profile_sidebar_border_color',
- array(
- 'description' => t("hex RGB value for a user's border color"),
- 'type' => 'varchar',
- 'length' => 6,
- 'not null' => TRUE,
- 'default' => '',
- ));
- db_add_field($ret, 'twitter_account', 'profile_background_image_url',
- array(
- 'description' => t("The url of the {twitter_account}'s profile image."),
- 'type' => 'varchar',
- 'length' => 255
- ));
- db_add_field($ret, 'twitter_account', 'profile_background_tile',
- array(
- 'description' => t("Boolean indicating if a user's background is tiled."),
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 1
- ));
- db_add_field($ret, 'twitter_account', 'verified',
- array(
- 'description' => t("Indicates if a user is verified."),
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 1
- ));
- db_add_field($ret, 'twitter_account', 'created_at',
- array(
- 'description' => t("Date and time the {twitter_account} was created."),
- 'type' => 'varchar',
- 'length' => 64,
- 'not null' => TRUE,
- 'default' => ''
- ));
- db_add_field($ret, 'twitter_account', 'created_time',
- array(
- 'description' => t("A duplicate of {twitter_account}.created_at in UNIX timestamp format."),
- 'type' => 'int',
- 'not null' => TRUE
- ));
- db_add_field($ret, 'twitter_account', 'utc_offset',
- array(
- 'description' => t("A duplicate of {twitter_account}.created_at in UNIX timestamp format."),
- 'type' => 'int',
- 'not null' => TRUE
- ));
- db_add_field($ret, 'twitter_account', 'import',
- array(
- 'description' => t("Boolean flag indicating whether the {twitter_user}'s posts should be pulled in by the site."),
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 1
- ));
- db_add_field($ret, 'twitter_account', 'is_global',
- array(
- 'description' => t("Boolean flag indicating if this account is available for global use"),
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0
- ));
-
-
- if (db_table_exists('twitter_user')) {
- $result = db_query("SELECT * FROM {twitter_user} ORDER BY uid DESC");
- while ($row = db_fetch_array($result)) {
- db_query("UPDATE {twitter_account} SET uid=%d, password='%s', import=%d WHERE screen_name='%s'",
- $row['uid'], $row['password'], $row['import'], $row['screen_name']);
- }
-
- db_drop_table($ret, 'twitter_user');
- }
-
- drupal_install_modules(array('twitter_post'));
-
- return $ret;
-}
-
-
-function twitter_uninstall() {
- // Remove tables.
- drupal_uninstall_schema('twitter');
+function twitter_update_last_removed() {
+ return 6005;
}
diff --git a/twitter.lib.php b/twitter.lib.php
index 853391b..a20bf12 100644
--- a/twitter.lib.php
+++ b/twitter.lib.php
@@ -237,7 +237,7 @@ class Twitter {
}
$response = drupal_http_request($url, $headers, $method, $data);
- if (!$response->error) {
+ if (!isset($response->error)) {
return $response->data;
}
else {
@@ -257,7 +257,15 @@ class Twitter {
switch ($format) {
case 'json':
- return json_decode($response, TRUE);
+ if (version_compare(PHP_VERSION, '5.3.0', '<')) {
+ // in_reply_to_id ?
+ // ALL integers?
+ $response = preg_replace('/"id":([0-9]*)/', '"id":"\1"', $response);
+ return json_decode($response, TRUE);
+ }
+ else {
+ return json_decode($response, TRUE, 512, JSON_BIGINT_AS_STRING);
+ }
}
}
@@ -483,7 +491,7 @@ class TwitterUser {
}
$this->utc_offset = $values['utc_offset'];
- if ($values['status']) {
+ if (isset($values['status'])) {
$this->status = new TwitterStatus($values['status']);
}
}
@@ -493,7 +501,9 @@ class TwitterUser {
}
public function set_auth($values) {
- $this->password = $values['password'];
+ if ( isset($values['password']) ) {
+ $this->password = $values['password'];
+ }
$this->oauth_token = $values['oauth_token'];
$this->oauth_token_secret = $values['oauth_token_secret'];
}
diff --git a/twitter.module b/twitter.module
index e9d5ae7..3d2193b 100644
--- a/twitter.module
+++ b/twitter.module
@@ -1,11 +1,9 @@
'Twitter',
'access callback' => TRUE,
@@ -14,72 +12,69 @@ function twitter_menu() {
'type' => MENU_CALLBACK,
'file' => 'twitter.pages.inc',
);
-
- $items['admin/settings/twitter'] = array(
- 'title' => 'Twitter setup',
- 'description' => 'Twitter module settings',
+
+ $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'),
- 'file' => 'twitter.pages.inc'
+ 'file' => 'twitter.pages.inc',
);
-
- $items['admin/settings/twitter/default'] = array(
+ $items['admin/config/services/twitter/default'] = array(
'title' => 'Twitter',
- 'type' => MENU_DEFAULT_LOCAL_TASK
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
);
- $items['user/%user_category/edit/twitter'] = array(
+ $items['user/%user/edit/twitter'] = array(
'title' => 'Twitter accounts',
'page callback' => 'twitter_user_settings',
'page arguments' => array(1),
'access arguments' => array('add twitter accounts'),
- 'load arguments' => array('%map', '%index'),
'weight' => 10,
'file' => 'twitter.pages.inc',
'type' => MENU_LOCAL_TASK,
);
-
$items['user/%user/edit/twitter/global/%'] = 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'),
'file' => 'twitter.pages.inc',
- 'type' => MENU_CALLBACK,
);
-
+
return $items;
}
/**
- * Implementation of hook_perm()
+ * Implements hook_permission().
*/
-function twitter_perm() {
- return array('add twitter accounts', 'use global twitter account', 'make twitter accounts global', 'import own tweets');
+function twitter_permission() {
+ return array(
+ 'add twitter accounts' => array(
+ 'title' => t('Add Twitter accounts'),
+ ),
+ 'use global twitter account' => array(
+ 'title' => t('Use global Twitter account'),
+ 'description' => t('Use the site global Twitter account.'),
+ ),
+ '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.'),
+ ),
+ );
}
/**
- * Implementation of hook_user().
+ * Implements hook_theme().
*/
-function twitter_user($op, &$edit, &$account, $category = NULL) {
- switch ($op) {
- case 'categories':
- return array(
- array(
- 'name' => 'twitter',
- 'title' => 'Twitter accounts',
- 'weight' => 3,
- ),
- );
- }
-}
-
function twitter_theme() {
return array(
'twitter_account_list_form' => array(
- 'arguments' => array('form' => NULL),
- )
+ 'render element' => 'form',
+ ),
);
}
@@ -102,7 +97,7 @@ function twitter_shorten_url($url) {
}
/**
- * Implementation of hook_cron()
+ * Implements hook_cron().
*
* Imports new Twitter statuses for site users, and deletes expired tweets.
*/
@@ -116,74 +111,54 @@ function twitter_cron() {
// 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.
-
- $sql = "SELECT twitter_uid FROM {twitter_account} WHERE import = 1 ORDER BY last_refresh ASC";
-
- $results = db_query_range($sql, 0, 20);
- while ($account = db_fetch_object($results)) {
+ $result = db_query_range("SELECT twitter_uid FROM {twitter_account} WHERE import = :import ORDER BY last_refresh ASC", 0, 20, array(':import' => 1));
+ foreach ($result as $account) {
twitter_fetch_user_timeline($account->twitter_uid);
}
// Nuke old statuses.
if ($age = variable_get('twitter_expire', 0)) {
- db_query('DELETE FROM {twitter} WHERE created_time < %d', time() - $age);
+ db_delete('twitter')
+ ->condition('created_time', REQUEST_TIME - $age, '<')
+ ->execute();
}
}
+/**
+ * Implements hook_filter_info().
+ */
+function twitter_filter_info() {
+ $filters['twitter_username'] = array(
+ 'title' => t('Twitter @username converter'),
+ 'description' => t('Converts Twitter-style @usernames into links to Twitter account pages.'),
+ 'process callback' => 'twitter_link_filter',
+ 'tips callback' => 'twitter_filter_tip_username',
+ );
+ $filters['twitter_hashtag'] = array(
+ 'title' => t('Twitter #hashtag converter'),
+ 'description' => t('Converts Twitter-style #hashtags into links to hashtags.org.'),
+ 'process callback' => 'twitter_link_filter',
+ 'tips callback' => 'twitter_filter_tip_hashtag',
+ );
+ return $filters;
+}
/**
- * Implementation of hook_filter().
- * - Twitter @username converter:
- * .Converts Twitter-style @usernames into links to Twitter account pages.
- * - Twitter #hashtag converter:
- * .Converts Twitter-style #hashtags into links to hashtags.org.
+ * Filter tips callback function for $filters[0] in hook_filter_info().
*/
-function twitter_filter($op, $delta = 0, $format = -1, $text = '') {
- switch ($op) {
- case 'list':
- return array(0 => t('Twitter @username converter'), 1 => t('Twitter #hashtag converter'));
-
- case 'description':
- switch ($delta) {
- case 0:
- return t('Converts Twitter-style @usernames into links to Twitter account pages.');
- case 1:
- return t('Converts Twitter-style #hashtags into links to hashtags.org.');
- default:
- return;
- }
-
- case 'process':
- switch ($delta) {
- case 0:
- return twitter_link_filter($text);
- case 1:
- return twitter_link_filter($text, '#', 'http://search.twitter.com/search?q=%23');
- default:
- return $text;
- }
-
- default:
- return $text;
- }
+function twitter_filter_tip_username($format, $long = FALSE) {
+ return t('Twitter-style @usernames are linked to their Twitter account pages.');
}
/**
- * Implementation of hook_filter_tips().
+ * Filter tips callback function for $filters[1] in hook_filter_info().
*/
-function twitter_filter_tips($delta, $format, $long = FALSE) {
- global $base_url;
- switch ($delta) {
- case 0:
- return t('Twitter-style @usersnames are linked to their Twitter account pages.');
-
- case 1:
- return t('Twitter-style #hashtags are linked to !url.', array('!url' => 'search.twitter.com'));
- }
+function twitter_filter_tip_hashtag($format, $long = FALSE) {
+ return t('Twitter-style #hashtags are linked to !url.', array('!url' => 'search.twitter.com'));
}
/**
- * This helper function converts Twitter-style @usernames and #hashtags into
+ * This helper function converts Twitter-style @usernames and #hashtags into
* actual links.
*/
function twitter_link_filter($text, $prefix = '@', $destination = 'http://twitter.com/') {
@@ -197,20 +172,18 @@ function twitter_link_filter($text, $prefix = '@', $destination = 'http://twitte
'' . $prefix . '${1}',
'${1}' . $prefix . '${2}',
);
- return preg_replace($matches, $replacements, $text);
+ return preg_replace($matches, $replacements, $text);
}
/**
- * Get a list of twitter accounts available to the current user.
- *
- * @return Array containing TwitterAccount objects
+ * Implements hook_user_load().
*/
-function twitter_get_user_accounts($uid) {
- $drupal_user = user_load($uid);
- return module_invoke_all('twitter_accounts', $drupal_user);
+function twitter_user_load($accounts) {
+ foreach ($accounts as $uid => $account) {
+ $accounts[$uid]->twitter_accounts = module_invoke_all('twitter_accounts', $account);
+ }
}
-
/**
* 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
@@ -219,33 +192,40 @@ function twitter_get_user_accounts($uid) {
*/
function twitter_twitter_accounts($account) {
module_load_include('inc', 'twitter');
-
+
$twitter_accounts = array();
-
- $sql = "SELECT twitter_uid FROM {twitter_account} WHERE uid = %d";
+
+ $query = db_select('twitter_account', 'ta');
+ $query->addField('ta', 'twitter_uid');
+ $query->condition('ta.uid', $account->uid);
if (user_access('use global twitter account')) {
- $sql.= " OR is_global=1";
+ $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);
}
- $results = db_query($sql, $account->uid);
- while ($row = db_fetch_array($results)) {
- $key = $row['twitter_uid'];
- $twitter_accounts[] = twitter_account_load($key);
+ $twitter_uids = $query->execute()->fetchCol();
+ foreach ($twitter_uids as $twitter_uid) {
+ $key = $row->twitter_uid;
+ $twitter_accounts[] = twitter_account_load($twitter_uid);
}
+
return $twitter_accounts;
}
+/**
+ * Detect whether we should use oauth. This can probably just go now :)
+ */
function _twitter_use_oauth() {
- if (!module_exists('oauth')) {
- return FALSE;
- }
-
- return (variable_get('twitter_consumer_key', '') && variable_get('twitter_consumer_secret', ''));
+ return module_exists('oauth_common') && variable_get('twitter_consumer_key', '') && variable_get('twitter_consumer_secret', '');
}
/**
- * Implementation of hook_views_api.
- * Notifies the Views module that we're compatible with a particular API revision.
+ * Implements hook_views_api().
*/
function twitter_views_api() {
return array('api' => 2);
diff --git a/twitter.pages.inc b/twitter.pages.inc
index 91a1731..497c4d9 100644
--- a/twitter.pages.inc
+++ b/twitter.pages.inc
@@ -1,78 +1,72 @@
'checkbox',
+ '#title' => t('Import and display the Twitter statuses of site users who have entered their Twitter account information.'),
+ '#default_value' => variable_get('twitter_import', 1),
+ );
+ $form['twitter_expire'] = array(
+ '#type' => 'select',
+ '#title' => t('Delete old statuses'),
+ '#default_value' => variable_get('twitter_expire', 0),
+ '#options' => array(0 => t('Never')) + drupal_map_assoc(array(604800, 2592000, 7776000, 31536000), 'format_interval'),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name=twitter_import]' => array('checked' => TRUE),
+ ),
+ ),
+ );
$form['oauth'] = array(
'#type' => 'fieldset',
'#title' => t('OAuth Settings'),
- '#description' => t(''),
- '#access' => module_exists('oauth'),
- '#description' => t('To enable OAuth based access for twitter, you must register your application with twitter and add the provided keys here.', array('@url' => 'https://twitter.com/apps/new')),
+ '#access' => module_exists('oauth_common'),
+ '#description' => t('To enable OAuth based access for twitter, you must register your application with Twitter and add the provided keys here.', array('@url' => 'https://twitter.com/apps/new')),
);
-
$form['oauth']['callback_url'] = array(
'#type' => 'item',
'#title' => t('Callback URL'),
- '#value' => url('twitter/oauth', array('absolute' => TRUE)),
+ '#markup' => url('twitter/oauth', array('absolute' => TRUE)),
);
-
$form['oauth']['twitter_consumer_key'] = array(
'#type' => 'textfield',
'#title' => t('OAuth Consumer key'),
'#default_value' => variable_get('twitter_consumer_key', NULL),
);
-
$form['oauth']['twitter_consumer_secret'] = array(
'#type' => 'textfield',
'#title' => t('OAuth Consumer secret'),
'#default_value' => variable_get('twitter_consumer_secret', NULL),
);
- $form['import'] = array(
- '#type' => 'fieldset',
- '#title' => t('Twitter import'),
- '#description' => t('Import and display the Twitter statuses of site users who have entered their Twitter account information.'),
- );
-
- $form['import']['twitter_import'] = array(
- '#type' => 'checkbox',
- '#title' => t('Import Twitter statuses'),
- '#default_value' => variable_get('twitter_import', TRUE),
- );
-
- $periods = array(0 => t('Never'));
- $periods += drupal_map_assoc(array(604800, 2419200, 7257600, 31449600), 'format_interval');
- $form['import']['twitter_expire'] = array(
- '#type' => 'select',
- '#title' => t('Delete old statuses'),
- '#default_value' => variable_get('twitter_expire', 0),
- '#options' => $periods
- );
-
return system_settings_form($form);
}
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
function twitter_user_settings($account) {
module_load_include('inc', 'twitter');
- $output = '';
- // This is directly calling a hook implementation, which is bad and naughty,
- // but oh well. We'll fix this in the next reshuffling when user account
- // management gets an overhaul.
- $twitter_accounts = twitter_twitter_accounts($account);
- if (!empty($twitter_accounts)) {
- $output .= drupal_get_form('twitter_account_list_form', $twitter_accounts);
+ $output = array();
+ if (!empty($account->twitter_accounts)) {
+ $output['list_form'] = drupal_get_form('twitter_account_list_form', $account->twitter_accounts);
}
- $output .= drupal_get_form('twitter_account_form', $account);
+ $output['form'] = drupal_get_form('twitter_account_form', $account);
return $output;
}
-function twitter_account_list_form($form_state, $twitter_accounts = array()) {
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
+function twitter_account_list_form($form, $form_state, $twitter_accounts = array()) {
$form['#tree'] = TRUE;
$form['accounts'] = array();
@@ -109,33 +103,31 @@ function _twitter_account_list_row($account) {
);
$form['image'] = array(
- '#type' => 'markup',
- '#value' => theme('image', $account->profile_image_url, '', '', array(), FALSE),
+ '#markup' => theme('image', array('path' => $account->profile_image_url)),
);
$form['visible_name'] = array(
- '#type' => 'markup',
- '#value' => l($account->screen_name, 'http://www.twitter.com/' . $account->screen_name),
+ '#markup' => l($account->screen_name, 'http://www.twitter.com/' . $account->screen_name),
);
$form['description'] = array(
- '#type' => 'markup',
- '#value' => filter_xss($account->description),
+ '#markup' => filter_xss($account->description),
);
$form['protected'] = array(
- '#type' => 'markup',
- '#value' => empty($account->protected) ? t('No') : t('Yes'),
+ '#markup' => empty($account->protected) ? t('No') : t('Yes'),
);
- if (user_access('import own tweets')){ // Here we use user_access('import own tweets') to check permission instead of user_access('import own tweets', $account->uid) is because we allow roles with sufficient permission to overwrite the user's import settings.
+ // Here we use user_access('import own tweets') to check permission instead
+ // of user_access('import own tweets', $account) is because we allow roles
+ // with sufficient permission to overwrite the user's import settings.
+ if (user_access('import own tweets')) {
$form['import'] = array(
- '#type' => 'checkbox',
- '#default_value' => user_access('import own tweets') ? $account->import : '',
+ '#type' => 'checkbox',
+ '#default_value' => user_access('import own tweets') ? $account->import : '',
);
}
-
$form['delete'] = array(
'#type' => 'checkbox',
);
@@ -143,11 +135,17 @@ function _twitter_account_list_row($account) {
return $form;
}
-function theme_twitter_account_list_form($form) {
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
+function theme_twitter_account_list_form($variables) {
+ $form = $variables['form'];
if (user_access('import own tweets')) {
$header = array('', t('Name'), t('Description'), t('Private'), t('Import'), t('Delete'));
- }else {
+ }
+ else {
$header = array('', t('Name'), t('Description'), t('Private'), t('Delete'));
}
@@ -161,49 +159,58 @@ function theme_twitter_account_list_form($form) {
$element = &$form['accounts'][$key];
if (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']),
+ 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 {
+ }
+ 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']),
+ 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[] = l($label, 'user/' . $element['#account']->uid . '/edit/twitter/global/' . $element['#account']->id);
}
$rows[] = $row;
}
- $output = theme('table', $header, $rows);
- $output .= drupal_render($form);
+ $output = theme('table', array('header' => $header, 'rows' => $rows));
+ $output .= drupal_render_children($form);
return $output;
}
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
function twitter_account_list_form_submit($form, &$form_state) {
$accounts = $form_state['values']['accounts'];
- foreach($accounts as $account) {
+ foreach ($accounts as $account) {
if (empty($account['delete'])) {
twitter_account_save($account);
}
else {
- twitter_user_delete($account['id'], $account['screen_name']);
+ twitter_account_delete($account['id'], $account['screen_name']);
}
}
}
-function twitter_user_make_global($form_state, $account, $twitter_uid) {
+/**
+ * @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);
@@ -229,16 +236,27 @@ function twitter_user_make_global($form_state, $account, $twitter_uid) {
$description = t('This will allow other users to post using this account.');
}
- return confirm_form($form, $text, 'user/'. $account->uid .'/edit/twitter', $description);
+ return confirm_form($form, $text, 'user/' . $account->uid . '/edit/twitter', $description);
}
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
function twitter_user_make_global_submit($form, &$form_state) {
- db_query("UPDATE {twitter_account} SET is_global = (1 - is_global) WHERE twitter_uid = %d", $form_state['values']['twitter_uid']);
+ 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_state['redirect'] = 'user/' . $form_state['values']['uid'] . '/edit/twitter';
}
-function twitter_account_form($form_state, $account = NULL) {
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
+function twitter_account_form($form, $form_state, $account = NULL) {
if (empty($account)) {
global $user;
$account = $user;
@@ -261,7 +279,7 @@ function twitter_account_form($form_state, $account = NULL) {
$form['password'] = array(
'#type' => 'password',
'#title' => t('Password'),
- '#description' => t("If your Twitter account is protected, or you wish to post to Twitter from Drupal, you must enter the Twitter account's password.")
+ '#description' => t("If your Twitter account is protected, or you wish to post to Twitter from Drupal, you must enter the Twitter account's password."),
);
$form['import'] = array(
@@ -281,6 +299,10 @@ function twitter_account_form($form_state, $account = NULL) {
return $form;
}
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
function twitter_account_form_validate($form, &$form_state) {
module_load_include('lib.php', 'twitter');
module_load_include('inc', 'twitter');
@@ -304,6 +326,10 @@ function twitter_account_form_validate($form, &$form_state) {
}
}
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
function twitter_account_form_submit($form, &$form_state) {
module_load_include('inc', 'twitter');
@@ -314,8 +340,12 @@ function twitter_account_form_submit($form, &$form_state) {
}
}
+/**
+ * If OAuth is enabled, intercept submission of 'Add Account' form on
+ * user/%/edit/twitter page and redirect to Twitter for auth.
+ */
function twitter_account_oauth_validate($form, &$form_state) {
- module_load_include('lib.php', 'oauth');
+ module_load_include('lib.php', 'oauth_common');
module_load_include('lib.php', 'twitter');
$key = variable_get('twitter_consumer_key', '');
@@ -328,19 +358,35 @@ function twitter_account_oauth_validate($form, &$form_state) {
drupal_goto($twitter->get_authorize_url($token));
}
+/**
+ * @TODO This code should probably be reviewed.
+ *
+ * Wrapper to calll drupal_form_submit() which wasn't required in D6.
+ */
+function twitter_oauth_callback() {
+ $form_state['values']['oauth_token'] = $_GET['oauth_token'];
+ drupal_form_submit('twitter_oauth_callback_form', $form_state);
+}
-function twitter_oauth_callback(&$form_state) {
+/**
+ * Form builder function. In D6 this form was built in response to the
+ * oauth return request from Twitter, and the setting of
+ * $form['#post'] seems to have caused the form to be validated and
+ * processed.
+ */
+function twitter_oauth_callback_form($form, &$form_state) {
$form['#post']['oauth_token'] = $_GET['oauth_token'];
-
$form['oauth_token'] = array(
'#type' => 'hidden',
'#default_value' => $_GET['oauth_token'],
);
-
return $form;
}
-function twitter_oauth_callback_validate($form, &$form_state) {
+/**
+ * Validate results from Twitter OAuth return request.
+ */
+function twitter_oauth_callback_form_validate($form, &$form_state) {
$key = variable_get('twitter_consumer_key', '');
$secret = variable_get('twitter_consumer_secret', '');
@@ -356,7 +402,7 @@ function twitter_oauth_callback_validate($form, &$form_state) {
form_set_error('oauth_token', t('Invalid OAuth token.'));
}
- module_load_include('lib.php', 'oauth');
+ module_load_include('lib.php', 'oauth_common');
module_load_include('lib.php', 'twitter');
module_load_include('inc', 'twitter');
@@ -365,7 +411,18 @@ function twitter_oauth_callback_validate($form, &$form_state) {
$form_state['twitter_oauth']['response'] = $response;
}
-function twitter_oauth_callback_submit(&$form, &$form_state) {
+/**
+ * Handle a Twitter OAuth return request and store the account creds
+ * in the DB. Redirects to user/%/edit/twitter
+ *
+ * @TODO Redirect better.
+ *
+ * I don't much like the use of drupal_goto() here as it might
+ * interfere with other modules trying to piggyback on the form
+ * submission, but setting $form['redirect'] was leaving us at the
+ * twitter/oauth URL.
+ */
+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'];
@@ -374,6 +431,14 @@ function twitter_oauth_callback_submit(&$form, &$form_state) {
$account = $twitter->users_show($response['screen_name']);
$account->set_auth($response);
twitter_account_save($account, TRUE);
- $form_state['redirect'] = $form_state['twitter_oauth']['destination'];
+
$form['#programmed'] = FALSE;
+
+ global $user ;
+ if ( $user->uid ) {
+ $form_state['redirect'] = url('user/' . $user->uid . '/edit/twitter');
+ }
+ // redirect isn't firing - because we're using drupal_submit_form()?
+ // - so adding drupal_goto() here (but not liking it).
+ drupal_goto('user/' . $user->uid . '/edit/twitter');
}
diff --git a/twitter.views.inc b/twitter.views.inc
index 97f1f65..230a6f0 100644
--- a/twitter.views.inc
+++ b/twitter.views.inc
@@ -11,27 +11,9 @@
* @{
*/
-/**
- * Implementation of hook_views_handlers()
- */
-function twitter_views_handlers() {
- return array(
- 'handlers' => array(
- 'twitter_views_handler_field_profile_image' => array(
- 'parent' => 'views_handler_field',
- 'file' => 'twitter_views_field_handlers.inc',
- ),
- 'twitter_views_handler_field_xss' => array(
- 'parent' => 'views_handler_field',
- 'file' => 'twitter_views_field_handlers.inc',
- ),
- ),
- );
-}
-
/**
- * Implementation of hook_views_data()
+ * Implements hook_views_data().
*/
function twitter_views_data() {
// Basic table information.
@@ -297,6 +279,10 @@ function twitter_views_data() {
}
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
function twitter_views_data_alter(&$data) {
$data['users']['table']['join']['twitter'] = array(
'left_table' => 'twitter_account',
diff --git a/twitter_actions/twitter_actions.info b/twitter_actions/twitter_actions.info
index 1184fdb..cb8f4a3 100644
--- a/twitter_actions/twitter_actions.info
+++ b/twitter_actions/twitter_actions.info
@@ -1,5 +1,5 @@
name = Twitter actions
description = Exposes Drupal actions to send Twitter messages.
-core = 6.x
+core = 7.x
dependencies[] = twitter
-dependencies[] = oauth
+dependencies[] = oauth_common
diff --git a/twitter_actions/twitter_actions.module b/twitter_actions/twitter_actions.module
index c5d1592..79e8f92 100644
--- a/twitter_actions/twitter_actions.module
+++ b/twitter_actions/twitter_actions.module
@@ -6,19 +6,29 @@
*/
/**
- * Implementation of hook_action_info().
+ * Implements hook_action_info().
*/
function twitter_actions_action_info() {
return array(
'twitter_actions_set_status_action' => array(
'type' => 'system',
- 'description' => t('Post a message to Twitter'),
+ 'label' => t('Post a message to Twitter'),
'configurable' => TRUE,
- 'hooks' => array(
- 'nodeapi' => array('view', 'insert', 'update', 'delete'),
- 'comment' => array('view', 'insert', 'update', 'delete'),
- 'user' => array('view', 'insert', 'update', 'delete', 'login'),
- 'cron' => array('run'),
+ 'triggers' => array(
+ 'nodeapi_view',
+ 'nodeapi_insert',
+ 'nodeapi_update',
+ 'nodeapi_delete',
+ 'comment_view',
+ 'comment_insert',
+ 'comment_update',
+ 'comment_delete',
+ 'user_view',
+ 'user_insert',
+ 'user_update',
+ 'user_delete',
+ 'user_login',
+ 'cron_run',
),
),
);
@@ -41,11 +51,11 @@ function twitter_actions_set_status_action_form($context = array()) {
);
$form['screen_name'] = array(
- '#type' => 'textfield',
- '#title' => t('Twitter account name'),
+ '#type' => 'textfield',
+ '#title' => t('Twitter account name'),
'#default_value' => $context['screen_name'],
- '#size' => 25,
- '#required' => TRUE,
+ '#size' => 25,
+ '#required' => TRUE,
);
$form['message'] = array(
@@ -55,29 +65,37 @@ function twitter_actions_set_status_action_form($context = array()) {
'#cols' => '80',
'#rows' => '3',
'#description' => t('The message that should be sent. You may include the following variables: %site_name, %username, %node_url, %node_type, %title, %teaser, %body, %tinyurl. Not all variables will be available in all contexts.'),
- '#required' => TRUE,
+ '#required' => TRUE,
);
return $form;
}
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
function twitter_actions_set_status_action_validate($form, $form_state) {
if (!_twitter_use_oauth()) {
form_set_error('screen_name', t('Oath has not yet been setup.'));
}
- if (!db_result(db_query("SELECT twitter_uid FROM {twitter_account} WHERE screen_name = '%s'", $form_state['values']['screen_name']))) {
+ if (!db_query("SELECT twitter_uid FROM {twitter_account} WHERE screen_name = :screen_name", array(':screen_name' => $form_state['values']['screen_name']))->fetchField()) {
form_set_error('screen_name', t('Twitter authentication failed. Please check your account name and try again.'));
}
}
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
function twitter_actions_set_status_action_submit($form, $form_state) {
$form_values = $form_state['values'];
- $twitter_uid = db_result(db_query("SELECT twitter_uid FROM {twitter_account} WHERE screen_name = '%s'", $form_values['screen_name']));
+ $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'],
+ 'message' => $form_values['message'],
);
return $params;
}
@@ -98,7 +116,7 @@ function twitter_actions_set_status_action($object, $context) {
// in $context.
$node = $context['node'];
break;
- // The comment hook provides nid, in $context.
+ // The comment hook provides nid, in $context.
case 'comment':
$comment = $context['comment'];
$node = node_load($comment->nid);
@@ -126,7 +144,7 @@ function twitter_actions_set_status_action($object, $context) {
'%vocabulary_name' => $vocabulary->name,
'%vocabulary_description' => $vocabulary->description,
'%vocabulary_id' => $vocabulary->vid,
- )
+ )
);
break;
default:
@@ -136,7 +154,7 @@ function twitter_actions_set_status_action($object, $context) {
if (isset($node)) {
if (!isset($account)) {
- $account = user_load(array('uid' => $node->uid));
+ $account = user_load($node->uid);
}
if ($recipient == '%author') {
$recipient = $account->mail;
@@ -148,20 +166,20 @@ function twitter_actions_set_status_action($object, $context) {
// Node-based variable translation is only available if we have a node.
if (isset($node) && is_object($node)) {
$variables = array_merge($variables, array(
- '%uid' => $node->uid,
- '%node_url' => url('node/'. $node->nid, array('absolute' => TRUE)),
- '%node_type' => node_get_types('name', $node),
- '%title' => $node->title,
- '%teaser' => $node->teaser,
- '%body' => $node->body
- )
+ '%uid' => $node->uid,
+ '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)),
+ '%node_type' => node_type_get_name($node),
+ '%title' => $node->title,
+ '%teaser' => $node->teaser,
+ '%body' => $node->body,
+ )
);
}
// 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))),
+ '%tinyurl' => twitter_shorten_url(url('node/' . $node->nid, array('absolute' => TRUE))),
));
}
diff --git a/twitter_actions/twitter_actions.rules.inc b/twitter_actions/twitter_actions.rules.inc
index 5721cd8..a57dbb9 100644
--- a/twitter_actions/twitter_actions.rules.inc
+++ b/twitter_actions/twitter_actions.rules.inc
@@ -5,7 +5,7 @@
*/
/**
- * Implementation of hook_rules_action_info_alter().
+ * Implements hook_rules_action_info_alter().
*
* Actions of type system are not supported, so rules won't make use of it automatically. So
* we have to provide some information about it to make it work.
@@ -14,7 +14,10 @@ function twitter_actions_rules_action_info_alter(&$actions) {
$actions['rules_core_twitter_actions_set_status_action'] = array(
'label' => t('Post a message to Twitter'),
// Make sure there is something passed for $object.
- 'arguments' => array('object' => array('type' => 'value', 'default value' => NULL)),
+ 'arguments' => array('object' => array(
+ 'type' => 'value',
+ 'default value' => NULL,
+ )),
'module' => 'Twitter',
'eval input' => array('screen_name', 'password', 'message'),
// Let the rules system for executing core style actions execute it.
diff --git a/twitter_post/twitter_post.info b/twitter_post/twitter_post.info
index 2504330..0edec53 100644
--- a/twitter_post/twitter_post.info
+++ b/twitter_post/twitter_post.info
@@ -1,5 +1,5 @@
name = Twitter Post
description = Enables posting to twitter
-core = 6.x
+core = 7.x
dependencies[] = twitter
-dependencies[] = oauth
\ No newline at end of file
+dependencies[] = oauth_common
diff --git a/twitter_post/twitter_post.module b/twitter_post/twitter_post.module
index 18f29e0..a98485e 100644
--- a/twitter_post/twitter_post.module
+++ b/twitter_post/twitter_post.module
@@ -6,29 +6,28 @@
*/
/**
- * Implementation of hook_menu().
+ * Implements hook_menu().
*/
function twitter_post_menu() {
- $items['admin/settings/twitter/post'] = array(
+ $items['admin/config/twitter/post'] = array(
'title' => 'Post',
'page callback' => 'drupal_get_form',
'page arguments' => array('twitter_post_admin_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'twitter_post.pages.inc',
'type' => MENU_LOCAL_TASK,
- 'weight' => 3
-
+ 'weight' => 3,
);
return $items;
}
/**
- * Implementation of hook_form_alter().
+ * Implements hook_form_alter().
*/
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 (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.
$type = $form['#node']->type;
@@ -68,7 +67,6 @@ function twitter_post_form_alter(&$form, $form_state, $form_id) {
* Intercepts newly published nodes and posts noticed to Twitter.
*/
function twitter_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
-
switch ($op) {
case 'insert':
case 'update':
@@ -76,14 +74,16 @@ function twitter_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
module_load_include('inc', 'twitter');
$twitter_account = twitter_account_load($node->twitter['account']);
- $replacements = array('!title' => $node->title,
- '!url' => url('node/'. $node->nid, array('absolute' => TRUE, 'alias' => TRUE)),
- '!url-alias' => url('node/'. $node->nid, array('absolute' => TRUE)),
- '!user' => $node->name);
+ $replacements = array(
+ '!title' => $node->title,
+ '!url' => url('node/' . $node->nid, array('absolute' => TRUE, 'alias' => TRUE)),
+ '!url-alias' => url('node/' . $node->nid, array('absolute' => TRUE)),
+ '!user' => $node->name,
+ );
// Only generate the shortened URL if it's going to be used. No sense
// burning through TinyURLs without a good reason.
if (strstr($node->twitter['status'], '!tinyurl') !== FALSE) {
- $replacements['!tinyurl'] = twitter_shorten_url(url('node/'. $node->nid, array('absolute' => TRUE)));
+ $replacements['!tinyurl'] = twitter_shorten_url(url('node/' . $node->nid, array('absolute' => TRUE)));
}
$status = strtr($node->twitter['status'], $replacements);
@@ -108,16 +108,14 @@ function twitter_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
* A Drupal user object.
*/
function twitter_post_form($account = NULL) {
- drupal_add_js(drupal_get_path('module', 'twitter') .'/twitter.js', 'module');
+ drupal_add_js(drupal_get_path('module', 'twitter') . '/twitter.js');
if (empty($account)) {
- global $user;
- $account = $user;
+ $account = user_load($GLOBALS['user']->uid);
}
- $twitter_accounts = twitter_get_user_accounts($account->uid);
$options = array();
- foreach ($twitter_accounts as $twitter_account) {
+ foreach ($account->twitter_accounts as $twitter_account) {
$options[$twitter_account->id] = $twitter_account->screen_name;
}
@@ -139,7 +137,7 @@ function twitter_post_form($account = NULL) {
else {
$form['account'] = array(
'#type' => 'value',
- '#value' => array_pop(array_keys($options))
+ '#value' => array_pop(array_keys($options)),
);
}
return $form;
diff --git a/twitter_post/twitter_post.pages.inc b/twitter_post/twitter_post.pages.inc
index bac161a..e4ef91a 100644
--- a/twitter_post/twitter_post.pages.inc
+++ b/twitter_post/twitter_post.pages.inc
@@ -3,11 +3,11 @@
/**
* Settings form callback
*/
-function twitter_post_admin_settings() {
+function twitter_post_admin_settings($form, &$form_state) {
$form['twitter_post_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Node types'),
- '#options' => node_get_types('names'),
+ '#options' => node_type_get_names(),
'#default_value' => variable_get('twitter_post_types', array('story' => 'story', 'blog' => 'blog')),
);
@@ -19,5 +19,5 @@ function twitter_post_admin_settings() {
'#default_value' => variable_get('twitter_post_default_format', 'New post: !title !tinyurl'),
);
- return system_settings_form($form);
+ return system_settings_form($form);
}
diff --git a/twitter_signin/twitter_signin.info b/twitter_signin/twitter_signin.info
index cf31d09..f9d24b4 100644
--- a/twitter_signin/twitter_signin.info
+++ b/twitter_signin/twitter_signin.info
@@ -1,6 +1,6 @@
-name = Twitter Signin
+name = Twitter Signin
description = Adds support for "Sign in with Twitter"
-php = 5.1
-core = 6.x
+core = 7.x
dependencies[] = twitter
-dependencies[] = oauth
+dependencies[] = oauth_common
+configure = admin/config/services/twitter/signin
diff --git a/twitter_signin/twitter_signin.module b/twitter_signin/twitter_signin.module
index 05ee4a7..47e2b46 100644
--- a/twitter_signin/twitter_signin.module
+++ b/twitter_signin/twitter_signin.module
@@ -1,57 +1,55 @@
'Twitter Redirect',
'page callback' => 'twitter_signin_redirect',
'access callback' => TRUE,
- 'type' => MENU_CALLBACK
-
+ 'type' => MENU_CALLBACK,
);
- $items['admin/settings/twitter/signin'] = array(
+ $items['admin/config/services/twitter/signin'] = array(
'title' => 'Sign-in',
'page callback' => 'drupal_get_form',
'page arguments' => array('twitter_signin_admin_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'twitter_signin.pages.inc',
'type' => MENU_LOCAL_TASK,
- 'weight' => 5
-
+ 'weight' => 5,
);
return $items;
}
/**
- * Implementation of hook_block().
+ * Implements hook_block_info().
*/
-function twitter_signin_block($op = 'list', $delta = 0, $edit = array()) {
- switch ($op) {
- case 'list':
- $block[0]['info'] = t('Sign in with Twitter');
- return $block;
- case 'view':
- global $user;
-
- if (!$user->uid && _twitter_use_oauth()) {
- $block['subject'] = t('Sign in with Twitter');
- $block['content'] = twitter_signin_button();
- return $block;
- }
+function twitter_signin_block_info() {
+ $block[0]['info'] = t('Sign in with Twitter');
+ return $block;
+}
+
+/**
+ * Implements hook_block_view().
+ */
+function twitter_signin_block_view($delta) {
+ global $user;
+
+ if (!$user->uid && _twitter_use_oauth()) {
+ $block['subject'] = t('Sign in with Twitter');
+ $block['content'] = twitter_signin_button();
+ return $block;
}
}
/**
- * Implementation of hook_user().
+ * Implements hook_user_insert().
*/
-function twitter_signin_user($op, &$edit, &$account, $category = NULL) {
- if ($op == 'insert' && isset($_SESSION['twitter']['values'])) {
+function twitter_signin_user_insert(&$edit, $account, $category) {
+ if (isset($_SESSION['twitter']['values'])) {
unset($_SESSION['twitter']);
}
}
@@ -60,12 +58,10 @@ function twitter_signin_user($op, &$edit, &$account, $category = NULL) {
* returns an image link for signing in with twitter
*/
function twitter_signin_button() {
- $img_path = drupal_get_path('module', 'twitter_signin') . '/images/';
- $img = $img_path . variable_get('twitter_signin_button', 'Sign-in-with-Twitter-lighter-small.png');
-
- return l(theme('image', $img, t('Sign in with Twitter')), 'twitter/redirect', array('html' => TRUE));
-}
+ $img = drupal_get_path('module', 'twitter_signin') . '/images/' . variable_get('twitter_signin_button', 'Sign-in-with-Twitter-lighter-small.png');
+ return l(theme('image', array('path' => $img, 'alt' => t('Sign in with Twitter'))), 'twitter/redirect', array('html' => TRUE));
+}
/**
* Submit handler for twitter signin
@@ -81,35 +77,38 @@ function twitter_signin_redirect() {
$token = $twitter->get_request_token();
$_SESSION['twitter_oauth']['token'] = $token;
- $_SESSION['twitter_oauth']['destination'] = referer_uri();
+ $_SESSION['twitter_oauth']['destination'] = $_SERVER['HTTP_REFERER'];
$_SESSION['twitter_oauth']['signin'] = TRUE;
drupal_goto($twitter->get_authenticate_url($token));
}
/**
- * Implementation of hook_form_alter()
+ * 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' && $_SESSION['twitter_oauth']['signin']) {
$form['#submit'] = array_merge(array('twitter_signin_oauth_callback_submit'), $form['#submit']);
}
-
+
if ($form_id == 'user_login' || $form_id == 'user_login_block') {
$items = array();
$items[] = twitter_signin_button();
-
+
$form['twitter_signin'] = array(
- '#value' => theme('item_list', $items),
+ '#value' => theme('item_list', array('items' => $items)),
);
}
elseif ($form_id == 'user_register' && isset($_SESSION['twitter']['values'])) {
$form['name']['#default_value'] = $_SESSION['twitter']['values']['screen_name'];
- $form['auth_twitter'] = array('#type' => 'hidden', '#value' => $_SESSION['twitter']['values']['user_id']);
+ $form['auth_twitter'] = array(
+ '#type' => 'hidden',
+ '#value' => $_SESSION['twitter']['values']['user_id'],
+ );
}
}
@@ -130,8 +129,11 @@ function twitter_signin_oauth_callback_submit(&$form, &$form_state) {
user_external_login($account, $response);
$success = TRUE;
}
- elseif ($uid = db_result(db_query("SELECT uid FROM {twitter_account} WHERE twitter_uid= %d", $response['user_id']))) {
+ elseif ($uid = db_query("SELECT uid FROM {twitter_account} WHERE twitter_uid = :twitter_uid", array(':twitter_uid' => $response['user_id']))->fetchField()) {
// We have an existing twitter account - set it up for login
+ // TODO Convert "user_load" to "user_load_multiple" if "$uid" is other than a uid.
+ // To return a single user object, wrap "user_load_multiple" with "array_shift" or equivalent.
+ // Example: array_shift(user_load_multiple(array(), $uid))
$account = user_load($uid);
$edit["authname_twitter"] = $response['user_id'];
user_save($account, $edit);
@@ -142,7 +144,7 @@ function twitter_signin_oauth_callback_submit(&$form, &$form_state) {
// No existing user account, let's see if we can register.
if (variable_get('twitter_signin_register', 0)) {
// Check for a nickname collision
- $account = user_load(array('name' => $response['screen_name']));
+ $account = array_shift(user_load_multiple(array(), array('name' => $response['screen_name'])));
if (!$account->uid) {
$edit = array(
'name' => $response['screen_name'],
@@ -150,7 +152,7 @@ function twitter_signin_oauth_callback_submit(&$form, &$form_state) {
'init' => $response['screen_name'],
'status' => 1,
"authname_twitter" => $response['user_id'],
- 'access' => time(),
+ 'access' => REQUEST_TIME,
);
$account = user_save('', $edit);
$user = $account;
@@ -164,7 +166,7 @@ function twitter_signin_oauth_callback_submit(&$form, &$form_state) {
drupal_set_message(t('Please complete the following registration form to create your new account on %site', array('%site' => variable_get('site_name', ''))));
}
}
-
+
if (!$success) {
$_SESSION['twitter']['values'] = $response;
drupal_goto('user/register');
diff --git a/twitter_signin/twitter_signin.pages.inc b/twitter_signin/twitter_signin.pages.inc
index 1696bb1..74ceb8b 100644
--- a/twitter_signin/twitter_signin.pages.inc
+++ b/twitter_signin/twitter_signin.pages.inc
@@ -1,14 +1,18 @@
basename] = theme('image', $image->filename);
+ $options[$image->basename] = theme('image', array('path' => $image->filename));
}
$form['twitter_signin_button'] = array(
@@ -21,10 +25,10 @@ function twitter_signin_admin_settings() {
$form['twitter_signin_register'] = array(
'#title' => t('Automatically register new users'),
'#type' => 'radios',
- '#options' => array(0 => t('No'), 1 => t('Yes')),
+ '#options' => array(t('No'), t('Yes')),
'#default_value' => variable_get('twitter_signin_register', 0),
'#description' => t('Warning, if you enable this, new user accounts will be created without email addresses.'),
);
-
+
return system_settings_form($form);
-}
\ No newline at end of file
+}
diff --git a/twitter_views_field_handlers.inc b/twitter_views_field_handlers.inc
index dee997e..13310a1 100644
--- a/twitter_views_field_handlers.inc
+++ b/twitter_views_field_handlers.inc
@@ -41,7 +41,11 @@ class twitter_views_handler_field_xss extends views_handler_field {
function render($values) {
$value = $values->{$this->field_alias};
if (!empty($this->options['link_urls'])) {
- $value = _filter_url($value, FILTER_DEFAULT);
+ $filter = new stdClass;
+ $filter->settings = array(
+ 'filter_url_length' => 496,
+ );
+ $value = _filter_url($value, $filter);
}
if (!empty($this->options['link_usernames'])) {
$value = twitter_link_filter($value);
@@ -60,7 +64,6 @@ class twitter_views_handler_field_xss extends views_handler_field {
class twitter_views_handler_field_profile_image extends views_handler_field {
function render($values) {
$value = $values->{$this->field_alias};
- return theme('image', $value, '', '', array(), FALSE);
+ return theme('image', array('path' => $value));
}
}
-