Esempio n. 1
0
 /**
  * Returns whether or not their is image editor support.
  *
  * @todo Nonfunctional method needs completed.
  *
  * @access public
  * @since  8.1
  * @static
  *
  * @return bool|void
  */
 public static function checkEditorSupport()
 {
     if (!is_admin()) {
         return;
     }
     $atts = array('mime_type' => 'image/jpeg');
     if (wp_image_editor_supports($atts) !== TRUE) {
         cnMessage::create('error', 'image_edit_support_failed');
     }
     return TRUE;
 }
 /**
  * Resize/Crop Selection
  *
  * @since 1.3.0
  *
  * @return boolean
  */
 public function resize_crop_selection($args = array())
 {
     extract($_POST);
     extract($args);
     global $wp_version;
     $thumb_offset = $orig_h / $final_h;
     $thumb_h = $orig_h / $thumb_offset;
     $thumb_w = $orig_w / $thumb_offset;
     $src_w = $final_w;
     $mime_type = get_post_mime_type($id);
     $editor_supports_args = array('mime_type' => $mime_type, 'methods' => array('crop', 'resize', 'save'));
     $img_editor_test = wp_image_editor_supports($editor_supports_args);
     if (floatval($wp_version) >= 3.5 and $img_editor_test !== false) {
         $upload_dir = wp_upload_dir();
         extract($upload_dir);
         $pathinfo = pathinfo($src);
         extract($pathinfo);
         // Make an URI out of an URL
         $img_src_uri = trailingslashit($basedir) . str_replace($baseurl, '', $src);
         // Make an Directory URI out of an URL
         $img_dir_uri = str_replace($basename, '', $img_src_uri);
         // Image Edit
         $img = wp_get_image_editor($img_src_uri);
         if (!is_wp_error($img)) {
             $resize = $img->resize($thumb_w, $thumb_h, false);
             $crop = $img->crop($src_x, $src_y, $src_w, $src_h, NULL, NULL, false);
             $filename = $img->generate_filename($img->get_suffix(), $img_dir_uri, $extension);
             $saved = $img->save();
             if (!is_wp_error($saved)) {
                 return true;
             } else {
                 return false;
             }
             // if/else()
         }
         // if()
         return false;
     }
 }
Esempio n. 3
0
function dynimg_404_handler()
{
    if (!is_404()) {
        return;
    }
    // Has the file name the proper format for this handler?
    if (!preg_match('/(.*)-([0-9]+)x([0-9]+)(c)?\\.(\\w+)($|\\?|#)/i', $_SERVER['REQUEST_URI'], $matches)) {
        return;
    }
    $mime_types = wp_get_mime_types();
    $img_ext = $matches[5];
    $ext_known = false;
    // The extensions for some MIME types are set as regular expression (PCRE).
    foreach ($mime_types as $rgx_ext => $mime_type) {
        if (preg_match("/{$rgx_ext}/i", $img_ext)) {
            if (wp_image_editor_supports(array('mime_type' => $mime_type))) {
                $ext_known = true;
                break;
            }
        }
    }
    if (!$ext_known) {
        return;
    }
    $filename = urldecode($matches[1] . '.' . $img_ext);
    $width = $matches[2];
    $height = $matches[3];
    $crop = !empty($matches[4]);
    $uploads_dir = wp_upload_dir();
    $temp = parse_url($uploads_dir['baseurl']);
    $upload_path = $temp['path'];
    $findfile = str_replace($upload_path, '', $filename);
    $basefile = $uploads_dir['basedir'] . $findfile;
    // Serve the image this one time (next time the webserver will do it for us)
    dynimg_create_save_stream($basefile, $width, $height, $crop);
}
Esempio n. 4
0
/**
 * Displays the image and editor in the post editor
 *
 * @since 3.5.0
 */
function edit_form_image_editor($post)
{
    $open = isset($_GET['image-editor']);
    if ($open) {
        require_once ABSPATH . 'wp-admin/includes/image-edit.php';
    }
    $thumb_url = false;
    if ($attachment_id = intval($post->ID)) {
        $thumb_url = wp_get_attachment_image_src($attachment_id, array(900, 450), true);
    }
    $alt_text = get_post_meta($post->ID, '_wp_attachment_image_alt', true);
    $att_url = wp_get_attachment_url($post->ID);
    ?>
	<div class="wp_attachment_holder">
	<?php 
    if (wp_attachment_is_image($post->ID)) {
        $image_edit_button = '';
        if (wp_image_editor_supports(array('mime_type' => $post->post_mime_type))) {
            $nonce = wp_create_nonce("image_editor-{$post->ID}");
            $image_edit_button = "<input type='button' id='imgedit-open-btn-{$post->ID}' onclick='imageEdit.open( {$post->ID}, \"{$nonce}\" )' class='button' value='" . esc_attr__('Edit Image') . "' /> <span class='spinner'></span>";
        }
        ?>

		<div class="imgedit-response" id="imgedit-response-<?php 
        echo $attachment_id;
        ?>
"></div>

		<div<?php 
        if ($open) {
            echo ' style="display:none"';
        }
        ?>
 class="wp_attachment_image" id="media-head-<?php 
        echo $attachment_id;
        ?>
">
			<p id="thumbnail-head-<?php 
        echo $attachment_id;
        ?>
"><img class="thumbnail" src="<?php 
        echo set_url_scheme($thumb_url[0]);
        ?>
" style="max-width:100%" alt="" /></p>
			<p><?php 
        echo $image_edit_button;
        ?>
</p>
		</div>
		<div<?php 
        if (!$open) {
            echo ' style="display:none"';
        }
        ?>
 class="image-editor" id="image-editor-<?php 
        echo $attachment_id;
        ?>
">
			<?php 
        if ($open) {
            wp_image_editor($attachment_id);
        }
        ?>
		</div>
	<?php 
    } elseif ($attachment_id && 0 === strpos($post->post_mime_type, 'audio/')) {
        wp_maybe_generate_attachment_metadata($post);
        echo wp_audio_shortcode(array('src' => $att_url));
    } elseif ($attachment_id && 0 === strpos($post->post_mime_type, 'video/')) {
        wp_maybe_generate_attachment_metadata($post);
        $meta = wp_get_attachment_metadata($attachment_id);
        $w = !empty($meta['width']) ? min($meta['width'], 640) : 0;
        $h = !empty($meta['height']) ? $meta['height'] : 0;
        if ($h && $w < $meta['width']) {
            $h = round($meta['height'] * $w / $meta['width']);
        }
        $attr = array('src' => $att_url);
        if (!empty($w) && !empty($h)) {
            $attr['width'] = $w;
            $attr['height'] = $h;
        }
        $thumb_id = get_post_thumbnail_id($attachment_id);
        if (!empty($thumb_id)) {
            $attr['poster'] = wp_get_attachment_url($thumb_id);
        }
        echo wp_video_shortcode($attr);
    }
    ?>
	</div>
	<div class="wp_attachment_details edit-form-section">
		<p>
			<label for="attachment_caption"><strong><?php 
    _e('Caption');
    ?>
</strong></label><br />
			<textarea class="widefat" name="excerpt" id="attachment_caption"><?php 
    echo $post->post_excerpt;
    ?>
</textarea>
		</p>


	<?php 
    if ('image' === substr($post->post_mime_type, 0, 5)) {
        ?>
		<p>
			<label for="attachment_alt"><strong><?php 
        _e('Alternative Text');
        ?>
</strong></label><br />
			<input type="text" class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" value="<?php 
        echo esc_attr($alt_text);
        ?>
" />
		</p>
	<?php 
    }
    ?>

	<?php 
    $quicktags_settings = array('buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close');
    $editor_args = array('textarea_name' => 'content', 'textarea_rows' => 5, 'media_buttons' => false, 'tinymce' => false, 'quicktags' => $quicktags_settings);
    ?>

	<label for="content"><strong><?php 
    _e('Description');
    ?>
</strong><?php 
    if (preg_match('#^(audio|video)/#', $post->post_mime_type)) {
        echo ': ' . __('Displayed on attachment pages.');
    }
    ?>
</label>
	<?php 
    wp_editor($post->post_content, 'attachment_content', $editor_args);
    ?>

	</div>
	<?php 
    $extras = get_compat_media_markup($post->ID);
    echo $extras['item'];
    echo '<input type="hidden" id="image-edit-context" value="edit-attachment" />' . "\n";
}
Esempio n. 5
0
/**
 * Loads the WP image-editing interface.
 *
 * @param int         $post_id Post ID.
 * @param bool|object $msg     Optional. Message to display for image editor updates or errors.
 *                             Default false.
 */
function wp_image_editor($post_id, $msg = false)
{
    $nonce = wp_create_nonce("image_editor-{$post_id}");
    $meta = wp_get_attachment_metadata($post_id);
    $thumb = image_get_intermediate_size($post_id, 'thumbnail');
    $sub_sizes = isset($meta['sizes']) && is_array($meta['sizes']);
    $note = '';
    if (isset($meta['width'], $meta['height'])) {
        $big = max($meta['width'], $meta['height']);
    } else {
        die(__('Image data does not exist. Please re-upload the image.'));
    }
    $sizer = $big > 400 ? 400 / $big : 1;
    $backup_sizes = get_post_meta($post_id, '_wp_attachment_backup_sizes', true);
    $can_restore = false;
    if (!empty($backup_sizes) && isset($backup_sizes['full-orig'], $meta['file'])) {
        $can_restore = $backup_sizes['full-orig']['file'] != basename($meta['file']);
    }
    if ($msg) {
        if (isset($msg->error)) {
            $note = "<div class='error'><p>{$msg->error}</p></div>";
        } elseif (isset($msg->msg)) {
            $note = "<div class='updated'><p>{$msg->msg}</p></div>";
        }
    }
    ?>
	<div class="imgedit-wrap">
	<div id="imgedit-panel-<?php 
    echo $post_id;
    ?>
">

	<div class="imgedit-settings">
	<div class="imgedit-group">
	<div class="imgedit-group-top">
		<h3><?php 
    _e('Scale Image');
    ?>
 <a href="#" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;"></a></h3>
		<div class="imgedit-help">
		<p><?php 
    _e('You can proportionally scale the original image. For best results, scaling should be done before you crop, flip, or rotate. Images can only be scaled down, not up.');
    ?>
</p>
		</div>
		<?php 
    if (isset($meta['width'], $meta['height'])) {
        ?>
		<p><?php 
        printf(__('Original dimensions %s'), $meta['width'] . ' &times; ' . $meta['height']);
        ?>
</p>
		<?php 
    }
    ?>
		<div class="imgedit-submit">
		<span class="nowrap"><input type="text" id="imgedit-scale-width-<?php 
    echo $post_id;
    ?>
" onkeyup="imageEdit.scaleChanged(<?php 
    echo $post_id;
    ?>
, 1)" onblur="imageEdit.scaleChanged(<?php 
    echo $post_id;
    ?>
, 1)" style="width:4em;" value="<?php 
    echo isset($meta['width']) ? $meta['width'] : 0;
    ?>
" /> &times; <input type="text" id="imgedit-scale-height-<?php 
    echo $post_id;
    ?>
" onkeyup="imageEdit.scaleChanged(<?php 
    echo $post_id;
    ?>
, 0)" onblur="imageEdit.scaleChanged(<?php 
    echo $post_id;
    ?>
, 0)" style="width:4em;" value="<?php 
    echo isset($meta['height']) ? $meta['height'] : 0;
    ?>
" />
		<span class="imgedit-scale-warn" id="imgedit-scale-warn-<?php 
    echo $post_id;
    ?>
">!</span></span>
		<input type="button" onclick="imageEdit.action(<?php 
    echo "{$post_id}, '{$nonce}'";
    ?>
, 'scale')" class="button button-primary" value="<?php 
    esc_attr_e('Scale');
    ?>
