/** * Update the associated Activity Id for a WordPress Comment * * @param type $comment_id * @param type $activity_id * @return type */ function mpp_comment_update_associated_activity_id($comment_id, $activity_id) { return mpp_update_comment_meta($comment_id, '_mpp_activity_id', $activity_id); }
/** * On New Activity Comment, Create a new shadow WordPress comment too * * @param type $comment_id * @param type $param * @param type $activity * @return type */ function mpp_activity_synchronize_reply_to_comment($comment_id, $param, $activity) { //it must be upload from activity //so lt us crea //check that the media was posted in activity $gallery_id = mpp_activity_get_gallery_id($activity->id); if (!$gallery_id) { return; } $bp_comment = new BP_Activity_Activity($comment_id); //now we need to add a comment // //my logic to find the parent may be flawed here, Needs a confirmation from other people if ($bp_comment->secondary_item_id != $activity->id) { $parent_id = $bp_comment->secondary_item_id; //this is a multilevel comment //we will add a child comment in wp too as the } else { $parent_id = $activity->id; } $wp_comment_parent_id = (int) mpp_activity_get_associated_comment_id($parent_id); //if we are here, It must be an activity where we have uploaded media //we will create a comment and add if ($wp_comment_parent_id > 0) { //we have a parent comment associated, so we will be adding a child comment $wp_comment = get_comment($wp_comment_parent_id); } $commetn_data = array('post_id' => $gallery_id, 'user_id' => get_current_user_id(), 'comment_parent' => $wp_comment_parent_id, 'comment_content' => $bp_comment->content, 'comment_type' => mpp_get_comment_type()); $new_comment_id = mpp_add_comment($commetn_data); //update comment meta if ($new_comment_id) { mpp_update_comment_meta($new_comment_id, '_mpp_activity_id', $comment_id); mpp_activity_update_associated_comment_id($comment_id, $new_comment_id); } }
function mpp_activity_create_comment_for_activity($activity_id) { if (!$activity_id || !mpp_get_option('activity_comment_sync')) { return; } $activity = new BP_Activity_Activity($activity_id); if ($activity->type != 'mpp_media_upload') { return; } $gallery_id = mpp_activity_get_gallery_id($activity_id); $media_id = mpp_activity_get_media_id($activity_id); //this is not MediaPress activity if (!$gallery_id && !$media_id) { return; } //parent post id for the comment $parent_id = $media_id > 0 ? $media_id : $gallery_id; //now, create a top level comment and save $comment_data = array('post_id' => $parent_id, 'user_id' => get_current_user_id(), 'comment_parent' => 0, 'comment_content' => $activity->content, 'comment_type' => mpp_get_comment_type()); $comment_id = mpp_add_comment($comment_data); //update comment meta if ($comment_id) { mpp_update_comment_meta($comment_id, '_mpp_activity_id', $activity_id); mpp_activity_update_associated_comment_id($activity_id, $comment_id); //also since there are media attched and we are mirroring activity, let us save the attached media too $media_ids = mpp_activity_get_attached_media_ids($activity_id); //it is a gallery upload post from activity if ($gallery_id && !empty($media_ids)) { //only available when sync is enabled if (function_exists('mpp_comment_update_attached_media_ids')) { mpp_comment_update_attached_media_ids($comment_id, $media_ids); } } //most probably a comment on media if (!empty($media_id)) { //should we add media as the comment meta? no, we don't need that at the moment } } }