Download & Extend

Sub-Module to use Twitter Avatars with Drupal Profiles

Project:Twitter
Version:7.x-3.x-dev
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

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:

<?php
// $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);
      }
    }
  }
}
?>
AttachmentSize
twitter_avatar.zip2.67 KB

Comments

#1

Also... 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