function wordbooker_poll_facebook($single_user = null) { global $wpdb, $user_ID, $table_prefix, $blog_id; # If a user ID has been passed in then restrict to that single user. wordbooker_trim_errorlogs(); $limit_user = ""; if (isset($single_user)) { $limit_user = "******" . $single_user . " limit 1"; } $wordbooker_settings = get_option('wordbooker_settings'); # This runs through the Cached users and refreshes them $sql = "Select user_id,name from " . WORDBOOKER_USERDATA . $limit_user; $wb_users = $wpdb->get_results($sql); if (is_array($wb_users)) { wordbooker_debugger("Batch Cache Refresh Commence ", " ", -1, 9); foreach ($wb_users as $wb_user) { wordbooker_debugger("Calling Cache refresh for : ", $wb_user->name . " (" . $wb_user->id . ")", -1, 9); $wbuser = wordbooker_get_userdata($wb_user->user_id); # $fbclient = wordbooker_fbclient($wbuser); wordbooker_cache_refresh($wb_user->user_id); } wordbooker_debugger("Batch Cache Refresh completed ", " ", -1, 9); } }
function wordbooker_publish_remote($post_id) { global $blog_id; $post = get_post($post_id); wordbooker_debugger("Commence Remote publish ", " ", $post->ID, 80); $wordbooker_settings = wordbooker_options(); }
function wordbooker_notes_post($post_id, $access_token, $post_title, $target_id, $dummy, $target_name) { if (isset($dummy)) { wordbooker_debugger("Notes publish to " . $target_name . " Test Only", 'No Post Made', $post_id, 90); return; } global $post, $user_ID; $data = array('access_token' => $access_token, 'message' => preg_replace("/<script.*?>.*?<\\/script>/xmsi", "", apply_filters('the_content', $post->post_content)), 'subject' => $post_title); try { $result = wordbooker_fb_note_publish($data, $target_id); wordbooker_store_post_result($post_id, $result->id); wordbooker_debugger("Note Publish to " . $target_name . " result : ", $result->id, $post_id, 90); } catch (Exception $e) { $error_code = $e->getCode(); $error_msg = $e->getMessage(); wordbooker_append_to_errorlogs($method, $error_code, $error_msg, $post_id, $user_ID); wordbooker_debugger("Notes publish to " . $target_name . " fail : " . $error_msg, $error_code, $post_id, 99); } }
function wordbooker_get_comments_from_facebook($user_id) { global $wpdb, $blog_id, $comment_user; $processed_posts = 0; $wbuser = wordbooker_get_userdata($user_id); if (strlen($wbuser->access_token) < 20) { wordbooker_debugger("No user session for comment handling ", " ", -2, 9); return 0; } $wordbooker_settings = get_option('wordbooker_settings'); $comment_approve = 0; if (isset($wordbooker_settings['wordbook_comment_approve'])) { $comment_approve = 1; } $sql = 'Select distinct fb_post_id from ' . WORDBOOKER_POSTCOMMENTS . ' where fb_comment_id is null and user_id=' . $user_id . ' and blog_id=' . $blog_id . " and in_out is null "; $rows = $wpdb->get_results($sql); wordbooker_debugger("Blog posts with FB Posts against them : " . $sql, count($rows), -2, 98); foreach ($rows as $fb_comment) { wordbooker_debugger("Starting comment handling for FB post " . $fb_comment->fb_post_id, "", -2, 9); wordbooker_debugger("Starting comment handling for FB post " . $fb_comment->fb_post_id, "", -3, 9); # $sql="select fb_comment_id from ".WORDBOOKER_POSTCOMMENTS." where fb_post_id='".$fb_comment->fb_post_id."' and in_out!='out' and in_out!='stat' order by comment_timestamp desc"; # $from_comment=$wpdb->get_row($sql); try { $all_comments = wordbooker_fb_get_comments($fb_comment->fb_post_id, $wbuser->access_token); wordbooker_debugger("Comments pulled from Facebook", count($all_comments->data), -2, 9); } catch (Exception $e) { $error_msg = $e->getMessage(); $err_no = (int) substr($error_msg, 2, 3); wordbooker_debugger("Failed to get comment from Facebook : " . $error_msg, $row->fb_post_id, -2, 9); wordbooker_debugger("Failed to get comment from Facebook : " . $error_msg, $row->fb_post_id, -3, 9); } if (count($all_comments->data) > 0) { foreach ($all_comments->data as $single_comment) { # Now check that we don't already have this comment in the table as it means we've processed it before (or sent it to FB) $sql = "Select fb_comment_id from " . WORDBOOKER_POSTCOMMENTS . " where fb_comment_id='" . $single_comment->id . "'"; if (!$wpdb->query($sql)) { wordbooker_debugger("Found new comment for FB post " . $fb_comment->fb_post_id, "from : " . $single_comment->from->name, -2, 9); wordbooker_debugger("Found new comment for FB post " . $fb_comment->fb_post_id, "from : " . $single_comment->from->name, -3, 9); $commemail = $wordbooker_settings['wordbooker_comment_email']; $time = date("Y-m-d H:i:s", strtotime($single_comment->created_time)); $current_offset = get_option('gmt_offset'); $atime = date("Y-m-d H:i:s", strtotime($single_comment->created_time) + 3600 * $current_offset); $sql = "select distinct wp_post_id from " . WORDBOOKER_POSTCOMMENTS . " where fb_post_id='" . $fb_comment->fb_post_id . "'"; $wp_post_rows = $wpdb->get_results($sql); wordbooker_debugger("Blogs posts to send comment to : " . $sql, count($wp_post_rows), -2, 98); foreach ($wp_post_rows as $wp_post_row) { $wordbooker_post_options = get_post_meta($wp_post_row->wp_post_id, '_wordbooker_options', true); if (!isset($wordbooker_post_options['wordbooker_comment_get'])) { wordbooker_debugger("Incoming comments disabled for WP post " . $wp_post_row->wp_post_id, ' ', -2, 9); wordbooker_debugger("Incoming comments disabled for WP post " . $wp_post_row->wp_post_id, ' ', -3, 9); continue; } $data = array('comment_post_ID' => $wp_post_row->wp_post_id, 'comment_author' => $single_comment->from->name, 'comment_author_email' => $commemail, 'comment_author_url' => 'https://www.facebook.com/' . $single_comment->from->id, 'comment_content' => $single_comment->message, 'comment_author_IP' => '127.0.0.1', 'comment_date' => $atime, 'comment_date_gmt' => $time, 'comment_parent' => 0, 'user_id' => 0, 'comment_agent' => 'Wordbooker plugin ' . WORDBOOKER_CODE_RELEASE, 'comment_approved' => $comment_approve); $data = apply_filters('preprocess_comment', $data); $data['comment_parent'] = isset($data['comment_parent']) ? absint($data['comment_parent']) : 0; $parent_status = 0 < $data['comment_parent'] ? wp_get_comment_status($data['comment_parent']) : ''; $data['comment_parent'] = 'approved' == $parent_status || 'unapproved' == $parent_status ? $data['comment_parent'] : 0; $newComment = wp_insert_comment($data); update_comment_meta($newComment, "fb_uid", $single_comment->from->id); wordbooker_debugger("Inserted comment from " . $single_comment->from->name . " into " . $wp_post_row->wp_post_id, "", -2, 9); wordbooker_debugger("Inserted comment from " . $single_comment->from->name . " into " . $wp_post_row->wp_post_id, "", -3, 9); $sql = "Insert into " . WORDBOOKER_POSTCOMMENTS . " (fb_post_id,user_id,comment_timestamp,wp_post_id,blog_id,wp_comment_id,fb_comment_id,in_out) values ('" . $fb_comment->fb_post_id . "'," . $user_id . "," . strtotime($single_comment->created_time) . "," . $wp_post_row->wp_post_id . "," . $blog_id . "," . $newComment . ",'" . $single_comment->id . "','in' )"; $wpdb->query($sql); $processed_posts = $processed_posts + 1; } wordbooker_debugger("Finished comment inserts for FB post " . $fb_comment->fb_post_id, "", -2, 9); wordbooker_debugger("Finished comment inserts for FB post " . $fb_comment->fb_post_id, "", -3, 9); } else { wordbooker_debugger("Found existing comment for FB post " . $fb_comment->fb_post_id, "from : " . $single_comment->from->name, -2, 9); wordbooker_debugger("Found existing comment for FB post " . $fb_comment->fb_post_id, "from : " . $single_comment->from->name, -3, 9); } } } wordbooker_debugger("Finished comment handling for FB post " . $fb_comment->fb_post_id, "", -2, 9); wordbooker_debugger("Finished comment handling for FB post " . $fb_comment->fb_post_id, "", -3, 9); } return $processed_posts; }