BlockController
3 years ago
BlockBase.php
3 years ago
GridHoverLayout.php
3 years ago
GridLayout.php
3 years ago
ListLayout.php
3 years ago
RttpgRow.php
3 years ago
GridLayout.php
194 lines
| 1 | <?php |
| 2 | |
| 3 | namespace RT\ThePostGrid\Controllers\Blocks; |
| 4 | |
| 5 | use RT\ThePostGrid\Controllers\Blocks\BlockController\SettingsTabController; |
| 6 | use RT\ThePostGrid\Controllers\Blocks\BlockController\StyleTabController; |
| 7 | use RT\ThePostGrid\Controllers\Blocks\BlockController\ContentTabController; |
| 8 | use RT\ThePostGrid\Helpers\Fns; |
| 9 | |
| 10 | class GridLayout extends BlockBase { |
| 11 | |
| 12 | private $prefix; |
| 13 | private $attribute_args; |
| 14 | private $block_type; |
| 15 | |
| 16 | public function __construct() { |
| 17 | add_action( 'init', [ $this, 'register_blocks' ] ); |
| 18 | $this->prefix = 'grid'; |
| 19 | $this->block_type = 'rttpg/tpg-' . $this->prefix . '-layout'; |
| 20 | $this->attribute_args = [ |
| 21 | 'prefix' => $this->prefix, |
| 22 | 'default_layout' => 'grid-layout1' |
| 23 | ]; |
| 24 | |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Register Block |
| 29 | * @return void |
| 30 | */ |
| 31 | public function register_blocks() { |
| 32 | if ( ! function_exists( 'register_block_type' ) ) { |
| 33 | return; |
| 34 | } |
| 35 | register_block_type( |
| 36 | $this->block_type, |
| 37 | [ |
| 38 | 'attributes' => $this->get_attributes(), |
| 39 | 'render_callback' => [ $this, 'render_block' ], |
| 40 | ] |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Get attributes |
| 46 | * |
| 47 | * @param bool $default |
| 48 | * |
| 49 | * @return array |
| 50 | */ |
| 51 | public function get_attributes() { |
| 52 | |
| 53 | /** |
| 54 | * All Attribute |
| 55 | * Content Tab | Settings Tab | Style Tab |
| 56 | */ |
| 57 | $content_attribute = ContentTabController::get_controller( $this->attribute_args ); |
| 58 | $settings_attribute = SettingsTabController::get_controller(); |
| 59 | $style_attribute = StyleTabController::get_controller(); |
| 60 | |
| 61 | return array_merge( $content_attribute, $settings_attribute, $style_attribute ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @param array $data |
| 66 | * |
| 67 | * @return false|string |
| 68 | */ |
| 69 | public function render_block( $data ) { |
| 70 | |
| 71 | $this->get_script_depends( $data ); |
| 72 | |
| 73 | $_prefix = $data['prefix']; |
| 74 | |
| 75 | if ( ! rtTPG()->hasPro() && ! in_array( $data[ $_prefix . '_layout' ], [ 'grid-layout1', 'grid-layout4', 'grid-layout3' ] ) ) { |
| 76 | $data[ $_prefix . '_layout' ] = 'grid-layout1'; |
| 77 | } |
| 78 | |
| 79 | //Query |
| 80 | $query_args = $this->post_query_guten( $data, $_prefix ); |
| 81 | $query = new \WP_Query( $query_args ); |
| 82 | $rand = mt_rand(); |
| 83 | $layoutID = "rt-tpg-container-" . $rand; |
| 84 | $posts_per_page = $data['display_per_page'] ? $data['display_per_page'] : $data['post_limit']; |
| 85 | |
| 86 | /** |
| 87 | * Get Post Data for render post |
| 88 | */ |
| 89 | |
| 90 | $post_data = Fns::get_render_data_set( $data, $query->max_num_pages, $posts_per_page, $_prefix, 'yes' ); |
| 91 | |
| 92 | /** |
| 93 | * Post type render |
| 94 | */ |
| 95 | |
| 96 | //Category Source if exists |
| 97 | if ( isset( $data['category_source'] ) ) { |
| 98 | $post_data[ $data['post_type'] . '_taxonomy' ] = $data['category_source']; |
| 99 | } |
| 100 | //Tag source |
| 101 | if ( isset( $data['tag_source'] ) ) { |
| 102 | $post_data[ $data['post_type'] . '_tags' ] = $data['tag_source']; |
| 103 | } |
| 104 | |
| 105 | $template_path = Fns::tpg_template_path( $post_data, 'gutenberg' ); |
| 106 | $_layout = $data[ $_prefix . '_layout' ]; |
| 107 | $_layout_style = $data['grid_layout_style']; |
| 108 | $dynamicClass = Fns::get_dynamic_class_gutenberg( $data ); |
| 109 | |
| 110 | ob_start(); |
| 111 | ?> |
| 112 | <div class="<?php echo esc_attr( $dynamicClass ) ?>"> |
| 113 | <div class="rt-container-fluid rt-tpg-container tpg-el-main-wrapper clearfix <?php echo esc_attr( $_layout . '-main' ); ?>" |
| 114 | id="<?php echo esc_attr( $layoutID ); ?>" |
| 115 | data-layout="<?php echo esc_attr( $data[ $_prefix . '_layout' ] ); ?>" |
| 116 | data-grid-style="<?php echo esc_attr( $data['grid_layout_style'] ); ?>" data-sc-id="elementor" |
| 117 | data-el-settings='<?php echo Fns::is_filter_enable( $data ) ? htmlspecialchars( wp_json_encode( $post_data ) ) : ''; ?>' |
| 118 | data-el-query='<?php echo Fns::is_filter_enable( $data ) ? htmlspecialchars( wp_json_encode( $query_args ) ) : ''; ?>' |
| 119 | data-el-path='<?php echo Fns::is_filter_enable( $data ) ? esc_attr( $template_path ) : ''; ?>'> |
| 120 | <?php |
| 121 | |
| 122 | $settings = get_option( rtTPG()->options['settings'] ); |
| 123 | if ( isset( $settings['tpg_load_script'] ) && isset( $settings['tpg_enable_preloader'] ) ) { |
| 124 | ?> |
| 125 | <div id="bottom-script-loader" class="bottom-script-loader"> |
| 126 | <div class="rt-ball-clip-rotate"> |
| 127 | <div></div> |
| 128 | </div> |
| 129 | </div> |
| 130 | <?php |
| 131 | } |
| 132 | |
| 133 | $wrapper_class = []; |
| 134 | $wrapper_class[] = str_replace( '-2', '', $_layout ); |
| 135 | $wrapper_class[] = 'grid-behaviour'; |
| 136 | $wrapper_class[] = ( in_array( $_layout, [ 'grid-layout2' ] ) ) ? "tpg-even" : $_layout_style; |
| 137 | $wrapper_class[] = $_prefix . '_layout_wrapper'; |
| 138 | if ( 'masonry' === $_layout_style && in_array( $_layout, [ |
| 139 | 'grid-layout1', |
| 140 | 'grid-layout3', |
| 141 | 'grid-layout4' |
| 142 | ] ) ) { |
| 143 | $wrapper_class[] = 'tpg-masonry'; |
| 144 | } |
| 145 | |
| 146 | if ( in_array( $_layout, [ 'grid-layout6', 'grid-layout6-2' ] ) && $data['middle_border'] === 'no' ) { |
| 147 | $wrapper_class[] = 'disable-middle-border'; |
| 148 | } |
| 149 | |
| 150 | //section title settings |
| 151 | $is_carousel = ''; |
| 152 | if ( rtTPG()->hasPro() && 'carousel' == $data['filter_btn_style'] && 'button' == $data['filter_type'] ) { |
| 153 | $is_carousel = 'carousel'; |
| 154 | } |
| 155 | |
| 156 | echo "<div class='tpg-header-wrapper {$is_carousel}'>"; |
| 157 | Fns::get_section_title( $data ); |
| 158 | Fns::print_html( Fns::get_frontend_filter_markup( $data, true ) ); |
| 159 | echo "</div>"; |
| 160 | ?> |
| 161 | |
| 162 | <div class="rt-row rt-content-loader gutenberg-inner <?php echo esc_attr( implode( ' ', $wrapper_class ) ) ?>"> |
| 163 | <?php |
| 164 | if ( $query->have_posts() ) { |
| 165 | $pCount = 1; |
| 166 | while ( $query->have_posts() ) { |
| 167 | $query->the_post(); |
| 168 | set_query_var( 'tpg_post_count', $pCount ); |
| 169 | set_query_var( 'tpg_total_posts', $query->post_count ); |
| 170 | Fns::tpg_template( $post_data, 'gutenberg' ); |
| 171 | $pCount ++; |
| 172 | } |
| 173 | } else { |
| 174 | if ( $data['no_posts_found_text'] ) { |
| 175 | printf( "<div class='no_posts_found_text'>%s</div>", esc_html( $data['no_posts_found_text'] ) ); |
| 176 | } else { |
| 177 | printf( "<div class='no_posts_found_text'>%s</div>", esc_html__( 'No post found', 'the-post-grid' ) ); |
| 178 | } |
| 179 | } |
| 180 | wp_reset_postdata(); |
| 181 | ?> |
| 182 | </div> |
| 183 | |
| 184 | <?php echo Fns::get_pagination_markup( $query, $data ); ?> |
| 185 | |
| 186 | </div> |
| 187 | </div> |
| 188 | <?php |
| 189 | |
| 190 | do_action( 'tpg_elementor_script' ); |
| 191 | |
| 192 | return ob_get_clean(); |
| 193 | } |
| 194 | } |