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
|
|
|
check_ajax_referer('fusion_load_nonce', 'fusion_load_nonce'); |
111
|
|
|
$data = array_fill_keys(['labels', 'results'], []); |
112
|
|
|
$params = filter_input(INPUT_POST, 'params', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
113
|
|
|
$labels = filter_input(INPUT_POST, 'labels', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
114
|
|
|
$search = filter_input(INPUT_POST, 'search'); |
115
|
|
|
$option = $params['option'] ?? ''; |
116
|
|
|
if (!is_null($search)) { |
117
|
|
|
$params['search'] = $search; |
118
|
|
|
$items = call_user_func([glsr(ShortcodeOptionManager::class), $option], $params); |
119
|
|
|
$callback = fn ($id, $text) => compact('id', 'text'); |
120
|
|
|
$data['results'] = array_map($callback, array_keys($items), array_values($items)); |
121
|
|
|
} elseif (!is_null($labels)) { |
122
|
|
|
$params['include'] = $labels; |
123
|
|
|
$items = call_user_func([glsr(ShortcodeOptionManager::class), $option], $params); |
124
|
|
|
$items = array_filter($items, fn ($id) => in_array($id, $labels), \ARRAY_FILTER_USE_KEY); |
125
|
|
|
$callback = fn ($id, $text) => compact('id', 'text'); |
126
|
|
|
$data['labels'] = array_map($callback, array_keys($items), array_values($items)); |
127
|
|
|
} |
128
|
|
|
echo wp_json_encode($data); |
129
|
|
|
wp_die(); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|