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); }
public function context_menu_edit() { if (!mpp_is_single_gallery()) { return; } if (mpp_is_gallery_management() || mpp_is_media_management()) { return; } if (!mpp_user_can_edit_gallery(mpp_get_current_gallery_id())) { return; } $links = ''; if (mpp_is_single_media()) { $url = mpp_get_media_edit_url(); $links .= sprintf('<li><a href="%1$s" title ="%2$s"> %3$s</a></li>', $url, _x('Edit media', 'Profile context menu rel', 'mediapress'), _x('Edit', 'Profile context menu media edit label', 'mediapress')); } else { $url = mpp_get_gallery_edit_media_url(mpp_get_current_gallery()); //bulk edit media url $links .= sprintf('<li><a href="%1$s" title ="%2$s"> %3$s</a></li>', $url, _x('Edit Gallery', 'Profile context menu rel attribute', 'mediapress'), _x('Edit', 'Profile contextual edit gallery menu label', 'mediapress')); $links .= sprintf('<li><a href="%1$s" title ="%2$s"> %3$s</a></li>', mpp_get_gallery_add_media_url(mpp_get_current_gallery()), _x('Add Media', 'Profile context menu rel attribute', 'mediapress'), _x('Add Media', 'Profile contextual add media menu label', 'mediapress')); } echo $links; }
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')); } }
/** * Handles Gallery creation on the front end in non ajax case * * @return type */ function mpp_action_create_gallery() { //allow gallery to be created from anywhere //the form must have mpp-action set and It should be set to 'create-gallery' if (empty($_POST['mpp-action']) || $_POST['mpp-action'] != 'create-gallery') { return; } $referer = wp_get_referer(); //if we are here, It is gallery create action if (!wp_verify_nonce($_POST['mpp-nonce'], 'mpp-create-gallery')) { //add error message and return back to the old page mpp_add_feedback(__('Action not authorized!', 'mediapress'), 'error'); if ($referer) { mpp_redirect($referer); } return; } //update it to allow passing component/id from the form $component = mpp_get_current_component(); $component_id = mpp_get_current_component_id(); //check for permission //we may want to allow passing of component from the form in future! if (!mpp_user_can_create_gallery($component, $component_id)) { mpp_add_feedback(__("You don't have permission to create gallery!", 'mediapress'), 'error'); if ($referer) { mpp_redirect($referer); } return; } //if we are here, validate the data and let us see if we can create $title = $_POST['mpp-gallery-title']; $description = $_POST['mpp-gallery-description']; $type = $_POST['mpp-gallery-type']; $status = $_POST['mpp-gallery-status']; $errors = array(); if (!mpp_is_active_status($status)) { $errors['status'] = __('Invalid Gallery status!', 'mediapress'); } if (!mpp_is_active_type($type)) { $errors['type'] = __('Invalid gallery type!', 'mediapress'); } //check for current component if (!mpp_is_active_component($component)) { $errors['component'] = __('Invalid gallery component!', 'mediapress'); } if (empty($title)) { $errors['title'] = __('Title can not be empty', 'mediapress'); } //give opportunity to other plugins to add their own validation errors $validation_errors = apply_filters('mpp-create-gallery-field-validation', $errors, $_POST); if (!empty($validation_errors)) { //let us add the validation error and return back to the earlier page $message = join('\\r\\n', $validation_errors); mpp_add_feedback($message, 'error'); if ($referer) { mpp_redirect($referer); } return; } //let us create gallery $gallery_id = mpp_create_gallery(array('title' => $title, 'description' => $description, 'type' => $type, 'status' => $status, 'creator_id' => get_current_user_id(), 'component' => $component, 'component_id' => $component_id)); if (!$gallery_id) { mpp_add_feedback(__('Unable to create gallery!', 'mediapress'), 'error'); if ($referer) { mpp_redirect($referer); } return; } //if we are here, the gallery was created successfully, //let us redirect to the gallery_slug/manage/upload page $redirect_url = mpp_get_gallery_add_media_url($gallery_id); mpp_add_feedback(__('Gallery created successfully!', 'mediapress')); mpp_redirect($redirect_url); }
/** * Print the url of the add media sub page for the gallery management screen * * @param type $gallery */ function mpp_gallery_add_media_url($gallery = null) { echo mpp_get_gallery_add_media_url($gallery); }