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 / widgets / TB_Archive_Pagination / TB_Archive_Pagination.php

TB_Archive_Pagination.php in King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder 51.1.86, at includes/widgets/TB_Archive_Pagination/TB_Archive_Pagination.php

346 lines 9.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Theme Builder Archive Pagination widget (Free).
4 *
5 * @package King_Addons
6 */
7
8 namespace King_Addons;
9
10 use Elementor\Controls_Manager;
11 use Elementor\Group_Control_Typography;
12 use Elementor\Widget_Base;
13
14 if (!defined('ABSPATH')) {
15 exit;
16 }
17
18 /**
19 * Outputs pagination for the current archive query.
20 */
21 class TB_Archive_Pagination extends Widget_Base
22 {
23 /**
24 * Widget slug.
25 *
26 * @return string
27 */
28 public function get_name(): string
29 {
30 return 'king-addons-tb-archive-pagination';
31 }
32
33 /**
34 * Widget title.
35 *
36 * @return string
37 */
38 public function get_title(): string
39 {
40 return esc_html__('TB - Archive Pagination', 'king-addons');
41 }
42
43 /**
44 * Widget icon.
45 *
46 * @return string
47 */
48 public function get_icon(): string
49 {
50 return 'king-addons-icon king-addons-tb-archive-pagination';
51 }
52
53 /**
54 * Style dependencies.
55 *
56 * @return array<int, string>
57 */
58 public function get_style_depends(): array
59 {
60 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-tb-archive-pagination-style'];
61 }
62
63 /**
64 * Script dependencies.
65 *
66 * @return array<int, string>
67 */
68 public function get_script_depends(): array
69 {
70 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-tb-archive-pagination-script'];
71 }
72
73 /**
74 * Categories.
75 *
76 * @return array<int, string>
77 */
78 public function get_categories(): array
79 {
80 return ['king-addons-theme-builder'];
81 }
82
83 /**
84 * Keywords.
85 *
86 * @return array<int, string>
87 */
88 public function get_keywords(): array
89 {
90 return ['pagination', 'archive', 'navigation', 'king-addons'];
91 }
92
93 public function get_custom_help_url()
94 {
95 return 'mailto:[email protected]?subject=Bug Report - King Addons&body=Please describe the issue';
96 }
97
98 /**
99 * Register controls.
100 *
101 * @return void
102 */
103 public function register_controls(): void
104 {
105 $this->register_content_controls(false);
106 $this->register_style_controls(false);
107 $this->register_pro_notice_controls();
108 }
109
110 /**
111 * Render output.
112 *
113 * @return void
114 */
115 public function render(): void
116 {
117 $settings = $this->get_settings_for_display();
118 $this->render_output($settings, false);
119 }
120
121 /**
122 * Content controls.
123 *
124 * @param bool $is_pro Whether Pro controls are enabled.
125 *
126 * @return void
127 */
128 protected function register_content_controls(bool $is_pro): void
129 {
130 $this->start_controls_section(
131 'kng_content_section',
132 [
133 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Content', 'king-addons'),
134 'tab' => Controls_Manager::TAB_CONTENT,
135 ]
136 );
137
138 $this->add_control(
139 'kng_type',
140 [
141 'label' => esc_html__('Type', 'king-addons'),
142 'type' => Controls_Manager::SELECT,
143 'default' => 'numbers',
144 'options' => [
145 'numbers' => esc_html__('Numbers', 'king-addons'),
146 'prev_next' => esc_html__('Previous/Next', 'king-addons'),
147 'numbers_prev_next' => esc_html__('Numbers + Prev/Next', 'king-addons'),
148 ],
149 ]
150 );
151
152 $this->add_control(
153 'kng_prev_label',
154 [
155 'label' => esc_html__('Previous Label', 'king-addons'),
156 'type' => Controls_Manager::TEXT,
157 'dynamic' => ['active' => true],
158 'default' => esc_html__('Previous', 'king-addons'),
159 ]
160 );
161
162 $this->add_control(
163 'kng_next_label',
164 [
165 'label' => esc_html__('Next Label', 'king-addons'),
166 'type' => Controls_Manager::TEXT,
167 'dynamic' => ['active' => true],
168 'default' => esc_html__('Next', 'king-addons'),
169 ]
170 );
171
172 $this->add_control(
173 'kng_show_first_last',
174 [
175 'label' => $is_pro ?
176 esc_html__('Show First/Last', 'king-addons') :
177 sprintf(__('Show First/Last %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
178 'type' => Controls_Manager::SWITCHER,
179 'return_value' => 'yes',
180 'default' => '',
181 'classes' => $is_pro ? '' : 'king-addons-pro-control',
182 ]
183 );
184
185 $this->end_controls_section();
186 }
187
188 /**
189 * Style controls.
190 *
191 * @param bool $is_pro Whether Pro controls are enabled.
192 *
193 * @return void
194 */
195 protected function register_style_controls(bool $is_pro): void
196 {
197 $this->start_controls_section(
198 'kng_style_section',
199 [
200 'label' => esc_html__('Style', 'king-addons'),
201 'tab' => Controls_Manager::TAB_STYLE,
202 ]
203 );
204
205 $this->add_group_control(
206 Group_Control_Typography::get_type(),
207 [
208 'name' => 'kng_typography',
209 'selector' => '{{WRAPPER}} .king-addons-tb-archive-pagination',
210 ]
211 );
212
213 $this->add_control(
214 'kng_color',
215 [
216 'label' => esc_html__('Text Color', 'king-addons'),
217 'type' => Controls_Manager::COLOR,
218 'selectors' => [
219 '{{WRAPPER}} .king-addons-tb-archive-pagination a, {{WRAPPER}} .king-addons-tb-archive-pagination span' => 'color: {{VALUE}};',
220 ],
221 ]
222 );
223
224 $this->add_control(
225 'kng_active_color',
226 [
227 'label' => esc_html__('Active Color', 'king-addons'),
228 'type' => Controls_Manager::COLOR,
229 'selectors' => [
230 '{{WRAPPER}} .king-addons-tb-archive-pagination .current' => 'color: {{VALUE}};',
231 ],
232 ]
233 );
234
235 $this->add_responsive_control(
236 'kng_alignment',
237 [
238 'label' => esc_html__('Alignment', 'king-addons'),
239 'type' => Controls_Manager::CHOOSE,
240 'options' => [
241 'left' => [
242 'title' => esc_html__('Left', 'king-addons'),
243 'icon' => 'eicon-text-align-left',
244 ],
245 'center' => [
246 'title' => esc_html__('Center', 'king-addons'),
247 'icon' => 'eicon-text-align-center',
248 ],
249 'right' => [
250 'title' => esc_html__('Right', 'king-addons'),
251 'icon' => 'eicon-text-align-right',
252 ],
253 ],
254 'selectors_dictionary' => [
255 'left' => 'justify-content: flex-start; text-align: left;',
256 'center' => 'justify-content: center; text-align: center;',
257 'right' => 'justify-content: flex-end; text-align: right;',
258 ],
259 'selectors' => [
260 // The list is display:flex; text-align alone leaves pills on the left.
261 '{{WRAPPER}} .king-addons-tb-archive-pagination' => '{{VALUE}}',
262 ],
263 ]
264 );
265
266 $this->end_controls_section();
267 }
268
269 /**
270 * Pro upsell.
271 *
272 * @return void
273 */
274 protected function register_pro_notice_controls(): void
275 {
276 if (king_addons_freemius()->can_use_premium_code__premium_only()) {
277 return;
278 }
279
280 Core::renderProFeaturesSection(
281 $this,
282 '',
283 Controls_Manager::RAW_HTML,
284 'tb-archive-pagination',
285 [
286 'First/last page links',
287 'Additional skins and hover states',
288 ]
289 );
290 }
291
292 /**
293 * Render output helper.
294 *
295 * @param array<string, mixed> $settings Settings.
296 * @param bool $is_pro Pro flag.
297 *
298 * @return void
299 */
300 protected function render_output(array $settings, bool $is_pro): void
301 {
302 global $wp_query;
303 if (!$wp_query instanceof \WP_Query || $wp_query->max_num_pages <= 1) {
304 return;
305 }
306
307 $type = $settings['kng_type'] ?? 'numbers';
308 $links = paginate_links(
309 [
310 'type' => 'array',
311 'mid_size' => 1,
312 'prev_next' => in_array($type, ['prev_next', 'numbers_prev_next'], true),
313 'prev_text' => esc_html($settings['kng_prev_label'] ?? ''),
314 'next_text' => esc_html($settings['kng_next_label'] ?? ''),
315 ]
316 );
317
318 if (empty($links)) {
319 return;
320 }
321
322 if ('prev_next' === $type) {
323 $links = array_values(array_filter($links, static function ($link) {
324 return is_string($link) && (bool) preg_match('/class="[^"]*\b(prev|next)\b/', $link);
325 }));
326 }
327
328 $show_first_last = $is_pro && ('yes' === ($settings['kng_show_first_last'] ?? ''));
329 $current = max(1, get_query_var('paged'));
330 $max = (int) $wp_query->max_num_pages;
331
332 if ($show_first_last && $current > 1) {
333 array_unshift($links, '<a class="page-numbers" href="' . esc_url(get_pagenum_link(1)) . '">&laquo;</a>');
334 }
335 if ($show_first_last && $current < $max) {
336 $links[] = '<a class="page-numbers" href="' . esc_url(get_pagenum_link($max)) . '">&raquo;</a>';
337 }
338
339 echo '<div class="king-addons-tb-archive-pagination">';
340 foreach ($links as $link) {
341 echo wp_kses_post($link);
342 }
343 echo '</div>';
344 }
345 }
346