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); }
<?php } ?> <?php mpp_reset_media_data(); ?> <?php } else { ?> <?php //we should seriously think about adding create gallery button here ?> <?php if (mpp_user_can_upload(mpp_get_current_component(), mpp_get_current_component_id())) { ?> <?php mpp_get_template('gallery/manage/add-media.php'); ?> <?php } else { ?> <div class="mpp-notice mpp-no-gallery-notice"> <p> <?php _ex('Nothing to see here!', 'No media Message', 'mediapress'); ?> </p> </div>
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); }
<?php /** * @package MediaPress * * Sitewide gallery single gallery home page * */ $gallery = mpp_get_current_gallery(); if (mpp_user_can_upload($gallery->component, $gallery->component_id)) { ?> <div class="mpp-menu mpp-menu-open mpp-menu-horizontal mpp-gallery-admin-menu"> <?php mpp_gallery_admin_menu(mpp_get_current_gallery(), mpp_get_current_edit_action()); ?> </div> <hr /> <?php } ?> <div class="mpp-container mpp-clearfix mpp-sitewide-component" id="mpp-container"> <div class="mpp-breadcrumbs"><?php mpp_gallery_breadcrumb(); ?> </div> <?php if (is_super_admin()) { mpp_display_space_usage(); } //main file loaded by MediaPress //it loads the requested file
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 reload_add_media() { //verify nonce if (!wp_verify_nonce($_POST['_wpnonce'], 'mpp-manage-gallery')) { wp_send_json(array('message' => __('Invalid action.', 'mediapress'), 'error' => 1)); exit(0); } $gallery_id = absint($_POST['gallery_id']); $gallery = mpp_get_gallery($gallery_id); if (!$gallery_id || !$gallery) { wp_send_json(array('message' => __('Invalid action.', 'mediapress'), 'error' => 1)); exit(0); } if (!mpp_user_can_upload($gallery->component, $gallery->component_id)) { wp_send_json(array('message' => __("You don't have permission to upload.", 'mediapress'), 'error' => 1)); exit(0); } //show the form mediapress()->current_gallery = $gallery; mediapress()->the_media_query = new MPP_Media_Query(array('gallery_id' => $gallery_id, 'per_page' => -1, 'nopaging' => true)); global $post; $bkp_post = $post; ob_start(); require_once $this->template_dir . 'gallery/add-media.php'; $contents = ob_get_clean(); $post = $bkp_post; wp_send_json(array('message' => __("Updated.", 'mediapress'), 'success' => 1, 'contents' => $contents)); exit(0); }
public function cover_upload() { check_ajax_referer('mpp_add_media'); //check for the referrer $response = array(); $file = $_FILES; $file_id = '_mpp_file'; //key name in the files array //find the components we are trying to add for $component = $component_id = 0; $context = 'cover'; $gallery_id = absint($_POST['mpp-gallery-id']); $parent_id = absint($_POST['mpp-parent-id']); if (!$gallery_id || !$parent_id) { return; } $gallery = mpp_get_gallery($gallery_id); $component = $gallery->component; $component_id = $gallery->component_id; //get the uploader $uploader = mpp_get_storage_manager(); //should we pass the component? //setup for component $uploader->setup_for($component, $component_id); //check if the server can handle the upload? if (!$uploader->can_handle()) { wp_send_json_error(array('message' => __('Server can not handle this much amount of data. Please upload a smaller file or ask your server administrator to change the settings.', 'mediapress'))); } $media_type = mpp_get_media_type_from_extension(mpp_get_file_extension($file[$file_id]['name'])); //cover is always a photo, if ($media_type != 'photo') { wp_send_json(array('message' => sprintf(__('Please upload a photo. Only <strong>%s</strong> files are allowed!', 'mediapress'), mpp_get_allowed_file_extensions_as_string($media_type)))); } $error = false; //if we are here, all is well :) if (!mpp_user_can_upload($component, $component_id, $gallery)) { wp_send_json_error(array('message' => __("You don't have sufficient permissions to upload.", 'mediapress'))); } //if we are here, we have checked for all the basic errors, so let us just upload now $uploaded = $uploader->upload($file, array('file_id' => $file_id, 'gallery_id' => $gallery_id, 'component' => $component, 'component_id' => $component_id, 'is_cover' => 1)); //upload was succesfull? if (!isset($uploaded['error'])) { //file was uploaded successfully $title = $_FILES[$file_id]['name']; $title_parts = pathinfo($title); $title = trim(substr($title, 0, -(1 + strlen($title_parts['extension'])))); $url = $uploaded['url']; $type = $uploaded['type']; $file = $uploaded['file']; //$title = isset( $_POST['media_title'] ) ? $_POST['media_title'] : ''; $content = isset($_POST['media_description']) ? $_POST['media_description'] : ''; $meta = $uploader->get_meta($uploaded); $title_desc = $this->get_title_desc_from_meta($type, $meta); if (!empty($title_desc)) { if (empty($title) && !empty($title_desc['title'])) { $title = $title_desc['title']; } if (empty($content) && !empty($title_desc['content'])) { $content = $title_desc['content']; } } $status = isset($_POST['media_status']) ? $_POST['media_status'] : ''; if (empty($status) && $gallery) { $status = $gallery->status; //inherit from parent,gallery must have an status } //we may need some more enhancements here if (!$status) { $status = mpp_get_default_status(); } // print_r($upload_info); $is_orphan = 0; $media_data = array('title' => $title, 'description' => $content, 'gallery_id' => $parent_id, 'user_id' => get_current_user_id(), 'is_remote' => false, 'type' => $media_type, 'mime_type' => $type, 'src' => $file, 'url' => $url, 'status' => $status, 'comment_status' => 'open', 'storage_method' => mpp_get_storage_method(), 'component_id' => $component_id, 'component' => $component, 'context' => $context, 'is_orphan' => $is_orphan, 'is_cover' => true); $id = mpp_add_media($media_data); $old_cover = mpp_get_gallery_cover_id($gallery_id); if ($gallery->type == 'photo') { mpp_gallery_increment_media_count($gallery_id); } else { //mark it as non gallery media mpp_delete_media_meta($id, '_mpp_is_mpp_media'); if ($old_cover) { mpp_delete_media($old_cover); } } mpp_update_media_cover_id($parent_id, $id); $attachment = mpp_media_to_json($id); //$attachment['data']['type_id'] = mpp_get_type_term_id( $gallery->type ); echo json_encode(array('success' => true, 'data' => $attachment)); //wp_send_json_success( array('name'=>'what') ); exit(0); } else { echo json_encode(array('error' => 1, 'message' => $uploaded['error'])); exit(0); } }