/** * Record Media Activity * * It does not actually records activity, simply simulates the activity update and rest are done by the actions.php functions * * It will be removed in future for a better record_activity method * @param type $args * @return boolean */ function mpp_record_activity($args = null) { //if activity module is not active, why bother if (!bp_is_active('activity')) { return false; } $default = array('gallery_id' => 0, 'media_id' => 0, 'media_ids' => null, 'action' => '', 'content' => '', 'type' => '', 'component' => mpp_get_current_component(), 'component_id' => mpp_get_current_component_id(), 'user_id' => get_current_user_id(), 'status' => ''); $args = wp_parse_args($args, $default); //atleast a gallery id or a media id should be given if (!$args['gallery_id'] && !$args['media_id'] || !mpp_is_active_component($args['component']) || !$args['component_id']) { return false; } $gallery_id = absint($args['gallery_id']); $media_id = absint($args['media_id']); $type = $args['type']; //should we validate type too? $hide_sitewide = 0; $status_object = null; if ($args['status']) { $status_object = mpp_get_status_object($args['status']); if ($status_object && ($status_object->activity_privacy == 'hidden' || $status_object->activity_privacy == 'onlyme')) { $hide_sitewide = 1; } } $media_ids = $args['media_ids']; if (!empty($media_ids) && !is_array($media_ids)) { $media_ids = explode(',', $media_ids); } $component = $args['component']; if ($component == buddypress()->members->id) { $component = buddypress()->activity->id; //for user gallery updates, let it be simple activity , do not set the component to 'members' } $activity_id = bp_activity_add(array('id' => false, 'user_id' => $args['user_id'], 'action' => $args['action'], 'content' => $args['content'], 'component' => $component, 'type' => 'mpp_media_upload', 'item_id' => absint($args['component_id']), 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => $hide_sitewide)); if (!$activity_id) { return false; //there was a problem } //store the type of gallery activity in meta if ($type) { mpp_activity_update_activity_type($activity_id, $type); } if ($media_ids) { $media_ids = wp_parse_id_list($media_ids); mpp_activity_update_attached_media_ids($activity_id, $media_ids); } if ($gallery_id) { mpp_activity_update_gallery_id($activity_id, $gallery_id); } if ($media_id) { mpp_activity_update_media_id($activity_id, $media_id); } mpp_activity_update_context($activity_id, 'gallery'); //save activity privacy if ($status_object) { bp_activity_update_meta($activity_id, 'activity-privacy', $status_object->activity_privacy); } return $activity_id; }
/** * Record Media Activity * * It does not actually records activity, simply simulates the activity update and rest are done by the actions.php functions * * It will be removed in future for a better record_activity method * @param type $args * @return boolean */ function mpp_record_activity($args = null) { //if activity module is not active, why bother if (!bp_is_active('activity')) { return false; } $default = array('id' => false, 'gallery_id' => 0, 'media_id' => 0, 'media_ids' => null, 'action' => '', 'content' => '', 'type' => '', 'component' => mpp_get_current_component(), 'component_id' => mpp_get_current_component_id(), 'user_id' => get_current_user_id(), 'status' => ''); $args = wp_parse_args($args, $default); //atleast a gallery id or a media id should be given if (!$args['gallery_id'] && !$args['media_id'] || !mpp_is_enabled($args['component'], $args['component_id']) || !$args['component_id']) { return false; } $gallery_id = absint($args['gallery_id']); $media_id = absint($args['media_id']); $type = $args['type']; //should we validate type too? $hide_sitewide = 0; $status_object = null; if ($args['status']) { $status_object = mpp_get_status_object($args['status']); if ($status_object && ($status_object->activity_privacy == 'hidden' || $status_object->activity_privacy == 'onlyme')) { $hide_sitewide = 1; } //if BuddyPress Activity privacy plugin is not active, revert back to hiding all non public activity if (!function_exists('bp_activity_privacy_check_config')) { $hide_sitewide = $args['status'] == 'public' ? 0 : 1; //overwrite privacy } } $media_ids = $args['media_ids']; if (!empty($media_ids) && !is_array($media_ids)) { $media_ids = explode(',', $media_ids); } $component = $args['component']; if ($component == buddypress()->members->id) { $component = buddypress()->activity->id; //for user gallery updates, let it be simple activity , do not set the component to 'members' } $activity_args = array('id' => $args['id'], 'user_id' => $args['user_id'], 'action' => $args['action'], 'content' => $args['content'], 'component' => $component, 'type' => 'mpp_media_upload', 'item_id' => absint($args['component_id']), 'secondary_item_id' => false, 'hide_sitewide' => $hide_sitewide); //only update record time if this is a new activity if (empty($args['id'])) { $activity_args['recorded_time'] = bp_core_current_time(); } //let us give an opportunity to customize the activity args //use this filter to work with the activity privacy $activity_args = apply_filters('mpp_record_activity_args', $activity_args, $default); $activity_id = bp_activity_add($activity_args); if (!$activity_id) { return false; //there was a problem } //store the type of gallery activity in meta if ($type) { mpp_activity_update_activity_type($activity_id, $type); } if ($media_ids) { $media_ids = wp_parse_id_list($media_ids); mpp_activity_update_attached_media_ids($activity_id, $media_ids); } if ($gallery_id) { mpp_activity_update_gallery_id($activity_id, $gallery_id); } if ($media_id) { mpp_activity_update_media_id($activity_id, $media_id); } mpp_activity_update_context($activity_id, 'gallery'); //save activity privacy if ($status_object) { bp_activity_update_meta($activity_id, 'activity-privacy', $status_object->activity_privacy); } return $activity_id; }