本文整理汇总了PHP中bp_activity_new_comment函数的典型用法代码示例。如果您正苦于以下问题:PHP bp_activity_new_comment函数的具体用法?PHP bp_activity_new_comment怎么用?PHP bp_activity_new_comment使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bp_activity_new_comment函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bp_activity_admin_reply
/**
* AJAX receiver for Activity replies via the admin screen. Adds a new activity
* comment, and returns HTML for a new table row.
*
* @since 1.6
*/
function bp_activity_admin_reply()
{
// Check nonce
check_ajax_referer('bp-activity-admin-reply', '_ajax_nonce-bp-activity-admin-reply');
$parent_id = !empty($_REQUEST['parent_id']) ? (int) $_REQUEST['parent_id'] : 0;
$root_id = !empty($_REQUEST['root_id']) ? (int) $_REQUEST['root_id'] : 0;
// $parent_id is required
if (empty($parent_id)) {
die('-1');
}
// If $root_id not set (e.g. for root items), use $parent_id
if (empty($root_id)) {
$root_id = $parent_id;
}
// Check that a reply has been entered
if (empty($_REQUEST['content'])) {
die(__('ERROR: Please type a reply.', 'buddypress'));
}
// Check parent activity exists
$parent_activity = new BP_Activity_Activity($parent_id);
if (empty($parent_activity->component)) {
die(__('ERROR: The item you are trying to reply to cannot be found, or it has been deleted.', 'buddypress'));
}
// @todo: Check if user is allowed to create new activity items
// if ( ! current_user_can( 'bp_new_activity' ) )
if (!is_super_admin()) {
die('-1');
}
// Add new activity comment
$new_activity_id = bp_activity_new_comment(array('activity_id' => $root_id, 'content' => $_REQUEST['content'], 'parent_id' => $parent_id));
// Fetch the new activity item, as we need it to create table markup to return
$new_activity = new BP_Activity_Activity($new_activity_id);
// This needs to be set for the BP_Activity_List_Table constructor to work
set_current_screen('toplevel_page_bp-activity');
// Set up an output buffer
ob_start();
$list_table = new BP_Activity_List_Table();
$list_table->single_row((array) $new_activity);
// Get table markup
$response = array('data' => ob_get_contents(), 'id' => $new_activity_id, 'position' => -1, 'what' => 'bp_activity');
ob_end_clean();
// Send response
$r = new WP_Ajax_Response();
$r->add($response);
$r->send();
exit;
}
示例2: test_get_activity_comments_format
/**
* @group get_activity_comments
*
* Verify the format of the activity comments array, for internal
* refactoring
*/
public function test_get_activity_comments_format()
{
$now = time();
$u1 = $this->factory->user->create();
$u2 = $this->factory->user->create();
$a1 = $this->factory->activity->create(array('content' => 'Life Rules', 'recorded_time' => date('Y-m-d H:i:s', $now), 'user_id' => $u1));
$a2 = bp_activity_new_comment(array('activity_id' => $a1, 'content' => 'Candy is good', 'recorded_time' => date('Y-m-d H:i:s', $now - 50), 'user_id' => $u1));
$a3 = bp_activity_new_comment(array('activity_id' => $a1, 'content' => 'Bread is good', 'recorded_time' => date('Y-m-d H:i:s', $now - 25), 'user_id' => $u2));
$keys = array('id', 'item_id', 'secondary_item_id', 'user_id', 'primary_link', 'component', 'type', 'action', 'content', 'date_recorded', 'hide_sitewide', 'mptt_left', 'mptt_right', 'is_spam');
$a2_obj = new BP_Activity_Activity($a2);
$e2 = new stdClass();
foreach ($keys as $key) {
$e2->{$key} = $a2_obj->{$key};
}
$e2_user = new WP_User($a2_obj->user_id);
$e2->user_email = $e2_user->user_email;
$e2->user_nicename = $e2_user->user_nicename;
$e2->user_login = $e2_user->user_login;
$e2->display_name = $e2_user->display_name;
$e2->user_fullname = bp_core_get_user_displayname($e2->user_id);
$e2->children = array();
$e2->depth = 1;
$a3_obj = new BP_Activity_Activity($a3);
$e3 = new stdClass();
foreach ($keys as $key) {
$e3->{$key} = $a3_obj->{$key};
}
$e3_user = new WP_User($e3->user_id);
$e3->user_email = $e3_user->user_email;
$e3->user_nicename = $e3_user->user_nicename;
$e3->user_login = $e3_user->user_login;
$e3->display_name = $e3_user->display_name;
$e3->user_fullname = bp_core_get_user_displayname($e3->user_id);
$e3->children = array();
$e3->depth = 1;
$expected = array($a2 => $e2, $a3 => $e3);
$a1_obj = new BP_Activity_Activity($a1);
$comments = BP_Activity_Activity::get_activity_comments($a1, $a1_obj->mptt_left, $a1_obj->mptt_right, 'ham_only', $a1);
$this->assertEquals($expected, $comments);
}
示例3: test_bp_has_activities_with_type_new_blog_comments
/**
* @group bp_has_activities
*/
public function test_bp_has_activities_with_type_new_blog_comments()
{
add_filter('bp_disable_blogforum_comments', '__return_false');
$u = $this->factory->user->create();
$now = time();
$a1 = $this->factory->activity->create(array('content' => 'Life Rules', 'component' => 'blogs', 'type' => 'new_blog_post', 'recorded_time' => date('Y-m-d H:i:s', $now), 'user_id' => $u));
$a2 = $this->factory->activity->create(array('content' => 'Life Drools', 'component' => 'blogs', 'type' => 'new_blog_comment', 'recorded_time' => date('Y-m-d H:i:s', $now - 100), 'user_id' => $u));
// This one will show up in the stream because it's a comment
// on a blog post
$a3 = bp_activity_new_comment(array('activity_id' => $a1, 'content' => 'Candy is good', 'recorded_time' => date('Y-m-d H:i:s', $now - 200), 'user_id' => $u));
$a4 = $this->factory->activity->create(array('content' => 'Life Rulez', 'component' => 'activity', 'type' => 'activity_update', 'recorded_time' => date('Y-m-d H:i:s', $now - 300), 'user_id' => $u));
// This one should not show up in the stream because it's a
// comment on an activity item
$a5 = bp_activity_new_comment(array('activity_id' => $a4, 'content' => 'Candy is great', 'recorded_time' => date('Y-m-d H:i:s', $now - 400), 'user_id' => $u));
global $activities_template;
// prime
bp_has_activities(array('component' => 'blogs', 'action' => 'new_blog_comment'));
$this->assertEquals(array($a3, $a2), wp_parse_id_list(wp_list_pluck($activities_template->activities, 'id')));
// Clean up
$activities_template = null;
remove_filter('bp_disable_blogforum_comments', '__return_false');
}
示例4: bp_legacy_theme_new_activity_comment
/**
* Posts new Activity comments received via a POST request.
*
* @global BP_Activity_Template $activities_template
* @return string HTML
* @since BuddyPress (1.2)
*/
function bp_legacy_theme_new_activity_comment()
{
global $activities_template;
// Bail if not a POST action
if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
return;
}
// Check the nonce
check_admin_referer('new_activity_comment', '_wpnonce_new_activity_comment');
if (!is_user_logged_in()) {
exit('-1');
}
if (empty($_POST['content'])) {
exit('-1<div id="message" class="error"><p>' . __('Please do not leave the comment area blank.', 'buddypress') . '</p></div>');
}
if (empty($_POST['form_id']) || empty($_POST['comment_id']) || !is_numeric($_POST['form_id']) || !is_numeric($_POST['comment_id'])) {
exit('-1<div id="message" class="error"><p>' . __('There was an error posting that reply, please try again.', 'buddypress') . '</p></div>');
}
$comment_id = bp_activity_new_comment(array('activity_id' => $_POST['form_id'], 'content' => $_POST['content'], 'parent_id' => $_POST['comment_id']));
if (!$comment_id) {
exit('-1<div id="message" class="error"><p>' . __('There was an error posting that reply, please try again.', 'buddypress') . '</p></div>');
}
// Load the new activity item into the $activities_template global
bp_has_activities('display_comments=stream&hide_spam=false&include=' . $comment_id);
// Swap the current comment with the activity item we just loaded
if (isset($activities_template->activities[0])) {
$activities_template->activity = new stdClass();
$activities_template->activity->id = $activities_template->activities[0]->item_id;
$activities_template->activity->current_comment = $activities_template->activities[0];
}
// get activity comment template part
bp_get_template_part('activity/comment');
unset($activities_template);
exit;
}
示例5: bp_activity_action_post_comment
/**
* Post new activity comment.
*
* @since 1.2.0
*
* @uses is_user_logged_in()
* @uses bp_is_activity_component()
* @uses bp_is_current_action()
* @uses check_admin_referer()
* @uses apply_filters() To call 'bp_activity_post_comment_activity_id' hook.
* @uses apply_filters() To call 'bp_activity_post_comment_content' hook.
* @uses bp_core_add_message()
* @uses bp_core_redirect()
* @uses bp_activity_new_comment()
* @uses wp_get_referer()
*
* @return bool False on failure.
*/
function bp_activity_action_post_comment()
{
if (!is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action('reply')) {
return false;
}
// Check the nonce.
check_admin_referer('new_activity_comment', '_wpnonce_new_activity_comment');
/**
* Filters the activity ID a comment will be in reply to.
*
* @since 1.2.0
*
* @param string $value ID of the activity being replied to.
*/
$activity_id = apply_filters('bp_activity_post_comment_activity_id', $_POST['comment_form_id']);
/**
* Filters the comment content for a comment reply.
*
* @since 1.2.0
*
* @param string $value Comment content being posted.
*/
$content = apply_filters('bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id]);
if (empty($content)) {
bp_core_add_message(__('Please do not leave the comment area blank.', 'buddypress'), 'error');
bp_core_redirect(wp_get_referer() . '#ac-form-' . $activity_id);
}
$comment_id = bp_activity_new_comment(array('content' => $content, 'activity_id' => $activity_id, 'parent_id' => false));
if (!empty($comment_id)) {
bp_core_add_message(__('Reply Posted!', 'buddypress'));
} else {
bp_core_add_message(__('There was an error posting that reply. Please try again.', 'buddypress'), 'error');
}
bp_core_redirect(wp_get_referer() . '#ac-form-' . $activity_id);
}
示例6: test_bp_blogs_sync_activity_edit_to_post_comment_trash_comment_ham_activity
/**
* @group bp_blogs_sync_activity_edit_to_post_comment
* @group post_type_comment_activities
* @group imath
*/
public function test_bp_blogs_sync_activity_edit_to_post_comment_trash_comment_ham_activity()
{
$old_user = get_current_user_id();
$u = $this->factory->user->create();
$this->set_current_user($u);
$userdata = get_userdata($u);
// let's use activity comments instead of single "new_blog_comment" activity items
add_filter('bp_disable_blogforum_comments', '__return_false');
// create the blog post
$post_id = $this->factory->post->create(array('post_status' => 'publish', 'post_type' => 'post', 'post_title' => 'Test activity comment to post comment'));
// grab the activity ID for the activity comment
$a1 = bp_activity_get_activity_id(array('type' => 'new_blog_post', 'component' => buddypress()->blogs->id, 'filter' => array('item_id' => get_current_blog_id(), 'secondary_item_id' => $post_id)));
$a2 = bp_activity_new_comment(array('content' => 'the generated comment should be spamed/unspamed once the activity comment is spamed/unspamed', 'user_id' => $u, 'activity_id' => $a1));
$c = bp_activity_get_meta($a2, 'bp_blogs_post_comment_id');
wp_trash_comment($c);
$activity = new BP_Activity_Activity($a2);
bp_activity_mark_as_ham($activity);
$activity->save();
$post_comments = get_comments(array('post_id' => $post_id, 'status' => 'approve'));
$comment = reset($post_comments);
$this->assertTrue((int) $comment->comment_ID === (int) bp_activity_get_meta($a2, 'bp_blogs_post_comment_id'), 'The comment ID should be in the activity meta');
$this->assertTrue((int) $a2 === (int) get_comment_meta($comment->comment_ID, 'bp_activity_comment_id', true), 'The activity ID should be in the comment meta');
// reset
remove_filter('bp_disable_blogforum_comments', '__return_false');
$this->set_current_user($old_user);
}
示例7: bp_dtheme_new_activity_comment
function bp_dtheme_new_activity_comment()
{
// Bail if not a POST action
if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
return;
}
// Check the nonce
check_admin_referer('new_activity_comment', '_nxtnonce_new_activity_comment');
if (!is_user_logged_in()) {
echo '-1';
return false;
}
if (empty($_POST['content'])) {
echo '-1<div id="message" class="error"><p>' . __('Please do not leave the comment area blank.', 'buddypress') . '</p></div>';
return false;
}
if (empty($_POST['form_id']) || empty($_POST['comment_id']) || !is_numeric($_POST['form_id']) || !is_numeric($_POST['comment_id'])) {
echo '-1<div id="message" class="error"><p>' . __('There was an error posting that reply, please try again.', 'buddypress') . '</p></div>';
return false;
}
$comment_id = bp_activity_new_comment(array('activity_id' => $_POST['form_id'], 'content' => $_POST['content'], 'parent_id' => $_POST['comment_id']));
if (!$comment_id) {
echo '-1<div id="message" class="error"><p>' . __('There was an error posting that reply, please try again.', 'buddypress') . '</p></div>';
return false;
}
global $activities_template;
// Load the new activity item into the $activities_template global
bp_has_activities('display_comments=stream&include=' . $comment_id);
// Swap the current comment with the activity item we just loaded
$activities_template->activity->id = $activities_template->activities[0]->item_id;
$activities_template->activity->current_comment = $activities_template->activities[0];
$template = locate_template('activity/comment.php', false, false);
// Backward compatibility. In older versions of BP, the markup was
// generated in the PHP instead of a template. This ensures that
// older themes (which are not children of bp-default and won't
// have the new template) will still work.
if (empty($template)) {
$template = BP_PLUGIN_DIR . '/bp-themes/bp-default/activity/comment.php';
}
load_template($template, false);
unset($activities_template);
}
示例8: check_return_comments
function check_return_comments()
{
global $rtmedia_query;
if ($rtmedia_query->action_query->action != 'comment') {
return;
}
if (isset($rtmedia_query->action_query->id) && count($_POST)) {
/**
* /media/comments [POST]
* Post a comment to the album by post id
*/
$nonce = $_REQUEST['rtmedia_comment_nonce'];
if (wp_verify_nonce($nonce, 'rtmedia_comment_nonce')) {
if (empty($_POST['comment_content'])) {
return false;
}
$comment = new RTMediaComment();
$attr = $_POST;
$mediaModel = new RTMediaModel();
$result = $mediaModel->get(array('id' => $rtmedia_query->action_query->id));
if (!isset($attr['comment_post_ID'])) {
$attr['comment_post_ID'] = $result[0]->media_id;
}
$id = $comment->add($attr);
if ($result[0]->activity_id != null) {
global $rtmedia_buddypress_activity;
remove_action("bp_activity_comment_posted", array($rtmedia_buddypress_activity, "comment_sync"), 10, 2);
if (function_exists('bp_activity_new_comment')) {
$comment_activity_id = bp_activity_new_comment(array('content' => $_POST['comment_content'], 'activity_id' => $result[0]->activity_id));
}
}
if (!empty($comment_activity_id)) {
update_comment_meta($id, 'activity_id', $comment_activity_id);
}
if (isset($_POST["rtajax"])) {
global $wpdb;
$comments = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->comments} WHERE comment_ID = %d", $id), ARRAY_A);
echo rmedia_single_comment($comments);
exit;
}
} else {
_e('Ooops !!! Invalid access. No nonce was found !!', 'buddypress-media');
}
}
}
示例9: bp_dtheme_new_activity_comment
function bp_dtheme_new_activity_comment() {
global $bp;
/* Check the nonce */
check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
if ( !is_user_logged_in() ) {
echo '-1';
return false;
}
if ( empty( $_POST['content'] ) ) {
echo '-1<div id="message" class="error"><p>' . __( 'Please do not leave the comment area blank.', 'buddypress' ) . '</p></div>';
return false;
}
if ( empty( $_POST['form_id'] ) || empty( $_POST['comment_id'] ) || !is_numeric( $_POST['form_id'] ) || !is_numeric( $_POST['comment_id'] ) ) {
echo '-1<div id="message" class="error"><p>' . __( 'There was an error posting that reply, please try again.', 'buddypress' ) . '</p></div>';
return false;
}
$comment_id = bp_activity_new_comment( array(
'content' => $_POST['content'],
'activity_id' => $_POST['form_id'],
'parent_id' => $_POST['comment_id']
));
if ( !$comment_id ) {
echo '-1<div id="message" class="error"><p>' . __( 'There was an error posting that reply, please try again.', 'buddypress' ) . '</p></div>';
return false;
}
if ( bp_has_activities ( 'include=' . $comment_id ) ) : ?>
<?php while ( bp_activities() ) : bp_the_activity(); ?>
<li id="acomment-<?php bp_activity_id() ?>">
<div class="acomment-avatar">
<?php bp_activity_avatar() ?>
</div>
<div class="acomment-meta">
<?php echo bp_core_get_userlink( bp_get_activity_user_id() ) ?> · <?php printf( __( '%s ago', 'buddypress' ), bp_core_time_since( bp_core_current_time() ) ) ?> ·
<a class="acomment-reply" href="#acomment-<?php bp_activity_id() ?>" id="acomment-reply-<?php echo esc_attr( $_POST['form_id'] ) ?>"><?php _e( 'Reply', 'buddypress' ) ?></a>
· <a href="<?php echo wp_nonce_url( $bp->root_domain . '/' . $bp->activity->slug . '/delete/' . bp_get_activity_id() . '?cid=' . $comment_id, 'bp_activity_delete_link' ) ?>" class="delete acomment-delete confirm"><?php _e( 'Delete', 'buddypress' ) ?></a>
</div>
<div class="acomment-content">
<?php bp_activity_content_body() ?>
</div>
</li>
<?php endwhile; ?>
<?php endif;
}
示例10: test_bp_blogs_comment_sync_activity_comment_for_custom_post_type
/**
* @group bp_blogs_comment_sync_activity_comment
* @group post_type_comment_activities
*/
public function test_bp_blogs_comment_sync_activity_comment_for_custom_post_type()
{
if (is_multisite()) {
$b = $this->factory->blog->create();
switch_to_blog($b);
add_filter('comment_flood_filter', '__return_false');
} else {
$b = get_current_blog_id();
}
$u = $this->factory->user->create();
$userdata = get_userdata($u);
$labels = array('name' => 'bars', 'singular_name' => 'bar');
register_post_type('foo', array('labels' => $labels, 'public' => true, 'supports' => array('comments')));
add_post_type_support('foo', 'buddypress-activity');
bp_activity_set_post_type_tracking_args('foo', array('comment_action_id' => 'new_foo_comment'));
add_filter('bp_disable_blogforum_comments', '__return_false');
$p = $this->factory->post->create(array('post_author' => $u, 'post_type' => 'foo'));
$a1 = bp_activity_get_activity_id(array('type' => 'new_foo', 'filter' => array('item_id' => $b, 'secondary_item_id' => $p)));
$c = wp_new_comment(array('comment_post_ID' => $p, 'comment_author' => $userdata->user_nicename, 'comment_author_url' => 'http://buddypress.org', 'comment_author_email' => $userdata->user_email, 'comment_content' => 'this is a foo comment', 'comment_type' => '', 'comment_parent' => 0, 'user_id' => $u));
$a2 = bp_activity_new_comment(array('content' => 'this should generate a new foo comment', 'user_id' => $u, 'activity_id' => $a1));
$activity_args = array('type' => 'activity_comment', 'display_comments' => 'stream', 'meta_query' => array(array('key' => 'bp_blogs_foo_comment_id', 'compare' => 'exists')));
$a = bp_activity_get($activity_args);
$aids = wp_list_pluck($a['activities'], 'id');
$cids = wp_list_pluck(get_approved_comments($p), 'comment_ID');
foreach ($aids as $aid) {
$this->assertTrue(in_array(bp_activity_get_meta($aid, 'bp_blogs_foo_comment_id'), $cids), 'The comment ID should be in the activity meta');
}
foreach ($cids as $cid) {
$this->assertTrue(in_array(get_comment_meta($cid, 'bp_activity_comment_id', true), $aids), 'The activity ID should be in the comment meta');
}
_unregister_post_type('foo');
if (is_multisite()) {
restore_current_blog();
remove_filter('comment_flood_filter', '__return_false');
}
remove_filter('bp_disable_blogforum_comments', '__return_false');
}
示例11: bp_dtheme_new_activity_comment
/**
* Posts new Activity comments received via a POST request.
*
* @global BP_Activity_Template $activities_template
* @return string HTML
* @since BuddyPress (1.2)
*/
function bp_dtheme_new_activity_comment()
{
global $activities_template;
// Bail if not a POST action
if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
return;
}
// Check the nonce
check_admin_referer('new_activity_comment', '_wpnonce_new_activity_comment');
if (!is_user_logged_in()) {
exit('-1');
}
if (empty($_POST['content'])) {
exit('-1<div id="message" class="error"><p>' . __('Please do not leave the comment area blank.', 'buddypress') . '</p></div>');
}
if (empty($_POST['form_id']) || empty($_POST['comment_id']) || !is_numeric($_POST['form_id']) || !is_numeric($_POST['comment_id'])) {
exit('-1<div id="message" class="error"><p>' . __('There was an error posting that reply, please try again.', 'buddypress') . '</p></div>');
}
$comment_id = bp_activity_new_comment(array('activity_id' => $_POST['form_id'], 'content' => $_POST['content'], 'parent_id' => $_POST['comment_id'], 'error_type' => 'wp_error'));
if (false === $comment_id) {
exit('-1<div id="message" class="error"><p>' . __('There was an error posting that reply, please try again.', 'buddypress') . '</p></div>');
} elseif (is_wp_error($comment_id)) {
exit('-1<div id="message" class="error bp-ajax-message"><p>' . esc_html($comment_id->get_error_message()) . '</p></div>');
}
// Load the new activity item into the $activities_template global
bp_has_activities('display_comments=stream&hide_spam=false&show_hidden=true&include=' . $comment_id);
// Swap the current comment with the activity item we just loaded
$activities_template->activity = new stdClass();
$activities_template->activity->id = $activities_template->activities[0]->item_id;
$activities_template->activity->current_comment = $activities_template->activities[0];
$template = locate_template('activity/comment.php', false, false);
/**
* Backward compatibility. In older versions of BP, the markup was
* generated in the PHP instead of a template. This ensures that
* older themes (which are not children of bp-default and won't
* have the new template) will still work.
*/
if (empty($template)) {
$template = buddypress()->plugin_dir . '/bp-themes/bp-default/activity/comment.php';
}
load_template($template, false);
unset($activities_template);
exit;
}
示例12: test_bp_activity_comment_on_deleted_activity
/**
* @group bp_activity_new_comment
* @group BP5907
*/
public function test_bp_activity_comment_on_deleted_activity()
{
$u = $this->factory->user->create();
$a = $this->factory->activity->create();
bp_activity_delete_by_activity_id($a);
$c = bp_activity_new_comment(array('activity_id' => $a, 'parent_id' => $a, 'content' => 'foo', 'user_id' => $u));
$this->assertEmpty($c);
}
示例13: rtmedia_api_process_add_rtmedia_comment_request
/**
* Post comment on activity_id or media_id
* @global type $this ->msg_server_error
* @global int $this ->ec_server_error
* @global int $this ->ec_invalid_media_id
* @global type $this ->msg_invalid_media_id
*/
function rtmedia_api_process_add_rtmedia_comment_request()
{
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
$this->rtmediajsonapifunction->rtmedia_api_media_activity_id_missing();
//Post comment errors
$ec_comment_content_missing = 800001;
$msg_comment_content_missing = esc_html__('comment content missing', 'buddypress-media');
$ec_comment_posted = 800002;
$msg_comment_posted = esc_html__('comment posted', 'buddypress-media');
//Fetch user id from token
$user_data = get_userdata($this->user_id);
$content = filter_input(INPUT_POST, 'content', FILTER_SANITIZE_STRING);
if (empty($content)) {
wp_send_json($this->rtmedia_api_response_object('FALSE', $ec_comment_content_missing, $msg_comment_content_missing));
}
if (empty($activity_id) && !empty($media_id)) {
$activity_id = $this->rtmediajsonapifunction->rtmedia_api_activityid_from_mediaid($media_id);
}
if (empty($activity_id)) {
wp_send_json($this->rtmedia_api_response_object('FALSE', $this->ec_invalid_media_id, $this->msg_invalid_media_id));
}
$args = array('content' => $content, 'activity_id' => intval($activity_id), 'user_id' => intval($this->user_id), 'parent_id' => false);
if (function_exists('bp_activity_new_comment')) {
$comment_id = bp_activity_new_comment($args);
}
if (isset($comment_id)) {
wp_send_json($this->rtmedia_api_response_object('TRUE', $ec_comment_posted, $msg_comment_posted));
} else {
wp_send_json($this->rtmedia_api_response_object('FALSE', $this->msg_server_error, $this->ec_server_error));
}
}
示例14: bp_blogs_comment_sync_activity_comment
/**
* Update Activity and blogs meta and eventually sync comment with activity comment
*
* @since 2.5.0
*
* @param int|bool $activity_id ID of recorded activity, or false if sync is active.
* @param WP_Comment|null $comment The comment object.
* @param array $activity_args Array of activity arguments.
* @param object|null $activity_post_object The post type tracking args object.
* @return int|bool Returns false if no activity, the activity id otherwise.
*/
function bp_blogs_comment_sync_activity_comment(&$activity_id, $comment = null, $activity_args = array(), $activity_post_object = null)
{
if (empty($activity_args) || empty($comment->post->ID) || empty($activity_post_object->comment_action_id)) {
return false;
}
// Set the current blog id.
$blog_id = get_current_blog_id();
// These activity metadatas are used to build the new_blog_comment action string
if (!empty($activity_id) && !empty($activity_args['item_id']) && 'new_blog_comment' === $activity_post_object->comment_action_id) {
// add some post info in activity meta
bp_activity_update_meta($activity_id, 'post_title', $comment->post->post_title);
bp_activity_update_meta($activity_id, 'post_url', esc_url_raw(add_query_arg('p', $comment->post->ID, home_url('/'))));
}
// Sync comment - activity comment
if (!bp_disable_blogforum_comments()) {
if (!empty($_REQUEST['action'])) {
$existing_activity_id = get_comment_meta($comment->comment_ID, 'bp_activity_comment_id', true);
if (!empty($existing_activity_id)) {
$activity_args['id'] = $existing_activity_id;
}
}
if (empty($activity_post_object)) {
$activity_post_object = bp_activity_get_post_type_tracking_args($comment->post->post_type);
}
if (isset($activity_post_object->action_id) && isset($activity_post_object->component_id)) {
// find the parent 'new_post_type' activity entry
$parent_activity_id = bp_activity_get_activity_id(array('component' => $activity_post_object->component_id, 'type' => $activity_post_object->action_id, 'item_id' => $blog_id, 'secondary_item_id' => $comment->comment_post_ID));
// Try to create a new activity item for the parent blog post.
if (empty($parent_activity_id)) {
$parent_activity_id = bp_activity_post_type_publish($comment->post->ID, $comment->post);
}
}
// we found the parent activity entry
// so let's go ahead and reconfigure some activity args
if (!empty($parent_activity_id)) {
// set the parent activity entry ID
$activity_args['activity_id'] = $parent_activity_id;
// now see if the WP parent comment has a BP activity ID
$comment_parent = 0;
if (!empty($comment->comment_parent)) {
$comment_parent = get_comment_meta($comment->comment_parent, 'bp_activity_comment_id', true);
}
// WP parent comment does not have a BP activity ID
// so set to 'new_' . post_type activity ID
if (empty($comment_parent)) {
$comment_parent = $parent_activity_id;
}
$activity_args['parent_id'] = $comment_parent;
$activity_args['skip_notification'] = true;
// could not find corresponding parent activity entry
// so wipe out $args array
} else {
$activity_args = array();
}
// Record in activity streams
if (!empty($activity_args)) {
$activity_id = bp_activity_new_comment($activity_args);
if (empty($activity_args['id'])) {
// The activity metadata to inform about the corresponding comment ID
bp_activity_update_meta($activity_id, "bp_blogs_{$comment->post->post_type}_comment_id", $comment->comment_ID);
// The comment metadata to inform about the corresponding activity ID
add_comment_meta($comment->comment_ID, 'bp_activity_comment_id', $activity_id);
// These activity metadatas are used to build the new_blog_comment action string
if ('new_blog_comment' === $activity_post_object->comment_action_id) {
bp_activity_update_meta($activity_id, 'post_title', $comment->post->post_title);
bp_activity_update_meta($activity_id, 'post_url', esc_url_raw(add_query_arg('p', $comment->post->ID, home_url('/'))));
}
}
/**
* Fires after an activity comment is added from a WP post comment.
*
* @since 2.6.0
*
* @param int $activity_id The activity comment ID.
* @param WP_Comment $post_type_comment WP Comment object.
* @param array $activity_args Activity comment arguments.
* @param object $activity_post_object The post type tracking args object.
*/
do_action('bp_blogs_comment_sync_activity_comment', $activity_id, $comment, $activity_args, $activity_post_object);
}
}
// Update the blogs last active date
bp_blogs_update_blogmeta($blog_id, 'last_activity', bp_core_current_time());
if ('new_blog_comment' === $activity_post_object->comment_action_id) {
/**
* Fires after BuddyPress has recorded metadata about a published blog post comment.
*
* @since 2.5.0
*
//.........这里部分代码省略.........
示例15: test_spammed_activity_comment_should_not_create_post_comment
/**
* @group bp_blogs_sync_activity_edit_to_post_comment
* @group post_type_comment_activities
*/
public function test_spammed_activity_comment_should_not_create_post_comment()
{
$old_user = get_current_user_id();
$u = $this->factory->user->create();
$this->set_current_user($u);
$userdata = get_userdata($u);
// let's use activity comments instead of single "new_blog_comment" activity items.
add_filter('bp_disable_blogforum_comments', '__return_false');
// create the blog post.
$post_id = $this->factory->post->create(array('post_status' => 'publish', 'post_type' => 'post', 'post_title' => 'Test activity comment to post comment'));
// Grab the activity ID for the activity comment.
$a1 = bp_activity_get_activity_id(array('type' => 'new_blog_post', 'component' => buddypress()->blogs->id, 'filter' => array('item_id' => get_current_blog_id(), 'secondary_item_id' => $post_id)));
// Set activity item to spam.
add_action('bp_activity_before_save', array($this, 'set_activity_to_spam'));
// Create spammed activity comment.
$a2 = bp_activity_new_comment(array('content' => 'this activity comment shoud not be created as a new post comment. yolo.', 'user_id' => $u, 'activity_id' => $a1));
// Grab post comments.
$approved_comments = get_approved_comments($post_id);
$comment = reset($approved_comments);
// Assert that post comment wasn't created.
$this->assertEmpty($comment);
// Reset.
remove_filter('bp_disable_blogforum_comments', '__return_false');
remove_action('bp_activity_before_save', array($this, 'set_activity_to_spam'));
$this->set_current_user($old_user);
}