| 1 |
<?php |
| 2 |
|
| 3 |
class WPUPG_Template_Container extends WPUPG_Template_Block { |
| 4 |
|
| 5 |
public $editorField = 'container'; |
| 6 |
|
| 7 |
public function __construct( $type = 'container' ) |
| 8 |
{ |
| 9 |
parent::__construct( $type ); |
| 10 |
|
| 11 |
// This is always the starting point of the template |
| 12 |
$this->parent = -1; |
| 13 |
$this->row = 0; |
| 14 |
$this->column = 0; |
| 15 |
$this->order = 0; |
| 16 |
} |
| 17 |
|
| 18 |
public function output( $post, $args = array() ) |
| 19 |
{ |
| 20 |
if( !$this->output_block( $post, $args ) ) return ''; |
| 21 |
|
| 22 |
$this->add_style( 'position', '' ); // Make sure position is handled by Isotope |
| 23 |
|
| 24 |
// Default arguments |
| 25 |
$args['desktop'] = true; |
| 26 |
$args['max_width'] = 9999; |
| 27 |
$args['max_height'] = 9999; |
| 28 |
|
| 29 |
$args['max_width'] = $this->max_width && $args['max_width'] > $this->max_width ? $this->max_width : $args['max_width']; |
| 30 |
$args['max_height'] = $this->max_height && $args['max_height'] > $this->max_height ? $this->max_height : $args['max_height']; |
| 31 |
|
| 32 |
if( isset( $args['classes'] ) ) { |
| 33 |
$this->classes = $args['classes']; |
| 34 |
} |
| 35 |
|
| 36 |
if( isset( $post->term ) && $post->term ) { |
| 37 |
$link = get_term_link( intval( $post->ID ), $post->post_type ); |
| 38 |
$custom_link = get_term_meta( intval( $post->ID ), 'wpupg_custom_link', true ); |
| 39 |
$custom_link_behaviour = get_term_meta( intval( $post->ID ), 'wpupg_custom_link_behaviour', true ); |
| 40 |
$image = intval( get_term_meta( intval( $post->ID ), 'wpupg_custom_image', true ) ); |
| 41 |
$image_url = $image ? wp_get_attachment_url( $image ) : ''; |
| 42 |
} else { |
| 43 |
$link = get_permalink( $post->ID ); |
| 44 |
$custom_link = trim( get_post_meta( $post->ID, 'wpupg_custom_link', true ) ); |
| 45 |
$custom_link_behaviour = trim( get_post_meta( $post->ID, 'wpupg_custom_link_behaviour', true ) ); |
| 46 |
$image = $post->post_type == 'attachment' ? $post->ID : get_post_thumbnail_id( $post->ID ); |
| 47 |
$image_url = $image ? wp_get_attachment_url( $image ) : ''; |
| 48 |
} |
| 49 |
|
| 50 |
$output = $this->before_output(); |
| 51 |
|
| 52 |
ob_start(); |
| 53 |
?> |
| 54 |
<div id="wpupg-container-post-<?php echo $post->ID; ?>" |
| 55 |
data-id="<?php echo $post->ID; ?>" |
| 56 |
data-permalink="<?php echo esc_attr( $link ); ?>" |
| 57 |
data-custom-link="<?php echo esc_attr( $custom_link ); ?>" |
| 58 |
data-custom-link-behaviour="<?php echo esc_attr( $custom_link_behaviour ); ?>" |
| 59 |
data-image="<?php echo esc_attr( $image_url ); ?>" |
| 60 |
<?php echo $this->style(); ?>> |
| 61 |
<?php $this->output_children( $post, 0, 0, $args ) ?> |
| 62 |
</div> |
| 63 |
<?php |
| 64 |
$output .= ob_get_contents(); |
| 65 |
ob_end_clean(); |
| 66 |
|
| 67 |
return $this->after_output( $output, $post ); |
| 68 |
} |
| 69 |
} |