/**
 * Format activity action for 'mpp_media_upload' activity type.
 *
 * 
 * @param string $action  activity action.
 * @param object $activity Activity object.
 * @return string
 */
function mpp_format_activity_action_media_upload($action, $activity)
{
    $userlink = mpp_get_user_link($activity->user_id);
    $media_ids = array();
    $media_id = 0;
    $media_id = mpp_activity_get_media_id($activity->id);
    if (!$media_id) {
        $media_ids = mpp_activity_get_attached_media_ids($activity->id);
        if (!empty($media_ids)) {
            $media_id = $media_ids[0];
        }
    }
    $gallery_id = mpp_activity_get_gallery_id($activity->id);
    if (!$media_id && !$gallery_id) {
        return $action;
        //not a gallery activity, no need to proceed further
    }
    $media = mpp_get_media($media_id);
    $gallery = mpp_get_gallery($gallery_id);
    if (!$media && !$gallery) {
        return $action;
    }
    $activity_type = mpp_activity_get_activity_type($activity->id);
    //is a type specified
    $skip = false;
    if ($activity_type) {
        if (in_array($activity_type, array('edit_gallery', 'add_media'))) {
            //'create_gallery',
            $skip = true;
        }
    }
    //there us still a chance for improvement, we should dynamically generate the action instead for the above actions too
    if ($skip) {
        return $action;
    }
    if ($activity_type == 'media_upload') {
        $media_count = count($media_ids);
        $media_id = current($media_ids);
        $type = $gallery->type;
        //we need the type plural in case of mult
        $type = _n($type, $type . 's', $media_count);
        //photo vs photos etc
        $action = sprintf(__('%s uploaded %d new %s', 'mediapress'), $userlink, $media_count, $type);
        //allow modules to filter the action and change the message
        $action = apply_filters('mpp_activity_action_media_upload', $action, $activity, $media_id, $media_ids, $gallery);
    } elseif ($activity_type == 'media_comment') {
        if (mpp_is_single_media()) {
            $action = sprintf(__('%s', 'mediapress'), $userlink);
        } else {
            $action = sprintf(__("%s commented on %s's %s", 'mediapress'), $userlink, mpp_get_user_link($media->user_id), $media->type);
            //brajesh singh commented on @mercime's photo
        }
    } elseif ($activity_type == 'gallery_comment') {
        if (mpp_is_single_gallery()) {
            $action = sprintf('%s', $userlink);
        } else {
            $action = sprintf(__("%s commented on %s's <a href='%s'>%s gallery</a>", 'mediapress'), $userlink, mpp_get_user_link($gallery->user_id), mpp_get_gallery_permalink($gallery), $gallery->type);
        }
    } elseif ($activity_type == 'create_gallery') {
        $action = sprintf(__('%s created a %s <a href="%s">gallery</a>', 'mediapress'), $userlink, $gallery->type, mpp_get_gallery_permalink($gallery));
    } else {
        $action = sprintf(__('%s', 'mediapress'), $userlink);
    }
    return apply_filters('mpp_format_activity_action_media_upload', $action, $activity, $media_id, $media_ids);
}
Example #2
0
/**
 * Format activity action for 'mpp_media_upload' activity type.
 *
 * 
 * @param string $action  activity action.
 * @param object $activity Activity object.
 * @return string
 */
function mpp_format_activity_action_media_upload($action, $activity)
{
    $userlink = bp_core_get_userlink($activity->user_id);
    $media_ids = array();
    //this could be a comment
    //or a media comment
    //or a gallery comment
    //or an activity upload
    $media_id = mpp_activity_get_media_id($activity->id);
    $gallery_id = mpp_activity_get_gallery_id($activity->id);
    if (!$media_id && !$gallery_id) {
        return $action;
    }
    //not a gallery activity, no need to proceed further
    $type = mpp_activity_get_activity_type($activity->id);
    //is a type specified
    $skip = false;
    if ($type) {
        if (in_array($type, array('create_gallery', 'edit_gallery', 'add_media'))) {
            $skip = true;
        }
    }
    if (!$skip && $media_id) {
        $media = mpp_get_media($media_id);
        //this is an activity comment on single media
        if (mpp_is_single_media()) {
            $action = sprintf(__('%s', 'mpp'), $userlink);
        } else {
            $action = sprintf(__("%s commented on %s's %s", 'mpp'), $userlink, bp_core_get_userlink($media->user_id), $media->type);
            //brajesh singh commented on @mercime's photo
        }
    } elseif (!$skip && $gallery_id) {
        $gallery = mpp_get_gallery($gallery_id);
        //check for the uploaded media
        $media_ids = mpp_activity_get_attached_media_ids($activity->id);
        //this will never fire but let us be defensive
        if (empty($media_ids)) {
            //this is gallery comment
            if (mpp_is_single_gallery()) {
                $action = sprintf('%s', $userlink);
            } else {
                $action = sprintf(__("%s commented on %s's <a href='%s'>%s gallery</a>", 'mpp'), $userlink, bp_core_get_userlink($gallery->user_id), mpp_get_gallery_permalink($gallery), $gallery->type);
            }
        } else {
            //we will always be here
            $media_count = count($media_ids);
            $media_id = current($media_ids);
            $type = $gallery->type;
            //we need the type plural in case of mult
            $type = _n($type, $type . 's', $media_count);
            //photo vs photos etc
            $action = sprintf(__('%s uploaded %d new %s', 'mpp'), $userlink, $media_count, $type);
            //allow modules to filter the action and change the message
            $action = apply_filters('mpp_activity_action_media_upload', $action, $activity, $media_id, $media_ids, $gallery);
        }
    }
    return apply_filters('mpp_format_activity_action_media_upload', $action, $activity, $media_id, $media_ids);
}