posts A";
$ids = $wpdb->get_col($thisquery);
$permalinks = array();
foreach ($ids as $id) {
$permalinks[get_permalink($id)] = $id;
}
}
return $permalinks[$url];
}
function import_facebook_page($notesurl, $verbose = false, $allpages = false, $start = 0) {
$challenge = md5($time); // This is just a random 32-digit hex number.
$test_run = $_POST['test_run'];
$notespage = facebook_get_url($notesurl . ($start == 0 ? '' : "&start=$start"), $challenge, $start);
$dontimport = get_option('facebook_dont_import');
//
Next
$notenumber = 0;
$url2 = "";
$lines = explode("\n", $notespage);
//0.34 use default URL
$defaultURL = get_option('facebook_default_url');
// This was originally written in Perl, which is why there are so many bloody regexes everywhere.
foreach ($lines as $line) {
//James 0.21 removed space from note title
if ( strstr($line, '') ) {
// Get the title, original URL, and Facebook URL for each note
$notenumber = $notenumber + 1;
//James 0.21 removed space from note title
$line = preg_replace("/.*?
/", '($1)', $line);
$line = preg_replace("/<\/a><\/div>.*/", "", $line);
$tmp = preg_split("/[()]/", $line);
$url[$notenumber] = $tmp[1];
$line = preg_replace("/\(.*?\)/", "", $line);
$title[$notenumber] = $line;
$tmp = explode("?", $url[$notenumber]);
$url2 = $tmp[1];
} elseif ( strstr($line, "note_redirect.php?") && strstr($line, "View Original Post") && $wpURL[$notenumber] == "" ) {
$line3 = preg_replace("/.*?note_redirect.php?([^\"]+)\".*/", "$1", $line);
$line3 = urldecode($line3);
//$wpURL[$notenumber] = preg_replace("/.*?url=([^\"]+)\&h.*/", "", $line3;
$wpURL[$notenumber] = preg_replace("/.*?url=/", "", $line3);
// the following line was adding by Aaron Harp to get the real URL if it's pointing to a Feedburner one
if (strstr($wpURL[$notenumber], 'feedburner.com')) {
$wpURL[$notenumber] = get_real_url($wpURL[$notenumber]);
}
if ($verbose) {
print "Checking for comments on $wpURL[$notenumber]...
\n";
}
}
//0.26 This line had to be changed, because splitting the lines by a line feed stopped working.
//elseif ( preg_match("/#comments\">[0-9]+ comment/", $line) ) {
//if ( preg_match("/#comments\">[0-9]+ comment/", $line) ) {
//0.30 change to new comment matching
if ( preg_match('/>Comment<\/a>/', $line) ) {
// This entry has comments. Perhaps we should follow its link!
$getcomments[$notenumber] = "true";
$l2 = facebook_get_url("http://facebook.com/".$url[$notenumber], $challenge);
//James: Facebook now seems to not have line feeds, so split by sometime else
//$l2 = explode("\n", $l2);
//$l2 = explode('
', $l2);
//0.35
$l2 = explode('
\n"; } } // end "if line contains profile_link" } // next table cell } // end "if line contains profile_link" } // next line of file } // Done with this note } // Next line of file if ($allpages) { if ( preg_match("/notes.php?.*\">Next/", $notespage) ) { if ($verbose) { print "
Getting next page...
\n"; } import_facebook_page($notesurl, $verbose, $allpages, $start+10); } } } function import_facebook_page_test($notesurl, $verbose = false, $allpages = false, $start = 0) { $challenge = md5($time); // This is just a random 32-digit hex number. $test_run = $_POST['test_run']; $notespage = facebook_get_url($notesurl . ($start == 0 ? '' : "&start=$start"), $challenge, $start); $dontimport = get_option('facebook_dont_import'); //
\n"; } } //0.26 This line had to be changed, because splitting the lines by a line feed stopped working. //elseif ( preg_match("/#comments\">[0-9]+ comment/", $line) ) { //if ( preg_match("/#comments\">[0-9]+ comment/", $line) ) { //0.30 change to new comment matching if ( preg_match('/>Comment<\/a>/', $line) ) { // This entry has comments. Perhaps we should follow its link! $getcomments[$notenumber] = "true"; $l2 = facebook_get_url("http://facebook.com/".$url[$notenumber], $challenge); //James: Facebook now seems to not have line feeds, so split by sometime else //$l2 = explode("\n", $l2); //$l2 = explode('
"; //0.37 fix for multiple links in a comment. //if(preg_match($comment_content, '(.*?)<\/span>.*/", '$1', $comment_content); //$commentHalf3 = preg_replace("/.*<\/span>(.*?)<\/a>.*/", '$1', $comment_content); //$comment_content = $commentHalf1 . $commentHalf2 . $commentHalf3; //} else { // do nothing //} //0.36 update if(strstr($comment_content, "class=\"text_exposed_hide\"")) { $commentHalf1 = substr($comment_content, 0, strpos($comment_content, "(.*?)<\/span>.*/", '$1', $comment_content); $comment_content = $commentHalf1 . $commentHalf2; } else { //do nothing } //$comment_content = preg_replace("/.*span class=\"text_exposed_show\">(.*?)<\/span>.*/", '$1', $comment_content); $comment_author = $comment_author . " " . get_option('facebook_add_to_author'); $when = str_replace("at ", "", $when); $when = str_replace("on ", "", $when); $epochtime = strtotime($when); print "---START COMMENT---
"; print "Comment Author: $comment_author
"; print "When: $when
"; print "Comment: $comment_content
"; print "---END COMMENT---
"; // Check if this comment exists already $addcomment = 1; global $wpdb; //$thisquery = "SELECT A.ID FROM $wpdb->posts A WHERE A.guid LIKE '$wpURL[$notenumber]'"; //$comment_post_ID = $wpdb->get_var($thisquery); if ($wpURL[$notenumber] == '') { print " Error, wordpress URL for post not stored... "; } else { $comment_post_ID = facebook_get_postid($wpURL[$notenumber]); if ($comment_post_ID == 0 || $comment_post_ID == '') { print " Error, original comment post $comment_post_ID not found... "; } else { $continue = true; if ($dontimport) { $comment_post = get_post($comment_post_ID); $continue = $comment_post->comment_status != 'closed'; } if ($verbose) { print " Comment found for post $comment_post_ID... "; } } } if ($verbose) { print "
\n"; } } // end "if line contains profile_link" } // next table cell } // end "if line contains profile_link" } // next line of file } // Done with this note } // Next line of file if ($allpages) { if ( preg_match("/notes.php?.*\">Next/", $notespage) ) { if ($verbose) { print "
Getting next page...
\n"; } import_facebook_page($notesurl, $verbose, $allpages, $start+10); } } } function import_facebook_comments() { // Start buffering ob_start(); import_facebook_page(get_option('facebook_notesURL'), get_option('facebook_plugin_verbose'), get_option('facebook_all_pages')); // Turn off buffering ob_end_flush(); return; } function import_facebook_comments_test() { // Start buffering ob_start(); import_facebook_page_test(get_option('facebook_notesURL'), get_option('facebook_plugin_verbose'), get_option('facebook_all_pages')); // Turn off buffering ob_end_flush(); return; } function facebook_activate() { // Add options add_option('facebook_add_to_author', " (via Facebook)", "Text to append to the comment author's name"); //0.34 add ability to add default author url add_option('facebook_default_url', " (via Facebook)", "Link to use instead of the facebook profile link"); add_option('facebook_auto_freq', "86400", "How often to automatically check Facebook to import comments"); // All other options are empty by default and so we'll add them when they have data, later. // Schedule if (!wp_next_scheduled('import_facebook_comments_hook')) { $freq = get_option('facebook_auto_freq'); if ($freq == 86400) { // Daily wp_schedule_event( time(), 'daily', 'import_facebook_comments_hook' ); } elseif ($freq == 3600) { // Hourly wp_schedule_event( time(), 'hourly', 'import_facebook_comments_hook' ); } else { // Turn off automatic checking. } } } function get_real_url($url) { $ch = curl_init(); // initialize curl handle curl_setopt($ch, CURLOPT_URL, $url); // set url to post to curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s if (!curl_exec($ch)) { return false; } return curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); } function get_facebook_auth() { add_submenu_page("options-general.php", "Facebook Comments", "Facebook Comments", 5, "facebooknotes.php", facebook_options_subpanel); } function facebook_options_subpanel() { if (! get_option('facebook_add_to_author')) { } if (isset($_POST['manual_run'])) { update_option('facebook_plugin_verbose', '1'); print '
'; print "Manually importing comments...
\n"; import_facebook_comments(); print '
'; print "Testing comments plugin...
\n"; import_facebook_comments_test(); print '