Пример #1
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_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 = bp_core_get_userlink($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
}
Пример #2
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);
 }