本文整理汇总了PHP中Social::Log方法的典型用法代码示例。如果您正苦于以下问题:PHP Social::Log方法的具体用法?PHP Social::Log怎么用?PHP Social::Log使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Social
的用法示例。
在下文中一共展示了Social::Log方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save_aggregated_comments
/**
* Saves the aggregated comments.
*
* @param object $post
* @param bool $skip_approval
* @return void
*/
public function save_aggregated_comments(&$post, $skip_approval = false)
{
if (isset($post->results[$this->_key])) {
global $wpdb;
foreach ($post->results[$this->_key] as $result) {
if (!isset($result->user->protected) or $result->user->protected == false) {
$account = (object) array('user' => (object) array('id' => $result->from_user_id, 'screen_name' => $result->from_user));
$class = 'Social_Service_' . $this->_key . '_Account';
$account = new $class($account);
$commentdata = array('comment_post_ID' => $post->ID, 'comment_type' => $result->comment_type, 'comment_author' => $wpdb->escape($account->username()), 'comment_author_email' => $wpdb->escape($this->_key . '.' . $account->id() . '@example.com'), 'comment_author_url' => $account->url(), 'comment_content' => $wpdb->escape($result->text), 'comment_date' => date('Y-m-d H:i:s', strtotime($result->created_at) + get_option('gmt_offset') * 3600), 'comment_date_gmt' => gmdate('Y-m-d H:i:s', strtotime($result->created_at)), 'comment_author_IP' => $_SERVER['SERVER_ADDR'], 'comment_agent' => 'Social Aggregator');
if ($skip_approval || apply_filters('social_approve_likes_and_retweets', false) && Social_Twitter::is_retweet(null, $result)) {
$commentdata['comment_approved'] = 1;
} else {
if (($commentdata = $this->allow_comment($commentdata, $result->id, $post)) === false) {
continue;
}
}
// sanity check to make sure this comment is not a duplicate
if ($this->is_duplicate_comment($post, $result->id)) {
Social::log('Result #:result_id already exists, skipping.', array('result_id' => $result->id), 'duplicate-comment');
continue;
}
Social::log('Saving #:result_id for account :account_id.', array('result_id' => $result->id, 'account_id' => $account->id()));
$comment_id = 0;
try {
Social::Log('Attempting to save commentdata: :commentdata', array('commentdata' => print_r($commentdata, true)));
$comment_id = wp_insert_comment($commentdata);
update_comment_meta($comment_id, 'social_account_id', addslashes_deep($result->from_user_id));
update_comment_meta($comment_id, 'social_profile_image_url', addslashes_deep($result->profile_image_url_https));
update_comment_meta($comment_id, 'social_status_id', addslashes_deep($result->id));
// Attempt to see if the comment is in response to an existing Tweet.
if (!isset($result->in_reply_to_status_id)) {
// This "should" only happen on tweets found on the URL search
foreach ($this->accounts() as $account) {
$response = $this->request($account, '1.1/statuses/show/' . $result->id)->body();
if (isset($response->in_reply_to_status_id)) {
if (!empty($response->in_reply_to_status_id)) {
$result->in_reply_to_status_id = $response->in_reply_to_status_id;
}
break;
}
}
}
if (isset($result->in_reply_to_status_id)) {
update_comment_meta($comment_id, 'social_in_reply_to_status_id', addslashes_deep($result->in_reply_to_status_id));
}
if (!isset($result->raw)) {
$result = (object) array_merge((array) $result, array('raw' => $result));
}
update_comment_meta($comment_id, 'social_raw_data', addslashes_deep(base64_encode(json_encode($result->raw))));
if ($commentdata['comment_approved'] !== 'spam') {
if ($commentdata['comment_approved'] == '0') {
wp_notify_moderator($comment_id);
}
if (get_option('comments_notify') and $commentdata['comment_approved'] and (!isset($commentdata['user_id']) or $post->post_author != $commentdata['user_id'])) {
wp_notify_postauthor($comment_id, 'comment');
}
}
} catch (Exception $e) {
// Something went wrong, remove the aggregated ID.
if (($key = array_search($result->id, $post->aggregated_ids['twitter'])) !== false) {
unset($post->aggregated_ids['twitter'][$key]);
}
if ((int) $comment_id) {
// Delete the comment in case it wasn't the insert that failed.
wp_delete_comment($comment_id);
}
}
}
}
}
}
示例2: save_aggregated_comments
/**
* Saves the aggregated comments.
*
* @param object $post
* @return void
*/
public function save_aggregated_comments(&$post)
{
if (isset($post->results[$this->_key])) {
global $wpdb;
foreach ($post->results[$this->_key] as $result) {
$commentdata = array('comment_post_ID' => $post->ID, 'comment_author_email' => $wpdb->escape($this->_key . '.' . $result->id . '@example.com'), 'comment_author_IP' => $_SERVER['SERVER_ADDR'], 'comment_agent' => 'Social Aggregator');
if (isset($result->parent)) {
if ($wp_parent = $this->get_comment_from_fb_id($result->parent->id)) {
$commentdata['comment_parent'] = $wp_parent->comment_id;
}
}
if (!isset($result->like)) {
$commentdata = array_merge($commentdata, array('comment_type' => 'social-facebook', 'comment_author' => $wpdb->escape($result->from->name), 'comment_author_url' => $result->from->link, 'comment_content' => $wpdb->escape($result->message), 'comment_date' => date('Y-m-d H:i:s', strtotime($result->created_time) + get_option('gmt_offset') * 3600), 'comment_date_gmt' => gmdate('Y-m-d H:i:s', strtotime($result->created_time))));
} else {
// v2.0+ returns app scoped ids, both app scoped ids and real ids redirect to the profile with
// https://www.facebook.com/{user-id}|{app-scoped-id}
$url = 'https://www.facebook.com/' . $result->id . '/';
$commentdata = array_merge($commentdata, array('comment_type' => 'social-facebook-like', 'comment_author' => $wpdb->escape($result->name), 'comment_author_url' => $url, 'comment_content' => $wpdb->escape('<a href="' . $url . '" target="_blank">' . $result->name . '</a> liked this on Facebook.'), 'comment_date' => current_time('mysql'), 'comment_date_gmt' => current_time('mysql', 1)));
}
$user_id = isset($result->like) ? $result->from_id : $result->from->id;
$commentdata = array_merge($commentdata, array('comment_post_ID' => $post->ID, 'comment_author_email' => $this->_key . '.' . $user_id . '@example.com'));
if (apply_filters('social_approve_likes_and_retweets', false) && isset($result->like)) {
$commentdata['comment_approved'] = 1;
} else {
if (($commentdata = $this->allow_comment($commentdata, $result->id, $post)) === false) {
continue;
}
}
Social::log('Saving #:result_id.', array('result_id' => $result->id));
$comment_id = 0;
try {
Social::Log('Attempting to save commentdata: :commentdata', array('commentdata' => print_r($commentdata, true)));
$comment_id = wp_insert_comment($commentdata);
update_comment_meta($comment_id, 'social_account_id', addslashes_deep($user_id));
update_comment_meta($comment_id, 'social_profile_image_url', addslashes_deep('https://graph.facebook.com/' . $user_id . '/picture'));
update_comment_meta($comment_id, 'social_status_id', addslashes_deep($result->status_id));
update_comment_meta($comment_id, 'social_broadcast_id', addslashes_deep($result->id));
if ($result->reply_to_id) {
update_comment_meta($comment_id, 'social_reply_to_id', addslashes_deep($result->reply_to_id));
}
if (!isset($result->raw)) {
$result = (object) array_merge((array) $result, array('raw' => $result));
}
update_comment_meta($comment_id, 'social_raw_data', addslashes_deep(base64_encode(json_encode($result->raw))));
if ($commentdata['comment_approved'] !== 'spam') {
if ($commentdata['comment_approved'] == '0') {
wp_notify_moderator($comment_id);
}
if (get_option('comments_notify') and $commentdata['comment_approved'] and (!isset($commentdata['user_id']) or $post->post_author != $commentdata['user_id'])) {
wp_notify_postauthor($comment_id, 'comment');
}
}
} catch (Exception $e) {
// Something went wrong, remove the aggregated ID.
if (($key = array_search($result->id, $post->aggregated_ids['facebook'])) !== false) {
unset($post->aggregated_ids['facebook'][$key]);
}
if ((int) $comment_id) {
// Delete the comment in case it wasn't the insert that failed.
wp_delete_comment($comment_id);
}
}
}
}
}
示例3: save_aggregated_comments
/**
* Saves the aggregated comments.
*
* @param object $post
* @return void
*/
public function save_aggregated_comments(&$post)
{
if (isset($post->results[$this->_key])) {
global $wpdb;
foreach ($post->results[$this->_key] as $result) {
$commentdata = array('comment_post_ID' => $post->ID, 'comment_author_email' => $wpdb->escape($this->_key . '.' . $result->id . '@example.com'), 'comment_author_IP' => $_SERVER['SERVER_ADDR'], 'comment_agent' => 'Social Aggregator');
if (!isset($result->like)) {
$url = 'http://graph.facebook.com/' . $result->from->id;
$request = wp_remote_get($url);
if (!is_wp_error($request)) {
$response = json_decode($request['body']);
$account = (object) array('user' => $response);
$class = 'Social_Service_' . $this->_key . '_Account';
$account = new $class($account);
$commentdata = array_merge($commentdata, array('comment_type' => 'social-facebook', 'comment_author' => $wpdb->escape($result->from->name), 'comment_author_url' => $account->url(), 'comment_content' => $wpdb->escape($result->message), 'comment_date' => date('Y-m-d H:i:s', strtotime($result->created_time) + get_option('gmt_offset') * 3600), 'comment_date_gmt' => gmdate('Y-m-d H:i:s', strtotime($result->created_time))));
}
} else {
$url = 'http://facebook.com/profile.php?id=' . $result->id;
$commentdata = array_merge($commentdata, array('comment_type' => 'social-facebook-like', 'comment_author' => $wpdb->escape($result->name), 'comment_author_url' => $url, 'comment_content' => $wpdb->escape('<a href="' . $url . '" target="_blank">' . $result->name . '</a> liked this on Facebook.'), 'comment_date' => current_time('mysql'), 'comment_date_gmt' => current_time('mysql', 1)));
}
$user_id = isset($result->like) ? $result->id : $result->from->id;
$commentdata = array_merge($commentdata, array('comment_post_ID' => $post->ID, 'comment_author_email' => $this->_key . '.' . $user_id . '@example.com'));
$result_id = isset($result->status_id) ? $result->status_id : $result->id;
if (apply_filters('social_approve_likes_and_retweets', true) && isset($result->like)) {
$commentdata['comment_approved'] = 1;
} else {
if (($commentdata = $this->allow_comment($commentdata, $result_id, $post)) === false) {
continue;
}
}
// sanity check to make sure this comment is not a duplicate
if ($this->is_duplicate_comment($post, $result->id)) {
Social::log('Result #:result_id already exists, skipping.', array('result_id' => $result->id), 'duplicate-comment');
continue;
}
Social::log('Saving #:result_id.', array('result_id' => isset($result->status_id) ? $result->status_id : $result->id));
$comment_id = 0;
try {
Social::Log('Attempting to save commentdata: :commentdata', array('commentdata' => print_r($commentdata, true)));
$comment_id = wp_insert_comment($commentdata);
update_comment_meta($comment_id, 'social_account_id', addslashes_deep($user_id));
update_comment_meta($comment_id, 'social_profile_image_url', addslashes_deep('http://graph.facebook.com/' . $user_id . '/picture'));
update_comment_meta($comment_id, 'social_status_id', addslashes_deep(isset($result->status_id) ? $result->status_id : $result->id));
if (!isset($result->raw)) {
$result = (object) array_merge((array) $result, array('raw' => $result));
}
update_comment_meta($comment_id, 'social_raw_data', addslashes_deep(base64_encode(json_encode($result->raw))));
if ($commentdata['comment_approved'] !== 'spam') {
if ($commentdata['comment_approved'] == '0') {
wp_notify_moderator($comment_id);
}
if (get_option('comments_notify') and $commentdata['comment_approved'] and (!isset($commentdata['user_id']) or $post->post_author != $commentdata['user_id'])) {
wp_notify_postauthor($comment_id, 'comment');
}
}
} catch (Exception $e) {
// Something went wrong, remove the aggregated ID.
if (($key = array_search(isset($result->status_id) ? $result->status_id : $result->id, $post->aggregated_ids['facebook'])) !== false) {
unset($post->aggregated_ids['facebook'][$key]);
}
if ((int) $comment_id) {
// Delete the comment in case it wasn't the insert that failed.
wp_delete_comment($comment_id);
}
}
}
}
}