Exemple #1
0
/**
 * On New Activity Comment, Create a new WordPress comment too
 * 
 * @param type $comment_id
 * @param type $param
 * @param type $activity
 * @return type
 */
function mpp_activity_synchronize_to_comment($comment_id, $param, $activity)
{
    //it must be upload from activity
    //so lt us crea
    //check that the media was posted in activity
    $gallery_id = mpp_activity_get_gallery_id($activity->id);
    if (!$gallery_id) {
        return;
    }
    $bp_comment = new BP_Activity_Activity($comment_id);
    //now we need to add a comment
    //
    //my logic to find the parent may be flawed here, Needs a confirmation from other people
    if ($bp_comment->secondary_item_id != $activity->id) {
        $parent_id = $bp_comment->secondary_item_id;
        //this is a multilevel comment
        //we will add a child comment in wp too as the
    } else {
        $parent_id = $activity->id;
    }
    $wp_comment_parent_id = (int) mpp_activity_get_associated_comment_id($parent_id);
    //if we are here, It must be an activity where we have uploaded media
    //we will create a comment and add
    if ($wp_comment_parent_id > 0) {
        //we have a parent comment associated, so we will be adding a child comment
        $wp_comment = get_comment($wp_comment_parent_id);
    }
    $commetn_data = array('post_id' => $gallery_id, 'user_id' => get_current_user_id(), 'comment_parent' => $wp_comment_parent_id, 'comment_content' => $bp_comment->content, 'comment_type' => mpp_get_comment_type());
    $new_comment_id = mpp_add_comment($commetn_data);
    //update comment meta
    if ($new_comment_id) {
        mpp_update_comment_meta($new_comment_id, '_mpp_activity_id', $comment_id);
        mpp_activity_update_associated_comment_id($comment_id, $new_comment_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;
 }
/**
 * 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);
    }
Exemple #5
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);
}
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);
}
Exemple #8
0
    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);
    }
Exemple #9
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);
}