Pull Referral Data into block

Damion - February 13, 2008 - 00:19

I am trying to pull referral data into a block with user profile data. I am using the referral plugin (new window) and a arg() script in a block to pull user profile information (thanks for help gpk & jbrown).

What I need to do now is pull data from the referral module (database) and output to screen. Here is basically what I want to do:

$output="";
if (UserReferred) { get from referrals(array); $referralid = referrals(uid); where referrer->uid get referrer->profile_name, referrer->profile_custom; $output = "referred by:< br />" . referrer->picture . "< br/>" . referrer->profile_name; }
if (UserNOTReferred) { $output = "different code"; }
print $output;

Thanks to gpk and jbrown I have the profile pulls in a block and am using the following code:

<?php
$output
= '';

switch(
arg(0)) {
  
    case
'blog':
        if (
is_numeric(arg(1))) {
           
$uid = arg(1);
        }
        break;
      
    case
'node':
        if (
is_numeric(arg(1))) {
           
$node = node_load(arg(1));
           
$uid = $node->uid;
        }
        break;
      
}

if(
$uid) {
 
$user = user_load(array('uid' => $uid));

  if (
$user->picture) {
   
$output .= theme_user_picture($user);
  }

 
$output .= '<strong>' . theme_username($user) . '</strong><br />' . $user->profile_name . '<br /><br /><strong>My Links</strong><br /><a href="' . $user->profile_link1 . '">Favorite Site 1</a><br /><a href="' . $user->profile_link2 . '">Favorite Site 2</a>';

}

print
$output;
?>

I added this

Damion - February 13, 2008 - 05:38

For anyone wanting to know how to do this with the referral module, I found a way.
There may be a better way to do this, and I appreciate any feedback, but this is how I got it to work:
CAVEAT - this is working in conjunction with my profile block and the $uid variable is initialized there. You could probably adapt the code fairly easily if you do not want the profile elements in the block.

<?php
$refuser
= ''; //initialize the variable
$refuser = referral_get_user(array($uid)); //this gets and returns the referring user, $uid is pulled in above code
if (is_numeric($refuser)) { } else { $refuser = 1; } //if the $refuser returns null, then we put the #1 user (admin) as the referrer - you could adapt for your needs
$reflink = user_load(array('uid' => $refuser)); //I am loading data from the User table of the referring person

$refput = 'Referred By:<br />' . theme_username($reflink) . '<br /><a href="' . $reflink->profile_link1 . '">Favorite Link</a>'; //I am displaying the Referred by: < br>Username (linked to profile) < br> Then a Custom Profile Field (URL)

print $refput; //print results to screen
?>

I tried both of these pieces of code

rmacleod - March 12, 2008 - 22:51

Hello

I tried both of the above items and It seems that the code actually shows the Referrer ID for the owner or creator of the node. Not the user who is logged in.

Does anyone have an idea on how to adapt it to show the referrer of the logged in person.

Also, is it possible to show the referrer info on the thank you page that is shown after someone signs up to the site.

So a newly referred person will see the name and website of the user that referred them to the site.

Cheers!
Thanks
Rick M.

Sorry I missed this before -

Damion - March 22, 2008 - 06:05

Sorry I missed this before - been tied up on another project and have not logged in here in a couple of weeks.

The code above is designed for a block to display the referring users info - you can see LinkPrimer.com to see what I am talking about - just navigate to any blog page and you will see what it does.

This code basically shows anyone who is visiting the blog page of a member who referred that blogger. In other words, if I referred you and someone visited your blog - it would say referred by and then link to my page. IF there is not a referral, it shows the data of the admin user. If you look at the linkprimer.com site you will see the top right block of any blog shows BOTH of these snippets of code.

If you just wanted to show the person who referred you, you should be able to do something like:

<?php
$uid
= $user->uid; //gets the uid of the logged in user
$refuser = referral_get_user(array($uid)); //gets the referrer uid
$reflink = user_load(array('uid' => $refuser)); //load the array of the referring user
$output = 'Referred By: ' . theme_username($reflink); //outputs a link to referrers profile
?>

Keep in mind that I DID NOT verify that this code works so don't try it on a production site without testing it somewhere else first. Please verify if it does work so anyone else who needs it will know.

I did not add any error handling so you may want to do that if you need it.

 
 

Drupal is a registered trademark of Dries Buytaert.