" />
		</div>
	</div>
	</div>

<?php 
    if ($can_restore) {
        ?>

	<div class="imgedit-group">
	<div class="imgedit-group-top">
		<h3><a onclick="imageEdit.toggleHelp(this);return false;" href="#"><?php 
        _e('Restore Original Image');
        ?>
 <span class="dashicons dashicons-arrow-down imgedit-help-toggle"></span></a></h3>
		<div class="imgedit-help">
		<p><?php 
        _e('Discard any changes and restore the original image.');
        if (!defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE) {
            echo ' ' . __('Previously edited copies of the image will not be deleted.');
        }
        ?>
</p>
		<div class="imgedit-submit">
		<input type="button" onclick="imageEdit.action(<?php 
        echo "{$post_id}, '{$nonce}'";
        ?>
, 'restore')" class="button button-primary" value="<?php 
        esc_attr_e('Restore image');
        ?>
" <?php 
        echo $can_restore;
        ?>
 />
		</div>
		</div>
	</div>
	</div>

<?php 
    }
    ?>

	<div class="imgedit-group">
	<div class="imgedit-group-top">
		<h3><?php 
    _e('Image Crop');
    ?>
 <a href="#" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;"></a></h3>

		<div class="imgedit-help">
		<p><?php 
    _e('To crop the image, click on it and drag to make your selection.');
    ?>
</p>

		<p><strong><?php 
    _e('Crop Aspect Ratio');
    ?>
</strong><br />
		<?php 
    _e('The aspect ratio is the relationship between the width and height. You can preserve the aspect ratio by holding down the shift key while resizing your selection. Use the input box to specify the aspect ratio, e.g. 1:1 (square), 4:3, 16:9, etc.');
    ?>
</p>

		<p><strong><?php 
    _e('Crop Selection');
    ?>
</strong><br />
		<?php 
    _e('Once you have made your selection, you can adjust it by entering the size in pixels. The minimum selection size is the thumbnail size as set in the Media settings.');
    ?>
</p>
		</div>
	</div>

	<p>
		<?php 
    _e('Aspect ratio:');
    ?>
		<span  class="nowrap">
		<input type="text" id="imgedit-crop-width-<?php 
    echo $post_id;
    ?>
" onkeyup="imageEdit.setRatioSelection(<?php 
    echo $post_id;
    ?>
, 0, this)" style="width:3em;" />
		:
		<input type="text" id="imgedit-crop-height-<?php 
    echo $post_id;
    ?>
" onkeyup="imageEdit.setRatioSelection(<?php 
    echo $post_id;
    ?>
, 1, this)" style="width:3em;" />
		</span>
	</p>

	<p id="imgedit-crop-sel-<?php 
    echo $post_id;
    ?>
">
		<?php 
    _e('Selection:');
    ?>
		<span  class="nowrap">
		<input type="text" id="imgedit-sel-width-<?php 
    echo $post_id;
    ?>
" onkeyup="imageEdit.setNumSelection(<?php 
    echo $post_id;
    ?>
)" style="width:4em;" />
		&times;
		<input type="text" id="imgedit-sel-height-<?php 
    echo $post_id;
    ?>
" onkeyup="imageEdit.setNumSelection(<?php 
    echo $post_id;
    ?>
)" style="width:4em;" />
		</span>
	</p>
	</div>

	<?php 
    if ($thumb && $sub_sizes) {
        $thumb_img = wp_constrain_dimensions($thumb['width'], $thumb['height'], 160, 120);
        ?>

	<div class="imgedit-group imgedit-applyto">
	<div class="imgedit-group-top">
		<h3><?php 
        _e('Thumbnail Settings');
        ?>
 <a href="#" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;"></a></h3>
		<p class="imgedit-help"><?php 
        _e('You can edit the image while preserving the thumbnail. For example, you may wish to have a square thumbnail that displays just a section of the image.');
        ?>
</p>
	</div>

	<p>
		<img src="<?php 
        echo $thumb['url'];
        ?>
" width="<?php 
        echo $thumb_img[0];
        ?>
" height="<?php 
        echo $thumb_img[1];
        ?>
" class="imgedit-size-preview" alt="" draggable="false" />
		<br /><?php 
        _e('Current thumbnail');
        ?>
	</p>

	<p id="imgedit-save-target-<?php 
        echo $post_id;
        ?>
">
		<strong><?php 
        _e('Apply changes to:');
        ?>
</strong><br />

		<label class="imgedit-label">
		<input type="radio" name="imgedit-target-<?php 
        echo $post_id;
        ?>
" value="all" checked="checked" />
		<?php 
        _e('All image sizes');
        ?>
</label>

		<label class="imgedit-label">
		<input type="radio" name="imgedit-target-<?php 
        echo $post_id;
        ?>
" value="thumbnail" />
		<?php 
        _e('Thumbnail');
        ?>
</label>

		<label class="imgedit-label">
		<input type="radio" name="imgedit-target-<?php 
        echo $post_id;
        ?>
" value="nothumb" />
		<?php 
        _e('All sizes except thumbnail');
        ?>
</label>
	</p>
	</div>

	<?php 
    }
    ?>

	</div>

	<div class="imgedit-panel-content">
		<?php 
    echo $note;
    ?>
		<div class="imgedit-menu">
			<div onclick="imageEdit.crop(<?php 
    echo "{$post_id}, '{$nonce}'";
    ?>
, this)" class="imgedit-crop disabled" title="<?php 
    esc_attr_e('Crop');
    ?>
"></div><?php 
    // On some setups GD library does not provide imagerotate() - Ticket #11536
    if (wp_image_editor_supports(array('mime_type' => get_post_mime_type($post_id), 'methods' => array('rotate')))) {
        ?>
			<div class="imgedit-rleft"  onclick="imageEdit.rotate( 90, <?php 
        echo "{$post_id}, '{$nonce}'";
        ?>
, this)" title="<?php 
        esc_attr_e('Rotate counter-clockwise');
        ?>
"></div>
			<div class="imgedit-rright" onclick="imageEdit.rotate(-90, <?php 
        echo "{$post_id}, '{$nonce}'";
        ?>
, this)" title="<?php 
        esc_attr_e('Rotate clockwise');
        ?>
"></div>
	<?php 
    } else {
        $note_no_rotate = esc_attr__('Image rotation is not supported by your web host.');
        ?>
		    <div class="imgedit-rleft disabled"  title="<?php 
        echo $note_no_rotate;
        ?>
"></div>
		    <div class="imgedit-rright disabled" title="<?php 
        echo $note_no_rotate;
        ?>
"></div>
	<?php 
    }
    ?>

			<div onclick="imageEdit.flip(1, <?php 
    echo "{$post_id}, '{$nonce}'";
    ?>
, this)" class="imgedit-flipv" title="<?php 
    esc_attr_e('Flip vertically');
    ?>
"></div>
			<div onclick="imageEdit.flip(2, <?php 
    echo "{$post_id}, '{$nonce}'";
    ?>
, this)" class="imgedit-fliph" title="<?php 
    esc_attr_e('Flip horizontally');
    ?>
"></div>

			<div id="image-undo-<?php 
    echo $post_id;
    ?>
" onclick="imageEdit.undo(<?php 
    echo "{$post_id}, '{$nonce}'";
    ?>
, this)" class="imgedit-undo disabled" title="<?php 
    esc_attr_e('Undo');
    ?>
"></div>
			<div id="image-redo-<?php 
    echo $post_id;
    ?>
" onclick="imageEdit.redo(<?php 
    echo "{$post_id}, '{$nonce}'";
    ?>
, this)" class="imgedit-redo disabled" title="<?php 
    esc_attr_e('Redo');
    ?>
"></div>
			<br class="clear" />
		</div>

		<input type="hidden" id="imgedit-sizer-<?php 
    echo $post_id;
    ?>
" value="<?php 
    echo $sizer;
    ?>
" />
		<input type="hidden" id="imgedit-history-<?php 
    echo $post_id;
    ?>
" value="" />
		<input type="hidden" id="imgedit-undone-<?php 
    echo $post_id;
    ?>
" value="0" />
		<input type="hidden" id="imgedit-selection-<?php 
    echo $post_id;
    ?>
" value="" />
		<input type="hidden" id="imgedit-x-<?php 
    echo $post_id;
    ?>
" value="<?php 
    echo isset($meta['width']) ? $meta['width'] : 0;
    ?>
" />
		<input type="hidden" id="imgedit-y-<?php 
    echo $post_id;
    ?>
" value="<?php 
    echo isset($meta['height']) ? $meta['height'] : 0;
    ?>
" />

		<div id="imgedit-crop-<?php 
    echo $post_id;
    ?>
" class="imgedit-crop-wrap">
		<img id="image-preview-<?php 
    echo $post_id;
    ?>
" onload="imageEdit.imgLoaded('<?php 
    echo $post_id;
    ?>
')" src="<?php 
    echo admin_url('admin-ajax.php', 'relative');
    ?>
?action=imgedit-preview&amp;_ajax_nonce=<?php 
    echo $nonce;
    ?>
&amp;postid=<?php 
    echo $post_id;
    ?>
&amp;rand=<?php 
    echo rand(1, 99999);
    ?>
" />
		</div>

		<div class="imgedit-submit">
			<input type="button" onclick="imageEdit.close(<?php 
    echo $post_id;
    ?>
, 1)" class="button" value="<?php 
    esc_attr_e('Cancel');
    ?>
