(.*?)<\/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);
// 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 ($continue) {
$doescommentexist = $wpdb->get_var("SELECT count(A.comment_post_ID) FROM $wpdb->comments A WHERE A.comment_post_ID = '$comment_post_ID' AND A.comment_approved = '1' AND A.comment_author LIKE '$comment_author'");
if ($doescommentexist) {
// All that the above SQL tells us is that this person already has a comment for this entry in the database. However, we don't know whether they commented more than once on this particular note/entry. So, we've got a bit more work to do.
//James 0.21 this was broken in the original, get_row only returns one row, so it wouldn't work if someone comments more than once.
//$thesecomments = $wpdb->get_row("SELECT A.comment_content FROM $wpdb->comments A WHERE A.comment_post_ID = '$comment_post_ID' AND A.comment_approved = '1' AND A.comment_author LIKE '$comment_author'", ARRAY_N);
$thesecomments = $wpdb->get_col("SELECT A.comment_content FROM $wpdb->comments A WHERE A.comment_post_ID = '$comment_post_ID' AND A.comment_approved = '1' AND A.comment_author LIKE '$comment_author'",0);
foreach ($thesecomments as $thiscomment) {
// We want to strip down the comments, both from the database and from Facebook, to the bare minimum and then compare them. So no HTML, no whitespace, no anything that isn't A-Z, 0-9, or underscore.
$tc = urldecode($thiscomment);
$tc = preg_replace("/<[^>]*>/", "", $tc);
$tc = preg_replace("/\W/", "", $tc);
$fc = urldecode($comment_content);
$fc = preg_replace("/<[^>]*>/", "", $fc);
$fc = preg_replace("/\W/", "", $fc);
if (strcmp($tc, $fc) == 0) {
// If these are the same comment, don't add it again.
if ($verbose) {
print "already exists in Wordpress database.";
}
$addcomment = 0;
}
}
}
if ($addcomment == 1) {
print "not in Wordpress database. ";
if ($test_run) {
if ($verbose) {
print "Test run, skipping add...";
}
} else {
if ($verbose) {
print "Adding to Wordpress...";
}
// Insert the comment
if (get_option('facebook_fake_author_email')) {
$comment_author_email = get_option('facebook_fake_author_email');
} else {
$comment_author_email = $email;
}
$comment_date = date("Y-m-d H:i:s", $epochtime);
$comment_date_gmt = gmdate("Y-m-d H:i:s", $epochtime);
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_date');
$comment_ID = facebook_new_comment ($commentdata);
if ($verbose) {
print "OK!";
}
}
} // Done adding the comment now.
} else {
if ($verbose) {
print "Comments closed for this post, skipping.";
}
}
}
}
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 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']) || isset($_POST['test_run'])) {
update_option('facebook_plugin_verbose', '1');
print '';
print "Manually importing comments...
\n";
import_facebook_comments();
print '
';
update_option('facebook_plugin_verbose', '');
}
if (isset($_POST['info_update'])) {?>