/** * Retrieve HTML for media items of post gallery. * * The HTML markup retrieved will be created for the progress of SWF Upload * component. Will also create link for showing and hiding the form to modify * the image attachment. * * @since 2.5.0 * * @param int $post_id Optional. Post ID. * @param array $errors Errors for attachment, if any. * @return string */ function get_media_items($post_id, $errors) { $attachments = array(); if ($post_id) { $post = get_post($post_id); if ($post && $post->post_type == 'attachment') { $attachments = array($post->ID => $post); } else { $attachments = get_children(array('post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC')); } } else { if (is_array($GLOBALS['wp_the_query']->posts)) { foreach ($GLOBALS['wp_the_query']->posts as $attachment) { $attachments[$attachment->ID] = $attachment; } } } $output = ''; foreach ((array) $attachments as $id => $attachment) { if ($attachment->post_status == 'trash') { continue; } if ($item = get_media_item($id, array('errors' => isset($errors[$id]) ? $errors[$id] : null))) { $output .= "\n<div id='media-item-{$id}' class='media-item child-of-{$attachment->post_parent} preloaded'><div class='progress hidden'><div class='bar'></div></div><div id='media-upload-error-{$id}' class='hidden'></div><div class='filename hidden'></div>{$item}\n</div>"; } } return $output; }
} elseif (empty($_COOKIE[AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie'])) { $_COOKIE[AUTH_COOKIE] = $_REQUEST['auth_cookie']; } unset($current_user); require_once 'admin.php'; header('Content-Type: text/plain; charset=' . get_option('blog_charset')); if (!current_user_can('upload_files')) { wp_die(__('You do not have permission to upload files.')); } // just fetch the detail form for that attachment if (isset($_REQUEST['attachment_id']) && ($id = intval($_REQUEST['attachment_id'])) && $_REQUEST['fetch']) { if (2 == $_REQUEST['fetch']) { add_filter('attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2); echo get_media_item($id, array('send' => false, 'delete' => false)); } else { echo get_media_item($id); } exit; } check_admin_referer('media-form'); $id = media_handle_upload('async-upload', $_REQUEST['post_id']); if (is_wp_error($id)) { echo '<div id="media-upload-error">' . wp_specialchars($id->get_error_message()) . '</div>'; exit; } if ($_REQUEST['short']) { // short form response - attachment ID only echo $id; } else { // long form response - big chunk o html $type = $_REQUEST['type'];
function get_media_items($post_id, $errors) { if ($post_id) { $post = get_post($post_id); if ($post && $post->post_type == 'attachment') { $attachments = array($post->ID => $post); } else { $attachments = get_children("post_parent={$post_id}&post_type=attachment&orderby=menu_order ASC, ID&order=DESC"); } } else { if (is_array($GLOBALS['wp_the_query']->posts)) { foreach ($GLOBALS['wp_the_query']->posts as $attachment) { $attachments[$attachment->ID] = $attachment; } } } if (empty($attachments)) { return ''; } foreach ($attachments as $id => $attachment) { if ($item = get_media_item($id, array('errors' => isset($errors[$id]) ? $errors[$id] : null))) { $output .= "\n<div id='media-item-{$id}' class='media-item child-of-{$attachment->post_parent} preloaded'><div class='progress'><div class='bar'></div></div><div id='media-upload-error-{$id}'></div><div class='filename'></div>{$item}\n</div>"; } } return $output; }
</h2> <form method="post" action="" class="media-upload-form" id="media-single-form"> <p class="submit" style="padding-bottom: 0;"> <?php submit_button(__('Update Media'), 'primary', 'save', false); ?> </p> <div class="media-single"> <div id='media-item-<?php echo $att_id; ?> ' class='media-item'> <?php echo get_media_item($att_id, array('toggle' => false, 'send' => false, 'delete' => false, 'show_title' => false, 'errors' => !empty($errors[$att_id]) ? $errors[$att_id] : null)); ?> </div> </div> <?php submit_button(__('Update Media'), 'primary', 'save'); ?> <input type="hidden" name="post_id" id="post_id" value="<?php echo isset($post_id) ? esc_attr($post_id) : ''; ?> " /> <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr($att_id); ?> " />
/** * Download the picture selected, associate it to the post and displays the * final form using get_media_item() * * @param noting. * @return noting. **/ function media_pac_pickapic_final_form() { global $type, $wp_version; $post_id = absint($_REQUEST['post_id']); $form_action_url = admin_url("media-upload.php?type={$type}&tab=pickapictab&post_id={$post_id}"); $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type); media_upload_header(); $flickr_info = pac_pickapic_flickr_getInfo($_POST['pac_pickapic_flickr_id']); $photo_url = pac_pickapic_flickr_getSizes($_POST['pac_pickapic_flickr_id']); if (is_wp_error($photo_url)) { pac_pickapic_show_error($rsp_obj); return; } ?> <form id="pickapic-media-form" enctype="multipart/form-data" action="<?php echo esc_html($form_action_url); ?> " class="media-upload-form type-form validate" method="post"> <?php wp_nonce_field('media-form'); ?> <div id="media-items"> <?php if (version_compare($wp_version, '3.4', '<')) { $excerpt = __('Foto: ' . $flickr_info['owner'], 'pickapic'); } else { $excerpt = __('Foto: ', 'pickapic') . "<a href='" . $flickr_info['url'] . "' target='_blank'>" . $flickr_info['owner'] . "</a>"; $show_license = pac_pickapic_get_option('flickrshowlicense'); if ($show_license) { $flickr_licenses = unserialize(PICKAPIC_FLICKR_LICENSES); $excerpt .= ' - ' . $flickr_licenses[$flickr_info['license']]; } } $attachment_id = pac_pickapic_media_sideload_image($photo_url, $post_id, '', array('post_title' => __($flickr_info['title'], 'pickapic'), 'post_excerpt' => $excerpt), $flickr_info['url'], $flickr_info['owner']); if (is_wp_error($attachment_id)) { echo '<div id="media-upload-error">' . esc_html($attachment_id->get_error_message()) . '</div></div>'; } else { // Render the form content using get_media_item $args = array('toggle' => false, 'show_title' => true); echo get_media_item($attachment_id, $args); } ?> </div> </form> <?php }
function get_media_items( $post_id, $errors ) { if ( $post_id ) { $post = get_post($post_id); if ( $post && $post->post_type == 'attachment' ) $attachments = array($post->ID => $post); else $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') ); } else { if ( is_array($GLOBALS['wp_the_query']->posts) ) foreach ( $GLOBALS['wp_the_query']->posts as $attachment ) $attachments[$attachment->ID] = $attachment; } if ( empty($attachments) ) return ''; foreach ( $attachments as $id => $attachment ) if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) ) $output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div class='progress'><div class='bar'></div></div><div id='media-upload-error-$id'></div><div class='filename'></div>$item\n</div>"; return $output; }
break; endswitch; } if ( $message ) echo "<div id='message' class='$class'><p>$message</p></div>\n"; ?> <div class="wrap"> <h2><?php _e( 'Edit Media' ); ?></h2> <form method="post" action="<?php echo clean_url( remove_query_arg( 'message' ) ); ?>" class="media-upload-form" id="media-single-form"> <div id="media-items" class="media-single"> <div id='media-item-<?php echo $att_id; ?>' class='media-item'> <?php echo get_media_item( $att_id, array( 'toggle' => false, 'send' => false, 'delete' => false, 'errors' => $errors ) ); ?> </div> </div> <p class="submit"> <input type="submit" class="button" name="save" value="<?php _e('Save Changes'); ?>" /> <input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>" /> <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo $att_id; ?>" /> <input type="hidden" name="action" value="editattachment" /> <?php wp_original_referer_field(true, 'previous'); ?> <?php wp_nonce_field('media-form'); ?> </p> </div>
<form action="<?php echo $url; ?> " method="post" style="padding:0 10px 10px" class="media-item"> <div class="submit"><input type="submit" class="button-primary" value="<?php _e('Update Media'); ?> " /></div> <input type="hidden" name="action" value="editattachment" /> <input type="hidden" name="attachment_id" value="<?php echo $id; ?> " /> <?php wp_nonce_field('media-form'); wp_original_referer_field(true, 'current'); echo get_media_item($id, array('toggle' => false, 'show_title' => false)); ?> <div class="submit"><input type="submit" class="button-primary" value="<?php _e('Update Media'); ?> " /></div> </form>
function editer_item() { global $page; global $item; global $message; $page['gabarit'] = "administration"; if (isset($_SESSION['role_user']) && droit_acces($item['editer_item'], $_SESSION['role_user'])) { $page['vue'] = "items/edit_item.vue.php"; $page['colonne'] = "items/sidebar_edit_item.vue.php"; if (isset($_GET['id'])) { $id = $_GET['id']; } if (isset($_POST['id_item'])) { $id = $_POST['id_item']; } if (is_proprietaire($id) || is_admin($_SESSION['id_user'])) { $page['item'] = get_item($id); $page['item'] = $page['item'][0]; if (isset($_POST['edit_item'])) { if (is_current_version_item($_POST['id_item'], $_POST['revision'])) { if (!has_resulat_item($_POST['id_item']) && !on_test($_POST['id_item']) && $page['item']['id_etat'] <= 2) { add_content_item($_POST['id_item'], html_entity_decode($_POST['content_item']), $_POST['couleur_item']); suppression_media_item($_POST['id_item']); if (isset($_POST['media'])) { foreach ($_POST['media'] as $media) { add_media_item($_POST['id_item'], $media); } } delete_reponse_item($_POST['id_item']); delete_dim_reponse_item($_POST['id_item']); $has_rep = false; foreach ($_POST as $name => $r) { $reponse = ""; if (strpos($name, 'repitem_textarea') !== false) { enregistrement_reponse_item(substr($name, 8), $rep, $_POST['id_item']); $has_rep = true; } elseif (strpos($name, 'repitem_input_text') !== false) { enregistrement_reponse_item(substr($name, 8), $rep, $_POST['id_item']); $has_rep = true; } elseif (strpos($name, 'repitem_') !== false) { if (is_array($r)) { foreach ($r as $rep) { if ($rep != '') { enregistrement_reponse_item(substr($name, 8), $rep[0], $_POST['id_item']); $has_rep = true; } } } else { if ($r != '') { enregistrement_reponse_item(substr($name, 8), $r, $_POST['id_item']); $has_rep = true; } } } } if ($has_rep) { set_item_to_non_consigne($_POST['id_item']); header("Location: index.php?controleur=item&tache=reponse_item&id=" . $_POST['id_item']); //header("Location: index.php?controleur=item&tache=apercu_item&id=".$_POST['id_item']); } else { header("Location: index.php?controleur=item&tache=apercu_item&id=" . $_POST['id_item']); } } else { header("Location: index.php?controleur=item&tache=apercu_item&id=" . $_POST['id_item']); } } else { $page['message'] = $message['item_outdated']; } } else { $page['item'] = get_item($_GET['id']); $page['item'] = $page['item'][0]; $page['item']['reponse'] = get_reponse_item($_GET['id']); $page['item']['media'] = get_media_item($_GET['id']); if (has_resulat_item($page['item']['id_item']) || on_test($page['item']['id_item']) || $page['item']['id_etat'] > 2) { $page['message'] = $message['item_edition_disabled']; } } } else { $page['message'] = $message['non_proprietaire']; } } else { $page['vue'] = "erreur_droit.vue.php"; } }
/** * Displays the 'Download from URL' tab (form) * * @since 1.0.8 * @param mixed $errors If not `false`, it contains one or more error messages to display to the user * @param int $attachment_id The ID of the attached image on successful retrieval from external source, or 0 */ public function onBgmUrlForm($errors, $attachment_id = 0) { media_upload_header(); $post_id = isset($_REQUEST['post_id']) ? (int) $_REQUEST['post_id'] : 0; $vars = array('nonce' => wp_nonce_field('media-form', '_wpnonce', false, false), 'get_btn' => get_submit_button(__('Download', $this->owner->getName()), 'button', 'submit', false, array('style' => 'display:inline-block')), 'save_btn' => get_submit_button(__('Save all changes', $this->owner->getName()), 'button', 'insert'), 'post_id' => $post_id, 'errors' => !is_array($errors) ? $errors : false, 'attachment_id' => $attachment_id, 'attachment' => $attachment_id ? get_media_item($attachment_id, array('toggle' => false, 'show_title' => false, 'send' => false, 'errors' => is_array($errors) && isset($errors[$attachment_id]) ? $errors[$attachment_id] : null)) : ''); $this->owner->template->display('media_library_bgm_url.html.twig', $vars); }
/** Edit Image iframe **/ public static function showIframeEditImage(Main $owner) { if (!defined('IFRAME_REQUEST')) { define('IFRAME_REQUEST', true); } if (!isset($_GET['id'])) { die; } // How did you get here? Hmm! $id = (int) $_GET['id']; $post = get_post($id); $vars = array(); $did_save = false; // Handle save request if (isset($_REQUEST['save'])) { $errors = media_upload_form_handler(); $did_save = true; } // Queue additional scripts and styles wp_enqueue_script('image-edit'); wp_enqueue_style('media'); // Send iframe header iframe_header(); if ($id == 0 || $post == false || $post->post_type != 'attachment' || $post->post_status == 'trash') { // Invalid ID or item was deleted $vars = array('deleted' => true); } else { $vars = array('did_save' => $did_save, 'has_error' => isset($errors[$id]), 'nonce' => wp_nonce_field('media-form', '_wpnonce', false, false), 'media_item' => get_media_item($id, array('toggle' => false, 'show_title' => false, 'send' => false, 'delete' => false, 'errors' => isset($errors[$id]) ? $errors[$id] : null)), 'submit' => get_submit_button(__('Save all changes'), 'button', 'save', false)); } // Render template $owner->template->display('gallery_edit_image.html.twig', $vars); // Send iframe footer and then 'die'. iframe_footer(); die; }