|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Integrations\FusionBuilder; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Controllers\AbstractController; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Database\ShortcodeOptionManager; |
|
7
|
|
|
use GeminiLabs\SiteReviews\Helpers\Svg; |
|
8
|
|
|
use GeminiLabs\SiteReviews\Integrations\FusionBuilder\Elements\FusionSiteReview; |
|
9
|
|
|
use GeminiLabs\SiteReviews\Integrations\FusionBuilder\Elements\FusionSiteReviews; |
|
10
|
|
|
use GeminiLabs\SiteReviews\Integrations\FusionBuilder\Elements\FusionSiteReviewsForm; |
|
11
|
|
|
use GeminiLabs\SiteReviews\Integrations\FusionBuilder\Elements\FusionSiteReviewsSummary; |
|
12
|
|
|
|
|
13
|
|
|
class Controller extends AbstractController |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @action fusion_builder_admin_scripts_hook; |
|
17
|
|
|
* @action fusion_builder_enqueue_live_scripts |
|
18
|
|
|
*/ |
|
19
|
|
|
public function enqueueBuilderStyles(): void |
|
20
|
|
|
{ |
|
21
|
|
|
$inlineFile = glsr()->path('assets/styles/integrations/fusion-inline.css'); |
|
22
|
|
|
if (!file_exists($inlineFile)) { |
|
23
|
|
|
glsr_log()->error("Inline stylesheet is missing: {$inlineFile}"); |
|
24
|
|
|
return; |
|
25
|
|
|
} |
|
26
|
|
|
$icons = [ |
|
27
|
|
|
':icon-0' => Svg::encoded('assets/images/icon-static.svg'), |
|
28
|
|
|
':icon-1' => Svg::encoded('assets/images/icons/fusion/icon-form.svg'), |
|
29
|
|
|
':icon-2' => Svg::encoded('assets/images/icons/fusion/icon-review.svg'), |
|
30
|
|
|
':icon-3' => Svg::encoded('assets/images/icons/fusion/icon-reviews.svg'), |
|
31
|
|
|
':icon-4' => Svg::encoded('assets/images/icons/fusion/icon-summary.svg'), |
|
32
|
|
|
]; |
|
33
|
|
|
$css = str_replace( |
|
34
|
|
|
array_keys($icons), |
|
35
|
|
|
array_values($icons), |
|
36
|
|
|
file_get_contents($inlineFile) |
|
37
|
|
|
); |
|
38
|
|
|
wp_add_inline_style('fusion_builder_css', $css); |
|
39
|
|
|
wp_add_inline_style('fusion-builder-frame-builder-css', $css); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @filter site-reviews/defaults/style-classes/defaults |
|
44
|
|
|
*/ |
|
45
|
|
|
public function filterButtonClass(array $defaults): array |
|
46
|
|
|
{ |
|
47
|
|
|
if ('default' !== glsr_get_option('general.style')) { |
|
48
|
|
|
return $defaults; |
|
49
|
|
|
} |
|
50
|
|
|
if (!defined('AVADA_VERSION')) { |
|
51
|
|
|
return $defaults; |
|
52
|
|
|
} |
|
53
|
|
|
$defaults['button'] = 'glsr-button fusion-button fusion-button-default fusion-button-default-size fusion-button-default-span fusion-button-default-type'; |
|
54
|
|
|
return $defaults; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @filter site-reviews/enqueue/public/inline-script/after |
|
59
|
|
|
*/ |
|
60
|
|
|
public function filterPublicInlineScript(string $script): string |
|
61
|
|
|
{ |
|
62
|
|
|
$inlineFile = glsr()->path('assets/scripts/integrations/fusion-inline.js'); |
|
63
|
|
|
if (!file_exists($inlineFile)) { |
|
64
|
|
|
glsr_log()->error("Inline javascript is missing: {$inlineFile}"); |
|
65
|
|
|
return $script; |
|
66
|
|
|
} |
|
67
|
|
|
return $script.file_get_contents($inlineFile); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @filter site-reviews/register/widgets |
|
72
|
|
|
*/ |
|
73
|
|
|
public function filterRegisterWidgets(bool $bool): bool |
|
74
|
|
|
{ |
|
75
|
|
|
if (function_exists('is_fusion_editor') && !is_fusion_editor()) { |
|
76
|
|
|
return false; |
|
77
|
|
|
} |
|
78
|
|
|
return $bool; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @action site-reviews/activated |
|
83
|
|
|
*/ |
|
84
|
|
|
public function onActivated(): void |
|
85
|
|
|
{ |
|
86
|
|
|
if (function_exists('fusion_builder_auto_activate_element')) { |
|
87
|
|
|
fusion_builder_auto_activate_element('site_review'); |
|
88
|
|
|
fusion_builder_auto_activate_element('site_reviews'); |
|
89
|
|
|
fusion_builder_auto_activate_element('site_reviews_form'); |
|
90
|
|
|
fusion_builder_auto_activate_element('site_reviews_summary'); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @action fusion_builder_before_init |
|
96
|
|
|
*/ |
|
97
|
|
|
public function registerFusionElements(): void |
|
98
|
|
|
{ |
|
99
|
|
|
FusionSiteReview::registerElement(); |
|
100
|
|
|
FusionSiteReviews::registerElement(); |
|
101
|
|
|
FusionSiteReviewsForm::registerElement(); |
|
102
|
|
|
FusionSiteReviewsSummary::registerElement(); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @action wp_ajax_glsr_fusion_search_query |
|
107
|
|
|
*/ |
|
108
|
|
|
public function runSearchQuery(): void |
|
109
|
|
|
{ |
|
110
|
|
|
$reqMethod = 'POST' === filter_input(INPUT_SERVER, 'REQUEST_METHOD') ? \INPUT_POST : \INPUT_GET; |
|
111
|
|
|
if (filter_input($reqMethod, 'fusion_load_nonce')) { |
|
112
|
|
|
check_ajax_referer('fusion_load_nonce', 'fusion_load_nonce'); |
|
113
|
|
|
} else { |
|
114
|
|
|
check_ajax_referer('fusion-page-options-nonce', 'fusion_po_nonce'); |
|
115
|
|
|
} |
|
116
|
|
|
$data = array_fill_keys(['labels', 'results'], []); |
|
117
|
|
|
$params = filter_input($reqMethod, 'params', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
118
|
|
|
$labels = filter_input($reqMethod, 'labels', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
119
|
|
|
$search = filter_input($reqMethod, 'search'); |
|
120
|
|
|
$option = $params['option'] ?? ''; |
|
121
|
|
|
if (!is_null($search)) { |
|
122
|
|
|
$params['search'] = $search; |
|
123
|
|
|
$items = call_user_func([glsr(ShortcodeOptionManager::class), $option], $params); |
|
124
|
|
|
$callback = fn ($id, $text) => compact('id', 'text'); |
|
125
|
|
|
$data['results'] = array_map($callback, array_keys($items), array_values($items)); |
|
126
|
|
|
} elseif (!is_null($labels)) { |
|
127
|
|
|
$params['include'] = $labels; |
|
128
|
|
|
$items = call_user_func([glsr(ShortcodeOptionManager::class), $option], $params); |
|
129
|
|
|
$items = array_filter($items, fn ($id) => in_array($id, $labels), \ARRAY_FILTER_USE_KEY); |
|
130
|
|
|
$callback = fn ($id, $text) => compact('id', 'text'); |
|
131
|
|
|
$data['labels'] = array_map($callback, array_keys($items), array_values($items)); |
|
132
|
|
|
} |
|
133
|
|
|
echo wp_json_encode($data); |
|
134
|
|
|
wp_die(); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|