/** * Since we are filtering on 'bp_activity_prefetch_object_data', the activity meta is already cached, * So, we won't query for media ids instead loop and build the list * * @param type $activities */ public function cache($activities) { if (empty($activities)) { return; } $media_ids = array(); $gallery_ids = array(); foreach ($activities as $activity) { //check if the activity has attached gallery $gallery_id = mpp_activity_get_gallery_id($activity->id); if ($gallery_id) { $gallery_ids[] = $gallery_id; } //check for media ids $attached_media_ids = mpp_activity_get_attached_media_ids($activity->id); if (!empty($attached_media_ids)) { $media_ids = array_merge($media_ids, $attached_media_ids); } $associated_media_id = mpp_activity_get_media_id($activity->id); if (!empty($associated_media_id)) { $media_ids[] = $associated_media_id; } } $merged_ids = array_merge($media_ids, $gallery_ids); $merged_ids = array_unique($merged_ids); if (!empty($merged_ids)) { _prime_post_caches($merged_ids, true, true); } return $activities; }
/** * Check if activity has associated media * * @param int $activity_id * @return mixed false if no attachment else array of attachment ids */ function mpp_activity_has_media($activity_id = false) { if (!$activity_id) { $activity_id = bp_get_activity_id(); } return mpp_activity_get_attached_media_ids($activity_id); }
/** * 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); }
public function fetch_activity_media() { //do we need nonce validation for this request too? no $items = array(); $activity_id = $_POST['activity_id']; if (!$activity_id) { exit(0); } $media_ids = mpp_activity_get_attached_media_ids($activity_id); if (empty($media_ids)) { array_push($items, __('Sorry, Nothing found!', 'mediapress')); wp_send_json(array('items' => $items)); exit(0); } $gallery_id = mpp_activity_get_gallery_id($activity_id); $gallery = mpp_get_gallery($gallery_id); if ($gallery->component == 'groups' && function_exists('bp_is_active') && bp_is_active('groups')) { //if( empty( buddypress()->groups)) } $media_query = new MPP_Media_Query(array('in' => $media_ids)); 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); }
/** * 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); }
<?php // Exit if the file is accessed directly over web if (!defined('ABSPATH')) { exit; } /** * List videos attached to activity * */ ?> <div class="mpp-container mpp-media-list mpp-activity-media-list mpp-activity-video-list mpp-activity-video-player"> <?php $ids = mpp_activity_get_attached_media_ids(bp_get_activity_id()); //is there only one video attached? if (count($ids) == 1) { $ids = array_pop($ids); $media = mpp_get_media($ids); $args = array('src' => mpp_get_media_src('', $media), 'poster' => mpp_get_media_src('thumbnail', $media)); //show single video with poster echo wp_video_shortcode($args); } else { //show all videos as playlist echo wp_playlist_shortcode(array('ids' => $ids, 'type' => 'video')); } ?> </div>
<?php // Exit if the file is accessed directly over web if (!defined('ABSPATH')) { exit; } /*** * * Media List attached to an activity * This is a fallback template for new media types * */ $activity_id = bp_get_activity_id(); $mppq = new MPP_Cached_Media_Query(array('in' => mpp_activity_get_attached_media_ids($activity_id))); if ($mppq->have_media()) { ?> <div class="mpp-container mpp-media-list mpp-activity-media-list"> <?php while ($mppq->have_media()) { $mppq->the_media(); ?> <a href="<?php mpp_media_permalink(); ?> " ><img src="<?php mpp_media_src('thumbnail'); ?> " class='mpp-attached-media-item' data-mpp-activity-id="<?php echo $activity_id;
function mpp_delete_activity_for_single_published_media($media_id) { if (!function_exists('bp_is_active') || !bp_is_active('activity')) { return false; //or false? } global $wpdb; $bp = buddypress(); //select ids , we need to delete comment too? $query = "SELECT activity_id FROM {$bp->activity->table_name_meta} WHERE ( meta_key = %s AND meta_value = %d ) OR ( meta_key = %s AND meta_value = %d ) "; $query = $wpdb->prepare($query, '_mpp_attached_media_id', $media_id, '_mpp_media_id', $media_id); $activity_ids = $wpdb->get_col($query); if (empty($activity_ids)) { return false; } //cache the activity meta bp_activity_update_meta_cache($activity_ids); $to_delete_ids = array(); foreach ($activity_ids as $activity_id) { $ids = mpp_activity_get_attached_media_ids($activity_id); if (count($ids) <= 1) { $to_delete_ids[] = $activity_id; } } if (empty($to_delete_ids)) { return false; } $list = '(' . join(',', $to_delete_ids) . ')'; if (!$wpdb->query("DELETE FROM {$bp->activity->table_name} WHERE id IN {$list}")) { return false; } //delete comments $activity_comment_ids = mpp_delete_activity_comments($to_delete_ids); //delete all activities $deleted_ids = array_merge($to_delete_ids, $activity_comment_ids); //get associated WordPress comment ids? No need to worry about that BP_Activity_Activity::delete_activity_meta_entries($deleted_ids); }
/** * 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); }
<?php // Exit if the file is accessed directly over web if (!defined('ABSPATH')) { exit; } /*** * List Photos attched to an activity * * Media List attached to an activity * */ $activity_id = bp_get_activity_id(); $mppq = new MPP_Cached_Media_Query(array('in' => mpp_activity_get_attached_media_ids($activity_id))); $ids = mpp_activity_get_attached_media_ids($activity_id); if ($mppq->have_media()) { ?> <ul class="mpp-item-list mpp-activity-media-item-list"> <?php while ($mppq->have_media()) { $mppq->the_media(); ?> <li class="mpp-list-item-entry mpp-list-item-entry-<?php echo mpp_media_type(); ?> "> <?php do_action('mpp_before_media_activity_item'); ?>
public function fetch_activity_media() { //do we need nonce validation for this request too? no $items = array(); $activity_id = $_POST['activity_id']; if (!$activity_id) { exit(0); } $media_ids = mpp_activity_get_attached_media_ids($activity_id); if (empty($media_ids)) { array_push($items, __('Sorry, Nothing found!', 'mediapress')); wp_send_json(array('items' => $items)); exit(0); } $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); //should we check for 'local' instead of default? 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_query = new MPP_Media_Query(array('in' => $media_ids)); if ($media_query->have_media()) { ?> <?php while ($media_query->have_media()) { $media_query->the_media(); ?> <?php $items[] = array('src' => $this->get_activity_media_lightbox_entry()); ?> <?php } ?> <?php } ?> <?php mpp_reset_media_data(); ?> <?php //media-loop-audio/media-loop-video,media-loop-photo, media-loop //mpp_get_template_part( 'gallery/activity/loop', $slug ); wp_send_json(array('items' => $items)); exit(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); }