|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Integrations\Elementor; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Controllers\AbstractController; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Database\ShortcodeOptionManager; |
|
7
|
|
|
use GeminiLabs\SiteReviews\Helpers\Svg; |
|
8
|
|
|
use GeminiLabs\SiteReviews\Integrations\Elementor\Controls\MultiSwitcher; |
|
9
|
|
|
use GeminiLabs\SiteReviews\Integrations\Elementor\Controls\Select2Ajax; |
|
10
|
|
|
use GeminiLabs\SiteReviews\Integrations\Elementor\Defaults\QueryAjaxDefaults; |
|
11
|
|
|
use GeminiLabs\SiteReviews\Integrations\Elementor\Widgets\ElementorSiteReview; |
|
12
|
|
|
use GeminiLabs\SiteReviews\Integrations\Elementor\Widgets\ElementorSiteReviews; |
|
13
|
|
|
use GeminiLabs\SiteReviews\Integrations\Elementor\Widgets\ElementorSiteReviewsForm; |
|
14
|
|
|
use GeminiLabs\SiteReviews\Integrations\Elementor\Widgets\ElementorSiteReviewsSummary; |
|
15
|
|
|
|
|
16
|
|
|
class Controller extends AbstractController |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @filter site-reviews/schema/generate |
|
20
|
|
|
*/ |
|
21
|
|
|
public function filterGeneratedSchema(array $schema): array |
|
22
|
|
|
{ |
|
23
|
|
|
return empty($schema) |
|
24
|
|
|
? glsr(SchemaParser::class)->generate() |
|
25
|
|
|
: $schema; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @filter site-reviews/modal_wrapped_by |
|
30
|
|
|
*/ |
|
31
|
|
|
public function filterModalWrappedBy(array $builders): array |
|
32
|
|
|
{ |
|
33
|
|
|
$builders[] = 'elementor'; |
|
34
|
|
|
return $builders; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Fix Star Rating control when review form is used inside an Elementor Pro Popup. |
|
39
|
|
|
* |
|
40
|
|
|
* @filter site-reviews/enqueue/public/inline-script/after |
|
41
|
|
|
*/ |
|
42
|
|
|
public function filterPublicInlineScript(string $script): string |
|
43
|
|
|
{ |
|
44
|
|
|
if (!defined('ELEMENTOR_VERSION')) { |
|
45
|
|
|
return $script; |
|
46
|
|
|
} |
|
47
|
|
|
$inlineScript = (string) file_get_contents(glsr()->path('assets/scripts/integrations/elementor-frontend.js')); |
|
48
|
|
|
return $script.$inlineScript; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Fix Star Rating CSS class prefix in the Elementor editor. |
|
53
|
|
|
* |
|
54
|
|
|
* @filter site-reviews/defaults/star-rating/defaults |
|
55
|
|
|
*/ |
|
56
|
8 |
|
public function filterStarRatingDefaults(array $defaults): array |
|
57
|
|
|
{ |
|
58
|
8 |
|
if ('elementor' === filter_input(INPUT_GET, 'action')) { |
|
59
|
|
|
$defaults['prefix'] = 'glsr-'; |
|
60
|
|
|
} |
|
61
|
8 |
|
return $defaults; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @see static::registerAjaxActions() |
|
66
|
|
|
*/ |
|
67
|
|
|
public function queryAjaxControlOptions($data): array |
|
68
|
|
|
{ |
|
69
|
|
|
$args = glsr(QueryAjaxDefaults::class)->restrict($data); |
|
70
|
|
|
$options = call_user_func([glsr(ShortcodeOptionManager::class), $args['option']], $args); |
|
71
|
|
|
if (!is_array($options)) { |
|
72
|
|
|
return []; |
|
73
|
|
|
} |
|
74
|
|
|
$callback = fn ($id, $text) => compact('id', 'text'); |
|
75
|
|
|
$results = array_map($callback, array_keys($options), array_values($options)); |
|
76
|
|
|
return compact('results'); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @see static::registerAjaxActions() |
|
81
|
|
|
*/ |
|
82
|
|
|
public function queryAjaxControlSelected($data): array |
|
83
|
|
|
{ |
|
84
|
|
|
$args = glsr(QueryAjaxDefaults::class)->restrict($data); |
|
85
|
|
|
$results = call_user_func([glsr(ShortcodeOptionManager::class), $args['option']], $args); |
|
86
|
|
|
if (!is_array($results)) { |
|
87
|
|
|
return []; |
|
88
|
|
|
} |
|
89
|
|
|
if (!array_key_exists($args['include'], $results)) { |
|
90
|
|
|
return []; |
|
91
|
|
|
} |
|
92
|
|
|
return [ |
|
93
|
|
|
$args['include'] => $results[$args['include']], |
|
94
|
|
|
]; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param \Elementor\Core\Common\Modules\Ajax\Module $manager |
|
99
|
|
|
* |
|
100
|
|
|
* @action elementor/ajax/register_actions |
|
101
|
|
|
*/ |
|
102
|
|
|
public function registerAjaxActions($manager): void |
|
103
|
|
|
{ |
|
104
|
|
|
$manager->register_ajax_action(glsr()->prefix.'elementor_ajax_query', [$this, 'queryAjaxControlOptions']); |
|
105
|
|
|
$manager->register_ajax_action(glsr()->prefix.'elementor_ajax_query_selected', [$this, 'queryAjaxControlSelected']); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @param \Elementor\Elements_Manager $manager |
|
110
|
|
|
* |
|
111
|
|
|
* @action elementor/elements/categories_registered |
|
112
|
|
|
*/ |
|
113
|
|
|
public function registerCategory($manager): void |
|
114
|
|
|
{ |
|
115
|
|
|
$manager->add_category(glsr()->id, [ |
|
116
|
|
|
'hideIfEmpty' => true, |
|
117
|
|
|
'title' => glsr()->name, |
|
118
|
|
|
]); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @param \Elementor\Controls_Manager $manager |
|
123
|
|
|
* |
|
124
|
|
|
* @action elementor/controls/register |
|
125
|
|
|
*/ |
|
126
|
|
|
public function registerControls($manager): void |
|
127
|
|
|
{ |
|
128
|
|
|
$manager->register(new MultiSwitcher()); |
|
129
|
|
|
$manager->register(new Select2Ajax()); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @action admin_enqueue_scripts |
|
134
|
|
|
* @action elementor/editor/after_enqueue_styles |
|
135
|
|
|
* @action elementor/preview/enqueue_styles |
|
136
|
|
|
*/ |
|
137
|
|
|
public function registerInlineStyles(): void |
|
138
|
|
|
{ |
|
139
|
|
|
$icons = [ |
|
140
|
|
|
'eicon-glsr-form' => Svg::encoded('assets/images/icons/elementor/icon-form.svg'), |
|
141
|
|
|
'eicon-glsr-review' => Svg::encoded('assets/images/icons/elementor/icon-review.svg'), |
|
142
|
|
|
'eicon-glsr-reviews' => Svg::encoded('assets/images/icons/elementor/icon-reviews.svg'), |
|
143
|
|
|
'eicon-glsr-summary' => Svg::encoded('assets/images/icons/elementor/icon-summary.svg'), |
|
144
|
|
|
]; |
|
145
|
|
|
$maskRules = ''; |
|
146
|
|
|
foreach ($icons as $class => $url) { |
|
147
|
|
|
$maskRules .= "i.{$class}::before { mask-image: url(\"{$url}\"); }"; |
|
148
|
|
|
} |
|
149
|
|
|
$css = <<<CSS |
|
150
|
|
|
i[class^="eicon-glsr-"]::before { |
|
151
|
|
|
background-color: currentColor; |
|
152
|
|
|
content: '.'; |
|
153
|
|
|
display: block; |
|
154
|
|
|
mask-repeat: no-repeat; |
|
155
|
|
|
mask-size: contain; |
|
156
|
|
|
width: 1em; |
|
157
|
|
|
} |
|
158
|
|
|
{$maskRules} |
|
159
|
|
|
.elementor-nerd-box-icon[src$="assets/images/premium.svg"] { |
|
160
|
|
|
width: 240px; |
|
161
|
|
|
} |
|
162
|
|
|
CSS; |
|
163
|
|
|
$css = preg_replace('/\s+/', ' ', $css); |
|
164
|
|
|
wp_add_inline_style('elementor-admin', $css); |
|
165
|
|
|
wp_add_inline_style('elementor-editor', $css); |
|
166
|
|
|
wp_add_inline_style('elementor-frontend', |
|
167
|
|
|
$css."[class*=\"eicon-glsr-\"]::before{font-size:28px;margin:0 auto}" |
|
168
|
|
|
); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @action elementor/editor/after_enqueue_scripts |
|
173
|
|
|
*/ |
|
174
|
|
|
public function registerScripts(): void |
|
175
|
|
|
{ |
|
176
|
|
|
wp_register_script( |
|
177
|
|
|
glsr()->id.'/elementor-editor', |
|
178
|
|
|
glsr()->url('assets/scripts/integrations/elementor-editor.js'), |
|
179
|
|
|
[], |
|
180
|
|
|
glsr()->version, |
|
181
|
|
|
['strategy' => 'defer'] |
|
182
|
|
|
); |
|
183
|
|
|
wp_enqueue_script(glsr()->id.'/elementor-editor'); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @param \Elementor\Widgets_Manager $manager |
|
188
|
|
|
* |
|
189
|
|
|
* @action elementor/widgets/register |
|
190
|
|
|
*/ |
|
191
|
|
|
public function registerWidgets($manager): void |
|
192
|
|
|
{ |
|
193
|
|
|
$manager->register(new ElementorSiteReview()); |
|
194
|
|
|
$manager->register(new ElementorSiteReviews()); |
|
195
|
|
|
$manager->register(new ElementorSiteReviewsForm()); |
|
196
|
|
|
$manager->register(new ElementorSiteReviewsSummary()); |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|