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); }
public function show_status_drodown() { if (!$this->is_add_gallery() && !$this->is_edit_gallery()) { return; } $is_new = false; if ($this->is_add_gallery()) { $is_new = true; } global $post; //_prime_post_caches( (array) $id , true, true ); $gallery = mpp_get_gallery($post); $component = $is_new ? '' : $gallery->component; $type = $is_new ? '' : $gallery->type; if (empty($type)) { $type = $this->get_editing_gallery_type(); } $selected = $is_new ? mpp_get_default_status() : $gallery->status; if (!$component && mpp_is_active_component('sitewide')) { $component = 'sitewide'; } ?> <div class='misc-status-section'> <label for='mpp-gallery-status'> <strong><?php _e('Status', 'mediapress'); ?> </strong> <?php mpp_status_dd(array('selected' => $selected, 'component' => $component)); // ?> </label> <input type='hidden' name="mpp-gallery-component-id" value="<?php echo $this->get_component_id($post->ID); ?> " /> <input type='hidden' name="mpp-gallery-type" value="<?php echo $type; ?> " /> <input type='hidden' name="mpp-gallery-component" value="<?php echo $component; ?> " /> </div> <?php }
/** * Initialize the admin settings panel and fields * */ public function init() { //'mpp-settings' is used as page slug as well as option to store in the database $page = new MPP_Admin_Settings_Page('mpp-settings'); //MPP_Admin_Page( 'mpp-settings' ); //Add a panel to to the admin //A panel is a Tab and what coms under that tab $panel = $page->add_panel('general', _x('General', 'Admin settings panel title', 'mediapress')); //A panel can contain one or more sections. each sections or $section = $panel->add_section('component-settings', _x('Component Settings', 'Admin settings section title', 'mediapress')); $components_details = array(); $components = mpp_get_registered_components(); foreach ($components as $key => $component) { $components_details[$key] = $component->label; } $component_keys = array_keys($components_details); $default_components = array_combine($component_keys, $component_keys); $active_components = array_keys(mpp_get_active_components()); if (!empty($active_components)) { $default_components = array_combine($active_components, $active_components); } $section->add_field(array('name' => 'active_components', 'label' => _x('Enable Galleries for?', 'Admin settings', 'mediapress'), 'type' => 'multicheck', 'options' => $components_details, 'default' => $default_components)); //second section // //enabled status //status $available_media_stati = mpp_get_registered_statuses(); $options = array(); foreach ($available_media_stati as $key => $available_media_status) { $options[$key] = $available_media_status->get_label(); } $panel->add_section('status-settings', _x('Privacy Settings', 'Admin settings section title', 'mediapress'))->add_field(array('name' => 'default_status', 'label' => _x('Default status for Gallery/Media', 'Admin settings', 'mediapress'), 'description' => _x('It will be used when we are not allowed to get the status from user', 'Admin settings', 'mediapress'), 'default' => mpp_get_default_status(), 'options' => $options, 'type' => 'select')); $section = $panel->get_section('status-settings'); $registered_statuses = mpp_get_registered_statuses(); $status_info = array(); foreach ($registered_statuses as $key => $status) { $status_info[$key] = $status->label; } $active_statuses = array_keys(mpp_get_active_statuses()); $status_keys = array_keys($status_info); $default_statuses = array_combine($status_keys, $status_keys); if (!empty($active_statuses)) { $default_statuses = array_combine($active_statuses, $active_statuses); } $section->add_field(array('name' => 'active_statuses', 'label' => _x('Enabled Media/Gallery Statuses', 'Admin settings', 'mediapress'), 'type' => 'multicheck', 'options' => $status_info, 'default' => $default_statuses)); //3rd section //enabled type? //types $section = $panel->add_section('types-settings', _x('Media Type settings', 'Admin settings section title', 'mediapress')); $valid_types = mpp_get_registered_types(); $options = array(); $types_info = array(); $extension_fields = array(); foreach ($valid_types as $type => $type_object) { $types_info[$type] = $type_object->label; $extension_fields[] = array('id' => 'extensions-' . $type, 'name' => 'extensions', 'label' => sprintf(_x('Allowed extensions for %s', 'Settings page', 'mediapress'), $type), 'description' => sprintf(_x('Use comma separated list of file extensions for %s ', 'Settings page', 'mediapress '), $type), 'default' => join(',', (array) $type_object->get_registered_extensions()), 'type' => 'extensions', 'extra' => array('key' => $type, 'name' => 'extensions')); } $type_keys = array_keys($types_info); $default_types = array_combine($type_keys, $type_keys); $active_types = array_keys(mpp_get_active_types()); if (!empty($active_types)) { $default_types = array_combine($active_types, $active_types); } $section->add_field(array('name' => 'active_types', 'label' => _x('Enabled Media/Gallery Types', 'Settings page', 'mediapress'), 'type' => 'multicheck', 'options' => $types_info, 'default' => $default_types)); /* $section->add_field( array( 'name' => 'allow_mixed_gallery', 'label' => __( 'Allow mixed Galleries?', 'mediapress' ), 'type' => 'radio', 'default' => 0,//10 MB 'options' => array( 1 => 'Yes', 0 => 'No', ), 'description' => __( 'Please keep it disabled. It is not truly enabled at the moment', 'mediapress' ) ) );*/ $section->add_fields($extension_fields); //4th section //enabled storage //Storage section $panel->add_section('storage-settings', _x('Storage Settings', 'Settings page section title', 'mediapress'))->add_field(array('name' => 'mpp_upload_space', 'label' => _x('maximum Upload space per user(MB)?', 'Admin storage settings', 'mediapress'), 'type' => 'text', 'default' => 10))->add_field(array('name' => 'mpp_upload_space_groups', 'label' => _x('maximum Upload space per group(MB)?', 'Admin storage settings', 'mediapress'), 'type' => 'text', 'default' => 10))->add_field(array('name' => 'show_upload_quota', 'label' => _x('Show upload Quota?', 'Admin storage settings', 'mediapress'), 'type' => 'radio', 'default' => 0, 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress')))); $storage_methods = mpp_get_registered_storage_managers(); $storage_methods = array_keys($storage_methods); $storage_method_options = array(); foreach ($storage_methods as $storage_method) { $storage_method_options[$storage_method] = ucfirst($storage_method); } //->add_field(); $panel->get_section('storage-settings')->add_field(array('name' => 'default_storage', 'label' => _x('Which should be marked as default storage?', 'Admin storage settings', 'mediapress'), 'default' => mpp_get_default_storage_method(), 'options' => $storage_method_options, 'type' => 'radio')); //5th section //activity settings $activity_section = $panel->add_section('activity-settings', _x('Activity Settings', 'Admin settings section title', 'mediapress')); $activity_section->add_field(array('name' => 'activity_upload', 'label' => _x('Allow Activity Upload?', 'Admin settings', 'mediapress'), 'desc' => _x('Allow users to uploading from Activity screen?', 'Admin settings', 'mediapress'), 'default' => 1, 'type' => 'radio', 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress')))); $activity_options = array('create_gallery' => _x('New Gallery is created.', 'Admin settings', 'mediapress'), 'add_media' => _x('New Media added/uploaded.', 'Admin settings', 'mediapress')); $default_activities = array_keys($activity_options); $default_activities = array_combine($default_activities, $default_activities); $activity_section->add_field(array('name' => 'autopublish_activities', 'label' => _x('Automatically Publish to activity When?', 'Admin settings', 'mediapress'), 'type' => 'multicheck', 'options' => $activity_options, 'default' => $default_activities)); //6th section //directory settings $panel->add_section('directory-settings', _x('Directory Settings', 'Admin settings section title', 'mediapress'))->add_field(array('name' => 'has_gallery_directory', 'label' => _x('Enable Gallery Directory?', 'Admin settings', 'mediapress'), 'desc' => _x('Create a page to list all galleries?', 'Admin settings', 'mediapress'), 'default' => 1, 'type' => 'radio', 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress'))))->add_field(array('name' => 'has_media_directory', 'label' => _x('Enable Media directory?', 'Admin settings', 'mediapress'), 'desc' => _x('Create a page to list all photos, videos etc? Please keep it disabled for now )', 'Admin settings', 'mediapress'), 'default' => 1, 'type' => 'radio', 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress')))); $panel->add_section('group-settings', _x('Group Settings', 'Admin settings section title', 'mediapress'))->add_field(array('name' => 'contributors_can_edit', 'label' => _x('Contributors can edit their own media?', 'Admin settings group section', 'mediapress'), 'type' => 'radio', 'default' => 1, 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress'))))->add_field(array('name' => 'contributors_can_delete', 'label' => _x('Contributors can delete their own media?', 'Admin settings group section', 'mediapress'), 'type' => 'radio', 'default' => 1, 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress')))); $panel->add_section('misc-settings', _x('Miscellaneous Settings', 'Admin settings section title', 'mediapress'))->add_field(array('name' => 'show_orphaned_media', 'label' => _x('Show orphaned media to the user?', 'Admin settings option', 'mediapress'), 'desc' => _x('Do you want to list the media if it was uploaded from activity but the activity was not published?', 'Admin settings', 'mediapress'), 'type' => 'radio', 'default' => 0, 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress'))))->add_field(array('name' => 'delete_orphaned_media', 'label' => _x('Delete orphaned media automatically?', 'Admin settings', 'mediapress'), 'desc' => _x('Do you want to delete the abandoned media uploade from activity?', 'Admin settings', 'mediapress'), 'type' => 'radio', 'default' => 1, 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress')))); $theme_panel = $page->add_panel('theming', _x('Theming', 'Admin settings theme panel tab title', 'mediapress')); $theme_panel->add_section('display-settings', _x('Display Settings ', 'Admin settings theme section title', 'mediapress'))->add_field(array('name' => 'galleries_per_page', 'label' => _x('How many galleries to list per page?', 'Admin theme settings', 'mediapress'), 'type' => 'text', 'default' => 12))->add_field(array('name' => 'media_per_page', 'label' => _x('How many Media per page?', 'Admin theme settings', 'mediapress'), 'type' => 'text', 'default' => 12))->add_field(array('name' => 'media_columns', 'label' => _x('How many media per row?', 'Admin theme settings', 'mediapress'), 'type' => 'text', 'default' => 4))->add_field(array('name' => 'gallery_columns', 'label' => _x('How many galleries per row?', 'Admin theme settings', 'mediapress'), 'type' => 'text', 'default' => 4)); $theme_panel->add_section('audio-video', _x('Audio/Video specific settings', ' Admin theme section title', 'mediapress'))->add_field(array('name' => 'enable_audio_playlist', 'label' => _x('Enable Audio Playlist?', 'admin theme settings', 'mediapress'), 'description' => _x('Should an audio gallery be listed as a playlist?', 'admin theme settings', 'mediapress'), 'default' => 1, 'type' => 'radio', 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress'))))->add_field(array('name' => 'enable_video_playlist', 'label' => _x('Enable Video Playlist?', 'admin theme settings', 'mediapress'), 'description' => _x('Should a video gallery be listed as a playlist?', 'admin theme settings', 'mediapress'), 'default' => 1, 'type' => 'radio', 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress')))); $theme_panel->add_section('comments', _x('Comment Settings', 'Admin theme section title', 'mediapress'))->add_field(array('name' => 'enable_media_comment', 'label' => _x('Enable Commenting on single media?', 'admin theme comment settings', 'mediapress'), 'default' => 1, 'type' => 'radio', 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress'))))->add_field(array('name' => 'enable_gallery_comment', 'label' => 'Enable Commenting on single Gallery?', 'default' => 1, 'type' => 'radio', 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress')))); $theme_panel->add_section('lightbox', _x('Lightbox Settings', 'admin theme section title', 'mediapress'))->add_field(array('name' => 'load_lightbox', 'label' => _x('Load Lightbox javascript & css )?', 'Admin theme settings', 'mediapress'), 'description' => _x('Should we load the included lightbox script? Set no, if you are not using lightbox or want to use your own', 'Admin settings', 'mediapress'), 'default' => 1, 'type' => 'radio', 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress'))))->add_field(array('name' => 'enable_activity_lightbox', 'label' => _x('Open Activity media in lightbox ?', 'Admin theme settings', 'mediapress'), 'description' => _x('If you set yes, the photos etc will be open in lightbox on activity screen.', 'Admin theme settings', 'mediapress'), 'default' => 1, 'type' => 'radio', 'options' => array(1 => _x('Yes', 'Admin settings option', 'mediapress'), 0 => _x('No', 'Admin settings option', 'mediapress')))); //add an empty addons panel to allow plugins to register any setting here //though a plugin can add a new panel, smaller plugins should use this panel instead $page->add_panel('addons', _x('Addons', 'Admin settings Addons panel tab title', 'mediapress'), _x('MediaPress Addon Settings', 'Addons panel description', 'mediapress')); //auto posting to activity on gallery upload? //should post after the whole gallery is uploaded or just after each media? $this->page = $page; mpp_admin()->set_page($this->page); do_action('mpp_admin_register_settings', $page); //allow enab $page->init(); }
/** * Create new Gallery * @param type $args * @return boolean */ function mpp_create_gallery($args = '') { $default = array('id' => false, 'creator_id' => get_current_user_id(), 'title' => '', 'description' => '', 'slug' => '', 'status' => '', 'order' => false, 'component' => false, 'component_id' => false, 'type' => '', 'date_created' => '', 'date_updated' => ''); //if the gallery id is set if (isset($args['id']) && !empty($args['id'])) { return mpp_update_gallery($args); } $args = wp_parse_args($args, $default); extract($args); $post_data = array('post_type' => mpp_get_gallery_post_type(), 'post_status' => 'publish', 'post_author' => $creator_id, 'post_title' => $title, 'post_content' => $description, 'post_name' => $slug); //if no component id is given, assume to be user gallery if (!$component_id) { $component_id = get_current_user_id(); } //if a component is not given, assume it to be user gallery if (!$component) { $component = 'members'; } if (!mpp_is_enabled($component, $component_id)) { return false; // not enabled for this, can not be created } if (!$type) { $type = 'photo'; } $gallery_status = mpp_get_default_status(); if (!empty($status)) { if (mpp_is_registered_status($status)) { $gallery_status = $status; } } //hierarchical tax should always pass ids $tax = array(mpp_get_component_taxname() => mpp_underscore_it($component), mpp_get_type_taxname() => mpp_underscore_it($type), mpp_get_status_taxname() => mpp_underscore_it($gallery_status)); $post_data['tax_input'] = $tax; if (!empty($date_created)) { $post_data['post_date'] = $date_created; } if (!empty($date_updated)) { $post_data['post_modified'] = $date_updated; } $gallery_id = wp_insert_post($post_data); if (is_wp_error($gallery_id)) { return false; //unable to add gallery } //otherwise update the meta with component id mpp_update_gallery_meta($gallery_id, '_mpp_component_id', $component_id); //fire the gallery created action do_action('mpp_gallery_created', $gallery_id); return $gallery_id; }
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']); $parent_type = isset($_POST['mpp-parent-type']) ? trim($_POST['mpp-parent-type']) : 'gallery'; //default upload to gallery cover 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); //cover shuld never be recorded as activity add_filter('mpp_do_not_record_add_media_activity', '__return_true'); $id = mpp_add_media($media_data); if ($parent_type == 'gallery') { $old_cover = mpp_get_gallery_cover_id($parent_id); } else { $old_cover = mpp_get_media_cover_id($parent_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); } }
// Exit if the file is accessed directly over web if (!defined('ABSPATH')) { exit; } //action:mediapress/create :- Create Gallery template ?> <div id="mpp-gallery-create-form-wrapper" class="mpp-container" > <?php if (mpp_user_can_create_gallery(mpp_get_current_component(), mpp_get_current_component_id())) { ?> <form method="post" action="" id="mpp-gallery-create-form" class="mpp-form mpp-form-stacked mpp-gallery-create-form"> <?php $title = $description = $type = ''; $status = mpp_get_default_status(); if (!empty($_POST['mpp-gallery-title'])) { $title = $_POST['mpp-gallery-title']; } if (!empty($_POST['mpp-gallery-description'])) { $description = $_POST['mpp-gallery-description']; } if (!empty($_POST['mpp-gallery-status'])) { $status = $_POST['mpp-gallery-status']; } if (!empty($_POST['mpp-gallery-type'])) { $type = $_POST['mpp-gallery-type']; } ?> <?php