PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 2.1.2
Admin Columns v2.1.2
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
1045 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 * Get cache ID
339 *
340 * @since 2.1.2
341 *
342 * @param $id Cache ID
343 * @return string MD5 Cache ID
344 */
345 function get_cache_id( $id ) {
346
347 return md5( $this->storage_model->key . $this->properties->name . $id );
348 }
349
350 /**
351 * Set cache objects
352 *
353 * @since 2.0.0
354 *
355 * @param $id Cache ID
356 * @param $cache_object Cache Object
357 */
358 function set_cache( $id, $cache_object ) {
359
360 if ( empty( $cache_object ) )
361 return false;
362
363 set_transient( $this->get_cache_id( $id ), $cache_object );
364 }
365
366 /**
367 * Get cache objects
368 *
369 * @since 2.0.0
370 *
371 * @param $id Cache ID ( could be a name of an addon for example )
372 * @return false | mixed Returns either false or the cached objects
373 */
374 function get_cache( $id ) {
375 $cache = get_transient( $this->get_cache_id( $id ) );
376
377 if ( empty( $cache ) )
378 return false;
379
380 return $cache;
381 }
382
383 /**
384 * Delete cache objects
385 *
386 * @since 2.0.0
387 *
388 * @param $id Cache ID
389 */
390 function delete_cache( $id ) {
391
392 delete_transient( $this->get_cache_id( $id ) );
393 }
394
395 /**
396 * Shorten URL - Value method
397 *
398 * @since 1.3.1
399 */
400 protected function get_shorten_url( $url = '' ) {
401 if ( ! $url )
402 return false;
403
404 return "<a title='{$url}' href='{$url}'>" . url_shorten( $url ) . "</a>";
405 }
406
407 /**
408 * Strip tags and trim - Value method
409 *
410 * @since 1.3
411 */
412 protected function strip_trim( $string ) {
413
414 return trim( strip_tags( $string ) );
415 }
416
417 /**
418 * Returns excerpt - Value method
419 *
420 * @since 1.0.0
421 *
422 * @param int $post_id Post ID
423 * @return string Post Excerpt.
424 */
425 protected function get_post_excerpt( $post_id, $words ) {
426 global $post;
427
428 $save_post = $post;
429 $post = get_post( $post_id );
430
431 setup_postdata( $post );
432
433 $excerpt = get_the_excerpt();
434 $post = $save_post;
435
436 if ( $post ) {
437 setup_postdata( $post );
438 }
439
440 $output = $this->get_shortened_string( $excerpt, $words );
441
442 return $output;
443 }
444
445 /**
446 * Returns shortened string - Value method
447 *
448 * @see wp_trim_words();
449 * @since 1.0.0
450 *
451 * @return string Trimmed text.
452 */
453 protected function get_shortened_string( $text = '', $num_words = 30, $more = null ) {
454 if ( ! $text )
455 return false;
456
457 return wp_trim_words( $text, $num_words, $more );
458 }
459
460 /**
461 * Get image from assets folder - Value method
462 *
463 * @since 1.3.1
464 *
465 * @param string $name
466 * @param string $title
467 * @return string HTML img element
468 */
469 public function get_asset_image( $name = '', $title = '' ) {
470 if ( ! $name )
471 return false;
472
473 return sprintf( "<img alt='' src='%s' title='%s'/>", CPAC_URL . "assets/images/{$name}", esc_attr( $title ) );
474 }
475
476 /**
477 * Checks an URL for image extension - Value method
478 *
479 * @since 1.2.0
480 *
481 * @param string $url
482 * @return bool
483 */
484 protected function is_image( $url ) {
485
486 if ( ! is_string( $url ) )
487 return false;
488
489 $validExt = array('.jpg', '.jpeg', '.gif', '.png', '.bmp');
490 $ext = strrchr( $url, '.' );
491
492 return in_array( $ext, $validExt );
493 }
494
495 /**
496 * Get all image sizes - Value method
497 *
498 * @since 1.0.0
499 *
500 * @return array Image Sizes.
501 */
502 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 Image Sizes by name - Value method
521 *
522 * @since 2.0.0
523 *
524 * @param string $name
525 * @return array Image Sizes
526 */
527 function get_image_size_by_name( $name = '' ) {
528 if ( ! $name || is_array( $name ) )
529 return false;
530
531 global $_wp_additional_image_sizes;
532
533 if ( ! isset( $_wp_additional_image_sizes[ $name ] ) )
534 return false;
535
536 return $_wp_additional_image_sizes[ $name ];
537 }
538
539 /**
540 * Image Resize - Value method
541 *
542 * @see image_resize()
543 * @since 2.0.0
544 *
545 * @return string Image URL
546 */
547 function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
548
549 $resized = false;
550
551 $editor = wp_get_image_editor( $file );
552
553 if ( is_wp_error( $editor ) )
554 return false;
555
556 $editor->set_quality( $jpeg_quality );
557
558 $resized = $editor->resize( $max_w, $max_h, $crop );
559 if ( is_wp_error( $resized ) )
560 return false;
561
562 $dest_file = $editor->generate_filename( $suffix, $dest_path );
563
564 $saved = $editor->save( $dest_file );
565
566 if ( is_wp_error( $saved ) )
567 return false;
568
569 $resized = $dest_file;
570
571 return $resized;
572 }
573
574 /**
575 * Get thumbnails - Value method
576 *
577 * @since 1.0.0
578 *
579 * @param mixed $meta Image files or Image ID's
580 * @param array $args
581 * @return array HTML img elements
582 */
583 public function get_thumbnails( $images, $args = array() ) {
584 if ( empty( $images ) || 'false' == $images )
585 return array();
586
587 $thumbnails = array();
588
589 // turn string to array
590 if ( is_string( $images ) ) {
591 if ( strpos( $images, ',' ) !== false ) {
592 $images = array_filter( explode( ',', $this->strip_trim( str_replace( ' ', '', $images ) ) ) );
593 }
594 else {
595 $images = array( $images );
596 }
597 }
598
599 // Image size
600 $defaults = array(
601 'image_size' => 'cpac-custom',
602 'image_size_w' => 80,
603 'image_size_h' => 80,
604 );
605 $args = wp_parse_args( $args, $defaults );
606
607 extract( $args );
608
609 // foreach image
610 foreach( $images as $value ) {
611
612 // Image
613 if ( $this->is_image( $value ) ) {
614
615 // get dimensions from image_size
616 if ( $sizes = $this->get_image_size_by_name( $image_size ) ) {
617 $image_size_w = $sizes['width'];
618 $image_size_h = $sizes['height'];
619 }
620
621 // get correct image path
622 $image_path = str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $value );
623
624 // resize image
625 if ( is_file( $image_path ) ) {
626
627 // try to resize image
628 if ( $resized = $this->image_resize( $image_path, $image_size_w, $image_size_h, true ) ) {
629 $thumbnails[] = "<img src='" . str_replace( WP_CONTENT_DIR, WP_CONTENT_URL, $resized ) . "' alt='' width='{$image_size_w}' height='{$image_size_h}' />";
630 }
631
632 // resizing failed so let's return full image with maxed dimensions
633 else {
634 $thumbnails[] = "<img src='{$value}' alt='' style='max-width:{$image_size_w}px;max-height:{$image_size_h}px' />";
635 }
636 }
637 }
638
639 // Media Attachment
640 elseif ( is_numeric( $value ) && wp_get_attachment_url( $value ) ) {
641
642 // custom image size
643 if ( ! $image_size || 'cpac-custom' == $image_size ) {
644 $width = $image_size_w;
645 $height = $image_size_h;
646
647 // to make sure wp_get_attachment_image_src() get the image with matching dimensions.
648 $image_size = array( $width, $height );
649 }
650
651 // image attributes
652 $attributes = wp_get_attachment_image_src( $value, $image_size );
653 $src = $attributes[0];
654 $width = $attributes[1];
655 $height = $attributes[2];
656
657 // image size by name
658 if ( $sizes = $this->get_image_size_by_name( $image_size ) ) {
659 $width = $sizes['width'];
660 $height = $sizes['height'];
661 }
662
663 // maximum dimensions
664 $max = max( array( $width, $height ) );
665
666 $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>";
667 }
668 }
669
670 return $thumbnails;
671 }
672
673 /**
674 * Implode for multi dimensional array - Value method
675 *
676 * @since 1.0.0
677 *
678 * @param string $glue
679 * @param array $pieces
680 * @return string Imploded array
681 */
682 protected function recursive_implode( $glue, $pieces ) {
683 foreach( $pieces as $r_pieces ) {
684 if ( is_array( $r_pieces ) ) {
685 $retVal[] = $this->recursive_implode( $glue, $r_pieces );
686 }
687 else {
688 $retVal[] = $r_pieces;
689 }
690 }
691 if ( isset($retVal) && is_array( $retVal ) ) {
692 return implode( $glue, $retVal );
693 }
694
695 return false;
696 }
697
698 /**
699 * Get timestamp
700 *
701 * @since 2.0.0
702 *
703 * @param string $date
704 * @return string Formatted date
705 */
706 private function get_timestamp( $date ) {
707
708 if ( empty( $date ) || in_array( $date, array( '0000-00-00 00:00:00', '0000-00-00', '00:00:00' ) ) )
709 return false;
710
711 // some plugins store dates in a jquery timestamp format, format is in ms since The Epoch
712 // See http://api.jqueryui.com/datepicker/#utility-formatDate
713 // credits: nmarks
714 if ( is_numeric( $date ) && 13 === strlen( trim( $date ) ) ) {
715 $date = substr( $date, 0, -3 );
716 }
717
718 // Parse with strtotime if it's:
719 // - not numeric ( like a unixtimestamp )
720 // - date format: yyyymmdd ( format used by ACF ) must start with 19xx or 20xx and is 8 long
721
722 // @todo: in theory a numeric string of 8 can also be a unixtimestamp.
723 // we need to replace this with an option to mark a date as unixtimestamp.
724 if ( ! is_numeric( $date ) || ( is_numeric( $date ) && strlen( trim( $date ) ) == 8 && ( strpos( $date, '20' ) === 0 || strpos( $date, '19' ) === 0 ) ) ) {
725 $date = strtotime( $date );
726 }
727
728 return $date;
729 }
730
731 /**
732 * Get date - Value method
733 *
734 * @since 1.3.1
735 *
736 * @param string $date
737 * @return string Formatted date
738 */
739 protected function get_date( $date, $format = '' ) {
740
741 if ( ! $date = $this->get_timestamp( $date ) )
742 return false;
743
744 if ( ! $format )
745 $format = get_option( 'date_format' );
746
747 return date_i18n( $format, $date );
748 }
749
750 /**
751 * Get time - Value method
752 *
753 * @since 1.3.1
754 *
755 * @param string $date
756 * @return string Formatted time
757 */
758 protected function get_time( $date, $format = '' ) {
759
760 if( ! $date = $this->get_timestamp( $date ) )
761 return false;
762
763 if ( ! $format )
764 $format = get_option( 'time_format' );
765
766 return date_i18n( $format, $date );
767 }
768
769 /**
770 * Label view
771 *
772 * @since 2.0.0
773 *
774 * @param string $field_key
775 * @return string Attribute Name
776 */
777 function label_view( $label, $description = '', $pointer = '' ) {
778 ?>
779 <td class="label">
780 <label for="<?php $this->attr_id( $pointer ); ?>">
781 <?php echo stripslashes( $label ); ?>
782
783 <?php if( $description ) : ?><p class="description"><?php echo $description; ?></p><?php endif; ?>
784 </label>
785 </td>
786 <?php
787 }
788
789 /**
790 * Display field Date Format
791 *
792 * @since 2.0.0
793 *
794 * @param bool $is_hidden Hides the table row by adding the class 'hidden'.
795 */
796 function display_field_date_format( $is_hidden = false ) {
797
798 $field_key = 'date_format';
799 $label = __( 'Date Format', 'cpac' );
800 $description = __( 'This will determine how the date will be displayed.', 'cpac' );
801
802 ?>
803 <tr class="column_<?php echo $field_key; ?>"<?php echo $is_hidden ? " style='display:none'" : ''; ?>>
804 <?php $this->label_view( $label, $description, $field_key ); ?>
805 <td class="input">
806 <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"/>
807 <p class="description">
808 <?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' ); ?>
809 <a target='_blank' href='http://codex.wordpress.org/Formatting_Date_and_Time'><?php _e( 'Documentation on date and time formatting.', 'cpac' ); ?></a>
810 </p>
811 </td>
812 </tr>
813
814 <?php
815 }
816
817 /**
818 * Display field Excerpt
819 *
820 * @since 2.0.0
821 *
822 * @param bool $is_hidden Hides the table row by adding the class 'hidden'.
823 */
824 function display_field_excerpt_length( $is_hidden = false ) {
825
826 $field_key = 'excerpt_length';
827 $label = __( 'Excerpt length', 'cpac' );
828 $description = __( 'Number of words', 'cpac' );
829
830 ?>
831 <tr class="column_<?php echo $field_key; ?>"<?php echo $is_hidden ? " style='display:none'" : ''; ?>>
832 <?php $this->label_view( $label, $description, $field_key ); ?>
833 <td class="input">
834 <input type="text" name="<?php $this->attr_name( $field_key ); ?>" id="<?php $this->attr_id( $field_key ); ?>" value="<?php echo $this->options->excerpt_length; ?>"/>
835 </td>
836 </tr>
837 <?php
838 }
839
840 /**
841 * Display field Preview Size
842 *
843 * @since 2.0.0
844 *
845 * @param bool $is_hidden Hides the table row by adding the class 'hidden'.
846 */
847 function display_field_preview_size( $is_hidden = false ) {
848
849 $field_key = 'image_size';
850 $label = __( 'Preview size', 'cpac' );
851
852 ?>
853 <tr class="column_<?php echo $field_key; ?>"<?php echo $is_hidden ? " style='display:none'" : ''; ?>>
854
855 <?php $this->label_view( $label, '', $field_key ); ?>
856
857 <td class="input">
858 <?php foreach ( $sizes = $this->get_all_image_sizes() as $id => $image_label ) : ?>
859 <label for="<?php $this->attr_id( $field_key ); ?>-<?php echo $id ?>" class="custom-size">
860 <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 ); ?>>
861 <?php echo $image_label; ?>
862 </label>
863 <?php endforeach; ?>
864
865 <div class="custom_image_size">
866 <label for="<?php $this->attr_id( $field_key ); ?>-custom" class="custom-size image-size-custom" >
867 <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' ); ?>
868 </label>
869 <label for="<?php $this->attr_id( $field_key ); ?>-w" class="custom-size-w<?php echo $this->options->image_size != 'cpac-custom' ? ' hidden' : ''; ?>">
870 <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' ); ?>
871 </label>
872 <label for="<?php $this->attr_id( $field_key ); ?>-h" class="custom-size-h<?php echo $this->options->image_size != 'cpac-custom' ? ' hidden' : ''; ?>">
873 <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' ); ?>
874 </label>
875 </div>
876 </td>
877 </tr>
878 <?php
879 }
880
881 /**
882 * Display field Preview Size
883 *
884 * @since 2.1.1
885 */
886 function display_field_before_after() {
887 ?>
888 <tr class="column_before">
889 <?php $this->label_view( __( "Before", 'cpac' ), __( 'This text will appear before the custom field value.', 'cpac' ), 'before' ); ?>
890 <td class="input">
891 <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 ) ); ?>"/>
892 </td>
893 </tr>
894 <tr class="column_after">
895 <?php $this->label_view( __( "After", 'cpac' ), __( 'This text will appear after the custom field value.', 'cpac' ), 'after' ); ?>
896 <td class="input">
897 <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 ) ); ?>"/>
898 </td>
899 </tr>
900 <?php
901 }
902
903 /**
904 * Get column list
905 *
906 * @since 2.0.0
907 *
908 * @param array Column Objects
909 * @return string HTML List
910 */
911 public function get_column_list( $columns = array(), $label = '' ) {
912
913 if ( empty( $columns ) )
914 return false;
915
916 $list = '';
917
918 // sort by alphabet
919 $_columns = array();
920 foreach ( $columns as $column ) {
921 $_columns[ $column->properties->type ] = 0 === strlen( strip_tags( $column->properties->label ) ) ? ucfirst( $column->properties->type ) : $column->properties->label;
922 }
923 asort( $_columns );
924
925 $list = "<optgroup label='{$label}'>";
926 foreach ( $_columns as $type => $label ){
927 $selected = selected( $this->properties->type, $type, false );
928 $list .= "<option value='{$type}'{$selected}>{$label}</option>";
929 }
930 $list .= "</optgroup>";
931
932 return $list;
933 }
934
935 /**
936 * Display
937 *
938 * @since 2.0.0
939 */
940 public function display() {
941
942 // classes
943 $classes = implode( ' ', array_filter( array ( "cpac-box-{$this->properties->type}", $this->properties->classes ) ) );
944
945 // column list
946 $column_list = $this->get_column_list( $this->storage_model->custom_columns, __( 'Custom', 'cpac' ) );
947 $column_list .= $this->get_column_list( $this->storage_model->default_columns, __( 'Default', 'cpac' ) );
948
949 // clone attribute
950 $data_clone = $this->properties->is_cloneable ? " data-clone='{$this->properties->clone}'" : '';
951
952 ?>
953 <div class="cpac-column <?php echo $classes; ?>" data-type="<?php echo $this->properties->type; ?>"<?php echo $data_clone; ?>>
954 <input type="hidden" class="column-name" name="<?php echo $this->attr_name( 'column-name' ); ?>" value="<?php echo esc_attr( $this->properties->name ); ?>" />
955 <input type="hidden" class="type" name="<?php echo $this->attr_name( 'type' ); ?>" value="<?php echo $this->properties->type; ?>" />
956 <input type="hidden" class="clone" name="<?php echo $this->attr_name( 'clone' ); ?>" value="<?php echo $this->properties->clone; ?>" />
957 <div class="column-meta">
958 <table class="widefat">
959 <tbody>
960 <tr>
961 <td class="column_sort"></td>
962 <td class="column_label">
963 <div class="inner">
964 <div class="meta">
965
966 <?php do_action( 'cac/column/label', $this ); ?>
967
968 </div>
969 <a class="toggle" href="javascript:;"><?php echo stripslashes( $this->get_label() ); ?></a>
970 <a class="edit-button" href="javascript:;"><?php _e( 'Edit', 'cpac' ); ?></a>
971 <a class="remove-button" href="javascript:;"><?php _e( 'Remove', 'cpac' ); ?></a>
972 </div>
973 </td>
974 <td class="column_type">
975 <div class="inner">
976 <a href="#"><?php echo stripslashes( $this->properties->label ); ?></a>
977 </div>
978 </td>
979 <td class="column_edit"></td>
980 </tr>
981 </tbody>
982 </table>
983 </div><!--.column-meta-->
984
985 <div class="column-form">
986 <table class="widefat">
987 <tbody>
988 <tr class="column_type">
989 <?php $this->label_view( __( 'Type', 'cpac' ), __( 'Choose a column type.', 'cpac' ) . '<em>' . __('ID','cpac') . ': ' . $this->properties->type . '</em>', 'type' ); ?>
990 <td class="input">
991 <select name="<?php $this->attr_name( 'type' ); ?>" id="<?php $this->attr_id( 'type' ); ?>">
992 <?php echo $column_list; ?>
993 </select>
994 <div class="msg"></div>
995 </td>
996 </tr><!--.column_label-->
997
998 <tr class="column_label<?php echo $this->properties->hide_label ? ' hidden' : ''; ?>">
999 <?php $this->label_view( __( 'Label', 'cpac' ), __( 'This is the name which will appear as the column header.', 'cpac' ), 'label' ); ?>
1000 <td class="input">
1001 <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 ); ?>" />
1002 </td>
1003 </tr><!--.column_label-->
1004
1005 <tr class="column_width">
1006 <?php $this->label_view( __( 'Width', 'cpac' ), '', 'width' ); ?>
1007 <td class="input">
1008 <div class="description width-decription" title="<?php _e( 'default', 'cpac' ); ?>">
1009 <?php echo $this->options->width > 0 ? $this->options->width . '%' : __( 'default', 'cpac' ); ?>
1010 </div>
1011 <div class="input-width-range"></div>
1012 <input type="hidden" class="input-width" name="<?php $this->attr_name( 'width' ); ?>" id="<?php $this->attr_id( 'width' ); ?>" value="<?php echo $this->options->width; ?>" />
1013
1014 </td>
1015 </tr><!--.column_width-->
1016
1017 <?php do_action( 'cac/column/settings_before', $this ); ?>
1018
1019 <?php
1020 /**
1021 * Load specific column settings.
1022 *
1023 */
1024 $this->display_settings();
1025
1026 ?>
1027
1028 <?php do_action( 'cac/column/settings_after', $this ); ?>
1029
1030 <tr class="column_action">
1031 <td colspan="2">
1032 <p>
1033 <a href="javascript:;" class="remove-button"><?php _e( 'Remove' );?></a>
1034 </p>
1035 </td>
1036 </tr>
1037
1038 </tbody>
1039 </table>
1040 </div><!--.column-form-->
1041 </div><!--.cpac-column-->
1042 <?php
1043
1044 }
1045 }