diff --git a/linkedin_connections/linkedin_connections.css b/linkedin_connections/linkedin_connections.css
new file mode 100644
index 0000000..4deba5c
--- /dev/null
+++ b/linkedin_connections/linkedin_connections.css
@@ -0,0 +1,22 @@
+/**
+ * Default styles for the LinkedIn Connections forms.
+ *
+ * This file can be overridden by copying to the theme directory such that
+ * the resulting path is:
+ *  {theme_path}/linkedin_connections.css
+ * OR
+ *  {theme_path}/css/linkedin_connections.css
+ *
+ */
+
+#linkedin-connections-list-connections-form .form-type-checkbox {
+  font-size: 0.9em;
+}
+
+#linkedin-connections-list-connections-form .form-type-checkbox:hover {
+  background: #eee;
+}
+
+#linkedin-connections-list-connections-form div.form-item {
+  margin: 0;
+}
\ No newline at end of file
diff --git a/linkedin_connections/linkedin_connections.info b/linkedin_connections/linkedin_connections.info
new file mode 100644
index 0000000..4dc0c51
--- /dev/null
+++ b/linkedin_connections/linkedin_connections.info
@@ -0,0 +1,7 @@
+name = "LinkedIn Connections"
+description = "Let users send messages to their LinkedIn connections to invite them to the site."
+core = "7.x"
+package = "Linkedin"
+version = "7.x-1.x-dev"
+project = "linkedin_connections"
+dependencies[] = "linkedin"
\ No newline at end of file
diff --git a/linkedin_connections/linkedin_connections.install b/linkedin_connections/linkedin_connections.install
new file mode 100644
index 0000000..838e74b
--- /dev/null
+++ b/linkedin_connections/linkedin_connections.install
@@ -0,0 +1,74 @@
+<?php
+
+/**
+ * @file
+ * Install, update and uninstall functions for the LinkedIn Connections module.
+ *
+ */
+
+/**
+ * Implements hook_install().
+ */
+function  linkedin_connections() {
+  // Set the module's weight to 20
+  db_query("UPDATE {system} SET weight = 20 WHERE name = 'janet_custom_linkedin_connections'");
+}
+
+
+/**
+ * Implements hook_schema().
+ */
+function linkedin_connections_schema() {
+  $schema['linkedin_connections'] = array(
+    'description' => 'Track which LinkedIn connections a user has sent a message to.',
+    'fields' => array(
+      'uid' => array(
+        'description' => 'User ID from {user}.uid.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'linkedin_id' => array(
+        'description' => 'The LinkedIn user id.',
+        'type' => 'varchar',
+        'length' => 100,
+        'not null' => TRUE,
+      ),
+      'message_timestamp' => array(
+        'description' => 'Timestamp of sent message.',
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+    ),
+  );
+  return $schema;
+}
+
+/**
+ * Implements hook_uninstall().
+ */
+function linkedin_connections_uninstall() {
+  // Delete variables
+  variable_del('linkedin_connections_message_body_custom');
+  variable_del('linkedin_connections_message_body_fixed');
+  variable_del('linkedin_connections_message_subject');
+
+}
+
+/**
+ * Implements hook_requirements().
+ */
+function linkedin_connections_requirements($phase) {
+  $requirements = array();
+  $t = get_t();
+  $has_curl = function_exists('curl_init');
+  $requirements['curl'] = array(
+    'title' => $t('cURL'),
+    'value' => $has_curl ? $t('Enabled') : $t('Not found'),
+  );
+  if (!$has_curl) {
+    $requirements['curl']['severity'] = REQUIREMENT_ERROR;
+    $requirements['curl']['description'] = $t('Linkedin Connecctions module could not be installed because the PHP <a href="@curl_url">cURL</a> library is not available.', array('@curl_url' => 'http://php.net/manual/en/curl.setup.php'));
+  }
+  return $requirements;
+}
\ No newline at end of file
diff --git a/linkedin_connections/linkedin_connections.module b/linkedin_connections/linkedin_connections.module
new file mode 100644
index 0000000..68d13ed
--- /dev/null
+++ b/linkedin_connections/linkedin_connections.module
@@ -0,0 +1,915 @@
+<?php
+/**
+ * @file
+ * Code for the LinkedIn Connections module.
+ *
+ */
+
+global $base_url;
+define('LINKEDIN_CONNECTIONS_MESSAGE_SUBJECT_DEFAULT', t('Join me on the @site-name!', array('@site-name' => variable_get('site_name'))));
+define('LINKEDIN_CONNECTIONS_MESSAGE_BODY_DEFAULT', t('
+I have joined the @site-name and think you would like it.
+
+LinkedIn does not allow html links, so copy the following url into your browser to register and join me there:
+
+@register_url
+
+',
+  array(
+    '@site-name' => variable_get('site_name'),
+    '@register_url' => $base_url . '/user/register',
+
+  )));
+define('LINKEDIN_CONNECTIONS_MESSAGE_SUBMIT_TEXT_DEFAULT', t('Send message to selected connections'));
+
+
+/**
+ * Implements hook_init().
+ */
+function linkedin_connections_init() {
+  global $theme_path;
+  $css = '/linkedin_connections.css';
+  if (file_exists($theme_path . $css)) {
+    drupal_add_css($css);
+  }
+  elseif (file_exists($theme_path . '/css' . $css)) {
+    drupal_add_css($theme_path . '/css' . $css);
+  }
+  else {
+    drupal_add_css(drupal_get_path('module', 'linkedin_connections') . $css);
+  }
+}
+
+/*
+ * Implements of hook_perm().
+ */
+function linkedin_connections_permission() {
+  return array(
+    'view own LinkedIn connections' => array(
+      'title' => t('view own LinkedIn connections'),
+      'description' => t('View own LinkedIn connections.'),
+    ),
+  );
+}
+
+/*
+ * Implements of hook_linkedin_user_edit_perms().
+ */
+function linkedin_connections_linkedin_user_edit_perms() {
+  return array('view own LinkedIn connections');
+}
+
+/**
+ * Implements hook_menu().
+ */
+function linkedin_connections_menu() {
+
+  $items = array();
+
+  $items['user/%user/linkedin_connections'] = array(
+    'title'            => 'Invite Linkedin Connections',
+    'page callback'    => 'linkedin_connections_page',
+    'access callback' => 'linkedin_connections_menu_access',
+    'type'             => MENU_LOCAL_TASK,
+    'weight'           => 2,
+    'menu_name'        => 'user-menu',
+  );
+
+  return $items;
+}
+
+/**
+ * Custom menu access callback.
+ */
+function linkedin_connections_menu_access() {
+
+  global $user;
+
+  if (arg(0)=='user' && arg(1) != $user->uid) {
+    return FALSE;
+  }
+
+  if (!user_access('send invitations')) {
+    return FALSE;
+  }
+
+
+  return TRUE;
+}
+
+/**
+ * Implements hook_linkedin_admin_page().
+ *
+ * This provides new form fields for settings at admin/config/services/linkedin
+ * @return $form
+ *   array of additional form fields
+ */
+function linkedin_connections_linkedin_admin_page() {
+
+  $form = array();
+
+  // Connections fieldset
+  $form['linkedin_connections'] = array(
+    '#description' => t('Let users send invitations to their LinkedIn connections.'),
+    '#title' => t('LinkedIn Connections'),
+    '#type' => 'fieldset',
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+
+  // default message subject
+  $form['linkedin_connections']['linkedin_connections_message_subject'] = array(
+    '#description' => t('Default text for subject of message sent to LinkedIn connections.'),
+    '#title' => t('Default invitation subject'),
+    '#type' => 'textfield',
+    // note - naming the variable the same as the form field saves the value automagically
+    '#default_value' => variable_get('linkedin_connections_message_subject', LINKEDIN_CONNECTIONS_MESSAGE_SUBJECT_DEFAULT),
+  );
+
+  // default message body
+  $form['linkedin_connections']['linkedin_connections_message_body_custom'] = array(
+    '#description' => t('Default text for message sent to LinkedIn connections.'),
+    '#title' => t('Default invitation body text'),
+    '#type' => 'textarea',
+    // note - naming the variable the same as the form field saves the value automagically
+    '#default_value' => variable_get('linkedin_connections_message_body_custom', LINKEDIN_CONNECTIONS_MESSAGE_BODY_DEFAULT),
+  );
+
+  // default text for submit button
+  $form['linkedin_connections']['linkedin_connections_message_submit_text'] = array(
+    '#description' => t('Default text for submit button on send mesage form.'),
+    '#title' => t('Default submit button text.'),
+    '#type' => 'textfield',
+    // note - naming the variable the same as the form field saves the value automagically
+    '#default_value' => variable_get('linkedin_connections_message_submit_text', LINKEDIN_CONNECTIONS_MESSAGE_SUBMIT_TEXT_DEFAULT),
+  );
+
+  $form['linkedin_connections']['linkedin_connections_message_log_reset'] = array(
+    '#description' => t('Remove all logs of previously sent messages.'),
+    '#title' => t('Wipe records of previously sent messages.'),
+    '#type' => 'checkbox',
+    // note - naming the variable the same as the form field saves the value automagically
+    '#default_value' => FALSE,
+  );
+
+  // add custom submit function
+  $form['#submit'][] = 'linkedin_connections_admin_page_submit';
+
+  return $form;
+}
+
+/**
+ *  Custom submit function.
+ */
+function linkedin_connections_admin_page_submit($form, &$form_state) {
+
+  if ($form_state['values']['linkedin_connections_message_log_reset'] == 1) {
+    $num_deleted = linkedin_connections_truncate_message_log();
+    if ($num_deleted > 0) {
+      drupal_set_message(t('Successfully deleted @num_deleted records from database.', array('@num_deleted' => $num_deleted)));
+    }
+  }
+}
+
+/**
+ *  Helper function to remove all message logs from the linkedin_connections table.
+ * @return type
+ */
+function linkedin_connections_truncate_message_log() {
+
+  $num_deleted = db_delete('linkedin_connections')->execute();
+
+  return $num_deleted;
+}
+
+/**
+ * Page callback for custom linkedin page
+ */
+function linkedin_connections_page() {
+
+  $output = t("<p>Find people on linkedin to connect with!</p>");
+
+  module_load_include('inc', 'linkedin', 'linkedin.pages');
+
+  module_load_include('module', 'linkedin');
+
+  global $user;
+
+  //$content = linkedin_user_settings($user);
+
+  $fields = array('id', 'first-name', 'last-name', 'positions');
+
+  // check if this account is connected with LinkedIn
+  $check = linkedin_get_profile_fields($user->uid, array('first-name', 'last-name', 'public-profile-url'), TRUE);
+
+  if (isset($check['error-code'])) {
+    // the $check returned an error, so this account is not linked
+    $output .= t('You must first authorize LinkedIn integration to use related features.');
+    $form = drupal_get_form('linkedin_user_enable_form', $user->uid);
+    $output .= drupal_render($form);
+  }
+  else {
+    $output .= t('Your account is associated with @name !public_profile.', array('@name' => $check['first-name'] . ' ' . $check['last-name'], '!public_profile' => l($check['public-profile-url'], $check['public-profile-url'])));
+    $form = drupal_get_form('linkedin_user_settings_form', $user);
+    $output .= drupal_render($form);
+
+    $connections_form = drupal_get_form('linkedin_connections_list_connections_form');
+    $output .= drupal_render($connections_form);
+  }
+
+  return $output;
+
+}
+
+/**
+ * Form builder for listing connections
+ */
+function linkedin_connections_list_connections_form($form) {
+
+  global $user;
+  $num_per_page = 10;
+  $page = isset($_GET['p']) ? $_GET['p'] : 0;
+  $start = $page * $num_per_page;
+
+
+
+  // initialise form array
+  $form = array();
+
+  // specify array of LinkeIn profile fields we want to return
+  $fields = array('id', 'first-name', 'last-name', 'positions');
+
+  // set options for linkedin_connections_get_connections().
+  $options = array(
+    'count' => $num_per_page,
+    'start' => $start,
+  );
+
+  // get connections for current user
+  $connections = linkedin_connections_get_connections($user->uid, $fields, $options);
+
+  if (!is_array($connections)) {
+    return;
+  }
+  if (isset($connections['status']) && $connections['status']!='200') {
+    drupal_set_message($connections['message']);
+    return;
+  }
+
+  // get array of previously sent messages
+  $previous_messages = linkedin_connections_get_previous_messages($user->uid);
+
+  // set form tree property
+  $form['connections']['#tree'] = TRUE;
+
+  // loop through connections
+  foreach ($connections as $id => $connection) {
+
+    // if the data retrieved from LinkedIn is private, skip
+    if ($connection['id'] == 'private') {
+      continue;
+    }
+
+    // if the message has already been sent, disable this connection to prevent
+    // further messages
+    $disable = FALSE;
+
+    // if we have this LinkedIn id in our array of previous_messages
+    if (array_key_exists($connection['id'], $previous_messages)) {
+      // disable this form item
+      $disable = TRUE;
+    }
+
+    // format position string
+    $positions_string = linkedin_connections_format_position($connection);
+
+
+    // Checkbox option to send message to this contact
+    $form['connections'][$id]['send'] = array(
+      '#type' => 'checkbox',
+      '#title' => check_plain($connection['first-name']) . ' ' . check_plain($connection['last-name']) . check_plain($positions_string),
+      '#disabled' => $disable,
+    );
+
+    // If we've already sent a message to this user, add a note say when
+    if ($disable) {
+      $form['connections'][$id]['sent'] = array(
+        '#markup' => t('Message sent on ' . date('D jS M Y H:i:s', $previous_messages[$connection['id']]->message_timestamp)),
+      );
+    }
+
+    // set the LinkedIn user ID
+    $form['connections'][$id]['id'] = array(
+      '#type' => 'hidden',
+      '#value' => $connection['id'],
+    );
+    $form['connections'][$id]['first-name'] = array(
+      '#type' => 'hidden',
+      '#value' => $connection['first-name'],
+    );
+    $form['connections'][$id]['last-name'] = array(
+      '#type' => 'hidden',
+      '#value' => $connection['last-name'],
+    );
+  }
+
+  $form['linkedin_connections_pager'] = array(
+    '#markup' => linkedin_connections_pager($num_per_page),
+  );
+
+
+  $form['linkedin_connections_message_subject_custom'] = array(
+    '#title' => t('Message subject'),
+    '#type' => 'textfield',
+    '#size' => '55',
+    '#description' => t('Please add a custom message to be sent to the connections selected above.'),
+    '#default_value' => variable_get('linkedin_connections_message_subject_custom', LINKEDIN_CONNECTIONS_MESSAGE_SUBJECT_DEFAULT),
+  );
+
+  $form['linkedin_connections_message_body_custom'] = array(
+    '#title' => t('Message body'),
+    '#type' => 'textarea',
+    '#description' => t('Please add a custom message to be sent to the connections selected above.'),
+    '#default_value' => variable_get('linkedin_connections_message_body_custom', LINKEDIN_CONNECTIONS_MESSAGE_BODY_DEFAULT),
+    '#rows' => '10',
+  );
+
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => variable_get('linkedin_connections_message_submit_text', LINKEDIN_CONNECTIONS_MESSAGE_SUBMIT_TEXT_DEFAULT),
+  );
+
+  return $form;
+}
+
+/**
+ *  Helper fuinction to format current position of connection
+ * @param $connection
+ *   array returned from LinkedIn api function
+ * @return $positions_string
+ *   string of connections's current position
+ */
+function linkedin_connections_format_position($connection) {
+  $positions_string = '';
+    $current_positions = array();
+    if (isset($connection['positions']) && count($connection['positions'])) {
+      foreach ($connection['positions']['position'] as $position) {
+        if (isset($position['is-current']) && $position['is-current'] == 'true') {
+          $current_positions[] = $position['title'] . ' @ ' . $position['company']['name'];
+        }
+      }
+
+      if (count($current_positions) > 0) {
+      $positions_string = ' (' . implode(', ', $current_positions) . ')';
+      }
+    }
+  return $positions_string;
+}
+
+/**
+ *  Helper function to add pager to LinkedIn connections form
+ * @param $num_per_page
+ * @return $output
+ *   string of formatted html for pager
+ */
+function linkedin_connections_pager($num_per_page) {
+
+  // initialise variables
+  $prev_link_query = array();
+  $next_link_query = array();
+  $prev_link = 'Previous';
+  $next_link = 'Next';
+
+  // get current page
+  $current_page = isset($_GET['p']) ? $_GET['p'] : 0;
+
+  // set previous page value
+  $prev_page = $current_page > 0 ? $current_page-1 : 0;
+
+  // currently we do not know the total numbe of connections from an initial
+  // api call
+  //$next_page = (($current_page + 1) * $num_per_page) < $total ? $current_page + 1 : $current_page;
+
+  $next_page = $current_page + 1;
+
+  if ($current_page > 0) {
+    $prev_link_query = array(
+      'p' => $prev_page,
+    );
+    $prev_link = l('Previous', current_path(), array('query' => $prev_link_query));
+  }
+
+  if ($next_page > $current_page) {
+    $next_link_query = array(
+      'p' => $next_page,
+    );
+    $next_link = l('Next', current_path(), array('query' => $next_link_query));
+  }
+
+
+
+
+
+  $output = $prev_link . $next_link;
+
+  return $output;
+
+}
+
+/**
+ * Form submit function
+ */
+function linkedin_connections_list_connections_form_submit($form, &$form_state) {
+
+  foreach ($form_state['values']['connections'] as $id => $connection) {
+    if ($connection['send'] == 1) {
+      $recipients[] = $connection;
+    }
+  }
+
+  foreach ($recipients as $recipient) {
+    // @todo - make this send the invite!
+
+    // set subject
+    $subject = $form_state['values']['linkedin_connections_message_subject_custom'];
+
+    // set body
+    $body = $form_state['values']['linkedin_connections_message_body_custom'];
+
+    // send message
+    $response = linkedin_connections_invite_connection($recipient, $subject, $body);
+
+    if ($response['status'] == '201') {
+      // success
+
+      global $user;
+
+      // log message in linkedin_connections table.
+      db_insert('linkedin_connections')
+        ->fields(array(
+          'uid' => $user->uid,
+          'linkedin_id' => $recipient['id'],
+          'message_timestamp' => REQUEST_TIME,
+        ))
+      ->execute();
+
+      drupal_set_message(t('Successfully sent message to @first-name @last-name via LinkedIn', array('@first-name' => $recipient['first-name'], '@last-name' => $recipient['last-name'])));
+
+      // add redirect
+      $form_state['redirect'] = array(
+        current_path(),
+        array(
+          'query' => array(
+            'p' => $_GET['p'],
+          ),
+        ),
+      );
+
+    }
+    else {
+      // problem
+      drupal_set_message(t('We have a problem.'));
+    }
+
+
+  }
+
+  //dpm($form_state);
+
+}
+
+/**
+ *
+ * @param $recipient
+ *   array containint
+ *   - id (required)
+ *   - first-name
+ *   - last-name
+ * @param $subject
+ *   string
+ * @param $message
+ *   string
+ *
+ */
+function linkedin_connections_invite_connection($recipient, $subject, $body) {
+
+  // check recipient id
+  if (!isset($recipient['id'])) {
+    return;
+  }
+
+  // check subject
+  if (!is_string($subject)) {
+    return;
+  }
+  $subject = check_plain($subject);
+
+  // check message
+  if (!is_string($body)) {
+    return;
+  }
+  $body = check_plain($body);
+
+  // format xml
+  $xml_message_body = '';
+  $xml_message_body .= '<?xml version="1.0" encoding="UTF-8"?>';
+  $xml_message_body .= '<mailbox-item>';
+  $xml_message_body .= '<recipients>';
+  $xml_message_body .= '<recipient>';
+  $xml_message_body .= '<person path="/people/' . $recipient['id'] . '" />';
+  $xml_message_body .= '</recipient>';
+  $xml_message_body .= '</recipients>';
+  $xml_message_body .= '<subject>' . $subject . '</subject>';
+  $xml_message_body .= '<body>' . $body . '</body>';
+  $xml_message_body .= '</mailbox-item>';
+
+  // call linkedin_connections_message_connection_send
+
+  global $user;
+
+  return linkedin_connections_message_connection_send($user->uid, $xml_message_body);
+
+}
+
+function linkedin_connections_message_connection_send($uid, $xml_message_body) {
+
+  module_load_include('inc', 'linkedin');
+
+  //Make sure library is loaded before doing anything.
+  linkedin_init();
+
+  // Set base URL
+  $base_url = "https://api.linkedin.com/v1/people/~/mailbox";
+
+  // initialise the append string
+  $append = '';
+
+  // Load the user's linked in tokken key and secret
+  $row = db_query("SELECT * FROM {linkedin_token} WHERE uid = :uid AND type = :type", array(':uid' => $uid, ':type' => 'access'))->fetchAssoc();
+
+  // If there is no data for this user
+  if (!$row || empty($row)) {
+    // This account does not have any LinkedIn account associated with.
+    $response = array(
+      'status' => '401',
+      'error-code' => 'custom',
+      'message' => 'No LinkedIn account is associated with this user',
+    );
+    // If linkedin_debug_mode - set debug message
+    if (variable_get('linkedin_debug_mode', 0) == 1) {
+      drupal_set_message(t('Linkedin debug : @status : @message', array('@status' => $response['status'], '@message' => $response['message'])));
+    }
+    // return error response
+    return $response;
+  }
+
+  // turn row object into a tokens array
+  $tokens = (array) $row;
+
+  // build the fields string to append tot he request
+  //$append .= _linkedin_build_fields_request($fields, $type);
+  // construct the full url
+  $url = $base_url;
+
+  //dpm($url);
+  //dpm($tokens);
+  //dpm($body);
+  // get the response
+  $response = linkedin_connections_send_message($url, $tokens, $xml_message_body);
+
+  return $response;
+
+}
+
+/**
+ *
+ * @param $url
+ *   string holding the url we are submitting to
+ * @param $tokens
+ *   array holding the LinkedIn key and secret
+ * @param $body
+ *   string holding the message body
+ * @return type
+ */
+function linkedin_connections_send_message($url, $tokens, $body) {
+
+  //Get sure library is loaded before doing anything.
+  linkedin_init();
+
+  $signature = new OAuthSignatureMethod_HMAC_SHA1();
+  $consumer_key = variable_get('linkedin_consumer_key', '');
+  $consumer_secret = variable_get('linkedin_consumer_secret', '');
+  $consumer = new OAuthConsumer($consumer_key, $consumer_secret, NULL); // callbackurl?
+  $token = new OAuthConsumer($tokens['token_key'], $tokens['token_secret'], 1);
+
+  $token = new OAuthToken($tokens['token_key'], $tokens['token_secret']);
+
+  $request = OAuthRequest::from_consumer_and_token($consumer, $token, "POST", $url);
+  $request->sign_request($signature, $consumer, $token);
+  $header = $request->to_header("https://api.linkedin.com");
+
+  //dpm($url); dpm($header);
+
+  $response = _linkedin_connections_http_request($url, $header, $body);
+
+
+  // If the http request was successful, we will have an integer value  201 as a response.
+  if (is_int($response) && $response == 201) {
+    // success
+    $response = array('status' => '201');
+    return $response;
+
+  }
+  else {
+    // We have a problem, which will probably be returned as xml.
+    parse_str($response);
+    $response = _linkedin_parse_fields($response);
+    $response = $response['error'];
+    //$response = _linkedin_parse_fields($response); dpm($response);
+    if (isset($response['error-code'])) {
+      $message = t('Linkedin debug : LinkedIn.com answered "@status : @message', array('@status' => $response['status'], '@message' => $response['message']));
+      if (variable_get('linkedin_debug_mode', 0) == 1) {
+        drupal_set_message($message, 'warning');
+      }
+      watchdog('warning', $message);
+    }
+    return $response;
+  }
+}
+
+/*
+ * Returns an array contening the fields requested.
+ * @params
+ * $url : full request url to a linkedin API ressource (see API doc for syntax)
+ * $tokens : the user tokens, as an array containing keys 'token_key' and 'token_secret' with their value
+ */
+function linkedin_connections_get_connection_fields($url, $tokens) {
+  //Get sure library is loaded before doing anything.
+  linkedin_init();
+
+  $signature = new OAuthSignatureMethod_HMAC_SHA1();
+  $consumer_key = variable_get('linkedin_consumer_key', '');
+  $consumer_secret = variable_get('linkedin_consumer_secret', '');
+  $consumer = new OAuthConsumer($consumer_key, $consumer_secret, NULL);
+  $token = new OAuthConsumer($tokens['token_key'], $tokens['token_secret'], 1);
+  $request = OAuthRequest::from_consumer_and_token($consumer, $token, "GET", $url);
+  $request->sign_request($signature, $consumer, $token);
+  $header = $request->to_header("https://api.linkedin.com");
+  $response = _linkedin_http_request($url, $header);
+  parse_str($response);
+  $response = _linkedin_parse_fields($response);
+  if (isset($response['error-code'])) {
+    $message = t('Linkedin debug : LinkedIn.com answered "@status : @message', array('@status' => $response['status'], '@message' => $response['message']));
+    if (variable_get('linkedin_debug_mode', 0) == 1) {
+      drupal_set_message($message, 'warning');
+    }
+    watchdog('warning', $message);
+  }
+  return $response;
+}
+
+
+/*
+ * Some internal helper functions...
+ */
+function _linkedin_connections_http_request($url, $header, $body = NULL) {
+
+  $ch = curl_init();
+
+  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
+  curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
+  curl_setopt($ch, CURLOPT_URL, $url);
+
+  if ($body) {
+    curl_setopt($ch, CURLOPT_POST, 1);
+    if ($body == 'token_request') {
+      curl_setopt($ch, CURLOPT_POSTFIELDS, '');
+    }
+    else {
+      curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
+      curl_setopt($ch, CURLOPT_HTTPHEADER, array($header, 'Content-Type: text/xml;charset=utf-8'));
+      curl_setopt($ch, CURLOPT_POST, 1);
+      // It is important to set request to POST for sending messages.
+      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
+    }
+  }
+
+  // execute the curl call
+  $output = curl_exec($ch);
+
+  // get the http response code
+  $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+
+  // close the curl connection
+  curl_close($ch);
+
+  // check for success. An httpd status of 201 inicates success:
+  // see https://developer.linkedin.com/documents/messaging-between-connections-api
+  if ($http_code == '201') {
+    return $http_code;
+  }
+  else {
+    // otherwise, return the xml $output
+    return $output;
+  }
+}
+
+/**
+ *
+ * @global $user
+ * @param $uid
+ * @param $fields
+ * @return string
+ */
+function linkedin_connections_get_connections($uid, $fields = array(), $options = array()) {
+
+  module_load_include('inc', 'linkedin');
+
+  //Make sure library is loaded before doing anything.
+  linkedin_init();
+
+  // Set base URL
+  $base_url = "https://api.linkedin.com/v1/people/~/connections";
+  $append = '';
+
+  // Load the user's linked in tokken key and secret
+  $row = db_query("SELECT * FROM {linkedin_token} WHERE uid = :uid AND type = :type", array(':uid' => $uid, ':type' => 'access'))->fetchAssoc();
+  // If there is no data for this user
+  if (!$row || empty($row)) {
+    // This account does not have any LinkedIn account associated with.
+    $response = array(
+      'status' => '401',
+      'error-code' => 'custom',
+      'message' => 'No LinkedIn account is associated with this user',
+    );
+    // If linkedin_debug_mode - set debug message
+    if (variable_get('linkedin_debug_mode', 0) == 1) {
+      drupal_set_message(t('Linkedin debug : @status : @message', array('@status' => $response['status'], '@message' => $response['message'])));
+    }
+    // return error response
+    return $response;
+  }
+
+  // grab the user object for the current user
+  global $user;
+  if ($user->uid == $uid) {
+    //User is requesting their own profile.
+    $tokens = $row;
+    //$append = '~';
+    $type = 'auth';
+  }
+
+  // turn tokens object into an array
+  $tokens = (array) $tokens;
+
+  // build the fields string to append tot he request
+  $append .= _linkedin_build_fields_request($fields, $type);
+
+  $query_string = array();
+
+  if (isset($options['count'])) {
+    $query_string[] = 'count=' . $options['count'];
+  }
+
+  if (isset($options['start'])) {
+    $query_string[] = 'start=' . $options['start'];
+  }
+
+  if (count($query_string)) {
+    $append .= '?' . implode("&", $query_string);
+  }
+
+  // construct the full url
+  $url = $base_url . $append;
+
+  //dpm($url);
+
+  // get the response
+  $response = linkedin_connections_get_connection_fields($url, $tokens);
+
+  if (isset($response['error']['status']) && ($response['error']['status'] == 401 || $response['error']['status'] == 403)) {
+    // No relationships between users, switch back to public profile and retry
+    $tokens = (array) $row;
+    $append = '~:public';
+    $append .= _linkedin_build_fields_request($fields, 'public');
+    $url = $base_url . $append;
+    $response = linkedin_get_fields($url, $tokens, $flat);
+  }
+
+  if (isset($response['connections'])) {
+    // odd case, if we have a single connection returned, the array structure is slightly different
+    // Possibly to do with the xmltoarray function or linkedinapi? - not sure.
+    if (isset($response['connections']['person']['id'])) {
+      $connection = $response['connections']['person'];
+      $response = array($connection);
+    }
+    else {
+      // we have a number of connections, in an array under $response['connections']['person']
+      $response = $response['connections']['person'];
+    }
+  }
+  else {
+    $response = $response['error'];
+  }
+  if (variable_get('linkedin_debug_mode', 0) == 1) {
+    if (isset($response['error-code'])) {
+      drupal_set_message(t('Linkedin debug : LinkedIn.com answered "@status : @message', array('@status' => $response['status'], '@message' => $response['message'])));
+    }
+  }
+  return $response;
+
+}
+
+/**
+ * Get records of previous messages sent by current user
+ */
+function linkedin_connections_get_previous_messages($uid) {
+
+  $result = db_query('SELECT * FROM {linkedin_connections} WHERE uid=:uid', array(':uid' => $uid));
+
+  // return as array of objects, keyed by linkedin_id
+  return $result->fetchAllAssoc('linkedin_id');
+
+}
+
+/**
+ * Convert xml to array
+ *
+ * @todo - extend this to retrieve the attributes from the root node and use
+ *  to retrieve the total number of connections to aid pagination.
+ *
+ */
+function linkedin_connections_xml_to_array($xml, $ns=NULL) {
+  $a = array();
+  for ($xml->rewind(); $xml->valid(); $xml->next()) {
+    $key = $xml->key();
+    if (!isset($a[$key])) {
+      $a[$key] = array();
+      $i=0;
+    }
+    else {
+      $i = count($a[$key]);
+    }
+    $simple = TRUE;
+    foreach ($xml->current()->attributes() as $k => $v) {
+        $a[$key][$i][$k]=(string)$v;
+        $simple = FALSE;
+    }
+    if ($ns) {
+      foreach ($ns as $nid => $name) {
+        foreach ($xml->current()->attributes($name) as $k => $v) {
+          $a[$key][$i][$nid . ':' . $k]=(string)$v;
+          $simple = FALSE;
+        }
+      }
+    }
+    if ($xml->hasChildren()) {
+        if ($simple) {
+          $a[$key][$i] = linkedin_connections_xml_to_array($xml->current(), $ns);
+
+        }
+        else {
+          $a[$key][$i]['content'] = linkedin_connections_xml_to_array($xml->current(), $ns);
+        }
+    }
+    else {
+        if ($simple) {
+          $a[$key][$i] = strval($xml->current());
+        }
+        else {
+          $a[$key][$i]['content'] = strval($xml->current());
+        }
+    }
+    $i++;
+  }
+  return $a;
+}
+
+
+/**
+ * Implements hook_block_info().
+ */
+function linkedin_connections_block_info() {
+  // provide block for linedin connections
+  $blocks['invite-connections'] = array(
+    'info' => t('Invite LinkedIn Connections'),
+    'cache' => DRUPAL_NO_CACHE,
+  );
+  return $blocks;
+}
+
+/**
+ * Implements hook_block_view().
+ */
+function linkedin_connections_block_view($delta) {
+
+  switch ($delta) {
+    case 'invite-connections':
+      $block['subject'] = t('Invite LinkedIn Connections');
+      $block['content'] = linkedin_connections_page();
+      break;
+  }
+
+  return $block;
+}
\ No newline at end of file
