PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 2.2
Admin Columns v2.2
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 / column.php
codepress-admin-columns / classes Last commit date
column 12 years ago storage_model 12 years ago addons.php 12 years ago column.php 12 years ago settings.php 12 years ago storage_model.php 12 years ago third_party.php 12 years ago upgrade.php 12 years ago utility.php 12 years ago
column.php
1016 lines
1 <?php
2 /**
3 * CPAC_Column class
4 *
5 * @since 2.0.0
6 *
7 * @param object $storage_model CPAC_Storage_Model
8 */
9 class CPAC_Column {
10
11 /**
12 * A Storage Model can be a Posttype, User, Comment, Link or Media storage type.
13 *
14 * @since 2.0.0
15 * @var object $storage_model contains a CPAC_Storage_Model object which the column belongs too.
16 */
17 public $storage_model;
18
19 /**
20 * @since 2.0.0
21 * @var array $options contains the user set options for the CPAC_Column object.
22 */
23 public $options = array();
24
25 /**
26 * @since 2.0.0
27 * @var object $options_default contains the options for the CPAC_Column object before they are populated with user input.
28 */
29 protected $options_default;
30
31 /**
32 * @since 2.0.0
33 * @var array $properties describes the fixed properties for the CPAC_Column object.
34 */
35 public $properties = array();
36
37 /**
38 * @since 2.0.0
39 * @param int $id ID
40 * @return string Value
41 */
42 public function get_value( $id ) {}
43
44 /**
45 * Get the raw, underlying value for the column
46 * Not suitable for direct display, use get_value() for that
47 *
48 * @since 2.0.3
49 * @param int $id ID
50 * @return mixed Value
51 */
52 public function get_raw_value( $id ) {}
53
54 /**
55 * @since 2.0.0
56 */
57 protected function display_settings() {}
58
59 /**
60 * Overwrite this function in child class to sanitize
61 * user submitted values.
62 *
63 * @since 2.0.0
64 * @param $options array User submitted column options
65 * @return array Options
66 */
67 protected function sanitize_options( $options ) {
68
69 if ( isset( $options['date_format'] ) ) {
70 $options['date_format'] = trim( $options['date_format'] );
71 }
72
73 return $options;
74 }
75
76 /**
77 * An object copy (clone) is created for creating multiple column instances.
78 *
79 * @since 2.0.0
80 */
81 public function __clone() {
82
83 // Force a copy of this->object, otherwise it will point to same object.
84 $this->options = clone $this->options;
85 $this->properties = clone $this->properties;
86 }
87
88 /**
89 * @since 2.0.0
90 * @param object $storage_model CPAC_Storage_Model
91 */
92 function __construct( CPAC_Storage_Model $storage_model ) {
93
94 $this->storage_model = $storage_model;
95
96 // every column contains these default properties
97 $default_properties = array(
98 'clone' => null, // Unique clone ID
99 'type' => null, // Unique type
100 'name' => null, // Unique name
101 'label' => null, // Label which describes this column.
102 'classes' => null, // Custom CSS classes for this column.
103 'hide_label' => false, // Should the Label be hidden?
104 'is_registered' => true, // Should the column be registered based on conditional logic, example usage see: 'post/page-template.php'
105 'is_cloneable' => true, // Should the column be cloneable
106 'default' => false, // Is this a WP default column,
107 'group' => 'custom'
108 );
109
110 // merge arguments with defaults. turn into object for easy handling
111 $properties = array_merge( $default_properties, $this->properties );
112
113 // set column name to column type
114 $properties['name'] = $properties['type'];
115
116 // apply conditional statements wheter this column should be available or not.
117 if ( method_exists( $this, 'apply_conditional' ) ) {
118 $properties['is_registered'] = $this->apply_conditional();
119 }
120
121 /**
122 * Filter the properties of a column type, such as type and is_cloneable
123 * Property $column_instance added in Admin Columns 2.2
124 *
125 * @since 2.0.0
126 * @param array $properties Column properties
127 * @param CPAC_Column $column_instance Column class instance
128 */
129 $properties = apply_filters( 'cac/column/properties', $properties, $this );
130
131 /**
132 * Filter the properties of a column type for a specific storage model
133 * Property $column_instance added in Admin Columns 2.2
134 *
135 * @since 2.0.0
136 * @see Filter cac/column/properties
137 */
138 $properties = apply_filters( "cac/column/properties/storage_key={$this->storage_model->key}", $properties, $this );
139
140 // convert to object for easy handling
141 $this->properties = (object) $properties;
142
143 // every column contains these default options
144 $default_options = array(
145 'label' => $this->properties->label, // Label for this column.
146 'width' => null, // Width for this column.
147 'state' => 'off' // Active state for this column.
148 );
149
150 // Default options
151 $default_options = array_merge( $default_options, $this->options );
152
153 /**
154 * Filter the default options for a column instance, such as label and width
155 *
156 * @since 2.2
157 * @param array $default_options Default column options
158 * @param CPAC_Column $column_instance Column class instance
159 */
160 $default_options = apply_filters( 'cac/column/default_options', $default_options, $this );
161
162 /**
163 * Filter the default options for a column instance for a specific storage model
164 *
165 * @since 2.2
166 * @see Filter cac/column/options
167 */
168 $default_options = apply_filters( "cac/column/default_options/storage_key={$this->storage_model->key}", $default_options, $this );
169
170 // merge arguments with defaults and stored options. turn into object for easy handling
171 $this->options = (object) $default_options;
172
173 // set default options before populating
174 $this->options_default = $this->options;
175
176 // add stored options
177 $this->populate_options();
178
179 $this->sanitize_label();
180 }
181
182 /**
183 * Populate Options
184 * Added $options parameter in 2.2
185 *
186 * @since 2.0.0
187 * @param array $options Optional. Options to populate the storage model with. Defaults to options from database.
188 */
189 public function populate_options( $options = NULL ) {
190 $this->options = (object) array_merge( (array) $this->options, is_array( $options ) ? $options : $this->read() );
191 }
192
193 /**
194 * @param string $property
195 * @return mixed $value
196 */
197 public function set_properties( $property, $value ) {
198 $this->properties->{$property} = $value;
199
200 return $this;
201 }
202
203 /**
204 * @param string $option
205 * @return mixed $value
206 */
207 public function set_options( $option, $value ) {
208 $this->options->{$option} = $value;
209
210 return $this;
211 }
212
213 /**
214 * @param int $id
215 * @return object
216 */
217 public function set_clone( $id = null ) {
218
219 if ( $id !== null && $id > 0 ) {
220 $this->properties->name = "{$this->properties->type}-{$id}";
221 $this->properties->clone = $id;
222 }
223
224 return $this;
225 }
226
227 /**
228 * @param string $field_key
229 * @return void
230 */
231 public function attr_name( $field_name ) {
232 echo "{$this->storage_model->key}[{$this->properties->name}][{$field_name}]";
233 }
234
235 /**
236 * @param string $field_key
237 * @return string Attribute Name
238 */
239 public function attr_id( $field_name ) {
240 echo "cpac-{$this->storage_model->key}-{$this->properties->name}-{$field_name}";
241 }
242
243 /**
244 * @since 2.0.0
245 * @return array Column options
246 */
247 public function read() {
248 $options = (array) get_option( "cpac_options_{$this->storage_model->key}" );
249
250 if ( empty( $options[ $this->properties->name ] ) ) {
251 return array();
252 }
253
254 return $options[ $this->properties->name ];
255 }
256
257 /**
258 * @since 2.0.0
259 */
260 public function sanitize_label() {
261
262 // check if original label has changed. Example WPML adds a language column, the column heading will have to display the added flag.
263 if ( $this->properties->hide_label && $this->properties->label !== $this->options->label ) {
264 $this->options->label = $this->properties->label;
265 }
266
267 // replace urls, so export will not have to deal with them
268 $this->options->label = stripslashes( str_replace( '[cpac_site_url]', site_url(), $this->options->label ) );
269 }
270
271 /**
272 * @since 2.0.0
273 * @param $options array User submitted column options
274 * @return array Options
275 */
276 public function sanitize_storage( $options ) {
277
278 // excerpt length must be numeric, else we will return it's default
279 if ( isset( $options['excerpt_length'] ) ) {
280 $options['excerpt_length'] = trim( $options['excerpt_length'] );
281 if ( empty( $options['excerpt_length'] ) || ! is_numeric( $options['excerpt_length'] ) ) {
282 $options['excerpt_length'] = $this->options_default->excerpt_length;
283 }
284 }
285
286 if ( ! empty( $options['label'] ) ) {
287
288 // Label can not contains the character ':', because
289 // CPAC_Column::get_sanitized_label() will return an empty string
290 $options['label'] = str_replace( ':', '', $options['label'] );
291 }
292
293 // used by child classes for additional sanitizing
294 $options = $this->sanitize_options( $options );
295
296 return $options;
297 }
298
299 /**
300 * @since 2.0.0
301 */
302 function get_label() {
303
304 /**
305 * Filter the column instance label
306 *
307 * @since 2.0.0
308 *
309 * @param string $label Column instance label
310 * @param CPAC_Column $column_instance Column class instance
311 */
312 return apply_filters( 'cac/column/settings_label', stripslashes( str_replace( '[cpac_site_url]', site_url(), $this->options->label ) ), $this );
313 }
314
315 /**
316 * Sanitizes label using intern wordpress function esc_url so it matches the label sorting url.
317 *
318 * @since 1.0.0
319 * @param string $string
320 * @return string Sanitized string
321 */
322 public function get_sanitized_label() {
323 $string = esc_url( $this->options->label );
324 $string = str_replace( 'http://', '', $string );
325 $string = str_replace( 'https://', '', $string );
326
327 return $string;
328 }
329
330 /**
331 * @since 2.2
332 * @param $id Cache ID
333 * @return string MD5 Cache ID
334 */
335 function get_cache_id( $id ) {
336 return md5( $this->storage_model->key . $this->properties->name . $id );
337 }
338
339 /**
340 * @since 2.0.0
341 * @param $id Cache ID
342 * @param $cache_object Cache Object
343 */
344 function set_cache( $id, $cache_object ) {
345
346 if ( empty( $cache_object ) ) {
347 return false;
348 }
349
350 set_transient( $this->get_cache_id( $id ), $cache_object );
351 }
352
353 /**
354 * @since 2.0.0
355 * @param $id Cache ID ( could be a name of an addon for example )
356 * @return false | mixed Returns either false or the cached objects
357 */
358 function get_cache( $id ) {
359 $cache = get_transient( $this->get_cache_id( $id ) );
360
361 if ( empty( $cache ) ) {
362 return false;
363 }
364
365 return $cache;
366 }
367
368 /**
369 * @since 2.0.0
370 * @param $id Cache ID
371 */
372 function delete_cache( $id ) {
373 delete_transient( $this->get_cache_id( $id ) );
374 }
375
376 /**
377 * @since 1.3.1
378 */
379 protected function get_shorten_url( $url = '' ) {
380 if ( ! $url ) {
381 return false;
382 }
383
384 return "<a title='{$url}' href='{$url}'>" . url_shorten( $url ) . "</a>";
385 }
386
387 /**
388 * @since 1.3
389 */
390 protected function strip_trim( $string ) {
391 return trim( strip_tags( $string ) );
392 }
393
394 /**
395 * @since 2.2.1
396 */
397 protected function get_term_field( $field, $term_id, $taxonomy ) {
398 $term_field = get_term_field( $field, $term_id, $taxonomy, 'display' );
399 if ( is_wp_error( $term_field ) ) {
400 return false;
401 }
402 return $term_field;
403 }
404
405 /**
406 * @since 1.0.0
407 * @param int $post_id Post ID
408 * @return string Post Excerpt.
409 */
410 protected function get_post_excerpt( $post_id, $words ) {
411 global $post;
412
413 $save_post = $post;
414 $post = get_post( $post_id );
415
416 setup_postdata( $post );
417
418 $excerpt = get_the_excerpt();
419 $post = $save_post;
420
421 if ( $post ) {
422 setup_postdata( $post );
423 }
424
425 $output = $this->get_shortened_string( $excerpt, $words );
426
427 return $output;
428 }
429
430 /**
431 * @see wp_trim_words();
432 * @since 1.0.0
433 * @return string Trimmed text.
434 */
435 protected function get_shortened_string( $text = '', $num_words = 30, $more = null ) {
436 if ( ! $text ) {
437 return false;
438 }
439
440 return wp_trim_words( $text, $num_words, $more );
441 }
442
443 /**
444 * @since 1.3.1
445 * @param string $name
446 * @param string $title
447 * @return string HTML img element
448 */
449 public function get_asset_image( $name = '', $title = '' ) {
450
451 if ( ! $name ) {
452 return false;
453 }
454
455 return sprintf( "<img alt='' src='%s' title='%s'/>", CPAC_URL . "assets/images/{$name}", esc_attr( $title ) );
456 }
457
458 /**
459 * @since 1.2.0
460 * @param string $url
461 * @return bool
462 */
463 protected function is_image( $url ) {
464
465 if ( ! is_string( $url ) ) {
466 return false;
467 }
468
469 $validExt = array('.jpg', '.jpeg', '.gif', '.png', '.bmp');
470 $ext = strrchr( $url, '.' );
471
472 return in_array( $ext, $validExt );
473 }
474
475 /**
476 * @since 1.0.0
477 * @return array Image Sizes.
478 */
479 public function get_all_image_sizes() {
480 $image_sizes = array(
481 'thumbnail' => __( "Thumbnail", 'cpac' ),
482 'medium' => __( "Medium", 'cpac' ),
483 'large' => __( "Large", 'cpac' ),
484 'full' => __( "Full", 'cpac' )
485 );
486
487 foreach( get_intermediate_image_sizes() as $size ) {
488 if ( ! isset( $image_sizes[$size] ) ) {
489 $image_sizes[$size] = ucwords( str_replace( '-', ' ', $size) );
490 }
491 }
492
493 return $image_sizes;
494 }
495
496 /**
497 * @since 2.0.0
498 * @param string $name
499 * @return array Image Sizes
500 */
501 public function get_image_size_by_name( $name = '' ) {
502
503 if ( ! $name || is_array( $name ) ) {
504 return false;
505 }
506
507 global $_wp_additional_image_sizes;
508
509 if ( ! isset( $_wp_additional_image_sizes[ $name ] ) ) {
510 return false;
511 }
512
513 return $_wp_additional_image_sizes[ $name ];
514 }
515
516 /**
517 * @see image_resize()
518 * @since 2.0.0
519 * @return string Image URL
520 */
521 public function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
522 $resized = false;
523 $editor = wp_get_image_editor( $file );
524
525 if ( is_wp_error( $editor ) )
526 return false;
527
528 $editor->set_quality( $jpeg_quality );
529
530 $resized = $editor->resize( $max_w, $max_h, $crop );
531 if ( is_wp_error( $resized ) )
532 return false;
533
534 $dest_file = $editor->generate_filename( $suffix, $dest_path );
535
536 $saved = $editor->save( $dest_file );
537
538 if ( is_wp_error( $saved ) )
539 return false;
540
541 $resized = $dest_file;
542
543 return $resized;
544 }
545
546 /**
547 * @since 1.0.0
548 * @param mixed $meta Image files or Image ID's
549 * @param array $args
550 * @return array HTML img elements
551 */
552 public function get_thumbnails( $images, $args = array() ) {
553 $thumbnails = array();
554
555 if ( empty( $images ) || 'false' == $images ) {
556 return $thumbnails;
557 }
558
559 // turn string to array
560 if ( is_string( $images ) ) {
561 if ( strpos( $images, ',' ) !== false ) {
562 $images = array_filter( explode( ',', $this->strip_trim( str_replace( ' ', '', $images ) ) ) );
563 }
564 else {
565 $images = array( $images );
566 }
567 }
568
569 // Image size
570 $defaults = array(
571 'image_size' => 'cpac-custom',
572 'image_size_w' => 80,
573 'image_size_h' => 80,
574 );
575 $args = wp_parse_args( $args, $defaults );
576
577 extract( $args );
578
579 foreach( $images as $value ) {
580 if ( $this->is_image( $value ) ) {
581
582 // get dimensions from image_size
583 if ( $sizes = $this->get_image_size_by_name( $image_size ) ) {
584 $image_size_w = $sizes['width'];
585 $image_size_h = $sizes['height'];
586 }
587
588 $image_path = str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $value );
589
590 if ( is_file( $image_path ) ) {
591
592 // try to resize image
593 if ( $resized = $this->image_resize( $image_path, $image_size_w, $image_size_h, true ) ) {
594 $thumbnails[] = "<img src='" . str_replace( WP_CONTENT_DIR, WP_CONTENT_URL, $resized ) . "' alt='' width='{$image_size_w}' height='{$image_size_h}' />";
595 }
596
597 // return full image with maxed dimensions
598 else {
599 $thumbnails[] = "<img src='{$value}' alt='' style='max-width:{$image_size_w}px;max-height:{$image_size_h}px' />";
600 }
601 }
602 }
603
604 // Media Attachment
605 elseif ( is_numeric( $value ) && wp_get_attachment_url( $value ) ) {
606
607 if ( ! $image_size || 'cpac-custom' == $image_size ) {
608 $width = $image_size_w;
609 $height = $image_size_h;
610
611 // to make sure wp_get_attachment_image_src() get the image with matching dimensions.
612 $image_size = array( $width, $height );
613 }
614
615 // image attributes
616 $attributes = wp_get_attachment_image_src( $value, $image_size );
617 $src = $attributes[0];
618 $width = $attributes[1];
619 $height = $attributes[2];
620
621 // image size by name
622 if ( $sizes = $this->get_image_size_by_name( $image_size ) ) {
623 $width = $sizes['width'];
624 $height = $sizes['height'];
625 }
626
627 // maximum dimensions
628 $max = max( array( $width, $height ) );
629
630 $thumbnails[] = "<span class='cpac-column-value-image' style='width:{$width}px;height:{$height}px;'><img style='max-width:{$max}px;max-height:{$max}px;' src='{$attributes[0]}' alt=''/></span>";
631 }
632 }
633
634 return $thumbnails;
635 }
636
637 /**
638 * Implode for multi dimensional array
639 *
640 * @since 1.0.0
641 * @param string $glue
642 * @param array $pieces
643 * @return string Imploded array
644 */
645 protected function recursive_implode( $glue, $pieces ) {
646 foreach( $pieces as $r_pieces ) {
647 if ( is_array( $r_pieces ) ) {
648 $retVal[] = $this->recursive_implode( $glue, $r_pieces );
649 }
650 else {
651 $retVal[] = $r_pieces;
652 }
653 }
654 if ( isset($retVal) && is_array( $retVal ) ) {
655 return implode( $glue, $retVal );
656 }
657
658 return false;
659 }
660
661 /**
662 * Get timestamp
663 *
664 * @since 2.0.0
665 * @param string $date
666 * @return string Formatted date
667 */
668 private function get_timestamp( $date ) {
669
670 if ( empty( $date ) || in_array( $date, array( '0000-00-00 00:00:00', '0000-00-00', '00:00:00' ) ) ) {
671 return false;
672 }
673
674 // some plugins store dates in a jquery timestamp format, format is in ms since The Epoch
675 // See http://api.jqueryui.com/datepicker/#utility-formatDate
676 // credits: nmarks
677 if ( is_numeric( $date ) && 13 === strlen( trim( $date ) ) ) {
678 $date = substr( $date, 0, -3 );
679 }
680
681 // Parse with strtotime if it's:
682 // - not numeric ( like a unixtimestamp )
683 // - date format: yyyymmdd ( format used by ACF ) must start with 19xx or 20xx and is 8 long
684
685 // @todo: in theory a numeric string of 8 can also be a unixtimestamp.
686 // we need to replace this with an option to mark a date as unixtimestamp.
687 if ( ! is_numeric( $date ) || ( is_numeric( $date ) && strlen( trim( $date ) ) == 8 && ( strpos( $date, '20' ) === 0 || strpos( $date, '19' ) === 0 ) ) ) {
688 $date = strtotime( $date );
689 }
690
691 return $date;
692 }
693
694 /**
695 * @since 1.3.1
696 * @param string $date
697 * @return string Formatted date
698 */
699 protected function get_date( $date, $format = '' ) {
700
701 if ( ! $date = $this->get_timestamp( $date ) ) {
702 return false;
703 }
704 if ( ! $format ) {
705 $format = get_option( 'date_format' );
706 }
707
708 return date_i18n( $format, $date );
709 }
710
711 /**
712 * @since 1.3.1
713 * @param string $date
714 * @return string Formatted time
715 */
716 protected function get_time( $date, $format = '' ) {
717
718 if ( ! $date = $this->get_timestamp( $date ) ) {
719 return false;
720 }
721 if ( ! $format ) {
722 $format = get_option( 'time_format' );
723 }
724
725 return date_i18n( $format, $date );
726 }
727
728 /**
729 * @since 2.0.0
730 * @param string $field_key
731 * @return string Attribute Name
732 */
733 function label_view( $label, $description = '', $pointer = '' ) {
734 ?>
735 <td class="label">
736 <label for="<?php $this->attr_id( $pointer ); ?>">
737 <?php echo stripslashes( $label ); ?>
738
739 <?php if( $description ) : ?><p class="description"><?php echo $description; ?></p><?php endif; ?>
740 </label>
741 </td>
742 <?php
743 }
744
745 /**
746 * @since 2.0.0
747 */
748 function display_field_date_format() {
749
750 $field_key = 'date_format';
751 $label = __( 'Date Format', 'cpac' );
752 $description = __( 'This will determine how the date will be displayed.', 'cpac' );
753
754 ?>
755 <tr class="column_<?php echo $field_key; ?>">
756 <?php $this->label_view( $label, $description, $field_key ); ?>
757 <td class="input">
758 <input type="text" name="<?php $this->attr_name( $field_key ); ?>" id="<?php $this->attr_id( $field_key ); ?>" value="<?php echo $this->options->date_format; ?>" placeholder="<?php _e( 'Example:', 'cpac' ); ?> d M Y H:i"/>
759 <p class="description">
760 <?php printf( __( 'Leave empty for WordPress date format, change your <a href="%s">default date format here</a>.' , 'cpac' ), admin_url( 'options-general.php' ) . '#date_format_custom_radio' ); ?>
761 <a target='_blank' href='http://codex.wordpress.org/Formatting_Date_and_Time'><?php _e( 'Documentation on date and time formatting.', 'cpac' ); ?></a>
762 </p>
763 </td>
764 </tr>
765
766 <?php
767 }
768
769 /**
770 * @since 2.0.0
771 */
772 function display_field_excerpt_length() {
773
774 $field_key = 'excerpt_length';
775 $label = __( 'Excerpt length', 'cpac' );
776 $description = __( 'Number of words', 'cpac' );
777
778 ?>
779 <tr class="column_<?php echo $field_key; ?>">
780 <?php $this->label_view( $label, $description, $field_key ); ?>
781 <td class="input">
782 <input type="text" name="<?php $this->attr_name( $field_key ); ?>" id="<?php $this->attr_id( $field_key ); ?>" value="<?php echo $this->options->excerpt_length; ?>"/>
783 </td>
784 </tr>
785 <?php
786 }
787
788 /**
789 * @since 2.0.0
790 */
791 function display_field_preview_size() {
792
793 $field_key = 'image_size';
794 $label = __( 'Preview size', 'cpac' );
795
796 ?>
797 <tr class="column_<?php echo $field_key; ?>">
798
799 <?php $this->label_view( $label, '', $field_key ); ?>
800
801 <td class="input">
802 <?php foreach ( $sizes = $this->get_all_image_sizes() as $id => $image_label ) : ?>
803 <label for="<?php $this->attr_id( $field_key ); ?>-<?php echo $id ?>" class="custom-size">
804 <input type="radio" value="<?php echo $id; ?>" name="<?php $this->attr_name( $field_key ); ?>" id="<?php $this->attr_id( $field_key ); ?>-<?php echo $id ?>"<?php checked( $this->options->image_size, $id ); ?>>
805 <?php echo $image_label; ?>
806 </label>
807 <?php endforeach; ?>
808
809 <div class="custom_image_size">
810 <label for="<?php $this->attr_id( $field_key ); ?>-custom" class="custom-size image-size-custom" >
811 <input type="radio" value="cpac-custom" name="<?php $this->attr_name( $field_key ); ?>" id="<?php $this->attr_id( $field_key ); ?>-custom"<?php checked( $this->options->image_size, 'cpac-custom' ); ?>><?php _e( 'Custom', 'cpac' ); ?>
812 </label>
813 <label for="<?php $this->attr_id( $field_key ); ?>-w" class="custom-size-w<?php echo $this->options->image_size != 'cpac-custom' ? ' hidden' : ''; ?>">
814 <input type="text" name="<?php $this->attr_name( 'image_size_w' ); ?>" id="<?php $this->attr_id( $field_key ); ?>-w" value="<?php echo $this->options->image_size_w; ?>" /><?php _e( 'width', 'cpac' ); ?>
815 </label>
816 <label for="<?php $this->attr_id( $field_key ); ?>-h" class="custom-size-h<?php echo $this->options->image_size != 'cpac-custom' ? ' hidden' : ''; ?>">
817 <input type="text" name="<?php $this->attr_name( 'image_size_h' ); ?>" id="<?php $this->attr_id( $field_key ); ?>-h" value="<?php echo $this->options->image_size_h; ?>" /><?php _e( 'height', 'cpac' ); ?>
818 </label>
819 </div>
820 </td>
821 </tr>
822 <?php
823 }
824
825 /**
826 * @since 2.1.1
827 */
828 function display_field_before_after() {
829 ?>
830 <tr class="column_before">
831 <?php $this->label_view( __( "Before", 'cpac' ), __( 'This text will appear before the custom field value.', 'cpac' ), 'before' ); ?>
832 <td class="input">
833 <input type="text" class="cpac-before" name="<?php $this->attr_name( 'before' ); ?>" id="<?php $this->attr_id( 'before' ); ?>" value="<?php echo esc_attr( stripslashes( $this->options->before ) ); ?>"/>
834 </td>
835 </tr>
836 <tr class="column_after">
837 <?php $this->label_view( __( "After", 'cpac' ), __( 'This text will appear after the custom field value.', 'cpac' ), 'after' ); ?>
838 <td class="input">
839 <input type="text" class="cpac-after" name="<?php $this->attr_name( 'after' ); ?>" id="<?php $this->attr_id( 'after' ); ?>" value="<?php echo esc_attr( stripslashes( $this->options->after ) ); ?>"/>
840 </td>
841 </tr>
842 <?php
843 }
844
845 /**
846 * @since 2.0.0
847 * @param array Column Objects
848 * @return string HTML List
849 */
850 public function get_column_list( $columns = array(), $label = '' ) {
851
852 if ( empty( $columns ) ) {
853 return false;
854 }
855
856 $list = '';
857
858 // sort by alphabet
859 $_columns = array();
860 foreach ( $columns as $column ) {
861 $_columns[ $column->properties->type ] = 0 === strlen( strip_tags( $column->properties->label ) ) ? ucfirst( $column->properties->type ) : $column->properties->label;
862 }
863 asort( $_columns );
864
865 $list = "<optgroup label='{$label}'>";
866 foreach ( $_columns as $type => $label ){
867 $selected = selected( $this->properties->type, $type, false );
868 $list .= "<option value='{$type}'{$selected}>{$label}</option>";
869 }
870 $list .= "</optgroup>";
871
872 return $list;
873 }
874
875 /**
876 * @since 2.0.0
877 */
878 public function display() {
879
880 $classes = implode( ' ', array_filter( array ( "cpac-box-{$this->properties->type}", $this->properties->classes ) ) );
881
882 // column list
883 $column_list = '';
884
885 $groups = $this->storage_model->get_column_type_groups();
886
887 foreach ( $groups as $group => $label ) {
888 $column_list .= $this->get_column_list( $this->storage_model->column_types[ $group ], $label );
889 }
890
891 // clone attribute
892 $data_clone = $this->properties->is_cloneable ? " data-clone='{$this->properties->clone}'" : '';
893
894 ?>
895 <div class="cpac-column <?php echo $classes; ?>" data-type="<?php echo $this->properties->type; ?>"<?php echo $data_clone; ?>>
896 <input type="hidden" class="column-name" name="<?php echo $this->attr_name( 'column-name' ); ?>" value="<?php echo esc_attr( $this->properties->name ); ?>" />
897 <input type="hidden" class="type" name="<?php echo $this->attr_name( 'type' ); ?>" value="<?php echo $this->properties->type; ?>" />
898 <input type="hidden" class="clone" name="<?php echo $this->attr_name( 'clone' ); ?>" value="<?php echo $this->properties->clone; ?>" />
899 <div class="column-meta">
900 <table class="widefat">
901 <tbody>
902 <tr>
903 <td class="column_sort"></td>
904 <td class="column_label">
905 <div class="inner">
906 <div class="meta">
907
908 <?php
909 /**
910 * Fires in the meta-element for column options, which is displayed right after the column label
911 *
912 * @since 2.0.0
913 *
914 * @param CPAC_Column $column_instance Column class instance
915 */
916 do_action( 'cac/column/settings_meta', $this );
917
918 /**
919 * @deprecated 2.2 Use cac/column/settings_meta instead
920 */
921 do_action( 'cac/column/label', $this );
922 ?>
923
924 </div>
925 <a class="toggle" href="javascript:;"><?php echo stripslashes( $this->get_label() ); ?></a>
926 <a class="edit-button" href="javascript:;"><?php _e( 'Edit', 'cpac' ); ?></a>
927 <a class="remove-button" href="javascript:;"><?php _e( 'Remove', 'cpac' ); ?></a>
928 </div>
929 </td>
930 <td class="column_type">
931 <div class="inner">
932 <a href="#"><?php echo stripslashes( $this->properties->label ); ?></a>
933 </div>
934 </td>
935 <td class="column_edit"></td>
936 </tr>
937 </tbody>
938 </table>
939 </div><!--.column-meta-->
940
941 <div class="column-form">
942 <table class="widefat">
943 <tbody>
944 <tr class="column_type">
945 <?php $this->label_view( __( 'Type', 'cpac' ), __( 'Choose a column type.', 'cpac' ) . '<em>' . __('ID','cpac') . ': ' . $this->properties->type . '</em>', 'type' ); ?>
946 <td class="input">
947 <select name="<?php $this->attr_name( 'type' ); ?>" id="<?php $this->attr_id( 'type' ); ?>">
948 <?php echo $column_list; ?>
949 </select>
950 <div class="msg"></div>
951 </td>
952 </tr><!--.column_label-->
953
954 <tr class="column_label<?php echo $this->properties->hide_label ? ' hidden' : ''; ?>">
955 <?php $this->label_view( __( 'Label', 'cpac' ), __( 'This is the name which will appear as the column header.', 'cpac' ), 'label' ); ?>
956 <td class="input">
957 <input class="text" type="text" name="<?php $this->attr_name( 'label' ); ?>" id="<?php $this->attr_id( 'label' ); ?>" value="<?php echo esc_attr( $this->options->label ); //echo sanitize_text_field( $this->options->label ); ?>" />
958 </td>
959 </tr><!--.column_label-->
960
961 <tr class="column_width">
962 <?php $this->label_view( __( 'Width', 'cpac' ), '', 'width' ); ?>
963 <td class="input">
964 <div class="description width-decription" title="<?php _e( 'default', 'cpac' ); ?>">
965 <?php echo $this->options->width > 0 ? $this->options->width . '%' : __( 'default', 'cpac' ); ?>
966 </div>
967 <div class="input-width-range"></div>
968 <input type="hidden" class="input-width" name="<?php $this->attr_name( 'width' ); ?>" id="<?php $this->attr_id( 'width' ); ?>" value="<?php echo $this->options->width; ?>" />
969
970 </td>
971 </tr><!--.column_width-->
972
973 <?php
974 /**
975 * Fires directly before the custom options for a column are displayed in the column form
976 *
977 * @since 2.0.0
978 * @param CPAC_Column $column_instance Column class instance
979 */
980 do_action( 'cac/column/settings_before', $this );
981 ?>
982
983 <?php
984 /**
985 * Load specific column settings.
986 *
987 */
988 $this->display_settings();
989
990 ?>
991
992 <?php
993 /**
994 * Fires directly after the custom options for a column are displayed in the column form
995 *
996 * @since 2.0.0
997 * @param CPAC_Column $column_instance Column class instance
998 */
999 do_action( 'cac/column/settings_after', $this );
1000 ?>
1001
1002 <tr class="column_action">
1003 <td colspan="2">
1004 <p>
1005 <a href="javascript:;" class="remove-button"><?php _e( 'Remove' );?></a>
1006 </p>
1007 </td>
1008 </tr>
1009
1010 </tbody>
1011 </table>
1012 </div><!--.column-form-->
1013 </div><!--.cpac-column-->
1014 <?php
1015 }
1016 }