" />
			<input type="button" onclick="imageEdit.save(<?php 
    echo "{$post_id}, '{$nonce}'";
    ?>
)" disabled="disabled" class="button button-primary imgedit-submit-btn" value="<?php 
    esc_attr_e('Save');
    ?>
" />
		</div>
	</div>

	</div>
	<div class="imgedit-wait" id="imgedit-wait-<?php 
    echo $post_id;
    ?>
"></div>
	<script type="text/javascript">jQuery( function() { imageEdit.init(<?php 
    echo $post_id;
    ?>
); });</script>
	<div class="hidden" id="imgedit-leaving-<?php 
    echo $post_id;
    ?>
"><?php 
    _e("There are unsaved changes that will be lost. 'OK' to continue, 'Cancel' to return to the Image Editor.");
    ?>
</div>
	</div>
<?php 
}
Esempio n. 6
0
/**
 * Displays the image and editor in the post editor
 *
 * @since 3.5.0
 */
function edit_form_image_editor()
{
    $post = get_post();
    $thumb_url = false;
    if ($attachment_id = intval($post->ID)) {
        $thumb_url = wp_get_attachment_image_src($attachment_id, array(900, 600), true);
    }
    $filename = esc_html(basename($post->guid));
    $title = esc_attr($post->post_title);
    $alt_text = get_post_meta($post->ID, '_wp_attachment_image_alt', true);
    $media_dims = '';
    $meta = wp_get_attachment_metadata($post->ID);
    if (is_array($meta) && array_key_exists('width', $meta) && array_key_exists('height', $meta)) {
        $media_dims .= "<span id='media-dims-{$post->ID}'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
    }
    $media_dims = apply_filters('media_meta', $media_dims, $post);
    $att_url = wp_get_attachment_url($post->ID);
    $image_edit_button = '';
    if (wp_image_editor_supports(array('mime_type' => $post->post_mime_type))) {
        $nonce = wp_create_nonce("image_editor-{$post->ID}");
        $image_edit_button = "<input type='button' id='imgedit-open-btn-{$post->ID}' onclick='imageEdit.open( {$post->ID}, \"{$nonce}\" )' class='button' value='" . esc_attr__('Edit Image') . "' /> <span class='spinner'></span>";
    }
    ?>
	<div class="wp_attachment_holder">
		<div class="imgedit-response" id="imgedit-response-<?php 
    echo $attachment_id;
    ?>
"></div>

		<div class="wp_attachment_image" id="media-head-<?php 
    echo $attachment_id;
    ?>
">
			<p id="thumbnail-head-<?php 
    echo $attachment_id;
    ?>
"><img class="thumbnail" src="<?php 
    echo set_url_scheme($thumb_url[0]);
    ?>
" style="max-width:100%" alt="" /></p>
			<p><?php 
    echo $image_edit_button;
    ?>
</p>
		</div>
		<div style="display:none" class="image-editor" id="image-editor-<?php 
    echo $attachment_id;
    ?>
"></div>
	</div>

	<div class="wp_attachment_details">
		<p>
			<label for="attachment_caption"><strong><?php 
    _e('Caption');
    ?>
</strong></label><br />
			<textarea class="widefat" name="excerpt" id="attachment_caption"><?php 
    echo $post->post_excerpt;
    ?>
</textarea>
		</p>

	<?php 
    if ('image' === substr($post->post_mime_type, 0, 5)) {
        ?>
		<p>
			<label for="attachment_alt"><strong><?php 
        _e('Alternative Text');
        ?>
</strong></label><br />
			<input type="text" class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" value="<?php 
        echo esc_attr($alt_text);
        ?>
" />
		</p>
	<?php 
    }
    ?>

	</div>
	<?php 
    $extras = get_compat_media_markup($post->ID);
    echo $extras['item'];
    foreach ($extras['hidden'] as $hidden_field => $value) {
        echo '<input type="hidden" name="' . esc_attr($hidden_field) . '" value="' . esc_attr($value) . '" />' . "\n";
    }
    echo '<input type="hidden" id="image-edit-context" value="edit-attachment" />' . "\n";
}
Esempio n. 7
0
        wp_update_attachment_metadata($id, $metadata);
        WP_CLI::log("Regenerated thumbnails for {$att_desc}");
    }
    private function remove_old_images($att_id)
    {
        $wud = wp_upload_dir();
        $metadata = wp_get_attachment_metadata($att_id);
        if (empty($metadata['file'])) {
            return;
        }
        $dir_path = $wud['basedir'] . '/' . dirname($metadata['file']) . '/';
        $original_path = $dir_path . basename($metadata['file']);
        if (empty($metadata['sizes'])) {
            return;
        }
        foreach ($metadata['sizes'] as $size_info) {
            $intermediate_path = $dir_path . $size_info['file'];
            if ($intermediate_path == $original_path) {
                continue;
            }
            if (file_exists($intermediate_path)) {
                unlink($intermediate_path);
            }
        }
    }
}
WP_CLI::add_command('media', 'Media_Command', array('before_invoke' => function () {
    if (!wp_image_editor_supports()) {
        WP_CLI::error('No support for generating images found. ' . 'Please install the Imagick or GD PHP extensions.');
    }
}));
Esempio n. 8
0
 private function _is_image_editor_supports()
 {
     $arg = ['mime_type' => 'image/jpeg'];
     return wp_image_editor_supports($arg);
 }
Esempio n. 9
0
/**
 * WordPress Image Editor
 *
 * @package WordPress
 * @subpackage Administration
 */
function wp_image_editor($post_id, $msg = false)
{
    $nonce = wp_create_nonce("image_editor-{$post_id}");
    $meta = wp_get_attachment_metadata($post_id);
    $thumb = image_get_intermediate_size($post_id, 'thumbnail');
    $sub_sizes = isset($meta['sizes']) && is_array($meta['sizes']);
    $note = '';
    if (is_array($meta) && isset($meta['width'])) {
        $big = max($meta['width'], $meta['height']);
    } else {
        die(__('Image data does not exist. Please re-upload the image.'));
    }
    $sizer = $big > 400 ? 400 / $big : 1;
    $backup_sizes = get_post_meta($post_id, '_wp_attachment_backup_sizes', true);
    $can_restore = !empty($backup_sizes) && isset($backup_sizes['full-orig']) && $backup_sizes['full-orig']['file'] != basename($meta['file']);
    if ($msg) {
        if (isset($msg->error)) {
            $note = "<div class='error'><p>{$msg->error}</p></div>";
        } elseif (isset($msg->msg)) {
            $note = "<div class='updated'><p>{$msg->msg}</p></div>";
        }
    }
    ?>
	<div class="imgedit-wrap">
	<?php 
    echo $note;
    ?>
	<table id="imgedit-panel-<?php 
    echo $post_id;
    ?>
"><tbody>
	<tr><td>
	<div class="imgedit-menu">
		<div onclick="imageEdit.crop(<?php 
    echo "{$post_id}, '{$nonce}'";
    ?>
, this)" class="imgedit-crop disabled" title="<?php 
    esc_attr_e('Crop');
    ?>
"></div><?php 
    // On some setups GD library does not provide imagerotate() - Ticket #11536
    if (wp_image_editor_supports(array('mime_type' => get_post_mime_type($post_id), 'methods' => array('rotate')))) {
        ?>
		<div class="imgedit-rleft"  onclick="imageEdit.rotate( 90, <?php 
        echo "{$post_id}, '{$nonce}'";
        ?>
, this)" title="<?php 
        esc_attr_e('Rotate counter-clockwise');
        ?>
"></div>
		<div class="imgedit-rright" onclick="imageEdit.rotate(-90, <?php 
        echo "{$post_id}, '{$nonce}'";
        ?>
, this)" title="<?php 
        esc_attr_e('Rotate clockwise');
        ?>
"></div>
<?php 
    } else {
        $note_no_rotate = esc_attr__('Image rotation is not supported by your web host.');
        ?>
	    <div class="imgedit-rleft disabled"  title="<?php 
        echo $note_no_rotate;
        ?>
"></div>
	    <div class="imgedit-rright disabled" title="<?php 
        echo $note_no_rotate;
        ?>
"></div>
<?php 
    }
    ?>

		<div onclick="imageEdit.flip(1, <?php 
    echo "{$post_id}, '{$nonce}'";
    ?>
, this)" class="imgedit-flipv" title="<?php 
    esc_attr_e('Flip vertically');
    ?>
"></div>
		<div onclick="imageEdit.flip(2, <?php 
    echo "{$post_id}, '{$nonce}'";
    ?>
, this)" class="imgedit-fliph" title="<?php 
    esc_attr_e('Flip horizontally');
    ?>
"></div>

		<div id="image-undo-<?php 
    echo $post_id;
    ?>
" onclick="imageEdit.undo(<?php 
    echo "{$post_id}, '{$nonce}'";
    ?>
, this)" class="imgedit-undo disabled" title="<?php 
    esc_attr_e('Undo');
    ?>
"></div>
		<div id="image-redo-<?php 
    echo $post_id;
    ?>
" onclick="imageEdit.redo(<?php 
    echo "{$post_id}, '{$nonce}'";
    ?>
, this)" class="imgedit-redo disabled" title="<?php 
    esc_attr_e('Redo');
    ?>
"></div>
		<br class="clear" />
	</div>

	<input type="hidden" id="imgedit-sizer-<?php 
    echo $post_id;
    ?>
" value="<?php 
    echo $sizer;
    ?>
" />
	<input type="hidden" id="imgedit-minthumb-<?php 
    echo $post_id;
    ?>
" value="<?php 
    echo get_option('thumbnail_size_w') . ':' . get_option('thumbnail_size_h');
    ?>
" />
	<input type="hidden" id="imgedit-history-<?php 
    echo $post_id;
    ?>
" value="" />
	<input type="hidden" id="imgedit-undone-<?php 
    echo $post_id;
    ?>
" value="0" />
	<input type="hidden" id="imgedit-selection-<?php 
    echo $post_id;
    ?>
" value="" />
	<input type="hidden" id="imgedit-x-<?php 
    echo $post_id;
    ?>
" value="<?php 
    echo $meta['width'];
    ?>
" />
	<input type="hidden" id="imgedit-y-<?php 
    echo $post_id;
    ?>
" value="<?php 
    echo $meta['height'];
    ?>
" />

	<div id="imgedit-crop-<?php 
    echo $post_id;
    ?>
" class="imgedit-crop-wrap">
	<img id="image-preview-<?php 
    echo $post_id;
    ?>
