View source
<?php
function linkedin_init() {
if (!@(include_once variable_get('linkedin_liboauth_path', ''))) {
if (file_exists(drupal_get_path('module', 'oauth') . '/oauth.lib.php')) {
variable_set('linkedin_liboauth_path', drupal_get_path('module', 'oauth') . '/oauth.lib.php');
}
elseif (file_exists(drupal_get_path('module', 'oauth_common') . '/lib/OAuth.php')) {
variable_set('linkedin_liboauth_path', drupal_get_path('module', 'oauth_common') . '/lib/OAuth.php');
}
else {
drupal_set_message(t('Unable to find the OAuth library. Please check your settings for the Linkedin module.'), 'warning');
}
}
module_load_include('inc', 'linkedin');
module_load_include('pages.inc', 'linkedin');
}
function linkedin_menu() {
$items = array();
$items['admin/settings/linkedin'] = array(
'title' => 'LinkedIn integration',
'description' => 'linkedin module settings',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'linkedin_admin',
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'linkedin.pages.inc',
);
$items['linkedin/token/%user'] = array(
'type' => MENU_CALLBACK,
'description' => 'Let user tie their LI account with their local user account',
'page callback' => 'linkedin_access_token',
'page arguments' => array(
2,
),
'access callback' => 'linkedin_token_access',
'access arguments' => array(
2,
),
'file' => 'linkedin.inc',
);
$items['user/%user/edit/linkedin'] = array(
'title' => 'Linkedin',
'type' => MENU_LOCAL_TASK,
'page callback' => 'linkedin_user_settings',
'page arguments' => array(
1,
),
'access callback' => 'linkedin_user_access',
'access arguments' => array(
1,
),
'file' => 'linkedin.pages.inc',
);
return $items;
}
function linkedin_token_access($account) {
global $user;
if ($account->uid > 0 && $account->uid == $user->uid) {
return TRUE;
}
if (variable_get('linkedin_debug_mode', 0) == 1) {
drupal_set_message(t('LinkedIn debug : Access denied to /linkedin/token/@requested. Requesting user has uid @requesting, which is different from the requested account.', array(
'@requested' => $account->uid,
'@requesting' => $user->uid,
)), 'warning');
}
return FALSE;
}
function linkedin_user_access($account) {
global $user;
if ($user->uid == $account->uid) {
$perms = module_invoke_all('linkedin_user_edit_perms');
foreach ($perms as $perm) {
if (user_access($perm)) {
return TRUE;
}
}
if (module_exists('linkedin_auth')) {
return TRUE;
}
}
if (variable_get('linkedin_debug_mode', 0) == 1) {
if ($user->uid != $account->uid) {
drupal_set_message(t('LinkedIn debug : Access denied to /linkedin/token/@requested.<br />
Requesting user (uid @requesting) is different from the requested account (uid @requested)', array(
'@requested' => $account->uid,
'@requesting' => $user->uid,
)));
return FALSE;
}
if (empty($perms)) {
drupal_set_message(t('LinkedIn debug : Access denied to /linkedin/token/@requested.<br />
No module is implementing hook_linkedin_user_edit_perms. Enable at least one submodule and check permissions'));
return FALSE;
}
foreach ($perms as $perm) {
$permissions .= $perm . ', ';
}
drupal_set_message(t('LinkedIn debug : Access denied to /linkedin/token/@requested.<br />
User must have at least one of these permissions : @permissions', array(
'@permissions' => $permissions,
)));
}
return FALSE;
}
function linkedin_user($op, &$edit, &$account, $category = NULL) {
if ($op == 'delete') {
db_query("DELETE FROM {linkedin_token} WHERE uid = %d", $account->uid);
}
}