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