skin-custom.php
639 lines
| 1 | <?php |
| 2 | namespace ElementorPro\Modules\Posts\Skins; |
| 3 | |
| 4 | use Elementor\Controls_Manager; |
| 5 | use Elementor\Group_Control_Box_Shadow; |
| 6 | use Elementor\Group_Control_Image_Size; |
| 7 | use Elementor\Group_Control_Typography; |
| 8 | use Elementor\Widget_Base; |
| 9 | use ElementorPro\Plugin; |
| 10 | use ElementorPro\Modules\ThemeBuilder\Module as ThemeBuilderModule; |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 13 | |
| 14 | class Skin_Posts_ECS extends Skin_Base { |
| 15 | |
| 16 | // private $template_cache=[]; |
| 17 | private $used_templates=[]; |
| 18 | private $pid; |
| 19 | public $settings; |
| 20 | public $conditions; |
| 21 | public $grid=[]; |
| 22 | public $grid_settings=[ |
| 23 | 'length' => 0, |
| 24 | 'current' => 0, |
| 25 | 'allow' => false, |
| 26 | ]; |
| 27 | |
| 28 | |
| 29 | public function get_id() { |
| 30 | return 'custom'; |
| 31 | } |
| 32 | |
| 33 | public function get_title() { |
| 34 | return __( 'Custom', 'ele-custom-skin' ); |
| 35 | } |
| 36 | |
| 37 | private function admin_bar_menu(){ |
| 38 | foreach($this->used_templates as $post_id){ |
| 39 | \ECS_Admin_Bar_Menu::add_document($post_id); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | protected function _register_controls_actions() { |
| 44 | parent::_register_controls_actions(); |
| 45 | add_action( 'elementor/element/posts/'.$this->get_id().'_section_design_layout/after_section_end', [ $this, 'register_navigation_design_controls' ] ); |
| 46 | add_action( 'elementor/element/posts/section_pagination/after_section_end', [ $this, 'register_navigation_controls' ] ); |
| 47 | } |
| 48 | public function register_navigation_controls() { |
| 49 | do_action( 'ECS_after_pagination_controls', $this ); |
| 50 | } |
| 51 | public function register_navigation_design_controls() { |
| 52 | do_action( 'ECS_after_style_controls', $this ); |
| 53 | } |
| 54 | |
| 55 | public function register_controls( Widget_Base $widget ) { |
| 56 | |
| 57 | $this->parent = $widget; |
| 58 | |
| 59 | $this->add_control( |
| 60 | 'skin_template', |
| 61 | [ |
| 62 | 'label' => __( 'Select a default template', 'ele-custom-skin' ), |
| 63 | 'description' => '<div style="text-align:center;"><a target="_blank" style="text-align: center;font-style: normal;" href="' . esc_url( admin_url( '/edit.php?post_type=elementor_library&tabs_group=theme&elementor_library_type=loop' ) ) . |
| 64 | '" class="elementor-button elementor-button-default elementor-repeater-add">' . |
| 65 | __( 'Create/edit a Loop Template', 'ele-custom-skin' ) . '</a></div>', |
| 66 | 'type' => Controls_Manager::SELECT2, |
| 67 | 'label_block' => true, |
| 68 | 'default' => [], |
| 69 | 'options' => $this->get_skin_template(), |
| 70 | ] |
| 71 | ); |
| 72 | |
| 73 | |
| 74 | $this->add_control(//this would make use of 100% if width |
| 75 | 'view', |
| 76 | [ |
| 77 | 'label' => __( 'View', 'ele-custom-skin' ), |
| 78 | 'type' => \Elementor\Controls_Manager::HIDDEN, |
| 79 | 'default' => 'top', |
| 80 | 'prefix_class' => 'elementor-posts--thumbnail-', |
| 81 | ] |
| 82 | ); |
| 83 | |
| 84 | $this->add_control( |
| 85 | 'use_custom_grid', |
| 86 | [ |
| 87 | 'label' => __( 'Use custom grid?', 'ele-custom-skin' ), |
| 88 | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 89 | 'label_off' => __( 'No', 'ele-custom-skin' ), |
| 90 | 'label_on' => __( 'Yes', 'ele-custom-skin' ), |
| 91 | 'return_value' => 'yes', |
| 92 | 'separator' => 'before', |
| 93 | 'default' =>'', |
| 94 | |
| 95 | ] |
| 96 | ); |
| 97 | |
| 98 | $this->add_control( |
| 99 | 'custom_grid', |
| 100 | [ |
| 101 | 'label' => __( 'Select a default template', 'ele-custom-skin' ), |
| 102 | 'description' => '<div style="text-align:center;"><a target="_blank" style="text-align: center;font-style: normal;" href="' . esc_url( admin_url( '/edit.php?post_type=elementor_library&tabs_group=theme&elementor_library_type=custom_grid' ) ) . |
| 103 | '" class="elementor-button elementor-button-default elementor-repeater-add">' . |
| 104 | __( 'Create/edit a Custom Grid', 'ele-custom-skin' ) . '</a></div>', |
| 105 | 'type' => Controls_Manager::SELECT2, |
| 106 | 'label_block' => true, |
| 107 | 'default' => [], |
| 108 | 'options' => $this->get_custom_grid(), |
| 109 | 'condition' => [ |
| 110 | $this->get_id().'_use_custom_grid' => 'yes' |
| 111 | ], |
| 112 | ] |
| 113 | ); |
| 114 | |
| 115 | do_action( 'ECS_after_control', $this ); |
| 116 | |
| 117 | $this->add_control( |
| 118 | 'hr2', |
| 119 | [ |
| 120 | 'type' => \Elementor\Controls_Manager::DIVIDER, |
| 121 | ] |
| 122 | ); |
| 123 | |
| 124 | parent::register_controls($widget); |
| 125 | |
| 126 | $this->remove_control( 'img_border_radius' ); |
| 127 | $this->remove_control( 'meta_data' ); |
| 128 | $this->remove_control( 'item_ratio' ); |
| 129 | $this->remove_control( 'image_width' ); |
| 130 | $this->remove_control( 'show_title' ); |
| 131 | $this->remove_control( 'title_tag' ); |
| 132 | $this->remove_control( 'masonry' ); |
| 133 | $this->remove_control( 'thumbnail' ); |
| 134 | $this->remove_control( 'thumbnail_size' ); |
| 135 | $this->remove_control( 'show_read_more' ); |
| 136 | $this->remove_control( 'read_more_text' ); |
| 137 | $this->remove_control( 'show_excerpt' ); |
| 138 | $this->remove_control( 'excerpt_length' ); |
| 139 | $this->remove_control( 'open_new_tab' ); |
| 140 | |
| 141 | } |
| 142 | private function get_post_id(){ |
| 143 | return $this->pid; |
| 144 | } |
| 145 | public function get_skin_template(){ |
| 146 | global $wpdb; |
| 147 | $templates = $wpdb->get_results( |
| 148 | "SELECT $wpdb->term_relationships.object_id as ID, $wpdb->posts.post_title as post_title FROM $wpdb->term_relationships |
| 149 | INNER JOIN $wpdb->term_taxonomy ON |
| 150 | $wpdb->term_relationships.term_taxonomy_id=$wpdb->term_taxonomy.term_taxonomy_id |
| 151 | INNER JOIN $wpdb->terms ON |
| 152 | $wpdb->term_taxonomy.term_id=$wpdb->terms.term_id AND $wpdb->terms.slug='loop' |
| 153 | INNER JOIN $wpdb->posts ON |
| 154 | $wpdb->term_relationships.object_id=$wpdb->posts.ID |
| 155 | WHERE $wpdb->posts.post_status='publish'" |
| 156 | ); |
| 157 | $options = [ 0 => 'Select a template' ]; |
| 158 | foreach ( $templates as $template ) { |
| 159 | $options[ $template->ID ] = $template->post_title; |
| 160 | } |
| 161 | return $options; |
| 162 | } |
| 163 | |
| 164 | |
| 165 | public function get_custom_grid(){ |
| 166 | global $wpdb; |
| 167 | $templates = $wpdb->get_results( |
| 168 | "SELECT $wpdb->term_relationships.object_id as ID, $wpdb->posts.post_title as post_title FROM $wpdb->term_relationships |
| 169 | INNER JOIN $wpdb->term_taxonomy ON |
| 170 | $wpdb->term_relationships.term_taxonomy_id=$wpdb->term_taxonomy.term_taxonomy_id |
| 171 | INNER JOIN $wpdb->terms ON |
| 172 | $wpdb->term_taxonomy.term_id=$wpdb->terms.term_id AND $wpdb->terms.slug='custom_grid' |
| 173 | INNER JOIN $wpdb->posts ON |
| 174 | $wpdb->term_relationships.object_id=$wpdb->posts.ID |
| 175 | WHERE $wpdb->posts.post_status='publish'" |
| 176 | ); |
| 177 | $options = [ 0 => 'Select a template' ]; |
| 178 | foreach ( $templates as $template ) { |
| 179 | $options[ $template->ID ] = $template->post_title; |
| 180 | } |
| 181 | return $options; |
| 182 | } |
| 183 | |
| 184 | |
| 185 | public function render_amp() { |
| 186 | |
| 187 | } |
| 188 | |
| 189 | /*protected function set_template($skin){// this is for terms we don't need passid so we can actually add them in cache |
| 190 | |
| 191 | if (!$skin) return; |
| 192 | if (isset($this->template_cache[$skin])) return $this->template_cache[$skin]; |
| 193 | |
| 194 | $return = \Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $skin ); |
| 195 | $this->template_cache[$skin] = $return; |
| 196 | |
| 197 | }*/ |
| 198 | |
| 199 | protected function set_used_template($skin){// this is for terms we don't need passid so we can actually add them in cache |
| 200 | |
| 201 | if (!$skin) return; |
| 202 | $this->used_templates[$skin]=$skin; |
| 203 | |
| 204 | } |
| 205 | |
| 206 | protected function set_custom_grid($grid){// this is for terms we don't need passid so we can actually add them in cache |
| 207 | |
| 208 | if (!$grid) return; |
| 209 | |
| 210 | $custom_grid = \Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $grid ); |
| 211 | |
| 212 | $this->set_used_template($grid); |
| 213 | |
| 214 | $this->grid = explode('{{ecs-article}}',$custom_grid); |
| 215 | $this->grid_settings['length'] = count($this->grid); |
| 216 | |
| 217 | } |
| 218 | public function get_grid(){ |
| 219 | $grid="<!-- start part [".$this->grid_settings['current']."] -->"; |
| 220 | if($this->grid_settings['current'] >= $this->grid_settings['length']-1){ |
| 221 | $grid.=$this->grid[$this->grid_settings['current']]; |
| 222 | $this->grid_settings['current']=0; |
| 223 | } |
| 224 | // print_r($this->grid_settings); |
| 225 | $grid.=$this->grid[$this->grid_settings['current']]; |
| 226 | $grid.="<!-- end part [".$this->grid_settings['current']."] -->"; |
| 227 | $this->grid_settings['current']++; |
| 228 | return $grid; |
| 229 | } |
| 230 | public function end_grid(){ |
| 231 | |
| 232 | if($this->grid_settings['current']) for($i = $this->grid_settings['current']; $i < $this->grid_settings['length'];$i++){ |
| 233 | echo "<!-- start part [".$i."] finishing -->"; |
| 234 | echo $this->grid[$i]; |
| 235 | echo "<!-- end part [".$i."] finishing -->"; |
| 236 | } |
| 237 | $this->grid_settings['current'] = 0; |
| 238 | |
| 239 | } |
| 240 | |
| 241 | protected function get_template(){ |
| 242 | global $ecs_render_loop, $wp_query,$ecs_index; |
| 243 | $ecs_index++; |
| 244 | $old_query=$wp_query; |
| 245 | //\Elementor\Plugin::$instance->documents->switch_to_document( get_the_ID() ); |
| 246 | //\Elementor\Plugin::$instance->db->switch_to_post( get_the_ID() ); |
| 247 | $new_query=new \WP_Query( array( 'p' => get_the_ID(), 'post_type' => get_post_type() ) ); |
| 248 | $wp_query = $new_query; |
| 249 | $settings = $this->parent->get_settings(); |
| 250 | $this->pid=get_the_ID();//set the current id in private var usefull to passid |
| 251 | $default_template = $this->get_instance_value( 'skin_template' ) ; |
| 252 | $template = $default_template; |
| 253 | /* move to pro */ |
| 254 | //print_r(ThemeBuilderModule::instance()->get_conditions_manager()->get_documents_for_location( 'loop' )); |
| 255 | |
| 256 | //print_r($this->conditions->get_template());echo "aici";print_r($template); |
| 257 | |
| 258 | $template = apply_filters( 'ECS_action_template', $template,$this,$ecs_index ); |
| 259 | $template = $this->get_current_ID($template); |
| 260 | |
| 261 | $ecs_render_loop=get_the_ID().",".$template; |
| 262 | //echo $ecs_render_loop; |
| 263 | |
| 264 | |
| 265 | /* end pro */ |
| 266 | if (!$template) return; |
| 267 | |
| 268 | $this->set_used_template($template); |
| 269 | |
| 270 | $return = \Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $template ); |
| 271 | $ecs_render_loop=false; |
| 272 | //\Elementor\Plugin::$instance->documents->restore_document(); |
| 273 | $wp_query = $old_query; |
| 274 | return $return; |
| 275 | } |
| 276 | |
| 277 | //this is for multilang porpouses... curently WPML |
| 278 | private function get_current_ID($id){ |
| 279 | $newid = apply_filters( 'wpml_object_id', $id, 'elementor_library', TRUE ); |
| 280 | return $newid ? $newid : $id; |
| 281 | } |
| 282 | |
| 283 | protected function render_post_header() { |
| 284 | $classes = 'elementor-post elementor-grid-item ecs-post-loop'; |
| 285 | $parent_settings = $this->parent->get_settings(); |
| 286 | $parent_settings[$this->get_id().'_post_slider'] = isset($parent_settings[$this->get_id().'_post_slider'])? $parent_settings[$this->get_id().'_post_slider'] : ""; |
| 287 | if($parent_settings[$this->get_id().'_post_slider'] == "yes") $classes .= ' swiper-slide'; |
| 288 | if ($this->grid_settings['allow']) { |
| 289 | echo $this->get_grid(); |
| 290 | ?> |
| 291 | <div id="post-<?php the_ID(); ?>" <?php post_class( [ $classes ] ); ?>> |
| 292 | <?php |
| 293 | } |
| 294 | else { |
| 295 | ?> |
| 296 | <article id="post-<?php the_ID(); ?>" <?php post_class( [ $classes ] ); ?>> |
| 297 | <?php |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | protected function render_post_footer() { |
| 302 | if (!$this->grid_settings['allow']){ |
| 303 | ?> |
| 304 | </article> |
| 305 | <?php |
| 306 | }else { |
| 307 | ?></div><?php |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | protected function render_post() { |
| 312 | do_action( 'ECS_before_render_post_header', $this ); |
| 313 | $this->render_post_header(); |
| 314 | do_action( 'ECS_after_render_post_header', $this ); |
| 315 | |
| 316 | if ($this->get_instance_value( 'skin_template' )){ |
| 317 | if ($this->get_instance_value( 'use_keywords' ) == "yes") { |
| 318 | global $post; |
| 319 | apply_filters( 'ecs_dynamic_filter', "", $post,"",$this->parent->get_settings());//this is for pre-use of custom values |
| 320 | $template = $this->get_template(); |
| 321 | $new_template = apply_filters( 'ecs_dynamic_filter', $template, $post,"",$this->parent->get_settings()); |
| 322 | echo $new_template ? $new_template : $template; |
| 323 | } |
| 324 | else echo $this->get_template(); |
| 325 | } |
| 326 | |
| 327 | else echo '<div style="display:table;border:1px solid #c6ced5; background:#dde1e5; width:100%; height:100%; min-height:200px;text-align:center; padding:20px;"><span style="vertical-align:middle;display: table-cell;color:#8995a0;">'. |
| 328 | __( "Please select a default template! ", 'ele-custom-skin').'</span></div>'; |
| 329 | |
| 330 | do_action( 'ECS_before_render_post_footer', $this ); |
| 331 | $this->render_post_footer(); |
| 332 | do_action( 'ECS_after_render_post_footer', $this ); |
| 333 | |
| 334 | } |
| 335 | |
| 336 | protected function ajax_pagination(){ |
| 337 | $settings = $this->parent->get_settings(); |
| 338 | $theme_document = \Elementor\Plugin::$instance->documents->get_current(); |
| 339 | $page_limit = $settings['pagination_page_limit'] ? $settings['pagination_page_limit'] : 999; |
| 340 | $max_pages = $this->parent->get_query()->max_num_pages; |
| 341 | $max_num_pages = $page_limit < $max_pages ? $page_limit : $max_pages; |
| 342 | $args = [ 'current_page' => $this->parent->get_current_page(), |
| 343 | 'max_num_pages' => $max_num_pages, |
| 344 | 'load_method' => $settings['pagination_type'],//or infinitescroll for pro |
| 345 | 'widget_id' => $this->parent->get_id(), |
| 346 | 'post_id' => get_the_id(), |
| 347 | 'theme_id' => is_null($theme_document) ? '' : $theme_document->get_main_id(), |
| 348 | 'change_url' => $settings['change_url'], |
| 349 | 'reinit_js' => $settings['reinit_js'], |
| 350 | |
| 351 | ]; |
| 352 | |
| 353 | $pagination=json_encode($args); |
| 354 | return $pagination; |
| 355 | } |
| 356 | |
| 357 | protected function render_loop_header() { |
| 358 | $parent_settings = $this->parent->get_settings(); |
| 359 | $parent_settings[$this->get_id().'_post_slider'] = isset($parent_settings[$this->get_id().'_post_slider'])? $parent_settings[$this->get_id().'_post_slider'] : ""; |
| 360 | |
| 361 | if($parent_settings[$this->get_id().'_post_slider'] == "yes") { |
| 362 | echo '<div class="elementor-main-swiper swiper-container swiper">'; |
| 363 | $this->grid_settings['allow'] = false; |
| 364 | } else {// we don't use custom grid if slider is activated |
| 365 | if($parent_settings[$this->get_id().'_use_custom_grid'] == "yes" && $parent_settings[$this->get_id().'_custom_grid'] ){ |
| 366 | $this->set_custom_grid($parent_settings[$this->get_id().'_custom_grid']); |
| 367 | $this->grid_settings['allow'] = true; |
| 368 | } else $this->grid_settings['allow'] = false; |
| 369 | } |
| 370 | $this->parent->add_render_attribute( 'container', [ |
| 371 | 'class' => [ |
| 372 | 'ecs-posts', |
| 373 | 'elementor-posts-container', |
| 374 | 'elementor-posts', |
| 375 | $parent_settings[$this->get_id().'_post_slider'] == "yes" ? 'swiper-wrapper' : "", |
| 376 | $this->grid_settings['allow'] ? "ecs-custom-grid" : '', |
| 377 | $parent_settings[$this->get_id().'_post_slider'] != "yes" && !$this->grid_settings['allow'] ? 'elementor-grid':'', |
| 378 | $this->get_container_class(), |
| 379 | ], |
| 380 | 'data-settings' => [htmlentities($this->ajax_pagination(), ENT_QUOTES)], |
| 381 | ] ); |
| 382 | |
| 383 | ?> |
| 384 | <div <?php echo $this->parent->get_render_attribute_string( 'container' ); ?>> |
| 385 | <?php |
| 386 | } |
| 387 | |
| 388 | protected function render_loop_footer() { |
| 389 | |
| 390 | $this->admin_bar_menu();// let's pass the templates we used so far to tha admin-bar-menu |
| 391 | |
| 392 | $parent_settings = $this->parent->get_settings(); |
| 393 | $parent_settings[$this->get_id().'_post_slider'] = isset($parent_settings[$this->get_id().'_post_slider'])? $parent_settings[$this->get_id().'_post_slider'] : ""; |
| 394 | |
| 395 | if($this->grid_settings['allow']){ |
| 396 | $this->end_grid(); |
| 397 | } |
| 398 | |
| 399 | ?> |
| 400 | </div> |
| 401 | <?php |
| 402 | |
| 403 | if($parent_settings[$this->get_id().'_post_slider'] == "yes") { |
| 404 | $this->slider_elements(); |
| 405 | echo '</div>'; |
| 406 | |
| 407 | } |
| 408 | if ( '' === $parent_settings['pagination_type'] ) { |
| 409 | return; |
| 410 | } |
| 411 | |
| 412 | $page_limit = $this->parent->get_query()->max_num_pages; |
| 413 | if ( '' !== $parent_settings['pagination_page_limit'] ) { |
| 414 | $page_limit = min( $parent_settings['pagination_page_limit'], $page_limit ); |
| 415 | } |
| 416 | |
| 417 | if ( 2 > $page_limit ) { |
| 418 | return; |
| 419 | } |
| 420 | |
| 421 | $this->parent->add_render_attribute( 'pagination', 'class', 'elementor-pagination' ); |
| 422 | |
| 423 | $has_numbers = in_array( $parent_settings['pagination_type'], [ 'numbers', 'numbers_and_prev_next' ] ); |
| 424 | $has_prev_next = in_array( $parent_settings['pagination_type'], [ 'prev_next', 'numbers_and_prev_next' ] ); |
| 425 | |
| 426 | $links = []; |
| 427 | |
| 428 | if ( $has_numbers ) { |
| 429 | $paginate_args = [ |
| 430 | 'type' => 'array', |
| 431 | 'current' => $this->parent->get_current_page(), |
| 432 | 'total' => $page_limit, |
| 433 | 'prev_next' => false, |
| 434 | 'show_all' => 'yes' !== $parent_settings['pagination_numbers_shorten'], |
| 435 | 'before_page_number' => '<span class="elementor-screen-only">' . __( 'Page', 'elementor-pro' ) . '</span>', |
| 436 | ]; |
| 437 | |
| 438 | if ( is_singular() && ! is_front_page() ) { |
| 439 | global $wp_rewrite; |
| 440 | if ( $wp_rewrite->using_permalinks() ) { |
| 441 | $paginate_args['base'] = trailingslashit( get_permalink() ) . '%_%'; |
| 442 | $paginate_args['format'] = user_trailingslashit( '%#%', 'single_paged' ); |
| 443 | } else { |
| 444 | $paginate_args['format'] = '?page=%#%'; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | $links = paginate_links( $paginate_args ); |
| 449 | } |
| 450 | |
| 451 | if ( $has_prev_next ) { |
| 452 | $prev_next = $this->parent->get_posts_nav_link( $page_limit ); |
| 453 | array_unshift( $links, $prev_next['prev'] ); |
| 454 | $links[] = $prev_next['next']; |
| 455 | } |
| 456 | |
| 457 | ?> |
| 458 | <nav class="elementor-pagination" role="navigation" aria-label="<?php esc_attr_e( 'Pagination', 'elementor-pro' ); ?>"> |
| 459 | <?php echo implode( PHP_EOL, $links ); ?> |
| 460 | </nav> |
| 461 | <?php |
| 462 | |
| 463 | if ( 'loadmore' === $parent_settings['pagination_type'] ) { |
| 464 | $this->render_loadmore_button(); |
| 465 | } |
| 466 | if ( 'lazyload' === $parent_settings['pagination_type'] ) { |
| 467 | $this->render_lazyload_animation(); |
| 468 | } |
| 469 | |
| 470 | } |
| 471 | |
| 472 | protected function render_lazyload_animation() { |
| 473 | $settings = $this->parent->get_settings(); |
| 474 | $next_page = $this->parent->get_current_page()+1; |
| 475 | $next_page_link = trailingslashit( get_permalink() ) . '?page='.$next_page; |
| 476 | $animation = \ECS_Loading_Animation::get_lazy_load_animations_html($settings['lazyload_animation']); |
| 477 | $target= $this->parent->get_id(); |
| 478 | |
| 479 | ?> |
| 480 | <nav class="ecs-lazyload elementor-pagination" data-targetid="<?php echo $target; ?>"> |
| 481 | <?php echo $animation; ?> |
| 482 | <a href="<?php echo $next_page_link; ?>" > |
| 483 | > |
| 484 | </a> |
| 485 | </nav> |
| 486 | <?php |
| 487 | } |
| 488 | protected function render_loadmore_button() { |
| 489 | $settings = $this->parent->get_settings(); |
| 490 | $next_page = $this->parent->get_current_page()+1; |
| 491 | $next_page_link = trailingslashit( get_permalink() ) . '?page='.$next_page; |
| 492 | $class=''; |
| 493 | $args = [ 'loading_text' => $settings['loadmore_loading_text'], |
| 494 | 'text' => $settings['loadmore_text'],//or infinitescroll for pro |
| 495 | 'widget_id' => $this->parent->get_id(), |
| 496 | |
| 497 | ]; |
| 498 | |
| 499 | $data=htmlentities(json_encode($args), ENT_QUOTES); |
| 500 | |
| 501 | if ( $settings['loadmore_hover_animation'] ) { |
| 502 | $class = 'elementor-animation-' . $settings['loadmore_hover_animation']; |
| 503 | } |
| 504 | |
| 505 | ?> |
| 506 | <nav class="elementor-button-wrapper elementor-pagination ecs-load-more-button" data-settings="<?php echo $data; ?>"> |
| 507 | <a href="<?php echo $next_page_link; ?>" class="elementor-button-link elementor-button <?php echo $class; ?>" role="button"> |
| 508 | <span><?php echo $settings['loadmore_text']; ?></span> |
| 509 | </a> |
| 510 | </nav> |
| 511 | <?php |
| 512 | } |
| 513 | |
| 514 | private function slider_elements(){ |
| 515 | $this->settings = $this->parent->get_settings(); |
| 516 | do_action( 'ECS_after_slider_elements', $this ); |
| 517 | } |
| 518 | |
| 519 | private function nothing_found(){ |
| 520 | $this->render_loop_header(); |
| 521 | $should_escape = apply_filters( 'elementor_pro/theme_builder/archive/escape_nothing_found_message', true ); |
| 522 | $message = $this->parent->get_settings_for_display( 'nothing_found_message' ); |
| 523 | if ( $should_escape ) { |
| 524 | $message = esc_html( $message ); |
| 525 | } |
| 526 | |
| 527 | $message = '<div class="elementor-posts-nothing-found">' . $message . '</div>'; |
| 528 | do_action( 'ECS_not_found', $this ); |
| 529 | echo $message; |
| 530 | $this->render_loop_footer(); |
| 531 | } |
| 532 | |
| 533 | public function render() { |
| 534 | $this->parent->query_posts(); |
| 535 | |
| 536 | /** @var \WP_Query $query */ |
| 537 | $query = $this->parent->get_query(); |
| 538 | |
| 539 | do_action("ECS_before_loop_query",$query,$this); |
| 540 | |
| 541 | // start de incercat de bagat in action ECS_before_loop_query |
| 542 | if (class_exists('ECS_Conditions_Manager')) |
| 543 | if($this->get_instance_value( 'is_display_conditions' )) $this->conditions = new \ECS_Conditions_Manager(); |
| 544 | |
| 545 | // end de bagat |
| 546 | |
| 547 | |
| 548 | if ( ! $query->found_posts ) { |
| 549 | $this->nothing_found(); |
| 550 | return; |
| 551 | } |
| 552 | |
| 553 | $this->render_loop_header(); |
| 554 | |
| 555 | // It's the global `wp_query` it self. and the loop was started from the theme. |
| 556 | if ( $query->in_the_loop ) { |
| 557 | $this->current_permalink = get_permalink(); |
| 558 | $this->render_post(); |
| 559 | } else { |
| 560 | while ( $query->have_posts() ) { |
| 561 | $query->the_post(); |
| 562 | |
| 563 | $this->current_permalink = get_permalink(); |
| 564 | $this->render_post(); |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | do_action("ECS_after_loop_query",$query,$this); |
| 569 | |
| 570 | wp_reset_postdata(); |
| 571 | |
| 572 | $this->render_loop_footer(); |
| 573 | |
| 574 | } |
| 575 | |
| 576 | public function get_settings_for_display( $setting_key = null ) { |
| 577 | //let's position ourselfs inside the loop item |
| 578 | global $wp_query; |
| 579 | $old_query=$wp_query; |
| 580 | $new_query=new \WP_Query( array( 'p' => get_the_ID(), 'post_type' => get_post_type() ) ); |
| 581 | $wp_query = $new_query; |
| 582 | if ( $setting_key ) { |
| 583 | $settings = [ |
| 584 | $setting_key => $this->parent->get_settings( $setting_key ), |
| 585 | ]; |
| 586 | } else { |
| 587 | $settings = $this->parent->get_active_settings(); |
| 588 | |
| 589 | } |
| 590 | $controls=$this->parent->get_controls(); |
| 591 | $controls = array_intersect_key($controls,$settings); |
| 592 | $parsed_settings = $this->parent->parse_dynamic_settings( $settings, $controls ); |
| 593 | $wp_query = $old_query;//get out of loop item |
| 594 | if ( $setting_key ) { |
| 595 | return $parsed_settings[ $setting_key ]; |
| 596 | } |
| 597 | return $parsed_settings; |
| 598 | } |
| 599 | |
| 600 | } |
| 601 | |
| 602 | |
| 603 | // it seems the same skin brakes if set to 2 widgets in the same time |
| 604 | |
| 605 | class Skin_Archive_ECS extends Skin_Posts_ECS { |
| 606 | |
| 607 | private $template_cache=[]; |
| 608 | private $pid; |
| 609 | |
| 610 | protected function _register_controls_actions() { |
| 611 | add_action( 'elementor/element/archive-posts/section_layout/before_section_end', [ $this, 'register_controls' ] ); |
| 612 | add_action( 'elementor/element/archive-posts/section_layout/after_section_end', [ $this, 'register_style_sections' ] ); |
| 613 | |
| 614 | add_action( 'elementor/element/archive-posts/'.$this->get_id().'_section_design_layout/after_section_end', [ $this, 'register_navigation_design_controls' ] ); |
| 615 | add_action( 'elementor/element/archive-posts/section_pagination/after_section_end', [ $this, 'register_navigation_controls' ] ); |
| 616 | } |
| 617 | |
| 618 | public function get_id() { |
| 619 | return 'archive_custom'; |
| 620 | } |
| 621 | |
| 622 | public function get_title() { |
| 623 | return __( 'Custom', 'ele-custom-skin' ); |
| 624 | } |
| 625 | |
| 626 | /* Remove `posts_per_page` control */ |
| 627 | protected function register_post_count_control(){} |
| 628 | |
| 629 | } |
| 630 | |
| 631 | // Add a custom skin for the POSTS widget |
| 632 | add_action( 'elementor/widget/posts/skins_init', function( $widget ) { |
| 633 | $widget->add_skin( new Skin_Posts_ECS( $widget ) ); |
| 634 | } ); |
| 635 | // Add a custom skin for the POST Archive widget |
| 636 | add_action( 'elementor/widget/archive-posts/skins_init', function( $widget ) { |
| 637 | $widget->add_skin( new Skin_Archive_ECS( $widget ) ); |
| 638 | } ); |
| 639 |