I am working on a solution for using Twitter avatars as the user profile picture in D7. I am not a developer but took a stab at converting the D6 module developed by @xenatt in issue #771882: Sub-module for showing Twitter avatars with Drupal profiles - include in the main Twitter package?
The module reported to be successful for D6 and I have taken it as far as my abilities will allow for D7. I am now getting an error message "Notice: Array to string conversion in rdf_preprocess_image() (line 772 of /.../modules/rdf/rdf.module)." when trying to access a user page.
I have attached the module and here is the code:
// $Id: twitter_avatar.module,v 1.1.2.6 2010/04/15 03:14:45 walkah Exp $
/**
*
*/
function twitter_avatar_preprocess_user_picture(&$variables) {
$variables['picture'] = '';
if (variable_get('user_pictures', 0)) {
$pic_url = '';
$account = $variables['account'];
$twitter_fdb = db_query("SELECT profile_image_url FROM {twitter_account} WHERE uid = :uid", array(':uid' => $account->uid))->fetchField();
if (eregi("_normal.jpg$", $twitter_fdb)) { $pic_url = ereg_replace("_normal.jpg$","_bigger.jpg",$twitter_fdb); }
elseif (eregi("_normal.JPG$", $twitter_fdb)) { $pic_url = ereg_replace("_normal.jpg$","_bigger.jpg",$twitter_fdb); }
elseif (eregi("_normal.png$", $twitter_fdb)) { $pic_url = ereg_replace("_normal.png$","_bigger.png",$twitter_fdb); }
elseif (eregi("_normal.PNG$", $twitter_fdb)) { $pic_url = ereg_replace("_normal.PNG$","_bigger.PNG",$twitter_fdb); }
elseif (eregi("_normal.gif$", $twitter_fdb)) { $pic_url = ereg_replace("_normal.gif$","_bigger.gif",$twitter_fdb); }
else { $pic_url = ereg_replace("_normal.GIF$","_bigger.GIF",$twitter_fdb); }
if (!empty($account->name) && !empty($pic_url)) {
$picture = $pic_url;
} elseif (!empty($account->picture) && file_exists($account->picture)) {
$picture = file_create_url($account->picture);
}
elseif (variable_get('user_picture_default', '')) {
$picture = variable_get('user_picture_default', '');
}
if (isset($picture)) {
$alt = t("@user's picture", array('@user' => $account->name ? $account->name : variable_get('anonymous', t('Anonymous'))));
$variables['picture'] = theme('image', $picture, $alt, $alt, '', FALSE);
if (!empty($account->uid) && user_access('access user profiles')) {
$attributes = array('attributes' => array('title' => t('View user profile.')), 'html' => TRUE);
$variables['picture'] = l($variables['picture'], "user/$account->uid", $attributes);
}
}
}
}
| Comment | File | Size | Author |
|---|---|---|---|
| twitter_avatar.zip | 2.67 KB | InTheLyonsDen |
Comments
Comment #1
InTheLyonsDen commentedAlso... Is this the best approach? Another would be to download the Twitter profile pic and insert it in to the user profile like Janrain / RPX. Tgere is a D6 approach here. Thoughts? #984512: Import Twitter picture and sync usernames
Comment #2
lyricnz commentedThere are a few issues around caching the profile image for twitter accounts locally, as well as integrating these local images into profile. These seem to be two separate things:
1) creating a local copy of the profile image for each twitter account (that can be imagecache processed etc)
2) integrating that local copy into the user profile image capability
It sounds like they can be implemented separately, in that order.
Comment #3
melsawy commentedCheckout this thread http://drupal.org/node/1840298 to import twitter picture during signin
Comment #4
dddave commentedThis branch no longer is supported. If this is relevant for another version feel free to reactivate against the proper version.