You are here

function linkedin_profile_user in LinkedIn Integration 6

File

linkedin_profile/linkedin_profile.module, line 84
Main hooks implementation for LinkedIn Profile module

Code

function linkedin_profile_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'categories':
      return array(
        array(
          'name' => 'linkedin',
          'title' => 'LinkedIn',
          'weight' => 3,
        ),
      );
      break;
    case 'load':
      if (variable_get('linkedin_profile_user_page_enabled', '0') > 0) {
        static $profile;

        // no need to ask for each user_load
        if (!isset($profile)) {
          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']) {
                  $items[] = theme('linkedin_profile_user_page_' . $multiples[$key] . '_item', $items_val);
                }
                else {

                  //iterate
                  foreach ($items_val as $item_val) {
                    $items[] = theme('linkedin_profile_user_page_' . $multiples[$key] . '_item', $item_val);
                  }
                }
                $item['value'] = theme('linkedin_profile_user_page_' . $key, $items);
              }
              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', $item);
            }
          }
        }
      }
      break;
    case 'view':
      if (variable_get('linkedin_profile_user_page_enabled', '0') == '2' && linkedin_profile_display_access($account)) {
        $account->content['linkedin'] = array(
          '#type' => 'user_profile_item',
          '#title' => t('Linkedin'),
          '#value' => theme('linkedin_profile_user_page', $account->linkedin),
          '#weight' => variable_get('linkedin_profile_user_page_weight', 2),
        );
      }
      break;
  }
}