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