本文整理汇总了PHP中groups_record_activity函数的典型用法代码示例。如果您正苦于以下问题:PHP groups_record_activity函数的具体用法?PHP groups_record_activity怎么用?PHP groups_record_activity使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了groups_record_activity函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: post_review
function post_review($args = '')
{
global $bp;
$defaults = array('content' => false, 'rating' => false, 'user_id' => $bp->loggedin_user->id, 'group_id' => $bp->groups->current_group->id);
$r = wp_parse_args($args, $defaults);
extract($r, EXTR_SKIP);
if (empty($content) || !strlen(trim($content)) || empty($user_id) || empty($group_id)) {
return false;
}
// Be sure the user is a member of the group before posting.
if (!is_super_admin() && !groups_is_user_member($user_id, $group_id)) {
return false;
}
// Record this in activity streams
$activity_action = sprintf(__('%s reviewed %s:', 'bpgr'), bp_core_get_userlink($user_id), '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . esc_html($bp->groups->current_group->name) . '</a>');
$rating_content = false;
if (!empty($rating)) {
$rating_content = '<span class="p-rating">' . bpgr_get_review_rating_html($rating) . '</span>';
}
$activity_content = $rating_content . $content;
$activity_id = groups_record_activity(array('user_id' => $user_id, 'action' => $activity_action, 'content' => $activity_content, 'type' => 'review', 'item_id' => $group_id));
$this->add_rating(array('score' => $rating, 'activity_id' => $activity_id, 'group_id' => $group_id));
groups_update_groupmeta($group_id, 'last_activity', gmdate("Y-m-d H:i:s"));
do_action('bpgr_posted_review', $args, $activity_id);
return $activity_id;
}
示例2: groups_screen_group_invites
/**
* Handle the loading of a user's Groups > Invites page.
*/
function groups_screen_group_invites()
{
$group_id = (int) bp_action_variable(1);
if (bp_is_action_variable('accept') && is_numeric($group_id)) {
// Check the nonce.
if (!check_admin_referer('groups_accept_invite')) {
return false;
}
if (!groups_accept_invite(bp_loggedin_user_id(), $group_id)) {
bp_core_add_message(__('Group invite could not be accepted', 'buddypress'), 'error');
} else {
bp_core_add_message(__('Group invite accepted', 'buddypress'));
// Record this in activity streams.
$group = groups_get_group(array('group_id' => $group_id));
groups_record_activity(array('type' => 'joined_group', 'item_id' => $group->id));
}
if (isset($_GET['redirect_to'])) {
$redirect_to = urldecode($_GET['redirect_to']);
} else {
$redirect_to = trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action());
}
bp_core_redirect($redirect_to);
} elseif (bp_is_action_variable('reject') && is_numeric($group_id)) {
// Check the nonce.
if (!check_admin_referer('groups_reject_invite')) {
return false;
}
if (!groups_reject_invite(bp_loggedin_user_id(), $group_id)) {
bp_core_add_message(__('Group invite could not be rejected', 'buddypress'), 'error');
} else {
bp_core_add_message(__('Group invite rejected', 'buddypress'));
}
if (isset($_GET['redirect_to'])) {
$redirect_to = urldecode($_GET['redirect_to']);
} else {
$redirect_to = trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action());
}
bp_core_redirect($redirect_to);
}
/**
* Fires before the loading of a users Groups > Invites template.
*
* @since 1.0.0
*
* @param int $group_id ID of the group being displayed
*/
do_action('groups_screen_group_invites', $group_id);
/**
* Filters the template to load for a users Groups > Invites page.
*
* @since 1.0.0
*
* @param string $value Path to a users Groups > Invites page template.
*/
bp_core_load_template(apply_filters('groups_template_group_invites', 'members/single/home'));
}
示例3: groups_left_group
function groups_left_group($group_id, $user_id = 0)
{
global $bp;
if (empty($user_id)) {
$user_id = bp_loggedin_user_id();
}
// Record this in activity streams
groups_record_activity(array('type' => 'left_group', 'item_id' => $group_id, 'user_id' => $user_id));
// Modify group meta
groups_update_groupmeta($group_id, 'last_activity', bp_core_current_time());
return true;
}
示例4: groups_screen_group_invites
function groups_screen_group_invites()
{
$group_id = (int) bp_action_variable(1);
if (bp_is_action_variable('accept') && is_numeric($group_id)) {
// Check the nonce
if (!check_admin_referer('groups_accept_invite')) {
return false;
}
if (!groups_accept_invite(bp_loggedin_user_id(), $group_id)) {
bp_core_add_message(__('Group invite could not be accepted', 'buddypress'), 'error');
} else {
bp_core_add_message(__('Group invite accepted', 'buddypress'));
// Record this in activity streams
$group = groups_get_group(array('group_id' => $group_id));
groups_record_activity(array('type' => 'joined_group', 'item_id' => $group->id));
}
if (isset($_GET['redirect_to'])) {
$redirect_to = urldecode($_GET['redirect_to']);
} else {
$redirect_to = trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action());
}
bp_core_redirect($redirect_to);
} else {
if (bp_is_action_variable('reject') && is_numeric($group_id)) {
// Check the nonce
if (!check_admin_referer('groups_reject_invite')) {
return false;
}
if (!groups_reject_invite(bp_loggedin_user_id(), $group_id)) {
bp_core_add_message(__('Group invite could not be rejected', 'buddypress'), 'error');
} else {
bp_core_add_message(__('Group invite rejected', 'buddypress'));
}
if (isset($_GET['redirect_to'])) {
$redirect_to = urldecode($_GET['redirect_to']);
} else {
$redirect_to = trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action());
}
bp_core_redirect($redirect_to);
}
}
do_action('groups_screen_group_invites', $group_id);
bp_core_load_template(apply_filters('groups_template_group_invites', 'members/single/home'));
}
示例5: groups_screen_group_invites
function groups_screen_group_invites()
{
$group_id = (int) bp_action_variable(1);
if (bp_is_action_variable('accept') && is_numeric($group_id)) {
// Check the nonce
if (!check_admin_referer('groups_accept_invite')) {
return false;
}
if (!groups_accept_invite(bp_loggedin_user_id(), $group_id)) {
bp_core_add_message(__('Group invite could not be accepted', 'buddypress'), 'error');
} else {
bp_core_add_message(__('Group invite accepted', 'buddypress'));
// Record this in activity streams
$group = new BP_Groups_Group($group_id);
groups_record_activity(array('action' => apply_filters_ref_array('groups_activity_accepted_invite_action', array(sprintf(__('%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink(bp_loggedin_user_id()), '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>'), bp_loggedin_user_id(), &$group)), 'type' => 'joined_group', 'item_id' => $group->id));
}
bp_core_redirect(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action());
} else {
if (bp_is_action_variable('reject') && is_numeric($group_id)) {
// Check the nonce
if (!check_admin_referer('groups_reject_invite')) {
return false;
}
if (!groups_reject_invite(bp_loggedin_user_id(), $group_id)) {
bp_core_add_message(__('Group invite could not be rejected', 'buddypress'), 'error');
} else {
bp_core_add_message(__('Group invite rejected', 'buddypress'));
}
bp_core_redirect(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action());
}
}
// Remove notifications
bp_core_delete_notifications_by_type(bp_loggedin_user_id(), 'groups', 'group_invite');
do_action('groups_screen_group_invites', $group_id);
bp_core_load_template(apply_filters('groups_template_group_invites', 'members/single/home'));
}
示例6: bp_groupblogs_fetch_group_feeds
function bp_groupblogs_fetch_group_feeds($group_id = false)
{
global $bp;
include_once ABSPATH . 'wp-includes/rss.php';
if (empty($group_id)) {
$group_id = $bp->groups->current_group->id;
}
if ($group_id == $bp->groups->current_group->id) {
$group = $bp->groups->current_group;
} else {
$group = new BP_Groups_Group($group_id);
}
if (!$group) {
return false;
}
$group_blogs = groups_get_groupmeta($group_id, 'blogfeeds');
$group_blogs = explode(";", $group_blogs[0]);
/* Set the visibility */
$hide_sitewide = 'public' != $group->status ? true : false;
foreach ((array) $group_blogs as $feed_url) {
$rss = fetch_feed(trim($feed_url));
if (!is_wp_error($rss)) {
foreach ($rss->get_items(0, 10) as $item) {
$key = $item->get_date('U');
$items[$key]['title'] = $item->get_title();
$items[$key]['subtitle'] = $item->get_title();
//$items[$key]['author'] = $item->get_author()->get_name();
$items[$key]['blogname'] = $item->get_feed()->get_title();
$items[$key]['link'] = $item->get_permalink();
$items[$key]['blogurl'] = $item->get_feed()->get_link();
$items[$key]['description'] = $item->get_description();
$items[$key]['source'] = $item->get_source();
$items[$key]['copyright'] = $item->get_copyright();
}
}
}
if ($items) {
ksort($items);
$items = array_reverse($items, true);
} else {
return false;
}
/* Record found blog posts in activity streams */
foreach ((array) $items as $post_date => $post) {
//var_dump($post);
if (substr($post['blogname'], 0, 7) == "Twitter") {
$activity_action = sprintf(__('%s from %s in the group %s', 'bp-groups-externalblogs'), '<a class="feed-link" href="' . esc_attr($post['link']) . '">Tweet</a>', '<a class="feed-author" href="' . esc_attr($post['blogurl']) . '">' . attribute_escape($post['blogname']) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . attribute_escape($group->name) . '</a>');
} else {
$activity_action = sprintf(__('Blog: %s from %s in the group %s', 'bp-groups-externalblogs'), '<a class="feed-link" href="' . esc_attr($post['link']) . '">' . esc_attr($post['title']) . '</a>', '<a class="feed-author" href="' . esc_attr($post['blogurl']) . '">' . attribute_escape($post['blogname']) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . attribute_escape($group->name) . '</a>');
}
$activity_content = '<div>' . strip_tags(bp_create_excerpt($post['description'], 175)) . '</div>';
$activity_content = apply_filters('bp_groupblogs_activity_content', $activity_content, $post, $group);
/* Fetch an existing activity_id if one exists. */
if (function_exists('bp_activity_get_activity_id')) {
$id = bp_activity_get_activity_id(array('user_id' => false, 'action' => $activity_action, 'component' => $bp->groups->id, 'type' => 'exb', 'item_id' => $group_id, 'secondary_item_id' => wp_hash($post['blogurl'])));
}
/* Record or update in activity streams. */
groups_record_activity(array('id' => $id, 'user_id' => false, 'action' => $activity_action, 'content' => $activity_content, 'primary_link' => $item->get_link(), 'type' => 'exb', 'item_id' => $group_id, 'secondary_item_id' => wp_hash($post['blogurl']), 'recorded_time' => gmdate("Y-m-d H:i:s", $post_date), 'hide_sitewide' => $hide_sitewide));
}
return $items;
}
示例7: groups_accept_membership_request
function groups_accept_membership_request( $membership_id, $user_id = false, $group_id = false ) {
global $bp;
if ( $user_id && $group_id )
$membership = new BP_Groups_Member( $user_id, $group_id );
else
$membership = new BP_Groups_Member( false, false, $membership_id );
$membership->accept_request();
if ( !$membership->save() )
return false;
/* Check if the user has an outstanding invite, if so delete it. */
if ( groups_check_user_has_invite( $membership->user_id, $membership->group_id ) )
groups_delete_invite( $membership->user_id, $membership->group_id );
/* Modify group member count */
groups_update_groupmeta( $membership->group_id, 'total_member_count', (int) groups_get_groupmeta( $membership->group_id, 'total_member_count') + 1 );
/* Record this in activity streams */
$group = new BP_Groups_Group( $membership->group_id );
groups_record_activity( array(
'action' => apply_filters( 'groups_activity_membership_accepted_action', sprintf( __( '%s joined the group %s', 'buddypress'), bp_core_get_userlink( $membership->user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ), $membership->user_id, &$group ),
'type' => 'joined_group',
'item_id' => $membership->group_id,
'user_id' => $membership->user_id
) );
/* Send a notification to the user. */
require_once ( BP_PLUGIN_DIR . '/bp-groups/bp-groups-notifications.php' );
groups_notification_membership_request_completed( $membership->user_id, $membership->group_id, true );
do_action( 'groups_membership_accepted', $membership->user_id, $membership->group_id );
return true;
}
示例8: bp_checkins_groups_post_update
function bp_checkins_groups_post_update($args = '')
{
global $bp;
$defaults = array('content' => false, 'user_id' => $bp->loggedin_user->id, 'group_id' => 0, 'type' => 'checkin', 'place_id' => false, 'place_name' => false, 'comment_id' => false, 'recorded_time' => bp_core_current_time());
$r = wp_parse_args($args, $defaults);
extract($r, EXTR_SKIP);
if (empty($group_id) && !empty($bp->groups->current_group->id)) {
$group_id = $bp->groups->current_group->id;
}
if ($type == "checkin" && (empty($content) || !strlen(trim($content)))) {
return false;
}
if (empty($user_id) || empty($group_id)) {
return false;
}
$bp->groups->current_group = new BP_Groups_Group($group_id);
// Be sure the user is a member of the group before posting.
if (!is_super_admin() && !groups_is_user_member($user_id, $group_id)) {
return false;
}
$from_user_link = bp_core_get_userlink($user_id);
if ($type == 'checkin') {
$activity_action = sprintf(__('%1$s added a checkin in the group %2$s', 'bp-checkins'), $from_user_link, '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . esc_attr($bp->groups->current_group->name) . '</a>');
$activity_content = $content;
$primary_link = bp_core_get_userlink($user_id, false, true);
$checkin_type = 'activity_checkin';
$item_id = $group_id;
$secondary_item_id = false;
} else {
if ($type == 'new_place' && !empty($place_id)) {
$place_permalink = '<a href="' . bp_get_checkins_places_the_permalink($place_id) . '" title="' . $place_name . '">' . $place_name . '</a>';
$activity_action = sprintf(__('%1$s added a new place %2$s in the group %3$s', 'bp-checkins'), $from_user_link, $place_permalink, '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . esc_attr($bp->groups->current_group->name) . '</a>');
$primary_link = bp_core_get_userlink($user_id, false, true);
$checkin_type = 'new_place';
$item_id = $group_id;
$activity_content = $content;
$secondary_item_id = $place_id;
} else {
if ($type == 'place_checkin' && !empty($place_id)) {
$place_permalink = '<a href="' . bp_get_checkins_places_the_permalink($place_id) . '" title="' . $place_name . '">' . $place_name . '</a>';
$activity_action = sprintf(__('%1$s checked-in %2$s in the group %3$s', 'bp-checkins'), $from_user_link, $place_permalink, '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . esc_attr($bp->groups->current_group->name) . '</a>');
$primary_link = bp_core_get_userlink($user_id, false, true);
$checkin_type = 'place_checkin';
$item_id = $group_id;
$activity_content = false;
$secondary_item_id = $place_id;
} else {
if ($type == 'place_comment' && !empty($place_id) && !empty($comment_id)) {
$place_permalink = '<a href="' . bp_get_checkins_places_the_permalink($place_id) . '" title="' . $place_name . '">' . $place_name . '</a>';
$activity_action = sprintf(__('%1$s added a comment on %2$s in the group %3$s', 'bp-checkins'), $from_user_link, $place_permalink, '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . esc_attr($bp->groups->current_group->name) . '</a>');
$primary_link = bp_core_get_userlink($user_id, false, true);
$checkin_type = 'place_comment';
$activity_content = $content;
$item_id = $group_id;
$secondary_item_id = $place_id;
} else {
if ($type == 'place_checkin_comment' && !empty($place_id) && !empty($comment_id)) {
$place_permalink = '<a href="' . bp_get_checkins_places_the_permalink($place_id) . '" title="' . $place_name . '">' . $place_name . '</a>';
$activity_action = sprintf(__('%1$s checked-in and added a comment on %2$s in the group %3$s', 'bp-checkins'), $from_user_link, $place_permalink, '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . esc_attr($bp->groups->current_group->name) . '</a>');
$primary_link = bp_core_get_userlink($user_id, false, true);
$checkin_type = 'place_comment';
$activity_content = $content;
$item_id = $group_id;
$secondary_item_id = $place_id;
}
}
}
}
}
$activity_id = groups_record_activity(array('user_id' => $user_id, 'component' => 'groups', 'action' => apply_filters('groups_activity_new_update_action', $activity_action), 'content' => apply_filters('groups_activity_new_update_content', $activity_content), 'type' => $checkin_type, 'item_id' => $group_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time));
if ($type == 'checkin') {
groups_update_groupmeta($group_id, 'last_activity', bp_core_current_time());
}
if ($checkin_type == 'place_comment') {
update_comment_meta($comment_id, 'group_place_activity_id', $activity_id);
}
do_action('bp_groups_posted_checkin', $content, $user_id, $group_id, $activity_id);
return $activity_id;
}
示例9: groups_update_group_forum_post
/**
* Update an existing group forum post.
*
* Uses the bundled version of bbPress packaged with BuddyPress.
*
* @since BuddyPress (1.1.0)
*
* @param int $post_id The post ID of the existing forum post.
* @param string $post_text The text for the forum post.
* @param int $topic_id The topic ID of the existing forum topic.
* @param mixed $page The page number where the new forum post should reside.
* Optional.
* @return mixed The forum post ID on success. Boolean false on failure.
*/
function groups_update_group_forum_post($post_id, $post_text, $topic_id, $page = false)
{
$bp = buddypress();
$post_text = apply_filters('group_forum_post_text_before_save', $post_text);
$topic_id = apply_filters('group_forum_post_topic_id_before_save', $topic_id);
$post = bp_forums_get_post($post_id);
$post_id = bp_forums_insert_post(array('post_id' => $post_id, 'post_text' => $post_text, 'post_time' => $post->post_time, 'topic_id' => $topic_id, 'poster_id' => $post->poster_id));
if (empty($post_id)) {
return false;
}
$topic = bp_forums_get_topic_details($topic_id);
$activity_action = sprintf(__('%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink($post->poster_id), '<a href="' . bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '">' . esc_attr($topic->topic_title) . '</a>', '<a href="' . bp_get_group_permalink(groups_get_current_group()) . '">' . esc_attr(bp_get_current_group_name()) . '</a>');
$activity_content = bp_create_excerpt($post_text);
$primary_link = bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '/';
if (!empty($page)) {
$primary_link .= "?topic_page=" . $page;
}
// Get the corresponding activity item
if (bp_is_active('activity')) {
$id = bp_activity_get_activity_id(array('user_id' => $post->poster_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post', 'item_id' => bp_get_current_group_id(), 'secondary_item_id' => $post_id));
}
// Update the entry in activity streams
groups_record_activity(array('id' => $id, 'action' => apply_filters_ref_array('groups_activity_new_forum_post_action', array($activity_action, $post_text, &$topic, &$topic)), 'content' => apply_filters_ref_array('groups_activity_new_forum_post_content', array($activity_content, $post_text, &$topic, &$topic)), 'primary_link' => apply_filters('groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id), 'type' => 'new_forum_post', 'item_id' => (int) bp_get_current_group_id(), 'user_id' => (int) $post->poster_id, 'secondary_item_id' => $post_id, 'recorded_time' => $post->post_time));
do_action_ref_array('groups_update_group_forum_post', array($post, &$topic));
return $post_id;
}
示例10: bp_ning_import_get_discussions
function bp_ning_import_get_discussions()
{
global $wpdb;
$ning_id_array = get_option('bp_ning_user_array');
// Get list of Ning groups for cross reference
$groups = bp_ning_import_prepare_json('groups');
$ning_group_id_array = get_option('bp_ning_group_array', array());
$discussions = bp_ning_import_prepare_json('discussions');
//delete_option('bp_ning_discussions_imported');
$imported = get_option('bp_ning_discussions_imported', array());
$counter = 0;
foreach ((array) $discussions as $discussion_key => $discussion) {
unset($topic_id);
if (isset($imported[$discussion->id])) {
continue;
}
if ($counter >= 10) {
update_option('bp_ning_discussions_imported', $imported);
printf(__('%d out of %d discussions done.'), count($imported), count($discussions));
return false;
}
$slug = sanitize_title(esc_attr($discussion->category));
$ning_group_creator_id = $discussion->contributorName;
$creator_id = $ning_id_array[$ning_group_creator_id];
if (!$creator_id) {
$what++;
continue;
}
$ndate = strtotime($discussion->createdDate);
$date_created = date("Y-m-d H:i:s", $ndate);
if (isset($discussion->category)) {
$ning_group_id = $discussion->category;
$group_id = $ning_group_id_array[$ning_group_id];
} else {
if (isset($discussion->groupId)) {
$ngroup_id = $discussion->groupId;
$group_id = $ning_group_id_array[$ngroup_id];
} else {
continue;
// todo fix me!
}
}
$group = new BP_Groups_Group($group_id);
$args = array('topic_title' => $discussion->title, 'topic_slug' => groups_check_slug(sanitize_title(esc_attr($discussion->title))), 'topic_text' => $discussion->description, 'topic_poster' => $creator_id, 'topic_poster_name' => bp_core_get_user_displayname($creator_id), 'topic_last_poster' => $creator_id, 'topic_last_poster_name' => bp_core_get_user_displayname($creator_id), 'topic_start_time' => $date_created, 'topic_time' => $date_created, 'forum_id' => groups_get_groupmeta($group_id, 'forum_id'));
$query = "SELECT `topic_id` FROM wp_bb_topics WHERE topic_title = '%s' AND topic_start_time = '%s' LIMIT 1";
$q = $wpdb->prepare($query, $args['topic_title'], $args['topic_start_time']);
$topic_exists = $wpdb->get_results($q);
if (isset($topic_exists[0])) {
echo "<em>- Topic {$discussion->title} already exists</em><br />";
$imported[$discussion->id] = true;
continue;
}
if (!$args['forum_id']) {
echo "No forum id - skipping";
continue;
}
if (!($topic_id = bp_forums_new_topic($args))) {
// TODO: WTF?
return false;
echo "<h2>Refresh to import more discussions</h2>";
die;
} else {
bp_ning_import_process_inline_images_new('discussions', $topic_id, 'topic');
echo "<strong>- Created topic: {$discussion->title}</strong><br />";
}
$activity_content = bp_create_excerpt($discussion->description);
$skip_activity = get_option('bp_ning_skip_forum_activity');
if (!$skip_activity) {
$topic = bp_forums_get_topic_details($topic_id);
// Activity item
$activity_action = sprintf(__('%s started the forum topic %s in the group %s:', 'buddypress'), bp_core_get_userlink($creator_id), '<a href="' . bp_get_group_permalink($group) . 'forum/topic/' . $topic->topic_slug . '/">' . esc_html($topic->topic_title) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . esc_html($group->name) . '</a>');
groups_record_activity(array('user_id' => $creator_id, 'action' => apply_filters('groups_activity_new_forum_topic_action', $activity_action, $discussion->description, $topic), 'content' => apply_filters('groups_activity_new_forum_topic_content', $activity_content, $discussion->description, $topic), 'primary_link' => apply_filters('groups_activity_new_forum_topic_primary_link', bp_get_group_permalink($group) . 'forum/topic/' . $topic->topic_slug . '/'), 'type' => 'new_forum_topic', 'item_id' => $group_id, 'secondary_item_id' => $topic->topic_id, 'recorded_time' => $date_created, 'hide_sitewide' => 0));
do_action('groups_new_forum_topic', $group_id, $topic);
}
// Now check for comments
if (isset($discussion->comments)) {
foreach ($discussion->comments as $reply) {
$ning_group_creator_id = $reply->contributorName;
$creator_id = $ning_id_array[$ning_group_creator_id];
$ndate = strtotime($reply->createdDate);
$date_created = date("Y-m-d H:i:s", $ndate);
$args = array('topic_id' => $topic_id, 'post_text' => $reply->description, 'post_time' => $date_created, 'poster_id' => $creator_id, 'poster_ip' => '192.168.1.1');
$query = "SELECT * FROM wp_bb_posts WHERE topic_id = '%s' AND post_text = '%s'";
$q = $wpdb->prepare($query, $args['topic_id'], $args['post_text']);
$post_exists = $wpdb->get_results($q);
if ($post_exists) {
continue;
}
$post_id = bp_forums_insert_post($args);
if ($post_id) {
bp_ning_import_process_inline_images_new('discussions', $post_id, 'topic_reply');
$import_summary = esc_html(bp_create_excerpt($reply->description, 100, array('html' => false)));
echo "<em>- Imported forum post: {$import_summary}</em><br />";
}
if (!groups_is_user_member($creator_id, $group_id)) {
if (!$bp->groups->current_group) {
$bp->groups->current_group = new BP_Groups_Group($group_id);
}
$new_member = new BP_Groups_Member();
$new_member->group_id = $group_id;
//.........这里部分代码省略.........
示例11: bp_group_management_join_group
function bp_group_management_join_group($group_id, $user_id = false)
{
global $bp;
if (!$user_id) {
$user_id = $bp->loggedin_user->id;
}
/* Check if the user has an outstanding invite, is so delete it. */
if (groups_check_user_has_invite($user_id, $group_id)) {
groups_delete_invite($user_id, $group_id);
}
/* Check if the user has an outstanding request, is so delete it. */
if (groups_check_for_membership_request($user_id, $group_id)) {
groups_delete_membership_request($user_id, $group_id);
}
/* User is already a member, just return true */
if (groups_is_user_member($user_id, $group_id)) {
return true;
}
if (!$bp->groups->current_group) {
$bp->groups->current_group = new BP_Groups_Group($group_id);
}
$new_member = new BP_Groups_Member();
$new_member->group_id = $group_id;
$new_member->user_id = $user_id;
$new_member->inviter_id = 0;
$new_member->is_admin = 0;
$new_member->user_title = '';
$new_member->date_modified = gmdate("Y-m-d H:i:s");
$new_member->is_confirmed = 1;
if (!$new_member->save()) {
return false;
}
/* Record this in activity streams */
groups_record_activity(array('user_id' => $user_id, 'action' => apply_filters('groups_activity_joined_group', sprintf(__('%s joined the group %s', 'bp-group-management'), bp_core_get_userlink($user_id), '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . esc_html($bp->groups->current_group->name) . '</a>')), 'type' => 'joined_group', 'item_id' => $group_id));
/* Modify group meta */
groups_update_groupmeta($group_id, 'total_member_count', (int) groups_get_groupmeta($group_id, 'total_member_count') + 1);
groups_update_groupmeta($group_id, 'last_activity', gmdate("Y-m-d H:i:s"));
do_action('groups_join_group', $group_id, $user_id);
return true;
}
示例12: save_event
/**
* Save or update a new event
* @version 2.0
*/
function save_event($post_id, $post = '')
{
// Don't do anything if it's not an event
if ('event' != $post->post_type) {
return;
}
// Verify the nonce before proceeding.
if (!isset($_POST['event-details-box']) || !wp_verify_nonce($_POST['event-details-box'], basename(__FILE__))) {
return $post_id;
}
/* -----------------------------------
SAVE EVENT TIME
------------------------------------*/
// Retrieve the event time
$event_time = date('Y-m-d H:i:s', strtotime($_POST['event-time']));
$prior_time = $post->post_date;
// Update the post object
$post->post_date = $event_time;
remove_action('save_post', array($this, 'save_event'));
wp_update_post($post);
add_action('save_post', array($this, 'save_event'), 10, 2);
/* -----------------------------------
SAVE META INFORMATION
------------------------------------ */
// Define the meta to look for
$meta = array('event_duration' => $_POST['event-duration'], 'event_capacity' => $_POST['event-capacity'], 'event_rsvp' => $_POST['event-rsvp'], 'event_role' => $_POST['event-role']);
// Loop through each meta, saving it to the database
foreach ($meta as $meta_key => $new_meta_value) {
// Get the meta value of the custom field key.
$meta_value = get_post_meta($post_id, $meta_key, true);
// If there is no new meta value but an old value exists, delete it.
if (current_user_can('delete_post_meta', $post_id, $meta_key) && '' == $new_meta_value && $meta_value) {
delete_post_meta($post_id, $meta_key, $meta_value);
} elseif (current_user_can('add_post_meta', $post_id, $meta_key) && $new_meta_value && '' == $meta_value) {
add_post_meta($post_id, $meta_key, $new_meta_value, true);
} elseif (current_user_can('edit_post_meta', $post_id, $meta_key) && $new_meta_value && $new_meta_value != $meta_value) {
update_post_meta($post_id, $meta_key, $new_meta_value);
}
}
// Delete the RSVP meta if the date has changed
if ($event_time != $prior_time) {
delete_post_meta($post_id, 'event_rsvps');
}
/* -----------------------------------
BUDDYPRESS NOTIFICATION
------------------------------------ */
// Get event data
global $bp, $wpdb;
if (!$user_id) {
$user_id = $post->post_author;
}
// Figure out which calendars this event belongs to
$calendars = wp_get_post_terms($post_id, 'calendar');
$group_slugs = array();
// For each calendar, check if it's a group calendar
foreach ($calendars as $calendar) {
if (is_group_calendar($calendar->term_id)) {
$groups[] = $calendar;
}
}
// If this event does not belong to a group, we can stop here
if (empty($groups)) {
return $post_id;
}
// Only register notifications for future or published events
if (!in_array($post->post_status, array('publish', 'future'))) {
return $post_id;
}
// Loop through each group, adding an activity entry for each one
foreach ($groups as $group) {
// Get the group data
$group_id = groups_get_id($group->slug);
$group_name = $group->name;
// Configure the activity entry
$post_permalink = get_permalink($post_id);
$activity_action = sprintf('%1$s added the event %2$s to the %3$s.', bp_core_get_userlink($post->post_author), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', $group_name . ' <a href="' . SITEURL . '/calendar/' . $group->slug . '">group calendar</a>');
$activity_content = $post->post_content;
// Check for existing entry
$activity_id = bp_activity_get_activity_id(array('user_id' => $user_id, 'component' => $bp->groups->id, 'type' => 'new_calendar_event', 'item_id' => $group_id, 'secondary_item_id' => $post_id));
// Record the entry
groups_record_activity(array('id' => $activity_id, 'user_id' => $user_id, 'action' => $activity_action, 'content' => $activity_content, 'primary_link' => $post_permalink, 'type' => 'new_calendar_event', 'item_id' => $group_id, 'secondary_item_id' => $post_id));
// Update the group's last activity meta
groups_update_groupmeta($group_id, 'last_activity', bp_core_current_time());
// Maybe notify every group member
if ($_POST['event-rsvp']) {
if (bp_group_has_members($args = array('group_id' => $group_id, 'exclude_admins_mods' => false, 'per_page' => 99999))) {
while (bp_members()) {
bp_the_member();
// Remove any existing notifications ( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false )
bp_notifications_delete_notifications_by_item_id(bp_get_group_member_id(), $group_id, $bp->groups->id, 'new_calendar_event', $post_id);
// Send a notification ( itemid , groupid , component, action , secondary )
bp_notifications_add_notification(array('user_id' => bp_get_group_member_id(), 'item_id' => $group_id, 'secondary_item_id' => $post_id, 'component_name' => $bp->groups->id, 'component_action' => 'new_calendar_event'));
}
}
}
}
//.........这里部分代码省略.........
示例13: bp_cover_group_handle_upload
function bp_cover_group_handle_upload($activity_id)
{
global $bp, $wpdb;
$group_id = bp_get_current_group_id();
$activity_table = $wpdb->prefix . "bp_activity";
$activity_meta_table = $wpdb->prefix . "bp_activity_meta";
$sql = "SELECT COUNT(*) as photo_count FROM {$activity_table} a INNER JOIN {$activity_meta_table} am ON a.id = am.activity_id WHERE a.item_id = %d AND meta_key = 'all_bp_cover_group'";
$sql = $wpdb->prepare($sql, $group_id);
$cnt = $wpdb->get_var($sql);
$max_cnt = bp_cover_get_max_total();
if ($cnt < $max_cnt) {
if ($_POST['encodedimg']) {
$file = $_POST['imgsize'];
$max_upload_size = bp_cover_get_max_media_size();
if ($max_upload_size > $file) {
$group_id = $bp->groups->current_group->id;
$imgresponse = array();
$uploaddir = wp_upload_dir();
/* let's decode the base64 encoded image sent */
$img = $_POST['encodedimg'];
$img = str_replace('data:' . $_POST['imgtype'] . ';base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$imgname = wp_unique_filename($uploaddir['path'], $_POST['imgname']);
$filepath = $uploaddir['path'] . '/' . $imgname;
$fileurl = $uploaddir['url'] . '/' . $imgname;
/* now we write the image in dir */
$success = file_put_contents($filepath, $data);
if ($success) {
$imgresponse[0] = "1";
$imgresponse[1] = $fileurl;
$size = @getimagesize($filepath);
$attachment = array('post_mime_type' => $_POST['imgtype'], 'guid' => $fileurl, 'post_title' => $imgname);
require_once ABSPATH . 'wp-admin/includes/image.php';
$attachment_id = wp_insert_attachment($attachment, $filepath);
$attach_data = wp_generate_attachment_metadata($attachment_id, $filepath);
wp_update_attachment_metadata($attachment_id, $attach_data);
groups_update_groupmeta($group_id, 'bp_cover_group', $fileurl);
groups_update_groupmeta($group_id, 'bp_cover_group_position', 0);
$group = groups_get_group(array("group_id" => $group_id));
$activity_id = groups_record_activity(array('action' => sprintf(__('%s uploaded a new cover picture to the group %s', 'bp-cover'), bp_core_get_userlink($bp->loggedin_user->id), '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>'), 'type' => 'cover_added', 'item_id' => $group_id, 'content' => bp_cover_group_get_image_scr(), 'item_id' => $group_id));
bp_activity_update_meta($activity_id, 'all_bp_cover_group', $attachment_id);
update_post_meta($attachment_id, 'bp_cover_group_thumb', $imgresponse[2]);
} else {
$imgresponse[0] = "0";
$imgresponse[1] = __('Upload Failed! Unable to write the image on server', 'bp-cover');
}
} else {
$imgresponse[0] = "0";
$imgresponse[1] = sprintf(__('The file you uploaded is too big. Please upload a file under %s', 'bp-cover'), size_format($max_upload_size));
}
} else {
$imgresponse[0] = "0";
$imgresponse[1] = __('Upload Failed! No image sent', 'bp-cover');
}
} else {
$imgresponse[0] = "0";
$imgresponse[1] = sprintf(__('Max total images allowed %d in a cover gallery', 'bp-cover'), $max_cnt);
}
/* if everything is ok, we send back url to thumbnail and to full image */
echo json_encode($imgresponse);
die;
}
示例14: activity_for_schedule
/**
* activity_for_schedule( $schedule_count, $type = "add" )
*
* Function generates activity updates on schedule actions
* @param Int $schedule_count, nr of added schedules
* @param String $type, the type of action: add - default, on schedule creations
*/
function activity_for_schedule($schedule_count, $type = "add")
{
global $bp;
$activity_action = sprintf(__('%s updated %s Courseware schedule.', 'bpsp'), bp_core_get_userlink($bp->loggedin_user->id), '<a href="' . bp_get_group_permalink($bp->groups->current_group) . '">' . attribute_escape($bp->groups->current_group->name) . '</a>');
$primary_link = bp_get_group_permalink($bp->groups->current_group) . 'courseware/schedules/';
groups_record_activity(array('action' => apply_filters('courseware_schedule_activity_action', $activity_action), 'primary_link' => apply_filters('courseware_schedule_activity_primary_link', $primary_link), 'type' => "schedule_{$type}", 'item_id' => $bp->groups->current_group->id));
}
示例15: groups_accept_membership_request
function groups_accept_membership_request($membership_id, $user_id = 0, $group_id = 0)
{
if (!empty($user_id) && !empty($group_id)) {
$membership = new BP_Groups_Member($user_id, $group_id);
} else {
$membership = new BP_Groups_Member(false, false, $membership_id);
}
$membership->accept_request();
if (!$membership->save()) {
return false;
}
// Check if the user has an outstanding invite, if so delete it.
if (groups_check_user_has_invite($membership->user_id, $membership->group_id)) {
groups_delete_invite($membership->user_id, $membership->group_id);
}
// Record this in activity streams
$group = groups_get_group(array('group_id' => $membership->group_id));
groups_record_activity(array('action' => apply_filters_ref_array('groups_activity_membership_accepted_action', array(sprintf(__('%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink($membership->user_id), '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>'), $membership->user_id, &$group)), 'type' => 'joined_group', 'item_id' => $membership->group_id, 'user_id' => $membership->user_id));
// Send a notification to the user.
groups_notification_membership_request_completed($membership->user_id, $membership->group_id, true);
do_action('groups_membership_accepted', $membership->user_id, $membership->group_id);
return true;
}