*/ /* Content filter callback function to replace the page comment with the hResume */ function lnhr_callback($content) { if(!preg_match('//', $content)) { return $content; } $hresume = lnhr_get_linkedin_page(); $hresume = lnhr_stripout_hresume($hresume); return str_replace('', $hresume, $content); } function lnhr_get_linkedin_page() { global $linkedin_url; global $linkedin_server; // If Wordpress caching is enabled, get content from the cache $data = wp_cache_get('lnhr_data'); if ($data !== false) { return $data; } // Split up the URL $matches = array(); preg_match('/^http:\/\/([^\/]+)(\/.*)$/', $linkedin_url, $matches); $linkedin_server = $matches[1]; $page = $matches[2]; // Request the LinkedIn page $errno = 0; $errstr = ''; $fp = @fsockopen($linkedin_server, 80, $errno, $errstr, 30); if (!$fp) { return "

Error retrieving resume from LinkedIn

$linkedin_server
$page

Details: $errstr ($errno)

"; } else { $out = "GET $page HTTP/1.1\r\n"; $out .= "Host: $linkedin_server\r\n"; $out .= "Connection: Close\r\n\r\n"; $response = ''; fwrite($fp, $out); while (!feof($fp)) { $response .= fgets($fp, 128); } fclose($fp); $response = split("\r\n\r\n", $response); $headers = $response[0]; $data = $response[1]; } // If Wordpress caching is enabled, cache the content wp_cache_set('lnhr_data', $data, '', 3600); return $data; } function lnhr_stripout_hresume($content) { global $lnhr_your_name; global $linkedin_server; // Just grab the hResume part minus some extra LinkedIn junk // Kind of lazy, but maybe do some parsing in another version $hresume = strstr($content, '
'); $pos = strpos($hresume, '
'); if ($pos !== false) { $hresume = substr($hresume, 0, $pos); $hresume .= '
'; } // Remove any Javascript $hresume = preg_replace('/<[ \n\r]*script[^>]*>.*<[ \n\r]*\/script[^>]*>/si', '', $hresume); // Convert wiki style formatting to XHTML $hresume = preg_replace("/(
\s*){2,}\*[ ]([^\n\r]*)(\s*
)/si", "\n$2", $hresume); $hresume = preg_replace("/(<\/li>)\s*
/si", "$1\n", $hresume); // Make links clickable $hresume = preg_replace('/([^"\'])(http:\/\/[^\s]+)([^"\'])/i', '$1$2$3', $hresume); // Fix images $hresume = preg_replace('/.*?<\/p>/si', '', $hresume); $hresume = preg_replace('/<\/ul>[\s\r\n]*?
.*?
    (.*?)<\/div>/si', '$1', $hresume); // Markup abbrivations INCOMPLETE $hresume = preg_replace('/([^a-zA-Z0-9])(CVS)([^a-zA-Z0-9])/', '$1$2$3', $hresume); // Convert LinkedIn tags to XHTML $hresume = preg_replace('/<\s*br\s*>/si', '
    ', $hresume); // Why does LinkedIn repeat your name so much on the same page? $hresume = preg_replace('/'.$lnhr_your_name.'’s /si', '', $hresume); return $hresume; } add_filter('the_content', 'lnhr_callback', 50); ?>