Ejemplo n.º 1
0
/**
 * Catches an activity to reshare if js is enabled
 *
 * @package BP Reshare
 * @since    1.0
 *
 * @uses  check_ajax_referer() for security reasons
 * @uses  buddyreshare_prepare_reshare() to build the reshare arguments
 * @uses  bp_activity_add() to save the reshare
 */
function buddyreshare_handle_ajax_reshare()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    check_ajax_referer('buddyreshare_update', 'nonce');
    $response = array('result' => 'error', 'message' => __('OOps, error while trying to reshare..', 'bp-reshare'));
    $activity_id = intval($_POST['activity']);
    if (empty($activity_id)) {
        $response['message'] = __('The activity was not found.', 'bp-reshare');
        exit(json_encode($response));
    }
    $args = buddyreshare_prepare_reshare($activity_id);
    if (isset($args['error'])) {
        $response['message'] = $args['error'];
        exit(json_encode($response));
    }
    $reshare_id = bp_activity_add($args);
    if (!empty($reshare_id)) {
        do_action('buddyreshare_reshare_added', $reshare_id);
        $response['result'] = 'success';
        $response['message'] = __('Activity successfully reshared.', 'bp-reshare');
    } else {
        do_action('buddyreshare_reshare_added_error', $reshare_id);
    }
    exit(json_encode($response));
}
Ejemplo n.º 2
0
 private static function record_activity($args = array())
 {
     // Default activity args
     $activity = array_merge(array('id' => null, 'user_id' => get_current_user_id(), 'type' => '', 'action' => '', 'item_id' => '', 'secondary_item_id' => '', 'content' => '', 'primary_link' => '', 'component' => 'dln-product-component', 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => false), $args);
     // Add the activity
     return bp_activity_add($activity);
 }
Ejemplo n.º 3
0
/**
 * bp_like_post_to_stream()
 * 
 * Posts to stream, depending on settings
 * 
 * TODO, Should we be posted that people like comments to the feed? This can get messy..
 * Also no point having 20 posts saying people liked the same status..
 * 
 */
function bp_like_post_to_stream($item_id, $user_id)
{
    if (bp_like_get_settings('post_to_activity_stream') == 1) {
        $activity = bp_activity_get_specific(array('activity_ids' => $item_id, 'component' => 'buddypress-like'));
        $author_id = $activity['activities'][0]->user_id;
        if ($user_id == $author_id) {
            $action = bp_like_get_text('record_activity_likes_own');
        } elseif ($user_id == 0) {
            $action = bp_like_get_text('record_activity_likes_an');
        } else {
            $action = bp_like_get_text('record_activity_likes_users');
        }
        $liker = bp_core_get_userlink($user_id);
        $author = bp_core_get_userlink($author_id);
        $activity_url = bp_activity_get_permalink($item_id);
        $content = '';
        //content must be defined...
        /* Grab the content and make it into an excerpt of 140 chars if we're allowed */
        if (bp_like_get_settings('show_excerpt') == 1) {
            $content = $activity['activities'][0]->content;
            if (strlen($content) > bp_like_get_settings('excerpt_length')) {
                $content = substr($content, 0, bp_like_get_settings('excerpt_length'));
                $content = strip_tags($content);
                $content = $content . '...';
            }
        }
        /* Filter out the placeholders */
        $action = str_replace('%user%', $liker, $action);
        $action = str_replace('%permalink%', $activity_url, $action);
        $action = str_replace('%author%', $author, $action);
        bp_activity_add(array('action' => $action, 'content' => $content, 'primary_link' => $activity_url, 'component' => 'bp-like', 'type' => 'activity_liked', 'user_id' => $user_id, 'item_id' => $item_id));
    }
}
Ejemplo n.º 4
0
/**
 * Catches an activity to reshare if js is disabled
 *
 * @package BP Reshare
 * @since    1.0
 *
 * @uses  bp_is_activity_component() are we in activity component
 * @uses  bp_is_current_action() to check current action
 * @uses  buddyreshare_get_component_slug() to get component slug
 * @uses  bp_action_variable() to check the variables
 * @uses  check_admin_referer() for security reasons
 * @uses  bp_core_get_user_domain() to build user's url
 * @uses  bp_loggedin_user_id() to get current user's id
 * @uses  bp_get_activity_slug() to get activity slug
 * @uses  buddyreshare_prepare_reshare() to build the reshare arguments
 * @uses  bp_core_add_message() to print a warning message
 * @uses  bp_core_redirect() to safely redirect user
 * @uses  bp_activity_add() to save the reshare
 */
