synchronise deletion of comments between red and wp

This commit is contained in:
friendica 2013-11-28 00:16:13 -08:00
parent 21e465e48a
commit aab9b30d03
3 changed files with 44 additions and 1 deletions

View File

@ -1101,6 +1101,16 @@ require_once('include/photos.php');
return false;
$id = $r[0]['iid'];
}
if($_REQUEST['namespace'] && $_REQUEST['comment_id']) {
$r = q("select * from item_id left join item on item.id = item_id.iid where service = '%s' and sid = '%s' and uid = %d and item.id != item.parent limit 1",
dbesc($_REQUEST['namespace']),
dbesc($_REQUEST['comment_id']),
intval($user_info['uid'])
);
if(! $r)
return false;
$id = $r[0]['iid'];
}
}
if(! $id)
return false;

View File

@ -148,6 +148,37 @@ function post_to_red_delete_post($post_id) {
}
}
function post_to_red_delete_comment($post_id) {
// The comment may already be destroyed so we can't query it or the parent post. That means
// we have to make a network call for any deleted comment to see if it's registered on Red.
// We really need a "before_delete_comment" action in WP to make
// this more efficient.
$user_name = post_to_red_get_acct_name();
$password = post_to_red_get_password();
$seed_location = post_to_red_get_seed_location();
$channel = post_to_red_get_channel_name();
if ((isset($user_name)) && (isset($password)) && (isset($seed_location))) {
$message_id = site_url() . '/' . $post_id;
$url = $seed_location . '/api/statuses/destroy';
$headers = array('Authorization' => 'Basic '.base64_encode("$user_name:$password"));
$body = array(
'namespace' => 'wordpress',
'comment_id' => $message_id,
);
if($channel)
$body['channel'] = $channel;
// post:
$request = new WP_Http;
$result = $request->request($url , array( 'method' => 'POST', 'body' => $body, 'headers' => $headers));
}
}
@ -259,6 +290,8 @@ add_action('add_meta_boxes', 'post_to_red_post_checkbox');
add_action('save_post', 'post_to_red_post_field_data');
add_action('before_delete_post', 'post_to_red_delete_post');
add_action('delete_comment', 'post_to_red_delete_comment');
add_filter('xmlrpc_methods', 'red_xmlrpc_methods');
add_filter('get_avatar', 'post_to_red_get_avatar',10,5);

View File

@ -1 +1 @@
2013-11-27.510
2013-11-28.511