Пример #1
0
function mpp_gallery_show_publish_gallery_activity_button()
{
    if (!mediapress()->is_bp_active()) {
        return;
    }
    $gallery_id = mpp_get_current_gallery_id();
    //if not a valid gallery id or no unpublished media exists, just don't show it
    if (!$gallery_id || !mpp_gallery_has_unpublished_media($gallery_id)) {
        return;
    }
    $gallery = mpp_get_gallery($gallery_id);
    $unpublished_media = mpp_gallery_get_unpublished_media($gallery_id);
    //unpublished media count
    $unpublished_media_count = count($unpublished_media);
    $type = $gallery->type;
    $type_name = _n($type, $type . 's', $unpublished_media_count);
    //if we are here, there are unpublished media
    ?>
	<div id="mpp-unpublished-media-info">
		<p> <?php 
    printf(__('You have %d %s not published to actvity.', 'mediapress'), $unpublished_media_count, $type_name);
    ?>
			<span class="mpp-gallery-publish-activity"><?php 
    mpp_gallery_publish_activity_link($gallery_id);
    ?>
</span>
			<span class="mpp-gallery-unpublish-activity"><?php 
    mpp_gallery_unpublished_media_delete_link($gallery_id);
    ?>
</span>
		</p>
	</div>

	<?php 
}
Пример #2
0
/**
 * Check if current Gallery has unpublished media
 * 
 * @param type $gallery_id
 * @return boolean
 */
function mpp_gallery_has_unpublished_media($gallery_id)
{
    $media_ids = mpp_gallery_get_unpublished_media($gallery_id);
    if (!empty($media_ids)) {
        return true;
    }
    return false;
}
Пример #3
0
function mpp_action_publish_gallery_media_to_activity()
{
    if (!is_user_logged_in() || !mpp_is_gallery_management() || !bp_is_action_variable('publish', 1)) {
        return;
    }
    $gallery_id = absint($_GET['gallery_id']);
    if (!$gallery_id) {
        return;
    }
    //$referrer = wp_get_referer();
    //if( empty( $referrer ) ) {
    $referrer = mpp_get_gallery_edit_media_url($gallery_id);
    //}
    //verify nonce
    if (!wp_verify_nonce($_GET['_wpnonce'], 'publish')) {
        mpp_add_feedback(__('Unauthorized action.', 'mediapress'), 'error');
        bp_core_redirect($referrer);
    }
    //all is good check for permission
    if (!mpp_user_can_publish_gallery_activity($gallery_id)) {
        mpp_add_feedback(__("You don't have sufficient permission.", 'mediapress'), 'error');
        bp_core_redirect($referrer);
    }
    if (!mpp_gallery_has_unpublished_media($gallery_id)) {
        mpp_add_feedback(__('Nothing to publish.', 'mediapress'), 'error');
        bp_core_redirect($referrer);
    }
    //now we can safely publish
    $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 = bp_core_get_userlink(get_current_user_id());
    $gallery_url = mpp_get_gallery_permalink($gallery);
    $gallery_link = '<a href="' . esc_url($gallery_url) . '" title="' . esc_attr($gallery->title) . '">{$gallery->title}</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 ', 'mediaprses'), $user_link, $media_count, $type_name, $gallery_link), 'content' => ''));
    if ($activity_id) {
        mpp_gallery_delete_unpublished_media($gallery_id);
        mpp_add_feedback(__("Published to activity successfully.", 'mediapress'));
    } else {
        mpp_add_feedback(__("There was a problem. Please try again later.", 'mediapress'), 'error');
    }
    bp_core_redirect($referrer);
}
Пример #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);
 }