|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Integrations\Flatsome; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Controllers\AbstractController; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Database\ShortcodeOptionManager; |
|
7
|
|
|
use GeminiLabs\SiteReviews\Helpers\Cast; |
|
8
|
|
|
use GeminiLabs\SiteReviews\Helpers\Str; |
|
9
|
|
|
|
|
10
|
|
|
class Controller extends AbstractController |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @filter site-reviews/modal_wrapped_by |
|
14
|
|
|
*/ |
|
15
|
|
|
public function filterModalWrappedBy(array $builders): array |
|
16
|
|
|
{ |
|
17
|
|
|
$builders[] = 'flatsome'; |
|
18
|
|
|
return $builders; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @action wp_ajax_ux_builder_get_posts:1 |
|
23
|
|
|
*/ |
|
24
|
|
|
public function interceptGetPostsQuery(): void |
|
25
|
|
|
{ |
|
26
|
|
|
$option = filter_input(INPUT_GET, 'option'); |
|
27
|
|
|
if (!str_starts_with($option, glsr()->prefix)) { |
|
28
|
|
|
return; |
|
29
|
|
|
} |
|
30
|
|
|
$option = Str::removePrefix($option, glsr()->prefix); |
|
31
|
|
|
$postId = (string) filter_input(INPUT_GET, 'id'); |
|
32
|
|
|
check_ajax_referer("ux-builder-{$postId}", 'security'); |
|
33
|
|
|
$values = filter_input(INPUT_GET, 'values', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
34
|
|
|
if (!is_array($values)) { |
|
35
|
|
|
$values = [filter_input(INPUT_GET, 'values')]; |
|
36
|
|
|
} |
|
37
|
|
|
$items = call_user_func([glsr(ShortcodeOptionManager::class), $option], [ |
|
38
|
|
|
'include' => array_filter($values), |
|
39
|
|
|
]); |
|
40
|
|
|
$items = array_filter($items, fn ($id) => in_array($id, $values), \ARRAY_FILTER_USE_KEY); |
|
41
|
|
|
$callback = fn ($id, $title) => compact('id', 'title'); |
|
42
|
|
|
$results = array_map($callback, array_keys($items), array_values($items)); |
|
43
|
|
|
wp_send_json_success($results); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @action wp_ajax_ux_builder_search_posts:1 |
|
48
|
|
|
*/ |
|
49
|
|
|
public function interceptSearchPostsQuery(): void |
|
50
|
|
|
{ |
|
51
|
|
|
$option = filter_input(INPUT_GET, 'option'); |
|
52
|
|
|
if (!str_starts_with($option, glsr()->prefix)) { |
|
53
|
|
|
return; |
|
54
|
|
|
} |
|
55
|
|
|
$option = Str::removePrefix($option, glsr()->prefix); |
|
56
|
|
|
$postId = (string) filter_input(INPUT_GET, 'id'); |
|
57
|
|
|
check_ajax_referer("ux-builder-{$postId}", 'security'); |
|
58
|
|
|
$query = filter_input(INPUT_GET, 'query'); |
|
59
|
|
|
$items = call_user_func([glsr(ShortcodeOptionManager::class), $option], [ |
|
60
|
|
|
'search' => $query, |
|
61
|
|
|
]); |
|
62
|
|
|
$callback = fn ($id, $title) => compact('id', 'title'); |
|
63
|
|
|
$results = array_map($callback, array_keys($items), array_values($items)); |
|
64
|
|
|
wp_send_json_success($results); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @action ux_builder_enqueue_scripts |
|
69
|
|
|
*/ |
|
70
|
|
|
public function printInlineScripts(string $page = ''): void |
|
71
|
|
|
{ |
|
72
|
|
|
if ('editor' === $page) { |
|
73
|
|
|
$script = file_get_contents(glsr()->path('assets/scripts/integrations/flatsome-inline.js')); |
|
74
|
|
|
wp_add_inline_script('ux-builder-core', $script); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @action ux_builder_enqueue_scripts |
|
80
|
|
|
*/ |
|
81
|
|
|
public function printInlineStyles(string $page = ''): void |
|
82
|
|
|
{ |
|
83
|
|
|
if ('editor' === $page) { |
|
84
|
|
|
$css = file_get_contents(glsr()->path('assets/styles/integrations/flatsome-inline.css')); |
|
85
|
|
|
wp_add_inline_style('ux-builder-core', $css); |
|
86
|
|
|
} else { |
|
87
|
|
|
// This fixes JS errors on mouseover events |
|
88
|
|
|
wp_add_inline_style('ux-builder-core', '.uxb-draggable>.glsr{pointer-events:none;}'); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @action init |
|
94
|
|
|
*/ |
|
95
|
|
|
public function registerShortcodes(): void |
|
96
|
|
|
{ |
|
97
|
|
|
glsr(Shortcodes\FlatsomeSiteReview::class)->register(); |
|
98
|
|
|
glsr(Shortcodes\FlatsomeSiteReviews::class)->register(); |
|
99
|
|
|
glsr(Shortcodes\FlatsomeSiteReviewsForm::class)->register(); |
|
100
|
|
|
glsr(Shortcodes\FlatsomeSiteReviewsSummary::class)->register(); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|