|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Integrations\UltimateMember\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Controllers\AbstractController; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Gatekeeper; |
|
7
|
|
|
use GeminiLabs\SiteReviews\Helpers\Arr; |
|
8
|
|
|
use GeminiLabs\SiteReviews\Modules\Html\Template; |
|
9
|
|
|
use GeminiLabs\SiteReviews\Review; |
|
10
|
|
|
|
|
11
|
|
|
class Controller extends AbstractController |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @filter site-reviews/avatar/generate |
|
15
|
|
|
*/ |
|
16
|
|
|
public function filterAvatarUrl(string $url, Review $review): string |
|
17
|
|
|
{ |
|
18
|
|
|
$type = glsr_get_option('reviews.avatars_fallback'); |
|
19
|
|
|
$defaultUrl = um_get_default_avatar_uri(); |
|
|
|
|
|
|
20
|
|
|
if ('none' === $type && !$review->author_id) { |
|
21
|
|
|
return $defaultUrl; |
|
22
|
|
|
} |
|
23
|
|
|
if ('none' !== $type && $url === $defaultUrl) { |
|
24
|
|
|
return ''; |
|
25
|
|
|
} |
|
26
|
|
|
return $url; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @filter site-reviews/enqueue/public/inline-styles |
|
31
|
|
|
*/ |
|
32
|
|
|
public function filterInlineStyles(string $css): string |
|
33
|
|
|
{ |
|
34
|
|
|
if (glsr_get_option('integrations.ultimatemember.display_directory_ratings', false, 'bool')) { |
|
35
|
|
|
$css .= '.um-directory .um-members-grid .um-member-rating:has(.glsr-star-rating) {display:flex; justify-content:center;}'; |
|
36
|
|
|
$css .= '.um-directory .um-members-list .um-member-rating:has(.glsr-star-rating) {display:flex;}'; |
|
37
|
|
|
$css .= '.um-directory .glsr-star-rating {margin:3px 0;}'; |
|
38
|
|
|
} |
|
39
|
|
|
if (glsr_get_option('integrations.ultimatemember.display_reviews_tab', false, 'bool')) { |
|
40
|
|
|
$css .= '.um-reviews-summary .glsr-summary-text {--glsr-summary-text: var(--glsr-text-base);}'; |
|
41
|
|
|
$css .= '.um-reviews-summary {padding-top:var(--glsr-gap-lg); padding-bottom:var(--glsr-gap-xl);}'; |
|
42
|
|
|
$css .= '.um-reviews-form:has(div) {border-top: 3px solid #eee; padding:var(--glsr-gap-xl) 0;}'; |
|
43
|
|
|
$css .= '.um-reviews-reviews:has(.glsr-reviews) {border-top: 3px solid #eee; padding-top:var(--glsr-gap-xl);}'; |
|
44
|
|
|
} |
|
45
|
|
|
return $css; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @filter site-reviews/assigned_users/profile_id |
|
50
|
|
|
*/ |
|
51
|
|
|
public function filterProfileId(int $profileId): int |
|
52
|
|
|
{ |
|
53
|
|
|
if (empty($profileId)) { |
|
54
|
|
|
return (int) um_get_requested_user(); |
|
55
|
|
|
} |
|
56
|
|
|
return $profileId; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @filter site-reviews/settings |
|
61
|
|
|
*/ |
|
62
|
|
|
public function filterSettings(array $settings): array |
|
63
|
|
|
{ |
|
64
|
|
|
return array_merge(glsr()->config('integrations/ultimatemember'), $settings); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @filter site-reviews/settings/sanitize |
|
69
|
|
|
*/ |
|
70
|
|
|
public function filterSettingsCallback(array $settings, array $input): array |
|
71
|
|
|
{ |
|
72
|
|
|
$enabled = Arr::get($input, 'settings.integrations.ultimatemember.enabled'); |
|
73
|
|
|
if ('yes' === $enabled && !$this->gatekeeper()->allows()) { // this renders any error notices |
|
74
|
|
|
$settings = Arr::set($settings, 'settings.integrations.ultimatemember.enabled', 'no'); |
|
75
|
|
|
} |
|
76
|
|
|
$shortcodes = [ |
|
77
|
|
|
'form' => 'site_reviews_form', |
|
78
|
|
|
'reviews' => 'site_reviews', |
|
79
|
|
|
'summary' => 'site_reviews_summary', |
|
80
|
|
|
]; |
|
81
|
|
|
foreach ($shortcodes as $key => $shortcode) { |
|
82
|
|
|
$path = "settings.integrations.ultimatemember.{$key}"; |
|
83
|
|
|
$value = Arr::get($input, $path); |
|
84
|
|
|
if (1 !== preg_match("/^\[{$shortcode}(\s[^\]]*\]|\])$/", $value)) { |
|
85
|
|
|
continue; |
|
86
|
|
|
} |
|
87
|
|
|
if (!str_contains($value, 'assigned_users')) { |
|
88
|
|
|
$value = str_replace($shortcode, sprintf('%s assigned_users="profile_id"', $shortcode), $value); |
|
89
|
|
|
$settings = Arr::set($settings, $path, $value); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
return $settings; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @filter site-reviews/integration/subsubsub |
|
97
|
|
|
*/ |
|
98
|
|
|
public function filterSubsubsub(array $subsubsub): array |
|
99
|
|
|
{ |
|
100
|
|
|
$subsubsub['ultimatemember'] = 'Ultimate Member'; |
|
101
|
|
|
return $subsubsub; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @action admin_init |
|
106
|
|
|
*/ |
|
107
|
|
|
public function renderNotice(): void |
|
108
|
|
|
{ |
|
109
|
|
|
if (glsr_get_option('integrations.ultimatemember.enabled', false, 'bool')) { |
|
110
|
|
|
$this->gatekeeper()->allows(); // this renders any error notices |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @action site-reviews/settings/ultimatemember |
|
116
|
|
|
*/ |
|
117
|
|
|
public function renderSettings(string $rows): void |
|
118
|
|
|
{ |
|
119
|
|
|
glsr(Template::class)->render('integrations/ultimatemember/settings', [ |
|
120
|
|
|
'context' => [ |
|
121
|
|
|
'rows' => $rows, |
|
122
|
|
|
], |
|
123
|
|
|
]); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
protected function gatekeeper(): Gatekeeper |
|
127
|
|
|
{ |
|
128
|
|
|
return new Gatekeeper([ |
|
129
|
|
|
'ultimate-member/ultimate-member.php' => [ |
|
130
|
|
|
'minimum_version' => '2.5', |
|
131
|
|
|
'name' => 'Ultimate Member', |
|
132
|
|
|
'plugin_uri' => 'https://wordpress.org/plugins/ultimate-member/', |
|
133
|
|
|
'untested_version' => '3.0', |
|
134
|
|
|
], |
|
135
|
|
|
]); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|