Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/bdthemes-element-pack/modules/post-list/module.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
namespace ElementPack\Modules\PostList;
3
+
4
+
use ElementPack\Base\Element_Pack_Module_Base;
5
+
use ElementPack\Traits\Global_Terms_Query_Controls;
6
+
7
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
8
+
9
+
class Module extends Element_Pack_Module_Base {
10
+
use Global_Terms_Query_Controls;
11
+
12
+
public function __construct() {
13
+
parent::__construct();
14
+
15
+
add_action('wp_ajax_bdt_post_list', [$this, 'bdt_post_list_callback']);
16
+
add_action('wp_ajax_nopriv_bdt_post_list', [$this, 'bdt_post_list_callback']);
17
+
}
18
+
19
+
public function get_name() {
20
+
return 'post-list';
21
+
}
22
+
23
+
public function get_widgets() {
24
+
25
+
$widgets = [
26
+
'Post_List',
27
+
];
28
+
29
+
return $widgets;
30
+
}
31
+
32
+
public function get_tab_output($output) {
33
+
$tags = [
34
+
'div' => ['class' => [], 'data-separator' => [], 'id' => []],
35
+
'a' => ['href' => [], 'target' => [], 'class' => [], 'data-bdt-tooltip' => []],
36
+
'span' => ['class' => [], 'style' => []],
37
+
'i' => ['class' => [], 'aria-hidden' => []],
38
+
'img' => ['src' => [], 'class' => []],
39
+
'h3' => [
40
+
'class' => []
41
+
],
42
+
];
43
+
44
+
if (isset($output)) {
45
+
echo wp_kses($output, $tags);
46
+
}
47
+
}
48
+
49
+
function bdt_post_list_callback() {
50
+
if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_key( wp_unslash($_POST['nonce']) ), 'element-pack-site')) {
51
+
wp_send_json_error(['message' => 'Security check failed'], 403);
52
+
exit;
53
+
}
54
+
55
+
$settings = isset($_POST['settings']) ? map_deep( wp_unslash( $_POST['settings'] ), 'sanitize_text_field' ) : [];
56
+
57
+
// Restrict Allowed Post Types
58
+
$allowed_post_types = ['post', 'page', 'campaign', 'lightbox_library', 'tribe_events', 'product', 'portfolio', 'faq', 'bdthemes-testimonial', 'bdthemes-testimonial', 'knowledge_base'];
59
+
$post_type = isset($_POST['post_type']) ? sanitize_text_field( wp_unslash($_POST['post_type']) ) : 'post';
60
+
61
+
if (!in_array($post_type, $allowed_post_types)) {
62
+
wp_send_json_error(['message' => 'Invalid post type'], 403);
63
+
exit;
64
+
}
65
+
66
+
// Restrict posts_per_page to Prevent DoS
67
+
$posts_per_page = isset($settings['posts_per_page']) ? intval($settings['posts_per_page']) : 6;
68
+
$posts_per_page = min($posts_per_page, 50); // Max 50
69
+
70
+
$category_slug = isset($_POST['category']) ? sanitize_text_field( wp_unslash($_POST['category']) ) : '';
71
+
72
+
// Visibility
73
+
$show_title = isset($_POST['showHide']['show_title']) ? sanitize_text_field( wp_unslash($_POST['showHide']['show_title']) ) : '';
74
+
$show_category = isset($_POST['showHide']['show_category']) ? sanitize_text_field( wp_unslash($_POST['showHide']['show_category']) ) : '';
75
+
$show_image = isset($_POST['showHide']['show_image']) ? sanitize_text_field( wp_unslash($_POST['showHide']['show_image']) ) : '';
76
+
$icon = isset($_POST['showHide']['icon']) ? sanitize_text_field( wp_unslash($_POST['showHide']['icon']) ) : '';
77
+
$show_date = isset($_POST['showHide']['show_date']) ? sanitize_text_field( wp_unslash($_POST['showHide']['show_date']) ) : '';
78
+
$bdt_link_new_tab = isset($_POST['showHide']['bdt_link_new_tab']) ? sanitize_text_field( wp_unslash($_POST['showHide']['bdt_link_new_tab']) ) : '';
79
+
$human_diff_time = isset($_POST['showHide']['human_diff_time']) ? sanitize_text_field( wp_unslash($_POST['showHide']['human_diff_time']) ) : '';
80
+
$human_diff_time_short = isset($_POST['showHide']['human_diff_time_short']) ? sanitize_text_field( wp_unslash($_POST['showHide']['human_diff_time_short']) ) : '';
81
+
82
+
// Settings
83
+
$taxonomy = isset($settings['taxonomy']) ? sanitize_text_field( wp_unslash($settings['taxonomy']) ) : '';
84
+
$order = isset($settings['order']) ? sanitize_text_field( wp_unslash($settings['order']) ) : '';
85
+
$orderby = isset($settings['orderby']) ? sanitize_text_field( wp_unslash($settings['orderby']) ) : '';
86
+
87
+
// Get include/exclude term IDs for "ALL" filter
88
+
$include_term_ids = isset($settings['posts_include_term_ids']) ? $settings['posts_include_term_ids'] : '';
89
+
$exclude_term_ids = isset($settings['posts_exclude_term_ids']) ? $settings['posts_exclude_term_ids'] : '';
90
+
91
+
// Create a unique transient key
92
+
// $transient_key = 'bdt_post_list_' . md5(serialize([$category_slug, $post_type, $order, $orderby, $posts_per_page]));
93
+
94
+
// Try to get cached response
95
+
// $response = get_transient($transient_key);
96
+
97
+
// If no cached response, proceed with the query and cache it
98
+
// if (false === $response) {
99
+
$ajaxposts = $this->bdt_get_posts_by_ajax($post_type, $order, $orderby, $posts_per_page, $taxonomy, $category_slug, $include_term_ids, $exclude_term_ids);
100
+
$response = '';
101
+
102
+
if ($ajaxposts->have_posts()) {
103
+
$item_index = 1;
104
+
while ($ajaxposts->have_posts()) :
105
+
if ($item_index > $posts_per_page) {
106
+
break;
107
+
}
108
+
$ajaxposts->the_post();
109
+
110
+
$post_link = get_permalink();
111
+
$image_src = wp_get_attachment_image_url(get_post_thumbnail_id(), 'full');
112
+
$category = element_pack_get_category_list($post_type, ', ');
113
+
114
+
if ($human_diff_time == 'yes') {
115
+
$date = element_pack_post_time_diff(($human_diff_time_short == 'yes') ? 'short' : '');
116
+
} else {
117
+
$date = get_the_date();
118
+
}
119
+
120
+
$placeholder_image_src = \Elementor\Utils::get_placeholder_image_src();
121
+
$image_src = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
122
+
if (!$image_src) {
123
+
$image_src = $placeholder_image_src;
124
+
} else {
125
+
$image_src = $image_src[0];
126
+
}
127
+
128
+
if ($bdt_link_new_tab == 'yes') {
129
+
$target = '_blank';
130
+
} else {
131
+
$target = '_self';
132
+
}
133
+
134
+
// Output structure for each post
135
+
$response .= '<div class="bdt-item-wrap bdt-flex">';
136
+
$response .= '<div class="bdt-item bdt-flex bdt-flex-middle">';
137
+
138
+
if ($icon) {
139
+
$response .= '<div class="bdt-list-icon">';
140
+
$response .= '<i class="'. esc_attr($icon) .'"></i>';
141
+
$response .= '</div>';
142
+
}
143
+
144
+
if ('yes' == $show_image) {
145
+
$response .= '<div class="bdt-image bdt-flex">';
146
+
$response .= '<a href="' . esc_url($post_link) . '"><img src="' . esc_url($image_src) . '" alt="' . get_the_title() . '"></a>';
147
+
$response .= '</div>';
148
+
}
149
+
150
+
$response .= '<div class="bdt-content">';
151
+
152
+
if ('yes' == $show_title) {
153
+
$response .= '<h3 class="bdt-title"><a href="' . esc_url($post_link) . '" class="bdt-link" target="'. $target .'">' . get_the_title() . '</a></h3>';
154
+
}
155
+
156
+
if ('yes' == $show_category || 'yes' == $show_date) {
157
+
$response .= '<div class="bdt-meta bdt-subnav bdt-flex-middle">';
158
+
if ($show_date == 'yes') {
159
+
$response .= '<span class="bdt-date">' . $date . '</span>';
160
+
}
161
+
if ($show_category == 'yes') {
162
+
$response .= '<span class="bdt-category">' . $category . '</span>';
163
+
}
164
+
$response .= '</div>';
165
+
}
166
+
167
+
$response .= '</div>';
168
+
$response .= '</div>';
169
+
$response .= '</div>';
170
+
171
+
$item_index++;
172
+
endwhile;
173
+
174
+
// Set the transient with the generated response
175
+
// set_transient($transient_key, $response, 6 * HOUR_IN_SECONDS); // Cache for 6 hours
176
+
} else {
177
+
$response = 'empty';
178
+
}
179
+
180
+
wp_reset_postdata();
181
+
// }
182
+
183
+
$this->get_tab_output($response);
184
+
exit();
185
+
}
186
+
187
+
}
188
+