You are here

function linkedin_profile_user_load in LinkedIn Integration 7

Implements hook_user_load().

File

linkedin_profile/linkedin_profile.module, line 94

Code

function linkedin_profile_user_load($users) {
  if (variable_get('linkedin_profile_user_page_enabled', 0) > 0) {
    foreach ($users as $account) {
      module_load_include('inc', 'linkedin', 'linkedin');
      $fields = _linkedin_profile_vget_user_page_linkedin_fields();
      $profile = linkedin_get_profile_fields($account->uid, $fields);
      if (!isset($profile['error-code'])) {

        //Let themers hook into items
        $multiples = array(
          'positions' => 'position',
          'educations' => 'education',
        );
        foreach ($profile as $key => $value) {
          $item = array(
            'name' => $key,
            'value' => $value,
          );

          //deal with multi-values structured fields
          if (array_key_exists($key, $multiples)) {
            $items = array();
            $items_val = $profile[$key][$multiples[$key]];
            if (is_array($items_val)) {
              if ($items_val['id']) {
                $variables[$multiples[$key]] = $items_val;
                $items[] = theme('linkedin_profile_user_page_' . $multiples[$key] . '_item', $variables);
              }
              else {
                foreach ($items_val as $item_val) {
                  $variables[$multiples[$key]] = $item_val;
                  $items[] = theme('linkedin_profile_user_page_' . $multiples[$key] . '_item', $variables);
                }
              }
              $variables[$key] = $items;
              $item['value'] = theme('linkedin_profile_user_page_' . $key, $variables);
            }
            else {
              unset($item['value']);
            }
          }

          //Simpler fields go directly through generic theme function
          if (!empty($item['value'])) {
            $account->linkedin[$key] = theme('linkedin_profile_user_page_item', array(
              'item' => $item,
            ));
          }
        }
      }
    }
  }
}