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