View source
<?php
module_load_include('pages.inc', 'linkedin_profile');
function linkedin_profile_init() {
global $theme_path;
$li_css = $theme_path . '/linkedin_profile.css';
if (file_exists($li_css)) {
drupal_add_css($li_css);
}
else {
drupal_add_css(drupal_get_path('module', 'linkedin_profile') . '/linkedin_profile.css');
}
}
function linkedin_profile_menu() {
$items = array();
if (variable_get('linkedin_profile_user_page_enabled', 0) === 1) {
$items['user/%user/linkedin'] = array(
'title' => 'Linkedin',
'type' => MENU_LOCAL_TASK,
'page callback' => 'linkedin_profile_display',
'page arguments' => array(
1,
),
'access callback' => 'linkedin_profile_display_access',
'access arguments' => array(
1,
),
'file' => 'linkedin_profile.pages.inc',
);
}
return $items;
}
function linkedin_profile_display_access($account) {
if (variable_get('linkedin_profile_user_page_enabled', 0) < 1) {
return FALSE;
}
if (!user_access('display LinkedIn profile', $account)) {
return FALSE;
}
if (!isset($account->data['linkedin_profile_user_page_enabled']) || $account->data['linkedin_profile_user_page_enabled'] != 1) {
return FALSE;
}
global $user;
if (!user_access('access user profiles') && $user->uid != $account->uid) {
return FALSE;
}
$check = linkedin_get_profile_fields($account->uid, array(
'id',
));
if (isset($check['error-code'])) {
return FALSE;
}
return TRUE;
}
function linkedin_profile_permission() {
return array(
'display LinkedIn profile' => array(
'title' => t('display LinkedIn profile'),
'description' => t('Display own LinkedIn profile on user page.'),
),
);
}
function linkedin_profile_linkedin_user_edit_perms() {
return array(
'display LinkedIn profile',
);
}
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'])) {
$multiples = array(
'positions' => 'position',
'educations' => 'education',
);
foreach ($profile as $key => $value) {
$item = array(
'name' => $key,
'value' => $value,
);
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']);
}
}
if (!empty($item['value'])) {
$account->linkedin[$key] = theme('linkedin_profile_user_page_item', array(
'item' => $item,
));
}
}
}
}
}
}
function linkedin_profile_user_view($account, $view_mode) {
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'),
'#markup' => theme('linkedin_profile_user_page', array(
'profile' => $account->linkedin,
)),
'#weight' => variable_get('linkedin_profile_user_page_weight', 2),
);
}
}
function linkedin_profile_block_info() {
$blocks = array();
if (variable_get('linkedin_profile_user_page_enabled', 0) == 3) {
$blocks['linkedin_profile'] = array(
'info' => t('LinkedIn Profile'),
'description' => t('User\'s LinkedIn profile'),
);
}
return $blocks;
}
function linkedin_profile_block_view($delta = '') {
if (variable_get('linkedin_profile_user_page_enabled', '0') == 3 && arg(0) == 'user' && is_numeric(arg(1))) {
$account = user_load(arg(1));
if (linkedin_profile_display_access($account)) {
$block['subject'] = t('Linkedin Profile');
$block['content'] = theme('linkedin_profile_user_page', array(
'profile' => $account->linkedin,
));
return $block;
}
}
return;
}
function linkedin_profile_theme($existing, $type, $theme, $path) {
$return = array();
$return['linkedin_profile_user_page'] = array(
'variables' => array(
'profile' => NULL,
),
'template' => 'linkedin-user-page',
);
$multiples = array(
'positions' => 'position',
'educations' => 'education',
);
foreach ($multiples as $key => $val) {
$return['linkedin_profile_user_page_' . $key] = array(
'variables' => array(
$key => NULL,
),
'template' => 'linkedin-user-page-' . $key,
);
$return['linkedin_profile_user_page_' . $val . '_item'] = array(
'variables' => array(
$val => NULL,
),
'template' => 'linkedin-user-page-' . $val . '-item',
);
}
$return['linkedin_profile_user_page_item'] = array(
'variables' => array(
'item' => NULL,
),
'file' => 'linkedin_profile.theme.inc',
);
return $return;
}
function _linkedin_profile_list_default_fields() {
$default_fields = array(
'first-name',
'last-name',
'headline',
'location',
'industry',
'summary',
'specialties',
'interests',
'picture-url',
'public-profile-url',
);
return $default_fields;
}
function _linkedin_profile_vget_user_page_linkedin_fields() {
$fields = array();
$var_fields = variable_get('linkedin_profile_user_page_linkedin_fields', _linkedin_profile_list_default_fields());
foreach ($var_fields as $field) {
if ($field !== 0) {
$fields[] = $field;
}
}
return $fields;
}