function render_file($id = null) { if (!$id) { echo ""; return; } // vars $file_src = wp_get_attachment_url($id); preg_match("~[^/]*\$~", $file_src, $file_name); $class = "active"; ?> <ul class="hl"> <li data-mime="<?php echo get_post_mime_type($id); ?> "> <img class="acf-file-icon" src="<?php echo wp_mime_type_icon($id); ?> " alt=""/> </li> <li> <span class="acf-file-name"><?php echo $file_name[0]; ?> </span><br /> <a href="javascript:;" class="acf-file-delete"><?php _e('Remove File', 'acf'); ?> </a> </li> </ul> <?php }
public static function get_preview_from_url($url) { $preview = ''; $images = array('jpg', 'jpeg', 'bmp', 'gif', 'png'); if (filter_var($url, FILTER_VALIDATE_URL) !== FALSE) { // check for extension, if it has extension then use it $info = pathinfo($url); if (isset($info['extension'])) { if (in_array($info['extension'], $images)) { $preview = $url; } else { $type = wp_ext2type($info['extension']); if (is_null($type)) { $type = 'default'; } $preview = includes_url() . 'images/crystal/' . $type . '.png'; } } else { // if no extension, try to discover from mime $mime = wp_remote_head($url); if (!is_wp_error($mime)) { $mime = $mime['headers']['content-type']; if (strpos($mime, 'image') === 0) { $preview = $url; } else { $preview = wp_mime_type_icon($mime); } } else { $preview = includes_url() . 'images/crystal/' . 'default' . '.png'; } } } return $preview; }
public static function attach_html($attach_id, $type = NULL) { if (!$type) { $type = isset($_GET['type']) ? $_GET['type'] : 'image'; } $attachment = get_post($attach_id); if (!$attachment) { return; } if (wp_attachment_is_image($attach_id)) { $image = wp_get_attachment_image_src($attach_id, 'thumbnail'); $image = $image[0]; } else { $image = wp_mime_type_icon($attach_id); } $html = '<li class="wpuf-image-wrap thumbnail">'; $html .= sprintf('<div class="attachment-name"><img src="%s" alt="%s" /></div>', $image, esc_attr($attachment->post_title)); if (wpuf_get_option('image_caption', 'wpuf_general', 'off') == 'on') { $html .= '<div class="wpuf-file-input-wrap">'; $html .= sprintf('<input type="text" name="wpuf_files_data[%d][title]" value="%s" placeholder="%s">', $attach_id, esc_attr($attachment->post_title), __('Title', 'wpuf')); $html .= sprintf('<textarea name="wpuf_files_data[%d][caption]" placeholder="%s">%s</textarea>', $attach_id, __('Caption', 'wpuf'), esc_textarea($attachment->post_excerpt)); $html .= sprintf('<textarea name="wpuf_files_data[%d][desc]" placeholder="%s">%s</textarea>', $attach_id, __('Description', 'wpuf'), esc_textarea($attachment->post_content)); $html .= '</div>'; } $html .= sprintf('<input type="hidden" name="wpuf_files[%s][]" value="%d">', $type, $attach_id); $html .= sprintf('<div class="caption"><a href="#" class="btn btn-danger btn-small attachment-delete" data-attach_id="%d">%s</a></div>', $attach_id, __('Delete', 'wpuf')); $html .= '</li>'; return $html; }
function acf_input_admin_l10n($l10n) { // append $l10n['media'] = array('select' => __("Select", 'acf'), 'edit' => __("Edit", 'acf'), 'update' => __("Update", 'acf'), 'uploadedTo' => __("Uploaded to this post", 'acf'), 'default_icon' => wp_mime_type_icon()); // return return $l10n; }
function aa_xml_mime_type_icon($icon, $mime, $post_id) { if ($mime == 'application/xml' || $mime == 'text/xml' || $mime == 'application/tei+xml') { return wp_mime_type_icon('document'); } return $icon; }
/** * Refresh the parameters passed to the JavaScript via JSON. * * @see WP_Fields_API_Control::to_json() */ public function to_json() { parent::to_json(); $this->json['label'] = html_entity_decode($this->label, ENT_QUOTES, get_bloginfo('charset')); $this->json['mime_type'] = $this->mime_type; $this->json['button_labels'] = $this->button_labels; $this->json['canUpload'] = current_user_can('upload_files'); $value = $this->value(); if (is_object($this->setting)) { if ($this->setting->default) { // Fake an attachment model - needs all fields used by template. // Note that the default value must be a URL, NOT an attachment ID. $type = in_array(substr($this->setting->default, -3), array('jpg', 'png', 'gif', 'bmp')) ? 'image' : 'document'; $default_attachment = array('id' => 1, 'url' => $this->setting->default, 'type' => $type, 'icon' => wp_mime_type_icon($type), 'title' => basename($this->setting->default)); if ('image' === $type) { $default_attachment['sizes'] = array('full' => array('url' => $this->setting->default)); } $this->json['defaultAttachment'] = $default_attachment; } if ($value && $this->setting->default && $value === $this->setting->default) { // Set the default as the attachment. $this->json['attachment'] = $this->json['defaultAttachment']; } elseif ($value) { $this->json['attachment'] = wp_prepare_attachment_for_js($value); } } }
/** * returns descriptive document type * used for icons in attachment list * both in backend and frontend * * needs more options and maybe a different approach... * @deprecated since 1.7.4 */ function file_gallery_get_file_type($mime) { return wp_mime_type_icon($mime); if (false !== strpos($mime, "text") || false !== strpos($mime, "xhtml")) { $type = "text"; } elseif (false !== strpos($mime, "excel")) { $type = "spreadsheet"; } elseif (false !== strpos($mime, "powerpoint")) { $type = "interactive"; } elseif (false !== strpos($mime, "code")) { $type = "code"; } elseif (false !== strpos($mime, "octet-stream")) { $type = "interactive"; } elseif (false !== strpos($mime, "audio")) { $type = "audio"; } elseif (false !== strpos($mime, "video")) { $type = "video"; } elseif (false !== strpos($mime, "stuffit") || false !== strpos($mime, "compressed") || false !== strpos($mime, "x-tar") || false !== strpos($mime, "zip")) { $type = "archive"; } elseif (false !== strpos($mime, "application")) { $type = "document"; } else { $type = "default"; } return apply_filters('file_gallery_get_file_type', $type, $mime); }
/** * Refresh the parameters passed to the JavaScript via JSON. * * @see WP_Fields_API_Control::to_json() */ public function json() { $json = parent::json(); $json['mime_type'] = $this->mime_type; $json['button_labels'] = $this->button_labels; $json['canUpload'] = current_user_can('upload_files'); $value = $this->value(); if (is_object($this->field)) { if ($this->field->default) { // Fake an attachment model - needs all fields used by template. // Note that the default value must be a URL, NOT an attachment ID. $type = 'document'; if (in_array(substr($this->field->default, -3), array('jpg', 'png', 'gif', 'bmp'))) { $type = 'image'; } $default_attachment = array('id' => 1, 'url' => $this->field->default, 'type' => $type, 'icon' => wp_mime_type_icon($type), 'title' => basename($this->field->default)); if ('image' === $type) { $default_attachment['sizes'] = array('full' => array('url' => $this->field->default)); } $json['defaultAttachment'] = $default_attachment; } if ($value && $this->field->default && $value === $this->field->default) { // Set the default as the attachment. $json['attachment'] = $json['defaultAttachment']; } elseif ($value) { $json['attachment'] = wp_prepare_attachment_for_js($value); } } return $json; }
/** * Outputs the content of the widget * * @param array $args * @param array $instance */ public function widget($args, $instance) { // outputs the content of the widget echo $args['before_widget']; if (!empty($instance['title'])) { echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title']; } $number_of_posts = -1; if (!empty($instance['show_number_files'])) { $number_of_posts = $instance['show_number_files']; } $orderby = 'date'; if (!empty($instance['sort_parameter'])) { $orderby = $instance['sort_parameter']; } $order_direction = 'DESC'; if (!empty($instance['sort_direction'])) { $order_direction = $instance['sort_direction']; } $exclude_ids = array(); if (!empty($instance['exclude_ids'])) { $exclude_ids = $instance['exclude_ids']; } // TODO: get template choice. Echo css based on choice echo '<style>.list_mediafiles_box{'; echo 'border: 1px solid #e2e2e2;'; echo 'margin: 5px;'; echo 'padding: 5px;'; echo '} .list_mediafiles_box img{'; echo 'max-width:100px;'; echo '} </style>'; $args = array('post_type' => 'attachment', 'numberposts' => $number_of_posts, 'post_status' => null, 'post_parent' => null, 'orderby' => $orderby, 'order' => $order_direction, 'exclude' => $exclude_ids); $attachments = get_posts($args); if ($attachments) { foreach ($attachments as $post) { echo '<div class="list_mediafiles_box">'; setup_postdata($post); echo '<h4>' . get_the_title($post->ID) . '</h4>'; switch ($post->post_mime_type) { case 'image/jpeg': case 'image/png': case 'image/gif': the_attachment_link($post->ID, false); break; default: echo '<a href="' . get_attachment_link($post->ID) . '"><img src="' . wp_mime_type_icon($post->post_mime_type) . '"></a>'; } echo '<span class="aligncenter" style="word-break:break-word;">'; the_excerpt(); echo '</span>'; echo '</div>'; } } //echo $args['after_widget']; }
/** * Returns HTML for Digital Download UI * * @param int $product_id * @return HTML */ function wpsc_select_product_file($product_id = null) { global $wpdb; $product_id = absint($product_id); $file_list = wpsc_uploaded_files(); $args = array('post_type' => 'wpsc-product-file', 'post_parent' => $product_id, 'numberposts' => -1, 'post_status' => 'all'); $attached_files = (array) get_posts($args); $output = '<table id="wpsc_digital_download_table" class="wp-list-table widefat posts select_product_file">'; $output .= '<thead>'; $output .= '<tr>'; $output .= '<th>' . _x('Title', 'Digital download UI', 'wp-e-commerce') . '</th>'; $output .= '<th>' . _x('Size', 'Digital download UI', 'wp-e-commerce') . '</th>'; $output .= '<th>' . _x('File Type', 'Digital download UI', 'wp-e-commerce') . '</th>'; $output .= '<th id="wpsc_digital_download_action_th">' . _x('Actions', 'Digital download UI', 'wp-e-commerce') . '</th>'; $output .= '</tr>'; $output .= '</thead>'; $output .= '<tfoot>'; $output .= '<tr>'; $output .= '<th>' . _x('Title', 'Digital download UI', 'wp-e-commerce') . '</th>'; $output .= '<th>' . _x('Size', 'Digital download UI', 'wp-e-commerce') . '</th>'; $output .= '<th>' . _x('File Type', 'Digital download UI', 'wp-e-commerce') . '</th>'; $output .= '<th id="wpsc_digital_download_action_th">' . _x('Actions', 'Digital download UI', 'wp-e-commerce') . '</th>'; $output .= '</tr>'; $output .= '</tfoot>'; $num = 0; $output .= '<tbody>'; $delete_nonce = _wpsc_create_ajax_nonce('delete_file'); foreach ((array) $attached_files as $file) { $file_dir = WPSC_FILE_DIR . $file->post_title; $file_size = 'http://s3file' == $file->guid ? __('Remote file sizes cannot be calculated', 'wp-e-commerce') : wpsc_convert_byte(filesize($file_dir)); $file_url = add_query_arg(array('wpsc_download_id' => $file->ID, '_wpnonce' => wp_create_nonce('wpsc-admin-download-file-' . $file->ID)), admin_url()); $deletion_url = wp_nonce_url("admin.php?wpsc_admin_action=delete_file&file_name={$file->post_title}&product_id={$product_id}&row_number={$num}", 'delete_file_' . $file->post_title); $class = !wpsc_is_odd($num) ? 'alternate' : ''; $file_type = get_post_mime_type($file->ID); $icon_url = wp_mime_type_icon($file_type); $output .= '<tr class="wpsc_product_download_row ' . $class . '">'; $output .= '<td style="padding-right: 30px;"><img src="' . $icon_url . '"><span>' . $file->post_title . '</span></td>'; $output .= '<td>' . $file_size . '</td>'; $output .= '<td>' . $file_type . '</td>'; $output .= '<td><a href="' . esc_url($file_url) . '">' . _x('Download', 'Digital download row UI', 'wp-e-commerce') . '</a><a data-file-name="' . esc_attr($file->post_title) . '" data-product-id="' . esc_attr($product_id) . '" data-nonce="' . esc_attr($delete_nonce) . '" class="file_delete_button" href="' . $deletion_url . '" >' . _x("Delete", "Digital download row UI", 'wp-e-commerce') . '</a></td>'; $output .= '</tr>'; $num++; } $output .= '</tbody>'; $output .= '</table>'; if (empty($attached_files)) { $output .= "<p class='no-item'>" . __('There are no files attached to this product. Upload a new file or select from other product files.', 'wp-e-commerce') . "</p>"; } $output .= "<div class='" . (is_numeric($product_id) ? 'edit_' : '') . "select_product_handle'></div>"; $output .= "<script type='text/javascript'>\r\n"; $output .= "var select_min_height = " . 25 * 3 . ";\r\n"; $output .= "var select_max_height = " . 25 * ($num + 1) . ";\r\n"; $output .= "</script>"; return $output; }
/** * Get thumbnail URL for document with given ID from default images. * * @param string $ID The attachment ID to retrieve thumbnail from. * @param int $pg Unused. * * @return string URL to thumbnail. */ public function getThumbnail($ID, $pg = 1) { static $image_exts = array('jpg', 'jpeg', 'gif', 'png'); $icon_url = DG_URL . 'assets/icons/'; $ext = self::getExt(wp_get_attachment_url($ID)); // handle images if (in_array($ext, $image_exts) && ($icon = self::getImageThumbnail($ID))) { // Nothing to do } elseif ($name = self::getDefaultIcon($ext)) { // try DG custom default icons first $icon = $icon_url . $name; // then fall back to standard WP default icons } elseif (!($icon = wp_mime_type_icon($ID))) { // everything failed. This is bad... $icon = $icon_url . 'missing.png'; } return $icon; }
public static function attach_html($attach_id, $custom_attr = []) { $attachment = get_post($attach_id); if (!$attachment) { return; } if (wp_attachment_is_image($attach_id)) { $image = wp_get_attachment_image_src($attach_id, array('80', '80')); $image = $image[0]; } else { $image = wp_mime_type_icon($attach_id); } $html = '<li class="erp-image-wrap thumbnail">'; $html .= sprintf('<div class="attachment-name"><img class="erp-file-mime" ' . implode(' data-', $custom_attr) . ' height="80" width="80" src="%s" alt="%s" /></div>', $image, esc_attr($attachment->post_title)); $html .= sprintf('<input type="hidden" name="files[]" value="%d">', $attach_id); $html .= sprintf('<div class="caption"><a href="#" class="erp-del-attc-button btn-danger btn-small attachment-delete" data-attach_id="%d">X</a></div>', $attach_id); $html .= '</li>'; return $html; }
public static function attach_html($attach_id, $type = NULL) { if (!$type) { $type = isset($_GET['type']) ? $_GET['type'] : 'image'; } $attachment = get_post($attach_id); if (!$attachment) { return; } if (wp_attachment_is_image($attach_id)) { $image = wp_get_attachment_image_src($attach_id, 'thumbnail'); $image = $image[0]; } else { $image = wp_mime_type_icon($attach_id); } $html = '<li class="image-wrap thumbnail" style="width: 150px">'; $html .= sprintf('<div class="attachment-name"><img src="%s" alt="%s" /></div>', $image, esc_attr($attachment->post_title)); $html .= sprintf('<div class="caption"><a href="#" class="btn btn-danger btn-small attachment-delete" data-attach_id="%d">%s</a></div>', $attach_id, __('Delete', 'wpuf')); $html .= sprintf('<input type="hidden" name="wpuf_files[%s][]" value="%d">', $type, $attach_id); $html .= '</li>'; return $html; }
/** * Refresh the parameters passed to the JavaScript via JSON. * * * highly based on WP_Customize_Media_Control merged with WP_Customize_Upload_Control ::to_json() */ public function to_json() { $this->json['mime_type'] = $this->mime_type; $this->json['button_labels'] = $this->button_labels; $this->json['bg_repeat_options'] = $this->bg_repeat_options; $this->json['bg_attachment_options'] = $this->bg_attachment_options; $this->json['bg_position_options'] = $this->bg_position_options; $this->json['canUpload'] = current_user_can('upload_files'); $this->json['default_model'] = $this->default_model; $value = $this->value(); if (isset($this->setting) && is_object($this->setting)) { $_defaults = isset($this->setting->default) ? $this->setting->default : null; $default_bg_img = isset($_defaults['background-image']) ? $_defaults['background-image'] : null; } $default_bg_im = isset($default_bg_img) ? $default_bg_img : null; if ($default_bg_img) { // Fake an attachment model - needs all fields used by template. // Note that the default value must be a URL, NOT an attachment ID. $type = in_array(substr($default_bg_img, -3), array('jpg', 'png', 'gif', 'bmp', 'svg')) ? 'image' : 'document'; $default_attachment = array('id' => 1, 'url' => $default_bg_img, 'type' => $type, 'icon' => wp_mime_type_icon($type), 'title' => basename($default_bg_img)); $default_attachment['sizes'] = array('full' => array('url' => $default_bg_img)); $this->json['defaultAttachment'] = $default_attachment; } $background_image = isset($value['background-image']) ? $value['background-image'] : null; if ($background_image && $default_bg_img && $background_image === $default_bg_img) { // Set the default as the attachment. $this->json['attachment'] = $this->json['defaultAttachment']; } elseif ($background_image) { $attachment_id = attachment_url_to_postid($background_image); if ($attachment_id) { $this->json['attachment'] = wp_prepare_attachment_for_js($attachment_id); } else { //already an id $this->json['attachment'] = wp_prepare_attachment_for_js($background_image); } } parent::to_json(); }
function xt_manage_post_custom_column($column, $post_id) { switch ($column) { case 'icon': $att_title = _draft_or_post_title(); ?> <a href="<?php echo esc_url(get_edit_post_link($post_id, true)); ?> " title="<?php echo esc_attr(sprintf(__('Edit “%s”', XT_TEXT_DOMAIN), $att_title)); ?> "><?php if ($thumb = get_the_post_thumbnail($post_id, array(80, 60))) { echo $thumb; } else { echo '<img width="46" height="60" src="' . wp_mime_type_icon('image/jpeg') . '" alt="">'; } ?> </a> <?php break; } }
function render_field($field) { // enqueue acf_enqueue_uploader(); // vars $posts = array(); $atts = array('id' => $field['id'], 'class' => "acf-gallery {$field['class']}", 'data-preview_size' => $field['preview_size'], 'data-library' => $field['library'], 'data-min' => $field['min'], 'data-max' => $field['max'], 'data-mime_types' => $field['mime_types']); // set gallery height $height = acf_get_user_setting('gallery_height', 400); $height = max($height, 200); // minimum height is 200 $atts['style'] = "height:{$height}px"; // load posts if (!empty($field['value'])) { $posts = acf_get_posts(array('post_type' => 'attachment', 'post__in' => $field['value'])); } ?> <div <?php acf_esc_attr_e($atts); ?> > <div class="acf-hidden"> <input type="hidden" <?php acf_esc_attr_e(array('name' => $field['name'], 'value' => '', 'data-name' => 'ids')); ?> /> </div> <div class="acf-gallery-main"> <div class="acf-gallery-attachments"> <?php if (!empty($posts)) { ?> <?php foreach ($posts as $post) { // vars $type = acf_maybe_get(explode('/', $post->post_mime_type), 0); $thumb_id = $post->ID; $thumb_url = ''; $thumb_class = 'acf-gallery-attachment acf-soh'; $filename = wp_basename($post->guid); // thumb if ($type === 'image' || $type === 'audio' || $type === 'video') { // change $thumb_id if ($type === 'audio' || $type === 'video') { $thumb_id = get_post_thumbnail_id($post->ID); } // get attachment if ($thumb_id) { $thumb_url = wp_get_attachment_image_src($thumb_id, $field['preview_size']); $thumb_url = acf_maybe_get($thumb_url, 0); } } // fallback if (!$thumb_url) { $thumb_url = wp_mime_type_icon($post->ID); $thumb_class .= ' is-mime-icon'; } ?> <div class="<?php echo $thumb_class; ?> " data-id="<?php echo $post->ID; ?> "> <input type="hidden" name="<?php echo $field['name']; ?> []" value="<?php echo $post->ID; ?> " /> <div class="margin" title="<?php echo $filename; ?> "> <div class="thumbnail"> <img src="<?php echo $thumb_url; ?> "/> </div> <?php if ($type !== 'image') { ?> <div class="filename"><?php echo acf_get_truncated($filename, 18); ?> </div> <?php } ?> </div> <div class="actions acf-soh-target"> <a class="acf-icon dark remove-attachment" data-id="<?php echo $post->ID; ?> " href="#"> <i class="acf-sprite-delete"></i> </a> </div> </div> <?php } ?> <?php } ?> </div> <div class="acf-gallery-toolbar"> <ul class="acf-hl"> <li> <a href="#" class="acf-button blue add-attachment"><?php _e('Add to gallery', 'acf'); ?> </a> </li> <li class="acf-fr"> <select class="bulk-actions"> <option value=""><?php _e('Bulk actions', 'acf'); ?> </option> <option value="date"><?php _e('Sort by date uploaded', 'acf'); ?> </option> <option value="modified"><?php _e('Sort by date modified', 'acf'); ?> </option> <option value="title"><?php _e('Sort by title', 'acf'); ?> </option> <option value="reverse"><?php _e('Reverse current order', 'acf'); ?> </option> </select> </li> </ul> </div> </div> <div class="acf-gallery-side"> <div class="acf-gallery-side-inner"> <div class="acf-gallery-side-data"></div> <div class="acf-gallery-toolbar"> <ul class="acf-hl"> <li> <a href="#" class="acf-button close-sidebar"><?php _e('Close', 'acf'); ?> </a> </li> <li class="acf-fr"> <a class="acf-button blue update-attachment"><?php _e('Update', 'acf'); ?> </a> </li> </ul> </div> </div> </div> </div> <?php }
/** * Prepares an attachment post object for JS, where it is expected * to be JSON-encoded and fit into an Attachment model. * * @since 3.5.0 * * @param mixed $attachment Attachment ID or object. * @return array|void Array of attachment details. */ function wp_prepare_attachment_for_js($attachment) { if (!($attachment = get_post($attachment))) { return; } if ('attachment' != $attachment->post_type) { return; } $meta = wp_get_attachment_metadata($attachment->ID); if (false !== strpos($attachment->post_mime_type, '/')) { list($type, $subtype) = explode('/', $attachment->post_mime_type); } else { list($type, $subtype) = array($attachment->post_mime_type, ''); } $attachment_url = wp_get_attachment_url($attachment->ID); $response = array('id' => $attachment->ID, 'title' => $attachment->post_title, 'filename' => wp_basename(get_attached_file($attachment->ID)), 'url' => $attachment_url, 'link' => get_attachment_link($attachment->ID), 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true), 'author' => $attachment->post_author, 'description' => $attachment->post_content, 'caption' => $attachment->post_excerpt, 'name' => $attachment->post_name, 'status' => $attachment->post_status, 'uploadedTo' => $attachment->post_parent, 'date' => strtotime($attachment->post_date_gmt) * 1000, 'modified' => strtotime($attachment->post_modified_gmt) * 1000, 'menuOrder' => $attachment->menu_order, 'mime' => $attachment->post_mime_type, 'type' => $type, 'subtype' => $subtype, 'icon' => wp_mime_type_icon($attachment->ID), 'dateFormatted' => mysql2date(get_option('date_format'), $attachment->post_date), 'nonces' => array('update' => false, 'delete' => false, 'edit' => false), 'editLink' => false, 'meta' => false); $author = new WP_User($attachment->post_author); $response['authorName'] = $author->display_name; if ($attachment->post_parent) { $post_parent = get_post($attachment->post_parent); } else { $post_parent = false; } if ($post_parent) { $parent_type = get_post_type_object($post_parent->post_type); if ($parent_type && $parent_type->show_ui && current_user_can('edit_post', $attachment->post_parent)) { $response['uploadedToLink'] = get_edit_post_link($attachment->post_parent, 'raw'); } $response['uploadedToTitle'] = $post_parent->post_title ? $post_parent->post_title : __('(no title)'); } $attached_file = get_attached_file($attachment->ID); if (isset($meta['filesize'])) { $bytes = $meta['filesize']; } elseif (file_exists($attached_file)) { $bytes = filesize($attached_file); } else { $bytes = ''; } if ($bytes) { $response['filesizeInBytes'] = $bytes; $response['filesizeHumanReadable'] = size_format($bytes); } if (current_user_can('edit_post', $attachment->ID)) { $response['nonces']['update'] = wp_create_nonce('update-post_' . $attachment->ID); $response['nonces']['edit'] = wp_create_nonce('image_editor-' . $attachment->ID); $response['editLink'] = get_edit_post_link($attachment->ID, 'raw'); } if (current_user_can('delete_post', $attachment->ID)) { $response['nonces']['delete'] = wp_create_nonce('delete-post_' . $attachment->ID); } if ($meta && 'image' === $type) { $sizes = array(); /** This filter is documented in wp-admin/includes/media.php */ $possible_sizes = apply_filters('image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size'))); unset($possible_sizes['full']); // Loop through all potential sizes that may be chosen. Try to do this with some efficiency. // First: run the image_downsize filter. If it returns something, we can use its data. // If the filter does not return something, then image_downsize() is just an expensive // way to check the image metadata, which we do second. foreach ($possible_sizes as $size => $label) { /** This filter is documented in wp-includes/media.php */ if ($downsize = apply_filters('image_downsize', false, $attachment->ID, $size)) { if (!$downsize[3]) { continue; } $sizes[$size] = array('height' => $downsize[2], 'width' => $downsize[1], 'url' => $downsize[0], 'orientation' => $downsize[2] > $downsize[1] ? 'portrait' : 'landscape'); } elseif (isset($meta['sizes'][$size])) { if (!isset($base_url)) { $base_url = str_replace(wp_basename($attachment_url), '', $attachment_url); } // Nothing from the filter, so consult image metadata if we have it. $size_meta = $meta['sizes'][$size]; // We have the actual image size, but might need to further constrain it if content_width is narrower. // Thumbnail, medium, and full sizes are also checked against the site's height/width options. list($width, $height) = image_constrain_size_for_editor($size_meta['width'], $size_meta['height'], $size, 'edit'); $sizes[$size] = array('height' => $height, 'width' => $width, 'url' => $base_url . $size_meta['file'], 'orientation' => $height > $width ? 'portrait' : 'landscape'); } } $sizes['full'] = array('url' => $attachment_url); if (isset($meta['height'], $meta['width'])) { $sizes['full']['height'] = $meta['height']; $sizes['full']['width'] = $meta['width']; $sizes['full']['orientation'] = $meta['height'] > $meta['width'] ? 'portrait' : 'landscape'; } $response = array_merge($response, array('sizes' => $sizes), $sizes['full']); } elseif ($meta && 'video' === $type) { if (isset($meta['width'])) { $response['width'] = (int) $meta['width']; } if (isset($meta['height'])) { $response['height'] = (int) $meta['height']; } } if ($meta && ('audio' === $type || 'video' === $type)) { if (isset($meta['length_formatted'])) { $response['fileLength'] = $meta['length_formatted']; } $response['meta'] = array(); foreach (wp_get_attachment_id3_keys($attachment, 'js') as $key => $label) { $response['meta'][$key] = false; if (!empty($meta[$key])) { $response['meta'][$key] = $meta[$key]; } } $id = get_post_thumbnail_id($attachment->ID); if (!empty($id)) { list($src, $width, $height) = wp_get_attachment_image_src($id, 'full'); $response['image'] = compact('src', 'width', 'height'); list($src, $width, $height) = wp_get_attachment_image_src($id, 'thumbnail'); $response['thumb'] = compact('src', 'width', 'height'); } else { $src = wp_mime_type_icon($attachment->ID); $width = 48; $height = 64; $response['image'] = compact('src', 'width', 'height'); $response['thumb'] = compact('src', 'width', 'height'); } } if (function_exists('get_compat_media_markup')) { $response['compat'] = get_compat_media_markup($attachment->ID, array('in_modal' => true)); } /** * Filter the attachment data prepared for JavaScript. * * @since 3.5.0 * * @param array $response Array of prepared attachment data. * @param int|object $attachment Attachment ID or object. * @param array $meta Array of attachment meta data. */ return apply_filters('wp_prepare_attachment_for_js', $response, $attachment, $meta); }
/** * @ticket 33012 */ public function test_wp_mime_type_icon_video() { $icon = wp_mime_type_icon('video/mp4'); $this->assertContains('images/media/video.png', $icon); }
function wp_playlist_shortcode($output, $attr) { global $content_width; $post = get_post(); static $instance = 0; $instance++; if (isset($attr['orderby'])) { $attr['orderby'] = sanitize_sql_orderby($attr['orderby']); if (!$attr['orderby']) { unset($attr['orderby']); } } extract(shortcode_atts(array('type' => 'audio', 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post ? $post->ID : 0, 'include' => '', 'exclude' => '', 'style' => 'light', 'tracklist' => true, 'tracknumbers' => true, 'images' => true, 'artists' => true), $attr, 'playlist')); $id = intval($id); if ('RAND' == $order) { $orderby = 'none'; } $args = array('post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => $type, 'order' => $order, 'orderby' => $orderby); if (!empty($include)) { $args['include'] = $include; $_attachments = get_posts($args); $attachments = array(); foreach ($_attachments as $key => $val) { $attachments[$val->ID] = $_attachments[$key]; } } elseif (!empty($exclude)) { $args['post_parent'] = $id; $args['exclude'] = $exclude; $attachments = get_children($args); } else { $args['post_parent'] = $id; $attachments = get_children($args); } if (empty($attachments)) { return ''; } if (is_feed()) { $output = "\n"; foreach ($attachments as $att_id => $attachment) { $output .= wp_get_attachment_link($att_id) . "\n"; } return $output; } $outer = 22; $default_width = 640; $default_height = 360; $theme_width = empty($content_width) ? $default_width : $content_width - $outer; $theme_height = empty($content_width) ? $default_height : round($default_height * $theme_width / $default_width); $data = compact('type'); foreach (array('tracklist', 'tracknumbers', 'images', 'artists') as $key) { $data[$key] = filter_var(${$key}, FILTER_VALIDATE_BOOLEAN); } $tracks = array(); foreach ($attachments as $attachment) { $url = wp_get_attachment_url($attachment->ID); $ftype = wp_check_filetype($url, wp_get_mime_types()); $track = array('src' => $url, 'type' => $ftype['type'], 'title' => $attachment->post_title, 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content); $track['meta'] = array(); $meta = wp_get_attachment_metadata($attachment->ID); if (!empty($meta)) { foreach (wp_get_attachment_id3_keys($attachment) as $key => $label) { if (!empty($meta[$key])) { $track['meta'][$key] = $meta[$key]; } } if ('video' === $type) { if (!empty($meta['width']) && !empty($meta['height'])) { $width = $meta['width']; $height = $meta['height']; $theme_height = round($height * $theme_width / $width); } else { $width = $default_width; $height = $default_height; } $track['dimensions'] = array('original' => compact('width', 'height'), 'resized' => array('width' => $theme_width, 'height' => $theme_height)); } } if ($images) { $id = get_post_thumbnail_id($attachment->ID); if (!empty($id)) { list($src, $width, $height) = wp_get_attachment_image_src($id, 'full'); $track['image'] = compact('src', 'width', 'height'); list($src, $width, $height) = wp_get_attachment_image_src($id, 'thumbnail'); $track['thumb'] = compact('src', 'width', 'height'); } else { $src = wp_mime_type_icon($attachment->ID); $width = 48; $height = 64; $track['image'] = compact('src', 'width', 'height'); $track['thumb'] = compact('src', 'width', 'height'); } } $tracks[] = $track; } $data['tracks'] = $tracks; $safe_type = esc_attr($type); $safe_style = esc_attr($style); $playlist_meta = 'true' == $this->options('playlist_meta') ? "" : " hide-playlist-meta-pro "; ob_start(); if (1 === $instance) { do_action('wp_playlist_scripts', $type, $style); } ?> <div class="wp-playlist wp-<?php echo $safe_type; ?> -playlist wp-playlist-<?php echo $safe_style; ?> <?php echo $playlist_meta; ?> "> <?php if ('audio' === $type) { ?> <div class="wp-playlist-current-item"></div> <?php } ?> <<?php echo $safe_type; ?> controls="controls" preload="none" width="<?php echo (int) $theme_width; ?> "<?php if ('video' === $safe_type) { echo ' height="', (int) $theme_height, '"'; } else { echo ' style="visibility: hidden"'; } ?> ></<?php echo $safe_type; ?> > <div class="wp-playlist-next"></div> <div class="wp-playlist-prev"></div> <noscript> <ol><?php foreach ($attachments as $att_id => $attachment) { printf('<li>%s</li>', wp_get_attachment_link($att_id)); } ?> </ol> </noscript> <script type="application/json"><?php echo json_encode($data); ?> </script> </div> <?php return apply_filters('wp_playlist_shortcode', ob_get_clean()); }
function ajax_get_files() { // vars $options = array('nonce' => '', 'files' => array()); $return = array(); // load post options $options = array_merge($options, $_POST); // verify nonce if (!wp_verify_nonce($options['nonce'], 'acf_nonce')) { die(0); } if ($options['files']) { foreach ($options['files'] as $id) { $o = array(); $file = get_post($id); $o['id'] = $file->ID; $o['icon'] = wp_mime_type_icon($file->ID); $o['title'] = $file->post_title; $o['size'] = size_format(filesize(get_attached_file($file->ID))); $o['url'] = wp_get_attachment_url($file->ID); $o['name'] = end(explode('/', $o['url'])); $return[] = $o; } } // return json echo json_encode($return); die; }
/** * grandWPMedia() * * @return mixed content */ function grandWPMedia() { global $user_ID, $gmDB, $gmCore, $gmProcessor, $gmGallery; $url = add_query_arg(array('page' => $gmProcessor->page), admin_url('admin.php')); $gm_screen_options = get_user_meta($user_ID, 'gm_screen_options', true); if (!is_array($gm_screen_options)) { $gm_screen_options = array(); } $gm_screen_options = array_merge($gmGallery->options['gm_screen_options'], $gm_screen_options); $arg = array('mime_type' => $gmCore->_get('mime_type', ''), 'orderby' => $gmCore->_get('orderby', $gm_screen_options['orderby_wpmedia']), 'order' => $gmCore->_get('order', $gm_screen_options['sortorder_wpmedia']), 'limit' => $gm_screen_options['per_page_wpmedia'], 'filter' => $gmCore->_get('filter', ''), 's' => $gmCore->_get('s', '')); $wpMediaLib = $gmDB->get_wp_media_lib($arg); $gmedia_pager = $gmDB->query_pager(); $gm_qty = array('total' => '', 'image' => '', 'audio' => '', 'video' => '', 'text' => '', 'application' => '', 'other' => ''); $gmDbCount = $gmDB->count_wp_media($arg); foreach ($gmDbCount as $key => $value) { $gm_qty[$key] = '<span class="badge pull-right">' . (int) $value . '</span>'; } ?> <div class="panel panel-default panel-fixed-header"> <div class="panel-heading-fake"></div> <div class="panel-heading clearfix" style="padding-bottom:2px;"> <div class="pull-right" style="margin-bottom:3px;"> <div class="clearfix"> <?php include GMEDIA_ABSPATH . 'admin/tpl/search-form.php'; ?> <div class="btn-toolbar pull-right" style="margin-bottom:4px; margin-left:4px;"> <?php if (!$gmProcessor->gmediablank) { ?> <a title="<?php _e('More Screen Settings', 'grand-media'); ?> " class="show-settings-link pull-right btn btn-default btn-xs"><span class="glyphicon glyphicon-cog"></span></a> <?php } ?> </div> </div> <?php echo $gmedia_pager; ?> <div class="spinner"></div> </div> <div class="btn-toolbar pull-left"> <div class="btn-group gm-checkgroup" id="cb_global-btn"> <span class="btn btn-default active"><input class="doaction" id="cb_global" data-group="cb_object" type="checkbox"/></span> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span> <span class="sr-only"><?php _e('Toggle Dropdown', 'grand-media'); ?> </span></button> <ul class="dropdown-menu" role="menu"> <li><a data-select="total" href="#"><?php _e('All', 'grand-media'); ?> </a></li> <li><a data-select="none" href="#"><?php _e('None', 'grand-media'); ?> </a></li> <li class="divider"></li> <li><a data-select="image" href="#"><?php _e('Images', 'grand-media'); ?> </a></li> <li><a data-select="audio" href="#"><?php _e('Audio', 'grand-media'); ?> </a></li> <li><a data-select="video" href="#"><?php _e('Video', 'grand-media'); ?> </a></li> <li class="divider"></li> <li> <a data-select="reverse" href="#" title="<?php _e('Reverse only visible items', 'grand-media'); ?> "><?php _e('Reverse', 'grand-media'); ?> </a> </li> </ul> </div> <div class="btn-group"> <?php $curr_mime = explode(',', $gmCore->_get('mime_type', 'total')); ?> <?php if (!empty($gmDB->filter)) { ?> <a class="btn btn-warning" title="<?php _e('Reset Filter', 'grand-media'); ?> " rel="total" href="<?php echo $url; ?> "><?php _e('Filter', 'grand-media'); ?> </a> <?php } else { ?> <button type="button" class="btn btn-default"><?php _e('Filter', 'grand-media'); ?> </button> <?php } ?> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span> <span class="sr-only"><?php _e('Toggle Dropdown', 'grand-media'); ?> </span> </button> <ul class="dropdown-menu" role="menu"> <li role="presentation" class="dropdown-header"><?php _e('TYPE', 'grand-media'); ?> </li> <li class="total<?php echo in_array('total', $curr_mime) ? ' active' : ''; ?> "><a rel="total" href="<?php echo $gmCore->get_admin_url(array(), array('mime_type', 'pager')); ?> "><?php echo $gm_qty['total'] . __('All', 'grand-media'); ?> </a></li> <li class="image<?php echo (in_array('image', $curr_mime) ? ' active' : '') . ($gmDbCount['image'] ? '' : ' disabled'); ?> "> <a rel="image" href="<?php echo $gmCore->get_admin_url(array('mime_type' => 'image'), array('pager')); ?> "><?php echo $gm_qty['image'] . __('Images', 'grand-media'); ?> </a></li> <li class="audio<?php echo (in_array('audio', $curr_mime) ? ' active' : '') . ($gmDbCount['audio'] ? '' : ' disabled'); ?> "> <a rel="audio" href="<?php echo $gmCore->get_admin_url(array('mime_type' => 'audio'), array('pager')); ?> "><?php echo $gm_qty['audio'] . __('Audio', 'grand-media'); ?> </a></li> <li class="video<?php echo (in_array('video', $curr_mime) ? ' active' : '') . ($gmDbCount['video'] ? '' : ' disabled'); ?> "> <a rel="video" href="<?php echo $gmCore->get_admin_url(array('mime_type' => 'video'), array('pager')); ?> "><?php echo $gm_qty['video'] . __('Video', 'grand-media'); ?> </a></li> <li class="application<?php echo (in_array('application', $curr_mime) || in_array('text', $curr_mime) ? ' active' : '') . ($gmDbCount['other'] ? '' : ' disabled'); ?> "> <a rel="application" href="<?php echo $gmCore->get_admin_url(array('mime_type' => 'application,text'), array('pager')); ?> "><?php echo $gm_qty['other'] . __('Other', 'grand-media'); ?> </a></li> <?php do_action('gmedia_wp_filter_list'); ?> </ul> </div> <div class="btn-group"> <a class="btn btn-default" href="#"><?php _e('Action', 'grand-media'); ?> </a> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span> <span class="sr-only"><?php _e('Toggle Dropdown', 'grand-media'); ?> </span></button> <?php $rel_selected_show = 'rel-selected-show'; $rel_selected_hide = 'rel-selected-hide'; ?> <ul class="dropdown-menu" role="menu"> <li class="<?php echo $rel_selected_show; if (!$gmCore->caps['gmedia_import']) { echo ' disabled'; } ?> "> <a href="#importModal" data-modal="import-wpmedia" data-action="gmedia_import_wpmedia_modal" class="gmedia-modal"><?php _e('Import to Gmedia Library...', 'grand-media'); ?> </a> </li> <!-- <li class="divider <?php echo $rel_selected_hide; ?> "></li> --> <li class="dropdown-header <?php echo $rel_selected_hide; ?> "><span><?php _e("Select items to see more actions", "grand-media"); ?> </span></li> <?php do_action('gmedia_action_list'); ?> </ul> </div> <form class="btn-group" id="gm-selected-btn" name="gm-selected-form" action="<?php echo add_query_arg(array('filter' => 'selected'), $url); ?> " method="post"> <button type="submit" class="btn btn<?php echo 'selected' == $gmCore->_req('filter') ? '-success' : '-info'; ?> "><?php printf(__('%s selected', 'grand-media'), '<span id="gm-selected-qty">' . count($gmProcessor->selected_items) . '</span>'); ?> </button> <button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span> <span class="sr-only"><?php _e('Toggle Dropdown', 'grand-media'); ?> </span></button> <input type="hidden" id="gm-selected" data-userid="<?php echo $user_ID; ?> " data-key="gmedia_library:wpmedia" name="selected_items" value="<?php echo implode(',', $gmProcessor->selected_items); ?> "/> <ul class="dropdown-menu" role="menu"> <li><a id="gm-selected-show" href="#show"><?php _e('Show only selected items', 'grand-media'); ?> </a></li> <li><a id="gm-selected-clear" href="#clear"><?php _e('Clear selected items', 'grand-media'); ?> </a></li> </ul> </form> </div> </div> <div class="panel-body"></div> <?php if (!empty($wpMediaLib)) { ?> <table class="table table-striped table-hover table-condenced" cellspacing="0"> <col class="cb" style="width:40px;"/> <col class="id" style="width:80px;"/> <col class="file" style="width:100px;"/> <col class="type" style="width:80px;"/> <col class="title"/> <col class="descr hidden-xs"/> <thead> <tr> <th class="cb"><span>#</span></th> <th class="id" title="<?php _e('Sort by ID', 'grand-media'); ?> "> <?php $new_order = 'ID' == $arg['orderby'] ? 'DESC' == $arg['order'] ? 'ASC' : 'DESC' : 'DESC'; ?> <a href="<?php echo $gmCore->get_admin_url(array('orderby' => 'ID', 'order' => $new_order)); ?> "><?php _e('ID', 'grand-media'); ?> </a> </th> <th class="file" title="<?php _e('Sort by filename', 'grand-media'); ?> "> <?php $new_order = 'filename' == $arg['orderby'] ? 'DESC' == $arg['order'] ? 'ASC' : 'DESC' : 'DESC'; ?> <a href="<?php echo $gmCore->get_admin_url(array('orderby' => 'filename', 'order' => $new_order)); ?> "><?php _e('File', 'grand-media'); ?> </a> </th> <th class="type"><span><?php _e('Type', 'grand-media'); ?> </span></th> <th class="title" title="<?php _e('Sort by Title', 'grand-media'); ?> "> <?php $new_order = 'title' == $arg['orderby'] ? 'DESC' == $arg['order'] ? 'ASC' : 'DESC' : 'DESC'; ?> <a href="<?php echo $gmCore->get_admin_url(array('orderby' => 'title', 'order' => $new_order)); ?> "><?php _e('Title', 'grand-media'); ?> </a> </th> <th class="descr hidden-xs"><span><?php _e('Description', 'grand-media'); ?> </span></th> </tr> </thead> <tbody> <?php foreach ($wpMediaLib as $item) { $is_selected = in_array($item->ID, $gmProcessor->selected_items) ? true : false; $image = wp_get_attachment_image($item->ID, array(50, 50), false); if (!$image) { if ($src = wp_mime_type_icon($item->ID)) { $src_image = $gmCore->gmedia_url . '/admin/assets/img/' . wp_basename($src); $image = '<img src="' . $src_image . '" width="50" height="50" alt="icon" title="' . esc_attr($item->post_title) . '"/>'; } } $item_url = wp_get_attachment_url($item->ID); $file_info = pathinfo($item_url); $type = explode('/', $item->post_mime_type); ?> <tr data-id="<?php echo $item->ID; ?> "> <td class="cb"> <span class="cb_object"><input name="doaction[]" type="checkbox" data-type="<?php echo $type[0]; ?> " value="<?php echo $item->ID; ?> "<?php echo $is_selected ? ' checked="checked"' : ''; ?> /></span> </td> <td class="id"><span><?php echo $item->ID; ?> </span></td> <td class="file"> <span><a href="<?php echo admin_url('media.php?action=edit&attachment_id=' . $item->ID); ?> "><?php echo $image; ?> </a></span> </td> <td class="type"><span><?php echo $file_info['extension']; ?> </span></td> <td class="title"><span><?php echo esc_html($item->post_title); ?> </span></td> <td class="descr hidden-xs"> <div><?php echo esc_html($item->post_content); ?> </div> </td> </tr> <?php } ?> </tbody> </table> <?php } else { ?> <div class="panel-body"> <div class="well well-lg text-center"> <h4><?php _e('No items to show.', 'grand-media'); ?> </h4> </div> </div> <?php } ?> <?php wp_original_referer_field(true, 'previous'); wp_nonce_field('GmediaGallery'); ?> </div> <script type="text/javascript"> function gmedia_import_done() { if(jQuery('#import_window').is(':visible')) { var btn = jQuery('#import-done'); btn.text(btn.data('complete-text')).prop('disabled', false); } } </script> <div class="modal fade gmedia-modal" id="importModal" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog"></div> </div> <?php }
function wp_upload_display( $dims = false, $href = '' ) { global $post; $id = get_the_ID(); $attachment_data = wp_get_attachment_metadata( $id ); $is_image = (int) wp_attachment_is_image(); if ( !isset($attachment_data['width']) && $is_image ) { if ( $image_data = getimagesize( get_attached_file( $id ) ) ) { $attachment_data['width'] = $image_data[0]; $attachment_data['height'] = $image_data[1]; wp_update_attachment_metadata( $id, $attachment_data ); } } if ( isset($attachment_data['width']) ) list($width,$height) = wp_shrink_dimensions($attachment_data['width'], $attachment_data['height'], 171, 128); ob_start(); the_title(); $post_title = attribute_escape(ob_get_contents()); ob_end_clean(); $post_content = attribute_escape(apply_filters( 'content_edit_pre', $post->post_content )); $class = 'text'; $innerHTML = get_attachment_innerHTML( $id, false, $dims ); if ( $image_src = get_attachment_icon_src() ) { $image_rel = wp_make_link_relative($image_src); $innerHTML = ' ' . str_replace($image_src, $image_rel, $innerHTML); $class = 'image'; } $src_base = wp_get_attachment_url(); $src = wp_make_link_relative( $src_base ); $src_base = str_replace($src, '', $src_base); $r = ''; if ( $href ) $r .= "<a id='file-link-$id' href='$href' title='$post_title' class='file-link $class'>\n"; if ( $href || $image_src ) $r .= "\t\t\t$innerHTML"; if ( $href ) $r .= "</a>\n"; $r .= "\n\t\t<div class='upload-file-data'>\n\t\t\t<p>\n"; $r .= "\t\t\t\t<input type='hidden' name='attachment-url-$id' id='attachment-url-$id' value='$src' />\n"; $r .= "\t\t\t\t<input type='hidden' name='attachment-url-base-$id' id='attachment-url-base-$id' value='$src_base' />\n"; if ( !$thumb_base = wp_get_attachment_thumb_url() ) $thumb_base = wp_mime_type_icon(); if ( $thumb_base ) { $thumb_rel = wp_make_link_relative( $thumb_base ); $thumb_base = str_replace( $thumb_rel, '', $thumb_base ); $r .= "\t\t\t\t<input type='hidden' name='attachment-thumb-url-$id' id='attachment-thumb-url-$id' value='$thumb_rel' />\n"; $r .= "\t\t\t\t<input type='hidden' name='attachment-thumb-url-base-$id' id='attachment-thumb-url-base-$id' value='$thumb_base' />\n"; } $r .= "\t\t\t\t<input type='hidden' name='attachment-is-image-$id' id='attachment-is-image-$id' value='$is_image' />\n"; if ( isset($width) ) { $r .= "\t\t\t\t<input type='hidden' name='attachment-width-$id' id='attachment-width-$id' value='$width' />\n"; $r .= "\t\t\t\t<input type='hidden' name='attachment-height-$id' id='attachment-height-$id' value='$height' />\n"; } $r .= "\t\t\t\t<input type='hidden' name='attachment-page-url-$id' id='attachment-page-url-$id' value='" . get_attachment_link( $id ) . "' />\n"; $r .= "\t\t\t\t<input type='hidden' name='attachment-title-$id' id='attachment-title-$id' value='$post_title' />\n"; $r .= "\t\t\t\t<input type='hidden' name='attachment-description-$id' id='attachment-description-$id' value='$post_content' />\n"; $r .= "\t\t\t</p>\n\t\t</div>\n"; return $r; }
function wpv_layout_meta_html_admin($post, $view_layout_settings) { global $WP_Views; $view_settings = $WP_Views->get_view_settings($post->ID); $defaults = array('layout_meta_html' => '', 'generated_layout_meta_html' => ''); $view_layout_settings = wp_parse_args($view_layout_settings, $defaults); ?> <div id="wpv_layout_meta_html_admin"> <input type="hidden" name="_wpv_settings[layout_meta_html_state][html]" id="wpv_layout_meta_html_state" value="<?php echo isset($view_settings['layout_meta_html_state']['html']) ? $view_settings['layout_meta_html_state']['html'] : 'off'; ?> " /> <div id="wpv_layout_meta_html_admin_show"> <p><i><?php echo __('The layout-style and fields that you selected generate meta HTML. This meta HTML includes shortcodes and HTML, which you can edit, to fully customize the appearance of this View\'s content output section.', 'wpv-views'); ?> </i></p> <input type="button" class="button-secondary" onclick="wpv_view_layout_meta_html()" value="<?php _e('View/Edit Meta HTML', 'wpv-views'); ?> " /> </div> <div id="wpv_layout_meta_html_admin_edit" style="background:<?php echo WPV_EDIT_BACKGROUND; ?> ;display:none"> <div style="margin:10px 10px 10px 10px;"> <p><?php _e('<strong>Meta HTML</strong> - This is used to layout the posts found. It gets generated from the View Layout settings and can be modified to suit.', 'wpv-views'); ?> </p> <div id="wpv_layout_meta_html_content_error" class="wpv_form_errors" style="display:none;"> <p><?php _e("Changes can't be applied. It appears that you made manual modifications to the Meta HTML.", 'wpv-views'); ?> </p> <a style="cursor:pointer;margin-bottom:10px;" onclick="wpv_layout_meta_html_generate_new()"><strong><?php echo __('Generate the new layout content', 'wpv-views'); ?> </strong></a> <?php _e('(your edits will be displayed and you can apply them again)', 'wpv-views'); ?> </div> <?php $show = $view_settings['query_type'][0] == 'posts' ? 'style="display:inline"' : 'style="display:none"'; ?> <div id="wpv-layout-v-icon-posts" <?php echo $show; ?> > <?php echo $WP_Views->editor_addon->add_form_button('', 'wpv_layout_meta_html_content', true, true); ?> </div> <?php $show = $view_settings['query_type'][0] == 'taxonomy' ? 'style="display:inline"' : 'style="display:none"'; ?> <div id="wpv-layout-v-icon-taxonomy" <?php echo $show; ?> > <?php // add a "V" icon for taxonomy remove_filter('editor_addon_menus_wpv-views', 'wpv_post_taxonomies_editor_addon_menus_wpv_views_filter', 11); add_filter('editor_addon_menus_wpv-views', 'wpv_layout_taxonomy_V'); echo $WP_Views->editor_addon->add_form_button('', 'wpv_layout_meta_html_content'); remove_filter('editor_addon_menus_wpv-views', 'wpv_layout_taxonomy_V'); add_filter('editor_addon_menus_wpv-views', 'wpv_post_taxonomies_editor_addon_menus_wpv_views_filter', 11); ?> </div> <!--<div style="display:inline">--> <span style="position: relative; top:-5px;"> <?php echo apply_filters('wpv_meta_html_add_form_button', '', '#wpv_layout_meta_html_content'); ?> </span> <!--</div>--> <textarea name="_wpv_layout_settings[layout_meta_html]" id="wpv_layout_meta_html_content" cols="40" rows="16" style="width:100%;margin-top:10px"><?php echo $view_layout_settings['layout_meta_html']; ?> </textarea> <div id="wpv_layout_meta_html_content_old_div" style="display:none"> <div class="wpv_form_notice"><?php _e('<strong>Your edits are shown below:</strong>', 'wpv-views'); ?> <a style="cursor:pointer;margin-bottom:10px;" onclick="wpv_layout_meta_html_old_dismiss()"><strong><?php echo __('dismiss', 'wpv-views'); ?> </strong></a></div> <textarea id="wpv_layout_meta_html_content_old" cols="40" rows="16" style="width:100%;margin-top:10px"></textarea> </div> <textarea name="_wpv_layout_settings[generated_layout_meta_html]" id="wpv_generated_layout_meta_html_content" cols="40" rows="16" style="display:none"><?php echo $view_layout_settings['generated_layout_meta_html']; ?> </textarea> <div id="wpv_layout_meta_html_notice" class="wpv_form_notice" style="display:none;"><?php _e('* These updates will take effect when you save the view.', 'wpv-views'); ?> </div> <p><a style="cursor:pointer;margin-bottom:10px;" onclick="wpv_view_layout_meta_html_close()"><strong><?php _e('Close', 'wpv-views'); ?> </strong></a></p> </div> </div> <div id="wpv_layout_meta_html_extra_css" style="margin-top:15px;"> <input type="hidden" name="_wpv_settings[layout_meta_html_state][css]" id="wpv_layout_meta_html_extra_css_state" value="<?php echo isset($view_settings['layout_meta_html_state']['css']) ? $view_settings['layout_meta_html_state']['css'] : 'off'; ?> " /> <input type="button" class="button-secondary wpv_layout_meta_html_extra_css_edit" onclick="wpv_view_layout_meta_html_extra(this)" value="<?php _e('Edit CSS', 'wpv-views'); ?> " /> <div id ="wpv_layout_meta_html_extra_css_edit" style="background:<?php echo WPV_EDIT_BACKGROUND; ?> "> <p><?php _e('<strong>CSS</strong> - This is used to add custom CSS to a View layout.', 'wpv-views'); ?> </p> <textarea name="_wpv_settings[layout_meta_html_css]" id="wpv_layout_meta_html_css" cols="97" rows="10"><?php echo isset($view_settings['layout_meta_html_css']) ? $view_settings['layout_meta_html_css'] : ''; ?> </textarea> <div id="wpv_layout_meta_html_extra_css_notice" class="wpv_form_notice" style="display:none;"><?php _e('* These updates will take effect when you save the view.', 'wpv-views'); ?> </div> <p><a style="cursor:pointer;margin-bottom:10px;" id="wpv_layout_meta_html_extra_css_close" onclick="wpv_view_layout_meta_html_extra_css_close()"><strong><?php _e('Close CSS editor', 'wpv-views'); ?> </strong></a></p> </div> </div> <div id="wpv_layout_meta_html_extra_js" style="margin-top:15px;"> <input type="hidden" name="_wpv_settings[layout_meta_html_state][js]" id="wpv_layout_meta_html_extra_js_state" value="<?php echo isset($view_settings['layout_meta_html_state']['js']) ? $view_settings['layout_meta_html_state']['js'] : 'off'; ?> " /> <input type="button" class="button-secondary wpv_layout_meta_html_extra_js_edit" onclick="wpv_view_layout_meta_html_extra(this)" value="<?php _e('Edit JS', 'wpv-views'); ?> " /> <div id="wpv_layout_meta_html_extra_js_edit" style="background:<?php echo WPV_EDIT_BACKGROUND; ?> "> <p><?php _e('<strong>JS</strong> - This is used to add custom javascript to a View layout.', 'wpv-views'); ?> </p> <textarea name="_wpv_settings[layout_meta_html_js]" id="wpv_layout_meta_html_js" cols="97" rows="10"><?php echo isset($view_settings['layout_meta_html_js']) ? $view_settings['layout_meta_html_js'] : ''; ?> </textarea> <div id="wpv_layout_meta_html_extra_js_notice" class="wpv_form_notice" style="display:none;"><?php _e('* These updates will take effect when you save the view.', 'wpv-views'); ?> </div> <p><a style="cursor:pointer;margin-bottom:10px;" id="wpv_layout_meta_html_extra_js_close" onclick="wpv_view_layout_meta_html_extra_js_close()"><strong><?php _e('Close JS editor', 'wpv-views'); ?> </strong></a></p> </div> </div> <div id="wpv_layout_meta_html_extra_img" style="margin-top:15px;"> <?php global $post; ?> <input type="hidden" name="_wpv_settings[layout_meta_html_state][img]" id="wpv_layout_meta_html_extra_img_state" value="<?php echo isset($view_settings['layout_meta_html_state']['img']) ? $view_settings['layout_meta_html_state']['img'] : 'off'; ?> " /> <input type="button" class="button-secondary wpv_layout_meta_html_extra_img_edit" onclick="wpv_view_layout_meta_html_extra(this)" value="<?php _e('Manage Media', 'wpv-views'); ?> " /> <div id ="wpv_layout_meta_html_extra_img_edit" style="background:<?php echo WPV_EDIT_BACKGROUND; ?> "> <p><?php _e('<strong>Media</strong> - This is used to add images to a View output.', 'wpv-views'); ?> </p> <input type="button" class="button-secondary wpv_layout_meta_html_extra_img_upload" onclick="tb_show('<?php _e('Upload images'); ?> ', 'media-upload.php?post_id=<?php echo $post->ID; ?> &type=image&wpv-media-insert=1&TB_iframe=true');return false;" value="<?php _e('Add Media', 'wpv-views'); ?> " /> <?php $args = array('post_type' => 'attachment', 'numberposts' => null, 'post_status' => null, 'post_parent' => $post->ID); $attachments = get_posts($args); if ($attachments) { ?> <div class="media-list"> <p>Copy the links of the media items and paste into the meta HTML and CSS editors. You can use full URLs. When exporting and importing this View to another site, all URLs will be adjusted.</p> <table class="wpv_table_attachments widefat"> <thead> <tr> <th><?php _e('Thumbnail', 'wpv-views'); ?> </th> <th><?php _e('URL', 'wpv-views'); ?> </th> </tr> </thead> <?php foreach ($attachments as $attachment) { $type = get_post_mime_type($attachment->ID); $icon = wp_mime_type_icon($type); if ($type == 'image/gif' || $type == 'image/jpeg' || $type == 'image/png') { $thumb = '<img src="' . $attachment->guid . '" alt="' . $attachment->post_title . '" width="60" height="60" />'; } else { $thumb = '<img src="' . $icon . '" />'; } ?> <tr> <td><?php echo $thumb; ?> </td> <td><a href="<?php echo $attachment->guid; ?> "><?php echo $attachment->guid; ?> </a></td> </tr> <?php } ?> </table> <p><input type="button" class="button-secondary wpv_layout_meta_html_extra_img_edit_existing" onclick="tb_show('<?php _e('Edit media items'); ?> ', 'media-upload.php?post_id=<?php echo $post->ID; ?> &type=image&tab=gallery&wpv-media-edit=1&TB_iframe=true');return false;" value="<?php _e('Edit media items', 'wpv-views'); ?> " /></p> </div> <?php } else { ?> <div class="media-list" style="display:none;"> <p>Copy the links of the media items and paste into the meta HTML and CSS editors. You can use full URLs. When exporting and importing this View to another site, all URLs will be adjusted.</p> <table class="wpv_table_attachments widefat"></table> <p><input type="button" class="button-secondary wpv_layout_meta_html_extra_img_edit_existing" onclick="tb_show('<?php _e('Edit media items'); ?> ', 'media-upload.php?post_id=<?php echo $post->ID; ?> &type=image&tab=gallery&wpv-media-edit=1&TB_iframe=true');return false;" value="<?php _e('Edit media items', 'wpv-views'); ?> " /></p> </div> <?php } ?> <div id="wpv_layout_meta_html_extra_img_notice" class="wpv_form_notice" style="display:none;"><?php _e('* These updates will take effect when you save the view.', 'wpv-views'); ?> </div> <p><a style="cursor:pointer;margin-bottom:10px;" id="wpv_layout_meta_html_extra_img_close" onclick="wpv_view_layout_meta_html_extra_img_close()"><strong><?php _e('Close Media manager', 'wpv-views'); ?> </strong></a></p> </div> </div> </div> <?php }
function render_attachment($id = 0, $field) { // vars $attachment = wp_prepare_attachment_for_js($id); $compat = get_compat_media_markup($id); $compat = $compat['item']; $prefix = 'attachments[' . $id . ']'; $thumb = ''; $dimentions = ''; // thumb if (isset($attachment['thumb']['src'])) { // video $thumb = $attachment['thumb']['src']; } elseif (isset($attachment['sizes']['thumbnail']['url'])) { // image $thumb = $attachment['sizes']['thumbnail']['url']; } elseif ($attachment['type'] === 'image') { // svg $thumb = $attachment['url']; } else { // fallback (perhaps attachment does not exist) $thumb = wp_mime_type_icon(); } // dimentions if ($attachment['type'] === 'audio') { $dimentions = __('Length', 'acf') . ': ' . $attachment['fileLength']; } elseif (!empty($attachment['width'])) { $dimentions = $attachment['width'] . ' x ' . $attachment['height']; } if (!empty($attachment['filesizeHumanReadable'])) { $dimentions .= ' (' . $attachment['filesizeHumanReadable'] . ')'; } ?> <div class="acf-gallery-side-info acf-cf"> <img src="<?php echo $thumb; ?> " alt="<?php echo $attachment['alt']; ?> " /> <p class="filename"><strong><?php echo $attachment['filename']; ?> </strong></p> <p class="uploaded"><?php echo $attachment['dateFormatted']; ?> </p> <p class="dimensions"><?php echo $dimentions; ?> </p> <p class="actions"> <a href="#" class="acf-gallery-edit" data-id="<?php echo $id; ?> "><?php _e('Edit', 'acf'); ?> </a> <a href="#" class="acf-gallery-remove" data-id="<?php echo $id; ?> "><?php _e('Remove', 'acf'); ?> </a> </p> </div> <table class="form-table"> <tbody> <?php acf_render_field_wrap(array('name' => 'title', 'prefix' => $prefix, 'type' => 'text', 'label' => __('Title', 'acf'), 'value' => $attachment['title']), 'tr'); acf_render_field_wrap(array('name' => 'caption', 'prefix' => $prefix, 'type' => 'textarea', 'label' => __('Caption', 'acf'), 'value' => $attachment['caption']), 'tr'); acf_render_field_wrap(array('name' => 'alt', 'prefix' => $prefix, 'type' => 'text', 'label' => __('Alt Text', 'acf'), 'value' => $attachment['alt']), 'tr'); acf_render_field_wrap(array('name' => 'description', 'prefix' => $prefix, 'type' => 'textarea', 'label' => __('Description', 'acf'), 'value' => $attachment['description']), 'tr'); ?> </tbody> </table> <?php echo $compat; }
function render_field($field) { // vars $uploader = acf_get_setting('uploader'); // enqueue if ($uploader == 'wp') { acf_enqueue_uploader(); } // vars $o = array('icon' => '', 'title' => '', 'url' => '', 'filesize' => '', 'filename' => ''); $div = array('class' => 'acf-file-uploader acf-cf', 'data-library' => $field['library'], 'data-mime_types' => $field['mime_types'], 'data-uploader' => $uploader); // has value? if ($field['value']) { $file = get_post($field['value']); if ($file) { $o['icon'] = wp_mime_type_icon($file->ID); $o['title'] = $file->post_title; $o['filesize'] = @size_format(filesize(get_attached_file($file->ID))); $o['url'] = wp_get_attachment_url($file->ID); $explode = explode('/', $o['url']); $o['filename'] = end($explode); } // url exists if ($o['url']) { $div['class'] .= ' has-value'; } } ?> <div <?php acf_esc_attr_e($div); ?> > <div class="acf-hidden"> <?php acf_hidden_input(array('name' => $field['name'], 'value' => $field['value'], 'data-name' => 'id')); ?> </div> <div class="show-if-value file-wrap acf-soh"> <div class="file-icon"> <img data-name="icon" src="<?php echo $o['icon']; ?> " alt=""/> </div> <div class="file-info"> <p> <strong data-name="title"><?php echo $o['title']; ?> </strong> </p> <p> <strong><?php _e('File name', 'acf'); ?> :</strong> <a data-name="filename" href="<?php echo $o['url']; ?> " target="_blank"><?php echo $o['filename']; ?> </a> </p> <p> <strong><?php _e('File size', 'acf'); ?> :</strong> <span data-name="filesize"><?php echo $o['filesize']; ?> </span> </p> <ul class="acf-hl acf-soh-target"> <?php if ($uploader != 'basic') { ?> <li><a class="acf-icon -pencil dark" data-name="edit" href="#"></a></li> <?php } ?> <li><a class="acf-icon -cancel dark" data-name="remove" href="#"></a></li> </ul> </div> </div> <div class="hide-if-value"> <?php if ($uploader == 'basic') { ?> <?php if ($field['value'] && !is_numeric($field['value'])) { ?> <div class="acf-error-message"><p><?php echo $field['value']; ?> </p></div> <?php } ?> <input type="file" name="<?php echo $field['name']; ?> " id="<?php echo $field['id']; ?> " /> <?php } else { ?> <p style="margin:0;"><?php _e('No file selected', 'acf'); ?> <a data-name="add" class="acf-button button" href="#"><?php _e('Add File', 'acf'); ?> </a></p> <?php } ?> </div> </div> <?php }
function ot_xml_mime_type_icon($icon, $mime) { if ($mime == 'application/xml' || $mime == 'text/xml') { return wp_mime_type_icon('document'); } return $icon; }
function acf_get_attachment($post) { // get post if (!($post = get_post($post))) { return false; } // vars $thumb_id = 0; $id = $post->ID; $a = array('ID' => $id, 'id' => $id, 'title' => $post->post_title, 'filename' => wp_basename($post->guid), 'url' => wp_get_attachment_url($id), 'alt' => get_post_meta($id, '_wp_attachment_image_alt', true), 'author' => $post->post_author, 'description' => $post->post_content, 'caption' => $post->post_excerpt, 'name' => $post->post_name, 'date' => $post->post_date_gmt, 'modified' => $post->post_modified_gmt, 'mime_type' => $post->post_mime_type, 'type' => acf_maybe_get(explode('/', $post->post_mime_type), 0, ''), 'icon' => wp_mime_type_icon($id)); // video may use featured image if ($a['type'] === 'image') { $thumb_id = $id; $src = wp_get_attachment_image_src($id, 'full'); $a['url'] = $src[0]; $a['width'] = $src[1]; $a['height'] = $src[2]; } elseif ($a['type'] === 'audio' || $a['type'] === 'video') { // video dimentions if ($a['type'] == 'video') { $meta = wp_get_attachment_metadata($id); $a['width'] = acf_maybe_get($meta, 'width', 0); $a['height'] = acf_maybe_get($meta, 'height', 0); } // feature image if ($featured_id = get_post_thumbnail_id($id)) { $thumb_id = $featured_id; } } // sizes if ($thumb_id) { // find all image sizes if ($sizes = get_intermediate_image_sizes()) { $a['sizes'] = array(); foreach ($sizes as $size) { // url $src = wp_get_attachment_image_src($thumb_id, $size); // add src $a['sizes'][$size] = $src[0]; $a['sizes'][$size . '-width'] = $src[1]; $a['sizes'][$size . '-height'] = $src[2]; } } } // return return $a; }
/** * Retrieve an image to represent an attachment. * * A mime icon for files, thumbnail or intermediate size for images. * * @since 2.5.0 * * @param int $attachment_id Image attachment ID. * @param string $size Optional, default is 'thumbnail'. * @param bool $icon Optional, default is false. Whether it is an icon. * @return bool|array Returns an array (url, width, height), or false, if no image is available. */ function wp_get_attachment_image_src($attachment_id, $size = 'thumbnail', $icon = false) { // get a thumbnail or intermediate image if there is one if ($image = image_downsize($attachment_id, $size)) { return $image; } $src = false; if ($icon && ($src = wp_mime_type_icon($attachment_id))) { $icon_dir = apply_filters('icon_dir', ABSPATH . WPINC . '/images/crystal'); $src_file = $icon_dir . '/' . basename($src); @(list($width, $height) = getimagesize($src_file)); } if ($src && $width && $height) { return array($src, $width, $height); } return false; }
/** * Retrieve icon URL and Path. * * @since 2.1.0 * @deprecated 2.5.0 * @deprecated Use wp_get_attachment_image_src() * @see wp_get_attachment_image_src() * * @param int $id Optional. Post ID. * @param bool $fullsize Optional, default to false. Whether to have full image. * @return array Icon URL and full path to file, respectively. */ function get_attachment_icon_src($id = 0, $fullsize = false) { _deprecated_function(__FUNCTION__, '2.5', 'wp_get_attachment_image_src()'); $id = (int) $id; if (!($post = get_post($id))) { return false; } $file = get_attached_file($post->ID); if (!$fullsize && ($src = wp_get_attachment_thumb_url($post->ID))) { // We have a thumbnail desired, specified and existing $src_file = basename($src); $class = 'attachmentthumb'; } elseif (wp_attachment_is_image($post->ID)) { // We have an image without a thumbnail $src = wp_get_attachment_url($post->ID); $src_file =& $file; $class = 'attachmentimage'; } elseif ($src = wp_mime_type_icon($post->ID)) { // No thumb, no image. We'll look for a mime-related icon instead. $icon_dir = apply_filters('icon_dir', get_template_directory() . '/images'); $src_file = $icon_dir . '/' . basename($src); } if (!isset($src) || !$src) { return false; } return array($src, $src_file); }
/** * Handle public file uploaded using buddydrive_editor * * @since 1.3.0 */ function buddydrive_add_public_file() { /** * Sending the json response will be different if * the current Plupload runtime is html4 */ $is_html4 = false; if (!empty($_POST['html4'])) { $is_html4 = true; } // Check the nonce check_admin_referer('bp-uploader'); // Init the BuddyPress parameters $bp_params = (array) $_POST['bp_params']; // Check params if (empty($bp_params['item_id'])) { bp_attachments_json_response(false, $is_html4); } // Capability check if (!is_user_logged_in() || (int) bp_loggedin_user_id() !== (int) $bp_params['item_id']) { bp_attachments_json_response(false, $is_html4); } $bd_file = buddydrive_upload_item($_FILES, $bp_params['item_id']); // Error while trying to upload the file if (!empty($bd_file['error'])) { bp_attachments_json_response(false, $is_html4, array('type' => 'upload_error', 'message' => $bd_file['error'])); } $name_parts = pathinfo($bd_file['file']); $url = $bd_file['url']; $mime = $bd_file['type']; $file = $bd_file['file']; $title = $name_parts['filename']; if (is_numeric($title)) { $title = 'f-' . $title; } $meta = new stdClass(); // Defaults to public. $meta->privacy = 'public'; if (!empty($bp_params['privacy'])) { $meta->privacy = $bp_params['privacy']; if (!empty($bp_params['privacy_item_id']) && 'groups' === $meta->privacy) { $meta->groups = $bp_params['privacy_item_id']; } } $buddyfile_id = buddydrive_save_item(array('type' => buddydrive_get_file_post_type(), 'guid' => $url, 'title' => $title, 'mime_type' => $mime, 'metas' => $meta)); if (empty($buddyfile_id)) { bp_attachments_json_response(false, $is_html4, array('type' => 'upload_error', 'message' => __('Error while creating the file, sorry.', 'buddydrive'))); } else { $icon = wp_mime_type_icon($buddyfile_id); // Try to create a thumbnail if it's an image and a public file if (!empty($buddyfile_id) && 'public' === $meta->privacy) { $thumbnail = buddydrive_set_thumbnail($buddyfile_id, $bd_file); if (!empty($thumbnail)) { $icon = $thumbnail; } } } $response = buddydrive_get_buddyfile($buddyfile_id); // Finally return file to the editor bp_attachments_json_response(true, $is_html4, array('name' => esc_html($response->title), 'icon' => $icon, 'url' => esc_url_raw($response->link))); }