PluginProbe
ECS – Ele Custom Skin for Elementor / 4.3.9
ECS – Ele Custom Skin for Elementor v4.3.9
4.3.11 4.3.10 4.3.9 4.3.8 4.3.7 4.3.6 4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.11 4.1.10 4.1.9 4.1.8 4.1.6 4.1.7 4.1.5 4.1.4 4.1.1 4.1.2 trunk 1.0.0 All 57 releases
ele-custom-skin / includes / ajax-pagination.php
ajax-pagination.php
568 lines 18.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
4 class ECS_Ajax_Load {
5 private $post_id='';
6 private $current_page=1;
7 private $widget_id='';
8 private $theme_id='';
9 private $query=[];
10
11 public function __construct($args=[]) {//["post_id"=>2,"current_page"=>2,"max_num_pages"=>5,"widget_id"=>"65054a0"]
12
13 $this->init();
14
15 if (!isset($args['post_id']))//debug line comment it
16 if(!isset($_POST['ecs_ajax_settings'])) return;
17 else $args = json_decode( stripslashes( $_POST['ecs_ajax_settings'] ), true );
18
19 $this->post_id = $args['post_id'];
20 $this->current_page = $args['current_page'] + 1;
21 $this->widget_id = $args['widget_id'];
22 $this->theme_id = isset($args['theme_id']) ? $args['theme_id'] : $args['post_id'];
23 $this->query = json_decode( stripslashes( $_POST['query'] ), true );
24 if ($this->current_page > $args['max_num_pages']) return;
25 $this->init_ajax();
26
27 }
28
29 public function init() {
30 add_action( 'wp_enqueue_scripts', [$this,'enqueue_scripts'] ,99);
31 add_action( 'elementor/element/before_section_end', [$this,'post_pagination'],10,3);
32 add_action( 'elementor/element/after_section_end', [$this,'button_pagination_style'],10,3);
33 }
34
35 public function init_ajax(){
36 //add_action( 'wp_footer',[$this,'get_document_data'],99);// debug line comment it
37 add_action( 'wp_ajax_ecsload', [$this,'get_document_data']);
38 add_action( 'wp_ajax_nopriv_ecsload', [$this,'get_document_data']);
39 }
40
41 public function post_pagination($element, $section_id='', $args=''){
42
43 if ( ( 'archive-posts' === $element->get_name() || 'posts' === $element->get_name() ) && 'section_pagination' === $section_id ) {
44
45 $element->remove_control( 'pagination_type' );
46
47 $element->add_control(
48 'pagination_type',
49 [
50 'label' => __( 'Pagination', 'ele-custom-skin' ),
51 'type' => \Elementor\Controls_Manager::SELECT,
52 'default' => '',
53 'options' => [
54 '' => __( 'None', 'elementor-pro' ),
55 'numbers' => __( 'Numbers', 'elementor-pro' ),
56 'loadmore' => __( 'Load More (Custom Skin)', 'ele-custom-skin' ),
57 'lazyload' => __( 'Infinite Load (Custom Skin Pro)', 'ele-custom-skin' ),
58 'prev_next' => __( 'Previous/Next', 'elementor-pro' ),
59 'numbers_and_prev_next' => __( 'Numbers', 'elementor-pro' ) . ' + ' . __( 'Previous/Next', 'elementor-pro' ),
60 ],
61 ]
62 );
63 /* lazyload stuff*/
64 $element->add_control(
65 'lazyload_title',
66 [
67 'label' => __( 'Infinite Load', 'ele-custom-skin' ),
68 'type' => \Elementor\Controls_Manager::HEADING,
69 'separator' => 'before',
70 'condition' => [
71 'pagination_type' => 'lazyload',
72 ],
73 ]
74 );
75
76 $element->add_control(
77 'lazyload_animation',
78 [
79 'label' => __( 'Loading Animation', 'ele-custom-skin' ),
80 'type' => \Elementor\Controls_Manager::SELECT,
81 'default' => 'default',
82 'options' => ECS_Loading_Animation::get_lazy_load_animations_list(),
83 'condition' => [
84 'pagination_type' => 'lazyload',
85 ],
86 ]
87 );
88 $element->add_control(
89 'lazyload_color',
90 [
91 'label' => __( 'Animation Color', 'ele-custom-skin' ),
92 'type' => \Elementor\Controls_Manager::COLOR,
93 'selectors' => [
94 '{{WRAPPER}} .ecs-lazyload .ecs-ll-brcolor' => 'border-color: {{VALUE}};',
95 '{{WRAPPER}} .ecs-lazyload .ecs-ll-bgcolor' => 'background-color: {{VALUE}} !important;',
96 ],
97 'condition' => [
98 'pagination_type' => 'lazyload',
99 ],
100 ]
101 );
102
103 $element->add_control(
104 'lazyload_spacing',
105 [
106 'label' => __( 'Animation Spacing', 'ele-custom-skin' ),
107 'type' => \Elementor\Controls_Manager::SLIDER,
108 'range' => [
109 'px' => [
110 'max' => 250,
111 ],
112 ],
113 'default' =>[
114 'unit' => 'px',
115 'size' => '20',
116 ],
117 'selectors' => [
118 '{{WRAPPER}} .ecs-lazyload' => 'margin-top: {{SIZE}}{{UNIT}};',
119 ],
120 'condition' => [
121 'pagination_type' => 'lazyload',
122 ],
123 ]
124 );
125 $element->add_control(
126 'lazyload_size',
127 [
128 'label' => __( 'Animation Size', 'ele-custom-skin' ),
129 'type' => \Elementor\Controls_Manager::SLIDER,
130 'range' => [
131 'px' => [
132 'max' => 50,
133 ],
134 ],
135 'selectors' => [
136 '{{WRAPPER}} .ecs-lazyload .ecs-lazy-load-animation' => 'font-size: {{SIZE}}{{UNIT}};',
137 ],
138 'condition' => [
139 'pagination_type' => 'lazyload',
140 ],
141 ]
142 );
143
144
145 /* load more button stuff */
146
147 $element->add_control(
148 'loadmore_title',
149 [
150 'label' => __( 'Load More Button', 'ele-custom-skin' ),
151 'type' => \Elementor\Controls_Manager::HEADING,
152 'separator' => 'before',
153 'condition' => [
154 'pagination_type' => 'loadmore',
155 ],
156 ]
157 );
158
159 $element->add_control(
160 'loadmore_text',
161 [
162 'label' => __( 'Text', 'ele-custom-skin' ),
163 'type' => \Elementor\Controls_Manager::TEXT,
164 'default' => __( 'Load More', 'elementor' ),
165 'placeholder' => __( 'Load More', 'elementor' ),
166 'condition' => [
167 'pagination_type' => 'loadmore',
168 ],
169 ]
170 );
171
172 $element->add_control(
173 'loadmore_loading_text',
174 [
175 'label' => __( 'Loading Text', 'ele-custom-skin' ),
176 'type' => \Elementor\Controls_Manager::TEXT,
177 'default' => __( 'Loading...', 'elementor' ),
178 'placeholder' => __( 'Loading...', 'elementor' ),
179 'condition' => [
180 'pagination_type' => 'loadmore',
181 ],
182 ]
183 );
184
185 $element->add_control(
186 'loadmore_spacing',
187 [
188 'label' => __( 'Button Spacing', 'ele-custom-skin' ),
189 'type' => \Elementor\Controls_Manager::SLIDER,
190 'range' => [
191 'px' => [
192 'max' => 250,
193 ],
194 ],
195 'default' =>[
196 'unit' => 'px',
197 'size' => '20',
198 ],
199 'selectors' => [
200 '{{WRAPPER}} .ecs-load-more-button .elementor-button' => 'margin-top: {{SIZE}}{{UNIT}};',
201 ],
202 'condition' => [
203 'pagination_type' => 'loadmore',
204 ],
205 ]
206 );
207 $element->add_control(
208 'change_url',
209 [
210 'label' => __( 'Change URL on ajax load?', 'ele-custom-skin' ),
211 'type' => \Elementor\Controls_Manager::SWITCHER,
212 'label_off' => __( 'No', 'ele-custom-skin' ),
213 'label_on' => __( 'Yes', 'ele-custom-skin' ),
214 'return_value' => true,
215 'separator' => 'before',
216 'default' => false,
217 ]
218 );
219
220 $element->add_control(
221 'reinit_js',
222 [
223 'label' => __( 'Reinitialize Elementor JS on Ajax Pagination?', 'ele-custom-skin' ),
224 'description' => __( 'This is used for the elements loaded through AJAX Pagination. This is experimental feature and it may not work properly.', 'ele-custom-skin'),
225 'type' => \Elementor\Controls_Manager::SWITCHER,
226 'label_off' => __( 'No', 'ele-custom-skin' ),
227 'label_on' => __( 'Yes', 'ele-custom-skin' ),
228 'return_value' => true,
229 'separator' => 'before',
230 'default' => false,
231 ]
232 );
233
234
235 }
236 }
237
238 public function button_pagination_style($element, $section_id='', $args=''){
239
240 if ( ( 'archive-posts' === $element->get_name() || 'posts' === $element->get_name() ) && 'section_pagination_style' === $section_id ) {
241
242 $element->start_controls_section(
243 'loadmore_section_style',
244 [
245 'label' => __( 'Load More Button', 'ele-custom-skin' ),
246 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
247 'condition' => [
248 'pagination_type' => 'loadmore',
249 ],
250 ]
251 );
252
253 $element->add_group_control(
254 \Elementor\Group_Control_Typography::get_type(),
255 [
256 'name' => 'loadmore_typography',
257 'global' => [
258 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Typography::TYPOGRAPHY_ACCENT,
259 ],
260 'selector' => '{{WRAPPER}} .ecs-load-more-button .elementor-button',
261 ]
262 );
263
264 $element->add_group_control(
265 \Elementor\Group_Control_Text_Shadow::get_type(),
266 [
267 'name' => 'loadmore_text_shadow',
268 'selector' => '{{WRAPPER}} .ecs-load-more-button .elementor-button',
269 ]
270 );
271
272 $element->start_controls_tabs( 'ecs_load_more_tabs_button_style' );
273
274 $element->start_controls_tab(
275 'loadmore_tab_button_normal',
276 [
277 'label' => __( 'Normal', 'ele-custom-skin' ),
278 ]
279 );
280
281 $element->add_control(
282 'loadmore_button_text_color',
283 [
284 'label' => __( 'Text Color', 'ele-custom-skin' ),
285 'type' => \Elementor\Controls_Manager::COLOR,
286 'default' => '',
287 'selectors' => [
288 '{{WRAPPER}} .ecs-load-more-button .elementor-button' => 'fill: {{VALUE}}; color: {{VALUE}};',
289 ],
290 ]
291 );
292
293 $element->add_control(
294 'loadmore_background_color',
295 [
296 'label' => __( 'Background Color', 'ele-custom-skin' ),
297 'type' => \Elementor\Controls_Manager::COLOR,
298 'global' => [
299 'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Colors::COLOR_ACCENT,
300 ],
301 'selectors' => [
302 '{{WRAPPER}} .ecs-load-more-button .elementor-button' => 'background-color: {{VALUE}};',
303 ],
304 ]
305 );
306
307 $element->end_controls_tab();
308
309 $element->start_controls_tab(
310 'loadmore_tab_button_hover',
311 [
312 'label' => __( 'Hover', 'ele-custom-skin' ),
313 ]
314 );
315
316 $element->add_control(
317 'loadmore_hover_color',
318 [
319 'label' => __( 'Text Color', 'ele-custom-skin' ),
320 'type' => \Elementor\Controls_Manager::COLOR,
321 'selectors' => [
322 '{{WRAPPER}} .ecs-load-more-button .elementor-button:hover, {{WRAPPER}} .ecs-load-more-button .elementor-button:focus' => 'color: {{VALUE}};',
323 '{{WRAPPER}} .ecs-load-more-button .elementor-button:hover svg, {{WRAPPER}} .ecs-load-more-button .elementor-button:focus svg' => 'fill: {{VALUE}};',
324 ],
325 ]
326 );
327
328 $element->add_control(
329 'loadmore_button_background_hover_color',
330 [
331 'label' => __( 'Background Color', 'ele-custom-skin' ),
332 'type' => \Elementor\Controls_Manager::COLOR,
333 'selectors' => [
334 '{{WRAPPER}} .ecs-load-more-button .elementor-button:hover, {{WRAPPER}} .elementor-button:focus' => 'background-color: {{VALUE}};',
335 ],
336 ]
337 );
338
339 $element->add_control(
340 'loadmore_button_hover_border_color',
341 [
342 'label' => __( 'Border Color', 'ele-custom-skin' ),
343 'type' => \Elementor\Controls_Manager::COLOR,
344 'condition' => [
345 'border_border!' => '',
346 ],
347 'selectors' => [
348 '{{WRAPPER}} .ecs-load-more-button .elementor-button:hover, {{WRAPPER}} .elementor-button:focus' => 'border-color: {{VALUE}};',
349 ],
350 ]
351 );
352
353 $element->add_control(
354 'loadmore_hover_animation',
355 [
356 'label' => __( 'Hover Animation', 'ele-custom-skin' ),
357 'type' => \Elementor\Controls_Manager::HOVER_ANIMATION,
358 ]
359 );
360
361 $element->end_controls_tab();
362
363 $element->end_controls_tabs();
364
365 $element->add_group_control(
366 \Elementor\Group_Control_Border::get_type(),
367 [
368 'name' => 'loadmore_border',
369 'selector' => '{{WRAPPER}} .elementor-button',
370 'separator' => 'before',
371 ]
372 );
373
374 $element->add_control(
375 'loadmore_border_radius',
376 [
377 'label' => __( 'Border Radius', 'ele-custom-skin' ),
378 'type' => \Elementor\Controls_Manager::DIMENSIONS,
379 'size_units' => [ 'px', '%' ],
380 'selectors' => [
381 '{{WRAPPER}} .ecs-load-more-button .elementor-button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
382 ],
383 ]
384 );
385
386 $element->add_group_control(
387 \Elementor\Group_Control_Box_Shadow::get_type(),
388 [
389 'name' => 'loadmore_button_box_shadow',
390 'selector' => '{{WRAPPER}} .ecs-load-more-button .elementor-button',
391 ]
392 );
393
394 $element->add_responsive_control(
395 'loadmore_text_padding',
396 [
397 'label' => __( 'Padding', 'ele-custom-skin' ),
398 'type' => \Elementor\Controls_Manager::DIMENSIONS,
399 'size_units' => [ 'px', 'em', '%' ],
400 'selectors' => [
401 '{{WRAPPER}} .ecs-load-more-button .elementor-button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
402 ],
403 'separator' => 'before',
404 ]
405 );
406 $element->end_controls_section();
407 }
408 }
409
410 private function get_element_data($id,$data){
411
412 foreach($data as $element){
413 //echo "[".$element['id']."] == (".$id.")";
414 if (isset($element['id']) && $element['id'] == $id) {
415 return $element;
416 } else {
417 //echo $element['id']." - ".count($element['elements'])." > ";//print_r($element['elements']);
418 if(count($element['elements'])) {
419 $element_children=$this->get_element_data($id,$element['elements']);
420 if ($element_children) return $element_children ;
421 }
422 //echo"am ajuns aici?";
423 }
424 }
425 return false;
426 }
427
428 public function get_document_data(){
429
430 check_ajax_referer( 'ecsload', 'nonce' );
431
432 global $wp_query;
433
434
435 $id = $this->widget_id;
436
437 $post_id = $this->post_id;
438 $theme_id = $this->theme_id;
439 $old_query = $wp_query->query_vars;
440
441 // This endpoint is reachable by anonymous visitors (wp_ajax_nopriv_ecsload),
442 // so both documents must be checked for public visibility before any of
443 // their content is loaded or returned. theme_id supplies the elements that
444 // actually get returned to the caller; post_id only supplies the wrapper
445 // used for matching in clean_response(), but is still validated here as a
446 // second line of defense since it also gets loaded and switched to.
447 if (
448 ! is_post_publicly_viewable( $theme_id ) || post_password_required( $theme_id ) ||
449 ! is_post_publicly_viewable( $post_id ) || post_password_required( $post_id )
450 ) {
451 wp_die();
452 }
453
454 $this->query['paged'] = $this->current_page; // we need current(next) page to be loaded
455 $this->query['post_status'] = 'publish';
456
457 $wp_query = new \WP_Query($this->query);
458 wp_reset_postdata();//this fixes some issues with some get_the_ID users.
459 if (is_archive()){
460 $post_id = $theme_id;
461 }
462
463 $document = \Elementor\Plugin::$instance->documents->get_doc_for_frontend( $post_id );
464 $theme_document = \Elementor\Plugin::$instance->documents->get_doc_for_frontend( $theme_id );
465
466 if ( ! $document || ! $theme_document ) {
467 wp_die();
468 }
469
470 $element_data = $this->get_element_data($id,$theme_document->get_elements_data());
471 if ( ! $element_data ) {
472 wp_die();
473 }
474 $data[] = $element_data;
475
476 // Change the current post, so widgets can use `documents->get_current`.
477 \Elementor\Plugin::$instance->documents->switch_to_document( $document );
478
479 ob_start();
480 $document->print_elements_with_wrapper( $data );
481 $content = ob_get_clean();
482 echo $this->clean_response($content,$id);
483
484 \Elementor\Plugin::$instance->documents->restore_document();
485 $wp_query->query_vars = $query_vars;
486
487 die;
488 }
489
490 private function clean_response($html,$id){
491 $content = "";
492 $dom = new DOMDocument();
493 libxml_use_internal_errors(true);
494 $dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
495 //$dom->loadHTML($html);
496 $xpath = new DOMXPath($dom);
497 $childs = $xpath->query('//div[@data-id="'.$id.'"]/div[@class="elementor-widget-container"]/div/* | //div[@data-elementor-type="custom_grid"]');
498 // $childs = $xpath->query('//div[@data-elementor-type="custom_grid"]');
499 //return $dom->saveHTML($childs->item(0));
500 foreach($childs as $child){
501 $content .= $dom->saveHTML($child);
502 }
503 //$div = $div->item(0);
504 return $content;
505 }
506
507 public function enqueue_scripts(){
508
509 global $wp_query;
510
511 wp_register_script('ecs_ajax_load', plugin_dir_url(__DIR__) . 'assets/js/ecs_ajax_pagination.js',array('jquery'),ELECS_VER);
512
513 wp_localize_script( 'ecs_ajax_load', 'ecs_ajax_params', array(
514 'ajaxurl' => site_url() . '/wp-admin/admin-ajax.php', // WordPress AJAX
515 'posts' => json_encode( $wp_query->query_vars ),
516 'nonce' => wp_create_nonce( 'ecsload' ),
517 ) );
518
519 wp_enqueue_script( 'ecs_ajax_load' );
520 }
521
522 }
523
524
525 class ECS_Loading_Animation {
526 private static function animations(){
527 return [
528 'default'=>[
529 'label' => __( 'Default', 'ele-custom-skin' ),
530 'html' => '<div class="lds-ellipsis ecs-lazy-load-animation"><div class="ecs-ll-bgcolor"></div><div class="ecs-ll-bgcolor"></div><div class="ecs-ll-bgcolor"></div><div class="ecs-ll-bgcolor"></div></div>',
531 ],
532 'progress_bar'=>[
533 'label' => __( 'Progress Bar', 'ele-custom-skin' ),
534 'html' => '<div class="barload-wrapper ecs-lazy-load-animation"><div class="barload-border ecs-ll-brcolor"><div class="barload-whitespace"><div class="barload-line ecs-ll-bgcolor"></div></div></div></div>',
535 ],
536 'running_dots'=>[
537 'label' => __( 'Running Dots', 'ele-custom-skin' ),
538 'html' => '<div class="ballsload-container ecs-lazy-load-animation"><div class="ecs-ll-bgcolor"></div><div class="ecs-ll-bgcolor"></div><div class="ecs-ll-bgcolor"></div><div class="ecs-ll-bgcolor"></div></div>',
539 ],
540 'ball_slide'=>[
541 'label' => __( 'Ball Slide', 'ele-custom-skin' ),
542 'html' => '<div id="movingBallG" class="ecs-lazy-load-animation"><div class="movingBallLineG ecs-ll-bgcolor"></div><div id="movingBallG_1" class="movingBallG ecs-ll-bgcolor"></div></div>',
543 ],
544
545 ];
546 }
547
548
549 public static function get_lazy_load_animations_html($animation){
550 $arrs = self::animations();
551 return $arrs[$animation]['html'];
552 }
553
554 public static function get_lazy_load_animations_list(){
555 $arrs = self::animations();
556 foreach ( $arrs as $key => $arr ) {
557 $options[ $key ] = $arr['label'];
558 }
559 return $options;
560 }
561
562 }
563
564
565
566 new ECS_Ajax_Load();
567
568