| 1 |
<?php |
| 2 |
|
| 3 |
class WPUPG_Template_Columns extends WPUPG_Template_Block { |
| 4 |
|
| 5 |
public $columns; |
| 6 |
public $widths; |
| 7 |
public $responsive = false; |
| 8 |
public $mobile_reverse = false; |
| 9 |
|
| 10 |
public $editorField = 'columns'; |
| 11 |
|
| 12 |
public function __construct( $type = 'columns' ) |
| 13 |
{ |
| 14 |
parent::__construct( $type ); |
| 15 |
|
| 16 |
$this->add_style( 'vertical-align', 'top', 'td' ); |
| 17 |
} |
| 18 |
|
| 19 |
public function columns( $columns ) |
| 20 |
{ |
| 21 |
$this->columns = $columns; |
| 22 |
return $this; |
| 23 |
} |
| 24 |
|
| 25 |
public function width( $widths ) |
| 26 |
{ |
| 27 |
$this->widths = $widths; |
| 28 |
foreach( $widths as $column => $width ) |
| 29 |
{ |
| 30 |
$this->add_style( 'width', $width, 'col-' . $column ); |
| 31 |
} |
| 32 |
return $this; |
| 33 |
} |
| 34 |
|
| 35 |
public function responsive( $responsive ) |
| 36 |
{ |
| 37 |
$this->responsive = $responsive; |
| 38 |
return $this; |
| 39 |
} |
| 40 |
|
| 41 |
public function mobile_reverse( $mobile_reverse ) |
| 42 |
{ |
| 43 |
$this->mobile_reverse = $mobile_reverse; |
| 44 |
return $this; |
| 45 |
} |
| 46 |
|
| 47 |
public function output( $post, $args = array() ) |
| 48 |
{ |
| 49 |
if( !$this->output_block( $post, $args ) ) return ''; |
| 50 |
|
| 51 |
$args['max_width'] = $this->max_width && $args['max_width'] > $this->max_width ? $this->max_width : $args['max_width']; |
| 52 |
$args['max_height'] = $this->max_height && $args['max_height'] > $this->max_height ? $this->max_height : $args['max_height']; |
| 53 |
$show_on_desktop = $args['desktop'] && $this->show_on_desktop; |
| 54 |
$output = $this->before_output(); |
| 55 |
|
| 56 |
ob_start(); |
| 57 |
?> |
| 58 |
<?php if( $this->responsive ) { $args['desktop'] = false; ?> |
| 59 |
<div class="wpupg-responsive-mobile"> |
| 60 |
<div<?php echo $this->style(); ?>> |
| 61 |
<?php if( $this->mobile_reverse ) { ?> |
| 62 |
<?php for( $j = $this->columns-1; $j >= 0; $j-- ) { ?> |
| 63 |
<?php if( $this->show( $post, 'col-' . $j, $args ) ) { ?> |
| 64 |
<div class="wpupg-rows-row"> |
| 65 |
<?php $this->output_children( $post, 0, $j, $args ); ?> |
| 66 |
</div> |
| 67 |
<?php } // end if show col ?> |
| 68 |
<?php } // end for cols ?> |
| 69 |
<?php } else { ?> |
| 70 |
<?php for( $j = 0; $j < $this->columns; $j++ ) { ?> |
| 71 |
<?php if( $this->show( $post, 'col-' . $j, $args ) ) { ?> |
| 72 |
<div class="wpupg-rows-row"> |
| 73 |
<?php $this->output_children( $post, 0, $j, $args ); ?> |
| 74 |
</div> |
| 75 |
<?php } // end if show col ?> |
| 76 |
<?php } // end for cols ?> |
| 77 |
<?php } // end responsive reverse ?> |
| 78 |
</div> |
| 79 |
</div> |
| 80 |
<div class="wpupg-responsive-desktop"> |
| 81 |
<?php } ?> |
| 82 |
<?php $args['desktop'] = $show_on_desktop; ?> |
| 83 |
<table<?php echo $this->style(); ?>> |
| 84 |
<tbody> |
| 85 |
<tr> |
| 86 |
<?php for( $j = 0; $j < $this->columns; $j++ ) { ?> |
| 87 |
<?php if( $this->show( $post, 'col-' . $j, $args ) ) { ?> |
| 88 |
<td<?php echo $this->style( array( 'td', 'col-' . $j ) ); ?>> |
| 89 |
<?php $this->output_children( $post, 0, $j, $args ); ?> |
| 90 |
</td> |
| 91 |
<?php } // end if show col ?> |
| 92 |
<?php } // end for cols ?> |
| 93 |
</tr> |
| 94 |
</tbody> |
| 95 |
</table> |
| 96 |
<?php if( $this->responsive ) echo '</div>'; ?> |
| 97 |
<?php |
| 98 |
$output .= ob_get_contents(); |
| 99 |
ob_end_clean(); |
| 100 |
|
| 101 |
return $this->after_output( $output, $post ); |
| 102 |
} |
| 103 |
} |