PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.86
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.86
51.1.86 51.1.84 51.1.85 51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 All 40 releases
king-addons / includes / extensions / Smart_Links / templates / view-links.php

view-links.php in King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder 51.1.86, at includes/extensions/Smart_Links/templates/view-links.php

281 lines 14.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Smart Links list view.
4 *
5 * @package King_Addons
6 */
7
8 if (!defined('ABSPATH')) {
9 exit;
10 }
11
12 $status_filter = isset($_GET['status']) ? sanitize_key($_GET['status']) : '';
13 $tag_filter = isset($_GET['tag']) ? sanitize_text_field(wp_unslash($_GET['tag'])) : '';
14 $search = isset($_GET['s']) ? sanitize_text_field(wp_unslash($_GET['s'])) : '';
15 $date_from = isset($_GET['date_from']) ? sanitize_text_field(wp_unslash($_GET['date_from'])) : '';
16 $date_to = isset($_GET['date_to']) ? sanitize_text_field(wp_unslash($_GET['date_to'])) : '';
17
18 if ($date_from && !preg_match('/^\d{4}-\d{2}-\d{2}$/', $date_from)) {
19 $date_from = '';
20 }
21 if ($date_to && !preg_match('/^\d{4}-\d{2}-\d{2}$/', $date_to)) {
22 $date_to = '';
23 }
24
25 $args = [
26 'post_type' => \King_Addons\Smart_Links\Smart_Links::POST_TYPE,
27 'post_status' => 'any',
28 'posts_per_page' => 50,
29 'orderby' => 'date',
30 'order' => 'DESC',
31 ];
32
33 $meta_query = [];
34
35 if ($status_filter !== '') {
36 $meta_query[] = [
37 'key' => \King_Addons\Smart_Links\Smart_Links::META_STATUS,
38 'value' => $status_filter,
39 ];
40 }
41
42 if ($tag_filter !== '') {
43 $meta_query[] = [
44 'key' => \King_Addons\Smart_Links\Smart_Links::META_TAGS,
45 'value' => '"' . $tag_filter . '"',
46 'compare' => 'LIKE',
47 ];
48 }
49
50 if ($search !== '') {
51 $meta_query[] = [
52 'relation' => 'OR',
53 [
54 'key' => \King_Addons\Smart_Links\Smart_Links::META_SLUG,
55 'value' => $search,
56 'compare' => 'LIKE',
57 ],
58 [
59 'key' => \King_Addons\Smart_Links\Smart_Links::META_DESTINATION,
60 'value' => $search,
61 'compare' => 'LIKE',
62 ],
63 ];
64 }
65
66 if (!empty($meta_query)) {
67 $args['meta_query'] = $meta_query;
68 }
69
70 if ($date_from || $date_to) {
71 $args['date_query'] = [
72 'inclusive' => true,
73 ];
74 if ($date_from) {
75 $args['date_query']['after'] = $date_from;
76 }
77 if ($date_to) {
78 $args['date_query']['before'] = $date_to;
79 }
80 }
81
82 $query = new WP_Query($args);
83 $links = $query->posts;
84
85 $base_url = admin_url('admin.php?page=king-addons-smart-links&view=links');
86 ?>
87
88 <div class="ka-filter-bar">
89 <form method="get" action="<?php echo esc_url($base_url); ?>" style="display: contents;">
90 <input type="hidden" name="page" value="king-addons-smart-links">
91 <input type="hidden" name="view" value="links">
92 <label>
93 <?php esc_html_e('Status', 'king-addons'); ?>
94 <select name="status">
95 <option value=""><?php esc_html_e('All', 'king-addons'); ?></option>
96 <option value="active" <?php selected($status_filter, 'active'); ?>><?php esc_html_e('Active', 'king-addons'); ?></option>
97 <option value="disabled" <?php selected($status_filter, 'disabled'); ?>><?php esc_html_e('Disabled', 'king-addons'); ?></option>
98 </select>
99 </label>
100 <label>
101 <?php esc_html_e('Tag', 'king-addons'); ?>
102 <input type="text" name="tag" value="<?php echo esc_attr($tag_filter); ?>" placeholder="<?php esc_attr_e('campaign', 'king-addons'); ?>">
103 </label>
104 <label>
105 <?php esc_html_e('From', 'king-addons'); ?>
106 <input type="date" name="date_from" value="<?php echo esc_attr($date_from); ?>">
107 </label>
108 <label>
109 <?php esc_html_e('To', 'king-addons'); ?>
110 <input type="date" name="date_to" value="<?php echo esc_attr($date_to); ?>">
111 </label>
112 <label>
113 <?php esc_html_e('Search', 'king-addons'); ?>
114 <input type="search" name="s" value="<?php echo esc_attr($search); ?>" placeholder="slug or url">
115 </label>
116 <button type="submit" class="button"><?php esc_html_e('Filter', 'king-addons'); ?></button>
117 <?php if ($status_filter || $tag_filter || $date_from || $date_to || $search) : ?>
118 <a href="<?php echo esc_url($base_url); ?>" class="button"><?php esc_html_e('Reset', 'king-addons'); ?></a>
119 <?php endif; ?>
120 </form>
121 </div>
122
123 <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
124 <input type="hidden" name="action" value="kng_smart_links_bulk">
125 <?php wp_nonce_field('kng_smart_links_bulk'); ?>
126
127 <div class="ka-card">
128 <div class="ka-card-header">
129 <span class="dashicons dashicons-admin-links green"></span>
130 <h2><?php esc_html_e('All Links', 'king-addons'); ?></h2>
131 </div>
132 <div class="ka-card-body" style="padding: 18px 20px;">
133 <div class="ka-bulk-actions">
134 <label>
135 <input type="checkbox" id="kng-select-all" />
136 <?php esc_html_e('Select all', 'king-addons'); ?>
137 </label>
138 <select name="bulk_action">
139 <option value=""><?php esc_html_e('Bulk actions', 'king-addons'); ?></option>
140 <option value="enable"><?php esc_html_e('Enable', 'king-addons'); ?></option>
141 <option value="disable"><?php esc_html_e('Disable', 'king-addons'); ?></option>
142 <option value="add_tag"><?php esc_html_e('Add tag', 'king-addons'); ?></option>
143 <option value="export"><?php esc_html_e('Export CSV', 'king-addons'); ?></option>
144 <option value="delete"><?php esc_html_e('Delete', 'king-addons'); ?></option>
145 </select>
146 <input type="text" name="bulk_tag" placeholder="<?php esc_attr_e('Tag name', 'king-addons'); ?>">
147 <button type="submit" class="ka-btn ka-btn-secondary ka-btn-sm"><?php esc_html_e('Apply', 'king-addons'); ?></button>
148 </div>
149 </div>
150 <div class="ka-card-body" style="padding: 0;">
151 <?php if (empty($links)) : ?>
152 <div class="ka-empty">
153 <span class="dashicons dashicons-admin-links"></span>
154 <p><?php esc_html_e('No smart links found.', 'king-addons'); ?></p>
155 </div>
156 <?php else : ?>
157 <table class="ka-table">
158 <thead>
159 <tr>
160 <th></th>
161 <th><?php esc_html_e('Title', 'king-addons'); ?></th>
162 <th><?php esc_html_e('Short URL', 'king-addons'); ?></th>
163 <th><?php esc_html_e('Destination', 'king-addons'); ?></th>
164 <th class="text-center"><?php esc_html_e('Clicks', 'king-addons'); ?></th>
165 <th class="text-center"><?php esc_html_e('Unique', 'king-addons'); ?></th>
166 <th><?php esc_html_e('Tags', 'king-addons'); ?></th>
167 <th><?php esc_html_e('Status', 'king-addons'); ?></th>
168 <th><?php esc_html_e('Created', 'king-addons'); ?></th>
169 <th><?php esc_html_e('Actions', 'king-addons'); ?></th>
170 </tr>
171 </thead>
172 <tbody>
173 <?php foreach ($links as $link) :
174 $slug = (string) get_post_meta($link->ID, \King_Addons\Smart_Links\Smart_Links::META_SLUG, true);
175 $short_url = $service->build_short_url($slug);
176 $destination = (string) get_post_meta($link->ID, \King_Addons\Smart_Links\Smart_Links::META_DESTINATION, true);
177 $status = (string) get_post_meta($link->ID, \King_Addons\Smart_Links\Smart_Links::META_STATUS, true);
178 $tags = (array) get_post_meta($link->ID, \King_Addons\Smart_Links\Smart_Links::META_TAGS, true);
179 $clicks = (int) get_post_meta($link->ID, \King_Addons\Smart_Links\Smart_Links::META_CLICKS, true);
180 $unique = (int) get_post_meta($link->ID, \King_Addons\Smart_Links\Smart_Links::META_UNIQUE_CLICKS, true);
181
182 $edit_url = add_query_arg([
183 'page' => 'king-addons-smart-links',
184 'view' => 'add',
185 'link_id' => $link->ID,
186 ], admin_url('admin.php'));
187
188 $analytics_url = add_query_arg([
189 'page' => 'king-addons-smart-links',
190 'view' => 'analytics',
191 'link_id' => $link->ID,
192 ], admin_url('admin.php'));
193
194 $duplicate_url = wp_nonce_url(
195 add_query_arg([
196 'action' => 'kng_smart_links_duplicate',
197 'link_id' => $link->ID,
198 ], admin_url('admin-post.php')),
199 'kng_smart_links_duplicate_' . $link->ID
200 );
201
202 $delete_url = wp_nonce_url(
203 add_query_arg([
204 'action' => 'kng_smart_links_delete',
205 'link_id' => $link->ID,
206 ], admin_url('admin-post.php')),
207 'kng_smart_links_delete_' . $link->ID
208 );
209
210 $toggle_status = $status === 'disabled' ? 'active' : 'disabled';
211 $toggle_url = wp_nonce_url(
212 add_query_arg([
213 'action' => 'kng_smart_links_toggle',
214 'link_id' => $link->ID,
215 'status' => $toggle_status,
216 ], admin_url('admin-post.php')),
217 'kng_smart_links_toggle_' . $link->ID
218 );
219 ?>
220 <tr>
221 <td>
222 <input type="checkbox" class="kng-link-checkbox" name="link_ids[]" value="<?php echo esc_attr($link->ID); ?>">
223 </td>
224 <td class="ka-link-list-title">
225 <strong><?php echo esc_html($link->post_title); ?></strong>
226 <small><?php echo esc_html($slug); ?></small>
227 </td>
228 <td>
229 <div class="ka-short-url">
230 <a href="<?php echo esc_url($short_url); ?>" target="_blank" rel="noopener" class="ka-short-url-text" data-copy="<?php echo esc_attr($short_url); ?>">
231 <?php echo esc_html($short_url); ?>
232 </a>
233 <button type="button" class="ka-copy-btn" data-copy="<?php echo esc_attr($short_url); ?>">
234 <span class="dashicons dashicons-admin-page"></span>
235 <span><?php esc_html_e('Copy', 'king-addons'); ?></span>
236 </button>
237 </div>
238 </td>
239 <td>
240 <a href="<?php echo esc_url($destination); ?>" target="_blank" rel="noopener">
241 <?php echo esc_html(wp_trim_words($destination, 6, '…')); ?>
242 </a>
243 </td>
244 <td class="text-center"><?php echo esc_html(number_format_i18n($clicks)); ?></td>
245 <td class="text-center"><?php echo esc_html(number_format_i18n($unique)); ?></td>
246 <td>
247 <div class="ka-tags">
248 <?php if (empty($tags)) : ?>
249 <span class="ka-tag-chip">—</span>
250 <?php else : ?>
251 <?php foreach ($tags as $tag) : ?>
252 <span class="ka-tag-chip"><?php echo esc_html($tag); ?></span>
253 <?php endforeach; ?>
254 <?php endif; ?>
255 </div>
256 </td>
257 <td>
258 <span class="ka-status <?php echo $status === 'disabled' ? 'ka-status-disabled' : 'ka-status-enabled'; ?>">
259 <span class="ka-status-dot"></span>
260 <?php echo $status === 'disabled' ? esc_html__('Disabled', 'king-addons') : esc_html__('Active', 'king-addons'); ?>
261 </span>
262 </td>
263 <td><?php echo esc_html(mysql2date('Y-m-d', $link->post_date)); ?></td>
264 <td>
265 <div class="ka-smart-links-actions">
266 <a href="<?php echo esc_url($edit_url); ?>"><?php esc_html_e('Edit', 'king-addons'); ?></a>
267 <a href="<?php echo esc_url($analytics_url); ?>"><?php esc_html_e('Analytics', 'king-addons'); ?></a>
268 <a href="<?php echo esc_url($toggle_url); ?>"><?php echo $status === 'disabled' ? esc_html__('Enable', 'king-addons') : esc_html__('Disable', 'king-addons'); ?></a>
269 <a href="<?php echo esc_url($duplicate_url); ?>"><?php esc_html_e('Duplicate', 'king-addons'); ?></a>
270 <a href="<?php echo esc_url($delete_url); ?>" onclick="return confirm('<?php echo esc_js(__('Delete this link?', 'king-addons')); ?>');"><?php esc_html_e('Delete', 'king-addons'); ?></a>
271 </div>
272 </td>
273 </tr>
274 <?php endforeach; ?>
275 </tbody>
276 </table>
277 <?php endif; ?>
278 </div>
279 </div>
280 </form>
281