Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
// $Id
/*
* @file : Main hooks implementation for Linkedin module
*/
/*
* hook_init()
* Make sure we load needed files.
*/
function linkedin_init() {
module_load_include('lib.php', 'oauth');
module_load_include('inc', 'linkedin');
module_load_include('pages.inc', 'linkedin');
global $theme_path;
$linkedin_css = $theme_path .'/linkedin.css';
if (file_exists($linkedin_css)) {
drupal_add_css($linkedin_css);
}
else {
drupal_add_css(drupal_get_path('module', 'linkedin') .'/linkedin.css');
}
}
/*
* hook_menu
*/
function linkedin_menu() {
$items = array();
//global settings form
$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'
);
//user settings form
$items['user/%user/edit/linkedin'] = array(
'title' => 'Linkedin',
'page callback' => 'linkedin_user_settings',
'page arguments' => array(1),
'access callback' => '_linkedin_user_access', //access arguments don't support multiple arguments, so create our access handler
'type' => MENU_LOCAL_TASK,
'file' => 'linkedin.pages.inc'
);
//callback for oauth token request on linkedin API.
$items['linkedin/token/%'] = array(
'page callback' => 'linkedin_access_token',
'page arguments' => array(2),
'access callback' => '_linkedin_user_access',
'type' =>MENU_CALLBACK,
'file' => 'linkedin.inc'
);
//LinkedIn profile tab for users
$items['user/%user/linkedin'] = array(
'title' => 'Linkedin',
'page callback' => 'linkedin_profile_display',
'page arguments' => array(1),
'type' => MENU_LOCAL_TASK,
'access callback' => '_linkedin_profile_display_access',
'access arguments' => array(1),
'file' => 'linkedin.pages.inc',
);
return $items;
}
/*
* hook_theme()
*/
function linkedin_theme($existing, $type, $theme, $path) {
return array(
//Let themers hook into profile elements
'linkedin_profile' => array(
'arguments' => array('profile' => NULL),
),
);
}
/*
* hook_user()
*/
function linkedin_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'categories':
return array(
array(
'name' => 'linkedin',
'title' => 'LinkedIn',
'weight' => 3,
),
);
break;
}
}
/*
* hook_perm()
*/
function linkedin_perm() {
return array('display LinkedIn profile', 'update LinkedIn status', 'use custom status text');
}
/*
* Custom access callback for user/%user/edit/linkedin
*/
function _linkedin_user_access () {
if(user_access('display LinkedIn profile') || user_access('update LinkedIn status')) {
return TRUE;
} else {
return FALSE;
}
}
/*
* Custom access callback for user/%user/linkedin
*/
function _linkedin_profile_display_access($account) {
global $user;
if(
variable_get('linkedin_profile_enabled', '0') != '1' ||
!user_access('access user profiles') ||
!user_access('display LinkedIn profile', $account) ||
$account->linkedin_profile_enabled != '1') {
return FALSE;
}
$check = linkedin_get_profile_fields($account->uid, array('id'));
if($check == 'refused') { // no need to display an empty tab
return FALSE;
}
return TRUE;
}
/*
* hook_form_alter()
* Call the user form when needed.
*/
function linkedin_form_alter(&$form, $form_state, $form_id) {
if($form_id == 'signup_form') {// add our form into event signup
global $user;
if(variable_get('linkedin_enabled_event_signup', '0') != '1' || !user_access('update LinkedIn status')) {
return;
} else {
//node object is not at same key everytime, so iterate until we find it
$array = $form['#parameters'];
$node = new stdClass();
foreach($array as $k) {
if(is_object($k) && isset($k->nid) && $k->type == 'event') {
$node = $k;
break;
} else {
array_pop($array);
}
}
$form['collapse']['signup_user_form']['linkedin'] = drupal_retrieve_form('linkedin_user_status_update_form', $form_state, $user, $node);
array_unshift($form['#submit'], 'linkedin_user_status_update_form_submit' ); //manually adding our submit handler
}
} else {//add our form into nodes edit page
if(isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id) {
global $user;
$node = $form['#node'];
if(variable_get('linkedin_enabled_'. $node->type, '0') != '1' || !user_access('update LinkedIn status')) {
return;
} else {
$form['linkedin'] = drupal_retrieve_form('linkedin_user_status_update_form', $form_state, $user, $node);
array_unshift($form['#submit'], 'linkedin_user_status_update_form_submit' );
}
}
}
return $form;
}
/*
* Themer function for user profile
*/
function theme_linkedin_profile($profile) {
$output = '';
$output .= '<a href="'. $profile['public-profile-url'] .'" title="Public profile of '. $profile['first-name'] .' '.$profile['last-name'] .' on www.linkedin.com.">';
if($profile['picture-url']) {
$output .= '<img src="'. $profile['picture-url'] .'" alt="'. $profile['first-name'] .' '.$profile['last-name'] .'" />';
}
$output .= '<h2 class="linkedin-name">'. $profile['first-name'] .' '.$profile['last-name'] .'</h2></a>';
$output .= '<h3 class="linkedin-headline">'. $profile['headline'] .' <i>('.$profile['industry'] .')</i></h3>';
$output .= '<p class="linkedin-location">'. $profile['name'] .'</p>';
$output .= '<div class="linkedin-summary">'. $profile['summary'] .'</div>';
$output .= '<div class="linkedin-specialties">'. $profile['specialties'] .'</div>';
$output .= '<div class="linkedin-status">';
$output .= '<p class="linkedin-submitted">'. format_date($profile['current-status-timestamp']) .'</p>';
$output .= $profile['current-status'];
$output .= '</div>';
return $output;
}