diff --git twitter.inc twitter.inc index e70e856..0356ae6 100644 --- twitter.inc +++ twitter.inc @@ -12,7 +12,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']) { @@ -27,7 +27,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) { @@ -38,7 +38,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 { @@ -46,17 +46,28 @@ 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)); + $result = db_query("SELECT * FROM {twitter_account} WHERE twitter_uid = :twitter_uid", array(':twitter_uid' => $id))->fetch(); + $values = (array)$result; $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; } @@ -67,14 +78,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); } - + } /** @@ -93,8 +104,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(); @@ -110,16 +121,31 @@ 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); + // TODO Please review the conversion of this statement to the D7 database API syntax. + /* db_query("UPDATE {twitter_account} SET last_refresh = %d WHERE twitter_uid=%d", REQUEST_TIME, $account->id) */ + db_update('twitter_account') + ->fields(array( + 'last_refresh' => REQUEST_TIME, + )) + ->condition('twitter_uid', $account->id) + ->execute(); } +/** + * 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_user_delete($twitter_uid, $screen_name = NULL) { - $sql = "DELETE FROM {twitter_account} WHERE twitter_uid = %d"; - $args = array($twitter_uid); + $sql = "DELETE FROM {twitter_account} WHERE twitter_uid = :twitter_uid"; + $args = array(':twitter_uid' => $twitter_uid); if (!empty($screen_name)) { - $sql .= " AND screen_name = '%s'"; - $args[] = $screen_name; + $sql .= " AND screen_name = :screen_name"; + $args[':screen_name'] = $screen_name; } db_query($sql, $args); } - diff --git twitter.info twitter.info index 49d60da..22c3ec6 100644 --- twitter.info +++ twitter.info @@ -2,4 +2,13 @@ name = Twitter description = Adds integration with the Twitter microblogging service. php = 5.1 -core = 6.x +core = 7.x +files[] = twitter.inc +files[] = twitter.install +files[] = twitter.lib.php +files[] = twitter.module +files[] = twitter.pages.inc +files[] = twitter.views.inc +files[] = twitter.views_default.inc +files[] = twitter_views_field_handlers.inc +configure = admin/config/services/twitter diff --git twitter.install twitter.install index d3f1d5a..caa0671 100644 --- twitter.install +++ twitter.install @@ -2,54 +2,60 @@ // $Id: twitter.install,v 1.3.2.4 2010/02/13 20:32:26 walkah Exp $ /** - * Implementation of hook_schema). + * @file + * Install, update and uninstall functions for the twitter module. + * + */ + +/** + * Implements hook_schema(). */ function twitter_schema() { $schema['twitter'] = array( - 'description' => 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, @@ -57,7 +63,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, @@ -65,214 +71,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')), @@ -283,14 +290,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'"); + // TODO The drupal_(un)install_schema functions are called automatically in D7. + // drupal_install_schema('twitter') + + // Set the weight to 3, making it heavier than Pathauto. + // TODO Please review the conversion of this statement to the D7 database API syntax. + /* db_query("UPDATE {system} SET weight = 3 WHERE name = 'twitter'") */ + db_update('system') + ->fields(array( + 'weight' => 3, + )) + ->condition('name', 'twitter') + ->execute(); } /** @@ -317,7 +332,7 @@ function twitter_update_6001() { $attributes = array( 'description' => t("The location of the {twitter_account}'s owner."), - 'length' => 255 + 'length' => 255, ); db_add_column($ret, 'twitter_account', 'location', 'varchar(255)', $attributes); @@ -325,11 +340,14 @@ function twitter_update_6001() { 'description' => t("The number of users following this {twitter_account}."), 'unsigned' => TRUE, 'not null' => TRUE, - 'default' => 0 + 'default' => 0, ); db_add_column($ret, 'twitter_account', 'followers_count', 'int', $attributes); - return $ret; + // hook_update_N() no longer returns a $ret array. Instead, return + // nothing or a translated string indicating the update ran successfully. + // See http://drupal.org/node/224333#update_sql. + //return t('TODO Add a descriptive string here to show in the UI.') /* $ret */; } /** @@ -338,8 +356,11 @@ function twitter_update_6001() { */ function twitter_update_6002() { $ret = array(); - $ret[] = update_sql("UPDATE {system} SET weight = 3 WHERE name = 'twitter'"); - return $ret; + db_query("UPDATE {system} SET weight = 3 WHERE name = 'twitter'"); + // hook_update_N() no longer returns a $ret array. Instead, return + // nothing or a translated string indicating the update ran successfully. + // See http://drupal.org/node/224333#update_sql. + //return t('TODO Add a descriptive string here to show in the UI.') /* $ret */; } /** @@ -348,18 +369,26 @@ function twitter_update_6002() { */ 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), + db_drop_primary_key('twitter'); + + db_change_field('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; + // hook_update_N() no longer returns a $ret array. Instead, return + // nothing or a translated string indicating the update ran successfully. + // See http://drupal.org/node/224333#update_sql. + //return t('TODO Add a descriptive string here to show in the UI.') /* $ret */; } /** - * Add NOT NULL constraint and DEFAULT value to the screen_name field of the + * 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 @@ -368,14 +397,17 @@ 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')))); + db_drop_index('twitter', 'screen_name'); + db_change_field('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; + db_drop_index('twitter_user', 'screen_name'); + db_drop_primary_key('twitter_user'); + db_change_field('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')))); + // hook_update_N() no longer returns a $ret array. Instead, return + // nothing or a translated string indicating the update ran successfully. + // See http://drupal.org/node/224333#update_sql. + //return t('TODO Add a descriptive string here to show in the UI.') /* $ret */; } @@ -396,16 +428,25 @@ function twitter_update_6005() { $ret = array(); // First clear out any borked statuses. - $ret[] = update_sql("DELETE FROM {twitter} WHERE twitter_id = 2147483647"); + // TODO update_sql has been removed. Use the database API for any schema or data changes. + db_query("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' => ''), + db_drop_primary_key('twitter'); + + db_change_field('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; + // hook_update_N() no longer returns a $ret array. Instead, return + // nothing or a translated string indicating the update ran successfully. + // See http://drupal.org/node/224333#update_sql. + //return t('TODO Add a descriptive string here to show in the UI.') /* $ret */; } /** @@ -421,9 +462,9 @@ function twitter_update_6005() { function twitter_update_6006() { $ret = array(); - db_drop_primary_key($ret, 'twitter'); - - db_change_field($ret, 'twitter', 'twitter_id', 'twitter_id', + db_drop_primary_key('twitter'); + + db_change_field('twitter', 'twitter_id', 'twitter_id', array( 'description' => t("Unique identifier for each {twitter} post."), 'type' => 'numeric', @@ -431,12 +472,12 @@ function twitter_update_6006() { 'precision' => 20, 'scale' => 0, 'not null' => TRUE, - 'default' => 0 + 'default' => 0, ), array('primary key' => array('twitter_id')) - ); - - db_add_field($ret, 'twitter', 'in_reply_to_status_id', + ); + + db_add_field('twitter', 'in_reply_to_status_id', array( 'description' => t("Unique identifier of a status this {twitter} post was replying to."), 'type' => 'numeric', @@ -445,9 +486,9 @@ function twitter_update_6006() { 'unsigned' => TRUE, 'not null' => FALSE, ) - ); + ); - db_add_field($ret, 'twitter', 'in_reply_to_user_id', + db_add_field('twitter', 'in_reply_to_user_id', array( 'description' => t("Unique identifier for the {twitter_account} this post was replying to."), 'type' => 'numeric', @@ -456,18 +497,18 @@ function twitter_update_6006() { 'unsigned' => TRUE, 'not null' => FALSE, ) - ); + ); - db_add_field($ret, 'twitter', 'in_reply_to_screen_name', + db_add_field('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', + db_add_field('twitter', 'truncated', array( 'description' => t("Boolean flag indicating whether the {twitter} status was cut off to fit in the 140 character limit."), 'type' => 'int', @@ -475,11 +516,11 @@ function twitter_update_6006() { 'not null' => TRUE, 'default' => 0, ) - ); - - db_drop_primary_key($ret, 'twitter_account'); + ); - db_change_field($ret, 'twitter_account', 'twitter_uid', 'twitter_uid', + db_drop_primary_key('twitter_account'); + + db_change_field('twitter_account', 'twitter_uid', 'twitter_uid', array( 'description' => t("The unique identifier of the {twitter_account}."), 'type' => 'numeric', @@ -487,209 +528,221 @@ function twitter_update_6006() { 'precision' => 20, 'scale' => 0, 'not null' => TRUE, - 'default' => 0 + 'default' => 0, ), array('primary key' => array('twitter_uid')) - ); + ); - - return $ret; + + // hook_update_N() no longer returns a $ret array. Instead, return + // nothing or a translated string indicating the update ran successfully. + // See http://drupal.org/node/224333#update_sql. + //return t('TODO Add a descriptive string here to show in the UI.') /* $ret */; } -/* - * Update the last_refresh column to supply a default value. http://drupal.org/node/301317 +/** + * 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', + db_change_field('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; + ); + // hook_update_N() no longer returns a $ret array. Instead, return + // nothing or a translated string indicating the update ran successfully. + // See http://drupal.org/node/224333#update_sql. + //return t('TODO Add a descriptive string here to show in the UI.') /* $ret */; } /** - * Update from 2.x to 3.x + * 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 - )); - - + db_add_field('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('twitter_account', 'host', + array( + 'description' => t('The host for this account can be a laconi.ca instance'), + 'type' => 'varchar', + 'length' => 255, + )); + db_add_field('twitter_account', 'password', + array( + 'description' => t("The password for the Twitter account."), + 'type' => 'varchar', + 'length' => 64, + )); + db_add_field('twitter_account', 'oauth_token', + array( + 'description' => t('The token_key for oauth-based access.'), + 'type' => 'varchar', + 'length' => 64, + )); + db_add_field('twitter_account', 'oauth_token_secret', + array( + 'description' => t('The token_secret for oauth-based access.'), + 'type' => 'varchar', + 'length' => 64, + )); + db_add_field('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('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('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('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('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('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('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('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('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('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('twitter_account', 'verified', + array( + 'description' => t("Indicates if a user is verified."), + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 1, + )); + db_add_field('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('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('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('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('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']); + // TODO Please review the conversion of this statement to the D7 database API syntax. + /* 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_update('twitter_account') + ->fields(array( + 'uid' => $row['uid'], + 'password' => $row['password'], + 'import' => $row['import'], + )) + ->condition('screen_name', $row['screen_name']) + ->execute(); } - db_drop_table($ret, 'twitter_user'); + db_drop_table('twitter_user'); } drupal_install_modules(array('twitter_post')); - return $ret; -} - - -function twitter_uninstall() { - // Remove tables. - drupal_uninstall_schema('twitter'); + // hook_update_N() no longer returns a $ret array. Instead, return + // nothing or a translated string indicating the update ran successfully. + // See http://drupal.org/node/224333#update_sql. + //return t('TODO Add a descriptive string here to show in the UI.') /* $ret */; } diff --git twitter.lib.php twitter.lib.php index ce252d9..804e7dd 100644 --- twitter.lib.php +++ twitter.lib.php @@ -238,7 +238,7 @@ class Twitter { } $response = drupal_http_request($url, $headers, $method, $data); - if (!$response->error) { + if (!isset($response->error)) { return $response->data; } else { @@ -258,7 +258,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); + } } } @@ -484,7 +492,7 @@ class TwitterUser { } $this->utc_offset = $values['utc_offset']; - if ($values['status']) { + if (isset($values['status'])) { $this->status = new TwitterStatus($values['status']); } } @@ -494,7 +502,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 twitter.module twitter.module index f3776c5..852538d 100644 --- twitter.module +++ twitter.module @@ -2,7 +2,7 @@ // $Id: twitter.module,v 1.10.2.7 2010/10/21 15:12:17 walkah Exp $ /** - * Implementation of hook_meu() + * Implements hook_meu(). */ function twitter_menu() { $items = array(); @@ -15,19 +15,20 @@ 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', + 'type' => MENU_NORMAL_ITEM, ); - - $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( @@ -49,38 +50,55 @@ function twitter_menu() { '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'), + 'description' => 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('make twitter accounts global'), + 'description' => t('Assign a Twitter account as the site global account.'), + ), + 'import own tweets' => array( + 'title' => t('import own tweets'), + 'description' => t('Import own tweets to the site.'), + ), + ); } /** - * Implementation of hook_user(). + * Implements hook_user_categories(). */ -function twitter_user($op, &$edit, &$account, $category = NULL) { - switch ($op) { - case 'categories': - return array( - array( - 'name' => 'twitter', - 'title' => 'Twitter accounts', - 'weight' => 3, - ), - ); - } +function twitter_user_categories() { + return array( + array( + 'name' => 'twitter', + 'title' => 'Twitter accounts', + 'weight' => 3, + ), + ); } +/** + * Implements hook_theme(). + */ function twitter_theme() { return array( 'twitter_account_list_form' => array( - 'arguments' => array('form' => NULL), - ) + 'render element' => 'form', + ), ); } @@ -103,7 +121,7 @@ function twitter_shorten_url($url) { } /** - * Implementation of hook_cron() + * Implements hook_cron(). * * Imports new Twitter statuses for site users, and deletes expired tweets. */ @@ -117,74 +135,57 @@ 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); + // TODO Please review the conversion of this statement to the D7 database API syntax. + /* db_query('DELETE FROM {twitter} WHERE created_time < %d', REQUEST_TIME - $age) */ + db_delete('twitter') + ->condition('created_time', REQUEST_TIME - $age, '<') + ->execute(); } } /** - * 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. + * Implements 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_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_tips(). + * Filter tips callback function for $filters[0] 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_username($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(). + */ +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/') { @@ -198,7 +199,7 @@ 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); } /** @@ -220,32 +221,36 @@ 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"; + + $sql = "SELECT twitter_uid FROM {twitter_account} WHERE uid = :uid"; if (user_access('use global twitter account')) { - $sql.= " OR is_global=1"; + $sql .= " OR is_global=1"; } - $results = db_query($sql, $account->uid); + $result = db_query($sql, array(':uid' => $account->uid)); - while ($row = db_fetch_array($results)) { - $key = $row['twitter_uid']; + foreach ($result as $row) { + $key = $row->twitter_uid; $twitter_accounts[] = twitter_account_load($key); } return $twitter_accounts; } +/** + * Detect whether we should use oauth. This can probably just go now :) + */ function _twitter_use_oauth() { - if (!module_exists('oauth')) { + if (!module_exists('oauth_common')) { return FALSE; } - + return (variable_get('twitter_consumer_key', '') && variable_get('twitter_consumer_secret', '')); } /** - * Implementation of hook_views_api. + * Implements hook_views_api(). + * * Notifies the Views module that we're compatible with a particular API revision. */ function twitter_views_api() { diff --git twitter.pages.inc twitter.pages.inc index 4fba645..de78630 100644 --- twitter.pages.inc +++ twitter.pages.inc @@ -4,21 +4,21 @@ /** * */ -function twitter_admin_form() { +function twitter_admin_form($form, &$form_state) { $form = array(); $form['oauth'] = array( '#type' => 'fieldset', '#title' => t('OAuth Settings'), '#description' => t(''), - '#access' => module_exists('oauth'), + '#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( @@ -51,12 +51,16 @@ function twitter_admin_form() { '#type' => 'select', '#title' => t('Delete old statuses'), '#default_value' => variable_get('twitter_expire', 0), - '#options' => $periods + '#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'); @@ -66,14 +70,18 @@ function twitter_user_settings($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 .= drupal_render(drupal_get_form('twitter_account_list_form', $twitter_accounts)); } - $output .= drupal_get_form('twitter_account_form', $account); + $output .= drupal_render(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(); @@ -110,33 +118,28 @@ 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, 'width' => '', 'height' => '', 'alt' => array(), 'title' => FALSE)), ); $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. + 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. $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', ); @@ -144,11 +147,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')); } @@ -162,39 +171,44 @@ 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); } @@ -204,7 +218,11 @@ function twitter_account_list_form_submit($form, &$form_state) { } } -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); @@ -230,16 +248,31 @@ 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']); - - $form_state['redirect'] = 'user/'. $form_state['values']['uid'] .'/edit/twitter'; + // TODO Please review the conversion of this statement to the D7 database API syntax. + /* db_query("UPDATE {twitter_account} SET is_global = (1 - is_global) WHERE twitter_uid = %d", $form_state['values']['twitter_uid']) */ + db_update('twitter_account') + ->fields(array( + 'is_global' => (1 - is_global), + )) + ->condition('twitter_uid', $form_state['values']['twitter_uid']) + ->execute(); + + $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; @@ -262,7 +295,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( @@ -282,6 +315,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'); @@ -305,6 +342,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'); @@ -315,8 +356,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', ''); @@ -329,19 +374,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', ''); @@ -357,7 +418,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'); @@ -366,7 +427,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']; @@ -375,6 +447,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 twitter.views.inc twitter.views.inc index a327140..51b36c0 100644 --- twitter.views.inc +++ twitter.views.inc @@ -13,7 +13,7 @@ */ /** - * Implementation of hook_views_handlers() + * Implements hook_views_handlers(). */ function twitter_views_handlers() { return array( @@ -32,7 +32,7 @@ function twitter_views_handlers() { /** - * Implementation of hook_views_data() + * Implements hook_views_data(). */ function twitter_views_data() { // Basic table information. @@ -298,6 +298,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 twitter.views_default.inc twitter.views_default.inc index b63632d..ff078e9 100644 --- twitter.views_default.inc +++ twitter.views_default.inc @@ -1,6 +1,10 @@ name = 'tweets'; diff --git twitter_actions/twitter_actions.info twitter_actions/twitter_actions.info index 6b66f34..1082358 100644 --- twitter_actions/twitter_actions.info +++ twitter_actions/twitter_actions.info @@ -1,6 +1,9 @@ ; $Id: twitter_actions.info,v 1.1.4.1 2010/10/20 16:37:30 walkah Exp $ name = Twitter actions description = Exposes Drupal actions to send Twitter messages. -core = 6.x +core = 7.x dependencies[] = twitter -dependencies[] = oauth +dependencies[] = oauth_common + +files[] = twitter_actions.module +files[] = twitter_actions.rules.inc diff --git twitter_actions/twitter_actions.module twitter_actions/twitter_actions.module index 756452f..665313b 100644 --- twitter_actions/twitter_actions.module +++ twitter_actions/twitter_actions.module @@ -7,19 +7,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', ), ), ); @@ -42,11 +52,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( @@ -56,29 +66,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; } @@ -99,7 +117,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); @@ -127,7 +145,7 @@ function twitter_actions_set_status_action($object, $context) { '%vocabulary_name' => $vocabulary->name, '%vocabulary_description' => $vocabulary->description, '%vocabulary_id' => $vocabulary->vid, - ) + ) ); break; default: @@ -137,7 +155,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; @@ -149,20 +167,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 twitter_actions/twitter_actions.rules.inc twitter_actions/twitter_actions.rules.inc index 489b3cc..b39a7c5 100644 --- twitter_actions/twitter_actions.rules.inc +++ twitter_actions/twitter_actions.rules.inc @@ -6,7 +6,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. @@ -15,7 +15,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 twitter_post/twitter_post.info twitter_post/twitter_post.info index 17a8d4b..6839759 100644 --- twitter_post/twitter_post.info +++ twitter_post/twitter_post.info @@ -1,6 +1,8 @@ ; $Id: twitter_post.info,v 1.1.2.2 2010/10/20 16:37:30 walkah Exp $ 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 +files[] = twitter_post.module +files[] = twitter_post.pages.inc diff --git twitter_post/twitter_post.module twitter_post/twitter_post.module index 3e262cd..b577ad1 100644 --- twitter_post/twitter_post.module +++ twitter_post/twitter_post.module @@ -7,29 +7,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; @@ -69,7 +68,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': @@ -77,14 +75,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); @@ -109,7 +109,7 @@ 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; @@ -140,7 +140,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 twitter_post/twitter_post.pages.inc twitter_post/twitter_post.pages.inc index 78ba57c..4431c3a 100644 --- twitter_post/twitter_post.pages.inc +++ twitter_post/twitter_post.pages.inc @@ -4,11 +4,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')), ); @@ -20,5 +20,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 twitter_signin/twitter_signin.info twitter_signin/twitter_signin.info index ed29132..799dc80 100644 --- twitter_signin/twitter_signin.info +++ twitter_signin/twitter_signin.info @@ -2,6 +2,9 @@ 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 + +files[] = twitter_signin.module +files[] = twitter_signin.pages.inc diff --git twitter_signin/twitter_signin.module twitter_signin/twitter_signin.module index 1bb453e..b92f020 100644 --- twitter_signin/twitter_signin.module +++ twitter_signin/twitter_signin.module @@ -2,7 +2,7 @@ // $Id: twitter_signin.module,v 1.1.2.6 2010/01/25 03:14:45 walkah Exp $ /** - * Implementation of hook_menu(). + * Implements hook_menu(). */ function twitter_signin_menu() { $items = array(); @@ -11,60 +11,70 @@ function twitter_signin_menu() { 'title' => '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/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_block(). + */ +function twitter_signin_block_OLD($op = 'list', $delta = 0, $edit = array()) { } + +/** + * 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 (TRUE && isset($_SESSION['twitter']['values'])) { unset($_SESSION['twitter']); } } /** + * Implements hook_user(). + */ +function twitter_signin_user_OLD($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)); + + return l(theme('image', array('path' => $img, 'width' => t('Sign in with Twitter'))), 'twitter/redirect', array('html' => TRUE)); } @@ -82,35 +92,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'], + ); } } @@ -131,8 +144,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); @@ -143,7 +159,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'], @@ -151,7 +167,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; @@ -165,7 +181,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 twitter_signin/twitter_signin.pages.inc twitter_signin/twitter_signin.pages.inc index 4694398..6f032e3 100644 --- twitter_signin/twitter_signin.pages.inc +++ twitter_signin/twitter_signin.pages.inc @@ -1,19 +1,23 @@ basename] = theme('image', $image->filename); + $options[$image->basename] = theme('image', array('path' => $image->filename)); } - + $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'), @@ -22,10 +26,13 @@ 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( + 0 => t('No'), + 1 => 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 twitter_views_field_handlers.inc twitter_views_field_handlers.inc index dee997e..c9410b1 100644 --- twitter_views_field_handlers.inc +++ 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,7 @@ 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, 'width' => '', 'height' => '', 'alt' => array(), 'title' => FALSE)); } }