/** * Post an activity update * * @since 1.2.0 * * @param array $args See docs for $defaults for details * * @global object $bp BuddyPress global settings * @uses nxt_parse_args() * @uses bp_core_is_user_spammer() * @uses bp_core_is_user_deleted() * @uses bp_core_get_userlink() * @uses bp_activity_add() * @uses apply_filters() To call the 'bp_activity_new_update_action' hook * @uses apply_filters() To call the 'bp_activity_new_update_content' hook * @uses apply_filters() To call the 'bp_activity_new_update_primary_link' hook * @uses bp_update_user_meta() * @uses nxt_filter_kses() * @uses do_action() To call the 'bp_activity_posted_update' hook * * @return int $activity_id The activity id */ function bp_activity_post_update($args = '') { global $bp; $defaults = array('content' => false, 'user_id' => $bp->loggedin_user->id); $r = nxt_parse_args($args, $defaults); extract($r, EXTR_SKIP); if (empty($content) || !strlen(trim($content))) { return false; } if (bp_core_is_user_spammer($user_id) || bp_core_is_user_deleted($user_id)) { return false; } // Record this on the user's profile $from_user_link = bp_core_get_userlink($user_id); $activity_action = sprintf(__('%s posted an update', 'buddypress'), $from_user_link); $activity_content = $content; $primary_link = bp_core_get_userlink($user_id, false, true); // Now write the values $activity_id = bp_activity_add(array('user_id' => $user_id, 'action' => apply_filters('bp_activity_new_update_action', $activity_action), 'content' => apply_filters('bp_activity_new_update_content', $activity_content), 'primary_link' => apply_filters('bp_activity_new_update_primary_link', $primary_link), 'component' => $bp->activity->id, 'type' => 'activity_update')); // Add this update to the "latest update" usermeta so it can be fetched anywhere. bp_update_user_meta($bp->loggedin_user->id, 'bp_latest_update', array('id' => $activity_id, 'content' => nxt_filter_kses($content))); do_action('bp_activity_posted_update', $content, $user_id, $activity_id); return $activity_id; }
/** * Return the activity latest update link. * * @since 1.2.0 * * @param int $user_id Defaults to 0 * * @global object $bp BuddyPress global settings * @uses bp_core_is_user_spammer() * @uses bp_core_is_user_deleted() * @uses bp_get_user_meta() * @uses apply_filters() To call the 'bp_get_activity_latest_update_excerpt' hook * @uses bp_create_excerpt() * @uses bp_get_root_domain() * @uses bp_get_activity_root_slug() * @uses apply_filters() To call the 'bp_get_activity_latest_update' hook * * @return string|bool $latest_update The activity latest update link. False on failure */ function bp_get_activity_latest_update($user_id = 0) { global $bp; if (!$user_id) { $user_id = $bp->displayed_user->id; } if (bp_core_is_user_spammer($user_id) || bp_core_is_user_deleted($user_id)) { return false; } if (!($update = bp_get_user_meta($user_id, 'bp_latest_update', true))) { return false; } $latest_update = apply_filters('bp_get_activity_latest_update_excerpt', trim(strip_tags(bp_create_excerpt($update['content'], 358)))); $latest_update .= ' <a href="' . bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $update['id'] . '/"> ' . __('View', 'buddypress') . '</a>'; return apply_filters('bp_get_activity_latest_update', $latest_update); }
function bp_forums_insert_post($args = '') { global $bp; do_action('bbpress_init'); $defaults = array('post_id' => false, 'topic_id' => false, 'post_text' => '', 'post_time' => bp_core_current_time(), 'poster_id' => $bp->loggedin_user->id, 'poster_ip' => $_SERVER['REMOTE_ADDR'], 'post_status' => 0, 'post_position' => false); $r = nxt_parse_args($args, $defaults); extract($r, EXTR_SKIP); if (!($post = bp_forums_get_post($post_id))) { $post_id = false; } if (!isset($topic_id)) { $topic_id = $post->topic_id; } if (empty($post_text)) { $post_text = $post->post_text; } if (!isset($post_time)) { $post_time = $post->post_time; } if (!isset($post_position)) { $post_position = $post->post_position; } if (empty($poster_id)) { return false; } if (bp_core_is_user_spammer($bp->loggedin_user->id) || bp_core_is_user_deleted($bp->loggedin_user->id)) { return false; } $post_id = bb_insert_post(array('post_id' => $post_id, 'topic_id' => $topic_id, 'post_text' => stripslashes(trim($post_text)), 'post_time' => $post_time, 'poster_id' => $poster_id, 'poster_ip' => $poster_ip, 'post_status' => $post_status, 'post_position' => $post_position)); if (!empty($post_id)) { do_action('bp_forums_new_post', $post_id); } return $post_id; }
/** * Record user activity to the database. Many functions use a "last active" feature to * show the length of time since the user was last active. * This function will update that time as a usermeta setting for the user every 5 minutes. * * @package BuddyPress Core * @global $userdata NXTClass user data for the current logged in user. * @uses bp_update_user_meta() BP function to update user metadata in the usermeta table. */ function bp_core_record_activity() { global $bp; if (!is_user_logged_in()) { return false; } $user_id = $bp->loggedin_user->id; if (bp_core_is_user_spammer($user_id) || bp_core_is_user_deleted($user_id)) { return false; } $activity = bp_get_user_meta($user_id, 'last_activity', true); if (!is_numeric($activity)) { $activity = strtotime($activity); } // Get current time $current_time = bp_core_current_time(); if (empty($activity) || strtotime($current_time) >= strtotime('+5 minutes', $activity)) { bp_update_user_meta($user_id, 'last_activity', $current_time); } }