BlockController
2 months ago
BlockBase.php
2 months ago
GridHoverLayout.php
2 months ago
GridLayout.php
2 months ago
ListLayout.php
2 months ago
RttpgRow.php
2 years ago
SectionTitle.php
1 year ago
GridHoverLayout.php
210 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 GridHoverLayout 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_hover'; |
| 19 | $this->block_type = 'rttpg/tpg-grid-hover-layout'; |
| 20 | $this->attribute_args = [ |
| 21 | 'prefix' => $this->prefix, |
| 22 | 'default_layout' => 'grid_hover-layout1', |
| 23 | ]; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Register Block |
| 28 | * |
| 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 | * All Attribute |
| 54 | * Content Tab | Settings Tab | Style Tab |
| 55 | */ |
| 56 | $content_attribute = ContentTabController::get_controller( $this->attribute_args ); |
| 57 | $settings_attribute = SettingsTabController::get_controller(); |
| 58 | $style_attribute = StyleTabController::get_controller(); |
| 59 | |
| 60 | return array_merge( $content_attribute, $settings_attribute, $style_attribute ); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @param array $data |
| 65 | * |
| 66 | * @return false|string |
| 67 | */ |
| 68 | public function render_block( $data ) { |
| 69 | $this->get_script_depends( $data ); |
| 70 | |
| 71 | $_prefix = $data['prefix']; |
| 72 | |
| 73 | if ( ! rtTPG()->hasPro() && ! in_array( |
| 74 | $data[ $_prefix . '_layout' ], |
| 75 | [ |
| 76 | 'grid_hover-layout1', |
| 77 | 'grid_hover-layout2', |
| 78 | 'grid_hover-layout3', |
| 79 | ], |
| 80 | true |
| 81 | ) ) { |
| 82 | $data[ $_prefix . '_layout' ] = 'grid_hover-layout1'; |
| 83 | } |
| 84 | |
| 85 | // Query. |
| 86 | $query_args = $this->post_query_guten( $data, $_prefix ); |
| 87 | if ( 'current_query' == $data['post_type'] && is_archive() ) { |
| 88 | global $wp_query; |
| 89 | $query = $wp_query; |
| 90 | } else { |
| 91 | $query = new \WP_Query( $query_args ); |
| 92 | } |
| 93 | |
| 94 | $rand = wp_rand(); |
| 95 | $layoutID = 'rt-tpg-container-' . $rand; |
| 96 | $posts_per_page = $data['display_per_page'] ?: ( 'show' == $data['show_pagination'] ? get_option( 'posts_per_page' ) : $data['post_limit'] ); |
| 97 | |
| 98 | /** |
| 99 | * Get Post Data for render post |
| 100 | */ |
| 101 | |
| 102 | $post_data = Fns::get_render_data_set( $data, $query->max_num_pages, $posts_per_page, $_prefix, 'yes' ); |
| 103 | |
| 104 | // Category Source if exists |
| 105 | if ( isset( $data['category_source'] ) ) { |
| 106 | $post_data[ $data['post_type'] . '_taxonomy' ] = $data['category_source']; |
| 107 | } |
| 108 | // Tag source |
| 109 | if ( isset( $data['tag_source'] ) ) { |
| 110 | $post_data[ $data['post_type'] . '_tags' ] = $data['tag_source']; |
| 111 | } |
| 112 | |
| 113 | $template_path = Fns::tpg_template_path( $post_data, 'gutenberg' ); |
| 114 | $_layout = $data[ $_prefix . '_layout' ]; |
| 115 | $dynamicClass = Fns::get_dynamic_class_gutenberg( $data ); |
| 116 | |
| 117 | /** |
| 118 | * Post type render |
| 119 | */ |
| 120 | ob_start(); |
| 121 | ?> |
| 122 | <div class="<?php echo esc_attr( $dynamicClass ); ?>"> |
| 123 | <div class="rt-container-fluid rt-tpg-container tpg-el-main-wrapper tpg-gutenberg clearfix <?php echo esc_attr( $_layout . '-main' ); ?>" |
| 124 | id="<?php echo esc_attr( $layoutID ); ?>" |
| 125 | data-layout="<?php echo esc_attr( $data[ $_prefix . '_layout' ] ); ?>" |
| 126 | data-grid-style="<?php echo esc_attr( $data['grid_layout_style'] ); ?>" data-sc-id="elementor" |
| 127 | data-el-settings='<?php echo Fns::is_filter_enable( $data ) ? esc_attr( htmlspecialchars( wp_json_encode( $post_data ) ) ) : ''; ?>' |
| 128 | data-el-query='<?php echo Fns::is_filter_enable( $data ) ? esc_attr( htmlspecialchars( wp_json_encode( $query_args ) ) ) : ''; ?>' |
| 129 | data-el-path='<?php echo Fns::is_filter_enable( $data ) ? esc_attr( $template_path ) : ''; ?>'> |
| 130 | <?php |
| 131 | |
| 132 | $settings = get_option( rtTPG()->options['settings'] ); |
| 133 | if ( isset( $settings['tpg_load_script'] ) || isset( $settings['tpg_enable_preloader'] ) ) { |
| 134 | ?> |
| 135 | <div id="bottom-script-loader" class="bottom-script-loader"> |
| 136 | <div class="rt-ball-clip-rotate"> |
| 137 | <div></div> |
| 138 | </div> |
| 139 | </div> |
| 140 | <?php |
| 141 | } |
| 142 | |
| 143 | $wrapper_class = []; |
| 144 | if ( in_array( |
| 145 | $_layout, |
| 146 | [ |
| 147 | 'grid_hover-layout6', |
| 148 | 'grid_hover-layout7', |
| 149 | 'grid_hover-layout8', |
| 150 | 'grid_hover-layout9', |
| 151 | 'grid_hover-layout10', |
| 152 | 'grid_hover-layout11', |
| 153 | 'grid_hover-layout5-2', |
| 154 | 'grid_hover-layout6-2', |
| 155 | 'grid_hover-layout7-2', |
| 156 | 'grid_hover-layout9-2', |
| 157 | ] |
| 158 | ) ) { |
| 159 | $wrapper_class[] = 'grid_hover-layout5'; |
| 160 | } |
| 161 | $wrapper_class[] = str_replace( '-2', '', $_layout ); |
| 162 | $wrapper_class[] = 'tpg-even grid-behaviour'; |
| 163 | $wrapper_class[] = $_prefix . '_layout_wrapper'; |
| 164 | |
| 165 | // section title settings |
| 166 | $is_carousel = ''; |
| 167 | if ( rtTPG()->hasPro() && 'carousel' == $data['filter_btn_style'] && 'button' == $data['filter_type'] ) { |
| 168 | $is_carousel = 'carousel'; |
| 169 | } |
| 170 | ?> |
| 171 | <div class='tpg-header-wrapper <?php echo esc_attr( $is_carousel ); ?>'> |
| 172 | <?php |
| 173 | Fns::get_section_title( $data, true ); |
| 174 | Fns::print_html( Fns::get_frontend_filter_markup( $data, 'guten' ) ); |
| 175 | ?> |
| 176 | </div> |
| 177 | <div class="rt-row rt-content-loader gutenberg-inner <?php echo esc_attr( implode( ' ', $wrapper_class ) ); ?>"> |
| 178 | <?php |
| 179 | if ( $query->have_posts() ) { |
| 180 | $pCount = 1; |
| 181 | while ( $query->have_posts() ) { |
| 182 | $query->the_post(); |
| 183 | set_query_var( 'tpg_post_count', $pCount ); |
| 184 | set_query_var( 'tpg_total_posts', $query->post_count ); |
| 185 | Fns::tpg_template( $post_data, 'gutenberg' ); |
| 186 | $pCount ++; |
| 187 | } |
| 188 | } else { |
| 189 | if ( $data['no_posts_found_text'] ) { |
| 190 | printf( "<div class='no_posts_found_text'>%s</div>", esc_html( $data['no_posts_found_text'] ) ); |
| 191 | } else { |
| 192 | printf( "<div class='no_posts_found_text'>%s</div>", esc_html__( 'No post found', 'the-post-grid' ) ); |
| 193 | } |
| 194 | } |
| 195 | wp_reset_postdata(); |
| 196 | ?> |
| 197 | </div> |
| 198 | |
| 199 | <?php Fns::print_html( Fns::get_pagination_markup( $query, $data ) ); ?> |
| 200 | |
| 201 | </div> |
| 202 | </div> |
| 203 | <?php |
| 204 | |
| 205 | do_action( 'tpg_elementor_script' ); |
| 206 | |
| 207 | return ob_get_clean(); |
| 208 | } |
| 209 | |
| 210 | } |