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