/** * 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; //get parent activity id if ('activity_comment' == $activity->type) { $activity_id = $activity->item_id; $activity = new BP_Activity_Activity($activity_id); } if ($activity->type != 'mpp_media_upload') { return $link; } $context = mpp_activity_get_context($activity_id); $gallery_id = mpp_activity_get_gallery_id($activity->id); if (!$gallery_id) { return $link; } //make sure that gallery exists $gallery = mpp_get_gallery($gallery_id); if (!$gallery) { return $link; } //if we are here, It is a gallery/media activity $media_id = mpp_activity_get_media_id($activity_id); if ($media_id && ($media = mpp_get_media($media_id))) { $link = mpp_get_media_permalink($media) . "#activity-{$activity_id}"; } else { $link = mpp_get_gallery_permalink($gallery) . "#activity-{$activity_id}"; } return $link; }
function mpp_get_media_permalink($media = null) { $media = mpp_get_media($media); $gallery_permalink = untrailingslashit(mpp_get_gallery_permalink($media->gallery_id)); if ($media->component == 'sitewide') { $gallery_permalink .= '/media'; } return apply_filters('mpp_get_media_permalink', $gallery_permalink . '/' . mpp_get_media_slug($media)); }
function mpp_media_filter_permalink($link, $post_id) { if (!mpp_is_valid_media($post_id)) { return $link; } $media = mpp_get_media($post_id); if ($media->component != 'sitewide') { return $link; } //in case of sitewide gallery, the permalink is like $gallery_permalink = mpp_get_gallery_permalink($media->gallery_id); return user_trailingslashit(untrailingslashit($gallery_permalink) . '/media/' . $media->slug); }
/** * 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_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); }
/** * Handles Media deletion * * @return type */ function mpp_action_delete_media() { if (empty($_REQUEST['mpp-action']) || $_REQUEST['mpp-action'] != 'delete-media') { return; } if (!$_REQUEST['mpp-media-id']) { return; } $referer = wp_get_referer(); if (!wp_verify_nonce($_REQUEST['mpp-nonce'], 'mpp-delete-media')) { //add error message and return back to the old page mpp_add_feedback(__('Action not authorized!', 'mediapress'), 'error'); if ($referer) { mpp_redirect($referer); } return; } $media = ''; if (!empty($_REQUEST['mpp-media-id'])) { $media = mpp_get_media((int) $_REQUEST['mpp-media-id']); } //check for permission //we may want to allow passing of component from the form in future! if (!mpp_user_can_delete_media($media->id)) { mpp_add_feedback(__("You don't have permission to delete this!", 'mediapress'), 'error'); if ($referer) { mpp_redirect($referer); } return; } //if we are here, delete media and redirect to the component base url mpp_delete_media($media->id); $redirect_url = apply_filters('mpp_media_delete_redirect_url', mpp_get_gallery_permalink($media->gallery_id), $media); mpp_add_feedback(__("Successfully deleted!", 'mediapress'), 'error'); mpp_redirect($redirect_url); }
/** * Generate/Display breadcrumb * @param array $args * @return string|null */ function mpp_gallery_breadcrumb($args = null) { $default = array('separator' => '/', 'before' => '', 'after' => '', 'show_home' => false); $args = wp_parse_args($args, $default); extract($args); $crumbs = array(); $component = mpp_get_current_component(); $component_id = mpp_get_current_component_id(); if (mediapress()->is_bp_active() && bp_is_active('groups') && bp_is_group()) { $name = bp_get_group_name(groups_get_current_group()); } elseif (mediapress()->is_bp_active() && bp_is_user()) { $name = bp_get_displayed_user_fullname(); } elseif ($component == 'sitewide') { $name = ''; } $my_or_his_gallery = ''; if ($name) { $my_or_his_gallery = sprintf(__("%s's gallery", 'mediapress'), $name); } if (function_exists('bp_is_my_profile') && bp_is_my_profile()) { $my_or_his_gallery = __('Your Galleries', 'mediapress'); } if (mpp_is_media_management()) { $crumbs[] = ucwords(mediapress()->get_edit_action()); } if (mpp_is_single_media()) { $media = mpp_get_current_media(); if (mpp_is_media_management()) { $crumbs[] = sprintf('<a href="%s">%s</a>', mpp_get_media_permalink($media), mpp_get_media_title($media)); } else { $crumbs[] = sprintf('<span>%s</span>', mpp_get_media_title($media)); } } if (mpp_is_gallery_management()) { $crumbs[] = ucwords(mediapress()->get_edit_action()); } if (mpp_is_single_gallery()) { $gallery = mpp_get_current_gallery(); if (mpp_is_gallery_management() || mpp_is_single_media()) { $crumbs[] = sprintf('<a href="%s">%s</a>', mpp_get_gallery_permalink($gallery), mpp_get_gallery_title($gallery)); } else { $crumbs[] = sprintf('<span>%s</span>', mpp_get_gallery_title($gallery)); } } if ($my_or_his_gallery) { $crumbs[] = sprintf('<a href="%s">%s</a>', mpp_get_gallery_base_url($component, $component_id), $my_or_his_gallery); } if (count($crumbs) <= 1 && !$show_home) { return; } $crumbs = array_reverse($crumbs); echo join($separator, $crumbs); }
/** * 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); }
/** * Generate an activity when a new gallery is created * We will not generate any activity for profile galleries though. * * @param type $gallery_id */ function mpp_new_gallery_activity($gallery_id) { //if the admin settings does not ask us to create new activity, //Or it is explicitly restricted, do not proceed if (!mpp_is_auto_publish_to_activity_enabled('create_gallery') || apply_filters('mpp_do_not_record_create_gallery_activity', false)) { return; } $gallery = mpp_get_gallery($gallery_id); $user_link = bp_core_get_userlink($gallery->user_id); $link = mpp_get_gallery_permalink($gallery); mpp_gallery_record_activity(array('gallery_id' => $gallery_id, 'type' => 'create_gallery', 'content' => '', 'action' => sprintf(__('%s created a %s <a href="%s">gallery</a>', 'mediapress'), $user_link, $gallery->type, $link))); //record gallery creation as activity, there will be issue with wall gallery though }
function mpp_setup_gallery_nav() { //only add on single gallery if (!mpp_is_single_gallery()) { return; } $gallery = mpp_get_current_gallery(); $url = ''; if ($gallery) { $url = mpp_get_gallery_permalink($gallery); } //only add view/edit/dele links on the single mgallery view mpp_add_gallery_nav_item(array('label' => __('View', 'mediapress'), 'url' => $url, 'action' => 'view', 'slug' => 'view')); $user_id = get_current_user_id(); if (mpp_user_can_edit_gallery($gallery->id, $user_id)) { mpp_add_gallery_nav_item(array('label' => __('Edit Media', 'mediapress'), 'url' => mpp_get_gallery_edit_media_url($gallery), 'action' => 'edit', 'slug' => 'edit')); } if (mpp_user_can_upload($gallery->component, $gallery->component_id)) { mpp_add_gallery_nav_item(array('label' => __('Add Media', 'mediapress'), 'url' => mpp_get_gallery_add_media_url($gallery), 'action' => 'add', 'slug' => 'add')); } if (mpp_user_can_edit_gallery($gallery->id, $user_id)) { mpp_add_gallery_nav_item(array('label' => __('Reorder', 'mediapress'), 'url' => mpp_get_gallery_reorder_media_url($gallery), 'action' => 'reorder', 'slug' => 'reorder')); mpp_add_gallery_nav_item(array('label' => __('Edit Details', 'mediapress'), 'url' => mpp_get_gallery_settings_url($gallery), 'action' => 'settings', 'slug' => 'settings')); } if (mpp_user_can_delete_gallery($gallery->id)) { mpp_add_gallery_nav_item(array('label' => __('Delete', 'mediapress'), 'url' => mpp_get_gallery_delete_url($gallery), 'action' => 'delete', 'slug' => 'delete')); } }
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); }
/** * Get the url for gallery management page * * It is like http://site.com/xyz/single-gallery-permalink/manage/ [ single-gallary-permalink/manage/ * @param type $gallery * @return type */ function mpp_get_gallery_management_base_url($gallery = null) { $gallery = mpp_get_gallery($gallery); $link = mpp_get_gallery_permalink($gallery) . '/manage/'; $link = apply_filters('mpp_get_gallery_management_base_url', $link, $gallery); return $link; }
/** * 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); }
function mpp_get_media_permalink($media = null) { $media = mpp_get_media($media); $gallery_permalink = mpp_get_gallery_permalink($media->gallery_id); return apply_filters('mpp_get_media_permalink', $gallery_permalink . '/' . mpp_get_media_slug($media)); }