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 }
public function display($gallery) { $gallery = mpp_get_gallery($gallery); $type = $gallery->type; $templates = array("gallery/views/grid-{$type}.php", 'gallery/views/grid.php'); mpp_locate_template($templates, true); }
function mpp_shortcode_uploader($atts = array(), $content = '') { $default = array('gallery_id' => 0, 'component' => mpp_get_current_component(), 'component_id' => mpp_get_current_component_id(), 'type' => '', 'status' => mpp_get_default_status(), 'view' => '', 'selected' => 0, 'label_empty' => __('Please select a gallery', 'mediapress'), 'show_error' => 1); $atts = shortcode_atts($default, $atts); //dropdown list of galleries to sllow userselect one $view = 'list'; if (!empty($atts['gallery_id']) && is_numeric($atts['gallery_id'])) { $view = 'single'; //single gallery uploader //override component and $component id $gallery = mpp_get_gallery($atts['gallery_id']); if (!$gallery) { return __('Nonexistent gallery should not be used', 'mediapress'); } //reset $atts['component'] = $gallery->component; $atts['component_id'] = $gallery->component_id; $atts['type'] = $gallery->type; } //the user must be able to upload to current component or galler $can_upload = false; if (mpp_user_can_upload($atts['component'], $atts['component_id'], $atts['gallery_id'])) { $can_upload = true; } if (!$can_upload && $atts['show_error']) { return __('Sorry, you are not allowed to upload here.', 'mediapress'); } //if we are here, the user can upload //we still have one issue, what if the user has not created any gallery and the admin intends to allow the user to upload to their created gallery $atts['context'] = 'shortcode'; //from where it is being uploaded, $atts['view'] = $view; //passing the 2nd arg makes all these variables available to the loaded file mpp_get_template('shortcodes/uploader.php', $atts); }
/** * 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; } }
public function display_cols($col, $post_id) { $allowed = array('type', 'status', 'component', 'user_id', 'media_count'); if (!in_array($col, $allowed)) { return $col; } $gallery = mpp_get_gallery(get_post($post_id)); switch ($col) { 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 bp_core_get_userlink($gallery->user_id); break; } }
function mpp_shortcode_show_gallery($atts = null, $content = '') { $defaults = array('id' => false, 'in' => false, 'exclude' => false, 'slug' => false, 'per_page' => false, 'offset' => false, 'page' => isset($_REQUEST['mpage']) ? absint($_REQUEST['mpage']) : false, 'nopaging' => false, 'order' => 'DESC', 'orderby' => 'date', 'user_id' => false, 'include_users' => false, 'exclude_users' => false, 'user_name' => false, 'scope' => false, 'search_terms' => '', 'meta_key' => '', 'meta_value' => '', 'column' => 4, 'view' => '', 'show_pagination' => 1); $defaults = apply_filters('mpp_shortcode_show_gallery_defaults', $defaults); $atts = shortcode_atts($defaults, $atts); if (!$atts['id']) { return ''; } $gallery_id = absint($atts['id']); global $wpdb; $attachments = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_type = %s ", $gallery_id, 'attachment')); array_push($attachments, $gallery_id); _prime_post_caches($attachments, true, true); $gallery = mpp_get_gallery($gallery_id); //if gallery does not exist, there is no proint in further proceeding if (!$gallery) { return ''; } if (!$atts['meta_key']) { unset($atts['meta_key']); unset($atts['meta_value']); } $view = $atts['view']; unset($atts['id']); unset($atts['view']); $atts['gallery_id'] = $gallery_id; $shortcode_column = $atts['column']; mpp_shortcode_save_media_data('column', $shortcode_column); mpp_shortcode_save_media_data('shortcode_args', $atts); unset($atts['column']); $show_pagination = $atts['show_pagination']; unset($atts['show_pagination']); $atts = array_filter($atts); $atts = apply_filters('mpp_shortcode_show_gallery_query_args', $atts, $defaults); $query = new MPP_Media_Query($atts); mpp_shortcode_save_media_data('query', $query); $content = apply_filters('mpp_shortcode_mpp_show_gallery_content', '', $atts, $view); if (!$content) { $templates = array('shortcodes/grid.php'); if ($view) { $type = $gallery->type; $preferred_templates = array("shortcodes/{$view}-{$type}.php", "shortcodes/{$view}.php"); //audio-playlist, video-playlist $templates = array_merge($preferred_templates, $templates); //array_unshift( $templates, $preferred_template ); } ob_start(); $located = mpp_locate_template($templates, false); //load if ($located) { require $located; } $content = ob_get_clean(); } mpp_shortcode_reset_media_data('column'); mpp_shortcode_reset_media_data('query'); mpp_shortcode_reset_media_data('shortcode_args'); return $content; }
/** * Filter get_permalink for mediapress gallery post type( mpp-gallery) * aand make it like site.com/members/username/mediapressslug/gallery-name or site.com/{component-page}/{single-component}/mediapress-slug/gallery-name * It allows us to get the permalink to gallery by using the_permalink/get_permalink functions */ function mpp_filter_gallery_permalink($permalink, $post, $leavename, $sample) { if (mpp_get_gallery_post_type() != $post->post_type) { return $permalink; } $gallery = mpp_get_gallery($post); $slug = $gallery->slug; $base_url = mpp_get_gallery_base_url($gallery->component, $gallery->component_id); return apply_filters('mpp_get_gallery_permalink', $base_url . '/' . $slug, $gallery); }
/** * If there is no cover set for a gallery, use the default cover image * * @param type $gallery * @param type $cover_type * @return type */ function mpp_get_default_gallery_cover_image_src($gallery, $cover_type) { $gallery = mpp_get_gallery($gallery); //we need to cache the assets to avoid heavy file system read/write etc $key = $gallery->type . '-' . $cover_type; //let us assume a naming convention like this //gallery_type-cover_type.png? or whatever e.g video-thumbnail.png, photo-mid.png $default_image = $gallery->type . '-' . $cover_type . '.png'; $default_image = apply_filters('mpp_default_cover_file_name', $default_image, $cover_type, $gallery); return mpp_get_asset_url('assets/images/' . $default_image, $key); }
function mpp_group_check_gallery_permission($can, $gallery, $user_id) { $gallery = mpp_get_gallery($gallery); //if it is not a group gallery, we should not be worried if ($gallery->component != 'groups') { return $can; } $group_id = $gallery->component_id; if (groups_is_user_admin($user_id, $group_id) || groups_is_user_mod($user_id, $group_id)) { $can = true; } return $can; }
function mpp_custom_restrict_group_upload($can_do, $component, $component_id, $gallery) { if ($component != 'groups') { return $can_do; } //we only care about group upload $gallery = mpp_get_gallery($gallery); if (!$gallery || $gallery->user_id != get_current_user_id()) { return false; //do not allow if gallery is not given } return true; //the user had created this gallery }
function mpp_filter_current_component_for_sitewide($component) { if (!mediapress()->is_bp_active()) { return $component; } if (mpp_admin_is_add_gallery() || mpp_admin_is_edit_gallery()) { global $post; $gallery = mpp_get_gallery($post); if ($gallery && $gallery->component) { $component = $gallery->component; } else { $component = 'sitewide'; } } return $component; }
/** * Show the list of attached media in an activity * Should we add a link to view gallery too? * * @return type */ function mpp_activity_inject_attached_media_html() { $media_ids = mpp_activity_get_attached_media_ids(bp_get_activity_id()); if (empty($media_ids)) { return; } $activity_id = bp_get_activity_id(); $gallery_id = mpp_activity_get_gallery_id($activity_id); $gallery = mpp_get_gallery($gallery_id); if (!$gallery) { return; } $type = $gallery->type; $view = mpp_get_activity_view($type); $view->activity_display($media_ids); }
/** * Maps the before_delete_post action to mpp_before_gallery_delete action * It also does the cleanup of attachments as wp_delete_post() does not delete attachments * * @param int $gallery_id post id * @return unknown */ public function map_before_delete_post_action($gallery_id) { //is this called or a valid gallery? if (!$gallery_id || !mpp_is_valid_gallery($gallery_id)) { return; } $gallery = mpp_get_gallery($gallery_id); //we are certain that it is called for gallery //fire the MediaPress gallery delete action if ($this->is_queued($gallery_id)) { //this action is already being executed for the current gallery, no need to do that again return; } $this->add_item($gallery_id, 'gallery'); do_action('mpp_before_gallery_delete', $gallery_id); //after that action, we delete all attachment global $wpdb; //1// delete all media $storage_manager = null; $media_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d", $gallery_id)); //we need the storage manager to notify it that it do do any final cleanup after the gallery delete //should we keep a reference to the storage manager for each gallery? what will happen for a gallery that contains local/remote media? //for the time being we are not keeping a reference but this method is doing exactly the same and I am not sure which approach will be fbetter for futuer if (!empty($media_ids)) { $mid = $media_ids[0]; $storage_manager = mpp_get_storage_manager($mid); } //delete all media foreach ($media_ids as $media_id) { wp_delete_attachment($media_id); //delete all media } if (mediapress()->is_bp_active()) { //delete all gallery activity mpp_gallery_delete_activity($gallery_id); //delete all associated activity meta //mpp_gallery_delete_activity_meta( $gallery_id ); } //Delete wall gallery meta mpp_delete_wall_gallery_id(array('component' => $gallery->component, 'component_id' => $gallery->component_id, 'gallery_id' => $gallery->id, 'media_type' => $gallery->type)); //do any final cleanup, deletegate to the storage manager if ($storage_manager) { $storage_manager->delete_gallery($gallery); } return; }
/** * Show the list of attached media in an activity * Should we add a link to view gallery too? * * @return type */ function mpp_activity_inject_attached_media_html() { $media_list = mpp_activity_get_attached_media_ids(bp_get_activity_id()); if (empty($media_list)) { return; } $activity_id = bp_get_activity_id(); $gallery_id = mpp_activity_get_gallery_id($activity_id); $gallery = mpp_get_gallery($gallery_id); //in case we are using oembed or other storage method $storage_method = mpp_get_media_meta($gallery->id, '_mpp_storage_method', true); if ($storage_method == mpp_get_default_storage_method()) { $storage_method = ''; } $slug = $gallery->type; if (!empty($storage_method)) { $slug = $slug . '-' . $storage_method; } //eg. video-oembed //media-loop-audio/media-loop-video,media-loop-photo, media-loop mpp_get_template_part('gallery/activity/loop', $slug); }
public function fetch_gallery_media() { //do we need nonce validation for this request too? no $items = array(); $gallery_id = absint($_POST['gallery_id']); $gallery = mpp_get_gallery($gallery_id); if (!$gallery_id || empty($gallery)) { exit(0); } $statuses = mpp_get_accessible_statuses($gallery->component, $gallery->component_id, get_current_user_id()); $media_query = new MPP_Media_Query(array('gallery_id' => $gallery_id, 'posts_per_page' => -1, 'status' => $statuses)); if ($media_query->have_media()) { ?> <?php while ($media_query->have_media()) { $media_query->the_media(); ?> <?php $items[] = array('src' => $this->get_media_lightbox_entry()); ?> <?php } ?> <?php } ?> <?php mpp_reset_media_data(); ?> <?php wp_send_json(array('items' => $items)); exit(0); }
/** * Filter get_permalink for mediapress gallery post type( mpp-gallery) * aand make it like site.com/members/username/mediapressslug/gallery-name or site.com/{component-page}/{single-component}/mediapress-slug/gallery-name * It allows us to get the permalink to gallery by using the_permalink/get_permalink functions */ function mpp_filter_gallery_permalink($permalink, $post, $leavename, $sample) { //check if BuddyPress is active, if not, we don't filter it yet //lightweight check if (!mediapress()->is_bp_active()) { return $permalink; } //a little more expensive if (mpp_get_gallery_post_type() != $post->post_type) { return $permalink; } //this is expensive if the post is not cached //If you see too many queries, just make sure to call _prime_post_caches($ids, true, true ); where $ids is collection of post ids //that will save a lot of query $gallery = mpp_get_gallery($post); // do not modify permalinks for Sitewide gallery if ($gallery->component == 'sitewide') { return $permalink; } $slug = $gallery->slug; $base_url = mpp_get_gallery_base_url($gallery->component, $gallery->component_id); return apply_filters('mpp_get_gallery_permalink', $base_url . '/' . $slug, $gallery); }
/** * Setup gallery for components like groups/events etc */ public function setup_component_gallery() { //current_action = mpp_slug(mediapress) if (mpp_is_active_component(bp_current_component())) { //is Component Gallery enabled? and are we on the Component section? $current_action = bp_action_variable(0); if ($current_action == 'create' || $current_action == 'upload') { mediapress()->set_action($current_action); mediapress()->set_edit_action($current_action); return; } //Are we looking at single gallery? or Media? //current action in this case is checked for being a gallery slug if ($this->action_variables && ($gallery = mpp_gallery_exists($this->action_variables[0], $this->component, $this->component_id))) { //setup current gallery & gallery query mediapress()->current_gallery = mpp_get_gallery($gallery); mediapress()->the_gallery_query = new MPP_Gallery_Query(array('id' => $gallery->ID)); $this->current_action = bp_action_variable(1); $this->current_manage_action = bp_action_variable(2); if (!empty($this->action_variables[1]) && $this->action_variables[1] == 'page' && $this->action_variables[2] > 0) { $this->mpage = (int) $this->action_variables[2]; } } else { if ($this->action_variables && $this->action_variables[0] == 'page' && $this->action_variables[1] > 0) { $this->gpage = (int) $this->action_variables[1]; } $args = array('component_id' => $this->component_id, 'component' => $this->component, 'status' => $this->accessible_statuses); if ($this->gpage) { $args['page'] = absint($this->gpage); } //we are on User gallery home page(gallery list) //we do need to check for the access level here and pass it to the query //how about gallery pagination? mediapress()->the_gallery_query = new MPP_Gallery_Query($args); //set it is the user galleries list view mediapress()->is_gallery_home = true; } //in this case, we are on the gallery directory, check if we have it enabled? } }
?> <?php $type = mpp_get_gallery_type(); ?> <div class='mpp-g mpp-item-list mpp-media-list mpp-<?php echo $type; ?> -list mpp-single-gallery-media-list mpp-single-gallery-<?php echo $type; ?> -list'> <?php mpp_get_template_part('gallery/media/loop', mpp_get_media_loop_template_slug(mpp_get_gallery())); ?> </div> <?php do_action('mpp_after_single_gallery'); ?> <?php mpp_media_pagination(); ?> <?php do_action('mpp_after_single_gallery_pagination'); ?>
/** * Render gallery menu * * @param type $gallery */ function mpp_gallery_admin_menu($gallery, $selected = '') { $gallery = mpp_get_gallery($gallery); mediapress()->get_menu('gallery')->render($gallery, $selected); }
function reset_gallery_data() { parent::reset_postdata(); if (!empty($this->post)) { mediapress()->current_gallery = mpp_get_gallery($this->post); } }
do_action('mpp_before_gallery_actions'); ?> <div class="mpp-item-actions mpp-gallery-actions"> <?php mpp_gallery_action_links(); ?> </div> <?php do_action('mpp_before_gallery_type_icon'); ?> <div class="mpp-type-icon"><?php do_action('mpp_type_icon', mpp_get_gallery_type(), mpp_get_gallery()); ?> </div> <div class="mpp-item-meta mpp-gallery-meta mpp-gallery-meta-bottom"> <?php do_action('mpp_gallery_meta'); ?> </div> <?php do_action('mpp_after_gallery_entry'); ?> </div> <?php
/** * Get the pagination text * @return string */ function mpp_get_media_pagination() { //check if the current gallery supports playlist. then do not show pagination if (!mediapress()->the_media_query || mpp_gallery_supports_playlist(mpp_get_gallery())) { return; } return "<div class='mpp-paginator'>" . mediapress()->the_media_query->paginate() . "</div>"; }
/** * Does the gallery or type supports playlist * * @param type $gallery_id * @param type $type * @return boolean */ function mpp_gallery_supports_playlist($gallery_id = null, $type = null) { if ($gallery_id) { $gallery = mpp_get_gallery($gallery_id); $type = $gallery->type; } //currently ardcoded types, in future, we will allow registering support if (!$type) { return false; } if ($type != 'audio' && $type != 'video') { return false; } //let us not worry about individual gallery preference yet if (mpp_get_option('enable_' . $type . '_playlist')) { // enable_audio_playlist, enable_video_playlist return true; } return false; }
/** * Check if the media can be deleted by the user * * @param type $media_id * @param type $user_id * @return boolean true if allowed false otherwise */ function mpp_user_can_delete_media($media_id, $user_id = null) { if (!$user_id) { $user_id = get_current_user_id(); } $media = mpp_get_media($media_id); if (!$media) { return false; } $gallery = mpp_get_gallery($media->gallery_id); $allow = false; //do not alow editing by default //if the user is gallery creator, allow him to delete media if ($gallery->user_id == $user_id) { //should we consider context here like members gallery or groups gallery? $allow = true; } elseif ($user_id == $media->user_id) { //since current user is uploader/contributor //let us check if the gallery allows deleting for contributor $allow_deleting = mpp_get_gallery_meta($gallery->id, '_mpp_contributors_can_delete', true); if ($allow_deleting == 'yes') { $allow = true; } elseif ($allow_deleting != 'no' && mpp_get_option('contributors_can_delete')) { //check for global settings & make sure it is not overridden in the local settings $allow = true; } } return apply_filters('mpp_user_can_delete_media', $allow, $media, $gallery, $user_id); }
/** * Called after gallery deletion * * @param type $gallery_id * @return boolean */ public function delete_gallery($gallery_id) { $gallery = mpp_get_gallery($gallery_id); $dir = $this->get_component_base_dir($gallery->component, $gallery->component_id); $dir = untrailingslashit(wp_normalize_path($dir)) . '/' . $gallery->id . '/'; if ($dir) { mpp_recursive_delete_dir($dir); } $this->invalidate_transient($gallery->component, $gallery->component_id); return true; }
function mpp_gallery_record_activity($args) { $default = array('id' => false, 'gallery_id' => null, 'media_ids' => null, 'action' => '', 'content' => '', 'type' => ''); $args = wp_parse_args($args, $default); if (!$args['gallery_id']) { return false; } $gallery_id = absint($args['gallery_id']); $gallery = mpp_get_gallery($gallery_id); if (!$gallery) { return false; } $args['status'] = $gallery->status; return mpp_record_activity($args); }
function mpp_get_gallery_action_links($gallery = null) { $links = array(); $gallery = mpp_get_gallery($gallery); $links['view'] = sprintf('<a href="%1$s" title="view %2$s" class="mpp-view-gallery">%3$s</a>', mpp_get_gallery_permalink($gallery), esc_attr($gallery->title), __('view', 'mediapress')); //upload? if (mpp_user_can_upload($gallery->component, $gallery->component_id, $gallery)) { $links['upload'] = sprintf('<a href="%s" alt="' . __('upload files to %s', 'mediapress') . '">%s</a>', mpp_get_gallery_add_media_url($gallery), mpp_get_gallery_title($gallery), __('upload', 'mediapress')); } //delete if (mpp_user_can_delete_gallery($gallery)) { $links['delete'] = sprintf('<a href="%s" alt="' . __('delete %s', 'mediapress') . '" class="confirm mpp-confirm mpp-delete mpp-delete-gallery">%s</a>', mpp_get_gallery_delete_url($gallery), mpp_get_gallery_title($gallery), __('delete', 'mediapress')); } return apply_filters('mpp_gallery_actions_links', join(' ', $links), $links, $gallery); }
/** * Initilize settings based on the current stack of action variables and component etc */ public function init() { $current_action = $this->get_variable(0); //on create or upload we don't need to setup Media or Gallery Query if ($current_action == 'create' || $current_action == 'upload') { mediapress()->set_action($current_action); mediapress()->set_edit_action($current_action); return; } //check for type/status $type_or_status = $this->get_variable(1); if ($current_action === 'type' && $type_or_status && mpp_is_active_type($type_or_status)) { $this->type = $type_or_status; mediapress()->is_gallery_home = true; } elseif ($current_action == 'status' && $type_or_status && mpp_is_active_status($type_or_status)) { $this->status = $type_or_status; mediapress()->is_gallery_home = true; } elseif ($gallery = mpp_gallery_exists($current_action, $this->component, $this->component_id)) { //Are we looking at single gallery? or Media? //current action in this case is checked for being a gallery slug //setup current gallery & gallery query mediapress()->current_gallery = mpp_get_gallery($gallery); $this->gallery_id = $gallery->ID; $this->current_action = $this->get_variable(1); $this->current_manage_action = $this->get_variable(2); //setup pagination for single gallery media if ($this->get_variable(1) == 'page' && $this->get_variable(2) > 0) { $this->mpage = (int) $this->get_variable(2); } } else { if ($this->get_variable(0) == 'page' && $this->get_variable(1) > 0) { $this->gpage = (int) $this->get_variable(1); } //set it is the user galleries list view mediapress()->is_gallery_home = true; } //check and setup pagination args for status/type archives if ($this->get_variable(2) == 'page' && $this->get_variable(3) > 0) { $this->gpage = (int) $this->get_variable(3); } }
/** * Get current gallery type being added/edited * * @return string empty string or the actual type 'photo|video etc' */ private function get_editing_gallery_type() { if ($this->is_add_gallery()) { $type = $_GET['mpp-gallery-type']; if (mpp_is_registered_type($type)) { return $type; } return ''; //no type,invalid } elseif ($this->is_edit_gallery()) { global $post; $gallery = mpp_get_gallery($post); return $gallery->type; } return ''; }
function mpp_media_record_activity($args) { $default = array('media_id' => null, 'action' => '', 'content' => '', 'type' => ''); $args = wp_parse_args($args, $default); if (!$args['media_id']) { return false; } $media_id = absint($args['media_id']); $media = mpp_get_media($media_id); if (!$media) { return false; } $gallery_id = $media->gallery_id; $gallery = mpp_get_gallery($gallery_id); $status = $media->status; //when a media is public, make sure to check that the gallery is public too if ($status == 'public') { $status = mpp_get_gallery_status($gallery); } //it is actually a gallery activity, isn't it? unset($args['media_id']); $args['status'] = $status; $args['gallery_id'] = $gallery->id; // $args['media_ids'] = (array) $media_id; return mpp_record_activity($args); }