Esempio n. 1
0
function mpp_group_form_uploaded_activity_action($action, $activity, $media_id, $media_ids, $gallery)
{
    if ($gallery->component != 'groups') {
        return $action;
    }
    $media_count = count($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
    $group_id = $activity->item_id;
    $group = new BP_Groups_Group($group_id);
    $group_link = sprintf("<a href='%s'>%s</a>", bp_get_group_permalink($group), bp_get_group_name($group));
    $action = sprintf(__('%s uploaded %d new %s to %s', 'mediapress'), mpp_get_user_link($activity->user_id), $media_count, $type, $group_link);
    return $action;
}
/**
 * Record a new upload activity if auto publishing is enabled in the 
 * @param type $media_id
 */
function mpp_action_record_new_media_activity($media_id)
{
    if (!mpp_is_auto_publish_to_activity_enabled('add_media') || apply_filters('mpp_do_not_record_add_media_activity', false)) {
        return;
    }
    $media = mpp_get_media($media_id);
    //if media is upload from activity, do not publish it again to activity
    if ($media->context == 'activity') {
        return;
    }
    $user_link = mpp_get_user_link($media->user_id);
    $link = mpp_get_media_permalink($media);
    mpp_media_record_activity(array('media_id' => $media_id, 'type' => 'add_media', 'content' => '', 'action' => sprintf(__('%s added a new <a href="%s">%s</a>', 'mediapress'), $user_link, $link, $media->type)));
}
Esempio n. 3
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 = 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);
}
Esempio n. 4
0
 public function publish_gallery_media()
 {
     //verify nonce
     if (!wp_verify_nonce($_POST['_wpnonce'], 'publish')) {
         //should we return or show error?
         return;
     }
     $gallery_id = absint($_POST['gallery_id']);
     if (!mpp_gallery_has_unpublished_media($gallery_id)) {
         wp_send_json(array('message' => __('No media to publish.', 'mediapress'), 'error' => 1));
         exit(0);
     }
     //check if user has permission
     if (!mpp_user_can_publish_gallery_activity($gallery_id)) {
         wp_send_json(array('message' => __("You don't have sufficient permission.", 'mediapress'), 'error' => 1));
         exit(0);
     }
     $media_ids = mpp_gallery_get_unpublished_media($gallery_id);
     $media_count = count($media_ids);
     $gallery = mpp_get_gallery($gallery_id);
     $type = $gallery->type;
     $type_name = _n($type, $type . 's', $media_count);
     $user_link = mpp_get_user_link(get_current_user_id());
     $gallery_url = mpp_get_gallery_permalink($gallery);
     $gallery_link = '<a href="' . esc_url($gallery_url) . '" title="' . esc_attr($gallery->title) . '">' . mpp_get_gallery_title($gallery) . '</a>';
     //has media, has permission, so just publish now
     //
     $activity_id = mpp_gallery_record_activity(array('gallery_id' => $gallery_id, 'media_ids' => $media_ids, 'type' => 'media_publish', 'action' => sprintf(__('%s shared %d %s to %s ', 'mediapress'), $user_link, $media_count, $type_name, $gallery_link), 'content' => ''));
     if ($activity_id) {
         mpp_gallery_delete_unpublished_media($gallery_id);
         wp_send_json(array('message' => __("Published to activity successfully.", 'mediapress'), 'success' => 1));
         exit(0);
     } else {
         wp_send_json(array('message' => __("There was a problem. Please try again later.", 'mediapress'), 'error' => 1));
         exit(0);
     }
     //we are good, let us check if there are actually unpublished media
     //$unpublished_media =
     //get unpublished media ids
     //call _mpp_record_activity
     //how about success/failure
     exit(0);
 }
Esempio n. 5
0
/**
 * Generate an activity when a new gallery is created
 * We will not generate any activity for profile galleries though.
 * 
 * @param type $gallery_id
 */
function mpp_action_new_gallery_activity($gallery_id)
{
    //if the admin settings does not ask us to create new activity,
    //Or it is explicitly restricted, do not proceed
    if (!mpp_is_auto_publish_to_activity_enabled('create_gallery') || apply_filters('mpp_do_not_record_create_gallery_activity', false)) {
        return;
    }
    $gallery = mpp_get_gallery($gallery_id);
    $user_link = mpp_get_user_link($gallery->user_id);
    $link = mpp_get_gallery_permalink($gallery);
    mpp_gallery_record_activity(array('gallery_id' => $gallery_id, 'type' => 'create_gallery', 'content' => '', 'action' => sprintf(__('%s created a %s <a href="%s">gallery</a>', 'mediapress'), $user_link, $gallery->type, $link)));
    //record gallery creation as activity, there will be issue with wall gallery though
}
 /**
  * Display the column data
  * 
  * @param string $col
  * @param int $post_id
  * @return string
  */
 public function display_cols($col, $post_id)
 {
     $allowed = array('type', 'status', 'component', 'user_id', 'media_count', 'cover');
     if (!in_array($col, $allowed)) {
         return $col;
     }
     $gallery = mpp_get_gallery(get_post($post_id));
     switch ($col) {
         case 'cover':
             echo "<img src='" . mpp_get_gallery_cover_src('thumbnail', $post_id) . "' height='100px' width='100px'/>";
             break;
         case 'type':
             echo $gallery->type;
             break;
         case 'status':
             echo $gallery->status;
             break;
         case 'component':
             echo $gallery->component;
             break;
         case 'media_count':
             echo $gallery->media_count;
             break;
         case 'user_id':
             echo mpp_get_user_link($gallery->user_id);
             break;
     }
 }