function buddyreshare_add_reshare()
{
    // Not adding a reshare
    if (!bp_is_activity_component() || !bp_is_current_action(buddyreshare_get_component_slug())) {
        return false;
    }
    // No reshare to add
    if (!bp_action_variable(0) || bp_action_variable(0) != 'add' || !bp_action_variable(1) || !is_numeric(bp_action_variable(1))) {
        return false;
    }
    $reshare_id = bp_action_variable(1);
    check_admin_referer('buddyreshare_update');
    // redirecting to user's profile
    $redirect = bp_core_get_user_domain(bp_loggedin_user_id()) . bp_get_activity_slug() . '/';
    $reshared_args = buddyreshare_prepare_reshare($reshare_id);
    if (isset($reshared_args['error'])) {
        bp_core_add_message($reshared_args['error'], 'error');
        bp_core_redirect($redirect);
    }
    $reshared = bp_activity_add($reshared_args);
    if (!empty($reshared)) {
        do_action('buddyreshare_reshare_added', $reshare_id);
        bp_core_add_message(__('Activity reshared !', 'bp-reshare'));
        bp_core_redirect($redirect);
    } else {
        do_action('buddyreshare_reshare_added_error', $reshare_id);
        bp_core_add_message(__('OOps, error while trying to reshare..', 'bp-reshare'), 'error');
        bp_core_redirect($redirect);
    }
}
Ejemplo n.º 5
0
/**
* let's add reshare if user's browser has javascript turned off
*/
function bp_reshare_post_reshare()
{
    if (!empty($_GET['to_reshare']) && is_numeric($_GET['to_reshare'])) {
        check_admin_referer('_reshare_update');
        $redirect = remove_query_arg(array('to_reshare', '_wpnonce'), wp_get_referer());
        /* We need to check if loggedin user is the author of the original activity
        		and if the loggedin user has already reshared this activity before posting the reshare */
        $to_reshare_id = intval($_GET['to_reshare']);
        if (bp_reshare_user_did_reshared($to_reshare_id)) {
            // user is the author of the original activity or already reshared
            do_action('bp_reshare_handle_nojs_already_reshared', $reshared_activity_id);
            bp_core_add_message(__('OOps, looks like you already reshared this activity or you are the author of it..', 'bp-reshare'), 'error');
            bp_core_redirect($redirect);
        } else {
            $reshared_args = bp_reshare_prepare_reshare($to_reshare_id);
            $reshared_activity_id = bp_activity_add($reshared_args);
            if (!empty($reshared_activity_id)) {
                do_action('bp_reshare_handle_nojs_posted', $reshared_activity_id);
                bp_core_add_message(__('Activity reshared !', 'bp-reshare'));
                bp_core_redirect($redirect);
            } else {
                do_action('bp_reshare_handle_nojs_missed', $reshared_activity_id);
                bp_core_add_message(__('OOps, error while trying to reshare..', 'bp-reshare'), 'error');
                bp_core_redirect($redirect);
            }
        }
    }
}
Ejemplo n.º 6
0
 function create_object($args)
 {
     if (!isset($args['user_id'])) {
         $args['user_id'] = get_current_user_id();
     }
     return bp_activity_add($args);
 }
/**
 * Record an activity item related to the Friends component.
 *
 * A wrapper for {@link bp_activity_add()} that provides some Friends-specific
 * defaults.
 *
 * @since 1.0.0
 *
 * @see bp_activity_add() for more detailed description of parameters and
 *      return values.
 *
 * @param array|string $args {
 *     An array of arguments for the new activity item. Accepts all parameters
 *     of {@link bp_activity_add()}. The one difference is the following
 *     argument, which has a different default here:
 *     @type string $component Default: the id of your Friends component
 *                             (usually 'friends').
 * }
 * @return bool See {@link bp_activity_add()}.
 */
function friends_record_activity($args = '')
{
    if (!bp_is_active('activity')) {
        return false;
    }
    $r = wp_parse_args($args, array('user_id' => bp_loggedin_user_id(), 'action' => '', 'content' => '', 'primary_link' => '', 'component' => buddypress()->friends->id, 'type' => false, 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => false));
    return bp_activity_add($r);
}
Ejemplo n.º 8
0
/**
 * bp_em_record_activity()
 *
 * If the activity stream component is installed, this function will record activity items for your
 * component.
 */
