PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 3.0.5
Admin Columns v3.0.5
7.1.4 7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Settings / Column / Image.php
codepress-admin-columns / classes / Settings / Column Last commit date
BeforeAfter 8 years ago ActionIcons.php 8 years ago AttachmentDisplay.php 8 years ago BeforeAfter.php 8 years ago CharacterLimit.php 8 years ago CommentCount.php 8 years ago CustomField.php 8 years ago CustomFieldType.php 8 years ago Date.php 8 years ago ExifData.php 8 years ago Image.php 8 years ago Images.php 8 years ago Label.php 8 years ago LinkLabel.php 8 years ago LinkToMenu.php 8 years ago Message.php 8 years ago Meta.php 8 years ago MissingImageSize.php 8 years ago NumberOfItems.php 8 years ago Password.php 8 years ago PathScope.php 8 years ago Post.php 8 years ago PostFormatIcon.php 8 years ago PostLink.php 8 years ago PostType.php 8 years ago Separator.php 8 years ago StatusIcon.php 8 years ago StringLimit.php 8 years ago Taxonomy.php 8 years ago Term.php 8 years ago Toggle.php 8 years ago Type.php 8 years ago User.php 8 years ago Width.php 8 years ago WordLimit.php 8 years ago WordsPerMinute.php 8 years ago
Image.php
200 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 class AC_Settings_Column_Image extends AC_Settings_Column
8 implements AC_Settings_FormatValueInterface {
9
10 /**
11 * @var string
12 */
13 private $image_size;
14
15 /**
16 * @var integer
17 */
18 private $image_size_w;
19
20 /**
21 * @var integer
22 */
23 private $image_size_h;
24
25 protected function set_name() {
26 return $this->name = 'image';
27 }
28
29 protected function define_options() {
30 return array(
31 'image_size',
32 'image_size_w' => 80,
33 'image_size_h' => 80,
34 );
35 }
36
37 public function create_view() {
38 $width = new AC_View( array(
39 'setting' => $this->create_element( 'number', 'image_size_w' ),
40 'label' => __( 'Width', 'codepress-admin-columns' ),
41 'tooltip' => __( 'Width in pixels', 'codepress-admin-columns' ),
42 ) );
43
44 $height = new AC_View( array(
45 'setting' => $this->create_element( 'number', 'image_size_h' ),
46 'label' => __( 'Height', 'codepress-admin-columns' ),
47 'tooltip' => __( 'Height in pixels', 'codepress-admin-columns' ),
48 ) );
49
50 $size = $this->create_element( 'select', 'image_size' )
51 ->set_options( $this->get_grouped_image_sizes() );
52
53 $view = new AC_View( array(
54 'label' => __( 'Image Size', 'codepress-admin-columns' ),
55 'setting' => $size,
56 'sections' => array( $width, $height ),
57 ) );
58
59 return $view;
60 }
61
62 /**
63 * @since 1.0
64 * @return array
65 */
66 private function get_grouped_image_sizes() {
67 global $_wp_additional_image_sizes;
68
69 $sizes = array(
70 'default' => array(
71 'title' => __( 'Default', 'codepress-admin-columns' ),
72 'options' => array(
73 'thumbnail' => __( 'Thumbnail', 'codepress-admin-columns' ),
74 'medium' => __( 'Medium', 'codepress-admin-columns' ),
75 'large' => __( 'Large', 'codepress-admin-columns' ),
76 ),
77 ),
78 );
79
80 $all_sizes = get_intermediate_image_sizes();
81
82 if ( ! empty( $all_sizes ) ) {
83 foreach ( $all_sizes as $size ) {
84 if ( 'medium_large' == $size || isset( $sizes['default']['options'][ $size ] ) ) {
85 continue;
86 }
87
88 if ( ! isset( $sizes['defined'] ) ) {
89 $sizes['defined']['title'] = __( 'Others', 'codepress-admin-columns' );
90 }
91
92 $sizes['defined']['options'][ $size ] = ucwords( str_replace( '-', ' ', $size ) );
93 }
94 }
95
96 foreach ( $sizes as $key => $group ) {
97 foreach ( array_keys( $group['options'] ) as $_size ) {
98
99 $w = isset( $_wp_additional_image_sizes[ $_size ]['width'] ) ? $_wp_additional_image_sizes[ $_size ]['width'] : get_option( "{$_size}_size_w" );
100 $h = isset( $_wp_additional_image_sizes[ $_size ]['height'] ) ? $_wp_additional_image_sizes[ $_size ]['height'] : get_option( "{$_size}_size_h" );
101
102 if ( $w && $h ) {
103 $sizes[ $key ]['options'][ $_size ] .= " ($w x $h)";
104 }
105 }
106 }
107
108 $sizes['default']['options']['full'] = __( 'Full Size', 'codepress-admin-columns' );
109
110 $sizes['custom'] = array(
111 'title' => __( 'Custom', 'codepress-admin-columns' ),
112 'options' => array( 'cpac-custom' => __( 'Custom Size', 'codepress-admin-columns' ) . '&hellip;' ),
113 );
114
115 return $sizes;
116 }
117
118 /**
119 * @return string
120 */
121 public function get_image_size() {
122 return $this->image_size;
123 }
124
125 /**
126 * @param string $image_size
127 *
128 * @return bool
129 */
130 public function set_image_size( $image_size ) {
131 $this->image_size = $image_size;
132
133 return true;
134 }
135
136 /**
137 * @return int
138 */
139 public function get_image_size_w() {
140 return $this->image_size_w;
141 }
142
143 /**
144 * @param int $image_size_w
145 *
146 * @return bool
147 */
148 public function set_image_size_w( $image_size_w ) {
149 if ( ! is_numeric( $image_size_w ) ) {
150 return false;
151 }
152
153 $this->image_size_w = $image_size_w;
154
155 return true;
156 }
157
158 /**
159 * @return int
160 */
161 public function get_image_size_h() {
162 return $this->image_size_h;
163 }
164
165 /**
166 * @param int $image_size_h
167 *
168 * @return bool
169 */
170 public function set_image_size_h( $image_size_h ) {
171 if ( ! is_numeric( $image_size_h ) ) {
172 return false;
173 }
174
175 $this->image_size_h = $image_size_h;
176
177 return true;
178 }
179
180 protected function get_size_args() {
181 $size = $this->get_image_size();
182
183 if ( 'cpac-custom' === $size ) {
184 $size = array( $this->get_image_size_w(), $this->get_image_size_h() );
185 }
186
187 // fallback size
188 if ( empty( $size ) ) {
189 $size = array( 80, 80 );
190 }
191
192 return $size;
193 }
194
195 public function format( $value, $original_value ) {
196 return ac_helper()->image->get_image( $value, $this->get_size_args() );
197 }
198
199 }
200