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