2

I have downloaded the User Referral Module and am trying to display the user's link within a block so I can place it on a specific landing page.

The module out of the box doesn't have Views support, so i was thinking i could add some PHP to a block. Filter by UID of current logged in user.

I wish I was better at PHP, but unfortunately I cannot figure it out.

Here is the section of module code that makes it show up on the user's page:

function referral_user_view($account, $view_mode, $langcod) {
  global $user;
  $referrals = array();
  $link = "referral/" . _referral_uid2ref($account->uid);
  if (!variable_get(REFERRAL_DISPLAY_MODE, 0)) {
    if (user_access(REFERRAL_PERM_USE)) {
      if ($user->uid == $account->uid) {
        // User is viewing own page, show referrals
        $referrals[] = array(
          '#title' => t('Your referral link'),
          '#markup' => url($link, array('query' => NULL, 'fragment' => NULL, 'absolute' => TRUE)),
           '#type' => 'user_profile_item',
        );
        $referrals[] = array(
          '#title' => t('Referrals'),
          '#markup' => l(t('View users you have referred'), 'referral/view'),
          '#type' => 'user_profile_item',
        );
      }
    }
  }

  if (!$user->uid) {
    $referrals[] = array(
      '#title' => t('Referral link'),
      '#markup' => l(t('Register to this site using my referral link'), $link),
      '#type' => 'user_profile_item',
      );

    referral_set_cookie(arg(1));
  }

  if ($referrals) {
    $referrals['#type'] = 'user_profile_category';
    $referrals['#title'] = t('Referrals');
    $referrals['#weight'] = 10;
    $account->content['Referrals'] = $referrals;
    // return array('Referrals' => $referrals); // obsolete from drupal 5
  }
}

function referral_set_cookie($uid) {
  $cookie = array(
    'uid'       => $uid,
    'timestamp' => time(),
    'ip'        => ip_address(),
    'referer'   => $_SERVER['HTTP_REFERER'],
  );

  $cookie_lifetime = variable_get('referral_cookie_lifetime', 1) * 86400;
  setcookie(REFERRAL_COOKIE, serialize($cookie), time() +     $cookie_lifetime, '/');
}

function referral_block($op = 'list', $delta = 0) {
  $title[0] = t('Top referring users');
  switch ($op) {
    case 'list':
      $block[0]['info'] = $title[0];
      return $block;

    case 'view':
    switch ($delta) {
      case 0:
        $block['subject'] = $title[0];
        $block['content'] = referral_block_content();
        break;
    }
    return $block;
  }
}

function referral_block_content() {
$header = array();

I tried this code with no luck:

 $referralLink = url('referral/'. _referral_uid2ref($GLOBALS['user']->uid), array('query' => NULL, 'fragment' => NULL, 'absolute' => TRUE));

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.