function bp_em_record_activity($args = '')
{
    if (!function_exists('bp_activity_add')) {
        return false;
    }
    $defaults = array('id' => false, 'user_id' => '', 'action' => '', 'content' => '', 'primary_link' => '', 'component' => 'events-manager', 'type' => false, 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => gmdate("Y-m-d H:i:s"), 'hide_sitewide' => false);
    $r = wp_parse_args($args, $defaults);
    extract($r);
    return bp_activity_add(array('id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide));
}
Ejemplo n.º 9
0
function friends_record_activity($args = '')
{
    global $bp;
    if (!bp_is_active('activity')) {
        return false;
    }
    $defaults = array('user_id' => $bp->loggedin_user->id, 'action' => '', 'content' => '', 'primary_link' => '', 'component' => $bp->friends->id, 'type' => false, 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => false);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    return bp_activity_add(array('user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide));
}
Ejemplo n.º 10
0
function bp_media_record_activity($args = '')
{
    global $bp;
    if (!function_exists('bp_activity_add')) {
        return false;
    }
    $defaults = array('component' => BP_MEDIA_SLUG);
    add_filter('bp_activity_allowed_tags', 'bp_media_override_allowed_tags');
    $r = wp_parse_args($args, $defaults);
    $activity_id = bp_activity_add($r);
    return $activity_id;
}
function bp_media_record_activity($args = '')
{
    global $bp;
    if (!function_exists('bp_activity_add')) {
        return false;
    }
    $defaults = array('id' => false, 'action' => '', 'content' => '', 'component' => BP_MEDIA_SLUG, 'type' => false, 'primary_link' => '', 'user_id' => $bp->loggedin_user->id, 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => false);
    add_filter('bp_activity_allowed_tags', 'bp_media_override_allowed_tags');
    $r = wp_parse_args($args, $defaults);
    extract($r);
    $activity_id = bp_activity_add(array('id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide));
    return $activity_id;
}
Ejemplo n.º 12
0
function bbpvotes_buddypress_voted_activity($post_id, $user_id, $vote)
{
    //check vote value
    if (is_bool($vote) === false) {
        return new WP_Error('vote_is_not_bool', __('Vote is not a boolean', 'bbpvotes'));
    }
    $voteplus = $vote === true;
    $voteminus = $vote === false;
    $post = get_post($post_id);
    $user_link = bbp_get_user_profile_link($user_id);
    //build item link
    if ($post->post_type == bbp_get_topic_post_type()) {
        $topic_id = $post->ID;
        $post_permalink = get_permalink($post->ID);
    } elseif ($post->post_type == bbp_get_reply_post_type()) {
        $topic_id = bbp_get_reply_topic_id($post->ID);
        $post_permalink = bbp_get_reply_url($post->ID);
    }
    //topic infos
    $topic = get_post($topic_id);
    $topic_author_link = bbp_get_user_profile_link($topic->post_author);
    $topic_title = $topic->post_title;
    $post_link = '<a href="' . $post_permalink . '">' . $topic_title . '</a>';
    if ($voteplus) {
        $type = 'bbpvotes_voted_up';
        if ($post->post_type == bbp_get_topic_post_type()) {
            $action = sprintf(esc_html__('%1$s voted up to the topic %2$s by %3$s', 'bbpress'), $user_link, $post_link, $topic_author_link);
        } elseif ($post->post_type == bbp_get_reply_post_type()) {
            $action = sprintf(esc_html__('%1$s voted up to a reply by %3$s in the topic %2$s', 'bbpress'), $user_link, $post_link, $topic_author_link);
        }
    } else {
        $type = 'bbpvotes_voted_down';
        if ($post->post_type == bbp_get_topic_post_type()) {
            $action = sprintf(esc_html__('%1$s voted down to the topic %2$s by %3$s', 'bbpress'), $user_link, $post_link, $topic_author_link);
        } elseif ($post->post_type == bbp_get_reply_post_type()) {
            $action = sprintf(esc_html__('%1$s voted down to a reply by %3$s in the topic %2$s', 'bbpress'), $user_link, $post_link, $topic_author_link);
        }
    }
    $args = array('action' => $action, 'component' => 'bbpress', 'type' => $type, 'item_id' => $topic->ID);
    if ($post->post_type == bbp_get_reply_post_type()) {
        $args['secondary_item_id'] = $post->ID;
    }
    /*
        if ($is_update){
       $previous_activity_id = 
       $args['id'] = $previous_activity_id;
        }
    */
    bp_activity_add($args);
}
Ejemplo n.º 13
0
 /**
  * Create a wall activity for this user after posting an answer.
  *
  * @param CMA_AnswerThread $instance
  * @param CMA_Answer $answer
  */
 static function answer_posted_activity(CMA_AnswerThread $instance, CMA_Answer $answer)
 {
     if (!$instance->isPublished()) {
         return;
     } else {
         if (!$answer->isApproved()) {
             return;
         }
     }
     $post = $instance->getPost();
     $user_id = $answer->getAuthorId();
     $permalink = $answer->getPermalink();
     bp_activity_add(array('action' => sprintf(CMA::__('%s answered to the question "%s"'), bp_core_get_userlink($user_id), sprintf('<a href="%s">%s</a>', esc_attr($permalink), esc_html($instance->getTitle()))), 'content' => CMA_AnswerThread::lightContent($answer->getContent()), 'component' => self::COMPONENT, 'type' => 'answer_posted', 'primary_link' => $permalink, 'user_id' => $user_id, 'item_id' => $answer->getId()));
 }
Ejemplo n.º 14
0
/**
 * bp_group_documents_record_activity()
 *
 * If the activity stream component is installed, this function will record upload
 * and edit activity items.
 */
function bp_group_documents_record_activity($args = '')
{
    global $bp;
    if (!function_exists('bp_activity_add')) {
        return false;
    }
    $defaults = array('primary_link' => bp_get_group_permalink($bp->groups->current_group), 'component_name' => 'groups', 'component_action' => false, 'hide_sitewide' => false, 'user_id' => $bp->loggedin_user->id, 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => false, 'content' => '');
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // If the group is not public, don't broadcast updates.
    if ('public' != $bp->groups->current_group->status) {
        $hide_sitewide = 1;
    }
    return bp_activity_add(array('content' => $content, 'primary_link' => $primary_link, 'component_name' => $component_name, 'component_action' => $component_action, 'user_id' => $user_id, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'hide_sitewide' => $hide_sitewide, 'action' => $action));
}
Ejemplo n.º 15
0
/**
 * Create a "became a registered user" activity item when a user activates his account.
 *
 * @param array $user Array of userdata passed to bp_core_activated_user hook.
 *
 * @return bool
 */
function bp_core_new_user_activity($user)
{
    if (empty($user)) {
        return false;
    }
    if (is_array($user)) {
        $user_id = $user['user_id'];
    } else {
        $user_id = $user;
    }
    if (empty($user_id)) {
        return false;
    }
    bp_activity_add(array('user_id' => $user_id, 'component' => buddypress()->members->id, 'type' => 'new_member'));
}
Ejemplo n.º 16
0
function bp_reshare_handle_ajax_reshare()
{
    check_ajax_referer('_reshare_update', 'nonce');
    $activity_id = $_POST['activity'];
    if (!$activity_id) {
        _e('Unknown activity ?!?', 'bp-reshare');
        die;
    }
    $args = bp_reshare_prepare_reshare($activity_id);
    if (bp_activity_add($args)) {
        echo '1';
    } else {
        _e('OOps, error while trying to reshare..', 'bp-reshare');
    }
    die;
}
Ejemplo n.º 17
0
function groups_record_activity($args = '')
{
    global $bp;
    if (!bp_is_active('activity')) {
        return false;
    }
    // If the group is not public, hide the activity sitewide.
    if (isset($bp->groups->current_group->status) && 'public' == $bp->groups->current_group->status) {
        $hide_sitewide = false;
    } else {
        $hide_sitewide = true;
    }
    $defaults = array('id' => false, 'user_id' => $bp->loggedin_user->id, 'action' => '', 'content' => '', 'primary_link' => '', 'component' => $bp->groups->id, 'type' => false, 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => $hide_sitewide);
    $r = nxt_parse_args($args, $defaults);
    extract($r);
    return bp_activity_add(array('id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide));
}
Ejemplo n.º 18
0
function qa_buddypress_activity_post($args)
{
    global $bp;
    $defaults = array('content' => false, 'user_id' => $bp->loggedin_user->id);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // Record this on the user's profile
    $from_user_link = bp_core_get_userlink($user_id);
    $activity_action = $action;
    $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' => $type));
    // 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' => wp_filter_kses($content)));
    do_action('bp_activity_posted_update', $content, $user_id, $activity_id);
    return $activity_id;
}
Ejemplo n.º 19
0
/**
 * GMW Location function - post location to activity
 * @param $args
 * @return boolean|Ambigous <number, boolean, unknown, mixed>
 */
function gmw_location_record_activity($args)
{
    if (!function_exists('bp_activity_add')) {
        return false;
    }
    global $bp;
    $settings = get_option('gmw_options');
    $user_id = isset($args['user_id']) ? $args['user_id'] : $bp->loggedin_user->id;
    $from_user_link = bp_core_get_userlink($user_id);
    $defaults = array('id' => false, 'location' => false, 'user_id' => $user_id, 'action' => false, 'content' => '', 'primary_link' => bp_core_get_userlink($user_id, false, true), 'component' => $bp->gmw_location->id, 'type' => 'gmw_location', 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => gmdate("Y-m-d H:i:s"));
    $r = wp_parse_args($args, $defaults);
    extract($r);
    $cCity = !empty($_COOKIE['gmw_city']) ? urldecode($_COOKIE['gmw_city']) : false;
    $cState = !empty($_COOKIE['gmw_state']) ? urldecode($_COOKIE['gmw_state']) : false;
    $cCountry = !empty($_COOKIE['gmw_country']) ? urldecode($_COOKIE['gmw_country']) : false;
    $region = !empty($settings['general_settings']['country_code']) ? '&region=' . $settings['general_settings']['country_code'] : '';
    $language = !empty($settings['general_settings']['language_code']) ? '&hl=' . $settings['general_settings']['language_code'] : '';
    $activity_id = bp_activity_add(array('user_id' => $user_id, 'action' => sprintf(__('%s Updated new location at %s', 'GMW'), $from_user_link, '<span class="gmw-fl-activity-map-marker fa fa-map-marker"></span><a target="_blank" href="https://maps.google.com/maps?f=d' . $language . '' . $region . '&geocode=&saddr=' . $location . '&daddr=' . $cCity . ' ' . $cState . ' ' . $cCountry . '&ie=UTF8&z=12" >' . $location . '</a>'), 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time));
    //if ( $type == 'gmw_location' )
    //bp_update_user_meta( $user_id, 'bp_latest_update', array( 'id' => $activity_id, 'content' => wp_filter_kses( $content ) ) );
    return $activity_id;
}
Ejemplo n.º 20
0
function bp_blogs_record_activity($args = '')
{
    global $bp;
    if (!bp_is_active('activity')) {
        return false;
    }
    $defaults = array('user_id' => bp_loggedin_user_id(), 'action' => '', 'content' => '', 'primary_link' => '', 'component' => $bp->blogs->id, 'type' => false, 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => false);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // Remove large images and replace them with just one image thumbnail
    if (bp_is_active('activity') && !empty($content)) {
        $content = bp_activity_thumbnail_content_images($content, $primary_link);
    }
    if (!empty($action)) {
        $action = apply_filters('bp_blogs_record_activity_action', $action);
    }
    if (!empty($content)) {
        $content = apply_filters('bp_blogs_record_activity_content', bp_create_excerpt($content), $content);
    }
    // Check for an existing entry and update if one exists.
    $id = bp_activity_get_activity_id(array('user_id' => $user_id, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id));
    return bp_activity_add(array('id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide));
}
function groups_record_activity($args = '')
{
    global $bp;
    if (!bp_is_active('activity')) {
        return false;
    }
    // Set the default for hide_sitewide by checking the status of the group
    $hide_sitewide = false;
    if (!empty($args['item_id'])) {
        if (bp_get_current_group_id() == $args['item_id']) {
            $group = groups_get_current_group();
        } else {
            $group = groups_get_group(array('group_id' => $args['item_id']));
        }
        if (isset($group->status) && 'public' != $group->status) {
            $hide_sitewide = true;
        }
    }
    $defaults = array('id' => false, 'user_id' => bp_loggedin_user_id(), 'action' => '', 'content' => '', 'primary_link' => '', 'component' => $bp->groups->id, 'type' => false, 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => $hide_sitewide);
    $r = wp_parse_args($args, $defaults);
    extract($r);
    return bp_activity_add(array('id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide));
}
        $inviteReg = $wpdb->get_row($query, OBJECT);
        if ($inviteReg != null) {
            $regid = (string) $inviteReg->reg_id;
            $inviteId = (string) $inviteReg->invite_id;
        } else {
            $inviteId = uniqid();
            $regid = $inviteId . "-" . uniqid();
            $require_login = 0;
            $show_course_info = 0;
            $wpdb->insert(ScormCloudDatabase::get_invitations_table(), array('invite_id' => $inviteId, 'blog_id' => $GLOBALS['blog_id'], 'app_id' => ScormCloudPlugin::get_wp_option('scormcloud_appid'), 'post_id' => $postId, 'course_id' => $courseId, 'course_title' => $courseTitle, 'header' => $header, 'description' => $description, 'require_login' => $require_login, 'show_course_info' => $show_course_info), array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d'));
            //create the cloud registration
            $regService->CreateRegistration($regid, $courseId, $user_email, $user_first_name, $user_last_name, $user_email);
            $wpdb->insert(ScormCloudDatabase::get_registrations_table(), array('invite_id' => $inviteId, 'reg_id' => $regid, 'user_email' => $user_email), array('%s', '%s', '%s'));
        }
        $courseTags = 'catalog_widget';
        $regTags = $GLOBALS['blog_id'] . ',' . $inviteId . ',' . $courseTags;
        $learnerTags = isset($current_user->roles[0]) ? $current_user->roles[0] : "anonymous";
        if (function_exists("bp_activity_add")) {
            global $bp;
            $actionStr = sprintf('%s launched course "%s" from the Catalog Widget', $user_first_name . ' ' . $user_last_name, $courseTitle);
            //error_log('logged in user: '******'action' => $actionStr, 'content' => '', 'component' => 'scormcloud', 'type' => 'training_launch', 'primary_link' => '', 'user_id' => false, 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => gmdate("Y-m-d H:i:s"), 'hide_sitewide' => false);
            $bpActivityId = bp_activity_add($activityArgs);
            error_log('Logging action: ' . $actionStr . ' Activity ID: ' . $bpActivityId);
        }
        $cssUrl = ScormCloudPlugin::get_wp_option('scormcloud_player_cssurl');
        echo $regService->GetLaunchUrl($regid, $returnUrl, $cssUrl, null, $courseTags, $learnerTags, $regTags);
        break;
    default:
        break;
}
Ejemplo n.º 23
0
 /**
  * @group bp_cleanup_friendship_activities
  */
 public function test_bp_cleanup_friendship_activities()
 {
     $old_user = get_current_user_id();
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     $users = array($u1, $u2);
     friends_add_friend($u2, $u1);
     $friendship_id = friends_get_friendship_id($u2, $u1);
     // Set current user to u1 to accepte the friendship and generate a public activity
     $this->set_current_user($u1);
     friends_accept_friendship($friendship_id);
     // Reset the current user
     $this->set_current_user($old_user);
     $users[] = $this->factory->user->create();
     $users[] = $this->factory->user->create();
     foreach ($users as $u) {
         bp_activity_add(array('user_id' => $u, 'item_id' => $friendship_id, 'type' => 'friendship_created', 'component' => buddypress()->friends->id, 'hide_sitewide' => true));
     }
     $hidden = bp_activity_get(array('component' => buddypress()->friends->id, 'filter' => array('action' => array('friendship_created')), 'show_hidden' => true));
     bp_cleanup_friendship_activities();
     $check = bp_activity_get(array('component' => buddypress()->friends->id, 'item_id' => $friendship_id, 'filter' => array('action' => array('friendship_created')), 'show_hidden' => true));
     $this->assertTrue(count($check['activities']) == 1);
 }
Ejemplo n.º 24
0
/**
 * Post an activity in user's profile
 *
 * @uses check_admin_referer() for security reasons
 * @uses bp_loggedin_user_id() to get the current user id
 * @uses buddydrive_get_folder_post_type() to get the BuddyFolder post type
 * @uses buddydrive_get_name() so that it's possible to brand the plugin
 * @uses buddydrive_get_file_post_type() to get the BuddyFile post type
 * @uses buddydrive_get_buddyfile() to get item
 * @uses bp_core_get_userlink() to get link to user's profile
 * @uses bp_activity_add() to finaly record the activity without updating the latest meta
 * @return int 1 or string an error message
 */
function buddydrive_share_in_profile()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Check the nonce
    check_admin_referer('buddydrive_actions', '_wpnonce_buddydrive_actions');
    $buddyitem = intval($_POST['itemid']);
    if (empty($buddyitem)) {
        _e('this is embarassing, it did not work :(', 'buddydrive');
        die;
    }
    $link = $_POST['url'];
    $result = false;
    $user_id = bp_loggedin_user_id();
    $item_type = 'folder' == $_POST['itemtype'] ? buddydrive_get_folder_post_type() : buddydrive_get_file_post_type();
    if (!empty($buddyitem)) {
        $buddyfile = buddydrive_get_buddyfile($buddyitem, $item_type);
        if (empty($buddyfile->ID) || $buddyfile->check_for != 'public') {
            // no item or not a public one ??
            _e('We could not find your BuddyDrive item or its privacy is not set to public', 'buddydrive');
            die;
        }
        $action = sprintf(__('%1$s shared a %2$s Item', 'buddydrive'), bp_core_get_userlink($user_id), buddydrive_get_name());
        $content = $link;
        $args = array('user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => bp_core_get_userlink($user_id, false, true), 'component' => 'activity', 'type' => 'activity_update');
        $result = bp_activity_add($args);
    }
    if (!empty($result)) {
        echo 1;
    } else {
        echo _e('this is embarassing, it did not work :(', 'buddydrive');
    }
    die;
}
Ejemplo n.º 25
0
/**
 * Record blog-related activity to the activity stream.
 *
 * @since BuddyPress (1.0.0)
 *
 * @see bp_activity_add() for description of parameters.
 * @global object $bp The BuddyPress global settings object.
 *
 * @param array $args {
 *     See {@link bp_activity_add()} for complete description of arguments.
 *     The arguments listed here have different default values from
 *     bp_activity_add().
 *     @type string $component Default: 'blogs'.
 * }
 * @return int|bool On success, returns the activity ID. False on failure.
 */
function bp_blogs_record_activity( $args = '' ) {
	global $bp;

	// Bail if activity is not active
	if ( ! bp_is_active( 'activity' ) ) {
		return false;
	}

	$defaults = array(
		'user_id'           => bp_loggedin_user_id(),
		'action'            => '',
		'content'           => '',
		'primary_link'      => '',
		'component'         => $bp->blogs->id,
		'type'              => false,
		'item_id'           => false,
		'secondary_item_id' => false,
		'recorded_time'     => bp_core_current_time(),
		'hide_sitewide'     => false
	);

	$r = wp_parse_args( $args, $defaults );

	// Remove large images and replace them with just one image thumbnail
	if ( ! empty( $r['content'] ) ) {
		$r['content'] = bp_activity_thumbnail_content_images( $r['content'], $r['primary_link'], $r );
	}

	if ( ! empty( $r['action'] ) ) {

		/**
		 * Filters the action associated with activity for activity stream.
		 *
		 * @since BuddyPress (1.2.0)
		 *
		 * @param string $value Action for the activity stream.
		 */
		$r['action'] = apply_filters( 'bp_blogs_record_activity_action', $r['action'] );
	}

	if ( ! empty( $r['content'] ) ) {

		/**
		 * Filters the content associated with activity for activity stream.
		 *
		 * @since BuddyPress (1.2.0)
		 *
		 * @param string $value Generated excerpt from content for the activity stream.
		 * @param string $value Content for the activity stream.
		 * @param array  $r     Array of arguments used for the activity stream item.
		 */
		$r['content'] = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $r['content'] ), $r['content'], $r );
	}

	// Check for an existing entry and update if one exists.
	$id = bp_activity_get_activity_id( array(
		'user_id'           => $r['user_id'],
		'component'         => $r['component'],
		'type'              => $r['type'],
		'item_id'           => $r['item_id'],
		'secondary_item_id' => $r['secondary_item_id'],
	) );

	return bp_activity_add( array( 'id' => $id, 'user_id' => $r['user_id'], 'action' => $r['action'], 'content' => $r['content'], 'primary_link' => $r['primary_link'], 'component' => $r['component'], 'type' => $r['type'], 'item_id' => $r['item_id'], 'secondary_item_id' => $r['secondary_item_id'], 'recorded_time' => $r['recorded_time'], 'hide_sitewide' => $r['hide_sitewide'] ) );
}
Ejemplo n.º 26
0
function bebop_create_buffer_item($params)
{
    global $bp, $wpdb;
    if (is_array($params)) {
        if (!bebop_tables::check_existing_content_id($params['user_id'], $params['extension'], $params['item_id'])) {
            $original_text = $params['content'];
            if (!bebop_tables::bebop_check_existing_content_buffer($params['user_id'], $params['extension'], $original_text)) {
                $content = '';
                if ($params['content_oembed'] == true) {
                    $content = $original_text;
                } else {
                    $content = '<div class="bebop_activity_container ' . $params['extension'] . '">' . $original_text . '</div>';
                }
                $action = '<a href="' . bp_core_get_user_domain($params['user_id']) . '" title="' . bp_core_get_username($params['user_id']) . '">' . bp_core_get_user_displayname($params['user_id']) . '</a>';
                $action .= ' ' . __('posted a', 'bebop');
                $action .= '<a href="' . $params['actionlink'] . '" target="_blank" rel="external"> ' . __($params['type'], 'bebop_' . $params['extension']);
                $action .= '</a>: ';
                $date_imported = gmdate('Y-m-d H:i:s', time());
                //extra check to be sure we don't have an empty activity
                $clean_comment = '';
                $clean_comment = trim(strip_tags($content));
                //controls how user content is verified.
                $should_users_verify_content = bebop_tables::get_option_value('bebop_' . $params['extension'] . '_content_user_verification');
                if ($should_users_verify_content == 'no') {
                    $oer_status = 'verified';
                } else {
                    $oer_status = 'unverified';
                }
                $hide_sitewide = bebop_tables::get_option_value('bebop_' . $params['extension'] . '_hide_sitewide');
                if ($hide_sitewide == 'yes') {
                    $oer_hide_sitewide = 1;
                } else {
                    $oer_hide_sitewide = 0;
                }
                if (!empty($clean_comment)) {
                    if (bebop_filters::day_increase($params['extension'], $params['user_id'], $params['username'])) {
                        if ($wpdb->query($wpdb->prepare('INSERT INTO ' . bp_core_get_table_prefix() . 'bp_bebop_oer_manager ( user_id, status, type, action, content, secondary_item_id, date_imported, date_recorded, hide_sitewide ) VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s )', $wpdb->escape($params['user_id']), $oer_status, $wpdb->escape($params['extension']), $wpdb->escape($action), $wpdb->escape($content), $wpdb->escape($params['item_id']), $wpdb->escape($date_imported), $wpdb->escape($params['raw_date']), $wpdb->escape($oer_hide_sitewide)))) {
                            $id = $wpdb->insert_id;
                            //if users shouldn't verify content, add it to the activity stream immediately.
                            if ($should_users_verify_content == 'no') {
                                $new_activity_item = array('user_id' => $params['user_id'], 'component' => 'bebop_oer_plugin', 'type' => $params['extension'], 'action' => $action, 'content' => $content, 'item_id' => $id, 'date_recorded' => $date_imported, 'hide_sitewide' => $oer_hide_sitewide);
                                if (bp_activity_add($new_activity_item)) {
                                    bebop_tables::update_oer_data($id, 'activity_stream_id', $activity_stream_id = $wpdb->insert_id);
                                }
                            }
                            return true;
                        } else {
                            bebop_tables::log_error(__('Importer', 'bebop'), __('Import query error', 'bebop'));
                        }
                    } else {
                        bebop_tables::log_error(__('Importer', 'bebop'), __('Could not import as a daycounter could not be found.', 'bebop'));
                    }
                } else {
                    bebop_tables::log_error(__('Importer', 'bebop'), __('Could not import, content already exists.', 'bebop'));
                }
            }
        }
    }
    return false;
}
Ejemplo n.º 27
0
 /**
  * Wrapper for recoding bbPress actions to the BuddyPress activity stream
  *
  * @since bbPress (r3395)
  * @param type $args Array of arguments for bp_activity_add()
  * @uses bbp_get_current_user_id()
  * @uses bp_core_current_time()
  * @uses bbp_parse_args()
  * @uses aplly_filters()
  * @uses bp_activity_add()
  * @return type Activity ID if successful, false if not
  */
 private function record_activity($args = '')
 {
     // Default activity args
     $activity = bbp_parse_args($args, array('id' => null, 'user_id' => bbp_get_current_user_id(), 'type' => '', 'action' => '', 'item_id' => '', 'secondary_item_id' => '', 'content' => '', 'primary_link' => '', 'component' => $this->component, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => false), 'record_activity');
     // Add the activity
     return bp_activity_add($activity);
 }
Ejemplo n.º 28
0
/**
 * Post an activity item on doc save.
 *
 * @since 1.0-beta
 *
 * @param obj $query The query object created in BP_Docs_Query and passed to the
 *        bp_docs_doc_saved filter
 * @return int $activity_id The id number of the activity created
 */
function bp_docs_post_activity($query)
{
    global $bp;
    // todo: exception for autosave?
    $doc_id = !empty($query->doc_id) ? $query->doc_id : false;
    if (!$doc_id) {
        return false;
    }
    $last_editor = get_post_meta($doc_id, 'bp_docs_last_editor', true);
    // Throttle 'doc edited' posts. By default, one per user per hour
    if (!$query->is_new_doc) {
        // Look for an existing activity item corresponding to this user editing
        // this doc
        $already_args = array('max' => 1, 'sort' => 'DESC', 'show_hidden' => 1, 'filter' => array('user_id' => $last_editor, 'action' => 'bp_doc_edited', 'secondary_id' => $doc_id));
        $already_activity = bp_activity_get($already_args);
        // If any activity items are found, compare its date_recorded with time() to
        // see if it's within the allotted throttle time. If so, don't record the
        // activity item
        if (!empty($already_activity['activities'])) {
            $date_recorded = $already_activity['activities'][0]->date_recorded;
            $drunix = strtotime($date_recorded);
            if (time() - $drunix <= apply_filters('bp_docs_edit_activity_throttle_time', 60 * 60)) {
                return;
            }
        }
    }
    $doc = get_post($doc_id);
    // Set the action. Filterable so that other integration pieces can alter it
    $action = '';
    $user_link = bp_core_get_userlink($last_editor);
    $doc_url = bp_docs_get_doc_link($doc_id);
    $doc_link = '<a href="' . $doc_url . '">' . $doc->post_title . '</a>';
    if ($query->is_new_doc) {
        $action = sprintf(__('%1$s created the doc %2$s', 'bp-docs'), $user_link, $doc_link);
    } else {
        $action = sprintf(__('%1$s edited the doc %2$s', 'bp-docs'), $user_link, $doc_link);
    }
    $action = apply_filters('bp_docs_activity_action', $action, $user_link, $doc_link, $query->is_new_doc, $query);
    $hide_sitewide = bp_docs_hide_sitewide_for_doc($doc_id);
    $component = 'bp_docs';
    // This is only temporary! This item business needs to be component-neutral
    $item = isset($bp->groups->current_group->id) ? $bp->groups->current_group->id : false;
    // Set the type, to be used in activity filtering
    $type = $query->is_new_doc ? 'bp_doc_created' : 'bp_doc_edited';
    $args = array('user_id' => $last_editor, 'action' => $action, 'primary_link' => $doc_url, 'component' => $component, 'type' => $type, 'item_id' => $query->item_id, 'secondary_item_id' => $doc_id, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => apply_filters('bp_docs_hide_sitewide', $hide_sitewide, false, $doc, $item, $component));
    do_action('bp_docs_before_activity_save', $args);
    $activity_id = bp_activity_add(apply_filters('bp_docs_activity_args', $args, $query));
    do_action('bp_docs_after_activity_save', $activity_id, $args);
    return $activity_id;
}
Ejemplo n.º 29
0
/**
 * Add an activity comment.
 *
 * @since BuddyPress (1.2.0)
 *
 * @global object $bp BuddyPress global settings.
 * @uses wp_parse_args()
 * @uses bp_activity_add()
 * @uses apply_filters() To call the 'bp_activity_comment_action' hook.
 * @uses apply_filters() To call the 'bp_activity_comment_content' hook.
 * @uses bp_activity_new_comment_notification()
 * @uses wp_cache_delete()
 * @uses do_action() To call the 'bp_activity_comment_posted' hook.
 *
 * @param array $args {
 *     @type int $id Optional. Pass an ID to update an existing comment.
 *     @type string $content The content of the comment.
 *     @type int $user_id Optional. The ID of the user making the comment.
 *           Defaults to the ID of the logged-in user.
 *     @type int $activity_id The ID of the "root" activity item, ie the oldest
 *           ancestor of the comment.
 *     @type int $parent_id Optional. The ID of the parent activity item, ie the
 *           item to which the comment is an immediate reply. If not provided,
 *           this value defaults to the $activity_id.
 * }
 * @return int|bool The ID of the comment on success, otherwise false.
 */
function bp_activity_new_comment($args = '')
{
    $r = wp_parse_args($args, array('id' => false, 'content' => false, 'user_id' => bp_loggedin_user_id(), 'activity_id' => false, 'parent_id' => false));
    // Bail if missing necessary data
    if (empty($r['content']) || empty($r['user_id']) || empty($r['activity_id'])) {
        return false;
    }
    // Maybe set current activity ID as the parent
    if (empty($r['parent_id'])) {
        $r['parent_id'] = $r['activity_id'];
    }
    $activity_id = $r['activity_id'];
    // Check to see if the parent activity is hidden, and if so, hide this comment publically.
    $activity = new BP_Activity_Activity($activity_id);
    $is_hidden = (int) $activity->hide_sitewide ? 1 : 0;
    // Insert the activity comment
    $comment_id = bp_activity_add(array('id' => $r['id'], 'content' => apply_filters('bp_activity_comment_content', $r['content']), 'component' => buddypress()->activity->id, 'type' => 'activity_comment', 'user_id' => $r['user_id'], 'item_id' => $activity_id, 'secondary_item_id' => $r['parent_id'], 'hide_sitewide' => $is_hidden));
    // Comment caches are stored only with the top-level item
    wp_cache_delete($activity_id, 'bp_activity_comments');
    // Walk the tree to clear caches for all parent items
    $clear_id = $r['parent_id'];
    while ($clear_id != $activity_id) {
        $clear_object = new BP_Activity_Activity($clear_id);
        wp_cache_delete($clear_id, 'bp_activity');
        $clear_id = intval($clear_object->secondary_item_id);
    }
    wp_cache_delete($activity_id, 'bp_activity');
    do_action('bp_activity_comment_posted', $comment_id, $r, $activity);
    return $comment_id;
}
Ejemplo n.º 30
-1
/**
 * When a Notepad is edited, record the fact to the activity stream
 *
 * @since 1.0
 * @param int $post_id
 * @param object $post
 * @return int The id of the activity item posted
 */
function participad_notepad_record_notepad_activity($post_id, $post)
{
    global $bp;
    // Run only for participad_notebook post type
    if (empty($post->post_type) || participad_notepad_post_type_name() != $post->post_type) {
        return;
    }
    // Throttle activity updates: No duplicate posts (same user, same
    // notepad) within 60 minutes
    $already_args = array('max' => 1, 'sort' => 'DESC', 'show_hidden' => 1, 'filter' => array('user_id' => get_current_user_id(), 'action' => 'participad_notepad_edited', 'secondary_id' => $post_id));
    $already_activity = bp_activity_get($already_args);
    // If any activity items are found, compare its date_recorded with time() to
    // see if it's within the allotted throttle time. If so, don't record the
    // activity item
    if (!empty($already_activity['activities'])) {
        $date_recorded = $already_activity['activities'][0]->date_recorded;
        $drunix = strtotime($date_recorded);
        if (time() - $drunix <= apply_filters('participad_notepad_edit_activity_throttle_time', 60 * 60)) {
            return;
        }
    }
    $post_permalink = get_permalink($post_id);
    $action = sprintf(__('%1$s edited a notepad %2$s on the site %3$s', 'participad'), bp_core_get_userlink(get_current_user_id()), '<a href="' . $post_permalink . '">' . esc_html($post->post_title) . '</a>', '<a href="' . get_option('siteurl') . '">' . get_option('blogname') . '</a>');
    $activity_id = bp_activity_add(array('user_id' => get_current_user_id(), 'component' => bp_is_active('blogs') ? $bp->blogs->id : 'blogs', 'action' => $action, 'primary_link' => $post_permalink, 'type' => 'participad_notepad_edited', 'item_id' => get_current_blog_id(), 'secondary_item_id' => $post_id, 'recorded_time' => $post->post_modified_gmt, 'hide_sitewide' => get_option('blog_public') <= 0));
    if (function_exists('bp_blogs_update_blogmeta')) {
        bp_blogs_update_blogmeta(get_current_blog_id(), 'last_activity', bp_core_current_time());
    }
    return $activity_id;
}