1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Integrations\ProfilePress\Controllers; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Commands\EnqueuePublicAssets; |
6
|
|
|
use GeminiLabs\SiteReviews\Controllers\AbstractController; |
7
|
|
|
use GeminiLabs\SiteReviews\Database\CountManager; |
8
|
|
|
use GeminiLabs\SiteReviews\Helper; |
9
|
|
|
use GeminiLabs\SiteReviews\Helpers\Arr; |
10
|
|
|
use GeminiLabs\SiteReviews\Integrations\ProfilePress\RatingField; |
11
|
|
|
use GeminiLabs\SiteReviews\Modules\Html\Builder; |
12
|
|
|
use ProfilePress\Core\Admin\SettingsPages\DragDropBuilder\DragDropBuilder; |
|
|
|
|
13
|
|
|
use ProfilePress\Core\Classes\FormRepository; |
|
|
|
|
14
|
|
|
|
15
|
|
|
class DirectoryController extends AbstractController |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param array $shortcodes |
19
|
|
|
* |
20
|
|
|
* @filter ppress_user_profile_available_shortcodes |
21
|
|
|
*/ |
22
|
|
|
public function filterAvailableShortcodes($shortcodes): array |
23
|
|
|
{ |
24
|
|
|
$shortcodes = Arr::consolidate($shortcodes); |
25
|
|
|
$shortcodes['profile-rating'] = [ |
26
|
|
|
'description' => esc_html_x('Rating of user', 'admin-text', 'site-reviews'), |
27
|
|
|
'shortcode' => 'profile-rating', |
28
|
|
|
]; |
29
|
|
|
return $shortcodes; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @filter site-reviews/enqueue/public/inline-styles |
34
|
|
|
*/ |
35
|
|
|
public function filterInlineStyles(string $css): string |
36
|
|
|
{ |
37
|
|
|
$css .= '.pp-member-directory .pp-member-rating {display:flex;justify-content:center;}'; |
38
|
|
|
$css .= '.pp-member-directory .pp-member-rating * {display:inline-flex;}'; |
39
|
|
|
return $css; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param array $args |
44
|
|
|
* |
45
|
|
|
* @filter ppress_member_directory_wp_user_args |
46
|
|
|
*/ |
47
|
|
|
public function filterMemberDirectoryArgs($args): array |
48
|
|
|
{ |
49
|
|
|
$args = Arr::consolidate($args); |
50
|
|
|
$sortby = $args['meta_key'] ?? ''; |
51
|
|
|
if (!in_array($sortby, [RatingField::LOW_RATED, RatingField::HIGH_RATED])) { |
52
|
|
|
return $args; |
53
|
|
|
} |
54
|
|
|
$order = RatingField::HIGH_RATED === $sortby ? 'DESC' : 'ASC'; |
55
|
|
|
$sortKey = 'bayesian' === glsr_get_option('integrations.profilepress.directory_sorting') |
56
|
|
|
? CountManager::META_RANKING |
57
|
|
|
: CountManager::META_AVERAGE; |
58
|
|
|
$args['meta_query'] ??= []; |
59
|
|
|
$args['meta_query'][] = [ |
60
|
|
|
'relation' => 'OR', |
61
|
|
|
[ |
62
|
|
|
'compare' => 'NOT EXISTS', |
63
|
|
|
'key' => $sortKey, |
64
|
|
|
'type' => 'NUMERIC', |
65
|
|
|
], |
66
|
|
|
'_rating_key' => [ |
67
|
|
|
'compare' => 'EXISTS', |
68
|
|
|
'key' => $sortKey, |
69
|
|
|
'type' => 'NUMERIC', |
70
|
|
|
], |
71
|
|
|
]; |
72
|
|
|
$args['orderby'] = [ |
73
|
|
|
'_rating_key' => $order, |
74
|
|
|
'user_registered' => 'DESC', |
75
|
|
|
]; |
76
|
|
|
unset($args['meta_key']); |
77
|
|
|
unset($args['order']); |
78
|
|
|
return $args; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $className |
83
|
|
|
* @param string $formTheme |
84
|
|
|
* @param string $formType |
85
|
|
|
* |
86
|
|
|
* @filter ppress_register_dnd_form_class |
87
|
|
|
*/ |
88
|
|
|
public function filterMemberDirectoryTheme($className, $formTheme, $formType): string |
89
|
|
|
{ |
90
|
|
|
if ('MemberDirectory' !== $formType) { |
91
|
|
|
return (string) $className; |
92
|
|
|
} |
93
|
|
|
$override = Helper::buildClassName((string) $formTheme, 'Integrations\ProfilePress\MemberDirectory'); |
94
|
|
|
if (!class_exists($override)) { |
95
|
|
|
return (string) $className; |
96
|
|
|
} |
97
|
|
|
return $override; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param array $settings |
102
|
|
|
* |
103
|
|
|
* @filter ppress_form_builder_meta_box_settings |
104
|
|
|
*/ |
105
|
|
|
public function filterMetaBoxSettings($settings): array |
106
|
|
|
{ |
107
|
|
|
$settings = Arr::consolidate($settings); |
108
|
|
|
$sorting = $settings['ppress_md_sorting'] ?? []; |
109
|
|
|
if (empty($sorting)) { |
110
|
|
|
return $settings; |
111
|
|
|
} |
112
|
|
|
foreach (['ppress_md_sort_default', 'ppress_md_sort_method_fields'] as $id) { |
113
|
|
|
$index = array_search($id, array_column($sorting, 'id')); |
114
|
|
|
if (false === $index) { |
115
|
|
|
continue; |
116
|
|
|
} |
117
|
|
|
$group = _x('Review Fields', 'admin-text', 'site-reviews'); |
118
|
|
|
$sorting[$index]['options'][$group] = [ |
119
|
|
|
RatingField::HIGH_RATED => _x('Highest rated first', 'admin-text', 'site-reviews'), |
120
|
|
|
RatingField::LOW_RATED => _x('Lowest rated first', 'admin-text', 'site-reviews'), |
121
|
|
|
]; |
122
|
|
|
$settings['ppress_md_sorting'] = $sorting; |
123
|
|
|
} |
124
|
|
|
return $settings; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @action wp_ajax_pp-builder-preview:5 |
129
|
|
|
*/ |
130
|
|
|
public function insertPreviewCss(): void |
131
|
|
|
{ |
132
|
|
|
check_ajax_referer('ppress-admin-nonce'); |
133
|
|
|
if (!current_user_can('manage_options')) { |
134
|
|
|
return; |
135
|
|
|
} |
136
|
|
|
if ('pp-builder-preview' !== filter_input(INPUT_POST, 'action')) { |
137
|
|
|
return; |
138
|
|
|
} |
139
|
|
|
$css = file_get_contents(glsr()->path('assets/styles/minimal.css')); |
140
|
|
|
$css .= glsr(EnqueuePublicAssets::class)->inlineStyles(); |
141
|
|
|
$_POST['builder_css'] = $_POST['builder_css'].$css; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @action admin_init |
146
|
|
|
*/ |
147
|
|
|
public function registerProfileBuilderField(): void |
148
|
|
|
{ |
149
|
|
|
if (!DragDropBuilder::get_instance()->is_drag_drop_page()) { |
150
|
|
|
return; |
151
|
|
|
} |
152
|
|
|
$formType = sanitize_text_field(filter_input(INPUT_GET, 'form-type')); |
153
|
|
|
if (!in_array($formType, [FormRepository::USER_PROFILE_TYPE, FormRepository::MEMBERS_DIRECTORY_TYPE])) { |
154
|
|
|
return; |
155
|
|
|
} |
156
|
|
|
new RatingField(); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param \WP_User $user |
161
|
|
|
* |
162
|
|
|
* @action ppress_register_profile_shortcode |
163
|
|
|
*/ |
164
|
|
|
public function registerProfileRatingShortcode($user): void |
165
|
|
|
{ |
166
|
|
|
if (!is_a($user, 'WP_User')) { |
167
|
|
|
return; |
168
|
|
|
} |
169
|
|
|
add_shortcode('profile-rating', function () use ($user) { |
170
|
|
|
$html = ''; |
171
|
|
|
if (!glsr_get_option('integrations.profilepress.enabled', false, 'bool')) { |
172
|
|
|
return $html; |
173
|
|
|
} |
174
|
|
|
$total = glsr(CountManager::class)->usersReviews($user->ID); |
175
|
|
|
if (0 < $total || glsr_get_option('integrations.profilepress.directory_display_empty', false, 'bool')) { |
176
|
|
|
$rating = glsr(CountManager::class)->usersAverage($user->ID); |
177
|
|
|
$html = glsr(Builder::class)->div([ |
178
|
|
|
'class' => 'pp-member-rating', |
179
|
|
|
'text' => glsr_star_rating($rating, $total), |
180
|
|
|
]); |
181
|
|
|
} |
182
|
|
|
return $html; |
183
|
|
|
}); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths