/** * Updates status on linkedin * * @param string $update Text to be posted on microblogging site * @param array $post_content * @return void */ public static function update_linkedin($old, $mp, $dash, $update, $post_content, $post_ID, $post_title, $permalink, $post_content_actual, $featured_image_src) { if ($mp['val'] == 1 && $mp['type'] == 'text') { return; } $curl = new MicroblogPoster_Curl(); $linkedin_accounts = MicroblogPoster_Poster::get_accounts_by_mode('linkedin', $post_ID); if (!empty($linkedin_accounts)) { foreach ($linkedin_accounts as $linkedin_account) { if (MicroblogPoster_Poster::is_method_callable('MicroblogPoster_Poster_Pro', 'filter_single_account') && $dash == 1 && $mp['val'] == 0 && $old == 0) { $active = MicroblogPoster_Poster_Pro::filter_single_account($linkedin_account['account_id']); if ($active === false) { continue; } else { if (isset($active['message_format']) && $active['message_format']) { $linkedin_account['message_format'] = $active['message_format']; } } } elseif (MicroblogPoster_Poster::is_method_callable('MicroblogPoster_Poster_Enterprise', 'filter_single_account_mp') && $dash == 1 && $mp['val'] == 1 && $old == 0) { $active = MicroblogPoster_Poster_Enterprise::filter_single_account_mp($linkedin_account['account_id']); if ($active === false) { continue; } else { if (isset($active['message_format']) && $active['message_format']) { $linkedin_account['message_format'] = $active['message_format']; } } } elseif (MicroblogPoster_Poster::is_method_callable('MicroblogPoster_Poster', 'filter_single_account_old') && $dash == 1 && $mp['val'] == 0 && $old == 1) { $active = MicroblogPoster_Poster::filter_single_account_old($linkedin_account['account_id']); if ($active === false) { continue; } else { if (isset($active['message_format']) && $active['message_format']) { $linkedin_account['message_format'] = $active['message_format']; } } } if (!$linkedin_account['extra']) { continue; } if ($linkedin_account['message_format'] && $mp['val'] == 0) { $update = str_ireplace(MicroblogPoster_Poster::get_shortcodes(), $post_content, $linkedin_account['message_format']); } elseif ($linkedin_account['message_format'] && $mp['val'] == 1 && $mp['type'] == 'link') { $update = str_ireplace(MicroblogPoster_Poster::get_shortcodes_mp(), $post_content, $linkedin_account['message_format']); } elseif ($mp['val'] == 1 && $mp['type'] == 'text') { } else { $update = ""; } $extra = json_decode($linkedin_account['extra'], true); if (isset($extra['access_token'])) { $post_data = array(); $post_data['update'] = $update; $post_data['post_title'] = $post_title; $post_data['permalink'] = $permalink; $post_data['post_content_actual'] = $post_content_actual; $post_data['featured_image_src'] = $featured_image_src; $acc_extra = $extra; if (isset($extra['target_type']) && $extra['target_type'] == 'group' && isset($extra['group_id'])) { if (MicroblogPoster_Poster::is_method_callable('MicroblogPoster_Poster_Pro', 'update_linkedin_group')) { $result = MicroblogPoster_Poster_Pro::update_linkedin_group($curl, $acc_extra, $post_data); } $action_result = 2; if (!$result) { $action_result = 1; $result = "Success"; } } elseif (isset($extra['target_type']) && $extra['target_type'] == 'company' && isset($extra['company_id'])) { if (MicroblogPoster_Poster::is_method_callable('MicroblogPoster_Poster_Pro', 'update_linkedin_company')) { $result = MicroblogPoster_Poster_Pro::update_linkedin_company($curl, $acc_extra, $post_data); } $action_result = 2; if ($result && stripos($result, '<update-key>') !== false && stripos($result, '</update-key>') !== false) { $action_result = 1; $result = "Success"; } } else { $url = "https://api.linkedin.com/v1/people/~/shares/?oauth2_access_token={$extra['access_token']}"; $body = new stdClass(); $body->comment = $update; if (isset($extra['post_type']) && $extra['post_type'] == 'link') { $body->content = new stdClass(); $body->content->title = $post_title; $body->content->{'submitted-url'} = $permalink; $body->content->description = $post_content_actual; $picture_url = 'http://localhost/imageplaceholder.jpg'; // 180 wid, 110 hei if (isset($extra['default_image_url']) && $extra['default_image_url']) { $picture_url = $extra['default_image_url']; } if ($featured_image_src) { $picture_url = $featured_image_src; } $body->content->{'submitted-image-url'} = $picture_url; } $body->visibility = new stdClass(); $body->visibility->code = 'anyone'; $body_json = json_encode($body); $curl->set_headers(array('Content-Type' => 'application/json')); $result = $curl->send_post_data_json($url, $body_json); $action_result = 2; if ($result && stripos($result, '<update-key>') !== false && stripos($result, '</update-key>') !== false) { $action_result = 1; $result = "Success"; } } $log_data = array(); $log_data['account_id'] = $linkedin_account['account_id']; $log_data['account_type'] = "linkedin"; $log_data['username'] = $linkedin_account['username']; $log_data['post_id'] = $post_ID; $log_data['action_result'] = $action_result; $log_data['update_message'] = $update; $log_data['log_message'] = $result; if ($mp['val'] == 1) { $log_data['log_type'] = 'manual'; } elseif ($old == 1) { $log_data['log_type'] = 'old'; } MicroblogPoster_Poster::insert_log($log_data); } } } }