<?php // Exit if the file is accessed directly over web if (!defined('ABSPATH')) { exit; } /*** * * Attachment in single media comment * This is a fallback template for new media types * */ $activity_id = bp_get_activity_id(); $mppq = new MPP_Cached_Media_Query(array('in' => (array) mpp_activity_get_media_id($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;
/** * 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; }
/** * Filter activity permalink and make it point to single media if the activity has an associated media * * @param string $link * @param type $activity * @return string */ function mpp_filter_activity_permalink($link, $activity) { $activity_id = $activity->id; if ('activity_comment' == $activity->type) { $activity_id = $activity->item_id; } if ($media_id = mpp_activity_get_media_id($activity_id)) { $link = mpp_get_media_permalink($media_id) . "#activity-{$activity_id}"; } elseif ($gallery_id = mpp_activity_get_gallery_id($activity->id)) { $link = mpp_get_gallery_permalink($gallery_id) . "#activity-{$activity_id}"; } return $link; }
function mpp_activity_inject_media_in_comment_replies() { $activity_id = bp_get_activity_id(); $media_id = mpp_activity_get_media_id($activity_id); if (empty($media_id)) { return; } $media = mpp_get_media($media_id); if (!$media) { return; } // $gallery_id = mpp_activity_get_gallery_id( $activity_id ); // // $gallery = mpp_get_gallery( $gallery_id ); // // if( ! $gallery ) { // return ; // } $slug = $media->type; //media-loop-audio/media-loop-video,media-loop-photo, media-loop mpp_get_template_part('buddypress/activity/entry-comment', $slug); }
function mpp_activity_create_comment_for_activity($activity_id) { if (!$activity_id || !mpp_get_option('activity_comment_sync')) { return; } $activity = new BP_Activity_Activity($activity_id); if ($activity->type != 'mpp_media_upload') { return; } $gallery_id = mpp_activity_get_gallery_id($activity_id); $media_id = mpp_activity_get_media_id($activity_id); //this is not MediaPress activity if (!$gallery_id && !$media_id) { return; } //parent post id for the comment $parent_id = $media_id > 0 ? $media_id : $gallery_id; //now, create a top level comment and save $comment_data = array('post_id' => $parent_id, 'user_id' => get_current_user_id(), 'comment_parent' => 0, 'comment_content' => $activity->content, 'comment_type' => mpp_get_comment_type()); $comment_id = mpp_add_comment($comment_data); //update comment meta if ($comment_id) { mpp_update_comment_meta($comment_id, '_mpp_activity_id', $activity_id); mpp_activity_update_associated_comment_id($activity_id, $comment_id); //also since there are media attched and we are mirroring activity, let us save the attached media too $media_ids = mpp_activity_get_attached_media_ids($activity_id); //it is a gallery upload post from activity if ($gallery_id && !empty($media_ids)) { //only available when sync is enabled if (function_exists('mpp_comment_update_attached_media_ids')) { mpp_comment_update_attached_media_ids($comment_id, $media_ids); } } //most probably a comment on media if (!empty($media_id)) { //should we add media as the comment meta? no, we don't need that at the moment } } }
/** * 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); }
/** * 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); }