" onload="imageEdit.imgLoaded('<?php 
    echo $post_id;
    ?>
')" src="<?php 
    echo admin_url('admin-ajax.php', 'relative');
    ?>
?action=imgedit-preview&amp;_ajax_nonce=<?php 
    echo $nonce;
    ?>
&amp;postid=<?php 
    echo $post_id;
    ?>
&amp;rand=<?php 
    echo rand(1, 99999);
    ?>
" />
	</div>

	<div class="imgedit-submit">
		<input type="button" onclick="imageEdit.close(<?php 
    echo $post_id;
    ?>
, 1)" class="button" value="<?php 
    esc_attr_e('Cancel');
    ?>
" />
		<input type="button" onclick="imageEdit.save(<?php 
    echo "{$post_id}, '{$nonce}'";
    ?>
)" disabled="disabled" class="button-primary imgedit-submit-btn" value="<?php 
    esc_attr_e('Save');
    ?>
" />
	</div>
	</td>

	<td class="imgedit-settings">
	<div class="imgedit-group">
	<div class="imgedit-group-top">
		<a class="imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" href="#"><strong><?php 
    _e('Scale Image');
    ?>
</strong></a>
		<div class="imgedit-help">
		<p><?php 
    _e('You can proportionally scale the original image. For best results the scaling should be done before performing any other operations on it like crop, rotate, etc. Note that if you make the image larger it may become fuzzy.');
    ?>
</p>
		<p><?php 
    printf(__('Original dimensions %s'), $meta['width'] . '&times;' . $meta['height']);
    ?>
</p>
		<div class="imgedit-submit">
		<span class="nowrap"><input type="text" id="imgedit-scale-width-<?php 
    echo $post_id;
    ?>
" onkeyup="imageEdit.scaleChanged(<?php 
    echo $post_id;
    ?>
, 1)" onblur="imageEdit.scaleChanged(<?php 
    echo $post_id;
    ?>
, 1)" style="width:4em;" value="<?php 
    echo $meta['width'];
    ?>
" />&times;<input type="text" id="imgedit-scale-height-<?php 
    echo $post_id;
    ?>
" onkeyup="imageEdit.scaleChanged(<?php 
    echo $post_id;
    ?>
, 0)" onblur="imageEdit.scaleChanged(<?php 
    echo $post_id;
    ?>
, 0)" style="width:4em;" value="<?php 
    echo $meta['height'];
    ?>
" />
		<span class="imgedit-scale-warn" id="imgedit-scale-warn-<?php 
    echo $post_id;
    ?>
">!</span></span>
		<input type="button" onclick="imageEdit.action(<?php 
    echo "{$post_id}, '{$nonce}'";
    ?>
, 'scale')" class="button-primary" value="<?php 
    esc_attr_e('Scale');
    ?>
" />
		</div>
		</div>
	</div>

<?php 
    if ($can_restore) {
        ?>

	<div class="imgedit-group-top">
		<a class="imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" href="#"><strong><?php 
        _e('Restore Original Image');
        ?>
</strong></a>
		<div class="imgedit-help">
		<p><?php 
        _e('Discard any changes and restore the original image.');
        if (!defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE) {
            echo ' ' . __('Previously edited copies of the image will not be deleted.');
        }
        ?>
</p>
		<div class="imgedit-submit">
		<input type="button" onclick="imageEdit.action(<?php 
        echo "{$post_id}, '{$nonce}'";
        ?>
, 'restore')" class="button-primary" value="<?php 
        esc_attr_e('Restore image');
        ?>
" <?php 
        echo $can_restore;
        ?>
 />
		</div>
		</div>
	</div>

<?php 
    }
    ?>

	</div>

	<div class="imgedit-group">
	<div class="imgedit-group-top">
		<strong><?php 
    _e('Image Crop');
    ?>
</strong>
		<a class="imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" href="#"><?php 
    _e('(help)');
    ?>
</a>
		<div class="imgedit-help">
		<p><?php 
    _e('The image can be cropped by clicking on it and dragging to select the desired part. While dragging the dimensions of the selection are displayed below.');
    ?>
</p>

		<p><strong><?php 
    _e('Crop Aspect Ratio');
    ?>
</strong><br />
		<?php 
    _e('You can specify the crop selection aspect ratio then hold down the Shift key while dragging to lock it. The values can be 1:1 (square), 4:3, 16:9, etc. If there is a selection, specifying aspect ratio will set it immediately.');
    ?>
</p>

		<p><strong><?php 
    _e('Crop Selection');
    ?>
</strong><br />
		<?php 
    _e('Once started, the selection can be adjusted by entering new values (in pixels). Note that these values are scaled to approximately match the original image dimensions. The minimum selection size equals the thumbnail size as set in the Media settings.');
    ?>
</p>
		</div>
	</div>

	<p>
		<?php 
    _e('Aspect ratio:');
    ?>
		<span  class="nowrap">
		<input type="text" id="imgedit-crop-width-<?php 
    echo $post_id;
    ?>
" onkeyup="imageEdit.setRatioSelection(<?php 
    echo $post_id;
    ?>
, 0, this)" style="width:3em;" />
		:
		<input type="text" id="imgedit-crop-height-<?php 
    echo $post_id;
    ?>
" onkeyup="imageEdit.setRatioSelection(<?php 
    echo $post_id;
    ?>
, 1, this)" style="width:3em;" />
		</span>
	</p>

	<p id="imgedit-crop-sel-<?php 
    echo $post_id;
    ?>
">
		<?php 
    _e('Selection:');
    ?>
		<span  class="nowrap">
		<input type="text" id="imgedit-sel-width-<?php 
    echo $post_id;
    ?>
" onkeyup="imageEdit.setNumSelection(<?php 
    echo $post_id;
    ?>
)" style="width:4em;" />
		:
		<input type="text" id="imgedit-sel-height-<?php 
    echo $post_id;
    ?>
" onkeyup="imageEdit.setNumSelection(<?php 
    echo $post_id;
    ?>
)" style="width:4em;" />
		</span>
	</p>
	</div>

	<?php 
    if ($thumb && $sub_sizes) {
        $thumb_img = wp_constrain_dimensions($thumb['width'], $thumb['height'], 160, 120);
        ?>

	<div class="imgedit-group imgedit-applyto">
	<div class="imgedit-group-top">
		<strong><?php 
        _e('Thumbnail Settings');
        ?>
</strong>
		<a class="imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" href="#"><?php 
        _e('(help)');
        ?>
</a>
		<p class="imgedit-help"><?php 
        _e('The thumbnail image can be cropped differently. For example it can be square or contain only a portion of the original image to showcase it better. Here you can select whether to apply changes to all image sizes or make the thumbnail different.');
        ?>
</p>
	</div>

	<p>
		<img src="<?php 
        echo $thumb['url'];
        ?>
" width="<?php 
        echo $thumb_img[0];
        ?>
" height="<?php 
        echo $thumb_img[1];
        ?>
" class="imgedit-size-preview" alt="" /><br /><?php 
        _e('Current thumbnail');
        ?>
	</p>

	<p id="imgedit-save-target-<?php 
        echo $post_id;
        ?>
">
		<strong><?php 
        _e('Apply changes to:');
        ?>
</strong><br />

		<label class="imgedit-label">
		<input type="radio" name="imgedit-target-<?php 
        echo $post_id;
        ?>
" value="all" checked="checked" />
		<?php 
        _e('All image sizes');
        ?>
</label>

		<label class="imgedit-label">
		<input type="radio" name="imgedit-target-<?php 
        echo $post_id;
        ?>
" value="thumbnail" />
		<?php 
        _e('Thumbnail');
        ?>
</label>

		<label class="imgedit-label">
		<input type="radio" name="imgedit-target-<?php 
        echo $post_id;
        ?>
" value="nothumb" />
		<?php 
        _e('All sizes except thumbnail');
        ?>
</label>
	</p>
	</div>

	<?php 
    }
    ?>

	</td></tr>
	</tbody></table>
	<div class="imgedit-wait" id="imgedit-wait-<?php 
    echo $post_id;
    ?>
"></div>
	<script type="text/javascript">jQuery( function() { imageEdit.init(<?php 
    echo $post_id;
    ?>
); });</script>
	<div class="hidden" id="imgedit-leaving-<?php 
    echo $post_id;
    ?>
"><?php 
    _e("There are unsaved changes that will be lost. 'OK' to continue, 'Cancel' to return to the Image Editor.");
    ?>
</div>
	</div>
<?php 
}
 /**
  * @ticket 39231
  */
 public function test_fallback_intermediate_image_sizes()
 {
     if (!wp_image_editor_supports(array('mime_type' => 'application/pdf'))) {
         $this->markTestSkipped('Rendering PDFs is not supported on this system.');
     }
     $orig_file = DIR_TESTDATA . '/images/wordpress-gsoc-flyer.pdf';
     $test_file = '/tmp/wordpress-gsoc-flyer.pdf';
     copy($orig_file, $test_file);
     $attachment_id = $this->factory->attachment->create_object($test_file, 0, array('post_mime_type' => 'application/pdf'));
     $this->assertNotEmpty($attachment_id);
     add_image_size('test-size', 100, 100);
     add_filter('fallback_intermediate_image_sizes', array($this, 'filter_fallback_intermediate_image_sizes'), 10, 2);
     $expected = array('file' => 'wordpress-gsoc-flyer-77x100.jpg', 'width' => 77, 'height' => 100, 'mime-type' => 'image/jpeg');
     $metadata = wp_generate_attachment_metadata($attachment_id, $test_file);
     $this->assertTrue(isset($metadata['sizes']['test-size']), 'The `test-size` was not added to the metadata.');
     $this->assertSame($metadata['sizes']['test-size'], $expected);
     remove_image_size('test-size');
     remove_filter('fallback_intermediate_image_sizes', array($this, 'filter_fallback_intermediate_image_sizes'), 10);
     unlink($test_file);
 }
Esempio n. 11
0
 function bfi_wp_image_editor_check()
 {
     $arg = array('mime_type' => 'image/jpeg');
     if (wp_image_editor_supports($arg) !== true) {
         add_filter('admin_notices', 'bfi_wp_image_editor_check_notice');
     }
 }
Esempio n. 12
0
/**
 * Displays the image and editor in the post editor
 *
 * @since 3.5.0
 */
