AlternateText.php
8 years ago
Author.php
8 years ago
AuthorName.php
8 years ago
AvailableSizes.php
8 years ago
Caption.php
8 years ago
Comments.php
8 years ago
Date.php
8 years ago
Description.php
8 years ago
Dimensions.php
8 years ago
ExifData.php
8 years ago
FileName.php
8 years ago
FileSize.php
8 years ago
FullPath.php
8 years ago
Height.php
8 years ago
ID.php
8 years ago
Meta.php
8 years ago
MetaValue.php
8 years ago
MimeType.php
8 years ago
Parent.php
8 years ago
Taxonomy.php
8 years ago
Title.php
8 years ago
Width.php
8 years ago
AvailableSizes.php
95 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * @since 2.0 |
| 9 | */ |
| 10 | class AC_Column_Media_AvailableSizes extends AC_Column_Media_MetaValue { |
| 11 | |
| 12 | public function __construct() { |
| 13 | parent::__construct(); |
| 14 | |
| 15 | $this->set_type( 'column-available_sizes' ); |
| 16 | $this->set_label( __( 'Available Sizes', 'codepress-admin-columns' ) ); |
| 17 | } |
| 18 | |
| 19 | protected function get_option_name() { |
| 20 | return 'sizes'; |
| 21 | } |
| 22 | |
| 23 | public function get_value( $id ) { |
| 24 | $sizes = $this->get_raw_value( $id ); |
| 25 | |
| 26 | if ( ! $sizes ) { |
| 27 | return $this->get_empty_char(); |
| 28 | } |
| 29 | |
| 30 | $paths = array(); |
| 31 | |
| 32 | if ( $available_sizes = $this->get_available_sizes( $sizes ) ) { |
| 33 | |
| 34 | $url = wp_get_attachment_url( $id ); |
| 35 | $paths[] = ac_helper()->html->tooltip( ac_helper()->html->link( $url, __( 'original', 'codepress-admin-columns' ) ), basename( $url ) ); |
| 36 | |
| 37 | foreach ( $available_sizes as $size ) { |
| 38 | $src = wp_get_attachment_image_src( $id, $size ); |
| 39 | |
| 40 | if ( ! empty( $src[0] ) ) { |
| 41 | $paths[] = ac_helper()->html->tooltip( ac_helper()->html->link( $src[0], $size ), basename( $src[0] ) ); |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | // include missing image sizes? |
| 47 | if ( '1' === $this->get_setting( 'include_missing_sizes' )->get_value() ) { |
| 48 | |
| 49 | if ( $missing = $this->get_missing_sizes( $sizes ) ) { |
| 50 | foreach ( $missing as $size ) { |
| 51 | $paths[] = ac_helper()->html->tooltip( $size, sprintf( __( 'Missing image file for size %s.', 'codepress-admin-columns' ), '<em>"' . $size . '"</em>' ), array( 'class' => 'ac-missing-size' ) ); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return "<div class='ac-image-sizes'>" . implode( ac_helper()->html->divider(), $paths ) . "</div>"; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @param array $image_sizes |
| 61 | * |
| 62 | * @return array |
| 63 | */ |
| 64 | public function get_available_sizes( $image_sizes ) { |
| 65 | return array_intersect( array_keys( (array) $image_sizes ), (array) get_intermediate_image_sizes() ); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @param array $image_sizes |
| 70 | * |
| 71 | * @return array |
| 72 | */ |
| 73 | public function get_missing_sizes( $image_sizes ) { |
| 74 | global $_wp_additional_image_sizes; |
| 75 | |
| 76 | if ( empty( $_wp_additional_image_sizes ) ) { |
| 77 | return array(); |
| 78 | } |
| 79 | |
| 80 | $additional_size = $_wp_additional_image_sizes; |
| 81 | |
| 82 | if ( isset( $additional_size['post-thumbnail'] ) ) { |
| 83 | unset( $additional_size['post-thumbnail'] ); |
| 84 | } |
| 85 | |
| 86 | // image does not have these additional sizes rendered yet |
| 87 | return array_diff( array_keys( (array) $additional_size ), array_keys( (array) $image_sizes ) ); |
| 88 | } |
| 89 | |
| 90 | public function register_settings() { |
| 91 | $this->add_setting( new AC_Settings_Column_MissingImageSize( $this ) ); |
| 92 | } |
| 93 | |
| 94 | } |
| 95 |