-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxpost_comments.php
87 lines (71 loc) · 3.13 KB
/
xpost_comments.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/*
* Crossposting and broadcasting of comments
*/
/* Copyright 2009-2010 Jan Gosmann (email: jan@hyper-world.de)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
require_once( 'xpost_config.php' );
require_once( ABSPATH . WPINC . '/class-IXR.php' );
add_action( 'wp_set_comment_status', 'crosspost_comment', 10, 2 );
add_action( 'comment_post', 'crosspost_fresh_comment', 10, 2 );
/**
* Wrapper for crossposting a fresh comment which needs no approval.
*/
function crosspost_fresh_comment( $id, $approved ) {
if( $approved == '1' ) {
crosspost_comment( $id, 'approve' );
}
}
/**
* Crossposts and broadcasts an approved comment.
* @param $id commend ID
* @param $approved Should be "approved" when the comment was approved.
* Otherwise one of "delete", "spam" or "hold".
*/
function crosspost_comment( $id, $approved ) {
global $wpdb;
if( $approved != 'approve' ) {
return;
}
$comment = get_comment( $id, OBJECT );
$commentData = array();
$commentData['comment_parent'] = 0;
$commentData['content'] = $comment->comment_content;
$commentData['author'] = $comment->comment_author;
$commentData['author_url'] = $comment->comment_author_url;
$commentData['author_email'] = $comment->comment_author_email;
$broadcastUrl = get_post_meta( $comment->comment_post_ID, '_xpost_commet_broadcast_url', true );
if( !empty( $broadcastUrl ) ) {
$commentToken = get_post_meta( $comment->comment_post_ID, '_xpost_comment_token', true );
$excludeId = get_post_meta( $comment->comment_post_ID, '_xpost_comment_exclude_id', true );
$originalPost = get_post_meta( $comment->comment_post_ID, '_xpost_original_postid', true );
$client = new IXR_Client( $broadcastUrl );
$client->query( 'xpost.broadcastComment', $commentToken, $originalPost, $excludeId, $commentData );
}
$sql = "SELECT id, remote_postid FROM ".XPOST_POSTS_TABLE_NAME." WHERE local_postid = $comment->comment_post_ID";
$blogs = $wpdb->get_results( $sql );
foreach( $blogs as $blog ) {
if( get_post_meta( $comment->comment_post_ID, '_xpost_blog'.$blog->id, true ) != '1' ) {
continue;
}
if( get_post_meta( $comment->comment_post_ID, '_xpost_blog'.$blog->id.'_xpostComments', true ) != '1' ) {
continue;
}
$sql = "SELECT blogid, xmlrpc, user, password FROM ".XPOST_TABLE_NAME." WHERE id = $blog->id";
$blogUserData = $wpdb->get_row( $sql );
$client = new IXR_Client( $blogUserData->xmlrpc );
$client->query( 'xpost.newComment', $blogUserData->blogid, $blogUserData->user, $blogUserData->password, $blog->remote_postid, $commentData );
}
}
?>