function edit_form_image_editor()
{
    $post = get_post();
    $open = isset($_GET['image-editor']);
    if ($open) {
        require_once ABSPATH . 'wp-admin/includes/image-edit.php';
    }
    $thumb_url = false;
    if ($attachment_id = intval($post->ID)) {
        $thumb_url = wp_get_attachment_image_src($attachment_id, array(900, 450), true);
    }
    $filename = esc_html(basename($post->guid));
    $title = esc_attr($post->post_title);
    $alt_text = get_post_meta($post->ID, '_wp_attachment_image_alt', true);
    $att_url = wp_get_attachment_url($post->ID);
    if (wp_attachment_is_image($post->ID)) {
        $image_edit_button = '';
        if (wp_image_editor_supports(array('mime_type' => $post->post_mime_type))) {
            $nonce = wp_create_nonce("image_editor-{$post->ID}");
            $image_edit_button = "<input type='button' id='imgedit-open-btn-{$post->ID}' onclick='imageEdit.open( {$post->ID}, \"{$nonce}\" )' class='button' value='" . esc_attr__('Edit Image') . "' /> <span class='spinner'></span>";
        }
        ?>
	<div class="wp_attachment_holder">
		<div class="imgedit-response" id="imgedit-response-<?php 
        echo $attachment_id;
        ?>
"></div>

		<div<?php 
        if ($open) {
            echo ' style="display:none"';
        }
        ?>
 class="wp_attachment_image" id="media-head-<?php 
        echo $attachment_id;
        ?>
">
			<p id="thumbnail-head-<?php 
        echo $attachment_id;
        ?>
"><img class="thumbnail" src="<?php 
        echo set_url_scheme($thumb_url[0]);
        ?>
" style="max-width:100%" alt="" /></p>
			<p><?php 
        echo $image_edit_button;
        ?>
</p>
		</div>
		<div<?php 
        if (!$open) {
            echo ' style="display:none"';
        }
        ?>
 class="image-editor" id="image-editor-<?php 
        echo $attachment_id;
        ?>
">
			<?php 
        if ($open) {
            wp_image_editor($attachment_id);
        }
        ?>
		</div>
	</div>
	<?php 
    }
    ?>

	<div class="wp_attachment_details">
		<p>
			<label for="attachment_caption"><strong><?php 
    _e('Caption');
    ?>
</strong></label><br />
			<textarea class="widefat" name="excerpt" id="attachment_caption"><?php 
    echo $post->post_excerpt;
    ?>
</textarea>
		</p>

	<?php 
    if ('image' === substr($post->post_mime_type, 0, 5)) {
        ?>
		<p>
			<label for="attachment_alt"><strong><?php 
        _e('Alternative Text');
        ?>
</strong></label><br />
			<input type="text" class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" value="<?php 
        echo esc_attr($alt_text);
        ?>
" />
		</p>
	<?php 
    }
    ?>

	<?php 
    $quicktags_settings = array('buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,spell,close');
    $editor_args = array('textarea_name' => 'content', 'textarea_rows' => 5, 'media_buttons' => false, 'tinymce' => false, 'quicktags' => $quicktags_settings);
    ?>

	<label for="content"><strong><?php 
    _e('Description');
    ?>
</strong></label>
	<?php 
    wp_editor($post->post_content, 'attachment_content', $editor_args);
    ?>

	</div>
	<?php 
    $extras = get_compat_media_markup($post->ID);
    echo $extras['item'];
    echo '<input type="hidden" id="image-edit-context" value="edit-attachment" />' . "\n";
}
 /**
  * @ticket 31050
  */
 public function test_wp_generate_attachment_metadata_pdf()
 {
     if (!wp_image_editor_supports(array('mime_type' => 'application/pdf'))) {
         $this->markTestSkipped('Rendering PDFs is not supported on this system.');
     }
     $orig_file = DIR_TESTDATA . '/images/wordpress-gsoc-flyer.pdf';
     $test_file = '/tmp/wordpress-gsoc-flyer.pdf';
     copy($orig_file, $test_file);
     $attachment_id = $this->factory->attachment->create_object($test_file, 0, array('post_mime_type' => 'application/pdf'));
     $this->assertNotEmpty($attachment_id);
     $expected = array('sizes' => array('thumbnail' => array('file' => "wordpress-gsoc-flyer-116x150.jpg", 'width' => 116, 'height' => 150, 'mime-type' => "image/jpeg"), 'medium' => array('file' => "wordpress-gsoc-flyer-232x300.jpg", 'width' => 232, 'height' => 300, 'mime-type' => "image/jpeg"), 'large' => array('file' => "wordpress-gsoc-flyer-791x1024.jpg", 'width' => 791, 'height' => 1024, 'mime-type' => "image/jpeg"), 'full' => array('file' => "wordpress-gsoc-flyer.jpg", 'width' => 1088, 'height' => 1408, 'mime-type' => "image/jpeg")));
     $metadata = wp_generate_attachment_metadata($attachment_id, $test_file);
     $this->assertSame($expected, $metadata);
     unlink($test_file);
 }
    /**
     * The main Regenerate Thumbnails interface, as displayed at Tools → Regen. Thumbnails.
     */
    public function regenerate_interface()
    {
        if (!current_user_can($this->capability)) {
            wp_die(__('Cheatin&#8217; uh?'));
        }
        // This is a container for the results message that gets shown using JavaScript
        echo '<div id="message" class="updated" style="display:none"></div>' . "\n";
        // Just an overall wrapper, used to help style
        echo '<div class="wrap regenthumbs">' . "\n";
        echo '<h1>' . __('Regenerate Thumbnails', 'regenerate-thumbnails') . "</h1>\n";
        // Make sure image editing is supported
        if (!wp_image_editor_supports()) {
            echo '<p>' . __("Sorry but your server doesn't support image editing which means that WordPress can't create thumbnails. Please ask your host to install the Imagick or GD PHP extensions.", 'regenerate-thumbnails') . '</p>';
        } elseif (empty($_POST['regenerate-thumbnails']) && empty($_REQUEST['ids'])) {
            $this->regenerate_interface_introduction();
        } else {
            $this->regenerate_interface_process();
        }
        echo '</div>';
        // end "wrap regenthumbs"
        return;
        ## Old page is below for reference while rewriting it above
        global $wpdb;
        ?>

		<div id="message" class="updated fade" style="display:none"></div>

		<div class="wrap regenthumbs">
			<h2><?php 
        _e('Regenerate Thumbnails', 'regenerate-thumbnails');
        ?>
</h2>

			<?php 
        // If the button was clicked
        if (!empty($_POST['regenerate-thumbnails']) || !empty($_REQUEST['ids'])) {
            // Capability check
            if (!current_user_can($this->capability)) {
                wp_die(__('Cheatin&#8217; uh?'));
            }
            // Create the list of image IDs
            if (!empty($_REQUEST['ids'])) {
                $images = array_map('intval', explode(',', trim($_REQUEST['ids'], ',')));
                $ids = implode(',', $images);
                // Form nonce check
                check_admin_referer($this->create_nonce_name($images));
            } else {
                check_admin_referer('regenerate-thumbnails');
                // Directly querying the database is normally frowned upon, but all
                // of the API functions will return the full post objects which will
                // suck up lots of memory. This is best, just not as future proof.
                if (!($images = $wpdb->get_results("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%' ORDER BY ID DESC"))) {
                    echo '	<p>' . sprintf(__("Unable to find any images. Are you sure <a href='%s'>some exist</a>?", 'regenerate-thumbnails'), esc_url(admin_url('upload.php?post_mime_type=image'))) . "</p></div>";
                    return;
                }
                // Generate the list of IDs
                $ids = array();
                foreach ($images as $image) {
                    $ids[] = $image->ID;
                }
                $ids = implode(',', $ids);
            }
            echo '	<p>' . __("Please be patient while the thumbnails are regenerated. This can take a while if your server is slow (inexpensive hosting) or if you have many images. Do not navigate away from this page until this script is done or the thumbnails will not be resized. You will be notified via this page when the regenerating is completed.", 'regenerate-thumbnails') . '</p>';
            $count = count($images);
            $text_goback = !empty($_GET['goback']) ? sprintf(__('To go back to the previous page, <a href="%s">click here</a>.', 'regenerate-thumbnails'), 'javascript:history.go(-1)') : '';
            $text_failures = sprintf(__('All done! %1$s image(s) were successfully resized in %2$s seconds and there were %3$s failure(s). To try regenerating the failed images again, <a href="%4$s">click here</a>. %5$s', 'regenerate-thumbnails'), "' + rt_successes + '", "' + rt_totaltime + '", "' + rt_errors + '", esc_url(wp_nonce_url(admin_url('tools.php?page=regenerate-thumbnails&goback=1'), 'regenerate-thumbnails') . '&ids=') . "' + rt_failedlist + '", $text_goback);
            $text_nofailures = sprintf(__('All done! %1$s image(s) were successfully resized in %2$s seconds and there were 0 failures. %3$s', 'regenerate-thumbnails'), "' + rt_successes + '", "' + rt_totaltime + '", $text_goback);
            ?>


				<noscript><p><em><?php 
            _e('You must enable Javascript in order to proceed!', 'regenerate-thumbnails');
            ?>
</em></p></noscript>

				<div id="regenthumbs-bar" style="position:relative;height:25px;">
					<div id="regenthumbs-bar-percent" style="position:absolute;left:50%;top:50%;width:300px;margin-left:-150px;height:25px;margin-top:-9px;font-weight:bold;text-align:center;"></div>
				</div>

				<p><input type="button" class="button hide-if-no-js" name="regenthumbs-stop" id="regenthumbs-stop" value="<?php 
            _e('Abort Resizing Images', 'regenerate-thumbnails');
            ?>
" /></p>

				<h3 class="title"><?php 
            _e('Debugging Information', 'regenerate-thumbnails');
            ?>
</h3>

				<p>
					<?php 
            printf(__('Total Images: %s', 'regenerate-thumbnails'), $count);
            ?>
<br />
					<?php 
            printf(__('Images Resized: %s', 'regenerate-thumbnails'), '<span id="regenthumbs-debug-successcount">0</span>');
            ?>
<br />
					<?php 
            printf(__('Resize Failures: %s', 'regenerate-thumbnails'), '<span id="regenthumbs-debug-failurecount">0</span>');
            ?>
				</p>

				<ol id="regenthumbs-debuglist">
					<li style="display:none"></li>
				</ol>

				<script type="text/javascript">
					jQuery(document).ready(function ($) {
						var i;
						var rt_images = [<?php 
            echo $ids;
            ?>
];
						var rt_total = rt_images.length;
						var rt_count = 1;
						var rt_percent = 0;
						var rt_successes = 0;
						var rt_errors = 0;
						var rt_failedlist = '';
						var rt_resulttext = '';
						var rt_timestart = new Date().getTime();
						var rt_timeend = 0;
						var rt_totaltime = 0;
						var rt_continue = true;

						// Create the progress bar
						$("#regenthumbs-bar").progressbar();
						$("#regenthumbs-bar-percent").html("0%");

						// Stop button
						$("#regenthumbs-stop").click(function () {
							rt_continue = false;
							$('#regenthumbs-stop').val("<?php 
            echo $this->esc_quotes(__('Stopping...', 'regenerate-thumbnails'));
            ?>
");
						});

						// Clear out the empty list element that's there for HTML validation purposes
						$("#regenthumbs-debuglist li").remove();

						// Called after each resize. Updates debug information and the progress bar.
						function RegenThumbsUpdateStatus(id, success, response) {
							$("#regenthumbs-bar").progressbar("value", ( rt_count / rt_total ) * 100);
							$("#regenthumbs-bar-percent").html(Math.round(( rt_count / rt_total ) * 1000) / 10 + "%");
							rt_count = rt_count + 1;

							if (success) {
								rt_successes = rt_successes + 1;
								$("#regenthumbs-debug-successcount").html(rt_successes);
								$("#regenthumbs-debuglist").append("<li>" + response.success + "</li>");
							}
							else {
								rt_errors = rt_errors + 1;
								rt_failedlist = rt_failedlist + ',' + id;
								$("#regenthumbs-debug-failurecount").html(rt_errors);
								$("#regenthumbs-debuglist").append("<li>" + response.error + "</li>");
							}
						}

						// Called when all images have been processed. Shows the results and cleans up.
						function RegenThumbsFinishUp() {
							rt_timeend = new Date().getTime();
							rt_totaltime = Math.round(( rt_timeend - rt_timestart ) / 1000);

							$('#regenthumbs-stop').hide();

							if (rt_errors > 0) {
								rt_resulttext = '<?php 
            echo $text_failures;
            ?>
';
							} else {
								rt_resulttext = '<?php 
            echo $text_nofailures;
            ?>
';
							}

							$("#message").html("<p><strong>" + rt_resulttext + "</strong></p>");
							$("#message").show();
						}

						// Regenerate a specified image via AJAX
						function RegenThumbs(id) {
							$.ajax({
								type   : 'POST',
								url    : ajaxurl,
								data   : {action: "regeneratethumbnail", id: id},
								success: function (response) {
									if (response === null) {
										response = new Object;
										response.success = false;
										response.error = "The resize request was abnormally terminated (ID " + id + "). This is likely due to the image exceeding available memory.";
									}

									if (response.success) {
										RegenThumbsUpdateStatus(id, true, response);
									}
									else {
										RegenThumbsUpdateStatus(id, false, response);
									}

									if (rt_images.length && rt_continue) {
										RegenThumbs(rt_images.shift());
									}
									else {
										RegenThumbsFinishUp();
									}
								},
								error  : function (response) {
									RegenThumbsUpdateStatus(id, false, response);

									if (rt_images.length && rt_continue) {
										RegenThumbs(rt_images.shift());
									}
									else {
										RegenThumbsFinishUp();
									}
								}
							});
						}

						RegenThumbs(rt_images.shift());
					});
				</script>
			<?php 
        } else {
            ?>
				<form method="post" action="">
					<?php 
            wp_nonce_field('regenerate-thumbnails');
            ?>

					<p><?php 
            printf(__("Use this tool to regenerate thumbnails for all images that you have uploaded to your site. This is useful if you've changed any of the thumbnail dimensions on the <a href='%s'>media settings page</a> or switched themes. Old thumbnails will be kept to avoid any broken images due to hard-coded URLs.", 'regenerate-thumbnails'), esc_url(admin_url('options-media.php')));
            ?>
</p>

					<p><?php 
            printf(__("You can regenerate specific images (rather than all images) from the <a href='%s'>Media</a> page. Hover over an image's row and click the link to resize just that one image or use the checkboxes and the &quot;Bulk Actions&quot; dropdown to resize multiple images (WordPress 3.1+ only).", 'regenerate-thumbnails'), esc_url(admin_url('upload.php')));
            ?>
</p>

					<p><?php 
            _e("Thumbnail regeneration is not reversible, but you can just change your thumbnail dimensions back to the old values and click the button again if you don't like the results.", 'regenerate-thumbnails');
            ?>
</p>

					<p><?php 
            _e('To begin, just press the button below.', 'regenerate-thumbnails');
            ?>
</p>

					<p><input type="submit" class="button hide-if-no-js" name="regenerate-thumbnails" id="regenerate-thumbnails" value="<?php 
            _e('Regenerate All Thumbnails', 'regenerate-thumbnails');
            ?>
" /></p>

					<noscript><p><em><?php 
            _e('You must enable Javascript in order to proceed!', 'regenerate-thumbnails');
            ?>
</em></p></noscript>

				</form>
			<?php 
        }
        // End if button
        ?>
		</div>

	<?php 
    }
 /**
  * Checks if the image editor supports tiff images
  *
  * @since 1.0
  *
  * @return bool true is possible
  */
 public function is_usable()
 {
     return wp_image_editor_supports(array('mime_type' => 'image/tiff'));
 }
/**
 * Adding our custom fields to the $form_fields array
 *
 * @param array $form_fields
 * @param object $post
 * @return array
 */
function kgvid_image_attachment_fields_to_edit($form_fields, $post)
{
    $options = kgvid_get_options();
    if (substr($post->post_mime_type, 0, 5) == 'video' && (empty($post->post_parent) || strpos(get_post_mime_type($post->post_parent), 'video') === false && get_post_meta($post->ID, '_kgflashmediaplayer-externalurl', true) == '')) {
        //if the attachment is a video with no parent or if it has a parent the parent is not a video and the video doesn't have the externalurl post meta
        wp_enqueue_media();
        //allows using the media modal in the Media Library
        wp_enqueue_script('kgvid_video_plugin_admin');
        wp_enqueue_style('video_embed_thumbnail_generator_style');
        $field_id = kgvid_backwards_compatible($post->ID);
        $movieurl = wp_get_attachment_url($post->ID);
        $moviefile = get_attached_file($post->ID);
        $kgvid_postmeta = kgvid_get_attachment_meta($post->ID);
        $form_fields["kgflashmediaplayer-url"]["input"] = "hidden";
        $form_fields["kgflashmediaplayer-url"]["value"] = $movieurl;
        $video_aspect = NULL;
        $dimensions_saved = false;
        $video_meta = wp_get_attachment_metadata($post->ID);
        if (is_array($video_meta) && array_key_exists('width', $video_meta) && array_key_exists('height', $video_meta)) {
            $video_aspect = $video_meta['height'] / $video_meta['width'];
        }
        if (!empty($kgvid_postmeta['width']) && !empty($kgvid_postmeta['height'])) {
            if (empty($video_aspect)) {
                $video_aspect = $kgvid_postmeta['height'] / $kgvid_postmeta['width'];
            }
            $dimensions_saved = true;
        }
        $dimension_words = array('width', 'height');
        $max = array();
        $set = array();
        foreach ($dimension_words as $dimension) {
            $max[$dimension] = $options[$dimension];
            if ($dimensions_saved) {
                $set[$dimension] = $kgvid_postmeta[$dimension];
            } elseif ($dimension == 'width' && $options['minimum_width'] == "on") {
                $set[$dimension] = $max[$dimension];
            } else {
                if (is_array($video_meta) && array_key_exists($dimension, $video_meta) && intval($video_meta[$dimension]) <= intval($max[$dimension])) {
                    $set[$dimension] = $video_meta[$dimension];
                } else {
                    $set[$dimension] = $max[$dimension];
                }
            }
            if (!$dimensions_saved) {
                $kgvid_postmeta[$dimension] = $set[$dimension];
            }
            $form_fields["kgflashmediaplayer-max" . $dimension]["input"] = "hidden";
            $form_fields["kgflashmediaplayer-max" . $dimension]["value"] = $max[$dimension];
        }
        $form_fields["kgflashmediaplayer-aspect"]["input"] = "hidden";
        $form_fields["kgflashmediaplayer-aspect"]["value"] = round($set['height'] / $set['width'], 5);
        $nonce = wp_create_nonce('video-embed-thumbnail-generator-nonce');
        $form_fields["views"]["label"] = __('Video Stats', 'video-embed-thumbnail-generator');
        $form_fields["views"]["input"] = "html";
        $form_fields["views"]["html"] = sprintf(_n('%d Start', '%d Starts', intval($kgvid_postmeta['starts']), 'video-embed-thumbnail-generator'), intval($kgvid_postmeta['starts'])) . ', ' . sprintf(_n('%d Complete View', '%d Complete Views', intval($kgvid_postmeta['completeviews']), 'video-embed-thumbnail-generator'), intval($kgvid_postmeta['completeviews'])) . '<br />' . __('Video ID:', 'video-embed-thumbnail-generator') . ' ' . $post->ID;
        // ** Thumbnail section **//
        $thumbnail_url = get_post_meta($post->ID, "_kgflashmediaplayer-poster", true);
        $thumbnail_html = "";
        if (!empty($kgvid_postmeta['autothumb-error'])) {
            $thumbnail_html = '<div class="kgvid_thumbnail_box kgvid_chosen_thumbnail_box">' . $kgvid_postmeta['autothumb-error'] . '</div>';
        } elseif ($thumbnail_url != "") {
            $thumbnail_html = '<div class="kgvid_thumbnail_box kgvid_chosen_thumbnail_box"><img width="200" src="' . $thumbnail_url . '"></div>';
        }
        if (current_user_can('make_video_thumbnails')) {
            if (!empty($kgvid_postmeta['thumbtime'])) {
                $kgvid_postmeta['numberofthumbs'] = "1";
            }
            $args = array('mime_type' => 'image/jpeg', 'methods' => array('save'));
            $img_editor_works = wp_image_editor_supports($args);
            if (!isset($options['ffmpeg_exists']) || $options['ffmpeg_exists'] == "notchecked") {
                kgvid_check_ffmpeg_exists($options, true);
            }
            if ($options['ffmpeg_exists'] == "notinstalled") {
                $ffmpeg_disabled_text = 'disabled="disabled" title="' . sprintf(__('%1$s not found at %2$s and unable to load video in browser for thumbnail generation.', 'video-embed-thumbnail-generator'), strtoupper($options['video_app']), $options['app_path']) . '"';
            } else {
                $ffmpeg_disabled_text = "";
            }
            $update_script = "";
            $created_time = time() - get_post_time('U', true, $post->ID);
            if ($created_time < 60 && ($options['auto_encode'] == "on" || $options['auto_thumb'] == "on")) {
                $update_script = '<script type="text/javascript">jQuery(document).ready(function() { ';
                if ($options['ffmpeg_exists'] == "on" && $options['auto_encode'] == "on") {
                    $update_script .= 'percent_timeout = setTimeout(function(){ kgvid_redraw_encode_checkboxes("' . $movieurl . '", "' . $post->ID . '", "attachment") }, 5000); jQuery(\'#wpwrap\').data("KGVIDCheckboxTimeout", percent_timeout);';
                }
                if ($options['ffmpeg_exists'] == "on" && $options['auto_thumb'] == "on" && !$thumbnail_url) {
                    $thumbnail_html = '<div class="kgvid_thumbnail_box kgvid_chosen_thumbnail_box" style="height:112px;"><span style="margin-top: 45px;
	display: inline-block;">Loading thumbnail...</span></div>';
                    $update_script .= ' setTimeout(function(){ kgvid_redraw_thumbnail_box("' . $post->ID . '") }, 5000);';
                }
                $update_script .= '});</script>';
            }
            $choose_from_video_content = "";
            $generate_content = "";
            $thumbnail_timecode = "";
            $moviefiletype = pathinfo($movieurl, PATHINFO_EXTENSION);
            $h264compatible = array("mp4", "mov", "m4v");
            if ($moviefiletype == "mov" || $moviefiletype == "m4v") {
                $moviefiletype = "mp4";
            }
            $video_formats = kgvid_video_formats();
            $encodevideo_info = kgvid_encodevideo_info($movieurl, $post->ID);
            if (in_array($moviefiletype, $h264compatible)) {
                $encodevideo_info["original"]["exists"] = true;
                $encodevideo_info["original"]["url"] = $movieurl;
                $video_formats = array("original" => array("mime" => "video/" . $moviefiletype)) + $video_formats;
            } else {
                $encodevideo_info["original"]["exists"] = false;
            }
            $sources = array();
            foreach ($video_formats as $format => $format_stats) {
                if ($format != "original" && $encodevideo_info[$format]["url"] == $movieurl) {
                    unset($sources['original']);
                }
                if ($encodevideo_info[$format]["exists"]) {
                    $sources[$format] = '<source src="' . $encodevideo_info[$format]["url"] . '" type="' . $format_stats["mime"] . '">';
                }
            }
            if ($img_editor_works) {
                $choose_from_video_content = '<div style="display:none;" class="kgvid_thumbnail_box kgvid-tabs-content" id="thumb-video-' . $post->ID . '-container">
					<div class="kgvid-reveal-thumb-video" onclick="kgvid_reveal_thumb_video(' . $post->ID . ')" id="show-thumb-video-' . $post->ID . '"><span class="kgvid-right-arrow"></span><span class="kgvid-show-video">' . __('Choose from video...', 'video-embed-thumbnail-generator') . '</span></div>
					<div style="display:none;" id="thumb-video-' . $post->ID . '-player">
						<video crossorigin="anonymous" preload="metadata" class="kgvid-thumb-video" width="200" data-allowed="' . $options['browser_thumbnails'] . '" onloadedmetadata="kgvid_thumb_video_loaded(\'' . $post->ID . '\');" id="thumb-video-' . $post->ID . '" controls>' . implode("\n", $sources) . '
						</video>
						<div class="kgvid-video-controls">
							<div class="kgvid-play-pause"></div>
							<div class="kgvid-seek-bar">
								<div class="kgvid-play-progress"></div>
								<div class="kgvid-seek-handle"></div></div>
						</div>
						<span id="manual-thumbnail" class="button-secondary" onclick="kgvid_thumb_video_manual(' . $post->ID . ');">Use this frame</span>
					</div>
				</div>';
            }
            $generate_content = '<div id="generate-thumb-' . $post->ID . '-container" class="kgvid-tabs-content">
			<input id="attachments-' . $post->ID . '-kgflashmediaplayer-numberofthumbs" name="attachments[' . $post->ID . '][kgflashmediaplayer-numberofthumbs]" type="text" value="' . $kgvid_postmeta['numberofthumbs'] . '" maxlength="2" style="width:35px;text-align:center;" onchange="kgvid_disable_thumb_buttons(\'' . $post->ID . '\', \'onchange\');document.getElementById(\'' . $field_id['thumbtime'] . '\').value =\'\';" ' . $ffmpeg_disabled_text . '/>
			<input type="button" id="attachments-' . $post->ID . '-thumbgenerate" class="button-secondary" value="' . _x('Generate', 'Button text. Implied "Generate thumbnails"', 'video-embed-thumbnail-generator') . '" name="thumbgenerate" onclick="kgvid_generate_thumb(' . $post->ID . ', \'generate\');" ' . $ffmpeg_disabled_text . '/>
			<input type="button" id="attachments-' . $post->ID . '-thumbrandomize" class="button-secondary" value="' . _x('Randomize', 'Button text. Implied "Randomize thumbnail generation"', 'video-embed-thumbnail-generator') . '" name="thumbrandomize" onclick="kgvid_generate_thumb(' . $post->ID . ', \'random\');" ' . $ffmpeg_disabled_text . '/>
			<span style="white-space:nowrap;"><input type="checkbox" id="attachments-' . $post->ID . '-firstframe" name="attachments[' . $post->ID . '][kgflashmediaplayer-forcefirst]" onchange="document.getElementById(\'' . $field_id['thumbtime'] . '\').value =\'\';" ' . checked($kgvid_postmeta['forcefirst'], 'on', false) . ' ' . $ffmpeg_disabled_text . '/> <label for="attachments-' . $post->ID . '-firstframe">' . __('Force 1st frame thumbnail', 'video-embed-thumbnail-generator') . '</label></span></div>';
            $thumbnail_timecode = __('Thumbnail timecode:', 'video-embed-thumbnail-generator') . ' <input name="attachments[' . $post->ID . '][kgflashmediaplayer-thumbtime]" id="attachments-' . $post->ID . '-kgflashmediaplayer-thumbtime" type="text" value="' . $kgvid_postmeta['thumbtime'] . '" style="width:60px;"><br>';
        }
        $form_fields["kgflashmediaplayer-autothumb-error"]["input"] = "hidden";
        $form_fields["kgflashmediaplayer-autothumb-error"]["value"] = $kgvid_postmeta['autothumb-error'];
        $form_fields["generator"]["label"] = _x("Thumbnails", 'Header for thumbnail section', 'video-embed-thumbnail-generator');
        $form_fields["generator"]["input"] = "html";
        $form_fields["generator"]["html"] = '<input type="hidden" name="attachments[' . $post->ID . '][kgflashmediaplayer-security]" id="attachments-' . $post->ID . '-kgflashmediaplayer-security" value="' . $nonce . '" />
		' . $choose_from_video_content . '
		' . $generate_content . '
		' . $thumbnail_timecode . '
		<div id="attachments-' . $post->ID . '-thumbnailplaceholder" style="position:relative;">' . $thumbnail_html . '</div>
		<span id="pick-thumbnail" class="button-secondary" style="margin:10px 0;" data-choose="' . __('Choose a Thumbnail', 'video-embed-thumbnail-generator') . '" data-update="' . __('Set as video thumbnail', 'video-embed-thumbnail-generator') . '" data-change="attachments-' . $post->ID . '-kgflashmediaplayer-poster" onclick="kgvid_pick_image(this);">' . __('Choose from Library', 'video-embed-thumbnail-generator') . '</span><br />
		<input type="checkbox" id="attachments-' . $post->ID . '-featured" name="attachments[' . $post->ID . '][kgflashmediaplayer-featured]" ' . checked($kgvid_postmeta['featured'], 'on', false) . ' ' . $ffmpeg_disabled_text . '/> <label for="attachments-' . $post->ID . '-featured">' . __('Set thumbnail as featured image', 'video-embed-thumbnail-generator') . '</label>' . $update_script;
        $form_fields["kgflashmediaplayer-poster"]["label"] = __("Thumbnail URL", 'video-embed-thumbnail-generator');
        $form_fields["kgflashmediaplayer-poster"]["value"] = get_post_meta($post->ID, "_kgflashmediaplayer-poster", true);
        $form_fields["kgflashmediaplayer-poster"]["helps"] = "<small>" . sprintf(__('Leave blank to use %sdefault thumbnail', 'video-embed-thumbnail-generator'), "<a href='options-general.php?page=video-embed-thumbnail-generator/video-embed-thumbnail-generator.php' target='_blank'>") . "</a>.</small>";
        $form_fields["kgflashmediaplayer-dimensions"]["label"] = __("Video Embed Dimensions", 'video-embed-thumbnail-generator');
        $form_fields["kgflashmediaplayer-dimensions"]["input"] = "html";
        $form_fields["kgflashmediaplayer-dimensions"]["html"] = __('Width:', 'video-embed-thumbnail-generator') . ' <input name="attachments[' . $post->ID . '][kgflashmediaplayer-width]" id="attachments-' . $post->ID . '-kgflashmediaplayer-width" type="text" value="' . $kgvid_postmeta['width'] . '" style="width:50px;" data-minimum="' . $options['minimum_width'] . '" onchange="kgvid_set_dimension(' . $post->ID . ', \'height\', this.value);" onkeyup="kgvid_set_dimension(' . $post->ID . ', \'height\', this.value);"> ' . __('Height:', 'video-embed-thumbnail-generator') . '
		<input name="attachments[' . $post->ID . '][kgflashmediaplayer-height]" id="attachments-' . $post->ID . '-kgflashmediaplayer-height" type="text" value="' . $kgvid_postmeta['height'] . '" style="width:50px;" onchange="kgvid_set_dimension(' . $post->ID . ', \'width\', this.value);" onkeyup="kgvid_set_dimension(' . $post->ID . ', \'width\', this.value);"> <br />
		<input type="checkbox" name="attachments[' . $post->ID . '][kgflashmediaplayer-lockaspect]" id="attachments-' . $post->ID . '-kgflashmediaplayer-lockaspect" onclick="kgvid_set_aspect(' . $post->ID . ', this.checked);" ' . checked($kgvid_postmeta['lockaspect'], 'on', false) . '>
		<label for="attachments-' . $post->ID . '-kgflashmediaplayer-lockaspect"><small>' . __('Lock to aspect ratio', 'video-embed-thumbnail-generator') . '</small></label>';
        $form_fields["kgflashmediaplayer-dimensions"]["helps"] = "<small>" . sprintf(__('Leave blank to use %sdefault dimensions', 'video-embed-thumbnail-generator'), "<a href='options-general.php?page=video-embed-thumbnail-generator/video-embed-thumbnail-generator.php' target='_blank'>") . "</a>.</small>";
        $checkboxes = kgvid_generate_encode_checkboxes($movieurl, $post->ID, "attachment");
        $form_fields["kgflashmediaplayer-encode"]["label"] = __("Additional Formats", 'video-embed-thumbnail-generator');
        $form_fields["kgflashmediaplayer-encode"]["input"] = "html";
        $form_fields["kgflashmediaplayer-encode"]["html"] = $checkboxes['checkboxes'];
        $tracks_html = '';
        if (is_array($kgvid_postmeta['track'])) {
            foreach ($kgvid_postmeta['track'] as $track => $track_attribute) {
                $items = array(__("subtitles", 'video-embed-thumbnail-generator') => "subtitles", __("captions", 'video-embed-thumbnail-generator') => "captions", __("chapters", 'video-embed-thumbnail-generator') => "chapters");
                $track_type_select = '<select name="attachments[' . $post->ID . '][kgflashmediaplayer-track][' . $track . '][kind]" id="attachments-' . $post->ID . '-kgflashmediaplayer-track_' . $track . '_kind]">';
                foreach ($items as $name => $value) {
                    $selected = $kgvid_postmeta['track'][$track]['kind'] == $value ? 'selected="selected"' : '';
                    $track_type_select .= "<option value='{$value}'>{$name}</option>";
                }
                $track_type_select .= "</select>";
                if (!array_key_exists('default', $kgvid_postmeta['track'][$track])) {
                    $kgvid_postmeta['track'][$track]['default'] = false;
                }
                $tracks_html .= '<div id="kgflashmediaplayer-' . $post->ID . '-trackdiv-' . $track . '" class="kgvid_thumbnail_box kgvid_track_box"><strong>' . _x('Track', 'captions track', 'video-embed-thumbnail-generator') . ' ' . strval($track + 1) . '</strong><span class="kgvid_track_box_removeable" onclick="jQuery(this).parent().remove();jQuery(\'form.compat-item input\').first().change();">X</span><br />
				' . __('Track type:', 'video-embed-thumbnail-generator') . ' ' . $track_type_select . '<br />
				<span id="pick-track' . $track . '" class="button-secondary" style="margin:10px 0;" data-choose="' . __('Choose a Text File', 'video-embed-thumbnail-generator') . '" data-update="' . __('Set as track source', 'video-embed-thumbnail-generator') . '" data-change="attachments-' . $post->ID . '-kgflashmediaplayer-track_' . $track . '_src" onclick="kgvid_pick_attachment(this);">' . __('Choose from Library', 'video-embed-thumbnail-generator') . '</span><br />
				URL: <input name="attachments[' . $post->ID . '][kgflashmediaplayer-track][' . $track . '][src]" id="attachments-' . $post->ID . '-kgflashmediaplayer-track_' . $track . '_src" type="text" value="' . $kgvid_postmeta['track'][$track]['src'] . '" class="text" style="width:180px;"><br />
				' . _x('Language code:', 'two-letter code indicating track\'s language', 'video-embed-thumbnail-generator') . ' <input name="attachments[' . $post->ID . '][kgflashmediaplayer-track][' . $track . '][srclang]" id="attachments-' . $post->ID . '-kgflashmediaplayer-track_' . $track . '_srclang" type="text" value="' . $kgvid_postmeta['track'][$track]['srclang'] . '" maxlength="2" style="width:40px;"><br />
				' . __('Label:', 'video-embed-thumbnail-generator') . ' <input name="attachments[' . $post->ID . '][kgflashmediaplayer-track][' . $track . '][label]" id="attachments-' . $post->ID . '-kgflashmediaplayer-track_' . $track . '_label" type="text" value="' . $kgvid_postmeta['track'][$track]['label'] . '" class="text" style="width:172px;"><br />
				' . __('Default:', 'video-embed-thumbnail-generator') . '<input ' . checked($kgvid_postmeta['track'][$track]['default'], 'default', false) . ' name="attachments[' . $post->ID . '][kgflashmediaplayer-track][' . $track . '][default]" id="attachments-' . $post->ID . '-kgflashmediaplayer-track_' . $track . '_default" type="checkbox" value="default"></div>';
            }
        }
        $form_fields["kgflashmediaplayer-track"]["label"] = __("Subtitles & Captions", 'video-embed-thumbnail-generator');
        $form_fields["kgflashmediaplayer-track"]["input"] = "html";
        $form_fields["kgflashmediaplayer-track"]["html"] = '<div id="kgflashmediaplayer-' . $post->ID . '-trackdiv">' . $tracks_html . '</div><span class="button-secondary" id="kgflashmediaplayer-add_track" onclick="kgvid_add_subtitles(' . $post->ID . ')">' . __('Add track', 'video-embed-thumbnail-generator') . '</span>';
        $items = array(__("Single Video", 'video-embed-thumbnail-generator') => "Single Video", __("Video Gallery", 'video-embed-thumbnail-generator') => "Video Gallery", __("WordPress Default", 'video-embed-thumbnail-generator') => "WordPress Default");
        $shortcode_select = '<select name="attachments[' . $post->ID . '][kgflashmediaplayer-embed]" id="attachments[' . $post->ID . '][kgflashmediaplayer-embed]">';
        foreach ($items as $name => $value) {
            $selected = $kgvid_postmeta['embed'] == $value ? 'selected="selected"' : '';
            $shortcode_select .= "<option value='{$value}' {$selected}>{$name}</option>";
        }
        $shortcode_select .= "</select>";
        $form_fields["kgflashmediaplayer-options"]["label"] = __("Video Embed Options", 'video-embed-thumbnail-generator');
        $form_fields["kgflashmediaplayer-options"]["input"] = "html";
        $form_fields["kgflashmediaplayer-options"]["html"] = '<input type="checkbox" name="attachments[' . $post->ID . '][kgflashmediaplayer-showtitle]" id="attachments-' . $post->ID . '-kgflashmediaplayer-showtitle" ' . checked($kgvid_postmeta['showtitle'], 'on', false) . '>
		<label for="attachments-' . $post->ID . '-kgflashmediaplayer-showtitle">' . __('Insert title above video', 'video-embed-thumbnail-generator') . '</label><br />
		<input type="checkbox" name="attachments[' . $post->ID . '][kgflashmediaplayer-downloadlink]" id="attachments-' . $post->ID . '-kgflashmediaplayer-downloadlink" ' . checked($kgvid_postmeta['downloadlink'], 'on', false) . '>
		<label for="attachments-' . $post->ID . '-kgflashmediaplayer-downloadlink">' . __('Insert download link below video', 'video-embed-thumbnail-generator') . '<em><small><br />' . __('Makes it easier for users to download file.', 'video-embed-thumbnail-generator') . '</em></small></label><br />
		<label for="attachments-' . $post->ID . '-kgflashmediaplayer-embed">' . _x('Insert', 'verb', 'video-embed-thumbnail-generator') . '</label>
		' . $shortcode_select . '
		<script type="text/javascript">jQuery(document).ready(function(){kgvid_hide_standard_wordpress_display_settings(' . $post->ID . ');});</script>';
        if ($kgvid_postmeta['embed'] == "Video Gallery") {
            if (empty($kgvid_postmeta['gallery_id'])) {
                $kgvid_postmeta['gallery_id'] = $post->post_parent;
            }
            $items = array("menu_order", "title", "post_date", "rand", "ID");
            $gallery_orderby_select = '<select name="attachments[' . $post->ID . '][kgflashmediaplayer-gallery_orderby]" id="attachments-' . $post->ID . '-kgflashmediaplayer-gallery_orderby">';
            foreach ($items as $item) {
                $selected = $kgvid_postmeta['gallery_orderby'] == $item ? 'selected="selected"' : '';
                $gallery_orderby_select .= "<option value='{$item}' {$selected}>{$item}</option>";
            }
            $gallery_orderby_select .= "</select>";
            $items = array("ASC", "DESC");
            $gallery_order_select = '<select name="attachments[' . $post->ID . '][kgflashmediaplayer-gallery_order]" id="attachments-' . $post->ID . '-kgflashmediaplayer-gallery_order">';
            foreach ($items as $item) {
                $selected = $kgvid_postmeta['gallery_order'] == $item ? 'selected="selected"' : '';
                $gallery_order_select .= "<option value='{$item}' {$selected}>{$item}</option>";
            }
            $gallery_order_select .= "</select>";
            $form_fields["kgflashmediaplayer-gallery"]["label"] = __("Gallery Settings (all optional)", 'video-embed-thumbnail-generator');
            $form_fields["kgflashmediaplayer-gallery"]["input"] = "html";
            $form_fields["kgflashmediaplayer-gallery"]["html"] = '<input name="attachments[' . $post->ID . '][kgflashmediaplayer-gallery_thumb_width]" id="attachments-' . $post->ID . '-kgflashmediaplayer-gallery_thumb_width" type ="text" value="' . $kgvid_postmeta['gallery_thumb_width'] . '" class="kgvid_50_width"> <label for="attachments-' . $post->ID . '-kgflashmediaplayer-gallery_thumb_width">' . __('Thumbnail Width', 'video-embed-thumbnail-generator') . '</label><br />
			' . $gallery_orderby_select . ' ' . __('Order By', 'video-embed-thumbnail-generator') . '<br />
			' . $gallery_order_select . ' ' . __('Sort Order', 'video-embed-thumbnail-generator') . '<br />
			<input name="attachments[' . $post->ID . '][kgflashmediaplayer-gallery_exclude]" id="attachments-' . $post->ID . '-kgflashmediaplayer-gallery_exclude" type ="text" value="' . $kgvid_postmeta['gallery_exclude'] . '" class="kgvid_50_width"> <label for="attachments-' . $post->ID . '-kgflashmediaplayer-gallery_exclude">' . __('Exclude', 'video-embed-thumbnail-generator') . '</label><br />
			<input name="attachments[' . $post->ID . '][kgflashmediaplayer-gallery_include]" id="attachments-' . $post->ID . '-kgflashmediaplayer-gallery_include" type ="text" value="' . $kgvid_postmeta['gallery_include'] . '" class="kgvid_50_width"> <label for="attachments-' . $post->ID . '-kgflashmediaplayer-gallery_include">' . __('Include', 'video-embed-thumbnail-generator') . '</label><br />
			<input name="attachments[' . $post->ID . '][kgflashmediaplayer-gallery_id]" id="attachments-' . $post->ID . '-kgflashmediaplayer-gallery_id" type ="text" value="' . $kgvid_postmeta['gallery_id'] . '" class="kgvid_50_width"> <label for="attachments-' . $post->ID . '-kgflashmediaplayer-gallery_id">' . __('Post ID', 'video-embed-thumbnail-generator') . '</label>
			';
        }
        //if video gallery
    }
    //only add fields if attachment is the right kind of video
    return $form_fields;
}